R/AllClasses.R

#' A container for geneset definitions.
#'
#' Please refer to the multiGSEA vignette (\code{vignette("multiGSEA")}),
#' (and the "The GeneSetDb Class" section, in particular) for a more deatiled
#' description of the sematnics of this central data object.
#'
#' @exportClass GeneSetDb
#'
#' @slot table The "gene set table": a data.table with geneset information,
#'   one row per gene set. Columns include collection, name, N, and n. The end
#'   user can add more columns to this data.table as desired. The actual
#'   feature IDs are computed on the fly by doing a `db[J(group, id)]`
#' @slot db A `data.table` to hold all of the original geneset id
#'   information that was used to construct this `GeneSetDb`.
#' @slot featureIdMap Maps the ids used in the geneset lists to the ids
#'   (rows) over the expression data the GSEA is run on
#' @slot collectionMetadata A `data.table` to keep metadata about each
#'   individual geneset collection, ie. the user might want to keep track of
#'   where the geneset definitions come from. Perhaps a function that parses
#'   the collection,name combination to generate an URL that points the user
#'   to more information about that geneset, etc.
#' @rdname GeneSetDb-class
.GeneSetDb <- setClass("GeneSetDb",
  slots=c(
    table="data.table",
    db="data.table",
    featureIdMap="data.table",
    collectionMetadata="data.table"),
  prototype=prototype(
    table=data.table(
      collection=character(),
      name=character(),
      active=logical(),
      N=integer(),
      n=integer(),
      key=c('collection', 'name')),
    db=data.table(
      collection=character(),
      name=character(),
      feature_id=character(),
      key=c('collection', 'name', 'feature_id')),
    featureIdMap=data.table(
      feature_id=character(),  ## The ids used in the defined genesets
      x.id=character(),
      x.idx=integer(),
      key='feature_id'),
    collectionMetadata=data.table(
      collection=character(),
      name=character(),
      value=list(),
      key=c('collection', 'name'))))

.MultiGSEARegistry <- setClass("MultiGSEARegistry",
  slots=c(
    methods="character",
    validate.fn="list",
    do.fn="list"),
  prototype=prototype(
    methods=character(),
    validate.fn=list(),
    do.fn=list()))

#' A MultiGSEAResult object holds the results from a multiGSEA call.
#'
#' @description A call to [multiGSEA()] will produce analyses for an
#' arbitrary number of GSEA methods, the results of which will be stored and
#' accessible here using the [result()], [results()], and [resultNames()].
#'
#' In addition, the [GeneSetDb()] used for the analysis is accessible
#' via [geneSetDb()], and the results from the differential
#' expression analysis is available via [logFC()].
#'
#' Visualizing results of a geneset based analysis also are functions that
#' operate over a `MultiGSEAResult` object, for instance see the
#' [iplot()] and [multiGSEA.shiny::explore()] functions.
#'
#' @exportClass MultiGSEAResult
#' @rdname MultiGSEAResult
#' @aliases MultiGSEAResult
#'
#' @slot gsd The [GeneSetDb()] this analysis was run over
#' @slot results The list of individual results generated by each of the
#'   GSEA methods that were run.
#' @slot logFC The differential expression statistics for each individual
#'   feature measured in the experiment.
.MultiGSEAResult <- setClass("MultiGSEAResult",
  slots=c(
    gsd="GeneSetDb",
    results="list",
    logFC='data.table'),
  prototype=prototype(
    gsd=new("GeneSetDb"),
    results=list(),
    # logFC=data.table(
    #   feature_id=character(),
    #   logFC=numeric(),
    #   t=numeric(),
    #   pval=numeric(),
    #   padj=numeric(),
    #   key='feature_id')))
    logFC=data.table(
      feature_id=character(),
      logFC=numeric(),
      t=numeric(),
      pval=numeric(),
      padj=numeric())))
lianos/multiGSEA documentation built on Nov. 17, 2020, 1:26 p.m.