Package htsjdk.samtools
Class SamReaderFactory
java.lang.Object
htsjdk.samtools.SamReaderFactory
Describes the functionality for producing SamReader
, and offers a
handful of static generators.
SamReaderFactory.makeDefault().open(new File("/my/bam.bam");
Example: Configure a factory
finalSamReaderFactory
factory = SamReaderFactory.makeDefault() .enable(SamReaderFactory.Option.INCLUDE_SOURCE_IN_RECORDS
,SamReaderFactory.Option.VALIDATE_CRC_CHECKSUMS
) .validationStringency(ValidationStringency.SILENT
);
Example: Open two bam files from different sources, using different options
finalSamReaderFactory
factory = SamReaderFactory.makeDefault() .enable(SamReaderFactory.Option.INCLUDE_SOURCE_IN_RECORDS
,SamReaderFactory.Option.VALIDATE_CRC_CHECKSUMS
) .validationStringency(ValidationStringency.SILENT
); // File-based bam finalSamReader
fileReader = factory.open(new File("/my/bam.bam")); // HTTP-hosted BAM with index from an arbitrary stream final SeekableStream myBamIndexStream = ... finalSamInputResource
resource =SamInputResource
.of(new URL("http://example.com/data.bam")).index(myBamIndexStream); finalSamReader
complicatedReader = factory.open(resource);
-
Nested Class Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionabstract SamReaderFactory
disable
(SamReaderFactory.Option... options) Disables the providedSamReaderFactory.Option
s, then returns itself.abstract SamReaderFactory
enable
(SamReaderFactory.Option... options) Enables the providedSamReaderFactory.Option
s, then returns itself.abstract SAMFileHeader
getFileHeader
(File samFile) Utility method to open the file get the header and close the fileabstract SAMFileHeader
getFileHeader
(Path samFile) Utility method to open the file get the header and close the fileabstract SamReaderFactory
inflaterFactory
(InflaterFactory inflaterFactory) Set this factory'sInflaterFactory
to the provided one, then returns itself.static SamReaderFactory
make()
Creates an "empty" factory with no enabledSamReaderFactory.Option
s,ValidationStringency.DEFAULT_STRINGENCY
, no path wrapper, andDefaultSAMRecordFactory
.static SamReaderFactory
Creates a copy of the defaultSamReaderFactory
.abstract SamReader
open
(SamInputResource resource) abstract SamReader
Open the specified path (without using any wrappers).open
(Path path, Function<SeekableByteChannel, SeekableByteChannel> dataWrapper, Function<SeekableByteChannel, SeekableByteChannel> indexWrapper) Open the specified path, using the specified wrappers for prefetching/caching.abstract void
reapplyOptions
(SamReader reader) Reapplies any changed options to the reader *abstract SamReaderFactory
referenceSequence
(File referenceSequence) Sets the specified reference sequence *abstract SamReaderFactory
referenceSequence
(Path referenceSequence) Sets the specified reference sequence.abstract CRAMReferenceSource
abstract SamReaderFactory
referenceSource
(CRAMReferenceSource referenceSequence) Sets the specified reference sequence *abstract SamReaderFactory
samRecordFactory
(SAMRecordFactory samRecordFactory) Set this factory'sSAMRecordFactory
to the provided one, then returns itself.static void
setDefaultValidationStringency
(ValidationStringency defaultValidationStringency) abstract SamReaderFactory
setOption
(SamReaderFactory.Option option, boolean value) Sets a specific Option to a boolean value.abstract SamReaderFactory
setUseAsyncIo
(boolean asynchronousIO) Set whether readers created by this factory will use asynchronous IO.abstract ValidationStringency
abstract SamReaderFactory
validationStringency
(ValidationStringency validationStringency) Set this factory'sValidationStringency
to the provided one, then returns itself.
-
Constructor Details
-
SamReaderFactory
public SamReaderFactory()
-
-
Method Details
-
open
-
open
Open the specified path (without using any wrappers).- Parameters:
path
- the SAM or BAM file to open.
-
open
public SamReader open(Path path, Function<SeekableByteChannel, SeekableByteChannel> dataWrapper, Function<SeekableByteChannel, SeekableByteChannel> indexWrapper) Open the specified path, using the specified wrappers for prefetching/caching.- Parameters:
path
- the SAM or BAM file to opendataWrapper
- the wrapper for the data (or null for none)indexWrapper
- the wrapper for the index (or null for none)
-
open
-
validationStringency
-
referenceSource
-
samRecordFactory
Set this factory'sSAMRecordFactory
to the provided one, then returns itself. -
inflaterFactory
Set this factory'sInflaterFactory
to the provided one, then returns itself. Note: The inflaterFactory provided here is only used for BAM decompression implemented withBAMFileReader
, it is not used for CRAM or other formats like a gzipped SAM file. -
enable
Enables the providedSamReaderFactory.Option
s, then returns itself. -
disable
Disables the providedSamReaderFactory.Option
s, then returns itself. -
setOption
Sets a specific Option to a boolean value. * -
referenceSequence
Sets the specified reference sequence * -
referenceSequence
Sets the specified reference sequence. -
referenceSource
Sets the specified reference sequence * -
getFileHeader
Utility method to open the file get the header and close the file -
getFileHeader
Utility method to open the file get the header and close the file -
reapplyOptions
Reapplies any changed options to the reader * -
validationStringency
Set this factory'sValidationStringency
to the provided one, then returns itself. -
setUseAsyncIo
Set whether readers created by this factory will use asynchronous IO. If this methods is not called, this flag will default to the value ofDefaults.USE_ASYNC_IO_READ_FOR_SAMTOOLS
. Note that this option may not be applicable to all readers returned from this factory. Returns the factory itself. -
setDefaultValidationStringency
-
makeDefault
Creates a copy of the defaultSamReaderFactory
. -
make
Creates an "empty" factory with no enabledSamReaderFactory.Option
s,ValidationStringency.DEFAULT_STRINGENCY
, no path wrapper, andDefaultSAMRecordFactory
.
-