Skip to content

Commit

Permalink
Merge pull request #351 from lishensuo/master
Browse files Browse the repository at this point in the history
Optimize some details
  • Loading branch information
lishensuo authored Aug 22, 2024
2 parents d46e537 + 8c9da6f commit 29d0b16
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 47 deletions.
3 changes: 2 additions & 1 deletion inst/shinyapp/modules/03_tcga/modules-pancan-comp-m2o.R
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,8 @@ server.modules_pancan_comp_m2o = function(input, output, session) {
data = dplyr::inner_join(y_data, group_data) %>%
dplyr::select(Sample, value, group, everything()) %>% na.omit()
# 检查数据是否合理
if(nrow(data)==0 | sd(data$value)==0 | length(unique(data$group))==1) return(c(NaN, NaN, NaN))
if(nrow(data)==0 | sd(data$value)==0) return(c(NaN, NaN, NaN))
if(length(unique(data$group))==1 | min(table(data$group))<3) return(c(NaN, NaN, NaN))

if(input$comp_method == "t.test"){
comp_obj = t.test(value ~ group, data)
Expand Down
2 changes: 1 addition & 1 deletion inst/shinyapp/modules/03_tcga/modules-pancan-comp-o2m.R
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ server.modules_pancan_comp_o2m = function(input, output, session) {
merge_data_line() %>%
dplyr::group_by(cancer, group) %>%
dplyr::summarise(n1=n()) %>%
dplyr::filter(n1>=2) %>% # 每小组的样本数大于等于2
dplyr::filter(n1>=3) %>% # 每小组的样本数大于等于3
dplyr::distinct(cancer, group) %>%
dplyr::count(cancer,name = "n2") %>%
dplyr::filter(n2==2) %>% dplyr::pull("cancer") # 每个肿瘤有两组
Expand Down
6 changes: 3 additions & 3 deletions inst/shinyapp/modules/03_tcga/modules-pancan-comp-o2o.R
Original file line number Diff line number Diff line change
Expand Up @@ -268,10 +268,10 @@ server.modules_pancan_comp_o2o = function(input, output, session) {
shiny::validate(
need(try(nrow(merge_data_box())>0),
"Please inspect whether to set groups or download variable data in S2 or S3 step."),
)
shiny::validate(
need(try(length(unique(merge_data_box()$group))==2),
"No enough samples for comparing, please check your input."),
"No two groups for comparing, please check your input."),
need(try(min(table(merge_data_box()$group))>2),
"No enough samples (n≤3) for one group for comparing, please check your input."),
)
merge_data_box = merge_data_box()

Expand Down
2 changes: 1 addition & 1 deletion inst/shinyapp/modules/03_tcga/modules-pancan-cor-m2o.R
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ server.modules_pancan_cor_m2o = function(input, output, session) {
xy_data = x_datas %>%
dplyr::filter(x_id == L3_x) %>%
dplyr::inner_join(y_data) %>% as.data.frame()
if(nrow(na.omit(xy_data))==0){return(c(NaN, NaN))}
if(nrow(na.omit(xy_data))<3){return(c(NaN, NaN))}
cor_obj = cor.test(xy_data[,"x_value"],xy_data[,"y_value"],
method = input$cor_method)
incProgress(1 / length(L3s_x()), detail = paste0("(Finished ",i,"/",length(L3s_x()),")"))
Expand Down
9 changes: 8 additions & 1 deletion inst/shinyapp/modules/03_tcga/modules-pancan-cor-o2m.R
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,16 @@ server.modules_pancan_cor_o2m = function(input, output, session) {
colnames(x_axis_data)[c(1:3,5)] = paste0("x_",colnames(x_axis_data)[c(1:3,5)])
y_axis_data = y_axis_data()
colnames(y_axis_data)[c(1:3,5)] = paste0("y_",colnames(y_axis_data)[c(1:3,5)])

data = dplyr::inner_join(x_axis_data, y_axis_data) %>%
dplyr::select(cancer, Sample, everything())

data <- data %>%
dplyr::filter(cancer %in% (
data %>%
dplyr::count(cancer) %>%
dplyr::filter(n > 2) %>%
dplyr::pull(cancer)
))
# print(head(data))
data
})
Expand Down
2 changes: 2 additions & 0 deletions inst/shinyapp/modules/03_tcga/modules-pancan-cor-o2o.R
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,8 @@ server.modules_pancan_cor_o2o = function(input, output, session) {
shiny::validate(
need(try(nrow(merge_data_sct())>0),
"Please inspect whether to get valid data in Step2."),
need(try(nrow(merge_data_sct())>2),
"Please adjust to ensure that enough samples (n≥3) are included for analysis.")
)
p = plot_cor_o2o(
data = merge_data_sct(), cor_method = input$cor_method,
Expand Down
75 changes: 37 additions & 38 deletions inst/shinyapp/modules/06_tpc_func/modules-z-download-feat.R
Original file line number Diff line number Diff line change
Expand Up @@ -264,51 +264,50 @@ download_feat_Server = function(input, output, session, database = "toil",#id_op
x_data$cancer = clinical_phe[,2,drop=T][match(x_data$Sample, clinical_phe$Sample)]
x_data = x_data[,c("id","level1","level2","Sample","value","cancer")] %>%
dplyr::arrange(cancer,Sample)
# shinyjs::enable("query_data")
shinyjs::enable("query_data")
x_data
})

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

observeEvent(input$query_data,{

w$show()
output$x_axis_data_table = renderUI({
if(table.ui){
output$x_tmp_table = renderDataTable({
shinyjs::enable("query_data")

shiny::validate(
need(try(nrow(download_data())>0),
"No sample data available. Please inspect operations in Preset step."),
)
if(check_numeric){
# observeEvent(input$query_data,{
observe({
if (input$query_data>0) {
w$show()
output$x_axis_data_table = renderUI({
if(table.ui){
output$x_tmp_table = renderDataTable({
# shinyjs::enable("query_data")
shiny::validate(
need(try(class(download_data()$value)!="character"),
"Please select a numeric variable."),
)
}
x_axis_data_ = download_data()[,c("Sample","value","cancer")]

if(class(x_axis_data_[,"value"])=="numeric"){
x_axis_data_[,"value"] = round(x_axis_data_[,"value"], digits = 3)
}
datatable(x_axis_data_,
options = list(pageLength = 3,
columnDefs = list(list(className = 'dt-center', targets="_all")))
)
})
dataTableOutput(ns("x_tmp_table"))
} else {
output$x_tmp_table = renderPrint({
# ids_num = nrow()
cat(paste0("Tip: identifier values of ", nrow(download_data()), " samples are prepared."))
})
verbatimTextOutput(ns("x_tmp_table"))
}
need(try(nrow(download_data())>0),
"No sample data available. Please inspect operations in Preset step."),
)
if(check_numeric){
shiny::validate(
need(try(class(download_data()$value)!="character"),
"Please select a numeric variable."),
)
}
x_axis_data_ = download_data()[,c("Sample","value","cancer")]

})

if(class(x_axis_data_[,"value"])=="numeric"){
x_axis_data_[,"value"] = round(x_axis_data_[,"value"], digits = 3)
}
datatable(x_axis_data_,
options = list(pageLength = 3,
columnDefs = list(list(className = 'dt-center', targets="_all")))
)
})
dataTableOutput(ns("x_tmp_table"))
} else {
output$x_tmp_table = renderPrint({
# ids_num = nrow()
cat(paste0("Tip: identifier values of ", nrow(download_data()), " samples are prepared."))
})
verbatimTextOutput(ns("x_tmp_table"))
}
})
}
})

# observeEvent(input$query_data,{
Expand Down
2 changes: 1 addition & 1 deletion inst/shinyapp/utils_appdata.R
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ tcga_id_option = list(
),
"TIMER" = list(
"all" = tcga_id.list[["TIMER"]],
"default" = "Monocyte"
"default" = "Macrophage"
),
"XCELL" = list(
"all" = tcga_id.list[["XCELL"]],
Expand Down
7 changes: 6 additions & 1 deletion inst/shinyapp/utils_plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,12 @@ plot_comb_o2m = function(data1, data2, x_name, title_name,

p1 = ggplot(data1_sub) +
stat_summary(aes(x=cancer, y=value, color=group),
position=position_dodge(width=0.5)) +
# colour = "gray",
position=position_dodge(width=0.5)) +
geom_jitter(aes(x=cancer, y=value, color=group),
position=position_dodge(width=0.5), size = 1,
# colour = "gray",
alpha = 0.4) +
xlab("") + ylab(x_name) + ggtitle(label = title_name) + #转置
scale_color_manual(values = c(group_1_color_2, group_2_color_2)) +
coord_flip() + custom_theme
Expand Down

0 comments on commit 29d0b16

Please sign in to comment.