fix(flashlfq): bound each peak window to one charge state - #1130
Open
trishorts wants to merge 1 commit into
Open
fix(flashlfq): bound each peak window to one charge state#1130trishorts wants to merge 1 commit into
trishorts wants to merge 1 commit into
Conversation
A ChromatographicPeak carries one isotopic envelope per scan per charge state, so taking Min/Max of IndexedPeak.M across all of them produced a single window spanning the gap between the charge states rather than a window around the peak. For EGFQVADGPLYR traced at z=2 (676.3 m/z) and z=3 (451.2 m/z) that is a 226 Da window whose contents are the rest of the spectrum, and 226x the rows of the single-charge case. PeakWindow.Create now takes the charge state whose envelopes bound the window, and CreateForEachChargeState yields one window per charge state in ascending order. WritePeakWindows writes them all under the peak's single id, told apart by the Peak Charge column, so the correspondence with QuantifiedPeaks is unchanged. ApexRetentionTime is now the apex of the window's own charge state: the peak's overall apex can belong to another charge state whose scan lies outside the window. Peak RT Start/Apex/End are renamed Window RT * to match what they have always measured. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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.
@Alexander-Sol — this targets
PeakEnvelopeOutput, so it lands inside #1122 rather than alongside it. It's the one blocking item from my review there; the other four findings are design calls I've left to you.The problem
ChromatographicPeak.IsotopicEnvelopesholds one envelope per scan per charge state — that is whatNumChargeStatesObservedcounts.PeakWindow.Createtook a singleMin/MaxofIndexedPeak.Macross all of them, so a peptide traced at more than one charge got one window spanning the gap between the charge states.Measured on
PeakEnvelopeOutputbefore this change, with EGFQVADGPLYR (1350.66 Da) at z=2 (676.3 m/z) and z=3 (451.2 m/z), over a synthetic MS1 with one peak every 0.5 m/z:226x the rows, and essentially none of that 226 Da is co-elution around the precursor — it's the rest of the spectrum. On real Orbitrap MS1 data (10-50k peaks over 350-1500 m/z) the output is effectively unbounded. I suspect the 200 Da window you benchmarked in the PR description is exactly this rather than a pathological case.
The change
PeakWindow.Createnow takes thechargeStatewhose envelopes bound the window, and only those envelopes setMinMz/MaxMz, the scan span, and the peakfinding flags.PeakWindow.CreateForEachChargeStateyields one window per traced charge state, ascending.PeakWindow.ChargeStateis exposed, and thePeak Chargecolumn now carries the window's charge state rather thanApex?.ChargeState ?? 0.WritePeakWindowswrites every charge state of a peak under that peak's singlepeakId, distinguished byPeak Charge. The correspondence with QuantifiedPeaks that the comment there promises is unchanged.ApexRetentionTimeis now the apex of the window's own charge state. The peak's overall apex can belong to a different charge state whose scan lies outside the window entirely, which would have put an out-of-range RT in theRT Apexcolumn.Peak RT Start/Peak RT Apex/Peak RT Endrenamed toWindow RT *, since they describe the window's scan span and that span is now per charge state.Tests
Your 13 tests still pass, updated for the new signature. Two added:
TestPeakWindowIsBoundedPerChargeState— the regression above. Builds the two-charge peak over a spectrum with a peak every 0.5 m/z, asserts two windows in ascending charge order, each exactly2 * mzExpansionwide and centred on its own m/z, and that the total peak count stays under 50 where the old bounding box swept in ~1356.TestPeakWindowApexIsPerChargeState— z=2 apexes in the first scan and z=3 in the last; asserts each window reports its own apex rather than the peak's.TestWritePeakWindowsadditionally asserts every row'sPeak Chargeis a charge the peak was actually traced at, and that every traced charge state contributed rows.Also added
BuildMultiChargePeak, so a test can build the peak FlashLFQ actually produces for a multiply-charged peptide;BuildPeaknow delegates to it and is unchanged for callers.Verification
x64|Debug, 0 errors.TestPeakWindowpass.upstream/master: 98.99% (196/198 changed executable lines), target 90. No file below the bar.Take it, adapt it, or close it — whichever is least friction for you.