Skip to content

Transformation and QC

Fluorescence intensities span several orders of magnitude and are skewed, so a raw scatter plot is unreadable. The transform that displays them has to do two things at once: compress the high end and resolve the low end where the negative, autofluorescent population sits. Linear compensation is done first, on the raw scale, and then the transform is applied. This page carries on with the FACSCalibur file of the compensation page, read on the linear scale and compensated with the same compdata matrix, so it carries the same over-compensation.

Logicle is the standard transform for flow cytometry. It is a biexponential function with a parameter for the width of the linear region near zero, which keeps the negative population visible instead of piling it against the axis. flowCore estimates the parameters from the data with estimateLogicle().

The FACSCalibur example files and compdata compensation matrix come from the flowCore 2.24.0 source archive. Its Artistic 2.0 license covers the distributed file collection. The fixture source notice identifies the package authors, original files, and derived lesson results. The complete license accompanies that notice.

library(flowCore)
extdata_dir <- system.file("extdata", package = "flowCore")
fcs_files <- list.files(extdata_dir, pattern = "0877408774", full.names = TRUE)
# The default read undoes the log amplifier, so the values are linear.
frame <- read.FCS(fcs_files[1])
# Compensate first, on the linear scale, with the compdata matrix the
# compensation page uses. The file stores no spillover keyword.
comp_path <- file.path(extdata_dir, "compdata", "compmatrix")
lines <- readLines(comp_path)
lines <- lines[nzchar(lines)]
chan <- strsplit(lines[3], "\t")[[1]]
spill <- do.call(rbind, lapply(lines[4:length(lines)], function(l) {
as.numeric(strsplit(l, "\t")[[1]])
}))
colnames(spill) <- chan
rownames(spill) <- chan
frame <- compensate(frame, spill)
# Logicle on the fluorescence channels only; scatter and time stay linear.
fl_channels <- grep("^FL[1-4]-H$", colnames(frame), value = TRUE)
trans <- estimateLogicle(frame, fl_channels)
transformed <- transform(frame, trans)
# The first rows on the transformed scale.
head(exprs(transformed)[, fl_channels], 3)
FL1-H FL2-H FL3-H FL4-H
[1,] 2.883256 0.3970231 1.338753 1.472031
[2,] 1.208551 1.8017156 1.283158 1.894600
[3,] 3.215105 0.3078858 1.225616 2.987713

The transformed values are now on a scale where a biaxial plot separates populations. The exact parameters depend on the dynamic range of each channel, which is why estimateLogicle reads them from the data rather than taking a fixed value.

The arcsinh transform is a coarser cousin of logicle. It takes a single cofactor per channel, and it is the default in mass cytometry, where asinh(value / 5) is common. It is close to linear for values well below the cofactor and close to logarithmic well above it, so it keeps the zero and negative values a plain log cannot take. It does not adapt the linear region to the data the way logicle does, so it is a poorer choice when a negative population sits close to zero on a fluorescence instrument.

# Arcsinh with a cofactor of 150, a common fluorescence default.
cofactor <- 150
asinh_trans <- arcsinhTransform(
transformationId = "asinh",
a = 0,
b = 1 / cofactor,
c = 0
)
asinh_list <- transformList(fl_channels, tfun = asinh_trans)
transformed_asinh <- transform(frame, asinh_list)
head(exprs(transformed_asinh)[, fl_channels], 3)
FL1-H FL2-H FL3-H FL4-H
[1,] 1.31714670 -0.4069312 0.053294205 0.07523678
[2,] 0.05764573 0.2992279 0.023535399 0.18072880
[3,] 1.98915638 -0.4692357 -0.007209067 1.47424600

The choice between logicle and arcsinh is mostly a question of how much you want the transform to adapt. Logicle adapts to each file. Arcsinh is fixed, so the transform adds no difference between files of its own, and it removes none of the differences that instruments, voltages and panels put there.

A sample degrades over the minutes it spends on the instrument. The acquisition rate drops, the signal drifts, and a tail of low-quality events accumulates. flowAI finds the time windows where the acquisition is stable and removes the rest, using three checks: a flow rate check on the number of events per time slice, a signal acquisition check on the stability of the fluorescence over time, and a dynamic range check that removes events piled at the upper limit and outliers below the lower one.

library(flowAI)
# flowAI returns a cleaned frame. The report and FCS outputs are off so the
# example stays self-contained.
clean_frame <- flow_auto_qc(
frame,
html_report = FALSE,
mini_report = FALSE,
fcs_QC = FALSE
)
head(exprs(clean_frame), 3)
Quality control for the file: 0877408774
57.3% of anomalous cells detected in the flow rate check.
0% of anomalous cells detected in signal acquisition check.
7.21% of anomalous cells detected in the dynamic range check.
FSC-H SSC-H FL1-H FL2-H FL3-H FL1-A FL4-H Time
[1,] 350 111 189.66380 -36.30354 0.02211386 37 2.876650 161
[2,] 222 95 119.63810 13.00038 -3.94806600 22 4.653702 161
[3,] 699 514 70.06136 159.02232 -10.51668644 11 611.449829 161

flow_auto_qc prints the fraction of events each check flags and returns the cleaned frame. The flow rate check flags 57.3 percent of this file. A real sample that loses a fraction that large has a problem upstream, a clog or an unstable event rate, and no transform will fix that.

