-
Notifications
You must be signed in to change notification settings - Fork 0
/
cic_signal_at_known_enhancers.Rmd
177 lines (133 loc) · 7.98 KB
/
cic_signal_at_known_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
``` {r setup, echo=FALSE, message=FALSE, include=FALSE, error=FALSE}
library(GenomicRanges, warn.conflicts=F)
library(magrittr)
library(parallel)
library(ggplot2)
library(plyr)
library(reshape)
setwd("/papagianni_PNAS_2017/analysis/")
options(knitr.figure_dir = "cic_signal_at_known_enhancers")
source("shared_code/knitr_common.r")
source("shared_code/granges_common.r")
source("shared_code/ggplot_common.r")
source("shared_code/metapeak_common.r")
source("shared_code/sample_common.r")
```
# Cic signal at knwon enhancers
**Author:** [Wanqing Shao](mailto:was@stowers.org)
**Generated:** `r format(Sys.time(), "%a %b %d %Y, %I:%M %p")`
### Cic and Dorsal ChIP-seq peak calling
The following code was ran in the terminal, Macs2 was used for Dl and Cic ChIP-seq peak calling
```{r eval= F}
macs2 callpeak -t /papagianni_PNAS_2017/bam/gd7_cic_chipseq_1.bam /papagianni_PNAS_2017/bam/gd7_cic_chipseq_2.bam -c /papagianni_PNAS_2017/bam/gd7_wce_1.bam /papagianni_PNAS_2017/bam/gd7_wce_2.bam -g dm --call-summits --nomodel --extsize 180 -n gd7_cic_chipseq_combined_rep
macs2 callpeak -t /papagianni_PNAS_2017/bam/tl10b_cic_chipseq_1.bam /papagianni_PNAS_2017/bam/tl10b_cic_chipseq_2.bam -c /papagianni_PNAS_2017/bam/tl10b_wce_1.bam /papagianni_PNAS_2017/bam/tl10b_wce_2.bam -g dm --call-summits --nomodel --extsize 180 -n tl_cic_chipseq_combined_rep
macs2 callpeak -t /papagianni_PNAS_2017/bam/tl10b_dl_chipseq_1.bam /papagianni_PNAS_2017/bam/tl10b_dl_chipseq_2.bam -c /papagianni_PNAS_2017/bam/tl10b_wce_1.bam /papagianni_PNAS_2017/bam/tl10b_wce_2.bam -g dm --call-summits --nomodel --extsize 180 -n tl_dl_chipseq_combined_rep
```
### Process ChIP-seq peaks
```{r peak_process}
valid_chr <- c("chr2L", "chr2R", "chr3L", "chr3R", "chr4", "chrX")
tss_gr <- get(load("rdata/dme_dm6_fb6.17_tss.gr.RData"))
process_peaks <- function(sample){
summit <- import(paste0("/papagianni_PNAS_2017/analysis/macs2/",sample, "_chipseq_combined_rep_summits.bed"))
chipnexus <- load_bigwig(paste0(sample, "_chipnexus_1"))
seqlevels(summit, pruning.mode="coarse") <- valid_chr
summit$sig <- nexus_regionSums(resize(summit, 101, "center"), chipnexus)
summit_c <- reduce(resize(summit, 201, "center"))
summit$overlapping_id <- findOverlaps(query = summit, subject = summit_c) %>% subjectHits
summit_o <- summit[order(summit$sig, decreasing = T)]
summit_u <- summit_o[!duplicated(summit_o$overlapping_id)]
summit_tss <- queryHits(findOverlaps(query=summit_u, subject = tss_gr)) %>% unique()
summit <- summit_u[-1 * summit_tss]
summit
}
dl_summit <- cache("dl_summit", function(){
process_peaks("tl_dl")
})
calc_sig <- function(sample, gr){
nexus <- load_bigwig(sample)
enrich_df <- data.frame(sig = nexus_regionSums(gr, nexus))
colnames(enrich_df) <- sample
enrich_df
}
chipnexus_samples <- list(gd7_cic = "gd7_cic_chipnexus_1", tl_cic = "tl_cic_chipnexus_1", tl_dl ="tl_dl_chipnexus_1")
sig_df <- cache("factor_signal_at_dl_summit", function(){
mclapply(names(chipnexus_samples), function(x)calc_sig(x,resize(dl_summit, 200, "center" )), mc.cores = 3)
})%>% do.call(cbind, .)
mcols(dl_summit) <- sig_df
```
### Prepare known enhancer list
Known enhancer list was downloaded from http://www.oreganno.org/
Previously identified dv enhancers (Koenecke et al, 2016, Genome Biology) were downloaded from https://static-content.springer.com/esm/art%3A10.1186%2Fs13059-016-1057-2/MediaObjects/13059_2016_1057_MOESM4_ESM.xlsx
```{r prepare_known_enhancer_list}
all_regulatory <- read.table("./rdata/ORegAnno_dm6_regulatory_region.txt", header = F, sep = "\t", stringsAsFactors = F)
all_regulatory <- all_regulatory[, c(3, 4, 5, 6, 8,15, 16, 17, 18)]
colnames(all_regulatory) <- c("outcome","type" , "gene", "fb_g_id", "regulatory_element_symbol", "strand", "chr", "start", "end")
regulatory_region <- subset(all_regulatory,
(gene %in% c("zen", "tld", "dpp", "hkb", "tll", "ind", "oc", "ems", "slp1", "gt", "btd")) &
type == "REGULATORY REGION")
regulatory_region$strand <- "*"
regulatory_region.gr <- makeGRangesFromDataFrame(regulatory_region)
regulatory_region.gr$gene <- regulatory_region$gene
nko_enhancer_gr <- get(load("rdata/nko_identified_dv_enhancer.RData")) %>% resize(., 501, "center")
nko_selected_enhancer <- nko_enhancer_gr[nko_enhancer_gr$nearest_gene %in% c("Doc2", "shn")]
nko_mcols <- data.frame(gene = nko_selected_enhancer$nearest_gene)
mcols(nko_selected_enhancer) <- nko_mcols
known_enhancers <- c(regulatory_region.gr, nko_selected_enhancer)
```
### Factor signal at known enhancers
```{r factor_signal_at_known_enhancers, fig.height=10, fig.width= 5}
binding_at_regulatory <- cache("factor_binding_at_enhancer", function(){
lapply(known_enhancers, function(x){
overlap_df <- findOverlaps(x, dl_summit)
if(length(overlap_df) != 0){
enrich_df <- data.frame(gene = x$gene[queryHits(overlap_df)],
gd7_cic = dl_summit$gd7_cic[subjectHits(overlap_df)],
tl_cic = dl_summit$tl_cic[subjectHits(overlap_df)],
tl_dl = dl_summit$tl_dl[subjectHits(overlap_df)])
}else{
enrich_df <- data.frame(gene = x$gene,
gd7_cic = 0,
tl_cic = 0,
tl_dl = 0)
}
enrich_df
}) %>% do.call(rbind, .)
})
### manually calculate signal for ems, gt and slp1
ems <- known_enhancers[known_enhancers$gene == "ems"][1] %>% resize(., 200, "center")
gt <- known_enhancers[known_enhancers$gene == "gt"][5] %>% resize(., 200, "center")
slp1 <- known_enhancers[known_enhancers$gene == "slp1"][5] %>% resize(., 200, "center")
new_gr <- c(ems, gt, slp1)
new_sig_df<- data.frame(gene = new_gr$gene,
gd7_cic = nexus_regionSums(new_gr, load_bigwig("gd7_cic_chipnexus_1")),
tl_cic = nexus_regionSums(new_gr, load_bigwig("tl_cic_chipnexus_1")),
tl_dl = nexus_regionSums(new_gr, load_bigwig("tl_dl_chipnexus_1")))
binding_at_regulatory <- rbind(binding_at_regulatory,new_sig_df )
binding_at_regulatory$sum <- rowSums(binding_at_regulatory[, 2:4])
binding_at_regulatory <- binding_at_regulatory[order(binding_at_regulatory$sum, decreasing = T),]
selected_ehancer_df <- binding_at_regulatory[!duplicated(binding_at_regulatory$gene),]
selected_ehancer_df_m <- melt(selected_ehancer_df, id.vars = c("gene", "sum"))
selected_ehancer_df_m$gene <- factor(selected_ehancer_df_m$gene,
levels = rev(c("zen", "tld", "dpp", "Doc2","shn",
"hkb", "tll", "ind", "oc",
"ems", "slp1", "gt", "btd")))
selected_ehancer_df_m$value <- log2(selected_ehancer_df_m$value)
selected_ehancer_df_m$value <- ifelse(selected_ehancer_df_m$value >= quantile(selected_ehancer_df_m$value, 0.85), quantile(selected_ehancer_df_m$value, 0.85),selected_ehancer_df_m$value)
selected_ehancer_df_m$value[is.infinite(selected_ehancer_df_m$value)] <- min(abs(selected_ehancer_df_m$value))
selected_ehancer_df_m$variable <- factor(selected_ehancer_df_m$variable, levels = c("tl_dl", "tl_cic", "gd7_cic"))
cic_df <- subset(selected_ehancer_df_m, variable %in% c("tl_cic", "gd7_cic"))
dl_df <- subset(selected_ehancer_df_m, variable %in% c("tl_dl"))
ggplot(cic_df, aes(x = variable, y = gene, fill = value)) + geom_tile() +
scale_fill_gradient2(high = "firebrick", mid = "peachpuff1", low = "snow",midpoint = 3.8) +
xlab("") + ylab("Enhancer") + ggtitle("factor binding at known enhancers") +
scale_x_discrete(labels = c("Cic Toll10b", "Cic gd7")) +
theme(axis.text.x = element_text(angle = 45, hjust = 1))
ggplot(dl_df, aes(x = variable, y = gene, fill = value)) + geom_tile() +
scale_fill_gradient2(high = "dodgerblue4", mid = "slategray1", low = "snow",midpoint = 3) +
xlab("") + ylab("Enhancer") + ggtitle("factor binding at known enhancers") +
scale_x_discrete(labels = c("Dl Toll10b")) +
theme(axis.text.x = element_text(angle = 45, hjust = 1))
```
```{r echo =F}
sessionInfo()
```