pub fn parse_fastx_reader<'a, R: 'a + Read + Send>(
    reader: R
) -> Result<Box<dyn FastxReader + 'a>, ParseError>
Expand description

The main entry point of needletail if you’re reading from something that implements std::io::Read. This automatically detects whether the file is:

  1. compressed: gzip, bz and xz are supported and will use the appropriate decoder
  2. FASTA or FASTQ: the right parser will be automatically instantiated

Option 1 is only available if the compression feature is enabled.

Errors

If the object you’re reading from has less than 2 bytes then a ParserError of the kind ParseErrorKind::EmptyFile is returned.

If the first byte in the object is unknown, then a ParserError of the kind ParseErrorKind::UnknownFormat is returned.

Examples

use needletail::parse_fastx_reader;

let reader = ">read1\nACGT\nread2\nGGGG".as_bytes();
let mut fastx_reader = parse_fastx_reader(reader).expect("invalid reader");
let mut idx = 0;
let read_ids = [b"read1", b"read2"];

while let Some(r) = fastx_reader.next() {
    let record = r.expect("invalid record");
    assert_eq!(record.id(), read_ids[idx]);
    idx += 1;
}