Repository navigation
Keep MGF arrays aligned when a peak line has no intensity - #227
Merged
levitsky merged 2 commits intoOct 26, 2026
Merged
Conversation
A peak line with only an m/z value appended the m/z and then hit the IndexError handler, so the intensity (and charge) arrays came out shorter than the m/z array and every later intensity was attributed to the wrong m/z. The handler was meant to tolerate such lines; store NaN for the missing intensity and a masked charge so the arrays stay aligned.
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.
pyteomics 5.0.1 and master return m/z
[100, 150, 200]but intensity[1, 3], so 3 is reported for m/z 150 instead of 200. The charge array is short by one too.Why: the peak loop appends the m/z, then
float(l[1])raises IndexError. The handler (except IndexError: pass) swallows it, but the m/z has already been appended.Fix: parse the whole line first, then append to every array. A missing intensity becomes NaN and a missing charge becomes masked, as for other lines without a charge.
Caveat for whoever reviews this: Mascot's current rules say an MS/MS peak line holds an m/z and an intensity, so a line with only an m/z is malformed. The bug is that pyteomics silently misaligns the arrays instead of either keeping them aligned or raising. If the maintainers would rather raise a PyteomicsError, that is a one-line change.
Tested: new
test_mz_only_peak_lines(MGF and IndexedMGF) fails on master and passes with the fix. Full suite 467 → 468 passed (same 10 sandbox failures). The real MGF set (32,691 spectra) gives the same hash before and after. It contains no m/z-only lines, so in our data this is only robustness.