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 through 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).
start
and stop
are zero-based. start
is inclusive, stop
is exclusive.
This replaces the old fetch and fetch_str implementations.
pub fn index(&self) -> &IndexView
Sourcepub fn index_stats(&mut self) -> Result<Vec<(i64, u64, u64, u64)>>
pub fn index_stats(&mut self) -> Result<Vec<(i64, u64, u64, u64)>>
Similar to samtools idxstats, this returns a vector of tuples containing the target id, length, number of mapped reads, and number of unmapped reads. The last entry in the vector corresponds to the unmapped reads for the entire file, with the tid set to -1.
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<()>>
Source§fn rc_records(&mut self) -> RcRecords<'_, Self> ⓘ
fn rc_records(&mut self) -> RcRecords<'_, Self> ⓘ
Source§fn header(&self) -> &HeaderView
fn header(&self) -> &HeaderView
Source§fn set_thread_pool(&mut self, tpool: &ThreadPool) -> Result<()>
fn set_thread_pool(&mut self, tpool: &ThreadPool) -> Result<()>
crate::tpool::ThreadPool::new(n_threads)
Read more