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 in `dplyr::inner_join()` when running `multi_nichenet_analysis()` #61

Closed cgoneill closed 4 months ago

cgoneill commented 4 months ago

This appears to be the same issue as #40; I'm opening a new issue, as that one is closed.

I'm following the steps laid out in the multifactorial breast cancer vignette but using my own data; none of the default parameters specified in the vignette were changed except for omitting one cell type from analysis entirely and setting one specific cell type as the sole sender. When I get to using the wrapper multi_nichenet_analysis(), I encounter an error message that appears to be in dplyr::inner_join().

unwounded_combined_no_sm <- unwounded_combined %>% 
  subset(subset = high_lv_ident == "Skeletal Muscle", invert = TRUE)
# removes an uninteresting cell type

for (i in 1:ncol(unwounded_combined_no_sm@meta.data)) {
  if (is.factor(unwounded_combined_no_sm@meta.data[, i])) {
    unwounded_combined_no_sm@meta.data[, i] <- droplevels(
      unwounded_combined_no_sm@meta.data[, i]
    )
  }
}
# gets rid of all unused factors in all metadata columns of type `factor`

unwounded_combined_sce <- as.SingleCellExperiment(unwounded_combined_no_sm) %>% 
  alias_to_symbol_SCE("mouse") %>% 
  makenames_SCE()

sample_id <- "orig.ident"
group_id <- "expt_group"
celltype_id <- "high_lv_ident"
covariates <- NA
batches <- NA

colData(unwounded_combined_sce)[, celltype_id] <- make.names(
  colData(unwounded_combined_sce)[, celltype_id]
)

senders_oi <- "Keratinocyte" # changes in transgenic model should originate here
receivers_oi <- unique(colData(unwounded_combined_sce)[, celltype_id])

unwounded_combined_sce <- unwounded_combined_sce[
  , 
  colData(unwounded_combined_sce)[, celltype_id] %in% 
    c(senders_oi, receivers_oi)
]

min_cells <- 10

contrasts_oi <- c(
  "'(Tam-Veh)-(Tam.STZ-Veh.STZ)','(Tam.STZ-Veh.STZ)-(Tam-Veh)'"
)

contrast_tbl <- tibble(
  contrast = c("(Tam-Veh)-(Tam.STZ-Veh.STZ)", "(Tam.STZ-Veh.STZ)-(Tam-Veh)"), 
  group = c("Tam", "Tam.STZ")
)

logFC_threshold <- log(1.5, base = 2)

p_val_threshold <- 0.05

fraction_cutoff <- 0.05

p_val_adj <- TRUE

empirical_pval <- FALSE

top_n_target <- 250

n.cores <- min(availableCores(), length(union(senders_oi, receivers_oi))) %>% 
  as.numeric()

# Define weights of prioritization of expression, DE, and NicheNet activity info

prioritizing_weights_DE <- c("de_ligand" = 1, "de_receptor" = 1)

prioritizing_weights_activity <- c("activity_scaled" = 2)

prioritizing_weights_expression_specificity <- c(
  "exprs_ligand" = 2, 
  "exprs_receptor" = 2
)

prioritizing_weights_expression_sufficiency <- c(
  "frac_exprs_ligand_receptor" = 1
)

prioritizing_weights_relative_abundance <- c(
  "abund_sender" = 0, 
  "abund_receiver" = 0
)

prioritizing_weights <- c(
  prioritizing_weights_DE, 
  prioritizing_weights_activity, 
  prioritizing_weights_expression_specificity, 
  prioritizing_weights_expression_sufficiency, 
  prioritizing_weights_relative_abundance
)

abundance_expression_info <- get_abundance_expression_info(
  sce = unwounded_combined_sce, 
  sample_id = sample_id, 
  group_id = group_id, 
  celltype_id = celltype_id, 
  min_cells = min_cells, 
  senders_oi = senders_oi, 
  receivers_oi = receivers_oi, 
  lr_network = lr_network, 
  batches = batches
)

