Struct noodles_bcf::io::reader::Reader
source · 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§
source§impl<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::io::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::io::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::io::Reader::from(&data[..]);
assert!(reader.into_inner().is_empty());
sourcepub fn read_header(&mut self) -> Result<Header>
pub fn read_header(&mut self) -> Result<Header>
Reads the VCF header.
This verifies the BCF magic number, discards the file format version, and reads and parses the raw VCF header. Associated string maps are also built from the raw header.
The position of the stream is expected to be at the start.
§Examples
use noodles_bcf as bcf;
let mut reader = File::open("sample.bcf").map(bcf::io::Reader::new)?;
let header = reader.read_header()?;
sourcepub fn read_record_buf(
&mut self,
header: &Header,
record: &mut RecordBuf,
) -> Result<usize>
pub fn read_record_buf( &mut self, header: &Header, record: &mut RecordBuf, ) -> Result<usize>
Reads a single record.
The stream is expected to be directly after the header or at the start of another record.
It is more ergonomic to read records using an iterator (see Self::records
), but using
this method directly allows the reuse of a single vcf::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;
use noodles_vcf as vcf;
let mut reader = File::open("sample.bcf").map(bcf::io::Reader::new)?;
let header = reader.read_header()?;
let mut record = vcf::variant::RecordBuf::default();
reader.read_record_buf(&header, &mut record)?;
sourcepub fn read_record(&mut self, record: &mut Record) -> Result<usize>
pub fn read_record(&mut self, record: &mut Record) -> Result<usize>
Reads a single record without eagerly decoding (most of) its fields.
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::io::Reader::new)?;
reader.read_header()?;
let mut record = bcf::Record::default();
reader.read_record(&mut record)?;
sourcepub fn record_bufs<'r, 'h>(
&'r mut self,
header: &'h Header,
) -> RecordBufs<'r, 'h, R> ⓘ
pub fn record_bufs<'r, 'h>( &'r mut self, header: &'h Header, ) -> RecordBufs<'r, 'h, R> ⓘ
Returns an iterator over records starting from the current stream position.
The stream is expected to be directly after the reference sequences or at the start of another record.
§Examples
use noodles_bcf as bcf;
let mut reader = File::open("sample.bcf").map(bcf::io::Reader::new)?;
let header = reader.read_header()?;
for result in reader.record_bufs(&header) {
let record = result?;
// ...
}
sourcepub fn records(&mut self) -> impl Iterator<Item = Result<Record>> + '_
pub fn records(&mut self) -> impl Iterator<Item = Result<Record>> + '_
Returns an iterator over lazy 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::io::Reader::new)?;
reader.read_header()?;
for result in reader.records() {
let record = result?;
println!("{:?}", record);
}
source§impl<R> Reader<R>
impl<R> Reader<R>
sourcepub fn query<'r, 'h, I>(
&'r mut self,
header: &'h Header,
index: &I,
region: &Region,
) -> Result<Query<'r, 'h, R>>where
I: BinningIndex,
pub fn query<'r, 'h, I>(
&'r mut self,
header: &'h Header,
index: &I,
region: &Region,
) -> Result<Query<'r, 'h, R>>where
I: BinningIndex,
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;
let mut reader = File::open("sample.bcf").map(bcf::io::Reader::new)?;
let header = reader.read_header()?;
let index = csi::read("sample.bcf.csi")?;
let region = "sq0:8-13".parse()?;
let query = reader.query(&header, &index, ®ion)?;
for result in query {
let record = result?;
// ...
}