# Class BlockCompressedIndexedFastaSequenceFile

java.lang.Object
htsjdk.samtools.reference.BlockCompressedIndexedFastaSequenceFile

All Implemented Interfaces:
  `ReferenceSequenceFile, Closeable, AutoCloseable`

public class BlockCompressedIndexedFastaSequenceFile extends Object
A block-compressed FASTA file driven by an index for fast lookups.

Supports two interfaces: the ReferenceSequenceFile for old-style, stateful lookups and a direct getter.

## Constructor Summary

Constructors
Constructor
Description
`BlockCompressedIndexedFastaSequenceFile(IOPath fastaPath, IOPath dictPath, FastaSequenceIndex index, GZIIndex gziIndex)`
Create a BlockCompressedIndexedFastaSequenceFile from explicitly provided files.
`BlockCompressedIndexedFastaSequenceFile(String source, SeekableStream in, FastaSequenceIndex index, SAMSequenceDictionary dictionary, GZIIndex gziIndex)`
Initialize the given indexed fasta sequence file stream.
`BlockCompressedIndexedFastaSequenceFile(Path path)`
`BlockCompressedIndexedFastaSequenceFile(Path path, FastaSequenceIndex index)`
`BlockCompressedIndexedFastaSequenceFile(Path path, FastaSequenceIndex index, GZIIndex gziIndex)`

## Method Summary

Modifier and Type
Method
Description
`void`
`close()`
`protected SAMSequenceDictionary`
`findAndLoadSequenceDictionary(Path fasta)`
Attempts to find and load the sequence dictionary if present.
`protected static Path`
`findFastaIndex(Path fastaFile)`
`protected static Path`
`findRequiredFastaIndexFile(Path fastaFile)`
`protected static File`
`findSequenceDictionary(File file)`
Deprecated.
use findSequenceDictionary(Path) instead.
`protected static Path`
`findSequenceDictionary(Path fastaPath)`
Attempts to locate the sequence dictionary file adjacent to the reference fasta file.
`protected String`
`getAbsolutePath()`
Returns the full path to the reference file.
`FastaSequenceIndex`
`getIndex()`
`protected Path`
`getPath()`
Returns the path to the reference file.
`ReferenceSequence`
`getSequence(String contig)`
Retrieves the complete sequence described by this contig.
`SAMSequenceDictionary`
`getSequenceDictionary()`
Returns the list of sequence records associated with the reference sequence if found otherwise null.
`protected String`
`getSource()`
Returns the named source of the reference file.
`ReferenceSequence`
`getSubsequenceAt(String contig, long start, long stop)`
Gets the subsequence of the contig in the range [start,stop]
`final boolean`
`isIndexed()`
default implementation -- override if index is supported
`protected static SAMSequenceDictionary`
`loadSequenceDictionary(IOPath dictPath)`
Attempt to load a sequence dictionary given a file path.
`ReferenceSequence`
`nextSequence()`
Gets the next sequence if available, or null if not present.
`protected int`
`readFromPosition(ByteBuffer buffer, long position)`
Reads a sequence of bytes from this sequence file into the given buffer, starting at the given file position.
`void`
`reset()`
Reset the iterator over the index.
`protected static void`
`sanityCheckDictionaryAgainstIndex(String fastaFile, SAMSequenceDictionary sequenceDictionary, FastaSequenceIndex index)`
Do some basic checking to make sure the dictionary and the index match.
`String`
`toString()`
Returns the full path to the reference file, or the source if no path was specified.

### Methods inherited from class Object

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

### Methods inherited from interface ReferenceSequenceFile

`getSubsequenceAt`

## Constructor Details

### BlockCompressedIndexedFastaSequenceFile

public BlockCompressedIndexedFastaSequenceFile(Path path) throws FileNotFoundException

Throws:
  `FileNotFoundException`

### BlockCompressedIndexedFastaSequenceFile

public BlockCompressedIndexedFastaSequenceFile(IOPath fastaPath, IOPath dictPath, FastaSequenceIndex index, GZIIndex gziIndex)
Create a BlockCompressedIndexedFastaSequenceFile from explicitly provided files. No assumptions are made about the relative location of the files (i.e., no assumption is made that they are siblings).

Parameters:
  `fastaPath` - the fasta file
  `dictPath` - the associated dictionary file
  `index` - the associated index
  `gziIndex` - the associated gziIndex

### BlockCompressedIndexedFastaSequenceFile

public BlockCompressedIndexedFastaSequenceFile(Path path, FastaSequenceIndex index)

### BlockCompressedIndexedFastaSequenceFile

