Struct noodles_bcf::Reader[][src]

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

A BCF reader.

The BCF format is comprised of two parts: 1) a VCF header and 2) a list of records.

Implementations

Creates a BCF reader.

Examples

use noodles_bcf as bcf;
let data = [];
let reader = bcf::Reader::new(&data[..]);

Reads the BCF file format.

The BCF magic number is also checked.

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

This returns the major and minor format versions as a tuple.

Examples

use noodles_bcf as bcf;
let mut reader = File::open("sample.bcf").map(bcf::Reader::new)?;
let (major, minor) = reader.read_file_format()?;

Reads the raw VCF header.

The position of the stream is expected to be directly after the file format.

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

Examples

use noodles_bcf as bcf;
let mut reader = File::open("sample.bcf").map(bcf::Reader::new)?;
reader.read_file_format()?;
let header = reader.read_header()?;

Reads a single record.

The stream is expected to be directly after the header or at the start of another record.

It is more ergnomic to read records using an iterator (see Self::records), but using this method directly allows the reuse of a single Record buffer.

If successful, the record size is returned. If a record size of 0 is returned, the stream reached EOF.

Examples

use noodles_bcf as bcf;

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

let mut record = bcf::Record::default();
reader.read_record(&mut record)?;

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

The stream is expected to be directly after the header or at the start of another record.

Examples

use noodles_bcf as bcf;

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

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

Returns the current virtual position of the underlying BGZF reader.

Examples

use noodles_bcf as bcf;

let data = Vec::new();
let reader = bcf::Reader::new(&data[..]);
let virtual_position = reader.virtual_position();

assert_eq!(virtual_position.compressed(), 0);
assert_eq!(virtual_position.uncompressed(), 0);

Seeks the underlying BGZF reader to the given virtual position.

Virtual positions typically come from an associated BCF index file.

Examples

use noodles_bcf as bcf;
use noodles_bgzf as bgzf;

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

let virtual_position = bgzf::VirtualPosition::from(102334155);
reader.seek(virtual_position)?;

Returns an iterator over records that intersects the given region.

Examples

use noodles_bcf as bcf;
use noodles_core::Region;
use noodles_csi as csi;
use noodles_vcf as vcf;

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

let header: vcf::Header = reader.read_header()?.parse()?;
let contigs = header.contigs();

let index = csi::read("sample.bcf.csi")?;
let region = Region::mapped("sq0", 8..=13);
let query = reader.query(&contigs, &index, &region)?;

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

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.

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.