Skip to content

Debugged spatialdata writer with refactored shapes - #28

Merged
EliHei2 merged 3 commits into
dpeerlab:v2-incrementalfrom
enric-bazz:bugfix/sd-writer
Mar 19, 2026
Merged

Debugged spatialdata writer with refactored shapes#28
EliHei2 merged 3 commits into
dpeerlab:v2-incrementalfrom
enric-bazz:bugfix/sd-writer

Conversation

@enric-bazz

Copy link
Copy Markdown

The main issues identified during debugging relate to the initialization of the SpatialData object with dictionaries and to writing. I also fixed cases in boundary generation with convex hull/delaunay where an ID has three or more points but the corresponding coordinates do not actually form a valid polygon (points coincide).

I slightly refactored the shapes element creation by separating concerns: one helper function for input boundaries, called separately for cell and nucleus boundaries, and one for generated boundaries, called iteratively for cells and fragments.

@EliHei2
EliHei2 merged commit af97ef1 into dpeerlab:v2-incremental Mar 19, 2026
EliHei2 added a commit that referenced this pull request Jun 1, 2026
Adds a focused export feature on top of main that turns
segger_segmentation.parquet into downstream artifacts.

10x Xenium Explorer (default, `--format xenium`) follows 10x's current
`xeniumranger import-segmentation` workflow rather than hand-writing a
cells.zarr bundle:
  - `--xenium-mode transcript_assignment`: Baysor-style segmentation.csv
    (transcript_id/cell/is_noise) + segmentation_polygons.json viz polygons
  - `--xenium-mode geojson`: cell polygon.geojson (objectType="cell")
  - `--xenium-mode both` (default): all of the above
and prints the exact `xeniumranger import-segmentation` command to run.

Other formats: `merged` (transcripts joined with assignments), `anndata`
(cell x gene), and `spatialdata` (Zarr for scverse/SOPA, optional extra).

Cell polygons use our multi-core Delaunay boundary generation (boundary.py),
never convex hulls; degenerate (<3 vertex) cells are dropped to avoid
crashing Xenium Explorer.

SpatialData output uses the up-to-date latest-spatialdata writer (dask points
path, init_from_elements with fallback, pre-release _accessor workaround,
separate cell/nucleus shape elements) debugged by Enrico Bazzacco (PR #28).
spatialdata/spatialdata-io/sopa are optional extras; the base install stays
light via lazy imports.

Ported the proven export modules from the b450 dev branch and added a new,
smaller xenium_import.py for the import-segmentation path. transcript_id and
micron coordinates are recovered from the source bundle's transcripts.parquet
by joining on row_index (assigned before quality filtering, so the positional
join is exact).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
EliHei2 added a commit that referenced this pull request Jun 1, 2026
Debugged spatialdata writer with refactored shapes
@enric-bazz
enric-bazz deleted the bugfix/sd-writer branch July 8, 2026 06:00
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