diff --git a/DESCRIPTION b/DESCRIPTION index 21a9a1a..10256d1 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -15,7 +15,7 @@ Description: This package contains precomputed data including comparisons in License: AGPL (>= 3) Encoding: UTF-8 Roxygen: list(markdown = TRUE) -RoxygenNote: 7.2.0 +RoxygenNote: 7.2.1 Depends: R (>= 2.10) LazyData: true diff --git a/R/genes_table.R b/R/genes_table.R index d8b54a2..b7d61a3 100644 --- a/R/genes_table.R +++ b/R/genes_table.R @@ -71,14 +71,17 @@ genes_table_server <- function(id, data) { "target=\"_blank\">{hgnc_name}" ), "Rank" = rank, - "Percentile" = percentile, + "%" = percentile, "Score" = score, "Median" = median_expression, + "IQR" = iqr_expression, + "QCV" = qcv_expression, "Mean" = mean_expression, - "Standard deviation" = sd_expression, - "Expressed" = above_zero, - "Above median" = above_median, - "Above 95%" = above_95 + "SD" = sd_expression, + "CV" = cv_expression, + "> 0" = above_zero, + "> median" = above_median, + "> 95%" = above_95 )], options = list( dom = "frtip", @@ -90,18 +93,21 @@ genes_table_server <- function(id, data) { ) |> DT::formatPercentage( c( - "Percentile", - "Score", - "Expressed", - "Above median", - "Above 95%" + "%", + "> 0", + "> median", + "> 95%" ), digits = 2, ) |> DT::formatRound(c( + "Score", "Median", + "IQR", + "QCV", "Mean", - "Standard deviation" + "SD", + "CV" )) }) }) diff --git a/R/ranking.R b/R/ranking.R index 7d5f089..dba5618 100644 --- a/R/ranking.R +++ b/R/ranking.R @@ -3,34 +3,26 @@ #' This function will compute a weighted average across multiple metrics that #' define how ubiquitous a gene is based on its expression across samples. #' -#' @param cross_sample_metric Metric to use for calculating the number of -#' samples a gene is expressed in. One of `above_95`, `above_median` or -#' `above_zero`. -#' @param cross_sample_weight Weighting of the cross sample metric within the -#' final score. -#' @param mean_expression_weight Weighting of the gene's mean expression within -#' the final score. -#' @param sd_expression_weight Weighting of the standard deviation of the -#' gene's expression within the final score. -#' #' @return A `data.table` with gene data as well as the scores, ranks and #' percentiles for each gene. #' #' @export rank_genes <- function(cross_sample_metric = "above_95", cross_sample_weight = 0.5, - mean_expression_weight = 0.25, - sd_expression_weight = -0.25) { + level_metric = "median_expression_normalized", + level_weight = 0.25, + variation_metric = "qcv_expression_normalized", + variation_weight = -0.25) { total_weight <- abs(cross_sample_weight) + - abs(mean_expression_weight) + - abs(sd_expression_weight) + abs(level_weight) + + abs(variation_weight) data <- copy(ubigen::genes) data[, score := (cross_sample_weight * get(cross_sample_metric) + - mean_expression_weight * mean_expression_normalized + - sd_expression_weight * sd_expression_normalized) / + level_weight * get(level_metric) + + variation_weight * get(variation_metric)) / total_weight] # Normalize scores to be between 0.0 and 1.0. diff --git a/R/server.R b/R/server.R index f02f504..2ff93fb 100644 --- a/R/server.R +++ b/R/server.R @@ -5,8 +5,10 @@ server <- function(input, output, session) { rank_genes( cross_sample_metric = input$cross_sample_metric, cross_sample_weight = input$cross_sample_weight, - mean_expression_weight = input$mean_expression, - sd_expression_weight = input$sd_expression + level_metric = input$level_metric, + level_weight = input$level_weight, + variation_metric = input$variation_metric, + variation_weight = input$variation_weight ) }) diff --git a/R/sysdata.rda b/R/sysdata.rda index 62f4499..fd826b0 100644 Binary files a/R/sysdata.rda and b/R/sysdata.rda differ diff --git a/R/ui.R b/R/ui.R index 8880886..d53e68b 100644 --- a/R/ui.R +++ b/R/ui.R @@ -43,26 +43,45 @@ ui <- function() { step = 0.01, value = 0.5 ), - sliderInput( - "mean_expression", + selectInput( + "level_metric", verticalLayout( - strong("Mean Expression"), - "Mean expression of the gene across all samples." + strong("Expression level"), + "Typical expression level of the gene across all samples." ), + list( + "Median expression" = "median_expression_normalized", + "Mean expression" = "mean_expression_normalized" + ) + ), + sliderInput( + "level_weight", + label = NULL, min = -1.0, max = 1.0, step = 0.01, value = 0.25 ), - sliderInput( - "sd_expression", + selectInput( + "variation_metric", verticalLayout( - strong("Standard deviation"), + strong("Expression variation"), paste0( - "Standard deviation of the gene's expression across all ", + "Measure of the variation of the gene's expression between ", "samples." ) ), + list( + "Quantile based coefficient of variation" = + "qcv_expression_normalized", + "Interquartile range" = "iqr_expression_normalized", + "Coefficient of variation" = "cv_expression_normalized", + "Standard deviation" = "sd_expression_normalized" + ) + ), + sliderInput( + "variation_weight", + label = NULL, min = -1.0, max = 1.0, step = 0.01, diff --git a/man/genes.Rd b/man/genes.Rd index e4a2a80..6a09d2c 100644 --- a/man/genes.Rd +++ b/man/genes.Rd @@ -5,7 +5,7 @@ \alias{genes} \title{A \code{data.table} containig data on genes and their expression behavior.} \format{ -An object of class \code{data.table} (inherits from \code{data.frame}) with 56156 rows and 14 columns. +An object of class \code{data.table} (inherits from \code{data.frame}) with 56156 rows and 20 columns. } \usage{ genes diff --git a/man/rank_genes.Rd b/man/rank_genes.Rd index f1065d6..68de9a6 100644 --- a/man/rank_genes.Rd +++ b/man/rank_genes.Rd @@ -7,24 +7,12 @@ rank_genes( cross_sample_metric = "above_95", cross_sample_weight = 0.5, - mean_expression_weight = 0.25, - sd_expression_weight = -0.25 + level_metric = "median_expression_normalized", + level_weight = 0.25, + variation_metric = "qcv_expression_normalized", + variation_weight = -0.25 ) } -\arguments{ -\item{cross_sample_metric}{Metric to use for calculating the number of -samples a gene is expressed in. One of \code{above_95}, \code{above_median} or -\code{above_zero}.} - -\item{cross_sample_weight}{Weighting of the cross sample metric within the -final score.} - -\item{mean_expression_weight}{Weighting of the gene's mean expression within -the final score.} - -\item{sd_expression_weight}{Weighting of the standard deviation of the -gene's expression within the final score.} -} \value{ A \code{data.table} with gene data as well as the scores, ranks and percentiles for each gene. diff --git a/scripts/gsea.R b/scripts/gsea.R index 5b25d54..59bd8fc 100644 --- a/scripts/gsea.R +++ b/scripts/gsea.R @@ -42,8 +42,8 @@ fig <- plotly::plot_ly(data) |> color = ~source ) |> plotly::add_lines( - x = ~bucket_smoothed, - y = ~total_smoothed, + x = bucket_smoothed, + y = total_smoothed, name = "All (smoothed)" ) |> plotly::layout(