drieslab / Giotto

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

A question about spatPlot() function #482

Open jhyhy0825 opened 1 year ago

jhyhy0825 commented 1 year ago

I used spatPlot() function and I got the result turned 90 degrees to the left. I extracted counts matrix and location matrix from Seurat object. I attached my code below. Let me know if there's a solution. Thank you.

count <- data@assays$Spatial@counts count <- data.matrix(count) location <- GetTissueCoordinates(data) location <- data.matrix(location) Giotto <- createGiottoObject(raw_exprs=count,spatial_locs=location) mg_img = magick::image_read(image) mypl = spatPlot(Giotto, return_plot = T, point_alpha = 0.8) orig_png = createGiottoImage(gobject = Giotto, mg_object = mg_img, name = 'image', xmax_adj = 450, xmin_adj = 550, ymax_adj = 200, ymin_adj = 200) mypl_image = addGiottoImageToSpatPlot(mypl, orig_png)

mattobny commented 1 year ago

Hello @jhyhy0825, would you be able to share your data so that I can try to reproduce this? Also, are you able to provide screenshots indicating the original, desired plot, and the rotated result? I am also gently assuming that the results from spatPlot() are rotated, while the image is not; please clarify this if I am assuming incorrectly.

jiajic commented 1 year ago

To add onto this, if it's only the spatial locations that are the issue, in Giotto Suite right now, there are internal functions for rotating spatial locations using radians

library(Giotto)
library(GiottoData)

# load test data
viz = loadGiottoMini('vizgen')

# get spatLocsObj
spatlocs = Giotto:::get_spatial_locations(viz)

# rotate spatial locations 90 deg clockwise (pi/2 radians)
# rotation center assumed to be the center of the x and y ranges
spatlocs[] = rotate_spatial_locations(
  spatlocs[],
  rotateradians = c(xy = pi/2, zy = 0, xz = 0),
  rcenter = c(x = mean(range(st[]$sdimx)), y = mean(range(st[]$sdimy)), z = 0)
)
viz = set_spatial_locations(viz, spatlocs = spatlocs)

Currently on our dev branch suite_dev, we also have the spin() generic that wraps the former code and works for spatLocsObj as well

plot(spatlocs)
spatlocs = spin(spatlocs, 90)
plot(spatlocs)