Package net.sf.samtools

Examples of net.sf.samtools.SAMRecord


    assertEquals(read1.getReadLength(), 292);
    assertEquals(read2.getReadLength(), 292);
  }
 
  private SAMRecord newRecord(int pos, String cigar, int length) {
    SAMRecord record = new SAMRecord(null);
    record.setReferenceName("chr21");
    record.setAlignmentStart(pos);
    record.setCigarString(cigar);
    record.setReadNegativeStrandFlag(false);
    char[] bases = new char[length];
    Arrays.fill(bases, 'A');
    record.setReadString(String.valueOf(bases));
    return record;
  }
View Full Code Here


public class SAMRecordUtilsTest {

  @Test (groups = "unit" )
  public void testRemoveSoftClips_withDeletionAndSoftClipAtEnd() {
    SAMRecord read = new SAMRecord(null);
   
    read.setReadName("TEST1");
    read.setCigarString("5M2D3M2S");
    read.setReadString("CCCCCCAGCC");
   
    SAMRecordUtils.removeSoftClips(read);
   
    Assert.assertEquals(read.getCigarString(), "5M2D3M");
    Assert.assertEquals(read.getReadString(), "CCCCCCAG");
  }
View Full Code Here

    Assert.assertEquals(read.getReadString(), "CCCCCCAG");
  }
 
  @Test (groups = "unit" )
  public void testRemoveSoftClips_withDeletionAndSoftClipAtStart() {
    SAMRecord read = new SAMRecord(null);
   
    read.setReadName("TEST1");
    read.setCigarString("2S5M2D3M");
    read.setReadString("CCCCCCAGCC");
   
    SAMRecordUtils.removeSoftClips(read);
   
    Assert.assertEquals(read.getCigarString(), "5M2D3M");
    Assert.assertEquals(read.getReadString(), "CCCCAGCC");
  }
View Full Code Here

    Cigar cigar2 = SAMRecordUtils.subset(cigar, 1, 198);
    Assert.assertEquals(cigar2.toString(), "99M100D99M");
  }
 
  private Cigar getCigar(String str) {
    SAMRecord read = new SAMRecord(null);
    read.setCigarString(str);
    return read.getCigar();
  }
View Full Code Here

    int maxRecords = 100000;
    int counter = 0;

    long writeNanos = 0;
    while (iterator.hasNext() && counter++ < maxRecords) {
      SAMRecord r = iterator.next();
      byte[] scores = r.getBaseQualities();
      long time1 = System.nanoTime();
      c.write(null, scores);
      writeNanos += System.nanoTime() - time1;
    }
    bos.close();
View Full Code Here

    int counter = 0;

    long writeNanos = 0;
    java.util.List<SAMRecord> records = new ArrayList<SAMRecord>(2*maxRecords) ;
    while (iterator.hasNext() && counter++ <= maxRecords) {
      SAMRecord r = iterator.next();
      records.add(r) ;
      byte[] scores = r.getBaseQualities();
      long time1 = System.nanoTime();
      c.write(null, scores);
      writeNanos += System.nanoTime() - time1;
    }
    bos.close();

    ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
    GZIPInputStream gis = new GZIPInputStream(bais);
    c = new ExternalByteArrayCodec(null, new BufferedInputStream(gis));

    long bases = 0;
    long readNanos = 0 ;
    for (counter = 0; counter < records.size(); counter++) {
      SAMRecord record = records.get(counter) ;
       
      long time4 = System.nanoTime();
      bases += c.read(null, record.getReadLength()).length;
      readNanos += System.nanoTime() - time4 ;
    }

    System.out.printf("ExternalByteArrayCodec: bases %d, %d ms, %d ms.\n", bases,
        (writeNanos) / 1000000, (readNanos) / 1000000);
View Full Code Here

      rec2.setInferredInsertSize(0);
    }
    // And if only one is mapped copy it's coordinate information to the
    // mate
    else {
      final SAMRecord mapped = rec1.getReadUnmappedFlag() ? rec2 : rec1;
      final SAMRecord unmapped = rec1.getReadUnmappedFlag() ? rec1 : rec2;

      mapped.setMateReferenceIndex(unmapped.getReferenceIndex());
      mapped.setMateAlignmentStart(unmapped.getAlignmentStart());
      mapped.setMateNegativeStrandFlag(unmapped
          .getReadNegativeStrandFlag());
      mapped.setMateUnmappedFlag(true);
      mapped.setInferredInsertSize(0);

      unmapped.setMateReferenceIndex(mapped.getReferenceIndex());
      unmapped.setMateAlignmentStart(mapped.getAlignmentStart());
      unmapped.setMateNegativeStrandFlag(mapped
          .getReadNegativeStrandFlag());
      unmapped.setMateUnmappedFlag(false);
      unmapped.setInferredInsertSize(0);
    }

    boolean firstIsFirst = rec1.getAlignmentStart() < rec2
        .getAlignmentStart();
    int insertSize = firstIsFirst ? SamPairUtil.computeInsertSize(rec1,
View Full Code Here

    SAMRecordIterator iterator = reader.iterator();

    Map<String, Out> map = new TreeMap<String, DecomposeBAM.Out>();
    long bases = 0;
    while (iterator.hasNext() && params.maxRecords-- > 0) {
      SAMRecord record = iterator.next();
      bases += record.getReadLength();

      put(map, "QNAME", record.getReadName());
      put(map, "FLAG", String.valueOf(record.getFlags()));
      put(map, "RNAME", record.getReferenceName());
      put(map, "POS", String.valueOf(record.getAlignmentStart()));
      put(map, "MAPQ", String.valueOf(record.getMappingQuality()));
      put(map, "CIGAR", record.getCigarString());
      put(map, "RNEXT", record.getMateReferenceName());
      put(map, "PNEXT", String.valueOf(record.getMateAlignmentStart()));
      put(map, "TLEN", String.valueOf(record.getInferredInsertSize()));
      put(map, "SEQ", record.getReadString());
      put(map, "QUAL", record.getBaseQualityString());

      for (SAMTagAndValue tv : record.getAttributes()) {
        writeTagValue(map, tv);
      }
    }

    close(map);
View Full Code Here

    long recordCounter = 0;

    while (it1.hasNext() && it2.hasNext()
        && discrepancies.size() < maxDiscrepandcies) {
      recordCounter++;
      SAMRecord record1 = it1.next();
      SAMRecord record2 = it2.next();

      compareRecords(record1, record2, recordCounter, discrepancies);
    }

    if (it1.hasNext() && !it2.hasNext()) {
View Full Code Here

        // check if the record ends before the query start:
        if (location != null && r.getAlignmentStart() < location.start)
          continue;

        time = System.nanoTime();
        SAMRecord s = c2sFactory.create(r);

        if (params.requiredFlags != 0
            && ((params.requiredFlags & s.getFlags()) == 0))
          continue;
        if (params.filteringFlags != 0
            && ((params.filteringFlags & s.getFlags()) != 0))
          continue;
        if (params.countOnly) {
          recordCount++;
          continue;
        }

        if (ref != null)
          Utils.calculateMdAndNmTags(s, ref, params.calculateMdTag,
              params.calculateNmTag);
        c2sTime += System.nanoTime() - time;
        samTime += System.nanoTime() - time;

        time = System.nanoTime();
        writer.addAlignment(s);
        sWriteTime += System.nanoTime() - time;
        writeTime += System.nanoTime() - time;
        if (params.outputFile == null && System.out.checkError())
          break;

        // we got all the reads for random access:
        if (location != null && location.end < s.getAlignmentStart()) {
          enough = true;
          break;
        }
      }
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.