DEEPTOOLS PLOTCOVERAGE

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

deepTools plotCoverage assess the sequencing depth of given samples. For more information about deepTools, also see the source code.

URL: https://deeptools.readthedocs.io/en/develop/content/tools/plotCoverage.html

Example

This wrapper can be used in the following way:

rule test_deeptools_plotcoverage:
    input:
        # Optional blacklisted regions
        # blacklist="",
        # Optional region file
        # bed="",
        bams=["a.bam"],
        bais=["a.bam.bai"],
    output:
        plot="coverage.png",
        # Optional raw counts
        raw_counts="coverage.raw",
        # Optional metrics
        metrics="coverage.metrics",
    params:
        extra="--coverageThresholds 1",
    log:
        "logs/deeptools/coverage.log"
    wrapper:
        "v3.12.1/bio/deeptools/plotcoverage"

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

  • deeptools=3.5.5

Input/Output

Input:

  • bams: Path to alignment (BAM)

  • bed: Path to region file (BED)

  • blacklist: Path to blacklisted regions (BED)

Output:

  • raw_counts: Raw coverage plot

  • metrics: Raw coverage metrics

  • plot: Path to image

Authors

  • Thibault Dayris

Code

__author__ = "Thibault Dayris"
__copyright__ = "Copyright 2023, Thibault Dayris"
__email__ = "thibault.dayris@gustaveroussy.fr"
__license__ = "MIT"

from snakemake.shell import shell

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


bed = snakemake.input.get("bed", "")
if bed:
    bed = " --BED " + bed


raw_counts = snakemake.output.get("raw_counts", "")
if raw_counts:
    raw_counts = " --outRawCounts " + raw_counts


metrics = snakemake.output.get("metrics", "")
if metrics:
    metrics = " --outCoverageMetrics " + metrics
    if not "--coverageThresholds" in extra:
        raise ValueError(
            "Coverage metrics without a `--coverageThresholds` in "
            "extra parameters will result in an empty file. Please "
            "provide `--coverageThresholds` or remove "
            "metrics file from expected output files."
        )


blacklist = snakemake.input.get("blacklist", "")
if blacklist:
    blacklist = " --blackListFileName " + blacklist


accepted_extensions = ["eps", "png", "svg", "pdf"]
out_image_extension = str(snakemake.output["plot"]).split(".")[-1]
if out_image_extension not in accepted_extensions:
    raise ValueError(
        "Wrong image format: {ext}, expected: {expected}".format(
            ext=out_image_extension, expected=str(accepted_extensions)
        )
    )


shell(
    "plotCoverage "
    "{extra} {bed} {raw_counts} {metrics} {blacklist} "
    "--numberOfProcessors {snakemake.threads} "
    "--bamfiles {snakemake.input.bams} "
    "--plotFile {snakemake.output.plot} "
    "--plotFileFormat {out_image_extension} "
    " {log}"
)