mirror of
https://github.com/johrpan/geposan.git
synced 2025-10-26 10:47:25 +01:00
analyze: Include preset in result
This commit is contained in:
parent
6d9511fa2e
commit
910eb06fe9
4 changed files with 32 additions and 21 deletions
27
R/analyze.R
27
R/analyze.R
|
|
@ -5,10 +5,14 @@
|
|||
#' function should accept a number between 0.0 and 1.0 for the current
|
||||
#' progress.
|
||||
#'
|
||||
#' @return An object containing the results of the analysis. It contains a
|
||||
#' [data.table] with one row for each gene identified by it's ID (`gene`
|
||||
#' column). The additional columns contain the resulting scores per method
|
||||
#' and are named after the method IDs.
|
||||
#' @returns An object containing the results of the analysis with the following
|
||||
#' items:
|
||||
#' \describe{
|
||||
#' \item{`preset`}{The preset that was used.}
|
||||
#' \item{`results`}{A [data.table] with one row for each gene identified by
|
||||
#' it's ID (`gene` column). The additional columns contain the resulting
|
||||
#' scores per method and are named after the method IDs.}
|
||||
#' }
|
||||
#'
|
||||
#' @export
|
||||
analyze <- function(preset, progress = NULL) {
|
||||
|
|
@ -34,10 +38,10 @@ analyze <- function(preset, progress = NULL) {
|
|||
"neural" = neural
|
||||
)
|
||||
|
||||
analysis <- cached("analysis", preset, {
|
||||
results <- cached("analysis", preset, {
|
||||
total_progress <- 0.0
|
||||
method_count <- length(preset$methods)
|
||||
analysis <- data.table(gene = preset$gene_ids)
|
||||
results <- data.table(gene = preset$gene_ids)
|
||||
|
||||
for (method_id in preset$methods) {
|
||||
method_progress <- if (!is.null(progress)) {
|
||||
|
|
@ -50,7 +54,7 @@ analyze <- function(preset, progress = NULL) {
|
|||
setnames(method_results, "score", method_id)
|
||||
|
||||
analysis <- merge(
|
||||
analysis,
|
||||
results,
|
||||
method_results,
|
||||
by = "gene"
|
||||
)
|
||||
|
|
@ -62,11 +66,14 @@ analyze <- function(preset, progress = NULL) {
|
|||
progress(1.0)
|
||||
}
|
||||
|
||||
analysis
|
||||
results
|
||||
})
|
||||
|
||||
structure(
|
||||
analysis,
|
||||
class = c("geposan_analysis", class(analysis))
|
||||
list(
|
||||
preset = preset,
|
||||
results = results
|
||||
),
|
||||
class = "geposan_analysis"
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,9 +7,9 @@
|
|||
#' @param weights Named list pairing method names with weighting factors. Only
|
||||
#' methods that are contained within this list will be included.
|
||||
#'
|
||||
#' @returns A ranking object. The object extends the analysis with additional
|
||||
#' columns containing the `score` and the `rank` of each gene. It will be
|
||||
#' ordered by rank.
|
||||
#' @returns A ranking object. The object extends the analysis result with
|
||||
#' additional columns containing the `score` and the `rank` of each gene. It
|
||||
#' will be ordered by rank.
|
||||
#'
|
||||
#' @export
|
||||
ranking <- function(analysis, weights) {
|
||||
|
|
@ -17,7 +17,7 @@ ranking <- function(analysis, weights) {
|
|||
stop("Invalid analyis. Use geposan::analyze().")
|
||||
}
|
||||
|
||||
ranking <- copy(analysis)
|
||||
ranking <- copy(analysis$results)
|
||||
ranking[, score := 0.0]
|
||||
|
||||
for (method in names(weights)) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue