Struct atglib::fasta::FastaReader
source · [−]pub struct FastaReader<R> { /* private fields */ }Expand description
Provides random access to nucleotide sequences in Fasta files
It parses the Fasta-index (*.fai) to calculate byte offsets
Please note that this reader is different from GtfReader
and RefGeneReader in that it does not parse transcripts
and cannot be used to build Transcripts.
Instead, FastaReader can only read nucleotide sequences from Fasta files.
Examples
use atglib;
use atglib::fasta::FastaReader;
let mut reader = FastaReader::from_file("tests/data/small.fasta").unwrap();
let seq = reader.read_sequence("chr1", 1, 10).unwrap();
assert_eq!(&seq.to_string(), "GCCTCAGAGG");Implementations
sourceimpl FastaReader<File>
impl FastaReader<File>
sourcepub fn from_file<P: AsRef<Path> + Display>(path: P) -> Result<Self, FastaError>
pub fn from_file<P: AsRef<Path> + Display>(path: P) -> Result<Self, FastaError>
Creates a FastaReader from a fasta file location
It assumes that the fasta index (fai) file has the same
filename as the fasta file with an appended .fai
Examples
use atglib;
use atglib::fasta::FastaReader;
let mut reader = FastaReader::from_file("tests/data/small.fasta").unwrap();
let seq = reader.read_sequence("chr1", 1, 10).unwrap();
assert_eq!(&seq.to_string(), "GCCTCAGAGG");sourcepub fn read_range(
&mut self,
chrom: &str,
start: u64,
end: u64
) -> Result<Vec<u8>, FastaError>
pub fn read_range(
&mut self,
chrom: &str,
start: u64,
end: u64
) -> Result<Vec<u8>, FastaError>
Returns the raw-bytes of the Fasta file for the genomic range
Reads from the FastaReader and returns the raw bytes from the fasta file. The raw bytes include newline and return carriage characters from the Fasta file.
Info
There are almost no use-cases to use this method. In most cases
you want to use read_sequence instead.
This method is using BufReader::read_exact internally
to read the exact required amount of bytes from the Fasta file.
sourcepub fn read_sequence(
&mut self,
chrom: &str,
start: u64,
end: u64
) -> Result<Sequence, FastaError>
pub fn read_sequence(
&mut self,
chrom: &str,
start: u64,
end: u64
) -> Result<Sequence, FastaError>
Returns the Nucleotide Sequence of the specified region
The Sequence includes both start and end positions and is 1-based.
This method is using BufReader::read_exact internally
to read the exact required amount of bytes from the Fasta file.
use atglib;
use atglib::fasta::FastaReader;
let mut reader = FastaReader::from_file("tests/data/small.fasta").unwrap();
// read the nucleotide at position 150 of chromosome 5
let seq = reader.read_sequence("chr5", 150, 150).unwrap();
assert_eq!(&seq.to_string(), "G");
// read the first 10 nucleotides of chromosome 1
let seq = reader.read_sequence("chr1", 1, 10).unwrap();
assert_eq!(&seq.to_string(), "GCCTCAGAGG");sourcepub fn new<P: AsRef<Path> + Display, P2: AsRef<Path> + Display>(
fasta_path: P,
fai_path: P2
) -> Result<Self, FastaError>
pub fn new<P: AsRef<Path> + Display, P2: AsRef<Path> + Display>(
fasta_path: P,
fai_path: P2
) -> Result<Self, FastaError>
Creates a FastaReader by specifying both fasta and fai file
Use this method if the fasta-index file (fai) does not follow standard
naming conventions. In most cases, you want to use
from_file instead.
Examples
use atglib;
use atglib::fasta::FastaReader;
let mut reader = FastaReader::new("tests/data/small.fasta", "tests/data/small.fasta.fai").unwrap();
let seq = reader.read_sequence("chr1", 1, 10).unwrap();
assert_eq!(&seq.to_string(), "GCCTCAGAGG");Auto Trait Implementations
impl<R> RefUnwindSafe for FastaReader<R> where
R: RefUnwindSafe,
impl<R> Send for FastaReader<R> where
R: Send,
impl<R> Sync for FastaReader<R> where
R: Sync,
impl<R> Unpin for FastaReader<R> where
R: Unpin,
impl<R> UnwindSafe for FastaReader<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 · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
