Move species count to preset

This commit is contained in:
Elias Projahn 2021-11-17 22:58:55 +01:00
parent 00fbdcac1f
commit a1807691d5
4 changed files with 39 additions and 42 deletions

View file

@ -43,11 +43,9 @@ methods_ui <- function(id) {
# Construct server for the methods editor.
#
# @param analysis The reactive containing the results to be weighted.
# @param min_n_species A reactive containing the minimum number of species to
# require for genes to be included in the ranking.
#
# @return A reactive containing the weighted results.
methods_server <- function(id, analysis, min_n_species) {
methods_server <- function(id, analysis) {
moduleServer(id, function(input, output, session) {
observeEvent(input$optimize_button, {
analysis <- analysis()
@ -64,8 +62,7 @@ methods_server <- function(id, analysis, min_n_species) {
analysis,
method_ids,
analysis$preset$reference_gene_ids,
target = input$target,
min_n_species = min_n_species()
target = input$target
)
for (method_id in method_ids) {
@ -79,9 +76,12 @@ methods_server <- function(id, analysis, min_n_species) {
# Observe each method's enable button and synchronise the slider state.
lapply(methods, function(method) {
observeEvent(input[[method$id]], {
observeEvent(input[[method$id]],
{ # nolint
shinyjs::toggleState(sprintf("%s_weight", method$id))
}, ignoreInit = TRUE)
},
ignoreInit = TRUE
)
})
reactive({
@ -96,11 +96,7 @@ methods_server <- function(id, analysis, min_n_species) {
}
}
geposan::ranking(
analysis(),
weights,
min_n_species = min_n_species()
)
geposan::ranking(analysis(), weights)
})
})
}

View file

@ -35,6 +35,14 @@ preset_editor_ui <- function(id) {
)
)
),
sliderInput(
NS(id, "n_species"),
"Required number of species per gene",
min = 0,
max = 18,
step = 1,
value = 10
),
selectInput(
NS(id, "reference_genes"),
"Reference genes",
@ -89,6 +97,7 @@ preset_editor_server <- function(id) {
methods = method_ids,
species_ids = species[replicative == TRUE, id],
gene_ids = genes$id,
min_n_species = 10,
reference_gene_ids = genes[suggested | verified == TRUE, id]
))
@ -108,6 +117,24 @@ preset_editor_server <- function(id) {
}
})
species_ids <- reactive({
if (input$species == "replicative") {
species[replicative == TRUE, id]
} else if (input$species == "all") {
species$id
} else {
input$custom_species
}
})
observeEvent(species_ids(), {
updateSliderInput(
session,
"n_species",
max = length(species_ids())
)
})
observeEvent(input$reference_genes, {
if (input$reference_genes == "custom") {
updateTabsetPanel(
@ -125,14 +152,6 @@ preset_editor_server <- function(id) {
})
new_preset <- reactive({
species_ids <- if (input$species == "replicative") {
species[replicative == TRUE, id]
} else if (input$species == "all") {
species$id
} else {
input$custom_species
}
reference_gene_ids <- if (input$reference_genes == "tpeold") {
genes[verified | suggested == TRUE, id]
} else if (input$reference_genes == "verified") {
@ -143,8 +162,9 @@ preset_editor_server <- function(id) {
geposan::preset(
methods = method_ids,
species_ids = species_ids,
species_ids = species_ids(),
gene_ids = genes$id,
min_n_species = input$n_species,
reference_gene_ids = reference_gene_ids
)
})

View file

@ -10,15 +10,6 @@ js_link <- DT::JS("function(row, data) {
server <- function(input, output, session) {
preset <- preset_editor_server("preset_editor")
observe({
species_count <- length(preset()$species_ids)
updateSliderInput(
session,
"n_species",
max = species_count
)
})
# Compute the results according to the preset.
analysis <- reactive({
preset <- preset()
@ -37,10 +28,8 @@ server <- function(input, output, session) {
analysis
})
min_n_species <- reactive(input$n_species)
# Rank the results.
ranking <- methods_server("methods", analysis, min_n_species)
ranking <- methods_server("methods", analysis)
# Add gene information to the results.
results <- reactive({

8
R/ui.R
View file

@ -7,14 +7,6 @@ ui <- fluidPage(
width = 3,
preset_editor_ui("preset_editor"),
filters_ui("filters"),
sliderInput(
"n_species",
"Required number of species per gene",
min = 0,
max = 18,
step = 1,
value = 10
),
methods_ui("methods")
),
mainPanel(