Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: MultiQC temp folder, specify outdir/filename, infer options, and bump version #2639

Merged
merged 6 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions bio/multiqc/environment.linux-64.pin.txt
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ https://conda.anaconda.org/conda-forge/linux-64/pyyaml-5.4.1-py311hd4cff14_4.tar
https://conda.anaconda.org/conda-forge/noarch/setuptools-69.0.3-pyhd8ed1ab_0.conda#40695fdfd15a92121ed2922900d0308b
https://conda.anaconda.org/conda-forge/linux-64/simplejson-3.19.2-py311h459d7ec_0.conda#d6478cbce002db6303f0d749860f3e22
https://conda.anaconda.org/conda-forge/noarch/six-1.16.0-pyh6c4a22f_0.tar.bz2#e5f25f8dbc060e9a8d912e432202afc2
https://conda.anaconda.org/bioconda/noarch/snakemake-wrapper-utils-0.6.2-pyhdfd78af_0.tar.bz2#fd8759bbd04116eace828c4fab906096
https://conda.anaconda.org/conda-forge/noarch/tenacity-8.2.3-pyhd8ed1ab_0.conda#1482e77f87c6a702a7e05ef22c9b197b
https://conda.anaconda.org/conda-forge/noarch/typing_extensions-4.9.0-pyha770c72_0.conda#a92a6440c3fe7052d63244f3aba2a4a7
https://conda.anaconda.org/conda-forge/noarch/wheel-0.42.0-pyhd8ed1ab_0.conda#1cdea58981c5cbc17b51973bcaddcea7
Expand Down
1 change: 1 addition & 0 deletions bio/multiqc/environment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ channels:
- nodefaults
dependencies:
- multiqc =1.20
- snakemake-wrapper-utils =0.6.2
6 changes: 5 additions & 1 deletion bio/multiqc/meta.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
name: multiqc
description: |
Generate qc report using multiqc.
Generate qc report using MultiQC.
url: https://multiqc.info/
authors:
- Julian de Ruiter
- Filipe G. Vieira
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:
- qc report (html)
- multiqc data folder or zip (optional)
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.
8 changes: 4 additions & 4 deletions bio/multiqc/test/Snakefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ rule multiqc_dir:
expand("samtools_stats/{sample}.txt", sample=["a", "b"]),
output:
"qc/multiqc.html",
directory("qc/multiqc_data"),
directory("qc_data/multiqc_data"),
params:
extra="--data-dir", # Optional: extra parameters for multiqc.
extra="--verbose", # Optional: extra parameters for multiqc.
log:
"logs/multiqc.log",
wrapper:
Expand All @@ -17,9 +17,9 @@ rule multiqc_file:
expand("samtools_stats/{sample}.txt", sample=["a"]),
output:
"qc/multiqc.a.html",
"qc/multiqc.a_data.zip",
"qc_data/multiqc.a_data.zip",
params:
extra="--zip-data-dir", # Optional: extra parameters for multiqc.
extra="--verbose", # Optional: extra parameters for multiqc.
use_input_files_only=True, # Optional, use only a.txt and don't search folder samtools_stats for files
log:
"logs/multiqc.log",
Expand Down
67 changes: 48 additions & 19 deletions bio/multiqc/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
__license__ = "MIT"


import tempfile
# No need for explicit temp folder, since MultiQC already uses TMPDIR (https://multiqc.info/docs/usage/troubleshooting/#no-space-left-on-device)

from pathlib import Path
from snakemake.shell import shell
from snakemake_wrapper_utils.snakemake import is_arg


extra = snakemake.params.get("extra", "")
Expand All @@ -24,21 +26,48 @@
input_data = set(snakemake.input)


with tempfile.TemporaryDirectory() as tmpdir:
shell(
"multiqc"
" {extra}"
" --outdir {tmpdir}"
" --filename out"
" {input_data}"
" {log}"
)

for output in snakemake.output:
if output.endswith("_data"):
ext = "_data"
elif output.endswith(".zip"):
ext = "_data.zip"
else:
ext = Path(output).suffix
shell("mv {tmpdir}/out{ext} {output}")
# Add extra options depending on output files
no_report = True
for output in snakemake.output:
if output.endswith(".html"):
no_report = False
if output.endswith("_data"):
extra += " --data-dir"
if output.endswith(".zip"):
extra += " --zip-data-dir"
if no_report:
extra += " --no-report"
if (
not is_arg("--data-dir", extra)
and not is_arg("-z", extra)
and not is_arg("--zip-data-dir", extra)
):
extra += " --no-data-dir"

# Specify output dir and file name, since they are stored in the JSON file
out_dir = Path(snakemake.output[0]).parent
file_name = Path(snakemake.output[0]).with_suffix("").name


shell(
"multiqc"
" {extra}"
" --outdir {out_dir}"
" --filename {file_name}"
" {input_data}"
" {log}"
)


# Move files to another destination (if needed)
for output in snakemake.output:
if output.endswith("_data"):
ext = "_data"
elif output.endswith(".zip"):
ext = "_data.zip"
else:
ext = Path(output).suffix

default_dest = f"{out_dir}/{file_name}{ext}"
if default_dest != output:
shell("mv {default_dest} {output}")