Expand description

noodles-bam handles the reading and writing of the BAM (Binary Alignment/Map) file format.

The BAM format contains the same information as SAM (Sequence Alignment/Map), namely a SAM header and a list of records.


Read all records

use noodles_bam as bam;

let mut reader = File::open("sample.bam").map(bam::Reader::new)?;

for result in reader.records() {
    let record = result?;
    println!("{:?}", record);

Query records

Querying allows filtering records by region. It requires an associated BAM index (BAI).

use noodles_bam::{self as bam, bai};
use noodles_core::Region;
use noodles_sam as sam;

let mut reader = File::open("sample.bam").map(bam::Reader::new)?;
let header: sam::Header = reader.read_header()?.parse()?;

let reference_sequences = header.reference_sequences();
let index = bai::read("sample.bam.bai")?;
let region = "sq0:5-8".parse()?;
let query = reader.query(&reference_sequences, &index, &region)?;

for result in query {
    let record = result?;
    println!("{:?}", record);


pub use self::reader::Reader;
pub use self::writer::Writer;


BAM index (BAI) and fields.

Lazily-evaluated BAM record and fields.

BAM reader and iterators.

BAM record and fields.

BAM writer.


An async BAM reader.

An async BAM writer.