CellChat icon indicating copy to clipboard operation
CellChat copied to clipboard

Bug in the liftCellChat function

Open BenJCQuah opened this issue 1 year ago • 2 comments

Hi,

I am using v2.1.2

I have encountered what appears to be an unresolved issue relating to #202. When using group.new = union(levels(cellchat1@idents), levels(cellchat2@idents)) in conjunction with liftCellChat() the levels of the new idents are not in line with the old ones and so many of the reports are out of sync.

For example if I run the following code, I should get the same results for each plot (left plot is the lifted and the right plot is the original). Instead I get the new idents added in to the lifted data (first plot attached with "pDC" and "t1cDC" add in) and this misaligns the the original idents so the interactions are no longer referring to the (presumably) correct ones in the original data (second plot). For example, the ident "Plat" out signals are in fact the the "DC" out signals etc. This would also imply the merged object are all incorrect from this point on.

Perhaps I am doing something wrong, but this appears to be a problem. I notice there was some code in #202 that may fix this, was this implimented? Any help would be greatly appreciated.

Thanks,

Ben

setdiff(cc_B_Nil@idents, cc_B_4T1@idents) [1] "pDC" "t1cDC" setdiff(cc_B_4T1@idents, cc_B_Nil@idents) [1] "GC B" group_new_n_t <- union(levels(cc_B_Nil@idents), levels(cc_B_4T1@idents)) cc_B_Nil_lift <- liftCellChat(cc_B_Nil, group_new_n_t) The CellChat object will be lifted up using the cell labels CD4 T, CD8 T, Treg, NK, B cell, Tran B, Neut, Mono, ncMono, Mac, iMac, aMac, DC, pDC, t1cDC, Plat, GC B Update slots object@net, object@netP, object@idents in a single dataset... cc_B_4T1_lift <- liftCellChat(cc_B_4T1, group_new_n_t) The CellChat object will be lifted up using the cell labels CD4 T, CD8 T, Treg, NK, B cell, Tran B, Neut, Mono, ncMono, Mac, iMac, aMac, DC, pDC, t1cDC, Plat, GC B Update slots object@net, object@netP, object@idents in a single dataset... object.list <- list(B_Nil = cc_B_Nil_lift, B_4T1 = cc_B_4T1_lift) cc_comb_b <- mergeCellChat(object.list, add.names = names(object.list), cell.prefix = TRUE) The cell barcodes in merged 'meta' is B-Nil_AAACCCAAGCAATAAC-1 B-Nil_AAACGAACAACTGCTA-1 B-Nil_AAACGAACAGTATACC-1 B-Nil_AAACGAACAGTGGGTA-1 B-Nil_AAACGAAGTGTAACGG-1 B-Nil_AAACGAATCCCTCGAT-1 Merge the following slots: 'data.signaling','images','net', 'netP','meta', 'idents', 'var.features' , 'DB', and 'LR'. Warning messages: 1: In mergeCellChat(object.list, add.names = names(object.list), cell.prefix = TRUE) : Prefix cell names! 2: In mergeCellChat(object.list, add.names = names(object.list), cell.prefix = TRUE) : The cell barcodes in merged 'meta' is different from those in the used data matrix. We now simply assign the colnames in the data matrix to the rownames of merged 'mata'! par(mfrow = c(1,2), xpd=TRUE) netVisual_aggregate(object.list$B_4T1, signaling = show_pathways, layout = "chord") netVisual_aggregate(cc_B_4T1, signaling = show_pathways, layout = "chord")

image

BenJCQuah avatar Mar 20 '24 06:03 BenJCQuah

Hello,

Could you please take a look at this? I'm running into the same problem. In the example below the APCs, which alphabetically come before the CASR_pos_1, are maintained correctly, but the Lymphatic_endothelial_cells, White_adipocytes, etc. are all skipped to the next alphabetical identity (ex. White_adipocyte_1 became White_adipocyte_2). I'm assuming it has to do with how the new cells are being merged into the dataset and how the functions are mapping them by order.

Thanks for providing such an amazing package!

#Define the cell types not present in one or other dataset setdiff(union(levels(cellchat.deep@idents), levels(cellchat.sup@idents)), intersect(levels(cellchat.deep@idents), levels(cellchat.sup@idents))) [1] "CASR_pos_1" "Unknown_5"

#Define the cell labels to lift up by combining both cell labels from the conditions group.new = union(levels(cellchat.sup@idents), levels(cellchat.deep@idents))

