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 = 103,
  mirror = NULL,
  TERM2GENE = NULL,
  TERM2NAME = NULL,
  minGSSize = 10,
  maxGSSize = 500,
  BPPARAM = BiocParallel::bpparam(),
  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". Defaults to "Seurat".

layer

A character vector specifying the layer in the Seurat object to use. Default is "counts".

assay

A character vector specifying the assay in the Seurat object to use. Default is NULL.

min_expcells

A numeric value specifying the minimum number of expected cells. Default is 20.

r.sq

A numeric value specifying the R-squared threshold. Default is 0.2.

dev.expl

A numeric value specifying the deviance explained threshold. Default is 0.2.

padjust

A numeric value specifying 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 analysis is performed.

db

A character vector specifying the name of the database to be used for enrichment analysis.

db_update

A logical value indicating 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 database to be used. This argument is ignored if db_update is TRUE. Default is "latest".

convert_species

A logical value indicating whether to use a species-converted database when the annotation is missing for the specified species. The default value is TRUE.

Ensembl_version

Ensembl database version. If NULL, use the current release version.

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

A numeric value specifying the minimum size of a gene set to be considered in the enrichment analysis.

maxGSSize

A numeric value specifying the maximum size of a gene set to be considered in the enrichment analysis.

BPPARAM

A BiocParallelParam object specifying the parallel back-end to be used for parallel computation. Defaults to BiocParallel::bpparam().

seed

The random seed for reproducibility. Defaults to 11.

Examples

data("pancreas_sub")
pancreas_sub <- RunSlingshot(
  pancreas_sub,
  group.by = "SubCellType",
  reduction = "UMAP"
)
#> Warning: No shared levels found between `names(values)` of the manual scale and the
#> data's fill values.
#> Warning: No shared levels found between `names(values)` of the manual scale and the
#> data's fill values.
#> Warning: Removed 9 rows containing missing values or values outside the scale range
#> (`geom_path()`).
#> Warning: Removed 9 rows containing missing values or values outside the scale range
#> (`geom_path()`).
#> Warning: Removed 13 rows containing missing values or values outside the scale range
#> (`geom_path()`).
#> Warning: Removed 13 rows containing missing values or values outside the scale range
#> (`geom_path()`).

pancreas_sub <- RunDynamicFeatures(
  pancreas_sub,
  lineages = "Lineage1",
  n_candidates = 200
)
#>  [2025-07-03 08:40:12] Start RunDynamicFeatures
#>  [2025-07-03 08:40:12] Workers: 2
#> Finding variable features for layer counts
#>  [2025-07-03 08:40:14] Number of candidate features(union): 200
#>  [2025-07-03 08:40:14] Calculate dynamic features for Lineage1...
#> 
  |                                                                            
  |                                                                      |   0%
  |                                                                            
  |===================================                                   |  50%
  |                                                                            
  |======================================================================| 100%
#> 
#>  [2025-07-03 08:40:36] RunDynamicFeatures done
#>  [2025-07-03 08:40:36] Elapsed time:24.11 secs
ht1 <- DynamicHeatmap(
  srt = pancreas_sub,
  lineages = "Lineage1",
  cell_annotation = "SubCellType",
  n_split = 4
)
#>  [2025-07-03 08:40:36] 139 features from Lineage1 passed the threshold (exp_ncells>20 & r.sq>0.2 & dev.expl>0.2 & padjust<0.05): 
#> Ins2,Nnat,Ins1,Iapp,Pyy,Npy,Chgb,2810417H13Rik,Rbp4,Cdkn1a...
#> 'magick' package is suggested to install to give better rasterization.
#> 
#> Set `ht_opt$message = FALSE` to turn off this message.
#>  [2025-07-03 08:40:38] 
#> 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'.

ht1$plot


pancreas_sub <- RunDynamicEnrichment(
  srt = pancreas_sub,
  lineages = "Lineage1",
  score_method = "UCell",
  db = "GO_BP",
  species = "Mus_musculus"
)
#>  [2025-07-03 08:40:39] Start RunDynamicFeatures
#>  [2025-07-03 08:40:39] Workers: 2
#>  [2025-07-03 08:40:39] Species: Mus_musculus
#>  [2025-07-03 08:40:39] Loading cached db: GO_BP version:3.21.0 nterm:15445 created:2025-07-03 08:21:21.572096
#>  [2025-07-03 08:40:43] Number of feature lists to be scored: 2759
#>  [2025-07-03 08:40:43] Start CellScoring
#>  [2025-07-03 08:40:43] Workers: 2
#> 
  |                                                                            
  |                                                                      |   0%
  |                                                                            
  |===================================                                   |  50%
  |                                                                            
  |======================================================================| 100%
#> 
#> Warning: Feature names cannot have underscores ('_'), replacing with dashes ('-')
#> Warning: Feature names cannot have underscores ('_'), replacing with dashes ('-')
#>  [2025-07-03 08:41:41] CellScoring done
#>  [2025-07-03 08:41:41] Elapsed time: 57.26 secs
#>  [2025-07-03 08:41:41] Start RunDynamicFeatures
#>  [2025-07-03 08:41:41] Workers: 2
#>  [2025-07-03 08:41:41] Number of candidate features(union): 2759
#>  [2025-07-03 08:41:42] Calculate dynamic features for Lineage1...
#> 
  |                                                                            
  |                                                                      |   0%
  |                                                                            
  |===================================                                   |  50%
  |                                                                            
  |======================================================================| 100%
#> 
#>  [2025-07-03 08:42:35] RunDynamicFeatures done
#>  [2025-07-03 08:42:35] Elapsed time:54.26 secs
#>  [2025-07-03 08:42:35] RunDynamicEnrichment done
#>  [2025-07-03 08:42:35] Elapsed time:1.93 mins
ht2 <- DynamicHeatmap(
  srt = pancreas_sub,
  assay = "GO_BP",
  lineages = "Lineage1_GO_BP",
  cell_annotation = "SubCellType",
  n_split = 4,
  split_method = "kmeans-peaktime"
)
#>  [2025-07-03 08:42:35] 1772 features from Lineage1_GO_BP passed the threshold (exp_ncells>20 & r.sq>0.2 & dev.expl>0.2 & padjust<0.05): 
#> GO-BP-2..deoxyribonucleotide.biosynthetic.process,GO-BP-2..deoxyribonucleotide.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.differentiation,GO-BP-B.cell.proliferation,GO-BP-BMP.signaling.pathway...
#> ! [2025-07-03 08:42:35] The values in the 'counts' layer are non-integer. Set the library size to 1.
#> 'magick' package is suggested to install to give better rasterization.
#> 
#> Set `ht_opt$message = FALSE` to turn off this message.
#>  [2025-07-03 08:42:36] 
#> 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'.

ht2$plot