EmbedSOM on single-cell data

Miroslav Kratochvíl, Abhishek Koladiya


This vignette gives a rough overview of using EmbedSOM for actual cytometry data; in this case on a bone marrow dataset from Bendall et al., available at Flowrepository-FR-FCM-ZY9R. We show how to get data into embedding, and how to choose different landmark-generating functions to highlight different aspects of data.

After you download the FCS file from the FlowRepository link above, you can read it as such:

data <- flowCore::read.FCS("Bone_Marrow_cytof.fcs")

After that, we simplify it a bit by converting it to a matrix, transform it, and see how much cells and parameters there is:

data <- asinh(0.2 * data@exprs)
## [1] 236187     13

Running EmbedSOM

First, you need to run the SOM algorithm to obtain a “map” of the cellular space:

time <- system.time(
map <- EmbedSOM::SOM(data, xdim=32, ydim=32, batch=T, parallel=T, rlen=20)

The parameters set the SOM size (20 times 20 is usually enough, but let’s see some detail), choose the parallelizable batch-SOM training, and add a bit of extra epochs above the default 10 (which is recommended if training larger SOMs). We also measured the required time, which is, in seconds:

## elapsed 
##  10.018

After we have the map, we can project the cells onto that:

time <- system.time(
e <- EmbedSOM::EmbedSOM(data=data, map=map, parallel=T)
## elapsed 
##   2.532

e is now a 2-column matrix with coordinates of individual cells. You may as well plot it manually:

plot(e, pch='.', col=rgb(0,0,0,0.2))

EmbedSOM provides its own function to ease various cell-plotting tasks, named (expectably) PlotEmbed. By default, it plots density:


Plotting of various cell-related data is supported, including the marker expressions (e.g. the CD19 here, to identify the B cells):

EmbedSOM::PlotEmbed(e, data=data, 'CD19', alpha=.4)

We will mix a slightly more comprehensive coloring of the cells to use later:

cellColor <- EmbedSOM::ExprColors(data[,c('CD19', 'CD4', 'CD8', 'CD34', 'CD33')], col=RColorBrewer::brewer.pal(5, 'Set1'), pow=4, alpha=1)
EmbedSOM::PlotEmbed(e, col=adjustcolor(cellColor, alpha=.4))