[][src]Module seq_io::fasta

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 by fasta::Reader::next() and in empty iterators for RecordsIter / 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

OwnedRecord

A FASTA record that ownes its data (requiring two allocations)

Position

Holds line number and byte offset of a FASTA record

Reader

Parser for FASTA files.

RecordSet

Set of FASTA records that owns it'P buffer and knows the positions of each record.

RecordSetIter

Iterator over record sets

RecordsIntoIter

Iterator of OwnedRecord that owns the underlying reader

RecordsIter

Borrowed iterator of OwnedRecord

RefRecord

A FASTA record that borrows data from a buffer.

SeqLines

Iterator over sequence the lines of a FASTA record.

Enums

Error

FASTA parsing error

Traits

Record

FASTA record trait implemented by both RefRecord and OwnedRecord

Functions

write_head

Writes only the sequence header.

write_id_desc

Writes only the sequence header given ID and description parts.

write_parts

Writes data to the FASTA format. ID and description parts of the header are supplied separately instead of a whole header line.

write_seq

Writes only the sequence line.

write_seq_iter

Writes the sequence line from an iterator (such as SeqLines)

write_to

Writes data (not necessarily stored in a Record instance) to the FASTA format.

write_wrap

Writes data to the FASTA format. Wraps the sequence to produce multi-line FASTA with a maximum width specified by the wrap parameter.

write_wrap_seq

Writes the sequence line, and wraps the output to a maximum width specified by wrap.

write_wrap_seq_iter

Writes the sequence line from an iterator (such as SeqLines) and wraps the output to a maximum width specified by wrap.