-
Notifications
You must be signed in to change notification settings - Fork 0
/
weight_superblock.Rmd
executable file
·229 lines (193 loc) · 7.43 KB
/
weight_superblock.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
---
title: "Weight optimization with interaction and superblock"
author: "Lluís Revilla Sancho"
date: "`r date()`"
output:
html_document:
code_folding: show
toc: true
toc_float: true
editor_options:
chunk_output_type: console
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE, cache = TRUE, warning = FALSE, fig.width = 120, fig.height = 50, collapse = TRUE)
library("RGCCA")
library("gliomaData")
library("ggplot2")
library("patchwork")
library("integration")
theme_set(theme_bw())
```
# Introduction
In this vignette we explore the relationship between weights (and models) with the outcome of the integration using the glioma data available, with an interaction whitin the gene expression.
```{r introduction}
data(ge_cgh_locIGR, package = "gliomaData")
A <- ge_cgh_locIGR$multiblocks
Loc <-factor(ge_cgh_locIGR$y)
levels(Loc) <-colnames(ge_cgh_locIGR$multiblocks$y)
A[[3]] = A[[3]][, -3]
B = A
B[[3]] =Reduce("cbind", A[1:(length(A)-1)])
# superblock
B[[4]] = A[[3]]
names(B) <- c("GE", "CGH", "Superblock", "Loc")
# Prepare some preliminary design/weights
C <- matrix(0,ncol = 4, nrow = 4)
dimnames(C) <- list(names(B), names(B))
```
# Original
Here we mimic the original study only using centroid scheme instead
```{r}
nb_block = 4
#length(B)
D = matrix(0, nb_block, nb_block)
D[, nb_block - 1] = 1 ;
D[nb_block - 1, ] = 1 ;
diag(D) = 0
shrinkage <- c(.071,.2, 1/sqrt(NCOL(B[[3]])) + .2, 1)
sgcca.glioma = sgcca(B, D, c1 = shrinkage,
ncomp = c(rep(2, (length(B) - 1)),1),
scheme = "centroid", scale = TRUE,
verbose = FALSE)
saveRDS(sgcca.glioma, "superblock_sgcca.RDS")
glioma.superblock <- cbind.data.frame(sgcca.glioma$Y[[3]], Loc, Samples = rownames(sgcca.glioma$Y[[3]]))
glioma.GE <- cbind.data.frame(sgcca.glioma$Y[[1]], Loc, Samples = rownames(sgcca.glioma$Y[[3]]))
ggplot(glioma.superblock) +
geom_text(aes(comp1, comp2, col = Loc, label = Samples)) +
ggtitle("Original design", subtitle = "Superblock")
ggplot(glioma.GE) +
geom_text(aes(comp1, comp2, col = Loc, label = Samples)) +
ggtitle("Original design", subtitle = "GE")
sgcca.glioma$AVE$AVE_inner
```
We can see that it explains 70% of the variance
# Design
We create a design matrix of dimension 4 with 4 weights per position and the interaction
```{r}
nweights <- 4
weight <- seq(from = 0, to = 1, length.out = nweights)
C_list2 <- weight_design(nweights, 4)
C_list3 <- c(C_list2,
lapply(C_list2, function(x){x[1, 1] <- weight[2];x}),
lapply(C_list2, function(x){x[1, 1] <- weight[3];x}),
lapply(C_list2, function(x){x[1, 1] <- weight[4];x}))
keep <- check_design(C_list3)
C_list3 <- C_list3[keep]
```
We first define a function to test the designs (with the help of the integration package):
```{r}
keep <- vapply(C_list3, correct, logical(1L))
design <- C_list3[keep]
testing <- function(x, type) {
result.sgcca <- RGCCA::sgcca(B, x,
c1 = c(.071, .2, 1/sqrt(NCOL(B[[3]])) + .2, 1),
ncomp = c(1, 1, 1),
scheme = type, verbose = FALSE)
out <- analyze(result.sgcca)
c(out, "var11" = result.sgcca$C[1, 1])
}
```
# Testing
Using the centroid scheme
```{r centroid}
out <- sapply(design, testing, type = "centroid", USE.NAMES = FALSE)
out2 <- t(out)
def <- as.data.frame(out2)
def$weights <- as.factor(def$weights)
offset <- is.na(def$AVE_inner)
def <- droplevels(def[!offset, ])
saveRDS(def, file = "superblock_interactions.RDS")
```
And we can see the stability for each type of model
```{r}
library("dplyr")
def %>%
group_by(weights) %>% add_count() %>%
dplyr::filter(AVE_inner == max(AVE_inner)) %>%
arrange(desc(AVE_inner), as.numeric(weights)) %>%
select(-matches("vs"))
```
We can plot them
```{r plot_centroid}
p <- ggplot(def)
r1 <- p + geom_point(aes(cc1, AVE_inner, col = weights)) + guides(col = FALSE)
r2 <- p + geom_point(aes(cc1, AVE_outer, col = weights)) + guides(col = FALSE)
r3 <- p + geom_count(aes(AVE_inner, AVE_outer, col = weights))
q1 <- p + geom_point(aes(var1, AVE_outer, col = weights)) + guides(col = FALSE) +
geom_smooth(aes(var2, AVE_outer, col = weights))
q2 <- p + geom_point(aes(var2, AVE_outer, col = weights)) + ylab("") + guides(col = FALSE) +
geom_smooth(aes(var2, AVE_outer, col = weights))
q3 <- p + geom_point(aes(var3, AVE_outer, col = weights)) + ylab("") + guides(col = FALSE) +
geom_smooth(aes(var3, AVE_outer, col = weights))
s1 <- p + geom_point(aes(var1, AVE_inner, col = weights)) + guides(col = FALSE) +
geom_smooth(aes(var1, AVE_inner, col = weights))
s2 <- p + geom_point(aes(var2, AVE_inner, col = weights)) + ylab("") + guides(col = FALSE) +
geom_smooth(aes(var2, AVE_inner, col = weights))
s3 <- p + geom_point(aes(var3, AVE_inner, col = weights)) + ylab("") + guides(col = FALSE) +
geom_smooth(aes(var3, AVE_inner, col = weights))
(r1 + r2 + r3) / (q1 + q2 + q3) / (s1 + s2 + s3)
```
# Final model
We select the best model
```{r}
nb_block = 4
#length(B)
D_best = matrix(0, nb_block, nb_block)
columns <- grep("var", colnames(def))
D_best <- symm(D_best, def[which.max(def$AVE_inner), columns])
dimnames(D_best) <- list(names(B), names(B))
sgcca.final <- sgcca(B, D_best, c1 = shrinkage,
ncomp = c(rep(2, (length(B) - 1)),1),
scheme = "centroid", scale = TRUE,
verbose = FALSE)
saveRDS(sgcca.final, "superblock_best.RDS")
levels(Loc) <- c("hemisphere", "DIPG", "midline")
final.superblock <- cbind.data.frame(sgcca.final$Y[[3]], Loc, Samples = rownames(sgcca.final$Y[[3]]))
final.GE <- cbind.data.frame(sgcca.final$Y[[1]], Loc, Samples = rownames(sgcca.final$Y[[3]]))
ggplot(final.superblock) +
geom_text(aes(comp1, comp2, col = Loc, label = Samples)) +
ggtitle("Final design", subtitle = "Superblock") +
scale_color_viridis_d() +
guides(col = guide_legend(title = "Localization"))
ggplot(final.GE) +
geom_text(aes(comp1, comp2, col = Loc, label = Samples)) +
ggtitle("Final design", subtitle = "GE") +
scale_color_viridis_d() +
guides(col = guide_legend(title = "Localization"))
```
```{r}
l <- looIndex(size(B))
loo_model <- function(x, model){
RGCCA::sgcca(A = subsetData(B, x),
C = model,
scheme = "centroid",
verbose = FALSE, c1 = shrinkage
)
}
result.out <- lapply(l, loo_model, model = D)
saveRDS(result.out, "loo-superblock.RDS")
result.out <- lapply(l, loo_model, model = D_best)
saveRDS(result.out, "loo-superblock_best.RDS")
boot <- boot_sgcca(B, D, shrinkage, 1000)
saveRDS(boot, file = "bootstrap_superblock.RDS")
# boot_evaluate(boot$STAB) # Plot some models
boot <- boot_sgcca(B, D_best, shrinkage, 1000)
saveRDS(boot, file = "bootstrap_superblock_best.RDS")
# boot_evaluate(boot$STAB)
```
## Conclusions
In general using only two weights leads to select models that account for more
variance while, even if we can't see in here, the model having only 2 variables
depends more on the weights regardless which scheme we use.
The weights that report more inner AVE are consistent for each scheme.
The distinction seems to be between adding a slighly relationship between CGH
and GE or not. [CGE](https://en.wikipedia.org/wiki/Comparative_genomic_hybridization)
allows to find copy number variations, which might affect the gene expression,
thus is reasonable to include in a model the interaction between copy number
variation and gene expression, as well as it is unexpected that it might play a .
huge role But we can see that its role is not neglibile
## Session Info {-}
```{r session, echo=FALSE}
devtools::session_info()
```