From 663128271ea6749e632a1b83c8b55b3d11b79887 Mon Sep 17 00:00:00 2001 From: Elias Projahn Date: Wed, 15 Dec 2021 12:41:35 +0100 Subject: [PATCH] Allow manually entering genes --- R/comparison_editor.R | 33 +++++++++++++++++---------------- R/preset_editor.R | 33 +++++++++++++++++---------------- 2 files changed, 34 insertions(+), 32 deletions(-) diff --git a/R/comparison_editor.R b/R/comparison_editor.R index d5ddfd6..f7e818c 100644 --- a/R/comparison_editor.R +++ b/R/comparison_editor.R @@ -19,11 +19,18 @@ comparison_editor_ui <- function(id) { "input['%s'] == 'custom'", NS(id, "comparison_genes") ), - selectizeInput( + selectInput( + NS(id, "identifier_type"), + "Gene identifiers", + choices = list( + "HGNC symbols" = "hgnc", + "Ensembl gene IDs" = "ensembl" + ) + ), + textAreaInput( inputId = NS(id, "custom_comparison_genes"), - label = "Select comparison genes", - choices = NULL, - multiple = TRUE + label = "Enter comparison genes", + height = "250px" ) ) ) @@ -37,17 +44,6 @@ comparison_editor_ui <- function(id) { # @return A reactive containing the comparison gene IDs. comparison_editor_server <- function(id, preset) { moduleServer(id, function(input, output, session) { - known_genes <- genes[name != ""] - gene_choices <- known_genes$id - names(gene_choices) <- known_genes$name - - updateSelectizeInput( - session, - "custom_comparison_genes", - choices = gene_choices, - server = TRUE - ) - reactive({ if (input$comparison_genes == "none") { NULL @@ -64,7 +60,12 @@ comparison_editor_server <- function(id, preset) { } else if (input$comparison_genes == "suggested") { genes[suggested == TRUE, id] } else { - input$custom_comparison_genes + inputs <- strsplit(input$custom_comparison_genes, "\\s+")[[1]] + if (input$identifier_type == "hgnc") { + geposan::genes[name %chin% inputs, id] + } else { + geposan::genes[id %chin% inputs, id] + } } }) }) diff --git a/R/preset_editor.R b/R/preset_editor.R index 7f6760b..b4afcf8 100644 --- a/R/preset_editor.R +++ b/R/preset_editor.R @@ -34,11 +34,18 @@ preset_editor_ui <- function(id) { "input['%s'] == 'custom'", NS(id, "reference_genes") ), - selectizeInput( + selectInput( + NS(id, "identifier_type"), + "Gene identifiers", + choices = list( + "HGNC symbols" = "hgnc", + "Ensembl gene IDs" = "ensembl" + ) + ), + textAreaInput( inputId = NS(id, "custom_reference_genes"), - label = "Select reference genes", - choices = NULL, - multiple = TRUE + label = "Enter reference genes", + height = "250px" ) ), selectInput( @@ -78,10 +85,6 @@ preset_editor_server <- function(id) { species_choices <- species$id names(species_choices) <- species$name - known_genes <- genes[name != ""] - gene_choices <- known_genes$id - names(gene_choices) <- known_genes$name - updateSelectizeInput( session, "custom_species", @@ -89,13 +92,6 @@ preset_editor_server <- function(id) { server = TRUE ) - updateSelectizeInput( - session, - "custom_reference_genes", - choices = gene_choices, - server = TRUE - ) - current_preset <- reactiveVal(geposan::preset( methods = method_ids, species_ids = species$id, @@ -118,7 +114,12 @@ preset_editor_server <- function(id) { } else if (input$reference_genes == "verified") { genes[verified == TRUE, id] } else { - input$custom_reference_genes + inputs <- strsplit(input$custom_reference_genes, "\\s+")[[1]] + if (input$identifier_type == "hgnc") { + geposan::genes[name %chin% inputs, id] + } else { + geposan::genes[id %chin% inputs, id] + } } geposan::preset(