-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.R
executable file
·377 lines (316 loc) · 18.5 KB
/
server.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
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
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
library(shiny)
library(ggplot2)
library(grid)
library(plyr)
library(dplyr)
library(magrittr)
load('ls_risk_data.rda')
load('ls_risk_data_subsequent.rda')
load('ls_organ.rda')
load('ls_organ_precomputed.rda')
shinyServer(function(input, output, session){
values <- reactiveValues()
observe({
values$lastLinkValue <- input$seeAbout[1] - 1
if (input$seeAbout[1] != values$lastLinkValue && values$lastLinkValue >= 0){
updateTabsetPanel(session, "mainNavbar", selected = "About")
}
})
output$UI.Date <- renderText({
Commentary.Date <- paste0("<p style=\"font-size:80%\"><i>Last data update: December 3rd 2015</i></p>")
return(Commentary.Date)
})
#output$Sex <- renderPrint({ input$Sex })
output$ctype <- renderPrint({ input$ctype })
output$Age <- renderPrint({ input$Age })
output$Age3 <- renderPrint({ input$Age3 })
output$Sex3 <- renderPrint({ input$Sex3 })
output$Sex4 <- renderPrint({ input$Sex4 })
output$ctype3 <- renderPrint({ input$ctype3 })
#output$text1 <- renderText({
#paste('<div style=\"position:relative; left:0em\">Calculated cumulative risk for first cancer for',tolower(input$Sex),'carrier of <i>',paste0('path_',input$genecarrier), '</i> with a current age of',input$Age, ':</div>')
#})
output$plot_incidence_gene <- renderPlot({
df <- dplyr::filter(all_cum_ind, Cancer == input$ctype & Sex == input$Sex & Age >= input$Age & Gene == input$genecarrier)
if(nrow(df) > 1){
df$tmp <- rep(1,nrow(df))
for (i in 2:nrow(df)) {
df$tmp[i] <- df$tmp[i - 1] - (df$tmp[i - 1] * df$Annual_incidence_rate[i - 1])
}
df$cum_risk_percent_dynamic <- (1 - df$tmp) * 100
}
else{
df$cum_risk_percent_dynamic <- df$Annual_incidence_rate * 100
}
df$SEXGENE <- paste(df$Sex,df$Gene, sep=" - ")
#cancer_type <- 'Any cancer type'
cancer_type <- paste('Any cancer type',tolower(input$Sex),sep = ' - ')
if(input$ctype == 'CRC'){
cancer_type <- paste('Colorectal cancer',tolower(input$Sex),sep = ' - ')
}
if(input$ctype == 'OVARIAN'){
cancer_type <- paste('Ovarian cancer',tolower(input$Sex),sep = ' - ')
}
if(input$ctype == 'UGI'){
cancer_type <- paste('Gastric/small intestine/biliary tract/pancreas cancer',tolower(input$Sex),sep = ' - ')
}
if(input$ctype == 'URO'){
cancer_type <- paste('Urine bladder/kidney/ureter cancer',tolower(input$Sex),sep = ' - ')
}
if(input$ctype == 'END'){
cancer_type <- paste('Endometrial cancer',tolower(input$Sex),sep = ' - ')
}
pathogenic_variant <- paste0('path_',input$genecarrier)
p <- ggplot(df, aes(x=Age,y=cum_risk_percent_dynamic,group=SEXGENE,colour=SEXGENE)) +
geom_line(size=1) + geom_point(size=3) +
theme_bw() +
ggtitle(bquote(atop(bold(.(cancer_type)), italic(.(pathogenic_variant))))) +
scale_x_continuous(breaks=seq(25,70,5),limits=c(25,70)) +
scale_y_continuous(breaks=seq(0,100,10),limits=c(0,100)) +
scale_color_brewer(palette='Dark2') +
theme(legend.title = element_blank(),
legend.position = "none",
panel.grid.major = element_line(colour = 'black', size = 0.3, linetype = 'dashed'),
panel.border = element_rect(size=1, colour = "black"),
axis.text.x=element_text(family="Helvetica",size=14),
axis.title.x=element_text(family="Helvetica",size=14,vjust=-0.5),
axis.text.y=element_text(family="Helvetica",size=14),
axis.title.y=element_text(family="Helvetica",size=14,vjust=1.5),
plot.margin = (unit(c(2, 0, 2, 2), "cm")),
plot.title = element_text(family="Helvetica",size=14,vjust=2,hjust=0.5),
legend.text = element_blank()) +
#legend.text=element_text(family="Helvetica",size=14)) +
ylab('Cumulative risk of first cancer (%)')
print(p)
}, height="auto",width="auto")
output$plot_incidence_gene_organ_cancer <- renderPlot({
# df <- NULL
# if(input$ctype3 == '182' || input$ctype3 == '174' || input$ctype3 == '183' || input$ctype3 == '182_183'){
# df <- dplyr::filter(organ_table, Cancer == input$ctype3 & Age >= input$Age3 & Gene == input$genecarrier3 & Sex == input$Sex3)
# }
# if(input$ctype3 == '153' || input$ctype3 == '154'){
# df <- dplyr::filter(organ_table, Cancer == input$ctype3 & Age >= input$Age3 & Gene == input$genecarrier3 & Sex == input$Sex5)
# }
# if(input$ctype3 == '185'){
# df <- dplyr::filter(organ_table, Cancer == input$ctype3 & Age >= input$Age3 & Gene == input$genecarrier3 & Sex == input$Sex4)
# }
# if(input$ctype3 == 'PANCANCER' || input$ctype3 == '151' || input$ctype3 == '152' || input$ctype3 == '156' || input$ctype3 == '157' || input$ctype3 == '188' || input$ctype3 == '189' || input$ctype3 == '191' || input$ctype3 == '151_152_156_157' || input$ctype3 == '188_189' || input$ctype3 == '153_154'){
# df <- dplyr::filter(organ_table, Cancer == input$ctype3 & Age >= input$Age3 & Gene == input$genecarrier3 & Sex == input$Sex6)
# }
# if(nrow(df) > 1){
# df$tmp <- rep(1,nrow(df))
# for (i in 2:nrow(df)) {
# df$tmp[i] <- df$tmp[i - 1] - (df$tmp[i - 1] * df$Annual_incidence_rate[i - 1])
# }
# df$cum_risk_percent_dynamic <- (1 - df$tmp) * 100
# }
# else{
# df$cum_risk_percent_dynamic <- df$Annual_incidence_rate * 100
# }
df <- NULL
if(input$ctype3 == '182' || input$ctype3 == '174' || input$ctype3 == '183' || input$ctype3 == '182_183'){
#df <- dplyr::filter(organ_table, Cancer == input$ctype3 & Age >= input$Age3 & Gene == input$genecarrier3 & Sex == input$Sex3)
df <- dplyr::filter(ls_organ_precomputed, Cancer == input$ctype3 & Age_start == input$Age3 & Gene == input$genecarrier3 & Sex == input$Sex3)
}
if(input$ctype3 == '153' || input$ctype3 == '154'){
#df <- dplyr::filter(organ_table, Cancer == input$ctype3 & Age >= input$Age3 & Gene == input$genecarrier3 & Sex == input$Sex5)
df <- dplyr::filter(ls_organ_precomputed, Cancer == input$ctype3 & Age_start == input$Age3 & Gene == input$genecarrier3 & Sex == input$Sex5)
}
if(input$ctype3 == '185'){
#df <- dplyr::filter(organ_table, Cancer == input$ctype3 & Age >= input$Age3 & Gene == input$genecarrier3 & Sex == input$Sex4)
df <- dplyr::filter(ls_organ_precomputed, Cancer == input$ctype3 & Age_start == input$Age3 & Gene == input$genecarrier3 & Sex == input$Sex4)
}
if(input$ctype3 == 'PANCANCER' || input$ctype3 == '151' || input$ctype3 == '152' || input$ctype3 == '156' || input$ctype3 == '157' || input$ctype3 == '188' || input$ctype3 == '189' || input$ctype3 == '191' || input$ctype3 == '151_152_156_157' || input$ctype3 == '188_189' || input$ctype3 == '153_154'){
#df <- dplyr::filter(organ_table, Cancer == input$ctype3 & Age >= input$Age3 & Gene == input$genecarrier3 & Sex == input$Sex6)
df <- dplyr::filter(ls_organ_precomputed, Cancer == input$ctype3 & Age_start == input$Age3 & Gene == input$genecarrier3 & Sex == input$Sex6)
}
df$SEXGENE <- paste(df$Sex,df$Gene, sep=" - ")
df$Age <- as.integer(df$Age_stop)
df$Age <- as.integer(df$Age)
r <- df[df$Age == 74,]
r$Age <- 75
df <- rbind(df, r)
#cancer_type <- paste('Any cancer type',tolower(input$Sex),sep = ' - ')
cancer_type <- paste(unique(df$Organ),tolower(unique(df$Sex)),sep=' - ')
if(unique(df$Sex) == 'BOTH'){
cancer_type <- paste(unique(df$Organ),paste(tolower(unique(df$Sex)),"genders","combined",sep=" "),sep=' - ')
}
pathogenic_variant <- paste0('path_',input$genecarrier3)
df_errorbars <- as.data.frame(dplyr::filter(df, Age == 25 | Age == 30 | Age == 35 | Age == 40 | Age == 45 | Age == 50 | Age == 55 | Age == 60 | Age == 65 | Age == 70 | Age == 75))
p <- ggplot(df, aes(x=Age,y=cum_estimate,group=SEXGENE, colour=SEXGENE)) +
geom_line(size=1) + geom_point(size=3) +
theme_bw() +
ggtitle(bquote(atop(bold(.(cancer_type)), italic(.(pathogenic_variant))))) +
geom_errorbar(aes(ymin = lower_limit, ymax = upper_limit), data = df_errorbars, width = 1, size = 1.1) +
scale_x_continuous(breaks=seq(25,75,5),limits=c(25,77)) +
scale_y_continuous(breaks=seq(0,100,10),limits=c(0,100)) +
scale_color_brewer(palette='Dark2') +
theme(legend.title = element_blank(),
legend.position = "none",
panel.grid.major = element_line(colour = 'black', size = 0.3, linetype = 'dashed'),
panel.border = element_rect(size=1, colour = "black"),
axis.text.x=element_text(family="Helvetica",size=14),
axis.title.x=element_text(family="Helvetica",size=14,vjust=-0.5),
axis.text.y=element_text(family="Helvetica",size=14),
axis.title.y=element_text(family="Helvetica",size=14,vjust=1.5),
plot.margin = (unit(c(2, 0, 2, 2), "cm")),
plot.title = element_text(family="Helvetica",size=14,vjust=2,hjust=0.5),
legend.text = element_blank()) +
#legend.text=element_text(family="Helvetica",size=14)) +
ylab('Cumulative risk of cancer (%)')
# p <- ggplot(df, aes(x=Age,y=cum_risk_percent_dynamic,group=SEXGENE,colour=SEXGENE)) +
# geom_line(size=1) + geom_point(size=3) +
# theme_bw() +
# ggtitle(bquote(atop(bold(.(cancer_type)), italic(.(pathogenic_variant))))) +
# scale_x_continuous(breaks=seq(25,75,5),limits=c(25,75)) +
# scale_y_continuous(breaks=seq(0,100,10),limits=c(0,100)) +
# scale_color_brewer(palette='Dark2') +
# theme(legend.title = element_blank(),
# legend.position = "none",
# panel.grid.major = element_line(colour = 'black', size = 0.5, linetype = 'dashed'),
# panel.border = element_rect(size=1, colour = "black"),
# axis.text.x=element_text(family="Helvetica",size=14),
# axis.title.x=element_text(family="Helvetica",size=14,vjust=-0.5),
# axis.text.y=element_text(family="Helvetica",size=14),
# axis.title.y=element_text(family="Helvetica",size=14,vjust=1.5),
# plot.margin = (unit(c(2, 0, 2, 2), "cm")),
# plot.title = element_text(family="Helvetica",size=14,vjust=2,hjust=0.5),
# legend.text = element_blank()) +
# #legend.text=element_text(family="Helvetica",size=14)) +
# ylab('Cumulative risk of cancer (%)')
print(p)
}, height="auto",width="auto")
output$plot_incidence_gene_subsequent_cancer <- renderPlot({
df <- dplyr::filter(all_cum_ind_previous_cancer, Cancer == input$ctype2 & Age >= input$Age2 & Gene == input$genecarrier2)
if(nrow(df) > 1){
df$tmp <- rep(1,nrow(df))
for (i in 2:nrow(df)) {
df$tmp[i] <- df$tmp[i - 1] - (df$tmp[i - 1] * df$Annual_incidence_rate[i - 1])
}
df$cum_risk_percent_dynamic <- (1 - df$tmp) * 100
}
else{
df$cum_risk_percent_dynamic <- df$Annual_incidence_rate * 100
}
df$SEXGENE <- paste(df$Sex,df$Gene, sep=" - ")
cancer_type <- paste('Any cancer type')
if(input$ctype2 == 'CRC'){
cancer_type <- paste('Colorectal cancer')
}
pathogenic_variant <- paste0('path_',input$genecarrier2)
p <- ggplot(df, aes(x=Age,y=cum_risk_percent_dynamic,group=SEXGENE,colour=SEXGENE)) +
geom_line(size=1) + geom_point(size=3) +
theme_bw() +
ggtitle(bquote(atop(bold(.(cancer_type)), italic(.(pathogenic_variant))))) +
scale_x_continuous(breaks=seq(25,70,5),limits=c(25,70)) +
scale_y_continuous(breaks=seq(0,100,10),limits=c(0,100)) +
scale_color_brewer(palette='Dark2') +
theme(legend.title = element_blank(),
legend.position = "none",
panel.grid.major = element_line(colour = 'black', size = 0.3, linetype = 'dashed'),
panel.border = element_rect(size=1, colour = "black"),
axis.text.x=element_text(family="Helvetica",size=14),
axis.title.x=element_text(family="Helvetica",size=14,vjust=-0.5),
axis.text.y=element_text(family="Helvetica",size=14),
axis.title.y=element_text(family="Helvetica",size=14,vjust=1.5),
plot.margin = (unit(c(2, 0, 2, 2), "cm")),
plot.title = element_text(family="Helvetica",size=14,vjust=2,hjust=0.5),
legend.text = element_blank()) +
#legend.text=element_text(family="Helvetica",size=14)) +
ylab('Cumulative risk of subsequent cancer (%)')
print(p)
}, height="auto",width="auto")
output$table_ALL <- renderTable({
df <- as.data.frame(dplyr::filter(all_cum_ind, Cancer == input$ctype & Sex == input$Sex & Gene == input$genecarrier & Age >= input$Age))
if(nrow(df) > 1){
df$tmp <- rep(1,nrow(df))
for (i in 2:nrow(df)) {
df$tmp[i] <- df$tmp[i - 1] - (df$tmp[i - 1] * df$Annual_incidence_rate[i - 1])
}
df$cum_risk_percent_dynamic <- as.integer(round((1 - df$tmp) * 100))
}
else{
df$cum_risk_percent_dynamic <- as.integer(round(df$Annual_incidence_rate * 100))
}
df <- as.data.frame(dplyr::filter(df, Age == 25 | Age == 40 | Age == 50 | Age == 60 | Age == 70))
df <- df %>% dplyr::select(Age,Sex,Gene,cum_risk_percent_dynamic)
df$Gene <- paste0('path_',df$Gene)
df <- df %>% dplyr::select(Age,cum_risk_percent_dynamic)
#test <- 1 - ((1 - df[1,]$Annual_incidence_rate) * (1 - df[2,]$Annual_incidence_rate) * (1 - df[3,]$Annual_incidence_rate) * (1 - df[4,]$Annual_incidence_rate) * (1 - df[5,]$Annual_incidence_rate) * (1 - df[6,]$Annual_incidence_rate) * (1 - df[7,]$Annual_incidence_rate) * (1 - df[8,]$Annual_incidence_rate) * (1 - df[9,]$Annual_incidence_rate) * (1 - df[10,]$Annual_incidence_rate) * (1 - df[11,]$Annual_incidence_rate) * (1 - df[12,]$Annual_incidence_rate) * (1 - df[13,]$Annual_incidence_rate) * (1 - df[14,]$Annual_incidence_rate) * (1 - df[15,]$Annual_incidence_rate))
colnames(df) <- c('Age','Risk (%)')
df
},include.rownames=F)
output$table_ALL2 <- renderTable({
df <- as.data.frame(dplyr::filter(all_cum_ind_previous_cancer, Cancer == input$ctype2 & Gene == input$genecarrier2 & Age >= input$Age2))
if(nrow(df) > 1){
df$tmp <- rep(1,nrow(df))
for (i in 2:nrow(df)) {
df$tmp[i] <- df$tmp[i - 1] - (df$tmp[i - 1] * df$Annual_incidence_rate[i - 1])
}
df$cum_risk_percent_dynamic <- as.integer(round((1 - df$tmp) * 100))
}
else{
df$cum_risk_percent_dynamic <- as.integer(round(df$Annual_incidence_rate * 100))
}
df <- as.data.frame(dplyr::filter(df, Age == 25 | Age == 40 | Age == 50 | Age == 60 | Age == 70))
df <- df %>% dplyr::select(Age,Sex,Gene,cum_risk_percent_dynamic)
df$Gene <- paste0('path_',df$Gene)
df <- df %>% dplyr::select(Age,cum_risk_percent_dynamic)
colnames(df) <- c('Age','Risk (%)')
df
},include.rownames=F)
#output$table_ALL3 <- DT::renderDataTable(DT::datatable({
output$table_ALL3 <- renderTable({
df <- NULL
if(input$ctype3 == '182' || input$ctype3 == '174' || input$ctype3 == '183' || input$ctype3 == '182_183'){
#df <- dplyr::filter(organ_table, Cancer == input$ctype3 & Age >= input$Age3 & Gene == input$genecarrier3 & Sex == input$Sex3)
df <- dplyr::filter(ls_organ_precomputed, Cancer == input$ctype3 & Age_start == input$Age3 & Gene == input$genecarrier3 & Sex == input$Sex3)
}
if(input$ctype3 == '153' || input$ctype3 == '154'){
#df <- dplyr::filter(organ_table, Cancer == input$ctype3 & Age >= input$Age3 & Gene == input$genecarrier3 & Sex == input$Sex5)
df <- dplyr::filter(ls_organ_precomputed, Cancer == input$ctype3 & Age_start == input$Age3 & Gene == input$genecarrier3 & Sex == input$Sex5)
}
if(input$ctype3 == '185'){
#df <- dplyr::filter(organ_table, Cancer == input$ctype3 & Age >= input$Age3 & Gene == input$genecarrier3 & Sex == input$Sex4)
df <- dplyr::filter(ls_organ_precomputed, Cancer == input$ctype3 & Age_start == input$Age3 & Gene == input$genecarrier3 & Sex == input$Sex4)
}
if(input$ctype3 == 'PANCANCER' || input$ctype3 == '151' || input$ctype3 == '152' || input$ctype3 == '156' || input$ctype3 == '157' || input$ctype3 == '188' || input$ctype3 == '189' || input$ctype3 == '191' || input$ctype3 == '151_152_156_157' || input$ctype3 == '188_189' || input$ctype3 == '153_154'){
#df <- dplyr::filter(organ_table, Cancer == input$ctype3 & Age >= input$Age3 & Gene == input$genecarrier3 & Sex == input$Sex6)
df <- dplyr::filter(ls_organ_precomputed, Cancer == input$ctype3 & Age_start == input$Age3 & Gene == input$genecarrier3 & Sex == input$Sex6)
}
# if(nrow(df) > 1){
# df$tmp <- rep(1,nrow(df))
# for (i in 2:nrow(df)) {
# df$tmp[i] <- df$tmp[i - 1] - (df$tmp[i - 1] * df$Annual_incidence_rate[i - 1])
# }
# df$cum_risk_percent_dynamic <- as.integer(round((1 - df$tmp) * 100))
# }
# else{
# df$cum_risk_percent_dynamic <- as.integer(round(df$Annual_incidence_rate * 100))
# }
# df <- as.data.frame(dplyr::filter(df, Age == 25 | Age == 40 | Age == 50 | Age == 60 | Age == 70 | Age == 74))
# df$Age <- as.integer(df$Age)
# df <- df %>% dplyr::select(Age,Sex,Gene,cum_risk_percent_dynamic)
# df$Gene <- paste0('path_',df$Gene)
# df <- df %>% dplyr::select(Age,cum_risk_percent_dynamic)
# df[df$Age == 74,]$Age <- 75
#
# colnames(df) <- c('Age','Risk (%)')
# df
df <- as.data.frame(dplyr::filter(df, Age_stop == 25 | Age_stop == 40 | Age_stop == 50 | Age_stop == 60 | Age_stop == 70 | Age_stop == 74))
df$Age <- as.integer(df$Age_stop)
df <- df %>% dplyr::select(Age,Sex,Gene,cum_estimate,lower_limit, upper_limit)
df$cum_estimate <- round(df$cum_estimate, digits = 1)
df$lower_limit <- round(df$lower_limit, digits = 1)
df$upper_limit <- round(df$upper_limit, digits = 1)
df$Gene <- paste0('path_',df$Gene)
df$CI <- paste0("[",df$lower_limit," - ",df$upper_limit,"]")
df <- df %>% dplyr::select(Age,cum_estimate,CI)
df[df$Age == 74,]$Age <- 75
df$Age <- as.integer(df$Age)
#
colnames(df) <- c('Age','Risk (%)','95% Confidence interval')
df
})
#}, rownames = F, width = 10, options <- list(paging = F, searching=F,caching=F,buttons = c('csv','excel'),dom = 'Bfrtip')))
})