Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PCA scaling #346

Merged
merged 3 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions program/shinyApp/R/C.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ 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')
}else{
# 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'))
}
Expand Down
2 changes: 1 addition & 1 deletion program/shinyApp/R/fun_getCodeSnippets.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
9 changes: 6 additions & 3 deletions program/shinyApp/R/pca/server.R
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down
8 changes: 8 additions & 0 deletions program/shinyApp/R/pca/ui.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
Loading