[][src]Module needletail::formats

Functions for reading sequence data from FASTA and FASTQ formats.

Design Note

These functions are designed to take callbacks to process the FASTX records they read. It would be nice to present a FASTX Iterator that downstream users can use at some point, but this is complicated because the lifetimes of the records are linked to the slice of buffer that's being parsed (the records are "zero-copy" so they mustn't outlive the buffer). Perhaps we'll figure out a "streaming iterator" strategy here someday.

See: https://github.com/emk/rust-streaming

Structs

FastaParser

An iterator that parses a buffer into a sequence of FASTARecords

FastaRecord

A zero-copy reference to a FASTA record in a buffer.

FastqParser

An iterator that parses a buffer into a sequence of FASTQRecords

FastqRecord

A zero-copy reference to a FASTQ record in a buffer.

RecBuffer

A buffer that wraps an object with the Read trait and allows extracting a set of slices to data. Acts as a lower-level primitive for our FASTX readers.

Traits

RecParser

[⚠️Unstable] RecParser is an adaptor trait that allows new file format parsers to be defined. It takes a chunk from a RecBuffer (from_reader), optionally parses an initial header out (header) and then provides an iterator interface to parse a record stream. When finished, it provides an eof function to determine if the stream is completely exhausted.

Functions

parse_sequence_path

This is a convenience method for easy drop into CLI programs. It will take a "path" which is either parsed as a filename or, if "-", as stdin. It then opens this, does automatic decompression and then determines the type of the file (which is calls type_callback with) before parsing the rest of the file into SequenceRecords that it calls callback on.

parse_sequence_reader

Opens a Read stream and parses the FASTX records out. Also takes a "type_callback" that gets called as soon as we determine if the records are FASTA or FASTQ. If a file starts with a gzip or other header, transparently decompress it.