-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathLCC_CV_test.R
executable file
·224 lines (148 loc) · 5.71 KB
/
LCC_CV_test.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
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
#### Multiplex RWR for all the Orphanet: using k-fold cross validation
## Ize Buphamalai
## 16 Apr 2020
## This uses the LCC computation from all genes
source("../functions/readdata_functions.R")
source("../functions/LCC_functions.R")
source("../functions/process_edgelist.R")
source("../functions/process_LCC_result.R")
source("../functions/weighted_multiplex_propagation.R")
source("../functions/RWR_get_allnodes.R")
source("../functions/RWR_transitional_matrix.R")
source("../functions//RWR.R")
library(igraph)
## load the LCC results
result_folder = "../cache/output/Orphageneset_rare/"
result_df = readRDS(paste0(result_folder, "LCC_and_distance_calculation_results.RDS"))
## from LCC_analysis_new: process the LCC
result_df = process_LCC_result(result_df)
### extract the most significant networks for all diseases
all_LCC_val_signif = result_df %>% dplyr::filter(correctedPval < 0.05) %>% dplyr::select(name, network, LCC.zscore)
## load the gene sets
Orphanet_df = process_disease_genes_data("../data/table_disease_gene_assoc_orphanet_genetic.tsv", min_gene = 20, max_gene = 2000)
Orphanet_df = Orphanet_df$disgene_list
## read all edgelists for all significant networks
network_dirs = "../data/network_edgelists/"
all_networks = all_LCC_val_signif %>% pull(network) %>% unique
el_all = list()
for(i in all_networks){
el_all[[i]] = read_tsv(paste0(network_dirs, i,".tsv"), col_names = c("A","B"), skip = 1)
}
el_all = lapply(el_all, process_edgelist)
## train and test sets
all_diseases = names(Orphanet_df)
## Ranking for significant networks
## to store ranking results
rank_df_all_folds = list()
for(disease_current in all_diseases){
print(disease_current)
# set seed
disease_genes = Orphanet_df[[disease_current]]
n = length(disease_genes)
LCC_val_signif = all_LCC_val_signif %>% dplyr::filter(name == disease_current) %>% select(network, LCC.zscore)
print(sprintf("Number of network taken into account is %i", nrow(LCC_val_signif)))
el = el_all[LCC_val_signif$network]
gene_allnet = get_allnodes(el)
supraadj = supraadjacency_compute(LCC_val_signif, el = el)
## shuffle data
seed = 144
disease_genes = disease_genes[sample(n)]
## k-fold validation: k = 10
k=10
# subsets the disease genes for seed and retrieval sets
set_labels = cut(1:n, breaks = k, labels = 1:k)
# each retrievat sets controlled by parameter i, i = 1:k
rank_df = list()
for(i in 1:k){
seed_sets = disease_genes[set_labels!=i]
retrieval_sets = disease_genes[set_labels==i]
## perform retrieval
rank_df[[i]] = weighted_multiplex_propagation(
seedset = seed_sets,
trueset = disease_genes,
weighted_layer_df = LCC_val_signif,
network_dirs = network_dirs,
el = el,
gene_allnet = gene_allnet,
Stest = supraadj)
}
rank_df_all_folds[[disease_current]] = rank_df
}
#})
saveRDS(rank_df_all_folds, "../cache/LCC_CV_ranking_rare_genetic_diseases_no_LCC_recompute.RDS")
##############
# prepare edge list, and supra-adjacency matrix (PPI alone)
LCC_val_signif = tibble(network = "ppi", LCC.zscore = 1) # just to add PPI
el = el_all[LCC_val_signif$network]
gene_allnet = get_allnodes(el)
supraadj = supraadjacency_compute(LCC_val_signif, el = el)
rank_df_all_folds_only_PPI = list()
for(disease_current in all_diseases){
print(disease_current)
# set seed
disease_genes = Orphanet_df[[disease_current]]
n = length(disease_genes)
## shuffle data
seed = 144
# assign groups to disease genes
disease_genes = disease_genes[sample(n)]
## k-fold validation: k = 10
k=10
# subsets the disease genes for seed and retrieval sets
set_labels = cut(1:n, breaks = k, labels = 1:k)
# each retrievat sets controlled by parameter i, i = 1:k
rank_df = list()
for(i in 1:k){
seed_sets = disease_genes[set_labels!=i]
retrieval_sets = disease_genes[set_labels==i]
## perform retrieval
rank_df[[i]] = weighted_multiplex_propagation(
seedset = seed_sets,
trueset = disease_genes,
weighted_layer_df = LCC_val_signif,
network_dirs = network_dirs,
el = el,
gene_allnet = gene_allnet,
Stest = supraadj)
}
rank_df_all_folds_only_PPI[[disease_current]] = rank_df
}
saveRDS(rank_df_all_folds_only_PPI, "../cache/LCC_CV_ranking_rare_genetic_diseases_only_PPI.RDS")
##############
# prepare edge list, and supra-adjacency matrix (all networks)
LCC_val_signif = tibble(network = unique(result_df$network), LCC.zscore = 1) # just to add PPI
el = el_all[LCC_val_signif$network]
gene_allnet = get_allnodes(el)
supraadj = supraadjacency_compute(LCC_val_signif, el = el)
rank_df_all_folds_allnets = list()
for(disease_current in all_diseases){
print(disease_current)
# set seed
disease_genes = Orphanet_df[[disease_current]]
n = length(disease_genes)
## shuffle data
seed = 144
# assign groups to disease genes
disease_genes = disease_genes[sample(n)]
## k-fold validation: k = 10
k=10
# subsets the disease genes for seed and retrieval sets
set_labels = cut(1:n, breaks = k, labels = 1:k)
# each retrievat sets controlled by parameter i, i = 1:k
rank_df = list()
for(i in 1:k){
seed_sets = disease_genes[set_labels!=i]
retrieval_sets = disease_genes[set_labels==i]
## perform retrieval
rank_df[[i]] = weighted_multiplex_propagation(
seedset = seed_sets,
trueset = disease_genes,
weighted_layer_df = LCC_val_signif,
network_dirs = network_dirs,
el = el,
gene_allnet = gene_allnet,
Stest = supraadj)
}
rank_df_all_folds_allnets[[disease_current]] = rank_df
}
saveRDS(rank_df_all_folds_allnets, "../cache/LCC_CV_ranking_rare_genetic_diseases_allnets.RDS")