/** * Prepare to read BAM from a file (seekable) * @param file source of bytes. * @param indexFile BAM index file * @param eagerDecode if true, decode all BAM fields as reading rather than lazily. * @param useAsynchronousIO if true, use asynchronous I/O * @param validationStringency Controls how to handle invalidate reads or header lines. * @param samRecordFactory SAM record factory * @param inflaterFactory InflaterFactory used by BlockCompressedInputStream * @throws IOException */ BAMFileReader(final File file, final File indexFile, final boolean eagerDecode, final boolean useAsynchronousIO, final ValidationStringency validationStringency, final SAMRecordFactory samRecordFactory, final InflaterFactory inflaterFactory) throws IOException { this(useAsynchronousIO ? new AsyncBlockCompressedInputStream(file, inflaterFactory) : new BlockCompressedInputStream(file, inflaterFactory), indexFile!=null ? indexFile : SamFiles.findIndex(file), eagerDecode, useAsynchronousIO, file.getAbsolutePath(), validationStringency, samRecordFactory); if (mIndexFile != null && mIndexFile.lastModified() < file.lastModified()) { System.err.println("WARNING: BAM index file " + mIndexFile.getAbsolutePath() + " is older than BAM " + file.getAbsolutePath()); } // Provide better error message when there is an error reading. mStream.setInputFileName(file.getAbsolutePath()); }
/** * Prepare to read BAM from a file (seekable) * @param file source of bytes. * @param indexFile BAM index file * @param eagerDecode if true, decode all BAM fields as reading rather than lazily. * @param useAsynchronousIO if true, use asynchronous I/O * @param validationStringency Controls how to handle invalidate reads or header lines. * @param samRecordFactory SAM record factory * @param inflaterFactory InflaterFactory used by BlockCompressedInputStream * @throws IOException */ BAMFileReader(final File file, final File indexFile, final boolean eagerDecode, final boolean useAsynchronousIO, final ValidationStringency validationStringency, final SAMRecordFactory samRecordFactory, final InflaterFactory inflaterFactory) throws IOException { this(useAsynchronousIO ? new AsyncBlockCompressedInputStream(file, inflaterFactory) : new BlockCompressedInputStream(file, inflaterFactory), indexFile!=null ? indexFile : SamFiles.findIndex(file), eagerDecode, useAsynchronousIO, file.getAbsolutePath(), validationStringency, samRecordFactory); if (mIndexFile != null && mIndexFile.lastModified() < file.lastModified()) { System.err.println("WARNING: BAM index file " + mIndexFile.getAbsolutePath() + " is older than BAM " + file.getAbsolutePath()); } // Provide better error message when there is an error reading. mStream.setInputFileName(file.getAbsolutePath()); }
/** * Prepare to read BAM from a file (seekable) * @param file source of bytes. * @param indexFile BAM index file * @param eagerDecode if true, decode all BAM fields as reading rather than lazily. * @param useAsynchronousIO if true, use asynchronous I/O * @param validationStringency Controls how to handle invalidate reads or header lines. * @param samRecordFactory SAM record factory * @param inflaterFactory InflaterFactory used by BlockCompressedInputStream * @throws IOException */ BAMFileReader(final File file, final File indexFile, final boolean eagerDecode, final boolean useAsynchronousIO, final ValidationStringency validationStringency, final SAMRecordFactory samRecordFactory, final InflaterFactory inflaterFactory) throws IOException { this(useAsynchronousIO ? new AsyncBlockCompressedInputStream(file, inflaterFactory) : new BlockCompressedInputStream(file, inflaterFactory), indexFile!=null ? indexFile : SamFiles.findIndex(file), eagerDecode, useAsynchronousIO, file.getAbsolutePath(), validationStringency, samRecordFactory); if (mIndexFile != null && mIndexFile.lastModified() < file.lastModified()) { System.err.println("WARNING: BAM index file " + mIndexFile.getAbsolutePath() + " is older than BAM " + file.getAbsolutePath()); } // Provide better error message when there is an error reading. mStream.setInputFileName(file.getAbsolutePath()); }
/** * Prepare to read BAM from a stream (seekable) * @param strm source of bytes * @param indexFile BAM index file * @param eagerDecode if true, decode all BAM fields as reading rather than lazily. * @param useAsynchronousIO if true, use asynchronous I/O * @param validationStringency Controls how to handle invalidate reads or header lines. * @param samRecordFactory SAM record factory * @param inflaterFactory InflaterFactory used by BlockCompressedInputStream * @throws IOException */ BAMFileReader(final SeekableStream strm, final File indexFile, final boolean eagerDecode, final boolean useAsynchronousIO, final ValidationStringency validationStringency, final SAMRecordFactory samRecordFactory, final InflaterFactory inflaterFactory) throws IOException { this(useAsynchronousIO ? new AsyncBlockCompressedInputStream(strm, inflaterFactory) : new BlockCompressedInputStream(strm, inflaterFactory), indexFile, eagerDecode, useAsynchronousIO, strm.getSource(), validationStringency, samRecordFactory); }
/** * Prepare to read BAM from a stream (seekable) * @param strm source of bytes * @param indexStream BAM index stream * @param eagerDecode if true, decode all BAM fields as reading rather than lazily. * @param useAsynchronousIO if true, use asynchronous I/O * @param validationStringency Controls how to handle invalidate reads or header lines. * @param samRecordFactory SAM record factory * @param inflaterFactory InflaterFactory used by BlockCompressedInputStream * @throws IOException */ BAMFileReader(final SeekableStream strm, final SeekableStream indexStream, final boolean eagerDecode, final boolean useAsynchronousIO, final ValidationStringency validationStringency, final SAMRecordFactory samRecordFactory, final InflaterFactory inflaterFactory) throws IOException { this(useAsynchronousIO ? new AsyncBlockCompressedInputStream(strm, inflaterFactory) : new BlockCompressedInputStream(strm, inflaterFactory), indexStream, eagerDecode, useAsynchronousIO, strm.getSource(), validationStringency, samRecordFactory); }
/** * Prepare to read BAM from a stream (seekable) * @param strm source of bytes * @param indexStream BAM index stream * @param eagerDecode if true, decode all BAM fields as reading rather than lazily. * @param useAsynchronousIO if true, use asynchronous I/O * @param validationStringency Controls how to handle invalidate reads or header lines. * @param samRecordFactory SAM record factory * @param inflaterFactory InflaterFactory used by BlockCompressedInputStream * @throws IOException */ BAMFileReader(final SeekableStream strm, final SeekableStream indexStream, final boolean eagerDecode, final boolean useAsynchronousIO, final ValidationStringency validationStringency, final SAMRecordFactory samRecordFactory, final InflaterFactory inflaterFactory) throws IOException { this(useAsynchronousIO ? new AsyncBlockCompressedInputStream(strm, inflaterFactory) : new BlockCompressedInputStream(strm, inflaterFactory), indexStream, eagerDecode, useAsynchronousIO, strm.getSource(), validationStringency, samRecordFactory); }
/** * Prepare to read BAM from a stream (seekable) * @param strm source of bytes * @param indexFile BAM index file * @param eagerDecode if true, decode all BAM fields as reading rather than lazily. * @param useAsynchronousIO if true, use asynchronous I/O * @param validationStringency Controls how to handle invalidate reads or header lines. * @param samRecordFactory SAM record factory * @param inflaterFactory InflaterFactory used by BlockCompressedInputStream * @throws IOException */ BAMFileReader(final SeekableStream strm, final File indexFile, final boolean eagerDecode, final boolean useAsynchronousIO, final ValidationStringency validationStringency, final SAMRecordFactory samRecordFactory, final InflaterFactory inflaterFactory) throws IOException { this(useAsynchronousIO ? new AsyncBlockCompressedInputStream(strm, inflaterFactory) : new BlockCompressedInputStream(strm, inflaterFactory), indexFile, eagerDecode, useAsynchronousIO, strm.getSource(), validationStringency, samRecordFactory); }
/** * Prepare to read BAM from a stream (seekable) * @param strm source of bytes * @param indexStream BAM index stream * @param eagerDecode if true, decode all BAM fields as reading rather than lazily. * @param useAsynchronousIO if true, use asynchronous I/O * @param validationStringency Controls how to handle invalidate reads or header lines. * @param samRecordFactory SAM record factory * @param inflaterFactory InflaterFactory used by BlockCompressedInputStream * @throws IOException */ BAMFileReader(final SeekableStream strm, final SeekableStream indexStream, final boolean eagerDecode, final boolean useAsynchronousIO, final ValidationStringency validationStringency, final SAMRecordFactory samRecordFactory, final InflaterFactory inflaterFactory) throws IOException { this(useAsynchronousIO ? new AsyncBlockCompressedInputStream(strm, inflaterFactory) : new BlockCompressedInputStream(strm, inflaterFactory), indexStream, eagerDecode, useAsynchronousIO, strm.getSource(), validationStringency, samRecordFactory); }
/** * Prepare to read BAM from a stream (not seekable) * @param stream source of bytes. * @param indexFile BAM index file * @param eagerDecode if true, decode all BAM fields as reading rather than lazily. * @param useAsynchronousIO if true, use asynchronous I/O * @param validationStringency Controls how to handle invalidate reads or header lines. * @param samRecordFactory SAM record factory * @param inflaterFactory InflaterFactory used by BlockCompressedInputStream * @throws IOException */ BAMFileReader(final InputStream stream, final File indexFile, final boolean eagerDecode, final boolean useAsynchronousIO, final ValidationStringency validationStringency, final SAMRecordFactory samRecordFactory, final InflaterFactory inflaterFactory) throws IOException { mIndexFile = indexFile; mIsSeekable = false; mCompressedInputStream = useAsynchronousIO ? new AsyncBlockCompressedInputStream(stream, inflaterFactory) : new BlockCompressedInputStream(stream, inflaterFactory); mStream = new BinaryCodec(new DataInputStream(mCompressedInputStream)); this.eagerDecode = eagerDecode; this.mValidationStringency = validationStringency; this.samRecordFactory = samRecordFactory; this.mFileHeader = readHeader(this.mStream, this.mValidationStringency, null); }
/** * Prepare to read BAM from a stream (seekable) * @param strm source of bytes * @param indexFile BAM index file * @param eagerDecode if true, decode all BAM fields as reading rather than lazily. * @param useAsynchronousIO if true, use asynchronous I/O * @param validationStringency Controls how to handle invalidate reads or header lines. * @param samRecordFactory SAM record factory * @param inflaterFactory InflaterFactory used by BlockCompressedInputStream * @throws IOException */ BAMFileReader(final SeekableStream strm, final File indexFile, final boolean eagerDecode, final boolean useAsynchronousIO, final ValidationStringency validationStringency, final SAMRecordFactory samRecordFactory, final InflaterFactory inflaterFactory) throws IOException { this(useAsynchronousIO ? new AsyncBlockCompressedInputStream(strm, inflaterFactory) : new BlockCompressedInputStream(strm, inflaterFactory), indexFile, eagerDecode, useAsynchronousIO, strm.getSource(), validationStringency, samRecordFactory); }
/** * Prepare to read BAM from a stream (not seekable) * @param stream source of bytes. * @param indexFile BAM index file * @param eagerDecode if true, decode all BAM fields as reading rather than lazily. * @param useAsynchronousIO if true, use asynchronous I/O * @param validationStringency Controls how to handle invalidate reads or header lines. * @param samRecordFactory SAM record factory * @param inflaterFactory InflaterFactory used by BlockCompressedInputStream * @throws IOException */ BAMFileReader(final InputStream stream, final File indexFile, final boolean eagerDecode, final boolean useAsynchronousIO, final ValidationStringency validationStringency, final SAMRecordFactory samRecordFactory, final InflaterFactory inflaterFactory) throws IOException { mIndexFile = indexFile; mIsSeekable = false; mCompressedInputStream = useAsynchronousIO ? new AsyncBlockCompressedInputStream(stream, inflaterFactory) : new BlockCompressedInputStream(stream, inflaterFactory); mStream = new BinaryCodec(new DataInputStream(mCompressedInputStream)); this.eagerDecode = eagerDecode; this.mValidationStringency = validationStringency; this.samRecordFactory = samRecordFactory; this.mFileHeader = readHeader(this.mStream, this.mValidationStringency, null); }
/** * Prepare to read BAM from a stream (not seekable) * @param stream source of bytes. * @param indexFile BAM index file * @param eagerDecode if true, decode all BAM fields as reading rather than lazily. * @param useAsynchronousIO if true, use asynchronous I/O * @param validationStringency Controls how to handle invalidate reads or header lines. * @param samRecordFactory SAM record factory * @param inflaterFactory InflaterFactory used by BlockCompressedInputStream * @throws IOException */ BAMFileReader(final InputStream stream, final File indexFile, final boolean eagerDecode, final boolean useAsynchronousIO, final ValidationStringency validationStringency, final SAMRecordFactory samRecordFactory, final InflaterFactory inflaterFactory) throws IOException { mIndexFile = indexFile; mIsSeekable = false; mCompressedInputStream = useAsynchronousIO ? new AsyncBlockCompressedInputStream(stream, inflaterFactory) : new BlockCompressedInputStream(stream, inflaterFactory); mStream = new BinaryCodec(new DataInputStream(mCompressedInputStream)); this.eagerDecode = eagerDecode; this.mValidationStringency = validationStringency; this.samRecordFactory = samRecordFactory; this.mFileHeader = readHeader(this.mStream, this.mValidationStringency, null); this.useAsynchronousIO = useAsynchronousIO; }
@DataProvider(name = "customInflaterInput") public Object[][] customInflateInput() throws IOException { final File tempFile = File.createTempFile("testCustomInflater.", ".bam"); tempFile.deleteOnExit(); final List<String> linesWritten = writeTempBlockCompressedFileForInflaterTest(tempFile); final InflaterFactory countingInflaterFactory = new CountingInflaterFactory(); return new Object[][]{ // set the default InflaterFactory to a CountingInflaterFactory {(CheckedExceptionInputStreamSupplier) () -> new BlockCompressedInputStream(new FileInputStream(tempFile), false), linesWritten, 4, countingInflaterFactory}, {(CheckedExceptionInputStreamSupplier) () -> new BlockCompressedInputStream(tempFile), linesWritten, 4, countingInflaterFactory}, {(CheckedExceptionInputStreamSupplier) () -> new AsyncBlockCompressedInputStream(tempFile), linesWritten, 4, countingInflaterFactory}, {(CheckedExceptionInputStreamSupplier) () -> new BlockCompressedInputStream(new URL("http://broadinstitute.github.io/picard/testdata/index_test.bam")), null, 21, countingInflaterFactory}, // provide a CountingInflaterFactory explicitly {(CheckedExceptionInputStreamSupplier) () -> new BlockCompressedInputStream(new FileInputStream(tempFile), false, countingInflaterFactory), linesWritten, 4, null}, {(CheckedExceptionInputStreamSupplier) () -> new BlockCompressedInputStream(tempFile, countingInflaterFactory), linesWritten, 4, null}, {(CheckedExceptionInputStreamSupplier) () -> new AsyncBlockCompressedInputStream(tempFile, countingInflaterFactory), linesWritten, 4, null}, {(CheckedExceptionInputStreamSupplier) () -> new BlockCompressedInputStream(new URL("http://broadinstitute.github.io/picard/testdata/index_test.bam"), countingInflaterFactory), null, 21, null} }; }
List<BlockCompressedInputStream> list = new ArrayList<>(); for (int i = 0; i < 8; i++) { list.add(new AsyncBlockCompressedInputStream(new SeekableFileStream(BAM_FILE)));