Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

All values in fraction_expressing_ligand_receptor column in prioritization_table_oi are 0 #23

Closed
catsargent opened this issue Aug 17, 2023 · 6 comments
Labels
bug Something isn't working

Comments

@catsargent
Copy link

Hi,

This is related to #22

No results are returned when running get_top_n_lr_pairs. It seems that the reason for this is because in the table prioritization_tbl_oi all of the values in the fraction_expressing_ligand_receptor column are 0.

Similarly, in the same table, the columns for fraction_receptor_group and fraction_ligand_group also contain only 0s. Do you know why this might be? I saw in expression_processing.R that there is a function called fix_frq_df which fixes a muscat-bug in fraction calculation in case that expression fraction would be NA / NaN. Change NA to 0. Could this be related? If so, any ideas on a workaround so that I can proceed with the anlaysis? We're really keen to apply mnn to our data!

Thanks for your help.

Catherine

@browaeysrobin
Copy link
Member

Hi @catsargent

This is indeed the reason that get_top_n_lr_pairs does return an empty table in your case.

But, I have currently no idea why all values of fraction_expressing_ligand_receptor are 0.

Can you run: get_muscat_exprs_frac(sce = sce, sample_id = sample_id, celltype_id = celltype_id, group_id = group_id) and check the frequencies there?

Do you have this issue on one specific dataset? on all the datasets you applied MultiNicheNet on? on the vignette data as well?

@catsargent
Copy link
Author

Thank you for getting back to me. I ran the command you specified above on our dataset and got the following output:

$frq_celltype_samples
# A tibble: 5,840,160 × 4
   gene        sample                                fraction_sample celltype    
   <chr>       <chr>                                           <dbl> <chr>       
 1 MIR1302.2HG X3a67845f.cae0.4d43.b98d.c2da40181fb4               0 Acinar.Cells
 2 FAM138A     X3a67845f.cae0.4d43.b98d.c2da40181fb4               0 Acinar.Cells
 3 OR4F5       X3a67845f.cae0.4d43.b98d.c2da40181fb4               0 Acinar.Cells
 4 AL627309.1  X3a67845f.cae0.4d43.b98d.c2da40181fb4               0 Acinar.Cells
 5 AL627309.3  X3a67845f.cae0.4d43.b98d.c2da40181fb4               0 Acinar.Cells
 6 AL627309.2  X3a67845f.cae0.4d43.b98d.c2da40181fb4               0 Acinar.Cells
 7 AL627309.5  X3a67845f.cae0.4d43.b98d.c2da40181fb4               0 Acinar.Cells
 8 AL627309.4  X3a67845f.cae0.4d43.b98d.c2da40181fb4               0 Acinar.Cells
 9 AP006222.2  X3a67845f.cae0.4d43.b98d.c2da40181fb4               0 Acinar.Cells
10 AL732372.1  X3a67845f.cae0.4d43.b98d.c2da40181fb4               0 Acinar.Cells
# ℹ 5,840,150 more rows
# ℹ Use `print(n = ...)` to see more rows

$frq_celltype_groups
# A tibble: 1,095,030 × 4
   gene        group         fraction_group celltype    
   <chr>       <chr>                  <dbl> <chr>       
 1 MIR1302.2HG Parotid.Gland              0 Acinar.Cells
 2 FAM138A     Parotid.Gland              0 Acinar.Cells
 3 OR4F5       Parotid.Gland              0 Acinar.Cells
 4 AL627309.1  Parotid.Gland              0 Acinar.Cells
 5 AL627309.3  Parotid.Gland              0 Acinar.Cells
 6 AL627309.2  Parotid.Gland              0 Acinar.Cells
 7 AL627309.5  Parotid.Gland              0 Acinar.Cells
 8 AL627309.4  Parotid.Gland              0 Acinar.Cells
 9 AP006222.2  Parotid.Gland              0 Acinar.Cells
10 AL732372.1  Parotid.Gland              0 Acinar.Cells
# ℹ 1,095,020 more rows
# ℹ Use `print(n = ...)` to see more rows

Warning messages:
1: In FUN(X[[i]], ...) :
  For Celltype Acinar.Cells gene names got lost while calculating the fraction of expression of each gene with muscat::calcExprFreqs (due to a bug in this function). We temporality fixed this ourselves for the moment.
