Function fastx::FastX::reader_from_path

source ·
pub fn reader_from_path(path: &Path) -> Result<BufReader<File>>
Examples found in repository?
examples/fastx_cat.rs (line 12)
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
fn main() -> io::Result<()>
{
    for filename in args().skip(1)
    {
        println!("{}", filename);
        let mut fastx_reader = FastX::reader_from_path(Path::new(&filename))?;
        let mut fastx_record = FastX::from_reader(&mut fastx_reader)?;

        while let Ok(_some @ 1..=usize::MAX) = fastx_record.read(&mut fastx_reader)
        {
            println!(">{} {}\n{}", fastx_record.id(), fastx_record.desc(), String::from_utf8_lossy(&fastx_record.seq()));
        }
    }
    Ok(())
}
More examples
Hide additional examples
examples/fastq_cat.rs (line 13)
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
fn main() -> io::Result<()>
{
    for filename in args().skip(1)
    {
        println!("{}", filename);
        let mut fastx_reader = FastX::reader_from_path(Path::new(&filename))?;
        let mut fastq_record = FastX::FastQRecord::default();

        while let Ok(_some @ 1..=usize::MAX) = fastq_record.read(&mut fastx_reader)
        {
            println!("@{} {}\n{}\n+{}\n{}",
                     fastq_record.id(),
                     fastq_record.desc(),
                     String::from_utf8_lossy(&fastq_record.seq()),
                     fastq_record.comment(),
                     String::from_utf8_lossy(&fastq_record.qual()));
        }
    }
    Ok(())
}
examples/fastx_count.rs (line 12)
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
fn main() -> io::Result<()>
{
    for filename in args().skip(1)
    {
        println!("{}", filename);
        let mut fastx_reader = FastX::reader_from_path(Path::new(&filename))?;
        let mut fastx_record = FastX::from_reader(&mut fastx_reader)?;

        /*
        // just for fun read the first line and seek back
        use std::io::BufRead;
        let mut line = String::new();
        let offset = fastx_reader.read_line(&mut line)?;
        println!("{}", line);
        fastx_reader.seek_relative(- (offset as i64))?;
        */

        // back to serious processing
        while let Ok(_some @ 1..=usize::MAX) = fastx_record.read(&mut fastx_reader)
        {
            println!("{}\t{}", fastx_record.id(), fastx_record.seq_len())
        }
    }
    Ok(())
}