The dynamic range check flags 7.21 percent. flowAI removes negative outliers by default, and it sets the lower floor of each channel from that channel’s own negative values, a fixed multiple of their spread below their median. Every event at or below the floor goes. The fence below applies the same rule to each fluorescence channel, to show where the flagged events sit.

The lower-floor calculation below corresponds to flow_margin_check in R/margins.R of flowAI 1.42.0, by Gianni Monaco with contributions from Chen Hao. This helper reports the threshold and event counts for one channel; the package function checks several margins and returns a filtered flowFrame.

#' Apply the lower floor rule of flowAI's dynamic range check to one channel.
#'
#' flowAI takes the channel's negative values and puts the floor at their
#' median minus 3.5 times their mad() divided by 0.6745.
#'
#' @param channel The channel name.
#' @param frame A compensated `flowFrame`.
#' @return The number of negative values, their median, the floor, and the
#' number of events at or below the floor.
LowerFloor <- function(channel, frame) {
values <- exprs(frame)[, channel]
negative <- values[values < 0]
floor_value <- median(negative) - 3.5 * mad(negative) / 0.6745
c(negative = length(negative), median = median(negative),
floor = floor_value, below_floor = sum(values <= floor_value))
}
floors <- t(vapply(fl_channels, LowerFloor, numeric(4), frame = frame))
round(floors, 1)
negative median floor below_floor
FL1-H 21 -1.2 -9.8 2
FL2-H 4168 -41.1 -132.8 17
FL3-H 3974 -4.3 -33.1 702
FL4-H 278 -0.7 -4.6 2

FL2-H holds the most negative values, 4168, because that is where the matrix pushed the FL1 bright population. Those events are the negative values the FL2-H floor is computed from, so they set it at -132.8, and only 17 fall beneath it. FL3-H has 3974 negative values, but their median is -4.3, so its floor sits at -33.1 and 702 events land below it. The matrix subtracts about 0.14 of the FL2-H signal from FL3-H, so an event bright on FL2-H lands far below zero on FL3-H, past a floor that the many small negatives set. Most of what this check removes is the over-compensation of the previous page, not a bad event.

The three scales side by side are worth looking at before you assume the transformation is doing what the textbook says.

library(ggplot2)
dir.create("outputs", showWarnings = FALSE, recursive = TRUE)
#' Put one channel of a frame into a plain data frame for plotting.
#'
#' @param frame A `flowFrame`.
#' @param channel The channel to extract.
#' @param scale_name A label for the scale, used as a facet title.
#' @return A data frame with the channel values and the scale label.
ChannelValues <- function(frame, channel, scale_name) {
data.frame(value = exprs(frame)[, channel], scale = scale_name)
}
scales <- rbind(
ChannelValues(frame, "FL1-H", "linear"),
ChannelValues(transformed, "FL1-H", "logicle"),
ChannelValues(transformed_asinh, "FL1-H", "arcsinh")
)
scales$scale <- factor(scales$scale,
levels = c("linear", "logicle", "arcsinh"))
scale_plot <- ggplot(scales, aes(x = value)) +
geom_density(fill = "steelblue", alpha = 0.5) +
facet_wrap(~scale, scales = "free") +
labs(title = "FL1-H on three scales", x = "FL1-H", y = "density")
ggsave("outputs/cyto-transform-scales.png", plot = scale_plot,
width = 9, height = 3, dpi = 110, bg = "white")

Density of FL1-H on three scales, one panel each. The linear panel piles the FL1 dim population into a sharp spike at zero and shows the bright one as a smaller hump near 230, with a tail out past 3000. The logicle panel resolves two well separated peaks, near 1.1 and 2.9. The arcsinh panel shows the bright population as a broad peak near 1.2 and presses the dim one into a sharp spike just above zero.

On the linear axis the dim population is a spike against zero and the bright one a small hump, because the dim values are tiny next to the bright tail. That is what fluorescence looks like once the log amplifier is undone, and a digital cytometer, which stores linear values from the start, produces the same picture. Logicle exists because a plain log cannot represent the negative values that compensation then adds at that spike.

Logicle resolves both populations. Arcsinh at a cofactor of 150 resolves the bright one and presses the dim one against zero, because the dim events sit far below the cofactor, in the part of arcsinh that stays linear. A smaller cofactor would spread them out. The FCS I/O page plots this file on the channel numbers the FACSCalibur stored, where the hardware log amplifier had already separated the two peaks.

Between the two transformed panels, neither is more correct. Logicle fits its parameters from the data and arcsinh takes the cofactor you supply, so the shape of the low end is a choice in both cases.

The order is compensation, QC, then transformation. Compensation is linear and must see the raw scale. QC removes events on the linear compensated scale, where the flow rate and dynamic range checks are meaningful. Transformation is nonlinear and is the last step before gating. Get the order wrong and the gates you draw downstream sit on the wrong coordinates. The gating page, next, moves to the Bodenmiller mass cytometry panel and starts from its arcsinh transform.

The flowCore package by Ellis and colleagues supplies the basic data structures for flow cytometry in R.

Monaco and colleagues, 2016 describe flowAI and its automatic detection of anomalies in flow cytometry data.

The flowCore documentation provides references for logicle estimation, arcsinh transforms, and transform lists. The flowAI documentation separates flow-rate, signal-acquisition, and dynamic-range checks. Read those definitions when you inspect which events a quality filter removes, especially after compensation changes the negative tail.