feat: add parallel k-mer counting and stats CLI

Introduces allocation-free `sum()` and `count_nonzero()` methods for compact integer vectors, extending the `ColumnWeights` trait with `partial_kmer_counts`. Adds parallel partition scanning to the k-mer index for computing per-genome distinct k-mer counts, and exposes a new `--stats` CLI flag to output these statistics as CSV.
This commit is contained in:
Eric Coissac committed 2026-06-12 11:29:32 +02:00
1 parent 94e0a370b3
commit f44fe042bc
5 files changed
+126 -3

No files matched your search

+26 -1
View File
@@ -20,6 +20,10 @@ pub struct UtilsArgs {
/// Print bits-per-kmer statistics (MPHF, evidence, matrix, total)
#[arg(long)]
pub bits_per_kmer: bool,
/// Print per-genome k-mer counts as CSV (one row per genome + total line)
#[arg(long)]
pub stats: bool,
}
pub fn run(args: UtilsArgs) {
@@ -40,12 +44,33 @@ pub fn run(args: UtilsArgs) {
run_bits_per_kmer(&args.index);
}
if args.stats {
any = true;
run_stats(&args.index);
}
if !any {
eprintln!("utils: no operation specified. Available options: --new-label NEW=OLD, --upgrade-index, --bits-per-kmer");
eprintln!("utils: no operation specified. Available options: --new-label NEW=OLD, --upgrade-index, --bits-per-kmer, --stats");
std::process::exit(1);
}
}
fn run_stats(index_path: &PathBuf) {
let idx = KmerIndex::open(index_path).unwrap_or_else(|e| {
eprintln!("error opening index: {e}");
std::process::exit(1);
});
let (total, per_genome) = idx.genome_kmer_counts().unwrap_or_else(|e| {
eprintln!("error computing stats: {e}");
std::process::exit(1);
});
println!("genome,n_kmers");
for (g, &n) in idx.meta().genomes.iter().zip(per_genome.iter()) {
println!("{},{}", g.label, n);
}
println!("total,{total}");
}
fn run_bits_per_kmer(index_path: &PathBuf) {
let idx = KmerIndex::open(index_path).unwrap_or_else(|e| {
eprintln!("error opening index: {e}");