LieberInstitute / spatialLIBD

Code for the spatialLIBD R/Bioconductor package and shiny app
http://LieberInstitute.github.io/spatialLIBD/
78 stars 16 forks source link

[BUG] Reporting of Missing Genes in Spot Plots multi-gene functionality #83

Open cyntsc opened 1 month ago

cyntsc commented 1 month ago

The multi-gene function fails if the genes requested report no expression variation in some slides (samples).

I have encountered an exception when certain genes are not present in some slides. The multigene function only fails if the gene search reports no expression variation when more than 2 genes are requested. Note. This feature does not fail when plotting one gene at a time, even if the gene has no variation on 1 or more slides.

Example using https://libd.shinyapps.io/Habenula_Visium/

  1. I selected Gene_grid (Static) tab.
  2. In continuos variables checkbox, I only selected CHAT gene ["CHAT; ENSG00000070748"]
image

You may notice that gene variations are not reported on the top slides, but are reported on the bottom slides. The spotplot can be displayed with no issues.

  1. Next, I selected TAC gene (now I am using multi-gene selection with 2 genes) ["TAC1; ENSG00000006128" "CHAT; ENSG00000070748"]
image

You may notice, spotplot visualization fails when using both gene.

  1. The same request selection by code ["TAC1; ENSG00000006128" "CHAT; ENSG00000070748"], reports next error:
    Error in `map2()`:
    ℹ In index: 1.
    Caused by error:
    ! After dropping features with no expression variation, less than 2 features were left. This error can occur when using data from only 1 spot.
    Run `rlang::last_trace()` to see where the error occurred.
    > lst_Habenula
    [1] "TAC1; ENSG00000006128" "CHAT; ENSG00000070748"

    Note that running gen by gen does not generate an error. Therefore, I think this simply occurs when more than one gene is mapped at a time.

Expected behavior

I would like to obtain spot plots that display variations in genes, even if the data is partial. It also would be very useful to have an informative message indicating which genes are missing (at least in general). This notification would allow users to take appropriate steps to explore and address the incomplete data.

Implementing this feature would greatly improve the user experience by providing crucial information about the dataset's completeness and enabling more informed analysis.

R Session Information

[1] "Reproducibility information:"

