Differential analysis with CATALYST

Most of the pipeline and visualizations presented herein were adapted from @Nowicka17's "CyTOF workflow: differential discovery in high-throughput high-dimensional cytometry datasets". For the complete workflow, go here.

# load required packages

Example data

# load example data
data(PBMC_fs, PBMC_panel, PBMC_md)

The code snippet below demonstrates how to construct a flowSet from a set of FCS files. However, we also give the option to directly specify the path to a set of FCS files (see next section).

# download exemplary set of FCS files
url <- "http://imlspenticton.uzh.ch/robinson_lab/cytofWorkflow"
fcs_zip <- "PBMC8_fcs_files.zip"
download.file(paste0(url, "/", fcs_zip), destfile = fcs_zip, mode = "wb")

# read in FCS files as flowSet
fcs_files <- list.files(pattern = ".fcs$")
fs <- read.flowSet(fcs_files, transformation = FALSE, truncate_max_range = FALSE)

Data organization: The daFrame class

Data used and returned throughout differential analysis are held in objects of the daFrame class. Its constructor requires the following inputs:

Optionally, cols_to_use will specify which columns (channels) to keep from the input data. Here, we keep all measurement parameters (default value cols_to_use = NULL).

# construct daFrame
(daf <- daFrame(PBMC_fs, PBMC_panel, PBMC_md))

We provide flexibility in the way the panel and metadata table can be set up. Specifically, column names are allowed to differ from the example above, and multiple factors (patient ID, conditions, batch etc.) can be specified. Arguments panel_cols and md_cols should then be used to specify which columns hold the required information. An example is given below:

# alter panel column names
panel2 <- PBMC_panel
colnames(panel2)[1:2] <- c("channel_name", "marker")

# alter metadata column names & add 2nd condition
md2 <- PBMC_md
colnames(md2) <- c("file", "sampleID", "cond1", "patientID")
md2$cond2 <- rep(c("A", "B"), 4)

# construct daFrame
daFrame(PBMC_fs, panel2, md2, 
    panel_cols = list(channel = "channel_name", antigen = "marker"),
    md_cols = list(file = "file", id = "sampleID", 
        factors = c("cond1", "cond2", "patientID")))

Note that, independent of the input panel and metadata tables, the constructor will fix the names of mandatory slots for latter data accession (sample_id in the rowData, channel_name and marker_name in the colData). The md table will be stored under experiment_info inside the metadata.

Diagnostic plots

plotCounts: Number of cells measured per sample

The number of cells measured per sample may be plotted with plotCounts, or directly accessed via n_cells(). This plot should be used as a guide together with other readouts to identify samples where not enough cells were assayed.

plotCounts(daf, color_by = "condition")

plotMDS: Multi-dimensional scaling plot

A multi-dimensional scaling (MDS) plot on median expresion values may be rendered with plotMDS. Such a plot will give a sense of similarities between samples in an unsupervised way and of key difference in expression before conducting any formal testing. In our example, we can see a clear separation between reference (REF) and stimulation condition (BCRXL).

plotMDS(daf, color_by = "condition")

plotExprHeatmap: Heatmap of (scaled) median marker expressions

plotExprHeatmap will show a heatmap on median marker intensities with hierarchically clustered rows (samples) and columns (markers). This plot should give an idea of which markers will drive sample clustering, and how similiar samples are in their expression profile. We specify bin_anno = TRUE to display expression values inside each bin, and row_anno = TRUE to include row annotations for each factor in metadata(daf).

plotExprHeatmap(daf, bin_anno = TRUE, row_anno = TRUE)


cluster: FlowSOM clustering & ConsensusClusterPlus metaclustering

r Biocpkg("CATALYST") provides a simple wrapper to perform high resolution FlowSOM clustering and lower resolution ConsensusClusterPlus metaclustering. By default, the data will be initially clustered into xdim = 10 x ydim = 10 = 100 groups. Secondly, the function will metacluster populations into 2 through maxK (default 20) clusters. To make analyses reproducible, the random seed may be set via seed. By default, if the colData()$marker_class column is specified, the set of markers with marker class "type" will be used for clustering. Alternatively, the markers that should be used for clustering can be specified with argument cols_to_use.

