Skip to content

fix(split-phase1): generalize z-gap splitter for alphanumeric cell_ids - #1

Open
atuldeshpande wants to merge 1 commit into
DeshpandeLab:mainfrom
imlong4real:claude/goofy-kalam-555feb
Open

fix(split-phase1): generalize z-gap splitter for alphanumeric cell_ids#1
atuldeshpande wants to merge 1 commit into
DeshpandeLab:mainfrom
imlong4real:claude/goofy-kalam-555feb

Conversation

@atuldeshpande

Copy link
Copy Markdown
Member

Summary

  • _spatial_split_phase1_entities (the Split-Phase1 z-gap splitter in tests/_pipeline_runner.py) gated entities through a numeric-only regex ^\d+(-\d+){0,2}$. On datasets whose cell_ids contain dashes (PDAC, e.g. jikammne-1), the regex rejected every entity, so the entire z-gap stage was a silent no-op — entities that should split on a z-gap > dz_threshold (2.0 µm) were never examined.
  • The gate now reads the _etype column (cell/partial) when present. _etype is set upstream from kernel codes (pruning.etype_from_codes), so it stays correct on alphanumeric cell_ids where label-string parsing is ambiguous. The legacy numeric regex is retained as a fallback when the column is absent, leaving that path byte-for-byte unchanged.
  • The numeric collision pre-scan (next_suffix/next_subsuffix) and the m_main/m_part/m_sub mint branches collapse into a single prefix-agnostic counter that appends the next collision-free -{k} suffix to the parent label — behavior-equivalent on numeric ids, correct for any prefix.

Why

PDAC and other Xenium FFPE/IO datasets carry alphanumeric, dash-containing cell_ids. The numeric-only assumption silently disabled the z-gap splitter on exactly those datasets. This is the same root issue tracked under the entity-type-column refactor: infer identity/kind from the _etype column rather than parsing the label string.

Audit (other numeric-only label parsers)

  • _phase1_rerank_within_parent_etype and _reassign_nuclear_post_1c_etype already anchor on the real cell_id column (lab.startswith(cid + "-")) and parse only the suffix — they handle adohnpem-1-style ids correctly. No change.
  • The UNASSIGNED mirror _split_unassigned_components uses UNASSIGNED_{i} with a numeric connected-component index by construction — unaffected. No change.
  • The dormant -tr- delimiter scheme (src/tracer/_etype.py) is the proper long-term fix but has zero live emitters; activating it requires regenerating all reference partitions, so it remains deferred to its own branch.

Tests

  • New tests/test_split_phase1_zgap.py (6 direct unit tests): alphanumeric+_etype splits, numeric+_etype parity, numeric no-_etype legacy parity, alphanumeric no-_etype boundary no-op, no-gap control, and existing-child collision avoidance.
  • Full suite: 157 passed, including test_pipeline_regression.py (reference-partition comparison) and test_etype.py — confirms numeric pipeline behavior is unchanged.

Test plan

  • PYTHONPATH=src python -m pytest tests/test_split_phase1_zgap.py -x -q
  • PYTHONPATH=src python -m pytest tests/test_pipeline_smoke.py -x -q
  • PYTHONPATH=src python -m pytest tests/ -q (157 passed)

🤖 Generated with Claude Code

The Split-Phase1 z-gap stage (_spatial_split_phase1_entities) gated
entities through a numeric-only regex (^\d+(-\d+){0,2}$). On datasets
with dash-containing cell_ids (PDAC, e.g. "jikammne-1"), every entity was
rejected and the entire stage became a silent no-op — z-gap splits never
fired.

Gate on the _etype column (cell/partial) when present; it is set upstream
from kernel codes (pruning.etype_from_codes) so it stays correct on
alphanumeric cell_ids where label parsing is ambiguous. Falls back to the
legacy numeric regex when the column is absent, leaving that path
unchanged. Collapse the numeric collision pre-scan and the
m_main/m_part/m_sub mint branches into a single prefix-agnostic
"append next free suffix" — behavior-equivalent on numeric ids.

Sibling label parsers (_phase1_rerank_within_parent_etype,
_reassign_nuclear_post_1c_etype) already anchor on the cell_id column and
the UNASSIGNED mirror uses numeric component indices, so none were
affected. The proper -tr- delimiter migration remains deferred.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@imlong4real
imlong4real deleted the claude/goofy-kalam-555feb branch June 24, 2026 20:13
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