sqjin / CellChat

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

Stop commands in case of 0 results instead of returning a valid (empty) object #243

Open stemangiola opened 3 years ago

stemangiola commented 3 years ago

The code is quite full of

stop("No significant signaling interactions are inferred based on the input!")

in case that no results are present. This is very detrimental to any workflow. In case results are present or not any internal and external function should return the same type of object with consistent formatting.

For example, if results are present

tibble:
column A | column B
foo           | foo
foo           | foo

If no results are present

tibble <0 rows>
column A | column B
sessionInfo()
R version 4.1.0 (2021-05-18)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: CentOS Linux 7 (Core)

Matrix products: default
BLAS:   /stornext/System/data/apps/R/R-4.1.0/lib64/R/lib/libRblas.so
LAPACK: /stornext/System/data/apps/R/R-4.1.0/lib64/R/lib/libRlapack.so

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       

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

other attached packages:
 [1] CellChat_1.1.0      Biobase_2.52.0      BiocGenerics_0.38.0 igraph_1.2.6        tidyseurat_0.2.3    GGally_2.1.1        patchwork_1.1.1    
 [8] forcats_0.5.1       stringr_1.4.0       dplyr_1.0.6         purrr_0.3.4         readr_1.4.0         tidyr_1.1.3         tibble_3.1.2       
[15] ggplot2_3.3.3       tidyverse_1.3.1     Seurat_4.0.2        SeuratObject_4.0.1 

loaded via a namespace (and not attached):
  [1] rappdirs_0.3.3                scattermore_0.7               widyr_0.1.3                   coda_0.19-4                  
  [5] pkgmaker_0.32.2               bit64_4.0.5                   irlba_2.3.3                   DelayedArray_0.18.0          
  [9] data.table_1.14.0             rpart_4.1-15                  inline_0.3.19                 KEGGREST_1.32.0              
 [13] RCurl_1.98-1.3                doParallel_1.0.16             generics_0.1.0                ScaledMatrix_1.0.0           
 [17] preprocessCore_1.54.0         callr_3.7.0                   cowplot_1.1.1                 RSQLite_2.2.7                
 [21] usethis_2.0.1                 RANN_2.6.1                    future_1.21.0                 bit_4.0.4                    
 [25] spatstat.data_2.1-0           xml2_1.3.2                    lubridate_1.7.10              httpuv_1.6.1                 
 [29] StanHeaders_2.26.1            SummarizedExperiment_1.22.0   assertthat_0.2.1              viridis_0.6.1                
 [33] celldex_1.2.0                 hms_1.1.0                     promises_1.2.0.1              fansi_0.5.0                  
 [37] progress_1.2.2                dendextend_1.15.1             dbplyr_2.1.1                  readxl_1.3.1                 
 [41] DBI_1.1.1                     htmlwidgets_1.5.3             reshape_0.8.8                 spatstat.geom_2.1-0          
 [45] stats4_4.1.0                  ellipsis_0.3.2                RSpectra_0.16-0               backports_1.2.1              
 [49] V8_3.4.2                      gridBase_0.4-7                tidyHeatmap_1.2.2             sparseMatrixStats_1.4.0      
 [53] RcppParallel_5.1.4            deldir_0.2-10                 MatrixGenerics_1.4.0          vctrs_0.3.8                  
 [57] SingleCellExperiment_1.14.1   ggalluvial_0.12.3             remotes_2.4.0                 Cairo_1.5-12.2               
 [61] ROCR_1.0-11                   abind_1.4-5                   cachem_1.0.5                  withr_2.4.2                  
 [65] sctransform_0.3.2             sna_2.6                       prettyunits_1.1.1             dittoSeq_1.4.1               
 [69] goftest_1.2-2                 svglite_2.0.0                 cluster_2.1.2                 ExperimentHub_2.0.0          
 [73] lazyeval_0.2.2                crayon_1.4.1                  pkgconfig_2.0.3               labeling_0.4.2               
 [77] GenomeInfoDb_1.28.0           nlme_3.1-152                  pkgload_1.2.1                 tidybulk_1.5.1               
 [81] devtools_2.4.1                rlang_0.4.11                  globals_0.14.0                lifecycle_1.0.0              
 [85] miniUI_0.1.1.1                filelock_1.0.2                registry_0.5-1                BiocFileCache_2.0.0          
 [89] rsvd_1.0.5                    modelr_0.1.8                  AnnotationHub_3.0.0           cellranger_1.1.0             
 [93] rprojroot_2.0.2               polyclip_1.10-0               matrixStats_0.59.0            lmtest_0.9-38                
 [97] rngtools_1.5                  Matrix_1.3-4                  loo_2.4.1                     zoo_1.8-9                    
