Skip to content

Commit

Permalink
block multiple picklists on SBTs and LCAs, for now
Browse files Browse the repository at this point in the history
  • Loading branch information
ctb committed Jun 17, 2021
1 parent a074127 commit ba5c8bc
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/sourmash/lca/lca_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ def select(self, ksize=None, moltype=None, num=0, scaled=0,

if picklist is not None:
self.picklists.append(picklist)
if len(self.picklists) > 1:
raise ValueError("we do not (yet) support multiple picklists for LCA databases")

return self

Expand Down
2 changes: 2 additions & 0 deletions src/sourmash/sbt.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,8 @@ def select(self, ksize=None, moltype=None, num=0, scaled=0,

if picklist is not None:
self.picklists.append(picklist)
if len(self.picklists) > 1:
raise ValueError("we do not (yet) support multiple picklists for SBTs")

return self

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


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

filename = utils.get_test_data('lca/47+63.lca.json')
db, ksize, scaled = lca_utils.load_single_database(filename)

# construct a picklist...
picklist = SignaturePicklist('md5prefix8')
picklist.init(['50a92740'])

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

with pytest.raises(ValueError) as exc:
xx = db.select(picklist=picklist)

assert "we do not (yet) support multiple picklists for LCA databases" in str(exc)



def test_search_db_scaled_gt_sig_scaled():
dbfile = utils.get_test_data('lca/47+63.lca.json')
db, ksize, scaled = lca_utils.load_single_database(dbfile)
Expand Down
30 changes: 30 additions & 0 deletions tests/test_sbt.py
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,36 @@ def test_sbt_as_index_find_picklist():
assert ss.md5sum().startswith('09a08691c')


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

factory = GraphFactory(31, 1e5, 4)
tree = SBT(factory, d=2)

sig47 = load_one_signature(utils.get_test_data('47.fa.sig'))
sig63 = load_one_signature(utils.get_test_data('63.fa.sig'))

tree.insert(sig47)
tree.insert(sig63)

# construct a picklist...
picklist = SignaturePicklist('md5prefix8')
picklist.init(['09a08691'])

# run a 'find' with sig63, should find 47 and 63 both.
search_obj = make_jaccard_search_query(do_containment=True, threshold=0.0)
results = list(tree.find(search_obj, sig63))
print(results)
assert len(results) == 2

# now, select twice on picklists...
tree = tree.select(picklist=picklist)

with pytest.raises(ValueError):
tree = tree.select(picklist=picklist)
assert "we do not (yet) support multiple picklists for SBT databases" in str(exc)


def test_sbt_as_index_signatures():
# test 'signatures' method from Index base class.
factory = GraphFactory(31, 1e5, 4)
Expand Down

0 comments on commit ba5c8bc

Please sign in to comment.