pub struct Reader<R> { /* private fields */ }
Expand description
An async CRAM reader.
Implementations§
Source§impl<R> Reader<R>
impl<R> Reader<R>
Sourcepub fn new(inner: R) -> Self
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[..]);
Sourcepub fn get_ref(&self) -> &R
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());
Sourcepub fn get_mut(&mut self) -> &mut R
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());
Sourcepub fn into_inner(self) -> R
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());
Sourcepub async fn read_file_definition(&mut self) -> Result<FileDefinition>
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?;
Sourcepub async fn read_file_header(&mut self) -> Result<String>
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?;
Sourcepub async fn read_header(&mut self) -> Result<Header>
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?;
Sourcepub async fn read_data_container(&mut self) -> Result<Option<DataContainer>>
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_header().await?;
while let Some(container) = reader.read_data_container().await? {
// ...
}
Sourcepub fn records<'r, 'h: 'r>(
&'r mut self,
header: &'h Header,
) -> impl Stream<Item = Result<Record>> + 'r
pub fn records<'r, 'h: 'r>( &'r mut self, header: &'h Header, ) -> impl Stream<Item = Result<Record>> + '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 data 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>
impl<R> Reader<R>
Sourcepub async fn seek(&mut self, pos: SeekFrom) -> Result<u64>
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?;
Sourcepub async fn position(&mut self) -> Result<u64>
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);
Sourcepub fn query<'r, 'h: 'r, 'i: 'r>(
&'r mut self,
header: &'h Header,
index: &'i Index,
region: &Region,
) -> Result<impl Stream<Item = Result<Record>> + 'r>
pub fn query<'r, 'h: 'r, 'i: 'r>( &'r mut self, header: &'h Header, index: &'i Index, region: &Region, ) -> Result<impl Stream<Item = Result<Record>> + '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, ®ion)?;
while let Some(record) = query.try_next().await? {
// ...
}