Introduce obikalgorithm crate to unify pipeline algorithms

Define a shared Algorithm trait with an associated Output type and a parameterless run(&mut self) method. Refactor PartitionRouter, Dereplicator, Counter, and LayerBuilder to implement the trait, standardizing receivers to &mut self and moving configuration and progress callbacks to dedicated builder setters. Decouple error handling using a generic boxed error type and update workspace dependencies accordingly.
This commit is contained in:
Eric Coissac
2026-08-21 22:03:08 +02:00
parent 8d6ba6546b
commit 00ba968628
15 changed files with 401 additions and 146 deletions
+3 -2
View File
@@ -18,7 +18,8 @@ rayon = "1"
tracing = "0.1.44"
[dev-dependencies]
obiread = { path = "../obiread" }
obikindexer = { path = "../obikindexer" }
obiread = { path = "../obiread" }
obikindexer = { path = "../obikindexer" }
obikalgorithm = { path = "../obikalgorithm" }
tempfile = "3"
tracing-subscriber = { version = "0.3", features = ["fmt", "env-filter"] }
+6 -5
View File
@@ -6,6 +6,7 @@ use obikindex::layer::MphfLayer;
use obisys::Reporter;
use tempfile::tempdir;
use obikalgorithm::Algorithm;
use obikindexer::algorithms::counter::Counter;
use obikindexer::algorithms::dereplicator::Dereplicator;
use obikindexer::algorithms::layer_builder::LayerBuilder;
@@ -68,11 +69,11 @@ fn build_single_genome_index(dir: &Path, label: &str, seq: &[u8]) -> KmerIndex {
evidence: obikindex::layer::IndexMode::Exact,
block_bits: 0,
};
let mut idx = KmerIndex::create(&index_path, config, Some(GenomeInfo::new(label)))
let idx = KmerIndex::create(&index_path, config, Some(GenomeInfo::new(label)))
.expect("create");
let stream = obiread::open_nuc_stream(fasta_path.to_str().unwrap(), K).expect("open fasta");
let mut router = PartitionRouter::new(&mut idx);
let mut router = PartitionRouter::new(&idx);
for page in stream {
let batch = obiskbuilder::build_superkmers_page(page, K, /* level_max */ 1, /* theta */ 0.0);
router.write_batch(batch).expect("write_batch");
@@ -80,10 +81,10 @@ fn build_single_genome_index(dir: &Path, label: &str, seq: &[u8]) -> KmerIndex {
router.close().expect("close partition writers"); // also marks scatter done
drop(router); // ends the borrow of `idx` early — `PartitionRouter`'s `Drop` impl would otherwise extend it to the end of scope
Dereplicator::new(&idx).run(None::<fn(obisys::Progress)>).expect("dereplicate");
Counter::new(&idx).run(None::<fn(obisys::Progress)>).expect("count_kmer"); // also writes the spectrum + marks counted
Dereplicator::new(&idx).run().expect("dereplicate");
Counter::new(&idx).run().expect("count_kmer"); // also writes the spectrum + marks counted
LayerBuilder::new(&idx)
.run(None::<fn(obisys::Progress)>)
.run()
.expect("build_layers"); // also marks indexed
idx
}