Skip to content

Commit

Permalink
index should error out if no sigs to index (#267)
Browse files Browse the repository at this point in the history
  • Loading branch information
bluegenes authored Mar 7, 2024
1 parent 3d54135 commit 89ab51f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
7 changes: 7 additions & 0 deletions src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ pub fn index<P: AsRef<Path>>(
allow_failed_sigpaths,
)?;

if collection.len() == 0 {
bail!(
"No sketches matching parameters, check input: '{}'",
&siglist
)
}

RevIndex::create(
output.as_ref(),
collection.select(selection)?.try_into()?,
Expand Down
25 changes: 23 additions & 2 deletions src/python/tests/test_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,31 @@ def test_index_empty_siglist(runtmp, capfd):
assert "Error: Signatures failed to load. Exiting." in captured.err


def test_index_nomatch_sig_in_siglist(runtmp, capfd):
def test_index_nomatch(runtmp, capfd):
# test index with a siglist file that has (only) a non-matching ksize sig
siglist = runtmp.output('against.txt')
db = runtmp.output('db.rdb')

sig1 = get_test_data('1.fa.k21.sig.gz')
make_file_list(siglist, [sig1])

with pytest.raises(utils.SourmashCommandFailed):
runtmp.sourmash('scripts', 'index', siglist,
'-o', db)

captured = capfd.readouterr()
print(runtmp.last_result.out)
print(runtmp.last_result.err)
print(captured.out)
print(captured.err)
assert not os.path.exists(db)


def test_index_nomatch_sig_in_siglist(runtmp, capfd):
# test index with a siglist file that has both matching and non-matching sigs
siglist = runtmp.output('against.txt')
db = runtmp.output('db.rdb')

sig2 = get_test_data('2.fa.sig.gz')
sig1 = get_test_data('1.fa.k21.sig.gz')
make_file_list(siglist, [sig2, sig1])
Expand All @@ -174,10 +194,11 @@ def test_index_nomatch_sig_in_siglist(runtmp, capfd):
'-o', db)

captured = capfd.readouterr()
assert os.path.exists(db) # currently empty file
print(runtmp.last_result.out)
print(runtmp.last_result.err)
print(captured.out)
print(captured.err)
assert os.path.exists(db)


def test_index_zipfile(runtmp, capfd):
Expand Down

0 comments on commit 89ab51f

Please sign in to comment.