private static List<Long> getContainerOffsets(Configuration conf, Path cramFile) throws IOException { SeekableStream seekableStream = WrapSeekable.openPath(conf, cramFile); CramContainerIterator cci = new CramContainerIterator(seekableStream); List<Long> containerOffsets = new ArrayList<Long>(); containerOffsets.add(seekableStream.position()); while (cci.hasNext()) { cci.next(); containerOffsets.add(seekableStream.position()); } containerOffsets.add(seekableStream.length()); return containerOffsets; }
private static List<Long> getContainerOffsets(Configuration conf, Path cramFile) throws IOException { SeekableStream seekableStream = WrapSeekable.openPath(conf, cramFile); CramContainerIterator cci = new CramContainerIterator(seekableStream); List<Long> containerOffsets = new ArrayList<Long>(); containerOffsets.add(seekableStream.position()); while (cci.hasNext()) { cci.next(); containerOffsets.add(seekableStream.position()); } containerOffsets.add(seekableStream.length()); return containerOffsets; }
private static List<Long> getContainerOffsets(Configuration conf, Path cramFile) throws IOException { SeekableStream seekableStream = WrapSeekable.openPath(conf, cramFile); CramContainerIterator cci = new CramContainerIterator(seekableStream); List<Long> containerOffsets = new ArrayList<Long>(); containerOffsets.add(seekableStream.position()); while (cci.hasNext()) { cci.next(); containerOffsets.add(seekableStream.position()); } containerOffsets.add(seekableStream.length()); return containerOffsets; }
public CRAMIterator(final InputStream inputStream, final CRAMReferenceSource referenceSource, final ValidationStringency validationStringency) throws IOException { if (null == referenceSource) { throw new CRAMException("A reference source is required for CRAM files"); } this.countingInputStream = new CountingInputStream(inputStream); this.referenceSource = referenceSource; this.validationStringency = validationStringency; final CramContainerIterator containerIterator = new CramContainerIterator(this.countingInputStream); cramHeader = containerIterator.getCramHeader(); this.containerIterator = containerIterator; firstContainerOffset = this.countingInputStream.getCount(); records = new ArrayList<SAMRecord>(CRAMContainerStreamWriter.DEFAULT_RECORDS_PER_SLICE); normalizer = new CramNormalizer(cramHeader.getSamFileHeader(), referenceSource); parser = new ContainerParser(cramHeader.getSamFileHeader()); }
public CRAMIterator(final InputStream inputStream, final CRAMReferenceSource referenceSource, final ValidationStringency validationStringency) { if (null == referenceSource) { throw new CRAMException("A reference source is required for CRAM files"); } this.countingInputStream = new CountingInputStream(inputStream); this.referenceSource = referenceSource; this.validationStringency = validationStringency; final CramContainerIterator containerIterator = new CramContainerIterator(this.countingInputStream); cramHeader = containerIterator.getCramHeader(); this.containerIterator = containerIterator; firstContainerOffset = this.countingInputStream.getCount(); records = new ArrayList<>(CRAMContainerStreamWriter.DEFAULT_RECORDS_PER_SLICE); normalizer = new CramNormalizer(cramHeader.getSamFileHeader(), referenceSource); parser = new ContainerParser(cramHeader.getSamFileHeader()); }
List<Container> fullContainers; try (SeekableFileStream seekableFileStream = new SeekableFileStream(cramFile)) { CramContainerIterator iterator = new CramContainerIterator(seekableFileStream); expectedHeader = iterator.getCramHeader(); fullContainers = Iterables.slurp(iterator);
@Test public void testCRAIIndexerFromContainer() throws IOException { final File CRAMFile = new File("src/test/resources/htsjdk/samtools/cram/test2.cram"); final File refFile = new File("src/test/resources/htsjdk/samtools/cram/auxf.fa"); ReferenceSource refSource = new ReferenceSource(refFile); CRAMFileReader reader = new CRAMFileReader( CRAMFile, null, refSource, ValidationStringency.STRICT); SAMFileHeader samHeader = reader.getFileHeader(); Iterator<SAMRecord> it = reader.getIterator(); while(it.hasNext()) { SAMRecord samRec = it.next(); } reader.close(); FileInputStream fis = new FileInputStream(CRAMFile); CramContainerIterator cit = new CramContainerIterator(fis); ByteArrayOutputStream bos = new ByteArrayOutputStream(); CRAMCRAIIndexer craiIndexer = new CRAMCRAIIndexer(bos, samHeader); while (cit.hasNext()) { craiIndexer.processContainer(cit.next()); } craiIndexer.finish(); bos.close(); List<CRAIEntry> craiEntries = CRAMCRAIIndexer.readIndex(new ByteArrayInputStream(bos.toByteArray())).getCRAIEntries(); Assert.assertEquals(craiEntries.size(), 1); }
@Test public void testIteratorFromFileSpan_SecondContainer() throws IOException, IllegalAccessException { CramContainerIterator it = new CramContainerIterator(new ByteArrayInputStream(cramBytes)); it.hasNext(); it.next();
@Test public void testIteratorSecondContainerSpan() throws IOException, IllegalAccessException { CramContainerIterator it = new CramContainerIterator(new ByteArrayInputStream(cramBytes)); it.hasNext(); it.next();