-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreffree_figures.Rmd
334 lines (253 loc) · 15.9 KB
/
reffree_figures.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
---
title: "Reference Free Cell Correction Comparison in Cord Blood"
author: "Meg Jones and Rachel Edgar"
date: "22/11/2017"
output: pdf_document
header-includes: \usepackage{float}
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r global_options, include=FALSE}
library(knitr)
knitr::opts_chunk$set(fig.pos = '!h')
```
```{r, include=FALSE, message=FALSE}
## Define consistent color scheme for methods
library(ggsci)
library(ggplot2)
library(ggridges)
library(knitr)
library(kableExtra)
library(dplyr)
library(reshape2)
## method colors
myColors <- c("gold","goldenrod",
"#2171b5","#6baed6","#6baed6",
"#9467BDFF","#D62728FF",
"#238443","#78c679","#addd8e","#d9f0a3",
"#dd3497","#fa9fb5","grey")
color_possibilities<-c("FACS - PCA - Gold-Standard","FACS - Drop One Cell Type",
"Deconvolution - PCA","Deconvolution - Drop One Cell Type","Deconvolution - Counts",
"ReFACTor","RefFreeCellMix",
"SVA - Supervised GA","SVA - Unsupervised GA",
"SVA - Supervised Sex","SVA - Unsupervised Sex",
"RUV - GA", "RUV - Sex",
"Uncorrected")
names(myColors) <- color_possibilities
fillscale <- scale_fill_manual(name="Method",
values = myColors, drop = T)
### Cell type colors
myColors_cell <- c("#fc4e2a","orange", "#cb181d","#1d91c0", "#7fcdbb", "#78c679","#238443")
color_possibilities_cell<-c("Monocytes","Granulocytes", "nRBCs","NK Cells", "B Cells", "CD4 T Cells","CD8 T Cells")
names(myColors_cell) <- color_possibilities_cell
fillscale_cell <- scale_fill_manual(name="Cell Type",
values = myColors_cell, drop = T)
### nice theme
th <- theme(axis.text=element_text(size=12),
axis.title=element_text(size=14),
strip.text.x = element_text(size = 12),
legend.text=element_text(size=12),
legend.title=element_text(size=14))
```
\newpage
```{r, echo=FALSE, message=FALSE}
## load meta data
meta_cord<-read.csv("/big_data/redgar/cordblood/24_wholebloods_samplesheet.csv")
meta_celltypes<-meta_cord[,c(12,13,5:11)]
female<-paste(round((length(which(meta_cord$Sex=="F"))/24)*100, 2),"%", sep="")
GA<-round(mean(meta_cord$GA), 2)
meta_celltypes<-meta_cord[,c(5:11)]
mean_celltypes<-t(as.data.frame(round(colMeans(meta_celltypes),2)))
sd_celltypes<-t(as.data.frame(round(apply(meta_celltypes,2, sd),2)))
mean_celltypes<-t(as.data.frame(paste(mean_celltypes,"% (",sd_celltypes,")", sep="")))
lab<-data.frame(celltype="Mean % (sd)")
meta_summary<-t(data.frame(Female=female,Mean_GA=GA,lab, mean_celltypes ))
rownames(meta_summary)<-c("Female","Mean Gestational Age","FACS Cell Composition","Monocytes","Granulocytes", "nRBCs","NK Cells", "B Cells", "CD4 T Cells","CD8 T Cells")
meta_summary<-as.data.frame(meta_summary)
meta_summary$genR<-""
colnames(meta_summary)<-c("UBC data (n=24)", "GenR (n=196)")
kable(meta_summary, format="latex", booktabs = T, caption = "Cohort Description")%>%
kable_styling(font_size = 12,(latex_options = c("HOLD_position")))%>%
row_spec(3, bold = T)%>%
add_indent(c(4:10))
```
## What point are we trying to make?
In cord blood we now have a reference based deconvolution method (**yay!**)
But in most other tissues we do not.
We can use the cord blood gold-standard correction to benchmark reference free methods to recommend a solution for tissues with no reference.
###How will we benchmark?
* Which method gives components which are most similar to FACS cell counts?
* Which method produces corrected betas most like the gold-standard corrected betas?
* Which method’s corrected betas are the most cell composition normalized (least variability in cell composition after correction)
* EWAS sensitivity specificity to gold-standard EWAS hits, and enrichment for cell type CpGs in EWAS hits.
\newpage
```{r, echo=FALSE, message=FALSE}
methods_table<-read.csv("methods_table.csv")
colnames(methods_table)<-c("Method","Explanation","Type","Phenotype Required","Citation" )
kable(methods_table, format="latex", booktabs = T, caption = "Method name used in comparison, explanation of method, whether it is reference free, reference based or semi reference free, whether the method models with a given phenotype for EWAS, and the relevant citation for the method.")%>%
kable_styling(font_size = 7,(latex_options = c("HOLD_position")))%>%
column_spec(column=2, width = "10em")
```
\pagebreak
\newpage
```{r R21, fig.width=8, fig.height=5, echo=FALSE, message=FALSE,fig.cap='Variance explained in each FACS cell count by models using components from several cell type estimation methods. Models were fit used a nested-models likelihood ratio test. Components from each method were included if they significantly (p<0.05) improved model fit.'}
load("~/referencefree_cord_blood/R2_plot.RData")
levels(plt_r2$facs_celltype)<-c("Monocytes","Granulocytes", "nRBCs","NK Cells", "B Cells", "CD4 T Cells","CD8 T Cells")
ggplot(plt_r2, aes(facs_celltype, R2_LRT, fill=method))+geom_point(shape=21, color="black", size=2, position=position_jitter(width=0.2))+theme_bw()+
fillscale+
ylab("R2 (FACS Cell Type Variance Accounted for)")+xlab("FACS Cell Type")+th+
theme(axis.text.x = element_text(size=12,angle = 45, hjust = 1))
ggsave("figures/Figure1R2.pdf", width = 9, height = 5, units = "in")
```
\newpage
```{r R22, fig.width=8, fig.height=7, echo=FALSE, message=FALSE,fig.cap='Variance explained in each FACS cell count by models using components from several cell type estimation methods. Models were fit used a nested-models likelihood ratio test. Models include components from each method if the component had significant likelihood ratio test p value (p<0.05). Expect for deconvolution - counts which gives measure of each cell type and R2 values are only for models with the deconvolution predicted cell type. Points represent each of 7 cell types, split by the method.'}
## mean boxplot
ggplot(plt_r2, aes(reorder(method, R2_LRT, FUN=median), R2_LRT))+geom_boxplot(outlier.size=NA, fill="grey95")+
geom_point(aes(fill=facs_celltype),shape=21, color="black", size=2.25, position=position_jitter(width=0.2))+theme_bw()+
ylab("R2 (FACS Cell Type Variance Accounted for)")+fillscale_cell+xlab("")+th+
theme(axis.text.x = element_text(size=12,color="black",angle = 90, hjust = 1))
ggsave("figures/Figure2R2.pdf", width = 8, height = 7, units = "in")
```
```{r}
load("~/referencefree_cord_blood/R2_inverse_plot.RData" )
ggplot(R2_inverse_all, aes(Method, R2_inverse, fill=Method))+geom_boxplot(outlier.size=NA, fill="grey95")+
geom_point(shape=21, color="black", size=2, position=position_jitter(width=0.2))+theme_bw()+
fillscale+
ylab("R2 (Component Variance not Accounted for)")+xlab("")+th+
theme(axis.text.x = element_text(size=12,angle = 45, hjust = 1))
ggsave("figures/Figure3R2.pdf", width = 8, height = 7, units = "in")
```
\newpage
```{r mae, fig.width=13, fig.height=11, echo=FALSE, message=FALSE,fig.cap='Mean absolute error(MAE) of CpGs compared to the gold-standard FACS-PCA corrected beta values. Errors shown are an average of all CpGs MAE. Boxes are coloured by the discretized MAE value to highlight method performance.'}
load("~/referencefree_cord_blood/error_all.RData")
error_all_unique<-error_all[!duplicated(error_all$mn_cpg_mae),]
error_all_unique<-error_all_unique[-1,]
error_all_unique$col_error<-cut(error_all_unique$mn_cpg_mae, c(0,0.001, 0.005,0.0075,0.01), right=FALSE, labels=c("<0.001","<0.005","<0.0075",">0.0075"))
ggplot(error_all_unique, aes(method_1,method_2, fill = col_error)) +
geom_tile(color = "black",size=0.5) +
geom_text(aes(label = round(mn_cpg_mae,3)), color="black", size=5)+theme_bw()+
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
panel.background = element_blank(), axis.line = element_blank())+
scale_fill_manual(values=c("#084594","#4292c6","#9ecae1","#deebf7"), name="MAE")+th+
theme(axis.text.y=element_text(size=12,color="black"),
axis.text.x = element_text(size=12,color="black",angle = 90, hjust = 1),
panel.border = element_blank(),
axis.ticks=element_blank())+xlab("")+ylab("")
ggsave("figures/maehalf.pdf", width = 13, height = 11, units = "in")
```
\newpage
```{r correlation, fig.width=12, fig.height=10, echo=FALSE, message=FALSE, fig.cap='Distributions of correlation of beta values across samples at each CpG. Betas across samples were correlated between each method and the gold-standard FACS-PCA corrected betas. Vertical blue line shows the median correlation across all CpGs for the Deconvolution PCA corrected betas.'}
load("~/referencefree_cord_blood/correlation_distributions.RData")
decon_med_cor<-median(cor_to_GS$correlation[which(cor_to_GS$method=="Deconvolution - PCA")])
ggplot(cor_to_GS, aes(x = correlation, y = reorder(method, correlation, FUN=median), fill=method)) +
geom_density_ridges(scale = 4) + theme_ridges() +
fillscale +xlab("CpG Correlation to Gold Standard Betas")+ylab("")+th+
geom_vline(xintercept=decon_med_cor, color="#2171b5", size=0.75)
ggsave("figures/Figure3cor.pdf", width = 12, height = 10, units = "in")
```
\newpage
```{r deconvolutioncounts, fig.width=9, fig.height=11, echo=FALSE, message=FALSE, fig.cap='Varibility in the predicted cell counts on data already corrected for cell type. Across methods the deconvolution predicted cell counts for each cell type are shown. '}
load("/big_data/reffree/adj.residuals.sva.unsup.sex_predicted_cell_types.Rdata")
sva.unsup.sex<- est_cell_counts
load("/big_data/reffree/adj.residuals.sva.unsup.ga_predicted_cell_types.Rdata")
sva.unsup.ga<- est_cell_counts
load("/big_data/reffree/adj.residuals.sva.sup.sex_predicted_cell_types.Rdata")
sva.sup.sex<- est_cell_counts
load("/big_data/reffree/adj.residuals.sva.sup.ga_predicted_cell_types.Rdata")
sva.sup.ga<- est_cell_counts
load("/big_data/reffree/adj.residuals.ruv.sex_predicted_cell_types.Rdata")
ruv.sex<- est_cell_counts
load("/big_data/reffree/adj.residuals.ruv.ga_predicted_cell_types.Rdata")
ruv.ga<- est_cell_counts
load("/big_data/reffree/adj.residuals.reffreecellmix_predicted_cell_types.Rdata")
cellmix<- est_cell_counts
load("/big_data/reffree/adj.residuals.refactor_predicted_cell_types.Rdata")
refactor<- est_cell_counts
load("/big_data/reffree/facs_predicted_cell_types.Rdata")
facs.counts<- est_cell_counts
load("/big_data/reffree/facs_pcs_predicted_cell_types.Rdata")
facs.pcs.counts<- est_cell_counts
load("/big_data/reffree/decon_predicted_cell_types.Rdata")
decon.counts<- est_cell_counts
load("/big_data/reffree/decon_pcs_predicted_cell_types.Rdata")
decon.pcs.counts<- est_cell_counts
load("/big_data/reffree/Louie_predicted_WB_celltypes_Oct27_use_Louies_sorted.rdata")
uncorrected<- est_cell_counts
plot.counts<- melt(rbind(cbind(as.data.frame(uncorrected), Method="uncorrected"),
cbind(as.data.frame(facs.counts), Method="FACS_counts"),
cbind(as.data.frame(facs.pcs.counts), Method="FACS_PCs"),
cbind(as.data.frame(decon.counts), Method="Decon_counts"),
cbind(as.data.frame(decon.pcs.counts), Method="Decon_PCs"),
cbind(as.data.frame(sva.unsup.sex), Method="sva.unsup.sex"),
cbind(as.data.frame(sva.unsup.ga), Method="sva.unsup.ga"),
cbind(as.data.frame(sva.sup.ga), Method="sva.sup.ga"),
cbind(as.data.frame(sva.sup.sex), Method="sva.sup.sex"),
cbind(as.data.frame(ruv.sex), Method="ruv.sex"),
cbind(as.data.frame(ruv.ga), Method="ruv.ga"),
cbind(as.data.frame(cellmix), Method="cellmix"),
cbind(as.data.frame(refactor), Method="refactor")
), id="Method")
levels(plot.counts$Method)<-c("Uncorrected","FACS - Drop One Cell Type","FACS - PCA - Gold-Standard",
"Deconvolution - Drop One Cell Type","Deconvolution - PCA","SVA - Unsupervised Sex",
"SVA - Unsupervised GA","SVA - Supervised GA","SVA - Supervised Sex",
"RUV - Sex","RUV - GA", "RefFreeCellMix", "ReFACTor")
ggplot(plot.counts, aes(Method, value, fill=Method))+
geom_point(shape=21, color="black", position = position_jitter(width = 0.1))+
facet_wrap(~variable, ncol=2)+
theme_bw()+
fillscale+xlab("")+ylab("Predicted Cell Count from Deconvolution")+th+
theme(axis.text.y=element_text(size=12,color="black"),
axis.text.x = element_blank(),
axis.ticks.x = element_blank())
ggsave("figures/Figure4decon.pdf", width = 9, height = 11, units = "in")
```
\newpage
```{r deconvolutionmad, fig.width=12, fig.height=10, echo=FALSE, message=FALSE, fig.cap='Median absolute deviation (MAD) of predicted cell type counts from deconvolution. Boxes are coloured by the discretized MAD value to highlight method performance. '}
mads<- data.frame(FACS_counts=apply(facs.counts, 2, mad),
FACS_pcs=apply(facs.pcs.counts, 2, mad),
Decon_counts=apply(decon.counts, 2, mad),
Decon_pcs=apply(decon.pcs.counts, 2, mad),
sva.unsup.sex= apply(sva.unsup.sex, 2, mad),
sva.unsup.ga= apply(sva.unsup.ga, 2, mad),
sva.sup.sex= apply(sva.sup.sex, 2, mad),
sva.sup.ga= apply(sva.sup.ga, 2, mad),
ruv.sex= apply(ruv.sex, 2, mad),
ruv.ga= apply(ruv.ga, 2, mad),
cellmix= apply(cellmix, 2, mad),
refactor=apply(refactor, 2, mad),
uncorrected=apply(uncorrected, 2, mad)
)
mads$celltypes<- rownames(mads)
mads.melt<- melt(mads, id="celltypes")
mads.melt$col_mad<-cut(mads.melt$value, c(0,0.005, 0.01,0.05,0.1), right=FALSE, labels=c("<0.005","<0.01","<0.05",">0.05"))
levels(mads.melt$variable)<-c("FACS - Drop One Cell Type","FACS - PCA - Gold-Standard",
"Deconvolution - Drop One Cell Type","Deconvolution - PCA","SVA - Unsupervised Sex",
"SVA - Unsupervised GA","SVA - Supervised Sex","SVA - Supervised GA",
"RUV - Sex","RUV - GA", "RefFreeCellMix", "ReFACTor","Uncorrected")
ggplot(mads.melt, aes(celltypes, variable, fill=col_mad))+
geom_tile(color = "black",size=0.5)+
geom_text(aes(label = round(value, 3)), size=5) +
theme_bw()+
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
panel.background = element_blank(), axis.line = element_blank())+
scale_fill_manual(values=c("#084594","#4292c6","#9ecae1","#deebf7"), name="Cell Count MAD")+th+
theme(axis.text.y=element_text(size=12,color="black"),
axis.text.x = element_text(size=12,color="black",angle = 90, hjust = 1),
panel.border = element_blank(),
axis.ticks=element_blank())+xlab("")+ylab("")
ggsave("figures/Figure5decon.pdf", width = 12, height = 10, units = "in")
```
\newpage
```{r, echo=FALSE, message=FALSE}
sex_table<-read.csv("Sex_EWAS_hit_tables.csv")
colnames(sex_table)<-c("Method","Hits","True Positives","False Positives","False Negatives","Spearman","Kendall" )
levels(sex_table$Method)<-c("Deconvolution - PCA","Deconvolution - Drop One Cell Type",
"FACS - PCA - Gold-Standard","FACS - Drop One Cell Type",
"ReFACTor","RefFreeCellMix","RUV","SVA - Supervised","SVA - Unsupervised","Uncorrected")
sex_table$Spearman<-round(sex_table$Spearman, 3)
sex_table$Kendall<-round(sex_table$Kendall, 3)
sex_table[1,3:7]<-"-"
kable(sex_table, format="latex", booktabs = T, caption = "Comparison of cell type correction methods through EWAS results. EWAS was performed for sex on each corrected dataset. True and false positives and negatives were cvalculated in comparison to the gold-standard FACS - PCA correction. Spearman is the correlation coefficient for all CpG p values, and Kendall is the rank correlation coefficient for the top 1000 CpG p values.")%>%
kable_styling(font_size = 7,(latex_options = c("HOLD_position")))
```