@@ -33,116 +33,129 @@ if config["peak_calling_macs2"]["run"]:
33
33
fdr = peak_fdr ("macs2_narrow" )
34
34
35
35
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" ,
39
38
output :
40
- multiext (f "results/macs2_narrow /fdr{ fdr } /{{bg_sample} }" ,
39
+ multiext ("results/macs2_broad /fdr{fdr}/{dir}/ {bg_sample}" ,
41
40
"_peaks.xls" ,
42
41
"_peaks.narrowPeak" ,
43
42
"_summits.bed"
44
43
)
45
44
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" ]
47
73
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"
51
100
52
101
53
102
rule peak_annotation_plots_macs2_narrow :
54
103
input :
55
104
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 ),
57
106
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" ),
60
109
params :
61
110
extra = "" ,
62
111
threads : config ["resources" ]["plotting" ]["cpu" ]
63
112
resources :
64
113
runtime = config ["resources" ]["plotting" ]["time" ]
65
114
log :
66
- f "logs/plotting/macs2_narrow_peak_annotation_plots_fdr{ fdr } .log"
115
+ "logs/plotting/macs2_narrow_peak_annotation_plots_fdr{fdr}.log"
67
116
conda :
68
117
"../envs/R.yaml"
69
118
script :
70
119
"../scripts/peak_annotation_plots.R"
71
120
72
-
121
+
73
122
rule annotate_peaks_macs_narrow :
74
123
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 " ,
76
125
adb = f"resources/{ resources .genome } _{ resources .build } _annotation.Rdata" ,
77
126
gtf = resources .gtf ,
78
127
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" ),
80
129
params :
81
130
extra = ""
131
+ log :
132
+ "logs/annotate_peaks_macs2_narrow_fdr{fdr}/{bg_sample}.log"
82
133
threads : config ["resources" ]["deeptools" ]["cpu" ]
83
134
resources :
84
135
runtime = config ["resources" ]["deeptools" ]["time" ]
85
- log :
86
- f"logs/annotate_peaks_macs2_narrow/fdr{ fdr } /{{bg_sample}}.log"
87
136
conda :
88
137
"../envs/R.yaml"
89
138
script :
90
139
"../scripts/annotate_peaks.R"
91
140
92
-
141
+
93
142
rule get_gene_names_macs2 :
94
143
input :
95
- txt = f "results/macs2_narrow/fdr{ fdr } /{{ bg_sample} }.annotated.txt"
144
+ txt = "results/macs2_narrow/fdr{fdr}/{bg_sample}.annotated.txt"
96
145
output :
97
- ids = f "results/macs2_narrow/fdr{ fdr } /{{ bg_sample} }.geneIDs.txt"
146
+ ids = "results/macs2_narrow/fdr{fdr}/{bg_sample}.geneIDs.txt"
98
147
threads : 1
99
148
resources :
100
149
runtime = 5
101
150
log :
102
- f "logs/geneIDs_peaks_macs2_narrow_fdr{ fdr } /{{ bg_sample} }.log"
151
+ "logs/geneIDs_peaks_macs2_narrow_fdr{fdr}/{bg_sample}.log"
103
152
conda :
104
153
"../envs/deeptools.yaml"
105
154
shell :
106
155
"sed '1d' {input.txt} | "
107
- "awk '{{print $(NF-4),$(NF-1)}}' |"
108
- " sort | "
156
+ "awk '{{print $(NF-4),$(NF-1)}}' | "
157
+ "sort | "
109
158
"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}"
146
159
147
160
elif config ["peak_calling_macs2" ]["mode" ] == "broad" :
148
161
fdr = config ["peak_calling_macs2" ]["broad_cutoff" ]
@@ -168,7 +181,7 @@ if config["peak_calling_macs2"]["run"]:
168
181
resources :
169
182
runtime = config ["resources" ]["deeptools" ]["time" ]
170
183
log :
171
- "logs/macs2_broad_single /fdr{fdr}/{dir}/{bg_sample}.log"
184
+ "logs/macs2_broad /fdr{fdr}/{dir}/{bg_sample}.log"
172
185
conda :
173
186
"../envs/peak_calling.yaml"
174
187
script :
@@ -207,7 +220,7 @@ if config["peak_calling_macs2"]["run"]:
207
220
resources :
208
221
runtime = 15
209
222
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"
211
224
conda :
212
225
"../envs/peak_calling.yaml"
213
226
script :
0 commit comments