Repository navigation
fix(correction): correct integrated areas once instead of every scan - #313
Draft
Jack-Coutts wants to merge 1 commit into
Draft
Jack-Coutts wants to merge 1 commit into
Jack-Coutts wants to merge 1 commit into
Conversation
Jack-Coutts
force-pushed
the
fix/177-correct-integrated-areas-v2
branch
from
November 10, 2026 19:37
2fd9df8 to
bdd3477
Compare
Collaborator
Author
|
Review verdict for head bdd3477: not ready. Reviewed by GPT-6.1 Sol. The merge waits for a method decision from the maintainer. What Sol ran:
What it found:
What holds:
Defects already on Nothing was fixed in review. |
Jack-Coutts
marked this pull request as draft
November 10, 2026 20:11
Collaborator
Author
This was referenced Nov 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #177. Fixes #202. Re-applies #213 onto
main.The bug
Natural-isotope correction solved the correction matrix at every scan, set negative scans to 0, and then integrated the corrected traces. In an isotopologue with no real label, noise swings above and below 0. Zeroing each negative scan kept only the positive swings, so unlabelled and small peaks showed false label. A peak with no raw signal at all could export 100% label incorporation.
The tiles had a second problem (#202). For a labelled compound with deconvolution off, the tile verdict read the stored corrected EIC, which does not exist until the first export, so it fell back to raw areas. The export then judged the corrected areas, and a peak near the threshold could pass on screen and fail in the export.
The fix
Every number now integrates the raw traces once and corrects that area vector once.
NaturalAbundanceCorrector.correct_areassolves A x = b on the integrated areas and sets negatives to 0. The export, the tile verdicts (get_compound_areas), the Isotopologue ratio bars and Process External Data all use it. The export no longer readseic_corrected, so the tiles and the export compute the same corrected areas from the same raw EIC.The corrected EIC plot is unchanged. It still corrects every scan to draw the traces and draws negative scans at 0. That trace is a picture of the correction, not the number: an isotopologue whose corrected area is 0 can still show small positive blips. On the bench data, Glycerol in
Std_MM_01draws M+1 and M+2 blips that the old code integrated to 30.6 and 22.2. The bars, tiles and export now show 0. The reference docs say this.Docs: the correction reference's section 3 now describes area-first correction and drops the claim that per-scan correction is more accurate. The Process External Data pages drop "Approximate Mode", because both workflows now correct the integrated areas. The README upgrade notes and the export's changelog note say the ratio sheets move for small peaks.
Results
bench/reference.py updateis committed with aHISTORY.mdentry. Labelled bench dataset:No real lab dataset was available on the test machine, so these numbers come from the synthetic bench data only.
Checks
tests/test_corrected_area_noise_bias.py: an unlabelled M+0 peak of area 3000 with zero-mean noise on M+1 to M+3, deconvolution off and on. The tile areas, the export's corrected areas and the bars must all equal[3000, 0, 0, 0]. Onmainthe tile areas are the raw areas with deconvolution off ([2242.19, 505.44, 213.67, 32.18]) and are biased with deconvolution on ([3004.69, 526.51, 407.73, 399.05]). Both cases pass with the fix.uv run python -m pytest -q: 673 passed.bench/reference.py checkafter the update: OK.Left out
eic_correctedbefore it runs (ensure_corrections_for_export), although no number reads it now. Removing it would touchprocess_all_corrections, which fix(eic): regenerate deleted compounds and samples on a mass tolerance change #306 changes.