2022-01-23 19:46:17 +01:00
|
|
|
#' Create the UI for a preset editor.
|
|
|
|
|
#'
|
|
|
|
|
#' @param id ID for namespacing.
|
2022-05-19 16:24:23 +02:00
|
|
|
#' @param options Global options for the application.
|
|
|
|
|
#'
|
2022-01-23 19:46:17 +01:00
|
|
|
#' @return The UI elements.
|
|
|
|
|
#'
|
|
|
|
|
#' @noRd
|
2022-05-19 16:24:23 +02:00
|
|
|
preset_editor_ui <- function(id, options) {
|
2022-05-26 12:44:09 +02:00
|
|
|
species_choices <- c("All species", names(options$species_sets))
|
2022-08-18 09:02:53 +02:00
|
|
|
gene_choices <- names(options$reference_gene_sets)
|
2022-05-19 16:24:23 +02:00
|
|
|
|
2022-05-26 12:44:09 +02:00
|
|
|
if (!options$locked) {
|
|
|
|
|
species_choices <- c(species_choices, "Customize")
|
|
|
|
|
gene_choices <- c(gene_choices, "Customize")
|
|
|
|
|
}
|
2022-05-19 16:24:23 +02:00
|
|
|
|
2022-05-26 12:44:09 +02:00
|
|
|
verticalLayout(
|
2022-08-18 12:21:00 +02:00
|
|
|
h5("Inputs"),
|
2024-02-18 14:29:23 +01:00
|
|
|
popover(
|
|
|
|
|
title = "Species to include",
|
|
|
|
|
help = paste0(
|
|
|
|
|
"This can be used to limit the input dataset to a predefined set of ",
|
|
|
|
|
"species. Normally, it is reasonable to use all species. So, do not ",
|
|
|
|
|
"change this unless you have specific reasons to do so. The ",
|
|
|
|
|
"algorithms will automatically optimize the input dataset by ",
|
|
|
|
|
"excluding species that do not share enough genes."
|
|
|
|
|
),
|
|
|
|
|
div(class = "label", "Species to include")
|
|
|
|
|
),
|
2022-05-26 12:44:09 +02:00
|
|
|
selectInput(
|
|
|
|
|
NS(id, "species"),
|
2024-02-18 14:29:23 +01:00
|
|
|
label = NULL,
|
2022-05-26 12:44:09 +02:00
|
|
|
choices = species_choices
|
|
|
|
|
),
|
|
|
|
|
if (!options$locked) {
|
|
|
|
|
conditionalPanel(
|
|
|
|
|
condition = sprintf(
|
|
|
|
|
"input['%s'] == 'Customize'",
|
|
|
|
|
NS(id, "species")
|
|
|
|
|
),
|
|
|
|
|
selectizeInput(
|
|
|
|
|
inputId = NS(id, "custom_species"),
|
|
|
|
|
label = "Select input species",
|
|
|
|
|
choices = NULL,
|
|
|
|
|
multiple = TRUE
|
2021-11-15 10:22:28 +01:00
|
|
|
),
|
2022-05-26 12:44:09 +02:00
|
|
|
)
|
|
|
|
|
},
|
2024-02-18 14:29:23 +01:00
|
|
|
popover(
|
|
|
|
|
title = "Reference genes",
|
|
|
|
|
help = paste0(
|
|
|
|
|
"The reference genes are the main input to the computation. They are ",
|
|
|
|
|
"used for computing some of the scores and for optimizing the weights ",
|
|
|
|
|
"of the different methods."
|
|
|
|
|
),
|
|
|
|
|
div(class = "label", "Reference genes")
|
|
|
|
|
),
|
2022-05-26 12:44:09 +02:00
|
|
|
selectInput(
|
|
|
|
|
NS(id, "reference_genes"),
|
2024-02-18 14:29:23 +01:00
|
|
|
label = NULL,
|
2022-05-26 12:44:09 +02:00
|
|
|
choices = gene_choices
|
|
|
|
|
),
|
|
|
|
|
if (!options$locked) {
|
|
|
|
|
conditionalPanel(
|
|
|
|
|
condition = sprintf(
|
|
|
|
|
"input['%s'] == 'Customize'",
|
|
|
|
|
NS(id, "reference_genes")
|
2021-11-15 10:22:28 +01:00
|
|
|
),
|
2022-05-26 12:44:09 +02:00
|
|
|
gene_selector_ui(NS(id, "custom_genes"))
|
|
|
|
|
)
|
|
|
|
|
},
|
2024-02-13 16:53:58 +01:00
|
|
|
tabsetPanel(
|
|
|
|
|
id = NS(id, "error_panel"),
|
|
|
|
|
type = "hidden",
|
|
|
|
|
tabPanelBody(value = "hide"),
|
|
|
|
|
tabPanelBody(
|
|
|
|
|
value = "show",
|
|
|
|
|
div(
|
|
|
|
|
style = "color: red;",
|
|
|
|
|
htmlOutput(NS(id, "errors"))
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
),
|
|
|
|
|
tabsetPanel(
|
|
|
|
|
id = NS(id, "warning_panel"),
|
|
|
|
|
type = "hidden",
|
|
|
|
|
tabPanelBody(value = "hide"),
|
|
|
|
|
tabPanelBody(
|
|
|
|
|
value = "show",
|
|
|
|
|
div(
|
|
|
|
|
style = "color: orange;",
|
|
|
|
|
htmlOutput(NS(id, "warnings"))
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
),
|
2022-05-26 12:44:09 +02:00
|
|
|
if (options$locked) {
|
|
|
|
|
HTML(paste0(
|
|
|
|
|
"This instance prohibits performing custom analyses ",
|
|
|
|
|
"to reduce resource usage. Normally, it is possible ",
|
|
|
|
|
"to use this web application for analyzing any set of ",
|
|
|
|
|
"reference genes to find patterns in their ",
|
|
|
|
|
"chromosomal positions. If you would like to apply ",
|
|
|
|
|
"this method for your own research, see ",
|
2024-04-25 22:29:33 +02:00
|
|
|
"<a href=\"https://github.com/johrpan/geposanui/blob/main/README.md\" ",
|
|
|
|
|
"target=\"_blank\">this page</a> for ",
|
2022-05-26 12:44:09 +02:00
|
|
|
"more information."
|
|
|
|
|
))
|
|
|
|
|
}
|
|
|
|
|
)
|
2021-10-21 14:56:19 +02:00
|
|
|
}
|
|
|
|
|
|
2022-01-23 19:46:17 +01:00
|
|
|
#' Application logic for the preset editor.
|
|
|
|
|
#'
|
|
|
|
|
#' @param id ID for namespacing the inputs and outputs.
|
2022-05-19 16:24:23 +02:00
|
|
|
#' @param options Global application options.
|
|
|
|
|
#'
|
2022-01-23 19:46:17 +01:00
|
|
|
#' @return A reactive containing the preset or `NULL`, if the input data doesn't
|
|
|
|
|
#' result in a valid one.
|
|
|
|
|
#'
|
|
|
|
|
#' @noRd
|
2022-05-19 16:24:23 +02:00
|
|
|
preset_editor_server <- function(id, options) {
|
2022-05-26 12:44:09 +02:00
|
|
|
moduleServer(id, function(input, output, session) {
|
2024-02-13 16:53:58 +01:00
|
|
|
preset_errors <- reactiveVal(character())
|
|
|
|
|
preset_warnings <- reactiveVal(character())
|
|
|
|
|
|
|
|
|
|
output$errors <- renderUI({
|
|
|
|
|
HTML(paste(preset_errors(), collapse = "<br>"))
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
output$warnings <- renderUI({
|
|
|
|
|
HTML(paste(preset_warnings(), collapse = "<br>"))
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
observe({
|
|
|
|
|
updateTabsetPanel(
|
|
|
|
|
session,
|
|
|
|
|
"error_panel",
|
|
|
|
|
selected = if (is.null(preset_errors())) "hide" else "show"
|
|
|
|
|
)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
observe({
|
|
|
|
|
updateTabsetPanel(
|
|
|
|
|
session,
|
|
|
|
|
"warning_panel",
|
|
|
|
|
selected = if (is.null(preset_warnings())) "hide" else "show"
|
|
|
|
|
)
|
|
|
|
|
})
|
|
|
|
|
|
2022-05-26 12:44:09 +02:00
|
|
|
custom_gene_ids <- if (!options$locked) {
|
|
|
|
|
species_choices <- geposan::species$id
|
|
|
|
|
names(species_choices) <- geposan::species$name
|
2021-12-08 13:46:59 +01:00
|
|
|
|
2022-05-26 12:44:09 +02:00
|
|
|
updateSelectizeInput(
|
|
|
|
|
session,
|
|
|
|
|
"custom_species",
|
|
|
|
|
choices = species_choices,
|
|
|
|
|
server = TRUE
|
|
|
|
|
)
|
2021-12-08 13:46:59 +01:00
|
|
|
|
2022-05-26 12:44:09 +02:00
|
|
|
gene_selector_server("custom_genes")
|
|
|
|
|
} else {
|
|
|
|
|
NULL
|
|
|
|
|
}
|
2022-01-26 14:48:29 +01:00
|
|
|
|
2022-05-26 12:44:09 +02:00
|
|
|
reactive({
|
|
|
|
|
reference_gene_ids <- if (input$reference_genes == "Customize") {
|
|
|
|
|
custom_gene_ids()
|
|
|
|
|
} else {
|
2022-08-18 09:02:53 +02:00
|
|
|
options$reference_gene_sets[[input$reference_genes]]
|
2022-05-26 12:44:09 +02:00
|
|
|
}
|
2022-01-20 11:04:49 +01:00
|
|
|
|
2022-05-26 12:44:09 +02:00
|
|
|
species_ids <- if (input$species == "All species") {
|
|
|
|
|
geposan::species$id
|
|
|
|
|
} else if (input$species == "Customize") {
|
|
|
|
|
input$custom_species
|
|
|
|
|
} else {
|
|
|
|
|
options$species_sets[[input$species]]
|
|
|
|
|
}
|
2021-11-18 14:10:06 +01:00
|
|
|
|
2024-02-13 16:53:58 +01:00
|
|
|
new_errors <- character()
|
|
|
|
|
new_warnings <- character()
|
|
|
|
|
|
|
|
|
|
preset <- withCallingHandlers(
|
|
|
|
|
tryCatch(
|
|
|
|
|
geposan::preset(
|
|
|
|
|
reference_gene_ids,
|
|
|
|
|
species_ids = species_ids,
|
|
|
|
|
methods = options$methods
|
|
|
|
|
),
|
|
|
|
|
error = function(e) {
|
|
|
|
|
new_errors <<- c(new_errors, e$message)
|
|
|
|
|
NULL
|
|
|
|
|
}
|
2022-05-26 12:44:09 +02:00
|
|
|
),
|
2024-02-13 16:53:58 +01:00
|
|
|
warning = function(w) {
|
|
|
|
|
new_warnings <<- c(new_warnings, w$message)
|
|
|
|
|
}
|
2022-05-26 12:44:09 +02:00
|
|
|
)
|
2024-02-13 16:53:58 +01:00
|
|
|
|
|
|
|
|
preset_errors(new_errors)
|
|
|
|
|
preset_warnings(new_warnings)
|
|
|
|
|
|
|
|
|
|
if (length(new_errors) >= 1) {
|
|
|
|
|
NULL
|
|
|
|
|
} else {
|
|
|
|
|
preset
|
|
|
|
|
}
|
2021-10-21 14:56:19 +02:00
|
|
|
})
|
2022-05-26 12:44:09 +02:00
|
|
|
})
|
2021-10-21 14:56:19 +02:00
|
|
|
}
|