Runs the main function fitExtractVarPartModel of the package variancePartition: Fits a linear (mixed) model to estimate contribution of multiple sources of variation while simultaneously correcting for all other variables for the features in a GRN object (TFs, peaks, and genes) given particular metadata. The function reports the fraction of variance attributable to each metadata variable. Note: The results are not added to GRN@connections$all.filtered, rerun the function getGRNConnections and set include_variancePartitionResults to TRUE to do so. The results object is stored in GRN@stats$variancePartition and can be used for the various diagnostic and plotting functions from variancePartition.

  formula = "auto",
  metadata = c("all"),
  features = "all_filtered",
  nCores = 1,
  forceRerun = FALSE,



Object of class GRN


Character(1). Either auto or a manually defined formula to be used for the model fitting. Default auto. Must include only terms that are part of the metadata as specified with the metadata parameter. If set to auto, the formula will be build automatically based on all metadata variables as specified with the metadata parameter. By default, numerical variables will be modeled as fixed effects, while variables that are defined as factors or can be converted to factors (characters and logical variables) are modeled as random effects as recommended by the variancePartition package.


Character vector. Default all. Vector of column names from the metadata data frame that was provided when using the function addData. Must either contain the special keyword all to denote that all (!) metadata columns from GRN@data$metadata are taken or if not, a subset of the column names from GRN@data$metadatato include in the model fitting for fitExtractVarPartModel..


Character(1). Either all_filtered or all. Default all_filtered. Should variancePartition only be run for the features (TFs, peaks and genes) from the filtered set of connections (the result of filterGRNAndConnectGenes) or for all genes that are defined in the object? If set to all, the running time is greatly increased.


Integer >0. Default 1. Number of cores to use. A value >1 requires the BiocParallel package (as it is listed under Suggests, it may not be installed yet).


TRUE or FALSE. Default FALSE. Force execution, even if the GRN object already contains the result. Overwrites the old results.


Additional parameters passed on to variancePartition::fitExtractVarPartModel beyond exprObj, formula and data. See the function help for more information


An updated GRN object, with additional information added from this function to GRN@stats$variancePartition as well as the elements genes, consensusPeaks and TFs within GRN@annotation. As noted above, the results are not added to GRN@connections$all.filtered; rerun the function getGRNConnections and set include_variancePartitionResults to TRUE to include the results in the eGRN output table.


The normalized count matrices are used as input for fitExtractVarPartModel.


# See the Workflow vignette on the GRaNIE website for examples
# GRN = loadExampleObject()
# GRN = add_featureVariation(GRN, metadata = c("mt_frac"), forceRerun = TRUE)