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

Error in Prob[, , i] <- Pnull #147

Closed anchormok closed 3 years ago

anchormok commented 3 years ago

Dear Professor,

Thanks for your development of this excellent package. When I performed the function "computeCommunProb", there is an error named "Error in Prob[, , i] <- Pnull, The replaced item is not a multiple of the length of the replacement value".

And my code was as follows:

data.input <- seob@assays$RNA@counts meta = seob@meta.data cellchat <- createCellChat(object = data.input, meta = meta, group.by = "celltype") cellchat <- addMeta(cellchat, meta = meta) cellchat <- setIdent(cellchat, ident.use = "celltype") levels(cellchat@idents) groupSize <- as.numeric(table(cellchat@idents)) CellChatDB <- CellChatDB.human CellChatDB.use <- subsetDB(CellChatDB, search="Secreted Signaling") cellchat@DB <- CellChatDB.use cellchat <- subsetData(cellchat) cellchat <- identifyOverExpressedGenes(cellchat) cellchat <- identifyOverExpressedInteractions(cellchat) cellchat <- projectData(cellchat, PPI.human) cellchat <- computeCommunProb(cellchat, raw.use = TRUE)

I confirmed that the seurat object was the same as the sample data, and the annotation of celltype was defined as the "idents" of cellchat object.

I am looking forward to your reply. Thanks again!

sqjin commented 3 years ago

@anchormok the input data is not correct and it should be the normalized data. data.input <- seob@assays$RNA@data or cellchat <- createCellChat(object = seob, group.by = "celltype")

chi16 commented 3 years ago

@sqjin i was also troubled in this problem, and my code was as follows:

data.input <- fl@assays$RNA@data meta <- data.frame(celltype =fl$celltype , row.names = names(fl$celltype)) cellchat2 <- createCellChat(object = data.input, meta = meta, group.by = "celltype") CellChatDB.mouse <- CellChatDB.mouse CellChatDB.use <- subsetDB(CellChatDB.mouse, search = "Secreted Signaling") cellchat2@DB <- CellChatDB.use cellchat2 <- subsetData(cellchat2) future::plan("multiprocess", workers = 4) cellchat2 <- identifyOverExpressedGenes(cellchat2) cellchat2 <- identifyOverExpressedInteractions(cellchat2) cellchat2 <- projectData(cellchat2, PPI.mouse) cellchat2 <- computeCommunProb(cellchat2, raw.use = TRUE)

then 'Error in Prob[, , i] <- Pnull' can you help me? thanks a lot!

sqjin commented 3 years ago

@chi16 The codes look fine. Can you check object@data.signaling and unique(object@idents) to see if they look OK?

chi16 commented 3 years ago

@sqjin Got it. The level of idents was wrong. Thanks for your help!

jessicook commented 3 years ago

Hi, I'm having the same issue. I tried the solutions above with no success. The odd thing is, I'm running cellchat on a subset of a seurat object, and the rest of the subsets looks fine. Here is my code:

uw <- subset(om.db, subset = orig.ident == "UW")
cellchat.uw <- createCellChat(object = uw, group.by = "jc_annos")
groupSize <- as.numeric(table(cellchat.uw@idents))
cellchat.uw <- setIdent(cellchat.uw, ident.use = "jc_annos") # set "jc_annos" as default cell identity
levels(cellchat.uw@idents) # show factor levels of the cell labels
groupSize <- as.numeric(table(cellchat.uw@idents)) # number of cells in each cell group
CellChatDB <- CellChatDB.mouse # use CellChatDB.human if running on human data
showDatabaseCategory(CellChatDB)
CellChatDB.use <- CellChatDB
# set the used database in the object
cellchat.uw@DB <- CellChatDB.use
cellchat.uw <- subsetData(cellchat.uw)
cellchat.uw <- identifyOverExpressedGenes(cellchat.uw)
cellchat.uw <- identifyOverExpressedInteractions(cellchat.uw)
cellchat.uw <- projectData(cellchat.uw, PPI.mouse)
cellchat.uw <- computeCommunProb(cellchat.uw, raw.use = TRUE)
|++++++++++++++++++++++++++++++++++++++++++++++++++| 100% elapsed=00s  
  |++++++++++++++++++++++++++++++++++++++++++++++++++| 100% elapsed=10s  
  |++++++++++++++++++++++++++++++++++++++++++++++++++| 100% elapsed=00s  
  |++++++++++++++++++++++++++++++++++++++++++++++++++| 100% elapsed=01s  
Error in Prob[, , i] <- Pnull : 
  number of items to replace is not a multiple of replacement length

session info:

R version 4.0.3 (2020-10-10)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Catalina 10.15.7

Matrix products: default
BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

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

other attached packages:
 [1] doParallel_1.0.16   iterators_1.0.13    foreach_1.5.1       patchwork_1.1.1    
 [5] forcats_0.5.1       stringr_1.4.0       purrr_0.3.4         readr_1.4.0        
 [9] tidyr_1.1.3         tibble_3.1.0        tidyverse_1.3.0     NMF_0.23.0         
