sqjin / CellChat

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

Possible BUG in the liftCellChat function coupled with rankNet function : different levels result in different P-values #333

Open SeadonXing opened 2 years ago

SeadonXing commented 2 years ago

Hi , I want to joint set of the identities of my two groups by set group.new = union(levels( cellchat.group1@idents), levels(cellchat.group2@idents))

However, I found that these two commands gave totally different P-values while I think it should be the same when calling rankNet function. group.new = union( levels(cellchat.group1@idents), levels(cellchat.group2@idents) ) group.new = union( levels(cellchat.group2@idents), levels(cellchat.group1@idents) )

To make sure, I run the example dataset of CellChat tutorial. As expected, different levels for liftCellChat result in same contribution, contribution.scaled, and contribution.relative.1 but with different pvalues for rankNet, also the different layout.

CODE-1

cellchat.E13 <- readRDS("cellchat_embryonic_E13.rds") cellchat.E13 <- updateCellChat(cellchat.E13) cellchat.E14 <- readRDS("cellchat_embryonic_E14.rds") cellchat.E14 <- updateCellChat(cellchat.E14)

first E14 then E13

group.new <- union( levels(cellchat.E14@idents), levels(cellchat.E13@idents) ) group.new

[1] "FIB-A" "FIB-B" "FIB-P" "DC" "Pericyte" "MYL" "Immune" "ENDO" "Muscle" "MELA" "Basal-P" "Basal" "Spinious"

cellchat.E13 <- liftCellChat(cellchat.E13, group.new) cellchat.E14 <- liftCellChat(cellchat.E14, group.new) object.list <- list(E13 = cellchat.E13, E14 = cellchat.E14) cellchat <- mergeCellChat(object.list, add.names = names(object.list), cell.prefix = TRUE) rankNet(cellchat , slot.name = "netP", mode = "comparison", do.stat=TRUE, stacked = T, return.data=TRUE)

name contribution contribution.scaled group contribution.relative.1 pvalues
TNF 0.000000e+00 0.00000000 E13 Inf 0.000000e+00
LIFR 0.000000e+00 0.00000000 E13 Inf 0.000000e+00
OSM 0.000000e+00 0.00000000 E13 Inf 0.000000e+00
ANGPT 0.000000e+00 0.00000000 E13 Inf 0.000000e+00
KIT 4.085102e-06 0.08059210 E13 181.8 1.963491e-11
GALECTIN 1.640631e-05 0.09076185 E13 8.1 3.917694e-03
IL2 4.121054e-09 0.05179426 E13 7.4 1.660156e-02
EDN 1.794384e-05 0.09150584 E13 4.7 1.611328e-02
EGF 1.210662e-06 0.07339803 E13 4.6 3.637979e-12
WNT 3.910415e-05 0.09852914 E13 4.6 9.536743e-07
IL4 1.802653e-07 0.06439633 E13 3.8 0.000000e+00
VEGF 3.570090e-06 0.07972625 E13 3.7 1.953125e-03
IGF 1.138691e-03 0.14753886 E13 2.5 1.517655e-11
SEMA3 1.848087e-03 0.15889147 E13 2.5 3.316465e-14
CCL 8.565934e-06 0.08570657 E13 2.4 1.250000e-01

CODE-2

cellchat.E13 <- readRDS("cellchat_embryonic_E13.rds") cellchat.E13 <- updateCellChat(cellchat.E13) cellchat.E14 <- readRDS("cellchat_embryonic_E14.rds") cellchat.E14 <- updateCellChat(cellchat.E14)

first E13 then E14

group.new <- union( levels(cellchat.E13@idents), levels(cellchat.E14@idents) ) group.new

[1] "FIB-A" "FIB-B" "FIB-P" "MYL" "Immune" "ENDO" "Muscle" "MELA" "Basal-P" "Basal" "Spinious" "DC" "Pericyte"

cellchat.E13 <- liftCellChat(cellchat.E13, group.new) cellchat.E14 <- liftCellChat(cellchat.E14, group.new) object.list <- list(E13 = cellchat.E13, E14 = cellchat.E14) cellchat <- mergeCellChat(object.list, add.names = names(object.list), cell.prefix = TRUE) rankNet(cellchat , slot.name = "netP", mode = "comparison", do.stat=TRUE, stacked = T, return.data=TRUE)

name contribution contribution.scaled group contribution.relative.1 pvalues
TNF 0.000000e+00 0.00000000 E13 Inf 0.000000e+00
LIFR 0.000000e+00 0.00000000 E13 Inf 0.000000e+00
OSM 0.000000e+00 0.00000000 E13 Inf 0.000000e+00
ANGPT 0.000000e+00 0.00000000 E13 Inf 0.000000e+00
KIT 4.085102e-06 0.08059210 E13 181.8 1.825301e-10
GALECTIN 1.640631e-05 0.09076185 E13 8.1 1.051080e-02
IL2 4.121054e-09 0.05179426 E13 7.4 2.453613e-02
EDN 1.794384e-05 0.09150584 E13 4.7 4.187012e-02
EGF 1.210662e-06 0.07339803 E13 4.6 1.635122e-03
WNT 3.910415e-05 0.09852914 E13 4.6 4.689366e-03
IL4 1.802653e-07 0.06439633 E13 3.8 0.000000e+00
VEGF 3.570090e-06 0.07972625 E13 3.7 2.253227e-01
IGF 1.138691e-03 0.14753886 E13 2.5 2.027632e-08
SEMA3 1.848087e-03 0.15889147 E13 2.5 1.279803e-09
CCL 8.565934e-06 0.08570657 E13 2.4 6.875000e-01
sqjin commented 2 years ago

@SeadonXing Thanks for pointing it out. I will find time to address it next week.