scverse / scverse/spatialdata

More informative error when subsetting results in no observations retained in Visium HD

Open
#1,096 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

needs: triage priority: low
Dominant language
Python
Stars
394
Forks
95
Avg merge
4d 3h
Merged PRs (30d)
7

Description

When filtering bin spots in Visium HD, when using a sufficiently large expression filter:

mask = (sdata.tables[table].X > 0).sum(axis=1).A1 >= 500

The resulting table, if filtered using the mask, would contain no observations.

However, the error provided does not indicate this, and instead suggests a different type of data mismatch:

schema = get_model(value)
  File "/home/admin/.local/lib/python3.10/site-packages/spatialdata/models/models.py", line 1195, in get_model
    return _validate_and_return(TableModel, e)
  File "/home/admin/.local/lib/python3.10/site-packages/spatialdata/models/models.py", line 1178, in _validate_and_return
    schema().validate(e)
  File "/home/admin/.local/lib/python3.10/site-packages/spatialdata/models/models.py", line 1056, in validate
    self._validate_table_annotation_metadata(data)
  File "/home/admin/.local/lib/python3.10/site-packages/spatialdata/models/models.py", line 1034, in _validate_table_annotation_metadata
    raise ValueError(f"Regions in the AnnData object and `{attr[self.REGION_KEY_KEY]}` do not match.")
ValueError: Regions in the AnnData object and `region` do not match.

It may be useful to first have a check that the relevant table is non-empty before throwing this ValueError, as it suggested to be that a metadata column was corrupted or removed during processing.

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

Start by tracing table filtering from the Visium HD bin-spot example into spatialdata.models.models.get_model and TableModel validation. Reproduce the case with the shown expression mask, then verify that an empty filtered table produces an informative error distinguishing no retained observations from a region mismatch.

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
Active
Clarity
Mostly clear
Newbie friendliness
67/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.