Class AbstractBAMFileIndex

java.lang.Object
htsjdk.samtools.AbstractBAMFileIndex
All Implemented Interfaces:
BAMIndex, Closeable, AutoCloseable
Direct Known Subclasses:
CSIIndex, DiskBasedBAMFileIndex

public abstract class AbstractBAMFileIndex extends Object implements BAMIndex
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.
  • Constructor Details

  • Method Details

    • close

      public void close()
      Close this index and release any associated resources.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface BAMIndex
      Specified by:
      close in interface Closeable
    • 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

      public int getLevelForBin(Bin bin)
      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

      public int getFirstLocusInBin(Bin bin)
      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

      public int getLastLocusInBin(Bin bin)
      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 interface BAMIndex
      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

      public BAMIndexMetaData getMetaData(int reference)
      Return meta data for the given reference including information about number of aligned, unaligned, and noCoordinate records
      Specified by:
      getMetaData in interface BAMIndex
      Parameters:
      reference - the reference of interest
      Returns:
      meta data for the reference
    • getNoCoordinateCount

      public Long 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 protected BitSet regionToBins(int startPos, int endPos)
      Deprecated.
      Use GenomicIndexUtil.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 protected List<Chunk> optimizeChunkList(List<Chunk> chunks, long minimumOffset)
    • verifyIndexMagicNumber

      protected void verifyIndexMagicNumber(String sourceName)
    • initParameters

      protected void initParameters()
      Initialization method used for simplifying the constructor hierarchy.
    • readChunks

      protected void readChunks(int nChunks, List<Chunk> chunks)
    • 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

      protected final SAMSequenceDictionary getBamDictionary()
    • setSequenceIndexes

      protected final void setSequenceIndexes(int nReferences)