A practical workflow for single-cell RNA-seq analysis

From a count matrix to annotated cell types, in the order you would run it.

Single-cell RNA-seq measures gene expression in thousands of individual cells. The raw output is a large, sparse table of counts, and most of the work is turning it into groups of cells that you can name and compare. This post walks through the standard path, with code in Scanpy (Python) and Seurat (R).

Start with a count matrix

A pipeline such as Cell Ranger gives you a matrix of counts: one entry for every cell and gene pair. Scanpy stores cells as rows, and Seurat stores them as columns. Most entries are zero. A zero usually means the gene was not detected in that cell, which is not always the same as not expressed.

1. Filter low-quality cells

Three simple measures catch most problems. Cells with very few detected genes are often empty droplets or debris. A high share of mitochondrial reads usually marks dying cells. Unusually high gene counts can point to doublets, where two cells were captured together.

Plot the distributions before choosing cut-offs, because good thresholds depend on the tissue and protocol. A limit of 10% mitochondrial reads is a common starting point and not a rule. Metabolically active tissues such as heart and kidney naturally have higher mitochondrial fractions, and a strict cut-off would remove real cells.

2. Normalise and choose variable genes

Cells differ in how deeply they were sequenced, so raw counts are not comparable between them. Normalisation scales each cell to the same total, and a log transform then reduces the influence of a few very high values. After that, keep around 2,000 highly variable genes. Focusing on them removes much of the noise from genes that barely change between cells.

3. Reduce dimensions

Run PCA on the variable genes and keep the first 30 to 50 components. Build a nearest-neighbour graph from those components. Then compute a UMAP for plotting. UMAP is for visualisation only: distances between islands on the plot are not quantitative, so cluster on the neighbour graph and not on the UMAP coordinates.

4. Cluster the cells

Leiden clustering on the neighbour graph is the usual choice. The resolution parameter controls how many clusters you get. Try several values and check that the clusters are stable and that each one is supported by distinct marker genes. Too many clusters is a common mistake, and it creates groups that differ only by noise.

5. Annotate cell types

Find the genes that distinguish each cluster, then compare them with known markers for the tissue. Reference-based tools such as CellTypist, SingleR and Azimuth can propose labels automatically. Treat those labels as a first draft and check them against marker genes yourself, especially for rare cell types.

6. Compare conditions with pseudobulk

If you want to compare conditions, treat samples as the unit of replication, not cells. Cells from the same sample are not independent, and testing them one by one makes differences look far more significant than they are. Instead, sum the counts for each sample and cell type, then use a bulk method such as DESeq2 or edgeR.

The workflow in Scanpy

import scanpy as sc

adata = sc.read_10x_h5("filtered_feature_bc_matrix.h5")
adata.var_names_make_unique()

# 1. Quality control
adata.var["mt"] = adata.var_names.str.startswith("MT-")
sc.pp.calculate_qc_metrics(adata, qc_vars=["mt"], inplace=True)
sc.pp.filter_cells(adata, min_genes=200)
sc.pp.filter_genes(adata, min_cells=3)
adata = adata[adata.obs["pct_counts_mt"] < 10].copy()

# 2. Normalise and select variable genes
adata.layers["counts"] = adata.X.copy()
sc.pp.normalize_total(adata, target_sum=1e4)
sc.pp.log1p(adata)
sc.pp.highly_variable_genes(adata, n_top_genes=2000)

# 3. Dimensionality reduction
sc.pp.pca(adata, n_comps=50)
sc.pp.neighbors(adata, n_neighbors=15, n_pcs=30)
sc.tl.umap(adata)

# 4. Clustering
sc.tl.leiden(adata, resolution=0.5, flavor="igraph", n_iterations=2, directed=False)

# 5. Marker genes per cluster
sc.tl.rank_genes_groups(adata, "leiden", method="wilcoxon")
sc.pl.umap(adata, color="leiden")

The same workflow in Seurat

library(Seurat)

counts <- Read10X("filtered_feature_bc_matrix/")
obj <- CreateSeuratObject(counts, min.cells = 3, min.features = 200)

# 1. Quality control
obj[["percent.mt"]] <- PercentageFeatureSet(obj, pattern = "^MT-")
obj <- subset(obj, subset = percent.mt < 10)

# 2. Normalise and select variable genes
obj <- NormalizeData(obj)
obj <- FindVariableFeatures(obj, nfeatures = 2000)
obj <- ScaleData(obj)

# 3. Dimensionality reduction
obj <- RunPCA(obj)
obj <- FindNeighbors(obj, dims = 1:30)
obj <- RunUMAP(obj, dims = 1:30)

# 4. Clustering
obj <- FindClusters(obj, resolution = 0.5)

# 5. Marker genes per cluster
markers <- FindAllMarkers(obj, only.pos = TRUE)

Common mistakes

Next: analysing spatial transcriptomics data  ยท  All posts