Calculates dynamic features for lineages in a single-cell RNA-seq dataset.
Usage
RunDynamicFeatures(
srt,
lineages,
features = NULL,
suffix = lineages,
n_candidates = 1000,
minfreq = 5,
family = NULL,
layer = "counts",
assay = NULL,
libsize = NULL,
BPPARAM = BiocParallel::bpparam(),
seed = 11
)
Arguments
- srt
A Seurat object.
- lineages
A character vector specifying the lineage names for which dynamic features should be calculated.
- features
A character vector specifying the features (genes or metadata variables) for which dynamic features should be calculated. If NULL, n_candidates must be provided.
- suffix
A character vector specifying the suffix to append to the output layer names for each lineage. Defaults to the lineage names.
- n_candidates
An integer specifying the number of candidate features to select when features is NULL. Defaults to 1000.
- minfreq
An integer specifying the minimum frequency threshold for candidate features. Features with a frequency less than minfreq will be excluded. Defaults to 5.
- family
A character or character vector specifying the family of distributions to use for the generalized additive models (GAMs). If family is set to NULL, the appropriate family will be automatically determined based on the data. If length(family) is 1, the same family will be used for all features. Otherwise, family must have the same length as features.
- 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.
- libsize
A numeric or numeric vector specifying the library size correction factors for each cell. If NULL, the library size correction factors will be calculated based on the expression matrix. If length(libsize) is 1, the same value will be used for all cells. Otherwise, libsize must have the same length as the number of cells in srt. Defaults to NULL.
- BPPARAM
A BiocParallelParam object specifying the parallelization parameters for computing dynamic features. Defaults to BiocParallel::bpparam.
- seed
An integer specifying the seed for random number generation. Defaults to 11.
Value
Returns the modified Seurat object with the calculated dynamic features stored in the tools slot.
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 = c("Lineage1", "Lineage2"),
n_candidates = 200
)
#> ℹ [2025-07-02 02:58:37] Start RunDynamicFeatures
#> ℹ [2025-07-02 02:58:37] Workers: 2
#> Finding variable features for layer counts
#> Finding variable features for layer counts
#> ℹ [2025-07-02 02:58:39] Number of candidate features(union): 226
#> ℹ [2025-07-02 02:58:40] Calculate dynamic features for Lineage1...
#>
|
| | 0%
|
|=================================== | 50%
|
|======================================================================| 100%
#>
#> ℹ [2025-07-02 02:59:07] Calculate dynamic features for Lineage2...
#>
|
| | 0%
|
|=================================== | 50%
|
|======================================================================| 100%
#>
#> ℹ [2025-07-02 02:59:15] RunDynamicFeatures done
#> ℹ [2025-07-02 02:59:15] Elapsed time:38.33 secs
names(
pancreas_sub@tools$DynamicFeatures_Lineage1
)
#> [1] "DynamicFeatures" "raw_matrix" "fitted_matrix" "upr_matrix"
#> [5] "lwr_matrix" "libsize" "lineages" "family"
head(
pancreas_sub@tools$DynamicFeatures_Lineage1$DynamicFeatures
)
#> features exp_ncells r.sq dev.expl peaktime valleytime pvalue
#> Gcg Gcg 221 -0.2692846 0.5962795 24.26994 11.833504 0
#> Ins2 Ins2 125 0.4729475 0.6745683 24.26994 10.023297 0
#> Nnat Nnat 310 0.4525511 0.5035587 24.26994 4.631264 0
#> Ghrl Ghrl 184 0.1087754 0.4638121 21.72654 18.828706 0
#> Ins1 Ins1 205 0.4406159 0.6619502 24.26994 3.421896 0
#> Iapp Iapp 430 0.4967401 0.7513166 24.26994 5.286387 0
#> padjust
#> Gcg 0
#> Ins2 0
#> Nnat 0
#> Ghrl 0
#> Ins1 0
#> Iapp 0
ht <- DynamicHeatmap(
srt = pancreas_sub,
lineages = c("Lineage1", "Lineage2"),
cell_annotation = "SubCellType",
n_split = 6,
reverse_ht = "Lineage1"
)
#> ℹ [2025-07-02 02:59:15] 158 features from Lineage1,Lineage2 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-02 02:59:17]
#> 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'.
ht$plot
DynamicPlot(
srt = pancreas_sub,
lineages = c("Lineage1", "Lineage2"),
features = c("Arxes1", "Ncoa2"),
group.by = "SubCellType",
compare_lineages = TRUE,
compare_features = FALSE
)
#> ℹ [2025-07-02 02:59:21] Start RunDynamicFeatures
#> ℹ [2025-07-02 02:59:21] Workers: 2
#> ℹ [2025-07-02 02:59:22] Number of candidate features(union): 2
#> ℹ [2025-07-02 02:59:22] Calculate dynamic features for Lineage1...
#>
|
| | 0%
|
|=================================== | 50%
|
|======================================================================| 100%
#>
#> ℹ [2025-07-02 02:59:24] RunDynamicFeatures done
#> ℹ [2025-07-02 02:59:24] Elapsed time:3.61 secs
#> ℹ [2025-07-02 02:59:24] Start RunDynamicFeatures
#> ℹ [2025-07-02 02:59:24] Workers: 2
#> ℹ [2025-07-02 02:59:25] Number of candidate features(union): 2
#> ℹ [2025-07-02 02:59:26] Calculate dynamic features for Lineage2...
#>
|
| | 0%
|
|=================================== | 50%
|
|======================================================================| 100%
#>
#> ℹ [2025-07-02 02:59:28] RunDynamicFeatures done
#> ℹ [2025-07-02 02:59:28] Elapsed time:3.74 secs
#> 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: No shared levels found between `names(values)` of the manual scale and the
#> data's fill values.