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
finalSamReaderFactoryfactory = 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
finalSamReaderFactoryfactory = SamReaderFactory.makeDefault() .enable(SamReaderFactory.Option.INCLUDE_SOURCE_IN_RECORDS,SamReaderFactory.Option.VALIDATE_CRC_CHECKSUMS) .validationStringency(ValidationStringency.SILENT); // File-based bam finalSamReaderfileReader = factory.open(new File("/my/bam.bam")); // HTTP-hosted BAM with index from an arbitrary stream final SeekableStream myBamIndexStream = ... finalSamInputResourceresource =SamInputResource.of(new URL("http://example.com/data.bam")).index(myBamIndexStream); finalSamReadercomplicatedReader = factory.open(resource);
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classSamReaderFactory.OptionA collection of binarySamReaderFactoryoptions.
-
Constructor Summary
Constructors Constructor Description SamReaderFactory()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract 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 SamReaderFactorymakeDefault()Creates a copy of the defaultSamReaderFactory.abstract SamReaderopen(SamInputResource resource)abstract SamReaderopen(File file)SamReaderopen(Path path)Open the specified path (without using any wrappers).SamReaderopen(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 CRAMReferenceSourcereferenceSource()abstract 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 ValidationStringencyvalidationStringency()abstract SamReaderFactoryvalidationStringency(ValidationStringency validationStringency)Set this factory'sValidationStringencyto 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'sSAMRecordFactoryto the provided one, then returns itself.
-
inflaterFactory
public abstract SamReaderFactory inflaterFactory(InflaterFactory 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
public abstract SamReaderFactory enable(SamReaderFactory.Option... options)
Enables the providedSamReaderFactory.Options, then returns itself.
-
disable
public abstract SamReaderFactory disable(SamReaderFactory.Option... options)
Disables the providedSamReaderFactory.Options, 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'sValidationStringencyto 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.Options,ValidationStringency.DEFAULT_STRINGENCY, no path wrapper, andDefaultSAMRecordFactory.
-
-