Skip to content

Commit

Permalink
[FEAT] - log transformation server logic
Browse files Browse the repository at this point in the history
  • Loading branch information
leopoldguyot committed Jul 17, 2024
1 parent 74aa9cd commit ec1e7f1
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 23 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
46 changes: 24 additions & 22 deletions R/interface_module_log_transform_tab.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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"
)
)
}
35 changes: 34 additions & 1 deletion R/server_module_log_transform_tab.R
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})
})
}
21 changes: 21 additions & 0 deletions R/utils_global.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

0 comments on commit ec1e7f1

Please sign in to comment.