{"id":19312453,"url":"https://github.com/exaexa/embedsom","last_synced_at":"2025-04-22T15:32:33.565Z","repository":{"id":56936507,"uuid":"158077819","full_name":"exaexa/EmbedSOM","owner":"exaexa","description":"Fast embedding ot multidimensional datasets, great for cytometry data","archived":false,"fork":false,"pushed_at":"2025-01-31T19:58:55.000Z","size":203,"stargazers_count":26,"open_issues_count":0,"forks_count":5,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-02T00:51:22.680Z","etag":null,"topics":["cytometry","rstats","som","visualization"],"latest_commit_sha":null,"homepage":"","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/exaexa.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-11-18T11:43:19.000Z","updated_at":"2025-02-25T22:49:44.000Z","dependencies_parsed_at":"2022-08-21T06:20:45.996Z","dependency_job_id":null,"html_url":"https://github.com/exaexa/EmbedSOM","commit_stats":null,"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/exaexa%2FEmbedSOM","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/exaexa%2FEmbedSOM/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/exaexa%2FEmbedSOM/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/exaexa%2FEmbedSOM/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/exaexa","download_url":"https://codeload.github.com/exaexa/EmbedSOM/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250267550,"owners_count":21402498,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cytometry","rstats","som","visualization"],"created_at":"2024-11-10T00:34:54.018Z","updated_at":"2025-04-22T15:32:33.274Z","avatar_url":"https://github.com/exaexa.png","language":"R","readme":"\n# EmbedSOM\n\n[![CRAN status](https://www.r-pkg.org/badges/version/EmbedSOM)](https://cran.r-project.org/package=EmbedSOM)\n[![CRAN downloads](https://cranlogs.r-pkg.org/badges/EmbedSOM)](https://cran.r-project.org/package=EmbedSOM)\n\nFast embedding and visualization of multidimensional datasets, originally intended for flow/mass cytometry data. Compatible with FlowSOM (https://github.com/SofieVG/FlowSOM).\n\nYou may read more about EmbedSOM in the research paper here:\n\n\u003e Miroslav Kratochvíl, Abhishek Koladiya, and Jiří Vondrášek. \"[Generalized EmbedSOM on quadtree-structured self-organizing maps](https://f1000research.com/articles/8-2120)\" *F1000Research* **8** (2019). [doi:10.12688/f1000research.21642.2](https://doi.org/10.12688/f1000research.21642.2)\n\n## Installation of R module\n\nUse `devtools`:\n\n```r\ndevtools::install_github('exaexa/EmbedSOM')\n```\n\n## Usage\n\nEmbedSOM 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.\n\nQuick way to get a visualization of multidimensional points saved in rows of `d`:\n\n```r\nmap \u003c- EmbedSOM::SOM(d, xdim=20, ydim=20)  # compute the self-organizing map\ne \u003c- EmbedSOM::EmbedSOM(d, map) # compute 2D coordinates of points\nEmbedSOM::PlotEmbed(e) # plot the result with density\n```\n\nThere are some parameters that affect speed, precision and shape of the embedding. Use `?EmbedSOM::EmbedSOM` to explore them in the documentation.\n\n## HOW-TOs\n\nTo get started quickly, you can have a look at the vignettes:\n\n- [Basic embedding on a toy dataset](https://bioinfo.uochb.cas.cz/embedsom/vignettes/basic.html)\n- [Visualization of single-cell cytometry data from A FCS file](https://bioinfo.uochb.cas.cz/embedsom/vignettes/landmarks.html)\n- [Advanced visualization of cytometry data with pseudotime](https://bioinfo.uochb.cas.cz/embedsom/vignettes/time.html)\n- [Embedding 3D animal skeleton pointclouds to 2D](https://bioinfo.uochb.cas.cz/embedsom/vignettes/bones.html)\n\n#### How to save an embedding to an FCS file?\n\nUse `flowCore` functionality to add any information to a FCS. The following template saves the scaled FlowSOM object data as-is, together with the embedding:\n\n```r\nfs \u003c- FlowSOM::ReadInput('original.fcs', scale=T, ...)\nfs \u003c- FlowSOM::BuildSOM(fs, ...)\ne \u003c- EmbedSOM::EmbedSOM(fs, ...)\nflowCore::write.FCS(new('flowFrame',\n\texprs=as.matrix(data.frame(fs$data,\n\t\t\t\t   embedsom1=e[,1],\n\t\t\t\t   embedsom2=e[,2]))),\n\t'original_with_embedding.fcs')\n```\n\nSee `flowCore` documentation for information about advanced FCS-writing functionality, e.g. for column descriptions.\n\n#### How to align the population positions in embedding of multiple files?\n\nTrain 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.\n\n```r\nfs \u003c- FlowSOM::ReadInput(\n\tFlowSOM::AggregateFlowFrames(c('file1.fcs', 'file2.fcs', ...),\n\t\t\t\t     cTotal=100000),\n\tscale=T, transform=...)\nn \u003c- length(fs$scaled.scale)-2\nmap \u003c- FlowSOM::SOM(fs)\n\nfs1 \u003c- FlowSOM::ReadInput('file1.fcs',\n\tscale=T,\n\tscaled.scale=fs$scaled.scale[1:n],\n\tscaled.center=fs$scaled.center[1:n],\n\ttransform=...)\ne1 \u003c- EmbedSOM::EmbedSOM(fs1, map=map)\nEmbedSOM::PlotEmbed(e1, fsom=fs1)\n# repeat as needed for file2.fcs, etc.\n```\n\n#### What are the color parameters of PlotEmbed?\n\nSee 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.\n\n`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.\n\n**New!** if you need to mix more nicer colors than just the default RGB, use `ExprColors`.\n\n#### How to plot the gazillions of the tiny points faster?\n#### How to reduce size (and loading time) of the PDFs that contain scatterplots?\n\nUse scattermore: https://github.com/exaexa/scattermore\n\n#### How to select point subsets from the embedding?\n\nA 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:\n\n```r\nclusters \u003c- cutree(k=10, hclust(method='average', dist(map$codes)))[map$mapping[,1]]\n```\n\nAfter 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:\n\n```r\nEmbedSOM::PlotEmbed(e, clust=clusters)\n```\n\nAfter 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`:\n\n```r\nd \u003c- d[clusters %in% c(5,6), ]\n```\n\n#### How to produce and display a 3D embedding?\n\nThere is now support for 3D SOM grids and 3D embedding. You need the customized SOM function from EmbedSOM:\n\n```r\nmap \u003c- EmbedSOM::SOM(someData, xdim=8, ydim=8, zdim=8)\ne \u003c- EmbedSOM::EmbedSOM(data=someData, map=map)\n```\n\n`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:\n\n```r\nplot3D::scatter3D(x=e[,1], y=e[,2], z=e[,3])\n```\n\nInteractive rotatable and zoomable plots are provided by the `rgl` library:\n\n```r\nrgl::points3d(x=e[,1], y=e[,2], z=e[,3])\n```\n\n#### What to do if embedding takes too long?\n\nYou 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`.\n\nFor SOM training, you need to explicitly switch to the parallelizable batch version, using `batch=T, parallel=T`.\n\n#### How to activate the SIMD support? (i.e. how to get even more speed?)\n\nAdditionally, 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)\n\nFirst, add a correct line to the R `Makevars` config file:\n```sh\n $ cat ~/.R/Makevars\nCXXFLAGS += -O3 -march=native\n```\n\nAfter 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.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fexaexa%2Fembedsom","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fexaexa%2Fembedsom","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fexaexa%2Fembedsom/lists"}