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
final SamReaderFactory 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
final SamReaderFactory factory =
SamReaderFactory.makeDefault()
.enable(SamReaderFactory.Option.INCLUDE_SOURCE_IN_RECORDS, SamReaderFactory.Option.VALIDATE_CRC_CHECKSUMS)
.validationStringency(ValidationStringency.SILENT);
// File-based bam
final SamReader fileReader = factory.open(new File("/my/bam.bam"));
// HTTP-hosted BAM with index from an arbitrary stream
final SeekableStream myBamIndexStream = ...
final SamInputResource resource =
SamInputResource.of(new URL("http://example.com/data.bam")).index(myBamIndexStream);
final SamReader complicatedReader = factory.open(resource);
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract SamReaderFactorydisable(SamReaderFactory.Option... options) Disables the providedSamReaderFactory.Options, then returns itself.abstract SamReaderFactoryenable(SamReaderFactory.Option... options) Enables the providedSamReaderFactory.Options, then returns itself.abstract SAMFileHeadergetFileHeader(File samFile) Utility method to open the file get the header and close the fileabstract SAMFileHeadergetFileHeader(Path samFile) Utility method to open the file get the header and close the fileabstract SamReaderFactoryinflaterFactory(InflaterFactory inflaterFactory) Set this factory'sInflaterFactoryto the provided one, then returns itself.static SamReaderFactorymake()Creates an "empty" factory with no enabledSamReaderFactory.Options,ValidationStringency.DEFAULT_STRINGENCY, no path wrapper, andDefaultSAMRecordFactory.static SamReaderFactoryCreates a copy of the defaultSamReaderFactory.abstract SamReaderopen(SamInputResource resource) abstract SamReaderOpen 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 voidreapplyOptions(SamReader reader) Reapplies any changed options to the reader *abstract SamReaderFactoryreferenceSequence(File referenceSequence) Sets the specified reference sequence *abstract SamReaderFactoryreferenceSequence(Path referenceSequence) Sets the specified reference sequence.abstract CRAMReferenceSourceabstract SamReaderFactoryreferenceSource(CRAMReferenceSource referenceSequence) Sets the specified reference sequence *abstract SamReaderFactorysamRecordFactory(SAMRecordFactory samRecordFactory) Set this factory'sSAMRecordFactoryto the provided one, then returns itself.static voidsetDefaultValidationStringency(ValidationStringency defaultValidationStringency) abstract SamReaderFactorysetOption(SamReaderFactory.Option option, boolean value) Sets a specific Option to a boolean value.abstract SamReaderFactorysetUseAsyncIo(boolean asynchronousIO) Set whether readers created by this factory will use asynchronous IO.abstract ValidationStringencyabstract SamReaderFactoryvalidationStringency(ValidationStringency validationStringency) Set this factory'sValidationStringencyto 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'sSAMRecordFactoryto the provided one, then returns itself. -
inflaterFactory
Set this factory'sInflaterFactoryto 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.Options, then returns itself. -
disable
Disables the providedSamReaderFactory.Options, 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'sValidationStringencyto 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.Options,ValidationStringency.DEFAULT_STRINGENCY, no path wrapper, andDefaultSAMRecordFactory.
-