[101] nanny_0.1.8                   reprex_2.0.0                  SingleR_1.6.1                 ggridges_0.5.3               
[105] GlobalOptions_0.1.2           processx_3.5.2                pheatmap_1.0.12               png_0.1-7                    
[109] viridisLite_0.4.0             rjson_0.2.20                  bitops_1.0-7                  KernSmooth_2.23-18           
[113] Biostrings_2.60.0             DelayedMatrixStats_1.14.0     blob_1.2.1                    shape_1.4.6                  
[117] parallelly_1.25.0             S4Vectors_0.30.0              beachmat_2.8.0                scales_1.1.1                 
[121] memoise_2.0.0                 magrittr_2.0.1                plyr_1.8.6                    ica_1.0-2                    
[125] zlibbioc_1.38.0               compiler_4.1.0                RColorBrewer_1.1-2            clue_0.3-59                  
[129] fitdistrplus_1.1-5            cli_2.5.0                     XVector_0.32.0                listenv_0.8.0                
[133] pbapply_1.4-3                 ps_1.6.0                      MASS_7.3-54                   mgcv_1.8-36                  
[137] tidyselect_1.1.1              stringi_1.6.2                 gg.gap_1.3                    yaml_2.2.1                   
[141] BiocSingular_1.8.0            ggrepel_0.9.1                 grid_4.1.0                    tools_4.1.0                  
[145] future.apply_1.7.0            circlize_0.4.12               rstudioapi_0.13               foreach_1.5.1                
[149] gridExtra_2.3                 farver_2.1.0                  Rtsne_0.15                    BiocManager_1.30.15          
[153] digest_0.6.27                 FNN_1.1.3                     shiny_1.6.0                   Rcpp_1.0.6                   
[157] GenomicRanges_1.44.0          broom_0.7.6                   BiocVersion_3.13.1            later_1.2.0                  
[161] RcppAnnoy_0.0.18              AnnotationDbi_1.54.0          httr_1.4.2                    ComplexHeatmap_2.8.0         
[165] colorspace_2.0-1              rvest_1.0.0                   fs_1.5.0                      tensor_1.5                   
[169] reticulate_1.20               IRanges_2.26.0                splines_4.1.0                 uwot_0.1.10                  
[173] spatstat.utils_2.1-0          plotly_4.9.3                  sessioninfo_1.1.1             systemfonts_1.0.2            
[177] xtable_1.8-4                  jsonlite_1.7.2                rle_0.9.2                     rstan_2.26.1                 
[181] testthat_3.0.2                R6_2.5.0                      pillar_1.6.1                  htmltools_0.5.1.1            
[185] mime_0.10                     NMF_0.23.0                    BiocParallel_1.26.0           glue_1.4.2                   
[189] fastmap_1.1.0                 BiocNeighbors_1.10.0          interactiveDisplayBase_1.30.0 codetools_0.2-18             
[193] pkgbuild_1.2.0                utf8_1.2.1                    lattice_0.20-44               spatstat.sparse_2.0-0        
[197] network_1.16.1                curl_4.3.1                    leiden_0.3.8                  gtools_3.8.2                 
[201] survival_3.2-11               statnet.common_4.4.1          desc_1.3.0                    munsell_0.5.0                
[205] GetoptLong_1.0.5              GenomeInfoDbData_1.2.6        iterators_1.0.13              haven_2.4.1                  
[209] reshape2_1.4.4                gtable_0.3.0                  spatstat.core_2.1-2    
sqjin commented 3 years ago

@stemangiola Thanks for your suggestion. I think these stop commands are mostly in the visualization functions. In these functions, we only generate a plot without returning the data. Thus I think a simple stop is fine.