Skip to contents

This function calculates gene-set scores from the specified database (db) for each lineage using the specified scoring method (score_method). It then treats these scores as expression values and uses them as input to the RunDynamicFeatures function to identify dynamically enriched terms along the lineage.

Usage

RunDynamicEnrichment(
  srt,
  lineages,
  score_method = "AUCell",
  layer = "data",
  assay = NULL,
  min_expcells = 20,
  r.sq = 0.2,
  dev.expl = 0.2,
  padjust = 0.05,
  IDtype = "symbol",
  species = "Homo_sapiens",
  db = "GO_BP",
  db_update = FALSE,
  db_version = "latest",
  convert_species = TRUE,
  Ensembl_version = NULL,
  mirror = NULL,
  TERM2GENE = NULL,
  TERM2NAME = NULL,
  minGSSize = 10,
  maxGSSize = 500,
  cores = 1,
  verbose = TRUE,
  seed = 11
)

Arguments

srt

A Seurat object containing the results of differential expression analysis (RunDEtest). If specified, the genes and groups will be extracted from the Seurat object automatically. If not specified, the geneID and geneID_groups arguments must be provided.

lineages

A character vector specifying the lineages to plot.

score_method

The method to use for scoring. Can be "Seurat", "AUCell", or "UCell". Default is "Seurat".

layer

Which layer to use. Default is "counts".

assay

Which assay to use. If NULL, the default assay of the Seurat object will be used.

min_expcells

The minimum number of expected cells. Default is 20.

r.sq

The R-squared threshold. Default is 0.2.

dev.expl

The deviance explained threshold. Default is 0.2.

padjust

The p-value adjustment threshold. Default is 0.05.

IDtype

A character vector specifying the type of gene IDs in the srt object or geneID argument. This argument is used to convert the gene IDs to a different type if IDtype is different from result_IDtype.

species

A character vector specifying the species for which the gene annotation databases should be prepared. Can be "Homo_sapiens" or "Mus_musculus".

db

A character vector specifying the annotation sources to be included in the gene annotation databases. Can be one or more of "GO", "GO_BP", "GO_CC", "GO_MF", "KEGG", "WikiPathway", "Reactome", "CORUM", "MP", "DO", "HPO", "PFAM", "CSPA", "Surfaceome", "SPRomeDB", "VerSeDa", "TFLink", "hTFtarget", "TRRUST", "JASPAR", "ENCODE", "MSigDB", "CellTalk", "CellChat", "Chromosome", "GeneType", "Enzyme", "TF".

db_update

Whether the gene annotation databases should be forcefully updated. If set to FALSE, the function will attempt to load the cached databases instead. Default is FALSE.

db_version

A character vector specifying the version of the gene annotation databases to be retrieved. Default is "latest".

convert_species

Whether to use a species-converted database when the annotation is missing for the specified species. Default is TRUE.

Ensembl_version

An integer specifying the Ensembl version. Default is NULL. If NULL, the latest version will be used.

mirror

Specify an Ensembl mirror to connect to. The valid options here are "www", "uswest", "useast", "asia".

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.

cores

The number of cores to use for parallelization with foreach::foreach. Default is 1.

verbose

Whether to print the message. Default is TRUE.

seed

Random seed for reproducibility. Default is 11.

Examples

