pub struct IndexedReader<R>where
    R: Read + Seek,{
    pub index: Index,
    /* private fields */
}
Expand description

A FASTA reader with an index as created by SAMtools (.fai).

Fields§

§index: Index

Implementations§

§

impl IndexedReader<File>

pub fn from_file<P>(path: &P) -> Result<IndexedReader<File>, Error>where P: AsRef<Path> + Debug,

Read from a given file path. This assumes the index ref.fasta.fai to be present for FASTA ref.fasta.

§

impl<R> IndexedReader<R>where R: Read + Seek,

pub fn new<I>(fasta: R, fai: I) -> Result<IndexedReader<R>, Error>where I: Read,

Read from a FASTA and its index, both given as io::Read. FASTA has to be io::Seek in addition.

pub fn with_index(fasta: R, index: Index) -> IndexedReader<R>

Read from a FASTA and its index, the first given as io::Read, the second given as index object.

pub fn fetch(&mut self, seq_name: &str, start: u64, stop: u64) -> Result<(), Error>

Fetch an interval from the sequence with the given name for reading.

start and stop are 0-based and stop is exclusive - i.e. [start, stop)

Example
use bio::io::fasta::IndexedReader;
// create dummy files
const FASTA_FILE: &[u8] = b">chr1\nGTAGGCTGAAAA\nCCCC";
const FAI_FILE: &[u8] = b"chr1\t16\t6\t12\t13";

let seq_name = "chr1";
let start: u64 = 0; // start is 0-based, inclusive
let stop: u64 = 10; // stop is 0-based, exclusive
                    // load the index
let mut faidx = IndexedReader::new(std::io::Cursor::new(FASTA_FILE), FAI_FILE).unwrap();
// move the pointer in the index to the desired sequence and interval
faidx
    .fetch(seq_name, start, stop)
    .expect("Couldn't fetch interval");
// read the subsequence defined by the interval into a vector
let mut seq = Vec::new();
faidx.read(&mut seq).expect("Couldn't read the interval");
assert_eq!(seq, b"GTAGGCTGAA");
Errors

If the seq_name does not exist within the index.

pub fn fetch_by_rid( &mut self, rid: usize, start: u64, stop: u64 ) -> Result<(), Error>

Fetch an interval from the sequence with the given record index for reading.

start and stop are 0-based and stop is exclusive - i.e. [start, stop)

Example
use bio::io::fasta::IndexedReader;
// create dummy files
const FASTA_FILE: &[u8] = b">chr1\nGTAGGCTGAAAA\nCCCC";
const FAI_FILE: &[u8] = b"chr1\t16\t6\t12\t13";

let rid: usize = 0;
let start: u64 = 0; // start is 0-based, inclusive
let stop: u64 = 10; // stop is 0-based, exclusive
                    // load the index
let mut faidx = IndexedReader::new(std::io::Cursor::new(FASTA_FILE), FAI_FILE).unwrap();
// move the pointer in the index to the desired sequence and interval
faidx
    .fetch_by_rid(rid, start, stop)
    .expect("Couldn't fetch interval");
// read the subsequence defined by the interval into a vector
let mut seq = Vec::new();
faidx.read(&mut seq).expect("Couldn't read the interval");
assert_eq!(seq, b"GTAGGCTGAA");
Errors

If rid does not exist within the index.

pub fn fetch_all(&mut self, seq_name: &str) -> Result<(), Error>

Fetch the whole sequence with the given name for reading.

pub fn fetch_all_by_rid(&mut self, rid: usize) -> Result<(), Error>

Fetch the whole sequence with the given record index for reading.

pub fn read(&mut self, seq: &mut Vec<u8, Global>) -> Result<(), Error>

Read the fetched sequence into the given vector.

pub fn read_iter(&mut self) -> Result<IndexedReaderIterator<'_, R>, Error>

Return an iterator yielding the fetched sequence.

Trait Implementations§

§

impl<R> Debug for IndexedReader<R>where R: Debug + Read + Seek,

§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

const: unstable · 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> Same<T> for T

§

type Output = T

Should always be Self
§

impl<SS, SP> SupersetOf<SS> for SPwhere SS: SubsetOf<SP>,

§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
source§

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

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V