saeyslab / multinichenetr

MultiNicheNet: a flexible framework for differential cell-cell communication analysis from multi-sample multi-condition single-cell transcriptomics data
GNU General Public License v3.0
107 stars 14 forks source link

Error when creating contrasts_oi_simplified when running multi_nichenet_analysis_combined #47

Closed Isabellvse closed 7 months ago

Isabellvse commented 8 months ago

Hello,

I am following this tutorial:

https://github.com/saeyslab/multinichenetr/blob/main/vignettes/threewise_analysis_MISC.md

But I get an error when I run the following function in step 2:

(Note: I have not made any changes to this)

multinichenet_output = multi_nichenet_analysis(sce = sce, celltype_id = celltype_id, sample_id = sample_id, group_id = group_id, lr_network = lr_network, ligand_target_matrix = ligand_target_matrix, contrasts_oi = contrasts_oi, contrast_tbl = contrast_tbl, batches = batches, covariates = covariates, prioritizing_weights = prioritizing_weights, min_cells = min_cells, logFC_threshold = logFC_threshold, p_val_threshold = p_val_threshold, fraction_cutoff = fraction_cutoff, p_val_adj = p_val_adj, empirical_pval = empirical_pval, top_n_target = top_n_target, n.cores = n.cores, sender_receiver_separate = FALSE, verbose = TRUE)

I got the following error:

Error in multi_nichenet_analysis_combined(...) : conditions written in contrasts_oi should be in the contrast column of contrast_tbl column! This is not the case, which can lead to errors downstream.

I looked in the code for multi_nichenet_analysis_combined, and the error occurs when creating the contrasts_oi_simplified

contrasts_oi_simplified = stringr::str_split(contrasts_oi, "'") %>% unlist() %>% unique() %>% stringr::str_split(",") %>% unlist() %>% unique() %>% generics::setdiff(c("", ",")) %>% unlist() %>% unique()

This creates a vector that looks like this: "A-B" " " "C-B", the " " is not removed.

I added this to the generics::setdiff(c("", ",")) so it becomes generics::setdiff(c("", ",", " "))

The full code: contrasts_oi_simplified = stringr::str_split(contrasts_oi, "'") %>% unlist() %>% unique() %>% stringr::str_split(",") %>% unlist() %>% unique() %>% generics::setdiff(c("", ",", " ")) %>% unlist() %>% unique()

and this creates a vector that looks like this: "A-B" "C-B"

And I am now able to run the command.

This is how I created the contrasts_oi and contrast_tbl

`contrasts_oi = c("'A-B', 'C-B'")

contrast_tbl = tibble(contrast = c('A-B', 'C-B'), group = c("A", "C")) ` Is there something I am doing wrong when creating the contrast_oi and contrast_tbl?

Kind Regards, Isabell

Session info:

