-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathadded_value.R
182 lines (122 loc) · 4.65 KB
/
added_value.R
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
# Copyright (c) [2019] [Ricardo O. Ramirez Flores]
#' In this script we test the differences in the predictions between the signature observed in our meta-analysis
#' and individual signatures from experiments
source("src/data_utils.R") #general functions
source("src/misc_utils.R")
METAheart = readRDS(file = "data/METAheart.rds") #main object
library(PLIER)
library(reshape2)
library(ROCR)
library(fgsea)
library(dplyr)
library(tidyr)
library(WriteXLS)
experiments = names(METAheart)
names(experiments) = experiments
# For labeling
t_matrix = get_all_limma(meta_list = METAheart,
limma_column = "t")
# Here we get AUC for pairwise classifiers
pairwise_500 = pairwise_ds(experiments = experiments,
meta_list = METAheart,
t_matrix = t_matrix,
ngenes = 500) #Second page excel
# Here we get the results from performing the meta-analysis
fisher_rank = run_fisher_meta(meta_list = METAheart,
n_missing = length(METAheart) - 10)
sum(fisher_rank < .00005)
genes = names(fisher_rank)
# Here we get the calculations of using the top N genes from the meta-analysis
ds_top = getRisk_Stats_v2(Experiment_List = METAheart,
limma_t_mat = t_matrix,
genes = names(fisher_rank[1:500]))
ds_top_predictions = enframe(lapply(ds_top, function(x) {
enframe(x[["SingleAUC"]])
})) %>% unnest()
colnames(ds_top_predictions) = c("PredictedExperiment",
"PredictorExperiment",
"meta_auc")
# Here we merge them
comp_df = left_join(pairwise_500,
ds_top_predictions) %>%
dplyr::filter(PredictedExperiment != PredictorExperiment) %>%
dplyr::select(PredictorExperiment,
PredictedExperiment,
single, meta_auc)
print("Are AUCs better?")
wilcox.test(comp_df$meta_auc,comp_df$single,paired = T,alternative = "greater")
comp_df = comp_df %>%
gather("type","AUROC",
-PredictorExperiment,
-PredictedExperiment)
saveRDS(comp_df, "data/figure_objects/added_value_ds.rds")
# Here we test the added value at consistency
study_deg_list_up = lapply(METAheart, function(x){
deg = dplyr::filter(x$HF_limma,
ID %in% names(fisher_rank[1:500])) %>%
filter(t >0)
return(deg[[1]])
})
study_deg_list_down = lapply(METAheart, function(x){
deg = dplyr::filter(x$HF_limma,
ID %in% names(fisher_rank[1:500])) %>%
filter(t < 0)
return(deg[[1]])
})
# upregulation
up_ES = lapply(experiments, function(x){
stat_rank = METAheart[[x]][["HF_limma"]][["t"]]
names(stat_rank) = METAheart[[x]][["HF_limma"]][["ID"]]
stat_rank = sort(stat_rank)
set.seed(1234)
up_row = as_tibble(fgsea(pathways = study_deg_list_up,
stats = stat_rank,nperm = 1000)) %>%
dplyr::select(pathway,ES)
})
up_ES = up_ES %>%
enframe("Reference") %>% unnest()
colnames(up_ES) = c("Reference","DEG","ES")
# downregulation
down_ES = lapply(experiments, function(x){
stat_rank = METAheart[[x]][["HF_limma"]][["t"]]
names(stat_rank) = METAheart[[x]][["HF_limma"]][["ID"]]
stat_rank = sort(stat_rank)
set.seed(1234)
up_row = as_tibble(fgsea(pathways = study_deg_list_down,
stats = stat_rank,nperm = 1000)) %>%
dplyr::select(pathway,ES)
})
down_ES = down_ES %>%
enframe("Reference") %>% unnest()
colnames(down_ES) = c("Reference","DEG","ES")
# Previous results
up_ES_single = readRDS(file = "data/figure_objects/up_ES.rds")
down_ES_single = readRDS(file = "data/figure_objects/down_ES.rds")
# Merge them
print("Is the ES better?")
comp_ES_up= left_join(up_ES_single,
up_ES, by = c("Reference","DEG")) %>%
dplyr::filter(Reference != DEG)
wilcox.test(comp_ES_up$ES.y,
comp_ES_up$ES.x,
paired = T,
alternative = "greater")
comp_ES_down = left_join(down_ES_single,
down_ES, by = c("Reference","DEG")) %>%
dplyr::filter(Reference != DEG)
wilcox.test(comp_ES_down$ES.y,
comp_ES_down$ES.x,
paired = T,
alternative = "less")
comp_ES = bind_rows("upregulated"=comp_ES_up,
"downregulated" =comp_ES_down,
.id = "comparison") %>%
mutate(single = ES.x,
meta_analysis = ES.y) %>%
dplyr::select(c("comparison","Reference","DEG",
"single","meta_analysis")) %>%
gather("type","ES",
-comparison,-Reference,
-DEG)
saveRDS(comp_ES, "data/figure_objects/added_value_es.rds")