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 gather output bug #589

Merged
merged 7 commits into from
Jan 3, 2019
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
8 changes: 4 additions & 4 deletions sourmash/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,29 +144,29 @@ def find_best(dblist, query, remainder):
leaf_e = leaf.data.minhash
similarity = query.minhash.containment_ignore_maxhash(leaf_e)
if similarity > 0.0:
results.append((similarity, leaf.data))
results.append((similarity, leaf.data, filename))
# or an LCA database
elif filetype == 'LCA':
lca_db = obj
for x in lca_db.find(query.minhash, 0.0,
containment=True, ignore_scaled=True):
(score, match_sig, md5, filename, name) = x
if score > 0.0:
results.append((score, match_sig))
results.append((score, match_sig, filename))

# search a signature
else:
for ss in obj:
similarity = query.minhash.containment_ignore_maxhash(ss.minhash)
if similarity > 0.0:
results.append((similarity, ss))
results.append((similarity, ss, filename))

if not results:
return None, None, None

# take the best result
results.sort(key=lambda x: (-x[0], x[1].name())) # reverse sort on similarity, and then on name
best_similarity, best_leaf = results[0]
best_similarity, best_leaf, filename = results[0]

for x in results[1:]:
remainder.add(x[1])
Expand Down
14 changes: 14 additions & 0 deletions tests/test_sourmash.py
Original file line number Diff line number Diff line change
Expand Up @@ -1178,6 +1178,20 @@ def test_gather_lca_db(c):
assert 'NC_009665.1 Shewanella baltica OS185' in str(c)


@utils.in_tempdir
def test_gather_csv_output_filename_bug(c):
# check a bug where the database filename in the output CSV was incorrect
query = utils.get_test_data('lca/TARA_ASE_MAG_00031.sig')
lca_db_1 = utils.get_test_data('lca/delmont-1.lca.json')
lca_db_2 = utils.get_test_data('lca/delmont-2.lca.json')

c.run_sourmash('gather', query, lca_db_1, lca_db_2, '-o', 'out.csv')
with open(c.output('out.csv'), 'rt') as fp:
r = csv.DictReader(fp)
row = next(r)
assert row['filename'] == lca_db_1


def test_compare_deduce_molecule():
# deduce DNA vs protein from query, if it is unique
with utils.TempDirectory() as location:
Expand Down