`R version 4.3.0 (2023-04-21) Platform: x86_64-pc-linux-gnu (64-bit) Running under: Ubuntu 22.04.1 LTS

Matrix products: default BLAS: /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.10.0 LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.10.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: Europe/Berlin tzcode source: system (glibc)

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

other attached packages: [1] SingleCellExperiment_1.24.0 SummarizedExperiment_1.32.0 Biobase_2.62.0 GenomicRanges_1.54.1 GenomeInfoDb_1.38.1
[6] IRanges_2.36.0 S4Vectors_0.40.2 BiocGenerics_0.48.1 MatrixGenerics_1.14.0 matrixStats_1.2.0
[11] ggplot2_3.4.4 dplyr_1.1.4 Signac_1.12.0 SeuratObject_5.0.1 Seurat_4.4.0
[16] multinichenetr_1.0.3

loaded via a namespace (and not attached): [1] progress_1.2.3 nnet_7.3-18 locfdr_1.1-8 goftest_1.2-3 Biostrings_2.70.1
[6] vctrs_0.6.5 spatstat.random_3.2-2 digest_0.6.33 png_0.1-8 corpcor_1.6.10
[11] shape_1.4.6 proxy_0.4-27 ggrepel_0.9.4 deldir_2.0-2 parallelly_1.36.0
[16] MASS_7.3-58.4 reshape2_1.4.4 httpuv_1.6.13 foreach_1.5.2 withr_2.5.2
[21] xfun_0.41 ggpubr_0.6.0 ellipsis_0.3.2 survival_3.5-5 memoise_2.0.1
[26] ggbeeswarm_0.7.2 emmeans_1.8.9 zoo_1.8-12 GlobalOptions_0.1.2 gtools_3.9.5
[31] pbapply_1.7-2 Formula_1.2-5 prettyunits_1.2.0 KEGGREST_1.42.0 promises_1.2.1
[36] httr_1.4.7 rstatix_0.7.2 globals_0.16.2 fitdistrplus_1.1-11 rstudioapi_0.14
[41] miniUI_0.1.1.1 generics_0.1.3 base64enc_0.1-3 zlibbioc_1.48.0 ScaledMatrix_1.10.0
[46] ggraph_2.1.0 polyclip_1.10-6 randomForest_4.7-1.1 GenomeInfoDbData_1.2.11 SparseArray_1.2.2
[51] xtable_1.8-4 stringr_1.5.1 doParallel_1.0.17 evaluate_0.23 S4Arrays_1.2.0
[56] hms_1.1.3 irlba_2.3.5.1 colorspace_2.1-0 visNetwork_2.1.2 ROCR_1.0-11
[61] reticulate_1.34.0 spatstat.data_3.0-3 magrittr_2.0.3 lmtest_0.9-40 readr_2.1.4
[66] later_1.3.2 viridis_0.6.4 lattice_0.21-8 genefilter_1.84.0 spatstat.geom_3.2-7
[71] future.apply_1.11.0 XML_3.99-0.16 scattermore_1.2 scuttle_1.12.0 shadowtext_0.1.2
[76] cowplot_1.1.1 RcppAnnoy_0.0.21 class_7.3-21 Hmisc_5.1-1 pillar_1.9.0
[81] nlme_3.1-162 iterators_1.0.14 caTools_1.18.2 compiler_4.3.0 beachmat_2.18.0
[86] stringi_1.8.3 gower_1.0.1 tensor_1.5 minqa_1.2.6 lubridate_1.9.3
[91] plyr_1.8.9 crayon_1.5.2 abind_1.4-5 scater_1.30.1 blme_1.0-5
[96] locfit_1.5-9.8 sp_2.1-2 bit_4.0.5 graphlayouts_1.0.2 UpSetR_1.4.0
[101] fastmatch_1.1-4 codetools_0.2-19 recipes_1.0.8 BiocSingular_1.18.0 e1071_1.7-14
[106] GetoptLong_1.0.5 plotly_4.10.3 remaCor_0.0.16 mime_0.12 splines_4.3.0
[111] circlize_0.4.15 Rcpp_1.0.11 sparseMatrixStats_1.14.0 blob_1.2.4 knitr_1.45
[116] utf8_1.2.4 here_1.0.1 clue_0.3-65 lme4_1.1-35.1 listenv_0.9.0
[121] checkmate_2.3.1 DelayedMatrixStats_1.24.0 Rdpack_2.6 ggsignif_0.6.4 estimability_1.4.1
[126] tibble_3.2.1 Matrix_1.6-4 statmod_1.5.0 tzdb_0.4.0 fANCOVA_0.6-1
[131] tweenr_2.0.2 pkgconfig_2.0.3 tools_4.3.0 cachem_1.0.8 RSQLite_2.3.4
[136] RhpcBLASctl_0.23-42 rbibutils_2.2.16 DBI_1.1.3 viridisLite_0.4.2 numDeriv_2016.8-1.1
[141] fastmap_1.1.1 rmarkdown_2.25 scales_1.3.0 grid_4.3.0 ica_1.0-3
[146] Rsamtools_2.16.0 nichenetr_2.0.4 broom_1.0.5 patchwork_1.1.3 coda_0.19-4
[151] dotCall64_1.1-1 carData_3.0-5 RANN_2.6.1 rpart_4.1.19 farver_2.1.1
[156] aod_1.3.2 tidygraph_1.2.3 mgcv_1.8-42 DiagrammeR_1.0.10 foreign_0.8-84
[161] cli_3.6.2 purrr_1.0.2 leiden_0.4.3.1 lifecycle_1.0.4 caret_6.0-94
[166] uwot_0.1.16 glmmTMB_1.1.8 mvtnorm_1.2-4 bluster_1.12.0 lava_1.7.3
[171] backports_1.4.1 annotate_1.80.0 BiocParallel_1.36.0 timechange_0.2.0 gtable_0.3.4
[176] rjson_0.2.21 ggridges_0.5.4 progressr_0.14.0 parallel_4.3.0 pROC_1.18.5
[181] limma_3.58.1 jsonlite_1.8.8 edgeR_4.0.3 bitops_1.0-7 bit64_4.0.5
[186] Rtsne_0.17 spatstat.utils_3.0-4 BiocNeighbors_1.20.0 muscat_1.16.0 metapod_1.10.0
[191] dqrng_0.3.2 pbkrtest_0.5.2 timeDate_4022.108 lazyeval_0.2.2 shiny_1.8.0
[196] htmltools_0.5.7 sctransform_0.4.1 glue_1.6.2 factoextra_1.0.7 spam_2.10-0
[201] XVector_0.42.0 RCurl_1.98-1.13 rprojroot_2.0.4 scran_1.30.0 gridExtra_2.3
[206] EnvStats_2.8.1 boot_1.3-28.1 igraph_1.6.0 variancePartition_1.32.2 TMB_1.9.9
[211] R6_2.5.1 sva_3.50.0 tidyr_1.3.0 DESeq2_1.42.0 gplots_3.1.3
[216] fdrtool_1.2.17 RcppRoll_0.3.0 cluster_2.1.4 ipred_0.9-14 nloptr_2.0.3
[221] DelayedArray_0.28.0 tidyselect_1.2.0 vipor_0.4.5 htmlTable_2.4.2 ggforce_0.4.1
[226] car_3.1-2 AnnotationDbi_1.64.1 future_1.33.0 ModelMetrics_1.2.2.2 rsvd_1.0.5
[231] munsell_0.5.0 KernSmooth_2.23-20 data.table_1.14.10 htmlwidgets_1.6.4 ComplexHeatmap_2.16.0
[236] RColorBrewer_1.1-3 rlang_1.1.2 spatstat.sparse_3.0-3 spatstat.explore_3.2-5 lmerTest_3.1-3
[241] ggnewscale_0.4.9 fansi_1.0.6 hardhat_1.3.0 beeswarm_0.4.0 prodlim_2023.08.28 `

browaeysrobin commented 7 months ago

Hi @Isabellvse

Now you wrote:

contrasts_oi = c("'A-B', 'C-B'")

Whereas the original code only works with this: contrasts_oi = c("'A-B','C-B'")

so without the space behind the comma

Therefore you had to adapt the code to remove the " " as well (but not really a problem if you do it this way).