pub struct IndexedFasta<S: ReadSeek = BoxedSource> { /* private fields */ }Expand description
Random access to an indexed FASTA file.
The source only has to be Read and Seek, so the same code serves a
plain file and a BGZF-compressed one — crate::bgzf::BgzfReader seeks in
uncompressed coordinates, which is the coordinate system a .fai uses.
Implementations§
Source§impl IndexedFasta<BoxedSource>
impl IndexedFasta<BoxedSource>
Sourcepub fn open<P: AsRef<Path>>(path: P) -> Result<IndexedFasta>
pub fn open<P: AsRef<Path>>(path: P) -> Result<IndexedFasta>
Open a FASTA file, loading <path>.fai if it exists or building the
index in memory if it does not.
Handles plain and BGZF-compressed FASTA. For BGZF it uses <path>.gzi
when present and otherwise builds one in memory, which is a header-only
scan.
Sourcepub fn with_index<P: AsRef<Path>>(
path: P,
index: FastaIndex,
) -> Result<IndexedFasta>
pub fn with_index<P: AsRef<Path>>( path: P, index: FastaIndex, ) -> Result<IndexedFasta>
Open a FASTA file with an index that is already in hand.
Source§impl<S: ReadSeek> IndexedFasta<S>
impl<S: ReadSeek> IndexedFasta<S>
Sourcepub fn from_source(source: S, index: FastaIndex) -> IndexedFasta<S>
pub fn from_source(source: S, index: FastaIndex) -> IndexedFasta<S>
Use an arbitrary seekable source, for data that is not in a file.
Sourcepub fn index(&self) -> &FastaIndex
pub fn index(&self) -> &FastaIndex
The index in use.
Sourcepub fn fetch_region(
&mut self,
name: &str,
start: u64,
end: u64,
) -> Result<Sequence>
pub fn fetch_region( &mut self, name: &str, start: u64, end: u64, ) -> Result<Sequence>
Fetch the half-open, 0-based region start..end.
Note that command line tools such as samtools faidx use 1-based
inclusive coordinates: chr1:11-20 is fetch_region("chr1", 10, 20).
Sourcepub fn fetch_locus(&mut self, locus: &str) -> Result<Sequence>
pub fn fetch_locus(&mut self, locus: &str) -> Result<Sequence>
Fetch a region given as name, name:start-end or name:start..end
using 1-based inclusive coordinates, as command line tools do.
let mut fasta = IndexedFasta::open("ref.fa")?;
let first_ten = fasta.fetch_locus("chr1:1-10")?;
assert_eq!(first_ten.len(), 10);Auto Trait Implementations§
impl<S> Freeze for IndexedFasta<S>where
S: Freeze,
impl<S> RefUnwindSafe for IndexedFasta<S>where
S: RefUnwindSafe,
impl<S> Send for IndexedFasta<S>where
S: Send,
impl<S> Sync for IndexedFasta<S>where
S: Sync,
impl<S> Unpin for IndexedFasta<S>where
S: Unpin,
impl<S> UnsafeUnpin for IndexedFasta<S>where
S: UnsafeUnpin,
impl<S> UnwindSafe for IndexedFasta<S>where
S: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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