INTERSECTBED

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

Intersect BED/BAM/VCF files with bedtools.

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

Example

This wrapper can be used in the following way:

rule bedtools_intersect:
    input:
        left="A.bed",
        right="B.bed"
    output:
        "A_B.intersected.bed"
    params:
        ## Add optional parameters
        extra="-wa -wb" ## In this example, we want to write original entries in A and B for each overlap.
    log:
        "logs/intersect/A_B.log"
    wrapper:
        "v8.1.1/bio/bedtools/intersect"


rule bedtools_intersect_gz:
    input:
        left="A.bed",
        right="B.bed"
    output:
        "A_B.intersected.bed.gz"
    params:
        ## Add optional parameters
        extra="-wa -wb" ## In this example, we want to write original entries in A and B for each overlap.
    log:
        "logs/intersect/A_B_gz.log"
    wrapper:
        "v8.1.1/bio/bedtools/intersect"

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

  • htslib=1.23

Input/Output

Input:

  • left: Path to the left region file. Each feature in left region file is compared to right region(s) file(s) in search of overlaps. (BAM/BED/GFF/VCF formatted)

  • right: Path or list of paths to region(s) file(s) (BAM/BED/GFF/VCF formatted)

Output:

  • Path to the intersection.

Params

  • extra: additional program arguments (except -a (left) and -b (right))

Authors

  • Jan Forster

Code

__author__ = "Jan Forster"
__copyright__ = "Copyright 2019, Jan Forster"
__email__ = "j.forster@dkfz.de"
__license__ = "MIT"

from snakemake.shell import shell

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

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

shell(
    "(bedtools intersect"
    " {extra}"
    " -a {snakemake.input.left}"
    " -b {snakemake.input.right}"
    " {compress}"
    " > {snakemake.output})"
    " {log}"
)