mirror of
https://github.com/johrpan/geposan.git
synced 2025-10-26 18:57:25 +01:00
ranking: Cache optimizations
This commit is contained in:
parent
e2b93babe5
commit
48ff555e88
1 changed files with 34 additions and 24 deletions
16
R/ranking.R
16
R/ranking.R
|
|
@ -64,11 +64,18 @@ optimal_weights <- function(analysis, methods, reference_gene_ids,
|
||||||
stop("Invalid analyis. Use geposan::analyze().")
|
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) {
|
target_rank <- function(factors) {
|
||||||
data <- ranking(analysis, as.list(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)
|
min(rank)
|
||||||
} else if (target == "max") {
|
} else if (target == "max") {
|
||||||
max(rank)
|
max(rank)
|
||||||
|
|
@ -76,7 +83,8 @@ optimal_weights <- function(analysis, methods, reference_gene_ids,
|
||||||
mean(rank)
|
mean(rank)
|
||||||
} else {
|
} else {
|
||||||
stats::median(rank)
|
stats::median(rank)
|
||||||
}]
|
}
|
||||||
|
]
|
||||||
|
|
||||||
if (result > 0) {
|
if (result > 0) {
|
||||||
result
|
result
|
||||||
|
|
@ -92,3 +100,5 @@ optimal_weights <- function(analysis, methods, reference_gene_ids,
|
||||||
|
|
||||||
as.list(optimal_factors / max(abs(optimal_factors)))
|
as.list(optimal_factors / max(abs(optimal_factors)))
|
||||||
}
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue