rust_htslib::bam

Struct Reader

Source
pub struct Reader { /* private fields */ }
Expand description

A BAM reader.

Implementations§

Source§

impl Reader

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_stdin() -> Result<Self>

Create a new Reader from STDIN.

Source

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

Create a new Reader from URL.

Source

pub fn iter_chunk( &mut self, start: Option<i64>, end: Option<i64>, ) -> ChunkIterator<'_, Self>

Iterator over the records between the (optional) virtual offsets start and end

§Arguments
  • start - Optional starting virtual offset to seek to. Throws an error if it is not a valid virtual offset.

  • end - Read until the virtual offset is less than end

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

Trait Implementations§

Source§

impl Debug for Reader

Source§

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

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

impl Drop for Reader

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl Read for Reader

Source§

fn read(&mut self, record: &mut Record) -> Option<Result<()>>

Read the next BAM record into the given Record. Returns None if there are no more records.

This method is useful if you want to read records as fast as possible as the Record can be reused. A more ergonomic approach is to use the records iterator.

§Errors

If there are any issues with reading the next record an error will be returned.

§Examples
use rust_htslib::errors::Error;
use rust_htslib::bam::{Read, Reader, Record};

let mut bam = Reader::from_path(&"test/test.bam")?;
let mut record = Record::new();

// Print the TID of each record
while let Some(r) = bam.read(&mut record) {
   r.expect("Failed to parse record");
   println!("TID: {}", record.tid())
}
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 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 Reader

Auto Trait Implementations§

§

impl Freeze for Reader

§

impl !RefUnwindSafe for Reader

§

impl !Sync for Reader

§

impl Unpin for Reader

§

impl !UnwindSafe for Reader

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