data(pancreas_sub)
pancreas_sub <- standard_scop(pancreas_sub)
#>  [2026-01-27 08:08:44] Start standard scop workflow...
#>  [2026-01-27 08:08:45] Checking a list of <Seurat>...
#> ! [2026-01-27 08:08:45] Data 1/1 of the `srt_list` is "unknown"
#>  [2026-01-27 08:08:45] Perform `NormalizeData()` with `normalization.method = 'LogNormalize'` on the data 1/1 of the `srt_list`...
#>  [2026-01-27 08:08:47] Perform `Seurat::FindVariableFeatures()` on the data 1/1 of the `srt_list`...
#>  [2026-01-27 08:08:48] Use the separate HVF from srt_list
#>  [2026-01-27 08:08:48] Number of available HVF: 2000
#>  [2026-01-27 08:08:48] Finished check
#>  [2026-01-27 08:08:48] Perform `Seurat::ScaleData()`
#>  [2026-01-27 08:08:49] Perform pca linear dimension reduction
#>  [2026-01-27 08:08:50] Perform `Seurat::FindClusters()` with `cluster_algorithm = 'louvain'` and `cluster_resolution = 0.6`
#>  [2026-01-27 08:08:50] Reorder clusters...
#>  [2026-01-27 08:08:50] Perform umap nonlinear dimension reduction
#>  [2026-01-27 08:08:50] Non-linear dimensionality reduction (umap) using (Standardpca) dims (1-50) as input
#>  [2026-01-27 08:08:54] Non-linear dimensionality reduction (umap) using (Standardpca) dims (1-50) as input
#>  [2026-01-27 08:08:59] Run scop standard workflow completed
pancreas_sub <- RunSlingshot(
  pancreas_sub,
  group.by = "CellType",
  reduction = "UMAP"
)

pancreas_sub <- RunDynamicFeatures(
  pancreas_sub,
  lineages = "Lineage1",
  n_candidates = 200
)
#>  [2026-01-27 08:09:00] Start find dynamic features
#>  [2026-01-27 08:09:00] Data type is raw counts
#>  [2026-01-27 08:09:01] Number of candidate features (union): 200
#>  [2026-01-27 08:09:02] Data type is raw counts
#>  [2026-01-27 08:09:02] Calculating dynamic features for "Lineage1"...
#>  [2026-01-27 08:09:02] Using 1 core
#>  [2026-01-27 08:09:02] Running for Gcg [1/200] 
#>  [2026-01-27 08:09:02] Running for Arg1 [42/200] ■■■■■■■                      
#>  [2026-01-27 08:09:02] Running for Aurkb [88/200] ■■■■■■■■■■■■■■              
#>  [2026-01-27 08:09:02] Running for Ass1 [137/200] ■■■■■■■■■■■■■■■■■■■■■■      
#>  [2026-01-27 08:09:02] Running for Dusp1 [185/200] ■■■■■■■■■■■■■■■■■■■■■■■■■■■
#>  [2026-01-27 08:09:02] Completed 200 tasks in 12.2s
#> 
#>  [2026-01-27 08:09:02] Building results
#>  [2026-01-27 08:09:14] Find dynamic features done
ht1 <- DynamicHeatmap(
  pancreas_sub,
  lineages = "Lineage1",
  cell_annotation = "CellType",
  n_split = 3
)
#>  [2026-01-27 08:09:14] [1] 146 features from Lineage1 passed the threshold (exp_ncells>[1] 20 & r.sq>[1] 0.2 & dev.expl>[1] 0.2 & padjust<[1] 0.05): 
#>                        Gcg,Ins1,Ins2,Nnat,Iapp,Lrpprc,Chgb,Slc38a5,2810417H13Rik,Rbp4...
#>  [2026-01-27 08:09:15] 
#>                        The size of the heatmap is fixed because certain elements are not scalable.
#>                        The width and height of the heatmap are determined by the size of the current viewport.
#>                        If you want to have more control over the size, you can manually set the parameters 'width' and 'height'.


