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
178 stars 19 forks source link

Question in analysis of Xenium or CosMx with CellChat #18

Open SGIlabes opened 5 months ago

SGIlabes commented 5 months ago

Thank you for creating such a wonderful package. I am finding it very useful. But I have a question.
When setting scale factors to create a CellChat object, what would be a good way to input metrics for data without spots, like from CosMx or Xenium? All I know is that CosMx coordinates are in pixels, and 1 pixel equals 0.18um. Do you have any suggestions for parameters in this case? Also, for CosMx data, should I enter 0.18 in the scale.distance parameter of computeCommunProb? And Do you still recommend interaction.range of 250 in this function for Xenium or CosMx? I would really appreciate your opinion on this.

sqjin commented 5 months ago

@SGIlabes Please check the new updates. We provide a tutorial on it.

SGIlabes commented 5 months ago

Thank you so much for the answer. The explanation from the tutorial was really clear. Also, at Xenium, it seems possible to apply the same code by setting the conversion factor to 1, right? Thank you so much. And, I am really sorry for keeping bother you, but when I use computeCommmunProb in CosMx data with your suggested scale factors, there are some errors in computeCommunProb functions as:

The suggested minimum value of scaled distances is in [1,2], and the calculated value here is Inf

In min(d.spatial, na.rm = TRUE) : no non-missing arguments to min; returning Inf

In this function, do I have to set interaction.range or scale.distance as some specific values?

sqjin commented 5 months ago

@SGIlabes Yes, you can set the conversion factor to 1 for Xenium as all of Xenium coordinates are in microns. However, because Xenium is in a subcellular resolution, you should set the tolerance factor tol as the minimum distance of cell center-to-center between cell pairs.

You can also see more details in https://kb.10xgenomics.com/hc/en-us/articles/11636252598925 for scale factors related to the image data. Documentation explaining Xenium outputs:

https://www.10xgenomics.com/support/in-situ-gene-expression/documentation/steps/onboard-analysis/xenium-outputs-zarr https://www.10xgenomics.com/support/in-situ-gene-expression/documentation/steps/onboard-analysis/at-a-glance-xenium-output-files https://www.10xgenomics.com/support/in-situ-gene-expression/documentation/steps/onboard-analysis/understanding-xenium-outputs

I do not have this error on my side. I may need to test this type of data in few days later. The interaction.range is 250um for any dataset. You can set distance.use = FALSE to see if the error goes way (I am afraid not in your case). You can further run the computeRegionDistance function to check the reasons for such errors.

SGIlabes commented 5 months ago

Thank you for the prompt response. When I set distance = FALSE, I'm encountering an error: '0%Error in if (sum(P1_Pspatial) == 0) { : missing value where TRUE/FALSE needed'. I'm not sure what this means, and it's quite disheartening.

It seemed to work fine when I increased the spot size to about 20. I'm thinking this issue might be because the CosMx data contains many FOVs that are far apart. I really want to use your package, but it's challenging.

However, I'm grateful for your kind and detailed explanations. Also, thank you for adding the tutorial.

mugpeng commented 5 months ago

You haven't updated your code following the newest version. Some changes have been made to create the obj. like:

meta = data.frame(labels = Idents(visium.brain), slices = "slice1", row.names = names(Idents(visium.brain))) # manually create a datafra
SGIlabes commented 5 months ago

You haven't updated your code following the newest version. Some changes have been made to create the obj. like:

meta = data.frame(labels = Idents(visium.brain), slices = "slice1", row.names = names(Idents(visium.brain))) # manually create a datafra

I am sorry but is this comment related to my question? I think I did it a right job here meta = data.frame(labels = Idents(dismal1K_fine), row.names = names(Idents(dismal1K_fine)))

mugpeng commented 5 months ago

yes, you need to set the slices parameter. Bez I have the same error as you, and I fix it by tracking the source code

mugpeng commented 5 months ago

By the way. I encountered the error:

Please increase the value of `scale.distance` and check the suggested values in the parameter

For me, I change the scale.distance from 0.01 to 0.02 in order to make d.spatial larger than 1. Will this normalization influence the final result? Thanks.

SGIlabes commented 5 months ago

yes, you need to set the slices parameter. Bez I have the same error as you, and I fix it by tracking the source code

Thank you for addressing my query. Although there are 16 FOVs in a single CosMx object, it seems I need to try to create separate data slices for each FOV

sqjin commented 5 months ago

@mugpeng It will not affect the ranking of the L-R pairs. Please check the documentation of the function via ?computeCommunProb.

sqjin commented 5 months ago

@SGIlabes You can also check the tutorial on analysis of multiple slices/FOVs spatial datasets.

SGIlabes commented 5 months ago

@SGIlabes You can also check the tutorial on analysis of multiple slices/FOVs spatial datasets.

Finally, with your help, it seems that I have resolved the issue. I have created slices for all FOVs, and your multi-sample spatial data tutorial was very helpful. Thank you!

SGIlabes commented 5 months ago

I am sorry but I have one more question. Is there a way to subset cellchat object by slice? I want to compare between slices.

sqjin commented 5 months ago

@SGIlabes If you tend to compare signaling between different slices, then you have to create a cellchat object for each slice. The multi-sample tutorial is used for finding signaling by aggregating information from all slices.

SGIlabes commented 5 months ago

@SGIlabes If you tend to compare signaling between different slices, then you have to create a cellchat object for each slice. The multi-sample tutorial is used for finding signaling by aggregating information from all slices.

Thank you, I have already followed your tutorials, which were very helpful. But I have a new question and I am very sorry for keeping bothering you.

I have a Poor Response group consisting of 34 slices and a Good Response group with 67 slices. Is it acceptable to compare the Poor Response group (merging the 34 slices) with the Good Response group (merging the 67 slices)? I am wondering if the number of interactions is affected by the number of slices. Is the number of interactions the average value calculated from each slice?