EmbedSOM

Fast embedding ot multidimensional datasets, great for cytometry data

https://github.com/exaexa/embedsom

Science Score: 39.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
    Found 3 DOI reference(s) in README
  • Academic publication links
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (11.4%) to scientific vocabulary

Keywords

cytometry rstats som visualization
Last synced: 6 months ago · JSON representation

Repository

Fast embedding ot multidimensional datasets, great for cytometry data

Basic Info
  • Host: GitHub
  • Owner: exaexa
  • License: gpl-3.0
  • Language: R
  • Default Branch: master
  • Homepage:
  • Size: 198 KB
Statistics
  • Stars: 26
  • Watchers: 5
  • Forks: 5
  • Open Issues: 0
  • Releases: 2
Topics
cytometry rstats som visualization
Created over 7 years ago · Last pushed about 1 year ago
Metadata Files
Readme License

README.md

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:

r 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:

r 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:

r 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.

```r 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:

r 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:

r 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:

r 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:

r 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:

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

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

r 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: sh $ 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.

Owner

  • Name: Mirek Kratochvil
  • Login: exaexa
  • Kind: user
  • Location: Belval, Luxembourg

I used a computer once.

GitHub Events

Total
  • Issues event: 2
  • Watch event: 1
  • Issue comment event: 14
  • Push event: 4
  • Pull request review event: 1
  • Pull request event: 4
  • Fork event: 1
Last Year
  • Issues event: 2
  • Watch event: 1
  • Issue comment event: 14
  • Push event: 4
  • Pull request review event: 1
  • Pull request event: 4
  • Fork event: 1

Committers

Last synced: over 2 years ago

All Time
  • Total Commits: 138
  • Total Committers: 1
  • Avg Commits per committer: 138.0
  • Development Distribution Score (DDS): 0.0
Past Year
  • Commits: 0
  • Committers: 0
  • Avg Commits per committer: 0.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
Mirek Kratochvil e****a@g****m 138

Issues and Pull Requests

Last synced: 6 months ago

All Time
  • Total issues: 1
  • Total pull requests: 4
  • Average time to close issues: about 2 months
  • Average time to close pull requests: 27 days
  • Total issue authors: 1
  • Total pull request authors: 2
  • Average comments per issue: 9.0
  • Average comments per pull request: 1.75
  • Merged pull requests: 4
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 1
  • Pull requests: 3
  • Average time to close issues: about 2 months
  • Average time to close pull requests: about 1 month
  • Issue authors: 1
  • Pull request authors: 1
  • Average comments per issue: 9.0
  • Average comments per pull request: 1.67
  • Merged pull requests: 3
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • SamGG (1)
Pull Request Authors
  • SamGG (4)
  • petrrysavy (1)
Top Labels
Issue Labels
Pull Request Labels

Packages

  • Total packages: 1
  • Total downloads:
    • cran 343 last-month
  • Total dependent packages: 0
  • Total dependent repositories: 7
  • Total versions: 5
  • Total maintainers: 1
cran.r-project.org: EmbedSOM

Fast Embedding Guided by Self-Organizing Map

  • Versions: 5
  • Dependent Packages: 0
  • Dependent Repositories: 7
  • Downloads: 343 Last month
Rankings
Stargazers count: 10.6%
Forks count: 10.8%
Dependent repos count: 11.1%
Average: 19.1%
Dependent packages count: 28.7%
Downloads: 34.2%
Maintainers (1)
Last synced: 6 months ago

Dependencies

DESCRIPTION cran
  • R >= 3.2 depends
  • FNN * imports
  • Matrix * imports
  • Rtsne * imports
  • ggplot2 * imports
  • igraph * imports
  • umap * imports
  • uwot * imports
  • knitr * suggests
  • rmarkdown * suggests