# specify markers to use for clustering
lineage_markers <- c("CD3", "CD45", "CD4", "CD20", 
    "CD33", "CD123", "CD14", "IgM", "HLA_DR", "CD7")
daf <- cluster(daf, cols_to_use = lineage_markers, 
    xdim = 10, ydim = 10, maxK = 20, verbose = FALSE, seed = 1)       

Let K = xdim x ydim be the number of r Biocpkg("FlowSOM") clusters. cluster will add information to the following slots of the input daFrame:

Delta area plot

The delta area represents the amount of extra cluster stability gained when clustering into k groups as compared to k-1 groups. It can be expected that high stability of clusters can be reached when clustering into the number of groups that best fits the data. The "natural" number of clusters present in the data should thus corresponds to the value of k where there is no longer a considerable increase in stability (pleateau onset). For more details, the user can refer to the original description of the consensus clustering method [@Monti03].

# access & render delta area plot

plotMedExprs: Median marker-expressions by cluster

A combined boxplot and jitter of median marker intensitied can be generated via plotMedExprs. In order to compare medians for each cluster, and potentially identify changes across conditions early on, we specify facet = "cluster_id".

p <- plotMedExprs(daf, k = "meta8", facet = "cluster_id", 
  group_by = "condition", shape_by = "patient_id")
p$facet$params$ncol <- 4

Alternatively, we can facet the above plot by antigen in order to compare marker expressions calculated over all cells across conditions:

p <- plotMedExprs(daf, facet = "antigen", 
  group_by = "condition", shape_by = "patient_id")
p$facet$params$ncol <- 6

plotClusterExprs: Marker-densities by cluster

Distributions of marker intensities (arcsinh-transformed) across cell populations of interest can be plotted with plotClusterExprs. We specify markers = "type" (equivalent to type_markers(daf)), to include type-markers only. Here, blue densities are calculated over all cells and serve as a reference.

plotClusterExprs(daf, k = "meta8", markers = "type")

mergeClusters: Manual cluster merging

Provided with a 2 column data.frame containing old_cluster and new_cluster IDs, mergeClusters allows for manual cluster merging of any clustering available within the input daFrame (i.e. the xdim x ydim r Biocpkg("FlowSOM") clusters, and any of the 2-maxK r Biocpkg("ConsensusClusterPlus") metaclusters). For latter accession (visualization, differential testing), the function will assign a unique ID (specified with id) to each merging, and add a column to the cluster_codes inside the metadata slot of the input daFrame.

daf <- mergeClusters(daf, k = "meta20", table = merging_table, id = "merging1")

plotClusterHeatmap: Heatmap of (meta)clustering results

Clusterings and metaclusters maybe be viewing with the plotClusterHeatmap. In its 1st panel, the function will display median (arcsinh-transformed and optionally scaled) cell-type marker expressions (across all samples). Depending on argument hm2, the 2nd panel will vary as follows:

Argument scale (default TRUE) specifies whether scaled values should be plotted. These correspond to arcsinh-transformed expression values scaled between 0 and 1 using low (1%) and high (99%) percentiles as boundaries. Note that, in any case, hierarchical clustering is performed on the unscaled data.
While it is only used here for visualization, this additional transformation of the arcsinh-transformed data can sometimes give a better representation of relative differences in marker expression between cell populations.

# median pS6 expression by sample as 2nd heatmap
plotClusterHeatmap(daf, hm2 = "pS6", k = "meta12", m = "meta6")
# population frequencies by sample as 2nd heatmap
plotClusterHeatmap(daf, hm2 = "abundances", 
    draw_freqs = TRUE, cluster_anno = FALSE)

plotAbundances: Relative population abundances

Relative population abundances for any clustering of interest can be plotted with plotAbundances. Argument by will specify whether to plot proportions for each sample or cluster.
If by = "sample_id", the function displays each sample's cell type composition, and the size of a given stripe reflects the proportion of the corresponding cell type the given sample. Argument group then specifies the facetting. If by = "cluster_id", argument group then specifies the grouping and color coding.

plotAbundances(daf, k = "meta12", by = "sample_id", group_by = "condition")
plotAbundances(daf, k = "merging1", by = "cluster_id", 
  group_by = "condition", shape_by = "patient_id")

