-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFigRtEnrichment.Rmd
343 lines (282 loc) · 14.2 KB
/
FigRtEnrichment.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
---
title: "RT Signal Enrichment"
author: "Weiyan"
date: "5/27/2020"
output: github_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r}
library(EnrichedHeatmap) # for making heatmap
library(rtracklayer) # for reading bigwig and bed files
library(GenomicRanges)
library(circlize)
library(png)
library(dplyr)
library(Hmisc)
library(tidyverse)
```
# Read in bigwig files to GRanges object
```{r}
# read in bigwig files to GRanges object, it can be slow. bigwig is several hundred MB
# you can use which argument to restrict the data in certain regions.
U2OS.bg<- import("data/U2OS_RT_R2-X_Loess_smoothing.bedGraph", format = "BedGraph")
Clone110.bg<- import("data/Clone110_RT_R2-X_Loess_smoothing.bedGraph", format = "BedGraph")
FUSClone110.bg<- import("data/FUSClone110_RT_R2-X_Loess_smoothing.bedGraph", format = "BedGraph")
```
# 1. ERD
## 1.1 load data
```{r}
# read in the bed peak files to GRanges object
ERD.bed<- import("data/ERD_lost.bed", format = "BED")
```
## 1.2 take only the center of the peaks
```{r}
ERD.1MB<- resize(ERD.bed, width = 1000000, fix = "center")
ERD.1MB.center<- resize(ERD.1MB, width =1, fix = "center")
```
## 1.3 prepare matrix
```{r}
U2OS.mat<- normalizeToMatrix(U2OS.bg, ERD.1MB.center, value_column = "score",
mean_mode="w0", w=1000, extend = 500000)
Clone110.mat<- normalizeToMatrix(Clone110.bg, ERD.1MB.center, value_column = "score",
mean_mode="w0", w=1000, extend = 500000)
FUSClone110.mat<- normalizeToMatrix(FUSClone110.bg, ERD.1MB.center, value_column = "score",
mean_mode="w0", w=1000, extend = 500000)
```
### 1.3.1 check data range for "keep" argument in normalizeToMatrix
```{r}
quantile(U2OS.mat, probs = c(0, 0.25, 0.5, 0.75, 0.99, 1))
quantile(Clone110.mat, probs = c(0, 0.25, 0.5, 0.75, 0.99, 1))
quantile(FUSClone110.mat, probs = c(0, 0.25, 0.5, 0.75, 0.99, 1))
```
## 1.4 mapping colors and enrich plot
**from the quantile, I choose the color mapping range**
```{r fig.height=8, fig.width=6}
col_fun_U2OS<- circlize::colorRamp2(c(0, 1), c("white", "red"))
col_fun_Clone110<- circlize::colorRamp2(c(0, 1), c("white", "red"))
col_fun_FUSClone110<- circlize::colorRamp2(c(0, 1), c("white", "red"))
EnrichedHeatmap(U2OS.mat, axis_name_rot = 0, name = "U2OS",
column_title = "U2OS", use_raster = TRUE, col = col_fun_U2OS,
top_annotation = HeatmapAnnotation(lines = anno_enriched(axis_param = list(facing ="inside",
side ="left" ))))+
EnrichedHeatmap(Clone110.mat, axis_name_rot = 0, name = "Clone110",
column_title = "Clone110", use_raster = TRUE, col = col_fun_Clone110,
top_annotation = HeatmapAnnotation(lines = anno_enriched(axis_param = list(facing ="inside",
side ="left" ))))+
EnrichedHeatmap(FUSClone110.mat, axis_name_rot = 0, name = "FUSClone110",
column_title = "FUSClone110", use_raster = TRUE, col = col_fun_FUSClone110,
top_annotation = HeatmapAnnotation(lines = anno_enriched(axis_param = list(facing ="inside",
side ="left" ))))
```
## 1.5 meta profile plot
```{r}
U2OS_mean<- data.frame(avg = colMeans(U2OS.mat),
CI_lower = apply(U2OS.mat, 2, Hmisc::smean.cl.normal)[2,],
CI_upper = apply(U2OS.mat, 2, Hmisc::smean.cl.normal)[3,]) %>%
mutate(factor = "U2OS", pos = colnames(U2OS.mat))
Clone110_mean<- data.frame(avg = colMeans(Clone110.mat),
CI_lower = apply(Clone110.mat, 2, Hmisc::smean.cl.normal)[2,],
CI_upper = apply(Clone110.mat, 2, Hmisc::smean.cl.normal)[3,]) %>%
mutate(factor = "Clone110", pos = colnames(Clone110.mat))
FUSClone110_mean<- data.frame(avg = colMeans(FUSClone110.mat),
CI_lower = apply(FUSClone110.mat, 2, Hmisc::smean.cl.normal)[2,],
CI_upper = apply(FUSClone110.mat, 2, Hmisc::smean.cl.normal)[3,]) %>%
mutate(factor = "FUSClone110", pos = colnames(FUSClone110.mat))
combine_all<- bind_rows(U2OS_mean, Clone110_mean, FUSClone110_mean)
## change position to factor and order it
combine_all$pos<- factor(combine_all$pos, levels= U2OS_mean$pos)
```
### 1.5.1 plot meta profile (without confidence interval)
```{r}
ggplot(combine_all, aes(x = pos,y = avg, group = factor)) + geom_line(aes(color = factor)) +
theme_bw(base_size = 14) +
theme(axis.ticks.x = element_blank()) +
scale_x_discrete(breaks = c("u1", "d10", "d500"), labels =c ("-500kb", "center", "500kb")) +
xlab("ERD") +
ylab("RT")+
ggtitle("RT signal in ERD")
```
### 1.5.2 plot meta profile (with confidence interval)
```{r}
ggplot(combine_all, aes(x = pos,y = avg, group = factor)) + geom_line(aes(color = factor)) +
geom_ribbon(aes(ymin= CI_lower, ymax=CI_upper), alpha=0.2, col = "#8B7E66") +
theme_bw(base_size = 14) +
theme(axis.ticks.x = element_blank()) +
scale_x_discrete(breaks = c("u1", "d10", "d500"), labels =c ("-500kb", "center", "500kb")) +
xlab("ERD") +
ylab("RT")+
ggtitle("RT signal in ERD")
```
# 2. MRD
## 2.1 load data
```{r}
# read in the bed peak files to GRanges object
MRD.bed<- import("data/MRD_lost.bed", format = "BED")
```
## 2.2 take only the center of the peaks
```{r}
MRD.1MB<- resize(MRD.bed, width = 1000000, fix = "center")
MRD.1MB.center<- resize(MRD.1MB, width =1, fix = "center")
```
## 2.3 prepare matrix
```{r}
U2OS.mat<- normalizeToMatrix(U2OS.bg, MRD.1MB.center, value_column = "score",
mean_mode="w0", w=1000, extend = 500000)
Clone110.mat<- normalizeToMatrix(Clone110.bg, MRD.1MB.center, value_column = "score",
mean_mode="w0", w=1000, extend = 500000)
FUSClone110.mat<- normalizeToMatrix(FUSClone110.bg, MRD.1MB.center, value_column = "score",
mean_mode="w0", w=1000, extend = 500000)
```
### 2.3.1 check data range for "keep" argument in normalizeToMatrix
```{r}
quantile(U2OS.mat, probs = c(0, 0.25, 0.5, 0.75, 0.99, 1))
quantile(Clone110.mat, probs = c(0, 0.25, 0.5, 0.75, 0.99, 1))
quantile(FUSClone110.mat, probs = c(0, 0.25, 0.5, 0.75, 0.99, 1))
```
## 2.4 mapping colors and enrich plot
**from the quantile, I choose the color mapping range**
```{r fig.height=8, fig.width=6}
col_fun_U2OS<- circlize::colorRamp2(c(-0.4, 0.4), c("white", "red"))
col_fun_Clone110<- circlize::colorRamp2(c(-0.4, 0.4), c("white", "red"))
col_fun_FUSClone110<- circlize::colorRamp2(c(-0.4, 0.4), c("white", "red"))
EnrichedHeatmap(U2OS.mat, axis_name_rot = 0, name = "U2OS",
column_title = "U2OS", use_raster = TRUE, col = col_fun_U2OS,
top_annotation = HeatmapAnnotation(lines = anno_enriched(axis_param = list(facing ="inside",
side ="left" ))))+
EnrichedHeatmap(Clone110.mat, axis_name_rot = 0, name = "Clone110",
column_title = "Clone110", use_raster = TRUE, col = col_fun_Clone110,
top_annotation = HeatmapAnnotation(lines = anno_enriched(axis_param = list(facing ="inside",
side ="left" ))))+
EnrichedHeatmap(FUSClone110.mat, axis_name_rot = 0, name = "FUSClone110",
column_title = "FUSClone110", use_raster = TRUE, col = col_fun_FUSClone110,
top_annotation = HeatmapAnnotation(lines = anno_enriched(axis_param = list(facing ="inside",
side ="left" ))))
```
## 2.5 meta profile plot
```{r}
U2OS_mean<- data.frame(avg = colMeans(U2OS.mat),
CI_lower = apply(U2OS.mat, 2, Hmisc::smean.cl.normal)[2,],
CI_upper = apply(U2OS.mat, 2, Hmisc::smean.cl.normal)[3,]) %>%
mutate(factor = "U2OS", pos = colnames(U2OS.mat))
Clone110_mean<- data.frame(avg = colMeans(Clone110.mat),
CI_lower = apply(Clone110.mat, 2, Hmisc::smean.cl.normal)[2,],
CI_upper = apply(Clone110.mat, 2, Hmisc::smean.cl.normal)[3,]) %>%
mutate(factor = "Clone110", pos = colnames(Clone110.mat))
FUSClone110_mean<- data.frame(avg = colMeans(FUSClone110.mat),
CI_lower = apply(FUSClone110.mat, 2, Hmisc::smean.cl.normal)[2,],
CI_upper = apply(FUSClone110.mat, 2, Hmisc::smean.cl.normal)[3,]) %>%
mutate(factor = "FUSClone110", pos = colnames(FUSClone110.mat))
combine_all<- bind_rows(U2OS_mean, Clone110_mean, FUSClone110_mean)
## change position to factor and order it
combine_all$pos<- factor(combine_all$pos, levels= U2OS_mean$pos)
```
### 2.5.1 plot meta profile (without confidence interval)
```{r}
ggplot(combine_all, aes(x = pos,y = avg, group = factor)) + geom_line(aes(color = factor)) +
theme_bw(base_size = 14) +
theme(axis.ticks.x = element_blank()) +
scale_x_discrete(breaks = c("u1", "d10", "d500"), labels =c ("-500kb", "center", "500kb")) +
xlab("MRD") +
ylab("RT")+
ggtitle("RT signal in MRD")
```
### 2.5.2 plot meta profile (with confidence interval)
```{r}
ggplot(combine_all, aes(x = pos,y = avg, group = factor)) + geom_line(aes(color = factor)) +
geom_ribbon(aes(ymin= CI_lower, ymax=CI_upper), alpha=0.2, col = "#8B7E66") +
theme_bw(base_size = 14) +
theme(axis.ticks.x = element_blank()) +
scale_x_discrete(breaks = c("u1", "d10", "d500"), labels =c ("-500kb", "center", "500kb")) +
xlab("MRD") +
ylab("RT")+
ggtitle("RT signal in MRD")
```
# 3. LRD
## 3.1 load data
```{r}
# read in the bed peak files to GRanges object
LRD.bed<- import("data/LRD_lost.bed", format = "BED")
```
## 3.2 take only the center of the peaks
```{r}
LRD.1MB<- resize(LRD.bed, width = 1000000, fix = "center")
LRD.1MB.center<- resize(LRD.1MB, width =1, fix = "center")
```
## 3.3 prepare matrix
```{r}
U2OS.mat<- normalizeToMatrix(U2OS.bg, LRD.1MB.center, value_column = "score",
mean_mode="w0", w=1000, extend = 500000)
Clone110.mat<- normalizeToMatrix(Clone110.bg, LRD.1MB.center, value_column = "score",
mean_mode="w0", w=1000, extend = 500000)
FUSClone110.mat<- normalizeToMatrix(FUSClone110.bg, LRD.1MB.center, value_column = "score",
mean_mode="w0", w=1000, extend = 500000)
```
### 3.3.1 check data range for "keep" argument in normalizeToMatrix
```{r}
quantile(U2OS.mat, probs = c(0, 0.25, 0.5, 0.75, 0.99, 1))
quantile(Clone110.mat, probs = c(0, 0.25, 0.5, 0.75, 0.99, 1))
quantile(FUSClone110.mat, probs = c(0, 0.25, 0.5, 0.75, 0.99, 1))
```
## 3.4 mapping colors and enrich plot
**from the quantile, I choose the color mapping range**
```{r fig.height=8, fig.width=6}
col_fun_U2OS<- circlize::colorRamp2(c(-1, 0), c("white", "red"))
col_fun_Clone110<- circlize::colorRamp2(c(-1, 0), c("white", "red"))
col_fun_FUSClone110<- circlize::colorRamp2(c(-1, 0), c("white", "red"))
EnrichedHeatmap(U2OS.mat, axis_name_rot = 0, name = "U2OS",
column_title = "U2OS", use_raster = TRUE, col = col_fun_U2OS,
top_annotation = HeatmapAnnotation(lines = anno_enriched(axis_param = list(facing ="inside",
side ="left" ))))+
EnrichedHeatmap(Clone110.mat, axis_name_rot = 0, name = "Clone110",
column_title = "Clone110", use_raster = TRUE, col = col_fun_Clone110,
top_annotation = HeatmapAnnotation(lines = anno_enriched(axis_param = list(facing ="inside",
side ="left" ))))+
EnrichedHeatmap(FUSClone110.mat, axis_name_rot = 0, name = "FUSClone110",
column_title = "FUSClone110", use_raster = TRUE, col = col_fun_FUSClone110,
top_annotation = HeatmapAnnotation(lines = anno_enriched(axis_param = list(facing ="inside",
side ="left" ))))
```
## 3.5 meta profile plot
```{r}
U2OS_mean<- data.frame(avg = colMeans(U2OS.mat),
CI_lower = apply(U2OS.mat, 2, Hmisc::smean.cl.normal)[2,],
CI_upper = apply(U2OS.mat, 2, Hmisc::smean.cl.normal)[3,]) %>%
mutate(factor = "U2OS", pos = colnames(U2OS.mat))
Clone110_mean<- data.frame(avg = colMeans(Clone110.mat),
CI_lower = apply(Clone110.mat, 2, Hmisc::smean.cl.normal)[2,],
CI_upper = apply(Clone110.mat, 2, Hmisc::smean.cl.normal)[3,]) %>%
mutate(factor = "Clone110", pos = colnames(Clone110.mat))
FUSClone110_mean<- data.frame(avg = colMeans(FUSClone110.mat),
CI_lower = apply(FUSClone110.mat, 2, Hmisc::smean.cl.normal)[2,],
CI_upper = apply(FUSClone110.mat, 2, Hmisc::smean.cl.normal)[3,]) %>%
mutate(factor = "FUSClone110", pos = colnames(FUSClone110.mat))
combine_all<- bind_rows(U2OS_mean, Clone110_mean, FUSClone110_mean)
## change position to factor and order it
combine_all$pos<- factor(combine_all$pos, levels= U2OS_mean$pos)
```
### 3.5.1 plot meta profile (without confidence interval)
```{r}
ggplot(combine_all, aes(x = pos,y = avg, group = factor)) + geom_line(aes(color = factor)) +
theme_bw(base_size = 14) +
theme(axis.ticks.x = element_blank()) +
scale_x_discrete(breaks = c("u1", "d10", "d500"), labels =c ("-500kb", "center", "500kb")) +
xlab("LRD") +
ylab("RT")+
ggtitle("RT signal in LRD")
```
### 3.5.2 plot meta profile (without confidence interval)
```{r}
ggplot(combine_all, aes(x = pos,y = avg, group = factor)) + geom_line(aes(color = factor)) +
geom_ribbon(aes(ymin= CI_lower, ymax=CI_upper), alpha=0.2, col = "#8B7E66") +
theme_bw(base_size = 14) +
theme(axis.ticks.x = element_blank()) +
scale_x_discrete(breaks = c("u1", "d10", "d500"), labels =c ("-500kb", "center", "500kb")) +
xlab("LRD") +
ylab("RT")+
ggtitle("RT signal in LRD")
```
```{r}
sessionInfo()
```