class

Fastx::Fasta::Reader

Inherits Reference < Object

Constructors

new(filename : String | Path)

Creates a new FASTA reader for the specified file. Automatically detects gzip compression from .gz extension.

Source
new(io : IO)

Creates a new FASTA reader for an already opened IO stream. IO-based readers do not perform gzip auto-detection. The reader takes ownership of the IO and closes it when the reader is closed.

Source

Class methods

open(filename : String | Path, &)

Opens a FASTA file, yields the reader to the block, and automatically closes it.

Source
open(io : IO, &)

Opens a FASTA stream, yields the reader to the block, and automatically closes it.

Source

Instance methods

close

Closes the reader and its underlying IO.

Source
closed?

Returns true if the file handle is closed.

Source
each

Iterates over each FASTA record, yielding name and sequence as owned String copies that remain valid after iteration.

Source
each_bytes

Iterates over each FASTA record, yielding name and sequence as borrowed Bytes (Slice(UInt8)).

The yielded slices point into internal buffers that are reused on every iteration. They are backed by reader-owned reusable buffers, not guaranteed zero-copy views of the input stream, and are only valid until the next record is read. To keep a value beyond the current iteration, copy it (String.new(bytes) or bytes.dup) or use #each.

Source
each_record_lines

Iterates over FASTA records while streaming sequence lines without accumulating the full sequence in memory. This is the lowest-memory FASTA reading API.

The yielded name is an owned String. SequenceLines#each yields borrowed Bytes slices into an internal buffer; each slice is only valid until the next line is read. Copy it (String.new(bytes) or bytes.dup) to keep it.

The specific method name leaves #each_record available for a possible future record-oriented API.

Source