Skip to contents

Run seurat unsupervised clustering

Usage

RunSeuratClustering(
  object,
  RunPCAArgs = list(),
  RunUMAPArgs = list(),
  FindNeighborsArgs = list(),
  FindClustersArgs = list(),
  log = NULL,
  cache = NULL
)

Arguments

object

Seurat object

RunPCAArgs

Arguments to pass to Seurat::RunPCA()

RunUMAPArgs

Arguments to pass to Seurat::RunUMAP(). RunUMAPArgs$features can be a character vector of features directly used for UMAP, or a list with the following fields:

  • order: The order of the markers to use for UMAP, e.g. "desc(abs(avg_log2FC))"

  • n: The number of total features to use for UMAP, e.g. 30 If RunUMAPArgs$features is a list, it will run RunSeuratDEAnalysis() to get the markers for each group, and then select the top n/ngroups features for each group based on the order field.

FindNeighborsArgs

Arguments to pass to Seurat::FindNeighbors()

FindClustersArgs

Arguments to pass to Seurat::FindClusters()

log

Logger

cache

Directory to cache the results. Set to FALSE to disable caching

Value

The Seurat object with clustering results

Examples

# \donttest{
obj <- RunSeuratClustering(SeuratObject::pbmc_small)
#> INFO    [2025-12-05 16:27:57] Running RunPCA ...
#> Warning: You're computing too large a percentage of total singular values, use a standard svd instead.
#> Warning: Requested number is larger than the number of available items (20). Setting to 20.
#> Warning: Requested number is larger than the number of available items (20). Setting to 20.
#> Warning: Requested number is larger than the number of available items (20). Setting to 20.
#> Warning: Requested number is larger than the number of available items (20). Setting to 20.
#> Warning: Requested number is larger than the number of available items (20). Setting to 20.
#> PC_ 1 
#> Positive:  SDPR, PF4, PPBP, TUBB1, CA2, TREML1, MYL9, PGRMC1, RUFY1, PARVB 
#> Negative:  HLA-DPB1, HLA-DQA1, S100A9, S100A8, GNLY, RP11-290F20.3, CD1C, AKR1C3, IGLL5, VDAC3 
#> PC_ 2 
#> Positive:  HLA-DPB1, HLA-DQA1, S100A8, S100A9, CD1C, RP11-290F20.3, PARVB, IGLL5, MYL9, SDPR 
#> Negative:  GNLY, AKR1C3, VDAC3, PGRMC1, TUBB1, PF4, TREML1, RUFY1, CA2, PPBP 
#> PC_ 3 
#> Positive:  S100A9, S100A8, RP11-290F20.3, AKR1C3, PARVB, GNLY, PPBP, PGRMC1, MYL9, TUBB1 
#> Negative:  HLA-DQA1, CD1C, IGLL5, HLA-DPB1, RUFY1, PF4, VDAC3, SDPR, TREML1, CA2 
#> PC_ 4 
#> Positive:  IGLL5, RP11-290F20.3, VDAC3, PPBP, TUBB1, TREML1, PF4, CA2, PARVB, MYL9 
#> Negative:  CD1C, AKR1C3, S100A8, GNLY, HLA-DPB1, HLA-DQA1, S100A9, PGRMC1, RUFY1, SDPR 
#> PC_ 5 
#> Positive:  MYL9, PARVB, IGLL5, TREML1, AKR1C3, PGRMC1, HLA-DPB1, S100A9, TUBB1, PF4 
#> Negative:  VDAC3, RP11-290F20.3, RUFY1, CD1C, HLA-DQA1, CA2, S100A8, PPBP, GNLY, SDPR 
#> INFO    [2025-12-05 16:27:58] Running FindNeighbors ...
#> Computing nearest neighbor graph
#> Computing SNN
#> INFO    [2025-12-05 16:27:59] Running FindClusters ...
#> INFO    [2025-12-05 16:27:59]   Using resolution(s): 0.8
#> Modularity Optimizer version 1.3.0 by Ludo Waltman and Nees Jan van Eck
#> 
#> Number of nodes: 80
#> Number of edges: 2352
#> 
#> Running Louvain algorithm...
#> Maximum modularity in 10 random starts: 0.4014
#> Number of communities: 2
#> Elapsed time: 0 seconds
#> INFO    [2025-12-05 16:28:00]   Found clusters (with resolution 0.8):
#> INFO    [2025-12-05 16:28:00]    | c1(44), c2(36)
#> INFO    [2025-12-05 16:28:00] Running RunUMAP ...
#> Warning: The default method for RunUMAP has changed from calling Python UMAP via reticulate to the R-native UWOT using the cosine metric
#> To use Python UMAP via reticulate, set umap.method to 'umap-learn' and metric to 'correlation'
#> This message will be shown once per session
#> 16:28:00 UMAP embedding parameters a = 0.9922 b = 1.112
#> 16:28:00 Read 80 rows and found 19 numeric columns
#> 16:28:00 Using Annoy for neighbor search, n_neighbors = 30
#> 16:28:00 Building Annoy index with metric = cosine, n_trees = 50
#> 0%   10   20   30   40   50   60   70   80   90   100%
#> [----|----|----|----|----|----|----|----|----|----|
#> *
#> *
#> *
#> *
#> *
#> *
#> *
#> *
#> *
#> *
#> *
#> *
#> *
#> *
#> *
#> *
#> *
#> *
#> *
#> *
#> *
#> *
#> *
#> *
#> *
#> *
#> *
#> *
#> *
#> *
#> *
#> *
#> *
#> *
#> *
#> *
#> *
#> *
#> *
#> *
#> *
#> *
#> *
#> *
#> *
#> *
#> *
#> *
#> *
#> *
#> |
#> 16:28:00 Writing NN index file to temp file /tmp/RtmpWi8BeT/file252b4f119bfc
#> 16:28:00 Searching Annoy index using 1 thread, search_k = 3000
#> 16:28:00 Annoy recall = 100%
#> 16:28:01 Commencing smooth kNN distance calibration using 1 thread
#>  with target n_neighbors = 30
#> 16:28:01 7 smooth knn distance failures
#> 16:28:02 Initializing from normalized Laplacian + noise (using RSpectra)
#> 16:28:02 Commencing optimization for 500 epochs, with 2664 positive edges
#> 16:28:02 Using rng type: pcg
#> 16:28:03 Optimization finished
GetIdentityColumn(obj)
#> Warning: [GetIdentityColumn] Using 'seurat_clusters' as the identity column, other candidates: seurat_clusters.0.8
#> [1] "seurat_clusters"
table(obj$seurat_clusters)
#> 
#> c1 c2 
#> 44 36 
# }