saeyslab / nichenetr

NicheNet: predict active ligand-target links between interacting cells
490 stars 117 forks source link

error when run calculate_niche_de() #145

Closed joe-jhou2 closed 2 years ago

joe-jhou2 commented 2 years ago

Follow this vignette (https://github.com/saeyslab/nichenetr/blob/master/vignettes/differential_nichenet.md) and apply on my data, when run calculate_niche_de() to calculate ligands only, has this error:

DE_sender = calculate_niche_de(seurat_obj = Lesion.combined.SCT %>% subset(features = lr_network$ligand %>% intersect(rownames(Lesion.combined.SCT))), niches = niches, type = "sender", assay_oi = "integrated")

Error in filter(): ! Problem while computing ..1 = sender == sender_other_niche_oi & .... ✖ Input ..1 must be of size 13 or 1, not size 0. Run rlang::last_error() to see where the error occurred.

I do not quite sure if this chunk is correct "lr_network$ligand %>% intersect(rownames(Lesion.combined.SCT)))". For me, intersect() is missing argument "y". I don't if it's the reason of this error.

sessionInfo() R version 4.2.0 (2022-04-22) Platform: x86_64-apple-darwin17.0 (64-bit) Running under: macOS Big Sur/Monterey 10.16

Matrix products: default LAPACK: /Library/Frameworks/R.framework/Versions/4.2/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] grid stats4 stats graphics grDevices utils datasets methods base

other attached packages: [1] nichenetr_1.1.0 UCell_2.0.0 BiocParallel_1.30.2 rlang_1.0.2 xlsx_0.6.5 RColorBrewer_1.1-3
[7] ggrepel_0.9.1 forcats_0.5.1 stringr_1.4.0 purrr_0.3.4 readr_2.1.2 tidyr_1.2.0
[13] tibble_3.1.7 tidyverse_1.3.1 dplyr_1.0.9 sp_1.4-7 SeuratObject_4.1.0 Seurat_4.1.1
[19] scater_1.24.0 ggplot2_3.3.6 scuttle_1.6.2 scRNAseq_2.10.0 celldex_1.6.0 SingleR_1.10.0
[25] SingleCellExperiment_1.18.0 SummarizedExperiment_1.26.1 Biobase_2.56.0 GenomicRanges_1.48.0 GenomeInfoDb_1.32.2 IRanges_2.30.0
[31] S4Vectors_0.34.0 BiocGenerics_0.42.0 MatrixGenerics_1.8.0 matrixStats_0.62.0

