[][src]Struct bam::bam_reader::IndexedReader

pub struct IndexedReader<R: Read + Seek> { /* fields omitted */ }

BAM file reader. In contrast to Reader the IndexedReader allows to fetch records from arbitrary positions, but does not allow to read all records consecutively.

The following code would load BAM file test.bam and its index test.bam.bai, take all records from 2:100001-200000 and print them on the stdout.

extern crate bam;

fn main() {
    let mut reader = bam::IndexedReader::from_path("test.bam").unwrap();

    // We need to clone the header to have access to reference names as the
    // reader will be blocked during fetch.
    let header = reader.header().clone();
    let mut stdout = std::io::BufWriter::new(std::io::stdout());

    for record in reader.fetch(1, 100_000, 200_000) {
        record.unwrap().write_sam(&mut stdout, &header).unwrap();
    }
}

You can find more detailed help on the main page.

Methods

impl IndexedReader<File>[src]

pub fn build() -> IndexedReaderBuilder[src]

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

Opens bam file from path. Bai index will be loaded from {path}.bai.

Same as Self::build().from_path(path).

impl<R: Read + Seek> IndexedReader<R>[src]

Important traits for RegionViewer<'a, R>
pub fn fetch<'a>(
    &'a mut self,
    ref_id: i32,
    start: i32,
    end: i32
) -> RegionViewer<'a, R>
[src]

Returns an iterator over records aligned to the reference ref_id (0-based), and intersecting half-open interval [start-end).

Important traits for RegionViewer<'a, R>
pub fn fetch_by<'a, F>(
    &'a mut self,
    ref_id: i32,
    start: i32,
    end: i32,
    predicate: F
) -> RegionViewer<'a, R> where
    F: 'static + Fn(&Record) -> bool
[src]

Returns an iterator over records aligned to the reference ref_id (0-based), and intersecting half-open interval [start-end).

Records will be filtered by predicate. It helps to slightly reduce fetching time, as some records will be removed without allocating new memory and without calculating alignment length.

pub fn header(&self) -> &Header[src]

Returns BAM header.

pub fn write_record_as_sam<W: Write>(
    &self,
    writer: &mut W,
    record: &Record
) -> Result<()>
[src]

Writes record in sam format. Same as Record::write_sam.

Auto Trait Implementations

impl<R> Send for IndexedReader<R> where
    R: Send

impl<R> Unpin for IndexedReader<R> where
    R: Unpin

impl<R> Sync for IndexedReader<R> where
    R: Sync

impl<R> UnwindSafe for IndexedReader<R> where
    R: UnwindSafe

impl<R> RefUnwindSafe for IndexedReader<R> where
    R: RefUnwindSafe

Blanket Implementations

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]