8000 there were an error in testNhoods() · Issue #364 · MarioniLab/miloR · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

there were an error in testNhoods() #364

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&rdqu 8000 o;, 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

Open
herong2006 opened this issue Apr 3, 2025 · 10 comments
Open

there were an error in testNhoods() #364

herong2006 opened this issue Apr 3, 2025 · 10 comments

Comments

@herong2006
Copy link

Describe the bug
There were an error in testNhoods(),would you help me?

Minimum code example
Minimum example to reproduce the error

## your code

devtools::install_local("github/miloR-master.zip")
library(stringr)
library(Seurat)
library(miloR)

library(SingleCellExperiment)
library(scater)
library(dplyr)
library(patchwork)
data("sim_trajectory",package="miloR")

traj_sce<-sim_trajectory[['SCE']]

traj_meta<-sim_trajectory[["meta"]]

colData(traj_sce)<-DataFrame(traj_meta)

logcounts(traj_sce)<-log(counts(traj_sce)+1)
traj_sce<-runPCA(traj_sce,ncomponents=30)
traj_sce<-runUMAP(traj_sce)

plotUMAP(traj_sce)

traj_milo<-Milo(traj_sce)
reducedDim(traj_milo,"UMAP")<-reducedDim(traj_sce,"UMAP")

traj_milo
traj_milo<-buildGraph(traj_milo,k=10,d=30)
traj_milo<-makeNhoods(traj_milo,prop=0.1,k=10,d=30,refined=TRUE)
plotNhoodSizeHist(traj_milo)

traj_milo<-countCells(traj_milo,meta.data=data.frame(colData(traj_milo)),samples="Sample")
head(nhoodCounts(traj_milo))

traj_design<-data.frame(colData(traj_milo))[,c("Sample","Condition")]
traj_design<-distinct(traj_design)
rownames(traj_design)<-traj_design$Sample

traj_design<-traj_design[colnames(nhoodCounts(traj_milo)),,drop=FALSE]

traj_design

traj_milo<-calcNhoodDistance(traj_milo,d=30)
rownames(traj_design)<-traj_design$Sample
da_results<-testNhoods(traj_milo,design=~Condition,design.df=traj_design)
Full error traceback

## the error

traj_design
Sample Condition
B_R1 B_R1 B
A_R1 A_R1 A
A_R2 A_R2 A
B_R2 B_R2 B
B_R3 B_R3 B
A_R3 A_R3 A
traj_milo<-calcNhoodDistance(traj_milo,d=30)
rownames(traj_design)<-traj_design$Sample
da_results<-testNhoods(traj_milo,design=~Condition,design.df=traj_design)
Using TMM normalisation
Performing spatial FDR correction withk-distance weighting
Error in testNhoods(traj_milo, design = ~Condition, design.df = traj_design) :
lazy-load database 'C:/Users/ASUS/AppData/Local/R/win-library/4.3/miloR/R/miloR.rdb' is corrupt
此外: Warning messages:
1: In testNhoods(traj_milo, design = ~Condition, design.df = traj_design) :
重新评估被中断的许诺
2: In testNhoods(traj_milo, design = ~Condition, design.df = traj_design) :
internal error -3 in R_decompress1

Session info
Output of sessionInfo()

@herong2006
Copy link
Author

When using the example code from the official website, I encountered an error as shown above. The same error persists when using my own data.
scRNA1 <- as.SingleCellExperiment(scRNA1)

构建miloR对象

scRNA1 <- Milo(scRNA1)
scRNA1
scRNA1 <- buildGraph(scRNA1, k = 10, d = 30)
scRNA1 <- makeNhoods(scRNA1, prop = 0.1, k = 10, d=30, refined = TRUE)
plotNhoodSizeHist(scRNA1)

scRNA1 <- countCells(scRNA1, meta.data = data.frame(colData(scRNA1)), samples="orig.ident")
head(nhoodCounts(scRNA1))

traj_design <- data.frame(colData(scRNA1))[,c("orig.ident", "Group")]
traj_design <- distinct(traj_design)
rownames(traj_design) <- traj_design$orig.ident

Reorder rownames to match columns of nhoodCounts(milo)

traj_design <- traj_design[colnames(nhoodCounts(scRNA1)), , drop=FALSE]

traj_design

scRNA1 <- calcNhoodDistance(scRNA1, d=30)
rownames(traj_design) <- traj_design$orig.ident
da_results <- testNhoods(scRNA1, design = ~ Group, design.df = traj_design)

error as follow:

