diff --git a/R/correlation.R b/R/correlation.R index 36a1503..d302d3b 100644 --- a/R/correlation.R +++ b/R/correlation.R @@ -1,5 +1,4 @@ -#' Compute the mean correlation coefficient comparing gene distances with a set -#' of reference genes. +#' Score genes based on their correlation with the reference genes. #' #' @return An object of class `geposan_method`. #' @@ -66,28 +65,21 @@ correlation <- function() { progress(0.66) - # Compute the final score as the mean of known correlation - # scores. Negative correlations will correctly lessen the - # score, which will be clamped to zero as its lower bound. - # Genes with no possible correlations at all will be assumed - # to have a score of 0.0. - - compute_score <- function(scores) { - score <- mean(scores, na.rm = TRUE) - - if (is.na(score) | score < 0.0) { - score <- 0.0 - } - - score - } - + # Find the highes correlation. results[, - score := compute_score(as.matrix(.SD)), + max_correlation := max(.SD, na.rm = TRUE), .SDcols = reference_gene_ids, by = gene ] + # Normalize scores. + results[, + score := (max_correlation - min(max_correlation)) / + (max(max_correlation) - min(max_correlation)) + ] + + # Normalize scores. + results[, .(gene, score)] result( diff --git a/man/correlation.Rd b/man/correlation.Rd index d207915..dda7070 100644 --- a/man/correlation.Rd +++ b/man/correlation.Rd @@ -2,8 +2,7 @@ % Please edit documentation in R/correlation.R \name{correlation} \alias{correlation} -\title{Compute the mean correlation coefficient comparing gene distances with a set -of reference genes.} +\title{Score genes based on their correlation with the reference genes.} \usage{ correlation() } @@ -11,6 +10,5 @@ correlation() An object of class \code{geposan_method}. } \description{ -Compute the mean correlation coefficient comparing gene distances with a set -of reference genes. +Score genes based on their correlation with the reference genes. }