[][src]Module seq_io::fastx

FASTX reading and writing

The fastx reader guesses the sequence format based on examination of the first non-empty line (should start with > for FASTA and @ for FASTQ). Once the format is known, the file is parsed according to the behaviour described in the fasta and fastq.

Flavours

There are two flavours of this parser:

Trait object approach

In addition to the above readers, an approach to FASTX reading using trait objects was implemented. It can be found in the fastx::dynamic module. The API is different, but has the advantage that it theoretically allows integrating sequence parsers not defined in this crate.

Example

This example parses FASTQ and transcribes it to FASTA.

use seq_io::prelude::*;
use seq_io::fastx::Reader;
use seq_io::fastx::SeqFormat;

let fastq = b"@id1
SEQUENCE
+
IIIIIIII
@id2
SEQUENCE
+
IIIIIIII
";

// Construct the reader
let mut reader = Reader::new(&fastq[..]);

// Records are written here
let mut output = vec![];

while let Some(result) = reader.next() {
    let rec = result.unwrap();
    rec.write_as(&mut output, SeqFormat::FASTA, None).unwrap();
}

let fasta_equivalent = b">id1
SEQUENCE
>id2
SEQUENCE
";

assert_eq!(output, fasta_equivalent);

Modules

dynamic

This module provides types and functions for FASTX reading via dynamic dispatch.

multiline_qual

FASTX reading with multi-line FASTQ support.

Structs

Error

Parsing error

LineStore
OwnedRecord

A FASTX record that ownes its data (requires allocations)

Reader

FASTX parser

RecordSet

Set of sequence records that owns it's 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 FASTX record that borrows data from a buffer It implements the traits BaseRecord and Record.

Enums

ErrorKind

The kind of error. Currently it has the same options as seq_io::fastq::ErrorKind.

SeqFormat

Traits

Record

FASTX record trait implemented by both RefRecord and OwnedRecord which adds more methods to BaseRecord.

Functions

recognize_format

Returns the sequence format guess based on the first character: > for FASTA, @ for FASTA. Empty input results in None, an invalid character results in an error of kind ErrorKind::InvalidStart. The tuple at the second position contains the byte offset of the first character in the buffer and the line offset in the file. Returns None if the file is empty.

Type Definitions

Result