-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmake_candidate_enhancers.Rmd
519 lines (398 loc) · 22.3 KB
/
make_candidate_enhancers.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
---
title: "ChIP-seq analysis of DV mutants"
author: "Liz Ing-Simmons"
date: "05/03/2020"
output:
html_document:
toc: true
toc_float: true
code_folding: hide
---
```{r global_options, echo=FALSE}
knitr::opts_chunk$set(fig.width=6, fig.height=4, dpi = 300, out.width = "60%",
warning=FALSE, message=FALSE, error= FALSE, dev = c("png", "pdf"))
pdf.options(useDingbats = FALSE)
options(stringsAsFactors = FALSE)
seed <- 20200116
colour_scheme <- c("PCNA-GFP" = "black", "w1118" = "grey",
gd7 = "#648FFF", Tollrm910 = "#DC267F", Toll10B = "#FFB000")
basedir <- here::here()
```
```{r load_packages, cache = FALSE}
# library("conflicted")
library("GenomicRanges")
library("GenomicFeatures")
library("dplyr")
library("rtracklayer")
library("ggplot2")
library("BSgenome.Dmelanogaster.UCSC.dm6")
Dmel <- Dmelanogaster
seqlevelsStyle(Dmel) <- "Ensembl"
dm3_to_dm6_chain <- import.chain(file.path(basedir, "../external_data/dm3ToDm6.over.chain"))
```
```{r functions}
calc_jaccard <- function(n1, n2, list){
union_size <- sum(width(GenomicRanges::union(list[[as.character(n1)]],
list[[as.character(n2)]],
ignore.strand = TRUE)))
intersect_size <- sum(width(GenomicRanges::intersect(list[[as.character(n1)]],
list[[as.character(n2)]],
ignore.strand = TRUE)))
return(intersect_size / union_size)
}
n_overlap <- function(n1, n2, list){
length(subsetByOverlaps(list[[as.character(n1)]], list[[as.character(n2)]],
ignore.strand = TRUE))
}
calc_jaccard2 <- function(n1, n2, list1, list2){
union_size <- sum(width(GenomicRanges::union(list1[[as.character(n1)]],
list2[[as.character(n2)]],
ignore.strand = TRUE)))
intersect_size <- sum(width(GenomicRanges::intersect(list1[[as.character(n1)]],
list2[[as.character(n2)]],
ignore.strand = TRUE)))
return(intersect_size / union_size)
}
n_overlap2 <- function(n1, n2, list1, list2){
length(subsetByOverlaps(list1[[as.character(n1)]],
list2[[as.character(n2)]],
ignore.strand = TRUE))
}
drop_windows <- function(windows, genome){
drop_idx <- end(windows) > seqlengths(genome)[as.character(seqnames(windows))] | start(windows) <= 0
message("Dropping ", sum(drop_idx), " ranges")
return(windows[!drop_idx])
}
```
The aim of this analysis is to compare ChIP-seq peaks, differential ChIP-seq peaks, and known enhancers.
# Import data
```{r}
blacklist <- import(file.path(basedir, "../external_data/blacklist/Blacklist/lists/dm6-blacklist.v2.bed"))
chrs_to_use <- c("2L", "2R", "3L", "3R", "4", "X", "Y")
```
## Genes
```{r, cache=TRUE}
gene_ids_key <- rtracklayer::import.gff(file.path(basedir, "../external_data/flybase/dmel-all-r6.30.gtf.gz")) %>%
as.data.frame() %>%
dplyr::filter(type == "gene") %>%
dplyr::select(gene_id, gene_symbol)
txdb <- makeTxDbFromGFF(file.path(basedir, "../external_data/flybase/dmel-all-r6.30.gtf.gz"))
transcripts_gr <- transcripts(txdb, columns = c("TXNAME", "GENEID"))
mcols(transcripts_gr)$GENEID <- unlist(mcols(transcripts_gr)$GENEID)
mcols(transcripts_gr) <- left_join(as.data.frame(mcols(transcripts_gr)),
gene_ids_key, by = c("GENEID" = "gene_id"))
transcripts_gr <- transcripts_gr[seqnames(transcripts_gr) %in% chrs_to_use]
# potential transcripts to exclude
# sapply(transcripts_gr$gene_symbol[grepl(":", transcripts_gr$gene_symbol)], function(str){
# strsplit(str, ":", fixed = TRUE)[[1]][1]
# }) %>% table()
tx_types_to_exclude <- c("tRNA:", "rRNA:", "rRNA-Psi:", "asRNA:", "snoRNA:", "scaRNA:", "snRNA:")
transcripts_gr <- transcripts_gr[!grepl(pattern = paste(tx_types_to_exclude, collapse = "|"),
transcripts_gr$gene_symbol)]
promoters_gr <- promoters(transcripts_gr, upstream = 100, downstream = 100)
```
```{r read_chipseq, cache=TRUE, eval=FALSE}
chipseq_bw <- list.files(file.path(basedir, "../external_data/koenecke_2016_2017/chipseq_aligned/"),
pattern ="_sorted_filtered_merged_canonical_chrs.bw$", full.names = TRUE) %>%
setNames(gsub("_sorted_filtered_merged_canonical_chrs.bw", "", basename(.)))
chipseq_bw2 <- list.files(file.path(basedir, "../external_data/extra_chip-seq/chipseq_aligned/"),
pattern ="_sorted_filtered_merged_canonical_chrs.bw$", full.names = TRUE) %>%
setNames(gsub("_sorted_filtered_merged_canonical_chrs.bw", "", basename(.)))
chipseq_bw <- c(chipseq_bw, chipseq_bw2)
chipseq_df <- tibble::tibble(file = basename(chipseq_bw), name = names(chipseq_bw)) %>%
tidyr::separate(name, into = c("factor", "genotype"), sep = "_", remove = FALSE)
chipseq_df %>%
dplyr::select(factor, genotype) %>%
knitr::kable()
files_to_use <- chipseq_df %>%
dplyr::filter(factor %in% c("H3K27ac", "H3K27me3")) %>%
arrange(factor) %>%
pull(name)
names(chipseq_bw)
chipseq_cov <- lapply(chipseq_bw[files_to_use], function(f) {
coverage(import.bw(f), weight = "score")})
```
## ChIP-seq peaks and differential peaks
```{r}
## ChIP-seq MACS2 peaks
koenecke_peaks <- list.files(file.path(basedir, "../external_data/koenecke_2016_2017/chipseq_peaks/"),
pattern = "H3K27.*filtered.narrowPeak", full.names = TRUE)
tollrm910_peaks <- list.files(file.path(basedir, "../external_data/extra_chip-seq/chipseq_peaks/"),
pattern = "H3K27.*filtered.narrowPeak", full.names = TRUE)
peak_files <- c(koenecke_peaks, tollrm910_peaks)
names(peak_files) <- gsub("_peaks_filtered.narrowPeak", "", basename(peak_files))
chipseq_peaks <- lapply(peak_files, function(f){
peaks <- read.table(f, col.names = c("chr", "start", "end", "name", "score", "strand",
"fc", "pval", "qval", "summit"))
makeGRangesFromDataFrame(peaks, keep.extra.columns = TRUE)
})
## Koenecke et al enhancers
koenecke_distal_enhancers_dm3 <- readxl::read_excel(
file.path(basedir, "../external_data/koenecke_2016_2017/enhancers/",
"distal_enhancers_dm3_13059_2016_1057_MOESM4_ESM.xlsx"), sheet = 2)
koenecke_distal_enhancers_dm6_list <- koenecke_distal_enhancers_dm3 %>%
as.data.frame() %>%
makeGRangesFromDataFrame(keep.extra.columns = TRUE) %>%
liftOver(dm3_to_dm6_chain)
koenecke_distal_enhancers_dm6 <- do.call("c", unname(koenecke_distal_enhancers_dm6_list[lengths(koenecke_distal_enhancers_dm6_list) == 1]))
seqlevelsStyle(koenecke_distal_enhancers_dm6) <- "Ensembl"
koenecke_enhancers_list <- split(koenecke_distal_enhancers_dm6,
koenecke_distal_enhancers_dm6$differential_k27ac)
names(koenecke_enhancers_list) <- gsub("Higher in ", "Koenecke et al. ", names(koenecke_enhancers_list))
## Literature enhancers from Koenecke et al
literature_enhancers_dm3 <- readxl::read_excel(file.path(basedir,
"../external_data/koenecke_2016_2017/enhancers/literature_enhancers_dm3_13059_2016_1057_MOESM2_ESM.xlsx"), sheet = 1)
literature_enhancers_dm6_list <- literature_enhancers_dm3 %>%
as.data.frame() %>%
makeGRangesFromDataFrame(keep.extra.columns = TRUE) %>%
liftOver(dm3_to_dm6_chain)
literature_enhancers_dm6 <- do.call("c", unname(literature_enhancers_dm6_list[lengths(literature_enhancers_dm6_list) == 1]))
seqlevelsStyle(literature_enhancers_dm6) <- "Ensembl"
literature_enhancers_list <- split(literature_enhancers_dm6, literature_enhancers_dm6$enhancer_type)
names(literature_enhancers_list) <- paste("Literature", names(literature_enhancers_list))
## My differential H3K27ac regions
differential_h3k27ac_peak_files <- list.files(file.path(basedir, "data/differential_chipseq/"),
"h3k27ac", full.names = TRUE)
names(differential_h3k27ac_peak_files) <- gsub(".bed", "", basename(differential_h3k27ac_peak_files))
differential_h3k27ac_peaks <- lapply(differential_h3k27ac_peak_files, function(f){
peaks <- read.table(f, col.names = c("chr", "start", "end", "name", "score", "strand"))
makeGRangesFromDataFrame(peaks, keep.extra.columns = TRUE)
})
```
# Inspecting ChIP-seq peak calls
```{r peak_counts}
peak_data <- lapply(chipseq_peaks, as.data.frame, stringsAsFactors = FALSE) %>%
bind_rows(.id = "sample") %>%
tidyr::separate(sample, into = c("factor", "genotype", "replicate"), sep = "_")
peak_counts <- peak_data %>%
group_by(factor, genotype, replicate) %>%
tally()
ggplot(peak_counts, aes(x = genotype, y = replicate, fill = n, label = n)) +
geom_tile() +
geom_text() +
scale_fill_gradient(low = "white", high = "steelblue") +
scale_x_discrete(position = "top") +
facet_wrap(~factor)
ggplot(peak_data, aes(x = genotype, fill = replicate, y = width)) +
geom_violin(draw_quantiles = c(0.25, 0.5, 0.75)) +
# geom_boxplot(width = 0.5, position = position_dodge(width = 0.9)) +
scale_y_log10(limits = c(100, 30000)) +
theme_bw() +
facet_wrap(~factor)
jaccard_list <- c(chipseq_peaks, promoters = promoters_gr)
sample_names <- sort(names(jaccard_list))
chipseq_peaks_jaccard <- data.frame(n1 = factor(rep(sample_names, length(sample_names)),
levels = sample_names),
n2 = factor(rep(sample_names, each = length(sample_names)),
levels = sample_names)) %>%
mutate(jaccard = purrr::map2_dbl(n1, n2, calc_jaccard, jaccard_list))
ggplot(chipseq_peaks_jaccard, aes(x = n1 , y = n2, fill = jaccard)) +
geom_tile() +
geom_text(aes(label = signif(jaccard, 2))) +
scale_fill_gradient(low = "white", high = "steelblue") +
theme_bw(base_size = 16) +
theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
labs(x = "", y = "")
```
## Using only peaks that overlap between replicates
```{r}
chip_names <- unique(paste(peak_counts$factor, peak_counts$genotype, sep = "_"))
chipseq_peaks_intersect_list <- lapply(chip_names, function(chip_name){
tmp <- chipseq_peaks[grep(chip_name, names(chipseq_peaks))]
ol <- GenomicRanges::intersect(tmp[[1]], tmp[[2]])
return(ol)
}) %>% setNames(chip_names)
peak_data <- lapply(chipseq_peaks_intersect_list, as.data.frame, stringsAsFactors = FALSE) %>%
bind_rows(.id = "sample") %>%
tidyr::separate(sample, into = c("factor", "genotype"), sep = "_")
peak_counts <- peak_data %>%
group_by(factor, genotype) %>%
tally()
ggplot(peak_counts, aes(x = genotype, y = factor, fill = n, label = n)) +
geom_tile() +
geom_text() +
scale_fill_gradient(low = "white", high = "steelblue") +
scale_x_discrete(position = "top")
ggplot(peak_data, aes(x = genotype, y = width)) +
geom_violin(draw_quantiles = c(0.25, 0.5, 0.75)) +
# geom_boxplot(width = 0.5, position = position_dodge(width = 0.9)) +
scale_y_log10(limits = c(100, 30000)) +
theme_bw() +
facet_wrap(~factor)
# jaccard index calculations
jaccard_list <- c(chipseq_peaks_intersect_list, promoters = promoters_gr)
sample_names <- sort(names(jaccard_list))
chipseq_peaks_intersect_jaccard <- data.frame(n1 = factor(rep(sample_names, length(sample_names)),
levels = sample_names),
n2 = factor(rep(sample_names, each = length(sample_names)),
levels = sample_names)) %>%
mutate(jaccard = purrr::map2_dbl(n1, n2, calc_jaccard, jaccard_list))
ggplot(chipseq_peaks_intersect_jaccard, aes(x = n1 , y = n2, fill = jaccard)) +
geom_tile() +
geom_text(aes(label = signif(jaccard, 2))) +
scale_fill_gradient(low = "white", high = "steelblue") +
theme_bw(base_size = 16) +
theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
labs(x = "", y = "")
```
# Inspecting differential H3K27ac peaks
Differential peaks are named as follows: e.g. gd7-Tollrm910_up are peaks that are up in Tollrm910.
So, we would expect overlaps between the following sets of peaks:
h3k27ac_gd7-tl10b_down & h3k27ac_gd7-Tollrm910_down - peaks higher in gd7 than others
h3k27ac_gd7-tl10b_up & h3k27ac_tl10b-Tollrm910_down - peaks higher in Toll10B than others
h3k27ac_gd7-Tollrm910_up & h3k27ac_tl10b-Tollrm910_up - peaks higher in Tollrm9/10 than others
```{r}
peak_data <- lapply(differential_h3k27ac_peaks, as.data.frame, stringsAsFactors = FALSE) %>%
bind_rows(.id = "sample") %>%
tidyr::separate(sample, into = c("factor", "genotype", "direction"), sep = "_")
peak_counts <- peak_data %>%
group_by(factor, genotype, direction) %>%
tally()
ggplot(peak_counts, aes(x = genotype, y = direction, fill = n, label = n)) +
geom_tile() +
geom_text() +
scale_fill_gradient(low = "white", high = "steelblue") +
scale_x_discrete(position = "top")
ggplot(peak_data, aes(x = genotype, y = width)) +
geom_violin(draw_quantiles = c(0.25, 0.5, 0.75)) +
# geom_boxplot(width = 0.5, position = position_dodge(width = 0.9)) +
scale_y_log10(limits = c(100, 30000)) +
theme_bw() +
facet_wrap(~direction)
# jaccard index calculations
jaccard_list <- c(differential_h3k27ac_peaks, promoters = promoters_gr)
sample_names <- sort(names(jaccard_list))
differential_h3k27ac_peaks_jaccard <- data.frame(n1 = factor(rep(sample_names, length(sample_names)),
levels = sample_names),
n2 = factor(rep(sample_names, each = length(sample_names)),
levels = sample_names)) %>%
mutate(jaccard = purrr::map2_dbl(n1, n2, calc_jaccard, jaccard_list))
ggplot(differential_h3k27ac_peaks_jaccard, aes(x = n1 , y = n2, fill = jaccard)) +
geom_tile() +
geom_text(aes(label = signif(jaccard, 2))) +
scale_fill_gradient(low = "white", high = "steelblue") +
theme_bw(base_size = 16) +
theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
labs(x = "", y = "")
```
I see the following patterns:
- peaks that are higher in gd7 than Toll10B overlap with peaks that are higher in gd7 than Tollrm9/10, but have even higher overlap with peaks that are higher in Tollrm9/10 than Toll10B, suggesting a set of peaks shared between gd7 and Tollrm9/10
- peaks that are higher in Toll10B than gd7 overlap with peaks that are higher in Tollrm9/10 than gd7, but also with peaks that are higher in Toll10B than in Tollrm9/10 - again, this suggests that a subset of peaks are shared between Toll10B and Tollrm9/10
- other overlaps support this pattern!
- no group has high overlap with promoters
```{r}
sapply(differential_h3k27ac_peaks, function(gr){
length(subsetByOverlaps(gr, promoters_gr))/length(gr)
})
differential_h3k27ac_peaks <- lapply(differential_h3k27ac_peaks, function(gr){
ol <- findOverlaps(gr, promoters_gr)
gr[-queryHits(ol)]
})
lengths(differential_h3k27ac_peaks)
```
~30-50% of peaks are within 100bp of a TSS. I'll remove these.
```{r}
# jaccard index calculations
jaccard_list <- c(literature_enhancers_list, differential_h3k27ac_peaks)
sample_names <- names(jaccard_list)
differential_h3k27ac_peaks_jaccard <- data.frame(n1 = factor(rep(sample_names, length(sample_names)),
levels = sample_names),
n2 = factor(rep(sample_names, each = length(sample_names)),
levels = sample_names)) %>%
mutate(jaccard = purrr::map2_dbl(n1, n2, n_overlap, jaccard_list))
ggplot(differential_h3k27ac_peaks_jaccard, aes(x = n1 , y = n2, fill = jaccard)) +
geom_tile() +
geom_text(aes(label = signif(jaccard, 2))) +
scale_fill_gradient(low = "white", high = "steelblue") +
theme_bw(base_size = 16) +
theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
labs(x = "", y = "")
```
```{r}
testlist <- c(literature_enhancers_list, koenecke_enhancers_list)
e_jaccard <- data.frame(n2 = factor(rep(names(differential_h3k27ac_peaks), length(testlist))),
n1 = factor(rep(names(testlist), each = length(differential_h3k27ac_peaks)))) %>%
mutate(jaccard = purrr::map2_dbl(n1, n2, calc_jaccard2,
list1 = testlist, list2 = differential_h3k27ac_peaks),
n_overlap = purrr::map2_dbl(n1, n2, n_overlap2,
list1 = testlist, list2 = differential_h3k27ac_peaks))
# ggplot(e_jaccard, aes(x = n1 , y = n2, fill = jaccard)) +
# geom_tile() +
# geom_text(aes(label = signif(jaccard, 2))) +
# scale_fill_gradient(low = "white", high = "steelblue") +
# theme_bw(base_size = 16) +
# theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
# labs(x = "", y = "")
ggplot(e_jaccard, aes(x = n1 , y = n2, fill = n_overlap)) +
geom_tile() +
geom_text(aes(label = n_overlap)) +
scale_fill_gradient(low = "white", high = "steelblue") +
theme_bw(base_size = 16) +
theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
labs(x = "", y = "")
testlist <- lapply(testlist, function(test_gr){
mcols(test_gr) <- cbind(mcols(test_gr),
as.data.frame(
sapply(differential_h3k27ac_peaks, function(gr){
countOverlaps(test_gr, gr) > 0 })))
return(test_gr)
})
```
Of the `r length(testlist[["Literature ME"]])` mesoderm enhancers identified from the literature by Koenecke et al, `r sum(mcols(testlist[["Literature ME"]])[, "h3k27ac_gd7-tl10b_down"])` overlap peaks that are significantly up in Toll10B compared to gd7.
Of the `r length(testlist[["Literature DEE"]])` dorsal ectoderm enhancers identified from the literature by Koenecke et al, `r sum(mcols(testlist[["Literature DEE"]])[, "h3k27ac_gd7-tl10b_up"])` overlap peaks that are significantly up in gd7 compared to Toll10B.
Of the `r length(testlist[["Koenecke et al. Toll10b"]])` Toll10B enhancers identified by Koenecke et al, `r sum(mcols(testlist[["Koenecke et al. Toll10b"]])[, "h3k27ac_gd7-tl10b_down"])` overlap peaks that are significantly up in Toll10B compared to gd7. `r sum(mcols(testlist[["Koenecke et al. Toll10b"]])[, "h3k27ac_tl10b-Tollrm910_up"])` overlap peaks that are significantly up in Toll10B compared to Tollrm9/10.
Of the `r length(testlist[["Koenecke et al. gd7"]])` dorsal ectoderm enhancers identified from the literature by Koenecke et al, `r sum(mcols(testlist[["Koenecke et al. gd7"]])[, "h3k27ac_gd7-tl10b_up"])` overlap peaks that are significantly up in gd7 compared to Toll10B. `r sum(mcols(testlist[["Koenecke et al. gd7"]])[, "h3k27ac_gd7-Tollrm910_up"])` overlap peaks that are significantly up in gd7 compared to Tollrm9/10.
## Selecting a stringent set of candidate enhancers
To select a stringent set of candidate enhancers, I'll take the subset of regions which are significantly enriched for H3K27ac in one genotype compared to *both* others.
```{r}
gd7_only <- BiocGenerics::intersect(differential_h3k27ac_peaks$`h3k27ac_gd7-tl10b_up`,
differential_h3k27ac_peaks$`h3k27ac_gd7-Tollrm910_up`)
tollrm910_only <- BiocGenerics::intersect(differential_h3k27ac_peaks$`h3k27ac_gd7-Tollrm910_down`,
differential_h3k27ac_peaks$`h3k27ac_tl10b-Tollrm910_down`)
toll10B_only <- BiocGenerics::intersect(differential_h3k27ac_peaks$`h3k27ac_gd7-tl10b_down`,
differential_h3k27ac_peaks$`h3k27ac_tl10b-Tollrm910_up`)
stringent_e_list <- list(gd7 = gd7_only, tollrm910 = tollrm910_only, toll10B = toll10B_only)
testlist <- c(literature_enhancers_list, koenecke_enhancers_list)
e_jaccard <- data.frame(n2 = factor(rep(names(stringent_e_list), length(testlist))),
n1 = factor(rep(names(testlist), each = length(stringent_e_list)))) %>%
mutate(jaccard = purrr::map2_dbl(n1, n2, calc_jaccard2,
list1 = testlist, list2 = stringent_e_list),
n_overlap = purrr::map2_dbl(n1, n2, n_overlap2,
list1 = testlist, list2 = stringent_e_list))
# ggplot(e_jaccard, aes(x = n1 , y = n2, fill = jaccard)) +
# geom_tile() +
# geom_text(aes(label = signif(jaccard, 2))) +
# scale_fill_gradient(low = "white", high = "steelblue") +
# theme_bw(base_size = 16) +
# theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
# labs(x = "", y = "")
ggplot(e_jaccard, aes(x = n1 , y = n2, fill = n_overlap)) +
geom_tile() +
geom_text(aes(label = n_overlap)) +
scale_fill_gradient(low = "white", high = "steelblue") +
theme_bw(base_size = 16) +
theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
labs(x = "", y = "")
testlist <- lapply(testlist, function(test_gr){
mcols(test_gr) <- cbind(mcols(test_gr),
as.data.frame(
sapply(stringent_e_list, function(gr){
countOverlaps(test_gr, gr) > 0 })))
return(test_gr)
})
```
Of the `r length(testlist[["Literature ME"]])` mesoderm enhancers identified from the literature by Koenecke et al, `r sum(mcols(testlist[["Literature ME"]])[, "toll10B"])` overlap Toll10B stringent enhancers. `r sum(mcols(testlist[["Literature ME"]])[, "tollrm910"])` overlap Tollrm9/10 stringent enhancers.
Of the `r length(testlist[["Literature DEE"]])` dorsal ectoderm enhancers identified from the literature by Koenecke et al, `r sum(mcols(testlist[["Literature DEE"]])[, "gd7"])` overlap gd7 stringent enhancers. `r sum(mcols(testlist[["Literature DEE"]])[, "tollrm910"])` overlap Tollrm9/10 stringent enhancers.
Of the `r length(testlist[["Koenecke et al. Toll10b"]])` Toll10B enhancers identified by Koenecke et al, `r sum(mcols(testlist[["Koenecke et al. Toll10b"]])[, "toll10B"])` overlap Toll10B stringent enhancers. `r sum(mcols(testlist[["Koenecke et al. Toll10b"]])[, "tollrm910"])` overlap Tollrm9/10 stringent enhancers.
Of the `r length(testlist[["Koenecke et al. gd7"]])` dorsal ectoderm enhancers identified from the literature by Koenecke et al, `r sum(mcols(testlist[["Koenecke et al. gd7"]])[, "gd7"])` overlap gd7 stringent enhancers.. `r sum(mcols(testlist[["Koenecke et al. gd7"]])[, "tollrm910"])` overlap Tollrm9/10 stringent enhancers.
### Exporting stringent enhancers
```{r, cache=TRUE}
export.bed(gd7_only, con = file.path(basedir, "data/supplementary_tables/gd7_candidate_enhancers.bed"))
export.bed(tollrm910_only, con = file.path(basedir, "data/supplementary_tables/Tollrm910_candidate_enhancers.bed"))
export.bed(toll10B_only, con = file.path(basedir, "data/supplementary_tables/Toll10B_candidate_enhancers.bed"))
```
# Session info
This report was generated at `r format(Sys.time(), "%X, %a %b %d %Y")`.
```{r}
devtools::session_info()
```