Original analysis (simplified)

This is a simplified version of the PBMC single-cell data analysis with Seurat.

# Load Seurat R package
library(Seurat)

# Set the seed of the random number generator:
set.seed(1234)

# Load data
pbmc.data <- Read10X(data.dir = "filtered_gene_bc_matrices/hg19/")

# Build the Seurat object
pbmc <- CreateSeuratObject(counts = pbmc.data,
                           project = "PBMC")

# Filter out low-quality cells
pbmc[["percent.mt"]] <- PercentageFeatureSet(pbmc, 
                                             pattern = "^MT-")
pbmc <- subset(pbmc, 
               subset =  nFeature_RNA > 200 & 
                 nFeature_RNA < 2500 & 
                 percent.mt < 5)

# Perform data normalization
pbmc <- NormalizeData(pbmc)

# Find highly variable genes
pbmc <- FindVariableFeatures(pbmc, 
                             nfeatures = 2000)
# Perform data scaling
pbmc <- ScaleData(pbmc, 
                  features = rownames(pbmc))

# Perform PCA
pbmc <- RunPCA(pbmc)

# Perform clustering
pbmc <- FindNeighbors(pbmc, 
                      dims = 1:10) 
pbmc <- FindClusters(pbmc, 
                     resolution = 0.5)

# Perform UMAP dimensionality reduction
pbmc <- RunUMAP(pbmc,
                dims = 1:10,
                n.neighbors = 30,
                min.dist = 0.3)

# Visualize UMAP plot
DimPlot(pbmc,
        reduction = "umap")

Impact of parameter settings

The following questions will guide you though the (visual) assessment of the impact of changes in some parameter settings. In particular, we will change clustering resultion, and the n.neighbors and min.dist parameters in UMAP dimensionality reduction.

Question: What happens if we increase the clustering resolution parameter to 1.5?

# Clustering
pbmc <- FindNeighbors(pbmc, 
                      dims = 1:10) 
pbmc <- FindClusters(pbmc, 
                     resolution = 1.5) # Original value: 0.5

# UMAP
pbmc <- RunUMAP(pbmc,
                dims = 1:10,
                n.neighbors = 30,
                min.dist = 0.3)
DimPlot(pbmc,
        reduction = "umap")

Question: What happens if we decrease the clustering resolution parameter to 0.1?

# Clustering
pbmc <- FindNeighbors(pbmc, 
                      dims = 1:10) 
pbmc <- FindClusters(pbmc, 
                     resolution = 0.1) # Original value: 0.5

# UMAP
pbmc <- RunUMAP(pbmc,
                dims = 1:10,
                n.neighbors = 30,
                min.dist = 0.3)
DimPlot(pbmc,
        reduction = "umap")

Question: What happens if we decrease the UMAP n.neighbors parameter to 5?

# Clustering
pbmc <- FindNeighbors(pbmc, 
                      dims = 1:10) 
pbmc <- FindClusters(pbmc, 
                     resolution = 0.1) 

# UMAP
pbmc <- RunUMAP(pbmc,
                dims = 1:10,
                n.neighbors = 5, # Original value: 30
                min.dist = 0.3)
DimPlot(pbmc,
        reduction = "umap")

Question: What happens if we increase the UMAP n.neighbors parameter to 1,000?

# Clustering
pbmc <- FindNeighbors(pbmc, 
                      dims = 1:10) 
pbmc <- FindClusters(pbmc, 
                     resolution = 0.1) 

# UMAP
pbmc <- RunUMAP(pbmc,
                dims = 1:10,
                n.neighbors = 1000, # Original value: 30
                min.dist = 0.3)
DimPlot(pbmc,
        reduction = "umap")

Question: What happens if we increase the UMAP min.dist parameter to 1, keeping n.neighbors = 30?

# Clustering
pbmc <- FindNeighbors(pbmc, 
                      dims = 1:10) 
pbmc <- FindClusters(pbmc, 
                     resolution = 0.1) 

# UMAP
pbmc <- RunUMAP(pbmc,
                dims = 1:10,
                n.neighbors = 30, # Original value: 30
                min.dist = 1)     # Original value: 0.3
DimPlot(pbmc,
        reduction = "umap")

Question: What happens if we decrease the UMAP min.dist parameter to 0.1, keeping n.neighbors = 30?

# Clustering
pbmc <- FindNeighbors(pbmc, 
                      dims = 1:10) 
pbmc <- FindClusters(pbmc, 
                     resolution = 0.1) 

# UMAP
pbmc <- RunUMAP(pbmc,
                dims = 1:10,
                n.neighbors = 30, # Original value: 30
                min.dist = 0.1)   # Original value: 0.3
DimPlot(pbmc,
        reduction = "umap")