Add unitig extraction command to obikdump and obikmer2
Introduces a new unitig extraction feature that reads k-mers from an index, filters them by group metadata, and partitions the computation using rayon. The implementation constructs per-partition de Bruijn graphs, merges them, computes node degrees, and writes the resulting sequences as FASTA. A corresponding CLI command is added to obikmer2 to expose this functionality with configurable filtering and progress reporting.
This commit is contained in:
1 parent
768fa0183d
commit
96dfb5300b
7 files changed
+129
-5
No files matched your search
@@ -7,3 +7,4 @@ pub mod merge;
|
||||
mod predicate;
|
||||
pub mod select;
|
||||
pub mod superkmer;
|
||||
pub mod unitig;
|
||||
@@ -0,0 +1,46 @@
|
||||
use std::io::{self, BufWriter};
|
||||
use std::path::PathBuf;
|
||||
|
||||
use clap::Args;
|
||||
use obikdump::IndexUnitigs;
|
||||
use obikfilter::KmerFilter;
|
||||
use obikindex::KmerIndex;
|
||||
use obisys::progress_bar;
|
||||
use tracing::info;
|
||||
|
||||
use super::predicate::GroupFilterArgs;
|
||||
|
||||
#[derive(Args)]
|
||||
pub struct UnitigArgs {
|
||||
/// Index directory
|
||||
pub index: PathBuf,
|
||||
|
||||
#[command(flatten)]
|
||||
pub group_filter: GroupFilterArgs,
|
||||
}
|
||||
|
||||
pub fn run(args: UnitigArgs) {
|
||||
let idx = KmerIndex::open(&args.index).unwrap_or_else(|e| {
|
||||
eprintln!("error opening index: {e}");
|
||||
std::process::exit(1);
|
||||
});
|
||||
|
||||
info!(
|
||||
"unitig: building de Bruijn graph from {} partition(s) (k={})",
|
||||
idx.n_partitions(),
|
||||
idx.kmer_size(),
|
||||
);
|
||||
|
||||
let filters: Vec<Box<dyn KmerFilter>> = vec![Box::new(args.group_filter.build_filter(&idx.meta()))];
|
||||
let pb = progress_bar("unitig", idx.n_partitions() as u64, "partitions");
|
||||
|
||||
let mut out = BufWriter::new(io::stdout());
|
||||
|
||||
let n = idx.write_unitigs(&mut out, &filters, || pb.inc(1)).unwrap_or_else(|e| {
|
||||
eprintln!("unitig error: {e}");
|
||||
std::process::exit(1);
|
||||
});
|
||||
pb.finish_and_clear();
|
||||
|
||||
info!("unitig: {n} unitig(s) written");
|
||||
}
|
||||
@@ -25,6 +25,8 @@ enum Commands {
|
||||
Select(cmd::select::SelectArgs),
|
||||
/// Dump an index's kmers as a CSV table
|
||||
Dump(cmd::dump::DumpArgs),
|
||||
/// Assemble an index's kmers into unitigs and write them as FASTA
|
||||
Unitig(cmd::unitig::UnitigArgs),
|
||||
/// Estimate approximate-evidence false-positive rates for given parameters
|
||||
Estimate(cmd::estimate::EstimateArgs),
|
||||
/// Read/write genome metadata (CSV) on an already-built index
|
||||
@@ -47,6 +49,7 @@ fn main() {
|
||||
Commands::Filter(args) => cmd::filter::run(args),
|
||||
Commands::Select(args) => cmd::select::run(args),
|
||||
Commands::Dump(args) => cmd::dump::run(args),
|
||||
Commands::Unitig(args) => cmd::unitig::run(args),
|
||||
Commands::Estimate(args) => cmd::estimate::run(args),
|
||||
Commands::Annotate(args) => cmd::annotate::run(args),
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user