2: In FUN(X[[i]], ...) :
  For Celltype PC.VSM gene names got lost while calculating the fraction of expression of each gene with muscat::calcExprFreqs (due to a bug in this function). We temporality fixed this ourselves for the moment.
3: In FUN(X[[i]], ...) :
  For Celltype T.Cells gene names got lost while calculating the fraction of expression of each gene with muscat::calcExprFreqs (due to a bug in this function). We temporality fixed this ourselves for the moment.
4: In FUN(X[[i]], ...) :
  For Celltype Ductal.KCs gene names got lost while calculating the fraction of expression of each gene with muscat::calcExprFreqs (due to a bug in this function). We temporality fixed this ourselves for the moment.
5: In FUN(X[[i]], ...) :
  For Celltype Ionocytes gene names got lost while calculating the fraction of expression of each gene with muscat::calcExprFreqs (due to a bug in this function). We temporality fixed this ourselves for the moment.
6: In FUN(X[[i]], ...) :
  For Celltype MECs gene names got lost while calculating the fraction of expression of each gene with muscat::calcExprFreqs (due to a bug in this function). We temporality fixed this ourselves for the moment.
7: In FUN(X[[i]], ...) :
  For Celltype Oral.Mucosal.KCs gene names got lost while calculating the fraction of expression of each gene with muscat::calcExprFreqs (due to a bug in this function). We temporality fixed this ourselves for the moment.
8: In FUN(X[[i]], ...) :
  For Celltype ILCs gene names got lost while calculating the fraction of expression of each gene with muscat::calcExprFreqs (due to a bug in this function). We temporality fixed this ourselves for the moment.
9: In FUN(X[[i]], ...) :
  For Celltype Fibroblast gene names got lost while calculating the fraction of expression of each gene with muscat::calcExprFreqs (due to a bug in this function). We temporality fixed this ourselves for the moment.
10: In FUN(X[[i]], ...) :
  For Celltype Plasma.Cells gene names got lost while calculating the fraction of expression of each gene with muscat::calcExprFreqs (due to a bug in this function). We temporality fixed this ourselves for the moment.

I will check what happens with the vignette data too.

@browaeysrobin
Copy link
Member

browaeysrobin commented Aug 18, 2023

Hi @catsargent

Can you show me the warnings, error messages, output of frq if you run the following:

  sce$id = sce[[sample_id]]
  sce = muscat::prepSCE(sce,
                        kid = celltype_id, # subpopulation assignments
                        gid = group_id,  # group IDs (ctrl/stim)
                        sid = "id",   # sample IDs (ctrl/stim.1234)
                        drop = FALSE)  #
  frq = muscat::calcExprFreqs(sce, assay = "counts", th = 0) 
  assayNames(frq)  
  head(assay(frq))

Can you also share your sessionInfo() ?

@catsargent
Copy link
Author

Hi,

There were no warnings as such when running the above code:

> assayNames(frq)  
[1] "Acinar.Cells"     "Ductal.KCs"       "Fibroblast"       "ILCs"             "Ionocytes"        "MECs"             "Oral.Mucosal.KCs"
[8] "Plasma.Cells"     "T.Cells"         
> head(assay(frq))
     c6860865.01a6.4d26.b0fd.35b468685376 c6bd9d09.068d.4644.b34f.4ab7a5194b63 cce79f31.965b.451e.8323.d27403781577
[1,]                                    0                                    0                                    0
[2,]                                    0                                    0                                    0
[3,]                                    0                                    0                                    0
[4,]                                    0                                    0                                    0
[5,]                                    0                                    0                                    0
[6,]                                    0                                    0                                    0
     d2110830.d924.4d18.a197.319ec2f4526b d5a83d9e.101d.4762.ab46.fe61a35e4742 df41b943.a958.4a49.baae.7f4cd6b37dbe
[1,]                                    0                                    0                                    0
[2,]                                    0                                    0                                    0
[3,]                                    0                                    0                                    0
[4,]                                    0                                    0                                    0
[5,]                                    0                                    0                                    0
[6,]                                    0                                    0                                    0
     ead6ff92.9050.4aec.8f88.e3cff5583d35 fe0ae9cb.e1f3.4dfb.944f.907528c3d52a X03797dbb.1d26.4e47.bb4c.1437e6bc0716
