Package net.sf.samtools

Examples of net.sf.samtools.SAMRecord


   
    for (SAMRecord read : contigReader) {
     
      String origSamStr = read.getReadName();
      origSamStr = origSamStr.replace(Sam2Fastq.FIELD_DELIMITER, "\t");
      SAMRecord orig;
      try {
        orig = samStringReader.getRead(origSamStr);
      } catch (RuntimeException e) {
        System.out.println("Error processing: [" + origSamStr + "]");
        System.out.println("Contig read: [" + read.getSAMString() + "]");
        e.printStackTrace();
        throw e;
      }
      orig.setHeader(samHeader);
     
      orig.setReadString(read.getReadString());
      orig.setBaseQualityString(read.getBaseQualityString());

      SAMRecord readToOutput = null;
     
      // Only adjust reads that align to contig with no indel and shorter edit distance than the original alignment
      String matchingString = read.getReadLength() + "M";
      if ((read.getCigarString().equals(matchingString)) &&
        (read.getReadUnmappedFlag() == false&&
        (!orig.getCigarString().contains("N")) &&  // Don't remap introns
        (SAMRecordUtils.getEditDistance(read, null) < SAMRecordUtils.getOrigEditDistance(orig)) &&
        (!isFiltered(orig))) {
       
        SAMRecord origRead = orig;
        String contigReadStr = read.getReferenceName();
       
        int numBestHits = SAMRecordUtils.getIntAttribute(read, "X0");
        int numSubOptimalHits = SAMRecordUtils.getIntAttribute(read, "X1");
       
View Full Code Here


    log("Done adjusting reads.  Number of reads realigned: " + realignedCount);
  }
 
  private SAMRecord getUpdatedReadInfo(Map<String, SAMRecord> outputReadAlignmentInfo, SAMRecord read,
      SAMRecord orig, SAMRecord origRead, CompareToReference2 c2r, int totalHits, boolean isTightAlignment) {
    SAMRecord readToOutput = null;
   
    if (outputReadAlignmentInfo.size() == 1) {
      readToOutput = outputReadAlignmentInfo.values().iterator().next();
     
      // Check to see if the original read location was in a non-target region.
      // If so, compare updated NM to ref versus original NM to ref
      if ((c2r != null) && (!isImprovedAlignment(readToOutput, orig, c2r))) {
        readToOutput = null;
      } else {
        int origBestHits = SAMRecordUtils.getIntAttribute(readToOutput, "X0");
        int origSuboptimalHits = SAMRecordUtils.getIntAttribute(readToOutput, "X1");
       
        // If the read mapped to multiple locations, set mapping quality to zero.
        if ((outputReadAlignmentInfo.size() > 1) || (totalHits > 1000)) {
          readToOutput.setMappingQuality(0);
        }
       
        // This must happen prior to updateMismatchAndEditDistance
        adjustForStrand(read.getReadNegativeStrandFlag(), readToOutput);
       
        if (readToOutput.getAttribute(ORIGINAL_ALIGNMENT_TAG) != null) {
          // HACK: Only add X0 for final alignment.  Assembler skips X0 > 1
          if (isTightAlignment) {
            readToOutput.setAttribute("X0", outputReadAlignmentInfo.size());
          } else {
            readToOutput.setAttribute("X0", null);
          }
          readToOutput.setAttribute("X1", origBestHits + origSuboptimalHits);
         
          // Clear various tags
          readToOutput.setAttribute("XO", null);
          readToOutput.setAttribute("XG", null);
          readToOutput.setAttribute("MD", null);
          readToOutput.setAttribute("XA", null);
          readToOutput.setAttribute("XT", null);
         
          if (c2r != null) {
            updateMismatchAndEditDistance(readToOutput, c2r, origRead);
          }
        }
View Full Code Here

   
    Map<String, SAMRecord> outputReadAlignmentInfo = new HashMap<String, SAMRecord>();
   
    for (HitInfo hitInfo : bestHits) {
     
      SAMRecord contigRead = hitInfo.getRecord();
      int position = hitInfo.getPosition() - 1;

      List<ReadBlock> contigReadBlocks = ReadBlock.getReadBlocks(contigRead);
     
      ReadPosition readPosition = new ReadPosition(origRead, position, -1);
      SAMRecord updatedRead = updateReadAlignment(contigRead,
          contigReadBlocks, readPosition);
     
      if (updatedRead != null) {           
        if (updatedRead.getReadUnmappedFlag()) {
          updatedRead.setReadUnmappedFlag(false);
        }
       
        updatedRead.setReadNegativeStrandFlag(hitInfo.isOnNegativeStrand());
       
        // If the read's alignment info has been modified, record the original alignment.
        if (origRead.getReadUnmappedFlag() ||
          !origRead.getReferenceName().equals(updatedRead.getReferenceName()) ||
          origRead.getAlignmentStart() != updatedRead.getAlignmentStart() ||
          origRead.getReadNegativeStrandFlag() != updatedRead.getReadNegativeStrandFlag() ||
          !origRead.getCigarString().equals(updatedRead.getCigarString())) {
       
          if (SAMRecordUtils.isSoftClipEquivalent(origRead, updatedRead)) {
            // Restore Cigar and position
//              System.out.println("Re-setting [" + updatedRead.getSAMString() + "] --- [" + origRead.getSAMString() + "]");
            updatedRead.setAlignmentStart(origRead.getAlignmentStart());
            updatedRead.setCigar(origRead.getCigar());
           
          } else {
            String originalAlignment;
            if (origRead.getReadUnmappedFlag()) {
              originalAlignment = "N/A";
            } else {
              originalAlignment = origRead.getReferenceName() + ":" + origRead.getAlignmentStart() + ":" +
                  (origRead.getReadNegativeStrandFlag() ? "-" : "+") + ":" + origRead.getCigarString();
            }
           
            // Read's original alignment position
            updatedRead.setAttribute(ORIGINAL_ALIGNMENT_TAG, originalAlignment);
          }
        }
       
        // Mismatches to the contig
        updatedRead.setAttribute(MISMATCHES_TO_CONTIG_TAG, hitInfo.getNumMismatches());
       
        // Contig's mapping quality
        updatedRead.setAttribute(CONTIG_QUALITY_TAG, hitInfo.getRecord().getMappingQuality());
       
        // Contig's length
//        updatedRead.setAttribute("YL", hitInfo.getRecord().getCigar().getReadLength());
       
        // Contig Position + CIGAR
//        updatedRead.setAttribute(CONTIG_ALIGNMENT_TAG, contigRead.getReferenceName() + ":" + contigRead.getAlignmentStart() +
//            ":" + contigRead.getCigarString());
       
        updatedRead.setAttribute(CONTIG_ALIGNMENT_TAG, contigRead.getStringAttribute("ZZ"));
       
        //TODO: Check strand!!!
        String readAlignmentInfo = updatedRead.getReferenceName() + "_" + updatedRead.getAlignmentStart() + "_" +
            updatedRead.getCigarString();
       
        if (!outputReadAlignmentInfo.containsKey(readAlignmentInfo)) {
          outputReadAlignmentInfo.put(readAlignmentInfo, updatedRead);
        }
      }
View Full Code Here

    rdr.setValidationStringency(ValidationStringency.SILENT);
   
    Iterator<SAMRecord> iter = rdr.queryContained(chromosome, 0, 0);
     
    while (iter.hasNext()) {
      SAMRecord read = (SAMRecord) iter.next();
     
      outputWriter.addAlignment(read);
    }
   
    rdr.close();
View Full Code Here

   
    // Now go back and retrieve the unmapped reads.
    System.err.println("Processing unmapped reads");
    Iterator<SAMRecord> iter = rdr.queryUnmapped();
    while (iter.hasNext()) {
      SAMRecord read = iter.next();
   
      // If this read is not assigned a position, but the mate is, include in the output BAM associated with mate's chromosome.
      if (read.getReferenceIndex() == SAMRecord.NO_ALIGNMENT_REFERENCE_INDEX && read.getMateReferenceIndex() != SAMRecord.NO_ALIGNMENT_REFERENCE_INDEX) {
        SAMFileWriter writer = outputWriterMap.get(read.getMateReferenceName());
        writer.addAlignment(read);
      }
    }
   
    for (SAMFileWriter writer : outputWriterMap.values()) {
View Full Code Here

     
      Iterator<SAMRecord> iter = reader.iterator();
     
      int cnt = 0;
      while ((iter.hasNext()) && (cnt < 1000000)) {
        SAMRecord read = iter.next();
        this.rnaReadLength = Math.max(this.rnaReadLength, read.getReadLength());
      }
    } finally {
      reader.close();
    }
   
View Full Code Here

  protected Breakpoint processRead(List<SAMRecord> readList) {
    if (readList.size() != 2) {
      return null;
    }
   
    SAMRecord read1 = readList.get(0);
    SAMRecord read2 = readList.get(1);
   
    if (read1.getMappingQuality() < MIN_MAPQ || read2.getMappingQuality() < MIN_MAPQ) {
      return null;
    }
   
    SAMRecord primary = null;
    SAMRecord secondary = null;
   
    if (SAMRecordUtils.isPrimary(read1) && !SAMRecordUtils.isPrimary(read2)) {
      primary = read1;
      secondary = read2;
    } else if (!SAMRecordUtils.isPrimary(read1) && SAMRecordUtils.isPrimary(read2)) {
View Full Code Here

      if (!read.getReadUnmappedFlag() && read.getCigarString().equals(fullMatch)) {
        if (read.getAlignmentStart() >= minStart && read.getAlignmentStart() <= maxStart) {
          int editDistance = SAMRecordUtils.getIntAttribute(read, "NM");
         
          if (editDistance <= MAX_EDIT_DISTANCE) {
            SAMRecord orig = getOrigRecord(read, samHeader);
            int origEditDistance = SAMRecordUtils.getIntAttribute(orig, "YX");
            if (editDistance < origEditDistance) {
              //TODO: Inspect alternate alignments
              String[] refFields = read.getReferenceName().split("_");
              if (refFields.length >= 6) {
View Full Code Here

    sortReadsByPosition(readList);
   
    pruneLikelyInserts(readList);
   
    if (readList.size() == 2) {
      SAMRecord read1 = readList.get(0);
      SAMRecord read2 = readList.get(1);
     
      // Look for same reference, strand and multipart Cigar
      if ((read1.getReferenceName().equals(read2.getReferenceName())) &&
        (read1.getReadNegativeStrandFlag() == read2.getReadNegativeStrandFlag()) &&
        (read1.getCigarLength() >= 2) &&
        (read2.getCigarLength() >= 2) &&
        (Math.abs(read1.getAlignmentStart()-read2.getAlignmentStart()) < MAX_GAP_LENGTH)) {
       
        SAMRecord combinedRead = combineChimericReads(read1, read2);
        if (combinedRead != null) {
          isCombined = true;
          reads = new ArrayList<SAMRecord>();
          reads.add(combinedRead);
        }
View Full Code Here

   
    return reads;
  }
 
  private SAMRecord getTopHit(SAMRecord read1, SAMRecord read2) {
    SAMRecord topHit = null;
   
    if (isTopHit(read1)) {
      topHit = read1;
    } else if (isTopHit(read2)) {
      topHit = read2;
View Full Code Here

TOP

Related Classes of net.sf.samtools.SAMRecord

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.