.. _`bio/bedtools/merge`: MERGEBED ======== .. image:: https://img.shields.io/github/issues-pr/snakemake/snakemake-wrappers/bio/bedtools/merge?label=version%20update%20pull%20requests :target: https://github.com/snakemake/snakemake-wrappers/pulls?q=is%3Apr+is%3Aopen+label%3Abio/bedtools/merge Merge entries in one or multiple BED/BAM/VCF/GFF files with bedtools. **URL**: https://bedtools.readthedocs.io/en/latest/content/tools/merge.html Example ------- This wrapper can be used in the following way: .. code-block:: python rule bedtools_merge: input: # Multiple bed-files can be added as list "A.bed" output: "A.merged.bed" params: ## Add optional parameters extra="-c 1 -o count" ## In this example, we want to count how many input lines we merged per output line log: "logs/merge/A.log" wrapper: "v3.0.1/bio/bedtools/merge" Note that input, output and log file paths can be chosen freely. When running with .. code-block:: bash snakemake --use-conda the software dependencies will be automatically deployed into an isolated environment before execution. Notes ----- * Warning: If multiple files are provided in input, then this wrapper requires exactly 3 threads. Else, it requires exactly one thread. Software dependencies --------------------- * ``bedtools=2.31.1`` Input/Output ------------ **Input:** * Path or list of paths to interval(s) file(s) (BED/GFF/VCF/BAM) **Output:** * Path to merged interval(s) file. Params ------ * ``extra``: additional program arguments (except for `-i`) Authors ------- * Jan Forster Code ---- .. code-block:: python __author__ = "Jan Forster, Felix Mölder" __copyright__ = "Copyright 2019, Jan Forster" __email__ = "j.forster@dkfz.de, felix.moelder@uni-due.de" __license__ = "MIT" from snakemake.shell import shell ## Extract arguments extra = snakemake.params.get("extra", "") log = snakemake.log_fmt_shell(stdout=True, stderr=True) if len(snakemake.input) > 1: if all(f.endswith(".gz") for f in snakemake.input): cat = "zcat" elif all(not f.endswith(".gz") for f in snakemake.input): cat = "cat" else: raise ValueError("Input files must be all compressed or uncompressed.") shell( "({cat} {snakemake.input} | " "sort -k1,1 -k2,2n | " "bedtools merge {extra} " "-i stdin > {snakemake.output}) " " {log}" ) else: shell( "( bedtools merge" " {extra}" " -i {snakemake.input}" " > {snakemake.output})" " {log}" ) .. |nl| raw:: html