-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.R
113 lines (96 loc) · 2.81 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
#load required packages
require(RCy3)
shinyServer(function(input, output, session) {
rv <- reactiveValues()
###########
# sidebar #
###########
#############
# cytoscape #
#############
refreshImage<-function(){
output$cyto.png <- renderImage({
RCy3::exportImage("cyto.png", width = 500, network = rv$net.suid)
list(src = "cyto.png", alt = "Cytoscape screenshot")
}, deleteFile = FALSE)
}
#############
# gene list #
#############
getGeneList <- function(){
output$gl.text <- NULL
output$gene.check <- NULL
rv$gl.status <- FALSE
if (file.exists("gl.csv")){
data.df <- read.table("gl.csv", sep = ",", header = T, stringsAsFactors = F)
checkTableData(data.df)
return(data.df)
}
}
#check table data
checkTableData <- function(data.df) {
output$gl.text <- renderText("Let's examine your gene list...")
ds.names <- tolower(names(data.df))
#GENE CHECK
if(!'gene' %in% ds.names){
stop('Please reformat your CSV to have a "gene" column with gene names.')
}
rv$gene.list <- data.df$gene[1:5]
#TODO
rv$gl.status <- TRUE
}
#render table data
output$table.gl <- DT::renderDataTable(server = TRUE,{
DT::datatable({ head(getGeneList()) },
rownames=FALSE,
options = list(
dom = 'Brt'
)
)
})
#when upload is performed
observeEvent(input$gl.file, {
# output$debug.text<-renderText(paste(input$gl.file$name,collapse = ","))
uploaded.file = file.rename(input$gl.file$datapath, "gl.csv")
output$table.gl <- NULL
getGeneList()
})
#set run status
observe({
if(rv$gl.status){
output$gl.ready <- renderText(" ✔ Ready!")
output$gl.status <- renderText(" ✔ Ready!")
output$string.button <- renderUI({
actionButton("string.query", "Create Network")
})
} else {
output$gl.ready <- NULL
output$gl.status <- NULL
}
})
observeEvent(input$string.query,{
rv$net.suid <- RCy3::commandsPOST(paste0(
'string protein query query="',
paste(rv$gene.list, collapse = ","),
'"')
)
refreshImage()
})
############
# data vis #
############
observeEvent(input$node.label.font.size, {
RCy3::setNodeFontSizeDefault(input$node.label.font.size, "STRING")
refreshImage()
})
#
# #differential analysis tab - select the cluster number
# output$DEclusterNumUI <- renderUI({
# selectInput(
# "clusterNum",
# "Choose a cluster to compare with all other clusters for differentially expressed genes",
# choices = sort(unique(get(input$dataset)@meta.data$seurat_clusters)),
# selected = sort(unique(get(input$dataset)@meta.data$seurat_clusters))[1]
# )
# })
})