drieslab / Giotto

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

Cannot display images after loadGiotto() #541

Open swbioinf opened 1 year ago

swbioinf commented 1 year ago

If I run the following, everything looks ok - image is plotted.

library(Giotto)
go <- createGiottoCosMxObject(cosmx_dir = "~/theFlatfileDir",  data_to_use = 'subcellular',  FOVs = 1)
saveGiotto(go, dir = getwd(),   foldername = "gosave", overwrite = T)

spatInSituPlotPoints(go, show_image=TRUE, use_overlap = FALSE, feats = list('rna' = c("JCHAIN")))

But, if I reload from that save, it appears the image filepath isn't found: go.reloaded <- loadGiotto(file.path(getwd(),"gosave"))

The loading message says filepath not found.

...

  1. read Giotto image information Attempting automatic reconnection...

image(s) discovered... --> image : filepath NOT found

image : no filepaths found. Skipping. ...

The contents of go@images[["image"]]@file_path is NULL.

I understand I should probably use reconnectGiottoImage() as a fix? (I'm still working on the right way to provide filepaths for that). But am I right in thinking that these paths should normally be recorded at the createGiottoCosMxObject() stage so auto-reconnect can work? Any suggestions of how I could get them into the go object upon load?

(NB: Have the same problem when loading multiple FOVs, the names are stored, but paths are not)

Giotto suite v3.2

Thanks!

> sessionInfo()
R version 4.1.0 (2021-05-18)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 20.04.5 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.9.0
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.9.0

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

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

other attached packages:
[1] Giotto_3.2      workflowr_1.6.2

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.10            lubridate_1.7.10       lattice_0.20-44        png_0.1-7              Biostrings_2.60.1      assertthat_0.2.1       digest_0.6.27         
 [8] utf8_1.2.1             R6_2.5.0               GenomeInfoDb_1.28.0    stats4_4.1.0           RSQLite_2.2.7          evaluate_0.14          httr_1.4.2            
[15] ggplot2_3.3.5          pillar_1.6.1           zlibbioc_1.38.0        rlang_0.4.11           rstudioapi_0.13        data.table_1.14.0      blob_1.2.1            
[22] S4Vectors_0.30.0       Matrix_1.3-4           reticulate_1.20        rmarkdown_2.9          RCurl_1.98-1.3         bit_4.0.4              munsell_0.5.0         
[29] compiler_4.1.0         httpuv_1.6.1           xfun_0.24              pkgconfig_2.0.3        BiocGenerics_0.38.0    htmltools_0.5.1.1      tidyselect_1.1.1      
[36] KEGGREST_1.32.0        tibble_3.1.2           GenomeInfoDbData_1.2.6 IRanges_2.26.0         codetools_0.2-18       fansi_0.5.0            crayon_1.4.1          
[43] dplyr_1.0.7            later_1.2.0            rappdirs_0.3.3         bitops_1.0-7           grid_4.1.0             jsonlite_1.7.2         gtable_0.3.0          
[50] lifecycle_1.0.0        DBI_1.1.1              magrittr_2.0.1         scales_1.1.1           cachem_1.0.5           XVector_0.32.0         fs_1.5.0              
[57] promises_1.2.0.1       ellipsis_0.3.2         vctrs_0.3.8            generics_0.1.0         RcppAnnoy_0.0.18       tools_4.1.0            bit64_4.0.5           
[64] Biobase_2.52.0         glue_1.4.2             purrr_0.3.4            parallel_4.1.0         fastmap_1.1.0          AnnotationDbi_1.54.1   colorspace_2.0-2      
[71] terra_1.6-47           memoise_2.0.0          knitr_1.33            
swbioinf commented 1 year ago

An update: Turns out file paths are in largeImages, not images. I can plot from go.reload, so long as I specify the large image name.

spatInSituPlotPoints(go.reloaded, 
                     show_image=TRUE, 
                     largeImage_name = "composite",
                     use_overlap = FALSE, feats = list('rna' = c("JCHAIN")))

So my immediate question is answered, I can produce the plots. But is there a cleaner way I should do this?

Why have I got an image with name 'image' (in a single fov object) with a null file_path? And why does that same command (without specifing large images) work when its freshly loaded?

Contents of my object are as follows;

Thanks again.

MomenehForoutan commented 10 months ago

Thanks Sarah for asking this; I am facing a similar scenario atm. I am using Giotto v3.3.1, and I am running my code on AWS EC2 instance. So I have processed the data and have been working on it for a couple of days now. I intentionally did not shout down the instance to avoid having any potential issues with the pointers when I reload it... but surprisingly, I am unable to run the exact same code I ran on the first day; Here is the code and the error I get.

spatInSituPlotPoints(fov_join,
                     show_image = T,
                     image_name = image_names,
                     show_polygon = TRUE,
                     spat_unit = 'cell',
                     feats = list('rna' = c("EPCAM")),
                     feats_color_code = c("yellow",),
                     point_size = 0.08, 
                     use_overlap = T,
                     coord_fix_ratio = TRUE,
                     background_color = NA,
                     polygon_line_size = 0.02,
                     polygon_alpha = 0.3,
                     polygon_feat_type = 'cell',
                     polygon_fill = 'CellSubType',
                     polygon_fill_as_factor = TRUE,
                     polygon_fill_code = CellSubType_col,
                     save_param = list(
                       save_name = paste0(sampleName, '_spatInSituPlotPoints'),
                       base_width = 9,
                       base_height = 7,
                       save_format = 'png'
                     ))

select image done
Error in gimage[[i]]@mg_object[[1]] : 
  object of type 'externalptr' is not subsettable

So I examined the image slot, and while I can see the image names under fov_join@images, the file_paths are NULL looking at the @file_path slot, for example fov_join@images$fov001-image@file_path. Interestingly, I do not get to see the largeImage list in this object anymore.

fov_join@largeImages
$`fov001-composite`
Error in .Call(list(name = "CppField__get", address = <pointer: (nil)>,  : 
  NULL value passed as symbol address

If I remove the image arguments from my code (i.e. commenting show_image = T & image_name = image_names), and run it with only polygons and points, I get a new Error:

Error in .External(list(name = "CppMethod__invoke_notvoid", address = <pointer: (nil)>,  : 
  NULL value passed as symbol address

So, then I thought I would load the data that I had saved half way through (after normalisation/processing), and try to visualise the data using the reloaded object. While loading the data, I get similar messages as @swbioinf mentioned above "image : no filepaths found. Skipping.". I also get the exact same Error as I got in the first chunk of code when trying to plot it. However, removing the image arguments this time, allowed me to plot it. Interestingly, in this reloaded object, I can see the large image information when checking fov_join@largeImages but still the file paths under the image slots are empty.

I also tried assigning largeimage_name argument instead of image_name argument in both data (using all three composite, overlay and compartment), but I get this error:

Error in get_giottoLargeImage(gobject = gobject, name = largeImage_name) : 
  composite was not found among the largeImage names. See showGiottoImageNames() 

and running showGiottoImageNames() gives me these names. Screenshot 2023-11-17 at 12 34 36 pm

So, there are a few things I do not understand here and they seem to be related to the pointer issues and linking to image file paths:

Really appreciate any help/comments or insights into these. Many thanks! Sepideh

R version 4.2.0 (2022-04-22)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Red Hat Enterprise Linux 8.7 (Ootpa)

Matrix products: default
BLAS/LAPACK: /usr/lib64/libopenblasp-r0.3.15.so

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8     LC_MONETARY=en_US.UTF-8   
 [6] LC_MESSAGES=en_US.UTF-8    LC_PAPER=en_US.UTF-8       LC_NAME=C                  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] plyr_1.8.9         cowplot_1.1.1      plotly_4.10.3      broom_1.0.5        growthcurver_0.3.1 lubridate_1.9.3    forcats_1.0.0      stringr_1.5.0     
 [9] purrr_1.0.2        readr_2.1.4        tidyr_1.3.0        tibble_3.2.1       tidyverse_2.0.0    shinyWidgets_0.8.0 shiny_1.7.5        UpSetR_1.4.0      
[17] Giotto_3.3.1       smfishHmrf_0.1     fs_1.6.3           pracma_2.4.2       singscore_1.18.0   InSituType_0.99.4  data.table_1.14.8  qs_0.25.5         
[25] dplyr_1.1.3        patchwork_1.1.3    viridis_0.6.4      viridisLite_0.4.2  ggplot2_3.4.4      RColorBrewer_1.1-3

loaded via a namespace (and not attached):
  [1] rappdirs_0.3.3              SnowballC_0.7.1             SparseM_1.81                scattermore_1.2             ragg_1.2.5                 
  [6] SeuratObject_4.1.4          bit64_4.0.5                 knitr_1.45                  irlba_2.3.5.1               DelayedArray_0.24.0        
 [11] inline_0.3.19               KEGGREST_1.38.0             RCurl_1.98-1.12             doParallel_1.0.17           generics_0.1.3             
 [16] flowCore_2.10.0             BiocGenerics_0.44.0         callr_3.7.3                 terra_1.7-55                usethis_2.2.2              
 [21] RSQLite_2.3.1               RApiSerialize_0.1.2         RANN_2.6.1                  future_1.33.0               bit_4.0.5                  
 [26] tzdb_0.4.0                  spatstat.data_3.0-1         httpuv_1.6.11               StanHeaders_2.26.28         SummarizedExperiment_1.28.0
 [31] xfun_0.41                   hms_1.1.3                   jquerylib_0.1.4             evaluate_0.23               promises_1.2.1             
 [36] fansi_1.0.5                 igraph_1.5.1                DBI_1.1.3                   htmlwidgets_1.6.2           spatstat.geom_3.2-5        
 [41] stats4_4.2.0                sccomp_1.2.1                ellipsis_0.3.2              RSpectra_0.16-1             ggpubr_0.6.0               
 [46] backports_1.4.1             cytolib_2.10.1              annotate_1.76.0             deldir_1.0-9                RcppParallel_5.1.7         
 [51] MatrixGenerics_1.10.0       vctrs_0.6.4                 SingleCellExperiment_1.20.1 Biobase_2.58.0              remotes_2.4.2.1            
 [56] ROCR_1.0-11                 abind_1.4-5                 cachem_1.0.8                withr_2.5.2                 progressr_0.14.0           
 [61] sctransform_0.4.0           prettyunits_1.2.0           goftest_1.2-3               mclust_6.0.0                cluster_2.1.4              
 [66] lazyeval_0.2.2              crayon_1.5.2                spatstat.explore_3.2-3      labeling_0.4.3              edgeR_3.40.2               
 [71] pkgconfig_2.0.3             GenomeInfoDb_1.34.9         pkgload_1.3.3               nlme_3.1-163                devtools_2.4.5             
 [76] rlang_1.1.2                 globals_0.16.2              lifecycle_1.0.4             miniUI_0.1.1.1              polyclip_1.10-6            
 [81] matrixStats_1.1.0           lmtest_0.9-40               platetools_0.1.5            graph_1.76.0                Matrix_1.6-1.1             
 [86] loo_2.6.0                   carData_3.0-5               boot_1.3-28.1               zoo_1.8-12                  ggridges_0.5.4             
 [91] GlobalOptions_0.1.2         processx_3.8.2              png_0.1-8                   rjson_0.2.21                stringfish_0.15.8          
 [96] bitops_1.0-7                KernSmooth_2.23-22          Biostrings_2.66.0           blob_1.2.4                  shape_1.4.6                
[101] spatstat.random_3.1-6       parallelly_1.36.0           rstatix_0.7.2               ggsignif_0.6.4              S4Vectors_0.36.2           
[106] scales_1.2.1                memoise_2.0.1               GSEABase_1.60.0             magrittr_2.0.3              ica_1.0-3                  
[111] zlibbioc_1.44.0             compiler_4.2.0              rstantools_2.3.1.1          clue_0.3-65                 fitdistrplus_1.1-11        
[116] cli_3.6.1                   urlchecker_1.0.1            XVector_0.38.0              listenv_0.9.0               pbapply_1.7-2              
[121] ps_1.7.5                    MASS_7.3-60                 tidyselect_1.2.0            stringi_1.8.1               RProtoBufLib_2.10.0        
[126] textshaping_0.3.6           yaml_2.3.7                  askpass_1.2.0               locfit_1.5-9.8              ggrepel_0.9.4              
[131] grid_4.2.0                  sass_0.4.7                  tools_4.2.0                 timechange_0.2.0            future.apply_1.11.0        
[136] parallel_4.2.0              circlize_0.4.15             rstudioapi_0.15.0           foreach_1.5.2               lsa_0.73.3                 
[141] gridExtra_2.3               farver_2.1.1                Rtsne_0.16                  BiocManager_1.30.22         digest_0.6.33              
[146] Rcpp_1.0.11                 car_3.1-2                   GenomicRanges_1.50.2        later_1.3.1                 RcppAnnoy_0.0.21           
[151] httr_1.4.7                  QuickJSR_1.0.6              AnnotationDbi_1.60.2        ComplexHeatmap_2.14.0       Rdpack_2.5                 
[156] colorspace_2.1-0            tensor_1.5                  XML_3.99-0.14               reticulate_1.34.0           umap_0.2.10.0              
[161] IRanges_2.32.0              splines_4.2.0               uwot_0.1.16                 spatstat.utils_3.0-3        sp_2.1-1                   
[166] systemfonts_1.0.4           sessioninfo_1.2.2           xtable_1.8-4                jsonlite_1.8.7              rstan_2.26.23              
[171] R6_2.5.1                    profvis_0.3.8               pillar_1.9.0                htmltools_0.5.7             mime_0.12                  
[176] glue_1.6.2                  fastmap_1.1.1               codetools_0.2-19            pkgbuild_1.4.2              utf8_1.2.4                 
[181] spatstat.sparse_3.0-2       lattice_0.21-9              bslib_0.5.1                 leiden_0.4.3                gtools_3.9.4               
[186] openssl_2.1.1               survival_3.5-7              limma_3.54.2                rmarkdown_2.25              munsell_0.5.0              
[191] GetoptLong_1.0.5            GenomeInfoDbData_1.2.9      iterators_1.0.14            reshape2_1.4.4              gtable_0.3.4               
[196] rbibutils_2.2.15            Seurat_4.4.0    
RubD commented 10 months ago

Thanks for letting us know and we're looking into this. We're currently making some major updates as part of a new big release so it might take us a little bit longer to figure this out.