Week 1 — Compensation & spectral unmixing in flow cytometry

Photo: Mark Fergus, CSIRO, CC BY 3.0, via Wikimedia Commons.

Schematic: Kierano, CC BY 3.0, via Wikimedia Commons.
One real sample: 10 000 cells, one row per cell, one column per detector.
FSC-H SSC-H FL1-H FL2-H (first 4 of 10 000 cells)
[1,] 382 77 259.5 1.0
[2,] 628 280 9.1 48.3
[3,] 1023 735 537.6 56.2
[4,] 373 128 6.2 24.1
Groups of cells separate by size and granularity (left) and by dye brightness (right). Example file 0877408774.B08 (FACSCalibur) from the Bioconductor package flowCore.
A flow cytometer measures thousands of cells per second, each stained with several fluorescent dyes. The detectors do not see one dye each: the colours leak into each other’s detectors and we have to compensate!
solve(S), just like undoing a misaligned image.Each detector sees a mix of the two dyes:
\begin{pmatrix} \text{FITC detector} \\ \text{PE detector} \end{pmatrix} = \begin{pmatrix} 1 & 0.02 \\ 0.25 & 1 \end{pmatrix} \begin{pmatrix} \text{FITC dye} \\ \text{PE dye} \end{pmatrix}
In words: measured = S × true, where S is the spillover matrix.
Four simulated populations, 1600 cells, one cell per column (like the pixels in Transforming images with matrices):
set.seed(1)
make_pop <- function(n, fitc, pe) { # true dye amounts, one cell per COLUMN
rbind(FITC = rlnorm(n, log(fitc), 0.3), PE = rlnorm(n, log(pe), 0.3))
}
true <- cbind(make_pop(600, 100, 100), # unstained
make_pop(400, 3000, 100), # FITC+
make_pop(400, 100, 2000), # PE+
make_pop(200, 3000, 2000)) # FITC+ PE+
group <- rep(c("unstained", "FITC+", "PE+", "FITC+ PE+"), c(600, 400, 400, 200))
noise <- function(n) matrix(rnorm(2 * n, 0, 30), nrow = 2) # detector noise
measured <- S %*% true + noise(ncol(true))How do we know the 0.25? Run a single-stained control: cells (or beads) carrying only FITC. Every PE-detector signal is then spillover.
ctrl <- S %*% rbind(FITC = rlnorm(500, log(3000), 0.5), PE = 0) +
noise(500)
fit <- lm(ctrl[2, ] ~ ctrl[1, ]) # PE detector vs FITC detector
coef(fit)[2] # slope 0.249: about 0.25
If measured = S\,\text{true}, then true = S^{-1}\,\text{measured}: the same solve() as in Linear systems in R.
solve(S) # [1.005 -0.020; -0.251 1.005]
comp <- solve(S) %*% measured # compensated: one %*% for all cellsThe FITC+ cells: median PE 850 before, 102 after (unstained cells: about 100).
solve(S) %*% S is the identity.\begin{pmatrix} a & b \\ c & d \end{pmatrix}^{-1} = \frac{1}{ad - bc}\begin{pmatrix} d & -b \\ -c & a \end{pmatrix}, \qquad \det S = 1 \cdot 1 - 0.02 \cdot 0.25 = 0.995
If two dyes have similar spectra, the columns of S point almost the same way and \det(S) is near 0:
S2 <- matrix(c(1, 0.9,
0.9, 1 ), nrow = 2,
byrow = TRUE) # det(S2) = 0.19
solve(S2) # [5.26 -4.74; -4.74 5.26]solve(). The inverse has large entries, so it multiplies the noise by about 5: unstained cells spread from sd 45 to 209, and populations smear.
For those who want to try real cytometry files:
read.FCS() reads a measurement file, exprs() gives the cells × channels matrix.spillover() estimates S from single-stained controls; compensate() applies S^{-1} to every cell, exactly our solve(S) %*% measured.data(GvHD) in flowCore, an extract of a graft-versus-host disease monitoring experiment. Many public experiments are in FlowRepository.| Concept | Key fact | R |
|---|---|---|
| Spillover | measured = S × true; column j = where dye j’s light lands | S %*% true |
| Estimating S | single-stained control: slope of other detector vs own detector | lm(ctrl[2, ] ~ ctrl[1, ]) |
| Compensation | true = S^{-1} × measured | solve(S) %*% measured |
| 2 × 2 inverse | swap diagonal, negate off-diagonal, divide by \det | solve(S) |
| Similar dyes | \det(S) \approx 0 → large inverse → noise amplified | det(S2) |
Next (Polar coordinates): a change of coordinates that no matrix can do, used to measure a ring on an image.