Package net.sf.samtools

Examples of net.sf.samtools.SAMRecord


    private boolean hasMoreReads() {
        return cachedRead != null || iter.hasNext();
    }
   
    private SAMRecord getNextRead() {
        SAMRecord next = null;
       
        if (cachedRead != null) {
            next = cachedRead;
            cachedRead = null;
        } else {
View Full Code Here


     
      Iterator<SAMRecord> iter = reader.iterator();
     
      int cnt = 0;
      while ((iter.hasNext()) && (cnt < 1000000)) {
        SAMRecord read = iter.next();
        this.readLength = Math.max(this.readLength, read.getReadLength());
        this.maxMapq = Math.max(this.maxMapq, read.getMappingQuality());
       
        // Assumes aligner sets proper pair flag correctly
        if ((isPairedEnd) && (read.getReadPairedFlag()) && (read.getProperPairFlag())) {
          this.minInsertLength = Math.min(this.minInsertLength, Math.abs(read.getInferredInsertSize()));
          this.maxInsertLength = Math.max(this.maxInsertLength, Math.abs(read.getInferredInsertSize()));
        }
      }
     
      // Allow some fudge in insert length
      minInsertLength = Math.max(minInsertLength - 2*readLength, 0);
View Full Code Here

      SAMRecord read, String matchingString) {
    List<HitInfo> bestHits = new ArrayList<HitInfo>();

    contigReadStr = contigReadStr.substring(contigReadStr.indexOf('~')+1);
    contigReadStr = contigReadStr.replace('~', '\t');
    SAMRecord contigRead = samStringReader.getRead(contigReadStr);
   
    int bestMismatches = SAMRecordUtils.getIntAttribute(read, "XM");
   
    // Filter this hit if it aligns past the end of the contig
    // Must use cigar length instead of read length, because the
    // the contig read bases are not loaded.
    if (read.getAlignmentEnd() <= contigRead.getCigar().getReadLength()) {
      HitInfo hit = new HitInfo(contigRead, read.getAlignmentStart(),
          read.getReadNegativeStrandFlag() ? '-' : '+', bestMismatches);
     
      bestHits.add(hit);
    }
   
    int numBestHits = SAMRecordUtils.getIntAttribute(read, "X0");
    int numSubOptimalHits = SAMRecordUtils.getIntAttribute(read, "X1");
   
    int totalHits = numBestHits + numSubOptimalHits;
   
    if ((totalHits > 1) && (totalHits < 1000)) {
     
      // Look in XA tag.
      String alternateHitsStr = (String) read.getAttribute("XA");
      if (alternateHitsStr == null) {
        String msg = "best hits = " + numBestHits + ", but no XA entry for: " + read.getSAMString();
        System.out.println(msg);             
      } else {
       
        String[] alternates = alternateHitsStr.split(";");
       
        for (int i=0; i<alternates.length-1; i++) {
          String[] altInfo = alternates[i].split(",");
          String altContigReadStr = altInfo[0];
          char strand = altInfo[1].charAt(0);
          int position = Integer.parseInt(altInfo[1].substring(1));
          String cigar = altInfo[2];
          int mismatches = Integer.parseInt(altInfo[3]);
         
          if ((cigar.equals(matchingString)) && (mismatches < bestMismatches)) {
            System.out.println("MISMATCH_ISSUE: " + read.getSAMString());
          }
         
          if ((cigar.equals(matchingString)) && (mismatches == bestMismatches)) {
            altContigReadStr = altContigReadStr.substring(altContigReadStr.indexOf('~')+1);
            altContigReadStr = altContigReadStr.replace('~', '\t');
            contigRead = samStringReader.getRead(altContigReadStr);
           
            // Filter this hit if it aligns past the end of the contig
            // Must use cigar length instead of read length, because the
            // the contig read bases are not loaded.
            if ((position + read.getReadLength()) <= contigRead.getCigar().getReadLength()) {
              HitInfo hit = new HitInfo(contigRead, position, strand, mismatches);
              bestHits.add(hit);
            }
          }
        }
View Full Code Here

  }
 
  private SAMRecord updateReadAlignment(SAMRecord contigRead,
      List<ReadBlock> contigReadBlocks, ReadPosition orig) {
    List<ReadBlock> blocks = new ArrayList<ReadBlock>();
    SAMRecord read = SAMRecordUtils.cloneRead(orig.getRead());

    read.setReferenceName(contigRead.getReferenceName());

    int contigPosition = orig.getPosition();
    int accumulatedLength = 0;

    // read block positions are one based
    // ReadPosition is zero based
   
    int totalInsertLength = 0;

    for (ReadBlock contigBlock : contigReadBlocks) {
      if ((contigBlock.getReadStart() + contigBlock.getReferenceLength()) >= orig
          .getPosition() + 1) {
        ReadBlock block = contigBlock.getSubBlock(accumulatedLength,
            contigPosition, read.getReadLength()
                - accumulatedLength);
       
        block.setReferenceStart(block.getReferenceStart() - totalInsertLength);
       
        // If this is an insert, we need to adjust the alignment start
        if ((block.getType() == CigarOperator.I) && (block.getLength() != 0)) {
          contigPosition = contigPosition - (contigBlock.getLength() - block.getLength());
          block.setReferenceStart(block.getReferenceStart() - (contigBlock.getLength() - block.getLength()));
//          block = contigBlock.getSubBlock(accumulatedLength,
//                contigPosition, read.getReadLength()
//                - accumulatedLength);
         
          totalInsertLength += block.getLength();
        }
       
        //TODO: Drop leading and trailing delete blocks

        // TODO: Investigate how this could happen
        if (block.getLength() != 0) {
          blocks.add(block);

          if (block.getType() != CigarOperator.D) {
            accumulatedLength += block.getLength();
          }

          if (accumulatedLength > read.getReadLength()) {
            throw new IllegalStateException("Accumulated Length: "
                + accumulatedLength
                + " is greater than read length: "
                + read.getReadLength());
          }

          if (accumulatedLength == read.getReadLength()) {
            break;
          }
        }
      }
    }

    if (blocks.size() > 0) {
     
      // If we've aligned past the end of the contig resulting in a short Cigar
      // length, append additonal M to the Cigar     
      ReadBlock.fillToLength(blocks, read.getReadLength());
      int newAlignmentStart = blocks.get(0).getReferenceStart();
      String newCigar = ReadBlock.toCigarString(blocks);

      read.setCigarString(newCigar);
      read.setAlignmentStart(newAlignmentStart);
    } else {
      // TODO: Investigate how this could happen.
      read = null;
    }
View Full Code Here

        realignCount += 1;
      }
      addAlignment(reads.getUpdatedRead());
      updatedCount += 1;
    } else {
      SAMRecord orig = reads.getOrigRead();
      addAlignment(orig);
      origCount += 1;
    }
  }
View Full Code Here

  private void processCandidates() {
    System.out.println("Processing candidates");
    SimpleSamReadPairReader reader = new SimpleSamReadPairReader(candidatesSam);
   
    for (ReadPair pair : reader) {
      SAMRecord updatedRead1 = pair.getRead1();
      SAMRecord updatedRead2 = pair.getRead2();
      SAMRecord origRead1 = getOriginalRead(updatedRead1);
      SAMRecord origRead2 = getOriginalRead(updatedRead2);
     
      if ((updatedRead1 !=  null) && (updatedRead2 != null)) {
        Reads reads1 = new Reads(updatedRead1, origRead1);
        Reads reads2 = new Reads(updatedRead2, origRead2);
       
View Full Code Here

    }
    System.out.println("Done processing candidates");
  }
 
  private SAMRecord getOriginalRead(SAMRecord read) {
    SAMRecord orig = null;
   
    if (read != null) {
      String origStr = (String) read.getAttribute("YG");
      orig = samStringReader.getRead(origStr);
      read.setAttribute("YG", null);
View Full Code Here

    SAMFileReader reader = new SAMFileReader(new File(input));
    reader.setValidationStringency(ValidationStringency.SILENT);
   
    int prevMaxEnd = -1;
   
    SAMRecord lastRead = null;

    for (SAMRecord read : reader) {
      if (read.getMappingQuality() > 0) {
        if (lastRead == null || !lastRead.getReferenceName().equals(read.getReferenceName()) || (read.getAlignmentStart()-prevMaxEnd) < MAX_READ_GAP) {
          currReads.add(read);
        } else {
//          processReads(currReads);
          spawnProcessingThread(currReads);
          currReads = new ArrayList<SAMRecord>();
          currReads.add(read);
        }
       
        if (read.getAlignmentEnd() > prevMaxEnd || !lastRead.getReferenceName().equals(read.getReferenceName())) {
          prevMaxEnd = read.getAlignmentEnd();
        }
       
        lastRead = read;
      }
View Full Code Here

 
  private void filterNbases(List<SAMRecord> reads) {
    Iterator<SAMRecord> iter = reads.iterator();
   
    while (iter.hasNext()) {
      SAMRecord read = iter.next();
      if (read.getReadString().contains("N")) {
        iter.remove();
      }
    }
   
  }
View Full Code Here

  public RnaRegionHandler(ThreadManager threadManager, RnaPoc poc, List<SAMRecord> reads) {
    super(threadManager);
    this.poc = poc;
    this.reads = reads;
    SAMRecord first = reads.get(0);
    SAMRecord last = reads.get(reads.size()-1);
    // NOTE: No guarantee that the last read's alignment end is really the end of the region.
    // Calculating this requires iterating over entire region.
    id = "thread: " + first.getReferenceName() + "_" + first.getAlignmentStart() + "_" + last.getAlignmentEnd() + " reads: " + reads.size();
  }
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.