Skip to content

Commit 29d0b16

Browse files
authored
Merge pull request #351 from lishensuo/master
Optimize some details
2 parents d46e537 + 8c9da6f commit 29d0b16

9 files changed

Lines changed: 61 additions & 47 deletions

inst/shinyapp/modules/03_tcga/modules-pancan-comp-m2o.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,8 @@ server.modules_pancan_comp_m2o = function(input, output, session) {
229229
data = dplyr::inner_join(y_data, group_data) %>%
230230
dplyr::select(Sample, value, group, everything()) %>% na.omit()
231231
# 检查数据是否合理
232-
if(nrow(data)==0 | sd(data$value)==0 | length(unique(data$group))==1) return(c(NaN, NaN, NaN))
232+
if(nrow(data)==0 | sd(data$value)==0) return(c(NaN, NaN, NaN))
233+
if(length(unique(data$group))==1 | min(table(data$group))<3) return(c(NaN, NaN, NaN))
233234

234235
if(input$comp_method == "t.test"){
235236
comp_obj = t.test(value ~ group, data)

inst/shinyapp/modules/03_tcga/modules-pancan-comp-o2m.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ server.modules_pancan_comp_o2m = function(input, output, session) {
265265
merge_data_line() %>%
266266
dplyr::group_by(cancer, group) %>%
267267
dplyr::summarise(n1=n()) %>%
268-
dplyr::filter(n1>=2) %>% # 每小组的样本数大于等于2
268+
dplyr::filter(n1>=3) %>% # 每小组的样本数大于等于3
269269
dplyr::distinct(cancer, group) %>%
270270
dplyr::count(cancer,name = "n2") %>%
271271
dplyr::filter(n2==2) %>% dplyr::pull("cancer") # 每个肿瘤有两组

inst/shinyapp/modules/03_tcga/modules-pancan-comp-o2o.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -268,10 +268,10 @@ server.modules_pancan_comp_o2o = function(input, output, session) {
268268
shiny::validate(
269269
need(try(nrow(merge_data_box())>0),
270270
"Please inspect whether to set groups or download variable data in S2 or S3 step."),
271-
)
272-
shiny::validate(
273271
need(try(length(unique(merge_data_box()$group))==2),
274-
"No enough samples for comparing, please check your input."),
272+
"No two groups for comparing, please check your input."),
273+
need(try(min(table(merge_data_box()$group))>2),
274+
"No enough samples (n≤3) for one group for comparing, please check your input."),
275275
)
276276
merge_data_box = merge_data_box()
277277

inst/shinyapp/modules/03_tcga/modules-pancan-cor-m2o.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ server.modules_pancan_cor_m2o = function(input, output, session) {
213213
xy_data = x_datas %>%
214214
dplyr::filter(x_id == L3_x) %>%
215215
dplyr::inner_join(y_data) %>% as.data.frame()
216-
if(nrow(na.omit(xy_data))==0){return(c(NaN, NaN))}
216+
if(nrow(na.omit(xy_data))<3){return(c(NaN, NaN))}
217217
cor_obj = cor.test(xy_data[,"x_value"],xy_data[,"y_value"],
218218
method = input$cor_method)
219219
incProgress(1 / length(L3s_x()), detail = paste0("(Finished ",i,"/",length(L3s_x()),")"))

inst/shinyapp/modules/03_tcga/modules-pancan-cor-o2m.R

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,9 +253,16 @@ server.modules_pancan_cor_o2m = function(input, output, session) {
253253
colnames(x_axis_data)[c(1:3,5)] = paste0("x_",colnames(x_axis_data)[c(1:3,5)])
254254
y_axis_data = y_axis_data()
255255
colnames(y_axis_data)[c(1:3,5)] = paste0("y_",colnames(y_axis_data)[c(1:3,5)])
256-
257256
data = dplyr::inner_join(x_axis_data, y_axis_data) %>%
258257
dplyr::select(cancer, Sample, everything())
258+
259+
data <- data %>%
260+
dplyr::filter(cancer %in% (
261+
data %>%
262+
dplyr::count(cancer) %>%
263+
dplyr::filter(n > 2) %>%
264+
dplyr::pull(cancer)
265+
))
259266
# print(head(data))
260267
data
261268
})

inst/shinyapp/modules/03_tcga/modules-pancan-cor-o2o.R

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,8 @@ server.modules_pancan_cor_o2o = function(input, output, session) {
269269
shiny::validate(
270270
need(try(nrow(merge_data_sct())>0),
271271
"Please inspect whether to get valid data in Step2."),
272+
need(try(nrow(merge_data_sct())>2),
273+
"Please adjust to ensure that enough samples (n≥3) are included for analysis.")
272274
)
273275
p = plot_cor_o2o(
274276
data = merge_data_sct(), cor_method = input$cor_method,

inst/shinyapp/modules/06_tpc_func/modules-z-download-feat.R

Lines changed: 37 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -264,51 +264,50 @@ download_feat_Server = function(input, output, session, database = "toil",#id_op
264264
x_data$cancer = clinical_phe[,2,drop=T][match(x_data$Sample, clinical_phe$Sample)]
265265
x_data = x_data[,c("id","level1","level2","Sample","value","cancer")] %>%
266266
dplyr::arrange(cancer,Sample)
267-
# shinyjs::enable("query_data")
267+
shinyjs::enable("query_data")
268268
x_data
269269
})
270270

271271
w <- waiter::Waiter$new(id = ns("x_axis_data_table"), html = waiter::spin_hexdots(), color = "black")
272272

273-
observeEvent(input$query_data,{
274-
275-
w$show()
276-
output$x_axis_data_table = renderUI({
277-
if(table.ui){
278-
output$x_tmp_table = renderDataTable({
279-
shinyjs::enable("query_data")
280-
281-
shiny::validate(
282-
need(try(nrow(download_data())>0),
283-
"No sample data available. Please inspect operations in Preset step."),
284-
)
285-
if(check_numeric){
273+
# observeEvent(input$query_data,{
274+
observe({
275+
if (input$query_data>0) {
276+
w$show()
277+
output$x_axis_data_table = renderUI({
278+
if(table.ui){
279+
output$x_tmp_table = renderDataTable({
280+
# shinyjs::enable("query_data")
286281
shiny::validate(
287-
need(try(class(download_data()$value)!="character"),
288-
"Please select a numeric variable."),
289-
)
290-
}
291-
x_axis_data_ = download_data()[,c("Sample","value","cancer")]
292-
293-
if(class(x_axis_data_[,"value"])=="numeric"){
294-
x_axis_data_[,"value"] = round(x_axis_data_[,"value"], digits = 3)
295-
}
296-
datatable(x_axis_data_,
297-
options = list(pageLength = 3,
298-
columnDefs = list(list(className = 'dt-center', targets="_all")))
299-
)
300-
})
301-
dataTableOutput(ns("x_tmp_table"))
302-
} else {
303-
output$x_tmp_table = renderPrint({
304-
# ids_num = nrow()
305-
cat(paste0("Tip: identifier values of ", nrow(download_data()), " samples are prepared."))
306-
})
307-
verbatimTextOutput(ns("x_tmp_table"))
308-
}
282+
need(try(nrow(download_data())>0),
283+
"No sample data available. Please inspect operations in Preset step."),
284+
)
285+
if(check_numeric){
286+
shiny::validate(
287+
need(try(class(download_data()$value)!="character"),
288+
"Please select a numeric variable."),
289+
)
290+
}
291+
x_axis_data_ = download_data()[,c("Sample","value","cancer")]
309292

310-
})
311-
293+
if(class(x_axis_data_[,"value"])=="numeric"){
294+
x_axis_data_[,"value"] = round(x_axis_data_[,"value"], digits = 3)
295+
}
296+
datatable(x_axis_data_,
297+
options = list(pageLength = 3,
298+
columnDefs = list(list(className = 'dt-center', targets="_all")))
299+
)
300+
})
301+
dataTableOutput(ns("x_tmp_table"))
302+
} else {
303+
output$x_tmp_table = renderPrint({
304+
# ids_num = nrow()
305+
cat(paste0("Tip: identifier values of ", nrow(download_data()), " samples are prepared."))
306+
})
307+
verbatimTextOutput(ns("x_tmp_table"))
308+
}
309+
})
310+
}
312311
})
313312

314313
# observeEvent(input$query_data,{

inst/shinyapp/utils_appdata.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ tcga_id_option = list(
9292
),
9393
"TIMER" = list(
9494
"all" = tcga_id.list[["TIMER"]],
95-
"default" = "Monocyte"
95+
"default" = "Macrophage"
9696
),
9797
"XCELL" = list(
9898
"all" = tcga_id.list[["XCELL"]],

inst/shinyapp/utils_plot.R

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,12 @@ plot_comb_o2m = function(data1, data2, x_name, title_name,
9797

9898
p1 = ggplot(data1_sub) +
9999
stat_summary(aes(x=cancer, y=value, color=group),
100-
position=position_dodge(width=0.5)) +
100+
# colour = "gray",
101+
position=position_dodge(width=0.5)) +
102+
geom_jitter(aes(x=cancer, y=value, color=group),
103+
position=position_dodge(width=0.5), size = 1,
104+
# colour = "gray",
105+
alpha = 0.4) +
101106
xlab("") + ylab(x_name) + ggtitle(label = title_name) + #转置
102107
scale_color_manual(values = c(group_1_color_2, group_2_color_2)) +
103108
coord_flip() + custom_theme

0 commit comments

Comments
 (0)