[13] cluster_2.1.0       rngtools_1.5        pkgmaker_0.32.2     registry_0.5-1     
[17] CellChat_1.0.0      Biobase_2.50.0      BiocGenerics_0.36.0 ggplot2_3.3.3      
[21] igraph_1.2.6        dplyr_1.0.5         SeuratObject_4.0.0  Seurat_4.0.0       

loaded via a namespace (and not attached):
  [1] utf8_1.2.1                  reticulate_1.18            
  [3] tidyselect_1.1.0            htmlwidgets_1.5.3          
  [5] grid_4.0.3                  Rtsne_0.15                 
  [7] devtools_2.3.2              munsell_0.5.0              
  [9] codetools_0.2-18            ica_1.0-2                  
 [11] future_1.21.0               miniUI_0.1.1.1             
 [13] withr_2.4.1                 colorspace_2.0-0           
 [15] knitr_1.31                  ggalluvial_0.12.3          
 [17] rstudioapi_0.13             stats4_4.0.3               
 [19] ROCR_1.0-11                 tensor_1.5                 
 [21] listenv_0.8.0               labeling_0.4.2             
 [23] MatrixGenerics_1.2.1        GenomeInfoDbData_1.2.4     
 [25] polyclip_1.10-0             farver_2.1.0               
 [27] rprojroot_2.0.2             coda_0.19-4                
 [29] parallelly_1.24.0           vctrs_0.3.6                
 [31] generics_0.1.0              xfun_0.20                  
 [33] R6_2.5.0                    GenomeInfoDb_1.26.2        
 [35] clue_0.3-58                 gg.gap_1.3                 
 [37] cachem_1.0.3                bitops_1.0-6               
 [39] spatstat.utils_2.0-0        DelayedArray_0.16.1        
 [41] assertthat_0.2.1            promises_1.1.1             
 [43] scales_1.1.1                gtable_0.3.0               
 [45] Cairo_1.5-12.2              globals_0.14.0             
 [47] processx_3.4.5              goftest_1.2-2              
 [49] rlang_0.4.10                systemfonts_1.0.1          
 [51] GlobalOptions_0.1.2         splines_4.0.3              
 [53] lazyeval_0.2.2              broom_0.7.4                
 [55] yaml_2.2.1                  reshape2_1.4.4             
 [57] abind_1.4-5                 modelr_0.1.8               
 [59] backports_1.2.1             httpuv_1.5.5               
 [61] usethis_2.0.0               tools_4.0.3                
 [63] gridBase_0.4-7              statnet.common_4.4.1       
 [65] ellipsis_0.3.1              RColorBrewer_1.1-2         
 [67] sessioninfo_1.1.1           ggridges_0.5.3             
 [69] Rcpp_1.0.6                  plyr_1.8.6                 
 [71] zlibbioc_1.36.0             RCurl_1.98-1.2             
 [73] prettyunits_1.1.1           ps_1.5.0                   
 [75] rpart_4.1-15                deldir_0.2-9               
 [77] pbapply_1.4-3               GetoptLong_1.0.5           
 [79] cowplot_1.1.1               S4Vectors_0.28.1           
 [81] zoo_1.8-8                   SummarizedExperiment_1.20.0
 [83] haven_2.3.1                 ggrepel_0.9.1              
 [85] fs_1.5.0                    tinytex_0.29               
 [87] magrittr_2.0.1              data.table_1.13.6          
 [89] RSpectra_0.16-0             sna_2.6                    
 [91] scattermore_0.7             circlize_0.4.13.1001       
 [93] lmtest_0.9-38               reprex_1.0.0               
 [95] RANN_2.6.1                  fitdistrplus_1.1-3         
 [97] matrixStats_0.58.0          pkgload_1.1.0              
 [99] hms_1.0.0                   mime_0.9                   
[101] evaluate_0.14               xtable_1.8-4               
[103] readxl_1.3.1                IRanges_2.24.1             
[105] gridExtra_2.3               shape_1.4.5                
[107] testthat_3.0.1              compiler_4.0.3             
[109] KernSmooth_2.23-18          crayon_1.4.1               
[111] htmltools_0.5.1.1           mgcv_1.8-33                
[113] later_1.1.0.1               lubridate_1.7.9.2          
[115] DBI_1.1.1                   dbplyr_2.1.0               
[117] ComplexHeatmap_2.7.9.1006   MASS_7.3-53                
[119] Matrix_1.3-2                cli_2.3.1                  
[121] GenomicRanges_1.42.0        pkgconfig_2.0.3            
[123] plotly_4.9.3                xml2_1.3.2                 
[125] svglite_2.0.0               XVector_0.30.0             
[127] rvest_0.3.6                 callr_3.5.1                
[129] digest_0.6.27               sctransform_0.3.2          
[131] RcppAnnoy_0.0.18            rle_0.9.2                  
[133] spatstat.data_1.7-0         rmarkdown_2.6              
[135] cellranger_1.1.0            leiden_0.3.7               
[137] uwot_0.1.10                 shiny_1.6.0                
[139] rjson_0.2.20                lifecycle_1.0.0            
[141] nlme_3.1-152                jsonlite_1.7.2             
[143] network_1.16.1              desc_1.2.0                 
[145] viridisLite_0.3.0           fansi_0.4.2                
[147] pillar_1.5.1                lattice_0.20-41            
[149] pkgbuild_1.2.0              fastmap_1.1.0              
[151] httr_1.4.2                  survival_3.2-7             
[153] remotes_2.2.0               glue_1.4.2                 
[155] FNN_1.1.3                   spatstat_1.64-1            
[157] png_0.1-7                   stringi_1.5.3              
[159] memoise_2.0.0               irlba_2.3.3                
[161] future.apply_1.7.0         

