Skip to content

refactored StrataMap pre-processing code - #317

Open
cornhundred wants to merge 1 commit into
DEGA-455-IST-preprocessing-codefrom
DEGA-455-NF
Open

refactored StrataMap pre-processing code#317
cornhundred wants to merge 1 commit into
DEGA-455-IST-preprocessing-codefrom
DEGA-455-NF

Conversation

@cornhundred

Copy link
Copy Markdown
Collaborator

Review and Refactor Summary — IST → StrataMap Preprocessing Script

Renamed IST → StrataMap (full rename)

  • File renamed: IST_Landscape_Pre-process.pyStrataMap_Landscape_Pre-process.py
  • "technology" value written into landscape_parameters.json updated
  • technology= arguments passed to dega.pre functions updated
  • CLI description= updated

Broke up main() into smaller functions

Previously one ~350-line function; now split into named steps:

  • _process_image
  • _process_cell_segmentation
  • _process_gene_metadata
  • _save_landscape_parameters
  • _save_dummy_meta_cluster
  • _process_cbg
  • _process_transcripts
  • Small helpers: _safe_polygon, _simple_format, _transform_polygon, _tile_grid_shape, _load_prep_stats

main() now just calls these in the original order — behavior is unchanged.

Reused existing code instead of duplicating

  • make_column_names_unique_fast was defined almost identically in both this file and run_pre_processing.py.
  • Hoisted it into landscape.py as make_column_names_unique, exported via dega.pre, and updated both call sites (removing the now-unused local copy and its defaultdict import in run_pre_processing.py).
  • Everything else (image pyramid generation, _get_name_mapping, read_cbg_mtx, save_cbg_gene_parquets, write_pseudotranscripts_from_sbg, etc.) already reused shared dega.pre code.
  • Left the StrataMap-specific logic (custom OME-TIFF handling, Expanded_5um_cell_contour_coords.csv polygon format, barcode-encoded transcript coordinates) as-is — it genuinely isn't shared with the Xenium/MERSCOPE path in boundary_tile.py/trx_tile.py, and forcing a cross-technology abstraction there would be a riskier, larger change.

Bugs/cleanup fixed while touching the file

  • CLI defaults bug: --tile_size, --image_scale, --jitter had no default=, so omitting them on the command line silently passed None into main(), overriding its real defaults (500 / 1.0 / 1) and breaking tile-grid arithmetic. Added matching defaults.
  • Missing required flags: --data_dir / --sample / --path_landscape_files weren't marked required=True, so omitting them produced a confusing None-path FileNotFoundError instead of a clear argparse error.
  • Removed unused imports (scipy.sparse.coo_matrix, pathlib.Path).
  • Removed ~40 lines of commented-out dead code for an old (non-segmented) cell-metadata path.

Verification

  • py_compile passes on all touched files
  • ruff check clean on the shared modules
  • git mv used to preserve file history
  • Existing tests/unit/test_pre suite (26 tests) still passes

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