mahmoodlab / HEST

HEST: Bringing Spatial Transcriptomics and Histopathology together - NeurIPS 2024
Other
164 stars 12 forks source link

HESTData: update `to_spatial_data()``` #63

Closed konst-int-i closed 3 weeks ago

konst-int-i commented 3 weeks ago

This PR

Makes several changes to the HESTData.to_spatial_data() behaviour:

Test instructions

from hest import load_hest
hest_data = load_hest('../hest_data', id_list=['TENX68'])
st = hest_data[0]
st.to_spatial_data(fullres=True)

Alternatively, run the first cell in tutorials/2-Interacting-with-HEST-1k.ipynb.

Expected behaviour

Old SpatialData conversion for sample TENX68

SpatialData object
├── Images
│     └── 'he': DataArray[cyx] (3, 38232, 20690)
├── Shapes
│     ├── 'cellvit': GeoDataFrame shape: (77165, 3) (2D shapes)
│     └── 'tissue_contours': GeoDataFrame shape: (2, 2) (2D shapes)
└── Tables
      └── 'anndata': AnnData (1657, 18085)
with coordinate systems:
    ▸ 'global', with elements:
        he (Images), cellvit (Shapes), tissue_contours (Shapes)

⬇️ ⬇️ ⬇️

New SpatialData conversion:

SpatialData object
├── Images
│     ├── 'ST_downscaled_hires_image': SpatialImage[cyx] (3, 4779, 2586)
│     ├── 'ST_downscaled_lowres_image': SpatialImage[cyx] (3, 1000, 541)
│     └── 'ST_fullres_image': DataTree[cyx] (3, 38232, 20690), (3, 19116, 10345)
├── Shapes
│     ├── 'cellvit': GeoDataFrame shape: (77165, 3) (2D shapes)
│     ├── 'locations': GeoDataFrame shape: (1657, 2) (2D shapes)
│     └── 'tissue_contours': GeoDataFrame shape: (2, 2) (2D shapes)
└── Tables
      └── 'table': AnnData (1657, 18085)
with coordinate systems:
    ▸ 'ST_downscaled_hires', with elements:
        ST_downscaled_hires_image (Images), cellvit (Shapes), locations (Shapes), tissue_contours (Shapes)
    ▸ 'ST_downscaled_lowres', with elements:
        ST_downscaled_lowres_image (Images), cellvit (Shapes), locations (Shapes), tissue_contours (Shapes)
    ▸ 'ST_fullres', with elements:
        ST_fullres_image (Images), cellvit (Shapes), locations (Shapes), tissue_contours (Shapes)
guillaumejaume commented 3 weeks ago

Thanks @konst-int-i! A couple of things to add:

@pauldoucet, let me know if I'm missing anything. Pushing for better interfacing with spatial data seems like a good direction.

pauldoucet commented 3 weeks ago

Hi @konst-int-i great work on your PR!

I added some checks and modified the conditional import statement (one cool trick, if you use from __future__ import annotations you can keep the return type of the method even if it's not imported yet)

konst-int-i commented 3 weeks ago

Addressed the additional requests from @guillaumejaume in 82f0779