Struct rust_htslib::bam::IndexedReader
source · pub struct IndexedReader { /* private fields */ }
Implementations§
source§impl IndexedReader
impl IndexedReader
pub fn from_path_and_index<P: AsRef<Path>>( path: P, index_path: P ) -> Result<Self>
pub fn from_url(url: &Url) -> Result<Self>
sourcepub fn fetch<'a, T: Into<FetchDefinition<'a>>>(
&mut self,
fetch_definition: T
) -> Result<()>
pub fn fetch<'a, T: Into<FetchDefinition<'a>>>( &mut self, fetch_definition: T ) -> Result<()>
Define the region from which .read() or .records will retrieve reads.
Both iterating (with .records()) and looping without allocation (with .read() are a two stage process:
- ‘fetch’ the region of interest
- iter/loop trough the reads.
Example:
use rust_htslib::bam::{IndexedReader, Read};
let mut bam = IndexedReader::from_path(&"test/test.bam").unwrap();
bam.fetch(("chrX", 10000, 20000)); // coordinates 10000..20000 on reference named "chrX"
for read in bam.records() {
println!("read name: {:?}", read.unwrap().qname());
}
The arguments may be anything that can be converted into a FetchDefinition such as
- fetch(tid: u32) -> fetch everything on this reference
- fetch(reference_name: &u8 | &str) -> fetch everything on this reference
- fetch((tid: i32, start: i64, stop: i64)): -> fetch in this region on this tid
- fetch((reference_name: &u8 | &str, start: i64, stop: i64) -> fetch in this region on this tid
- fetch(FetchDefinition::All) or fetch(“.”) -> Fetch overything
- fetch(FetchDefinition::Unmapped) or fetch(“*”) -> Fetch unmapped (as signified by the ‘unmapped’ flag in the BAM - might be unreliable with some aligners.
The start / stop coordinates will take i64 (the correct type as of htslib’s ‘large coordinates’ expansion), i32, u32, and u64 (with a possible panic! if the coordinate won’t fit an i64).
This replaces the old fetch and fetch_str implementations.
Trait Implementations§
source§impl Debug for IndexedReader
impl Debug for IndexedReader
source§impl Drop for IndexedReader
impl Drop for IndexedReader
source§impl Read for IndexedReader
impl Read for IndexedReader
source§fn records(&mut self) -> Records<'_, Self> ⓘ
fn records(&mut self) -> Records<'_, Self> ⓘ
Iterator over the records of the fetched region.
Note that, while being convenient, this is less efficient than pre-allocating a
Record
and reading into it with the read
method, since every iteration involves
the allocation of a new Record
.
source§fn read(&mut self, record: &mut Record) -> Option<Result<()>>
fn read(&mut self, record: &mut Record) -> Option<Result<()>>
Read next BAM record into given record.
Use this method in combination with a single allocated record to avoid the reallocations
occurring with the iterator. Read more
source§fn rc_records(&mut self) -> RcRecords<'_, Self> ⓘ
fn rc_records(&mut self) -> RcRecords<'_, Self> ⓘ
source§fn header(&self) -> &HeaderView
fn header(&self) -> &HeaderView
Return the header.
source§fn set_thread_pool(&mut self, tpool: &ThreadPool) -> Result<()>
fn set_thread_pool(&mut self, tpool: &ThreadPool) -> Result<()>
Use a shared thread-pool for writing. This permits controlling the total
thread count when multiple readers and writers are working simultaneously.
A thread pool can be created with
crate::tpool::ThreadPool::new(n_threads)
Read more