Bin numbers for BAI and CSI.
BAI is the special case min_shift = 14, depth = 5. That scheme covers
reference positions whose exclusive end is at most 2^29 (512 Mbp). The
on-disk BAM record stores this BAI bin in a 16-bit field. CSI uses the
same recurrence with a caller-chosen shift and depth, and it stores bin
numbers in the index as 32-bit integers.
Intervals are zero-based and half-open. The formulas are the ones in the
CSI specification, which reduce to the SAM specification's reg2bin for
the BAI parameters. A CIGAR that consumes no reference bases is given
length 1 before the bin is chosen, matching the January 2021 SAM note and
bam_endpos.
Summary
Functions
BAI bin for [beg, end), after the zero-reference-consumption rule.
Number of addressable BAI bins. Valid bin numbers are 0 until this
value, exclusive.
BAI depth. The level of 16 kbp bins is 5, and level 0 is the single bin that spans the whole addressable range.
Largest exclusive end a BAI index can store, 2^29.
Pseudo-bin used by HTSlib to store mapped and unmapped counts. For BAI this is 37450. Those chunks are metadata, not file ranges.
True when a reference of this length fits in a BAI index.
BAI min_shift.
First bin number that is not a real bin for these parameters. The
metadata pseudo-bin, when present, is bin_limit + 1.
First bin number at level. Level 0 starts at 0.
Half-open reference interval covered by bin.
Largest exclusive coordinate a CSI parameter pair can name.
Metadata pseudo-bin number.
True when the bin's interval overlaps [beg, end).
Bin that contains the half-open interval [beg, end).
Bin numbers that can overlap [beg, end).
Functions
@spec bai_bin(non_neg_integer(), non_neg_integer()) :: non_neg_integer()
BAI bin for [beg, end), after the zero-reference-consumption rule.
reference_length is the number of reference bases the CIGAR consumes.
Zero is treated as one.
@spec bai_bin_limit() :: pos_integer()
Number of addressable BAI bins. Valid bin numbers are 0 until this
value, exclusive.
@spec bai_depth() :: 5
BAI depth. The level of 16 kbp bins is 5, and level 0 is the single bin that spans the whole addressable range.
@spec bai_max_pos() :: pos_integer()
Largest exclusive end a BAI index can store, 2^29.
@spec bai_meta_bin() :: pos_integer()
Pseudo-bin used by HTSlib to store mapped and unmapped counts. For BAI this is 37450. Those chunks are metadata, not file ranges.
@spec bai_reference?(non_neg_integer()) :: boolean()
True when a reference of this length fits in a BAI index.
Length 2^29 fits, because the exclusive end of a base at the last
position is 2^29. A longer reference needs CSI.
@spec bai_shift() :: 14
BAI min_shift.
@spec bin_limit(non_neg_integer(), non_neg_integer()) :: non_neg_integer()
First bin number that is not a real bin for these parameters. The
metadata pseudo-bin, when present, is bin_limit + 1.
@spec first_bin(non_neg_integer()) :: non_neg_integer()
First bin number at level. Level 0 starts at 0.
@spec interval(non_neg_integer(), non_neg_integer(), non_neg_integer()) :: {non_neg_integer(), non_neg_integer()}
Half-open reference interval covered by bin.
@spec max_pos(non_neg_integer(), non_neg_integer()) :: pos_integer()
Largest exclusive coordinate a CSI parameter pair can name.
@spec meta_bin(non_neg_integer(), non_neg_integer()) :: non_neg_integer()
Metadata pseudo-bin number.
@spec overlaps?( non_neg_integer(), non_neg_integer(), pos_integer(), non_neg_integer(), non_neg_integer() ) :: boolean()
True when the bin's interval overlaps [beg, end).
@spec reg2bin(non_neg_integer(), pos_integer(), non_neg_integer(), non_neg_integer()) :: non_neg_integer()
Bin that contains the half-open interval [beg, end).
Examples
iex> BAM.Index.Bin.reg2bin(0, 1, 14, 5)
4681
iex> BAM.Index.Bin.reg2bin(0, 16_385, 14, 5)
585
iex> BAM.Index.Bin.reg2bin(0, 536_870_912, 14, 5)
0
@spec reg2bins(non_neg_integer(), pos_integer(), non_neg_integer(), non_neg_integer()) :: [ non_neg_integer() ]
Bin numbers that can overlap [beg, end).
The list follows the CSI reg2bins recurrence. Callers that already hold
an index should intersect it with the bins that index actually contains.