@@ -196,6 +196,60 @@ if config["peak_calling_macs2"]["run"]:
196
196
"../envs/R.yaml"
197
197
script :
198
198
"../scripts/plot_enrichment.R"
199
+
200
+
201
+ rule count_reads_in_peaks :
202
+ # Adapted from https://www.biostars.org/p/337872/#337890
203
+ input :
204
+ bam = "results/bam/{dir}/{bg_sample}.bam" ,
205
+ b = "results/macs2_narrow/fdr{fdr}/{dir}/{bg_sample}_peaks.narrowPeak" ,
206
+ output :
207
+ total_read_count = "results/macs2_narrow/fdr{fdr}/read_counts/{dir}/{bg_sample}.total.count" ,
208
+ peak_read_count = "results/macs2_narrow/fdr{fdr}/read_counts/{dir}/{bg_sample}.peak.count" ,
209
+ params :
210
+ extra = "" ,
211
+ threads : config ["resources" ]["deeptools" ]["cpu" ]
212
+ resources :
213
+ runtime = config ["resources" ]["deeptools" ]["time" ]
214
+ log :
215
+ "logs/bedtools_intersect/fdr{fdr}/{dir}/{bg_sample}.log"
216
+ conda :
217
+ "../envs/peak_calling.yaml"
218
+ shell :
219
+ "bedtools bamtobed "
220
+ "{params.extra} "
221
+ "-i {input.bam} | "
222
+ "sort -k1,1 -k2,2n | "
223
+ "tee >(wc -l > {output.total_read_count}) | "
224
+ "bedtools intersect "
225
+ "{params.extra} "
226
+ "-sorted "
227
+ "-c "
228
+ "-a {input.b} "
229
+ "-b stdin | "
230
+ "awk '{{i+=$NF}}END{{print i}}' > "
231
+ "{output.peak_read_count} "
232
+ "{log}"
233
+
234
+
235
+ rule plot_fraction_of_reads_in_peaks :
236
+ input :
237
+ total_read_count = expand ("results/macs2_broad/fdr{fdr}/read_counts/{dir}/{bg_sample}.total.count" , dir = DIRS , fdr = fdr , bg_sample = BG_SAMPLES ),
238
+ peak_read_count = expand ("results/macs2_broad/fdr{fdr}/read_counts/{dir}/{bg_sample}.peak.count" , dir = DIRS , fdr = fdr , bg_sample = BG_SAMPLES ),
239
+ output :
240
+ plot = "results/plots/macs2_broad/fdr{fdr}/frip.pdf" ,
241
+ csv = "results/macs2_broad/fdr{fdr}/frip.csv" ,
242
+ params :
243
+ extra = "" ,
244
+ threads : config ["resources" ]["plotting" ]["cpu" ]
245
+ resources :
246
+ runtime = config ["resources" ]["plotting" ]["time" ]
247
+ log :
248
+ "logs/plot_frip/fdr{fdr}.log"
249
+ conda :
250
+ "../envs/R.yaml"
251
+ script :
252
+ "../scripts/plot_frip.R"
199
253
200
254
elif config ["peak_calling_macs2" ]["mode" ] == "broad" :
201
255
fdr = config ["peak_calling_macs2" ]["broad_cutoff" ]
@@ -347,6 +401,7 @@ if config["peak_calling_macs2"]["run"]:
347
401
script :
348
402
"../scripts/enrichment_analysis.R"
349
403
404
+
350
405
rule plot_enrichment :
351
406
input :
352
407
xlsx = "results/macs2_broad/fdr{fdr}/enrichment_analysis/{bg_sample}.xlsx" ,
@@ -363,4 +418,58 @@ if config["peak_calling_macs2"]["run"]:
363
418
conda :
364
419
"../envs/R.yaml"
365
420
script :
366
- "../scripts/plot_enrichment.R"
421
+ "../scripts/plot_enrichment.R"
422
+
423
+
424
+ rule count_reads_in_peaks :
425
+ # Adapted from https://www.biostars.org/p/337872/#337890
426
+ input :
427
+ bam = "results/bam/{dir}/{bg_sample}.bam" ,
428
+ b = "results/macs2_broad/fdr{fdr}/{dir}/{bg_sample}_peaks.broadPeak" ,
429
+ output :
430
+ total_read_count = "results/macs2_broad/fdr{fdr}/read_counts/{dir}/{bg_sample}.total.count" ,
431
+ peak_read_count = "results/macs2_broad/fdr{fdr}/read_counts/{dir}/{bg_sample}.peak.count" ,
432
+ params :
433
+ extra = "" ,
434
+ threads : config ["resources" ]["deeptools" ]["cpu" ]
435
+ resources :
436
+ runtime = config ["resources" ]["deeptools" ]["time" ]
437
+ log :
438
+ "logs/bedtools_intersect/fdr{fdr}/{dir}/{bg_sample}.log"
439
+ conda :
440
+ "../envs/peak_calling.yaml"
441
+ shell :
442
+ "bedtools bamtobed "
443
+ "{params.extra} "
444
+ "-i {input.bam} | "
445
+ "sort -k1,1 -k2,2n | "
446
+ "tee >(wc -l > {output.total_read_count}) | "
447
+ "bedtools intersect "
448
+ "{params.extra} "
449
+ "-sorted "
450
+ "-c "
451
+ "-a {input.b} "
452
+ "-b stdin | "
453
+ "awk '{{i+=$NF}}END{{print i}}' > "
454
+ "{output.peak_read_count} "
455
+ "{log}"
456
+
457
+
458
+ rule plot_fraction_of_reads_in_peaks :
459
+ input :
460
+ total_read_count = expand ("results/macs2_broad/fdr{fdr}/read_counts/{dir}/{bg_sample}.total.count" , dir = DIRS , fdr = fdr , bg_sample = BG_SAMPLES ),
461
+ peak_read_count = expand ("results/macs2_broad/fdr{fdr}/read_counts/{dir}/{bg_sample}.peak.count" , dir = DIRS , fdr = fdr , bg_sample = BG_SAMPLES ),
462
+ output :
463
+ plot = "results/plots/macs2_broad/fdr{fdr}/frip.pdf" ,
464
+ csv = "results/macs2_broad/fdr{fdr}/frip.csv" ,
465
+ params :
466
+ extra = "" ,
467
+ threads : config ["resources" ]["plotting" ]["cpu" ]
468
+ resources :
469
+ runtime = config ["resources" ]["plotting" ]["time" ]
470
+ log :
471
+ "logs/plot_frip/fdr{fdr}.log"
472
+ conda :
473
+ "../envs/R.yaml"
474
+ script :
475
+ "../scripts/plot_frip.R"
0 commit comments