Closed jleechung closed 1 year ago
In theory, it should work. However, we haven't gotten around to updating our code to more flexibly identify neighborhood structure. If you are interested in hacking together something yourself, the relevant section of the code for identifying neighbors is in the .find_neighbors
function here.
I was working on an example earlier with NanoString CosMx data which is similar. Here's a code snippet I used to find neighbors within a fixed radius.
radius = 100 #100 pixels
positions = cbind(sce$CenterX_global_px, sce$CenterY_global_px)
pdist = as.matrix(stats::dist(positions, "euclidean")) #this probably won't work so well if you have a lot of cells
neighbors = (pdist <= radius & pdist > 0)
df_j = sapply(seq_len(nrow(positions)), #this can be used as the return to the .find_neighbors() call in spatialCluster()
function(x) as.vector(which(neighbors[x, ])) - 1)
Thanks for the clarification and pointers. Would something like taking the k-nearest spatial neighbors work? i.e.:
sce <- exampleSCE()
k <- 10 # hyperparam
positions = cbind(sce$row, sce$col)
knn <- dbscan::kNN(positions, k = k)$id - 1
df_j <- split(knn, seq(nrow(knn)))
names(df_j) <- NULL
I guess this would also be generalizable to Visium (k=6) and ST (k=4).
Yes, k nearest neighbors should work as well!
Cool, thanks!
Hi @edward130603 ,
Can BayesSpace be used for clustering high-resolution spatial omics data (e.g. MERFISH)?