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
         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
Modifier and Type
Class
Description
`static enum`
`SamReaderFactory.Option`
A collection of binary `SamReaderFactory` options.

## Constructor Summary

Constructors
Constructor
Description
`SamReaderFactory()`

## Method Summary

Modifier and Type
Method
Description
`abstract SamReaderFactory`
`disable(SamReaderFactory.Option... options)`
Disables the provided `SamReaderFactory.Option`s, then returns itself.
`abstract SamReaderFactory`
`enable(SamReaderFactory.Option... options)`
Enables the provided `SamReaderFactory.Option`s, then returns itself.
`abstract SAMFileHeader`
`getFileHeader(File samFile)`
Utility method to open the file get the header and close the file
`abstract SAMFileHeader`
`getFileHeader(Path samFile)`
Utility method to open the file get the header and close the file
`abstract SamReaderFactory`
`inflaterFactory(InflaterFactory inflaterFactory)`
Set this factory's `InflaterFactory` to the provided one, then returns itself.
`static SamReaderFactory`
`make()`
Creates an "empty" factory with no enabled `SamReaderFactory.Option`s, `ValidationStringency.DEFAULT_STRINGENCY`, no path wrapper, and `DefaultSAMRecordFactory`.
`static SamReaderFactory`
`makeDefault()`
Creates a copy of the default `SamReaderFactory`.
`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's `SAMRecordFactory` 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's `ValidationStringency` to the provided one, then returns itself.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### SamReaderFactory

public SamReaderFactory()

## Method Details

### open

public abstract SamReader open(File file)

### 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 open
  `dataWrapper` - 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's `SAMRecordFactory` to the provided one, then returns itself.

### inflaterFactory

public abstract SamReaderFactory inflaterFactory(InflaterFactory inflaterFactory)
Set this factory's `InflaterFactory` to the provided one, then returns itself. Note: The inflaterFactory provided here is only used for BAM decompression implemented with `BAMFileReader`, it is not used for CRAM or other formats like a gzipped SAM file.

### enable

public abstract SamReaderFactory enable(SamReaderFactory.Option... options)
Enables the provided `SamReaderFactory.Option`s, then returns itself.

### disable

public abstract SamReaderFactory disable(SamReaderFactory.Option... options)
Disables the provided `SamReaderFactory.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's `ValidationStringency` 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 of `Defaults.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 default `SamReaderFactory`.

### make

public static SamReaderFactory make()
Creates an "empty" factory with no enabled `SamReaderFactory.Option`s, `ValidationStringency.DEFAULT_STRINGENCY`, no path wrapper, and `DefaultSAMRecordFactory`.