Skip to content

Commit 8f4d223

Browse files
lparsonsfgvieira
andauthored
fix: remove NA string replacement, fixed upstream (snakemake#2940)
<!-- Ensure that the PR title follows conventional commit style (<type>: <description>)--> <!-- Possible types are here: https://github.com/commitizen/conventional-commit-types/blob/master/index.json --> Wrapper previously failed if the optional output `qc_metrics` was not supplied due to NA replacement code that was not in a conditional. The code is no longer required since NA strings are now output correctly in deeptools/deepTools#1002 <!-- Add a description of your PR here--> ### 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 <[email protected]>
1 parent 445b35f commit 8f4d223

File tree

6 files changed

+16
-27
lines changed

6 files changed

+16
-27
lines changed

bio/deeptools/plotfingerprint/test/Snakefile

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,20 @@ rule plot_fingerprint:
22
input:
33
bam_files=expand("samples/{sample}.bam", sample=["a", "b"]),
44
bam_idx=expand("samples/{sample}.bam.bai", sample=["a", "b"]),
5-
jsd_sample="samples/b.bam" # optional, requires qc_metrics output
5+
jsd_sample="samples/b.bam", # optional, requires qc_metrics output
66
output:
77
# Please note that --plotFile and --outRawCounts are exclusively defined via output files.
88
# Usable output variables, their extensions and which option they implicitly call are listed here:
99
# https://snakemake-wrappers.readthedocs.io/en/stable/wrappers/deeptools/plotfingerprint.html.
1010
fingerprint="plot_fingerprint/plot_fingerprint.png", # required
1111
# optional output
1212
counts="plot_fingerprint/raw_counts.tab",
13-
qc_metrics="plot_fingerprint/qc_metrics.txt"
13+
qc_metrics="plot_fingerprint/qc_metrics.txt",
1414
log:
15-
"logs/deeptools/plot_fingerprint.log"
15+
"logs/deeptools/plot_fingerprint.log",
1616
params:
1717
# optional parameters
18-
"--numberOfSamples 200 "
19-
threads:
20-
8
18+
extra="--numberOfSamples 200",
19+
threads: 8
2120
wrapper:
2221
"master/bio/deeptools/plotfingerprint"

bio/deeptools/plotfingerprint/wrapper.py

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
__author__ = "Antonie Vietor"
2-
__copyright__ = "Copyright 2020, Antonie Vietor"
2+
__copyright__ = "Copyright 2024, Antonie Vietor, Lance Parsons"
33
__email__ = "[email protected]"
44
__license__ = "MIT"
55

6-
from snakemake.shell import shell
76
import re
87

8+
from snakemake.shell import shell
9+
910
log = snakemake.log_fmt_shell(stdout=True, stderr=True)
11+
extra = snakemake.params.get("extra", "")
1012

1113
jsd_sample = snakemake.input.get("jsd_sample")
1214
out_counts = snakemake.output.get("counts")
@@ -30,16 +32,5 @@
3032
"{optional_output} "
3133
"--numberOfProcessors {snakemake.threads} "
3234
"{jsd} "
33-
"{snakemake.params}) {log}"
35+
"{extra}) {log}"
3436
)
35-
# ToDo: remove the 'NA' string replacement when fixed in deepTools, see:
36-
# https://github.com/deeptools/deepTools/pull/999
37-
regex_passes = 2
38-
39-
with open(out_metrics, "rt") as f:
40-
metrics = f.read()
41-
for i in range(regex_passes):
42-
metrics = re.sub("\tNA(\t|\n)", "\tnan\\1", metrics)
43-
44-
with open(out_metrics, "wt") as f:
45-
f.write(metrics)

bio/deeptools/plotheatmap/test/Snakefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ rule plot_heatmap:
1414
"logs/deeptools/heatmap.log"
1515
params:
1616
# optional parameters
17-
"--plotType=fill "
17+
extra="--plotType=fill "
1818
wrapper:
1919
"master/bio/deeptools/plotheatmap"

bio/deeptools/plotheatmap/wrapper.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from snakemake.shell import shell
77

88
log = snakemake.log_fmt_shell(stdout=True, stderr=True)
9+
extra = snakemake.params.get("extra", "")
910

1011
out_region = snakemake.output.get("regions")
1112
out_matrix = snakemake.output.get("heatmap_matrix")
@@ -27,5 +28,5 @@
2728
"-m {snakemake.input[0]} "
2829
"-o {snakemake.output.heatmap_img} "
2930
"{optional_output} "
30-
"{snakemake.params}) {log}"
31+
"{extra}) {log}"
3132
)

bio/deeptools/plotprofile/test/Snakefile

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@ rule plot_profile:
1515
"logs/deeptools/plot_profile.log"
1616
params:
1717
# optional parameters
18-
"--plotType=fill "
19-
"--perGroup "
20-
"--colors red yellow blue "
21-
"--dpi 150 "
18+
extra="--plotType=fill --perGroup --colors red yellow blue --dpi 150"
2219
wrapper:
2320
"master/bio/deeptools/plotprofile"

bio/deeptools/plotprofile/wrapper.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from snakemake.shell import shell
77

88
log = snakemake.log_fmt_shell(stdout=True, stderr=True)
9+
extra = snakemake.params.get("extra", "")
910

1011
out_region = snakemake.output.get("regions")
1112
out_data = snakemake.output.get("data")
@@ -25,5 +26,5 @@
2526
"-m {snakemake.input[0]} "
2627
"-o {snakemake.output.plot_img} "
2728
"{optional_output} "
28-
"{snakemake.params}) {log}"
29+
"{extra}) {log}"
2930
)

0 commit comments

Comments
 (0)