@Test(dataProvider = "containersForRefTests") public void paramTest(final List<CramCompressionRecord> records, final Set<Integer> expectedKeys) { final ContainerFactory factory = new ContainerFactory(ContainerFactoryTest.getSAMFileHeaderForTests(), TEST_RECORD_COUNT); final Container container = factory.buildContainer(records); final ContainerParser parser = new ContainerParser(ContainerFactoryTest.getSAMFileHeaderForTests()); final Map<Integer, AlignmentSpan> referenceSet = parser.getReferences(container, ValidationStringency.STRICT); Assert.assertEquals(referenceSet.keySet(), expectedKeys); final List<CramCompressionRecord> roundTripRecords = parser.getRecords(container, null, ValidationStringency.STRICT); // TODO this fails. return to this when refactoring Container and CramCompressionRecord //Assert.assertEquals(roundTripRecords, records); Assert.assertEquals(roundTripRecords.size(), TEST_RECORD_COUNT); }
@Test(dataProvider = "eof") public void testEOF(final Version version) throws IOException { final ContainerParser parser = new ContainerParser(ContainerFactoryTest.getSAMFileHeaderForTests()); try (final ByteArrayOutputStream baos = new ByteArrayOutputStream()) { CramIO.issueEOF(version, baos); final Container container = ContainerIO.readContainer(version, new ByteArrayInputStream(baos.toByteArray())); Assert.assertTrue(container.isEOF()); Assert.assertTrue(parser.getRecords(container, null, ValidationStringency.STRICT).isEmpty()); } }
@Test public void testMultirefContainer() { final Map<Integer, AlignmentSpan> expectedSpans = new HashMap<>(); for (int i = 0; i < 10; i++) { expectedSpans.put(i, new AlignmentSpan(i + 1, 3, 1)); } final ContainerFactory factory = new ContainerFactory(ContainerFactoryTest.getSAMFileHeaderForTests(), TEST_RECORD_COUNT); final Container container = factory.buildContainer(ContainerFactoryTest.getMultiRefRecords()); final ContainerParser parser = new ContainerParser(ContainerFactoryTest.getSAMFileHeaderForTests()); final Map<Integer, AlignmentSpan> referenceSet = parser.getReferences(container, ValidationStringency.STRICT); Assert.assertEquals(referenceSet, expectedSpans); }
final SAMFileHeader samFileHeader = ContainerFactoryTest.getSAMFileHeaderForTests(); final ContainerParser parser = new ContainerParser(samFileHeader);
@Test public void multiRefWithUnmappedNoStart() { final ContainerFactory factory = new ContainerFactory(getSAMFileHeaderForTests(), 10); final List<CramCompressionRecord> records = new ArrayList<>(); for (int i = 0; i < 10; i++) { final CramCompressionRecord record = createMappedRecord(i); if (i % 2 == 0) { record.setSegmentUnmapped(true); record.alignmentStart = SAMRecord.NO_ALIGNMENT_START; } records.add(record); } final Container container = factory.buildContainer(records); assertContainerState(container, 10, Slice.MULTI_REFERENCE, Slice.NO_ALIGNMENT_START, Slice.NO_ALIGNMENT_SPAN); }
@Test public void testUnmappedNoReferenceId() { final ContainerFactory factory = new ContainerFactory(getSAMFileHeaderForTests(), 10); final Container container = factory.buildContainer(getUnmappedNoRefRecords()); assertContainerState(container, 10, SAMRecord.NO_ALIGNMENT_REFERENCE_INDEX, Slice.NO_ALIGNMENT_START, Slice.NO_ALIGNMENT_SPAN); }
@Test public void testMultiref() { final ContainerFactory factory = new ContainerFactory(getSAMFileHeaderForTests(), 10); final Container container = factory.buildContainer(getMultiRefRecords()); assertContainerState(container, 10, Slice.MULTI_REFERENCE, Slice.NO_ALIGNMENT_START, Slice.NO_ALIGNMENT_SPAN); }
@Test public void multiRefWithUnmappedNoRef() { final ContainerFactory factory = new ContainerFactory(getSAMFileHeaderForTests(), 10); final List<CramCompressionRecord> records = new ArrayList<>(); for (int i = 0; i < 10; i++) { final CramCompressionRecord record = createMappedRecord(i); if (i % 2 == 0) { record.setSegmentUnmapped(true); record.sequenceId = SAMRecord.NO_ALIGNMENT_REFERENCE_INDEX; } records.add(record); } final Container container = factory.buildContainer(records); assertContainerState(container, 10, Slice.MULTI_REFERENCE, Slice.NO_ALIGNMENT_START, Slice.NO_ALIGNMENT_SPAN); }
@Test public void testMapped() { final int recordCount = 10; final int sequenceId = 0; final int alignmentStart = 1; final int alignmentSpan = 12; final ContainerFactory factory = new ContainerFactory(getSAMFileHeaderForTests(), 10); final Container container = factory.buildContainer(getSingleRefRecords(recordCount)); assertContainerState(container, recordCount, sequenceId, alignmentStart, alignmentSpan); }
@Test public void testUnmappedNoAlignmentStart() { final ContainerFactory factory = new ContainerFactory(getSAMFileHeaderForTests(), 10); final Container container = factory.buildContainer(getUnmappedNoStartRecords()); assertContainerState(container, 10, SAMRecord.NO_ALIGNMENT_REFERENCE_INDEX, Slice.NO_ALIGNMENT_START, Slice.NO_ALIGNMENT_SPAN); }
@Test public void singleRefWithUnmappedNoRef() { final ContainerFactory factory = new ContainerFactory(getSAMFileHeaderForTests(), 10); final List<CramCompressionRecord> records = new ArrayList<>(); for (int i = 0; i < 10; i++) { final CramCompressionRecord record = createMappedRecord(i); if (i % 2 == 0) { record.setSegmentUnmapped(true); record.sequenceId = SAMRecord.NO_ALIGNMENT_REFERENCE_INDEX; } records.add(record); } final Container container = factory.buildContainer(records); assertContainerState(container, 10, Slice.MULTI_REFERENCE, Slice.NO_ALIGNMENT_START, Slice.NO_ALIGNMENT_SPAN); }
@Test public void singleRefWithUnmappedNoStart() { final ContainerFactory factory = new ContainerFactory(getSAMFileHeaderForTests(), 10); final List<CramCompressionRecord> records = new ArrayList<>(); for (int i = 0; i < 10; i++) { final CramCompressionRecord record = createMappedRecord(i); if (i % 2 == 0) { record.setSegmentUnmapped(true); record.alignmentStart = SAMRecord.NO_ALIGNMENT_START; } records.add(record); } final Container container = factory.buildContainer(records); assertContainerState(container, 10, Slice.MULTI_REFERENCE, Slice.NO_ALIGNMENT_START, Slice.NO_ALIGNMENT_SPAN); }
static List<Container> getMultiRefContainersForStateTest() { final ContainerFactory factory = new ContainerFactory(getSAMFileHeaderForTests(), 10); final List<Container> testContainers = new ArrayList<>(3); final List<CramCompressionRecord> records = new ArrayList<>(); final CramCompressionRecord record0 = createMappedRecord(0); record0.sequenceId = 0; records.add(record0); final Container container0 = factory.buildContainer(records); final CramCompressionRecord record1 = createMappedRecord(1); record1.sequenceId = 1; records.add(record1); final Container container1 = factory.buildContainer(records); final CramCompressionRecord unmapped = createMappedRecord(2); unmapped.alignmentStart = SAMRecord.NO_ALIGNMENT_START; unmapped.sequenceId = SAMRecord.NO_ALIGNMENT_REFERENCE_INDEX; unmapped.setSegmentUnmapped(true); records.add(unmapped); final Container container2 = factory.buildContainer(records); testContainers.add(container0); testContainers.add(container1); testContainers.add(container2); return testContainers; }