[][src]Trait rust_htslib::bam::Read

pub trait Read: Sized {
    fn read(&mut self, record: &mut Record) -> Result<bool>;
fn records(&mut self) -> Records<Self>;
fn pileup(&mut self) -> Pileups<Self>;
fn htsfile(&self) -> *mut htsFile;
fn header(&self) -> &HeaderView;
fn header_mut(&mut self) -> &mut HeaderView; fn seek(&mut self, offset: i64) -> Result<()> { ... }
fn tell(&self) -> i64 { ... }
fn set_threads(&mut self, n_threads: usize) -> Result<()> { ... } }

A trait for a BAM reader with a read method.

Required methods

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

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.

Arguments

  • record - the record to be filled

Returns

Ok(true) if record was read without error, Ok(false) if there is no more record in the file.

fn records(&mut self) -> Records<Self>

Iterator over the records of the seeked 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.

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

Iterator over pileups.

fn htsfile(&self) -> *mut htsFile

Return the htsFile struct

fn header(&self) -> &HeaderView

Return the header.

fn header_mut(&mut self) -> &mut HeaderView

Return the header, mutable.

Loading content...

Provided methods

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

Seek to the given virtual offset in the file

fn tell(&self) -> i64

Report the current virtual offset

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.

Setting nthreads to 0 does not change the current state. Note that it is not possible to set the number of background threads below 1 once it has been set.

Arguments

  • n_threads - number of extra background writer threads to use, must be > 0.
Loading content...

Implementors

impl Read for IndexedReader[src]

fn records(&mut self) -> Records<Self>[src]

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.

impl Read for Reader[src]

fn read(&mut self, record: &mut Record) -> Result<bool>[src]

Read the next BAM record into the given Record. Returns a true result if a record was read, or false 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::bam::{Error, Read, Reader, Record};

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

// Print the TID of each record
while bam.read(&mut record)? {
   println!("TID: {}", record.tid())
}

fn records(&mut self) -> Records<Self>[src]

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.

Loading content...