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};
use anyhow::Result;
use clap::Args;

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

pub fn run(args: &HpcArgs) -> 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)? {
        if record.seq.is_empty() {
            continue;
        }

        let mut compressed = Vec::new();
        let mut last = 0usize;

        for i in 1..=record.seq.len() {
            if i == record.seq.len() || record.seq[last] != record.seq[i] {
                compressed.push(record.seq[last]);
                last = i;
            }
        }

        println!(">{}", String::from_utf8_lossy(&record.name));
        println!("{}", String::from_utf8_lossy(&compressed));
    }

    Ok(())
}