abundance_expression_info$abund_plot_sample

# Perform cell-cell communication analysis

multinichenet_output <- multi_nichenet_analysis(
  sce = unwounded_combined_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
)

The last call returns the following output and error message:

[1] "Calculate differential expression for all cell types"
[1] "DE analysis is done:"
[1] "included cell types are:"
[1] "Immune.Cell"   "Keratinocyte"  "Fibroblast"    "Vascular.Cell" "Neural.Crest" 
[1] "Make diagnostic abundance plots + Calculate expression information"
[1] "Calculate NicheNet ligand activities and ligand-target links"
[1] "Combine all the information in prioritization tables"
Error in `dplyr::inner_join()`:
! Can't convert `out[merge]$target` <logical> to match type of `target` <character>.
Run `rlang::last_trace()` to see where the error occurred.
> rlang::last_trace(drop = FALSE)
<error/vctrs_error_cast>
Error in `dplyr::inner_join()`:
! Can't convert `out[merge]$target` <logical> to match type of `target` <character>.
---
Backtrace:
     ▆
  1. ├─multinichenetr::multi_nichenet_analysis(...)
  2. │ └─multinichenetr::multi_nichenet_analysis_combined(...)
  3. │   ├─base::suppressMessages(...)
  4. │   │ └─base::withCallingHandlers(...)
  5. │   └─multinichenetr::generate_prioritization_tables(...)
  6. │     └─... %>% dplyr::distinct()
  7. ├─dplyr::distinct(.)
  8. ├─dplyr::select(...)
  9. ├─dplyr::inner_join(...)
 10. ├─dplyr:::inner_join.data.frame(...)
 11. │ └─dplyr:::join_mutate(...)
 12. │   └─vctrs::vec_cast(x = out[merge], to = x_merge, call = error_call)
 13. └─vctrs (local) `<fn>`()
 14.   └─vctrs::vec_default_cast(...)
 15.     ├─base::withRestarts(...)
 16.     │ └─base (local) withOneRestart(expr, restarts[[1L]])
 17.     │   └─base (local) doWithOneRestart(return(expr), restart)
 18.     └─vctrs::stop_incompatible_cast(...)
 19.       └─vctrs::stop_incompatible_type(...)
 20.         └─vctrs:::stop_incompatible(...)
 21.           └─vctrs:::stop_vctrs(...)
 22.             └─rlang::abort(message, class = c(class, "vctrs_error"), ..., call = call)

Session info is as follows:

> 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] grid      parallel  stats4    stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] multinichenetr_1.0.3        ggvenn_0.1.10               patchwork_1.2.0             ggalluvial_0.12.5           NMF_0.27                   
 [6] cluster_2.1.6               rngtools_1.5.2              registry_0.5-1              fgeo.tool_1.2.9             enrichR_3.2                
[11] enrichplot_1.22.0           org.Mm.eg.db_3.18.0         AnnotationDbi_1.64.1        clusterProfiler_4.10.0      reshape2_1.4.4             
[16] rlang_1.1.3                 pheatmap_1.0.12             RColorBrewer_1.1-3          scater_1.30.1               scuttle_1.12.0             
[21] tradeSeq_1.16.0             slingshot_2.10.0            TrajectoryUtils_1.10.0      princurve_2.1.6             scProportionTest_0.0.0.9000
[26] SeuratWrappers_0.3.19       clustree_0.5.1              xlsx2dfs_0.1.0              harmony_1.2.0               Rcpp_1.0.12                
[31] doMC_1.3.8                  doParallel_1.0.17           iterators_1.0.14            foreach_1.5.2               future_1.33.1              
[36] parallelly_1.37.1           DoubletFinder_2.0.4         DropletUtils_1.22.0         SingleCellExperiment_1.24.0 SummarizedExperiment_1.32.0
[41] GenomicRanges_1.54.1        GenomeInfoDb_1.38.8         IRanges_2.36.0              S4Vectors_0.40.2            MatrixGenerics_1.14.0      
[46] matrixStats_1.2.0           openxlsx_4.2.5.2            cowplot_1.1.3               magrittr_2.0.3              lubridate_1.9.3            
[51] forcats_1.0.0               stringr_1.5.1               purrr_1.0.2                 readr_2.1.5                 tidyr_1.3.1                
[56] tibble_3.2.1                tidyverse_2.0.0             Matrix_1.6-5                SoupX_1.6.2                 data.table_1.15.0          
[61] scCustomize_2.1.2           Seurat_5.0.1                SeuratObject_5.0.1          sp_2.1-3                    ggraph_2.1.0               
[66] CellChat_2.1.2              synchronicity_1.3.10        bigmemory_4.6.4             Biobase_2.62.0              BiocGenerics_0.48.1        
[71] ggplot2_3.5.0               dplyr_1.1.4                 igraph_1.6.0               

