2021-10-21 14:56:19 +02:00
|
|
|
# Create a preset editor.
|
|
|
|
|
preset_editor_ui <- function(id) {
|
|
|
|
|
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",
|
2021-10-21 14:56:19 +02:00
|
|
|
choices = list(
|
|
|
|
|
"All species" = "all",
|
2021-11-23 16:51:55 +01:00
|
|
|
"Known replicatively aging species" = "replicative",
|
2021-10-21 14:56:19 +02:00
|
|
|
"Customize" = "custom"
|
|
|
|
|
)
|
|
|
|
|
),
|
2021-12-08 13:46:59 +01:00
|
|
|
conditionalPanel(
|
|
|
|
|
condition = sprintf("input['%s'] == 'custom'", 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",
|
|
|
|
|
choices = list(
|
|
|
|
|
"Verified or suggested TPE-OLD genes" = "tpeold",
|
|
|
|
|
"Only verified TPE-OLD genes" = "verified",
|
|
|
|
|
"Customize" = "custom"
|
|
|
|
|
)
|
|
|
|
|
),
|
2021-12-08 13:46:59 +01:00
|
|
|
conditionalPanel(
|
|
|
|
|
condition = sprintf(
|
|
|
|
|
"input['%s'] == 'custom'",
|
|
|
|
|
NS(id, "reference_genes")
|
|
|
|
|
),
|
2021-12-15 12:41:35 +01:00
|
|
|
selectInput(
|
|
|
|
|
NS(id, "identifier_type"),
|
|
|
|
|
"Gene identifiers",
|
|
|
|
|
choices = list(
|
|
|
|
|
"HGNC symbols" = "hgnc",
|
|
|
|
|
"Ensembl gene IDs" = "ensembl"
|
|
|
|
|
)
|
|
|
|
|
),
|
|
|
|
|
textAreaInput(
|
2021-12-08 13:46:59 +01:00
|
|
|
inputId = NS(id, "custom_reference_genes"),
|
2021-12-15 12:41:35 +01:00
|
|
|
label = "Enter reference genes",
|
|
|
|
|
height = "250px"
|
2021-11-15 10:22:28 +01:00
|
|
|
)
|
|
|
|
|
),
|
|
|
|
|
tabsetPanel(
|
|
|
|
|
id = NS(id, "apply_panel"),
|
|
|
|
|
type = "hidden",
|
|
|
|
|
tabPanelBody(value = "hide"),
|
|
|
|
|
tabPanelBody(
|
|
|
|
|
value = "show",
|
2021-11-02 14:42:52 +01:00
|
|
|
actionButton(
|
|
|
|
|
NS(id, "apply_button"),
|
|
|
|
|
"Perform analysis",
|
|
|
|
|
class = "btn-primary",
|
|
|
|
|
style = "margin-top: 16px; margin-bottom: 16px"
|
|
|
|
|
)
|
2021-10-21 14:56:19 +02:00
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Create a server for the preset editor.
|
|
|
|
|
#
|
|
|
|
|
# @param id ID for namespacing the inputs and outputs.
|
|
|
|
|
#
|
|
|
|
|
# @return A reactive containing the preset.
|
|
|
|
|
preset_editor_server <- function(id) {
|
|
|
|
|
moduleServer(id, function(input, output, session) {
|
2022-01-17 20:42:27 +01:00
|
|
|
species_choices <- geposan::species$id
|
|
|
|
|
names(species_choices) <- geposan::species$name
|
2021-12-08 13:46:59 +01:00
|
|
|
|
|
|
|
|
updateSelectizeInput(
|
|
|
|
|
session,
|
|
|
|
|
"custom_species",
|
|
|
|
|
choices = species_choices,
|
|
|
|
|
server = TRUE
|
|
|
|
|
)
|
|
|
|
|
|
2021-11-15 10:22:28 +01:00
|
|
|
current_preset <- reactiveVal(geposan::preset(
|
2022-01-17 20:42:27 +01:00
|
|
|
genes[suggested | verified == TRUE, id]
|
2021-11-15 10:22:28 +01:00
|
|
|
))
|
2021-10-21 14:56:19 +02:00
|
|
|
|
2022-01-20 11:04:49 +01:00
|
|
|
# Reactive containing the latest valid set of reference genes.
|
|
|
|
|
reference_gene_ids <- reactiveVal(
|
|
|
|
|
genes[verified | suggested == TRUE, id]
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
observeEvent(c(input$reference_genes, input$custom_reference_genes), {
|
|
|
|
|
if (input$reference_genes == "custom") {
|
|
|
|
|
inputs <- strsplit(input$custom_reference_genes, "\\s+")[[1]]
|
|
|
|
|
|
|
|
|
|
gene_ids <- if (input$identifier_type == "hgnc") {
|
|
|
|
|
geposan::genes[name %chin% inputs, id]
|
|
|
|
|
} else {
|
|
|
|
|
geposan::genes[id %chin% inputs, id]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (length(gene_ids) >= 5) {
|
|
|
|
|
reference_gene_ids(gene_ids)
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
reference_gene_ids(if (input$reference_genes == "tpeold") {
|
|
|
|
|
genes[verified | suggested == TRUE, id]
|
|
|
|
|
} else if (input$reference_genes == "verified") {
|
|
|
|
|
genes[verified == TRUE, id]
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
2021-11-15 10:22:28 +01:00
|
|
|
new_preset <- reactive({
|
2021-11-18 14:10:06 +01:00
|
|
|
species_ids <- if (input$species == "replicative") {
|
2022-01-17 20:42:27 +01:00
|
|
|
species_ids_replicative
|
2021-11-18 14:10:06 +01:00
|
|
|
} else if (input$species == "all") {
|
2022-01-17 20:42:27 +01:00
|
|
|
geposan::species$id
|
2021-11-18 14:10:06 +01:00
|
|
|
} else {
|
|
|
|
|
input$custom_species
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-15 10:22:28 +01:00
|
|
|
geposan::preset(
|
2022-01-20 11:04:49 +01:00
|
|
|
reference_gene_ids(),
|
2021-12-16 13:52:14 +01:00
|
|
|
methods = methods,
|
2021-11-18 14:10:06 +01:00
|
|
|
species_ids = species_ids,
|
2022-01-17 20:36:34 +01:00
|
|
|
gene_ids = genes$id
|
2021-11-15 10:22:28 +01:00
|
|
|
)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
observeEvent(
|
|
|
|
|
{ # nolint
|
|
|
|
|
current_preset()
|
|
|
|
|
new_preset()
|
|
|
|
|
},
|
|
|
|
|
{ # nolint
|
|
|
|
|
if (rlang::hash(new_preset()) !=
|
|
|
|
|
rlang::hash(current_preset())) {
|
|
|
|
|
updateTabsetPanel(
|
|
|
|
|
session,
|
|
|
|
|
"apply_panel",
|
|
|
|
|
selected = "show"
|
|
|
|
|
)
|
|
|
|
|
} else {
|
|
|
|
|
updateTabsetPanel(
|
|
|
|
|
session,
|
|
|
|
|
"apply_panel",
|
|
|
|
|
selected = "hide"
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
observeEvent(input$apply_button, {
|
|
|
|
|
current_preset(new_preset())
|
2021-10-21 14:56:19 +02:00
|
|
|
})
|
|
|
|
|
|
2021-11-15 10:22:28 +01:00
|
|
|
current_preset
|
2021-10-21 14:56:19 +02:00
|
|
|
})
|
|
|
|
|
}
|