loaded via a namespace (and not attached): [1] rsvd_1.0.5 Hmisc_4.7-0 ica_1.0-2 class_7.3-20 ps_1.7.0
[6] Rsamtools_2.12.0 foreach_1.5.2 lmtest_0.9-40 rprojroot_2.0.3 crayon_1.5.1
[11] spatstat.core_2.4-2 MASS_7.3-57 nlme_3.1-157 backports_1.4.1 reprex_2.0.1
[16] XVector_0.36.0 caret_6.0-92 ROCR_1.0-11 readxl_1.4.0 irlba_2.3.5
[21] callr_3.7.0 limma_3.52.1 filelock_1.0.2 rjson_0.2.21 bit64_4.0.5
[26] glue_1.6.2 pheatmap_1.0.12 sctransform_0.3.3 parallel_4.2.0 processx_3.5.3
[31] vipor_0.4.5 spatstat.sparse_2.1-1 AnnotationDbi_1.58.0 spatstat.geom_2.4-0 haven_2.5.0
[36] tidyselect_1.1.2 usethis_2.1.5 fitdistrplus_1.1-8 XML_3.99-0.9 zoo_1.8-10
[41] GenomicAlignments_1.32.0 xtable_1.8-4 magrittr_2.0.3 cli_3.3.0 zlibbioc_1.42.0
[46] rstudioapi_0.13 miniUI_0.1.1.1 rpart_4.1.16 ensembldb_2.20.1 tinytex_0.39
[51] shiny_1.7.1 BiocSingular_1.12.0 xfun_0.31 clue_0.3-60 pkgbuild_1.3.1
[56] cluster_2.1.3 caTools_1.18.2 KEGGREST_1.36.0 interactiveDisplayBase_1.34.0 listenv_0.8.0
[61] xlsxjars_0.6.1 Biostrings_2.64.0 png_0.1-7 future_1.25.0 ipred_0.9-12
[66] withr_2.5.0 bitops_1.0-7 plyr_1.8.7 cellranger_1.1.0 AnnotationFilter_1.20.0
[71] hardhat_0.2.0 e1071_1.7-9 pROC_1.18.0 pillar_1.7.0 GlobalOptions_0.1.2
[76] cachem_1.0.6 GenomicFeatures_1.48.1 fs_1.5.2 GetoptLong_1.0.5 DelayedMatrixStats_1.18.0
[81] vctrs_0.4.1 ellipsis_0.3.2 generics_0.1.2 lava_1.6.10 devtools_2.4.3
[86] tools_4.2.0 foreign_0.8-82 beeswarm_0.4.0 munsell_0.5.0 proxy_0.4-26
[91] DelayedArray_0.22.0 fastmap_1.1.0 compiler_4.2.0 pkgload_1.2.4 abind_1.4-5
[96] httpuv_1.6.5 rtracklayer_1.56.0 ExperimentHub_2.4.0 sessioninfo_1.2.2 plotly_4.10.0
[101] rgeos_0.5-9 rJava_1.0-6 GenomeInfoDbData_1.2.8 prodlim_2019.11.13 gridExtra_2.3
[106] lattice_0.20-45 deldir_1.0-6 visNetwork_2.1.0 utf8_1.2.2 later_1.3.0
[111] BiocFileCache_2.4.0 recipes_0.2.0 jsonlite_1.8.0 scales_1.2.0 ScaledMatrix_1.4.0
[116] pbapply_1.5-0 sparseMatrixStats_1.8.0 lazyeval_0.2.2 promises_1.2.0.1 doParallel_1.0.17
[121] latticeExtra_0.6-29 goftest_1.2-3 checkmate_2.1.0 spatstat.utils_2.3-1 reticulate_1.25
[126] cowplot_1.1.1 Rtsne_0.16 uwot_0.1.11 igraph_1.3.1 survival_3.3-1
[131] yaml_2.3.5 htmltools_0.5.2 memoise_2.0.1 BiocIO_1.6.0 viridisLite_0.4.0
[136] digest_0.6.29 assertthat_0.2.1 mime_0.12 rappdirs_0.3.3 RSQLite_2.2.14
[141] future.apply_1.9.0 remotes_2.4.2 data.table_1.14.2 blob_1.2.3 DiagrammeR_1.0.9
[146] Formula_1.2-4 splines_4.2.0 labeling_0.4.2 AnnotationHub_3.4.0 ProtGenerics_1.28.0
[151] RCurl_1.98-1.6 broom_0.8.0 hms_1.1.1 modelr_0.1.8 base64enc_0.1-3
[156] colorspace_2.0-3 BiocManager_1.30.17 ggbeeswarm_0.6.0 shape_1.4.6 nnet_7.3-17
[161] Rcpp_1.0.8.3 RANN_2.6.1 circlize_0.4.15 fansi_1.0.3 tzdb_0.3.0
[166] brio_1.1.3 parallelly_1.31.1 ModelMetrics_1.2.2.2 R6_2.5.1 ggridges_0.5.3
[171] lifecycle_1.0.1 curl_4.3.2 leiden_0.4.2 testthat_3.1.4 Matrix_1.4-1
[176] desc_1.4.1 RcppAnnoy_0.0.19 iterators_1.0.14 gower_1.0.0 htmlwidgets_1.5.4
[181] beachmat_2.12.0 polyclip_1.10-0 biomaRt_2.52.0 rvest_1.0.2 ComplexHeatmap_2.12.0
[186] mgcv_1.8-40 globals_0.15.0 htmlTable_2.4.0 patchwork_1.1.1 spatstat.random_2.2-0
[191] progressr_0.10.0 codetools_0.2-18 lubridate_1.8.0 randomForest_4.7-1 prettyunits_1.1.1
[196] dbplyr_2.1.1 gtable_0.3.0 DBI_1.1.2 tensor_1.5 httr_1.4.3
[201] KernSmooth_2.23-20 stringi_1.7.6 progress_1.2.2 reshape2_1.4.4 farver_2.1.0
[206] viridis_0.6.2 fdrtool_1.2.17 timeDate_3043.102 xml2_1.3.3 BiocNeighbors_1.14.0
[211] restfulr_0.0.13 scattermore_0.8 BiocVersion_3.15.2 bit_4.0.4 jpeg_0.1-9
[216] spatstat.data_2.2-0 pkgconfig_2.0.3 knitr_1.39

browaeysrobin commented 2 years ago

Hi @mimisikai

if "intersect() is missing argument "y", this is likely the reason for the error. It means there is no overlap between the ligand names of the lr_network and the genes in your dataset. Can you check out the reason for this? (did you define the right species upfront etc)

joe-jhou2 commented 2 years ago

I meant, your code in the vignette missing argument "y". Screen Shot 2022-05-26 at 11 45 08 AM

browaeysrobin commented 2 years ago

Hi @mimisikai

it does not miss "y" because of the piping: a %>% intersect(b) is the same as intersect(a,b)

About your error: without seeing how you defined your niches etc, it's very hard to say what went wrong. But I see that you use the integrated assay as assay to calculate DE. I would recommend against using this since corrected, integrated, expression values should not be used for DE analysis.

browaeysrobin commented 2 years ago

Hi @mimisikai

Any update on this?

sunnyzwu commented 1 year ago

I had the exact same error here, and figured out that the issue is related to the code likely when generating the sender_vs_sender_tbl, which doesn't allow the same sender cell types to be computed in different niches. Means you probably have to make separate outputs yourself for the calculate_niche_de if you want to do this comparison.

niches = list( "niche1" = list( "sender" = c("Fibroblasts 1", "Fibroblasts 2", "Fibroblasts 3"), "receiver" = ("T cells 1")), "niche2" = list( "sender" = c("Fibroblasts 1", "Fibroblasts 2", "Fibroblasts 3"), "receiver" = ("T cells 2")), "niche3" = list( "sender" = c("Fibroblasts 1", "Fibroblasts 2", "Fibroblasts 3"), "receiver" = ("T cells 3")) )

Error in filter(): ℹ In argument: sender == sender_other_niche_oi & .... Caused by error: ! ..1 must be of size 1, not size 0.

niches = list( "niche1" = list( "sender" = c("Fibroblasts 1"), "receiver" = ("T cells 1")), "niche2" = list( "sender" = c("Fibroblasts 2"), "receiver" = ("T cells 2")), "niche3" = list( "sender" = c("Fibroblasts 3"), "receiver" = ("T cells 3")) )

No error