[1,]                                    0                                    0                                     0
[2,]                                    0                                    0                                     0
[3,]                                    0                                    0                                     0
[4,]                                    0                                    0                                     0
[5,]                                    0                                    0                                     0
[6,]                                    0                                    0                                     0
     X3545cb11.ec09.4475.80ae.a687a5da268d X3a67845f.cae0.4d43.b98d.c2da40181fb4 X3c2efb4c.fe37.4f79.b0a0.0c6a93b27e1f
[1,]                                     0                                     0                                     0
[2,]                                     0                                     0                                     0
[3,]                                     0                                     0                                     0
[4,]                                     0                                     0                                     0
[5,]                                     0                                     0                                     0
[6,]                                     0                                     0                                     0
     X3cab0b6b.d9f5.4870.b1af.417cd2521ca0 X6122780d.df04.4827.89a7.f166bd123655 X71f09799.9a58.4b1a.89f7.9db8f53b8a01
[1,]                                     0                                     0                                     0
[2,]                                     0                                     0                                     0
[3,]                                     0                                     0                                     0
[4,]                                     0                                     0                                     0
[5,]                                     0                                     0                                     0
[6,]                                     0                                     0                                     0
     X7a77635c.f7b8.405f.9d9b.1c5c3a24d6c8 Minor.Salivary.Gland Parotid.Gland Submandibular.Gland
[1,]                                     0                    0             0                   0
[2,]                                     0                    0             0                   0
[3,]                                     0                    0             0                   0
[4,]                                     0                    0             0                   0
[5,]                                     0                    0             0                   0
[6,]                                     0                    0             0                   0

However, comparing it to the output generated using the vignette data (see below), I noticed that there are no gene names. So presumably this could be the issue? The counts assay in my sce object includes the gene names.

> assayNames(frq)  
[1] "L_NK_CD56._CD16."       "L_T_TIM3._CD38._HLADR." "M_Monocyte_CD16"       
> head(assay(frq))
                     A1          A2          A3          A4          M1        M2          M3          M4         M5         M6
AL627309.1 0.0000000000 0.001404494 0.000000000 0.000785546 0.000000000 0.0000000 0.000000000 0.001745201 0.00000000 0.00000000
AL669831.5 0.0145929339 0.014044944 0.006493506 0.010212097 0.031645570 0.0000000 0.014652015 0.013961606 0.02083333 0.08510638
LINC00115  0.0046082949 0.004213483 0.010822511 0.008641005 0.018987342 0.0000000 0.007326007 0.013961606 0.00000000 0.00000000
FAM41C     0.0007680492 0.001404494 0.000000000 0.000785546 0.000000000 0.0000000 0.003663004 0.003490401 0.00000000 0.00000000
NOC2L      0.1244239631 0.108146067 0.090909091 0.095836606 0.126582278 0.1509434 0.095238095 0.157068063 0.15625000 0.08510638
KLHL17     0.0046082949 0.000000000 0.002164502 0.002356638 0.006329114 0.0000000 0.003663004 0.000000000 0.00000000 0.00000000
                    M7          S1          S2          S3          S4          S5            A            M            S
AL627309.1 0.000000000 0.000000000 0.000000000 0.000000000 0.002772643 0.003039514 0.0005334756 0.0006381621 0.0014609204
AL669831.5 0.019073569 0.006451613 0.025352113 0.008522727 0.007393715 0.012158055 0.0120032009 0.0191448628 0.0102264427
LINC00115  0.010899183 0.003225806 0.005633803 0.014204545 0.008317930 0.006079027 0.0066684449 0.0108487556 0.0073046019
FAM41C     0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.003039514 0.0008002134 0.0019144863 0.0003652301
NOC2L      0.092643052 0.093548387 0.095774648 0.107954545 0.092421442 0.094224924 0.1074953321 0.1257179324 0.0953250548
KLHL17     0.002724796 0.006451613 0.002816901 0.005681818 0.005545287 0.006079027 0.0026673780 0.0019144863 0.0054784514

And here is my session info:

R version 4.2.3 (2023-03-15)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: macOS Monterey 12.6.3

Matrix products: default
LAPACK: /Users/sargent/miniconda3/envs/mnn-env/lib/libopenblasp-r0.3.23.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] stats4    stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] multinichenetr_1.0.0        DropletUtils_1.18.0         ggplot2_3.4.2               dplyr_1.1.2                
 [5] SingleCellExperiment_1.20.0 SummarizedExperiment_1.28.0 Biobase_2.58.0              GenomicRanges_1.50.0       
 [9] GenomeInfoDb_1.34.9         IRanges_2.32.0              S4Vectors_0.36.0            BiocGenerics_0.44.0        