loaded via a namespace (and not attached):
  [1] Formula_1.2-5             ica_1.0-3                 plotly_4.10.4             rematch2_2.1.2            zlibbioc_1.48.2          
  [6] tidyselect_1.2.1          bit_4.0.5                 clue_0.3-65               lattice_0.22-5            rjson_0.2.21             
 [11] factoextra_1.0.7          blob_1.2.4                S4Arrays_1.2.1            caret_6.0-94              pbkrtest_0.5.2           
 [16] png_0.1-8                 cli_3.6.2                 ggplotify_0.1.2           goftest_1.2-3             variancePartition_1.32.5 
 [21] bluster_1.12.0            BiocNeighbors_1.20.2      ggnetwork_0.5.13          muscat_1.16.0             uwot_0.1.16              
 [26] shadowtext_0.1.3          curl_5.0.1                evaluate_0.23             mime_0.12                 tidytree_0.4.6           
 [31] leiden_0.4.3.1            ComplexHeatmap_2.18.0     stringi_1.8.3             pROC_1.18.5               backports_1.4.1          
 [36] XML_3.99-0.16.1           lmerTest_3.1-3            httpuv_1.6.14             paletteer_1.6.0           splines_4.3.2            
 [41] prodlim_2023.08.28        sctransform_0.4.1         ggbeeswarm_0.7.2          DBI_1.2.2                 HDF5Array_1.30.1         
 [46] genefilter_1.84.0         corpcor_1.6.10            jquerylib_0.1.4           withr_3.0.0               class_7.3-22             
 [51] systemfonts_1.0.6         lmtest_0.9-40             ggnewscale_0.4.10         tidygraph_1.3.0           sva_3.50.0               
 [56] BiocManager_1.30.22       htmlwidgets_1.6.4         fs_1.6.3                  ggrepel_0.9.5             statnet.common_4.9.0     
 [61] labeling_0.4.3            fANCOVA_0.6-1             SparseArray_1.2.4         DESeq2_1.42.1             annotate_1.80.0          
 [66] reticulate_1.35.0         zoo_1.8-12                knitr_1.45                XVector_0.42.0            network_1.18.2           
 [71] RhpcBLASctl_0.23-42       timechange_0.3.0          fansi_1.0.6               visNetwork_2.1.2          caTools_1.18.2           
 [76] timeDate_4032.109         ggtree_3.10.1             rhdf5_2.46.1              R.oo_1.26.0               RSpectra_0.16-1          
 [81] irlba_2.3.5.1             DiagrammeR_1.0.11         ggrastr_1.0.2             fastDummies_1.7.3         gridGraphics_0.5-1       
 [86] ellipsis_0.3.2            lazyeval_0.2.2            survival_3.5-7            scattermore_1.2           crayon_1.5.2             
 [91] RcppAnnoy_0.0.22          progressr_0.14.0          tweenr_2.0.3              later_1.3.2               base64enc_0.1-3          
 [96] ggridges_0.5.6            codetools_0.2-19          GlobalOptions_0.1.2       aod_1.3.3                 KEGGREST_1.42.0          
