refactor: centralize k-mer config and introduce packed sequences
Centralize k-mer and minimizer configuration using a thread-safe global module, and replace manual bit-packing with a memory-efficient `PackedSeq` type. Refactor core sequence and k-mer types to use compile-time length enforcement and centralized hashing. Introduce a new De Bruijn graph implementation with compact node encoding and traversal iterators. Update I/O, partitioning, and builder modules to align with the new architecture, and add the `xxhash-rust` dependency.
This commit is contained in:
1 parent
602f414957
commit
8c17bf958b
37 files changed
+2641
-2456
No files matched your search
@@ -64,7 +64,7 @@ fn dump_super_kmers(kp: &KmerPartition, partition_dir: &PathBuf) {
|
||||
std::process::exit(1)
|
||||
});
|
||||
|
||||
let mut reader = SKFileReader::open(&in_path, k).unwrap_or_else(|e| {
|
||||
let mut reader = SKFileReader::open(&in_path).unwrap_or_else(|e| {
|
||||
eprintln!("error opening {}: {e}", in_path.display());
|
||||
std::process::exit(1)
|
||||
});
|
||||
|
||||
@@ -7,6 +7,7 @@ use niffler::Level;
|
||||
use niffler::send::compression::Format;
|
||||
use obidebruinj::GraphDeBruijn;
|
||||
use obikpartitionner::KmerPartition;
|
||||
use obikseq::set_k;
|
||||
use obiskio::SKFileReader;
|
||||
use ph::fmph::GOFunction;
|
||||
use rayon::prelude::*;
|
||||
@@ -33,6 +34,7 @@ pub fn run(args: LongtigArgs) {
|
||||
});
|
||||
|
||||
let k = kp.kmer_size();
|
||||
set_k(k);
|
||||
let n = kp.n_partitions();
|
||||
info!("building longtigs from {n} partitions (k={k}, parallel)");
|
||||
|
||||
@@ -46,7 +48,7 @@ pub fn run(args: LongtigArgs) {
|
||||
}
|
||||
let out_path = part_dir.join("longtig.fasta.gz");
|
||||
|
||||
let mut g = GraphDeBruijn::new(k);
|
||||
let mut g = GraphDeBruijn::new();
|
||||
|
||||
let mphf_path = part_dir.join("mphf1.bin");
|
||||
let counts_path = part_dir.join("counts1.bin");
|
||||
@@ -86,12 +88,12 @@ pub fn run(args: LongtigArgs) {
|
||||
.as_ref()
|
||||
.map(|m| unsafe { std::slice::from_raw_parts(m.as_ptr() as *const u32, m.len() / 4) });
|
||||
|
||||
let mut reader = SKFileReader::open(&in_path, k).unwrap_or_else(|e| {
|
||||
let mut reader = SKFileReader::open(&in_path).unwrap_or_else(|e| {
|
||||
eprintln!("error opening {}: {e}", in_path.display());
|
||||
std::process::exit(1)
|
||||
});
|
||||
for sk in reader.iter() {
|
||||
for kmer in sk.iter_canonical_kmers(k) {
|
||||
for kmer in sk.iter_canonical_kmers() {
|
||||
let accept = match (&mphf_opt, counts_slice) {
|
||||
(Some(mphf), Some(counts)) => {
|
||||
if let Some(slot) = mphf.get(&kmer) {
|
||||
|
||||
@@ -2,7 +2,7 @@ use std::path::PathBuf;
|
||||
|
||||
use clap::Args;
|
||||
use obikpartitionner::KmerPartition;
|
||||
use obikseq::RoutableSuperKmer;
|
||||
use obikseq::{RoutableSuperKmer, set_k, set_m};
|
||||
use tracing::info;
|
||||
|
||||
use crate::cli::{CommonArgs, PipelineData, open_chunks};
|
||||
@@ -25,7 +25,9 @@ pub struct PartitionArgs {
|
||||
|
||||
pub fn run(args: PartitionArgs) {
|
||||
let k = args.common.kmer_size;
|
||||
set_k(k);
|
||||
let m = args.common.minimizer_size;
|
||||
set_m(m);
|
||||
let theta = args.common.theta;
|
||||
let level_max = args.common.level_max;
|
||||
let n_workers = args.common.threads.max(1);
|
||||
@@ -42,7 +44,7 @@ pub fn run(args: PartitionArgs) {
|
||||
PipelineData : PathBuf => Vec<RoutableSuperKmer>,
|
||||
||? { |path| open_chunks(path) } : Path => RawChunk,
|
||||
|? { move |rope| obiread::normalize_sequence_chunk(rope, k) } : RawChunk => NormChunk,
|
||||
| { move |rope| obiskbuilder::build_superkmers(rope, k, m, level_max, theta) }: NormChunk => Batch,
|
||||
| { move |rope| obiskbuilder::build_superkmers(rope, k, level_max, theta) }: NormChunk => Batch,
|
||||
};
|
||||
|
||||
for batch in pipe.apply(path_source, n_workers, 1) {
|
||||
|
||||
@@ -25,7 +25,7 @@ fn write_batch(
|
||||
let partition_mask = (1u64 << partition_bits) - 1;
|
||||
for rsk in batch {
|
||||
let minimizer = *rsk.minimizer();
|
||||
let partition = (minimizer.seq_hash(m) & partition_mask) as usize;
|
||||
let partition = (minimizer.seq_hash() & partition_mask) as usize;
|
||||
write_scatter(rsk.superkmer(), out, k, m, partition, minimizer)?;
|
||||
}
|
||||
Ok(())
|
||||
@@ -47,7 +47,7 @@ pub fn run(args: SuperkmerArgs) {
|
||||
PipelineData : PathBuf => Vec<RoutableSuperKmer>,
|
||||
||? { |path| open_chunks(path) } : Path => RawChunk,
|
||||
|? { move |rope| obiread::normalize_sequence_chunk(rope, k) } : RawChunk => NormChunk,
|
||||
| { move |rope| obiskbuilder::build_superkmers(rope, k, m, level_max, theta) }: NormChunk => Batch,
|
||||
| { move |rope| obiskbuilder::build_superkmers(rope, k, level_max, theta) }: NormChunk => Batch,
|
||||
};
|
||||
|
||||
let mut out = BufWriter::new(io::stdout());
|
||||
|
||||
@@ -7,6 +7,7 @@ use niffler::Level;
|
||||
use niffler::send::compression::Format;
|
||||
use obidebruinj::GraphDeBruijn;
|
||||
use obikpartitionner::KmerPartition;
|
||||
use obikseq::set_k;
|
||||
use obiskio::SKFileReader;
|
||||
use ph::fmph::GOFunction;
|
||||
use rayon::prelude::*;
|
||||
@@ -33,6 +34,7 @@ pub fn run(args: UnitigArgs) {
|
||||
});
|
||||
|
||||
let k = kp.kmer_size();
|
||||
set_k(k);
|
||||
let n = kp.n_partitions();
|
||||
info!("building unitigs from {n} partitions (k={k}, parallel)");
|
||||
|
||||
@@ -46,7 +48,7 @@ pub fn run(args: UnitigArgs) {
|
||||
}
|
||||
let out_path = part_dir.join("unitig.fasta.gz");
|
||||
|
||||
let mut g = GraphDeBruijn::new(k);
|
||||
let mut g = GraphDeBruijn::new();
|
||||
|
||||
let mphf_path = part_dir.join("mphf1.bin");
|
||||
let counts_path = part_dir.join("counts1.bin");
|
||||
@@ -86,12 +88,12 @@ pub fn run(args: UnitigArgs) {
|
||||
.as_ref()
|
||||
.map(|m| unsafe { std::slice::from_raw_parts(m.as_ptr() as *const u32, m.len() / 4) });
|
||||
|
||||
let mut reader = SKFileReader::open(&in_path, k).unwrap_or_else(|e| {
|
||||
let mut reader = SKFileReader::open(&in_path).unwrap_or_else(|e| {
|
||||
eprintln!("error opening {}: {e}", in_path.display());
|
||||
std::process::exit(1)
|
||||
});
|
||||
for sk in reader.iter() {
|
||||
for kmer in sk.iter_canonical_kmers(k) {
|
||||
for kmer in sk.iter_canonical_kmers() {
|
||||
let accept = match (&mphf_opt, counts_slice) {
|
||||
(Some(mphf), Some(counts)) => {
|
||||
if let Some(slot) = mphf.get(&kmer) {
|
||||
|
||||
Reference in new issue
Block a user