ranking: Cache optimizations

This commit is contained in:
Elias Projahn 2021-12-16 13:57:02 +01:00
parent e2b93babe5
commit 48ff555e88

View file

@ -64,11 +64,18 @@ optimal_weights <- function(analysis, methods, reference_gene_ids,
stop("Invalid analyis. Use geposan::analyze().")
}
# Compute the target rank of the reference genes when applying the weights.
cached(
"optimization",
c(analysis$preset, methods, reference_gene_ids, target),
{ # nolint
# Compute the target rank of the reference genes when applying the
# weights.
target_rank <- function(factors) {
data <- ranking(analysis, as.list(factors))
result <- data[gene %chin% reference_gene_ids, if (target == "min") {
result <- data[
gene %chin% reference_gene_ids,
if (target == "min") {
min(rank)
} else if (target == "max") {
max(rank)
@ -76,7 +83,8 @@ optimal_weights <- function(analysis, methods, reference_gene_ids,
mean(rank)
} else {
stats::median(rank)
}]
}
]
if (result > 0) {
result
@ -92,3 +100,5 @@ optimal_weights <- function(analysis, methods, reference_gene_ids,
as.list(optimal_factors / max(abs(optimal_factors)))
}
)
}