String json = aceptaDefault(); JSONParser parser = new JSONParser(); ContainerFactory orderedKeyFactory = new ContainerFactory() { public List createArrayContainer() { return new LinkedList(); } public Map createObjectContainer() { return new LinkedHashMap(); } }; Object obj = parser.parse(json,orderedKeyFactory); LinkedHashMap map = (LinkedHashMap)obj;
@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); }
sam2CramRecordFactory.captureTags.addAll(captureTags); sam2CramRecordFactory.ignoreTags.addAll(ignoreTags); containerFactory.setPreserveReadNames(preserveReadNames); final Container container = containerFactory.buildContainer(cramRecords); for (final Slice slice : container.slices) { slice.setRefMD5(refs);
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; calculateAlignmentBoundaries(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<>(); 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; }
@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); }
sam2CramRecordFactory.captureTags.addAll(captureTags); sam2CramRecordFactory.ignoreTags.addAll(ignoreTags); containerFactory.setPreserveReadNames(preserveReadNames); final Container container = containerFactory.buildContainer(cramRecords); for (final Slice slice : container.slices) { slice.setRefMD5(refs);
final Container container = cramContext.containerFactory.buildContainer(cramRecords);
@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); }
public static Values parseJSONToMap(String msgData) { JSONParser parser = new JSONParser(); ContainerFactory containerFactory = new ContainerFactory(){ @Override public Map createObjectContainer() { return new LinkedHashMap(); } @Override public List creatArrayContainer() { return null; } }; try { return (Map<String,Object>)parser.parse(msgData, containerFactory); } catch (ParseException e) { log.warn("Exception parsing JSON string {}", msgData, e); } return null; }
@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); }
String jsonText = "{\"first\": 123, \"second\": [4, 5, 6], \"third\": 789}"; JSONParser parser = new JSONParser(); ContainerFactory containerFactory = new ContainerFactory(){ public List creatArrayContainer() { return new LinkedList(); } public Map createObjectContainer() { return new LinkedHashMap(); } }; try { Map json = (Map)parser.parse(jsonText, containerFactory); Iterator iter = json.entrySet().iterator(); System.out.println("==iterate result=="); while(iter.hasNext()){ Map.Entry entry = (Map.Entry)iter.next(); System.out.println(entry.getKey() + "=>" + entry.getValue()); } System.out.println("==toJSONString()=="); System.out.println(JSONValue.toJSONString(json)); } catch(ParseException pe){ System.out.println(pe); }
@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); }
/** * Create a CRAMContainerStreamWriter for writing SAM records into a series of CRAM * containers on output stream, with an optional index. * * @param outputStream where to write the CRAM stream. * @param indexStream where to write the output index. Can be null if no index is required. * @param source reference source * @param samFileHeader {@link SAMFileHeader} to be used. Sort order is determined by the sortOrder property of this arg. * @param cramId used for display in error message display */ public CRAMContainerStreamWriter( final OutputStream outputStream, final OutputStream indexStream, final CRAMReferenceSource source, final SAMFileHeader samFileHeader, final String cramId) { this.outputStream = outputStream; this.samFileHeader = samFileHeader; this.cramID = cramId; this.source = source; containerFactory = new ContainerFactory(samFileHeader, recordsPerSlice); if (indexStream != null) { indexer = new CRAMBAIIndexer(indexStream, samFileHeader); } }
@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); }
/** * Create a CRAMContainerStreamWriter for writing SAM records into a series of CRAM * containers on output stream, with an optional index. * * @param outputStream where to write the CRAM stream. * @param indexStream where to write the output index. Can be null if no index is required. * @param source reference source * @param samFileHeader {@link SAMFileHeader} to be used. Sort order is determined by the sortOrder property of this arg. * @param cramId used for display in error message display */ public CRAMContainerStreamWriter( final OutputStream outputStream, final OutputStream indexStream, final CRAMReferenceSource source, final SAMFileHeader samFileHeader, final String cramId) { this.outputStream = outputStream; this.samFileHeader = samFileHeader; this.cramID = cramId; this.source = source; containerFactory = new ContainerFactory(samFileHeader, recordsPerSlice); if (indexStream != null) { indexer = new CRAMBAIIndexer(indexStream, samFileHeader); } }
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; }
public CramContext(SAMFileHeader samFileHeader, ReferenceSource referenceSource, CramLossyOptions lossyOptions) { this.samFileHeader = samFileHeader; this.referenceSource = referenceSource; this.lossyOptions = lossyOptions; sam2cramFactory = new Sam2CramRecordFactory(null, samFileHeader, CramVersions.CRAM_v3); sam2cramFactory.captureAllTags = lossyOptions.isCaptureAllTags(); sam2cramFactory.captureTags.addAll(lossyOptions.getCaptureTags()); sam2cramFactory.ignoreTags.addAll(lossyOptions.getIgnoreTags()); containerFactory = new ContainerFactory(samFileHeader, RECORDS_PER_SLICE); } }
@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 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); }