Package htsjdk.samtools
Class AbstractBAMFileIndex
java.lang.Object
htsjdk.samtools.AbstractBAMFileIndex
- All Implemented Interfaces:
BAMIndex
,Closeable
,AutoCloseable
- Direct Known Subclasses:
CSIIndex
,DiskBasedBAMFileIndex
Provides basic, generic capabilities to be used reading BAM index files. Users can
subclass this class to create new BAM index functionality for adding querying facilities,
changing caching behavior, etc.
Of particular note: the AbstractBAMFileIndex is, by design, the only class aware of the
details of the BAM index file format (other than the four classes representing the data,
BAMIndexContent, Bin, Chunk, LinearIndex, and the classes for building the BAM index).
Anyone wanting to implement a reader for a differing
or extended BAM index format should implement BAMIndex directly.
-
Field Summary
Fields inherited from interface htsjdk.samtools.BAMIndex
BAI_INDEX_SUFFIX, BAMIndexSuffix, CSI_INDEX_SUFFIX
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
AbstractBAMFileIndex
(htsjdk.samtools.IndexFileBuffer indexFileBuffer, String source, SAMSequenceDictionary dictionary) protected
AbstractBAMFileIndex
(SeekableStream stream, SAMSequenceDictionary dictionary) protected
AbstractBAMFileIndex
(File file, SAMSequenceDictionary dictionary) protected
AbstractBAMFileIndex
(File file, SAMSequenceDictionary dictionary, boolean useMemoryMapping) -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Close this index and release any associated resources.protected final SAMSequenceDictionary
static int
getFirstBinInLevel
(int levelNumber) Gets the first bin in the given level.int
getFirstLocusInBin
(Bin bin) Gets the first locus that this bin can index into.int
getLastLocusInBin
(Bin bin) Gets the last locus that this bin can index into.int
getLevelForBin
(Bin bin) Gets the level associated with the given bin number.int
getLevelSize
(int levelNumber) Gets the number of bins in the given level.protected int
Gets the possible number of bins for a given reference sequence.getMetaData
(int reference) Return meta data for the given reference including information about number of aligned, unaligned, and noCoordinate recordsReturns count of records unassociated with any reference.int
static int
Get the number of levels employed by this index.protected abstract htsjdk.samtools.BAMIndexContent
getQueryResults
(int reference) long
Use to get close to the unmapped reads at the end of a BAM file.protected void
Initialization method used for simplifying the constructor hierarchy.optimizeChunkList
(List<Chunk> chunks, long minimumOffset) Deprecated.protected final long
position()
protected htsjdk.samtools.BAMIndexContent
query
(int referenceSequence, int startPos, int endPos) protected final void
readBytes
(byte[] bytes) protected void
readChunks
(int nChunks, List<Chunk> chunks) protected final int
protected final long
readLong()
protected BitSet
regionToBins
(int startPos, int endPos) Deprecated.UseGenomicIndexUtil.regionToBins(int, int)
instead.protected final void
seek
(long position) protected final void
setSequenceIndexes
(int nReferences) protected final void
skipBytes
(int count) protected void
skipToSequence
(int sequenceIndex) protected void
verifyIndexMagicNumber
(String sourceName) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface htsjdk.samtools.BAMIndex
getSpanOverlapping
-
Constructor Details
-
AbstractBAMFileIndex
-
AbstractBAMFileIndex
-
AbstractBAMFileIndex
protected AbstractBAMFileIndex(File file, SAMSequenceDictionary dictionary, boolean useMemoryMapping) -
AbstractBAMFileIndex
protected AbstractBAMFileIndex(htsjdk.samtools.IndexFileBuffer indexFileBuffer, String source, SAMSequenceDictionary dictionary)
-
-
Method Details
-
close
public void close()Close this index and release any associated resources. -
getNumIndexLevels
public static int getNumIndexLevels()Get the number of levels employed by this index.- Returns:
- Number of levels in this index.
-
getFirstBinInLevel
public static int getFirstBinInLevel(int levelNumber) Gets the first bin in the given level.- Parameters:
levelNumber
- Level number. 0-based.- Returns:
- The first bin in this level.
-
getLevelSize
public int getLevelSize(int levelNumber) Gets the number of bins in the given level.- Parameters:
levelNumber
- Level number. 0-based.- Returns:
- The size (number of possible bins) of the given level.
-
getLevelForBin
Gets the level associated with the given bin number.- Parameters:
bin
- The bin for which to determine the level.- Returns:
- the level associated with the given bin number.
-
getFirstLocusInBin
Gets the first locus that this bin can index into.- Parameters:
bin
- The bin to test.- Returns:
- The last position that the given bin can represent.
-
getLastLocusInBin
Gets the last locus that this bin can index into.- Parameters:
bin
- The bin to test.- Returns:
- The last position that the given bin can represent.
-
getNumberOfReferences
public int getNumberOfReferences() -
getStartOfLastLinearBin
public long getStartOfLastLinearBin()Use to get close to the unmapped reads at the end of a BAM file.- Specified by:
getStartOfLastLinearBin
in interfaceBAMIndex
- Returns:
- The file offset of the first record in the last linear bin, or -1 if there are no elements in linear bins (i.e. no mapped reads).
-
getMetaData
Return meta data for the given reference including information about number of aligned, unaligned, and noCoordinate records- Specified by:
getMetaData
in interfaceBAMIndex
- Parameters:
reference
- the reference of interest- Returns:
- meta data for the reference
-
getNoCoordinateCount
Returns count of records unassociated with any reference. Call before the index file is closed- Returns:
- meta data at the end of the bam index that indicates count of records holding no coordinates or null if no meta data (old index format)
-
query
protected htsjdk.samtools.BAMIndexContent query(int referenceSequence, int startPos, int endPos) -
getQueryResults
protected abstract htsjdk.samtools.BAMIndexContent getQueryResults(int reference) -
getMaxAddressibleGenomicLocation
protected int getMaxAddressibleGenomicLocation()Gets the possible number of bins for a given reference sequence.- Returns:
- How many bins could possibly be used according to this indexing scheme to index a single contig.
-
regionToBins
Deprecated.UseGenomicIndexUtil.regionToBins(int, int)
instead. Get candidate bins for the specified region- Parameters:
startPos
- 1-based start of target region, inclusive.endPos
- 1-based end of target region, inclusive.- Returns:
- bit set for each bin that may contain SAMRecords in the target region.
-
optimizeChunkList
Deprecated.InvokeChunk.optimizeChunkList(java.util.List<htsjdk.samtools.Chunk>, long)
directly. -
verifyIndexMagicNumber
-
initParameters
protected void initParameters()Initialization method used for simplifying the constructor hierarchy. -
readChunks
-
skipToSequence
protected void skipToSequence(int sequenceIndex) -
readBytes
protected final void readBytes(byte[] bytes) -
readInteger
protected final int readInteger() -
readLong
protected final long readLong() -
skipBytes
protected final void skipBytes(int count) -
seek
protected final void seek(long position) -
position
protected final long position() -
getBamDictionary
-
setSequenceIndexes
protected final void setSequenceIndexes(int nReferences)
-
Chunk.optimizeChunkList(java.util.List<htsjdk.samtools.Chunk>, long)
directly.