-
Notifications
You must be signed in to change notification settings - Fork 1
/
Global.R
172 lines (144 loc) · 6.3 KB
/
Global.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
processDataFiles <- function(input, uiType) {
data.obj <- NULL
# 根据uiType确定正确的inputId
dataFileId <- paste0(uiType, "_dataFile")
countDataId <- paste0(uiType, "_countData")
metadataId <- paste0(uiType, "_metadata")
taxonomyId <- paste0(uiType, "_taxonomy")
phyloTreeId <- paste0(uiType, "_phyloTree")
if(is.null(input[[dataFileId]])) {
if(!is.null(input[[countDataId]]) && !is.null(input[[metadataId]]) && !is.null(input[[taxonomyId]])) {
message("Reading count data...")
countData <- as.matrix(read.table(input[[countDataId]]$datapath, header = TRUE, row.names = 1, sep = ",", check.names = FALSE))
message("Reading metadata...")
metadata <- read.table(input[[metadataId]]$datapath, header = TRUE, row.names = 1, sep = ",")
if(!is.data.frame(metadata)) {
metadata <- as.data.frame(metadata)
}
message("Reading taxonomy data...")
taxonomy <- as.matrix(read.table(input[[taxonomyId]]$datapath, header = TRUE, row.names = 1, sep = ","))
if(!is.null(input[[phyloTreeId]])) {
message("Reading phylogenetic tree...")
phyloTree <- read.tree(input[[phyloTreeId]]$datapath)
} else {
phyloTree <- NULL
}
message("Creating data object...")
data.obj <- list(
feature.tab = countData,
meta.dat = metadata,
feature.ann = taxonomy,
tree = phyloTree
)
mStat_validate_data(data.obj)
message("Data object created successfully.")
}
} else {
loadData <- load(file = input[[dataFileId]]$datapath)
data.obj <- get(loadData)
}
return(data.obj)
}
updateDepthChoices <- function(data.obj, session, idPrefix = "") {
if(!is.null(data.obj$feature.tab) && is.matrix(data.obj$feature.tab)) {
# 计算 feature.tab 的 colSums 的最小值
minDepth <- min(colSums(data.obj$feature.tab))
# 更新 depth 的选项
updateSliderInput(session, paste0(idPrefix, 'depth'), min = 1, max = minDepth, value = minDepth, step = 1)
} else {
# 可选:如果data.obj不包含feature.tab或feature.tab不是矩阵,则显示错误消息
showModal(modalDialog(
title = "Error",
"The uploaded data.obj file does not contain a valid feature.tab matrix.",
easyClose = TRUE
))
}
}
updateMetaDatChoices <- function(data.obj, session, idPrefix = "") {
if(!is.null(data.obj$meta.dat) && is.data.frame(data.obj$meta.dat)) {
# 获取meta.dat的列名
colNames <- names(data.obj$meta.dat)
# 更新selectInput元素的选项
updateSelectInput(session, paste0(idPrefix, 'groupVar'), choices = colNames)
updateSelectInput(session, paste0(idPrefix, 'visAdjVars'), choices = colNames)
updateSelectInput(session, paste0(idPrefix, 'testAdjVars'), choices = colNames)
updateSelectInput(session, paste0(idPrefix, 'strataVar'), choices = colNames)
updateSelectInput(session, paste0(idPrefix, 'subjectVar'), choices = colNames)
updateSelectInput(session, paste0(idPrefix, 'timeVar'), choices = colNames)
} else {
# 可选:如果data.obj不包含meta.dat或meta.dat不是数据框,则显示错误消息
showModal(modalDialog(
title = "Error",
"The uploaded data.obj file does not contain a valid meta.dat data frame.",
easyClose = TRUE
))
}
}
# 定义函数
updateFeatureAnnChoices <- function(data.obj, session, idPrefix = "") {
# 确保data.obj包含feature.ann,并且它是一个矩阵
if(!is.null(data.obj$feature.ann) && is.matrix(data.obj$feature.ann)) {
# 获取feature.ann的列名
featureAnnColNames <- colnames(data.obj$feature.ann)
# 添加"original"选项
featureAnnChoices <- c("original", featureAnnColNames)
# 更新selectInput元素的选项
updateSelectInput(session, paste0(idPrefix, 'visFeatureLevel'), choices = featureAnnChoices)
updateSelectInput(session, paste0(idPrefix, 'testFeatureLevel'), choices = featureAnnChoices)
} else {
# 可选:如果data.obj不包含feature.ann或feature.ann不是矩阵,则显示错误消息
showModal(modalDialog(
title = "Error",
"The uploaded data.obj file does not contain a valid feature.ann matrix.",
easyClose = TRUE
))
}
}
# 定义函数
updateTLevelChoices <- function(data.obj, input, session, idPrefix = "") {
observeEvent(input[[paste0(idPrefix, 'timeVar')]], {
# 确保 data.obj 包含 meta.dat,并且它是一个数据框
if(!is.null(data.obj$meta.dat) && is.data.frame(data.obj$meta.dat)) {
# 获取 time.var 的唯一值
timeVarValues <- unique(data.obj$meta.dat[[input[[paste0(idPrefix, 'timeVar')]]]])
# 更新 tLevel 的选项
updateSelectInput(session, paste0(idPrefix, 'tLevel'), choices = timeVarValues)
}
})
}
# 定义函数
updateChangeBaseChoices <- function(data.obj, input, session, idPrefix = "") {
observeEvent(input[[paste0(idPrefix, 'timeVar')]], {
# 确保 data.obj 包含 meta.dat,并且它是一个数据框
if(!is.null(data.obj$meta.dat) && is.data.frame(data.obj$meta.dat)) {
# 获取 time.var 的唯一值
timeVarValues <- unique(data.obj$meta.dat[[input[[paste0(idPrefix, 'timeVar')]]]])
# 更新 changeBase 的选项
updateSelectInput(session, paste0(idPrefix, 'changeBase'), choices = timeVarValues)
}
})
}
# 定义函数
updateT0LevelChoices <- function(data.obj, input, session, idPrefix = "") {
observeEvent(input[[paste0(idPrefix, 'timeVar')]], {
# 确保 data.obj 包含 meta.dat,并且它是一个数据框
if(!is.null(data.obj$meta.dat) && is.data.frame(data.obj$meta.dat)) {
# 获取 time.var 的唯一值
timeVarValues <- unique(data.obj$meta.dat[[input[[paste0(idPrefix, 'timeVar')]]]])
# 更新 t0Level 的选项
updateSelectInput(session, paste0(idPrefix, 't0Level'), choices = timeVarValues)
}
})
}
# 定义函数
updateTSLevelsChoices <- function(data.obj, input, session, idPrefix = "") {
observeEvent(input[[paste0(idPrefix, 'timeVar')]], {
# 确保 data.obj 包含 meta.dat,并且它是一个数据框
if(!is.null(data.obj$meta.dat) && is.data.frame(data.obj$meta.dat)) {
# 获取 time.var 的唯一值
timeVarValues <- unique(data.obj$meta.dat[[input[[paste0(idPrefix, 'timeVar')]]]])
# 更新 tsLevels 的选项
updateSelectInput(session, paste0(idPrefix, 'tsLevels'), choices = timeVarValues)
}
})
}