[101] Rtsne_0.17                shape_1.4.6.1             estimability_1.5          limma_3.58.1              foreign_0.8-86           
[106] pkgconfig_2.0.3           TMB_1.9.10                ggpubr_0.6.0              EnvStats_2.8.1            aplot_0.2.2              
[111] spatstat.sparse_3.0-3     ape_5.7-1                 viridisLite_0.4.2         gridBase_0.4-7            xtable_1.8-4             
[116] car_3.1-2                 plyr_1.8.9                httr_1.4.7                rbibutils_2.2.16          tools_4.3.2              
[121] globals_0.16.3            hardhat_1.3.1             checkmate_2.3.1           htmlTable_2.4.2           beeswarm_0.4.0           
[126] broom_1.0.5               nlme_3.1-164              HDO.db_0.99.1             lme4_1.1-35.1             digest_0.6.35            
[131] numDeriv_2016.8-1.1       remaCor_0.0.18            farver_2.1.1              tzdb_0.4.0                ModelMetrics_1.2.2.2     
[136] yulab.utils_0.1.4         WriteXLS_6.5.0            viridis_0.6.5             rpart_4.1.23              glue_1.7.0               
[141] cachem_1.0.8              polyclip_1.10-6           UpSetR_1.4.0              Hmisc_5.1-2               generics_0.1.3           
[146] Biostrings_2.70.3         mvtnorm_1.2-4             presto_1.0.0              nichenetr_2.0.5           statmod_1.5.0            
[151] RcppHNSW_0.6.0            ScaledMatrix_1.10.0       carData_3.0-5             minqa_1.2.6               pbapply_1.7-2            
[156] spam_2.10-0               gson_0.1.0                dqrng_0.3.2               utf8_1.2.4                gower_1.0.1              
[161] gtools_3.9.5              graphlayouts_1.1.1        ggsignif_0.6.4            lava_1.8.0                gridExtra_2.3            
[166] shiny_1.8.0               GenomeInfoDbData_1.2.11   glmmTMB_1.1.9             R.utils_2.12.3            rhdf5filters_1.14.1      
[171] RCurl_1.98-1.14           memoise_2.0.1             rmarkdown_2.26            locfdr_1.1-8              scales_1.3.0             
[176] R.methodsS3_1.8.2         svglite_2.1.3             RANN_2.6.1                bigmemory.sri_0.1.8       spatstat.data_3.0-4      
[181] rstudioapi_0.15.0         janitor_2.2.0             spatstat.utils_3.0-4      hms_1.1.3                 fitdistrplus_1.1-11      
[186] fdrtool_1.2.17            munsell_0.5.0             colorspace_2.1-0          FNN_1.1.4                 DelayedMatrixStats_1.24.0
[191] sparseMatrixStats_1.14.0  ipred_0.9-14              dotCall64_1.1-1           ggforce_0.4.2             circlize_0.4.16          
[196] xfun_0.42                 mgcv_1.9-1                e1071_1.7-14              TH.data_1.1-2             coda_0.19-4.1            
[201] sna_2.7-2                 recipes_1.0.10            remotes_2.4.2.1           emmeans_1.10.0            randomForest_4.7-1.1     
[206] abind_1.4-5               GOSemSim_2.28.1           treeio_1.26.0             Rhdf5lib_1.24.2           Rdpack_2.6               
[211] bitops_1.0-7              promises_1.2.1            scatterpie_0.2.1          RSQLite_2.3.5             qvalue_2.34.0            
[216] sandwich_3.1-0            proxy_0.4-27              fgsea_1.28.0              DelayedArray_0.28.0       GO.db_3.18.0             
[221] compiler_4.3.2            prettyunits_1.2.0         boot_1.3-28.1             beachmat_2.18.1           listenv_0.9.1            
[226] edgeR_4.0.16              BiocSingular_1.18.0       tensor_1.5                progress_1.2.3            MASS_7.3-60              
[231] uuid_1.2-0                BiocParallel_1.36.0       spatstat.random_3.2-3     R6_2.5.1                  multcomp_1.4-25          
[236] fastmap_1.1.1             fastmatch_1.1-4           rstatix_0.7.2             vipor_0.4.7               ROCR_1.0-11              
[241] nnet_7.3-19               rsvd_1.0.5                gtable_0.3.4              KernSmooth_2.23-22        miniUI_0.1.1.1           
[246] deldir_2.0-4              htmltools_0.5.7           bit64_4.0.5               spatstat.explore_3.2-7    lifecycle_1.0.4          
[251] ggprism_1.0.5             blme_1.0-5                zip_2.3.1                 nloptr_2.0.3              sass_0.4.9               
[256] vctrs_0.6.5               spatstat.geom_3.2-9       snakecase_0.11.1          DOSE_3.28.2               scran_1.30.2             
[261] ggfun_0.1.4               future.apply_1.11.1       bslib_0.6.1               pillar_1.9.0              gplots_3.1.3.1           
[266] metapod_1.10.1            locfit_1.5-9.9            jsonlite_1.8.8            GetoptLong_1.0.5         
cgoneill commented 4 months ago

