From 59e232ef88e45c93b81f571609fb480ce8088444 Mon Sep 17 00:00:00 2001 From: PaulJonasJost Date: Wed, 23 Oct 2024 15:37:05 +0200 Subject: [PATCH 1/3] Add option whether to scale data to unit variance --- program/shinyApp/R/pca/server.R | 9 ++++++--- program/shinyApp/R/pca/ui.R | 8 ++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/program/shinyApp/R/pca/server.R b/program/shinyApp/R/pca/server.R index 07d7b071..72c5dc34 100644 --- a/program/shinyApp/R/pca/server.R +++ b/program/shinyApp/R/pca/server.R @@ -130,7 +130,8 @@ pca_Server <- function(id, data, params, row_select){ check <- check_calculations(list( sample_selection_pca = input$sample_selection_pca, SampleAnnotationTypes_pca = input$SampleAnnotationTypes_pca, - batch = ifelse(par_tmp[[session$token]]$BatchColumn != "NULL" && input$UseBatch == "Yes",T,F) + batch = ifelse(par_tmp[[session$token]]$BatchColumn != "NULL" && input$UseBatch == "Yes",T,F), + scale_data = input$scale_data ), "PCA") if (check == "No Result yet"){ output$PCA_Info <- renderText("PCA computed.") @@ -200,7 +201,7 @@ pca_Server <- function(id, data, params, row_select){ pca <- prcomp( x = as.data.frame(t(as.data.frame(assay(data2plot)))), center = T, - scale. = FALSE + scale. = ifelse(input$scale_data == "Yes",T,F) ) }, error = function(e){ error_modal(e) @@ -223,7 +224,9 @@ pca_Server <- function(id, data, params, row_select){ # assign par_temp as empty list par_tmp[[session$token]][["PCA"]] <<- list( sample_selection_pca = input$sample_selection_pca, - SampleAnnotationTypes_pca = input$SampleAnnotationTypes_pca + SampleAnnotationTypes_pca = input$SampleAnnotationTypes_pca, + batch = ifelse(par_tmp[[session$token]]$BatchColumn != "NULL" && input$UseBatch == "Yes",T,F), + scale_data = input$scale_data ) } else { # otherwise read the reactive values diff --git a/program/shinyApp/R/pca/ui.R b/program/shinyApp/R/pca/ui.R index 9ac3835b..2e3e8227 100644 --- a/program/shinyApp/R/pca/ui.R +++ b/program/shinyApp/R/pca/ui.R @@ -16,6 +16,14 @@ pca_sidebar_panel <- function(ns){ ), uiOutput(outputId = ns("SampleAnnotationTypes_pca_ui")), uiOutput(outputId = ns("sample_selection_pca_ui")), + # Scale data to unit variance y/n + radioGroupButtons( + inputId = ns("scale_data"), + label = "Scale data to unit variance?", + choices = c("Yes","No"), + direction = "horizontal", + selected = "No" + ), ### start pca --- actionButton( inputId = ns("Do_PCA"), From 58e1e2e9e9cf323bf046d6610179bed01507961b Mon Sep 17 00:00:00 2001 From: PaulJonasJost Date: Wed, 23 Oct 2024 15:39:49 +0200 Subject: [PATCH 2/3] Added it to downloadable code --- program/shinyApp/R/fun_getCodeSnippets.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/program/shinyApp/R/fun_getCodeSnippets.R b/program/shinyApp/R/fun_getCodeSnippets.R index fbff02a9..35805a4d 100644 --- a/program/shinyApp/R/fun_getCodeSnippets.R +++ b/program/shinyApp/R/fun_getCodeSnippets.R @@ -235,7 +235,7 @@ lapply(ls(pattern="violin"), get) pca <- prcomp( x = as.data.frame(t(assay(res_tmp$data))), center = T, - scale. = FALSE + scale. = ifelse(par_tmp$PCA$scale_data == "Yes",T,F) ) pcaData <- data.frame(pca$x,colData(res_tmp$data)) From a26c6fc8c024998fb1a30a85ac1b0625aa4cb000 Mon Sep 17 00:00:00 2001 From: PaulJonasJost Date: Wed, 23 Oct 2024 15:44:33 +0200 Subject: [PATCH 3/3] Fixed small error regarding rds vs RDS files in code --- program/shinyApp/R/C.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/program/shinyApp/R/C.R b/program/shinyApp/R/C.R index 8e448533..b053fec0 100644 --- a/program/shinyApp/R/C.R +++ b/program/shinyApp/R/C.R @@ -34,7 +34,7 @@ MANUALLY <- FALSE # change to TRUE, if you want to set the paths manually if(MANUALLY){ # Adjust the path to the data file - envList <- readRDS('path/to/Data.rds') + envList <- readRDS('path/to/Data.RDS') # Adjust the path to the utils.R file source('path/to/utils.R') print('Path manually set') @@ -42,7 +42,7 @@ if(MANUALLY){ # if you get an error try to set paths manually # remember to set MANUALLY <- TRUE direcoty_of_files <- dirname(rstudioapi::getSourceEditorContext()$path) - envList <- readRDS(paste0(direcoty_of_files,'/','Data.rds')) + envList <- readRDS(paste0(direcoty_of_files,'/','Data.RDS')) if('utils.R' %in% list.files(direcoty_of_files)){ source(file.path(direcoty_of_files,'utils.R')) }