Returns averaged expression values for each identity class.

AverageExpression(
  object,
  assays = NULL,
  features = NULL,
  return.seurat = FALSE,
  group.by = "ident",
  add.ident = NULL,
  layer = "data",
  slot = deprecated(),
  verbose = TRUE,
  ...
)

Arguments

object

Seurat object

assays

Which assays to use. Default is all assays

features

Features to analyze. Default is all features in the assay

return.seurat

Whether to return the data as a Seurat object. Default is FALSE

group.by

Category (or vector of categories) for grouping (e.g, ident, replicate, celltype); 'ident' by default To use multiple categories, specify a vector, such as c('ident', 'replicate', 'celltype')

add.ident

(Deprecated). Place an additional label on each cell prior to pseudobulking

layer

Layer(s) to use; if multiple layers are given, assumed to follow the order of 'assays' (if specified) or object's assays

slot

(Deprecated). Slots(s) to use

verbose

Print messages and show progress bar

...

Arguments to be passed to methods such as CreateSeuratObject

Value

Returns a matrix with genes as rows, identity classes as columns. If return.seurat is TRUE, returns an object of class Seurat.

Details

If layer is set to 'data', this function assumes that the data has been log normalized and therefore feature values are exponentiated prior to averaging so that averaging is done in non-log space. Otherwise, if layer is set to either 'counts' or 'scale.data', no exponentiation is performed prior to averaging. If return.seurat = TRUE and layer is not 'scale.data', averaged values are placed in the 'counts' layer of the returned object and 'log1p' is run on the averaged counts and placed in the 'data' layer ScaleData is then run on the default assay before returning the object. If return.seurat = TRUE and layer is 'scale.data', the 'counts' layer contains average counts and 'scale.data' is set to the averaged values of 'scale.data'.

Examples

data("pbmc_small")
head(AverageExpression(object = pbmc_small)$RNA)
#> 6 x 3 sparse Matrix of class "dgCMatrix"
#>                 g0         g1        g2
#> MS4A1     .          2.083443  171.6152
#> CD79B    10.814657  17.548842  152.1344
#> CD79A     .         11.618333  215.0869
#> HLA-DRA  37.105857 405.850522 1158.0852
#> TCL1A     .          3.463203  142.0748
#> HLA-DQB1  3.968254  45.353183  169.2762
head(AverageExpression(object = pbmc_small, group.by = c('ident', 'groups'))$RNA)
#> 6 x 6 sparse Matrix of class "dgCMatrix"
#>             g0_g1     g0_g2      g1_g1      g1_g2      g2_g1     g2_g2
#> MS4A1     .        .          3.720434   .          83.27443  269.7716
#> CD79B    12.32353  8.928571  16.783660  18.522712   80.07761  232.1975
#> CD79A     .        .         14.204794   8.326474  174.12523  260.5998
#> HLA-DRA  44.81837 27.465213 473.313733 319.988254 1217.90859 1091.6148
#> TCL1A     .        .          6.184292   .          60.19691  233.0502
#> HLA-DQB1  .        8.928571  51.863218  37.067684  170.88236  167.4915