sqjin / CellChat

R toolkit for inference, visualization and analysis of cell-cell communication from single-cell data
GNU General Public License v3.0
637 stars 145 forks source link

computeCommunProb scaled distances calculated value here is Inf #607

Open Blackshoots opened 1 year ago

Blackshoots commented 1 year ago

Hello, I have recently encountered a problem that when I followed the tutorial to run computeCommunProb it showed that The suggested minimum value of scaled distances is in [1,2], and the calculated value here is Inf. In that way, the slot net$count in cellchat object shows all zero values which originate from Inf distance. I have seen source code and found the adjacancy matrix can hardly get edge 1 leading to Inf distance matrix.

cortex from Seurat tutorial Analysis, visualization, and integration of spatial datasets with Seurat

data.input = GetAssayData(cortex, slot = "data", assay = "SCT") # normalized data matrix
Idents(cortex) <- rownames(cortex[["predictions"]])[max.col(t(cortex[["predictions"]]@data), ties.method = "first")]
meta = data.frame(labels = Idents(cortex), row.names = names(Idents(cortex))) 
spatial.locs = GetTissueCoordinates(cortex, scale = NULL, cols = c("imagerow", "imagecol")) 
scale.factors <- list(spot.diameter = 65, spot = cortex@images$anterior1@scale.factors$spot, # these two information are required
                     fiducial = cortex@images$anterior1@scale.factors$fiducial, 
                     hires = cortex@images$anterior1@scale.factors$hires, 
                     lowres = cortex@images$anterior1@scale.factors$lowres # these three information are not required
)
cellchat <- createCellChat(object = data.input, meta = meta, group.by = "labels",
                           datatype = "spatial", coordinates = spatial.locs, scale.factors = scale.factors)
cellchat <- computeCommunProb(cellchat, type = "truncatedMean", trim = 0.1, 
                              distance.use = TRUE, interaction.length = 200, scale.distance = 0.01)

truncatedMean is used for calculating the average gene expression per cell group. [1] ">>> Run CellChat on spatial imaging data using distances as constraints <<< [2023-04-30 00:04:15]" The suggested minimum value of scaled distances is in [1,2], and the calculated value here is Inf |=====================================================================================================| 100% [1] ">>> CellChat inference is done. Parameter values are stored in object@options$parameter <<< [2023-04-30 00:04:28]"

13198910213 commented 1 year ago

Hello, I'm having the same problem, is there a solution yet? I hope I can get your help, thanks!

sqjin commented 1 year ago

@Hui-Se @13198910213 You cannot directly use the scale factor from the Seurat object because the cortex@images$anterior1@scale.factors$spot is not the same meaning as the one in CellChat. In Seurat, the value of cortex@images$anterior1@scale.factors$spot is the same as the value of cortex@images$anterior1@scale.factors$hires, which is not correct.