seqtkrs 0.1.1

A Rust reimplementation of seqtk, a fast and lightweight tool for processing biological sequences in FASTA/FASTQ format
Documentation
use crate::core::{SeqReader, SeqRecord, LOOKUP_TABLES};
use anyhow::Result;
use clap::Args;

#[derive(Args, Debug)]
pub struct ListhetArgs {
    /// 输入FASTA文件
    #[arg(value_name = "in.fa")]
    pub input: String,
}

pub fn run(args: &ListhetArgs) -> Result<()> {
    let mut reader = if args.input == "-" {
        SeqReader::from_stdin()
    } else {
        SeqReader::from_path(&args.input)?
    };

    let mut record = SeqRecord::new(Vec::new(), Vec::new());

    while reader.read_next(&mut record)? {
        for (i, &base) in record.seq.iter().enumerate() {
            let nt16 = LOOKUP_TABLES.nt16[base as usize];
            if LOOKUP_TABLES.bitcnt[nt16 as usize] == 2 {
                println!(
                    "{}\t{}\t{}",
                    String::from_utf8_lossy(&record.name),
                    i + 1,
                    base as char
                );
            }
        }
    }

    Ok(())
}