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
276 stars 45 forks source link

Error in identifyOverExpressedInteractions() after plan("multisession") - Error in rep(no, length.out = len) : attempt to replicate an object of type 'closure' #93

Open cgoneill opened 7 months ago

cgoneill commented 7 months ago

I noticed an interesting error in identifyOverExpressedInteractions() when attempting to parallelize using future.

> plan("multisession", workers = availableCores()) # with this session, future::availableCores() = 6
> for (i in seq_along(cellchat_list)) {
+   cellchat_list[[i]] <- identifyOverExpressedGenes(cellchat_list[[i]])
+   cellchat_list[[i]] <- identifyOverExpressedInteractions(cellchat_list[[i]])
+ }
Error in rep(no, length.out = len) : 
  attempt to replicate an object of type 'closure'

When I try to run identifyOverExpressedInteractions() outside of the for loop on just one of the four CellChat objects in the list, I get the same error, indicating the issue is not in my iteration scheme.

> cellchat_list[[2]] <- identifyOverExpressedInteractions(cellchat_list[[2]])
Error in rep(no, length.out = len) : 
  attempt to replicate an object of type 'closure'

However, when I change to running in sequential, the function works as intended:

> plan("sequential")
> for (i in seq_along(cellchat_list)) {
+   cellchat_list[[i]] <- identifyOverExpressedGenes(cellchat_list[[i]])
+   cellchat_list[[i]] <- identifyOverExpressedInteractions(cellchat_list[[i]])
+ }
  |++++++++++++++++++++++++++++++++++++++++++++++++++| 100% elapsed=00s  
  |++++++++++++++++++++++++++++++++++++++++++++++++++| 100% elapsed=00s  
  |++++++++++++++++++++++++++++++++++++++++++++++++++| 100% elapsed=01s  
The number of highly variable ligand-receptor pairs used for signaling inference is 2762 
  |++++++++++++++++++++++++++++++++++++++++++++++++++| 100% elapsed=00s  
  |++++++++++++++++++++++++++++++++++++++++++++++++++| 100% elapsed=00s  
  |++++++++++++++++++++++++++++++++++++++++++++++++++| 100% elapsed=02s  
The number of highly variable ligand-receptor pairs used for signaling inference is 2361 
  |++++++++++++++++++++++++++++++++++++++++++++++++++| 100% elapsed=00s  
  |++++++++++++++++++++++++++++++++++++++++++++++++++| 100% elapsed=00s  
  |++++++++++++++++++++++++++++++++++++++++++++++++++| 100% elapsed=01s  
The number of highly variable ligand-receptor pairs used for signaling inference is 2606 
  |++++++++++++++++++++++++++++++++++++++++++++++++++| 100% elapsed=00s  
  |++++++++++++++++++++++++++++++++++++++++++++++++++| 100% elapsed=00s  
  |++++++++++++++++++++++++++++++++++++++++++++++++++| 100% elapsed=01s  
The number of highly variable ligand-receptor pairs used for signaling inference is 2840

I'm able to progress with my analysis, and the runtime was short enough that parallelization wasn't necessary, but I figured this was worth bringing to your attention - others may work with larger individual datasets where not being able to parallelize the function may be more of a concern.

Here is the session information for your use:

