diff --git a/R/server.R b/R/server.R index c39826e..f3f6290 100644 --- a/R/server.R +++ b/R/server.R @@ -105,24 +105,76 @@ server <- function(custom_dataset = NULL) { highlighted_genes = custom_genes() )) - selected_genes <- reactive({ + selected_top_genes <- reactive({ selected_points <- plotly::event_data("plotly_selected") ranked_data()[rank %in% selected_points$x] }) - genes_table_server("selected_genes", reactive({ - if (nrow(selected_genes()) > 0) { - selected_genes() + genes_table_server("selected_top_genes", reactive({ + if (nrow(selected_top_genes()) > 0) { + selected_top_genes() } else { ranked_data() } })) + output$rankings_plot <- plotly::renderPlotly({ + handle_axis <- function(ranking_id) { + if (ranking_id == "gtex_all") { + list( + ranking = rank_genes(ubigen::gtex_all), + label = "GTEx (across tissues and conditions)" + ) + } else if (ranking_id == "gtex_tissues") { + list( + ranking = rank_genes(ubigen::gtex_tissues), + label = "GTEx (across tissues)" + ) + } else if (ranking_id == "hpa_tissues") { + list( + ranking = rank_genes(ubigen::hpa_tissues), + label = "Human Protein Atlas (across tissues)" + ) + } else if (ranking_id == "cmap") { + list( + ranking = rank_genes(ubigen::cmap), + label = "CMap" + ) + } else { + list( + ranking = ranked_data(), + label = "Custom" + ) + } + } + + x <- handle_axis(input$ranking_x) + y <- handle_axis(input$ranking_y) + + rankings_comparison_plot( + x$ranking, + y$ranking, + label_x = x$label, + label_y = y$label, + highlighted_genes = custom_genes(), + use_percentiles = input$rankings_comparison_mode == "percentiles" + ) + }) + + selected_comparison_genes <- reactive({ + selected_points <- plotly::event_data("plotly_selected") + ranked_data()[gene %chin% selected_points$customdata] + }) + + genes_table_server("selected_comparison_genes", reactive({ + selected_comparison_genes() + })) + gsea_genes <- reactive({ sort(if (input$gsea_set == "top") { ranked_data()[rank >= input$gsea_ranks, gene] } else if (input$gsea_set == "selected") { - selected_genes()[, gene] + selected_top_genes()[, gene] } else { custom_genes() }) diff --git a/R/ui.R b/R/ui.R index d9152c8..d8d336f 100644 --- a/R/ui.R +++ b/R/ui.R @@ -126,7 +126,8 @@ ui <- function(custom_dataset = NULL) { value = "top_genes", div(paste0( "Hover over the markers to see details on each gene. Click ", - "or drag within the figure to select genes of interest." + "or drag within the figure to select genes of interest. ", + "Double-click removes the selection." )), plotly::plotlyOutput("scores_plot"), div(class = "p-1"), @@ -137,7 +138,67 @@ ui <- function(custom_dataset = NULL) { "on." )), div(class = "p-1"), - genes_table_ui("selected_genes") + genes_table_ui("selected_top_genes") + ), + tabPanel( + "Compare rankings", + value = "rankings", + div( + class = "flow-layout", + selectInput( + "ranking_y", + label = NULL, + list( + "Custom" = "custom", + "GTEx (across tissues and conditions)" = "gtex_all", + "GTEx (across tissues)" = "gtex_tissues", + "Human Protein Atlas (across tissues)" = "hpa_tissues", + "CMap" = "cmap" + ), + selected = "cmap" + ), + span( + style = paste0( + "display: inline-block;", + "margin-right: 12px;", + "padding: 0.375rem 0.75rem;" + ), + "~" + ), + selectInput( + "ranking_x", + label = NULL, + list( + "Custom" = "custom", + "GTEx (across tissues and conditions)" = "gtex_all", + "GTEx (across tissues)" = "gtex_tissues", + "Human Protein Atlas (across tissues)" = "hpa_tissues", + "CMap" = "cmap" + ) + ), + selectInput( + "rankings_comparison_mode", + label = NULL, + list( + "Compare scores" = "scores", + "Compare percentiles" = "percentiles" + ) + ) + ), + div(class = "p-1"), + div(paste0( + "Hover over the markers to see the HGNC symbols for the ", + "genes. Click or draw within the figure to select genes of ", + "interest. Double-click removes the selection." + )), + div(class = "p-1"), + plotly::plotlyOutput( + "rankings_plot", + width = "800px", + height = "800px" + ), + div(class = "p-1"), + genes_table_ui("selected_comparison_genes") ), tabPanel( "GSEA",