computeCommunProb: Error in nn.ranked[idx.i, ] : subscript out of bounds
Opened this issue · 5 comments
When running computeCommunProb
, I'm getting this error: Error in nn.ranked[idx.i, ] : subscript out of bounds
@strawberry098 When you work on multiple spatial datasets, do you have some cell groups that are missing in one sample? You may can run computeRegionDistance
line by line to figure out the specific reasons.
@sqjin Do you recommend that I split the multiple spatial dataset into individual spatial datasets?
I don't quite understand how to use the function computeRegionDistance
@sqjin Yes, I had samples that were missing certain cell types. As a result, I split the multiple spatial dataset into individual samples and tried to rerun CellChat successful for the first sample. However, for the remaining samples, I am getting the same error.
It seems that when I split the multiple-spatial-dataset Seurat Object, the spatial images for all samples remained for each split one-sample-only Seurat Object. I'm unsure if this is the reason causing the issue.
For what it is worth, I ran into this issue as well. The problem in my code was that GetTissueCoordinates() returns only the coordinates for the first sample/image in the combined Seurat object. As a result, when I blindly built the cellchat object, subsequent calls to computeCommunProb would produce this error "nn.ranked[idx.i, ]."
I fixed it by ensuring that spatial.locs included all samples/images as follows:
spatial.locs <- bind_rows(lapply(Images(seurat.obj), function(x) GetTissueCoordinates(seurat.obj, image = x, scale = NULL)))
spatial.locs <- spatial.locs[, 1:2]
cellchat <- createCellChat(object = data.input, meta = meta, group.by = "labels", datatype = "spatial", coordinates = spatial.locs, spatial.factors = spatial.factors)
I hope this is helpful!
For what it is worth, I ran into this issue as well. The problem in my code was that GetTissueCoordinates() returns only the coordinates for the first sample/image in the combined Seurat object. As a result, when I blindly built the cellchat object, subsequent calls to computeCommunProb would produce this error "nn.ranked[idx.i, ]."
I fixed it by ensuring that spatial.locs included all samples/images as follows:
spatial.locs <- bind_rows(lapply(Images(seurat.obj), function(x) GetTissueCoordinates(seurat.obj, image = x, scale = NULL))) spatial.locs <- spatial.locs[, 1:2] cellchat <- createCellChat(object = data.input, meta = meta, group.by = "labels", datatype = "spatial", coordinates = spatial.locs, spatial.factors = spatial.factors)
I hope this is helpful!
I didn’t even realize that the issue was with the GetTissueCoordinates function. Thank you so much for your response; it solved the problem I was facing.