object@data.signaling:

1035 x 2404 sparse Matrix of class "dgCMatrix"
   [[ suppressing 35 column names ‘UW_AAACCCACACATGGTT-1’, ‘UW_AAACCCACACATGTTG-1’, ‘UW_AAACCCACATTCGGGC-1’ ... ]]
   [[ suppressing 35 column names ‘UW_AAACCCACACATGGTT-1’, ‘UW_AAACCCACACATGTTG-1’, ‘UW_AAACCCACATTCGGGC-1’ ... ]]

Oprk1   . . . . . . . .  . . . . . . . . . . . . . . . . . . . . . . . . . . . ......
Npbwr1  . . . . . . . .  . . . . . . . . . . . . . . . . . . . . . . . . . . . ......
Il17a   . . . . . . . .  . . . . . . . . . . . . . . . . . . . . . . . . . . . ......
Il17f   . . . . . . . .  . . . . . . . . . . . . . . . . . . . . . . . . . . . ......
Col9a1  . . . . . . . .  . . . . . . . . . . . . . . . . . . . . . . . . . . . ......
Cfc1    . . . . . . . .  . . . . . . . . . . . . . . . . . . . . . . . . . . . ......
Sema4c  4 . . . . 1 1 .  . . . . . . . . 1 . 1 . . . . . 2 1 . 1 . . . . . 1 . ......
Nms     . . . . . . . .  . . . . . . . . . . . . . . . . . . . . . . . . . . . ......
Il1r2   . . . . . . . . 37 . . . . . . 1 . . . . . 2 . . . 4 . . . . . . . . . ......
Il1r1   . . . . . . . .  . . . 2 . . 1 . . . . . . 1 1 . . . . . . . . . . . . ......
Il1rl2  . . . . . . . .  . . . . . . . . . . . . . . . . . . . . . . . . . . . ......
Il1rl1  . . . . . . . .  . . . . . . . . . . . . . . . . . . . . . . . . . . . ......
Il18r1  . . . . . . . .  . . . . . . . . . . . . . . . . . . . . . . . . . . . ......
Il18rap . . . . . . . .  1 . . . . . . . . . . . . . . . . . . . . . . . . . . ......

 ..............................
 ........suppressing 2369 columns and 1007 rows in show(); maybe adjust 'options(max.print= *, width = *)'
 ..............................
   [[ suppressing 35 column names ‘UW_AAACCCACACATGGTT-1’, ‘UW_AAACCCACACATGTTG-1’, ‘UW_AAACCCACATTCGGGC-1’ ... ]]

Pdcd1lg2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ......
Il33     . . . . . . . 2 . . . . . . . . . . . . 1 . . . . 2 . . . . . . . . . ......
Dkk1     . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ......
Fas      2 1 . . . . 1 . . . . . . . 1 1 . . . . . . . . . . . . . . . . . . . ......
Entpd1   3 . . . . 2 . . . . . . . . . . 1 . . . . . 1 . . . . . 1 1 . . . . . ......
Sfrp5    . . . . . . . . . . . . . . . . . . 1 . . . . . . . . . . . . . . . . ......
Wnt8b    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ......
Sema4g   . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ......
Fgf8     . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ......
Ins1     . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ......
Gfra1    . . . . . . . 1 . . . . . . . . . . 1 . . . . . . . . . . 1 . 1 . 1 . ......
Prlhr    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ......
Csf2ra   . . . 3 . . . . 1 . . . . . . . . . . . . . . . . . . . . . . . . . . ......
Ccl21c   . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ......

unique(object@idents):

[1] Endothelium               ECM Int. Fibroblasts 2    M2 Macrophages           
 [4] Translation Fibroblasts 1 ECM Org. Fibroblasts 2    Dendritic Cells          
 [7] Repair Fibroblasts        Activated Endothelium     Signaling Fibroblasts 2  
[10] Translation Fibroblasts 2 ECM Int. Fibroblasts 1    Myofibroblasts           
[13] ECM Org. Fibroblasts 1    T Cells                   Signaling Fibroblasts 1  
[16] Epithelium               
17 Levels: Translation Fibroblasts 1 Translation Fibroblasts 2 ... M2 Macrophages
sqjin commented 3 years ago

@jessicook Two mistakes in your data: 1) The input data should be normalized data instead of count data. 2) The number of levels in object@idents is not the same number of cell groups. You should drop the levels in the factor variable.