Use newly computed metrics

This commit is contained in:
Elias Projahn 2022-09-25 20:01:42 +02:00
parent 76f81ab6a7
commit 3829154c1e
9 changed files with 64 additions and 57 deletions

View file

@ -15,7 +15,7 @@ Description: This package contains precomputed data including comparisons in
License: AGPL (>= 3) License: AGPL (>= 3)
Encoding: UTF-8 Encoding: UTF-8
Roxygen: list(markdown = TRUE) Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.0 RoxygenNote: 7.2.1
Depends: Depends:
R (>= 2.10) R (>= 2.10)
LazyData: true LazyData: true

View file

@ -71,14 +71,17 @@ genes_table_server <- function(id, data) {
"target=\"_blank\">{hgnc_name}</a>" "target=\"_blank\">{hgnc_name}</a>"
), ),
"Rank" = rank, "Rank" = rank,
"Percentile" = percentile, "%" = percentile,
"Score" = score, "Score" = score,
"Median" = median_expression, "Median" = median_expression,
"IQR" = iqr_expression,
"QCV" = qcv_expression,
"Mean" = mean_expression, "Mean" = mean_expression,
"Standard deviation" = sd_expression, "SD" = sd_expression,
"Expressed" = above_zero, "CV" = cv_expression,
"Above median" = above_median, "> 0" = above_zero,
"Above 95%" = above_95 "> median" = above_median,
"> 95%" = above_95
)], )],
options = list( options = list(
dom = "frtip", dom = "frtip",
@ -90,18 +93,21 @@ genes_table_server <- function(id, data) {
) |> ) |>
DT::formatPercentage( DT::formatPercentage(
c( c(
"Percentile", "%",
"Score", "> 0",
"Expressed", "> median",
"Above median", "> 95%"
"Above 95%"
), ),
digits = 2, digits = 2,
) |> ) |>
DT::formatRound(c( DT::formatRound(c(
"Score",
"Median", "Median",
"IQR",
"QCV",
"Mean", "Mean",
"Standard deviation" "SD",
"CV"
)) ))
}) })
}) })

View file

@ -3,34 +3,26 @@
#' This function will compute a weighted average across multiple metrics that #' This function will compute a weighted average across multiple metrics that
#' define how ubiquitous a gene is based on its expression across samples. #' 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 #' @return A `data.table` with gene data as well as the scores, ranks and
#' percentiles for each gene. #' percentiles for each gene.
#' #'
#' @export #' @export
rank_genes <- function(cross_sample_metric = "above_95", rank_genes <- function(cross_sample_metric = "above_95",
cross_sample_weight = 0.5, cross_sample_weight = 0.5,
mean_expression_weight = 0.25, level_metric = "median_expression_normalized",
sd_expression_weight = -0.25) { level_weight = 0.25,
variation_metric = "qcv_expression_normalized",
variation_weight = -0.25) {
total_weight <- abs(cross_sample_weight) + total_weight <- abs(cross_sample_weight) +
abs(mean_expression_weight) + abs(level_weight) +
abs(sd_expression_weight) abs(variation_weight)
data <- copy(ubigen::genes) data <- copy(ubigen::genes)
data[, score := data[, score :=
(cross_sample_weight * get(cross_sample_metric) + (cross_sample_weight * get(cross_sample_metric) +
mean_expression_weight * mean_expression_normalized + level_weight * get(level_metric) +
sd_expression_weight * sd_expression_normalized) / variation_weight * get(variation_metric)) /
total_weight] total_weight]
# Normalize scores to be between 0.0 and 1.0. # Normalize scores to be between 0.0 and 1.0.

View file

@ -5,8 +5,10 @@ server <- function(input, output, session) {
rank_genes( rank_genes(
cross_sample_metric = input$cross_sample_metric, cross_sample_metric = input$cross_sample_metric,
cross_sample_weight = input$cross_sample_weight, cross_sample_weight = input$cross_sample_weight,
mean_expression_weight = input$mean_expression, level_metric = input$level_metric,
sd_expression_weight = input$sd_expression level_weight = input$level_weight,
variation_metric = input$variation_metric,
variation_weight = input$variation_weight
) )
}) })

Binary file not shown.

35
R/ui.R
View file

@ -43,26 +43,45 @@ ui <- function() {
step = 0.01, step = 0.01,
value = 0.5 value = 0.5
), ),
sliderInput( selectInput(
"mean_expression", "level_metric",
verticalLayout( verticalLayout(
strong("Mean Expression"), strong("Expression level"),
"Mean expression of the gene across all samples." "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, min = -1.0,
max = 1.0, max = 1.0,
step = 0.01, step = 0.01,
value = 0.25 value = 0.25
), ),
sliderInput( selectInput(
"sd_expression", "variation_metric",
verticalLayout( verticalLayout(
strong("Standard deviation"), strong("Expression variation"),
paste0( paste0(
"Standard deviation of the gene's expression across all ", "Measure of the variation of the gene's expression between ",
"samples." "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, min = -1.0,
max = 1.0, max = 1.0,
step = 0.01, step = 0.01,

View file

@ -5,7 +5,7 @@
\alias{genes} \alias{genes}
\title{A \code{data.table} containig data on genes and their expression behavior.} \title{A \code{data.table} containig data on genes and their expression behavior.}
\format{ \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{ \usage{
genes genes

View file

@ -7,24 +7,12 @@
rank_genes( rank_genes(
cross_sample_metric = "above_95", cross_sample_metric = "above_95",
cross_sample_weight = 0.5, cross_sample_weight = 0.5,
mean_expression_weight = 0.25, level_metric = "median_expression_normalized",
sd_expression_weight = -0.25 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{ \value{
A \code{data.table} with gene data as well as the scores, ranks and A \code{data.table} with gene data as well as the scores, ranks and
percentiles for each gene. percentiles for each gene.

View file

@ -42,8 +42,8 @@ fig <- plotly::plot_ly(data) |>
color = ~source color = ~source
) |> ) |>
plotly::add_lines( plotly::add_lines(
x = ~bucket_smoothed, x = bucket_smoothed,
y = ~total_smoothed, y = total_smoothed,
name = "All (smoothed)" name = "All (smoothed)"
) |> ) |>
plotly::layout( plotly::layout(