From 4e31d4ef794a0bf1abeec53cc1ab7aee819b7156 Mon Sep 17 00:00:00 2001 From: Elias Projahn Date: Sun, 14 Aug 2022 18:04:40 +0200 Subject: [PATCH] Add rankings correlation plot --- R/server.R | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ R/ui.R | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 101 insertions(+), 1 deletion(-) diff --git a/R/server.R b/R/server.R index c1ce3a9..33b17e1 100644 --- a/R/server.R +++ b/R/server.R @@ -116,6 +116,54 @@ server <- function(options) { geposan::plot_rankings(rankings, gene_sets) }) + output$ranking_correlation_plot <- plotly::renderPlotly({ + preset <- preset() + ranking <- ranking() + + ranking_x <- if (input$ranking_x == "combined") { + ranking + } else { + weights <- list() + weights[[input$ranking_x]] <- 1.0 + geposan::ranking(ranking, weights) + } + + ranking_y <- if (input$ranking_y == "combined") { + ranking + } else { + weights <- list() + weights[[input$ranking_y]] <- 1.0 + geposan::ranking(ranking, weights) + } + + gene_sets <- list("Reference genes" = preset$reference_gene_ids) + comparison_gene_ids <- comparison_gene_ids() + + if (length(comparison_gene_ids) >= 1) { + gene_sets <- c( + gene_sets, + list("Comparison genes" = comparison_gene_ids) + ) + } + + method_names <- geposan::all_methods() |> purrr::lmap(function(method) { + l <- list() + l[[method[[1]]$id]] <- method[[1]]$name + l + }) + + method_names[["combined"]] <- "Combined" + + geposan::plot_rankings_correlation( + ranking_x, + ranking_y, + method_names[[input$ranking_x]], + method_names[[input$ranking_y]], + gene_sets = gene_sets, + use_ranks = input$use_ranks + ) + }) + output$comparison_text <- renderUI({ reference <- geposan::compare( ranking(), diff --git a/R/ui.R b/R/ui.R index e1179a1..a84d05b 100644 --- a/R/ui.R +++ b/R/ui.R @@ -4,6 +4,14 @@ #' #' @noRd ui <- function(options) { + ranking_choices <- purrr::lmap(geposan::all_methods(), function(method) { + l <- list() + l[[method[[1]]$name]] <- method[[1]]$id + l + }) + + ranking_choices <- c(ranking_choices, "Combined" = "combined") + div( custom_css(), shinyjs::useShinyjs(), @@ -46,7 +54,7 @@ ui <- function(options) { ) ), tabPanel( - title = "Methods & Distribution", + title = "Method comparison", div( style = "margin-top: 16px", plotly::plotlyOutput( @@ -56,6 +64,50 @@ ui <- function(options) { ) ) ), + tabPanel( + title = "Method correlation", + div( + style = "margin-top: 16px", + div( + class = "flow-layout", + selectInput( + "ranking_y", + label = NULL, + choices = ranking_choices + ), + span( + style = paste0( + "display: inline-block;", + "margin-right: 12px;", + "padding: 0.375rem 0.75rem;" + ), + "~" + ), + selectInput( + "ranking_x", + label = NULL, + choices = ranking_choices, + selected = "combined" + ), + div( + style = paste0( + "display: inline-block;", + "padding: 0.375rem 0.75rem;" + ), + checkboxInput( + "use_ranks", + "Use ranks instead of scores", + value = TRUE + ) + ) + ), + plotly::plotlyOutput( + "ranking_correlation_plot", + width = "100%", + height = "600px" + ) + ) + ), tabPanel( title = "Comparison", div(