Skip to content

FastaParser

Mojo struct 🡭

@memory_only
struct FastaParser[R: Reader, config: ParserConfig = ParserConfig(False)]

Streaming FASTA parser over a Reader.

Multi-line FASTA sequences are normalised so that all line breaks within the sequence body are stripped, producing a single contiguous sequence string per record.

API: - next_record()FastaRecord (raises EOFError when exhausted) - for rec in parser: (standard iteration, propagates parse errors — see note on _FastaParserRecordIter)

  • IteratorType[origin: Origin]: AnyStruct[_FastaParserRecordIter[R, config, origin]] = _FastaParserRecordIter[R, config, origin]
  • R (Reader)
  • config (ParserConfig)
  • lines (LineIterator[R])
  • validator (Validator)

AnyType, ImplicitlyDestructible, Iterable, Movable

def __init__(out self, var reader: R)

Args:

  • reader (R)
  • self (Self)

Returns:

Self

Raises:

def has_more(self) -> Bool

Return True if there may be more records to read.

Args:

  • self (Self)

Returns:

Bool

def get_buffer_position(ref self) -> Int

Return the current buffer position.

Args:

  • self (Self)

Returns:

Int

def next_record(mut self) -> FastaRecord

Return the next FASTA record as an owned FastaRecord.

Raises EOFError when no more records are available. Raises Error on malformed input (empty sequence, missing ’>’).

Args:

  • self (Self)

Returns:

FastaRecord

Raises:

def records(ref self) -> _FastaParserRecordIter[R, config, origin_of(self)]

Args:

  • self (Self)

Returns:

_FastaParserRecordIter

def __iter__(ref self) -> _FastaParserRecordIter[R, config, origin_of(self)]

Args:

  • self (Self)

Returns:

_FastaParserRecordIter