Clustering Analysis - Answer Key

Author

Noor Sohail

Published

August 17, 2026

Exercise 1

  1. What differences do you notice between resolution 0.4 and 0.8?

There are more clusters in resolution 0.8 compared to 0.4

# UMAP resolution 0.4 and 0.8
DimPlot(seurat_integrated,
        reduction = "umap",
        group.by = c("integrated_snn_res.0.4",
                     "integrated_snn_res.0.8"))
Figure 1: Cells colored by leiden resolutions 0.4 and 0.8 on the UMAP.
# UMAP resolution 0.4 and 0.8
sc.pl.embedding(adata_integrated, 
                color = ["leiden_0.4" ,"leiden_0.8"], 
                basis = "umap_scvi")
Figure 2: Cells colored by leiden resolutions 0.4 and 0.8 on the UMAP.

Exercise 2

  1. Check the object at each different resolution (0.4, 0.6, 0.8, 1.0, 1.4). For each resolution plot the corresponding UMAP and report how many clusters you observe.
resolutions <- c(0.4, 0.6, 0.8, 1.0, 1.4)

for (res in resolutions) {
  p <- DimPlot(seurat_integrated,
        reduction = "umap",
        group.by = paste0("integrated_snn_res.", res))
  print(p)

  n_clust <- seurat_integrated@meta.data[paste0("integrated_snn_res.", res)] %>%
    unique() %>% unname() %>% unlist() %>% length()
  print(paste("Resolution", res, "=", n_clust, "clusters"))
}

[1] "Resolution 0.4 = 12 clusters"

[1] "Resolution 0.6 = 15 clusters"

[1] "Resolution 0.8 = 16 clusters"

[1] "Resolution 1 = 20 clusters"

[1] "Resolution 1.4 = 26 clusters"
resolutions = [0.4, 0.6, 0.8, 1.0, 1.4]

for res in resolutions:

  # Number of clusters at this resolution
  n_clust = adata_integrated.obs[f"leiden_{res}"].nunique()
  print(f"Resolution {res}: {n_clust} clusters")

  sc.pl.embedding(adata_integrated, 
                color = f"leiden_{res}", 
                basis = "umap_scvi")
Resolution 0.4: 12 clusters
Resolution 0.6: 14 clusters
Resolution 0.8: 17 clusters
Resolution 1.0: 19 clusters
Resolution 1.4: 25 clusters


Back to Lesson >>

Back to Schedule

Reuse

CC-BY-4.0