Skip to content

Commit

Permalink
add n_hashes fn to signature
Browse files Browse the repository at this point in the history
  • Loading branch information
bluegenes committed Jan 6, 2025
1 parent 29aa2db commit d293d2d
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/core/src/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,18 @@ impl Signature {
}
}

pub fn n_hashes(&self) -> usize {
if self.signatures.len() == 1 {
match &self.signatures[0] {
Sketch::MinHash(mh) => mh.size(),
Sketch::LargeMinHash(mh) => mh.size(),
Sketch::HyperLogLog(mh) => mh.size(),
}
} else {
unimplemented!()
}
}

pub fn select_sketch(&self, sketch: &Sketch) -> Option<&Sketch> {
if let Sketch::MinHash(template) = sketch {
for sk in &self.signatures {
Expand Down Expand Up @@ -2072,4 +2084,31 @@ mod test {
"Hashes do not match in order for SeqToHashes"
);
}

#[test]
fn test_n_hashes_minhash() {
// Load the signature file
let mut filename = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
filename.push("../../tests/test-data/genome-s10+s11.sig");

let file = File::open(filename).expect("Could not open file");
let reader = BufReader::new(file);
let sigs = Signature::from_reader(reader).expect("Error loading signature");

// Use the first signature for testing
assert_eq!(sigs.len(), 4, "Expected 4 signatures in the test data");
let sig = sigs.get(0).expect("No signature found");

// Ensure it has exactly one sketch
assert_eq!(
sig.signatures.len(),
1,
"Expected exactly one sketch in the signature"
);

// Test n_hashes
let n_hashes = sig.n_hashes();

assert!(n_hashes == 500, "Expected n_hashes to be 500");
}
}

0 comments on commit d293d2d

Please sign in to comment.