BcfReader

Struct BcfReader 

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

Source

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.)

Source

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

Read the header

Source

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> 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.