drieslab / Giotto

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

Error in dispaying tissue images over 10 Visium #218

Closed moutazhelal closed 1 year ago

moutazhelal commented 2 years ago

Dear authors,

Thank you fro reading my message,

I have encountered an Error in displaying the tissue image underneath for example clusters or gene expression. the plot is generated without any problems if I set show_image = F but if I choose to show the image it does not produce an out put I am using this to plot the figure

spatPlot2D(Giotto_HBTm, cell_color = 'leiden_clus', point_size = 2, legend_symbol_size=3.5,  cell_color_code= colors, show_image = T,point_alpha = 0.7,
           save_param = list(save_name = '5_aa_covis_leiden_image_1', base_width=6, base_height=6))

But this Error comes up

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

Could you help me solve this issue?

Thank you very much, Best

RubD commented 2 years ago

Hi @moutazhelal Can you provide a bit more information and the Giotto version you're using? Did this error also occur with the examples? Also pinging @jiajic on this thread who might help with any image specific issues. Thanks, Ruben

iivario commented 2 years ago

Thanks for the awesome Giotto Suite,

I also got the 'externalptr' error when plotting spots on the tissue image.

This appears only after opening the Giotto object in new R session and is likely because the magick objects are not saved correctly to the Giotto object when using magick with the future package. (see https://cran.r-project.org/web/packages/future/vignettes/future-4-non-exportable-objects.html)

Giotto_object@images[[img_1142243F_lowres]][[mg_object]] Error: Image pointer is dead. You cannot save or cache image objects between R sessions.

As a workaround, I'm currently importing the spatial images again after each Giotto object reload.

## Function to re-import images 

reimport_imgs2 <- function(gobj) { 
  for (n in 1:length(gobj@images)) {
      gobj@images[[n]]@mg_object = 
        magick::image_read(gobj@images[[n]]@file_path)  
  } 
  return(gobj) 
} 
jiajic commented 2 years ago

Hi @iivario thank you for continuing this discussion,

Unfortunately, the 'externalptr error' issue has been a longstanding and unavoidable one with larger files such as images both to improve performance and to save on file sizes.

The workaround that you arrived at is the same one that we did, and it is implemented as the function reconnectGiottoImages() which should work based on the filepaths recorded in the image object's @file_path slot. So as long as the file path has not changed it should work without any specific parameters other than the gobject. There's also a more manual workflow to reconnecting image media that is accessed by setting the parameter auto_reconnect to FALSE and supplying the new full image paths to the image_path or largeImage_path params as named lists (the names should be the respective names of the images that were used in the gobject) In the future, we are planning to implement it into Giotto-specific save and load functions, and that should provide a more native solution.

Thanks, George

RubD commented 1 year ago

Closing this with a general comment:

We've worked on new functions saveGiotto() and loadGiotto, which are essentially wrappers around the basesaveRDS() or qsave function from the qs package. They allow you to save the new Giotto Suite (> 3.0) objects into a folder structure and also load them back in. It should also work between different machines.