pub struct Reader<R> { /* private fields */ }
Expand description
A BCF reader.
The BCF format is comprised of two parts: 1) a VCF header and 2) a list of records.
Implementations
sourceimpl<R> Reader<R> where
R: Read,
impl<R> Reader<R> where
R: Read,
sourcepub fn get_ref(&self) -> &R
pub fn get_ref(&self) -> &R
Returns a reference to the underlying reader.
Examples
use noodles_bcf as bcf;
let data = [];
let reader = bcf::Reader::from(&data[..]);
assert!(reader.get_ref().is_empty());
sourcepub fn get_mut(&mut self) -> &mut R
pub fn get_mut(&mut self) -> &mut R
Returns a mutable reference to the underlying reader.
Examples
use noodles_bcf as bcf;
let data = [];
let mut reader = bcf::Reader::from(&data[..]);
assert!(reader.get_mut().is_empty());
sourcepub fn into_inner(self) -> R
pub fn into_inner(self) -> R
Returns the underlying reader.
Examples
use noodles_bcf as bcf;
let data = [];
let reader = bcf::Reader::from(&data[..]);
assert!(reader.into_inner().is_empty());
sourcepub fn read_file_format(&mut self) -> Result<(u8, u8), Error>
pub fn read_file_format(&mut self) -> Result<(u8, u8), Error>
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()?;
sourcepub fn read_header(&mut self) -> Result<String, Error>
pub fn read_header(&mut self) -> Result<String, Error>
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()?;
sourcepub fn read_record(&mut self, record: &mut Record) -> Result<usize, Error>
pub fn read_record(&mut self, record: &mut Record) -> Result<usize, Error>
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)?;
sourcepub fn records(&mut self) -> Records<'_, R>ⓘNotable traits for Records<'a, R>impl<'a, R> Iterator for Records<'a, R> where
R: Read, type Item = Result<Record, Error>;
pub fn records(&mut self) -> Records<'_, R>ⓘNotable traits for Records<'a, R>impl<'a, R> Iterator for Records<'a, R> where
R: Read, type Item = Result<Record, Error>;
R: Read, type Item = Result<Record, Error>;
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);
}
sourceimpl<R> Reader<Reader<R>> where
R: Read,
impl<R> Reader<Reader<R>> where
R: Read,
sourcepub fn new(reader: R) -> Reader<Reader<R>>
pub fn new(reader: R) -> Reader<Reader<R>>
Creates a BCF reader.
Examples
use noodles_bcf as bcf;
let data = [];
let reader = bcf::Reader::new(&data[..]);
sourcepub fn virtual_position(&self) -> VirtualPosition
pub fn virtual_position(&self) -> VirtualPosition
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);
sourceimpl<R> Reader<Reader<R>> where
R: Read + Seek,
impl<R> Reader<Reader<R>> where
R: Read + Seek,
sourcepub fn seek(&mut self, pos: VirtualPosition) -> Result<VirtualPosition, Error>
pub fn seek(&mut self, pos: VirtualPosition) -> Result<VirtualPosition, Error>
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)?;
sourcepub fn query<I, RS>(
&mut self,
contig_string_map: &StringMap,
index: &I,
region: &Region
) -> Result<Query<'_, R>, Error> where
I: BinningIndex<RS>,
RS: ReferenceSequenceExt,
pub fn query<I, RS>(
&mut self,
contig_string_map: &StringMap,
index: &I,
region: &Region
) -> Result<Query<'_, R>, Error> where
I: BinningIndex<RS>,
RS: ReferenceSequenceExt,
Returns an iterator over records that intersects the given region.
Examples
use noodles_bcf::{self as bcf, header::StringMaps};
use noodles_core::Region;
use noodles_csi as csi;
let mut reader = File::open("sample.bcf").map(bcf::Reader::new)?;
reader.read_file_format()?;
let string_maps: StringMaps = reader.read_header()?.parse()?;
let index = csi::read("sample.bcf.csi")?;
let region = "sq0:8-13".parse()?;
let query = reader.query(string_maps.contigs(), &index, ®ion)?;
for result in query {
let record = result?;
// ...
}
Trait Implementations
Auto Trait Implementations
impl<R> RefUnwindSafe for Reader<R> where
R: RefUnwindSafe,
impl<R> Send for Reader<R> where
R: Send,
impl<R> Sync for Reader<R> where
R: Sync,
impl<R> Unpin for Reader<R> where
R: Unpin,
impl<R> UnwindSafe for Reader<R> where
R: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more