I attempted this again but ran the subsetting on the SingleCellExperiment object as follows:

senders_oi <- "Keratinocyte" # origin of signaling changes
receivers_oi <- unique(colData(unwounded_combined_sce)[, celltype_id])[-6]
# remove uninteresting cell type

unwounded_combined_sce <- unwounded_combined_sce[
  , 
  colData(unwounded_combined_sce)[, celltype_id] %in% 
    c(senders_oi, receivers_oi)
]

for (i in 1:ncol(colData(unwounded_combined_sce))) {
  if (is.factor(colData(unwounded_combined_sce)[, i])) {
    colData(unwounded_combined_sce)[, i] <- droplevels(
      colData(unwounded_combined_sce)[, i]
    )
  }
}

All other code was run as written above, and the error message and output from rlang::last_trace(drop = FALSE) were the same.

cgoneill commented 4 months ago

I ran the multifactorial breast cancer vignette as written except for subsetting senders_oi and receivers_oi and subsetting the SingleCellExperiment object accordingly:

senders_oi <- "CD4T"

receivers_oi <- unique(SummarizedExperiment::colData(sce)[, celltype_id])[-3]

sce <- sce[, colData(sce)[, celltype_id] %in% c(senders_oi, receivers_oi)]

When running this in a different interactive session on the same system, I did not encounter this error message. Below is the session information for that session:

> 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] stats4    stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] tidyr_1.3.1                 stringr_1.5.1               magrittr_2.0.3              RColorBrewer_1.1-3          multinichenetr_1.0.3       
 [6] ggplot2_3.5.0               dplyr_1.1.4                 SingleCellExperiment_1.24.0 SummarizedExperiment_1.32.0 Biobase_2.62.0             
[11] GenomicRanges_1.54.1        GenomeInfoDb_1.38.8         IRanges_2.36.0              S4Vectors_0.40.2            BiocGenerics_0.48.1        
[16] MatrixGenerics_1.14.0       matrixStats_1.2.0          

