Skip to content

Commit

Permalink
[FEAT] - Normalisation skeleton
Browse files Browse the repository at this point in the history
  • Loading branch information
leopoldguyot committed Jul 18, 2024
1 parent ec1e7f1 commit 3095aea
Show file tree
Hide file tree
Showing 6 changed files with 150 additions and 3 deletions.
2 changes: 1 addition & 1 deletion R/interface_module_box_readQFeatures.R
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ box_readqfeatures_ui <- function(id) {
),
checkboxInput(
inputId = NS(id, "singlecell"),
label = "Single cell data (WIP)",
label = "Single cell data",
value = FALSE
),
actionButton(
Expand Down
96 changes: 96 additions & 0 deletions R/interface_module_normalisation_tab.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
#' normalisation tab (section) ui builder
#'
#' @return A shiny tagList object that contains the normalisation tab UI components
#' @rdname INTERNAL_interface_module_normalisation_tab
#' @keywords internal
#'
#' @importFrom shiny fluidRow NS actionButton icon uiOutput
#' @importFrom shinydashboardPlus box
#' @importFrom htmltools tagList
#' @importFrom shinyBS bsTooltip
#'
interface_module_normalisation_tab <- function(id) {
tagList(
actionButton(
NS(id, "reload"),
"Load assays from previous step",
icon("hand-pointer", class = "fa-solid"),
width = "100%",
class = "load-button"
),
shinyBS::bsTooltip(
id = NS(id, "reload"),
title = paste("Load the assays from the previous step.",
"Click on this button the first time you visit this page",
"or if you updated the assays from the previous steps.",
sep = " "
),
trigger = "hover"
),
box(
title = "Normalisation",
status = "primary",
width = 12,
solidHeader = TRUE,
collapsible = FALSE,
fluidRow(
box(
title = "Prior Distribution",
status = "primary",
width = 5,
solidHeader = TRUE,
collapsible = TRUE,
withSpinner(plotlyOutput(outputId = NS(id, "prior_dist")),
type = 6,
color = "#3c8dbc"
)
),
box(
title = "Post Distribution",
status = "primary",
width = 5,
solidHeader = TRUE,
collapsible = TRUE,
withSpinner(plotlyOutput(outputId = NS(id, "post_dist")),
type = 6,
color = "#3c8dbc"
)
),
box(
title = "Normalisation Settings",
status = "primary",
width = 2,
solidHeader = TRUE,
collapsible = TRUE,
selectInput(inputId = NS(id, "method"),
label = "method",
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"
)
)
}
8 changes: 8 additions & 0 deletions R/server_dynamic_workflow.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ server_dynamic_workflow <- function(input, output, session) {
interface_module_log_transform_tab(
paste0("log_transform_", i)
)
} else if(global_rv$workflow_config[[i]] == "Normalisation") {
interface_module_normalisation_tab(
paste0("normalisation_", i)
)
}
)
})
Expand All @@ -66,6 +70,10 @@ server_dynamic_workflow <- function(input, output, session) {
server_module_log_transform_tab(paste0("log_transform_", i),
step_number = i
)
} else if(global_rv$workflow_config[[i]] == "Normalisation") {
server_module_normalisation_tab(paste0("normalisation_", i),
step_number = i
)
}
})
})
Expand Down
41 changes: 41 additions & 0 deletions R/server_module_normalisation_tab.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#' Server for the module normalisation tab
#'
#' @param id module id
#' @return The server logic for the normalisation tab
#' @rdname INTERNAL_server_module_normalisation_tab
#' @keywords internal
#'
#' @importFrom shiny moduleServer updateSelectInput observeEvent eventReactive is.reactive
#' @importFrom MultiAssayExperiment getWithColData
#'
server_module_normalisation_tab <- function(id, step_number) {
moduleServer(id, function(input, output, session) {
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({
return(assays_to_process())
})

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 = "normalisation"
)
removeModal()
})
})
}
3 changes: 2 additions & 1 deletion R/server_module_workflow_config.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ server_module_workflow_config <- function(id) {
choices = c(
"Samples Filtering",
"Features Filtering",
"Log Transformation"
"Log Transformation",
"Normalisation"
),
selected = selected,
width = "90%"
Expand Down
3 changes: 2 additions & 1 deletion R/utils_global.R
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,8 @@ add_assays_to_global_rv <- function(processed_qfeatures, step_number, type) {
#' @return `QFeatures` object with the log transformed assays
#' @rdname INTERNAL_log_transform_qfeatures
#' @keywords internal
#' @importFrom QFeatures logTransform QFeatures colData
#' @importFrom QFeatures logTransform QFeatures
#' @importFrom SummarizedExperiment colData
#'

log_transform_qfeatures <- function(qfeatures, base, pseudocount) {
Expand Down

0 comments on commit 3095aea

Please sign in to comment.