diff --git a/R/server.R b/R/server.R index 9c98018..83459f7 100644 --- a/R/server.R +++ b/R/server.R @@ -109,6 +109,52 @@ server <- function(options) { geposan::plot_rankings(rankings, gene_sets) }) + output$comparison_text <- renderUI({ + reference <- geposan::compare( + ranking(), + preset()$reference_gene_ids + ) + + comparison <- if (!is.null(comparison_gene_ids())) { + geposan::compare(ranking(), comparison_gene_ids()) + } + + num <- function(x, digits) { + format( + round(x, digits = digits), + nsmall = digits, + scientific = FALSE + ) + } + + comparison_text <- function(name, comparison) { + glue::glue( + "The {name} have a mean score of ", + "{num(comparison$mean_score, 4)} ", + "resulting in a mean rank of ", + "{num(comparison$mean_rank, 1)}. ", + "This corresponds to a percent rank of ", + "{num(100 * comparison$mean_percentile, 2)}%. ", + "A Wilcoxon rank sum test with the hypothesis of higher ", + "than usual scores gives a p-value of ", + "{num(comparison$p_value, 4)}." + ) + } + + reference_div <- div(HTML( + comparison_text("reference genes", reference) + )) + + if (!is.null(comparison)) { + div( + reference_div, + div(HTML(comparison_text("comparison genes", comparison))) + ) + } else { + reference_div + } + }) + output$boxplot <- plotly::renderPlotly({ preset <- preset() gene_sets <- list("Reference genes" = preset$reference_gene_ids) diff --git a/R/ui.R b/R/ui.R index cf12dde..587dc94 100644 --- a/R/ui.R +++ b/R/ui.R @@ -58,6 +58,7 @@ ui <- function(options) { title = "Comparison", div( style = "margin-top: 16px", + htmlOutput("comparison_text"), plotly::plotlyOutput( "boxplot", width = "100%",