MULTIQC

https://img.shields.io/github/issues-pr/snakemake/snakemake-wrappers/bio/multiqc?label=version%20update%20pull%20requests

Generate qc report using multiqc.

URL: https://multiqc.info/

Example

This wrapper can be used in the following way:

rule multiqc_dir:
    input:
        expand("samtools_stats/{sample}.txt", sample=["a", "b"]),
    output:
        "qc/multiqc.html",
        directory("qc/multiqc_data"),
    params:
        extra="--data-dir",  # Optional: extra parameters for multiqc.
    log:
        "logs/multiqc.log",
    wrapper:
        "v3.3.7/bio/multiqc"


rule multiqc_file:
    input:
        expand("samtools_stats/{sample}.txt", sample=["a"]),
    output:
        "qc/multiqc.a.html",
        "qc/multiqc.a_data.zip",
    params:
        extra="--zip-data-dir",  # 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",
    wrapper:
        "v3.3.7/bio/multiqc"

Note that input, output and log file paths can be chosen freely.

When running with

snakemake --use-conda

the software dependencies will be automatically deployed into an isolated environment before execution.

Software dependencies

  • multiqc=1.20

Input/Output

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

  • 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

Authors

  • Julian de Ruiter

Code

"""Snakemake wrapper for trimming paired-end reads using cutadapt."""

__author__ = "Julian de Ruiter"
__copyright__ = "Copyright 2017, Julian de Ruiter"
__email__ = "julianderuiter@gmail.com"
__license__ = "MIT"


import tempfile
from pathlib import Path
from snakemake.shell import shell


extra = snakemake.params.get("extra", "")
log = snakemake.log_fmt_shell(stdout=True, stderr=True)


# 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)
else:
    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}")