IndexedBcfReader

Struct IndexedBcfReader 

Source
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

Source

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. See ParMultiGzipReader::from_reader (by default (None) use 3); this construct will automaticall read and parse the header
Source

pub fn read_header(&mut self) -> Result<Header>

Read the header bytes, parse them and return a Header

Source

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(_)

Source

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§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.