pub struct Reader<R> { /* private fields */ }
Expand description

A CRAM reader.

The CRAM format is comprised of four main parts: 1) a file definition, 2) a file header, 3) a list of data containers, and 4) an end-of-file (EOF) container.

Examples

use noodles_cram as cram;
use noodles_fasta as fasta;

let repository = fasta::Repository::default();

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

let header = reader.read_file_header()?.parse()?;

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

Implementations

Creates a CRAM reader.

Examples
use noodles_cram as cram;
let mut reader = File::open("sample.bam").map(cram::Reader::new)?;

Returns a reference to the underlying reader.

Examples
use noodles_cram as cram;
let data = [];
let reader = cram::Reader::new(&data[..]);
assert!(reader.get_ref().is_empty());

Returns a mutable reference to the underlying reader.

Examples
use noodles_cram as cram;
let data = [];
let mut reader = cram::Reader::new(&data[..]);
assert!(reader.get_mut().is_empty());

Unwraps and returns the underlying reader.

Examples
use noodles_cram as cram;
let data = [];
let reader = cram::Reader::new(&data[..]);
assert!(reader.into_inner().is_empty());

Reads the CRAM file definition.

The CRAM magic number is also checked.

The position of the stream is expected to be at the start.

Examples
use noodles_cram as cram;
let mut reader = File::open("sample.cram").map(cram::Reader::new)?;
let file_definition = reader.read_file_definition()?;

Reads the raw SAM header.

The position of the stream is expected to be at the CRAM header container, i.e., directly after the file definition.

This returns the raw SAM header as a String. It can subsequently be parsed as a noodles_sam::Header.

Examples
use noodles_cram as cram;

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

let header = reader.read_file_header()?;

Reads a data container.

This returns None if the container header is the EOF container header, which signals the end of the stream.

Examples
use noodles_cram as cram;

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

while let Some(container) = reader.read_data_container()? {
    // ...
}

Returns a iterator over records starting from the current stream position.

The stream is expected to be at the start of a data container.

Examples
use noodles_cram as cram;
use noodles_fasta as fasta;

let repository = fasta::Repository::default();

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

let header = reader.read_file_header()?.parse()?;

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

Seeks the underlying reader to the given position.

Positions typically come from the associated CRAM index file.

Examples
use std::io::SeekFrom;
use noodles_cram as cram;

let mut reader = File::open("sample.cram").map(cram::Reader::new)?;
reader.seek(SeekFrom::Start(17711))?;

Returns the current position of the underlying reader.

Examples
use noodles_cram as cram;
let data = Cursor::new(Vec::new());
let mut reader = cram::Reader::new(data);
let position = reader.position()?;
assert_eq!(position, 0);

Returns an iterator over records that intersects the given region.

Examples
use noodles_cram::{self as cram, crai};
use noodles_fasta as fasta;

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

let repository = fasta::Repository::default();
let header = reader.read_file_header()?.parse()?;
let index = crai::read("sample.cram.crai")?;
let region = "sq0:8-13".parse()?;
let query = reader.query(&repository, &header, &index, &region)?;

for result in query {
    let record = result?;
    // ...
}

Trait Implementations

Reads a SAM header.

Returns an iterator over records.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Should always be Self

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.