All Projects → exaexa → EmbedSOM

exaexa / EmbedSOM

Licence: GPL-3.0 license
Fast embedding ot multidimensional datasets, great for cytometry data

Programming Languages

r
7636 projects
C++
36643 projects - #6 most used programming language
c
50402 projects - #5 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to EmbedSOM

SOMns
SOMns: A Newspeak for Concurrency Research
Stars: ✭ 62 (+181.82%)
Mutual labels:  som
pyERA
Python implementation of the Epigenetic Robotic Architecture (ERA). It includes standalone classes for Self-Organizing Maps (SOM) and Hebbian Networks.
Stars: ✭ 68 (+209.09%)
Mutual labels:  som
kohonen-maps
Implementation of SOM and GSOM
Stars: ✭ 62 (+181.82%)
Mutual labels:  som
DESOM
🌐 Deep Embedded Self-Organizing Map: Joint Representation Learning and Self-Organization
Stars: ✭ 76 (+245.45%)
Mutual labels:  som
CytoPy
A data-centric flow/mass cytometry automated analysis framework
Stars: ✭ 27 (+22.73%)
Mutual labels:  cytometry
ntnu-som
Using Self-Organizing Maps for Travelling Salesman Problem
Stars: ✭ 31 (+40.91%)
Mutual labels:  som
SelfOrganizingMap-SOM
Pytorch implementation of Self-Organizing Map(SOM). Use MNIST dataset as a demo.
Stars: ✭ 33 (+50%)
Mutual labels:  som
sparse-som
Efficient Self-Organizing Map for Sparse Data
Stars: ✭ 17 (-22.73%)
Mutual labels:  som
FlowKit
FlowKit is an intuitive Python toolkit for flow cytometry analysis and visualization, with full support for the GatingML 2.0 standard and limited support for FlowJo 10 workspace files.
Stars: ✭ 67 (+204.55%)
Mutual labels:  cytometry

EmbedSOM

CRAN status CRAN downloads

