Skip to content

Commit

Permalink
MRG: fix calculate_gather_stats threshold=0 bug (#3052)
Browse files Browse the repository at this point in the history
The error shows up when we try to calculate abundance info with a
`match_size` of 0:
```
match: GCF_002819265.1 Choclo virus, match_size: 0, query_size: 273, query_trackabund: true
thread '<unnamed>' panicked at 'called `Option::unwrap()` on a `None` value', /home/ntpierce/sourmash/src/core/src/index/mod.rs:301:55
```

...we should never be trying to calculate statistics on `match_size` of
0, but the logic is currently `match_size >= threshold`.This includes a
check to break if `match_size` is 0.

- fixes #3051
  • Loading branch information
bluegenes authored Feb 29, 2024
1 parent c7a1265 commit fe4790f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/core/src/index/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,13 +280,14 @@ pub fn calculate_gather_stats(

// If abundance, calculate abund-related metrics (vs current query)
if calc_abund_stats {
// need current downsampled query here to get f_unique_weighted
// take abunds from subtracted query
let (abunds, unique_weighted_found) = match match_mh.inflated_abundances(&query) {
Ok((abunds, unique_weighted_found)) => (abunds, unique_weighted_found),
Err(e) => {
return Err(e);
}
};

n_unique_weighted_found = unique_weighted_found as usize;
sum_total_weighted_found = sum_weighted_found + n_unique_weighted_found;
f_unique_weighted = n_unique_weighted_found as f64 / total_weighted_hashes as f64;
Expand Down
4 changes: 4 additions & 0 deletions src/core/src/index/revindex/disk_revindex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,10 @@ impl RevIndexOps for RevIndex {

let (dataset_id, size) = counter.k_most_common_ordered(1)[0];
match_size = if size >= threshold { size } else { break };
// handle special case where threshold was set to 0
if match_size == 0 {
break;
}

// this should downsample mh for us
let match_sig = self.collection.sig_for_dataset(dataset_id)?;
Expand Down

0 comments on commit fe4790f

Please sign in to comment.