sqjin / CellChat

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

Strange Cell labels cannot contain `0`! error #320

Open dmsalsgh97 opened 2 years ago

dmsalsgh97 commented 2 years ago

HI, I used cellChat since last month, using Seurat object. tutorial's code for converting Seurat object to Cellchat object worked well until last week...

data.input <- GetAssayData(seurat_object, assay = "RNA", slot = "data") # normalized data matrix
labels <- Idents(seurat_object)
meta <- data.frame(group = labels, row.names = names(labels)) # create a dataframe of the cell labels

cellchat <- createCellChat(object = data.input, meta = meta, group.by = "labels")

But, When I re-use the code, createCellChat function says an error,

Set cell identities for the new CellChat object
Error in setIdent(object, ident.use = group.by) : 
  Cell labels cannot contain `0`! 

I searched github issue pages and re-installed cellchat but it was not a solution...

In this case, anyone knows or tips the reason for this error?? Thanks,

Here is my sessioninfo()...

> sessionInfo()
R version 3.6.0 (2019-04-26)
Platform: x86_64-redhat-linux-gnu (64-bit)
Running under: CentOS Linux 7 (Core)

Matrix products: default
BLAS/LAPACK: /usr/lib64/R/lib/libRblas.so

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

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

other attached packages:
[1] patchwork_1.1.1     CellChat_1.1.3      bigmemory_4.5.36    Biobase_2.46.0      BiocGenerics_0.32.0 ggplot2_3.3.5      
[7] igraph_1.2.8        dplyr_1.0.7         Seurat_3.1.5       

loaded via a namespace (and not attached):
  [1] circlize_0.4.13       systemfonts_1.0.3     NMF_0.23.0            plyr_1.8.6            lazyeval_0.2.2       
  [6] splines_3.6.0         listenv_0.8.0         usethis_2.0.1         gridBase_0.4-7        digest_0.6.28        
 [11] foreach_1.5.1         htmltools_0.5.2       ggalluvial_0.12.3     fansi_0.5.0           magrittr_2.0.1       
 [16] memoise_2.0.0         cluster_2.1.2         doParallel_1.0.16     ROCR_1.0-11           remotes_2.4.0        
 [21] sna_2.6               ComplexHeatmap_2.11.1 globals_0.14.0        matrixStats_0.61.0    svglite_2.0.0        
 [26] prettyunits_1.1.1     colorspace_2.0-2      ggrepel_0.9.1         callr_3.7.0           crayon_1.4.2         
 [31] jsonlite_1.7.2        bigmemory.sri_0.1.3   survival_3.2-13       zoo_1.8-9             iterators_1.0.13     
 [36] ape_5.5               glue_1.5.0            registry_0.5-1        gtable_0.3.0          leiden_0.3.9         
 [41] GetoptLong_1.0.5      pkgbuild_1.2.0        future.apply_1.8.1    shape_1.4.6           scales_1.1.1         
 [46] DBI_1.1.1             rngtools_1.5.2        Rcpp_1.0.7            viridisLite_0.4.0     xtable_1.8-4         
 [51] clue_0.3-60           reticulate_1.22       rsvd_1.0.3            stats4_3.6.0          tsne_0.1-3           
 [56] htmlwidgets_1.5.4     httr_1.4.2            FNN_1.1.3             RColorBrewer_1.1-2    ellipsis_0.3.2       
 [61] ica_1.0-2             pkgconfig_2.0.3       uwot_0.1.10           utf8_1.2.2            tidyselect_1.1.1     
 [66] rlang_0.4.12          reshape2_1.4.4        munsell_0.5.0         tools_3.6.0           cachem_1.0.6         
 [71] cli_3.1.0             generics_0.1.1        statnet.common_4.5.0  devtools_2.4.2        ggridges_0.5.3       
 [76] stringr_1.4.0         fastmap_1.1.0         processx_3.5.2        fs_1.5.0              fitdistrplus_1.1-5   
 [81] purrr_0.3.4           RANN_2.6.1            pbapply_1.5-0         future_1.23.0         nlme_3.1-153         
 [86] compiler_3.6.0        rstudioapi_0.13       plotly_4.9.4.1        curl_4.3.2            png_0.1-7            
 [91] testthat_3.0.4        tibble_3.1.6          stringi_1.7.5         ps_1.6.0              desc_1.3.0           
 [96] RSpectra_0.16-0       lattice_0.20-45       Matrix_1.3-4          vctrs_0.3.8           pillar_1.6.4         
[101] lifecycle_1.0.1       lmtest_0.9-38         GlobalOptions_0.1.2   RcppAnnoy_0.0.19      data.table_1.14.0    
[106] cowplot_1.1.1         irlba_2.3.3           R6_2.5.1              network_1.17.1        KernSmooth_2.23-20   
[111] gridExtra_2.3         IRanges_2.20.2        parallelly_1.28.1     sessioninfo_1.1.1     codetools_0.2-18     
[116] MASS_7.3-54           assertthat_0.2.1      pkgload_1.2.2         pkgmaker_0.32.2       rprojroot_2.0.2      
[121] rjson_0.2.20          withr_2.4.2           sctransform_0.3.2     S4Vectors_0.24.4      grid_3.6.0           
[126] tidyr_1.1.4           coda_0.19-4           Rtsne_0.15 
margotvanriel commented 2 years ago

Hi,

I encounter the same problem. Any chance you find a solution to this issue?

Thanks. Best, Margot

sqjin commented 2 years ago

@margotvanriel The simple way is to re-name your cluster names. Cell labels cannot contain 0!

margotvanriel commented 2 years ago

Hi,

Thanks for your reply. Yes, I thought that was the issue, but couldn't find a quick solution until I now stumbled upon the RenameIdents function, after which it worked!

ACastanza commented 2 years ago

@margotvanriel The simple way is to re-name your cluster names. Cell labels cannot contain 0!

Unfortunately this isn't really a reasonable solution, numbered clusters should be supported since numbered clustering is the default output of all of the clustering pipelines. Consider that at the point in which you are wanting to run CellChat you might not yet know the specific cell type for a given cluster and therefore wouldn't have had a reason to manually intervene to rename your clusters. Not allowing numerical clustering prevents CellChat from being incorporated into any standardized pipeline. Could we perhaps revisit this issue and change this?

sqjin commented 2 years ago

@ACastanza You can run CellChat on numerical clustering, but it should start from 1,2,... (not 0). I agree that it will be nicer to deal with the case with '0'.

ACastanza commented 2 years ago

Oh, I see, that's still unfortuante, in my experience both seurat and scanpy clustering start with 0 by default no matter which algorithm is used (leiden, louvian, walktrap, etc)

As a workaround, the following code is an okay interim solution:

new_cluster_ids = paste0("C", levels(seurat_object)) names(new_cluster_ids) <- levels(seurat_object) seurat_object <- RenameIdents(seurat_object, new_cluster_ids)