feat: introduce packed matrix storage and layer metadata

Unifies bit and integer matrix storage into `PersistentBitMatrix` and `PersistentCompactIntMatrix` enums, supporting both columnar and memory-mapped single-file layouts. Introduces `LayerMeta` to persist layer dimensions as `layer_meta.json`, enabling correct initialization of implicit presence matrices. Adds CLI commands (`pack` and `--upgrade-index`) to convert existing columnar indices to the compact format and backfill missing metadata. Updates partitionner and layered map logic to use the new persistent builders, optimized memory allocation, and auto-detected storage backends.
This commit is contained in:
Eric Coissac committed 2026-06-03 14:16:04 +02:00
1 parent de1a41810a
commit 173ac9fb42
20 files changed
+799 -271

No files matched your search

+1
View File
@@ -1,4 +1,5 @@
pub mod annotate;
pub mod pack;
pub mod utils;
pub mod distance;
pub mod dump;
+36
View File
@@ -0,0 +1,36 @@
use std::path::PathBuf;
use clap::Args;
use obikindex::KmerIndex;
use obisys::{Reporter, Stage};
use tracing::info;
#[derive(Args)]
pub struct PackArgs {
/// Index directory to pack
pub index: PathBuf,
}
pub fn run(args: PackArgs) {
let idx = KmerIndex::open(&args.index).unwrap_or_else(|e| {
eprintln!("error opening index: {e}");
std::process::exit(1);
});
info!(
"pack: {} partition(s), {} genome(s)",
idx.n_partitions(),
idx.meta().genomes.len(),
);
let mut rep = Reporter::new();
let t = Stage::start("pack");
idx.pack_matrices().unwrap_or_else(|e| {
eprintln!("pack error: {e}");
std::process::exit(1);
});
rep.push(t.stop());
rep.print();
}
+24 -1
View File
@@ -2,6 +2,7 @@ use std::path::PathBuf;
use clap::Args;
use obikindex::{validate_label, KmerIndex};
use obikseq::set_k;
use tracing::info;
#[derive(Args)]
@@ -12,6 +13,10 @@ pub struct UtilsArgs {
/// Set a new genome label: NEW_LABEL=OLD_LABEL
#[arg(long, value_name = "NEW=OLD")]
pub new_label: Option<String>,
/// Add missing layer_meta.json files to each layer (required after upgrading from old indexes)
#[arg(long)]
pub upgrade_index: bool,
}
pub fn run(args: UtilsArgs) {
@@ -22,12 +27,30 @@ pub fn run(args: UtilsArgs) {
run_rename(&args.index, spec);
}
if args.upgrade_index {
any = true;
run_upgrade_index(&args.index);
}
if !any {
eprintln!("utils: no operation specified. Available options: --new-label NEW=OLD");
eprintln!("utils: no operation specified. Available options: --new-label NEW=OLD, --upgrade-index");
std::process::exit(1);
}
}
fn run_upgrade_index(index_path: &PathBuf) {
let idx = KmerIndex::open(index_path).unwrap_or_else(|e| {
eprintln!("error opening index: {e}");
std::process::exit(1);
});
set_k(idx.kmer_size());
idx.upgrade_layer_meta().unwrap_or_else(|e| {
eprintln!("upgrade error: {e}");
std::process::exit(1);
});
info!("upgrade-index: layer_meta.json written to all layers that were missing it");
}
fn run_rename(index_path: &PathBuf, spec: &str) {
let (old_label, new_label) = parse_rename_spec(spec);
+3
View File
@@ -38,6 +38,8 @@ enum Commands {
Reindex(cmd::reindex::ReindexArgs),
/// Miscellaneous index utilities (--rename, …)
Utils(cmd::utils::UtilsArgs),
/// Pack matrix column files into single-file format to reduce query I/O
Pack(cmd::pack::PackArgs),
}
fn main() {
@@ -71,6 +73,7 @@ fn main() {
Commands::Estimate(args) => cmd::estimate::run(args),
Commands::Reindex(args) => cmd::reindex::run(args),
Commands::Utils(args) => cmd::utils::run(args),
Commands::Pack(args) => cmd::pack::run(args),
}
#[cfg(feature = "profiling")]