refactor: optimize unitig iteration and graph traversal

Switches unitig processing to a lazy, fallible `try_for_each_unitig` API across partitioner layers, reducing intermediate allocations and enabling proper error propagation. Refactors de Bruijn graph traversal into a two-pass algorithm with explicit node flags, named constants, and diagnostic logging. Introduces parallel chain processing and staged performance profiling for the unitig command, and adds a memory-efficient `FromIterator` implementation for packed nucleotide sequences.
This commit is contained in:
Eric Coissac committed 2026-06-05 19:48:59 +02:00
1 parent ea2c594c86
commit 27088ab810
6 files changed
+511 -274

No files matched your search

+4 -9
View File
@@ -75,7 +75,9 @@ pub fn run(args: UnitigArgs) {
let out = Mutex::new(BufWriter::new(io::stdout()));
let j = AtomicUsize::new(0);
let write_unitig_fn = |unitig: obikseq::unitig::Unitig| {
let stage = Stage::start("enumerate unitigs");
g.for_each_unitig(|nuc_iter| {
let unitig: obikseq::unitig::Unitig = nuc_iter.collect();
let idx = j.fetch_add(1, Ordering::Relaxed);
let mut w = out.lock().unwrap();
write_unitig(&unitig, k, 0, idx, &mut *w).unwrap_or_else(|e| {
@@ -85,14 +87,7 @@ pub fn run(args: UnitigArgs) {
if idx % 10_000 == 0 {
pb.set_message(format!("{idx} unitigs written"));
}
};
let stage = Stage::start("chain unitigs");
g.par_for_each_chain_unitig(&write_unitig_fn);
rep.push(stage.stop());
let stage = Stage::start("remaining unitigs");
g.for_each_remaining_unitig(&write_unitig_fn);
});
pb.finish_and_clear();
rep.push(stage.stop());