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 bug in LCA_Database.downsample #2117

Merged
merged 1 commit into from
Jul 11, 2022
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
2 changes: 1 addition & 1 deletion src/sourmash/lca/lca_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ def downsample_scaled(self, scaled):
max_hash = _get_max_hash_for_scaled(scaled)

# filter out all hashes over max_hash in value.
new_hashvals = {}
new_hashvals = defaultdict(set)
for k, v in self._hashval_to_idx.items():
if k < max_hash:
new_hashvals[k] = v
Expand Down
26 changes: 26 additions & 0 deletions tests/test_lca.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,32 @@ def test_api_create_insert_two_then_scale():
assert len(lca_db._hashval_to_idx) == len(combined_mins)


def test_api_create_insert_two_then_scale_then_add():
# construct database, THEN downsample, then add another
ss = sourmash.load_one_signature(utils.get_test_data('47.fa.sig'),
ksize=31)
ss2 = sourmash.load_one_signature(utils.get_test_data('63.fa.sig'),
ksize=31)

lca_db = sourmash.lca.LCA_Database(ksize=31, scaled=1000)
lca_db.insert(ss)

# downsample everything to 5000
lca_db.downsample_scaled(5000)

# insert another after downsample
lca_db.insert(ss2)

# now test -
ss.minhash = ss.minhash.downsample(scaled=5000)
ss2.minhash = ss2.minhash.downsample(scaled=5000)

# & check...
combined_mins = set(ss.minhash.hashes.keys())
combined_mins.update(set(ss2.minhash.hashes.keys()))
assert len(lca_db._hashval_to_idx) == len(combined_mins)


def test_api_create_insert_scale_two():
# downsample while constructing database
ss = sourmash.load_one_signature(utils.get_test_data('47.fa.sig'),
Expand Down