scverse / spatialdata-io

BSD 3-Clause "New" or "Revised" License
42 stars 27 forks source link

Inquiry about Visium HD #177

Open aalia09123 opened 3 months ago

aalia09123 commented 3 months ago

Hi, I am working with the Visium HD colorectal cancer dataset. I have annotated a mask on the microscopic image with qupath and have it as a geoJSON file. Could I please get instructions/ links to tutorials on how I can impose the mask on the microscopic image and extract the gene information.

I have done this with 10 X Visium datasets before but since the Visium HD datasets would need alignment, I am unsure if I would have to use the JSON file provided in visium to align the image, and if yes, how would I proceed with this.

Additionally, the tutorial here https://spatialdata.scverse.org/en/latest/tutorials/notebooks/notebooks/examples/technology_visium_hd.html has loaded the full microscopic image onto the python pipeline however my microscopic image is 11.6 GB and therefore cannot be opened in my pipeline. Please do advise on how I may proceed.

LucaMarconato commented 3 months ago

Hi, we currently don't have a tutorial that specifically shows how to add an additional segmentation mask to an existing dataset, but the requirements for this use case are covered by the following more general tutorials:

Please also have a look at SOPA, which builds on top of the SpatialData framework and offers a variety of functions to add and compare segmentations masks on top of exiting objects.

LucaMarconato commented 3 months ago

Final comment to kick start the solution.

  1. In your case if you call
from spatialdata.models import ShapesModel

my_new_mask = ShapesModel.parse(path_to_geo_json_file)

you will get a GeoPandas object with the polygons/multipolygons.

  1. Then you can use sdata['my_new_mask'] = my_new_mask to add the new element to the SpatialData object and you can call sdata.write_element(...) to update the disk storage for the new masks. You can also work just in-memory and write once at the very end.

  2. You can check with napari-spatialdata if the data is already aligned; if not you can examine and transfer transformations between elements using get_transformation and set_transformation, which you can import from spatialdata.transformations. Here I would have a look at how SOPA recommends to align the new data since it's a task that it solved.

  3. Finally, if you had written the data to disk before, you can update the transformation without the need to rewrite the whole data by calling sdata.write_transformations(...).

More details can be found in the tutorials above, but I hope this helps 😊