Skip to content

Feat/export cli#66

Open
EliHei2 wants to merge 7 commits into
mainfrom
feat/export-cli
Open

Feat/export cli#66
EliHei2 wants to merge 7 commits into
mainfrom
feat/export-cli

Conversation

@EliHei2

@EliHei2 EliHei2 commented Jun 11, 2026

Copy link
Copy Markdown
Collaborator

feat(export): segger export CLI — get segmentations into the tools people actually use

Motivation : A segger run produces a segger_segmentation.parquet — but that would need post processing to get the transcirpt metadata and make cell table, make polygons for vis etc. this is to get that parquet file into Xenium
Explorer, anndata, +metadata .parquet, or spaitaldata (sopa specs).

Specifics: segger export reads a segmentation result and emits it in four formats:

  • xenium (default) — Baysor-style segmentation.csv + viz polygons / cell GeoJSON for 10x's xeniumranger
    import-segmentation, and prints the exact command to run next.
  • anndata — cell × gene .h5ad
  • merged — original transcripts joined with segger assignments (+ fragment annotations).
  • spatialdata — SOPA-compatible Zarr (optional segger[spatialdata] extra).

Vis: multi-core Delaunay cell-boundary generation from assigned transcripts (or reuse the platform's own
boundaries), and export-time re-thresholding so you can tune the assignment cutoff without re-running
segmentation.

Usage

`segger export -s <segmentation.parquet> -i -o [--format ...]

`
  # Xenium Explorer (default) — writes import-segmentation inputs + prints the xeniumranger command
  segger export -s seg.parquet -i data/xenium_run/ -o export/

  # AnnData for scanpy
  segger export -s seg.parquet -i data/xenium_run/ -o export/ --format anndata

  # Merged transcripts table
  segger export -s seg.parquet -i data/xenium_run/ -o export/ --format merged

  # SpatialData / SOPA Zarr (needs: pip install 'segger[spatialdata]')
  segger export -s seg.parquet -i data/xenium_run/ -o export/ --format spatialdata -n 8

  # Re-threshold at export time — no re-segmentation
  segger export -s seg.parquet -i data/xenium_run/ -o export/ --min-similarity 0.5

Key flags:

--format {xenium,merged,anndata,spatialdata} · --xenium-mode {transcript_assignment,geojson,both} ·
--min-similarity / --min-similarity-shift · --boundary-method {delaunay,input} · -n/--num-workers. 

Cell-ID column
auto-resolves across segger_cell_id/seg_cell_id/cell_id; spatialdata degrades gracefully if the extra isn't
installed.

Implementation

7 focused commits, ~one per module, reviewable in order:

  1. refactor(utils) — utils.py → package + optional-dependency helpers
  2. lazy export package + output-format/writer registry (OutputFormat, get_writer, register_writer)
  3. Delaunay boundary generation --> vs. convex hull!
  4. Xenium Explorer via xeniumranger import-segmentation
  5. merged-transcripts writer
  6. AnnData writer
  7. segger export CLI

Heavy/optional deps (spatialdata, anndata) are imported lazily so the base install stays light. Covered by
tests/test_export_cli.py and tests/test_export_xenium_import.py.

EliHei2 added 7 commits June 1, 2026 14:05
…pers

Promote src/segger/utils.py -> src/segger/utils/ package: _logging.py keeps
setup_logging/MemFilter (re-exported from __init__), and optional_deps.py adds
lazy import + availability helpers for spatialdata/sopa/rapids. pyproject: add
rtree dep and the spatialdata/sopa optional extras. Base for the export stack.
export/__init__.py (PEP-562 lazy submodule loader) and output_formats.py
(OutputFormat enum + writer registry/get_writer). No writers registered yet.
export/boundary.py: BoundaryIdentification (Delaunay + edge pruning + cycle
detection) and parallel generate_boundaries(); extract_largest_polygon.
export/xenium_import.py: write Baysor-style segmentation.csv + viz polygons +
cell GeoJSON and the import-segmentation command (10x's current recommended
path; output opens in Xenium Explorer).
export/merged_writer.py (join predictions back onto transcripts) and
utils/fragment_outputs.py (fragment/cell/unassigned classification helpers).
export/anndata_writer.py: build_anndata_table + AnnDataWriter producing a
cell x gene .h5ad from the segmentation (cells / fragments split).
cli/export.py: `segger export` dispatching xenium / merged / anndata /
spatialdata, with cell-id alias resolution and keep-column recompute; register
in cli/main.py.
@EliHei2 EliHei2 requested a review from Tobiaspk June 11, 2026 14:22
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.

1 participant