pub struct BcfReader<R>where
R: Read,{ /* private fields */ }Expand description
BcfReader suitable for read through the BCF file.
This assumes that the source reader is in BCF format and stored as BGZF blocks.
§Example
use bcf_reader::*;
use std::{
fs::File,
io::{BufReader, Seek},
};
// underlying reader can be stdin or a file
let reader = std::fs::File::open("testdata/test3.bcf")
.map(BufReader::new)
.unwrap();
// 1. for sequential decompression (works for data from stdin or a file)
let reader = flate2::bufread::MultiGzDecoder::new(reader);
// 2. for parallel decompression (works for data from stdin or a file)
// however, when data is from stdin, jump is not supported for now.
// let reader = ParMultiGzipReader::from_reader(reader, 3, None, None);
// create bcf reader
let mut reader = BcfReader::from_reader(reader);
// read though header
let _header = reader.read_header();
// create a reusable record
let mut record = Record::default();
let mut pos_found = vec![];
// iterate records from the targeted genome interval
while let Ok(_) = reader.read_record(&mut record) {
pos_found.push(record.pos() + 1);
}
assert_eq!(pos_found[0], 72);
assert_eq!(*pos_found.last().unwrap(), 1498841);Implementations§
Source§impl<R> BcfReader<R>where
R: Read,
impl<R> BcfReader<R>where
R: Read,
Sourcepub fn from_reader(reader: R) -> Self
pub fn from_reader(reader: R) -> Self
max_gzip, the number of gzip blocks to read before batch
decompression. See ParMultiGzipReader::from_reader (by default or
None, 3 gzip buffers will be used.)
Sourcepub fn read_header(&mut self) -> Result<Header>
pub fn read_header(&mut self) -> Result<Header>
Read the header
Sourcepub fn read_record(&mut self, record: &mut Record) -> Result<()>
pub fn read_record(&mut self, record: &mut Record) -> Result<()>
Read one record. This should be called after the header is read and parsed. Otherwise, it will panic.
Auto Trait Implementations§
impl<R> Freeze for BcfReader<R>where
R: Freeze,
impl<R> RefUnwindSafe for BcfReader<R>where
R: RefUnwindSafe,
impl<R> Send for BcfReader<R>where
R: Send,
impl<R> Sync for BcfReader<R>where
R: Sync,
impl<R> Unpin for BcfReader<R>where
R: Unpin,
impl<R> UnwindSafe for BcfReader<R>where
R: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more