rust_htslib::bam

Struct IndexedReader

Source
pub struct IndexedReader { /* private fields */ }

Implementations§

Source§

impl IndexedReader

Source

pub fn from_path<P: AsRef<Path>>(path: P) -> Result<Self>

Create a new Reader from path.

§Arguments
  • path - the path to open.
Source

pub fn from_path_and_index<P: AsRef<Path>>( path: P, index_path: P, ) -> Result<Self>

Source

pub fn from_url(url: &Url) -> Result<Self>

Source

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:

  1. ‘fetch’ the region of interest
  2. 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.

Source

pub fn set_reference<P: AsRef<Path>>(&mut self, path: P) -> Result<()>

Set the reference path for reading CRAM files.

§Arguments
  • path - path to the FASTA reference
Source

pub fn index(&self) -> &IndexView

Source

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

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for IndexedReader

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl Read for IndexedReader

Source§

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<()>>

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>

Records iterator using an Rc to avoid allocating a Record each turn. This is about 1% slower than the read based API in micro benchmarks, but has nicer ergonomics (and might not actually be slower in your applications). Read more
Source§

fn pileup(&mut self) -> Pileups<'_, Self>

Iterator over pileups.
Source§

fn htsfile(&self) -> *mut htsFile

Return the htsFile struct
Source§

fn header(&self) -> &HeaderView

Return the header.
Source§

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
Source§

fn seek(&mut self, offset: i64) -> Result<()>

Seek to the given virtual offset in the file
Source§

fn tell(&self) -> i64

Report the current virtual offset
Source§

fn set_threads(&mut self, n_threads: usize) -> Result<()>

Activate multi-threaded BAM read support in htslib. This should permit faster reading of large BAM files. Read more
Source§

fn set_cram_options( &mut self, fmt_opt: hts_fmt_option, fields: sam_fields, ) -> Result<()>

If the underlying file is in CRAM format, allows modifying CRAM options. Note that this method does not check that the underlying file actually is in CRAM format. Read more
Source§

impl Send for IndexedReader

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T