cellchat.deep.lift <- liftCellChat(cellchat.deep, group.new) The CellChat object will be lifted up using the cell labels APC_1, APC_2, APC_3, APC_4, APC_5, Brown_adipocyte, CASR_pos_2, Endothelial_1, Endothelial_2, Endothelial_3, Lymphatic_endothelial_1, Lymphatic_endothelial_2, Lymphatic_endothelial_3, Lymphocyte_1, Lymphocyte_2, Macrophage, Mast, Mesenchymal, Neuron_associated, Neutrophil, Pericyte, PRM1_pos, Schwann_myelinating, Schwann_non_myelinating_Schwann, Smooth_muscle_1, Smooth_muscle_2, Unknown_1, Unknown_2, Unknown_3, Unknown_4, Unknown_5, White_adipocyte_1, White_adipocyte_2, White_adipocyte_3, White_adipocyte_4, White_adipocyte_5, CASR_pos_1 Update slots object@net, object@netP, object@idents in a single dataset... cellchat.sup.lift <- liftCellChat(cellchat.sup, group.new) The CellChat object will be lifted up using the cell labels APC_1, APC_2, APC_3, APC_4, APC_5, Brown_adipocyte, CASR_pos_2, Endothelial_1, Endothelial_2, Endothelial_3, Lymphatic_endothelial_1, Lymphatic_endothelial_2, Lymphatic_endothelial_3, Lymphocyte_1, Lymphocyte_2, Macrophage, Mast, Mesenchymal, Neuron_associated, Neutrophil, Pericyte, PRM1_pos, Schwann_myelinating, Schwann_non_myelinating_Schwann, Smooth_muscle_1, Smooth_muscle_2, Unknown_1, Unknown_2, Unknown_3, Unknown_4, Unknown_5, White_adipocyte_1, White_adipocyte_2, White_adipocyte_3, White_adipocyte_4, White_adipocyte_5, CASR_pos_1 Update slots object@net, object@netP, object@idents in a single dataset...

#Merge objects object.list <- list(SUPERFICIAL = cellchat.sup, DEEP = cellchat.deep) cellchat <- mergeCellChat(object.list, add.names = names(object.list), cell.prefix = TRUE) The cell barcodes in merged 'meta' is AAGCGAGTCTACGCAA-1_Axiom001_SQ GGTGTTATCGAACGCC-1_Axiom001_SQ CGTTGGGTCTGCTAGA-1_Axiom001_SQ CCCATTGCAAGTTTGC-1_Axiom001_SQ TTGTTTGGTACAAGCG-1_Axiom001_SQ CGATGCGTCACTGATG-1_Axiom001_SQ Merge the following slots: 'data.signaling','images','net', 'netP','meta', 'idents', 'var.features' , 'DB', and 'LR'.

num.link <- sapply(object.list, function(x) {rowSums(x@net$count) + colSums(x@net$count)-diag(x@net$count)}) weight.MinMax <- c(min(num.link), max(num.link))

plots = list() plots[[1]] = netAnalysis_signalingRole_scatter(cellchat.deep.lift, title = "SUPERFICIAL - Lifted", weight.MinMax = weight.MinMax) Signaling role analysis on the aggregated cell-cell communication network from all signaling pathways plots[[2]] = netAnalysis_signalingRole_scatter(cellchat.deep, title = "SUPERFICIAL - original", weight.MinMax = weight.MinMax) Signaling role analysis on the aggregated cell-cell communication network from all signaling pathways p = patchwork::wrap_plots(plots = plots) p

Rplot

sessionInfo() R version 4.3.1 (2023-06-16 ucrt) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 10 x64 (build 18363)

Matrix products: default

attached base packages: [1] parallel grid stats graphics grDevices utils datasets methods base

other attached packages: [1] ggpubr_0.6.0 tibble_3.2.1 doParallel_1.0.17 iterators_1.0.14 foreach_1.5.2 ggalluvial_0.12.5
[7] NMF_0.27 cluster_2.1.6 rngtools_1.5.2 registry_0.5-1 ComplexHeatmap_2.16.0 circlize_0.4.16
[13] CellChat_1.6.1 Biobase_2.62.0 BiocGenerics_0.48.1 igraph_2.0.2 dplyr_1.1.4 Matrix_1.6-5
[19] VISION_3.0.1 RColorBrewer_1.1-3 ggplot2_3.5.0 Seurat_5.0.2 SeuratObject_5.0.1 sp_2.1-3

camara-h avatar Mar 26 '24 19:03 camara-h

I just happened to look and saw you had the same issue half a year ago. I assume they're just nor looking into it or doing fixes anymore? https://github.com/jinworks/CellChat/issues/193

WayGW avatar Sep 16 '24 17:09 WayGW