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. # Construct server for the methods editor.
# #
# @param analysis The reactive containing the results to be weighted. # @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. # @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) { moduleServer(id, function(input, output, session) {
observeEvent(input$optimize_button, { observeEvent(input$optimize_button, {
analysis <- analysis() analysis <- analysis()
@ -64,8 +62,7 @@ methods_server <- function(id, analysis, min_n_species) {
analysis, analysis,
method_ids, method_ids,
analysis$preset$reference_gene_ids, analysis$preset$reference_gene_ids,
target = input$target, target = input$target
min_n_species = min_n_species()
) )
for (method_id in method_ids) { 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. # Observe each method's enable button and synchronise the slider state.
lapply(methods, function(method) { lapply(methods, function(method) {
observeEvent(input[[method$id]], { observeEvent(input[[method$id]],
{ # nolint
shinyjs::toggleState(sprintf("%s_weight", method$id)) shinyjs::toggleState(sprintf("%s_weight", method$id))
}, ignoreInit = TRUE) },
ignoreInit = TRUE
)
}) })
reactive({ reactive({
@ -96,11 +96,7 @@ methods_server <- function(id, analysis, min_n_species) {
} }
} }
geposan::ranking( geposan::ranking(analysis(), weights)
analysis(),
weights,
min_n_species = min_n_species()
)
}) })
}) })
} }

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( selectInput(
NS(id, "reference_genes"), NS(id, "reference_genes"),
"Reference genes", "Reference genes",
@ -89,6 +97,7 @@ preset_editor_server <- function(id) {
methods = method_ids, methods = method_ids,
species_ids = species[replicative == TRUE, id], species_ids = species[replicative == TRUE, id],
gene_ids = genes$id, gene_ids = genes$id,
min_n_species = 10,
reference_gene_ids = genes[suggested | verified == TRUE, id] 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, { observeEvent(input$reference_genes, {
if (input$reference_genes == "custom") { if (input$reference_genes == "custom") {
updateTabsetPanel( updateTabsetPanel(
@ -125,14 +152,6 @@ preset_editor_server <- function(id) {
}) })
new_preset <- reactive({ 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") { reference_gene_ids <- if (input$reference_genes == "tpeold") {
genes[verified | suggested == TRUE, id] genes[verified | suggested == TRUE, id]
} else if (input$reference_genes == "verified") { } else if (input$reference_genes == "verified") {
@ -143,8 +162,9 @@ preset_editor_server <- function(id) {
geposan::preset( geposan::preset(
methods = method_ids, methods = method_ids,
species_ids = species_ids, species_ids = species_ids(),
gene_ids = genes$id, gene_ids = genes$id,
min_n_species = input$n_species,
reference_gene_ids = reference_gene_ids reference_gene_ids = reference_gene_ids
) )
}) })

View file

@ -10,15 +10,6 @@ js_link <- DT::JS("function(row, data) {
server <- function(input, output, session) { server <- function(input, output, session) {
preset <- preset_editor_server("preset_editor") 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. # Compute the results according to the preset.
analysis <- reactive({ analysis <- reactive({
preset <- preset() preset <- preset()
@ -37,10 +28,8 @@ server <- function(input, output, session) {
analysis analysis
}) })
min_n_species <- reactive(input$n_species)
# Rank the results. # Rank the results.
ranking <- methods_server("methods", analysis, min_n_species) ranking <- methods_server("methods", analysis)
# Add gene information to the results. # Add gene information to the results.
results <- reactive({ results <- reactive({

8
R/ui.R
View file

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