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: add more output information when sketches fail to load #43

Merged
merged 2 commits into from
Aug 23, 2023
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
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 26 additions & 21 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -450,33 +450,38 @@ fn load_sketches_above_threshold(
.filter_map(|m| {
let sigs = Signature::from_path(m);

let mut mm = None;
if let Ok(sigs) = sigs {
for sig in &sigs {
if let Some(mh) = prepare_query(sig, template) {
if let Ok(overlap) = mh.count_common(query, false) {
if overlap >= threshold_hashes {
let result = PrefetchResult {
name: sig.name(),
minhash: mh,
overlap,
};
mm = Some(result);
break;
match sigs {
Ok(sigs) => {
let mut mm = None;
for sig in &sigs {
if let Some(mh) = prepare_query(sig, template) {
if let Ok(overlap) = mh.count_common(query, false) {
if overlap >= threshold_hashes {
let result = PrefetchResult {
name: sig.name(),
minhash: mh,
overlap,
};
mm = Some(result);
break;
}
}
} else {
eprintln!("WARNING: no compatible sketches in path '{}'",
m.display());
let _i = skipped_paths.fetch_add(1, atomic::Ordering::SeqCst);
}
} else {
eprintln!("WARNING: no compatible sketches in path '{}'",
m.display());
let _i = skipped_paths.fetch_add(1, atomic::Ordering::SeqCst);
}
mm
}
} else {
let _ = failed_paths.fetch_add(1, atomic::Ordering::SeqCst);
eprintln!("WARNING: could not load sketches from path '{}'",
Err(err) => {
eprintln!("Sketch loading error: {}", err);
let _ = failed_paths.fetch_add(1, atomic::Ordering::SeqCst);
eprintln!("WARNING: could not load sketches from path '{}'",
m.display());
None
}
}
mm
})
.collect();

Expand Down
28 changes: 28 additions & 0 deletions src/python/tests/test_gather.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,34 @@ def test_bad_against_2(runtmp, capfd):
assert "WARNING: 1 signature paths failed to load. See error messages above." in captured.err


def test_bad_against_3(runtmp, capfd):
# test bad 'against' file - in this case, one containing an empty file
query = get_test_data('SRR606249.sig.gz')
against_list = runtmp.output('against.txt')

sig2 = get_test_data('2.fa.sig.gz')
empty_file = runtmp.output('empty.sig')
with open(empty_file, 'wb') as fp:
pass
make_file_list(against_list, [sig2, empty_file])


g_output = runtmp.output('gather.csv')
p_output = runtmp.output('prefetch.csv')

runtmp.sourmash('scripts', 'fastgather', query, against_list,
'-o', g_output, '--output-prefetch', p_output,
'-s', '100000')

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

assert "Sketch loading error: File is too short, less than five bytes" in captured.err
assert "WARNING: could not load sketches from path" in captured.err

assert "WARNING: 1 signature paths failed to load. See error messages above." in captured.err


def test_against_multisigfile(runtmp):
# test against a sigfile that contains multiple sketches
query = get_test_data('SRR606249.sig.gz')
Expand Down