Struct noodles_cram::reader::Reader[][src]

pub struct Reader<R> where
    R: Read
{ /* fields omitted */ }
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;

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

for result in reader.records() {
    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;

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

for result in reader.records() {
    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);

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

Performs the conversion.

Performs the conversion.

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.