BAMTOBED

https://img.shields.io/badge/wrapper_version-v9.4.1-10785b https://img.shields.io/github/issues-pr/snakemake/snakemake-wrappers/bio/bedtools/bamtobed?label=version%20update%20pull%20requests&color=1cb481

Conversion utility that converts sequence alignments in BAM format into BED, BED12, and/or BEDPE records.

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

Example

This wrapper can be used in the following way:

rule bamtobed:
    input:
        "{sample}.bam",
    output:
        "{sample}.bed",
    log:
        "logs/bamtobed/{sample}.log",
    params:
        extra="-bedpe",  # optional parameters
    wrapper:
        "v9.4.1/bio/bedtools/bamtobed"

rule bamtobed_gz:
    input:
        "{sample}.bam",
    output:
        "{sample}.bed.gz",
    log:
        "logs/bamtobed/{sample}.gz.log",
    params:
        extra="-bedpe",  # optional parameters
    wrapper:
        "v9.4.1/bio/bedtools/bamtobed"

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.

Notes

  • This program/wrapper does not handle multi-threading.

Software dependencies

  • bedtools=2.31.1

  • htslib=1.23.1

Input/Output

Input:

  • BAM file, this must be the first file in the input file list

Output:

  • BED file, this must be the first file in the output file list

Params

  • extra: additional program arguments (except -i)

Authors

  • Filipe G. Vieira

Code

__author__ = "Filipe G. Vieira"
__copyright__ = "Copyright 2022, Filipe G. Vieira"
__license__ = "MIT"

from snakemake.shell import shell

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

compress = "| bgzip" if snakemake.output[0].endswith(".gz") else ""

shell(
    "(bamToBed"
    " {extra}"
    " -i {snakemake.input[0]}"
    " {compress}"
    " > {snakemake.output[0]}"
    ") {log}"
)