noodles_bam/bai.rs
1//! BAM index (BAI) and fields.
2//!
3//! A BAM index (BAI) is used with an associated coordinate-sorted BAM file that allows random
4//! access to records, e.g., [querying].
5//!
6//! The index contains a list of reference sequences parallel to the one defined in the BAM file.
7//! Each indexed reference sequence has a calculated set of hierarchical bins at different
8//! granularities. The bins then define a list of physical file positions in the BAM to search for
9//! overlapping records.
10//!
11//! When reading entire BAM files sequentially, a BAM index is not necessary.
12//!
13//! [querying]: crate::io::Reader::query
14//!
15//! # Examples
16//!
17//! ## Reading a BAM index
18//!
19//! ```no_run
20//! # use std::io;
21//! use noodles_bam::bai;
22//! let index = bai::fs::read("sample.bam.bai")?;
23//! # Ok::<(), io::Error>(())
24//! ```
25
26#[cfg(feature = "async")]
27pub mod r#async;
28
29pub mod fs;
30pub mod io;
31
32use noodles_csi::binning_index::{self, index::reference_sequence::index::LinearIndex};
33
34const DEPTH: u8 = 5;
35
36const MAGIC_NUMBER: [u8; 4] = *b"BAI\x01";
37
38/// A BAM index.
39pub type Index = binning_index::Index<LinearIndex>;