Container buildContainer(final List<CramCompressionRecord> records, final SubstitutionMatrix substitutionMatrix) { // sets header APDelta final boolean coordinateSorted = samFileHeader.getSortOrder() == SAMFileHeader.SortOrder.coordinate; final CompressionHeader header = new CompressionHeaderFactory().build(records, substitutionMatrix, coordinateSorted); header.readNamesIncluded = preserveReadNames; final List<Slice> slices = new ArrayList<>(); final Container container = new Container(); container.header = header; container.nofRecords = records.size(); container.globalRecordCounter = globalRecordCounter; container.bases = 0; container.blockCount = 0; long lastGlobalRecordCounter = container.globalRecordCounter; for (int i = 0; i < records.size(); i += recordsPerSlice) { final List<CramCompressionRecord> sliceRecords = records.subList(i, Math.min(records.size(), i + recordsPerSlice)); final Slice slice = Slice.buildSlice(sliceRecords, header); slice.globalRecordCounter = lastGlobalRecordCounter; lastGlobalRecordCounter += slice.nofRecords; container.bases += slice.bases; slices.add(slice); } container.finalizeContainerState(slices.toArray(new Slice[0])); globalRecordCounter += records.size(); return container; }
Container buildContainer(final List<CramCompressionRecord> records, final SubstitutionMatrix substitutionMatrix) { // sets header APDelta final boolean coordinateSorted = samFileHeader.getSortOrder() == SAMFileHeader.SortOrder.coordinate; final CompressionHeader header = new CompressionHeaderFactory().build(records, substitutionMatrix, coordinateSorted); header.readNamesIncluded = preserveReadNames; final List<Slice> slices = new ArrayList<Slice>(); final Container container = new Container(); container.header = header; container.nofRecords = records.size(); container.globalRecordCounter = globalRecordCounter; container.bases = 0; container.blockCount = 0; long lastGlobalRecordCounter = container.globalRecordCounter; for (int i = 0; i < records.size(); i += recordsPerSlice) { final List<CramCompressionRecord> sliceRecords = records.subList(i, Math.min(records.size(), i + recordsPerSlice)); final Slice slice = buildSlice(sliceRecords, header); slice.globalRecordCounter = lastGlobalRecordCounter; lastGlobalRecordCounter += slice.nofRecords; container.bases += slice.bases; slices.add(slice); // assuming one sequence per container max: if (container.sequenceId == -1 && slice.sequenceId != -1)
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; }
@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 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); }
@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 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 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 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); }
final Container container = cramContext.containerFactory.buildContainer(cramRecords);
records.add(createRecord(2, 1, 3)); final Container container1 = containerFactory.buildContainer(records); Assert.assertNotNull(container1); Assert.assertEquals(container1.nofRecords, records.size()); records.add(createRecord(4, 2, 3)); records.add(createRecord(5, 2, 4)); final Container container2 = containerFactory.buildContainer(records); Assert.assertNotNull(container2); Assert.assertEquals(container2.nofRecords, records.size());
final Container container = containerFactory.buildContainer(cramRecords); for (final Slice slice : container.slices) { slice.setRefMD5(refs);
final Container container = containerFactory.buildContainer(cramRecords); for (final Slice slice : container.slices) { slice.setRefMD5(refs);