LSMA

LONDON SCHOOL OF MULTIOMICS & AI

LSMA

LONDON SCHOOL OF MULTIOMICS & AI

Free course

Free course

0 of 31 lessons

Markers and cell types

Markers and cell types

Markers and cell types

Nine numbered clusters become nine named cell types. This lesson finds each cluster's marker genes, explains every column of the result and why its p-values are too small, and checks the names against known blood-cell markers.

Finding the genes that define each cluster

Clustering and UMAP split the 2,635 cells into nine clusters, numbered 0 to 8. Numbers are not cell types. This lesson finds the genes that mark each cluster, compares them with genes known from decades of immunology, and gives each cluster a name.

A marker gene is one expressed more in a cluster than in the other cells. Seurat finds them by testing every gene in every cluster against all remaining cells, by default with the Wilcoxon rank-sum test from Comparing two groups, run on the log-normalised values.

R
library(Seurat)
library(ggplot2)
pbmc <- readRDS("pbmc_clustered.rds")
Idents(pbmc) <- "RNA_snn_res.0.5"

markers <- FindAllMarkers(pbmc, only.pos = TRUE, logfc.threshold = 0.5,
                          min.pct = 0.25, verbose = FALSE)
dim(markers)

top <- do.call(rbind, lapply(split(markers, markers$cluster), function(d)
  head(d[order(d$p_val_adj, -d$avg_log2FC), ], 3)))
top[, c("cluster", "gene", "avg_log2FC", "pct.1", "pct.2", "p_val_adj")]
[1] 2663 7 cluster gene avg_log2FC pct.1 pct.2 p_val_adj 0.RPS12 0 RPS12 0.7510121 1.000 0.992 1.259283e-144 … 1.S100A8 1 S100A8 6.6451206 0.975 0.121 0.000000e+00 1.S100A9 1 S100A9 6.1586586 0.996 0.216 0.000000e+00 … 3.CD79A 3 CD79A 6.9093333 0.936 0.041 0.000000e+00 3.MS4A1 3 MS4A1 5.7166319 0.855 0.053 0.000000e+00 … 6.GZMB1 6 GZMB 6.0050206 0.986 0.071 2.793640e-261 … 7.FCER1A 7 FCER1A 7.6524718 0.818 0.011 3.713755e-226 … 8.ITGA2B 8 ITGA2B 11.6159641 0.833 0.002 0.000000e+00 8.GP9 8 GP9 11.4234729 0.917 0.002 0.000000e+00

What this does

  • FindAllMarkers() compares each cluster in turn with all other cells. only.pos = TRUE keeps genes higher in the cluster, which is what a marker usually means.
  • logfc.threshold = 0.5 tests only genes whose average log2 fold change is at least 0.5, about 1.4-fold, and min.pct = 0.25 only genes detected in at least 25% of the cells in one of the two groups. Both are filters that save time and remove weak candidates; they are not part of the test.
  • The second command keeps the three genes with the smallest adjusted p-values in each cluster, breaking ties by the largest fold change. 2,663 gene–cluster pairs passed in total.

Reading the columns

  • avg_log2FC is the log2 fold change between the cluster and the rest, the same scale as DESeq2's log2FoldChange. S100A8 at 6.6 is about 100 times higher in cluster 1.
  • pct.1 is the share of cells in the cluster with at least one UMI of the gene, and pct.2 the share among all other cells. These two often say more than the fold change. CD79A is detected in 93.6% of cluster 3 and 4.1% of the rest: a clean marker. RPS12, a ribosomal protein gene, is in 100% of cluster 0 but also in 99.2% of other cells: higher on average, but not something that marks the cluster.
  • p_val_adj is the p-value corrected by Bonferroni for the number of genes in the dataset. Values of exactly 0 are smaller than R can store.

The tiny p-values come with a warning, explained in the next section. Rank markers by fold change and by the gap between pct.1 and pct.2, and treat the p-value only as a rough filter.