```r > sessionInfo() R version 4.3.2 (2023-10-31) Platform: x86_64-pc-linux-gnu (64-bit) Running under: Rocky Linux 8.7 (Green Obsidian) Matrix products: default BLAS/LAPACK: /usr/local/intel/2022.1.2.146/mkl/2022.0.2/lib/intel64/libmkl_rt.so.2; LAPACK version 3.9.0 locale: [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8 LC_MONETARY=en_US.UTF-8 [6] LC_MESSAGES=en_US.UTF-8 LC_PAPER=en_US.UTF-8 LC_NAME=C LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C time zone: America/New_York tzcode source: system (glibc) attached base packages: [1] parallel stats4 stats graphics grDevices utils datasets methods base other attached packages: [1] fgeo.tool_1.2.9 enrichR_3.2 enrichplot_1.22.0 org.Mm.eg.db_3.18.0 AnnotationDbi_1.64.1 [6] clusterProfiler_4.10.0 reshape2_1.4.4 rlang_1.1.3 pheatmap_1.0.12 RColorBrewer_1.1-3 [11] scater_1.30.1 scuttle_1.12.0 tradeSeq_1.16.0 slingshot_2.10.0 TrajectoryUtils_1.10.0 [16] princurve_2.1.6 scProportionTest_0.0.0.9000 SeuratWrappers_0.3.19 clustree_0.5.1 xlsx2dfs_0.1.0 [21] harmony_1.2.0 Rcpp_1.0.12 doMC_1.3.8 doParallel_1.0.17 iterators_1.0.14 [26] foreach_1.5.2 future_1.33.1 parallelly_1.37.1 DoubletFinder_2.0.4 DropletUtils_1.22.0 [31] SingleCellExperiment_1.24.0 SummarizedExperiment_1.32.0 GenomicRanges_1.54.1 GenomeInfoDb_1.38.1 IRanges_2.36.0 [36] S4Vectors_0.40.2 MatrixGenerics_1.14.0 matrixStats_1.2.0 openxlsx_4.2.5.2 cowplot_1.1.3 [41] magrittr_2.0.3 lubridate_1.9.3 forcats_1.0.0 stringr_1.5.1 purrr_1.0.2 [46] readr_2.1.5 tidyr_1.3.1 tibble_3.2.1 tidyverse_2.0.0 Matrix_1.6-5 [51] SoupX_1.6.2 data.table_1.15.0 scCustomize_2.1.2 Seurat_5.0.1 SeuratObject_5.0.1 [56] sp_2.1-3 ggraph_2.1.0 CellChat_2.1.2 synchronicity_1.3.10 bigmemory_4.6.4 [61] Biobase_2.62.0 BiocGenerics_0.48.1 ggplot2_3.5.0 dplyr_1.1.4 igraph_1.6.0 loaded via a namespace (and not attached): [1] R.methodsS3_1.8.2 goftest_1.2-3 Biostrings_2.70.1 HDF5Array_1.30.0 vctrs_0.6.5 [6] spatstat.random_3.2-3 digest_0.6.34 png_0.1-8 shape_1.4.6 registry_0.5-1 [11] ggrepel_0.9.5 deldir_2.0-4 MASS_7.3-60 httpuv_1.6.14 qvalue_2.34.0 [16] withr_3.0.0 ggrastr_1.0.2 ggfun_0.1.3 ggpubr_0.6.0 ellipsis_0.3.2 [21] survival_3.5-7 memoise_2.0.1 ggbeeswarm_0.7.2 gson_0.1.0 janitor_2.2.0 [26] systemfonts_1.0.5 tidytree_0.4.6 zoo_1.8-12 GlobalOptions_0.1.2 pbapply_1.7-2 [31] R.oo_1.25.0 rematch2_2.1.2 KEGGREST_1.42.0 promises_1.2.1 httr_1.4.7 [36] rstatix_0.7.2 globals_0.16.2 fitdistrplus_1.1-11 rhdf5filters_1.14.1 rhdf5_2.46.1 [41] rstudioapi_0.15.0 miniUI_0.1.1.1 generics_0.1.3 DOSE_3.28.2 ggalluvial_0.12.5 [46] curl_5.0.1 zlibbioc_1.48.0 ScaledMatrix_1.10.0 polyclip_1.10-6 GenomeInfoDbData_1.2.11 [51] SparseArray_1.2.3 xtable_1.8-4 S4Arrays_1.2.0 hms_1.1.3 irlba_2.3.5.1 [56] colorspace_2.1-0 ggnetwork_0.5.13 ROCR_1.0-11 reticulate_1.35.0 spatstat.data_3.0-3 [61] lmtest_0.9-40 snakecase_0.11.1 ggtree_3.10.0 later_1.3.2 viridis_0.6.4 [66] lattice_0.22-5 spatstat.geom_3.2-9 NMF_0.27 future.apply_1.11.1 shadowtext_0.1.2 [71] scattermore_1.2 RcppAnnoy_0.0.21 pillar_1.9.0 nlme_3.1-164 sna_2.7-2 [76] gridBase_0.4-7 compiler_4.3.2 beachmat_2.18.0 RSpectra_0.16-1 stringi_1.8.3 [81] tensor_1.5 plyr_1.8.9 crayon_1.5.2 abind_1.4-5 gridGraphics_0.5-1 [86] locfit_1.5-9.8 graphlayouts_1.0.2 bit_4.0.5 fastmatch_1.1-4 codetools_0.2-19 [91] BiocSingular_1.18.0 bslib_0.6.1 paletteer_1.6.0 GetoptLong_1.0.5 plotly_4.10.4 [96] mime_0.12 splines_4.3.2 circlize_0.4.15 fastDummies_1.7.3 sparseMatrixStats_1.14.0 [101] HDO.db_0.99.1 blob_1.2.4 utf8_1.2.4 clue_0.3-65 WriteXLS_6.5.0 [106] fs_1.6.3 listenv_0.9.1 DelayedMatrixStats_1.24.0 ggplotify_0.1.2 ggsignif_0.6.4 [111] statmod_1.5.0 tzdb_0.4.0 svglite_2.1.3 tweenr_2.0.2 pkgconfig_2.0.3 [116] network_1.18.2 tools_4.3.2 cachem_1.0.8 RSQLite_2.3.4 viridisLite_0.4.2 [121] DBI_1.2.1 fastmap_1.1.1 scales_1.3.0 grid_4.3.2 ica_1.0-3 [126] broom_1.0.5 sass_0.4.8 patchwork_1.2.0 coda_0.19-4.1 FNN_1.1.4 [131] BiocManager_1.30.22 ggprism_1.0.4 dotCall64_1.1-1 carData_3.0-5 RANN_2.6.1 [136] farver_2.1.1 mgcv_1.9-1 scatterpie_0.2.1 tidygraph_1.3.0 cli_3.6.2 [141] leiden_0.4.3.1 lifecycle_1.0.4 uwot_0.1.16 presto_1.0.0 backports_1.4.1 [146] BiocParallel_1.36.0 timechange_0.3.0 gtable_0.3.4 rjson_0.2.21 ggridges_0.5.5 [151] progressr_0.14.0 ape_5.7-1 limma_3.58.1 jsonlite_1.8.8 edgeR_4.0.6 [156] RcppHNSW_0.6.0 bitops_1.0-7 bigmemory.sri_0.1.8 bit64_4.0.5 Rtsne_0.17 [161] yulab.utils_0.1.3 spatstat.utils_3.0-4 BiocNeighbors_1.20.2 zip_2.3.0 jquerylib_0.1.4 [166] GOSemSim_2.28.0 dqrng_0.3.2 R.utils_2.12.3 lazyeval_0.2.2 shiny_1.8.0 [171] htmltools_0.5.7 GO.db_3.18.0 sctransform_0.4.1 glue_1.7.0 spam_2.10-0 [176] XVector_0.42.0 RCurl_1.98-1.14 treeio_1.26.0 gridExtra_2.3 R6_2.5.1 [181] labeling_0.4.3 cluster_2.1.6 rngtools_1.5.2 Rhdf5lib_1.24.0 aplot_0.2.2 [186] statnet.common_4.9.0 DelayedArray_0.28.0 tidyselect_1.2.0 vipor_0.4.7 ggforce_0.4.1 [191] car_3.1-2 rsvd_1.0.5 munsell_0.5.0 KernSmooth_2.23-22 htmlwidgets_1.6.4 [196] fgsea_1.28.0 ComplexHeatmap_2.18.0 spatstat.sparse_3.0-3 spatstat.explore_3.2-6 remotes_2.4.2.1 [201] uuid_1.2-0 fansi_1.0.6 beeswarm_0.4.0 ```
cgoneill commented 7 months ago

I also encountered this behavior in computeCommunProb().