Exercise: ratio imaging and the noise of a ratio
Before this unit: Acceptor photobleaching, and what an efficiency means (previous unit); Day 46: Colour.
See also: Day 47: Spectral unmixing; Day 16: Measurements; Day 23: FFT registration.
Goal
By the end of this exercise you should be able to:
- explain why the ratio of a single-chain biosensor cancels concentration, thickness and illumination, and why it does not cancel a background,
- mask and display a ratio image,
- calibrate a ratio to a concentration and estimate the error, especially near R_\text{max},
- predict the noise of a ratio from photon counts, and its bias when the denominator is dim,
- choose between the ratio of sums and the mean of ratios, and bin before dividing,
- (math) derive the delta-method variance and bias of A/D, the calibration equation and dc/dR, and the effect of a shared fluctuation.
Do the pen-and-paper part first, then the two demos.
Background
| Idea | What it means |
|---|---|
| Ratio | R = I_A/I_D; a common factor k in both channels cancels |
| Background | (A + b)/(D + b) moves towards 1: subtract b first |
| Mask | threshold on A + D; outside the cell the ratio is noise/noise |
| Intensity-modulated display | hue = ratio, lightness = intensity |
| Calibration | c = K_d (R - R_\text{min})/(R_\text{max} - R); dc/dR = K_d(R_\text{max} - R_\text{min})/(R_\text{max} - R)^2 |
| Noise of a ratio (photons) | \mathrm{CV}^2 \approx 1/N_A + 1/N_D |
| Bias | \operatorname{E}[A/D] \approx (\mu_A/\mu_D)(1 + 1/\mu_D) |
| Region value | ratio of sums \sum A/\sum D, not mean of ratios |
| Binning m pixels | counts × m, \mathrm{CV}^2 / m |
By hand
B1. A pixel has A = 100 and D = 400 photons above background; the background is 50 in each channel. (a) What ratio do you get with and without background subtraction? (b) A dim pixel of the same cell has A = 10, D = 40 above background. Same question. Which pixel is affected more?
B2. Noise. Same pixel (A = 100, D = 400 photons, Poisson). (a) CV of R per pixel. (b) After binning 4 × 4. (c) You can double the light in one channel. Which one, and what is the CV then?
B3. Bias. The donor channel has on average 10 photons per pixel, the acceptor 1000. (a) By how much is the mean of the pixel ratios biased, according to the delta method? (b) Why is this an approximation, and in which direction would you expect the exact answer to differ? (Think of D = 1 or 2.)
B4. Region value. A region has four pixels (A, D): (10, 5), (50, 50), (100, 200), (200, 400). The true ratio of the sensor is 0.5. (a) Compute the ratio of sums and the mean of ratios. (b) Which is closer to 0.5, and which pixel causes the difference?
B5. Calibration. K_d = 200 nM, R_\text{min} = 0.5, R_\text{max} = 2.5. (a) Convert R = 1.5, 2.3 and 2.4 to concentrations. (b) For each, give the concentration range for R \pm 0.05. (c) What would you change to measure 2000 nM reliably?
B6. Predict. The acceptor channel is shifted by one pixel to the right relative to the donor channel. What does the ratio image show at the left and right edge of a uniform cell?
B1. (a) 0.25 with subtraction, 150/450 = 0.333 without. (b) 0.25 with, 60/90 = 0.667 without. The dim pixel is pulled much further towards 1: the offset is larger relative to its signal. An unsubtracted background makes the ratio depend on brightness, which the ratio was supposed to remove.
B2. (a) \sqrt{1/100 + 1/400} = 0.112: 11 %. (b) 16 times the photons: 0.112/4 = 2.8 %. (c) The acceptor (the dimmer channel): \sqrt{1/200 + 1/400} = 8.7 %; doubling the donor gives only \sqrt{1/100 + 1/800} = 10.6 %.
B3. (a) 1/\mu_D = 1/10: about +10 %. (b) The expansion assumes small fluctuations of D around 10; with Poisson counts D is sometimes 2, 3, 4, where 1/D is far above the parabola of the expansion (and D = 0 gives no ratio at all). The exact bias is larger: a simulation gives about +13 % (excluding D = 0).
B4. (a) Ratio of sums 360/655 = 0.550; mean of ratios (2 + 1 + 0.5 + 0.5)/4 = 1.00. (b) The ratio of sums. The dim pixel (10, 5), with ratio 2, counts as much as the bright ones in the mean of ratios; in the sums it contributes 15 of 1015 photons.
B5. (a) 200, 1800 and 3800 nM. (b) R = 1.45–1.55: 181–221 nM; 2.25–2.35: 1400–2467 nM; 2.35–2.45: 2467–7800 nM. (c) A sensor with a larger K_d (for example 2000 nM puts 2000 nM in the middle of its range), or a larger dynamic range R_\text{max}/R_\text{min}, and more photons.
B6. At one edge the acceptor channel has signal where the donor channel has (almost) none: very high ratios. At the other edge the donor has signal and the acceptor not yet: ratios near 0. A bright rim on one side, a dark rim on the other, although the cell is uniform.
Math questions
B7. (math) (a) Expand g(A, D) = A/D to first order around (\mu_A, \mu_D) and derive \operatorname{Var}(R) \approx (\mu_A/\mu_D)^2[\sigma_A^2/\mu_A^2 + \sigma_D^2/\mu_D^2 - 2\operatorname{Cov}(A, D)/(\mu_A\mu_D)]. (b) Expand to second order and derive the mean. (c) Specialise both to independent Poisson counts.
B8. (math) Derive the calibration equation c = K_d(R - R_\text{min})/(R_\text{max} - R) from a single binding site (\theta = c/(c + K_d)) and R linear in \theta. Then derive dc/dR and evaluate it at R = 1.5 and 2.3 (numbers of B5).
B9. (math) Both channels are multiplied by the same random factor g (lamp flicker) with mean 1 and small variance s^2, on top of independent Poisson noise. (a) Show that g cancels in A/D exactly. (b) Show that in the delta-method formula it adds s^2 to each of \sigma_A^2/\mu_A^2 and \sigma_D^2/\mu_D^2 and s^2\mu_A\mu_D to the covariance, so that the three terms cancel.
B7. (a) g \approx \mu_A/\mu_D + \delta A/\mu_D - \mu_A\,\delta D/\mu_D^2. \operatorname{Var}(g) \approx \sigma_A^2/\mu_D^2 + \mu_A^2\sigma_D^2/\mu_D^4 - 2\mu_A\operatorname{Cov}/\mu_D^3; factor out (\mu_A/\mu_D)^2. (b) Second-order terms: \partial^2 g/\partial D^2 = 2A/D^3, \partial^2 g/\partial A\partial D = -1/D^2, \partial^2 g/\partial A^2 = 0. \operatorname{E}[g] \approx \mu_A/\mu_D + \tfrac12\cdot2\mu_A\sigma_D^2/\mu_D^3 - \operatorname{Cov}/\mu_D^2 = (\mu_A/\mu_D)(1 + \sigma_D^2/\mu_D^2 - \operatorname{Cov}/(\mu_A\mu_D)). (c) \sigma^2 = \mu, Cov = 0: \mathrm{CV}^2 = 1/\mu_A + 1/\mu_D, \operatorname{E}[R] \approx (\mu_A/\mu_D)(1 + 1/\mu_D).
B8. R = R_\text{min} + (R_\text{max} - R_\text{min})\theta gives \theta = (R - R_\text{min})/(R_\text{max} - R_\text{min}) and 1 - \theta = (R_\text{max} - R)/(R_\text{max} - R_\text{min}). From \theta = c/(c + K_d): c = K_d\theta/(1 - \theta) = K_d(R - R_\text{min})/(R_\text{max} - R). Quotient rule: dc/dR = K_d[(R_\text{max} - R) + (R - R_\text{min})]/(R_\text{max} - R)^2 = K_d(R_\text{max} - R_\text{min})/(R_\text{max} - R)^2. At 1.5: 200\cdot2/1 = 400 nM per unit R (±0.05 → ±20 nM). At 2.3: 400/0.04 = 10\,000 (±0.05 → ±500 nM to first order; the exact range 1400–2467 is asymmetric).
B9. (a) gA/(gD) = A/D. (b) With A = gA_0, \operatorname{Var}(A) \approx \mu_A + s^2\mu_A^2 (Poisson plus the flicker), likewise for D, and \operatorname{Cov}(A, D) = s^2\mu_A\mu_D. Then \sigma_A^2/\mu_A^2 + \sigma_D^2/\mu_D^2 - 2\operatorname{Cov}/(\mu_A\mu_D) = 1/\mu_A + s^2 + 1/\mu_D + s^2 - 2s^2 = 1/\mu_A + 1/\mu_D: the flicker drops out.
Explore: ratio images
Three seeded cells over 40 frames: a wave of high concentration crosses cell 1 (right), cell 2 (top left) has a steady gradient, cell 3 (bottom left) is a constant control at 150 nM. The cells differ in thickness and expression. The sensor has R_\text{min} = 0.5, R_\text{max} = 2.5, K_d = 200 nM. Left: the donor and acceptor channels. Middle: the ratio map (or ratio × intensity, or the donor intensity alone) with two regions (radius 5 px; choose “place region 1/2” and click). Right: the ratio over time in both regions (ratio of sums solid, mean of pixel ratios dashed) and the calibration curve with region 1’s value and error bar.
E1. Preset intensity lies: thick cells look active. Which cell looks most “active” in intensity? Switch to ratio (preset the ratio cancels thickness) and press play. Where is the signal really? Read R in both regions at frame 20.
E2. Preset forgot the background. Read both regions at frame 20 and compare with E1. Which way do the values move, and why does the wave cell’s concentration estimate suffer most?
E3. Preset no mask: the background explodes, then intensity-modulated display. What does each show outside the cells? Which would you put in a paper?
E4. Preset few photons: bin before dividing (6 photons). Compare the solid and dashed curves in the time plot, and the readouts of region 1 and 2 at frame 20. Then bin 4 × 4. Which of the two numbers changes, and why?
E5. Preset acceptor bleaches: the ratio drifts (1 % per frame). Read the control region at frames 0, 20 and 39. What would you conclude about the control cell without knowing about bleaching, and how would you correct it?
E6. Preset calibrate: near R_max the error explodes (30 photons, frame 20). Read region 1’s R, its error and the concentration range. Compare with region 2. Why is the true value (2457 nM) above the estimate, even beyond noise?
E7. Set the bleed-through slider to 0.3 at the default settings. What happens to the ratio of the control cell and to its calibrated concentration? How should the calibration be done to absorb this?
E1. In intensity, cell 1 (right) is the brightest (mean donor about 130 photons against 66 and 94) and has a bright thick spot: it looks “active” all the time. In the ratio, the cells are uniform except for the wave, which crosses cell 1 between frames 10 and 30. Frame 20: region 1 (on the wave) R = 2.33, region 2 (control) R = 1.36 (true 1.357 for 150 nM).
E2. Region 1 drops to 2.13, region 2 to 1.30: both towards 1 (the offset of 40 is added to both channels). Calibrated, region 1 gives 885 nM instead of 2179 nM: near R_\text{max} a small change in R is a large change in c.
E3. Without a mask the background is a carpet of extreme colours (half of the background pixels have a negative ratio, one in eight beyond ±5). With the intensity-modulated display the background is dark and the cells keep their colours, with the dim rims darker. The intensity-modulated display (or a mask) belongs in a paper; the plain map draws the eye to the noise.
E4. At 6 photons the dashed curves (mean of pixel ratios) lie far above the solid ones and jump around. Frame 20: region 1 ratio of sums 2.18 against mean of ratios 3.42; region 2 1.34 against 2.52 (true 1.357). With 4 × 4 binning the means of ratios drop to 2.20 and 1.44, the ratios of sums do not change (they sum the same photons). Dim pixel ratios are biased upwards and heavy-tailed; binning first makes each ratio a ratio of larger counts.
E5. Region 2: 1.35 at frame 0, 1.11 at 20, 0.93 at 39 (the acceptor channel has lost 32 % by frame 39: 0.99^{39} = 0.68). Without the knowledge you would conclude that the concentration in the control cell falls from 147 to 54 nM. Correct with a no-stimulus control: its ratio drift (here a factor 0.99^t) divides every cell’s ratio, or fit and remove an exponential drift.
E6. Region 1: R = 2.31 \pm 0.05, c = 1867 nM (1465–2527 nM). Region 2: R = 1.36, c = 150 nM, with a narrow range. The true mean concentration in region 1 is 2457 nM, but the ratio is averaged over a region where the concentration varies across the wave; the calibration curve is convex, so c of the mean ratio is below the mean of c (the same trap as averaging E over distances in the first unit). Add the noise near R_\text{max} and the number is unreliable.
E7. The control’s ratio rises from 1.35 to 1.65 at frame 0 (region 1, at the base of the wave, from 1.08 to 1.38), and its concentration estimate from 147 to 269 nM: the bleed-through adds d = 0.3 to every ratio. Calibration absorbs it if R_\text{min} and R_\text{max} are measured on the same microscope (sensor empty and saturated), because both shift by the same 0.3.
Explore: the noise of a ratio
Monte Carlo with 20 000 seeded pairs of photon counts with means N_A and N_D (Poisson, or Gaussian with the same variance), optionally a shared flicker, binning and regions of m pixels. The histogram shows the pixel ratios (or log ratios) with the true value (green), the mean of the draws (red dashes) and the delta-method normal curve (black). The tabs difference and bleach do the same for the corrected sensitised emission F_c (unit 2) and E = 1 - P/Q (unit 3).
F1. Preset bright: the formula works (400/1000). Compare the observed and predicted CV and the mean with the truth. Then set N_A = 100, N_D = 400 (the numbers of B2). Then binning 16.
F2. Preset dim denominator: bias and a long tail (20/5). Read the mean of pixel ratios, the predicted bias, the observed and predicted CV and the number of draws with D = 0. Why do the formulas fail here? Now swap: N_A = 5, N_D = 20. Which situation is worse, and why?
F3. Preset log ratio is symmetric. Compare the shapes of the two histograms (tick and untick plot log ratio).
F4. Preset ratio of sums beats mean of ratios (10/10, regions of 16). Read both region estimates. Change m to 1, 4, 64: which estimate improves with m and which does not?
F5. Preset shared flicker cancels (each channel varies by 20 %). Read the CV of the ratio, and compare with flicker 0. Why is ratio imaging robust to lamp fluctuations?
F6. Preset low FRET: the corrected signal is mostly noise (the difference tab; B4 of the sensitised-emission exercise). Read the true F_c and its standard deviation. Then preset bleaching: \sigma_E at 600/800 photons. Set P = 60, Q = 80.
F1. 400/1000: CV 5.9 % observed and predicted, mean 0.400 (true 0.400). 100/400: CV 11.3 % (predicted 11.2 %), mean bias +0.1 %. Binning 16: 2.8 % as predicted.
F2. Mean of ratios 5.15 against the true 4.00 (+28.8 %; the formula predicts +20 %); CV 72.8 % observed against 50 % predicted; 152 of 20 000 draws have D = 0. With 5 photons the fluctuations of D are not small compared with its mean, so the Taylor expansion is not accurate, and D can be 0 or 1. Swapped (5/20): mean +5.4 % (predicted +5 %), CV 52 % (50 %): the same CV formula, but a dim numerator does not cause the bias and the tail; a dim denominator does.
F3. The ratio histogram at 20/5 is skewed with a long right tail; the log-ratio histogram is nearly symmetric around \log 4 = 1.39 (mean of the logs 1.47). In log space a doubling and a halving are equally far from the centre.
F4. Ratio of sums 1.003, mean of ratios 1.120 (true 1). For m = 1 both are the same (1.12); with larger m the ratio of sums approaches 1 (its bias is about 1/(m N_D)), while the mean of ratios stays at about 1.12: averaging more biased ratios does not remove the bias.
F5. With flicker 0.2 the CV of the ratio is 6.5 % (6.4 % without flicker), while each channel alone varies by about 20 %. The flicker multiplies both channels and cancels in the ratio; in the formula it is the positive covariance.
F6. F_c = 20, \sigma = 20.7 predicted (20.8 observed): about 100 % relative noise. Bleaching at 600/800: E = 0.25, \sigma_E = 0.0405 predicted (0.0402 observed). At 60/80: 0.128 predicted (0.130 observed), and the mean shifts to 0.240: dim ratios are biased.
Code
Write the algorithms of this unit yourself, in Rust. Setup, and how to run and check your code: coding exercises: getting started. Your code goes in fret/src/ratiometric/exercise.rs.
C1. ratio_image(a, d, bg_a, bg_d, min_sum): subtract the background, mask, divide:
for every pixel:
A' = A − bg_A, D' = D − bg_D
if A' + D' ≥ min_sum: R = A' / D'
else: R = no value # outside the cells
The check is B1: 0.25 for both pixels after subtraction, 0.333 and 0.667 without.
C2. ratio_of_sums(a, d, mask) = \sum A / \sum D and mean_of_ratios(a, d, mask), the mean of A/D over the pixels (skipping D \le 0). The check is B4: 0.550 and 1.00.
C3. calibrate(r, kd, r_min, r_max) = K_d (R - R_\text{min})/(R_\text{max} - R). The check is B5.
C4. bin(img, k): sum every k \times k block into one pixel.
C5. intensity_modulated(ratio, intensity, r_lo, r_hi, i_max): the colour from the ratio (a colour map from blue to red is given), the lightness from the intensity:
for every pixel:
if R has no value: black
else: colour_map((R − r_lo) / (r_hi − r_lo)) · min(intensity / i_max, 1)
Then cargo run -p fret -- ratiometric and open the pictures in out/ratiometric/. The program simulates a biosensor (R_\text{min} = 0.5, R_\text{max} = 2.5, K_d = 200 nM) in cells of different thickness and expression (about 150 photons per pixel, background 40): most cells at 150 nM, cell 1 with a gradient from 50 to 1000 nM, cell 2 at 2000 nM. It saves the donor channel, the ratio with and without a mask (black R_\text{min}, white R_\text{max}) and the intensity-modulated display; it prints the ratio of sums and the calibrated concentration per cell, with and without background subtraction; the ratio of sums and the mean of ratios at 6 photons per pixel, also after binning; and a simulation of 20 000 Poisson pairs for four photon numbers.
C6. Compare donor.png with ratio.png, and ratio-no-mask.png with ratio-imd.png. How many background pixels get a negative ratio without a mask?
C7. In the table, what does forgetting the background do to R and to c? For cell 1 (the gradient) and cell 2, compare the calibrated concentration with the true mean concentration. Why are they so different, even with the background subtracted?
C8. At 6 photons, compare the ratio of sums with the mean of ratios, before and after binning. In the Poisson simulation, compare the bias and the CV of 20/5 and 5/20 photons with the delta method.
The model solution is fret/src/ratiometric/solution.rs in the download.
C6. In the donor channel the cells differ in brightness (thickness and expression); in the ratio image the 150 nM cells look alike, cell 2 is bright and cell 1 shows its gradient. Without a mask the background is noise divided by noise: 7290 of 15 551 background pixels are negative and 1935 are beyond ±5 or undefined, so the picture is a carpet of black and white. The intensity-modulated display keeps the ratios and lets the dim background fade to black.
C7. For the 150 nM cells (true R = 1.357): subtracted 1.347 to 1.399 (147 to 163 nM); without subtraction 1.234 to 1.302 (116 to 134 nM): pulled towards 1, by different amounts in dimmer and brighter cells. Cell 2 (2000 nM, true mean R 2.318): 2.284 with subtraction, which calibrates to only 1649 nM: near R_\text{max} a small error in R is a large error in c; without subtraction 1.831 and 398 nM. Cell 1: the true mean concentration is 502 nM, but its ratio 1.779 calibrates to 355 nM. The calibration curve is convex, so c of the mean ratio is below the mean of c (E6, the same trap as averaging E over distances).
C8. At 6 photons (true 1.357): ratio of sums 1.356, mean of pixel ratios 1.665 (+23 %). Binned 2 × 2: 1.361 and 1.425; 4 × 4: 1.349 and 1.361. The ratio of sums does not need binning; the mean of ratios becomes usable only when each ratio has enough photons. Poisson pairs: 400/1000 and 100/400 behave as predicted (CV 5.9 % and 11.2 %, no bias). 20/5: mean 5.128 instead of 4 (+28 %, the formula 1/N_D predicts +20 %), CV 72.5 % against 50 % predicted, and 124 of 20 000 draws with D = 0. 5/20: +5.5 % (predicted +5 %), CV 51.9 %. A dim denominator causes the bias and the tail (F2).
Where this leads
The ratio is the everyday tool of FRET imaging: one number per pixel and frame, cancelling much of what makes intensities lie. Its weak points are the background, bleaching, motion and the statistics of dim counts, all of which a careful analysis controls. Lifetimes (the FLIM day, day 50; FRET by lifetime in FLIM-FRET) avoid ratios altogether: a lifetime does not depend on concentration, and it separates the fraction bound from the efficiency. The noise propagation of this unit, the delta method, returns wherever a measurement is a ratio or a difference of noisy numbers.