Skip to content

Commit 6656c6d

Browse files
authored
Fix mosdepth coverage in general stats if key is missing (MultiQC#3432)
1 parent 9cd6ef2 commit 6656c6d

4 files changed

Lines changed: 39 additions & 2 deletions

File tree

docs/markdown/modules/mosdepth.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,17 @@ mosdepth_config:
5454
- 30000
5555
```
5656
57+
:::info{title="Missing coverage thresholds"}
58+
59+
Mosdepth does omit cumulative coverages at high coverage thresholds. To work around this, MultiQC will
60+
use the next cumulative coverage available. E.g. if 3301x coverage is present, but 3300x is missing,
61+
and 3300x is requested, the value of 3301x will be used. This should provide the technically correct value
62+
because it is a cumulative distribution and mosdepth [only skips values if there are no bases at that coverage
63+
level](https://github.com/brentp/mosdepth/blob/df8c74a0aabae4ae5e6da1ea0c633b4db829f20a/mosdepth.nim#L439).
64+
65+
For more details, see [this](https://github.com/MultiQC/MultiQC/pull/3432#issuecomment-3672811525) comment.
66+
:::
67+
5768
You can also specify which columns would be hidden when the report loads (by default, all values are hidden except 30X):
5869
5970
```yaml
@@ -125,4 +136,4 @@ mosdepth/region_dist:
125136
mosdepth/summary:
126137
fn: '*.mosdepth.summary.txt'
127138
```
128-
139+

multiqc/modules/mosdepth/mosdepth.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,13 @@ def read_config():
5757

5858
def genstats_cov_thresholds(cum_fraction_by_cov: Dict[int, float], threshs: List[int]) -> Dict[str, float]:
5959
genstats: Dict[str, float] = {}
60+
sorted_cum_fraction_by_cov = sorted(cum_fraction_by_cov.items())
6061
for t in threshs:
61-
genstats[f"{t}_x_pc"] = cum_fraction_by_cov.get(t, 0.0) * 100.0
62+
# take next known value
63+
# e.g. if only 50x is known but the threshold is 40x, take the 50x value
64+
# if there is no next threshold, just take 0.0
65+
cov_val = next((proportion for cov, proportion in sorted_cum_fraction_by_cov if cov >= t), 0.0)
66+
genstats[f"{t}_x_pc"] = cov_val * 100.0
6267
return genstats
6368

6469

multiqc/modules/mosdepth/tests/__init__.py

Whitespace-only changes.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import pytest
2+
3+
from multiqc.modules.mosdepth.mosdepth import genstats_cov_thresholds
4+
5+
6+
def test_genstats_cov_thresholds():
7+
cum_fraction_by_cov = {
8+
1: 1.0,
9+
10: 0.8,
10+
20: 0.2,
11+
30: 0.1,
12+
}
13+
thresholds = 10, 15, 30, 200
14+
15+
actual_thresholds = genstats_cov_thresholds(cum_fraction_by_cov, thresholds)
16+
assert actual_thresholds == {
17+
"10_x_pc": 80.0,
18+
"15_x_pc": 20.0,
19+
"30_x_pc": 10.0,
20+
"200_x_pc": 0.0,
21+
}

0 commit comments

Comments
 (0)