public final class GZIIndex
extends java.lang.Object
The .gzi index is a mapping between the offset of each block in the gzipped file and the
uncompressed offset that that block starts with. This mapping is represented by GZIIndex.IndexEntry
.
An example of usage for this index for random access a bgzip file using an index generated
from raw data. For example, for indexing a compressed FASTA file the .gzi index can be used in
conjunction with the FastaSequenceIndex
to seek concrete
sequences.
Modifier and Type | Class and Description |
---|---|
static class |
GZIIndex.IndexEntry
Index entry mapping the block-offset (compressed offset) to the uncompressed offset where the
block starts.
|
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
DEFAULT_EXTENSION
Default extension for the files storing a
GZIIndex . |
Modifier and Type | Method and Description |
---|---|
static GZIIndex |
buildIndex(java.nio.file.Path bgzipFile)
Builds a
GZIIndex on the fly from a BGZIP file. |
static GZIIndex |
createIndex(java.nio.file.Path bgzipFile,
boolean overwrite)
Creates a
GZIIndex from a BGZIP file and store it in memory and disk. |
boolean |
equals(java.lang.Object obj) |
java.util.List<GZIIndex.IndexEntry> |
getIndexEntries()
Gets an unmodifiable list with the index entries.
|
int |
getNumberOfBlocks()
Gets the number of blocks on the file.
|
long |
getVirtualOffsetForSeek(long uncompressedOffset)
Gets the virtual offset for seek with
BlockCompressedInputStream.seek(long) . |
int |
hashCode() |
static GZIIndex |
loadIndex(java.nio.file.Path indexPath)
Loads the index from the provided file.
|
static java.nio.file.Path |
resolveIndexNameForBgzipFile(java.nio.file.Path bgzipFile)
Gets the default index path for the bgzip file.
|
java.lang.String |
toString() |
void |
writeIndex(java.nio.file.Path output)
Writes this index into the requested path.
|
public static final java.lang.String DEFAULT_EXTENSION
GZIIndex
.public int getNumberOfBlocks()
public java.util.List<GZIIndex.IndexEntry> getIndexEntries()
Note: because the first block corresponds to a dummy index entry (0, 0), the returned list
does not include it. Thus, the size of the list is getNumberOfBlocks() - 1
.
public long getVirtualOffsetForSeek(long uncompressedOffset)
BlockCompressedInputStream.seek(long)
.
BlockCompressedInputStream.seek(long)
parameter is not a byte-offset, but a
special virtual file pointer that specifies the block-offset within the file
(BlockCompressedFilePointerUtil.getBlockAddress(long)
), and the offset within the
block (BlockCompressedFilePointerUtil.getBlockOffset(long)
).
This methods converts the provided byte-offset on the file to the special file pointer used to seek a block-compressed file, using this index to find the block where the byte-offset is located.
uncompressedOffset
- the file-offset.BlockCompressedInputStream
.BlockCompressedFilePointerUtil
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object
public void writeIndex(java.nio.file.Path output) throws java.io.IOException
output
- the output file.java.io.IOException
- if an I/O error occurs.public static final GZIIndex loadIndex(java.nio.file.Path indexPath) throws java.io.IOException
indexPath
- the path for the index to load.java.io.IOException
- if an I/O error occurs.public static final GZIIndex buildIndex(java.nio.file.Path bgzipFile) throws java.io.IOException
GZIIndex
on the fly from a BGZIP file.
Note that this method does not write the index on disk. Use writeIndex(Path)
on
the returned object to save the index.
bgzipFile
- the bgzip file.java.io.IOException
- if an I/O error occurs.public static GZIIndex createIndex(java.nio.file.Path bgzipFile, boolean overwrite) throws java.io.IOException
GZIIndex
from a BGZIP file and store it in memory and disk.bgzipFile
- the bgzip file.overwrite
- if the .fai index already exists override it if true
; otherwise, throws a IOException
.java.io.IOException
- if an IO error occurs.public static java.nio.file.Path resolveIndexNameForBgzipFile(java.nio.file.Path bgzipFile)