JEFworks-Lab / STdeconvolve

Reference-free cell-type deconvolution of multi-cellular spatially resolved transcriptomics data
http://jef.works/STdeconvolve/
98 stars 12 forks source link

Superimpose scatterpies on an H&E image #38

Closed peleg555 closed 1 year ago

peleg555 commented 1 year ago

Dear Dr. Miller (@bmill3r ),

I am working on spatial transcriptomics data that I created using the 10X visium kit. I used this tool to deconvolute the cell types in my tissue and it works like a charm. Now I am trying to superimpose the scatterpies I got on top of the H&E images. I saw in the vizAllTopics function that you added an "overlay" argument but I didn't succeeded to place the scatterpies and the image on top of each other. Can I please get your assistance on how to do so?

Thank you so much for creating STdeconvolve, Best regards, Peleg

bmill3r commented 1 year ago

Hi @peleg555 ,

Thanks for your question and using STdeconvolve!

To be fair, the overlay argument in vizAllTopics() was my attempt to do what you are asking but I had some trouble getting it to align the spots to the correct positions on the H&E image. So really it should be treated like a deprecated argument, however, I think in the function you can still get it to work but it might not be super straightforward.

Basically, overlay should be a 3D rasterized array of the image you are trying to overlay the spots on. It is important that the coordinates of the spots are equivalent to the corresponding pixel spatial positions in the array. The function uses the first and second dimension of the 3D array as the x and y coordinates. It might take some playing around with scaling or transforming the dimensions to get it to align just right.

For reference, the function essentially uses ggplot2::annotation_raster() to first plot the rasterized image, and then uses scatterpie::geom_scatterpie() to plot the scatterpies on top of that.

I can't guarantee that this will work but hopefully this helps a little, Brendan