R
m_mono <- FindMarkers(pbmc, ident.1 = "5", ident.2 = "1",
                      logfc.threshold = 0.5, min.pct = 0.25, verbose = FALSE)
head(m_mono, 5)
p_val avg_log2FC pct.1 pct.2 p_val_adj FCGR3A 1.193617e-101 5.019527 0.975 0.131 1.636926e-97 LYZ 9.061278e-75 -2.653741 0.988 1.000 1.242664e-70 RHOC 2.216219e-68 3.330606 0.864 0.160 3.039322e-64 S100A8 8.833368e-65 -4.016608 0.500 0.975 1.211408e-60 S100A9 1.736101e-64 -3.394937 0.870 0.996 2.380890e-60

FindMarkers() compares two chosen groups directly, here cluster 5 against cluster 1, which both sit on the monocyte island of the UMAP. A positive avg_log2FC means higher in ident.1, cluster 5. FCGR3A is in 97.5% of cluster 5 and 13.1% of cluster 1, while S100A8 is in 50% and 97.5%. Comparing close neighbours like this is how you tell apart clusters that the all-against-the-rest test finds similar.

Why marker p-values are too small

The clusters were made from the same genes that are now being tested. The algorithm placed the boundaries exactly where cells differ, so testing whether cells on either side differ is partly asking a question you have already answered. This is called double dipping: using the data once to form groups and again to test them. It is the leakage problem of Random forests and cross-validation in another form.

A simulation shows the size of the effect. The code below makes 600 "cells" whose 2,000 genes are pure random counts, with no structure at all, runs the usual pipeline, and tests markers. It then tests again after shuffling the cluster labels at random.

R
set.seed(11)
fake <- matrix(rpois(2000 * 600, lambda = 1), nrow = 2000,
               dimnames = list(paste0("g", 1:2000), paste0("c", 1:600)))
noise <- CreateSeuratObject(fake)
noise <- NormalizeData(noise, verbose = FALSE)
noise <- FindVariableFeatures(noise, verbose = FALSE)
noise <- ScaleData(noise, verbose = FALSE)
noise <- RunPCA(noise, npcs = 10, verbose = FALSE)
noise <- FindNeighbors(noise, dims = 1:10, verbose = FALSE)
noise <- FindClusters(noise, resolution = 0.8, random.seed = 1, verbose = FALSE)
table(Idents(noise))

noise_clusters <- Idents(noise)
nm <- FindAllMarkers(noise, logfc.threshold = 0, min.pct = 0,
                     return.thresh = 1, verbose = FALSE)
round(mean(nm$p_val < 0.05), 3)
sum(nm$p_val_adj < 0.05)

set.seed(12)
Idents(noise) <- factor(sample(unname(noise_clusters)))
nm2 <- FindAllMarkers(noise, logfc.threshold = 0, min.pct = 0,
                      return.thresh = 1, verbose = FALSE)
round(mean(nm2$p_val < 0.05), 3)
sum(nm2$p_val_adj < 0.05)
0 1 2 3 4 148 136 115 101 100 [1] 0.109 [1] 5 [1] 0.052 [1] 0

Reading the output

Pure noise still produced five clusters: the algorithm always finds groups, because that is what it is asked to do. Testing those clusters, 10.9% of the gene–cluster tests had p < 0.05, about twice the 5% expected by chance, and five "markers" survived the Bonferroni correction. With the same cluster sizes but random labels, 5.2% had p < 0.05, close to the expected rate, and nothing survived.

In real data, where clusters differ a great deal, the inflation is much larger and the p-values become very hard to interpret. The practical conclusions:

  • Use marker p-values to rank and filter candidates, not as evidence that a cluster exists.
  • Judge a cluster by whether its markers make biological sense and are clean (high pct.1, low pct.2), not by how small its p-values are.
  • For a formal test of a difference between groups of cells, the groups must be defined without the data being tested, for example by condition. That is the subject of Comparing conditions with pseudobulk.