loaded via a namespace (and not attached):
  [1] progress_1.2.3            nnet_7.3-19               locfdr_1.1-8              goftest_1.2-3             Biostrings_2.70.3        
  [6] TH.data_1.1-2             vctrs_0.6.5               spatstat.random_3.2-3     proxy_0.4-27              digest_0.6.35            
 [11] png_0.1-8                 corpcor_1.6.10            shape_1.4.6.1             ggrepel_0.9.5             deldir_2.0-4             
 [16] parallelly_1.37.1         MASS_7.3-60               reshape2_1.4.4            foreach_1.5.2             httpuv_1.6.14            
 [21] qvalue_2.34.0             withr_3.0.0               xfun_0.42                 ggfun_0.1.4               ggpubr_0.6.0             
 [26] ellipsis_0.3.2            survival_3.5-7            memoise_2.0.1             ggbeeswarm_0.7.2          clusterProfiler_4.10.0   
 [31] emmeans_1.10.0            gson_0.1.0                tidytree_0.4.6            zoo_1.8-12                GlobalOptions_0.1.2      
 [36] gtools_3.9.5              pbapply_1.7-2             Formula_1.2-5             prettyunits_1.2.0         KEGGREST_1.42.0          
 [41] promises_1.2.1            httr_1.4.7                rstatix_0.7.2             globals_0.16.3            fitdistrplus_1.1-11      
 [46] rstudioapi_0.15.0         miniUI_0.1.1.1            generics_0.1.3            DOSE_3.28.2               base64enc_0.1-3          
 [51] zlibbioc_1.48.2           ScaledMatrix_1.10.0       ggraph_2.1.0              randomForest_4.7-1.1      polyclip_1.10-6          
 [56] GenomeInfoDbData_1.2.11   SparseArray_1.2.4         xtable_1.8-4              doParallel_1.0.17         evaluate_0.23            
 [61] S4Arrays_1.2.1            hms_1.1.3                 irlba_2.3.5.1             visNetwork_2.1.2          colorspace_2.1-0         
 [66] ROCR_1.0-11               reticulate_1.35.0         spatstat.data_3.0-4       readr_2.1.5               lmtest_0.9-40            
 [71] later_1.3.2               viridis_0.6.5             ggtree_3.10.1             lattice_0.22-5            genefilter_1.84.0        
 [76] spatstat.geom_3.2-9       future.apply_1.11.1       XML_3.99-0.16.1           scattermore_1.2           scuttle_1.12.0           
 [81] shadowtext_0.1.3          cowplot_1.1.3             RcppAnnoy_0.0.22          Hmisc_5.1-2               class_7.3-22             
 [86] pillar_1.9.0              nlme_3.1-164              iterators_1.0.14          caTools_1.18.2            compiler_4.3.2           
 [91] beachmat_2.18.1           RSpectra_0.16-1           stringi_1.8.3             gower_1.0.1               lubridate_1.9.3          
 [96] tensor_1.5                minqa_1.2.6               plyr_1.8.9                crayon_1.5.2              abind_1.4-5              
