Skip to content

Commit

Permalink
rest of fixes?
Browse files Browse the repository at this point in the history
  • Loading branch information
ctb committed Nov 5, 2024
1 parent d768a06 commit 8c2d226
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/core/src/ani_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use roots::{find_root_brent, SimpleConvergency};
use statrs::distribution::{ContinuousCDF, Normal};

use crate::Error;
use crate::{Error, ScaledType};

fn exp_n_mutated(l: f64, k: f64, r1: f64) -> f64 {
let q = r1_to_q(k, r1);
Expand Down Expand Up @@ -93,7 +93,7 @@ pub fn ani_from_containment(containment: f64, ksize: f64) -> f64 {
pub fn ani_ci_from_containment(
containment: f64,
ksize: f64,
scaled: u32,
scaled: ScaledType,
n_unique_kmers: u64,
confidence: Option<f64>,
) -> Result<(f64, f64), Error> {
Expand Down
2 changes: 1 addition & 1 deletion src/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ cfg_if! {
}

type HashIntoType = u64;
type ScaledType = u32;
pub type ScaledType = u32;

pub fn _hash_murmur(kmer: &[u8], seed: u64) -> u64 {
murmurhash3_x64_128(kmer, seed).0
Expand Down
4 changes: 2 additions & 2 deletions src/core/src/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::encodings::HashFunctions;
use crate::prelude::*;
use crate::signature::SigsTrait;
use crate::sketch::Sketch;
use crate::Result;
use crate::{Result, ScaledType};

/// Individual manifest record, containing information about sketches.

Expand All @@ -38,7 +38,7 @@ pub struct Record {
num: u32,

#[getset(get = "pub")]
scaled: u32,
scaled: ScaledType,

#[getset(get = "pub")]
n_hashes: usize,
Expand Down
2 changes: 1 addition & 1 deletion src/core/src/selection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ impl Selection {
self.scaled
}

pub fn set_scaled(&mut self, scaled: u32) {
pub fn set_scaled(&mut self, scaled: ScaledType) {
self.scaled = Some(scaled);
}

Expand Down
4 changes: 2 additions & 2 deletions src/core/src/sketch/minhash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ impl<'de> Deserialize<'de> for KmerMinHash {

impl KmerMinHash {
pub fn new(
scaled: u32,
scaled: ScaledType,
ksize: u32,
hash_function: HashFunctions,
seed: u64,
Expand Down Expand Up @@ -1115,7 +1115,7 @@ impl<'de> Deserialize<'de> for KmerMinHashBTree {

impl KmerMinHashBTree {
pub fn new(
scaled: u32,
scaled: ScaledType,
ksize: u32,
hash_function: HashFunctions,
seed: u64,
Expand Down
6 changes: 3 additions & 3 deletions src/core/src/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl KmerMinHash {
dayhoff: bool,
hp: bool,
seed: u32,
scaled: u32,
scaled: ScaledType,
track_abundance: bool,
) -> KmerMinHash {
// TODO: at most one of (prot, dayhoff, hp) should be true
Expand Down Expand Up @@ -84,8 +84,8 @@ impl ComputeParameters {
}

#[wasm_bindgen]
pub fn set_scaled(&mut self, scaled: u32) {
self.0.set_scaled(scaled as u64);
pub fn set_scaled(&mut self, scaled: ScaledType) {
self.0.set_scaled(scaled);
}

#[wasm_bindgen]
Expand Down
3 changes: 2 additions & 1 deletion src/core/tests/minhash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::path::PathBuf;
use proptest::collection::vec;
use proptest::num::u64;
use proptest::proptest;
use sourmash::ScaledType;
use sourmash::encodings::HashFunctions;
use sourmash::signature::SeqToHashes;
use sourmash::signature::{Signature, SigsTrait};
Expand Down Expand Up @@ -328,7 +329,7 @@ fn oracle_mins_scaled(hashes in vec(u64::ANY, 1..10000)) {
proptest! {
#[test]
fn prop_merge(seq1 in "[ACGT]{6,100}", seq2 in "[ACGT]{6,200}") {
let scaled: u32 = 10;
let scaled: ScaledType = 10;
let mut a = KmerMinHash::new(scaled, 6, HashFunctions::Murmur64Dna, 42, true, 0);
let mut b = KmerMinHashBTree::new(scaled, 6, HashFunctions::Murmur64Dna, 42, true, 0);

Expand Down
8 changes: 4 additions & 4 deletions tests/test_signature.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def test_roundtrip_empty(track_abundance):


def test_roundtrip_scaled(track_abundance):
e = MinHash(n=0, ksize=20, track_abundance=track_abundance, max_hash=10)
e = MinHash(n=0, ksize=20, track_abundance=track_abundance, max_hash=2**61)
e.add_hash(5)
sig = SourmashSignature(e)
s = save_signatures_to_json([sig])
Expand Down Expand Up @@ -222,14 +222,14 @@ def test_roundtrip_seed(track_abundance):

def test_similarity_downsample(track_abundance):
e = MinHash(n=0, ksize=20, track_abundance=track_abundance, max_hash=2**63)
f = MinHash(n=0, ksize=20, track_abundance=track_abundance, max_hash=2**2)
f = MinHash(n=0, ksize=20, track_abundance=track_abundance, max_hash=2**61)

e.add_hash(1)
e.add_hash(5)
e.add_hash(2**62)
assert len(e.hashes) == 2

f.add_hash(1)
f.add_hash(5) # should be discarded due to max_hash
f.add_hash(2**62) # should be discarded due to max_hash
assert len(f.hashes) == 1

ee = SourmashSignature(e)
Expand Down

0 comments on commit 8c2d226

Please sign in to comment.