Skip to content

Commit

Permalink
fix: deeptools bamcoverage fix (#2719)
Browse files Browse the repository at this point in the history
Fixes a small issue when including the genome and read_length pulling
from the pre-computed effective genome sizes. The returned genome size
is an int rather than a string.

### QC
<!-- Make sure that you can tick the boxes below. -->

* [x] I confirm that:

For all wrappers added by this PR, 

* there is a test case which covers any introduced changes,
* `input:` and `output:` file paths in the resulting rule can be changed
arbitrarily,
* either the wrapper can only use a single core, or the example rule
contains a `threads: x` statement with `x` being a reasonable default,
* rule names in the test case are in
[snake_case](https://en.wikipedia.org/wiki/Snake_case) and somehow tell
what the rule is about or match the tools purpose or name (e.g.,
`map_reads` for a step that maps reads),
* all `environment.yaml` specifications follow [the respective best
practices](https://stackoverflow.com/a/64594513/2352071),
* the `environment.yaml` pinning has been updated by running
`snakedeploy pin-conda-envs environment.yaml` on a linux machine,
* wherever possible, command line arguments are inferred and set
automatically (e.g. based on file extensions in `input:` or `output:`),
* all fields of the example rules in the `Snakefile`s and their entries
are explained via comments (`input:`/`output:`/`params:` etc.),
* `stderr` and/or `stdout` are logged correctly (`log:`), depending on
the wrapped tool,
* temporary files are either written to a unique hidden folder in the
working directory, or (better) stored where the Python function
`tempfile.gettempdir()` points to (see
[here](https://docs.python.org/3/library/tempfile.html#tempfile.gettempdir);
this also means that using any Python `tempfile` default behavior
works),
* the `meta.yaml` contains a link to the documentation of the respective
tool or command,
* `Snakefile`s pass the linting (`snakemake --lint`),
* `Snakefile`s are formatted with
[snakefmt](https://github.com/snakemake/snakefmt),
* Python wrapper scripts are formatted with
[black](https://black.readthedocs.io).
* Conda environments use a minimal amount of channels, in recommended
ordering. E.g. for bioconda, use (conda-forge, bioconda, nodefaults, as
conda-forge should have highest priority and defaults channels are
usually not needed because most packages are in conda-forge nowadays).

---------

Co-authored-by: Filipe G. Vieira <1151762+fgvieira@users.noreply.github.com>
  • Loading branch information
jeffhsu3 and fgvieira committed Apr 20, 2024
1 parent a375c11 commit 206425b
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 51 deletions.
15 changes: 15 additions & 0 deletions bio/deeptools/bamcoverage/test/Snakefile
Expand Up @@ -13,3 +13,18 @@ rule test_deeptools_bamcoverage:
"logs/coverage.log",
wrapper:
"master/bio/deeptools/bamcoverage"


rule test_deeptools_bamcoverage_default_eff_len:
input:
bam="a.sorted.bam",
bai="a.sorted.bam.bai",
output:
"a.coverage_code.bw",
params:
genome="GRCm38",
read_length=200,
log:
"logs/coverage_efault_eff_len.log",
wrapper:
"master/bio/deeptools/bamcoverage"
141 changes: 90 additions & 51 deletions bio/deeptools/bamcoverage/wrapper.py
Expand Up @@ -10,61 +10,93 @@

# See: https://deeptools.readthedocs.io/en/latest/content/feature/effectiveGenomeSize.html
default_effective_genome_size = {
"GRCz10": {
"50": 1195445591,
"75": 1251132686,
"100": 1280189044,
"150": 1312207169,
"200": 1321355241,
},
"WBcel235": {
"50": 95159452,
"75": 96945445,
"100": 98259998,
"150": 98721253,
"200": 98672758,
},
"dm3": {
"50": 130428560,
"75": 135004462,
"100": 139647232,
"150": 144307808,
"200": 148524010,
},
"dm6": {
"50": 125464728,
"75": 127324632,
"100": 129789873,
"150": 129941135,
"200": 132509163,
},
"GRCh37": {
"50": 2685511504,
"75": 2736124973,
"100": 2776919808,
"150": 2827437033,
"200": 2855464000,
"50": 2685511454,
"75": 2736124898,
"100": 2776919708,
"150": 2827436883,
"200": 2855463800,
"250": 2855044784,
},
"GRCh38": {
"50": 2701495761,
"75": 2747877777,
"100": 2805636331,
"150": 2862010578,
"200": 2887553303,
"50": 2701495711,
"75": 2747877702,
"100": 2805636231,
"150": 2862010428,
"200": 2887553103,
"250": 2898802627,
},
"GRCm37": {
"50": 2304947926,
"75": 2404646224,
"100": 2462481010,
"150": 2489384235,
"200": 2513019276,
"50": 2304947876,
"75": 2404646149,
"100": 2462480910,
"150": 2489384085,
"200": 2513019076,
"250": 2528988583,
},
"GRCm38": {
"50": 2308125349,
"75": 2407883318,
"100": 2467481108,
"150": 2494787188,
"200": 2520869189,
"50": 2308125299,
"75": 2407883243,
"100": 2467481008,
"150": 2494787038,
"200": 2520868989,
"250": 2538590322,
},
"GRCz10": {
"50": 1195445541,
"75": 1251132611,
"100": 1280188944,
"150": 1312207019,
"200": 1321355041,
"250": 1339205109,
},
"GRCz11": {
"50": 1197575653,
"75": 1250812288,
"100": 1280354977,
"150": 1311832909,
"200": 1322366338,
"250": 1342093482,
},
"T2T/CHM13CAT_v2": {
"50": 2725240337,
"75": 2786136059,
"100": 2814334875,
"150": 2931551487,
"200": 2936403235,
"250": 2960856300,
},
"TAIR10": {
"50": 114339094,
"75": 115317469,
"100": 118459858,
"150": 118504138,
"200": 117723393,
"250": 119585546,
},
"WBcel235": {
"50": 95159402,
"75": 96945370,
"100": 98259898,
"150": 98721103,
"200": 98672558,
"250": 101271756,
},
"dm3": {
"50": 130428510,
"75": 135004387,
"100": 139647132,
"150": 144307658,
"200": 148523810,
"250": 151901455,
},
"dm6": {
"50": 125464678,
"75": 127324557,
"100": 129789773,
"150": 129940985,
"200": 132508963,
"250": 132900923,
},
}

Expand All @@ -73,10 +105,17 @@
genome = snakemake.params.get("genome")
read_length = snakemake.params.get("read_length")
if genome and read_length:
effective_genome_size = "--effectiveGenomeSize "
effective_genome_size += default_effective_genome_size[genome][str(read_length)]
try:
effective_genome_size = f"--effectiveGenomeSize {default_effective_genome_size[genome][str(read_length)]}"
except KeyError:
raise KeyError(
(
"A valid genome and read_length need to be provided. See "
"https://deeptools.readthedocs.io/en/latest/content/feature/effectiveGenomeSize.html"
)
)
else:
effective_genome_size = "--effectiveGenomeSize " + str(effective_genome_size)
effective_genome_size = f"--effectiveGenomeSize {effective_genome_size}"


output_format = ""
Expand Down
15 changes: 15 additions & 0 deletions test.py
Expand Up @@ -2833,6 +2833,21 @@ def test_deeptools_bamcoverage():
)


@skip_if_not_modified
def test_deeptools_bamcoverage_eff():
run(
"bio/deeptools/bamcoverage",
[
"snakemake",
"--cores",
"1",
"a.coverage_code.bw",
"--use-conda",
"-F",
],
)


@skip_if_not_modified
def test_deeptools_alignmentsieve():
run(
Expand Down

0 comments on commit 206425b

Please sign in to comment.