Skip to content

Commit

Permalink
MRG: fix count bug (#11)
Browse files Browse the repository at this point in the history
* stop using _hash_murmur

* add test

* bump to v0.2.3
ctb authored Sep 4, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 2cf8f0e commit 756c77c
Showing 4 changed files with 169 additions and 4 deletions.
147 changes: 146 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "oxli"
version = "0.2.2"
version = "0.2.3"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
@@ -12,3 +12,5 @@ crate-type = ["cdylib"]
pyo3 = { version="0.22.2", features = ["extension-module", "anyhow"] }
sourmash = "0.15.1"
anyhow = "1.0.86"
log = "0.4.22"
env_logger = "0.11.5"
6 changes: 4 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -3,10 +3,10 @@ use pyo3::prelude::*;
// use rayon::prelude::*;

use anyhow::{anyhow, Result};
use log::debug;
use std::collections::HashMap;

// use sourmash::sketch::nodegraph::Nodegraph;
use sourmash::_hash_murmur;
use sourmash::encodings::HashFunctions;
use sourmash::signature::SeqToHashes;

@@ -63,7 +63,7 @@ impl KmerCountTable {
"kmer size does not match count table ksize",
))
} else {
let hashval = _hash_murmur(kmer.as_bytes(), 42);
let hashval = self.hash_kmer(kmer).unwrap();
let count = self.count_hash(hashval);
Ok(count)
}
@@ -81,6 +81,7 @@ impl KmerCountTable {
Some(count) => count,
None => &0,
};
debug!("get: hashval {}, count {}", hashval, count);
Ok(*count)
}
}
@@ -121,6 +122,7 @@ impl KmerCountTable {

#[pymodule]
fn oxli(m: &Bound<'_, PyModule>) -> PyResult<()> {
env_logger::init();
m.add_class::<KmerCountTable>()?;
Ok(())
}
16 changes: 16 additions & 0 deletions src/python/tests/test_basic.py
Original file line number Diff line number Diff line change
@@ -79,3 +79,19 @@ def test_consume_bad_DNA_ignore_is_default():
assert cg.get("ATCG") == 1
assert cg.get("TCGG") == 1
assert cg.get("CCGA") == 1 # rc


def test_count_get():
# test a bug reported by adam taranto: count and get should work together!
kmer = 'TAAACCCTAACCCTAACCCTAACCCTAACCC'

cg = oxli.KmerCountTable(ksize=31)
hashkey = cg.hash_kmer(kmer)

assert cg.get(kmer) == 0
assert cg.count(kmer) == 1
assert cg.count(kmer) == 2

x = cg.get(kmer)
assert x == 2, x

0 comments on commit 756c77c

Please sign in to comment.