Expand description
Efficient FASTA reading and writing
Example
This example reads some content, writes it back and compares the output (should be the same):
use seq_io::fasta::{Reader, Record};
let input = b">id1
ACGT
ACGT
>id2
TGCA
TGCA
";
let mut reader = Reader::new(&input[..]);
let mut output = vec![];
while let Some(record) = reader.next() {
let record = record.expect("Error reading record");
println!("id: {}", record.id().unwrap());
record.write_wrap(&mut output, 4);
}
assert_eq!(input, output.as_slice());
Details on parsing behaviour
- The parser handles UNIX (LF) and Windows (CRLF) line endings, but not old Mac-style (CR) endings. However, FASTA writing currently always uses UNIX line endings.
- Empty lines are allowed anywhere in the file, they will just be ignored.
The first non-empty line must start with
>
, indicating the first header. - Whitespace at the end of header and sequence lines is never removed.
- If two consecutive FASTA header lines (starting with
>
) are encountered without intermediate sequence line, the first record will have an empty sequence. The same is true if the input ends with a header line. - Empty input will result in
None
being returned immediately byfasta::Reader::next()
and in empty iterators forRecordsIter
/RecordsIntoIter
. - Comment lines starting with
;
are not supported. If at the start of a file, there will be an error, since>
is expected. Intermediate comments are appended to the sequence.
Structs
- A FASTA record that ownes its data (requiring two allocations)
- Holds line number and byte offset of a FASTA record
- Parser for FASTA files.
- Set of FASTA records that owns it’P buffer and knows the positions of each record.
- Iterator over record sets
- Iterator of
OwnedRecord
that owns the underlying reader - Borrowed iterator of
OwnedRecord
- A FASTA record that borrows data from a buffer.
- Iterator over sequence the lines of a FASTA record.
Enums
- FASTA parsing error
Traits
- FASTA record trait implemented by both
RefRecord
andOwnedRecord
Functions
- Writes only the sequence header.
- Writes only the sequence header given ID and description parts.
- Writes data to the FASTA format. ID and description parts of the header are supplied separately instead of a whole header line.
- Writes only the sequence line.
- Writes the sequence line from an iterator (such as
SeqLines
) - Writes data (not necessarily stored in a
Record
instance) to the FASTA format. - Writes data to the FASTA format. Wraps the sequence to produce multi-line FASTA with a maximum width specified by the
wrap
parameter. - Writes the sequence line, and wraps the output to a maximum width specified by
wrap
. - Writes the sequence line from an iterator (such as
SeqLines
) and wraps the output to a maximum width specified bywrap
.