Running PCA
PCA is calculated on the scale.data slot of an assay using calculate_pca(). The result is stored in dataset@reduction under the name PCA.<assay> by default. Make sure to run scale_dataset() first (see feature transformation and scaling).
Features with any NA values are automatically excluded. A warning is raised listing how many were removed. The full prcomp object (including loadings) can be retained by setting ret.prcomp=TRUE.
Clustering cells
Clustering is performed on a PCA reduction using calculate_clustering(), which builds a k-nearest neighbour graph and applies Louvain or Leiden community detection. Cluster labels are added as new columns in dataset@meta under the name <col.out>res_<resolution>.
The k argument controls the number of nearest neighbours used to build the graph (default 10). Higher k tends to produce larger, coarser clusters. The method argument can be "louvain" (default) or "leiden". The graph is cached on the dataset and reused automatically if k, reduction, and exact.nn are unchanged.
By default an approximate nearest neighbour (Annoy-based) is used for speed. For exact kNN, set exact.nn=TRUE.
Running UMAP
UMAP is calculated from an existing PCA reduction using calculate_umap(). The result is stored in dataset@reduction under the name UMAP.PCA.<assay> by default.
Additional arguments are passed through to uwot::umap(), so hyperparameters such as n_neighbors, min_dist and spread can be tuned via ....
For very large datasets, a random subsample can be used to compute the UMAP embedding while preserving the full object count in the output (non-sampled objects are set to NA):
Visualizing reductions
The tglow_dimplot() function plots any two-dimensional reduction stored in dataset@reduction.