Package htsjdk.samtools.reference
Class FastaSequenceIndex
java.lang.Object
htsjdk.samtools.reference.FastaSequenceIndex
- All Implemented Interfaces:
Iterable<FastaSequenceIndexEntry>
Reads/writes a fasta index file (.fai), as generated by `samtools faidx`.
-
Constructor Summary
ModifierConstructorDescriptionprotected
Empty, protected constructor for unit testing.FastaSequenceIndex
(File indexFile) Build a sequence index from the specified file.Build a sequence index from the specified input stream.FastaSequenceIndex
(Path indexFile) Build a sequence index from the specified file. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
add
(FastaSequenceIndexEntry indexEntry) Add a new index entry to the list.boolean
Compare two FastaSequenceIndex objects for equality.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()
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
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
Build a sequence index from the specified file.- Parameters:
indexFile
- File to open.- Throws:
FileNotFoundException
- if the index file cannot be found.
-
FastaSequenceIndex
Build a sequence index from the specified file.- Parameters:
indexFile
- File to open.- Throws:
FileNotFoundException
- if the index file cannot be found.
-
FastaSequenceIndex
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
Add a new index entry to the list. Protected for unit testing.- Parameters:
indexEntry
- New index entry to add.
-
rename
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
Compare two FastaSequenceIndex objects for equality. -
hashCode
public int hashCode() -
write
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
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
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
Creates an iterator which can iterate through all entries in a fasta index.- Specified by:
iterator
in interfaceIterable<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.
-