Skip to main content

Crate kira_cdh_compat_lsh

Crate kira_cdh_compat_lsh 

Source
Expand description

kira_cdh_compat_lsh

Candidate search primitive for high-identity clustering pipelines (e.g., CD-HIT-like). This crate provides:

  • MinHash and KMV (bottom-k) sketches over pre-hashed k-mers (u64),
  • Classic LSH banding to retrieve candidate neighbors,
  • Parallel bulk build & queries (feature parallel).

The crate does not parse FASTA/FASTQ and does not write .clstr; it focuses solely on sketching and candidate retrieval.

§Quick Start

use kira_cdh_compat_lsh::*;

// Suppose you already have hashed k-mers for sequences:
let seq_a: Vec<u64> = vec![1, 2, 3, 10, 11, 12];
let seq_b: Vec<u64> = vec![2, 3, 4, 11, 12, 13];

// Build a KMV sketch (fast single-hash approach):
let mut kmv = kmv::KmvSketch::new(128);
for h in &seq_a { kmv.update(*h); }
let sig_a = kmv.finish(); // Vec<u64> of length <= k (exactly k if enough items)

let mut kmv2 = kmv::KmvSketch::new(128);
for h in &seq_b { kmv2.update(*h); }
let sig_b = kmv2.finish();

// LSH parameters: 32 bands x 4 rows = 128
let params = lsh::LshParams::new(32, 4).unwrap();

let mut index = lsh::LshIndex::with_params(params.clone());
index.insert(0, &sig_a);
index.insert(1, &sig_b);
index.build(); // finalize buckets (optional no-op for current implementation)

// Query candidates for seq_a's signature:
let cands = index.query_candidates(&sig_a, 1); // min 1 band collision
// cands is Vec<(id, collisions)>
assert!(cands.iter().any(|(id, _)| *id == 1));

// Jaccard estimate (KMV or MinHash signatures):
let j_est = sketch::jaccard_from_signatures(&sig_a, &sig_b);
eprintln!("Estimated Jaccard: {:.3}", j_est);

§Notes

  • For MinHash, use minhash::MinHash with num_hashes = bands * rows.
  • For KMV, you might prefer slightly larger k to reach stable estimates.
  • LSH banding is deterministic and uses splitmix64 to map bands to buckets.

Re-exports§

pub use lsh::LshIndex;
pub use lsh::LshParams;

Modules§

errors
kmv
KMV (k-minimum values, aka bottom-k) sketch over a single hash stream. Typically faster than classical MinHash as it uses a single hash per element.
lsh
LSH banding over MinHash/KMV signatures.
minhash
Classic MinHash with K seeded permutations via splitmix64.
sketch
Sketch utilities common to MinHash and KMV.
util
Small utilities: splitmix64 mixing and helpers.