refactor: pass Unitig objects directly instead of raw byte slices

Refactored `try_for_each_unitig` and related pipelines across `obidebruinj` and `obikpartitionner` to accept `Unitig` instances directly. This eliminates manual `Unitig::from_nucleotides()` conversions, simplifies the data flow, and reduces unnecessary allocation overhead.
This commit is contained in:
Eric Coissac
2026-06-13 10:46:35 +02:00
parent 1f336fe496
commit fb8c6e427c
5 changed files with 14 additions and 16 deletions
+6 -8
View File
@@ -1,7 +1,7 @@
//use ahash::RandomState;
use hashbrown::HashMap;
use obikseq::k;
use obikseq::{CanonicalKmer, Sequence};
use obikseq::{CanonicalKmer, Sequence, Unitig};
use rayon::iter::{IntoParallelRefIterator, ParallelIterator};
use std::cell::RefCell;
use std::fmt;
@@ -452,17 +452,17 @@ impl GraphDeBruijn {
pub fn try_for_each_unitig<E, F>(&self, f: F) -> Result<(), E>
where
E: Send,
F: FnMut(&[u8]) -> Result<(), E> + Send,
F: FnMut(&Unitig) -> Result<(), E> + Send,
{
thread_local! {
static BUF: RefCell<Vec<u8>> = RefCell::new(Vec::with_capacity(4096));
}
let (tx, rx) = crossbeam_channel::bounded::<Vec<u8>>(rayon::current_num_threads() * 256);
let (tx, rx) = crossbeam_channel::bounded::<Unitig>(rayon::current_num_threads() * 256);
std::thread::scope(|s| {
let writer = s.spawn(move || -> Result<(), E> {
let mut f = f;
for nucs in rx {
f(&nucs)?;
for unitig in rx {
f(&unitig)?;
}
Ok(())
});
@@ -471,9 +471,7 @@ impl GraphDeBruijn {
let mut buf = buf.borrow_mut();
buf.clear();
buf.extend(iter);
let to_send = buf.clone();
buf.clear();
tx.send(to_send).ok();
tx.send(Unitig::from_nucleotides(&buf)).ok();
});
});
drop(tx);
+2 -2
View File
@@ -24,8 +24,8 @@ fn canonical_kmers(seq: &[u8]) -> Vec<CanonicalKmer> {
fn collect_unitigs(g: &GraphDeBruijn) -> Vec<Unitig> {
let mut unitigs = Vec::new();
g.try_for_each_unitig(|nucs| -> Result<(), std::convert::Infallible> {
unitigs.push(Unitig::from_nucleotides(nucs));
g.try_for_each_unitig(|unitig| -> Result<(), std::convert::Infallible> {
unitigs.push(unitig.clone());
Ok(())
})
.unwrap();