Dr Cheng ZhangDigital Liver Group · translational systems medicine

Bioinformatics, step by step · Workshop

Module 3 · Exploring samples with PCA

Video: T4 PCA, step by step. Script: scripts/03_exploration_pca.R

Goal. See whether the samples group as we expect, before any statistical testing. Find out what PCA is sensitive to.

A. The original approach: PCA on raw TPM

p_raw <- prcomp(t(tpm), scale. = FALSE)

Q3.1 How much variance does PC1 explain? Do the samples separate by condition?

Q3.2 Which genes have the largest weights (p_raw$rotation[, 1])? What share of the total variance do the top 10 most variable genes carry? What does that tell you about PCA on an untransformed scale?

B. and C. Log scale, then vst

Q3.3 Repeat with log2(TPM + 1), and then with DESeq2's vst() on the counts (top 500 most variable genes). How do the plots change? Which samples separate on PC1, and which on PC2?

Q3.4 Why should we use blind = TRUE in vst() for quality control, but might use blind = FALSE later?

D. and E. Scree plot and sample distances

Q3.5 How many PCs do you need to explain 90% of the variance in the vst data?

Q3.6 In the distance heatmap, are the replicates each other's nearest neighbours? Would you remove any sample?

Theory check (video T4). For two genes, PC1 is the line through the centred data with the largest variance of the projected points. Use prcomp() on the 6 × 2 toy matrix below, and check that PC1 explains about 94% of the variance.

X <- rbind(c(3, 5), c(4, 3.5), c(5, 6.5), c(9, 8), c(10, 11), c(11, 8.5))
summary(prcomp(X))