BEDTOOLS GENOMECOVERAGEBED

bedtools’s genomeCoverageBed computes the coverage of a feature file as histograms, per-base reports or BEDGRAPH summaries among a given genome. For usage information about genomeCoverageBed, please see bedtools’s documentation. For more information about bedtools, also see the source code.

Example

This wrapper can be used in the following way:

rule genomecov_bam:
    input:
        "bam_input/{sample}.sorted.bam"
    output:
        "genomecov_bam/{sample}.genomecov"
    log:
        "logs/genomecov_bam/{sample}.log"
    params:
        "-bg"  # optional parameters
    wrapper:
        "0.76.0/bio/bedtools/genomecov"

rule genomecov_bed:
    input:
        # for genome file format please see:
        # https://bedtools.readthedocs.io/en/latest/content/general-usage.html#genome-file-format
        bed="bed_input/{sample}.sorted.bed",
        ref="bed_input/genome_file"
    output:
        "genomecov_bed/{sample}.genomecov"
    log:
        "logs/genomecov_bed/{sample}.log"
    params:
        "-bg"  # optional parameters
    wrapper:
        "0.76.0/bio/bedtools/genomecov"

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

  • bedtools==2.29.2

Input/Output

Input:

  • BED/GFF/VCF files grouped by chromosome and genome file (genome file format) OR
  • BAM files sorted by position.

Output:

  • genomecov (.genomecov)

Authors

  • Antonie Vietor

Code

__author__ = "Antonie Vietor"
__copyright__ = "Copyright 2020, Antonie Vietor"
__email__ = "antonie.v@gmx.de"
__license__ = "MIT"

import os
from snakemake.shell import shell

log = snakemake.log_fmt_shell(stdout=False, stderr=True)

genome = ""
input_file = ""

if (os.path.splitext(snakemake.input[0])[-1]) == ".bam":
    input_file = "-ibam " + snakemake.input[0]

if len(snakemake.input) > 1:
    if (os.path.splitext(snakemake.input[0])[-1]) == ".bed":
        input_file = "-i " + snakemake.input.get("bed")
        genome = "-g " + snakemake.input.get("ref")

shell(
    "(genomeCoverageBed"
    " {snakemake.params}"
    " {input_file}"
    " {genome}"
    " > {snakemake.output[0]}) {log}"
)