Skip to content

Commit

Permalink
MRG: fix a loading problem where only one sketch was checked by manys…
Browse files Browse the repository at this point in the history
…earch for compat (#36)

* provisional fix for loading against sigs from files with multiple

* add test for load-only-one bug
  • Loading branch information
ctb authored Aug 20, 2023
1 parent 68eb731 commit 97582bd
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,18 +224,24 @@ fn manysearch<P: AsRef<Path>>(
}

let mut search_mh = None;
let mut search_sig = None;
let mut results = vec![];

// load search signature from path:
let search_sig = Signature::from_path(filename);
if search_sig.is_ok() {
let search_sig = search_sig.unwrap();
let search_sig = &search_sig[0]; // @CTB check on this

let search_sigs = Signature::from_path(filename);
if search_sigs.is_ok() {
let search_sigs = search_sigs.unwrap();

for ss in search_sigs.iter() {
if let Some(mh) = prepare_query(ss, &template) {
search_sig = Some(ss);
search_mh = Some(mh);
break;
}
}
// make sure it is compatible etc.
if let Some(mh) = prepare_query(search_sig, &template) {
search_mh = Some(mh);
} else {

if !search_mh.is_some() {
eprintln!("WARNING: no compatible sketches in path '{}'",
filename.display());
let _ = skipped_paths.fetch_add(1, atomic::Ordering::SeqCst);
Expand All @@ -251,6 +257,7 @@ fn manysearch<P: AsRef<Path>>(

let containment = overlap / size;
if containment > threshold {
let search_sig = search_sig.unwrap();
results.push((q.name.clone(),
q.minhash.md5sum(),
search_sig.name(),
Expand Down
Binary file added src/python/tests/test-data/1.combined.sig.gz
Binary file not shown.
Binary file added src/python/tests/test-data/1.fa.k31.sig.gz
Binary file not shown.
25 changes: 25 additions & 0 deletions src/python/tests/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,3 +251,28 @@ def test_nomatch_query(runtmp, capfd):
print(captured.err)

assert 'WARNING: skipped 1 paths - no compatible signatures.' in captured.err


def test_load_only_one_bug(runtmp, capfd):
# check that we behave properly when presented with multiple against
# sketches
query_list = runtmp.output('query.txt')
against_list = runtmp.output('against.txt')

sig1_k31 = get_test_data('1.fa.k31.sig.gz')
sig1_all = get_test_data('1.combined.sig.gz')

make_file_list(query_list, [sig1_k31])
make_file_list(against_list, [sig1_all])

output = runtmp.output('out.csv')

runtmp.sourmash('scripts', 'manysearch', query_list, against_list,
'-o', output)
assert os.path.exists(output)

captured = capfd.readouterr()
print(captured.err)

assert not 'WARNING: skipped 1 paths - no compatible signatures.' in captured.err
assert not 'WARNING: no compatible sketches in path ' in captured.err

0 comments on commit 97582bd

Please sign in to comment.