Perform Gene Set Variation Analysis (GSVA)
Usage
RunGSVA(
object = NULL,
assay = NULL,
group.by = NULL,
layer = "data",
assay_name = "GSVA",
new_assay = TRUE,
store_metadata = NULL,
db = "GO_BP",
species = "Homo_sapiens",
IDtype = "symbol",
db_update = FALSE,
db_version = "latest",
db_combine = FALSE,
convert_species = TRUE,
Ensembl_version = NULL,
mirror = NULL,
features = NULL,
TERM2GENE = NULL,
TERM2NAME = NULL,
minGSSize = 10,
maxGSSize = 500,
unlimited_db = c("Chromosome", "GeneType", "TF", "Enzyme", "CSPA"),
method = c("gsva", "ssgsea", "zscore", "plage"),
backend = c("cpp", "r"),
cpp_chunk_size = NULL,
kcdf = c("Gaussian", "Poisson", "none"),
abs.ranking = FALSE,
min.sz = 10,
max.sz = Inf,
mx.diff = TRUE,
tau = 1,
ssgsea.norm = TRUE,
cores = NULL,
verbose = TRUE,
...,
srt = NULL
)Arguments
- object
A
Seuratobject orSummarizedExperimentobject containing the results of differential expression analysis (RunDEtest()). If specified, the genes and groups will be extracted from the object automatically. If not specified, thegeneIDandgeneID_groupsarguments must be provided.- assay
Assay to use.
NULLuses the default assay.- group.by
Name of metadata column to group cells by for averaging expression. If provided, expression will be averaged within each group before GSVA analysis (cell-type level). If
NULL, GSVA is performed on each cell individually (single-cell level).- layer
Data layer to use when
group.by = NULL. Usually"data"for normalized or"counts"for count matrix.- assay_name
Name of the assay to store GSVA scores when
group.by = NULLandnew_assay = TRUE.- new_assay
Whether to create a new assay for GSVA scores when
group.by = NULL. Default isTRUE.- store_metadata
Whether to also store single-cell GSVA scores in
meta.data. WhenNULL, customfeaturesorTERM2GENEinput is stored inmeta.databy default, while database-derived results stay assay-only whennew_assay = TRUE.- db
Character vector of database or resource selectors:
"GO","GO_BP","GO_CC","GO_MF","KEGG","WikiPathway","Reactome","CORUM","MP","DO","HPO","PFAM","Chromosome","GeneType","Enzyme","TF","CSPA","Surfaceome","SPRomeDB","VerSeDa","TFLink","hTFtarget","TRRUST","JASPAR","ENCODE","MSigDB","CellTalk","CellChat","CytoTRACE2"or"MSigDB_<collection>". A vector may combine sources. See the corresponding preparation function for source-specific settings.- species
"Homo_sapiens"or"Mus_musculus".- IDtype
Type of gene IDs in the
objectobject orgeneIDargument. This argument is used to convert the gene IDs to a different type ifIDtypeis different fromresult_IDtype.- db_update
Force a refresh.
FALSEloads the cache when available.- db_version
Database version to retrieve.
- db_combine
Whether to combine multiple databases into one. If
TRUE, all database specified bydbwill be combined as one named "Combined".- convert_species
Use a species-converted database when the annotation is missing for
species.- Ensembl_version
Ensembl version.
NULLuses the latest.- mirror
Specify an Ensembl mirror to connect to. The valid options here are
"www","uswest","useast","asia".- features
A named list of feature lists for custom enrichment gene sets. If provided, it takes precedence over
TERM2GENEanddb.- TERM2GENE
A data frame specifying the gene-term mapping for a custom database. The first column should contain the term IDs, and the second column should contain the gene IDs.
- TERM2NAME
A data frame specifying the term-name mapping for a custom database. The first column should contain the term IDs, and the second column should contain the corresponding term names.
- minGSSize
The minimum size of a gene set to be considered in the enrichment analysis.
- maxGSSize
The maximum size of a gene set to be considered in the enrichment analysis.
- unlimited_db
Names of databases that do not have size restrictions.
- method
The method to use for GSVA. Options are
"gsva","ssgsea","zscore", or"plage". Multiple methods can be supplied at once; in single-cell mode they will be stored in method-suffixed assays such as"GSVA_gsva"and"GSVA_ssgsea".- backend
Scoring backend.
"cpp"is the default and supports all currentmethodvalues."r"uses the originalGSVA::gsva()implementation."cpp"supportsmethod = "ssgsea",method = "zscore",method = "plage", andmethod = "gsva"withkcdf = "Gaussian",kcdf = "Poisson", orkcdf = "none". Gaussian GSVA uses the native C++ KDE/ranking kernel, tracking the sparse scoring walk of the installed GSVA release; other GSVA kernels keep the validated GSVA implementation. PLAGE scores are oriented to have non-negative dot product with the gene set mean z-score so SVD signs are deterministic.- cpp_chunk_size
Optional cell chunk size for C++ GSVA kernels.
NULLor"auto"automatically chunks large matrices to reduce peak dense intermediate memory; positive values set the chunk size manually.- kcdf
The kernel cumulative distribution function used for GSVA. Options are
"Gaussian"(for continuous data),"Poisson"(for count data), or"none"(skip kernel estimation and use ranks directly). When omitted,backend = "cpp"withmethod = "gsva"uses"none"for faster single-cell scoring; explicit"Gaussian"or"Poisson"values are still honored. Other backends and methods default to"Gaussian".- abs.ranking
Whether to use absolute ranking for GSVA.
- min.sz
Minimum size of gene sets to be included in the analysis.
- max.sz
Maximum size of gene sets to be included in the analysis.
- mx.diff
Whether to use the maximum difference method.
- tau
Exponent for the GSVA method.
- ssgsea.norm
Whether to normalize SSGSEA scores.
- cores
Number of OpenMP threads for C++ scoring.
NULLuses the process OpenMP default.- verbose
Whether to print the message. Default is
TRUE.- ...
Passed to helper functions.
- srt
Deprecated alias for
object; supply exactly one of the two. It will be removed in scop 1.0.0.
Value
Returns the modified Seurat object. When group.by is provided, GSVA scores are stored in the tools slot.
When group.by = NULL, scores are stored in the tools slot, optionally in a new assay,
and optionally in meta.data for direct use with FeatureDimPlot() and FeatureStatPlot().
Examples
data(pancreas_sub)
pancreas_sub <- RunStandardWorkflow(pancreas_sub)
#> ℹ [2026-10-11 23:19:21] Start standard processing workflow...
#> ℹ [2026-10-11 23:19:21] Checking a list of <Seurat>...
#> ! [2026-10-11 23:19:21] Data 1/1 of the `srt_list` is "unknown"
#> ℹ [2026-10-11 23:19:21] Perform `NormalizeData()` with `normalization.method = 'LogNormalize'` on 1/1 of `srt_list`...
#> ℹ [2026-10-11 23:19:22] Perform `FindVariableFeatures()` on 1/1 of `srt_list`...
#> ℹ [2026-10-11 23:19:22] Use the separate HVF from `srt_list`
#> ℹ [2026-10-11 23:19:22] Number of available HVF: 2000
#> ℹ [2026-10-11 23:19:22] Finished check
#> ℹ [2026-10-11 23:19:22] Perform `ScaleData()`
#> ℹ [2026-10-11 23:19:22] Perform pca linear dimension reduction
#> ℹ [2026-10-11 23:19:22] Use stored estimated dimensions 1:23 for Standardpca
#> ℹ [2026-10-11 23:19:23] Perform `Seurat::FindClusters()` with `cluster_algorithm = 'louvain'` and `cluster_resolution = 0.6`
#> ℹ [2026-10-11 23:19:23] Reorder clusters...
#> ℹ [2026-10-11 23:19:23] Skip `log1p()` because `layer = data` is not "counts"
#> ℹ [2026-10-11 23:19:23] Perform umap nonlinear dimension reduction
#> ✔ [2026-10-11 23:19:30] Standard processing workflow completed
pancreas_sub <- RunGSVA(
pancreas_sub,
group.by = "CellType",
species = "Mus_musculus"
)
#> ℹ [2026-10-11 23:19:30] Start GSVA analysis
#> ℹ [2026-10-11 23:19:30] Start GSVA analysis
#> ℹ [2026-10-11 23:19:30] Species: "Mus_musculus"
#> ℹ [2026-10-11 23:19:30] Loading cached: GO_BP version: 3.23.0 nterm:14957 created: 2026-10-11 22:48:45
#> ℹ [2026-10-11 23:19:31] Averaging expression by "CellType" ...
#> ℹ [2026-10-11 23:19:31] Aggregated expression matrix: 15998 genes x 5 groups
#> ℹ [2026-10-11 23:19:31] Processing database: "GO_BP" ...
#> ℹ [2026-10-11 23:19:32] Initial overlap: 11277 genes out of 15998 expression genes and 16594 genes in gene sets
#> ℹ [2026-10-11 23:19:32] Running GSVA for 5633 gene sets ...
#> ℹ 45447 nonzeros (less than 2^31) and 7.96% sparsity
#> ℹ [2026-10-11 23:19:38] GSVA results stored in `tools` slot: "GSVA_CellType_gsva"
#> ✔ [2026-10-11 23:19:38] GSVA analysis done
#> ℹ [2026-10-11 23:19:38] Start GSVA analysis
#> ℹ [2026-10-11 23:19:38] Species: "Mus_musculus"
#> ℹ [2026-10-11 23:19:38] Loading cached: GO_BP version: 3.23.0 nterm:14957 created: 2026-10-11 22:48:45
#> ℹ [2026-10-11 23:19:39] Averaging expression by "CellType" ...
#> ℹ [2026-10-11 23:19:39] Aggregated expression matrix: 15998 genes x 5 groups
#> ℹ [2026-10-11 23:19:39] Processing database: "GO_BP" ...
#> ℹ [2026-10-11 23:19:40] Initial overlap: 11277 genes out of 15998 expression genes and 16594 genes in gene sets
#> ℹ [2026-10-11 23:19:40] Running GSVA for 5633 gene sets ...
#> ℹ [2026-10-11 23:19:42] GSVA results stored in `tools` slot: "GSVA_CellType_ssgsea"
#> ✔ [2026-10-11 23:19:42] GSVA analysis done
#> ℹ [2026-10-11 23:19:42] Start GSVA analysis
#> ℹ [2026-10-11 23:19:42] Species: "Mus_musculus"
#> ℹ [2026-10-11 23:19:42] Loading cached: GO_BP version: 3.23.0 nterm:14957 created: 2026-10-11 22:48:45
#> ℹ [2026-10-11 23:19:43] Averaging expression by "CellType" ...
#> ℹ [2026-10-11 23:19:43] Aggregated expression matrix: 15998 genes x 5 groups
#> ℹ [2026-10-11 23:19:43] Processing database: "GO_BP" ...
#> ℹ [2026-10-11 23:19:44] Initial overlap: 11277 genes out of 15998 expression genes and 16594 genes in gene sets
#> ℹ [2026-10-11 23:19:44] Running GSVA for 5633 gene sets ...
#> ℹ [2026-10-11 23:19:46] GSVA results stored in `tools` slot: "GSVA_CellType_zscore"
#> ✔ [2026-10-11 23:19:46] GSVA analysis done
#> ℹ [2026-10-11 23:19:46] Start GSVA analysis
#> ℹ [2026-10-11 23:19:46] Species: "Mus_musculus"
#> ℹ [2026-10-11 23:19:46] Loading cached: GO_BP version: 3.23.0 nterm:14957 created: 2026-10-11 22:48:45
#> ℹ [2026-10-11 23:19:46] Averaging expression by "CellType" ...
#> ℹ [2026-10-11 23:19:46] Aggregated expression matrix: 15998 genes x 5 groups
#> ℹ [2026-10-11 23:19:46] Processing database: "GO_BP" ...
#> ℹ [2026-10-11 23:19:48] Initial overlap: 11277 genes out of 15998 expression genes and 16594 genes in gene sets
#> ℹ [2026-10-11 23:19:48] Running GSVA for 5633 gene sets ...
#> ℹ [2026-10-11 23:19:49] GSVA results stored in `tools` slot: "GSVA_CellType_plage"
#> ✔ [2026-10-11 23:19:49] GSVA analysis done
ht <- GSVAPlot(
pancreas_sub,
group.by = "CellType",
plot_type = "heatmap",
topTerm = 10,
width = 1,
height = 2
)
#> ! [2026-10-11 23:19:49] Multiple GSVA results found for "CellType". Using "GSVA_CellType_gsva"
features_all <- rownames(pancreas_sub)
pancreas_sub <- RunGSVA(
pancreas_sub,
features = list(
A = features_all[1:20],
B = features_all[21:40]
),
method = c("gsva", "ssgsea")
)
#> ℹ [2026-10-11 23:19:50] Start GSVA analysis
#> ℹ [2026-10-11 23:19:50] Start GSVA analysis
#> ℹ [2026-10-11 23:19:50] Single-cell GSVA mode: using expression matrix directly ...
#> ℹ [2026-10-11 23:19:50] Expression matrix: 15998 genes x 1000 cells
#> ℹ [2026-10-11 23:19:50] Processing database: "custom" ...
#> ℹ [2026-10-11 23:19:50] Initial overlap: 40 genes out of 15998 expression genes and 40 genes in gene sets
#> ℹ [2026-10-11 23:19:50] Running GSVA for 2 gene sets ...
#> ℹ 6826 nonzeros (less than 2^31) and 81.04% sparsity
#> ℹ [2026-10-11 23:19:52] GSVA results stored in assay "GSVA_gsva", meta.data, and tools slot "GSVA_cell_gsva"
#> ✔ [2026-10-11 23:19:52] GSVA analysis done
#> ℹ [2026-10-11 23:19:52] Start GSVA analysis
#> ℹ [2026-10-11 23:19:52] Single-cell GSVA mode: using expression matrix directly ...
#> ℹ [2026-10-11 23:19:52] Expression matrix: 15998 genes x 1000 cells
#> ℹ [2026-10-11 23:19:52] Processing database: "custom" ...
#> ℹ [2026-10-11 23:19:52] Initial overlap: 40 genes out of 15998 expression genes and 40 genes in gene sets
#> ℹ [2026-10-11 23:19:52] Running GSVA for 2 gene sets ...
#> ℹ [2026-10-11 23:19:52] GSVA results stored in assay "GSVA_ssgsea", meta.data, and tools slot "GSVA_cell_ssgsea"
#> ✔ [2026-10-11 23:19:52] GSVA analysis done
FeatureDimPlot(
pancreas_sub,
features = "GSVA_gsva_A",
add_density = TRUE
)
FeatureStatPlot(
pancreas_sub,
stat.by = c("GSVA_gsva_A", "GSVA_ssgsea_A"),
group.by = "CellType",
plot.by = "feature",
plot_type = "violin",
stack = TRUE,
flip = TRUE
)
#> ℹ [2026-10-11 23:19:52] Setting `group.by` to "Features" as `plot.by` is set to "feature"