Skip to main content

FastaReader

Struct FastaReader 

Source
pub struct FastaReader { /* private fields */ }
Expand description

Streaming FASTA reader that yields one record at a time.

Uses a fixed 1 MB BufReader internally — never grows to chromosome size. Handles plain and gzipped FASTA files (via get_dynamic_reader). Uppercases all sequence bytes (ASCII only).

§Why not seq_io?

We previously used the seq_io crate for FASTA parsing in the store pipeline. seq_io is a well-tested, high-performance parser, but its fasta::Reader is record-oriented: it buffers the entire FASTA record (header + all sequence lines) in an internal buffer before returning a RefRecord. For typical genomes this is fine, but for large vertebrates (e.g., palmate newt chromosomes at ~2 GB), the reader’s internal buffer grows to chromosome size. Combined with the raw_bytes Vec built from it, the reading thread holds two full copies of the chromosome simultaneously — pure waste that contributed to OOM on HPC.

This reader uses a fixed-size BufReader (1 MB) and builds raw_bytes directly line by line, so only one chromosome-sized allocation exists at a time. FASTA is a simple enough format (lines starting with > are headers, everything else is sequence data) that a custom reader is low-risk.

See guides/core/refgetstore_oom_diagnosis.md for the full investigation.

Implementations§

Source§

impl FastaReader

Source

pub fn from_path<P: AsRef<Path>>(path: P) -> Result<Self>

Source

pub fn next_record(&mut self) -> Result<Option<FastaRecord>>

Read the next FASTA record. Returns None at EOF.

Auto Trait Implementations§

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

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.