Skip to content

Keep MGF arrays aligned when a peak line has no intensity - #227

Merged
levitsky merged 2 commits into
levitsky:masterfrom
aaronkanzer:fix/mgf-mz-only-peak-lines
Oct 26, 2026
Merged

levitsky merged 2 commits into
levitsky:masterfrom
aaronkanzer:fix/mgf-mz-only-peak-lines

Conversation

@aaronkanzer

Copy link
Copy Markdown
Contributor
BEGIN IONS
TITLE=a
PEPMASS=500
100 1
150
200 3
END IONS

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.

aaronkanzer and others added 2 commits October 22, 2026 21:29
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.
@levitsky
levitsky merged commit 7a92333 into levitsky:master Oct 26, 2026
15 checks passed
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.

2 participants