Dimensionality reduction with runDR

The set of dimension reduction (DR) methods available from the r Biocpkg("scater") can be applied using runDR. To make results reproducible, the random seed should be set via set.seed prior to running runDR. The subset of markers to use is specified via cols_to_use, and the cells to use with argument rows_to_use. When rows_to_use is a single numeric value N, runDR will draw a random subset of N cells per sample. CATALYST allows DRs to use different sets of cells. In the example below, we can run a PCA on the full dataset, but more time-consuming methods, e.g., t-SNE or UMAP, on only a subset of cells.

# run PCA on all cells
daf <- runDR(daf, "PCA")

# run UMAP on 200 cells per sample
daf <- runDR(daf, "UMAP", rows_to_use = 200)

As in a regular r Biocpkg("SingleCellExperiment"), DRs available within the daFrame can be viewed via reducedDimNames and accessed with reducedDim(s).

# view & access DRs
head(reducedDim(daf, "PCA"))

# all cells
nrow(reducedDim(daf, "PCA")) == nrow(daf) 

# 200 per sample
nrow(reducedDim(daf, "UMAP")) == 200 * nlevels(sample_ids(daf))

plotDR: Visualizing reduced dimensions

plotDR is a flexbile wrapper to plot reduced dimensions stored within the reducedDims slot of a daFrame. The coloring of cell projections is specified with argument color_by, and may correspond to a marker, clustering, or any factor available in the daFrame's rowData. In order to facilitate comparing reduced dimensions across experimental groups or samples, embeddings can be split via facet.

# color by marker expression & split by condition
plotDR(daf, "UMAP", color_by = "pS6", facet = "condition")
# color by 8 metaclusters & split by sample ID
plotDR(daf, "UMAP", color_by = "meta8", facet = "sample_id")

Differental testing with r Biocpkg("diffcyt")

r Biocpkg("CATALYST") has been designed to be compatible with the r Biocpkg("diffcyt") package [@diffcyt], which implements statistical methods for differential discovery in high-dimensional cytometry (including flow cytometry, mass cytometry or CyTOF, and oligonucleotide-tagged cytometry) using high-resolution clustering and moderated tests. The input to the r Biocpkg("diffcyt") pipeline can either be raw data, or a daFrame object. We give an exmaple of the latter below.
Please refer to the r Biocpkg("diffcyt") vignette and R documentation (??diffcyt) for more detailed information.

# create design & constrast matrix
formula <- createFormula(
    experiment_info = PBMC_md, 
    cols_fixed = "condition", 
    cols_random = "patient_id")
contrast <- createContrast(c(0, 1))
# test for
# - differential abundance (DA) of clusters
# - differential states (DS) within clusters
res_DA <- diffcyt(daf, contrast = contrast, formula = formula, 
    analysis_type = "DA", method_DA = "diffcyt-DA-GLMM", clustering_to_use = "meta10")
res_DS <- diffcyt(daf, contrast = contrast, formula = formula, 
    analysis_type = "DS", method_DS = "diffcyt-DS-LMM", clustering_to_use = "meta10")

plotDiffHeatmap: Heatmap of differential testing results

Differential testing results returned by r Biocpkg("diffcyt") can be displayed with the plotDiffHeatmap function.

For differential abundance (DA) tests, plotDiffHeatmap will display

For differential state (DS) tests, plotDiffHeatmap will display

Clusters (DA) and cluster-marker combinations (DS), respectively, will be marked as significant if their adjusted p-value falls below the threshold value specified with th (default 0.1), and will be ordered by significance if order = TRUE (the default). The number of top findings to display can be specified with top_n (default 20). When normalize = TRUE, the right-hand side heatmap will display Z-score normalized values. For DA, cluster frequencies will be arcsine-square-root scaled prior to normalization.

plotDiffHeatmap(daf, res_DA, all = TRUE, th = 0.05)
plotDiffHeatmap(daf, res_DS, top_n = 20)

Session Information



Try the CATALYST package in your browser

Any scripts or data that you put into this service are public.

CATALYST documentation built on July 29, 2019, 2 a.m.