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; }
@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(); it.hasNext(); Container secondContainer = it.next(); Assert.assertNotNull(secondContainer);
@Test public void testIteratorSecondContainerSpan() throws IOException, IllegalAccessException { CramContainerIterator it = new CramContainerIterator(new ByteArrayInputStream(cramBytes)); it.hasNext(); it.next(); it.hasNext(); Container secondContainer = it.next(); Assert.assertNotNull(secondContainer);