Skip to content

xenium: label hex cell_ids without label_id; drop degenerate boundary polygons - #431

Open
timtreis wants to merge 2 commits into
scverse:mainfrom
timtreis:fix/xenium-hex-cellid-labels
Open

timtreis wants to merge 2 commits into
scverse:mainfrom
timtreis:fix/xenium-hex-cellid-labels

Conversation

@timtreis

Copy link
Copy Markdown
Member

Follow-up to #427 (CSV-only / stripped Xenium bundles), found converting GEO Xenium deposits.

Hex cell_ids without label_id. XOA 1.3-1.x boundary files carry hex cell_ids but no label_id; the mask values live only in cells.zarr.zip, which stripped (e.g. GEO) deposits omit. _get_labels_from_boundaries raised "Cannot build raster labels…". The shifted-hex prefix now decodes (via the existing prefix_suffix_uint32_from_cell_id_str) to an integer label, used for both the reconstructed raster and the table's cell_labels column, so the instance key joins. Only applied when ids are decodable, from a single dataset suffix, nonzero and unique; otherwise the previous error stands. The label need not equal the original XOA mask value (that's unrecoverable without the zarr).

Degenerate boundaries. XOA occasionally emits 2-3 vertex boundaries (7/40,754 cells, 17/15,488 nuclei in one GEO deposit), and shapely raised "A linearring requires at least 4 coordinates". These are now dropped with a warning (skipped when indices_mapping must align 1:1 without label_id).

Tests: test_xenium_csv_only_hex_without_label_id (hex fixture with label_id stripped) and test_xenium_degenerate_boundary_dropped. Verified on two real GEO deposits (GSE280376, GSE280069) that previously failed: both now read with cell/nucleus labels and boundaries.

… polygons

Stripped XOA 1.3-1.x deposits (no cells.zarr.zip, boundary files without label_id) have hex
cell_ids, so the raster labels could not be reconstructed. Decode the shifted-hex prefix to an
integer label, used for both the raster and the table's cell_labels column.

Boundaries with fewer than 4 coordinates (2-3 vertex polygons XOA occasionally emits) made
shapely raise; drop them with a warning.
@codecov-commenter

codecov-commenter commented Oct 21, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 89.65517% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 66.79%. Comparing base (9548686) to head (71a9936).

Files with missing lines Patch % Lines
src/spatialdata_io/readers/xenium.py 89.65% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #431      +/-   ##
==========================================
+ Coverage   66.60%   66.79%   +0.18%     
==========================================
  Files          26       26              
  Lines        3345     3373      +28     
==========================================
+ Hits         2228     2253      +25     
- Misses       1117     1120       +3     
Files with missing lines Coverage Δ
src/spatialdata_io/readers/xenium.py 79.11% <89.65%> (+0.58%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants