public SAMRecord next() { if (this.hasNext()) { currentRecord += 1; return i.next(); } else { throw new NoSuchElementException(); } }
public Alignment readElem() { Alignment alignment = null; SAMRecord record = null; if(iterator.hasNext()){ record = iterator.next(); alignment = AlignmentConverter.buildAlignment(record); } return alignment; }
public SAMRecord read() { while(iterator.hasNext()) { SAMRecord record = iterator.next(); if (filter != 0 && (record.getFlags() & filter) != 0) { continue; } return record; } return null; }
@Override public boolean nextKeyValue() { if (!iterator.hasNext()) return false; final SAMRecord r = iterator.next(); key.set(BAMRecordReader.getKey(r)); record.set(r); return true; } }
@Override public boolean nextKeyValue() { if (!iterator.hasNext()) return false; final SAMRecord r = iterator.next(); key.set(BAMRecordReader.getKey(r)); record.set(r); return true; } }
@Test(expectedExceptions = SAMException.class) public void throwOnRecordValidationFailure() { try (SAMRecordIterator cramIteratorOverInvalidRecords = getCramFileIterator(ValidationStringency.STRICT)) { while (cramIteratorOverInvalidRecords.hasNext()) { cramIteratorOverInvalidRecords.next(); } } }
private int countRecords(final SamReader reader) { int count = 0; try (final SAMRecordIterator iter = reader.iterator()) { while (iter.hasNext()) { iter.next(); count++; } } return count; }
@Test(dataProvider = "sortsFailCramWithoutIndex", expectedExceptions = IllegalStateException.class) public void testCramSortFail(String file, String fileReference, SAMFileHeader.SortOrder order) throws Exception { final CRAMFileReader cramFileReader = getCramFileReader(file, fileReference); final SAMRecordIterator samRecordIterator = cramFileReader.getIterator().assertSorted(order); Assert.assertTrue(samRecordIterator.hasNext()); while (samRecordIterator.hasNext()) { Assert.assertNotNull(samRecordIterator.next()); } }
@Test(dataProvider = "sortsCramWithoutIndex") public void testCramSort(String file, String fileReference, SAMFileHeader.SortOrder order) throws Exception { final CRAMFileReader cramFileReader = getCramFileReader(file, fileReference); final SAMRecordIterator samRecordIterator = cramFileReader.getIterator().assertSorted(order); Assert.assertTrue(samRecordIterator.hasNext()); while (samRecordIterator.hasNext()) { Assert.assertNotNull(samRecordIterator.next()); } }
@Test public void testGoodSamStrict() throws IOException { final SamReaderFactory factory = SamReaderFactory.makeDefault().validationStringency(ValidationStringency.STRICT); Assert.assertEquals(0, ((Number) factory.open(createSamForIntAttr(0)).iterator().next().getAttribute("UI")).intValue()); Assert.assertEquals(-1, ((Number) factory.open(createSamForIntAttr(-1)).iterator().next().getAttribute("UI")).intValue()); Assert.assertEquals(Integer.MIN_VALUE, ((Number) factory.open(createSamForIntAttr(Integer.MIN_VALUE)).iterator().next().getAttribute("UI")).intValue()); Assert.assertEquals(Integer.MAX_VALUE, ((Number) factory.open(createSamForIntAttr(Integer.MAX_VALUE)).iterator().next().getAttribute("UI")).intValue()); Assert.assertEquals(1L + (long) Integer.MAX_VALUE, ((Number) factory.open(createSamForIntAttr(1L + (long) Integer.MAX_VALUE)).iterator().next().getAttribute("UI")).longValue()); Assert.assertEquals(BinaryCodec.MAX_UINT, ((Number) factory.open(createSamForIntAttr(BinaryCodec.MAX_UINT)).iterator().next().getAttribute("UI")).longValue()); }
@Test public void testCramIteratorWithoutCallingHasNextFirst() throws IOException { final SAMRecordSetBuilder builder = new SAMRecordSetBuilder(false, SAMFileHeader.SortOrder.unsorted); builder.addFrag("1", 0, 2, false); final CRAMFileReader reader = CRAMTestUtils.writeAndReadFromInMemoryCram(builder); final SAMRecordIterator iterator = reader.getIterator(); Assert.assertNotNull(iterator.next()); Assert.assertThrows(NoSuchElementException.class, iterator::next); } }
@Test public void testCigarOverflow() throws Exception { final SamReader reader = SamReaderFactory.makeDefault().validationStringency(ValidationStringency.LENIENT).open(new File(TEST_DATA_DIR, "BAMCigarOverflowTest/CigarOverflowTest.bam")); //Load the single read from the BAM file. final SAMRecord testBAMRecord = reader.iterator().next(); CloserUtil.close(reader); //The BAM file that exposed the bug triggered a SAM validation error because the bin field of the BAM record did not equal the computed value. Here we test for this error. //Cast to int to avoid an ambiguity in the assertEquals() call between assertEquals(int,int) and assertEquals(Object,Object). assertEquals(testBAMRecord.computeIndexingBin(), 0); } }
@Test(expectedExceptions = IllegalStateException.class) public void testSortsDisagree() throws Exception { SAMRecordIterator it = SamReaderFactory.makeDefault().open(new File(COORDINATE_SORTED_FILE)).iterator(); try { it.assertSorted(SAMFileHeader.SortOrder.queryname); while (it.hasNext()) { it.next(); } Assert.fail("Queryname assertion should have failed on coordinate sorted file but didn't"); } finally { it.close(); } }
@Test(dataProvider = "serializationTestData") public void testSAMRecordSerialization( final File inputFile ) throws Exception { final SamReader reader = SamReaderFactory.makeDefault().open(inputFile); final SAMRecord initialSAMRecord = reader.iterator().next(); reader.close(); final SAMRecord deserializedSAMRecord = TestUtil.serializeAndDeserialize(initialSAMRecord); Assert.assertEquals(deserializedSAMRecord, initialSAMRecord, "Deserialized SAMRecord not equal to original SAMRecord"); }
private int countRecordsInQueryInterval(final SamReader reader, final QueryInterval query) { final SAMRecordIterator iter = reader.queryOverlapping(new QueryInterval[]{query}); int count = 0; while (iter.hasNext()) { iter.next(); count++; } iter.close(); return count; }
@Test(dataProvider = "validSorts") public void testSortAssertionValid(String file, SAMFileHeader.SortOrder order) { SAMRecordIterator it = SamReaderFactory.makeDefault().open(new File(file)).iterator(); try { it.assertSorted(order); while (it.hasNext()) { it.next(); } } finally { it.close(); } }
@Test(dataProvider = "serializationTestData") public void testNullHeaderSerialization(final File inputFile) throws Exception { final SamReader reader = SamReaderFactory.makeDefault().open(inputFile); final SAMRecord initialSAMRecord = reader.iterator().next(); reader.close(); initialSAMRecord.setHeader(null); final SAMRecord deserializedSAMRecord = TestUtil.serializeAndDeserialize(initialSAMRecord); Assert.assertEquals(deserializedSAMRecord, initialSAMRecord, "Deserialized SAMRecord not equal to original SAMRecord"); }
@Test(expectedExceptions = SAMException.class) public void testBadSamStrict() throws IOException { final SamReader reader = SamReaderFactory.makeDefault().validationStringency(ValidationStringency.STRICT).open(createSamForIntAttr(BinaryCodec.MAX_UINT + 1L)); reader.iterator().next(); }
@Test public void testBadSamSilent() throws IOException { final SamReader reader = SamReaderFactory.makeDefault().validationStringency(ValidationStringency.SILENT).open(createSamForIntAttr(BinaryCodec.MAX_UINT + 1L)); reader.iterator().next(); }
private void validateUq(final File input, final File reference) { final SamReader reader = SamReaderFactory.makeDefault().referenceSequence(reference).open(input); final SAMRecordIterator iterator = reader.iterator(); while (iterator.hasNext()){ SAMRecord rec = iterator.next(); if (!rec.getReadUnmappedFlag()) Assert.assertNotNull(rec.getAttribute("UQ")); } }