Struct Reader

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

An async CRAM reader.

Implementations§

Source§

impl<R> Reader<R>

Source

pub fn get_ref(&self) -> &R

Returns a reference to the underlying reader.

§Examples
use noodles_cram as cram;
use tokio::io;
let reader = cram::r#async::io::Reader::new(io::empty());
let _inner = reader.get_ref();
Source

pub fn get_mut(&mut self) -> &mut R

Returns a mutable reference to the underlying reader.

§Examples
use noodles_cram as cram;
use tokio::io;
let mut reader = cram::r#async::io::Reader::new(io::empty());
let _inner = reader.get_mut();
Source

pub fn into_inner(self) -> R

Returns the underlying reader.

§Examples
use noodles_cram as cram;
use tokio::io;
let reader = cram::r#async::io::Reader::new(io::empty());
let _inner = reader.into_inner();
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;
use tokio::io;
let reader = cram::r#async::io::Reader::new(io::empty());
Source

pub fn header_reader(&mut self) -> Reader<&mut R>

Returns an async CRAM header reader.

§Examples
use noodles_cram as cram;
use tokio::{fs::File, io::AsyncReadExt};

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

let mut header_reader = reader.header_reader();
header_reader.read_magic_number().await?;
header_reader.read_format_version().await?;
header_reader.read_file_id().await?;

let mut container_reader = header_reader.container_reader().await?;

let _raw_header = {
    let mut raw_sam_header_reader = container_reader.raw_sam_header_reader().await?;
    let mut raw_header = String::new();
    raw_sam_header_reader.read_to_string(&mut raw_header).await?;
    raw_sam_header_reader.discard_to_end().await?;
    raw_header
};

container_reader.discard_to_end().await?;
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<Header>

Reads the SAM header.

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

§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_header(&mut self) -> Result<Header>

Reads the SAM header.

This verifies the CRAM magic number, discards the file definition, and reads and parses the file header as a SAM header.

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 _header = reader.read_header().await?;
Source

pub async fn read_container( &mut self, container: &mut Container, ) -> Result<usize>

Reads a container.

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

§Examples
use noodles_cram::{self as cram, io::reader::Container};
use tokio::fs::File;

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

let mut container = Container::default();

while reader.read_container(&mut container).await? != 0 {
    // ...
}
Source

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

👎Deprecated since 0.78.0: Use Reader::read_container instead.

Reads a container.

Source

pub fn records<'r, 'h: 'r>( &'r mut self, header: &'h Header, ) -> impl Stream<Item = Result<RecordBuf>> + 'r

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

§Examples
use futures::TryStreamExt;
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 header = reader.read_header().await?;

let mut records = reader.records(&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 noodles_cram as cram;
use tokio::io::{self, SeekFrom};
let mut reader = cram::r#async::io::Reader::new(io::empty());
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 tokio::io;
use noodles_cram as cram;
let mut reader = cram::r#async::io::Reader::new(io::empty());
assert_eq!(reader.position().await?, 0);
Source

pub fn query<'r, 'h: 'r, 'i: 'r>( &'r mut self, header: &'h Header, index: &'i Index, region: &Region, ) -> Result<impl Stream<Item = Result<RecordBuf>> + 'r>

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 tokio::fs::File;

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

let index = crai::r#async::read("sample.cram.crai").await?;
let region = "sq0:8-13".parse()?;
let mut query = reader.query(&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

Source§

type Output = T

Should always be Self
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.