feat: add merge command to consolidate k-mer indexes

Introduces a new `merge` CLI subcommand and underlying implementation to consolidate multiple pre-indexed k-mer indexes into a single output. Adds `append_column` methods to persistent bit and int matrices to enable incremental genome column expansion without rebuilding the MPHF. Includes new error variants for index readiness and configuration mismatches, adds a `--force` flag to the index command, and updates documentation and navigation structure accordingly.
This commit is contained in:
Eric Coissac committed 2026-05-21 13:44:50 +02:00
1 parent bfa436ad15
commit e1d59fde54
17 files changed
+799 -8

No files matched your search

+9 -2
View File
@@ -48,20 +48,27 @@ pub fn run(args: IndexArgs) {
let mut rep = Reporter::new();
// ── Open or create the index ─────────────────────────────────────────────
let mut idx = if KmerIndex::exists(&output) {
let mut idx = if KmerIndex::exists(&output) && !args.force {
info!("resuming from existing index at {}", output.display());
KmerIndex::open(&output).unwrap_or_else(|e| {
eprintln!("error opening index: {e}");
std::process::exit(1);
})
} else {
if args.force && KmerIndex::exists(&output) {
info!("--force: removing existing index at {}", output.display());
std::fs::remove_dir_all(&output).unwrap_or_else(|e| {
eprintln!("error removing existing index: {e}");
std::process::exit(1);
});
}
let config = IndexConfig {
kmer_size: args.common.kmer_size,
minimizer_size: args.common.minimizer_size,
n_bits: args.common.partition_bits,
with_counts: args.with_counts,
};
KmerIndex::create(&output, config, args.label.clone(), args.force).unwrap_or_else(|e| {
KmerIndex::create(&output, config, args.label.clone(), false).unwrap_or_else(|e| {
eprintln!("error creating index: {e}");
std::process::exit(1);
})
+47
View File
@@ -0,0 +1,47 @@
use std::path::PathBuf;
use clap::Args;
use obikindex::{KmerIndex, MergeMode};
use obisys::Reporter;
use tracing::info;
#[derive(Args)]
pub struct MergeArgs {
/// Source index directories to merge
#[arg(required = true)]
pub sources: Vec<PathBuf>,
/// Output index directory
#[arg(short, long)]
pub output: PathBuf,
/// Overwrite output directory if it already exists
#[arg(long, default_value_t = false)]
pub force: bool,
/// Merge in count mode (requires all sources to have with_counts=true)
#[arg(long, default_value_t = false)]
pub with_counts: bool,
}
pub fn run(args: MergeArgs) {
let mode = if args.with_counts { MergeMode::Count } else { MergeMode::Presence };
let sources: Vec<KmerIndex> = args.sources.iter().map(|p| {
info!("opening source index: {}", p.display());
KmerIndex::open(p).unwrap_or_else(|e| {
eprintln!("error opening source index {}: {e}", p.display());
std::process::exit(1);
})
}).collect();
let source_refs: Vec<&KmerIndex> = sources.iter().collect();
info!("merging {} indexes → {}", sources.len(), args.output.display());
let rep = Reporter::new();
KmerIndex::merge(&args.output, &source_refs, mode, args.force).unwrap_or_else(|e| {
eprintln!("error merging: {e}");
std::process::exit(1);
});
rep.print();
}
+1
View File
@@ -1,3 +1,4 @@
pub mod index;
pub mod merge;
pub mod superkmer;
pub mod unitig;
+3
View File
@@ -18,6 +18,8 @@ enum Commands {
Superkmer(cmd::superkmer::SuperkmerArgs),
/// Build the complete genome index (scatter → dereplicate → count → layered MPHF)
Index(cmd::index::IndexArgs),
/// Merge multiple built indexes into one
Merge(cmd::merge::MergeArgs),
/// Dump unitigs from a built index to stdout (debug)
Unitig(cmd::unitig::UnitigArgs),
}
@@ -43,6 +45,7 @@ fn main() {
match cli.command {
Commands::Superkmer(args) => cmd::superkmer::run(args),
Commands::Index(args) => cmd::index::run(args),
Commands::Merge(args) => cmd::merge::run(args),
Commands::Unitig(args) => cmd::unitig::run(args),
}