Compensation & spectral unmixing

Week 1 — Compensation & spectral unmixing in flow cytometry

Quantitative biology and integrative omics

Flow cytometry: measuring single cells

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

  • A flow cytometer measures cells one at a time, thousands per second.
  • The cells (for example from blood) float in a liquid. They are labelled with fluorescent antibodies: each dye marks one protein on the cell surface.
  • For every cell the machine records a handful of numbers: how the cell scatters light, and how bright each dye is.
  • It is a daily tool in immunology and haematology: counting cell types, following an infection or a leukaemia, sorting cells.

How a cell is measured

Schematic: Kierano, CC BY 3.0, via Wikimedia Commons.

  • A thin stream lines the cells up single file and carries them through a laser beam.
  • Forward scatter (FSC): light that goes almost straight on. Roughly the cell’s size.
  • Side scatter (SSC): light bounced sideways. The cell’s granularity.
  • The dyes fluoresce. Mirrors and filters split this light into colour bands, with one detector per band (FL1, FL2, FL3, …).
  • Modern instruments have several lasers and dozens of detectors.

The data are a table: one row per cell, one column per detector

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.

About this lecture

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!

  • The leak is a 2 × 2 matrix S: measured = S × true.
  • Compensation undoes it with the inverse, solve(S), just like undoing a misaligned image.
  • Spectral unmixing is the same equation, with S built from reference spectra.
  • When two dyes look too alike, \det(S) is close to 0, and compensation amplifies noise.

One dye’s light leaks into another dye’s detector: spillover

  • Cells are labelled with antibodies carrying dyes, e.g. FITC (green) and PE (orange). Each dye marks one protein.
  • Each detector collects one band of colours. But FITC’s emission has a long tail that reaches the PE detector.
  • A cell with only FITC therefore shows a false PE signal: this is spillover.

A spillover matrix S mixes the dyes: measured = S × true

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.

  • Column 1 = where FITC’s light lands: all in the FITC detector, plus 25 % of that in the PE detector.
  • Column 2 = where PE’s light lands: 2 % in the FITC detector.
  • A cell with FITC = 1000, PE = 0 is measured as (1000,\ 250). A cell with PE = 1000 only: (20,\ 1000).
S <- matrix(c(1,    0.02,                         # rows = detectors, columns = dyes
              0.25, 1   ), nrow = 2, byrow = TRUE,
            dimnames = list(c("FITC det", "PE det"), c("FITC", "PE")))
S %*% c(1000, 0)                                  # 1000, 250

Spillover tilts FITC-positive cells into a false PE signal

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))

A single-stained control measures the spillover directly

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
  • The slope is the spillover coefficient: column 1 of S, measured.
  • A PE-only control gives column 2 the same way.
  • In general, for each dye you have, include cells stained with this dye alone!
  • Modern flow cytometry can have up to 32 colors. It might look simple in 2D, but it stops being possible to interpret by eye when more dyes are used

Multiplying by the inverse of S removes the spillover

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 cells

The FITC+ cells: median PE 850 before, 102 after (unstained cells: about 100).

Try it: guess the spillover

The inverse tilts the axes back, but detector noise remains

  • S^{-1}S = I: undoing after doing changes nothing. Check: solve(S) %*% S is the identity.
  • In pictures: S tilts the FITC axis (column 1 points along (1, 0.25)); S^{-1} tilts it back to (1, 0).
  • For a 2 × 2 matrix the inverse has a formula:

\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

  • Noise is not removed: compensated values still carry the detector noise, mixed through S^{-1}. Here that costs little (unstained cells: sd 45 after compensation, 33 in the true amounts, the rest is detector noise). Next slide: when it costs a lot.

Dyes with similar colours make compensation amplify noise

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]
  • Top: what the detectors record. With similar dyes, every population lies near one line: the two detectors say almost the same thing.
  • Bottom: after 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.

Real data in R (optional)

For those who want to try real cytometry files:

  • Bioconductor package flowCore: 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.
  • Example data: data(GvHD) in flowCore, an extract of a graft-versus-host disease monitoring experiment. Many public experiments are in FlowRepository.
# install.packages("BiocManager"); BiocManager::install("flowCore")   # optional
library(flowCore)
data(GvHD)
head(exprs(GvHD[[1]]))            # one sample: cells as ROWS, channels as columns

Summary

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.