Skip to content

Commit

Permalink
[MRG] Fix picklist-induced error in LCA_Database (#1639)
Browse files Browse the repository at this point in the history
* add test for bug #1638

* fix bug

* force generator to work
  • Loading branch information
ctb authored Jun 25, 2021
1 parent a5a52b1 commit e386085
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/sourmash/lca/lca_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,11 @@ def find(self, search_fn, query, **kwargs):
# NOTE: one future low-mem optimization could be to support doing
# this piecemeal by iterating across all the hashes, instead.

subj = self._signatures[idx]
subj = self._signatures.get(idx)
if subj is None: # must be because of a picklist exclusion
assert self.picklists
continue

subj_mh = prepare_subject(subj.minhash)

# all numbers calculated after downsampling --
Expand Down
20 changes: 20 additions & 0 deletions tests/test_lca.py
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,26 @@ def test_lca_index_select_picklist():
assert ss.minhash.ksize == 31


def test_lca_index_find_picklist_check_overlap():
# make sure 'find' works for picklists that exclude relevant signatures
# (bug #1638)

query_fn = utils.get_test_data('47.fa.sig')
query_sig = sourmash.load_one_signature(query_fn, ksize=31)
db_fn = utils.get_test_data('lca/47+63.lca.json')
db, ksize, scaled = lca_utils.load_single_database(db_fn)

# construct a picklist...
picklist = SignaturePicklist('ident')
picklist.init(['NC_009665.1'])

xx = db.select(picklist=picklist)
assert xx == db

results = list(db.search(query_sig, threshold=0.1))
assert len(results) == 1


def test_lca_index_select_picklist_exclude():
# test 'select' method from Index base class with a picklist.

Expand Down

0 comments on commit e386085

Please sign in to comment.