refactor: relocate partition iterator and expose graph builder API

Move the partition iterator implementation from obikdump to obikfilter, updating imports and exposing the type publicly. Add obikidxcache as a local dependency for obikfilter. In obikindexer, expose the new build_layer_from_kmers function to enable shared graph-building logic across pipelines without code duplication.
This commit is contained in:
Eric Coissac
2026-08-26 09:39:02 +02:00
parent 16ade823d6
commit 294f132a0a
8 changed files with 35 additions and 14 deletions
+1
View File
@@ -1543,6 +1543,7 @@ version = "0.1.0"
dependencies = [ dependencies = [
"obicompactvec", "obicompactvec",
"obikentropy", "obikentropy",
"obikidxcache",
"obikindex", "obikindex",
"obikseq", "obikseq",
"obiskio", "obiskio",
+1 -1
View File
@@ -8,7 +8,7 @@ use obikindex::KmerIndex;
use obikidxcache::index_cache::IndexCache; use obikidxcache::index_cache::IndexCache;
use obikfilter::KmerFilter; use obikfilter::KmerFilter;
use crate::partition_iter::FilteredPartitionIter; use obikfilter::FilteredPartitionIter;
/// Raw content export of a `KmerIndex` — `KmerIndex` is a foreign type /// Raw content export of a `KmerIndex` — `KmerIndex` is a foreign type
/// (`obikindex`), so this is an extension trait rather than an inherent `impl`. /// (`obikindex`), so this is an extension trait rather than an inherent `impl`.
-3
View File
@@ -6,6 +6,3 @@
//! reverse), same pattern as `obikindexer`/`obikquery`. //! reverse), same pattern as `obikindexer`/`obikquery`.
mod dump; mod dump;
mod partition_iter;
pub use partition_iter::FilteredPartitionIter;
+1
View File
@@ -10,3 +10,4 @@ obikseq = { path = "../obikseq" }
obiskio = { path = "../obiskio" } obiskio = { path = "../obiskio" }
obitaxonomy = { path = "../obitaxonomy" } obitaxonomy = { path = "../obitaxonomy" }
obikentropy = { path = "../obikentropy" } obikentropy = { path = "../obikentropy" }
obikidxcache = { path = "../obikidxcache" }
+8 -7
View File
@@ -3,19 +3,20 @@
//! Orthogonal to genome-column selection/aggregation (`obikselect`), which //! Orthogonal to genome-column selection/aggregation (`obikselect`), which
//! operates on already-retained k-mers. //! operates on already-retained k-mers.
//! //!
//! [`filter`] (the `KmerFilter` trait + its implementations) depends only //! [`filter`] (the `KmerFilter` trait + its implementations) is the pure
//! on `obicompactvec`/`obikseq`, not on `obikindex`. The partition/layer //! judging logic. [`partition_iter`] (`FilteredPartitionIter`) is the read
//! iteration that actually runs these filters over an index //! side that actually runs those filters over a *complete* source index's
//! (`iter_partition_kmers`, `iter_partition_kmers_located`) lives in //! partitions/layers, batched through `obikidxcache::IndexCache` for
//! `obikdump` instead (`FilteredPartitionIter`) — it needs `obikidxcache`'s //! locality — used both by `obikdump` (CSV export) and by this crate's own
//! `IndexCache` to read a *complete* source index, which this crate has no //! `Filter` algorithm (index-to-index rebuild).
//! reason to depend on.
mod filter; mod filter;
mod partition_iter;
mod predicate; mod predicate;
pub use filter::{ pub use filter::{
GroupQuorumFilter, KmerFilter, MaxGenomeCount, MaxGenomeFraction, MaxTotalCount, GroupQuorumFilter, KmerFilter, MaxGenomeCount, MaxGenomeFraction, MaxTotalCount,
MinComplexity, MinGenomeCount, MinGenomeFraction, MinTotalCount, passes_all, MinComplexity, MinGenomeCount, MinGenomeFraction, MinTotalCount, passes_all,
}; };
pub use partition_iter::FilteredPartitionIter;
pub use predicate::{GenomeSelector, GroupFilterParams, MetaPred, Selection}; pub use predicate::{GenomeSelector, GroupFilterParams, MetaPred, Selection};
@@ -1,5 +1,5 @@
//! Filtered, batch-oriented iteration over an already-cached index's //! Filtered, batch-oriented iteration over an already-cached index's
//! partitions/layers — the read side of `obikfilter`'s `KmerFilter`s. //! partitions/layers — the read side of [`crate::KmerFilter`]s.
//! `IndexCache` is a foreign type (`obikidxcache`), so this is an extension //! `IndexCache` is a foreign type (`obikidxcache`), so this is an extension
//! trait rather than an inherent `impl`. //! trait rather than an inherent `impl`.
//! //!
@@ -13,7 +13,7 @@ use obikindex::layer::{KmerLayer, LayerContent};
use obikidxcache::index_cache::IndexCache; use obikidxcache::index_cache::IndexCache;
use obikseq::CanonicalKmer; use obikseq::CanonicalKmer;
use obikfilter::{KmerFilter, passes_all}; use crate::filter::{KmerFilter, passes_all};
/// Kmers pulled per batch from a layer before filtering — keeps matrix reads /// Kmers pulled per batch from a layer before filtering — keeps matrix reads
/// grouped by (partition, layer) for locality instead of hopping row to row /// grouped by (partition, layer) for locality instead of hopping row to row
+21
View File
@@ -148,3 +148,24 @@ pub fn materialize_layer(
debug!("materialize_layer: MPHF build done"); debug!("materialize_layer: MPHF build done");
Ok(n) Ok(n)
} }
// ── build_layer_from_kmers ──────────────────────────────────────────────────
/// Build a layer's identity (unitigs + MPHF + evidence) straight from an
/// already-filtered kmer iterator — no file I/O, no abundance filtering:
/// the caller has already decided which kmers survive (e.g. abundance
/// filtering in [`crate::extensions::build_index_layer`], metadata-based
/// filtering in `obikfilter::Filter`). Both share this same construction
/// tail instead of duplicating the graph-building mechanism.
pub fn build_layer_from_kmers(
kmers: impl Iterator<Item = CanonicalKmer>,
layer_dir: &Path,
block_bits: u8,
evidence: &IndexMode,
) -> OKIResult<usize> {
let mut g = GraphDeBruijn::new();
for kmer in kmers {
g.push(kmer);
}
materialize_layer(g, layer_dir, block_bits, evidence)
}
+1 -1
View File
@@ -16,4 +16,4 @@ pub mod algorithms;
pub(crate) mod extensions; pub(crate) mod extensions;
pub mod graph_pipeline; pub mod graph_pipeline;
pub use graph_pipeline::{build_graph, materialize_layer, write_graph_as_unitigs}; pub use graph_pipeline::{build_graph, build_layer_from_kmers, materialize_layer, write_graph_as_unitigs};