spatialdata icon indicating copy to clipboard operation
spatialdata copied to clipboard

Can't save transformation result

Open Ithinky opened this issue 1 year ago • 3 comments

Hi, Thanks for your great work in Spatial omics filed! I used SpatialData to integrate two images and following the tutorial "Use landmark annotations to align multiple -omics layers". Everything went well, but when I wanted to save the result by save_transformations( ) , the information returned like this image . And the recommend function write_transformations( ) can't be used. My SpatialData objects are here: image image

By the way, after alignment, where can I get the alignment relationship between pixel spots in two image, like spot1 in image1 is aligned to spot3 in image2?

I would appreciate it if you could help me!

Ithinky avatar May 06 '24 10:05 Ithinky

Hi, thanks for reaching out! I would suggest using the code from this pull request (it will be merged soon, probably this week): https://github.com/scverse/spatialdata/pull/501

Here you can explicitly call write_element(), which will make sure that the annotations are saved to disk.

Regarding the second questions, we don't have yet explicit code for what you asked but you can easily implement it:

  • a super easy implementation (slow, but probably ok for Visium) is to call the query APIs for each Visium circle on the aligned coordinate system and see which circles are present in each of the two datasets
  • a better implementation (still easy to implement) is to first call sdata.subset() to create a SpatialData object (or more than one) containing only the shapes, then call sdata.transform_to_coordinate_system() to transform the data in the aligned coordinate system, and then use sjoin directly from geopandas to see which aligned shapes overlap. This is much faster than calling query as a single call will operate on all the Visium circles.

LucaMarconato avatar May 06 '24 11:05 LucaMarconato

Thanks for your fast reply! I will try it.

Ithinky avatar May 06 '24 11:05 Ithinky

How can I call write_element( ), I can't import it from spatialdata_io or spatialdata. Thank you again! image

Ithinky avatar May 08 '24 08:05 Ithinky

it is not an import. If you have a spatialdata object you can call it as a method of the spatialdata object directly, no import required. So for example my spatialdata object is called sdata and I have an element called registration_landmarks that I just added in memory to the object, the way to write it do disk is:

sdata.write_element("registration_landmarks")

Let us know if you have any issues!

melonora avatar May 15 '24 08:05 melonora

btw just so you know the PR as @LucaMarconato stated is not merged yet, so if you would like to try you have to either clone the repo, checkout the PR using the github cli and perform an editable install, or have a bit of patience:)

melonora avatar May 15 '24 09:05 melonora

@Ithinky getting back to you, we are cutting the release that includes the method in the following days. I will close this issue now.

melonora avatar Jun 28 '24 13:06 melonora