Struct noodles::bcf::async::io::Reader

source ·
pub struct Reader<R> { /* private fields */ }
Expand description

An async BCF reader.

§Examples

use futures::TryStreamExt;
use noodles_bcf as bcf;
use tokio::fs::File;

let mut reader = File::open("sample.bcf").await.map(bcf::r#async::io::Reader::new)?;
reader.read_header().await?;

let mut records = reader.records();

while let Some(record) = records.try_next().await? {
    // ...
}

Implementations§

source§

impl<R> Reader<R>
where R: AsyncRead + Unpin,

source

pub fn get_ref(&self) -> &R

Returns a reference to the underlying reader.

§Examples
use noodles_bcf as bcf;
let data = [];
let reader = bcf::r#async::io::Reader::from(&data[..]);
assert!(reader.get_ref().is_empty());
source

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::r#async::io::Reader::from(&data[..]);
assert!(reader.get_mut().is_empty());
source

pub fn into_inner(self) -> R

Returns the underlying reader.

§Examples
use noodles_bcf as bcf;
let data = [];
let reader = bcf::r#async::io::Reader::from(&data[..]);
assert!(reader.into_inner().is_empty());
source

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

Reads the VCF header.

The BCF magic number is checked, and the file format version is discarded.

The position of the stream is expected to be at the start.

§Examples
use noodles_bcf as bcf;
use tokio::fs::File;

let mut reader = File::open("sample.bcf").await.map(bcf::r#async::io::Reader::new)?;
let header = reader.read_header().await?;
source

pub async fn read_record(&mut self, record: &mut Record) -> Result<usize, Error>

Reads a single record without decoding (most of) its feilds.

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 a stream (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.

use noodles_bcf as bcf;
use tokio::fs::File;

let mut reader = File::open("sample.bcf").await.map(bcf::r#async::io::Reader::new)?;
reader.read_header().await?;

let mut record = bcf::Record::default();
reader.read_record(&mut record).await?;
source

pub fn records(&mut self) -> impl Stream<Item = Result<Record, Error>>

Returns an (async) stream over lazy records starting from the current (input) stream position.

The (input) stream is expected to be directly after the header or at the start of another record.

§Examples
use futures::TryStreamExt;
use noodles_bcf as bcf;
use tokio::fs::File;

let mut reader = File::open("sample.bcf").await.map(bcf::r#async::io::Reader::new)?;
reader.read_header().await?;

let mut records = reader.records();

while let Some(record) = records.try_next().await? {
    // ...
}
source§

impl<R> Reader<Reader<R>>
where R: AsyncRead + Unpin,

source

pub fn new(inner: R) -> Reader<Reader<R>>

Creates an async BCF reader.

§Examples
use noodles_bcf as bcf;
let data = [];
let reader = bcf::r#async::io::Reader::new(&data[..]);
source§

impl<R> Reader<Reader<R>>
where R: AsyncRead + AsyncSeek + Unpin,

source

pub fn query<I>( &mut self, header: &Header, index: &I, region: &Region ) -> Result<impl Stream<Item = Result<Record, Error>>, Error>
where I: BinningIndex,

Returns a stream over records that intersect the given region.

§Examples
use futures::TryStreamExt;
use noodles_bcf as bcf;
use noodles_core::Region;
use noodles_csi as csi;
use tokio::fs::File;

let mut reader = File::open("sample.bcf").await.map(bcf::r#async::io::Reader::new)?;
let header = reader.read_header().await?;

let index = csi::r#async::read("sample.bcf.csi").await?;
let region = "sq0:8-13".parse()?;
let mut query = reader.query(&header, &index, &region)?;

while let Some(record) = query.try_next().await? {
    // ...
}

Trait Implementations§

source§

impl<R> From<R> for Reader<R>

source§

fn from(inner: R) -> Reader<R>

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<R> Freeze for Reader<R>
where R: Freeze,

§

impl<R> RefUnwindSafe for Reader<R>
where R: RefUnwindSafe,

§

impl<R> Send for Reader<R>
where R: Send,

§

impl<R> Sync for Reader<R>
where R: Sync,

§

impl<R> Unpin for Reader<R>
where R: Unpin,

§

impl<R> UnwindSafe for Reader<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<!> for T

source§

fn from(t: !) -> T

Converts to this type from the input type.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Same for T

§

type Output = T

Should always be Self
source§

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

§

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

§

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

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more