pancreas_sub <- RunDynamicEnrichment(
  pancreas_sub,
  lineages = "Lineage1",
  score_method = "AUCell",
  db = "GO_BP",
  species = "Mus_musculus"
)
#>  [2026-01-27 08:09:16] Species: "Mus_musculus"
#>  [2026-01-27 08:09:16] Loading cached: GO_BP version: 3.22.0 nterm:15169 created: 2026-01-27 07:42:00
#>  [2026-01-27 08:09:19] Start cell scoring
#>  [2026-01-27 08:09:19] Data type is log-normalized
#>  [2026-01-27 08:09:21] Number of feature lists to be scored: 2761
#>  [2026-01-27 08:12:12] Cell scoring completed
#>  [2026-01-27 08:12:12] Start find dynamic features
#>  [2026-01-27 08:12:13] Data type is log-normalized
#>  [2026-01-27 08:12:13] Number of candidate features (union): 2761
#>  [2026-01-27 08:12:13] Data type is log-normalized
#>  [2026-01-27 08:12:13] Calculating dynamic features for "Lineage1"...
#>  [2026-01-27 08:12:13] Using 1 core
#>  [2026-01-27 08:12:13] Running for GO-BP-2..deoxyribonucleotide.biosynthetic.p
#>  [2026-01-27 08:12:13] Running for GO-BP-atrial.cardiac.muscle.tissue.developm
#>  [2026-01-27 08:12:13] Running for GO-BP-cellular.response.to.lipopolysacchari
#>  [2026-01-27 08:12:13] Running for GO-BP-epithelial.structure.maintenance [563
#>  [2026-01-27 08:12:13] Running for GO-BP-insulin.receptor.signaling.pathway [7
#>  [2026-01-27 08:12:13] Running for GO-BP-mitochondrial.gene.expression [966/27
#>  [2026-01-27 08:12:13] Running for GO-BP-negative.regulation.of.intracellular.
#>  [2026-01-27 08:12:13] Running for GO-BP-olfactory.lobe.development [1379/2761
#>  [2026-01-27 08:12:13] Running for GO-BP-positive.regulation.of.glial.cell.pro
#>  [2026-01-27 08:12:13] Running for GO-BP-positive.regulation.of.viral.genome.r
#>  [2026-01-27 08:12:13] Running for GO-BP-regulation.of.bone.mineralization [19
#>  [2026-01-27 08:12:13] Running for GO-BP-regulation.of.macrophage.migration [2
#>  [2026-01-27 08:12:13] Running for GO-BP-regulation.of.telomere.maintenance.vi
#>  [2026-01-27 08:12:13] Running for GO-BP-signal.transduction.in.response.to.DN
#>  [2026-01-27 08:12:13] Completed 2761 tasks in 41.3s
#> 
#>  [2026-01-27 08:12:13] Building results
#>  [2026-01-27 08:12:55] Find dynamic features done
#>  [2026-01-27 08:12:55] Dynamic enrichment analysis completed
ht2 <- DynamicHeatmap(
  pancreas_sub,
  assay = "GO_BP",
  lineages = "Lineage1_GO_BP",
  cell_annotation = "CellType",
  n_split = 3,
  split_method = "kmeans-peaktime"
)
#>  [2026-01-27 08:12:55] [1] 1897 features from Lineage1_GO_BP passed the threshold (exp_ncells>[1] 20 & r.sq>[1] 0.2 & dev.expl>[1] 0.2 & padjust<[1] 0.05): 
#>                        GO-BP-2..deoxyribonucleotide.biosynthetic.process,GO-BP-2..deoxyribonucleotide.metabolic.process,GO-BP-ADP.catabolic.process,GO-BP-ADP.metabolic.process,GO-BP-ATP.biosynthetic.process,GO-BP-ATP.metabolic.process,GO-BP-ATP.synthesis.coupled.electron.transport,GO-BP-B.cell.activation,GO-BP-B.cell.apoptotic.process,GO-BP-B.cell.proliferation...
#> ! [2026-01-27 08:12:55] The values in the 'counts' layer are non-integer. Set the library size to 1.
#>  [2026-01-27 08:12:56] 
#>                        The size of the heatmap is fixed because certain elements are not scalable.
#>                        The width and height of the heatmap are determined by the size of the current viewport.
#>                        If you want to have more control over the size, you can manually set the parameters 'width' and 'height'.