mirror of
https://github.com/johrpan/geposan.git
synced 2025-10-26 10:47:25 +01:00
correlation: Make summary function customizable
This commit also changes the default behavior to using `stats::median()`.
This commit is contained in:
parent
3cedc4fea4
commit
7fe07aceec
2 changed files with 19 additions and 5 deletions
|
|
@ -1,9 +1,13 @@
|
|||
#' Score genes based on their correlation with the reference genes.
|
||||
#'
|
||||
#' @param summarize A function for combining the different correlation
|
||||
#' coefficients into one metric. By default, [stats::median()] is used. Other
|
||||
#' suggested options include [max()] and [mean()].
|
||||
#'
|
||||
#' @return An object of class `geposan_method`.
|
||||
#'
|
||||
#' @export
|
||||
correlation <- function() {
|
||||
correlation <- function(summarize = stats::median) {
|
||||
method(
|
||||
id = "correlation",
|
||||
name = "Correlation",
|
||||
|
|
@ -15,7 +19,7 @@ correlation <- function() {
|
|||
|
||||
cached(
|
||||
"correlation",
|
||||
c(species_ids, gene_ids, reference_gene_ids),
|
||||
c(species_ids, gene_ids, reference_gene_ids, summarize),
|
||||
{ # nolint
|
||||
# Prefilter distances by species.
|
||||
distances <- geposan::distances[species %chin% species_ids]
|
||||
|
|
@ -65,9 +69,14 @@ correlation <- function() {
|
|||
|
||||
progress(0.66)
|
||||
|
||||
# Find the highes correlation.
|
||||
# Combine the correlation coefficients.
|
||||
results[,
|
||||
max_correlation := max(.SD, na.rm = TRUE),
|
||||
max_correlation := as.double(summarize(na.omit(
|
||||
# Convert the data.table subset into a
|
||||
# vector to get the correct na.omit
|
||||
# behavior.
|
||||
as.matrix(.SD)[1, ]
|
||||
))),
|
||||
.SDcols = reference_gene_ids,
|
||||
by = gene
|
||||
]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue