Extract k-mer counting logic into a dedicated counter module

Decouple k-mer counting from the partitioner by introducing a new `Counter` struct. The module exposes a fluent builder API with optional partial file retention, executes partition processing in parallel via Rayon with memory-aware chunk sizing, and integrates thread-safe progress callbacks. Update all callers to use the new counter, simplify test pipelines by removing serialization overhead, and clarify algorithm separation in module documentation.
This commit is contained in:
Eric Coissac committed 2026-08-21 05:48:02 +02:00
1 parent 96b6517541
commit 878b63566f
12 files changed
+376 -129

No files matched your search

+10 -7
View File
@@ -2,6 +2,7 @@ use std::path::PathBuf;
use std::time::Instant;
use clap::Args;
use obikindexer::algorithms::counter::Counter;
use obikindexer::algorithms::dereplicator::Dereplicator;
use obikindexer::algorithms::partitionner::PartitionRouter;
use obikindex::{validate_label, GenomeInfo, IndexConfig, IndexState, KmerIndex};
@@ -301,15 +302,17 @@ pub fn run(args: IndexArgs) {
pb.finish_and_clear();
rep.push(t.stop());
let router = PartitionRouter::new(&mut idx);
let t = Stage::start("count_kmer");
let spectrum = router.count_kmer(args.keep_intermediate).unwrap_or_else(|e| {
eprintln!("error: {e}");
std::process::exit(1);
});
let pb = progress_bar("counting", idx.n_partitions() as u64, "partitions");
let spectrum = Counter::new(&idx)
.keep_partial(args.keep_intermediate)
.run(Some(|_: Progress| pb.inc(1)))
.unwrap_or_else(|e| {
eprintln!("error: {e}");
std::process::exit(1);
});
pb.finish_and_clear();
rep.push(t.stop());
drop(router); // ends the borrow of `idx` early — `PartitionRouter`'s `Drop` impl would otherwise extend it to the end of scope
idx.write_spectrum(spectrum.f0, spectrum.f1, &spectrum.counts).unwrap_or_else(|e| {
eprintln!("error: {e}");