[13] MatrixGenerics_1.10.0       matrixStats_1.0.0          

loaded via a namespace (and not attached):
  [1] rsvd_1.0.5                Hmisc_5.1-0               ica_1.0-3                 class_7.3-22              ps_1.7.5                 
  [6] foreach_1.5.2             lmtest_0.9-40             crayon_1.5.2              rbibutils_2.2.13          MASS_7.3-60              
 [11] rhdf5filters_1.10.0       nlme_3.1-162              backports_1.4.1           sva_3.46.0                rlang_1.1.1              
 [16] XVector_0.38.0            caret_6.0-94              ROCR_1.0-11               irlba_2.3.5.1             nloptr_2.0.3             
 [21] callr_3.7.3               limma_3.54.0              scater_1.26.0             BiocParallel_1.32.5       rjson_0.2.21             
 [26] bit64_4.0.5               glue_1.6.2                sctransform_0.3.5         pbkrtest_0.5.2            parallel_4.2.3           
 [31] processx_3.8.2            vipor_0.4.5               spatstat.sparse_3.0-2     AnnotationDbi_1.60.0      UpSetR_1.4.0             
 [36] muscat_1.12.0             spatstat.geom_3.2-2       tidyselect_1.2.0          usethis_2.2.2             SeuratObject_4.1.3       
 [41] fitdistrplus_1.1-11       variancePartition_1.28.0  XML_3.99-0.14             tidyr_1.3.0               zoo_1.8-12               
 [46] ggpubr_0.6.0              xtable_1.8-4              magrittr_2.0.3            evaluate_0.21             Rdpack_2.4               
 [51] scuttle_1.8.0             cli_3.6.1                 zlibbioc_1.44.0           rstudioapi_0.15.0         miniUI_0.1.1.1           
 [56] sp_2.0-0                  rpart_4.1.19              aod_1.3.2                 locfdr_1.1-8              shiny_1.7.4.1            
 [61] xfun_0.39                 BiocSingular_1.14.0       clue_0.3-64               pkgbuild_1.4.2            cluster_2.1.4            
 [66] caTools_1.18.2            tidygraph_1.2.3           KEGGREST_1.38.0           tibble_3.2.1              ggrepel_0.9.3            
 [71] listenv_0.9.0             Biostrings_2.66.0         png_0.1-8                 future_1.33.0             ipred_0.9-14             
 [76] withr_2.5.0               bitops_1.0-7              ggforce_0.4.1             plyr_1.8.8                hardhat_1.3.0            
 [81] e1071_1.7-13              dqrng_0.3.0               pROC_1.18.4               pillar_1.9.0              nichenetr_2.0.0          
 [86] gplots_3.1.3              GlobalOptions_0.1.2       cachem_1.0.8              fs_1.6.2                  GetoptLong_1.0.5         
 [91] DelayedMatrixStats_1.20.0 vctrs_0.6.3               ellipsis_0.3.2            generics_0.1.3            lava_1.7.2.1             
 [96] devtools_2.4.5            tools_4.2.3               foreign_0.8-84            beeswarm_0.4.0            munsell_0.5.0            
