Skip to content

Fix/efp relative mode per group control from global control#178

Closed
VinLau wants to merge 5 commits intostagingfrom
fix/efp-relative-mode-per-group-control-from-global-control
Closed

Fix/efp relative mode per group control from global control#178
VinLau wants to merge 5 commits intostagingfrom
fix/efp-relative-mode-per-group-control-from-global-control

Conversation

@VinLau
Copy link
Copy Markdown
Collaborator

@VinLau VinLau commented Apr 16, 2026

Fix eFP relative mode per-group control

Problem

The eFP relative color mode and log2 fold change tooltip were using data.control — the average of all group controls across the entire experiment — instead of each tissue's own group.control. This produced incorrect colours and values in any experiment where groups have different controls.

Example: Biotic Stress Botrytis cinerea eFP, AT3G24650

The 18hr group has a control mean of 6.59, the 48hr group has 10.77. The old code averaged these to ~8.68 and used that for everything.

| Tissue | Expected log2 FC | Before | After |
| Mock Treatment (Control) 18hr | 0.00 | -0.40 | 0.00 |
| Treated 18hr | -0.15 | -0.55 | -0.16 | *off by 0.01 due to rounding
| Control 48hr | 0.00 | 0.31 | 0.00 |

XML: https://bar.utoronto.ca/eplant/data/experiment/efps/BioticStressBotrytiscinerea/Arabidopsis_thaliana.xml

The control tissues in each group should always show a fold change of 0.00 and render as neutral/yellow in relative mode. They didn't.

Fix

Commit 1 — per-group control for relative mode

  • EFPTooltip.tsx: tooltip log2 fold change now uses group.control (falls back to data.control, then 1)
  • svg.tsx: useStyles passes group instead of data to getColor, so the relative-mode extremum calculation scales against the group's own min/max and control
  • legend.tsx: removed unused EFPState import; added a comment noting the legend is a global approximation that may not exactly match per-group colours

Commit 2 — preserve absolute mode scaling

  • The first commit broke absolute mode: passing group to getColor meant absolute colours normalised against group.max instead of the experiment-wide data.max, making every tissue appear fully red
  • Added an optional absoluteMax parameter to getColor; absolute mode now uses absoluteMax ?? group.max
  • useStyles passes data.max as the new argument
  • legend.tsx unchanged — it already passes data as its group arg, so the fallback resolves correctly

What was NOT changed

  • The XML parser — group-level <control> tags are parsed correctly
  • The data shape in types.tsx or the loader in views/eFP/index.tsx — per-group control was already computed correctly; only downstream consumers were ignoring it, so we are just making sure it gets read
  • The data.control aggregate field — it remains as a fallback

Screenshots

Relative mode — before (wrong fold changes) → after (correct)

image image

Note

The Eplant/main.tsx change (router basename) is from <other-branch-name>, included because this branch is based on it. It will disappear from this diff once that PR merges.

@VinLau VinLau closed this Apr 16, 2026
@VinLau VinLau deleted the fix/efp-relative-mode-per-group-control-from-global-control branch April 16, 2026 18:30
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