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
195 stars 21 forks source link

Error in netVisual_aggregate in spatial cellchat data #155

Closed Jaimelan closed 1 week ago

Jaimelan commented 4 weeks ago

So I have been receiving the following error when trying to plot a cellchat object computed from a Seurat object from spatial transcriptomics data (Visium 10x):

Error in names(x) <- value : 'names' attribute [4] must be the same length as the vector [2]

I am working with Cellchat v2.1.2 and Seurat v5.0.2 and the traceback of the error is:

4. `colnames<-`(`*tmp*`, value = c("X1", "Y1", "X2", "Y2")) at visualization.R#1554

3. netVisual_spatial(prob.sum, coordinates = coordinates, meta = meta.t,
sample.use = sample.use, alpha.image = alpha.image, point.size = point.size,
sources.use = sources.use, targets.use = targets.use, idents.use = idents.use,
remove.isolate = remove.isolate, top = top, color.use = color.use, ... at visualization.R#599

2. netVisual_aggregate(object = cellchat, signaling = pathways.show,
signaling.name = pathways.show, layout = "spatial", edge.width.max = 2,
alpha.image = 0.2, vertex.weight = "incoming", vertex.size.max = 3,
vertex.label.cex = 3.5)

1. ccc_spat_plt_in(cellchat, pathways.show)

Where the function in 1 receives a cellchat object and the name of the pathway to plot in the spatial plot of communications.

I am not sure what is failing in the process, the objects were created following the available tutorial for spatial published in this repo, and I am struggling to identify the origin of the 4 attributes expected by the function in `colnames<-(*tmp*, value = c("X1", "Y1", "X2", "Y2")) at visualization.R#1554`

Thank you for your work developing this package and for your attention.

Best, Jaime

Jaimelan commented 4 weeks ago

Also, I attach the sessionInfo() output:

R version 4.3.2 (2023-10-31)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 22.04.4 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.10.0 
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.10.0

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=es_ES.UTF-8        LC_COLLATE=en_US.UTF-8     LC_MONETARY=es_ES.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=es_ES.UTF-8       LC_NAME=C                  LC_ADDRESS=C               LC_TELEPHONE=C             LC_MEASUREMENT=es_ES.UTF-8 LC_IDENTIFICATION=C       

time zone: Europe/Madrid
tzcode source: system (glibc)

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

other attached packages:
 [1] SeuratDisk_0.0.0.9021 Seurat_5.0.2          SeuratObject_5.0.1    sp_2.1-3              patchwork_1.2.0       CellChat_2.1.2        Biobase_2.62.0        BiocGenerics_0.48.1  
 [9] ggplot2_3.5.0         igraph_2.0.2          dplyr_1.1.4          

loaded via a namespace (and not attached):
  [1] RcppAnnoy_0.0.22       splines_4.3.2          later_1.3.2            tibble_3.2.1           polyclip_1.10-6        ggnetwork_0.5.13       fastDummies_1.7.3      lifecycle_1.0.4       
  [9] rstatix_0.7.2          doParallel_1.0.17      globals_0.16.3         lattice_0.22-5         hdf5r_1.3.10           MASS_7.3-60.0.1        backports_1.4.1        magrittr_2.0.3        
 [17] plotly_4.10.4          sass_0.4.8             jquerylib_0.1.4        httpuv_1.6.14          NMF_0.27               sctransform_0.4.1      spam_2.10-0            spatstat.sparse_3.0-3 
 [25] reticulate_1.35.0      cowplot_1.1.3          pbapply_1.7-2          RColorBrewer_1.1-3     abind_1.4-5            Rtsne_0.17             purrr_1.0.2            presto_1.0.0          
 [33] circlize_0.4.16        IRanges_2.36.0         S4Vectors_0.40.2       ggrepel_0.9.5          irlba_2.3.5.1          listenv_0.9.1          spatstat.utils_3.0-4   goftest_1.2-3         
 [41] RSpectra_0.16-1        spatstat.random_3.2-3  fitdistrplus_1.1-11    parallelly_1.37.1      svglite_2.1.3          leiden_0.4.3.1         codetools_0.2-19       tidyselect_1.2.0      
 [49] shape_1.4.6.1          matrixStats_1.2.0      stats4_4.3.2           spatstat.explore_3.2-6 jsonlite_1.8.8         GetoptLong_1.0.5       BiocNeighbors_1.20.2   ellipsis_0.3.2        
 [57] progressr_0.14.0       ggridges_0.5.6         ggalluvial_0.12.5      survival_3.5-7         iterators_1.0.14       systemfonts_1.0.6      foreach_1.5.2          tools_4.3.2           
 [65] sna_2.7-2              ica_1.0-3              Rcpp_1.0.12            glue_1.7.0             gridExtra_2.3          withr_3.0.0            BiocManager_1.30.22    fastmap_1.1.1         
 [73] fansi_1.0.6            digest_0.6.34          R6_2.5.1               mime_0.12              colorspace_2.1-0       scattermore_1.2        tensor_1.5             spatstat.data_3.0-4   
 [81] utf8_1.2.4             tidyr_1.3.1            generics_0.1.3         renv_1.0.5             data.table_1.15.2      FNN_1.1.4              httr_1.4.7             htmlwidgets_1.6.4     
 [89] uwot_0.1.16            pkgconfig_2.0.3        gtable_0.3.4           registry_0.5-1         ComplexHeatmap_2.18.0  lmtest_0.9-40          htmltools_0.5.7        carData_3.0-5         
 [97] dotCall64_1.1-1        clue_0.3-65            scales_1.3.0           tidyverse_2.0.0        png_0.1-8              rstudioapi_0.15.0      reshape2_1.4.4         rjson_0.2.21          
[105] coda_0.19-4.1          statnet.common_4.9.0   nlme_3.1-163           cachem_1.0.8           zoo_1.8-12             GlobalOptions_0.1.2    stringr_1.5.1          KernSmooth_2.23-22    
[113] parallel_4.3.2         miniUI_0.1.1.1         pillar_1.9.0           grid_4.3.2             vctrs_0.6.5            RANN_2.6.1             promises_1.2.1         ggpubr_0.6.0          
[121] car_3.1-2              xtable_1.8-4           cluster_2.1.6          cli_3.6.2              compiler_4.3.2         rlang_1.1.3            crayon_1.5.2           rngtools_1.5.2        
[129] future.apply_1.11.1    ggsignif_0.6.4         plyr_1.8.9             stringi_1.8.3          viridisLite_0.4.2      network_1.18.2         deldir_2.0-4           gridBase_0.4-7        
[137] BiocParallel_1.36.0    munsell_0.5.0          lazyeval_0.2.2         spatstat.geom_3.2-9    Matrix_1.6-5           RcppHNSW_0.6.0         bit64_4.0.5            future_1.33.1         
[145] shiny_1.8.0            ROCR_1.0-11            broom_1.0.5            bslib_0.6.1            bit_4.0.5   
```R version 4.3.2 (2023-10-31)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 22.04.4 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.10.0 
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.10.0

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=es_ES.UTF-8        LC_COLLATE=en_US.UTF-8     LC_MONETARY=es_ES.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=es_ES.UTF-8       LC_NAME=C                  LC_ADDRESS=C               LC_TELEPHONE=C             LC_MEASUREMENT=es_ES.UTF-8 LC_IDENTIFICATION=C       

time zone: Europe/Madrid
tzcode source: system (glibc)

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

other attached packages:
 [1] SeuratDisk_0.0.0.9021 Seurat_5.0.2          SeuratObject_5.0.1    sp_2.1-3              patchwork_1.2.0       CellChat_2.1.2        Biobase_2.62.0        BiocGenerics_0.48.1  
 [9] ggplot2_3.5.0         igraph_2.0.2          dplyr_1.1.4          

loaded via a namespace (and not attached):
  [1] RcppAnnoy_0.0.22       splines_4.3.2          later_1.3.2            tibble_3.2.1           polyclip_1.10-6        ggnetwork_0.5.13       fastDummies_1.7.3      lifecycle_1.0.4       
  [9] rstatix_0.7.2          doParallel_1.0.17      globals_0.16.3         lattice_0.22-5         hdf5r_1.3.10           MASS_7.3-60.0.1        backports_1.4.1        magrittr_2.0.3        
 [17] plotly_4.10.4          sass_0.4.8             jquerylib_0.1.4        httpuv_1.6.14          NMF_0.27               sctransform_0.4.1      spam_2.10-0            spatstat.sparse_3.0-3 
 [25] reticulate_1.35.0      cowplot_1.1.3          pbapply_1.7-2          RColorBrewer_1.1-3     abind_1.4-5            Rtsne_0.17             purrr_1.0.2            presto_1.0.0          
 [33] circlize_0.4.16        IRanges_2.36.0         S4Vectors_0.40.2       ggrepel_0.9.5          irlba_2.3.5.1          listenv_0.9.1          spatstat.utils_3.0-4   goftest_1.2-3         
 [41] RSpectra_0.16-1        spatstat.random_3.2-3  fitdistrplus_1.1-11    parallelly_1.37.1      svglite_2.1.3          leiden_0.4.3.1         codetools_0.2-19       tidyselect_1.2.0      
 [49] shape_1.4.6.1          matrixStats_1.2.0      stats4_4.3.2           spatstat.explore_3.2-6 jsonlite_1.8.8         GetoptLong_1.0.5       BiocNeighbors_1.20.2   ellipsis_0.3.2        
 [57] progressr_0.14.0       ggridges_0.5.6         ggalluvial_0.12.5      survival_3.5-7         iterators_1.0.14       systemfonts_1.0.6      foreach_1.5.2          tools_4.3.2           
 [65] sna_2.7-2              ica_1.0-3              Rcpp_1.0.12            glue_1.7.0             gridExtra_2.3          withr_3.0.0            BiocManager_1.30.22    fastmap_1.1.1         
 [73] fansi_1.0.6            digest_0.6.34          R6_2.5.1               mime_0.12              colorspace_2.1-0       scattermore_1.2        tensor_1.5             spatstat.data_3.0-4   
 [81] utf8_1.2.4             tidyr_1.3.1            generics_0.1.3         renv_1.0.5             data.table_1.15.2      FNN_1.1.4              httr_1.4.7             htmlwidgets_1.6.4     
 [89] uwot_0.1.16            pkgconfig_2.0.3        gtable_0.3.4           registry_0.5-1         ComplexHeatmap_2.18.0  lmtest_0.9-40          htmltools_0.5.7        carData_3.0-5         
 [97] dotCall64_1.1-1        clue_0.3-65            scales_1.3.0           tidyverse_2.0.0        png_0.1-8              rstudioapi_0.15.0      reshape2_1.4.4         rjson_0.2.21          
[105] coda_0.19-4.1          statnet.common_4.9.0   nlme_3.1-163           cachem_1.0.8           zoo_1.8-12             GlobalOptions_0.1.2    stringr_1.5.1          KernSmooth_2.23-22    
[113] parallel_4.3.2         miniUI_0.1.1.1         pillar_1.9.0           grid_4.3.2             vctrs_0.6.5            RANN_2.6.1             promises_1.2.1         ggpubr_0.6.0          
[121] car_3.1-2              xtable_1.8-4           cluster_2.1.6          cli_3.6.2              compiler_4.3.2         rlang_1.1.3            crayon_1.5.2           rngtools_1.5.2        
[129] future.apply_1.11.1    ggsignif_0.6.4         plyr_1.8.9             stringi_1.8.3          viridisLite_0.4.2      network_1.18.2         deldir_2.0-4           gridBase_0.4-7        
[137] BiocParallel_1.36.0    munsell_0.5.0          lazyeval_0.2.2         spatstat.geom_3.2-9    Matrix_1.6-5           RcppHNSW_0.6.0         bit64_4.0.5            future_1.33.1         
[145] shiny_1.8.0            ROCR_1.0-11            broom_1.0.5            bslib_0.6.1            bit_4.0.5   
sqjin commented 3 weeks ago

@Jaimelan I feel this issue may be related to the input cell group information. The cell names in cell group labels are not the same with the cell names in the spatial coordinates. You can check this in the cellchat object. Otherwise, you have to run the source codes one by one to figure out the reason.

Jaimelan commented 1 week ago

I checked them to be concordant and it worked just fine. Thanks for the tip and you work with this software!