scverse / scverse/spatialdata

Missing filtered table in polygon_query() of MERFISH data

Open
#633 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug 🚨 method: query
Dominant language
Python
Stars
394
Forks
95
Avg merge
4d 3h
Merged PRs (30d)
7

Description

Using this tutorial for MERFISH data, I found that the output of polygon_query(sdata, my_napari_annotation) does not contain any filtered table, despite my_napari_annotation covering multiple cells. Is there something missing in my code?

With filter_table=False, I get the unfiltered table, which is not what I am looking for. This is similar to https://github.com/scverse/spatialdata/issues/532

Much appreciated!

Details:

# load

sdata = sio.merscope(full_paths, backend="rioxarray", slide_name="s1", region_name="r0")

sdata
SpatialData object
β”œβ”€β”€ Points
β”‚     └── 's1_r0_transcripts': DataFrame with shape: (<Delayed>, 9) (2D points)
β”œβ”€β”€ Shapes
β”‚     └── 's1_r0_polygons': GeoDataFrame shape: (96632, 9) (2D shapes)
└── Tables
      └── 'table': AnnData (96632, 500)
with coordinate systems:
    β–Έ 'global', with elements:
        s1_r0_transcripts (Points), s1_r0_polygons (Shapes)

sdata.table.uns
OrderedDict([('spatialdata_attrs',
              {'region': 's1_r0_polygons',
               'region_key': 'cells_region',
               'instance_key': 'EntityID'})])

sdata["table"]
AnnData object with n_obs Γ— n_vars = 96632 Γ— 500
    obs: 'fov', 'volume', 'center_x', 'center_y', 'min_x', 'min_y', 'max_x', 'max_y', 'anisotropy', 'transcript_count', 'perimeter_area_ratio', 'solidity', 'DAPI_raw', 'DAPI_high_pass', 'PolyT_raw', 'PolyT_high_pass', 'region', 'slide', 'dataset_id', 'cells_region', 'EntityID'
    uns: 'spatialdata_attrs'
    obsm: 'blank', 'spatial'

print(sd.SpatialData.get_annotated_regions(sdata["table"]))
s1_r0_polygons
# annotate shape

interactive = napari_spatialdata.Interactive(sdata)

interactive.run() 

# export shape layer from Napari

shape = "overlap"

sdata[shape]
geometry
0	POLYGON ((5423.45 1777.948, 6398.625 1777.948,...

sdata[shape].geometry.iloc[0]
image
sdata
SpatialData object
β”œβ”€β”€ Points
β”‚     └── 's1_r0_transcripts': DataFrame with shape: (<Delayed>, 9) (2D points)
β”œβ”€β”€ Shapes
β”‚     β”œβ”€β”€ 'overlap': GeoDataFrame shape: (1, 1) (2D shapes)
β”‚     └── 's1_r0_polygons': GeoDataFrame shape: (96632, 9) (2D shapes)
└── Tables
      └── 'table': AnnData (96632, 500)
with coordinate systems:
    β–Έ 'global', with elements:
        s1_r0_transcripts (Points), overlap (Shapes), s1_r0_polygons (Shapes)
# sd.polygon_query

subset = sd.polygon_query(
    sdata, polygon=sdata[shape].geometry.iloc[0], target_coordinate_system="global", filter_table=True
)

subset
SpatialData object
└── Shapes
      └── 'overlap': GeoDataFrame shape: (1, 1) (2D shapes)
with coordinate systems:
    β–Έ 'global', with elements:
        overlap (Shapes)

# subset does not contain filtered table

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up β€” it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the documented MERFISH workflow and the shown polygon_query() call with filter_table=True, then compare it with filter_table=False and review the related issue 532. Done means the resulting SpatialData object includes the filtered table for the annotated polygon.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.