SofieVG / FlowSOM

Using self-organizing maps for visualization and interpretation of cytometry data
61 stars 26 forks source link

Accessing MapDataFromCodes in FlowSOM/installation error using devtools #43

Closed alex-l-kong closed 3 years ago

alex-l-kong commented 3 years ago

I'm trying to use FlowSOM to train on a subset of our data and apply the trained weights to cluster the entire dataset. The default settings of the FlowSOM algorithm, however, seem to only support training and clustering on the entire dataset with no intuitive way to allow for subsetting.

Looking at the source code and documentation, it looks like this can be done by passing the subsetted data into SOM, then passing the trained weights and the entire dataset into MapDataToCodes. However, it seems like we would need version 1.4.0 of the library to do so according to RDocumentation, and BiocManager only installs 1.19.4. I tried using devtools (as outlined in the repo) to install the latest version from GitHub, but I run into this error:

   Error: processing vignette 'FlowSOM.Rnw' failed with diagnostics:
   Running 'texi2dvi' on 'FlowSOM.tex' failed.
   LaTeX errors:
   ! Undefined control sequence.
   l.320 \code
              {PlotFlowSOM} or you can use the \code{PlotStars} function.
   The control sequence at the end of the top line
   of your error message was never \def'ed. If you have
   ! Undefined control sequence.
   l.320 \code{PlotFlowSOM} or you can use the \code
                                                    {PlotStars} function.
   The control sequence at the end of the top line
   of your error message was never \def'ed. If you have
   ! Undefined control sequence.
   l.345 node, you can use the parameter \code
                                              {equalNodeSize = T} in every plot...
   The control sequence at the end of the top line
   of your error message was never \def'ed. If you have
   --- failed re-building ‘FlowSOM.Rnw’

Is there an easy fix to this, and if not, how can I download version 1.4.0 as outlined in the RDocumentation page so I can access MapDataToCodes?

SamGG commented 3 years ago

Hi, Version 1.4.0 is older than 1.19.4 because 4 < 19 Here are my current versions, and I think they are the latest. Check https://bioconductor.org/packages/release/bioc/html/FlowSOM.html.

> packageVersion("FlowSOM")
[1] ‘1.22.0’
> BiocManager::version()
[1] ‘3.12’

MapDataToCodes() is currently exported and could be used in your code. Your strategy is correct. Best.

alex-l-kong commented 3 years ago

@SamGG thanks for the clarification on the version numbers.

When I try to call MapDataToCodes, I still get the error 'MapDataFromCodes' is not found with both versions 1.22.0 and 1.14.1. I'm calling it as such:

library(FlowSOM)
...
som_results <- SOM(data=as.matrix(pixelMatData_subset))
clusters <- MapDataToCodes(som_results$codes, pixelMatData)

Am I missing anything in the call to MapDataToCodes?

SamGG commented 3 years ago

I was wrong, the function is not exported. So the call must be prefixed to access the function, even if the library is already loaded.

clusters <- FlowSOM:::MapDataToCodes(som_results$codes, pixelMatData)

The results is a matrix with the first column being the nearest node id and the second column the distance to it. Be sure to set a name to each column of pixelMatData using colnames function. Best.

alex-l-kong commented 3 years ago

@SamGG thanks for your help!

SofieVG commented 3 years ago

Hi @alex-l-kong ,

Next to the solution provided by @SamGG, would the NewData() function (which is exported by FlowSOM, and the one which uses "MapDataToCodes" internally) be of interest for your question? If not, could you shortly explain if there would be a way we could extend this function to make it suit your needs?

All the best, Sofie

SamGG commented 3 years ago

@SofieVG Sorry, I forgot this nice function. Thanks.

alex-l-kong commented 3 years ago

@SofieVG MapDataToCodes worked quite nicely for us, but NewData looks like it could provide even more information (and not just a new mapping). Thanks for the recommendation!