Skip to content

Commit

Permalink
feat: gatk DenoisedReadCounts wrapper (#1319)
Browse files Browse the repository at this point in the history
### Description

Add gatk DenoiseReadCountWrapper

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

* [ ] 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),
* 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
Smeds and fgvieira committed May 3, 2023
1 parent a9c7117 commit 0288ace
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 0 deletions.
7 changes: 7 additions & 0 deletions bio/gatk/denoisereadcounts/environment.yaml
@@ -0,0 +1,7 @@
channels:
- conda-forge
- bioconda
- nodefaults
dependencies:
- gatk4 =4.4.0.0
- snakemake-wrapper-utils =0.5.3
16 changes: 16 additions & 0 deletions bio/gatk/denoisereadcounts/meta.yaml
@@ -0,0 +1,16 @@
name: gatk DenoiseReadCounts
url: https://gatk.broadinstitute.org/hc/en-us/articles/13832751133851-DenoiseReadCounts
description: |
Denoises read counts to produce denoised copy ratios
authors:
- Patrik Smeds
input:
- hdf5: TSV or HDF5 file with counts from CollectReadCounts.
- pon: Panel-of-normals from CreateReadCountPanelOfNormals (optional)
- gc_interval: GC-content annotated-intervals from {@link AnnotateIntervals (optional)
output:
- std_copy_ratio: Standardized-copy-ratios file
- denoised_copy_ratio: Denoised-copy-ratios file
params:
- java_opts: additional arguments to be passed to the java compiler, e.g. "-XX:ParallelGCThreads=10" (not for `-XmX` or `-Djava.io.tmpdir`, since they are handled automatically).
- extra: additional program arguments.
15 changes: 15 additions & 0 deletions bio/gatk/denoisereadcounts/test/Snakefile
@@ -0,0 +1,15 @@
rule denoisereadcounts:
input:
hdf5=["a.counts.hdf5"],
output:
std_copy_ratio="a.standardizedCR.tsv",
denoised_copy_ratio="a.denoisedCR.tsv",
log:
"logs/gatk/denoisereadcounts.log",
params:
extra="", # optional
java_opts="", # optional
resources:
mem_mb=1024,
wrapper:
"master/bio/gatk/denoisereadcounts"
Binary file added bio/gatk/denoisereadcounts/test/a.counts.hdf5
Binary file not shown.
37 changes: 37 additions & 0 deletions bio/gatk/denoisereadcounts/wrapper.py
@@ -0,0 +1,37 @@
__author__ = "Patrik Smeds"
__copyright__ = "Copyright 2023, Patrik Smed"
__email__ = "patrik.smeds@gmail.com"
__license__ = "MIT"


import tempfile
from snakemake.shell import shell
from snakemake_wrapper_utils.java import get_java_opts


panel_of_normal = ""
if snakemake.input.get("pon", None):
panel_of_normal = "--count-panel-of-normals {snakemake.input.pon}"


gc_intervals = ""
if snakemake.input.get("gc_interval", None):
gc_intervals = "--annotated-intervals {snakemake.input.gc_interval}"

extra = snakemake.params.get("extra", "")
java_opts = get_java_opts(snakemake)

log = snakemake.log_fmt_shell(stdout=True, stderr=True)

with tempfile.TemporaryDirectory() as tmpdir:
shell(
"gatk --java-options '{java_opts}' DenoiseReadCounts"
" -I {snakemake.input.hdf5} "
" {panel_of_normal}"
" {gc_intervals}"
" --standardized-copy-ratios {snakemake.output.std_copy_ratio}"
" --denoised-copy-ratios {snakemake.output.denoised_copy_ratio}"
" --tmp-dir {tmpdir}"
" {extra}"
" {log}"
)
9 changes: 9 additions & 0 deletions test.py
Expand Up @@ -4043,6 +4043,15 @@ def test_gatk_applybqsrspark_cram():
["snakemake", "-s", "Snakefile_cram", "--cores", "1", "recal/a.cram", "--use-conda", "-F"],
)


@skip_if_not_modified
def test_gatk_denoisereadcounts():
run(
"bio/gatk/denoisereadcounts",
["snakemake", "--cores", "1", "a.standardizedCR.tsv", "a.denoisedCR.tsv", "--use-conda", "-F"],
)


@skip_if_not_modified
def test_gatk_haplotypecaller_vcf():
run(
Expand Down

0 comments on commit 0288ace

Please sign in to comment.