[101] tweenr_2.0.2              emmeans_1.8.7             proxy_0.4-27              DelayedArray_0.24.0       fastmap_1.1.1            
[106] compiler_4.2.3            pkgload_1.3.2.1           abind_1.4-5               httpuv_1.6.11             sessioninfo_1.2.2        
[111] plotly_4.10.2             GenomeInfoDbData_1.2.9    prodlim_2023.03.31        gridExtra_2.3             glmmTMB_1.1.7            
[116] edgeR_3.40.0              lattice_0.21-8            ggnewscale_0.4.9          deldir_1.0-9              visNetwork_2.1.2         
[121] utf8_1.2.3                later_1.3.1               recipes_1.0.6             jsonlite_1.8.7            scales_1.2.1             
[126] ScaledMatrix_1.6.0        carData_3.0-5             pbapply_1.7-2             sparseMatrixStats_1.10.0  estimability_1.4.1       
[131] genefilter_1.80.0         lazyeval_0.2.2            promises_1.2.0.1          car_3.1-2                 doParallel_1.0.17        
[136] R.utils_2.12.2            goftest_1.2-3             checkmate_2.2.0           spatstat.utils_3.0-3      reticulate_1.30          
[141] rmarkdown_2.23            cowplot_1.1.1             blme_1.0-5                statmod_1.5.0             Rtsne_0.16               
[146] uwot_0.1.16               igraph_1.5.0              HDF5Array_1.26.0          survival_3.5-5            numDeriv_2016.8-1.1      
[151] htmltools_0.5.5           memoise_2.0.1             profvis_0.3.8             Seurat_4.3.0.1            locfit_1.5-9.8           
[156] graphlayouts_1.0.0        viridisLite_0.4.2         digest_0.6.33             RhpcBLASctl_0.23-42       mime_0.12                
[161] RSQLite_2.3.1             future.apply_1.11.0       remotes_2.4.2             data.table_1.14.8         urlchecker_1.0.1         
[166] blob_1.2.4                R.oo_1.25.0               DiagrammeR_1.0.10         labeling_0.4.2            Formula_1.2-5            
[171] splines_4.2.3             Rhdf5lib_1.20.0           RCurl_1.98-1.12           broom_1.0.5               hms_1.1.3                
[176] base64enc_0.1-3           rhdf5_2.42.0              colorspace_2.1-0          ggbeeswarm_0.7.2          shape_1.4.6              
[181] nnet_7.3-19               Rcpp_1.0.10               RANN_2.6.1                mvtnorm_1.2-2             circlize_0.4.15          
[186] fansi_1.0.4               tzdb_0.4.0                parallelly_1.36.0         ModelMetrics_1.2.2.2      R6_2.5.1                 
[191] grid_4.2.3                factoextra_1.0.7          ggridges_0.5.4            lifecycle_1.0.3           bluster_1.8.0            
[196] ggsignif_0.6.4            minqa_1.2.5               leiden_0.4.3              Matrix_1.6-0              RcppAnnoy_0.0.21         
[201] RColorBrewer_1.1-3        iterators_1.0.14          spatstat.explore_3.2-1    TMB_1.9.4                 stringr_1.5.0            
[206] gower_1.0.1               htmlwidgets_1.6.2         beachmat_2.14.0           polyclip_1.10-4           purrr_1.0.1              
[211] shadowtext_0.1.2          timechange_0.2.0          mgcv_1.8-42               ComplexHeatmap_2.14.0     globals_0.16.2           
[216] htmlTable_2.4.1           patchwork_1.1.2           spatstat.random_3.1-5     progressr_0.13.0          codetools_0.2-19         
[221] lubridate_1.9.2           metapod_1.6.0             randomForest_4.7-1.1      gtools_3.9.4              prettyunits_1.1.1        
[226] R.methodsS3_1.8.2         gtable_0.3.3              DBI_1.1.3                 highr_0.10                tensor_1.5               
[231] httr_1.4.6                KernSmooth_2.23-21        stringi_1.7.12            progress_1.2.2            reshape2_1.4.4           
[236] farver_2.1.1              annotate_1.76.0           viridis_0.6.3             fdrtool_1.2.17            timeDate_4022.108        
[241] boot_1.3-28.1             BiocNeighbors_1.16.0      lme4_1.1-34               readr_2.1.4               geneplotter_1.76.0       
[246] scattermore_1.2           scran_1.26.2              DESeq2_1.38.0             bit_4.0.5                 spatstat.data_3.0-1      
[251] ggraph_2.1.0              pkgconfig_2.0.3           lmerTest_3.1-3            rstatix_0.7.2             knitr_1.43            

@browaeysrobin
Copy link
Member

Hi @catsargent

This problem seems to be due to an issue with using muscat::calcExprFreqs on your input. I can't think of a potential reason why it fails that way for your data. You can file an issue with muscat, but I am considering reimplementing this function.

@browaeysrobin browaeysrobin added the bug Something isn't working label Aug 21, 2023
@catsargent
Copy link
Author

Hi @browaeysrobin,

I tracked back the error and realised that it was due to my sce object not having the counts dimnames set.
e.g. sce@assays@data@listData[["counts"]]@Dimnames

I am therefore closing this issue.

Thanks for your help.
Catherine

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants