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: fix count bug #11

Merged
merged 3 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
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
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
Expand All @@ -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
Expand Up @@ -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;

Expand Down Expand Up @@ -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)
}
Expand All @@ -81,6 +81,7 @@ impl KmerCountTable {
Some(count) => count,
None => &0,
};
debug!("get: hashval {}, count {}", hashval, count);
Ok(*count)
}
}
Expand Down Expand Up @@ -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
Expand Up @@ -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

Loading