Fast embedding and visualization of multidimensional datasets, originally intended for flow/mass cytometry data. Compatible with FlowSOM (https://github.com/SofieVG/FlowSOM).

You may read more about EmbedSOM in the research paper here:

Miroslav Kratochvíl, Abhishek Koladiya, and Jiří Vondrášek. "Generalized EmbedSOM on quadtree-structured self-organizing maps" F1000Research 8 (2019). doi:10.12688/f1000research.21642.2

Installation of R module

Use devtools:

devtools::install_github('exaexa/EmbedSOM')

Usage

EmbedSOM works by aligning the points to a precomputed self-organizing map (SOM). The main function EmbedSOM takes the SOM and data, and returns a matrix with 2D point coordinates on each row.

Quick way to get a visualization of multidimensional points saved in rows of d:

map <- EmbedSOM::SOM(d, xdim=20, ydim=20)  # compute the self-organizing map
e <- EmbedSOM::EmbedSOM(d, map) # compute 2D coordinates of points
EmbedSOM::PlotEmbed(e) # plot the result with density

There are some parameters that affect speed, precision and shape of the embedding. Use ?EmbedSOM::EmbedSOM to explore them in the documentation.

HOW-TOs

To get started quickly, you can have a look at the vignettes:

How to save an embedding to an FCS file?

Use flowCore functionality to add any information to a FCS. The following template saves the scaled FlowSOM object data as-is, together with the embedding:

fs <- FlowSOM::ReadInput('original.fcs', scale=T, ...)
fs <- FlowSOM::BuildSOM(fs, ...)
e <- EmbedSOM::EmbedSOM(fs, ...)
flowCore::write.FCS(new('flowFrame',
	exprs=as.matrix(data.frame(fs$data,
				   embedsom1=e[,1],
				   embedsom2=e[,2]))),
	'original_with_embedding.fcs')

See flowCore documentation for information about advanced FCS-writing functionality, e.g. for column descriptions.

How to align the population positions in embedding of multiple files?

Train a SOM on an aggregate file, and use it to embed the individual files. It is important to always apply the same scaling and transformations on all input files.

fs <- FlowSOM::ReadInput(
	FlowSOM::AggregateFlowFrames(c('file1.fcs', 'file2.fcs', ...),
				     cTotal=100000),
	scale=T, transform=...)
n <- length(fs$scaled.scale)-2
map <- FlowSOM::SOM(fs)

fs1 <- FlowSOM::ReadInput('file1.fcs',
	scale=T,
	scaled.scale=fs$scaled.scale[1:n],
	scaled.center=fs$scaled.center[1:n],
	transform=...)
e1 <- EmbedSOM::EmbedSOM(fs1, map=map)
EmbedSOM::PlotEmbed(e1, fsom=fs1)
# repeat as needed for file2.fcs, etc.

What are the color parameters of PlotEmbed?

See documentation in ?PlotEmbed. By default, PlotEmbed plots a simple colored representation of point density. If supplied with a FCS column name (or number), it uses the a color scale similar to ColorBrewer's RdYlBu (with improvements for transparent stuff) to plot a single marker expression. Parameters red, green and blue can be used to set column names (or numbers) to mix RGB color from marker expressions.

PlotEmbed optionally accepts parameter col with a vector of R colors, which, if provided, is just forwarded to the internal plot function. For example, use col=rgb(0,0,0,0.2) for transparent black points.

New! if you need to mix more nicer colors than just the default RGB, use ExprColors.

How to plot the gazillions of the tiny points faster?

How to reduce size (and loading time) of the PDFs that contain scatterplots?

Use scattermore: https://github.com/exaexa/scattermore

How to select point subsets from the embedding?

A pretty fast (and still precise) way to dissect the dataset is to run a metaclustering on SOM clusters, and map the result to the individual points:

clusters <- cutree(k=10, hclust(method='average', dist(map$codes)))[map$mapping[,1]]

After that, the metaclusters can be plotted in the embedding. Because the clustering is related to the small SOM-defined "pre-clusters" rather than the individual points, it is necessary to map the individual points to these clusters first:

EmbedSOM::PlotEmbed(e, clust=clusters)

After you choose a metacluster in the embedding, use the color scale to find its number, then filter the points in your dataset to the corresponding subset. This example selects the point subset in metacluster number 5 and 6:

d <- d[clusters %in% c(5,6), ]

How to produce and display a 3D embedding?

There is now support for 3D SOM grids and 3D embedding. You need the customized SOM function from EmbedSOM:

map <- EmbedSOM::SOM(someData, xdim=8, ydim=8, zdim=8)
e <- EmbedSOM::EmbedSOM(data=someData, map=map)

PlotEmbed and other functions do not work on 3D points in embed, but you may use other libraries to display the plots. For example, the plot3D library:

plot3D::scatter3D(x=e[,1], y=e[,2], z=e[,3])

Interactive rotatable and zoomable plots are provided by the rgl library:

rgl::points3d(x=e[,1], y=e[,2], z=e[,3])

What to do if embedding takes too long?

You may use parallelized versions of the algorithms. Several functions (SOM, GQTSOM, EmbedSOM) support setting parallel=T, which enables parallel processing; you may fine-tune the number of used CPUs by setting e.g. threads=5.

For SOM training, you need to explicitly switch to the parallelizable batch version, using batch=T, parallel=T.

How to activate the SIMD support? (i.e. how to get even more speed?)

Additionally, EmbedSOM has support for SIMD-assisted computation of both SOM and the embedding. If your CPU can work with SSE4 instructions (almost every amd64 (a.k.a. x64 a.k.a. x86_64) CPU built after around 2013 can do that), just tell R to compile your code with correct C++ flags, and SOM+EmbedSOM computation should get faster! (the usual speedup is at least around 3x, depending on the CPU and dataset shape)

First, add a correct line to the R Makevars config file:

 $ cat ~/.R/Makevars
CXXFLAGS += -O3 -march=native

After reinstalling EmbedSOM, SIMD code will be used by default. Note that only the functions from EmbedSOM are affected, i.e. you will need to use EmbedSOM::SOM instead of FlowSOM::SOM and BuildSOM to get this speedup.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].