Struct rust_htslib::bam::IndexedReader
source · [−]pub struct IndexedReader { /* private fields */ }
Implementations
sourceimpl 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
sourceimpl Debug for IndexedReader
impl Debug for IndexedReader
sourceimpl Drop for IndexedReader
impl Drop for IndexedReader
sourceimpl Read for IndexedReader
impl Read for IndexedReader
sourcefn records(&mut self) -> Records<'_, Self>ⓘNotable traits for Records<'a, R>impl<'a, R: Read> Iterator for Records<'a, R> type Item = Result<Record>;
fn records(&mut self) -> Records<'_, Self>ⓘNotable traits for Records<'a, R>impl<'a, R: Read> Iterator for Records<'a, R> type Item = Result<Record>;
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
.
sourcefn 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
sourcefn rc_records(&mut self) -> RcRecords<'_, Self>ⓘNotable traits for RcRecords<'a, R>impl<'a, R: Read> Iterator for RcRecords<'a, R> type Item = Result<Rc<Record>>;
fn rc_records(&mut self) -> RcRecords<'_, Self>ⓘNotable traits for RcRecords<'a, R>impl<'a, R: Read> Iterator for RcRecords<'a, R> type Item = Result<Rc<Record>>;
sourcefn pileup(&mut self) -> Pileups<'_, Self>ⓘNotable traits for Pileups<'a, R>impl<'a, R: Read> Iterator for Pileups<'a, R> type Item = Result<Pileup>;
fn pileup(&mut self) -> Pileups<'_, Self>ⓘNotable traits for Pileups<'a, R>impl<'a, R: Read> Iterator for Pileups<'a, R> type Item = Result<Pileup>;
Iterator over pileups.
sourcefn header(&self) -> &HeaderView
fn header(&self) -> &HeaderView
Return the header.
sourcefn 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
impl Send for IndexedReader
Auto Trait Implementations
impl !RefUnwindSafe for IndexedReader
impl !Sync for IndexedReader
impl Unpin for IndexedReader
impl !UnwindSafe for IndexedReader
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more