Add unified matrix builder abstraction and k-mer filtering CLI
Introduces a unified MatrixBuilder abstraction for persistent bit and integer matrices, replacing custom dispatch enums and boolean flags across consumers. Refactors index, merge, and select layers to adopt explicit merge modes and centralized lifecycle management. Adds a complete k-mer filtering implementation with partition-level processing, progress tracking, and a new CLI subcommand supporting configurable predicates and thresholds.
This commit is contained in:
1 parent
b7a8b5e6cf
commit
354e6f9bf1
17 files changed
+588
-125
No files matched your search
@@ -11,8 +11,8 @@ use std::io;
|
||||
use std::path::Path;
|
||||
|
||||
use obicompactvec::{
|
||||
ColGroup, MatrixGroupOps, PersistentBitMatrix, PersistentBitMatrixBuilder,
|
||||
PersistentCompactIntMatrix, PersistentCompactIntMatrixBuilder, TempBitVec, TempCompactIntVec,
|
||||
ColGroup, MatrixBuilder, MatrixGroupOps, PersistentBitMatrix,
|
||||
PersistentCompactIntMatrix, TempBitVec, TempCompactIntVec,
|
||||
};
|
||||
use obikindex::layer::{KmerLayer, LayerContent};
|
||||
use obikindex::{KmerIndex, OKIError, OKIResult};
|
||||
@@ -66,36 +66,15 @@ fn compute_group(mat: &dyn MatrixGroupOps, spec: &OutputCol, threshold: u32) ->
|
||||
})
|
||||
}
|
||||
|
||||
// ── DstBuilder — destination matrix, generic over output content ─────────────
|
||||
// ── AggResult → MatrixBuilder ─────────────────────────────────────────────────
|
||||
|
||||
enum DstBuilder {
|
||||
Bit(PersistentBitMatrixBuilder),
|
||||
Int(PersistentCompactIntMatrixBuilder),
|
||||
}
|
||||
|
||||
impl DstBuilder {
|
||||
fn new(output_presence: bool, n: usize, dir: &Path) -> io::Result<Self> {
|
||||
Ok(if output_presence {
|
||||
DstBuilder::Bit(PersistentBitMatrixBuilder::new(n, dir)?)
|
||||
} else {
|
||||
DstBuilder::Int(PersistentCompactIntMatrixBuilder::new(n, dir)?)
|
||||
})
|
||||
}
|
||||
|
||||
fn add(&mut self, r: AggResult) -> io::Result<()> {
|
||||
match (self, r) {
|
||||
(DstBuilder::Bit(b), AggResult::Bit(v)) => b.add_col_from(&v),
|
||||
(DstBuilder::Bit(b), AggResult::Int(v)) => b.add_col_from_int(&v),
|
||||
(DstBuilder::Int(b), AggResult::Bit(v)) => b.add_col_from_bit(&v),
|
||||
(DstBuilder::Int(b), AggResult::Int(v)) => b.add_col_from(&v),
|
||||
}
|
||||
}
|
||||
|
||||
fn close(self) -> io::Result<()> {
|
||||
match self {
|
||||
DstBuilder::Bit(b) => b.close(),
|
||||
DstBuilder::Int(b) => b.close(),
|
||||
}
|
||||
/// Add one already-aggregated column to `mb` — the only piece `MatrixBuilder`
|
||||
/// (generic row/column mechanics, `obicompactvec`) can't know itself, since
|
||||
/// `AggResult` is select's own aggregation-output type.
|
||||
fn add_result(mb: &mut MatrixBuilder, r: AggResult) -> io::Result<()> {
|
||||
match r {
|
||||
AggResult::Bit(v) => mb.add_col_from_bit(&v),
|
||||
AggResult::Int(v) => mb.add_col_from_int(&v),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -156,10 +135,10 @@ pub(crate) fn select_partition(
|
||||
let data_dir = dst_layer_dir.join(data_subdir);
|
||||
fs::create_dir_all(&data_dir).map_err(OKIError::Io)?;
|
||||
|
||||
let mut builder = DstBuilder::new(output_presence, n, &data_dir).map_err(OKIError::Io)?;
|
||||
let mut builder = MatrixBuilder::new(output_presence, n, &data_dir).map_err(OKIError::Io)?;
|
||||
for spec in specs {
|
||||
let r = compute_group(group_mat.as_ref(), spec, threshold).map_err(OKIError::Io)?;
|
||||
builder.add(r).map_err(OKIError::Io)?;
|
||||
add_result(&mut builder, r).map_err(OKIError::Io)?;
|
||||
}
|
||||
builder.close().map_err(OKIError::Io)?;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user