Skip to content

Add animated GIF QC for per-instance and coloc crops#145

Merged
akhanf merged 6 commits intomainfrom
copilot/add-qc-rules-animated-gifs
Apr 5, 2026
Merged

Add animated GIF QC for per-instance and coloc crops#145
akhanf merged 6 commits intomainfrom
copilot/add-qc-rules-animated-gifs

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 4, 2026

Adds two new QC rules that produce animated GIFs of 2D SPIM crops centred on each detected instance, showing all stain channels side-by-side with a hollow circle marker for the equivalent spherical diameter and per-frame annotation.

New rules (qc.smk)

  • qc_stain_instance_gif{stain} wildcard selects the instance type; reads aggregated regionprops parquet; produces one GIF per atlas seg × stain × seg method
  • qc_coloc_instance_gif — same layout for colocalized pairs; reads coloc parquet; gated on do_coloc

Both rules emit two outputs:

  • *instancerandom.gif / *colocinstancerandom.gif — frames in reproducible randomised order
  • *instancesorted.gif / *colocinstancesorted.gif — frames sorted ascending by equivalent spherical radius

Both are wired into rule all_qc.

New script (qc_instance_gif.py)

Shared by both rules via snakemake.params.instance_type = "stain" | "coloc".

Key behaviours:

  • Loads all stain channels from the OME-Zarr; crops a patch_size×patch_size 2D axial slice at each instance's subject-space position via ZarrNii.crop_centered
  • Draws a hollow yellow circle with radius = (3·nvoxels / 4π)^⅓ voxels (avg radius for coloc pairs)
  • Annotation line per frame: idx | pos(x,y,z) | atlas ROI | radius
  • Atlas labels looked up at runtime with ZarrNiiAtlas.label_region_properties; failure is logged and non-fatal
  • Global per-channel intensity normalisation uses the coarsest available pyramid level (progressive fallback: base+5 → base+3 → base+1 → base)
  • Sub-samples deterministically to max_instances when the table is large

patch_size and max_instances are configurable via instance_gif_patch_size / instance_gif_max_instances in the workflow config (defaults 100 / 200).

compute_colocalization.py

Added pos_coloc_x/y/z — subject-space midpoint of the two objects — to the coloc parquet. Required for crop_centered calls in the GIF script (the existing template_coloc_x/y/z are in template space only).

Copilot AI changed the title [WIP] Add QC rules and script for generating animated GIFs Add animated GIF QC for per-instance and coloc crops Apr 4, 2026
Copilot AI requested a review from akhanf April 4, 2026 14:35
@akhanf akhanf marked this pull request as ready for review April 5, 2026 01:24
@akhanf akhanf merged commit e18facc into main Apr 5, 2026
2 checks passed
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