mirror of
https://github.com/johrpan/geposan.git
synced 2025-10-26 18:57:25 +01:00
correlation: Score based on best correlation
This commit is contained in:
parent
23bb499d3a
commit
fa49a5a887
2 changed files with 13 additions and 23 deletions
|
|
@ -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(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue