@Override protected CramHeader readHeader(InputStream is) throws IOException { try { return CramIO.readCramHeader(is); } catch (IOException e) { throw e; } catch (Exception ee) { return null; } } };
public CraiIndexer(InputStream cramInputStream, OutputStream craiOutputStream) throws FileNotFoundException, IOException { this.is = new CountingInputStream(cramInputStream); cramHeader = CramIO.readCramHeader(this.is); index = new CramIndex(); os = new GZIPOutputStream(new BufferedOutputStream(craiOutputStream)); }
private CramSpanContainerIterator(final SeekableStream seekableStream, final long[] coordinates) throws IOException { this.seekableStream = seekableStream; seekableStream.seek(0); this.cramHeader = CramIO.readCramHeader(seekableStream); firstContainerOffset = seekableStream.position(); final List<Boundary> boundaries = new ArrayList<Boundary>(); for (int i = 0; i < coordinates.length; i += 2) { boundaries.add(new Boundary(coordinates[i], coordinates[i + 1])); } containerBoundaries = boundaries.iterator(); currentBoundary = containerBoundaries.next(); }
private CramSpanContainerIterator(final SeekableStream seekableStream, final long[] coordinates) throws IOException { this.seekableStream = seekableStream; seekableStream.seek(0); this.cramHeader = CramIO.readCramHeader(seekableStream); firstContainerOffset = seekableStream.position(); final List<Boundary> boundaries = new ArrayList<Boundary>(); for (int i = 0; i < coordinates.length; i += 2) { boundaries.add(new Boundary(coordinates[i], coordinates[i + 1])); } containerBoundaries = boundaries.iterator(); currentBoundary = containerBoundaries.next(); }
public CramContainerIterator(final InputStream inputStream) throws IOException { this.countingInputStream = new CountingInputStream(inputStream); cramHeader = CramIO.readCramHeader(countingInputStream); this.offset = countingInputStream.getCount(); }
public CramContainerIterator(final InputStream inputStream) { this.countingInputStream = new CountingInputStream(inputStream); cramHeader = CramIO.readCramHeader(countingInputStream); this.offset = countingInputStream.getCount(); }
public static void main(String[] args) throws IOException, IllegalArgumentException, IllegalAccessException { Log.setGlobalLogLevel(LogLevel.INFO); File cramFile = new File(args[0]); InputStream is = new BufferedInputStream(new FileInputStream(cramFile)); CramHeader header = CramIO.readCramHeader(is); Container c = null; while ((c = ContainerIO.readContainer(header.getVersion(), is)) != null && !c.isEOF()) { for (Slice slice : c.slices) { if (slice.sequenceId == Slice.MULTI_REFERENCE) { System.out.println("Read feature B detected."); System.exit(1); } } } } }
/** * Check if the file: 1) contains proper CRAM header. 2) given the version info from the header check the end of file marker. * * @param file the CRAM file to check * @return true if the file is a valid CRAM file and is properly terminated with respect to the version. * @throws IOException as per java IO contract */ public static boolean checkHeaderAndEOF(final File file) throws IOException { final SeekableStream seekableStream = new SeekableFileStream(file); final CramHeader cramHeader = readCramHeader(seekableStream); return checkEOF(cramHeader.getVersion(), seekableStream); }
public BaiIndexer(InputStream is, OutputStream output) throws IOException { this.is = new CountingInputStream(is); cramHeader = CramIO.readCramHeader(this.is); samFileHeader = cramHeader.getSamFileHeader(); indexer = new CRAMBAIIndexer(output, samFileHeader); }
public boolean fixHeaderInFile(File cramFile) throws IOException, MD5MismatchError { FileInputStream fis = new FileInputStream(cramFile); CramHeader cramHeader = CramIO.readCramHeader(fis); fixSequences(cramHeader.getSamFileHeader().getSequenceDictionary().getSequences()); String cmd = "fixheader"; String version = getClass().getPackage().getImplementationVersion(); addPG(cramHeader.getSamFileHeader(), "cramtools", cmd, version); CramHeader newHeader = cramHeader.clone(); return CramIO.replaceCramHeader(cramFile, newHeader); }
/** * Check if the file: 1) contains proper CRAM header. 2) given the version info from the header check the end of file marker. * * @param file the CRAM file to check * @return true if the file is a valid CRAM file and is properly terminated with respect to the version. */ public static boolean checkHeaderAndEOF(final File file) { try (final SeekableStream seekableStream = new SeekableFileStream(file)) { final CramHeader cramHeader = readCramHeader(seekableStream); return checkEOF(cramHeader.getVersion(), seekableStream); } catch (final IOException e) { throw new RuntimeIOException(e); } }
File cramFile = new File(args[0]); InputStream is = new BufferedInputStream(new FileInputStream(cramFile)); CramHeader header = CramIO.readCramHeader(is); Container c = null; while ((c = ContainerIO.readContainer(header.getVersion(), is)) != null && !c.isEOF()) {
private static void dist(File file, byte defaultQualityScore) throws IllegalArgumentException, IOException, IllegalAccessException { InputStream is = new FileInputStream(file); CramHeader header = CramIO.readCramHeader(is); Container c = null; ContainerParser parser = new ContainerParser(header.getSamFileHeader()); ArrayList<CramCompressionRecord> records = new ArrayList<CramCompressionRecord>(10000); long[] freq = new long[255]; while ((c = ContainerIO.readContainer(header.getVersion(), is)) != null && !c.isEOF()) { parser.getRecords(c, records, ValidationStringency.SILENT); CramNormalizer.restoreQualityScores(defaultQualityScore, records); for (CramCompressionRecord record : records) { for (byte b : record.qualityScores) freq[b & 0xFF]++; } records.clear(); } print(freq, defaultQualityScore, System.out); }
CramHeader cramHeader = CramIO.readCramHeader(fis);
@Test public void testSliceMD5() throws IOException { final CramTestCase test = new CramTestCase(); // read the CRAM: final ByteArrayInputStream bais = new ByteArrayInputStream(test.cramData); final CramHeader cramHeader = CramIO.readCramHeader(bais); final Container container = ContainerIO.readContainer(cramHeader.getVersion(), bais); final Slice slice = container.slices[0]; Assert.assertEquals(slice.alignmentStart, 1); Assert.assertEquals(slice.alignmentSpan, test.referenceBases.length); // check the slice MD5 is the MD5 of upper-cased ref bases: final byte[] ucRefMD5 = SequenceUtil.calculateMD5(test.refBasesFromUCSource, 0, test.refBasesFromUCSource.length); Assert.assertEquals(slice.refMD5, ucRefMD5); // check the CRAM file reads: final CRAMFileReader reader = new CRAMFileReader(new ByteArrayInputStream(test.cramData), (File) null, test.referenceSourceUpperCased, ValidationStringency.STRICT); final SAMRecordIterator iterator = reader.getIterator(); Assert.assertTrue(iterator.hasNext()); Assert.assertEquals(iterator.next(), test.record); }
Assert.assertTrue(CramIO.checkHeaderAndEOF(file)); final CramHeader cramHeader3 = CramIO.readCramHeader(new FileInputStream(file)); Assert.assertEquals(cramHeader3.getVersion(), CramVersions.CRAM_v3); Assert.assertFalse(cramHeader3.getSamFileHeader().getSequenceDictionary().isEmpty());
/** * Generate and write a CRAI index to an output stream from a CRAM input stream * * @param cramStream CRAM stream to index; must be coordinate sorted * @param craiStream stream for output index */ public static void writeIndex(final SeekableStream cramStream, OutputStream craiStream) { try { final CramHeader cramHeader = CramIO.readCramHeader(cramStream); final CRAMCRAIIndexer indexer = new CRAMCRAIIndexer(craiStream, cramHeader.getSamFileHeader()); final Version cramVersion = cramHeader.getVersion(); // get the first container and it's offset long offset = cramStream.position(); Container container = ContainerIO.readContainer(cramVersion, cramStream); while (container != null && !container.isEOF()) { container.offset = offset; indexer.processContainer(container); offset = cramStream.position(); container = ContainerIO.readContainer(cramVersion, cramStream); } indexer.finish(); } catch (IOException e) { throw new RuntimeIOException("Error writing CRAI index to output stream"); } }
/** * Generate and write a CRAI index to an output stream from a CRAM input stream * * @param cramStream CRAM stream to index; must be coordinate sorted * @param craiStream stream for output index */ public static void writeIndex(final SeekableStream cramStream, OutputStream craiStream) { try { final CramHeader cramHeader = CramIO.readCramHeader(cramStream); final CRAMCRAIIndexer indexer = new CRAMCRAIIndexer(craiStream, cramHeader.getSamFileHeader()); final Version cramVersion = cramHeader.getVersion(); // get the first container and it's offset long offset = cramStream.position(); Container container = ContainerIO.readContainer(cramVersion, cramStream); while (container != null && !container.isEOF()) { container.offset = offset; indexer.processContainer(container); offset = cramStream.position(); container = ContainerIO.readContainer(cramVersion, cramStream); } indexer.finish(); } catch (IOException e) { throw new RuntimeIOException("Error writing CRAI index to output stream"); } }
final CramHeader cramHeader = CramIO.readCramHeader(stream); if (cramHeader.getSamFileHeader().getSortOrder() != SAMFileHeader.SortOrder.coordinate) { throw new SAMException("Expecting a coordinate sorted file.");
final CramHeader cramHeader = CramIO.readCramHeader(stream); if (cramHeader.getSamFileHeader().getSortOrder() != SAMFileHeader.SortOrder.coordinate) { throw new SAMException("Expecting a coordinate sorted file.");