Sys.time() [1] "2024-07-11 12:09:15 EDT" proc.time() user system elapsed 68.417 2.262 2990.522 options(width = 120) session_info() .8 2022-06-12 [2] CRAN (R 4.3.2) benchmarkmeData 1.0.4 2020-04-23 [2] CRAN (R 4.3.2) Biobase 2.62.0 2023-10-24 [2] Bioconductor BiocFileCache 2.10.1 2023-10-26 [2] Bioconductor BiocGenerics 0.48.1 2023-11-01 [2] Bioconductor BiocIO 1.12.0 2023-10-24 [2] Bioconductor BiocManager 1.30.22 2023-08-08 [2] CRAN (R 4.3.2) BiocNeighbors 1.20.2 2024-01-07 [2] Bioconductor 3.18 (R 4.3.2) BiocParallel 1.36.0 2023-10-24 [2] Bioconductor BiocSingular 1.18.0 2023-10-24 [2] Bioconductor BiocVersion 3.18.1 2023-11-15 [2] Bioconductor Biostrings 2.70.2 2024-01-28 [2] Bioconductor 3.18 (R 4.3.2) bit 4.0.5 2022-11-15 [2] CRAN (R 4.3.2) bit64 4.0.5 2020-08-30 [2] CRAN (R 4.3.2) bitops 1.0-7 2021-04-24 [2] CRAN (R 4.3.2) blob 1.2.4 2023-03-17 [2] CRAN (R 4.3.2) bslib 0.6.1 2023-11-28 [2] CRAN (R 4.3.2) cachem 1.0.8 2023-05-01 [2] CRAN (R 4.3.2) cellranger 1.1.0 2016-07-27 [2] CRAN (R 4.3.2) cli 3.6.2 2023-12-11 [2] CRAN (R 4.3.2) codetools 0.2-19 2023-02-01 [3] CRAN (R 4.3.2) colorspace 2.1-0 2023-01-23 [2] CRAN (R 4.3.2) config 0.3.2 2023-08-30 [2] CRAN (R 4.3.2) cowplot 1.1.3 2024-01-22 [2] CRAN (R 4.3.2) crayon 1.5.2 2022-09-29 [2] CRAN (R 4.3.2) curl 5.2.0 2023-12-08 [2] CRAN (R 4.3.2) data.table 1.15.0 2024-01-30 [2] CRAN (R 4.3.2) DBI 1.2.1 2024-01-12 [2] CRAN (R 4.3.2) dbplyr 2.4.0 2023-10-26 [2] CRAN (R 4.3.2) DelayedArray 0.28.0 2023-10-24 [2] Bioconductor DelayedMatrixStats 1.24.0 2023-10-24 [2] Bioconductor digest 0.6.34 2024-01-11 [2] CRAN (R 4.3.2) doParallel 1.0.17 2022-02-07 [2] CRAN (R 4.3.2) dotCall64 1.1-1 2023-11-28 [2] CRAN (R 4.3.2) dplyr 1.1.4 2023-11-17 [2] CRAN (R 4.3.2) DT 0.31 2023-12-09 [2] CRAN (R 4.3.2) edgeR 4.0.14 2024-01-29 [2] Bioconductor 3.18 (R 4.3.2) ellipsis 0.3.2 2021-04-29 [2] CRAN (R 4.3.2) ExperimentHub 2.10.0 2023-10-24 [2] Bioconductor fansi 1.0.6 2023-12-08 [2] CRAN (R 4.3.2) farver 2.1.1 2022-07-06 [2] CRAN (R 4.3.2) fastmap 1.1.1 2023-02-24 [2] CRAN (R 4.3.2) fields 15.2 2023-08-17 [2] CRAN (R 4.3.2) filelock 1.0.3 2023-12-11 [2] CRAN (R 4.3.2) forcats 1.0.0 2023-01-29 [2] CRAN (R 4.3.2) foreach 1.5.2 2022-02-02 [2] CRAN (R 4.3.2) generics 0.1.3 2022-07-05 [2] CRAN (R 4.3.2) GenomeInfoDb 1.38.5 2023-12-28 [2] Bioconductor 3.18 (R 4.3.2) GenomeInfoDbData 1.2.11 2024-02-09 [2] Bioconductor GenomicAlignments 1.38.2 2024-01-16 [2] Bioconductor 3.18 (R 4.3.2) GenomicRanges 1.54.1 2023-10-29 [2] Bioconductor ggbeeswarm 0.7.2 2023-04-29 [2] CRAN (R 4.3.2) ggplot2 3.4.4 2023-10-12 [2] CRAN (R 4.3.2) ggrepel 0.9.5 2024-01-10 [2] CRAN (R 4.3.2) glue 1.7.0 2024-01-09 [2] CRAN (R 4.3.2) golem 0.4.1 2023-06-05 [2] CRAN (R 4.3.2) gridExtra 2.3 2017-09-09 [2] CRAN (R 4.3.2) gtable 0.3.4 2023-08-21 [2] CRAN (R 4.3.2) HDF5Array 1.30.0 2023-10-24 [2] Bioconductor here 1.0.1 2020-12-13 [2] CRAN (R 4.3.2) hms 1.1.3 2023-03-21 [2] CRAN (R 4.3.2) htmltools 0.5.7 2023-11-03 [2] CRAN (R 4.3.2) htmlwidgets 1.6.4 2023-12-06 [2] CRAN (R 4.3.2) httpuv 1.6.14 2024-01-26 [2] CRAN (R 4.3.2) httr 1.4.7 2023-08-15 [2] CRAN (R 4.3.2) interactiveDisplayBase 1.40.0 2023-10-24 [2] Bioconductor IRanges 2.36.0 2023-10-24 [2] Bioconductor irlba 2.3.5.1 2022-10-03 [2] CRAN (R 4.3.2) iterators 1.0.14 2022-02-05 [2] CRAN (R 4.3.2) jquerylib 0.1.4 2021-04-26 [2] CRAN (R 4.3.2) jsonlite 1.8.8 2023-12-04 [2] CRAN (R 4.3.2) KEGGREST 1.42.0 2023-10-24 [2] Bioconductor labeling 0.4.3 2023-08-29 [2] CRAN (R 4.3.2) later 1.3.2 2023-12-06 [2] CRAN (R 4.3.2) lattice 0.22-5 2023-10-24 [3] CRAN (R 4.3.2) lazyeval 0.2.2 2019-03-15 [2] CRAN (R 4.3.2) lifecycle 1.0.4 2023-11-07 [2] CRAN (R 4.3.2) limma 3.58.1 2023-10-31 [2] Bioconductor lobstr 1.1.2 2022-06-22 [2] CRAN (R 4.3.2) locfit 1.5-9.8 2023-06-11 [2] CRAN (R 4.3.2) lubridate 1.9.3 2023-09-27 [2] CRAN (R 4.3.2) magick 2.8.2 2023-12-20 [2] CRAN (R 4.3.2) magrittr 2.0.3 2022-03-30 [2] CRAN (R 4.3.2) maps 3.4.2 2023-12-15 [2] CRAN (R 4.3.2) Matrix 1.6-5 2024-01-11 [3] CRAN (R 4.3.2) MatrixGenerics 1.14.0 2023-10-24 [2] Bioconductor matrixStats 1.2.0 2023-12-11 [2] CRAN (R 4.3.2) memoise 2.0.1 2021-11-26 [2] CRAN (R 4.3.2) mime 0.12 2021-09-28 [2] CRAN (R 4.3.2) munsell 0.5.0 2018-06-12 [2] CRAN (R 4.3.2) paletteer 1.6.0 2024-01-21 [2] CRAN (R 4.3.2) pillar 1.9.0 2023-03-22 [2] CRAN (R 4.3.2) pkgconfig 2.0.3 2019-09-22 [2] CRAN (R 4.3.2) plotly 4.10.4 2024-01-13 [2] CRAN (R 4.3.2) png 0.1-8 2022-11-29 [2] CRAN (R 4.3.2) promises 1.2.1 2023-08-10 [2] CRAN (R 4.3.2) purrr 1.0.2 2023-08-10 [2] CRAN (R 4.3.2) R6 2.5.1 2021-08-19 [2] CRAN (R 4.3.2) rappdirs 0.3.3 2021-01-31 [2] CRAN (R 4.3.2) RColorBrewer 1.1-3 2022-04-03 [2] CRAN (R 4.3.2) Rcpp 1.0.12 2024-01-09 [2] CRAN (R 4.3.2) RCurl 1.98-1.14 2024-01-09 [2] CRAN (R 4.3.2) readr 2.1.5 2024-01-10 [2] CRAN (R 4.3.2) readxl 1.4.3 2023-07-06 [2] CRAN (R 4.3.2) rematch2 2.1.2 2020-05-01 [2] CRAN (R 4.3.2) restfulr 0.0.15 2022-06-16 [2] CRAN (R 4.3.2) rhdf5 2.46.1 2023-11-29 [2] Bioconductor 3.18 (R 4.3.2) rhdf5filters 1.14.1 2023-11-06 [2] Bioconductor Rhdf5lib 1.24.2 2024-02-07 [2] Bioconductor 3.18 (R 4.3.2) rjson 0.2.21 2022-01-09 [2] CRAN (R 4.3.2) rlang 1.1.3 2024-01-10 [2] CRAN (R 4.3.2) rprojroot 2.0.4 2023-11-05 [2] CRAN (R 4.3.2) Rsamtools 2.18.0 2023-10-24 [2] Bioconductor RSQLite 2.3.5 2024-01-21 [2] CRAN (R 4.3.2) rsvd 1.0.5 2021-04-16 [2] CRAN (R 4.3.2) rtracklayer 1.62.0 2023-10-24 [2] Bioconductor S4Arrays 1.2.0 2023-10-24 [2] Bioconductor S4Vectors 0.40.2 2023-11-23 [2] Bioconductor 3.18 (R 4.3.2) sass 0.4.8 2023-12-06 [2] CRAN (R 4.3.2) ScaledMatrix 1.10.0 2023-10-24 [2] Bioconductor scales 1.3.0 2023-11-28 [2] CRAN (R 4.3.2) scater 1.30.1 2023-11-16 [2] Bioconductor scuttle 1.12.0 2023-10-24 [2] Bioconductor sessioninfo 1.2.2 2021-12-06 [2] CRAN (R 4.3.2) shiny 1.8.0 2023-11-17 [2] CRAN (R 4.3.2) shinyWidgets 0.8.1 2024-01-10 [2] CRAN (R 4.3.2) SingleCellExperiment 1.24.0 2023-10-24 [2] Bioconductor spam 2.10-0 2023-10-23 [2] CRAN (R 4.3.2) SparseArray 1.2.3 2023-12-25 [2] Bioconductor 3.18 (R 4.3.2) sparseMatrixStats 1.14.0 2023-10-24 [2] Bioconductor SpatialExperiment 1.12.0 2023-10-24 [2] Bioconductor spatialLIBD 1.15.4 2024-05-01 [1] Github (LieberInstitute/spatialLIBD@77a5303) statmod 1.5.0 2023-01-06 [2] CRAN (R 4.3.2) stringi 1.8.3 2023-12-11 [2] CRAN (R 4.3.2) stringr 1.5.1 2023-11-14 [2] CRAN (R 4.3.2) SummarizedExperiment 1.32.0 2023-10-24 [2] Bioconductor tibble 3.2.1 2023-03-20 [2] CRAN (R 4.3.2) tidyr 1.3.1 2024-01-24 [2] CRAN (R 4.3.2) tidyselect 1.2.0 2022-10-10 [2] CRAN (R 4.3.2) tidyverse 2.0.0 2023-02-22 [2] CRAN (R 4.3.2) timechange 0.3.0 2024-01-18 [2] CRAN (R 4.3.2) tzdb 0.4.0 2023-05-12 [2] CRAN (R 4.3.2) utf8 1.2.4 2023-10-22 [2] CRAN (R 4.3.2) vctrs 0.6.5 2023-12-01 [2] CRAN (R 4.3.2) vipor 0.4.7 2023-12-18 [2] CRAN (R 4.3.2) viridis 0.6.5 2024-01-29 [2] CRAN (R 4.3.2) viridisLite 0.4.2 2023-05-02 [2] CRAN (R 4.3.2)

Additional Context

This is the RScript used, you can run the script and uncommented the line below to reproduce the bug

https://github.com/LieberInstitute/Habenula_Visium/blob/facfbbf6c03286d95469395ccdd99e206100aa38/code/04_harmony_BayesSpace/05-multi_gene_selection.R#L208

lst_Habenula <- lst_Habenula[1:2]

Cynthia SC

lcolladotor commented 1 month ago

Looks like we could use https://github.com/daattali/shinyalert to provide more informative error messages.