Ejemplo n.º 1
0
  private List<String> getReferenceNames(final URL bamFile) throws IOException {

    final SamReader reader =
        SamReaderFactory.makeDefault().open(SamInputResource.of(bamFile.openStream()));

    final List<String> result = new ArrayList<String>();
    final List<SAMSequenceRecord> seqRecords =
        reader.getFileHeader().getSequenceDictionary().getSequences();
    for (final SAMSequenceRecord seqRecord : seqRecords) {
      if (seqRecord.getSequenceName() != null) {
        result.add(seqRecord.getSequenceName());
      }
    }
    reader.close();
    return result;
  }
Ejemplo n.º 2
0
  private void runLocalRemoteTest(
      final URL bamURL,
      final File bamFile,
      final String sequence,
      final int startPos,
      final int endPos,
      final boolean contained) {
    verbose("Testing query " + sequence + ":" + startPos + "-" + endPos + " ...");
    final SamReader reader1 =
        SamReaderFactory.makeDefault()
            .disable(SamReaderFactory.Option.EAGERLY_DECODE)
            .open(SamInputResource.of(bamFile).index(BAM_INDEX_FILE));
    final SamReader reader2 =
        SamReaderFactory.makeDefault()
            .disable(SamReaderFactory.Option.EAGERLY_DECODE)
            .open(SamInputResource.of(bamURL).index(BAM_INDEX_FILE));
    final Iterator<SAMRecord> iter1 = reader1.query(sequence, startPos, endPos, contained);
    final Iterator<SAMRecord> iter2 = reader2.query(sequence, startPos, endPos, contained);

    final List<SAMRecord> records1 = new ArrayList<SAMRecord>();
    final List<SAMRecord> records2 = new ArrayList<SAMRecord>();

    while (iter1.hasNext()) {
      records1.add(iter1.next());
    }
    while (iter2.hasNext()) {
      records2.add(iter2.next());
    }

    assertTrue(records1.size() > 0);
    assertEquals(records1.size(), records2.size());
    for (int i = 0; i < records1.size(); i++) {
      // System.out.println(records1.get(i).format());
      assertEquals(records1.get(i).getSAMString(), records2.get(i).getSAMString());
    }
  }
Ejemplo n.º 3
0
 private int runQueryTest(
     final URL bamURL,
     final String sequence,
     final int startPos,
     final int endPos,
     final boolean contained) {
   verbose("Testing query " + sequence + ":" + startPos + "-" + endPos + " ...");
   final SamReader reader1 =
       SamReaderFactory.makeDefault()
           .disable(SamReaderFactory.Option.EAGERLY_DECODE)
           .open(SamInputResource.of(bamURL).index(BAM_INDEX_FILE));
   final SamReader reader2 =
       SamReaderFactory.makeDefault()
           .disable(SamReaderFactory.Option.EAGERLY_DECODE)
           .open(SamInputResource.of(bamURL).index(BAM_INDEX_FILE));
   final Iterator<SAMRecord> iter1 = reader1.query(sequence, startPos, endPos, contained);
   final Iterator<SAMRecord> iter2 = reader2.iterator();
   // Compare ordered iterators.
   // Confirm that iter1 is a subset of iter2 that properly filters.
   SAMRecord record1 = null;
   SAMRecord record2 = null;
   int count1 = 0;
   int count2 = 0;
   int beforeCount = 0;
   int afterCount = 0;
   while (true) {
     if (record1 == null && iter1.hasNext()) {
       record1 = iter1.next();
       count1++;
     }
     if (record2 == null && iter2.hasNext()) {
       record2 = iter2.next();
       count2++;
     }
     // System.out.println("Iteration:");
     // System.out.println(" Record1 = " + ((record1 == null) ? "null" : record1.format()));
     // System.out.println(" Record2 = " + ((record2 == null) ? "null" : record2.format()));
     if (record1 == null && record2 == null) {
       break;
     }
     if (record1 == null) {
       checkPassesFilter(false, record2, sequence, startPos, endPos, contained);
       record2 = null;
       afterCount++;
       continue;
     }
     assertNotNull(record2);
     final int ordering = compareCoordinates(record1, record2);
     if (ordering > 0) {
       checkPassesFilter(false, record2, sequence, startPos, endPos, contained);
       record2 = null;
       beforeCount++;
       continue;
     }
     assertTrue(ordering == 0);
     checkPassesFilter(true, record1, sequence, startPos, endPos, contained);
     checkPassesFilter(true, record2, sequence, startPos, endPos, contained);
     assertEquals(record1.getReadName(), record2.getReadName());
     assertEquals(record1.getReadString(), record2.getReadString());
     record1 = null;
     record2 = null;
   }
   CloserUtil.close(reader1);
   CloserUtil.close(reader2);
   verbose("Checked " + count1 + " records against " + count2 + " records.");
   verbose("Found " + (count2 - beforeCount - afterCount) + " records matching.");
   verbose("Found " + beforeCount + " records before.");
   verbose("Found " + afterCount + " records after.");
   return count1;
 }