logo
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

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");

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.

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");

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

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.