rsomics-fasta-utils 0.1.2

FASTA utility toolkit — count, chroms, len, revcomp, rename, tab, wrap, unique, convert, and more
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
use needletail::parse_fastx_file;
use rsomics_common::{Result, RsomicsError};
use std::path::Path;

pub fn count(input: &Path) -> Result<u64> {
    if std::fs::metadata(input).is_ok_and(|m| m.len() == 0) {
        return Ok(0);
    }
    let mut reader = parse_fastx_file(input)
        .map_err(|e| RsomicsError::InvalidInput(format!("{}: {e}", input.display())))?;
    let mut n: u64 = 0;
    while let Some(record) = reader.next() {
        record.map_err(|e| RsomicsError::InvalidInput(format!("parsing: {e}")))?;
        n += 1;
    }
    Ok(n)
}