[101] scater_1.30.1             blme_1.0-5                gridGraphics_0.5-1        locfit_1.5-9.9            sp_2.1-3                 
[106] graphlayouts_1.1.1        bit_4.0.5                 UpSetR_1.4.0              sandwich_3.1-0            fastmatch_1.1-4          
[111] codetools_0.2-19          multcomp_1.4-25           recipes_1.0.10            BiocSingular_1.18.0       e1071_1.7-14             
[116] GetoptLong_1.0.5          plotly_4.10.4             remaCor_0.0.18            mime_0.12                 splines_4.3.2            
[121] circlize_0.4.16           Rcpp_1.0.12               fastDummies_1.7.3         sparseMatrixStats_1.14.0  HDO.db_0.99.1            
[126] knitr_1.45                blob_1.2.4                utf8_1.2.4                clue_0.3-65               lme4_1.1-35.1            
[131] fs_1.6.3                  checkmate_2.3.1           listenv_0.9.1             DelayedMatrixStats_1.24.0 Rdpack_2.6               
[136] ggsignif_0.6.4            ggplotify_0.1.2           estimability_1.5          tibble_3.2.1              Matrix_1.6-5             
[141] statmod_1.5.0             tzdb_0.4.0                fANCOVA_0.6-1             tweenr_2.0.3              pkgconfig_2.0.3          
[146] tools_4.3.2               cachem_1.0.8              RhpcBLASctl_0.23-42       rbibutils_2.2.16          RSQLite_2.3.5            
[151] viridisLite_0.4.2         DBI_1.2.2                 numDeriv_2016.8-1.1       rmarkdown_2.26            fastmap_1.1.1            
[156] scales_1.3.0              grid_4.3.2                ica_1.0-3                 Seurat_5.0.1              nichenetr_2.0.5          
[161] broom_1.0.5               patchwork_1.2.0           coda_0.19-4.1             dotCall64_1.1-1           carData_3.0-5            
[166] rpart_4.1.23              RANN_2.6.1                farver_2.1.1              aod_1.3.3                 tidygraph_1.3.0          
[171] scatterpie_0.2.1          mgcv_1.9-1                foreign_0.8-86            DiagrammeR_1.0.11         cli_3.6.2                
[176] purrr_1.0.2               leiden_0.4.3.1            lifecycle_1.0.4           caret_6.0-94              uwot_0.1.16              
[181] glmmTMB_1.1.9             mvtnorm_1.2-4             bluster_1.12.0            lava_1.8.0                backports_1.4.1          
[186] annotate_1.80.0           BiocParallel_1.36.0       timechange_0.3.0          gtable_0.3.4              rjson_0.2.21             
[191] ggridges_0.5.6            progressr_0.14.0          pROC_1.18.5               parallel_4.3.2            ape_5.7-1                
[196] limma_3.58.1              jsonlite_1.8.8            edgeR_4.0.16              RcppHNSW_0.6.0            bitops_1.0-7             
[201] bit64_4.0.5               Rtsne_0.17                yulab.utils_0.1.4         spatstat.utils_3.0-4      BiocNeighbors_1.20.2     
[206] SeuratObject_5.0.1        muscat_1.16.0             metapod_1.10.1            dqrng_0.3.2               GOSemSim_2.28.1          
[211] timeDate_4032.109         pbkrtest_0.5.2            lazyeval_0.2.2            shiny_1.8.0               htmltools_0.5.7          
[216] enrichplot_1.22.0         GO.db_3.18.0              sctransform_0.4.1         factoextra_1.0.7          glue_1.7.0               
[221] spam_2.10-0               XVector_0.42.0            RCurl_1.98-1.14           treeio_1.26.0             scran_1.30.2             
[226] gridExtra_2.3             EnvStats_2.8.1            boot_1.3-28.1             igraph_1.6.0              variancePartition_1.32.5 
[231] TMB_1.9.10                R6_2.5.1                  sva_3.50.0                fdrtool_1.2.17            DESeq2_1.42.1            
[236] gplots_3.1.3.1            cluster_2.1.6             ipred_0.9-14              aplot_0.2.2               nloptr_2.0.3             
[241] DelayedArray_0.28.0       tidyselect_1.2.1          vipor_0.4.7               htmlTable_2.4.2           ggforce_0.4.2            
[246] car_3.1-2                 AnnotationDbi_1.64.1      future_1.33.1             ModelMetrics_1.2.2.2      rsvd_1.0.5               
[251] munsell_0.5.0             KernSmooth_2.23-22        data.table_1.15.0         htmlwidgets_1.6.4         fgsea_1.28.0             
[256] ComplexHeatmap_2.18.0     rlang_1.1.3               spatstat.sparse_3.0-3     spatstat.explore_3.2-7    lmerTest_3.1-3           
[261] ggnewscale_0.4.10         fansi_1.0.6               hardhat_1.3.1             prodlim_2023.08.28        beeswarm_0.4.0           
cgoneill commented 4 months ago

I went through the pipeline without the wrapper and localized the problem to generate_prioritization_tables().

abundance_expression_info <- get_abundance_expression_info(
  sce = unwounded_combined_sce, 
  sample_id = sample_id, 
  group_id = group_id, 
  celltype_id = celltype_id, 
  min_cells = min_cells, 
  senders_oi = senders_oi, 
  receivers_oi = receivers_oi, 
  lr_network = lr_network, 
  batches = batches
)

abundance_expression_info$abund_plot_sample + 
  NoLegend() + 
  theme(axis.text.x = element_text(angle = 0, hjust = 0.5)) + 
  theme(text = element_text(family = "Arial"))

