diff --git a/R/interface_module_box_readscp.R b/R/interface_module_box_readscp.R index c0f88b9..7fa66a8 100644 --- a/R/interface_module_box_readscp.R +++ b/R/interface_module_box_readscp.R @@ -54,6 +54,11 @@ box_readscp_ui <- function(id) { label = "Convert zeros to NA", value = TRUE ), + checkboxInput( + inputId = NS(id, "singlecell"), + label = "Single cell data", + value = FALSE + ), actionButton( inputId = NS(id, "convert"), "Convert to a QFeatures object" diff --git a/R/interface_module_qc_metrics.R b/R/interface_module_qc_metrics.R index 3b1012b..54e450a 100644 --- a/R/interface_module_qc_metrics.R +++ b/R/interface_module_qc_metrics.R @@ -91,6 +91,16 @@ interface_module_pca_box <- function(id, title) { label = "Color by", choices = NULL ), + checkboxInput( + inputId = NS(id, "scale"), + label = "Scale data", + value = TRUE + ), + checkboxInput( + inputId = NS(id, "center"), + label = "Center data", + value = TRUE + ), checkboxInput( inputId = NS(id, "show_legend"), label = "Show Legend", diff --git a/R/server_module_qc_metrics.R b/R/server_module_qc_metrics.R index e56fc9a..e39bb6e 100644 --- a/R/server_module_qc_metrics.R +++ b/R/server_module_qc_metrics.R @@ -62,7 +62,7 @@ server_module_qc_metrics <- function(id, assays_to_process, type) { #' @importFrom pcaMethods pca scores #' @importFrom methods is #' -server_module_pca_box <- function(id, single_assay, method, transpose) { +server_module_pca_box <- function(id, single_assay, method, transpose) { moduleServer(id, function(input, output, session) { annotation_names <- reactive({ req(single_assay()) @@ -104,12 +104,15 @@ server_module_pca_box <- function(id, single_assay, method, transpose) { return(df) }) + pca_result <- reactive({ req(single_assay()) pcaMethods_wrapper( single_assay(), method = method, - transpose = transpose + transpose = transpose, + scale = input$scale, + center = input$center ) }) dataframe <- reactive({ diff --git a/R/server_module_summary_tab.R b/R/server_module_summary_tab.R index 9c5ebbd..fb0035e 100644 --- a/R/server_module_summary_tab.R +++ b/R/server_module_summary_tab.R @@ -62,7 +62,7 @@ server_module_summary_tab <- function(id) { output$download_qfeatures <- downloadHandler( filename = function() { - "scp_qfeature_object.rds" + "qfeatures_object.rds" }, content = function(file) { saveRDS(global_rv$qfeatures, file) diff --git a/R/utils_global.R b/R/utils_global.R index 3b8d6c9..3df1008 100644 --- a/R/utils_global.R +++ b/R/utils_global.R @@ -166,6 +166,8 @@ remove_scpGUI <- function(string) { #' #' @param sce A SingleCellExperiment object. The PCA is performed on the assay of this object. #' @param method A character string specifying the PCA method to use. This should be one of the methods supported by the pcaMethods package. +#' @param center A logical indicating whether the variables should be centered before PCA. +#' @param scale A logical indicating whether the variables should be scaled before PCA. #' #' @return A pcaRes object resulting from the PCA. #' @rdname INTERNAL_pcaMethods_wrapper @@ -174,15 +176,19 @@ remove_scpGUI <- function(string) { #' @importFrom pcaMethods pca #' @importFrom SummarizedExperiment assay #' -pcaMethods_wrapper <- function(sce, method, transpose = FALSE) { +pcaMethods_wrapper <- function(sce, method, center, scale, transpose = FALSE) { mat <- assay(sce) mat <- mat[rowSums(is.na(mat)) != ncol(mat), ] mat <- mat[, colSums(is.na(mat)) < nrow(mat)] + if (scale) { + mat <- scale(mat) + } if (transpose) { mat <- t(mat) } pca <- pcaMethods::pca(mat, - method = method + method = method, + center = center ) pca }