MarioniLab / miloR

R package implementation of Milo for testing for differential abundance in KNN graphs
https://bioconductor.org/packages/release/bioc/html/miloR.html
GNU General Public License v3.0
316 stars 20 forks source link

Import precomputed graph #340

Open Dannyxu123 opened 1 week ago

Dannyxu123 commented 1 week ago

Hi! it's a great tool to use. However, After adding precomputated graph from an integrated Seurat Object (integrated using RPCA) into milo Object, makeNhoods could not identify valid graph for processing. However, when checking the milo Object, the graph is there. I am not sure where to begin troubleshooting.

 your code

test<-as.SingleCellExperiment(Merge.combined,assay = "integrated") test_milo <- Milo(test) graph(test_milo) <- buildFromAdjacency(Merge.combined@graphs$integrated_snn,k=20) test_milo <- makeNhoods(test_milo, prop = 0.1, k = 30, d=30, refined = TRUE, reduced_dims = "UMAP")

**Errors Checking valid object Error in makeNhoods(test_milo, prop = 0.1, k = 30, d = 30, refined = TRUE, : Not a valid Milo object - graph is missing. Please run buildGraph() first.

Session info

sessionInfo() R version 4.2.2 (2022-10-31) Platform: x86_64-pc-linux-gnu (64-bit) Running under: Ubuntu 22.04.2 LTS

Matrix products: default BLAS: /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3 LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.20.so

locale: [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=en_US.UTF-8
[4] LC_COLLATE=en_US.UTF-8 LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=en_US.UTF-8 LC_NAME=C LC_ADDRESS=C
[10] LC_TELEPHONE=C LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

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

other attached packages: [1] miloR_1.6.0 edgeR_3.40.2 limma_3.54.2
[4] patchwork_1.2.0 pheatmap_1.0.12 ggsci_3.0.0
[7] dplyr_1.1.4 cowplot_1.1.3 ggalluvial_0.12.5
[10] biomaRt_2.54.1 ddqcR_0.1.0 scCustomize_1.1.3
[13] ggrepel_0.9.5 uwot_0.1.16 hexbin_1.28.3
[16] circlize_0.4.16 ComplexHeatmap_2.14.0 nabor_0.5.0
[19] SeuratObject_4.1.3 Seurat_4.3.0 rhdf5_2.42.1
[22] SummarizedExperiment_1.28.0 Biobase_2.58.0 MatrixGenerics_1.10.0
[25] Rcpp_1.0.12 Matrix_1.6-5 GenomicRanges_1.50.2
[28] GenomeInfoDb_1.34.9 IRanges_2.32.0 S4Vectors_0.36.2
[31] BiocGenerics_0.44.0 matrixStats_1.2.0 data.table_1.15.0
[34] stringr_1.5.1 plyr_1.8.9 magrittr_2.0.3
[37] ggplot2_3.4.4 gtable_0.3.4 gtools_3.9.5
[40] gridExtra_2.3 ArchR_1.0.2

loaded via a namespace (and not attached): [1] utf8_1.2.4 spatstat.explore_3.2-6 reticulate_1.35.0
[4] tidyselect_1.2.0 RSQLite_2.3.5 AnnotationDbi_1.60.2
[7] htmlwidgets_1.6.4 BiocParallel_1.32.6 Rtsne_0.17
[10] ScaledMatrix_1.6.0 munsell_0.5.0 codetools_0.2-18
[13] ica_1.0-3 future_1.33.1 miniUI_0.1.1.1
[16] withr_3.0.0 spatstat.random_3.2-2 colorspace_2.1-0
[19] progressr_0.14.0 filelock_1.0.3 rstudioapi_0.15.0
[22] SingleCellExperiment_1.20.1 ROCR_1.0-11 tensor_1.5
[25] listenv_0.9.1 labeling_0.4.3 GenomeInfoDbData_1.2.9
[28] polyclip_1.10-6 farver_2.1.1 bit64_4.0.5
[31] parallelly_1.36.0 vctrs_0.6.5 generics_0.1.3
[34] BiocFileCache_2.6.1 timechange_0.3.0 R6_2.5.1
[37] doParallel_1.0.17 graphlayouts_1.1.0 ggbeeswarm_0.7.2
[40] clue_0.3-65 rsvd_1.0.5 locfit_1.5-9.8
[43] bitops_1.0-7 rhdf5filters_1.10.1 spatstat.utils_3.0-4
[46] cachem_1.0.8 DelayedArray_0.24.0 promises_1.2.1
[49] scales_1.3.0 ggraph_2.1.0 beeswarm_0.4.0
[52] beachmat_2.14.2 Cairo_1.6-2 globals_0.16.2
[55] goftest_1.2-3 spam_2.10-0 tidygraph_1.3.1
[58] rlang_1.1.3 GlobalOptions_0.1.2 splines_4.2.2
[61] lazyeval_0.2.2 spatstat.geom_3.2-8 reshape2_1.4.4
[64] abind_1.4-5 httpuv_1.6.14 tools_4.2.2
[67] ellipsis_0.3.2 RColorBrewer_1.1-3 ggridges_0.5.6
[70] progress_1.2.3 zlibbioc_1.44.0 purrr_1.0.2
[73] RCurl_1.98-1.14 prettyunits_1.2.0 deldir_2.0-2
[76] viridis_0.6.5 pbapply_1.7-2 GetoptLong_1.0.5
[79] zoo_1.8-12 cluster_2.1.4 scattermore_1.2
[82] lmtest_0.9-40 RANN_2.6.1 fitdistrplus_1.1-11
[85] hms_1.1.3 mime_0.12 xtable_1.8-4
[88] XML_3.99-0.16.1 shape_1.4.6 compiler_4.2.2
[91] tibble_3.2.1 KernSmooth_2.23-20 crayon_1.5.2
[94] htmltools_0.5.7 ggfun_0.1.4 later_1.3.2
[97] ggprism_1.0.4 tidyr_1.3.1 lubridate_1.9.3
[100] DBI_1.2.2 tweenr_2.0.2 dbplyr_2.4.0
[103] rappdirs_0.3.3 MASS_7.3-58.1 cli_3.6.2
[106] dotCall64_1.1-1 igraph_2.0.2 forcats_1.0.0
[109] pkgconfig_2.0.3 tidydr_0.0.5 sp_2.1-3
[112] plotly_4.10.4 spatstat.sparse_3.0-3 xml2_1.3.6
[115] paletteer_1.6.0 foreach_1.5.2 vipor_0.4.7
[118] XVector_0.38.0 snakecase_0.11.1 digest_0.6.34
[121] sctransform_0.4.1 RcppAnnoy_0.0.22 janitor_2.2.0
[124] spatstat.data_3.0-4 Biostrings_2.66.0 leiden_0.4.3.1
[127] curl_5.2.0 shiny_1.8.0 rjson_0.2.21
[130] lifecycle_1.0.4 nlme_3.1-160 jsonlite_1.8.8
[133] Rhdf5lib_1.20.0 BiocNeighbors_1.16.0 viridisLite_0.4.2
[136] fansi_1.0.6 pillar_1.9.0 lattice_0.20-45
[139] ggrastr_1.0.2 KEGGREST_1.38.0 fastmap_1.1.1
[142] httr_1.4.7 survival_3.4-0 glue_1.7.0
[145] png_0.1-8 iterators_1.0.14 bit_4.0.5
[148] ggforce_0.4.2 stringi_1.8.3 rematch2_2.1.2
[151] blob_1.2.4 BiocSingular_1.14.0 memoise_2.0.1
[154] irlba_2.3.5.1 future.apply_1.11.1

MikeDMorgan commented 1 week ago

Do you get the same error if you explicitly use miloR::graph()?

Dannyxu123 commented 1 week ago

Do you get the same error if you explicitly use miloR::graph()?

Yes, I get the same error. And here's the info I get when I run buildFromAdjacency: Adding nhoodDistances to Milo object Warning message: In .M2v(x) : sparse->dense coercion: allocating vector of size 6.3 GiB

I am not sure if this indicates graph is added successfully or not?

MikeDMorgan commented 1 week ago

OK - your version of Milo is very out of date (1.6.0 vs. current 2.0.0).

Secondly, the error is an out of memory error, so no, the graph isn't being added. Could you paste the code with the traceback immediately following it?

mdpatric commented 1 week ago

Hello, I believe the issue is after running buildFromAdjacency(seurat.combined@graphs$SCT_snn,k=20) it adds another milo object into the graph slot with it's own graph slot with an iGraph object. After running milo@graph[["graph"]] <- milo@graph[["graph"]]@graph[["graph"]] mine runs.

This issue is also addressed by simply adding miloR::graph(test_milo) <- miloR::graph(buildFromAdjacency(Merge.combined@graphs$integrated_snn,k=20))

Dannyxu123 commented 1 week ago

Hello, I believe the issue is after running buildFromAdjacency(seurat.combined@graphs$SCT_snn,k=20) it adds another milo object into the graph slot with it's own graph slot with an iGraph object. After running milo@graph[["graph"]] <- milo@graph[["graph"]]@graph[["graph"]] mine runs.

This issue is also addressed by simply adding miloR::graph(test_milo) <- miloR::graph(buildFromAdjacency(Merge.combined@graphs$integrated_snn,k=20))

This works! thank you a lot! However, makeNhoods seems to lead to another problem. I guess I will update the milo first

Code

test_milo <- makeNhoods(test_milo, prop = 0.1, k =20, d=30, refined = TRUE, reduced_dims = "UMAP")

Info

Checking valid object Running refined sampling with reduced_dim Error in .subset_to_index(subset, precomputed, byrow = TRUE) : 'subset' indices out of range of 'x'

MikeDMorgan commented 1 week ago

@Dannyxu123 - do not use UMAP for constructing your graph - the distances aren't valid. Use an alternative reduced dimensional space where the distances are retained, e.g. PCA or diffusion map.

MikeDMorgan commented 1 week ago

Hello, I believe the issue is after running buildFromAdjacency(seurat.combined@graphs$SCT_snn,k=20) it adds another milo object into the graph slot with it's own graph slot with an iGraph object. After running milo@graph[["graph"]] <- milo@graph[["graph"]]@graph[["graph"]] mine runs.

This issue is also addressed by simply adding miloR::graph(test_milo) <- miloR::graph(buildFromAdjacency(Merge.combined@graphs$integrated_snn,k=20))

In general, it is not good practise to access objects using the @ accessor - if these slot names change then your code will break. However, using the appropriate getter and setter methods ensures that functionality is retained regardless of what the slot names are.