Skip to content

Commit

Permalink
feat: Enhance deeptools compute matrix (#1236)
Browse files Browse the repository at this point in the history
<!-- 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
-->

### Description

Add the following : muti threading option, blacklist input file, and
temporary directory for deep blue download.

### 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),
* 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: tdayris <tdayris@gustaveroussy.fr>
Co-authored-by: tdayris <thibault.dayris@gustaveroussy.fr>
Co-authored-by: Johannes Köster <johannes.koester@uni-due.de>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: snakedeploy-bot[bot] <115615832+snakedeploy-bot[bot]@users.noreply.github.com>
Co-authored-by: Felix Mölder <felix.moelder@uni-due.de>
Co-authored-by: Christopher Schröder <christopher.schroeder@tu-dortmund.de>
Co-authored-by: Filipe G. Vieira <1151762+fgvieira@users.noreply.github.com>
  • Loading branch information
9 people committed Apr 7, 2023
1 parent 74a9de2 commit a44bef5
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 21 deletions.
17 changes: 12 additions & 5 deletions bio/deeptools/computematrix/meta.yaml
@@ -1,4 +1,5 @@
name: deepTools computeMatrix
url: https://deeptools.readthedocs.io/en/develop/content/tools/computeMatrix.html
description: >
``deepTools computeMatrix`` calculates scores per genomic region.
The matrix file can be used as input for other tools or for the generation of a ``deepTools plotHeatmap`` or ``deepTools plotProfiles``.
Expand Down Expand Up @@ -27,10 +28,16 @@ description: >
authors:
- Antonie Vietor
- Thibault Dayris
input:
- BED or GTF files (.bed or .gtf) AND
- bigWig files (.bw)
- bed: Path to BED or GTF files (.bed or .gtf) AND
- bigwig: Path to bigWig files (.bw)
output:
- gzipped matrix file (.gz) AND/OR
- tab-separated table of matrix file (.tab) AND/OR
- BED matrix file with sorted regions after skiping zeros or min/max threshold values (.bed)
- matrix_gz: gzipped matrix file (.gz) AND/OR
- matrix_tab: tab-separated table of matrix file (.tab) AND/OR
- matrix_bed: BED matrix file with sorted regions after skiping zeros or min/max threshold values (.bed)
params:
- command: Either `scale-regions` or `reference-point`
- extra: Optional parameters given to computeMatrix
notes:
- Bigwig DeepBlue URL, if any, should be given in `params.extra`, or downloaded separately.
16 changes: 9 additions & 7 deletions bio/deeptools/computematrix/test/Snakefile
@@ -1,22 +1,24 @@
rule compute_matrix:
input:
# Please note that the -R and -S options are defined via input files
bed=expand("{sample}.bed", sample=["a", "b"]),
bigwig=expand("{sample}.bw", sample=["a", "b"])
# Please note that the -R and -S options are defined via input files
bed=expand("{sample}.bed", sample=["a", "b"]),
bigwig=expand("{sample}.bw", sample=["a", "b"]),
# Optional blacklist file
# blacklist="",
output:
# Please note that --outFileName, --outFileNameMatrix and --outFileSortedRegions are exclusively defined via output files.
# Usable output variables, their extensions and which option they implicitly call are listed here:
# https://snakemake-wrappers.readthedocs.io/en/stable/wrappers/deeptools/computematrix.html.
matrix_gz="matrix_files/matrix.gz", # required
matrix_gz="matrix_files/matrix.gz", # required
# optional output files
matrix_tab="matrix_files/matrix.tab",
matrix_bed="matrix_files/matrix.bed"
matrix_bed="matrix_files/matrix.bed",
log:
"logs/deeptools/compute_matrix.log"
"logs/deeptools/compute_matrix.log",
params:
# required argument, choose "scale-regions" or "reference-point"
command="scale-regions",
# optional parameters
extra="--regionBodyLength 200 --verbose"
extra="--regionBodyLength 200 --verbose",
wrapper:
"master/bio/deeptools/computematrix"
30 changes: 21 additions & 9 deletions bio/deeptools/computematrix/wrapper.py
Expand Up @@ -4,9 +4,14 @@
__license__ = "MIT"

from snakemake.shell import shell
from tempfile import TemporaryDirectory

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

blacklist = snakemake.input.get("blacklist", "")
if blacklist:
blacklist = f"--blackListFileName {blacklist}"

out_tab = snakemake.output.get("matrix_tab")
out_bed = snakemake.output.get("matrix_bed")

Expand All @@ -18,12 +23,19 @@
if out_bed:
optional_output += " --outFileSortedRegions {out_bed} ".format(out_bed=out_bed)

shell(
"(computeMatrix "
"{snakemake.params.command} "
"{snakemake.params.extra} "
"-R {snakemake.input.bed} "
"-S {snakemake.input.bigwig} "
"-o {snakemake.output.matrix_gz} "
"{optional_output}) {log}"
)

with TemporaryDirectory() as tempdir:
temp = ""
if "deepBlueURL" in snakemake.params.extra:
temp = f"--deepBlueTempDir {tempdir}"

shell(
"computeMatrix "
"{snakemake.params.command} "
"{snakemake.params.extra} "
"--numberOfProcessors {snakemake.threads} "
"-R {snakemake.input.bed} "
"-S {snakemake.input.bigwig} "
"-o {snakemake.output.matrix_gz} "
"{blacklist} {optional_output} {temp} {log}"
)

0 comments on commit a44bef5

Please sign in to comment.