Lesson · 40 min · Free
Clustering and Assigning Cell Types
Clustering and Assigning Cell Types After preprocessing single-cell RNA-seq data—quality control, normalization, and dimensionality reduction—the next major step is to group cells into biologically meaningful populations
Clustering and Assigning Cell Types
After preprocessing single-cell RNA-seq data—quality control, normalization, and dimensionality reduction—the next major step is to group cells into biologically meaningful populations. Clustering algorithms identify groups of cells with similar transcriptional profiles, allowing us to distinguish, for example, T cells from B cells within a complex tumor sample. The most widely used approach combines graph-based clustering with the low-dimensional representations produced by PCA and UMAP or t-SNE. Graph-based clustering works by constructing a k-nearest-neighbor (kNN) graph, where each cell is connected to its most transcriptionally similar neighbors. The algorithm then detects "communities" within this graph—groups of cells that are densely connected to each other but sparsely connected to other groups. The Louvain and Leiden algorithms are the most popular community-detection methods because they scale well to datasets with hundreds of thousands of cells. A critical parameter is the clustering resolution : low resolution yields broad cell classes, while high resolution splits populations into finer subtypes. Choosing an appropriate resolution often requires iterating between computational results and biological interpretation. Once clusters are identified, the key question becomes: what cell type is each cluster? The standard strategy is differential expression analysis—identifying genes that are highly expressed in one cluster relative to all others. These marker genes are then compared against known cell-type signatures. For example, high expression of CD3D and CD3E suggests T cells, MS4A1 (CD20) marks B cells, LYZ and S100A8 indicate monocytes, and PTPRC broadly confirms immune origin. Automated annotation tools such as SingleR, Azimuth, and CellTypist can accelerate this process by matching clusters against curated reference datasets, though manual inspection of canonical markers remains essential for confident annotation. The following example demonstrates clustering and visualization using the Seurat workflow in R: # Perform clustering on the top principal components pbmc <- FindNeighbors(pbmc, dims = 1:15) pbmc <- FindClusters(pbmc, resolution = 0.5) # Run UMAP for 2D visualization pbmc <- RunUMAP(pbmc, dims = 1:15) # Visualize clusters and a canonical T-cell marker DimPlot(pbmc, reduction = "umap", label = TRUE) FeaturePlot(pbmc, features = c("CD3D", "MS4A1", "LYZ")) The same analysis can be performed in Python using Scanpy, which follows an analogous workflow: import scanpy as sc # Build the neighbor graph and cluster with Leiden sc.pp.neighbors(adata, n_neighbors=10, n_pcs=15) sc.tl.leiden(adata, resolution=0.5, key_added="clusters") # Compute UMAP and visualize sc.tl.umap(adata) sc.pl.umap(adata, color=["clusters", "CD3D", "MS4A1"]) # Identify marker genes for each cluster sc.tl.rank_genes_groups(adata, groupby="clusters", method="wilcoxon") sc.pl.rank_genes_groups(adata, n_genes=10) When interpreting marker genes, remember that cluster identity is inferred, not measured directly. Ambiguous markers, doublets, and stress-induced genes can all mislead annotation, so cross-checking multiple markers per proposed cell type is best practice. It is also wise to report the resolution used and to confirm that clusters are stable across nearby resolution values—clusters that only appear at very high resolution may reflect noise rather than genuine biology. Graph-based clustering (Louvain/Leiden) on a kNN graph is the standard method for grouping single-cell transcriptomic data. Clustering resolution controls granularity; it should be chosen based on biological expectations, not defaults alone. Cell types are assigned by examining cluster-specific marker genes against known canonical markers or reference datasets. Automated annotation tools (SingleR, Azimuth, CellTypist) speed up labeling but should be validated manually. Always visualize marker expression on UMAP plots to confirm that annotation is spatially coherent within clusters. Practice exercise: Using the PBMC3k dataset bundled with Scanpy, run the full pipeline from normalization through PCA, clustering at three different resolutions (0.2, 0.5, and 1.0), and UMAP visualization. For each resolution, use sc.tl.rank_genes_groups to extract the top five marker genes per cluster, then assign a putative cell type to each cluster using canonical markers such as CD3D (T cells), MS4A1 (B cells), LYZ (monocytes), NKG7 (NK cells), and PPBP (platelets). Write a short summary describing how the number of clusters and the ease of annotation changed as resolution increased, and state which resolution you would choose for downstream analysis and why.
Watch the full lesson — free
This topic is part of Computational Biomedicine: From Command Line to Single-Cell, a complete AI-narrated video course. Press play once and watch the entire lecture like a movie.
Start the course free →