From 527ba01cc9adbbe103df606ea4cd420b316658fc Mon Sep 17 00:00:00 2001 From: Elias Projahn Date: Fri, 15 Oct 2021 13:16:51 +0200 Subject: [PATCH] Add rank plot --- rank_plot.R | 36 ++++++++++++++++++++++++++++++++++++ server.R | 6 ++++++ ui.R | 6 ++++++ 3 files changed, 48 insertions(+) create mode 100644 rank_plot.R diff --git a/rank_plot.R b/rank_plot.R new file mode 100644 index 0000000..efea50e --- /dev/null +++ b/rank_plot.R @@ -0,0 +1,36 @@ +library(data.table) +library(plotly) + +#' Draw a plot displaying the rank of reference genes. +#' +#' The input table should contain the following columns: +#' +#' - `gene` Gene IDs of genes to display. +#' - `name` Name of genes to display. +#' - `score` Score of the genes. +#' - `rank` Rank of the genes based on the score. +#' +#' @param results Results to display. +#' @param reference_gene_ids IDs of reference genes. +rank_plot <- function(results, reference_gene_ids) { + plot <- plot_ly() |> add_trace( + data = results, + x = ~rank, + y = ~score, + name = "All genes", + type = "scatter", + mode = "line", + hoverinfo = "skip" + ) |> add_trace( + data = results[gene %chin% reference_gene_ids], + x = ~rank, + y = ~score, + color = ~gene, + name = ~name, + width = 10, + type = "bar" + ) |> layout( + xaxis = list(title = "Ranks"), + yaxis = list(title = "Score") + ) +} \ No newline at end of file diff --git a/server.R b/server.R index 59070a1..c6ba4f9 100644 --- a/server.R +++ b/server.R @@ -6,6 +6,7 @@ library(rclipboard) library(shiny) source("init.R") +source("rank_plot.R") source("scatter_plot.R") #' Java script function to replace gene IDs with Ensembl gene links. @@ -83,6 +84,11 @@ server <- function(input, output) { results[, rank := .I] }) + output$rank_plot <- renderPlotly({ + results <- results() + rank_plot(results, genes[suggested | verified == TRUE, id]) + }) + output$genes <- renderDT({ method_ids <- sapply(methods, function(method) method$id) method_names <- sapply(methods, function(method) method$name) diff --git a/ui.R b/ui.R index 5e72b39..147f048 100644 --- a/ui.R +++ b/ui.R @@ -48,6 +48,12 @@ ui <- fluidPage( ), ), mainPanel( + h3("Gene ranks"), + plotlyOutput( + "rank_plot", + width = "100%", + height = "600px" + ), h3("Results"), textOutput("synposis"), div(