Skip to content

refactor(features): adopt histogram template workflow - #86

Merged
georgezakinih merged 6 commits into
FNLCR-DMAP:devfrom
zhan4329:ref/features-server-template
Sep 16, 2026
Merged

georgezakinih merged 6 commits into
FNLCR-DMAP:devfrom
zhan4329:ref/features-server-template

Conversation

@zhan4329

@zhan4329 zhan4329 commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

Description

This PR refactors features_server.py to use the latest SPAC histogram template while preserving the current non-facet user experience.

The server now reads canonical AnnData, converts the existing features inputs to the template contract, and runs the template through the in-memory registry. The template's figure and dataframe remain the canonical results for the plot preview and CSV download.

This creates the execution boundary needed for later facet and agent-facing controls.

Related

  • Template workflow follows Issue #73
  • Builds on the updated environment introduced by SPAC Shiny PR #85
  • Depends on the latest histogram template introduced by SCSAWorkflow PR #433
  • The adapter design was informed by Mousumi's commit ffa8644; PNG conversion was adapted from 5d65369, with Heaven Golladay-Watkins credited as co-author.

Changes

Everything is on the 'Features' tab. The 'Annotation' tab is unchanged.

  • Use shared["adata_main"] instead of reconstructing AnnData.
  • Normalize current UI values before mapping them to template parameters.
  • Execute with save_to_disk=False and show_plot=False, with registry cleanup guaranteed in finally.
  • Keep Plot_By="Feature" and Facet=False explicit for this PR.
  • Serialize the template figure to PNG through a new helper function fig_to_png_bytes() in utils/plot_utils.py, and render the image directly through Shiny. This is to resolve rendering issue introduced by the histogram template.
  • Publish the returned dataframe only after successful execution and cleanup.
  • Preserve button-gated rendering, current grouping behavior, and CSV download.

New ui controls including facets will be exposed in the next PR.

Testing

  • User-tested ordinary, grouped-Together, and repeated renders in Shiny.
  • python -m py_compile server/features_server.py utils/plot_utils.py ui/features_ui.py
  • python -m pytest tests/test_utils/test_plot_utils.py -q — 6 passed
  • git diff --check
  • Focused PNG serialization and figure-closure smoke check passed.

There is not yet committed automated coverage for the new Features adapter or fig_to_png_bytes().

Notes for Review

Suggested order: server/features_server.py, utils/plot_utils.py, then ui/features_ui.py.

The template wrapper must be imported before the Histogram template because the template binds its loader during import.

There is a known issue: in some cases, the title may be too long to render. This needs to be fixed in the SPAC package.

image

zhan4329 and others added 6 commits August 20, 2026 23:23
- map semantic inputs to Histogram template parameters
- pass canonical AnnData through the memory registry
- publish template results after guaranteed cleanup
- describe template delegation in module and server docstrings
- clarify the semantic input snapshot responsibility
- Adapt the PNG conversion boundary from plot-caching commit 5d65369 to preserve the template DPI and intrinsic figure boundary while retaining Shiny's render.plot interface.
- Close source figures after serialization to avoid retained Matplotlib state.

Co-authored-by: Heaven Golladay-Watkins <hgolladay05@gmail.com>
- Replace the Matplotlib display wrapper with direct render.image delivery.
- Preserve the template PNG geometry and let Shiny delete delivered temporary files.
- Remove the unused PNG-to-figure conversion helper.
@zhan4329
zhan4329 marked this pull request as ready for review September 8, 2026 18:41
@georgezakinih
georgezakinih merged commit 5a3cf25 into FNLCR-DMAP:dev Sep 16, 2026
zhan4329 added a commit to zhan4329/SPAC_Shiny that referenced this pull request Sep 16, 2026
- update overview and PR summary to document PR FNLCR-DMAP#86 / FNLCR-DMAP#87 integration strategy
- record combined baseline integration requirements in implementation notes
- update task reassignment links to match renumbered PR plan entries
zhan4329 added a commit to zhan4329/SPAC_Shiny that referenced this pull request Sep 16, 2026
- mark PR FNLCR-DMAP#86 as merged into dev on 2026-09-16 in overview
- add decision D21 recording completion of template delegation PR
- update next steps to integrate PR FNLCR-DMAP#87 and point to Features facet tracker
zhan4329 added a commit to zhan4329/SPAC_Shiny that referenced this pull request Sep 16, 2026
- mark Tasks 3 (verification) and 4 (static Group By controls) complete
- record postponement of Task 5 (shared styling) to cross-tab roadmap
- add PR FNLCR-DMAP#87 summary covering changes, testing, and notes for review
- update overview and implementation notes to coordinate PR FNLCR-DMAP#86 / FNLCR-DMAP#87 integration
zhan4329 added a commit to zhan4329/SPAC_Shiny that referenced this pull request Sep 16, 2026
- mark Tasks 3 (verification) and 4 (static Group By controls) complete
- record postponement of Task 5 (shared styling) to cross-tab roadmap
- add PR FNLCR-DMAP#87 summary covering changes, testing, and notes for review
- update overview and implementation notes to coordinate PR FNLCR-DMAP#86 / FNLCR-DMAP#87 integration
zhan4329 added a commit to zhan4329/SPAC_Shiny that referenced this pull request Sep 16, 2026
- move features-facet-pr-plan.md into docs/plans/pr-plans/
- update cross-references in development-roadmap.md and future-work.md
- record PR FNLCR-DMAP#86 merge in facet plan and prioritize PR 4 (canonical text) before PR 3
- align roadmap calendar milestones with updated PR sequence
zhan4329 added a commit to zhan4329/SPAC_Shiny that referenced this pull request Sep 16, 2026
- update overview with prerequisite PR FNLCR-DMAP#86 and PR FNLCR-DMAP#87 context and open issues
- add decisions D2 (branch stacking) and D3 (inheriting UI structure)
- detail template boundary, Together/Facet conflicts, and verification in notes
- establish development-details tracker structure for facet implementation
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