.gitignore: ignore zstandard-compressed files
- Add *.zst pattern to .gitignore - Prevents tracking of zstandard-compressed archives
This commit is contained in:
1 parent
1f466bf113
commit
7efec54b27
12 files changed
+281
-94
No files matched your search
@@ -14,4 +14,5 @@ obiskbuilder = { path = "../obiskbuilder" }
|
||||
obifastwrite = { path = "../obifastwrite" }
|
||||
obipipeline = { path = "../obipipeline" }
|
||||
clap = { version = "4", features = ["derive"] }
|
||||
obikrope = { path = "../obikrope" }
|
||||
obikrope = { path = "../obikrope" }
|
||||
obikpartitionner = { path = "../obikpartitionner" }
|
||||
@@ -1 +1,2 @@
|
||||
pub mod partition;
|
||||
pub mod superkmer;
|
||||
@@ -1,16 +1,20 @@
|
||||
use std::io::{self, BufWriter, Write};
|
||||
use std::io;
|
||||
use std::path::PathBuf;
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
use clap::Args;
|
||||
use obifastwrite::write_scatter;
|
||||
use obikrope::Rope;
|
||||
use obikseq::superkmer::SuperKmer;
|
||||
use obipipeline::{WorkerPool, make_pipeline};
|
||||
use obiskbuilder::SuperKmerIter;
|
||||
use obikpartitionner::KmerPartition;
|
||||
|
||||
#[derive(Args)]
|
||||
pub struct PartitionArgs {
|
||||
/// Output partition directory
|
||||
#[arg(short, long)]
|
||||
pub output: PathBuf,
|
||||
|
||||
/// Input files or directories (FASTA/FASTQ, optionally gzip-compressed)
|
||||
#[arg(num_args = 1..)]
|
||||
pub inputs: Vec<String>,
|
||||
@@ -35,6 +39,10 @@ pub struct PartitionArgs {
|
||||
#[arg(short, long, default_value_t = 8)]
|
||||
pub partition_bits: usize,
|
||||
|
||||
/// Overwrite output directory if it already exists
|
||||
#[arg(long, default_value_t = false)]
|
||||
pub force: bool,
|
||||
|
||||
/// Number of worker threads
|
||||
#[arg(
|
||||
short = 'T',
|
||||
@@ -59,8 +67,6 @@ unsafe impl Sync for PipelineData {}
|
||||
|
||||
// ── Stage functions ───────────────────────────────────────────────────────────
|
||||
|
||||
/// Opens a sequence file and returns an iterator over its raw Rope chunks.
|
||||
/// Chunk-level I/O errors are logged and skipped.
|
||||
fn open_chunks(path: PathBuf) -> io::Result<impl Iterator<Item = Rope>> {
|
||||
let path_str = path
|
||||
.to_str()
|
||||
@@ -75,12 +81,10 @@ fn open_chunks(path: PathBuf) -> io::Result<impl Iterator<Item = Rope>> {
|
||||
}))
|
||||
}
|
||||
|
||||
/// Normalises a raw sequence chunk (FASTA or FASTQ) into a compact ACGT/NUL rope.
|
||||
fn normalize(rope: Rope, k: usize) -> io::Result<Rope> {
|
||||
obiread::normalize_sequence_chunk(rope, k)
|
||||
}
|
||||
|
||||
/// Extracts all super-kmers from a normalised rope.
|
||||
fn build_superkmers(
|
||||
rope: Rope,
|
||||
k: usize,
|
||||
@@ -91,34 +95,11 @@ fn build_superkmers(
|
||||
SuperKmerIter::new(&rope, k, m, level_max, theta).collect()
|
||||
}
|
||||
|
||||
/// Writes a batch of super-kmers to the output sink.
|
||||
fn write_batch(
|
||||
batch: Vec<SuperKmer>,
|
||||
out: &Mutex<BufWriter<io::Stdout>>,
|
||||
partition_bits: usize,
|
||||
k: usize,
|
||||
m: usize,
|
||||
) -> io::Result<()> {
|
||||
let mut w = out.lock().unwrap();
|
||||
let partition_mask = (1u64 << partition_bits) - 1;
|
||||
for sk in batch {
|
||||
let minimizer = sk
|
||||
.kmer(sk.minimizer_pos() as usize, m)
|
||||
.map_err(|e| std::io::Error::other(e))?
|
||||
.canonical(m);
|
||||
let partition = (minimizer.hash(m) & partition_mask) as usize;
|
||||
write_scatter(&sk, &mut *w, k, m, partition_bits, minimizer)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn mix64(x: u64) -> u64 {
|
||||
let x = x ^ (x >> 30);
|
||||
let x = x.wrapping_mul(0xbf58476d1ce4e5b9);
|
||||
let x = x ^ (x >> 27);
|
||||
let x = x.wrapping_mul(0x94d049bb133111eb);
|
||||
x ^ (x >> 31)
|
||||
fn write_batch(batch: Vec<SuperKmer>, kp: &Mutex<KmerPartition>) -> io::Result<()> {
|
||||
kp.lock()
|
||||
.unwrap()
|
||||
.write_batch(&batch)
|
||||
.map_err(|e| io::Error::other(e))
|
||||
}
|
||||
|
||||
// ── Entry point ───────────────────────────────────────────────────────────────
|
||||
@@ -128,24 +109,25 @@ pub fn run(args: PartitionArgs) {
|
||||
let m = args.minimizer_size;
|
||||
let theta = args.theta;
|
||||
let level_max = args.level_max;
|
||||
let partition_bits = args.partition_bits;
|
||||
let n_workers = args.threads.max(1);
|
||||
|
||||
let kp = KmerPartition::create(&args.output, args.partition_bits, k, m, args.force)
|
||||
.unwrap_or_else(|e| { eprintln!("error: {e}"); std::process::exit(1) });
|
||||
let kp = Arc::new(Mutex::new(kp));
|
||||
let kp_sink = Arc::clone(&kp);
|
||||
|
||||
let paths = args.inputs.iter().map(PathBuf::from).collect();
|
||||
let path_source = obiread::PathIter::new(paths);
|
||||
|
||||
let out = Arc::new(Mutex::new(BufWriter::new(io::stdout())));
|
||||
let out_sink = Arc::clone(&out);
|
||||
|
||||
let pipeline = make_pipeline! {
|
||||
PipelineData,
|
||||
source path_source => Path,
|
||||
||? open_chunks : Path => RawChunk,
|
||||
|? { move |rope| normalize(rope, k) } : RawChunk => NormChunk,
|
||||
| { move |rope| build_superkmers(rope, k, m, level_max, theta) }: NormChunk => Batch,
|
||||
sink? { move |batch| write_batch(batch, &out_sink, partition_bits, k, m) } @ Batch,
|
||||
sink? { move |batch| write_batch(batch, &kp_sink) } @ Batch,
|
||||
};
|
||||
|
||||
WorkerPool::new(pipeline, n_workers, 1).run();
|
||||
out.lock().unwrap().flush().expect("flush error");
|
||||
kp.lock().unwrap().close().expect("close error");
|
||||
}
|
||||
@@ -107,7 +107,7 @@ fn write_batch(
|
||||
.map_err(|e| std::io::Error::other(e))?
|
||||
.canonical(m);
|
||||
let partition = (minimizer.hash(m) & partition_mask) as usize;
|
||||
write_scatter(&sk, &mut *w, k, m, partition_bits, minimizer)?;
|
||||
write_scatter(&sk, &mut *w, k, m, partition, minimizer)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -13,11 +13,14 @@ struct Cli {
|
||||
enum Commands {
|
||||
/// Extract super-kmers from a sequence file (scatter phase)
|
||||
Superkmer(cmd::superkmer::SuperkmerArgs),
|
||||
/// Partition super-kmers on disk by minimizer
|
||||
Partition(cmd::partition::PartitionArgs),
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let cli = Cli::parse();
|
||||
match cli.command {
|
||||
Commands::Superkmer(args) => cmd::superkmer::run(args),
|
||||
Commands::Partition(args) => cmd::partition::run(args),
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user