Skip to content

Do not fail on MGF RTINSECONDS ranges - #226

Merged
levitsky merged 3 commits into
levitsky:masterfrom
aaronkanzer:fix/mgf-rtinseconds-range
Oct 26, 2026
Merged

levitsky merged 3 commits into
levitsky:masterfrom
aaronkanzer:fix/mgf-rtinseconds-range

Conversation

@aaronkanzer

Copy link
Copy Markdown
Contributor

Reading an MGF spectrum whose RTINSECONDS is a range raises, and the rest of the file cannot be read:

BEGIN IONS
TITLE=Spectrum 3
PEPMASS=1244.7
SCANS=29-34
RTINSECONDS=95-97
100 1
END IONS
next(mgf.read("rtrange.mgf"))
# ValueError: could not convert string to float: '95-97'

This spectrum is the example in the Mascot MGF documentation (https://www.matrixscience.com/help/data_file_help.html). Its parameter table defines RTINSECONDS as "Retention time or range (in seconds)", a[-b], and the merged peak list section allows "a single retention time to a complex list of retention time ranges". Mascot Distiller writes ranges for summed scans.

Why: _read_spectrum_lines always runs aux.unitfloat(params['rtinseconds'], 'second').

Fix: convert only when the value is a single number. Otherwise keep the string as given, the same way SCANS ranges are kept.

Tested:

  • New test_rtinseconds_range checks that both MGF and IndexedMGF read a range and a single value. It fails on master and passes with the fix.
  • Full suite: 467 passed before, 468 passed after (same 10 sandbox-only map() failures).
  • No change on real files: 32,691 spectra and 2,071,884 peaks (38 GNPS libraries, 17,091 Enveda-180 spectra, and the pyteomics and matchms MGF test data) give the same hash (7ff3778b69f55a99) before and after.

aaronkanzer and others added 3 commits October 22, 2026 21:33
RTINSECONDS can be a range or a list of ranges (the Mascot MGF
documentation uses RTINSECONDS=95-97 as its example), but the reader
converted it with unitfloat unconditionally and raised ValueError, so
the whole file could not be read. Keep the value as a string when it is
not a single number.
@levitsky
levitsky merged commit a5a6be5 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