drieslab / Giotto

Spatial omics analysis toolbox
https://drieslab.github.io/Giotto_website/
Other
240 stars 95 forks source link

Error while running runDWLSDeconv #295

Closed AhmedAmineAnzali closed 1 year ago

AhmedAmineAnzali commented 1 year ago

Hello,

I have been trying to run DWLS deconvolution on some visium spatial data, however I have been getting the following error:

DWLS_matrix<-makeSignMatrixDWLSfromMatrix(matrix = as.matrix(get_expression_values(giotto_SC,values = "normalized")), cell_type = pDataDT(giotto_SC)$cell_annotations, sign_gene = top_markers$feats) visium_kidney = runDWLSDeconv(gobject = visium_kidney, sign_matrix = DWLS_matrix)

Error in if (out == "quadprog.indifinite.error") { : the condition has length > 1

For more context, I am running R version 4.2.0 and Giotto version 2.0.0.988.

Giotto:::checkGiottoEnvironment()

giotto environment found at C:/Users/AppData/Local/r-miniconda\envs\giotto_env\python.exe [1] TRUE

Giotto:::showProcessingSteps(visium_kidney) Processing steps:

0_subset

1_subset

2_filter

3_normalize

4_feat_stats

5_cell_stats

6_hvf name info: hvf HVFplot

7_pca

8_umap

9_nn_network name info: sNN.pca

10_cluster name info: leiden_clus sNN.pca

11_spatial_enrichment name info: hypergeometric

str(visium_kidney, max.level = 3) Formal class 'giotto' [package "Giotto"] with 21 slots ..@ expression :List of 1 .. ..$ cell:List of 1 ..@ expression_feat : chr "rna" ..@ spatial_locs :List of 1 .. ..$ cell:List of 1 ..@ spatial_info : NULL ..@ cell_metadata :List of 1 .. ..$ cell:List of 1 ..@ feat_metadata :List of 1 .. ..$ cell:List of 1 ..@ feat_info : NULL ..@ cell_ID :List of 1 .. ..$ cell: Named chr [1:3341] "AAACAAGTATCTCCCA-1" "AAACAATCTACTAGCA-1" "AAACACCAATAACTGC-1" "AAACAGAGCGACTCCT-1" ... .. .. ..- attr(, "names")= chr [1:3341] "2" "3" "4" "5" ... ..@ feat_ID :List of 1 .. ..$ rna: Named chr [1:16725] "OR4F5" "SAMD11" "NOC2L" "KLHL17" ... .. .. ..- attr(, "names")= chr [1:16725] "3" "24" "25" "26" ... ..@ spatial_network : NULL ..@ spatial_grid : NULL ..@ spatial_enrichment :List of 1 .. ..$ cell:List of 1 ..@ dimension_reduction:List of 1 .. ..$ cells:List of 1 ..@ nn_network :List of 1 .. ..$ cell:List of 1 ..@ images :List of 1 .. ..$ image:Formal class 'giottoImage' [package "Giotto"] with 8 slots ..@ largeImages : NULL ..@ parameters :List of 12 .. ..$ 0_subset : Named chr [1:6] "visium_kidney" "in_tissue_barcodes" "TRUE" "2" ... .. .. ..- attr(, "names")= chr [1:6] "gobject" "cell_ids" "verbose" "toplevel_params" ... .. ..$ 1_subset : Named chr [1:10] "gobject" "spat_unit" "feat_type" "selected_cell_ids" ... .. .. ..- attr(, "names")= chr [1:10] "gobject" "spat_unit" "feat_type" "cell_ids" ... .. ..$ 2_filter : Named chr [1:7] "visium_kidney" "raw" "1" "50" ... .. .. ..- attr(, "names")= chr [1:7] "gobject" "expression_values" "expression_threshold" "feat_det_in_min_cells" ... .. ..$ 3_normalize : Named chr [1:14] "visium_kidney" "raw" "standard" "TRUE" ... .. .. ..- attr(, "names")= chr [1:14] "gobject" "expression_values" "norm_methods" "library_size_norm" ... .. ..$ 4_feat_stats : Named chr [1:4] "visium_kidney" "normalized" "0" "TRUE" .. .. ..- attr(, "names")= chr [1:4] "gobject" "expression_values" "detection_threshold" "return_gobject" .. ..$ 5_cell_stats : Named chr [1:4] "visium_kidney" "normalized" "0" "TRUE" .. .. ..- attr(, "names")= chr [1:4] "gobject" "expression_values" "detection_threshold" "return_gobject" .. ..$ 6_hvf : Named chr [1:17] "visium_kidney" "normalized" "cov_groups" "FALSE" ... .. .. ..- attr(, "names")= chr [1:17] "gobject" "expression_values" "method" "reverse_log_scale" ... .. ..$ 7_pca : Named chr [1:15] "visium_kidney" "normalized" "cells" "hvf" ... .. .. ..- attr(, "names")= chr [1:15] "gobject" "expression_values" "reduction" "feats_to_use" ... .. ..$ 8_umap : Named chr [1:17] "visium_kidney" "normalized" "cells" "pca" ... .. .. ..- attr(, "names")= chr [1:17] "gobject" "expression_values" "reduction" "dim_reduction_to_use" ... .. ..$ 9_nn_network : Named chr [1:12] "visium_kidney" "sNN" "pca" "1:30" ... .. .. ..- attr(, "names")= chr [1:12] "gobject" "type" "dim_reduction_to_use" "dimensions_to_use" ... .. ..$ 10_cluster : Named chr [1:11] "visium_kidney" "leiden_clus" "sNN" "sNN.pca" ... .. .. ..- attr(, "names")= chr [1:11] "gobject" "name" "nn_network_to_use" "network_name" ... .. ..$ 11_spatial_enrichment: Named chr [1:9] "rank" "hypergeometric" "normalized" "TRUE" ... .. .. ..- attr(, "names")= chr [1:9] "method used" "enrichment name" "expression values" "reverse log scale" ... ..@ instructions :List of 11 .. ..$ python_path: chr "C:/Users/anzal/AppData/Local/r-miniconda\envs\giotto_env\python.exe" .. ..$ show_plot : logi FALSE .. ..$ return_plot: logi TRUE .. ..$ save_plot : logi TRUE .. ..$ save_dir : chr "/path/to/directory/" .. ..$ plot_format: chr "png" .. ..$ dpi : num 300 .. ..$ units : chr "in" .. ..$ height : num 9 .. ..$ width : num 9 .. ..$ is_docker : logi FALSE ..@ offset_file : NULL ..@ OS_platform : chr "windows" ..@ join_info : NULL

ZengTaox commented 1 year ago

Because there are some mistakes in this version. In https://github.com/RubD/Giotto/blob/suite/R/spatial_enrichment.R, line 1734 and line 1754 have mistakes. Changing if(out == 'final.error') {into if('final.error' %in% out) and changing if(out == 'quadprog.indifinite.error') { into if( 'quadprog.indifinite.error' %in% out) { can fix this problem.

criphg commented 1 year ago

I have the same problem here and your link not work for me. Could you please help us with more details to solve this problem? Thank you.

sessionInfo() R version 4.2.1 (2022-06-23) 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/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
[3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=en_US.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

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

other attached packages: [1] Giotto_2.0.0.998 Matrix_1.5-1

loaded via a namespace (and not attached): [1] bitops_1.0-7 matrixStats_0.62.0
[3] rprojroot_2.0.3 GenomeInfoDb_1.33.7
[5] tools_4.2.1 utf8_1.2.2
[7] R6_2.5.1 irlba_2.3.5
[9] DBI_1.1.3 BiocGenerics_0.43.4
[11] colorspace_2.0-3 tidyselect_1.1.2
[13] compiler_4.2.1 cli_3.4.1
[15] Biobase_2.57.1 BiocNeighbors_1.15.1
[17] DelayedArray_0.23.2 labeling_0.4.2
[19] scales_1.2.1 quadprog_1.5-8
[21] rappdirs_0.3.3 digest_0.6.29
[23] dbscan_1.1-10 XVector_0.37.1
[25] pkgconfig_2.0.3 htmltools_0.5.3
[27] sparseMatrixStats_1.9.0 MatrixGenerics_1.9.1
[29] fastmap_1.1.0 limma_3.53.9
[31] rlang_1.0.6 rstudioapi_0.14
[33] shiny_1.7.2 DelayedMatrixStats_1.19.0
[35] farver_2.1.1 generics_0.1.3
[37] jsonlite_1.8.0 BiocParallel_1.31.12
[39] dplyr_1.0.10 RCurl_1.98-1.8
[41] magrittr_2.0.3 BiocSingular_1.13.1
[43] GenomeInfoDbData_1.2.8 scuttle_1.7.4
[45] Rcpp_1.0.9 munsell_0.5.0
[47] S4Vectors_0.35.4 fansi_1.0.3
[49] reticulate_1.26 lifecycle_1.0.2
[51] RcppZiggurat_0.1.6 edgeR_3.39.6
[53] SummarizedExperiment_1.27.3 zlibbioc_1.43.0
[55] grid_4.2.1 parallel_4.2.1
[57] promises_1.2.0.1 dqrng_0.3.0
[59] miniUI_0.1.1.1 lattice_0.20-45
[61] cowplot_1.1.1 beachmat_2.13.4
[63] locfit_1.5-9.6 metapod_1.5.0
[65] knitr_1.40 pillar_1.8.1
[67] igraph_1.3.5 GenomicRanges_1.49.1
[69] codetools_0.2-18 ScaledMatrix_1.5.1
[71] stats4_4.2.1 glue_1.6.2
[73] scran_1.25.1 data.table_1.14.2
[75] png_0.1-7 vctrs_0.4.1
[77] httpuv_1.6.6 gtable_0.3.1
[79] purrr_0.3.4 assertthat_0.2.1
[81] ggplot2_3.3.6 xfun_0.33
[83] rsvd_1.0.5 mime_0.12
[85] Rfast_2.0.6 xtable_1.8-4
[87] later_1.3.0 SingleCellExperiment_1.19.0 [89] tibble_3.1.8 IRanges_2.31.2
[91] cluster_2.1.4 bluster_1.7.0
[93] statmod_1.4.37 ellipsis_0.3.2
[95] here_1.0.1

ZengTaox commented 1 year ago

@criphg Codes in the link have some mistakes, as out == 'final.error' and out == 'quadprog.indifinite.error' can generate a logical vector which many longer than 1. This can arise error in if condition. Changing if(out == 'final.error')into if('final.error' %in% out) and changing if(out == 'quadprog.indifinite.error') into if( 'quadprog.indifinite.error' %in% out) and rebuild the package can fix this problem. And the codes with problems are here https://github.com/RubD/Giotto/blob/suite/R/spatial_enrichment.R

XuanCao-CX commented 1 year ago

Hi @AhmedAmineAnzali,

Could you please share the data "giotto_SC" and "visium_kidney" that you have been getting the error? So I can try to fix this error?

Best, Xuan

tdyoshida commented 1 year ago

Hi, has this problem been solved? I got the same issue running Mouse Visium Brain tutorial.

visium_brain = runDWLSDeconv(gobject = visium_brain, sign_matrix = DWLS_matrix)

Error in if (out == "quadprog.indifinite.error") { : the condition has length > 1

The code up to this section (7.4) worked fine.

I got the same error when I did the following as well: (1) Run the tutorial on my other Linux/Ubuntu machine. (2) Run the same processes on my own Visium spatial and scRNA-seq dataset. Thus I don't suppose the error is system-specific or data-specific.

Below are my environment and data info. sessionInfo()

R version 4.2.1 (2022-06-23) Platform: aarch64-apple-darwin20 (64-bit) Running under: macOS Monterey 12.2.1

Matrix products: default BLAS: /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/lib/li bRblas.0.dylib LAPACK: /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/lib/li bRlapack.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] stats graphics grDevices utils datasets methods base

other attached packages: [1] Giotto_2.0.0.998 glue_1.6.2 nvimcom_0.9-115

loaded via a namespace (and not attached): [1] bitops_1.0-7 matrixStats_0.62.0 [3] RColorBrewer_1.1-3 GenomeInfoDb_1.34.2 [5] tools_4.2.1 utf8_1.2.2 [7] R6_2.5.1 irlba_2.3.5.1 [9] uwot_0.1.14 DBI_1.1.3 [11] BiocGenerics_0.44.0 colorspace_2.0-3 [13] withr_2.5.0 tidyselect_1.2.0 [15] compiler_4.2.1 textshaping_0.3.6 [17] cli_3.4.1 Biobase_2.58.0 [19] BiocNeighbors_1.16.0 DelayedArray_0.24.0 [21] labeling_0.4.2 scales_1.2.1 [23] quadprog_1.5-8 systemfonts_1.0.4 [25] stringr_1.4.1 dbscan_1.1-11 [27] R.utils_2.12.1 XVector_0.38.0 [29] pkgconfig_2.0.3 sparseMatrixStats_1.10.0 [31] MatrixGenerics_1.10.0 limma_3.54.0 [33] rlang_1.0.6 FNN_1.1.3.1 [35] DelayedMatrixStats_1.20.0 farver_2.1.1 [37] generics_0.1.3 jsonlite_1.8.3 [39] BiocParallel_1.32.1 dplyr_1.0.10 [41] R.oo_1.25.0 RCurl_1.98-1.9 [43] magrittr_2.0.3 BiocSingular_1.14.0 [45] GenomeInfoDbData_1.2.9 scuttle_1.8.0 [47] Matrix_1.5-1 Rcpp_1.0.9 [49] munsell_0.5.0 S4Vectors_0.36.0 [51] fansi_1.0.3 reticulate_1.26 [53] RcppZiggurat_0.1.6 lifecycle_1.0.3 [55] R.methodsS3_1.8.2 stringi_1.7.8 [57] edgeR_3.40.0 SummarizedExperiment_1.28.0 [59] zlibbioc_1.44.0 Rtsne_0.16 [61] plyr_1.8.7 grid_4.2.1 [63] parallel_4.2.1 ggrepel_0.9.2 [65] dqrng_0.3.0 lattice_0.20-45 [67] cowplot_1.1.1 beachmat_2.14.0 [69] locfit_1.5-9.6 magick_2.7.3 [71] metapod_1.6.0 pillar_1.8.1 [73] igraph_1.3.5 GenomicRanges_1.50.1 [75] reshape2_1.4.4 codetools_0.2-18 [77] ScaledMatrix_1.6.0 stats4_4.2.1 [79] scran_1.26.0 data.table_1.14.4 [81] png_0.1-7 vctrs_0.5.0 [83] gtable_0.3.1 assertthat_0.2.1 [85] ggplot2_3.4.0 rsvd_1.0.5 [87] Rfast_2.0.6 ragg_1.2.4 [89] SingleCellExperiment_1.20.0 tibble_3.1.8 [91] IRanges_2.32.0 cluster_2.1.4 [93] bluster_1.8.0 statmod_1.4.37

packageVersion("Giotto")

‘2.0.0.998’

Giotto::checkGiottoEnvironment()

giotto environment found at /Users/tdyoshida/Library/r-miniconda-arm64/envs/giotto_env/bin/pythonw

Giotto::showProcessingSteps(visium_brain)

Processing steps: 0_subset 1_subset 2_filter 3_normalize 4_feat_stats 5_cell_stats 6_hvf name info: hvf HVFplot 7_pca 8_umap 9_tsne 10_nn_network name info: sNN.pca 11_cluster name info: leiden_clus sNN.pca 12_spatial_enrichment name info: PAGE 13_spatial_enrichment name info: hypergeometric 14_spatial_enrichment name info: rank

Giotto::showProcessingSteps(giotto_SC)

Processing steps: 0_normalize

Also, this is a separate issue, but when I run getSpatialDataset(dataset = 'Mouse_brain_scRNAseq', directory = results_folder) I got an error:

could not find function "getSpatialDataset"

So I used the file in spatial-datasets repo

I tried the solution suggested by @ZengTaox, but it did not work (although I'm not entirely sure I did what was suggested).

Thank you for your help!

V2O5-666 commented 1 year ago

@ZengTaox Hi, I meet the same issue and I can understand your solution. But I really don't how to rebuild the package. Would you please explain it in more detail?Please. Thank so much.

mattobny commented 1 year ago

419 Fixes this error; the function runDWLSDeconv() should now run smoothly.

tdyoshida commented 1 year ago

Now it's working. Thank you so much!

RubD commented 1 year ago

@ZengTaox Hi, I meet the same issue and I can understand your solution. But I really don't how to rebuild the package. Would you please explain it in more detail?Please. Thank so much.

The simplest way would be to reinstall Giotto with devtools::install_github("drieslab/Giotto@suite")

RubD commented 1 year ago

Thanks for fixing this issue @mattobny