sqjin / CellChat

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

error when run computeCommunProb function #360

Open Magetutor opened 2 years ago

Magetutor commented 2 years ago

Thank you very much for providing cellchat! When I run the function computeCommunProb on my data, I met below error

V59.cellchat <- computeCommunProb(V59.cellchat, raw.use = TRUE)
  |         |   0% Error in if (sum(P1) == 0) { : missing value where TRUE/FALSE needed
In addition: There were 18 warnings (use warnings() to see them)

and my data in object@data.project and object@data.signaling as below

> str(V59.cellchat@data.signaling)
Formal class 'dgCMatrix' [package "Matrix"] with 6 slots
  ..@ i       : int [1:2483819] 0 1 2 3 4 5 6 7 8 9 ...
  ..@ p       : int [1:11240] 0 221 442 663 884 1105 1326 1547 1768 1989 ...
  ..@ Dim     : int [1:2] 221 11239
  ..@ Dimnames:List of 2
  .. ..$ : chr [1:221] "Cxcl2" "Ccl5" "Ccl4" "Ccl8" ...
  .. ..$ : chr [1:11239] "V_59_AAACCCAAGAGAGTTT-1" "V_59_AAACCCAAGCACTGGA-1" "V_59_AAACCCACAAGAATAC-1" "V_59_AAACCCACAATAGTAG-1" ...
  ..@ x       : num [1:2483819] -1.681 6.142 -2.049 -1.193 -0.874 ...
  ..@ factors : list()
> str(V59.cellchat@data.project)
 num [1:221, 1:11239] -1.681 6.142 -2.049 -1.193 -0.874 ...
 - attr(*, "dimnames")=List of 2
  ..$ : chr [1:221] "Cxcl2" "Ccl5" "Ccl4" "Ccl8" ...
  ..$ : chr [1:11239] "V_59_AAACCCAAGAGAGTTT-1" "V_59_AAACCCAAGCACTGGA-1" "V_59_AAACCCACAAGAATAC-1" "V_59_AAACCCACAATAGTAG-1" ...

Thanks for your beautiful work! Looking forward for your reply and help!

sqjin commented 2 years ago

@Magetutor Your data have negative values. You should use the normalized data without negative values.

Magetutor commented 2 years ago

@sqjin Many thanks for your quick reply!I got it!

domjacri commented 2 years ago

@Magetutor Would you mind sharing the code you used to select normalized data without negative values if you are using analysis from Seurat?

RoseString commented 2 years ago

Hello @sqjin! My data were batch-corrected by fastMNN, and therefore contained many negative values. Batch correction is quite important in my case as the two datasets I integrated had very different cell-type compositions.

Can you give me advice on how to make the input matrix suitable for CellChat? Thanks!

sqjin commented 2 years ago

@RoseString While I have not extensively tested the batch-corrected data, I think people usually set the negative values to zero when using it for downstream analysis such as gene scoring analysis and gene expression analysis. What is your strategy when using these corrected data? I think you can try it in this way.

sqjin commented 2 years ago

@RoseString You can simply get this normalized data via GetAssayData(object = pbmc_small, slot = "data",assay = "RNA")