Package net.sf.samtools

Examples of net.sf.samtools.SAMRecord


        double mapQ = 0.0;
        double seqQ = 0.0;
        while (it.hasNext()) {
            SamLocusIterator.RecordAndOffset record = (SamLocusIterator.RecordAndOffset) it.next();
            seqQ += (int) record.getBaseQuality();
            SAMRecord sr = record.getRecord();
            mapQ += sr.getMappingQuality();
        }       
        setMeanMapQ(mapQ / (double) l.size());
        setMeanSeqQ(seqQ / (double) l.size());       
    }
View Full Code Here


    int altCount = 0;
    int refCount = 0;
   
    CloseableIterator<SAMRecord> iter = reader.queryOverlapping(locus.chromosome, locus.posStart, locus.posStop);
    while (iter.hasNext()) {
      SAMRecord read = iter.next();
      if (!read.getDuplicateReadFlag()) {
        depth += 1;
       
        Object[] baseAndQual = getBaseAndQualAtPosition(read, locus.posStart);
        Character base = (Character) baseAndQual[0];
        int baseQual = (Integer) baseAndQual[1];
View Full Code Here

  }

  @Override
  public SAMRecord next() {

    SAMRecord read = null;
    boolean isCacheUpToDate = false;
    if (!cache.isEmpty()) {
      InsertShiftSAMRecord first = cache.first();
      InsertShiftSAMRecord last = cache.last();
     
      // Don't seek too far ahead
      if (last.read.getAlignmentStart() > first.read.getAlignmentStart()+2 || !last.read.getReferenceName().equals(first.read.getReferenceName())) {
        isCacheUpToDate = true;
      }
     
      read = first.read;
    } else {
      read = iter.next();
      cache.add(new InsertShiftSAMRecord(read));
    }
   
    int cacheStart = read.getAlignmentStart() + 1;
    String cacheChromosome = read.getReferenceName();
   
    while (!isCacheUpToDate && iter.hasNext() && read.getAlignmentStart() <= cacheStart+1 && read.getReferenceName().equals(cacheChromosome)) {
      read = iter.next();
      cache.add(new InsertShiftSAMRecord(read));
    }
   
    return cache.pollFirst().read;
View Full Code Here

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

    }
   
    private List<SAMRecord> getNextReadList() {
      List<SAMRecord> reads = new ArrayList<SAMRecord>();
     
      SAMRecord read = null;
      String readName = null;
     
      if (hasMoreReads()) {
        read = getNextRead();
        readName = read.getReadName();
       
        reads.add(read);
       
        while (hasMoreReads() && read.getReadName().equals(readName)) {
          read = getNextRead();
         
          if (read.getReadName().equals(readName)) {
            reads.add(read);
          }
        }
       
        // If the last read doesn't have the same name, cache it
        if (!read.getReadName().equals(readName)) {
          cachedRead = read;
        }
      }
     
      return reads;
View Full Code Here

    int numBases = 0;
   
    CloseableIterator<SAMRecord> iter =  reader.queryOverlapping(chromosome, pos-readLength, pos+length+readLength);

    while (iter.hasNext()) {
      SAMRecord read = (SAMRecord) iter.next();
     
//      String yo = (String) read.getAttribute("YO");

//      if ((yo == null) || (!yo.equals("N/A"))) {
        numMismatches += c2r.noiseAroundIndel(read, indelType, pos, length);
       
        for (int qual : read.getBaseQualities()) {
  //        qual = qual - '!';
          if (qual >= minBaseQuality) {
            numBases += 1;
          }
        }
View Full Code Here

      long totalMapq = 0;
     
      CloseableIterator<SAMRecord> iter = reader.queryOverlapping(region.getSeqname(), (int) region.getStart(), (int) region.getEnd());
     
      while (iter.hasNext()) {
        SAMRecord read = iter.next();
       
        if (read.getMappingQuality() >= 10) {
          String qualStr = read.getBaseQualityString();
         
          boolean readLt5 = false;
          boolean readLt10 = false;
          boolean readLt20 = false;
          boolean readLt30 = false;
          boolean internalReadLt20 = false;
         
          numReads++;
          numBases += qualStr.length();
          int readBasesLt5 = 0;
 
          for (int i=0; i<qualStr.length(); i++) {
           
            // Assuming phred33
            int qual = qualStr.charAt(i) - '!';
            totalQuality += qual;
           
            if (qual < 5) {
              numBasesLt5++;
              readBasesLt5++;
              readLt5 = true;
            }
           
            if (qual < 10) {
              numBasesLt10++;
              readLt10 = true;
            }
           
            if (qual < 20) {
              numBasesLt20++;
              readLt20 = true;
             
              if ((i>=10) && (i<90)) {
                internalReadLt20 = true;
              }
            }
           
            if (qual < 30) {
              readLt30 = true;
            }
          }
         
          if (readLt5) {
            numReadsLt5++;
          }
         
          if (readLt10) {
            numReadsLt10++;
          }
         
          if (readLt20) {
            numReadsLt20++;
          }
         
          if (readLt30) {
            numReadsLt30++;
          }
         
          if (readBasesLt5 >= 10) {
            numReads5X10++;
          }
         
          if (internalReadLt20 == true) {
            numInternalReadsLt20++;
          }
         
          if (read.getReadString().contains("N")) {
            numReadsWithAmbiguousBases++;
          }
         
          if (readLt20 || read.getReadString().contains("N")) {
            numReadsIntersectLt20Ambiguous++;
          }
         
          if (read.getMappingQuality() < minMapq) {
            minMapq = read.getMappingQuality();
          }
         
          totalMapq += read.getMappingQuality();
        }
      }
     
      iter.close();
     
View Full Code Here

      int[] counts = new int[thresholds.length];
      System.err.println(region.getDescriptor());
      Iterator<SAMRecord> iter = reader.queryOverlapping(region.getSeqname(), (int) region.getStart(), (int) region.getEnd());
      while (iter.hasNext()) {
        SAMRecord read = iter.next();
        if (!read.getReadUnmappedFlag()) {
          for (int i=0; i<thresholds.length; i++) {
            if (read.getMappingQuality() <= thresholds[i]) {
              counts[i] += 1;
            }
          }
        }
      }
View Full Code Here

            (reads2.size() > 0 ? reads2.get(0).getReadName() : "null");
        System.out.println(msg);
//        throw new RuntimeException(msg);
      }
     
      SAMRecord read1 = null;
      SAMRecord read2 = null;
     
      if (reads1.size() >= 1) {
        read1 = reads1.get(0);
      }
     
View Full Code Here

       
        List<SAMRecord> reads1 = new ArrayList<SAMRecord>();
        List<SAMRecord> reads2 = new ArrayList<SAMRecord>();
       
        // Get the list of records for the first read
        SAMRecord read = getNextRead();
        if (read != null) {
            String baseName = getBaseName(read);
           
            while ((read != null) && (baseName.equals(getBaseName(read)))) {
                if ((read.getReadPairedFlag()) && (read.getFirstOfPairFlag())) {
                    reads1.add(read);
                } else if ((read.getReadPairedFlag()) && (read.getSecondOfPairFlag())) {
                    reads2.add(read);
                } else {
//                    System.out.println("Unpaired read: " + read);
                }
               
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.