saeyslab / FlowSOM

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

size is not part of MST anymore #14

Open gitdemont opened 2 years ago

gitdemont commented 2 years ago

I did rely on MST$size element in the returned object from BuildMST function. However, with the new version of FlowSOM (at least the one I did just install), size is not part of the returned object anymore.

I think size was computed thanks to UpdateNodeSize function. But this function is now deprecated.

Would it be possible to either:

SofieVG commented 2 years ago

What are you using this information for? Due to our switch to ggplot plotting instead of igraph, using the UpdateNodeSize does not make sense anymore. We currently base the node sizes on the cluster percentages, which you can easily access with GetPercentages(flowSOM.res, level = "clusters") (or flowSOM.res$map$pctgs). The node sizes can also be immediately passed on as an argument to any plotting function (see the help of PlotFlowSOM), rather than having to wrap the FlowSOM object in an UpdateNodeSize function first. We make use of an internal function for rescaling the percentages to sizes used in ggplot, given the maximum wanted node size and a reference value (which is typically the original maximum, but can be a different value when you want comparable values for different trees). The maximum wanted is estimated based on the tree layout, again with an internal function (AutoMaxNodeSize). We could export these function and make them available in the package if that would be helpful for you.

nodeSizes <- GetPercentages(flowSOM.res, level = "clusters")
FlowSOM:::ParseNodeSize(nodeSizes, max_wanted, max(nodeSizes))

If you could explain in a little more detail what you used the MST$size element for, I can try to suggest a specific solution for your use case.

gitdemont commented 2 years ago

Thanks a lot for your reply,

It was really instructive and it also helped me to use maxNodeSize argument in the new PlotFlowSOM function (v2.2.0) to get graphs that look like the former ones (v1.2.0), I just tested some values and it seems maxNodeSize = 2.6 gives nice result

I also tested:

a = FlowSOM::UpdateNodeSize(flowSOM.res)$MST$size
nodeSizes <- FlowSOM::GetPercentages(flowSOM.res, level = "clusters")
b = FlowSOM:::ParseNodeSize(nodeSizes, max(a), max(nodeSizes))
all.equal(a, b, check.attributes = FALSE)

Which gives same result, so I think I will use a copy of FlowSOM::UpdateNodeSize without the deprecated warning, except if fsom object elements (map$nNodes, map$grid, map$mapping) are expected to be changed. Notably because ParseNodeSize is an internal function and should be accessed through :::

For the use case here, I am working on an shiny app IFCshiny for interactive imaging and conventional flow cytometry analysis. In a ML module, I included FlowSOM, and users should be allowed to export the results of the embedding to fcs (conventional) and daf (imaging) files. The idea is to take the points that fall into each node and give them some jittering arround nodes centers so has to display them in a 2D graph that will look like the MST. The amount of jittering is controlled by MST$size