feat: enable index resumption and enforce directory creation
The command now supports reopening existing indexes instead of failing when the output file exists. Control flow branches between opening an existing index and constructing a new one, moving configuration setup exclusively to the creation path. Directory existence is enforced upfront with proper I/O error propagation. The --force flag retains its original semantics by removing the target directory before proceeding with a fresh build.
This commit is contained in:
1 parent
abc51c2add
commit
5c1584967f
161 files changed
+5274
-845
No files matched your search
@@ -15,14 +15,11 @@ obifastwrite = { path = "../obifastwrite" }
|
||||
obidebruinj = { path = "../obidebruinj" }
|
||||
obipipeline = { path = "../obipipeline" }
|
||||
obikrope = { path = "../obikrope" }
|
||||
obikpartitionner = { path = "../obikpartitionner" }
|
||||
obikderep = { path = "../obikderep" }
|
||||
obisys = { path = "../obisys" }
|
||||
obiskio = { path = "../obiskio" }
|
||||
obikindex = { path = "../obikindex", default-features = false }
|
||||
obikphylo = { path = "../obikphylo" }
|
||||
obitaxonomy = { path = "../obitaxonomy" }
|
||||
obilayeredmap = { path = "../obilayeredmap" }
|
||||
clap = { version = "4", features = ["derive"] }
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
serde_json = "1"
|
||||
|
||||
@@ -2,10 +2,10 @@ use std::path::PathBuf;
|
||||
use std::time::Instant;
|
||||
|
||||
use clap::Args;
|
||||
use obikderep::Dereplicator;
|
||||
use obikindex::algorithms::dereplicator::Dereplicator;
|
||||
use obikindex::algorithms::partitionner::PartitionRouter;
|
||||
use obikindex::{validate_label, GenomeInfo, IndexConfig, IndexState, KmerIndex};
|
||||
use obikpartitionner::PartitionRouter;
|
||||
use obilayeredmap::IndexMode;
|
||||
use obikindex::layer::IndexMode;
|
||||
|
||||
fn parse_key_value(s: &str) -> Result<(String, String), String> {
|
||||
let pos = s.find('=').ok_or_else(|| format!("invalid key=value: no '=' in '{s}'"))?;
|
||||
@@ -188,50 +188,49 @@ pub fn run(args: IndexArgs) {
|
||||
};
|
||||
|
||||
// ── Open or create the index ─────────────────────────────────────────────
|
||||
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}");
|
||||
if KmerIndex::exists(&output) {
|
||||
if !args.force {
|
||||
eprintln!(
|
||||
"error: an index already exists at {} (use --force to overwrite it)",
|
||||
output.display()
|
||||
);
|
||||
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 n_bits = partitions_to_bits(args.common.partitions);
|
||||
let effective = 1usize << n_bits;
|
||||
if effective != args.common.partitions {
|
||||
info!("partitions: {} → {} (next power of 2)", args.common.partitions, effective);
|
||||
}
|
||||
let block_bits = block_size_to_bits(args.block_size);
|
||||
let config = IndexConfig {
|
||||
kmer_size: effective_kmer_size,
|
||||
minimizer_size: args.common.minimizer_size,
|
||||
n_bits,
|
||||
with_counts: args.with_counts,
|
||||
evidence: evidence.clone(),
|
||||
block_bits,
|
||||
};
|
||||
let genome_info = args.label.as_ref().map(|label| {
|
||||
validate_label(label).unwrap_or_else(|e| {
|
||||
eprintln!("error: --label: {e}");
|
||||
std::process::exit(1);
|
||||
});
|
||||
let mut info = GenomeInfo::new(label.clone());
|
||||
for (k, v) in &args.meta {
|
||||
info.meta.insert(k.clone(), v.clone());
|
||||
}
|
||||
info
|
||||
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);
|
||||
});
|
||||
KmerIndex::create(&output, config, genome_info).unwrap_or_else(|e| {
|
||||
eprintln!("error creating index: {e}");
|
||||
std::process::exit(1);
|
||||
})
|
||||
}
|
||||
let n_bits = partitions_to_bits(args.common.partitions);
|
||||
let effective = 1usize << n_bits;
|
||||
if effective != args.common.partitions {
|
||||
info!("partitions: {} → {} (next power of 2)", args.common.partitions, effective);
|
||||
}
|
||||
let block_bits = block_size_to_bits(args.block_size);
|
||||
let config = IndexConfig {
|
||||
kmer_size: effective_kmer_size,
|
||||
minimizer_size: args.common.minimizer_size,
|
||||
n_bits,
|
||||
with_counts: args.with_counts,
|
||||
evidence: evidence.clone(),
|
||||
block_bits,
|
||||
};
|
||||
let genome_info = args.label.as_ref().map(|label| {
|
||||
validate_label(label).unwrap_or_else(|e| {
|
||||
eprintln!("error: --label: {e}");
|
||||
std::process::exit(1);
|
||||
});
|
||||
let mut info = GenomeInfo::new(label.clone());
|
||||
for (k, v) in &args.meta {
|
||||
info.meta.insert(k.clone(), v.clone());
|
||||
}
|
||||
info
|
||||
});
|
||||
let mut idx = KmerIndex::create(&output, config, genome_info).unwrap_or_else(|e| {
|
||||
eprintln!("error creating index: {e}");
|
||||
std::process::exit(1);
|
||||
});
|
||||
|
||||
|
||||
// ── Stage 1: scatter ─────────────────────────────────────────────────────
|
||||
|
||||
@@ -13,7 +13,7 @@ use std::time::Instant;
|
||||
use clap::Args;
|
||||
use obikindex::KmerIndex;
|
||||
use obikrope::Rope;
|
||||
use obilayeredmap::IndexMode;
|
||||
use obikindex::layer::IndexMode;
|
||||
use obipipeline::{Throttled, ThrottleGuard, throttle};
|
||||
use obiread::chunk::read_sequence_chunks_sized;
|
||||
use obisys::{Reporter, Stage, available_memory_bytes, spinner};
|
||||
|
||||
@@ -2,7 +2,7 @@ use std::path::PathBuf;
|
||||
|
||||
use clap::Args;
|
||||
use obikindex::KmerIndex;
|
||||
use obilayeredmap::IndexMode;
|
||||
use obikindex::layer::IndexMode;
|
||||
use obisys::Reporter;
|
||||
use tracing::info;
|
||||
|
||||
|
||||
Reference in new issue
Block a user