macs2 callpeak
Version:2.2
2.2
Identifier: TL_89cd0d_58.17
Tool
1__author__ = "Antonie Vietor"
2__copyright__ = "Copyright 2020, Antonie Vietor"
3__email__ = "antonie.v@gmx.de"
4__license__ = "MIT"
5
6import os
7import sys
8from snakemake.shell import shell
9
10log = snakemake.log_fmt_shell(stdout=True, stderr=True)
11
12in_contr = snakemake.input.get("control")
13params = "{}".format(snakemake.params)
14opt_input = ""
15out_dir = ""
16
17ext = "_peaks.xls"
18out_file = [o for o in snakemake.output if o.endswith(ext)][0]
19out_name = os.path.basename(out_file[: -len(ext)])
20out_dir = os.path.dirname(out_file)
21
22if in_contr:
23 opt_input = "-c {contr}".format(contr=in_contr)
24
25if out_dir:
26 out_dir = "--outdir {dir}".format(dir=out_dir)
27
28if any(out.endswith(("_peaks.narrowPeak", "_summits.bed")) for out in snakemake.output):
29 if any(
30 out.endswith(("_peaks.broadPeak", "_peaks.gappedPeak"))
31 for out in snakemake.output
32 ):
33 sys.exit(
34 "Output files with _peaks.narrowPeak and/or _summits.bed extensions cannot be created together with _peaks.broadPeak and/or _peaks.gappedPeak extended output files.\n"
35 "For usable extensions please see https://snakemake-wrappers.readthedocs.io/en/stable/wrappers/macs2/callpeak.html.\n"
36 )
37 else:
38 if " --broad" in params:
39 sys.exit(
40 "If --broad option in params is given, the _peaks.narrowPeak and _summits.bed files will not be created. \n"
41 "Remove --broad option from params if these files are needed.\n"
42 )
43
44if any(
45 out.endswith(("_peaks.broadPeak", "_peaks.gappedPeak")) for out in snakemake.output
46):
47 if "--broad " not in params and not params.endswith("--broad"):
48 params += " --broad "
49
50if any(
51 out.endswith(("_treat_pileup.bdg", "_control_lambda.bdg"))
52 for out in snakemake.output
53):
54 if all(p not in params for p in ["--bdg", "-B"]):
55 params += " --bdg "
56else:
57 if any(p in params for p in ["--bdg", "-B"]):
58 sys.exit(
59 "If --bdg or -B option in params is given, the _control_lambda.bdg and _treat_pileup.bdg extended files must be specified in output. \n"
60 )
61
62shell(
63 "(macs2 callpeak "
64 "-t {snakemake.input.treatment} "
65 "{opt_input} "
66 "{out_dir} "
67 "-n {out_name} "
68 "{params}) {log}"
69)
70