pub struct IndexedBcfReader { /* private fields */ }Expand description
IndexedBcfReader allows random access to a specific genome interval of the
BCF file using a CSI index file. It is an wrapper around
ParMultiGzipReader<BufReader<File>> to allow parallelizable bgzip
decompression.
The source should be BCF file consisting of small BGZF blocks.
§Example
use bcf_reader::*;
// create indexed bcf reader
let mut reader =
IndexedBcfReader::from_path("testdata/test3.bcf", "testdata/test3.bcf.csi", None).unwrap();
// read though header
let _header = reader.read_header();
// define targeted genome interval
let interval = GenomeInterval {
chrom_id: 0,
start: 1489230 - 1,
end: Some(1498509 - 1),
};
// set interval
reader.set_interval(interval);
// 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,
vec![
1489230, 1489979, 1490069, 1490311, 1492233, 1492337, 1493505, 1494178, 1495207,
1495403, 1495746, 1496047, 1497964, 1498188,
]
)Implementations§
Source§impl IndexedBcfReader
impl IndexedBcfReader
Sourcepub fn from_path(
path_bcf: impl AsRef<Path>,
path_csi: impl AsRef<Path>,
max_gzip: Option<usize>,
) -> Result<Self>
pub fn from_path( path_bcf: impl AsRef<Path>, path_csi: impl AsRef<Path>, max_gzip: Option<usize>, ) -> Result<Self>
Create an IndexedBcfReader from paths to a bcf file and a corresponding csi index file.
max_gzip, the number of gzip blocks to read before each batch parallelized decompression. SeeParMultiGzipReader::from_reader(by default (None) use 3); this construct will automaticall read and parse the header
Sourcepub fn read_header(&mut self) -> Result<Header>
pub fn read_header(&mut self) -> Result<Header>
Read the header bytes, parse them and return a Header
Sourcepub fn set_interval(&mut self, genome_interval: GenomeInterval) -> Result<()>
pub fn set_interval(&mut self, genome_interval: GenomeInterval) -> Result<()>
Jump the file pointer to the begining to the targeted genome interval
If no site within the genome interval, read_record will return Err(_)
Sourcepub fn read_record(&mut self, record: &mut Record) -> Result<()>
pub fn read_record(&mut self, record: &mut Record) -> Result<()>
Read one record. Should be called after header is parsed.
If set_interval has been called, only records within the given interval
will be read.
Auto Trait Implementations§
impl Freeze for IndexedBcfReader
impl RefUnwindSafe for IndexedBcfReader
impl Send for IndexedBcfReader
impl Sync for IndexedBcfReader
impl Unpin for IndexedBcfReader
impl UnwindSafe for IndexedBcfReader
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