Expand description
A FASTA reader with an index as created by SAMtools (.fai).
Fields
index: Index
Implementations
sourceimpl IndexedReader<File>
impl IndexedReader<File>
sourceimpl<R: Read + Seek> IndexedReader<R>
impl<R: Read + Seek> IndexedReader<R>
sourcepub fn new<I: Read>(fasta: R, fai: I) -> Result<Self>
pub fn new<I: Read>(fasta: R, fai: I) -> Result<Self>
Read from a FASTA and its index, both given as io::Read
. FASTA has to
be io::Seek
in addition.
sourcepub fn with_index(fasta: R, index: Index) -> Self
pub fn with_index(fasta: R, index: Index) -> Self
Read from a FASTA and its index, the first given as io::Read
, the
second given as index object.
sourcepub fn fetch(&mut self, seq_name: &str, start: u64, stop: u64) -> Result<()>
pub fn fetch(&mut self, seq_name: &str, start: u64, stop: u64) -> Result<()>
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.
sourcepub fn fetch_by_rid(&mut self, rid: usize, start: u64, stop: u64) -> Result<()>
pub fn fetch_by_rid(&mut self, rid: usize, start: u64, stop: u64) -> Result<()>
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.
sourcepub fn fetch_all(&mut self, seq_name: &str) -> Result<()>
pub fn fetch_all(&mut self, seq_name: &str) -> Result<()>
Fetch the whole sequence with the given name for reading.
sourcepub fn fetch_all_by_rid(&mut self, rid: usize) -> Result<()>
pub fn fetch_all_by_rid(&mut self, rid: usize) -> Result<()>
Fetch the whole sequence with the given record index for reading.
sourcepub fn read(&mut self, seq: &mut Text) -> Result<()>
pub fn read(&mut self, seq: &mut Text) -> Result<()>
Read the fetched sequence into the given vector.
sourcepub fn read_iter(&mut self) -> Result<IndexedReaderIterator<'_, R>>
pub fn read_iter(&mut self) -> Result<IndexedReaderIterator<'_, R>>
Return an iterator yielding the fetched sequence.
Trait Implementations
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
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<SS, SP> SupersetOf<SS> for SP where
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SP where
SS: SubsetOf<SP>,
pub fn to_subset(&self) -> Option<SS>
pub fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct self
from the equivalent element of its
superset. Read more
pub fn is_in_subset(&self) -> bool
pub fn is_in_subset(&self) -> bool
Checks if self
is actually part of its subset T
(and can be converted to it).
pub fn to_subset_unchecked(&self) -> SS
pub fn to_subset_unchecked(&self) -> SS
Use with care! Same as self.to_subset
but without any property checks. Always succeeds.
pub fn from_subset(element: &SS) -> SP
pub fn from_subset(element: &SS) -> SP
The inclusion map: converts self
to the equivalent element of its superset.