Skip to content

Commit 32587a7

Browse files
committed
updated macs2 narrow
1 parent 09f476e commit 32587a7

File tree

2 files changed

+77
-68
lines changed

2 files changed

+77
-68
lines changed

workflow/rules/peak_calling.smk

+74-61
Original file line numberDiff line numberDiff line change
@@ -33,116 +33,129 @@ if config["peak_calling_macs2"]["run"]:
3333
fdr = peak_fdr("macs2_narrow")
3434

3535
rule peak_calling_MACS2_narrow:
36-
input:
37-
treatment=expand("results/bam/{dir}/{{bg_sample}}.bam", bg_sample=BG_SAMPLES),
38-
control=expand("results/bam/{dir}/{dam_sample}.bam", dam_sample=DAM_SAMPLES),
36+
input:
37+
bam="results/bam/{dir}/{bg_sample}.bam",
3938
output:
40-
multiext(f"results/macs2_narrow/fdr{fdr}/{{bg_sample}}",
39+
multiext("results/macs2_broad/fdr{fdr}/{dir}/{bg_sample}",
4140
"_peaks.xls",
4241
"_peaks.narrowPeak",
4342
"_summits.bed"
4443
)
4544
params:
46-
macs2_params(),
45+
outdir=lambda w, output: os.path.dirname(output[0]),
46+
paired_end=paired_end,
47+
mode="narrow",
48+
fdr=fdr,
49+
genome=resources.genome,
50+
data_dir=lambda w, input: os.path.dirname(input[0]),
51+
extra=config["peak_calling_macs2"]["extra"]
52+
threads: config["resources"]["deeptools"]["cpu"]
53+
resources:
54+
runtime=config["resources"]["deeptools"]["time"]
55+
log:
56+
"logs/macs2_narrow/fdr{fdr}/{dir}/{bg_sample}.log"
57+
conda:
58+
"../envs/peak_calling.yaml"
59+
script:
60+
"../scripts/macs2.py"
61+
62+
63+
rule consensus_peaks_macs2_narrow:
64+
input:
65+
peaks=expand("results/macs2_narrow/fdr{fdr}/{dir}/{{bg_sample}}_peaks.narrowPeak", dir=DIRS, fdr=fdr),
66+
output:
67+
"results/macs2_narrow/fdr{fdr}/consensus_peaks/{bg_sample}.overlap.bed"
68+
params:
69+
extra=""
70+
threads: config["resources"]["deeptools"]["cpu"]
71+
resources:
72+
runtime=config["resources"]["deeptools"]["time"]
4773
log:
48-
f"logs/macs2_narrow/fdr{fdr}/{{bg_sample}}.log"
49-
wrapper:
50-
f"{wrapper_version}/bio/macs2/callpeak"
74+
"logs/consensus_peaks_macs2_narrow_fdr{fdr}/{bg_sample}.log"
75+
conda:
76+
"../envs/peak_calling.yaml"
77+
shell:
78+
"bedtools multiinter {params.extra} -i {input.peaks} > {output}"
79+
80+
81+
rule filter_consensus_peaks_macs2_narrow:
82+
input:
83+
bed="results/macs2_narrow/fdr{fdr}/consensus_peaks/{bg_sample}.overlap.bed",
84+
cs=f"resources/{resources.genome}_chrom.sizes",
85+
output:
86+
ext_bed="results/macs2_narrow/fdr{fdr}/consensus_peaks/{bg_sample}.overlap.filtered.bed",
87+
params:
88+
k=config["consensus_peaks"]["keep"],
89+
max_size=config["consensus_peaks"]["max_size"],
90+
e=config["consensus_peaks"]["extend_by"],
91+
threads: 1
92+
resources:
93+
runtime=15
94+
log:
95+
"logs/filter_consensus_peaks/macs2_narrow/fdr{fdr}/{bg_sample}.log"
96+
conda:
97+
"../envs/peak_calling.yaml"
98+
script:
99+
"../scripts/filter_consensus_peaks.py"
51100

52101

53102
rule peak_annotation_plots_macs2_narrow:
54103
input:
55104
gtf=resources.gtf,
56-
bed=expand(f"results/macs2_narrow/fdr{fdr}/{{bg_sample}}_peaks.narrowPeak", bg_sample=BG_SAMPLES),
105+
bed=expand("results/macs2_narrow/fdr{fdr}/consensus_peaks/{bg_sample}.overlap.filtered.bed", fdr=fdr,bg_sample=BG_SAMPLES),
57106
output:
58-
fd=report(f"results/plots/macs2_narrow/fdr{fdr}/feature_distributions.pdf", caption="../report/feature_distributions.rst", category="Peak annotation MACS2 narrow"),
59-
dt=report(f"results/plots/macs2_narrow/fdr{fdr}/distance_to_tss.pdf", caption="../report/distance_to_tss.rst", category="Peak annotation MACS2 narrow"),
107+
fd=report("results/plots/macs2_narrow/fdr{fdr}/feature_distributions_overlap.pdf", caption="../report/feature_distributions.rst", category="Peak annotation MACS2 narrow"),
108+
dt=report("results/plots/macs2_narrow/fdr{fdr}/distance_to_tss.pdf_overlap", caption="../report/distance_to_tss.rst", category="Peak annotation MACS2 narrow"),
60109
params:
61110
extra="",
62111
threads: config["resources"]["plotting"]["cpu"]
63112
resources:
64113
runtime=config["resources"]["plotting"]["time"]
65114
log:
66-
f"logs/plotting/macs2_narrow_peak_annotation_plots_fdr{fdr}.log"
115+
"logs/plotting/macs2_narrow_peak_annotation_plots_fdr{fdr}.log"
67116
conda:
68117
"../envs/R.yaml"
69118
script:
70119
"../scripts/peak_annotation_plots.R"
71120

72-
121+
73122
rule annotate_peaks_macs_narrow:
74123
input:
75-
bed=f"results/macs2_narrow/fdr{fdr}/{{bg_sample}}_peaks.narrowPeak",
124+
bed="results/macs2_narrow/fdr{fdr}/consensus_peaks/{bg_sample}.overlap.filtered.bed",
76125
adb=f"resources/{resources.genome}_{resources.build}_annotation.Rdata",
77126
gtf=resources.gtf,
78127
output:
79-
txt=report(f"results/macs2_narrow/fdr{fdr}/{{bg_sample}}.annotated.txt", caption="../report/annotated_peaks.rst", category="Annotated peaks MACS2 narrow"),
128+
txt=report("results/macs2_narrow/fdr{fdr}/{bg_sample}.annotated.txt", caption="../report/annotated_peaks.rst", category="Annotated peaks MACS2 narrow"),
80129
params:
81130
extra=""
131+
log:
132+
"logs/annotate_peaks_macs2_narrow_fdr{fdr}/{bg_sample}.log"
82133
threads: config["resources"]["deeptools"]["cpu"]
83134
resources:
84135
runtime=config["resources"]["deeptools"]["time"]
85-
log:
86-
f"logs/annotate_peaks_macs2_narrow/fdr{fdr}/{{bg_sample}}.log"
87136
conda:
88137
"../envs/R.yaml"
89138
script:
90139
"../scripts/annotate_peaks.R"
91140

92-
141+
93142
rule get_gene_names_macs2:
94143
input:
95-
txt=f"results/macs2_narrow/fdr{fdr}/{{bg_sample}}.annotated.txt"
144+
txt="results/macs2_narrow/fdr{fdr}/{bg_sample}.annotated.txt"
96145
output:
97-
ids=f"results/macs2_narrow/fdr{fdr}/{{bg_sample}}.geneIDs.txt"
146+
ids="results/macs2_narrow/fdr{fdr}/{bg_sample}.geneIDs.txt"
98147
threads: 1
99148
resources:
100149
runtime=5
101150
log:
102-
f"logs/geneIDs_peaks_macs2_narrow_fdr{fdr}/{{bg_sample}}.log"
151+
"logs/geneIDs_peaks_macs2_narrow_fdr{fdr}/{bg_sample}.log"
103152
conda:
104153
"../envs/deeptools.yaml"
105154
shell:
106155
"sed '1d' {input.txt} | "
107-
"awk '{{print $(NF-4),$(NF-1)}}' |"
108-
" sort | "
156+
"awk '{{print $(NF-4),$(NF-1)}}' | "
157+
"sort | "
109158
"uniq > {output.ids}"
110-
111-
112-
rule peak_calling_MACS2_narrow_single:
113-
input:
114-
treatment=expand("results/bam/{dir}/{bg_sample}.bam", dir=DIRS, bg_sample=BG_SAMPLES),
115-
control=expand("results/bam/{dir}/{dam_sample}.bam", dam_sample=DAM_SAMPLES, dir=DIRS),
116-
output:
117-
multiext(f"results/macs2_narrow_single/fdr{fdr}/{{bg_sample}}",
118-
"_peaks.xls",
119-
"_peaks.narrowPeak",
120-
"_summits.bed"
121-
)
122-
params:
123-
macs2_params(),
124-
log:
125-
f"logs/macs2_narrow_single/fdr{fdr}/{{bg_sample}}.log"
126-
wrapper:
127-
f"{wrapper_version}/bio/macs2/callpeak"
128-
129-
130-
rule overlapping_peaks_macs2_narrow:
131-
input:
132-
peaks=expand(f"results/macs2_narrow_single/fdr{fdr}/{{bg_sample}}_peaks.narrowPeak", fdr=peak_fdr("macs2_narrow"), bg_sample=BG_SAMPLES),
133-
output:
134-
f"results/macs2_narrow_single/fdr{fdr}/overlapping_peaks/{{bg_sample}}.overlap.bed"
135-
params:
136-
extra=""
137-
threads: config["resources"]["deeptools"]["cpu"]
138-
resources:
139-
runtime=config["resources"]["deeptools"]["time"]
140-
log:
141-
f"logs/overlapping_peaks_macs2_narrow_fdr{fdr}/{{bg_sample}}.log"
142-
conda:
143-
"../envs/peak_calling.yaml"
144-
shell:
145-
"bedtools multiinter {params.extra} -i {input.beds} > {output}"
146159

147160
elif config["peak_calling_macs2"]["mode"] == "broad":
148161
fdr = config["peak_calling_macs2"]["broad_cutoff"]
@@ -168,7 +181,7 @@ if config["peak_calling_macs2"]["run"]:
168181
resources:
169182
runtime=config["resources"]["deeptools"]["time"]
170183
log:
171-
"logs/macs2_broad_single/fdr{fdr}/{dir}/{bg_sample}.log"
184+
"logs/macs2_broad/fdr{fdr}/{dir}/{bg_sample}.log"
172185
conda:
173186
"../envs/peak_calling.yaml"
174187
script:
@@ -207,7 +220,7 @@ if config["peak_calling_macs2"]["run"]:
207220
resources:
208221
runtime=15
209222
log:
210-
"logs/filter_consensus_peaks/macs2_broad/fdr{fdr}/{{bg_sample}}.log"
223+
"logs/filter_consensus_peaks/macs2_broad/fdr{fdr}/{bg_sample}.log"
211224
conda:
212225
"../envs/peak_calling.yaml"
213226
script:

workflow/scripts/general_functions.smk

+3-7
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,9 @@ def targets():
3838
if config["peak_calling_macs2"]["run"]:
3939
if config["peak_calling_macs2"]["mode"] == "narrow":
4040
TARGETS.extend([
41-
#expand(f"results/plots/macs2_narrow/fdr{fdr}/feature_distributions.pdf"),
42-
#expand(f"results/plots/macs2_narrow/fdr{fdr}/distance_to_tss.pdf"),
43-
#expand(f"results/macs2_narrow/fdr{fdr}/{{bg_sample}}_peaks.xls", bg_sample=BG_SAMPLES),
44-
#expand(f"results/macs2_narrow/fdr{fdr}/{{bg_sample}}_peaks.narrowPeak",bg_sample=BG_SAMPLES),
45-
#expand(f"results/macs2_narrow/fdr{fdr}/{{bg_sample}}_summits.bed", bg_sample=BG_SAMPLES),
46-
#expand(f"results/macs2_narrow/fdr{fdr}/{{bg_sample}}.annotated.txt", bg_sample=BG_SAMPLES),
47-
#expand(f"results/macs2_narrow/fdr{fdr}/{{bg_sample}}.geneIDs.txt", bg_sample=BG_SAMPLES)
41+
expand("results/plots/macs2_narrow/fdr{fdr}/feature_distributions_overlap.pdf", fdr=fdr),
42+
expand("results/plots/macs2_narrow/fdr{fdr}/distance_to_tss.pdf_overlap", fdr=fdr),
43+
expand("results/macs2_narrow/fdr{fdr}/{bg_sample}.geneIDs.txt", fdr=fdr, bg_sample=BG_SAMPLES),
4844
])
4945
elif config["peak_calling_macs2"]["mode"] == "broad":
5046
TARGETS.extend([

0 commit comments

Comments
 (0)