Skip to content

Commit

Permalink
[MRG] catch TypeError in search w/abund vs flat at the command line (#…
Browse files Browse the repository at this point in the history
…1928)

* catch TypeError in search w/abund vs flat

* added a test
  • Loading branch information
ctb authored Apr 15, 2022
1 parent f0726c3 commit 0d04cca
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/sourmash/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,12 +492,16 @@ def search(args):

# do the actual search
if query.minhash.track_abundance:
results = search_databases_with_abund_query(query, databases,
threshold=args.threshold,
do_containment=args.containment,
do_max_containment=args.max_containment,
best_only=args.best_only,
unload_data=True)
try:
results = search_databases_with_abund_query(query, databases,
threshold=args.threshold,
do_containment=args.containment,
do_max_containment=args.max_containment,
best_only=args.best_only,
unload_data=True)
except TypeError as exc:
error(f"ERROR: {str(exc)}")
sys.exit(-1)
else:
results = search_databases_with_flat_query(query, databases,
threshold=args.threshold,
Expand Down
11 changes: 11 additions & 0 deletions tests/test_sourmash.py
Original file line number Diff line number Diff line change
Expand Up @@ -826,6 +826,17 @@ def test_search_ignore_abundance(runtmp):
assert out1 != out2


def test_search_abund_subj_flat(runtmp):
# test Index.search_abund requires an abund subj
sig47 = utils.get_test_data('track_abund/47.fa.sig')
sig63 = utils.get_test_data('63.fa.sig')

with pytest.raises(SourmashCommandFailed) as exc:
runtmp.sourmash('search', sig47, sig63)

assert "'search_abund' requires subject signatures with abundance information" in str(exc.value)


def test_search_abund_csv(runtmp):
# test search with abundance signatures, look at CSV output
testdata1 = utils.get_test_data('short.fa')
Expand Down

0 comments on commit 0d04cca

Please sign in to comment.