BISMARK2BEDGRAPH

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

Generate bedGraph and coverage files from positional methylation files created by bismark_methylation_extractor (see https://github.com/FelixKrueger/Bismark/blob/master/bismark2bedGraph).

Example

This wrapper can be used in the following way:

# Example for CHG+CHH summary coverage:
rule bismark2bedGraph_noncpg:
    input:
        "meth/CHG_context_{sample}.txt.gz",
        "meth/CHH_context_{sample}.txt.gz"
    output:
        bedGraph="meth_non_cpg/{sample}_non_cpg.bedGraph.gz",
        cov="meth_non_cpg/{sample}_non_cpg.bismark.cov.gz"
    log:
        "logs/meth_non_cpg/{sample}_non_cpg.log"
    params:
        extra="--CX"
    wrapper:
        "v3.8.0-1-g149ef14/bio/bismark/bismark2bedGraph"

# Example for CpG only coverage
rule bismark2bedGraph_cpg:
    input:
        "meth/CpG_context_{sample}.txt.gz"
    output:
        bedGraph="meth_cpg/{sample}_CpG.bedGraph.gz",
        cov="meth_cpg/{sample}_CpG.bismark.cov.gz"
    log:
        "logs/meth_cpg/{sample}_CpG.log"
    wrapper:
        "v3.8.0-1-g149ef14/bio/bismark/bismark2bedGraph"

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

  • bowtie2=2.5.3

  • bismark=0.24.2

  • samtools=1.19.2

Input/Output

Input:

  • Files generated by bismark_methylation_extractor, e.g. CpG_context*.txt.gz, CHG_context*.txt.gz, CHH_context*.txt.gz. By default only CpG file is required, if ‘–CX’ option is output is build by merged input files.

Output:

  • bedGraph: Bismark methylation level track, *.bedGraph.gz (0-based start, 1-based end coordintates, i.e. end offset exclusive)

  • cov: Optional bismark coverage file *.bismark.cov.gz, file name is calculated by bedGraph name (1-based start and end, i.e. end offset inclusive)

Params

  • extra: Any additional args, e.g. ‘–CX’, ‘–ample_memory’, ‘ –buffer_size 10G’, etc.

Authors

  • Roman Cherniatchik

Code

"""Snakemake wrapper for Bismark bismark2bedGraph tool."""

# https://github.com/FelixKrueger/Bismark/blob/master/bismark2bedGraph

__author__ = "Roman Chernyatchik"
__copyright__ = "Copyright (c) 2019 JetBrains"
__email__ = "roman.chernyatchik@jetbrains.com"
__license__ = "MIT"


import os
from snakemake.shell import shell

bedGraph = snakemake.output.get("bedGraph", "")
if not bedGraph:
    raise ValueError("bismark/bismark2bedGraph: Please specify bedGraph output path")

params_extra = snakemake.params.get("extra", "")
cmdline_args = ["bismark2bedGraph {params_extra}"]

dir_name = os.path.dirname(bedGraph)
if dir_name:
    cmdline_args.append("--dir {dir_name}")

fname = os.path.basename(bedGraph)
cmdline_args.append("--output {fname}")

cmdline_args.append("{snakemake.input}")

log = snakemake.log_fmt_shell(stdout=True, stderr=True)
cmdline_args.append("{log}")

# run
shell(" ".join(cmdline_args))