From b5957262a3368cd38a556ef31c272f7e39129da3 Mon Sep 17 00:00:00 2001 From: Elias Projahn Date: Mon, 15 Nov 2021 09:35:47 +0100 Subject: [PATCH] Use plots from geposan --- R/rank_plot.R | 53 --------------------------------------------------- R/server.R | 17 +++++++++++++---- R/ui.R | 8 ++++++++ 3 files changed, 21 insertions(+), 57 deletions(-) delete mode 100644 R/rank_plot.R diff --git a/R/rank_plot.R b/R/rank_plot.R deleted file mode 100644 index f9a847a..0000000 --- a/R/rank_plot.R +++ /dev/null @@ -1,53 +0,0 @@ -# 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. -# @param max_rank Last rank of the included genes. -rank_plot <- function(results, reference_gene_ids, max_rank) { - plot <- plotly::plot_ly() |> plotly::add_trace( - data = results, - x = ~rank, - y = ~score, - name = "All genes", - type = "scatter", - mode = "line", - hoverinfo = "skip" - ) |> plotly::add_trace( - data = results[gene %chin% reference_gene_ids], - x = ~rank, - y = ~score, - color = ~gene, - name = ~name, - width = 10, - type = "bar" - ) |> plotly::layout( - xaxis = list(title = "Ranks"), - yaxis = list(title = "Score") - ) - - first_not_included_rank <- max_rank + 1 - last_rank <- results[, .N] - - if (first_not_included_rank <= last_rank) { - plot <- plot |> plotly::layout( - shapes = list( - type = "rect", - fillcolor = "black", - opacity = 0.1, - x0 = first_not_included_rank, - x1 = last_rank, - y0 = 0.0, - y1 = 1.0 - ) - ) - } - - plot -} diff --git a/R/server.R b/R/server.R index 788ce5d..51d5b97 100644 --- a/R/server.R +++ b/R/server.R @@ -154,10 +154,19 @@ server <- function(input, output, session) { }) output$rank_plot <- plotly::renderPlotly({ - rank_plot( - results(), - preset()$reference_gene_ids, - results_filtered()[, max(rank)] + geposan::plot_scores( + ranking(), + gene_sets = list(preset()$reference_gene_ids), + labels = "TPE-OLD genes", + max_rank = results_filtered()[, max(rank)] + ) + }) + + output$boxplot <- plotly::renderPlotly({ + geposan::plot_boxplot( + ranking(), + gene_sets = list(preset()$reference_gene_ids), + labels = "TPE-OLD genes" ) }) diff --git a/R/ui.R b/R/ui.R index 95f6d39..d637b9e 100644 --- a/R/ui.R +++ b/R/ui.R @@ -48,6 +48,14 @@ ui <- fluidPage( height = "600px" ) ), + div( + style = "margin-top: 16px", + plotly::plotlyOutput( + "boxplot", + width = "100%", + height = "600px" + ) + ), ), tabPanel( "Analysis",