@Override public SAMRecordIterator queryUnmapped() { return new AssertingIterator(this.reader.queryUnmapped()); }
private void processUnmapped(SAMFileWriter output, String inputBam) throws IOException { Logger.debug("Processing unmapped reads..."); SamReader reader = SAMRecordUtils.getSamReader(inputBam); // This should give us only read pairs with both ends unmapped Iterator<SAMRecord> iter = reader.queryUnmapped(); while (iter.hasNext()) { SAMRecord read = iter.next(); output.addAlignment(read); } reader.close(); }
@Test(dataProvider="unmappedQueries") public void testQueryUnmapped( final File cramFileName, final File referenceFileName, final String[] expectedNames) throws IOException { doQueryTest( reader -> reader.queryUnmapped(), cramFileName, referenceFileName, expectedNames ); }
void openFile() throws IOException { LOG.info("Processing shard " + shard); final SamReader reader = BAMIO.openBAM(storageClient, shard.file, options.getStringency()); iterator = null; if (reader.hasIndex() && reader.indexing() != null) { if (filter == Filter.UNMAPPED_ONLY) { LOG.info("Processing unmapped"); iterator = reader.queryUnmapped(); } else if (shard.span != null) { LOG.info("Processing span for " + shard.contig); iterator = reader.indexing().iterator(shard.span); } else if (shard.contig.referenceName != null && !shard.contig.referenceName.isEmpty()) { LOG.info("Processing all bases for " + shard.contig); iterator = reader.query(shard.contig.referenceName, (int) shard.contig.start, (int) shard.contig.end, false); } } if (iterator == null) { LOG.info("Processing all reads"); iterator = reader.iterator(); } }
void openFile() throws IOException { LOG.info("Processing shard " + shard); final SamReader reader = BAMIO.openBAM(storageClient, shard.file, options.getStringency()); iterator = null; if (reader.hasIndex() && reader.indexing() != null) { if (filter == Filter.UNMAPPED_ONLY) { LOG.info("Processing unmapped"); iterator = reader.queryUnmapped(); } else if (shard.span != null) { LOG.info("Processing span for " + shard.contig); iterator = reader.indexing().iterator(shard.span); } else if (shard.contig.referenceName != null && !shard.contig.referenceName.isEmpty()) { LOG.info("Processing all bases for " + shard.contig); iterator = reader.query(shard.contig.referenceName, (int) shard.contig.start, (int) shard.contig.end, false); } } if (iterator == null) { LOG.info("Processing all reads"); iterator = reader.iterator(); } }
@Test(dataProvider = "dataProvider") public void testQueryUnmappedEmptyBam(final String bam) throws Exception { final SamReader reader = SamReaderFactory.makeDefault().open(new File(TEST_DATA_DIR, bam)); final CloseableIterator<SAMRecord> it = reader.queryUnmapped(); int numRecords = 0; while (it.hasNext()) { it.next(); ++numRecords; } Assert.assertEquals(numRecords, 0); CloserUtil.close(reader); }
@Test(dataProvider = "testUnmappedCounts") public void testUnmappedCounts(String acc, int expectedNumUnmapped) { SamReader reader = SamReaderFactory.make().validationStringency(ValidationStringency.SILENT).open( SamInputResource.of(new SRAAccession(acc)) ); final SAMRecordIterator samRecordIterator = reader.queryUnmapped(); assertCorrectCountsOfMappedAndUnmappedRecords(samRecordIterator, 0, expectedNumUnmapped); }
@Test(dataProvider = "unmappedSliceTest") public void testUnmappedMultiSlice( final File cramFileName, final File referenceFileName, final int expectedCount) throws IOException { SamReaderFactory factory = SamReaderFactory.makeDefault().validationStringency(ValidationStringency.SILENT); factory = factory.referenceSequence(referenceFileName); int count = 0; try (final SamReader reader = factory.open(cramFileName); final CloseableIterator<SAMRecord> it = reader.queryUnmapped()) { while (it.hasNext()) { it.next(); count++; } } Assert.assertEquals(count, expectedCount); }
@Test public void testQueryUnmapped() throws IOException { try (final SamReader samReader = SamReaderFactory.makeDefault().open(BAM_FILE); final SAMRecordIterator unmappedSamIterator = samReader.queryUnmapped()) { CRAMFileReader reader = new CRAMFileReader( new ByteArraySeekableStream(cramBytes), new ByteArraySeekableStream(craiBytes), source, ValidationStringency.STRICT); int counter = 0; CloseableIterator<SAMRecord> unmappedCramIterator = reader.queryUnmapped(); while (unmappedSamIterator.hasNext()) { Assert.assertTrue(unmappedCramIterator.hasNext()); SAMRecord r1 = unmappedSamIterator.next(); SAMRecord r2 = unmappedCramIterator.next(); Assert.assertEquals(r1.getReadName(), r2.getReadName()); Assert.assertEquals(r1.getBaseQualityString(), r2.getBaseQualityString()); counter++; } Assert.assertFalse(unmappedCramIterator.hasNext()); Assert.assertEquals(counter, nofUnmappedReads); } }
@Test public void scanAllUnmappedReads() throws IOException { SamReader samReader = SamReaderFactory.makeDefault().open(BAM_FILE); CRAMFileReader reader = new CRAMFileReader(new ByteArraySeekableStream(cramBytes), new ByteArraySeekableStream(baiBytes), source, ValidationStringency.SILENT); reader.setValidationStringency(ValidationStringency.SILENT); int counter = 0; SAMRecordIterator unmappedSamIterator = samReader.queryUnmapped(); CloseableIterator<SAMRecord> unmappedCramIterator = reader.queryUnmapped(); while (unmappedSamIterator.hasNext()) { Assert.assertTrue(unmappedCramIterator.hasNext()); SAMRecord r1 = unmappedSamIterator.next(); SAMRecord r2 = unmappedCramIterator.next(); Assert.assertEquals(r1.getReadName(), r2.getReadName()); Assert.assertEquals(r1.getBaseQualityString(), r2.getBaseQualityString()); counter++; } Assert.assertFalse(unmappedCramIterator.hasNext()); Assert.assertEquals(counter, nofUnmappedReads); reader.close(); }
final CloseableIterator<SAMRecord> it = reader.queryUnmapped(); rec = null; while (it.hasNext()) {
linearScan.stop(); queryUnmapped.start(); it = reader.queryUnmapped(); int unmappedCountFromQueryUnmapped = 0; while (it.hasNext()) {
writeReads(out, in.queryUnmapped(), newOrder, "unmapped");
writeReads(out, in.queryUnmapped(), newOrder, "unmapped");