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) {
|
|
|
|
|
species_choices <- c("All species", names(options$species_sets))
|
|
|
|
|
gene_choices <- names(options$gene_sets)
|
|
|
|
|
|
|
|
|
|
if (!options$locked) {
|
|
|
|
|
species_choices <- c(species_choices, "Customize")
|
|
|
|
|
gene_choices <- c(gene_choices, "Customize")
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-21 14:56:19 +02:00
|
|
|
verticalLayout(
|
2021-11-15 10:22:28 +01:00
|
|
|
h3("Inputs"),
|
2021-10-21 14:56:19 +02:00
|
|
|
selectInput(
|
2021-11-15 10:22:28 +01:00
|
|
|
NS(id, "species"),
|
|
|
|
|
"Species to include",
|
2022-05-19 16:24:23 +02:00
|
|
|
choices = species_choices
|
2021-11-15 10:22:28 +01:00
|
|
|
),
|
2022-05-19 16:24:23 +02:00
|
|
|
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
|
|
|
selectInput(
|
|
|
|
|
NS(id, "reference_genes"),
|
|
|
|
|
"Reference genes",
|
2022-05-19 16:24:23 +02:00
|
|
|
choices = gene_choices
|
2021-11-15 10:22:28 +01:00
|
|
|
),
|
2022-05-19 16:24:23 +02:00
|
|
|
if (!options$locked) {
|
|
|
|
|
conditionalPanel(
|
|
|
|
|
condition = sprintf(
|
|
|
|
|
"input['%s'] == 'Customize'",
|
|
|
|
|
NS(id, "reference_genes")
|
|
|
|
|
),
|
|
|
|
|
gene_selector_ui(NS(id, "custom_genes"))
|
|
|
|
|
)
|
|
|
|
|
},
|
|
|
|
|
if (options$locked) {
|
|
|
|
|
HTML(
|
|
|
|
|
"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 ",
|
|
|
|
|
"<a href=\"https://code.johrpan.de/johrpan/tpeold\"",
|
|
|
|
|
"target=\"_blank\">this page</a> for more information."
|
2021-11-15 10:22:28 +01:00
|
|
|
)
|
2022-05-19 16:24:23 +02:00
|
|
|
}
|
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) {
|
2021-10-21 14:56:19 +02:00
|
|
|
moduleServer(id, function(input, output, session) {
|
2022-05-19 16:24:23 +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-19 16:24:23 +02:00
|
|
|
updateSelectizeInput(
|
|
|
|
|
session,
|
|
|
|
|
"custom_species",
|
|
|
|
|
choices = species_choices,
|
|
|
|
|
server = TRUE
|
|
|
|
|
)
|
2021-12-08 13:46:59 +01:00
|
|
|
|
2022-05-19 16:24:23 +02:00
|
|
|
gene_selector_server("custom_genes")
|
|
|
|
|
} else {
|
|
|
|
|
NULL
|
|
|
|
|
}
|
2022-01-26 14:48:29 +01:00
|
|
|
|
2022-01-23 19:46:17 +01:00
|
|
|
reactive({
|
2022-05-19 16:24:23 +02:00
|
|
|
reference_gene_ids <- if (input$reference_genes == "Customize") {
|
2022-01-26 14:48:29 +01:00
|
|
|
custom_gene_ids()
|
2022-05-19 16:24:23 +02:00
|
|
|
} else {
|
|
|
|
|
options$gene_sets[[input$reference_genes]]
|
2022-01-20 11:04:49 +01:00
|
|
|
}
|
|
|
|
|
|
2022-05-19 16:24:23 +02:00
|
|
|
species_ids <- if (input$species == "All species") {
|
2022-01-17 20:42:27 +01:00
|
|
|
geposan::species$id
|
2022-05-19 16:24:23 +02:00
|
|
|
} else if (input$species == "Customize") {
|
2021-11-18 14:10:06 +01:00
|
|
|
input$custom_species
|
2022-05-19 16:24:23 +02:00
|
|
|
} else {
|
|
|
|
|
options$species_sets[[input$species]]
|
2021-11-18 14:10:06 +01:00
|
|
|
}
|
|
|
|
|
|
2022-01-23 19:46:17 +01:00
|
|
|
tryCatch(
|
|
|
|
|
geposan::preset(
|
|
|
|
|
reference_gene_ids,
|
|
|
|
|
species_ids = species_ids
|
|
|
|
|
),
|
|
|
|
|
error = function(err) NULL
|
2021-11-15 10:22:28 +01:00
|
|
|
)
|
|
|
|
|
})
|
2021-10-21 14:56:19 +02:00
|
|
|
})
|
|
|
|
|
}
|