diff --git a/NAMESPACE b/NAMESPACE index d8269a9..d31c87d 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -11,6 +11,7 @@ importFrom(MultiAssayExperiment,getWithColData) importFrom(QFeatures,QFeatures) importFrom(QFeatures,addAssayLink) importFrom(QFeatures,filterFeatures) +importFrom(QFeatures,logTransform) importFrom(QFeatures,readQFeatures) importFrom(QFeatures,zeroIsNA) importFrom(RColorBrewer,brewer.pal) diff --git a/R/interface_module_log_transform_tab.R b/R/interface_module_log_transform_tab.R index bbea45d..170b39f 100644 --- a/R/interface_module_log_transform_tab.R +++ b/R/interface_module_log_transform_tab.R @@ -27,28 +27,7 @@ interface_module_log_transform_tab <- function(id) { ), trigger = "hover" ), - interface_box_distribution("box_distribution"), - actionButton( - NS(id, "export"), - "Save the processed assays", - icon("hand-pointer", class = "fa-solid"), - width = "100%", - class = "load-button" - ), - shinyBS::bsTooltip( - id = NS(id, "export"), - title = paste("Write the processed assays to the QFeatures object.", - "This is needed to proceed to the next steps.", - sep = " " - ), - trigger = "hover", - placement = "top" - ) - ) -} - -interface_box_distribution <- function(id) { - box( + box( title = "Log Transformation", status = "primary", width = 12, @@ -87,8 +66,31 @@ interface_box_distribution <- function(id) { label = "Log Base", choices = c(2, 10), selected = 2 + ), + numericInput(inputId = NS(id, "pseudocount"), + label = "Pseudocount", + value = 0, + min = 0, + step = 1 ) ) ) + ), + actionButton( + NS(id, "export"), + "Save the processed assays", + icon("hand-pointer", class = "fa-solid"), + width = "100%", + class = "load-button" + ), + shinyBS::bsTooltip( + id = NS(id, "export"), + title = paste("Write the processed assays to the QFeatures object.", + "This is needed to proceed to the next steps.", + sep = " " + ), + trigger = "hover", + placement = "top" + ) ) } diff --git a/R/server_module_log_transform_tab.R b/R/server_module_log_transform_tab.R index 7f89ba5..b0f7e63 100644 --- a/R/server_module_log_transform_tab.R +++ b/R/server_module_log_transform_tab.R @@ -10,6 +10,39 @@ #' server_module_log_transform_tab <- function(id, step_number) { moduleServer(id, function(input, output, session) { - return(NULL) + assays_to_process <- eventReactive(input$reload, { + error_handler(page_assays_subset, + component_name = "Page assays subset", + qfeatures = global_rv$qfeatures, + pattern = paste0("_(QFeaturesGUI#", step_number - 1, ")") + ) + }) + + processed_assays <- reactive({ + req(assays_to_process()) + error_handler( + log_transform_qfeatures, + component_name = "Log transformation", + qfeatures = assays_to_process(), + base = as.integer(input$log_base), + pseudocount = as.integer(input$pseudocount) + ) + }) + + observeEvent(input$export, { + req(processed_assays()) + loading(paste("Be aware that this operation", + "can be quite time consuming for large data sets", + sep = " " + )) + error_handler( + add_assays_to_global_rv, + component_name = "Add assays to global_rv", + processed_qfeatures = processed_assays(), + step_number = step_number, + type = "log_transformation" + ) + removeModal() + }) }) } \ No newline at end of file diff --git a/R/utils_global.R b/R/utils_global.R index 558b6fc..83cd6a2 100644 --- a/R/utils_global.R +++ b/R/utils_global.R @@ -339,3 +339,24 @@ add_assays_to_global_rv <- function(processed_qfeatures, step_number, type) { ) } } + + +#' A function that will logTransform all the assays of a qfeatures +#' @param qfeatures `QFeatures` object to logTransform +#' @param base `numeric` base of the log transformation +#' @param pseudocount `numeric` pseudocount to add to the data +#' @return `QFeatures` object with the log transformed assays +#' @rdname INTERNAL_log_transform_qfeatures +#' @keywords internal +#' @importFrom QFeatures logTransform QFeatures colData +#' + +log_transform_qfeatures <- function(qfeatures, base, pseudocount) { + el <- lapply(names(qfeatures), function(name) { + QFeatures::logTransform(object = qfeatures[[name]], + base = base, + pc = pseudocount) + }) + names(el) <- names(qfeatures) + QFeatures(el, colData = colData(qfeatures)) + } \ No newline at end of file