I’m just wondering how to plot a MST, just like when using flowsom, but do it using the catalyst package instead. I have followed the catalyst tutorial on bioconductor and just finished the clustering bit. It would be nice to be able to visualise the clustering using a MST but I am not sure how to do it…
Thanks a lot for helping
Here’s the code I tried for clustering using catalyst package:
sce <- cluster(sce, features = "type",
xdim = 10, ydim = 10, maxK = 20,
verbose = FALSE, seed = 1)
Then I tried the following to plot a MST:
fsom <- metadata(sce)$SOM
PlotStars(fsom, view = "MST", backgroundValues = fsom$metaclustering)
However I got the following:
Error in UpdateFlowSOM(fsom) : fsom should be a FlowSOM object.
I’m not sure how to make this work now…
-
First, extract the SOM results:
som_results <- metadata(sce)$SOM
2)Get the SOM weights and meta-clustering results:
som_weights <- som_results$codes
meta_clusters <- som_results$metaclustering
-
Calculate distances between SOM nodes:
library(dist)
distances <- as.matrix(dist(som_weights)) -
Create an MST using these distances:
library(igraph)
mst <- minimum.spanning.tree(graph_from_adjacency_matrix(distances, weighted = TRUE, mode = “undirected”))
5)Finally, plot the MST:
library(ggraph)
library(tidygraph)
graph_data <- as_tbl_graph(mst) %>%
mutate(cluster = meta_clusters)
ggraph(graph_data, layout = "kk") +
geom_edge_link() +
geom_node_point(aes(color = factor(cluster)), size = 5) +
theme_void() +
labs(color = "Meta-cluster")
This code creates an MST using the SOM results and colors each node according to the meta-clusters. The result will be similar to FlowSOM’s MST visualization.