Struct noodles_cram::async::io::Reader

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

An async CRAM reader.

Implementations§

source§

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

source

pub fn new(inner: R) -> Self

Creates an async CRAM reader.

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

pub fn get_ref(&self) -> &R

Returns a reference to the underlying reader.

§Examples
use noodles_cram as cram;
let data = [];
let reader = cram::r#async::io::Reader::new(&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_cram as cram;
let data = [];
let mut reader = cram::r#async::io::Reader::new(&data[..]);
assert!(reader.get_mut().is_empty());
source

pub fn into_inner(self) -> R

Returns the underlying reader.

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

pub async fn read_file_definition(&mut self) -> Result<FileDefinition>

Reads the CRAM file definition.

This also checks the magic number.

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

§Examples
use noodles_cram as cram;
use tokio::fs::File;
let mut reader = File::open("sample.cram").await.map(cram::r#async::io::Reader::new)?;
let file_definition = reader.read_file_definition().await?;
source

pub async fn read_file_header(&mut self) -> Result<String>

Reads the raw SAM header.

The position of the stream is expected to be at the CRAM header container, i.e., directly after the file definition.

This returns the raw SAM header as a String. It can subsequently be parsed as a noodles_sam::Header.

§Examples
use noodles_cram as cram;
use tokio::fs::File;

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

let header = reader.read_file_header().await?;
source

pub async fn read_data_container(&mut self) -> Result<Option<DataContainer>>

Reads a data container.

This returns None if the container header is the EOF container header, which signals the end of the stream.

§Examples
use noodles_cram as cram;
use tokio::fs::File;

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

while let Some(container) = reader.read_data_container().await? {
    // ...
}
source

pub fn records<'a>( &'a mut self, reference_sequence_repository: &'a Repository, header: &'a Header ) -> impl Stream<Item = Result<Record>> + 'a

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

The (input) stream position is expected to be at the start of a data container.

§Examples
use futures::TryStreamExt;
use noodles_cram as cram;
use noodles_fasta as fasta;
use tokio::fs::File;

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

let repository = fasta::Repository::default();
let header = reader.read_file_header().await?.parse()?;
let mut records = reader.records(&repository, &header);

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

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

source

pub async fn seek(&mut self, pos: SeekFrom) -> Result<u64>

Seeks the underlying reader to the given position.

Positions typically come from an associated CRAM index file.

§Examples
use std::io::{Cursor, SeekFrom};
use noodles_cram as cram;
let mut reader = cram::r#async::io::Reader::new(Cursor::new(Vec::new()));
reader.seek(SeekFrom::Start(0)).await?;
source

pub async fn position(&mut self) -> Result<u64>

Returns the current position of the underlying reader.

§Examples
use std::io::{Cursor, SeekFrom};
use noodles_cram as cram;
let mut reader = cram::r#async::io::Reader::new(Cursor::new(Vec::new()));
assert_eq!(reader.position().await?, 0);
source

pub fn query<'a>( &'a mut self, reference_sequence_repository: &'a Repository, header: &'a Header, index: &'a Index, region: &Region ) -> Result<impl Stream<Item = Result<Record>> + '_>

Returns a stream over records that intersects the given region.

§Examples
use futures::TryStreamExt;
use noodles_core::Region;
use noodles_cram::{self as cram, crai};
use noodles_fasta as fasta;
use tokio::fs::File;

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

let repository = fasta::Repository::default();
let header = reader.read_file_header().await?.parse()?;
let index = crai::r#async::read("sample.cram.crai").await?;
let region = "sq0:8-13".parse()?;
let mut query = reader.query(&repository, &header, &index, &region)?;

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

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