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
241 stars 34 forks source link

Compare interactions between >2 datasets #128

Open mboisvert1 opened 5 months ago

mboisvert1 commented 5 months ago

Hi,

I am trying to compare signaling interactions between a group of 5 datasets sharing the same cell types.

I've read in the cell chat objects for each dataset and have merged them using mergeCellChat.

When I run: gg1 <- compareInteractions(cellchat, show.legend = F, group = c(1,4)) gg2 <- compareInteractions(cellchat, show.legend = F, group = c(1,4), measure = "weight") gg1 + gg2

I get the following error: Error in $<-.data.frame(*tmp*, "group", value = c(1, 2)) : replacement has 2 rows, data has 5

Is it possible to run the comparative analysis using more than 2 datasets?

Thank you

sqjin commented 5 months ago

@mboisvert1 This is possible. But you use the function in a wrong way. You can leave 'group' as empty or define it as a vector with the length 5.

superjmiscool commented 4 months ago

I have a similar problem, the compareInteractions() function works fine, but when I use the rankNet() function to compare a cellchat object containing 8 datasets, something different occurs as described below: gg1 <- rankNet(cellchat,slot.name = "netP",tol = 0.5, comparison = c(1,3), mode = "comparison", stacked = T, thresh = 0.05, measure = "weight",
return.data = F, do.flip = F)
=====> run successfully gg1 <- rankNet(cellchat,slot.name = "netP",tol = 0.5, comparison = c(1,5), mode = "comparison", stacked = T, thresh = 0.05, measure = "weight",
return.data = F, do.flip = F)
=====> run successfully gg1 <- rankNet(cellchat,slot.name = "netP",tol = 0.5, comparison = c(2,8), mode = "comparison", stacked = T, thresh = 0.05, measure = "weight",
return.data = F, do.flip = F)
=====> Error in prob.values[, j] <- as.vector(prob.list[[j]][, , pair.name.all[i]]) : number of items to replace is not a multiple of replacement length gg1 <- rankNet(cellchat,slot.name = "netP",tol = 0.5, comparison = c(4,8), mode = "comparison", stacked = T, thresh = 0.05, measure = "weight",
return.data = F, do.flip = F)
=====> Error in prob.values[, j] <- as.vector(prob.list[[j]][, , pair.name.all[i]]) : number of items to replace is not a multiple of replacement length

In short, it means that rankNet does not run successfully when the COMPARISON involves 8, but this cellchat object does contain 8 subsets plus a JOINT set

length(cellchat@idents) [1] 9

emcramer commented 1 month ago

Is there a solution to this issue? I am getting the same error as @superjmiscool for the same function. I'm using CellChat version 2.1.2

