Skip to content

Commit

Permalink
feat: MultiQC automatically detects configuration from input file(s) (#…
Browse files Browse the repository at this point in the history
…2722)

<!-- 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
-->

<!-- Add a description of your PR here-->

This PR lets MultiQC automatically detect configuration file, when user
provides them in input, as described in [official
documentation](https://multiqc.info/docs/getting_started/config/).

### 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: 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 Mar 6, 2024
1 parent 7611d30 commit f61238d
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 6 deletions.
3 changes: 2 additions & 1 deletion bio/multiqc/meta.yaml
Expand Up @@ -5,6 +5,7 @@ url: https://multiqc.info/
authors:
- Julian de Ruiter
- Filipe G. Vieira
- Thibault Dayris
input:
- input directory containing qc files, default behaviour is to extract folder path from the provided files or parent folder if a folder is provided.
output:
Expand All @@ -14,4 +15,4 @@ params:
- extra: additional program arguments.
- use_input_files_only: if this variable is set to True input will be used as it is, i.e no folder will be extract from provided file names
notes: |
* options `--data-dir`, `--no-data-dir`, `--zip-data-dir`, and `--no-report` are automaticall inferred.
* options `--data-dir`, `--no-data-dir`, `--zip-data-dir`, `--no-report`, and `--config` are automaticall inferred.
19 changes: 17 additions & 2 deletions bio/multiqc/test/Snakefile
@@ -1,4 +1,4 @@
rule multiqc_dir:
rule test_multiqc_dir:
input:
expand("samtools_stats/{sample}.txt", sample=["a", "b"]),
output:
Expand All @@ -12,7 +12,7 @@ rule multiqc_dir:
"master/bio/multiqc"


rule multiqc_file:
rule test_multiqc_file:
input:
expand("samtools_stats/{sample}.txt", sample=["a"]),
output:
Expand All @@ -25,3 +25,18 @@ rule multiqc_file:
"logs/multiqc.log",
wrapper:
"master/bio/multiqc"


rule test_multiqc_config:
input:
expand("samtools_stats/{sample}.txt", sample=["a", "b"]),
config="config/multiqc_config.yaml",
output:
"qc/multiqc.config.html",
"qc_data/multiqc.config_data.zip",
params:
extra="--verbose",
log:
"logs/multiqc.log",
wrapper:
"master/bio/multiqc"
1 change: 1 addition & 0 deletions bio/multiqc/test/config/multiqc_config.yaml
@@ -0,0 +1 @@
title: "A dummy config test"
16 changes: 13 additions & 3 deletions bio/multiqc/wrapper.py
@@ -1,4 +1,4 @@
"""Snakemake wrapper for trimming paired-end reads using cutadapt."""
"""Snakemake wrapper for MultiQC"""

__author__ = "Julian de Ruiter"
__copyright__ = "Copyright 2017, Julian de Ruiter"
Expand All @@ -16,14 +16,24 @@
extra = snakemake.params.get("extra", "")
log = snakemake.log_fmt_shell(stdout=True, stderr=True)

# Automatically detect configuration files when provided
# in input. For other ways to provide configuration to
# multiqc, see: https://multiqc.info/docs/getting_started/config/
mqc_config = snakemake.input.get("config", "")
if isinstance(mqc_config, list):
for fp in mqc_config:
extra += f" --config {fp}"
elif mqc_config:
extra += f" --config {mqc_config}"


# Set this to False if multiqc should use the actual input directly
# instead of parsing the folders where the provided files are located
use_input_files_only = snakemake.params.get("use_input_files_only", False)
if not use_input_files_only:
input_data = set(Path(fp).parent for fp in snakemake.input)
input_data = set(Path(fp).parent for fp in snakemake.input if fp not in mqc_config)
else:
input_data = set(snakemake.input)
input_data = set(fp for fp in snakemake.input if fp not in mqc_config)


# Add extra options depending on output files
Expand Down
7 changes: 7 additions & 0 deletions test.py
Expand Up @@ -3513,6 +3513,13 @@ def test_multiqc_a():
["snakemake", "--cores", "1", "qc/multiqc.a.html", "--use-conda", "-F"],
)

@skip_if_not_modified
def test_multiqc_config():
run(
"bio/multiqc",
["snakemake", "--cores", "1", "qc/multiqc.config.html", "--use-conda", "-F"],
)


@skip_if_not_modified
def test_muscle_super5():
Expand Down

0 comments on commit f61238d

Please sign in to comment.