Skip to content

fix(eic): keep each stored tR window when the mass tolerance changes (#187) - #304

Merged
Jack-Coutts merged 1 commit into
mainfrom
fix/187-reload-keeps-tr-windows
Nov 10, 2026
Merged

Jack-Coutts merged 1 commit into
mainfrom
fix/187-reload-keeps-tr-windows

Conversation

@Jack-Coutts

Copy link
Copy Markdown
Collaborator

Fixes #187.
Re-applies #217 onto main.

The bug

Changing the mass tolerance re-extracted every EIC at the default 0.2 min tR window. A window set with Apply window was lost, and so was the wider window Add Compound extracts at from a compound's tR tolerance. Plots narrowed and the tR Window field changed. A window narrower than 0.2 was widened instead.

The fix

regenerate_all_eics_with_mass_tolerance in eic_importer.py now reads each sample's stored EIC windows and re-extracts each compound at its stored window. It still widens a window that would not cover the integration offsets. A compound with no stored EIC in a sample keeps the old rule, the default window or the offset minimum. The shared window passed to the extraction is now 0.0, so it no longer widens a narrower stored window.

The user guide and the mass tolerance reference say that a tolerance change keeps each EIC's tR window.

Checks

  • tests/test_mass_tolerance_keeps_tr_window.py drives the window. It writes a CDF, imports it, sets Glucose's window with Apply window (0.9, and 0.15 in a second case), adds Lactate with a 0.6 tR tolerance through Add Compound, then changes the mass tolerance. It asserts each stored window and the EIC's time range. Without the fix both cases fail, for example {'Glucose': (0.2, 4.8, 5.2)} != {'Glucose': (0.9, 4.1, 5.9)} and {'Lactate': (0.2, 4.8, 5.2)} != {'Lactate': (0.6, 4.4, 5.6)}. With it, 2 passed.
  • uv run python -m pytest -q: 673 passed.
  • bench/reference.py check: exported results unchanged.

Left out of #217

Its test in test_rt_window_centering.py, which stubbed the CDF reader and called the function directly. The new test runs through the window in its own file. The subquery and second bind parameter in the per-sample query are replaced by a separate query for the stored windows, so this does not touch the query's WHERE clause or parameters.

@Jack-Coutts

Copy link
Copy Markdown
Collaborator Author

Review verdict for head 4de1cca: CLEAN. Reviewed by GPT-6.1 Sol.

What Sol ran:

  • The full suite: 673 passed.
  • The new tests: 2 failed with src restored from origin/main, then 2 passed on the head.
  • The results check: zero changed cells against the reference.
  • Two tolerance reloads in a row through the window, with applied windows of 0.9 and 0.15. Windows, time ranges and exported raw and corrected areas held. A window narrower than its offsets need widened once to 0.5 and stayed there, so the widening does not build up.
  • The shared 0.0 passed to _extract_all_eics_for_file. It is used only in the max with each target's window, so nothing downstream sees it.
  • Soft-deleting a compound. Only compounds.deleted changes, so its EIC rows keep deleted = 0, and fix(eic): regenerate deleted compounds and samples on a mass tolerance change #306's rebuild of deleted compounds keeps their stored windows.

What it found:

  • No blocker or warning.
  • main allows duplicate live EIC rows for one sample and compound if import_eics runs twice. The window then wins in no set order. The UI prevents a second folder import, so this is not this pull request's to fix.

Nothing was fixed in review.

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.

Changing mass tolerance discards wider tR windows

1 participant