Session Info ─ Session info ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── | setting | value | |----------|--------------------------------------------| | version | R version 4.3.2 (2023-10-31) | | os | macOS Ventura 13.6.2 | | system | aarch64, darwin20 | | ui | RStudio | | language | (EN) | | collate | en_US.UTF-8 | | ctype | en_US.UTF-8 | | tz | America/Los_Angeles | | date | 2024-07-18 | | rstudio | 2024.04.2+764 Chocolate Cosmos (desktop) | | pandoc | 3.1.11.1 @ /usr/local/bin/ (via rmarkdown) | ─ Packages ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── ! package * version date (UTC) lib source P abind 1.4-5 2016-07-21 [?] RSPM P backports 1.5.0 2024-05-23 [?] RSPM P Biobase * 2.62.0 2023-10-26 [?] Bioconductor P BiocGenerics * 0.48.1 2023-11-02 [?] Bioconductor P BiocManager 1.30.23 2024-05-04 [?] RSPM P BiocNeighbors 1.20.2 2024-01-13 [?] Bioconduc~ P BiocParallel 1.36.0 2023-10-26 [?] Bioconductor P broom 1.0.6 2024-05-17 [?] RSPM P bslib 0.7.0 2024-03-29 [?] RSPM P cachem 1.1.0 2024-05-16 [?] RSPM P car 3.1-2 2023-03-30 [?] RSPM P carData 3.0-5 2022-01-06 [?] RSPM P CellChat * 2.1.2 2024-07-11 [?] Github (jinworks/CellChat@88c2e13) P circlize 0.4.16 2024-02-20 [?] RSPM P cli 3.6.3 2024-06-21 [?] RSPM P clue 0.3-65 2023-09-23 [?] RSPM P cluster 2.1.6 2023-12-01 [?] CRAN (R 4.3.1) P coda 0.19-4.1 2024-01-31 [?] RSPM P codetools 0.2-19 2023-02-01 [?] CRAN (R 4.3.2) P colorspace 2.1-0 2023-01-23 [?] RSPM P ComplexHeatmap 2.18.0 2023-10-26 [?] Bioconductor P cowplot 1.1.3 2024-01-22 [?] RSPM P crayon 1.5.3 2024-06-20 [?] RSPM P devtools 2.4.5 2022-10-11 [?] RSPM P digest 0.6.36 2024-06-23 [?] RSPM P doParallel 1.0.17 2022-02-07 [?] RSPM P dplyr * 1.1.4 2023-11-17 [?] RSPM P ellipsis 0.3.2 2021-04-29 [?] RSPM P evaluate 0.24.0 2024-06-10 [?] RSPM P fansi 1.0.6 2023-12-08 [?] RSPM P farver 2.1.2 2024-05-13 [?] RSPM P fastmap 1.2.0 2024-05-15 [?] RSPM P FNN 1.1.4 2024-01-12 [?] RSPM P foreach 1.5.2 2022-02-02 [?] RSPM P fs 1.6.4 2024-04-25 [?] RSPM P future 1.33.2 2024-03-26 [?] RSPM P future.apply 1.11.2 2024-03-28 [?] RSPM P generics 0.1.3 2022-07-05 [?] RSPM P GetoptLong 1.0.5 2020-12-15 [?] RSPM P ggalluvial 0.12.5 2023-02-22 [?] RSPM P ggnetwork 0.5.13 2024-02-14 [?] RSPM P ggplot2 * 3.5.1 2024-04-23 [?] RSPM P ggpubr 0.6.0 2023-02-10 [?] RSPM P ggrepel 0.9.5 2024-01-10 [?] RSPM P ggsignif 0.6.4 2022-10-13 [?] RSPM P GlobalOptions 0.1.2 2020-06-10 [?] RSPM P globals 0.16.3 2024-03-08 [?] RSPM P glue 1.7.0 2024-01-09 [?] RSPM P gridBase 0.4-7 2014-02-24 [?] RSPM P gtable 0.3.5 2024-04-22 [?] RSPM P htmltools 0.5.8.1 2024-04-04 [?] RSPM P htmlwidgets 1.6.4 2023-12-06 [?] RSPM P httpuv 1.6.15 2024-03-26 [?] RSPM P igraph * 2.0.3 2024-03-13 [?] RSPM P IRanges 2.36.0 2023-10-26 [?] Bioconductor P irlba 2.3.5.1 2022-10-03 [?] RSPM P iterators 1.0.14 2022-02-05 [?] RSPM P jquerylib 0.1.4 2021-04-26 [?] RSPM P jsonlite 1.8.8 2023-12-04 [?] RSPM P knitr 1.48 2024-07-07 [?] RSPM P labeling 0.4.3 2023-08-29 [?] RSPM P later 1.3.2 2023-12-06 [?] RSPM P lattice 0.22-5 2023-10-24 [?] CRAN (R 4.3.1) P lifecycle 1.0.4 2023-11-07 [?] RSPM P listenv 0.9.1 2024-01-29 [?] RSPM P magrittr 2.0.3 2022-03-30 [?] RSPM P Matrix 1.6-5 2024-01-11 [?] CRAN (R 4.3.1) P matrixStats 1.3.0 2024-04-11 [?] RSPM P memoise 2.0.1 2021-11-26 [?] RSPM P mime 0.12 2021-09-28 [?] RSPM P miniUI 0.1.1.1 2018-05-18 [?] RSPM P munsell 0.5.1 2024-04-01 [?] RSPM P network 1.18.2 2023-12-05 [?] RSPM P NMF 0.27 2024-02-08 [?] RSPM P parallelly 1.37.1 2024-02-29 [?] RSPM P patchwork 1.2.0 2024-01-08 [?] RSPM P pbapply 1.7-2 2023-06-27 [?] RSPM P pillar 1.9.0 2023-03-22 [?] RSPM P pkgbuild 1.4.4 2024-03-17 [?] RSPM P pkgconfig 2.0.3 2019-09-22 [?] RSPM P pkgload 1.4.0 2024-06-28 [?] RSPM P plyr 1.8.9 2023-10-02 [?] RSPM P png 0.1-8 2022-11-29 [?] RSPM P profvis 0.3.8 2023-05-02 [?] RSPM P promises 1.3.0 2024-04-05 [?] RSPM P purrr 1.0.2 2023-08-10 [?] RSPM P R6 2.5.1 2021-08-19 [?] RSPM P RColorBrewer 1.1-3 2022-04-03 [?] RSPM P Rcpp 1.0.12 2024-01-09 [?] RSPM P registry 0.5-1 2019-03-05 [?] RSPM P remotes 2.5.0 2024-03-17 [?] RSPM renv 1.0.5 2024-02-29 [1] CRAN (R 4.3.1) P reshape2 1.4.4 2020-04-09 [?] RSPM P reticulate 1.38.0 2024-06-19 [?] RSPM P rjson 0.2.21 2022-01-09 [?] RSPM P rlang 1.1.4 2024-06-04 [?] RSPM P rmarkdown 2.27 2024-05-17 [?] RSPM P rngtools 1.5.2 2021-09-20 [?] RSPM P RSpectra 0.16-1 2022-04-24 [?] RSPM P rstatix 0.7.2 2023-02-01 [?] RSPM P S4Vectors 0.40.2 2023-11-25 [?] Bioconduc~ P sass 0.4.9 2024-03-15 [?] RSPM P scales 1.3.0 2023-11-28 [?] RSPM P sessioninfo 1.2.2 2021-12-06 [?] RSPM P shape 1.4.6.1 2024-02-23 [?] RSPM P shiny 1.8.1.1 2024-04-02 [?] RSPM P sna 2.7-2 2023-12-06 [?] RSPM P statnet.common 4.9.0 2023-05-24 [?] RSPM P stringi 1.8.4 2024-05-06 [?] RSPM P stringr 1.5.1 2023-11-14 [?] RSPM P svglite 2.1.3 2023-12-08 [?] RSPM P systemfonts 1.1.0 2024-05-15 [?] RSPM P tibble 3.2.1 2023-03-20 [?] RSPM P tidyr 1.3.1 2024-01-24 [?] RSPM P tidyselect 1.2.1 2024-03-11 [?] RSPM P urlchecker 1.0.1 2021-11-30 [?] RSPM P usethis 2.2.3 2024-02-19 [?] RSPM P utf8 1.2.4 2023-10-22 [?] RSPM P vctrs 0.6.5 2023-12-01 [?] RSPM P withr 3.0.0 2024-01-16 [?] RSPM P xfun 0.45 2024-06-16 [?] RSPM P xtable 1.8-4 2019-04-21 [?] RSPM P yaml 2.3.9 2024-07-05 [?] RSPM