Struct noodles_bam::async::io::Reader
source · pub struct Reader<R> { /* private fields */ }
Expand description
An async BAM reader.
§Examples
use futures::TryStreamExt;
use noodles_bam as bam;
use tokio::fs::File;
let mut reader = File::open("sample.bam").await.map(bam::r#async::io::Reader::new)?;
let _header = reader.read_header().await?;
let mut records = reader.records();
while let Some(_record) = records.try_next().await? {
// ...
}
Implementations§
source§impl<R> Reader<R>
impl<R> Reader<R>
sourcepub fn get_ref(&self) -> &R
pub fn get_ref(&self) -> &R
Returns a reference to the underlying reader.
§Examples
use noodles_bam as bam;
use tokio::io;
let reader = bam::r#async::io::Reader::from(io::empty());
let _inner = reader.get_ref();
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_bam as bam;
use tokio::io;
let mut reader = bam::r#async::io::Reader::from(io::empty());
let _inner = reader.get_mut();
sourcepub fn into_inner(self) -> R
pub fn into_inner(self) -> R
Returns the underlying reader.
§Examples
use noodles_bam as bam;
use tokio::io;
let reader = bam::r#async::io::Reader::from(io::empty());
let _inner = reader.into_inner();
source§impl<R> Reader<R>
impl<R> Reader<R>
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 BAM magic number, reads and parses the raw SAM header, and reads the binary reference sequences. If the SAM header has a reference sequence dictionary, it must match the binary reference sequences; otherwise, the binary reference sequences are added to the SAM header.
The position of the stream is expected to be at the start.
§Examples
use noodles_bam as bam;
use tokio::fs::File;
let mut reader = File::open("sample.bam").await.map(bam::r#async::io::Reader::new)?;
let header = reader.read_header().await?;
sourcepub async fn read_record_buf(
&mut self,
header: &Header,
record: &mut RecordBuf
) -> Result<usize>
pub async fn read_record_buf( &mut self, header: &Header, record: &mut RecordBuf ) -> Result<usize>
Reads a record into an alignment record buffer.
The record block size (bs
) is read from the underlying stream and bs
bytes are read
into an internal buffer. This buffer is then used to decode fields into the given record.
The stream is expected to be directly after the reference sequences or at the start of another record.
It is more ergonomic to read records using a stream (see Self::records
and
Self::query
), but using this method directly allows the reuse of a RecordBuf
.
If successful, the record block size is returned. If a block size of 0 is returned, the stream reached EOF.
§Examples
use noodles_bam as bam;
use noodles_sam::alignment::RecordBuf;
use tokio::fs::File;
let mut reader = File::open("sample.bam").await.map(bam::r#async::io::Reader::new)?;
let header = reader.read_header().await?;
let mut record = RecordBuf::default();
reader.read_record_buf(&header, &mut record).await?;
sourcepub async fn read_record(&mut self, record: &mut Record) -> Result<usize>
pub async fn read_record(&mut self, record: &mut Record) -> Result<usize>
Reads a record.
The record block size (bs
) is read from the underlying stream and bs
bytes are read
into the record’s buffer. No fields are decoded, meaning the record is not necessarily
valid. However, the structure of the buffer is guaranteed to be record-like.
The stream is expected to be directly after the reference sequences or at the start of another record.
If successful, the record block size is returned. If a block size of 0 is returned, the stream reached EOF.
§Examples
use noodles_bam as bam;
use tokio::fs::File;
let mut reader = File::open("sample.bam").await.map(bam::r#async::io::Reader::new)?;
reader.read_header().await?;
let mut record = bam::Record::default();
reader.read_record(&mut record).await?;
sourcepub fn record_bufs<'a>(
&'a mut self,
header: &'a Header
) -> impl Stream<Item = Result<RecordBuf>> + '_
pub fn record_bufs<'a>( &'a mut self, header: &'a Header ) -> impl Stream<Item = Result<RecordBuf>> + '_
Returns an (async) stream over alignment record buffers starting from the current (input) stream position.
The (input) stream is expected to be directly after the reference sequences or at the start of another record.
§Examples
use futures::TryStreamExt;
use noodles_bam as bam;
use tokio::fs::File;
let mut reader = File::open("sample.bam").await.map(bam::r#async::io::Reader::new)?;
let header = reader.read_header().await?;
let mut records = reader.record_bufs(&header);
while let Some(record) = records.try_next().await? {
// ...
}
sourcepub fn records(&mut self) -> impl Stream<Item = Result<Record>> + '_
pub fn records(&mut self) -> impl Stream<Item = Result<Record>> + '_
Returns a stream over records.
The (input) stream is expected to be directly after the reference sequences or at the start of another record.
§Examples
use futures::TryStreamExt;
use noodles_bam as bam;
use tokio::fs::File;
let mut reader = File::open("sample.bam").await.map(bam::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<AsyncReader<R>>
impl<R> Reader<AsyncReader<R>>
source§impl<R> Reader<AsyncReader<R>>
impl<R> Reader<AsyncReader<R>>
sourcepub fn query<I>(
&mut self,
header: &Header,
index: &I,
region: &Region
) -> Result<impl Stream<Item = Result<Record>> + '_>where
I: BinningIndex,
pub fn query<I>(
&mut self,
header: &Header,
index: &I,
region: &Region
) -> Result<impl Stream<Item = Result<Record>> + '_>where
I: BinningIndex,
Returns a stream over records that intersect the given region.
§Examples
use futures::TryStreamExt;
use noodles_bam::{self as bam, bai};
use noodles_core::Region;
use noodles_sam as sam;
use tokio::fs::File;
let mut reader = File::open("sample.bam").await.map(bam::AsyncReader::new)?;
let header = reader.read_header().await?;
let index = bai::r#async::read("sample.bam.bai").await?;
let region = "sq0:8-13".parse()?;
let mut query = reader.query(&header, &index, ®ion)?;
while let Some(record) = query.try_next().await? {
// ...
}