GENOMECOVERAGEBED

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

Computes the coverage of a feature file as histograms, per-base reports or BEDGRAPH summaries among a given genome.

URL: https://bedtools.readthedocs.io/en/latest/content/tools/genomecov.html

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:
        "v3.6.0-3-gc8272d7/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:
        "v3.6.0-3-gc8272d7/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.31.1

Input/Output

Input:

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

  • BAM files sorted by position.

  • ref: Path to genome file, this must come after the other files

Output:

  • genomecov (.genomecov)

Params

  • extra: additional program arguments

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}"
)