Package htsjdk.samtools
Class SamReaderFactory
- java.lang.Object
-
- htsjdk.samtools.SamReaderFactory
-
public abstract class SamReaderFactory extends Object
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 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
Nested Classes Modifier and Type Class Description static class
SamReaderFactory.Option
A collection of binarySamReaderFactory
options.
-
Constructor Summary
Constructors Constructor Description SamReaderFactory()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract 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
makeDefault()
Creates a copy of the defaultSamReaderFactory
.abstract SamReader
open(SamInputResource resource)
abstract SamReader
open(File file)
SamReader
open(Path path)
Open the specified path (without using any wrappers).SamReader
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
referenceSource()
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
validationStringency()
abstract SamReaderFactory
validationStringency(ValidationStringency validationStringency)
Set this factory'sValidationStringency
to the provided one, then returns itself.
-
-
-
Method Detail
-
open
public SamReader open(Path path)
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
public abstract SamReader open(SamInputResource resource)
-
validationStringency
public abstract ValidationStringency validationStringency()
-
referenceSource
public abstract CRAMReferenceSource referenceSource()
-
samRecordFactory
public abstract SamReaderFactory samRecordFactory(SAMRecordFactory samRecordFactory)
Set this factory'sSAMRecordFactory
to the provided one, then returns itself.
-
inflaterFactory
public abstract SamReaderFactory inflaterFactory(InflaterFactory 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
public abstract SamReaderFactory enable(SamReaderFactory.Option... options)
Enables the providedSamReaderFactory.Option
s, then returns itself.
-
disable
public abstract SamReaderFactory disable(SamReaderFactory.Option... options)
Disables the providedSamReaderFactory.Option
s, then returns itself.
-
setOption
public abstract SamReaderFactory setOption(SamReaderFactory.Option option, boolean value)
Sets a specific Option to a boolean value. *
-
referenceSequence
public abstract SamReaderFactory referenceSequence(File referenceSequence)
Sets the specified reference sequence *
-
referenceSequence
public abstract SamReaderFactory referenceSequence(Path referenceSequence)
Sets the specified reference sequence.
-
referenceSource
public abstract SamReaderFactory referenceSource(CRAMReferenceSource referenceSequence)
Sets the specified reference sequence *
-
getFileHeader
public abstract SAMFileHeader getFileHeader(File samFile)
Utility method to open the file get the header and close the file
-
getFileHeader
public abstract SAMFileHeader getFileHeader(Path samFile)
Utility method to open the file get the header and close the file
-
reapplyOptions
public abstract void reapplyOptions(SamReader reader)
Reapplies any changed options to the reader *
-
validationStringency
public abstract SamReaderFactory validationStringency(ValidationStringency validationStringency)
Set this factory'sValidationStringency
to the provided one, then returns itself.
-
setUseAsyncIo
public abstract SamReaderFactory setUseAsyncIo(boolean asynchronousIO)
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
public static void setDefaultValidationStringency(ValidationStringency defaultValidationStringency)
-
makeDefault
public static SamReaderFactory makeDefault()
Creates a copy of the defaultSamReaderFactory
.
-
make
public static SamReaderFactory make()
Creates an "empty" factory with no enabledSamReaderFactory.Option
s,ValidationStringency.DEFAULT_STRINGENCY
, no path wrapper, andDefaultSAMRecordFactory
.
-
-