DE_info <- get_DE_info(
  sce = unwounded_combined_sce,
  sample_id = sample_id,
  group_id = group_id,
  celltype_id = celltype_id,
  batches = batches,
  covariates = covariates,
  contrasts_oi = contrasts_oi,
  min_cells = min_cells
)

celltype_de <- DE_info$celltype_de$de_output_tidy

sender_receiver_de <- combine_sender_receiver_de(
  sender_de = celltype_de,
  receiver_de = celltype_de,
  senders_oi = senders_oi,
  receivers_oi = receivers_oi,
  lr_network = lr_network
)

ligand_activities_targets_DEgenes <- get_ligand_activities_targets_DEgenes(
  receiver_de = celltype_de,
  receivers_oi = receivers_oi,
  ligand_target_matrix = ligand_target_matrix,
  logFC_threshold = logFC_threshold,
  p_val_threshold = p_val_threshold,
  p_val_adj = p_val_adj,
  top_n_target = top_n_target,
  verbose = TRUE,
  n.cores = n.cores
)

sender_receiver_tbl <- dplyr::distinct(sender_receiver_de, sender, receiver)

metadata_combined <- as_tibble(colData(unwounded_combined_sce))

grouping_tbl <- metadata_combined[, c(sample_id, group_id)] %>% 
  as_tibble() %>% 
  dplyr::distinct()

colnames(grouping_tbl) <- c("sample", "group")

prioritization_tables <- generate_prioritization_tables(
  sender_receiver_info = abundance_expression_info$sender_receiver_info, 
  sender_receiver_de = sender_receiver_de, 
  ligand_activities_targets_DEgenes = ligand_activities_targets_DEgenes, 
  contrast_tbl = contrast_tbl, 
  sender_receiver_tbl = sender_receiver_tbl, 
  grouping_tbl = grouping_tbl, 
  prioritizing_weights = prioritizing_weights, 
  fraction_cutoff = fraction_cutoff, 
  abundance_data_receiver = abundance_expression_info$abundance_data_receiver, 
  abundance_data_sender = abundance_expression_info$abundance_data_sender
)
Error in `dplyr::inner_join()`:
! Can't convert `out[merge]$target` <logical> to match type of `target` <character>.
Run `rlang::last_trace()` to see where the error occurred.
> rlang::last_trace()
<error/vctrs_error_cast>
Error in `dplyr::inner_join()`:
! Can't convert `out[merge]$target` <logical> to match type of `target` <character>.
---
Backtrace:
    ▆
 1. ├─multinichenetr::generate_prioritization_tables(...)
 2. │ └─... %>% dplyr::distinct()
 3. ├─dplyr::distinct(.)
 4. ├─dplyr::select(...)
 5. ├─dplyr::inner_join(...)
 6. └─dplyr:::inner_join.data.frame(...)
Run rlang::last_trace(drop = FALSE) to see 12 hidden frames.
cgoneill commented 4 months ago

I think I found the problem. At the step in generate_prioritization_tables() that reads:

ligand_activities_target_de_tbl = dplyr::inner_join(
  ligand_activities_targets_DEgenes$ligand_activities, 
  ligand_activities_targets_DEgenes$de_genes_df %>% 
    dplyr::rename(target = gene, p_val_adj = p_adj)
) %>% 
  dplyr::select(
    contrast, 
    receiver, 
    ligand, 
    activity, 
    activity_scaled, 
    target, 
    ligand_target_weight, 
    logFC, 
    p_val, 
    p_val_adj, 
    direction_regulation
  ) %>% 
  dplyr::distinct()

ligand_activities_targets_DEgenes$de_genes_df has no entries - it's listed as a tibble with 0 rows and 6 columns. I set p_val_adj = FALSE in get_ligand_activities_targets_DEgenes(), as it had previously been set to TRUE, and that gave me some significant changes in signaling to work with - this also worked when running the wrapper function. I'll close the issue, as it appears to just be a shortcoming of my dataset.