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