jinworks / CellChat

R toolkit for inference, visualization and analysis of cell-cell communication from single-cell and spatially resolved transcriptomics
GNU General Public License v3.0
248 stars 36 forks source link

Warning message is lying #26

Open mvfki opened 9 months ago

mvfki commented 9 months ago

I noticed some recent updates to the package and just couldn't wait to try it out. I used some old script I have with spatial data (not too old!) but got the following warning message which seemed new to me:

Warning message:
In createCellChat(object = mat, meta = meta, group.by = "ident",  :
  The 'meta' data does not have a column named `slices` for spatial transcriptomics data analysis.
              We now add this column and all cells are assigned as `slice1`!

And later the whole thing failed when I ran computeCommunProb() because some matrices got fully filled with NaN.

I did some code reading myself and am pretty sure that the bug is located between R/CellChat_class.R line 254 to line 266. You helped adding the column in meta but forgot to put it back to the object which is finally returned.

I've already figured out the way to make it work though, it would also be nice to add a line or two in the createCellChat() function to help check whether user customized metadata columns are factors or just character vectors. I also tried remaking my metadata with slice name properly set with meta$slices <- "name", but didn't factor it. And later I found in the code that the cluster wise distance is calculated on a per slice base and the for-loop for each slice is based on levels(meta$slices) which is obviously NULL for me and that's the story.

Thanks for the great tool!

sqjin commented 9 months ago

Hello @mvfki,

Thank you very very much for pointing out these two points. We now fix these two issues.

Best, Suoqin