Implement pack CLI command for matrix packing and layer compaction
Adds the `pack` subcommand to `obikmer2` for persisting presence and count matrices in sparse or dense formats. Introduces the `compact_layer` module in `obikrebuild` to merge multiple partition layers into a single layer in-place via atomic operations. Updates dependencies across `obikdump`, `obikmer2`, and `obikrebuild` to resolve new local crate references. Shifts the architecture from multi-layer accumulation to in-place compaction, removing legacy rebuild modules.
This commit is contained in:
1 parent
96dfb5300b
commit
904d85f33b
12 files changed
+252
-382
No files matched your search
@@ -19,6 +19,7 @@ obikmerge = { path = "../obikmerge" }
|
||||
obikfilter = { path = "../obikfilter" }
|
||||
obikselect = { path = "../obikselect" }
|
||||
obikdump = { path = "../obikdump" }
|
||||
obikrebuild = { path = "../obikrebuild" }
|
||||
obifastwrite = { path = "../obifastwrite" }
|
||||
obiskbuilder = { path = "../obiskbuilder" }
|
||||
clap = { version = "4", features = ["derive"] }
|
||||
|
||||
@@ -4,6 +4,7 @@ pub mod estimate;
|
||||
pub mod filter;
|
||||
pub mod index;
|
||||
pub mod merge;
|
||||
pub mod pack;
|
||||
mod predicate;
|
||||
pub mod select;
|
||||
pub mod superkmer;
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
use std::path::PathBuf;
|
||||
|
||||
use clap::Args;
|
||||
use obikindex::KmerIndex;
|
||||
use obikrebuild::IndexCompact;
|
||||
use obisys::{Reporter, Stage, progress_bar};
|
||||
use tracing::info;
|
||||
|
||||
#[derive(Args)]
|
||||
pub struct PackArgs {
|
||||
/// Index directory to pack
|
||||
pub index: PathBuf,
|
||||
|
||||
/// Compact every partition's accumulated layers into one before packing
|
||||
/// — undoes the multi-layer stopgap `merge` leaves behind.
|
||||
#[arg(long, default_value_t = false)]
|
||||
pub compact_layers: bool,
|
||||
|
||||
/// Pack presence and count matrices into the dense on-disk format instead
|
||||
/// of the default sparse, deduplicated one. Dense is faster for
|
||||
/// column-oriented access (`--metric` distance matrices); sparse is
|
||||
/// smaller and faster for single-row access on real, sparse data.
|
||||
#[arg(long, default_value_t = false)]
|
||||
pub dense: bool,
|
||||
}
|
||||
|
||||
pub fn run(args: PackArgs) {
|
||||
// Modifies the index in place; acquired before opening so a concurrent
|
||||
// writer can't slip in between the open and the pack below.
|
||||
let _lock = obisys::DirLock::acquire(&args.index).unwrap_or_else(|e| {
|
||||
eprintln!("error locking index directory {}: {e}", args.index.display());
|
||||
std::process::exit(1);
|
||||
});
|
||||
|
||||
let idx = KmerIndex::open(&args.index).unwrap_or_else(|e| {
|
||||
eprintln!("error opening index: {e}");
|
||||
std::process::exit(1);
|
||||
});
|
||||
|
||||
let n_genomes = idx.meta().genomes().unwrap_or_else(|e| {
|
||||
eprintln!("error reading index metadata: {e}");
|
||||
std::process::exit(1);
|
||||
}).len();
|
||||
info!(
|
||||
"pack: {} partition(s), {} genome(s)",
|
||||
idx.n_partitions(),
|
||||
n_genomes,
|
||||
);
|
||||
|
||||
let mut rep = Reporter::new();
|
||||
|
||||
if args.compact_layers {
|
||||
let t = Stage::start("compact layers");
|
||||
let pb = progress_bar("compact", idx.n_partitions() as u64, "partitions");
|
||||
idx.compact_layers(|| pb.inc(1)).unwrap_or_else(|e| {
|
||||
eprintln!("compact error: {e}");
|
||||
std::process::exit(1);
|
||||
});
|
||||
pb.finish_and_clear();
|
||||
rep.push(t.stop());
|
||||
}
|
||||
|
||||
let t = Stage::start("pack");
|
||||
idx.pack_matrices(!args.dense).unwrap_or_else(|e| {
|
||||
eprintln!("pack error: {e}");
|
||||
std::process::exit(1);
|
||||
});
|
||||
rep.push(t.stop());
|
||||
|
||||
rep.print();
|
||||
}
|
||||
@@ -27,6 +27,8 @@ enum Commands {
|
||||
Dump(cmd::dump::DumpArgs),
|
||||
/// Assemble an index's kmers into unitigs and write them as FASTA
|
||||
Unitig(cmd::unitig::UnitigArgs),
|
||||
/// Pack an index's matrices into single-file, sparse format by default (--dense to opt out), in place
|
||||
Pack(cmd::pack::PackArgs),
|
||||
/// Estimate approximate-evidence false-positive rates for given parameters
|
||||
Estimate(cmd::estimate::EstimateArgs),
|
||||
/// Read/write genome metadata (CSV) on an already-built index
|
||||
@@ -50,6 +52,7 @@ fn main() {
|
||||
Commands::Select(args) => cmd::select::run(args),
|
||||
Commands::Dump(args) => cmd::dump::run(args),
|
||||
Commands::Unitig(args) => cmd::unitig::run(args),
|
||||
Commands::Pack(args) => cmd::pack::run(args),
|
||||
Commands::Estimate(args) => cmd::estimate::run(args),
|
||||
Commands::Annotate(args) => cmd::annotate::run(args),
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user