Function fastq::parse_path [] [src]

pub fn parse_path<P, F, O>(path: Option<P>, func: F) -> Result<O> where
    P: AsRef<Path>,
    F: FnOnce(Parser<&mut Read>) -> O, 

Create a parser and guess the compression.

At the moment this supports gzip, lz4 and plain fastq files. If the path is None, read from stdin.

Examples

use fastq::{parse_path, Record};
use std::env::args;

let filename = args().nth(1);
// Accept "-" as stdin
let path = match filename.as_ref().map(String::as_ref) {
    None | Some("-") => { None },
    Some(name) => Some(name)
};

parse_path(path, |mut parser| {
    let stopped = parser.each(|record| {
        // stop parsing if we find a sequnce containing 'N'
        record.validate_dnan()
    }).expect("Invalid fastq file");
    if stopped {
        println!("The file contains only sequences with ACTGN");
    } else {
        println!("The file contains invalid sequences");
    }
}).expect("Invalid compression");