Struct IndexedReader

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

Source§

impl IndexedReader<File>

Source

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.

Source§

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

Source

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.

Source

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.

Source

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.

Source

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.

Source

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

Fetch the whole sequence with the given name for reading.

Source

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

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

Source

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

Read the fetched sequence into the given vector.

Source

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

Return an iterator yielding the fetched sequence.

Trait Implementations§

Source§

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

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

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

§

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 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

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

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

fn is_in_subset(&self) -> bool

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

fn to_subset_unchecked(&self) -> SS

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

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 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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V