INTERSECTBED

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

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_merge:
    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:
        "v3.7.0/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

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)

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