Naming the clusters

Annotation means matching each cluster's markers to genes known to mark cell types. For blood, a short list covers the main types: IL7R and CCR7 in T cells (CCR7 especially in naive T cells), CD8A in CD8 T cells, MS4A1 in B cells, CD14 and LYZ in classical monocytes, FCGR3A and MS4A7 in non-classical monocytes, GNLY and NKG7 in NK cells, FCER1A and CST3 in dendritic cells, and PPBP in platelets.

R
known <- c("IL7R", "CCR7", "CD8A", "MS4A1", "CD14", "LYZ",
           "FCGR3A", "MS4A7", "GNLY", "NKG7", "FCER1A", "CST3", "PPBP")

DotPlot(pbmc, features = known) + RotatedAxis() + theme_classic() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))
FeaturePlot(pbmc, features = c("MS4A1", "CD14", "FCGR3A", "GNLY"), ncol = 2)
VlnPlot(pbmc, features = c("CD8A", "CCR7"), pt.size = 0)

pct <- sapply(levels(Idents(pbmc)), function(cl)
  rowMeans(LayerData(pbmc, layer = "counts")[known, WhichCells(pbmc, idents = cl)] > 0))
round(100 * pct)
0 1 2 3 4 5 6 7 8 IL7R 60 12 75 11 46 14 13 33 17 CCR7 43 2 25 16 4 5 1 9 0 CD8A 14 2 9 3 49 4 9 3 0 MS4A1 4 6 6 85 4 9 6 6 0 CD14 2 67 2 0 1 15 1 24 0 LYZ 47 100 54 42 42 99 43 97 42 FCGR3A 4 13 5 4 27 98 88 15 8 MS4A7 2 26 3 6 1 81 1 18 8 GNLY 9 13 12 8 35 14 96 24 0 NKG7 14 19 19 9 97 33 100 27 17 FCER1A 2 1 0 0 1 1 2 82 0 CST3 17 99 23 17 18 100 25 100 58 PPBP 1 5 2 1 1 7 0 3 100

What each plot shows

  • DotPlot() puts genes across and clusters down. The size of each dot is the percentage of cells expressing the gene and its colour the average scaled expression. It is the most compact summary for annotation; the table printed after it holds the same percentages as numbers.
  • FeaturePlot() colours the UMAP by one gene's expression. It shows whether a marker covers a whole cluster or only part of it.
  • VlnPlot() shows the distribution of one gene in each cluster, useful for genes such as CD8A that are detected in only some cells of a type.

Worked example · reading the table cluster by cluster

Look for the gene that is high in one cluster and low elsewhere, then check the others agree:

3: MS4A1 85% (others ≤ 9%) → B cells
8: PPBP 100% (others ≤ 7%) → platelets
7: FCER1A 82%, CST3 100% → dendritic cells
1: CD14 67%, LYZ 100%, FCGR3A 13% → CD14 monocytes
5: FCGR3A 98%, MS4A7 81%, CD14 15% → FCGR3A monocytes
6: GNLY 96%, NKG7 100%, CD8A 9% → NK cells
4: CD8A 49%, NKG7 97% → CD8 T cells
0: IL7R 60%, CCR7 43% → naive CD4 T cells
2: IL7R 75%, CCR7 25% → memory CD4 T cells

What the answer means. Seven clusters are clear from one or two genes. The two T-cell clusters 0 and 2 are the hard case: both express IL7R, and they differ in degree, with CCR7, a gene of naive T cells that have not yet met their antigen, more common in cluster 0. Cluster 2's own top markers, IL32 and LTB, fit memory T cells. Such labels deserve more caution than "B cells" does.

LYZ is detected in about 40–50% of T and B cells here. Monocytes hold so much LYZ RNA that RNA released from them into the liquid, ambient RNA, is a likely source. It is one reason to read pct.2 as well as pct.1.

