-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.R
executable file
·169 lines (158 loc) · 5.74 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
#!/usr/bin/env Rscript
options(encoding="UTF-8")
suppressPackageStartupMessages({
require(shiny)
require(AnnotationHub)
require(clusterProfiler)
require(DOSE)
require(AnnotationDbi)
require(ggplot2)
require(stringr)
require(magrittr)
require(dplyr)
require(plyr)
require(purrr)
library(rstatix)
library(FSA)
library(lattice)
library(car)
library(emmeans)
library(corrplot)
})
get_file_path <- function() {
cmdArgs <- commandArgs(trailingOnly = FALSE)
if (length(grep("^-f$", cmdArgs)) > 0) {
# R console option
normalizePath(dirname(cmdArgs[grep("^-f", cmdArgs) + 1]))[1]
} else if (length(grep("^--file=", cmdArgs)) > 0) {
# Rscript/R console option
scriptPath <- normalizePath(dirname(sub("^--file=", "", cmdArgs[grep("^--file=", cmdArgs)])))[1]
} else if (Sys.getenv("RSTUDIO") == "1") {
if (rstudioapi::isAvailable(version_needed=NULL,child_ok=FALSE)) {
# RStudio interactive
dirname(rstudioapi::getSourceEditorContext()$path)
} else if (is.null(knitr::current_input(dir = TRUE)) == FALSE) {
# Knit
knitr::current_input(dir = TRUE)
} else {
# R markdown on RStudio
getwd()
}
} else if (is.null(attr(stub, "srcref")) == FALSE) {
# 'source'd via R console
dirname(normalizePath(attr(attr(stub, "srcref"), "srcfile")$filename))
} else {
stop("Cannot find file path")
}
}
root_dir = get_file_path()
source(paste0(root_dir, "/modules/utils.R"))
source(paste0(root_dir,"/modules/statisitcs.R"))
source(paste0(root_dir,"/modules/visualize.R"))
source(paste0(root_dir,"/modules/conversion.R"))
source(paste0(root_dir,"/modules/go.R"))
source(paste0(root_dir,"/modules/orgdb.R"))
source(paste0(root_dir,"/modules/ora.R"))
shinyServer(function(input, output, session) {
# Statisitic
# s_file <- reactive(input$s_file)
s_demo <- eventReactive(input$s_example, {get_stas_demo()})
s_data <- eventReactive(input$s_action, {
infile <- input$s_file
header <- input$s_header
if (!is.null(infile$datapath)) {
if (input$s_type == "csv") {
exec_func(args=list(infile$datapath, header), func=read_file)
}
} else {
return(s_demo())
}
})
callback <- c(
"var colnames = table.columns().header().to$().map(function(){return this.innerHTML;}).get();",
"Shiny.onInputChange('colnames', colnames);",
"table.on('dblclick.dt', 'thead th', function(e) {",
" var $th = $(this);",
" var index = $th.index();",
" var colname = $th.text(), newcolname = colname;",
" var $input = $('<input type=\"text\">')",
" $input.val(colname);",
" $th.empty().append($input);",
" $input.on('change', function(){",
" newcolname = $input.val();",
" if(newcolname != colname){",
" $(table.column(index).header()).text(newcolname);",
" colnames[index] = newcolname;",
" Shiny.onInputChange('colnames', colnames);",
" }",
" $input.remove();",
" }).on('blur', function(){",
" $(table.column(index).header()).text(newcolname);",
" $input.remove();",
" });",
"});"
)
output$s_data <- DT::renderDT(s_data(), server=T, editable="cell",
selection = 'none', callback=DT::JS(callback))
observeEvent(input$s_action, {run_desc(input,output,s_data())})
observeEvent(input$s_action, {run_normality_test(input,output,s_data())})
observeEvent(input$s_action, {run_hetero_test(input,output,s_data())})
observe({
m_type <- input$m_type
m_methods <- if (m_type == "parametric") c('Least Squares Means') else
c('Kruskal-Wallis test for equal variances', "Welch's anova for unequal variances")
updateSelectInput(session, "m_method",
label = paste("Select a stastistical method"),
choices = m_methods,
selected = tail(m_methods, 1))
})
observeEvent(input$s_action, {run_sign_test(input, output, s_data())})
# id conversion
id_types <- list(`GI number`=c("Entrez Gene (GeneID)", "Protein Accession"),
`Entrez Gene (GeneID)`=c("GI number", "Protein Accession"),
`Protein Accession`=c("GI number", "Entrez Gene (GeneID)"))
observeEvent(input$id_select_fr, {
fr <- input$id_select_fr
to <- input$id_select_to
updateSelectInput(session, "id_select_to", label = paste("To"),
choices = id_types[[fr]],
selected = head(id_types[[fr]], 1))
if (fr == "GI number") {
value <- echo_gi_demo()
} else if (fr == "Entrez Gene (GeneID)") {
value <- echo_entrezid_demo()
} else if (fr == "Protein Accession") {
value <- echo_prot_acc_demo()
}
updateTextAreaInput(session, "id_input", value=value)
})
observeEvent(input$id_clear, {
updateTextAreaInput(session, "id_input", value="")
})
observeEvent(input$id_action, {
showModal(modalDialog("In progress for converting gene ids", footer=NULL))
run_convert_id(input, output)
removeModal()
})
observeEvent(input$go_demo, {
updateTextAreaInput(session, "go_geneid",
value=paste(as.character(get_goclass_demo()), collapse="\n"))
})
observeEvent(input$go_id_clear, {
updateTextAreaInput(session, "go_geneid", value="")
})
observeEvent(input$go_action, {
showModal(modalDialog("In progress for grouping GO classification", footer=NULL))
run_go_class(input, output)
removeModal()
})
observeEvent(input$ora_demo, {
updateTextAreaInput(session, "ora_geneid",
value=paste(as.character(get_ora_demo()), collapse="\n"))
})
observeEvent(input$ora_action, {
showModal(modalDialog("In progress for Over-Representation Analysis", footer=NULL))
run_ora(input, output)
removeModal()
})
})