spatialdata
spatialdata copied to clipboard
Can't save transformation result
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
. And the recommend function write_transformations( ) can't be used.
My SpatialData objects are here:
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!
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
queryAPIs 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 aSpatialDataobject (or more than one) containing only the shapes, then callsdata.transform_to_coordinate_system()to transform the data in thealignedcoordinate system, and then usesjoindirectly fromgeopandasto see which aligned shapes overlap. This is much faster than callingqueryas a single call will operate on all the Visium circles.
Thanks for your fast reply! I will try it.
How can I call write_element( ), I can't import it from spatialdata_io or spatialdata. Thank you again!
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!
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:)
@Ithinky getting back to you, we are cutting the release that includes the method in the following days. I will close this issue now.