Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MRG: add public n_hashes fn to signature #3470

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 40 additions & 1 deletion src/core/src/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
}

impl SigsTrait for Sketch {
fn size(&self) -> usize {
pub fn size(&self) -> usize {

Check failure on line 86 in src/core/src/signature.rs

View workflow job for this annotation

GitHub Actions / Lints (stable)

visibility qualifiers are not permitted here

Check failure on line 86 in src/core/src/signature.rs

View workflow job for this annotation

GitHub Actions / Check

visibility qualifiers are not permitted here

Check failure on line 86 in src/core/src/signature.rs

View workflow job for this annotation

GitHub Actions / Lints (beta)

visibility qualifiers are not permitted here

Check failure on line 86 in src/core/src/signature.rs

View workflow job for this annotation

GitHub Actions / test (stable)

visibility qualifiers are not permitted here

Check failure on line 86 in src/core/src/signature.rs

View workflow job for this annotation

GitHub Actions / test (beta)

visibility qualifiers are not permitted here

Check failure on line 86 in src/core/src/signature.rs

View workflow job for this annotation

GitHub Actions / Run tests under wasm32-wasi

visibility qualifiers are not permitted here

Check failure on line 86 in src/core/src/signature.rs

View workflow job for this annotation

GitHub Actions / test (windows)

visibility qualifiers are not permitted here

Check failure on line 86 in src/core/src/signature.rs

View workflow job for this annotation

GitHub Actions / minimum_rust_version

unnecessary visibility qualifier

Check failure on line 86 in src/core/src/signature.rs

View workflow job for this annotation

GitHub Actions / test (macos)

visibility qualifiers are not permitted here
match *self {
Sketch::MinHash(ref mh) => mh.size(),
Sketch::LargeMinHash(ref mh) => mh.size(),
Expand Down Expand Up @@ -618,6 +618,18 @@
}
}

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 @@
"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");
}
}
Loading