traj_design
orig.ident Group
Normal1 Normal1 Normal
Normal2 Normal2 Normal
Normal3 Normal3 Normal
Normal4 Normal4 Normal
TBI1 TBI1 TBI
TBI2 TBI2 TBI
TBI3 TBI3 TBI
scRNA1 <- calcNhoodDistance(scRNA1, d=30)
rownames(traj_design) <- traj_design$orig.ident
da_results <- testNhoods(scRNA1, design = ~ Group, design.df = traj_design)
Using TMM normalisation
Performing spatial FDR correction withk-distance weighting
Error in testNhoods(scRNA1, design = ~Group, design.df = traj_design) :
lazy-load database 'C:/Users/ASUS/AppData/Local/R/win-library/4.3/miloR/R/miloR.rdb' is corrupt
此外: Warning message:
In testNhoods(scRNA1, design = ~Group, design.df = traj_design) :
internal error -3 in R_decompress1

I want to know where the error is in my code. I've downloaded and installed the latest version of MiloR from GitHub, but the issue still persists. What modifications do I need to make to my code?

@MikeDMorgan
Copy link
Member

If you don't include the output from sessionInfo() I can't help you.

@herong2006
Copy link
Author

sessionInfo() as follow:

sessionInfo()
R version 4.3.2 (2023-10-31 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 11 x64 (build 22621)

Matrix products: default

locale:
[1] LC_COLLATE=Chinese (Simplified)_China.utf8 LC_CTYPE=Chinese (Simplified)_China.utf8 LC_MONETARY=Chinese (Simplified)_China.utf8
[4] LC_NUMERIC=C LC_TIME=Chinese (Simplified)_China.utf8

time zone: Asia/Shanghai
tzcode source: internal

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

loaded via a namespace (and not attached):
[1] vctrs_0.6.5 cli_3.6.3 rlang_1.1.4 purrr_1.0.2 pkgload_1.4.0 promises_1.3.2 shiny_1.10.0
[8] xtable_1.8-4 glue_1.8.0 htmltools_0.5.8.1 httpuv_1.6.15 pkgbuild_1.4.7 ellipsis_0.3.2 fastmap_1.2.0
[15] lifecycle_1.0.4 memoise_2.0.1 BiocManager_1.30.25 compiler_4.3.2 miniUI_0.1.1.1 fs_1.6.5 sessioninfo_1.2.3
[22] htmlwidgets_1.6.4 Rcpp_1.0.13-1 urlchecker_1.0.1 rstudioapi_0.17.1 later_1.4.1 digest_0.6.37 R6_2.6.1
[29] usethis_3.1.0 magrittr_2.0.3 tools_4.3.2 mime_0.12 devtools_2.4.5 profvis_0.4.0 cachem_1.1.0
[36] remotes_2.5.0

Thank you

@herong2006
Copy link
Author

when i library all packages,i got sessionInfo() as follow:
library(stringr)
library(Seurat)
library(miloR)
library(SingleCellExperiment)
library(scater)
library(dplyr)
library(patchwork)
library(qs)

sessionInfo()
R version 4.3.2 (2023-10-31 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 11 x64 (build 22621)

Matrix products: default

locale:
[1] LC_COLLATE=Chinese (Simplified)_China.utf8 LC_CTYPE=Chinese (Simplified)_China.utf8 LC_MONETARY=Chinese (Simplified)_China.utf8
[4] LC_NUMERIC=C LC_TIME=Chinese (Simplified)_China.utf8

time zone: Asia/Shanghai
tzcode source: internal

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

other attached packages:
[1] qs_0.27.3 patchwork_1.3.0 dplyr_1.1.4 scater_1.30.1 ggplot2_3.5.1
[6] scuttle_1.12.0 SingleCellExperiment_1.24.0 SummarizedExperiment_1.32.0 Biobase_2.62.0 GenomicRanges_1.54.1
[11] GenomeInfoDb_1.38.8 IRanges_2.36.0 S4Vectors_0.40.2 BiocGenerics_0.48.1 MatrixGenerics_1.14.0
[16] matrixStats_1.4.1 miloR_2.1.3 edgeR_4.0.16 limma_3.58.1 Seurat_5.2.1
[21] SeuratObject_5.0.2 sp_2.1-4 stringr_1.5.1 devtools_2.4.5 usethis_3.1.0

loaded via a namespace (and not attached):
[1] RcppAnnoy_0.0.22 splines_4.3.2 later_1.4.1 bitops_1.0-9 tibble_3.2.1
[6] polyclip_1.10-7 fastDummies_1.7.5 lifecycle_1.0.4 globals_0.16.3 lattice_0.22-6
[11] MASS_7.3-60.0.1 magrittr_2.0.3 plotly_4.10.4 remotes_2.5.0 httpuv_1.6.15
[16] sctransform_0.4.1 spam_2.11-0 sessioninfo_1.2.3 pkgbuild_1.4.7 spatstat.sparse_3.1-0
[21] reticulate_1.40.0 cowplot_1.1.3 pbapply_1.7-2 RColorBrewer_1.1-3 abind_1.4-8
[26] pkgload_1.4.0 zlibbioc_1.48.2 Rtsne_0.17 purrr_1.0.2 ggraph_2.2.1
[31] RCurl_1.98-1.16 pracma_2.4.4 tweenr_2.0.3 GenomeInfoDbData_1.2.11 ggrepel_0.9.6
[36] irlba_2.3.5.1 listenv_0.9.1 spatstat.utils_3.1-3 goftest_1.2-3 RSpectra_0.16-2
[41] spatstat.random_3.3-2 fitdistrplus_1.2-2 parallelly_1.41.0 DelayedMatrixStats_1.24.0 codetools_0.2-20
[46] DelayedArray_0.28.0 RApiSerialize_0.1.4 ggforce_0.4.2 tidyselect_1.2.1 farver_2.1.2
[51] ScaledMatrix_1.10.0 viridis_0.6.5 spatstat.explore_3.3-3 jsonlite_1.8.9 BiocNeighbors_1.20.2
[56] ellipsis_0.3.2 tidygraph_1.3.1 progressr_0.15.1 ggridges_0.5.6 survival_3.8-3
[61] tools_4.3.2 ica_1.0-3 Rcpp_1.0.13-1 glue_1.8.0 gridExtra_2.3
[66] SparseArray_1.2.4 numDeriv_2016.8-1.1 withr_3.0.2 BiocManager_1.30.25 fastmap_1.2.0
[71] rsvd_1.0.5 digest_0.6.37 R6_2.6.1 mime_0.12 colorspace_2.1-1
[76] scattermore_1.2 gtools_3.9.5 tensor_1.5 spatstat.data_3.1-6 tidyr_1.3.1
[81] generics_0.1.3 data.table_1.16.4 graphlayouts_1.2.2 httr_1.4.7 htmlwidgets_1.6.4
[86] S4Arrays_1.2.1 uwot_0.2.2 pkgconfig_2.0.3 gtable_0.3.6 lmtest_0.9-40
[91] XVector_0.42.0 htmltools_0.5.8.1 profvis_0.4.0 dotCall64_1.2 scales_1.3.0
[96] png_0.1-8 spatstat.univar_3.1-1 rstudioapi_0.17.1 reshape2_1.4.4 nlme_3.1-168
[101] cachem_1.1.0 zoo_1.8-12 KernSmooth_2.23-24 vipor_0.4.7 parallel_4.3.2
[106] miniUI_0.1.1.1 pillar_1.10.1 grid_4.3.2 vctrs_0.6.5 RANN_2.6.2
[111] urlchecker_1.0.1 promises_1.3.2 stringfish_0.16.0 BiocSingular_1.18.0 beachmat_2.18.1
[116] xtable_1.8-4 cluster_2.1.8 beeswarm_0.4.0 cli_3.6.3 locfit_1.5-9.12
[121] compiler_4.3.2 rlang_1.1.4 crayon_1.5.3 future.apply_1.11.3 ggbeeswarm_0.7.2
[126] plyr_1.8.9 fs_1.6.5 stringi_1.8.4 viridisLite_0.4.2 deldir_2.0-4
[131] BiocParallel_1.36.0 munsell_0.5.1 lazyeval_0.2.2 spatstat.geom_3.3-4 Matrix_1.6-5
[136] RcppHNSW_0.6.0 sparseMatrixStats_1.14.0 future_1.34.0 statmod_1.5.0 shiny_1.10.0
[141] ROCR_1.0-11 igraph_2.1.2 memoise_2.0.1 RcppParallel_5.1.10

@MikeDMorgan
Copy link
Member

I'd strongly recommend updating to latest R (4.4.3) and Bioconductor (3.20) - the version of Milo you have is not the latest.

@herong2006
Copy link
Author

The version of miloR I am using is 2.1.3, downloaded the package from website at https://github.com/MarioniLab/miloR. May I ask where to download the latest version of miloR, and what is the latest version number?

@MikeDMorgan
Copy link
Member

As it says on the repo landing page:

## Milo is available from Bioconductor (preferred stable installation)
if (!requireNamespace("BiocManager", quietly = TRUE))
    install.packages("BiocManager")

BiocManager::install("miloR")

You need to update Bioconductor to the latest version: https://www.bioconductor.org/install/

@herong2006
Copy link
Author

Thank you

@herong2006
Copy link
Author

code as follow:
scRNA1 <- calcNhoodDistance(scRNA1, d=30)
rownames(traj_design) <- traj_design$orig.ident
da_results <- testNhoods(scRNA1, design = ~ Group, design.df = traj_design)

da_results %>%
arrange(- SpatialFDR) %>%
head()

plotUMAP(scRNA1) + plotNhoodGraphDA(scRNA1, da_results, alpha=0.05) +

  • plot_layout(guides="collect")

ggplot(da_results, aes(PValue)) + geom_histogram(bins=50)

scRNA1 <- buildNhoodGraph(scRNA1)
da_results <- annotateNhoods(scRNA1, da_results, coldata_col = "celltype")
head(da_results)
ggplot(da_results, aes(celltype_fraction)) + geom_histogram(bins=50)
da_results$celltype <- ifelse(da_results$celltype_fraction < 0.7, "Mixed", da_results$celltype)
dim(da_results)
unique(da_results$celltype)
plotDAbeeswarm(da_results, group.by = "celltype")

results as follow:

da_results %>%

  • arrange(- SpatialFDR) %>%
  • head()
    logFC logCPM F PValue FDR Nhood SpatialFDR
    7839 0.0018372519 7.203229 4.201819e-07 0.9994828 0.9995396 7839 0.9995396
    8613 -0.0003378292 6.751858 3.328996e-07 0.9995396 0.9995396 8613 0.9995396
    1268 -0.0018185543 6.698875 9.623325e-07 0.9992173 0.9993897 1268 0.9993314
    7902 -0.0021256938 6.314727 2.282021e-06 0.9987947 0.9990532 7902 0.9989896
    8789 -0.0028578066 6.553282 2.365185e-06 0.9987729 0.9990532 8789 0.9989896
    8922 -0.0036386152 6.835571 2.932497e-06 0.9986337 0.9990532 8922 0.9989401

scRNA1 <- buildNhoodGraph(scRNA1)
plotUMAP(scRNA1) + plotNhoodGraphDA(scRNA1, da_results, alpha=0.05) +

  • plot_layout(guides="collect")
    Adding nhood effect sizes to neighbourhood graph attributes

ggplot(da_results, aes(PValue)) + geom_histogram(bins=50)
da_results <- annotateNhoods(scRNA1, da_results, coldata_col = "celltype")
Converting celltype to factor...
head(da_results)
logFC logCPM F PValue FDR Nhood SpatialFDR celltype celltype_fraction
1 -2.641325 7.851987 0.7659455 0.38147789 0.5228889 1 0.5022718 Immune 0.9285714
2 4.274507 7.066683 2.7077264 0.09986865 0.2460492 2 0.2244751 ExN 0.9411765
3 -6.931837 7.611479 3.9979885 0.04555926 0.1749356 3 0.1518710 InN 1.0000000
4 3.068745 7.153488 1.5106656 0.21904254 0.3808521 4 0.3566222 InN 1.0000000
5 -3.774695 7.865194 1.3901037 0.23839243 0.3998058 5 0.3758232 Astro_RG 1.0000000
6 -4.052649 7.013778 2.0165519 0.15559749 0.3240748 6 0.2989748 Immune 0.9729730
ggplot(da_results, aes(celltype_fraction)) + geom_histogram(bins=50)
da_results$celltype <- ifelse(da_results$celltype_fraction < 0.7, "Mixed", da_results$celltype)
plotDAbeeswarm(da_results, group.by = "celltype")
Converting group_by to factor...
Error in scale_color_gradient2():
! Discrete values supplied to continuous scale.
ℹ Example values: NA, NA, NA, NA, and NA
Run rlang::last_trace() to see where the error occurred.
dim(da_results)
[1] 11592 9

unique(da_results$celltype)
[1] "Immune" "ExN" "InN" "Astro_RG" "Epend" "Mixed" "OPC" "Oligo" "VASC"
plotDAbeeswarm(da_results, group.by = "celltype")
Converting group_by to factor...
Error in scale_color_gradient2():
! Discrete values supplied to continuous scale.
ℹ Example values: NA, NA, NA, NA, and NA
Run rlang::last_trace() to see where the error occurred.
what's wrong in the code:plotDAbeeswarm(da_results, group.by = "celltype")

@herong2006
Copy link
Author

I found this issue (Error in scale_color_gradient2()) in (#321), so I tried to solve it according to issue 321, but the problem wasn't resolved. I have raised the error issue again in issue 321.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
0