public BlockCompressedIndexedFastaSequenceFile(Path path, FastaSequenceIndex index, GZIIndex gziIndex)

### BlockCompressedIndexedFastaSequenceFile

public BlockCompressedIndexedFastaSequenceFile(String source, SeekableStream in, FastaSequenceIndex index, SAMSequenceDictionary dictionary, GZIIndex gziIndex)
Initialize the given indexed fasta sequence file stream.

Parameters:
  `source` - The named source of the reference file (used in error messages).
  `in` - The input stream to read the fasta file from; should not be decompressed already.
  `index` - The fasta index.
  `dictionary` - The sequence dictionary, or null if there isn't one.
  `gziIndex` - The GZI index; may not be null.

## Method Details

### readFromPosition

protected int readFromPosition(ByteBuffer buffer, long position) throws IOException
Reads a sequence of bytes from this sequence file into the given buffer, starting at the given file position.

Parameters:
  `buffer` - the buffer into which bytes are to be transferred
  `position` - the position to start reading at
Returns:
  the number of bytes read
Throws:
  `IOException` - if an I/O error occurs while reading

### close

public void close() throws IOException

Throws:
  `IOException`

### findRequiredFastaIndexFile

protected static Path findRequiredFastaIndexFile(Path fastaFile) throws FileNotFoundException

Throws:
  `FileNotFoundException`

### findFastaIndex

protected static Path findFastaIndex(Path fastaFile)

### sanityCheckDictionaryAgainstIndex

protected static void sanityCheckDictionaryAgainstIndex(String fastaFile, SAMSequenceDictionary sequenceDictionary, FastaSequenceIndex index)
Do some basic checking to make sure the dictionary and the index match.

Parameters:
  `fastaFile` - Used for error reporting only.
  `sequenceDictionary` - sequence dictionary to check against the index.
  `index` - index file to check against the dictionary.

### getIndex

public FastaSequenceIndex getIndex()

### nextSequence

public ReferenceSequence nextSequence()
Gets the next sequence if available, or null if not present.

Returns:
  next sequence if available, or null if not present.

### reset

public void reset()
Reset the iterator over the index.

### isIndexed

public final boolean isIndexed()
default implementation -- override if index is supported

Specified by:
  `isIndexed` in interface `ReferenceSequenceFile`
Returns:
  true if getSequence and getSubsequenceAt methods are allowed.

### getSequence

public ReferenceSequence getSequence(String contig)
Retrieves the complete sequence described by this contig.

Specified by:
  `getSequence` in interface `ReferenceSequenceFile`
Parameters:
  `contig` - contig whose data should be returned.
Returns:
  The full sequence associated with this contig.

### getSubsequenceAt

public ReferenceSequence getSubsequenceAt(String contig, long start, long stop)
Gets the subsequence of the contig in the range [start,stop]

Specified by:
  `getSubsequenceAt` in interface `ReferenceSequenceFile`
Parameters:
  `contig` - Contig whose subsequence to retrieve.
  `start` - inclusive, 1-based start of region.
  `stop` - inclusive, 1-based stop of region.
Returns:
  The partial reference sequence associated with this range.

### findAndLoadSequenceDictionary

protected SAMSequenceDictionary findAndLoadSequenceDictionary(Path fasta)
Attempts to find and load the sequence dictionary if present.

### loadSequenceDictionary

protected static SAMSequenceDictionary loadSequenceDictionary(IOPath dictPath)
Attempt to load a sequence dictionary given a file path. Path may be null.

Parameters:
  `dictPath` - the dictionary file to open
Returns:
  the SAMSequenceDictionary, or null

### findSequenceDictionary

@Deprecated protected static File findSequenceDictionary(File file)
Deprecated.
use findSequenceDictionary(Path) instead.

### findSequenceDictionary

protected static Path findSequenceDictionary(Path fastaPath)
Attempts to locate the sequence dictionary file adjacent to the reference fasta file.

### getPath

protected Path getPath()
Returns the path to the reference file.

### getSource

protected String getSource()
Returns the named source of the reference file.

### getSequenceDictionary

public SAMSequenceDictionary getSequenceDictionary()
Returns the list of sequence records associated with the reference sequence if found otherwise null.

Specified by:
  `getSequenceDictionary` in interface `ReferenceSequenceFile`
Returns:
  a list of sequence records representing the sequences in this reference file

### getAbsolutePath

protected String getAbsolutePath()
Returns the full path to the reference file.

### toString

public String toString()
Returns the full path to the reference file, or the source if no path was specified.

Specified by:
  `toString` in interface `ReferenceSequenceFile`
Overrides:
  `toString` in class `Object`
Returns:
  Reference name, file name, or something other human-readable representation.