R
labels <- c("0" = "Naive CD4 T", "1" = "CD14 monocyte", "2" = "Memory CD4 T",
            "3" = "B", "4" = "CD8 T", "5" = "FCGR3A monocyte",
            "6" = "NK", "7" = "Dendritic cell", "8" = "Platelet")
pbmc <- RenameIdents(pbmc, labels)
pbmc$cell_type <- Idents(pbmc)
DimPlot(pbmc, label = TRUE, repel = TRUE) + NoLegend() + theme_classic()

table(ours = pbmc$cell_type, published = pbmc$seurat_annotations)
published ours Naive CD4 T Memory CD4 T CD14+ Mono B CD8 T FCGR3A+ Mono Naive CD4 T 692 21 0 0 7 0 CD14 monocyte 0 0 479 0 0 0 Memory CD4 T 3 461 0 0 4 0 B 0 0 0 344 0 0 CD8 T 0 1 0 0 260 0 … published ours NK DC Platelet Naive CD4 T 0 0 0 … CD8 T 11 0 0 NK 144 0 0 Dendritic cell 0 32 0 Platelet 0 0 12

Checking against the published labels

RenameIdents() replaces cluster numbers with names, and the names are saved as a column so they survive later changes of identity. The cross-table compares them with the seurat_annotations column that came with the dataset. Adding the diagonal, 2,586 of 2,635 cells, 98%, get the same label. The disagreements are where you would expect: 21 cells called naive that the published labels call memory, and 11 cells called CD8 T that they call NK. These are the boundaries between similar types, where any clustering has to draw a line.

Do not read 98% as independent confirmation: the published labels were made with a very similar pipeline on the same cells. They show that your steps were run correctly, not that the biology is settled.

Go deeper: annotating from a reference

Choosing markers by hand works for well-known tissues and becomes hard for less familiar ones. Reference-based annotation compares each cell, or each cluster, with expression profiles of purified cell types. The SingleR package does this, and the celldex package supplies references such as the Human Primary Cell Atlas. The call is short, SingleR(test = ..., ref = ..., labels = ref$label.main), but celldex downloads its references on first use, so it was not run here.

A reference can only offer the labels it contains, and its cells may have been prepared differently from yours. Treat its labels as a second opinion to compare with your markers, and look closely wherever the two disagree.

Common mistakes

  • Reporting marker p-values as discoveries. Clusters were built to differ; the p-values are inflated by double dipping.
  • Ranking by fold change alone. A gene detected in 5% of a cluster can have a large fold change. Check pct.1 and pct.2.
  • Naming a cluster from one gene. Use two or three markers that agree, and a gene that is low elsewhere.
  • Mixing up the direction. In FindMarkers(), a positive fold change means higher in ident.1.

The problem of testing clusters with the data that defined them is analysed by Zhang, Kamath & Tibshirani 2019, "Valid post-clustering differential analysis for single-cell RNA-seq" (Cell Systems). SingleR is described in Aran et al. 2019 (Nature Immunology). For marker genes of immune cells, review articles and curated databases are a better source than any single dataset; state where your marker list came from.

Key point

Markers are found with statistics but named with biology. Read the fold change with the percentages of cells expressing each gene, confirm each label with several known markers, and treat marker p-values as a ranking, not as proof that a cluster is real.

Further reading · Module 6Zhang, Kamath & Tibshirani 2019: why testing clusters on the same data inflates p-values. · All reading for this course

Check your understanding

1. A marker for cluster 4 has avg_log2FC = 3, pct.1 = 0.08 and pct.2 = 0.01. How good a marker is it?

2. Why are the p-values from FindAllMarkers() too small to be taken at face value?

3. A cluster has high FCGR3A and MS4A7 and low CD14. Which cell type does this suggest?

Ask LSMA