Calculates eigengenes for modules in new data. By default, eigengenes are
calculated from scratch using PCA, in a similar manner to the
moduleEigengenes function. The function also offers a
projection approach, which functions in a similar fashion to the
predict
method of prcomp.
Usage
# S4 method for class 'ModularExperiment,matrix'
calcEigengenes(
object,
newdata,
project = FALSE,
scale_reduced = TRUE,
return_loadings = FALSE,
scale_newdata = NULL,
center_newdata = NULL,
realign = TRUE,
min_module_genes = 10
)
# S4 method for class 'ModularExperiment,data.frame'
calcEigengenes(
object,
newdata,
project = FALSE,
scale_reduced = TRUE,
return_loadings = FALSE,
scale_newdata = NULL,
center_newdata = NULL,
realign = TRUE,
min_module_genes = 10
)
# S4 method for class 'ModularExperiment,SummarizedExperiment'
calcEigengenes(
object,
newdata,
project = FALSE,
scale_reduced = TRUE,
assay_name = "normal",
scale_newdata = NULL,
center_newdata = NULL,
realign = TRUE,
min_module_genes = 10
)
# S4 method for class 'ModularExperiment'
predict(object, newdata, ...)
Arguments
- object
A ModularExperiment object. By default, the
scale
andcenter
slots are used to apply the original transformation to the new data. Theloadings
slot of this class will be used ifproject
isTRUE
.- newdata
New data for eigengenes to be calculated in. Must be a
data.frame
ormatrix
with features as rows and samples as columns, or a SummarizedExperiment object. Assumes that the rows ofnewdata
match those of the ModularExperiment object.- project
If
FALSE
(default), calculate eigengenes from scratch in the new dataset using an approach similar to moduleEigengenes (i.e., performing PCA for each module innewdata
). IfFALSE
, perform projection, using PCA rotation matrix from the original data to calculate module eigengenes. Projection approach is experimental.- scale_reduced
Whether or not the reduced data should be scaled after calculation.
- return_loadings
If
TRUE
, additionally returns the feature loadings for the eigengenes.- scale_newdata
Controls whether the
newdata
are scaled. IfNULL
, performs scaling based on the ModularExperiment object'sscale
slot. The value of this argument will be passed to thescale
argument of scale.- center_newdata
Controls whether the
newdata
are centered IfNULL
, performs centering based on the ModularExperiment object'scenter
slot. The value of this argument will be passed to thecenter
argument of scale.- realign
If
project
isTRUE
, this argument is ignored. Else, controls whether eigengenes are realigned after PCA is performed to ensure the resultant signatures are positively correlated with average expression of the module. Similar to thealign
argument of moduleEigengenes.- min_module_genes
If
project
isFALSE
, this argument is ignores. Else, controls the minimum number of genes required in a module for projection. Projected eigengenes are not calculated for modules with sizes below this threshold.- assay_name
If a SummarizedExperiment object is passed as new data, this argument indicates which assay should be used for projection.
- ...
Additional arguments to be passed to calcEigengenes.
Value
If return_loadings is TRUE
, returns a list with the "reduced" matrix
and "loadings" vector (one value per feature). If FALSE
, returns only the
reduced matrix.
The reduced matrix has samples as rows and modules as columns. If
newdata
was a matrix
or data.frame
, this will be returned as a matrix.
If a SummarizedExperiment object was passed
instead, then a If a ModularExperiment
object will be created containing this matrix in its reduced
slot.
Details
If scale_newdata
and center_newdata
are left as NULL
, then the
projection method assumes that the newdata
are on the same scale as the
original data of the object
. It will therefore use the values of the
center
and scale
slots of the object
. For instance, if the scale
slot
is TRUE
, the newdata
will be scaled. If the scale
slot is a vector,
the values of this vector will be applied to scale the newdata
.
Examples
# Create ModularExperiment with random data (100 features, 50 samples,
# 10 modules)
me_1 <- ReducedExperiment:::.createRandomisedModularExperiment(100, 50, 10)
# Generate a new dataset with the same features (100 rows) but different
# samples/observations (20 columns)
X_2 <- ReducedExperiment:::.makeRandomData(100, 20, "gene", "sample")
# We can use the projection approach to calculate the eigengenes for
# the modules identified in dataset 1 for the samples in dataset 2
# This approach is based on the module loadings
me_2_project <- calcEigengenes(me_1, X_2, project = TRUE)
me_2_project[1:5, 1:5]
#> module_3 module_4 module_5 module_7 module_9
#> sample_1 1.22860282 0.1098998 -0.3994967 0.6225404 -0.3399150
#> sample_2 0.03840139 1.4757127 1.5290504 2.3318725 0.6358647
#> sample_3 0.06706610 -1.2801196 -0.8433581 -0.5570758 -2.3058230
#> sample_4 -1.03371358 -0.2736773 0.7469042 0.4239787 0.7531614
#> sample_5 -0.05816772 -2.2594398 0.9274514 0.6076134 -0.8240435
# Alternatively, we can calculate eigengenes from scratch in the second
# dataset. This still uses the modules identified in the first dataset (me_1)
# but does not make use of the loadings. This approach is similar to
# that applied by WGCNA::moduleEigengenes.
me_2_eig <- calcEigengenes(me_1, X_2, project = FALSE)
me_2_eig[1:5, 1:5]
#> module_1 module_2 module_3 module_4 module_5
#> sample_1 -0.77264363 -0.79497888 -0.03168875 -1.70172233 0.12220734
#> sample_2 -1.14156851 0.70822928 0.05088189 -0.17936889 2.64330795
#> sample_3 2.30464866 1.49382155 0.40186869 -0.01352815 -0.52443628
#> sample_4 0.09542815 -0.08564603 0.14493088 0.30611324 0.46941327
#> sample_5 -0.04783814 -1.62024124 0.95875606 -0.09346481 -0.04152795