Package htsjdk.samtools.reference

# Class FastaSequenceIndex

java.lang.Object
htsjdk.samtools.reference.FastaSequenceIndex

All Implemented Interfaces:
  `Iterable<FastaSequenceIndexEntry>`

public class FastaSequenceIndex extends Object implements Iterable<FastaSequenceIndexEntry>
Reads/writes a fasta index file (.fai), as generated by `samtools faidx`.

## Constructor Summary

Constructors
Modifier
Constructor
Description
`protected`
`FastaSequenceIndex()`
Empty, protected constructor for unit testing.
``
`FastaSequenceIndex(File indexFile)`
Build a sequence index from the specified file.
``
`FastaSequenceIndex(InputStream in)`
Build a sequence index from the specified input stream.
``
`FastaSequenceIndex(Path indexFile)`
Build a sequence index from the specified file.

## Method Summary

Modifier and Type
Method
Description
`protected void`
`add(FastaSequenceIndexEntry indexEntry)`
Add a new index entry to the list.
`boolean`
`equals(Object other)`
Compare two FastaSequenceIndex objects for equality.
`FastaSequenceIndexEntry`
`getIndexEntry(String contigName)`
Retrieve the index entry associated with the given contig.
`int`
`hashCode()`
`boolean`
`hasIndexEntry(String contigName)`
Does the given contig name have a corresponding entry?
`Iterator<FastaSequenceIndexEntry>`
`iterator()`
Creates an iterator which can iterate through all entries in a fasta index.
`protected void`
`rename(FastaSequenceIndexEntry entry, String newName)`
Renames the existing index entry to the new index entry with the specified name.
`int`
`size()`
Returns the number of elements in the index.
`void`
`write(Path indexFile)`
Writes this index to the specified path.

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

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

### Methods inherited from interface java.lang.Iterable

`forEach, spliterator`

## Constructor Details

### FastaSequenceIndex

public FastaSequenceIndex(File indexFile)
Build a sequence index from the specified file.

Parameters:
  `indexFile` - File to open.
Throws:
  `FileNotFoundException` - if the index file cannot be found.

### FastaSequenceIndex

public FastaSequenceIndex(Path indexFile)
Build a sequence index from the specified file.

Parameters:
  `indexFile` - File to open.
Throws:
  `FileNotFoundException` - if the index file cannot be found.

### FastaSequenceIndex

public FastaSequenceIndex(InputStream in)
Build a sequence index from the specified input stream.

Parameters:
  `in` - InputStream to read from.

### FastaSequenceIndex

protected FastaSequenceIndex()
Empty, protected constructor for unit testing.

## Method Details

### add

protected void add(FastaSequenceIndexEntry indexEntry)
Add a new index entry to the list. Protected for unit testing.

Parameters:
  `indexEntry` - New index entry to add.

### rename

protected void rename(FastaSequenceIndexEntry entry, String newName)
Renames the existing index entry to the new index entry with the specified name.

Parameters:
  `entry` - entry to update.
  `newName` - New name for the index entry.

### equals

public boolean equals(Object other)
Compare two FastaSequenceIndex objects for equality.

Overrides:
  `equals` in class `Object`
Parameters:
  `other` - Another FastaSequenceIndex to compare
Returns:
  True if index has the same entries as other instance, in the same order

### hashCode

public int hashCode()

Overrides:
  `hashCode` in class `Object`

### write

public void write(Path indexFile) throws IOException
Writes this index to the specified path.

Parameters:
  `indexFile` - index file to output the index in the .fai format
Throws:
  `IOException` - if an IO error occurs.

### hasIndexEntry

public boolean hasIndexEntry(String contigName)
Does the given contig name have a corresponding entry?

Parameters:
  `contigName` - The contig name for which to search.
Returns:
  True if contig name is present; false otherwise.

### getIndexEntry

public FastaSequenceIndexEntry getIndexEntry(String contigName)
Retrieve the index entry associated with the given contig.

Parameters:
  `contigName` - Name of the contig for which to search.
Returns:
  Index entry associated with the given contig.
Throws:
  `SAMException` - if the associated index entry can't be found.

### iterator

public Iterator<FastaSequenceIndexEntry> iterator()
Creates an iterator which can iterate through all entries in a fasta index.

Specified by:
  `iterator` in interface `Iterable<FastaSequenceIndexEntry>`
Returns:
  iterator over all fasta index entries.

### size

public int size()
Returns the number of elements in the index.

Returns:
  Number of elements in the index.