Repository navigation
Fix decoding of MS-Numpress encoded spectra - #413
Merged
Merged
Conversation
Spectra whose arrays use any MS-Numpress compression term failed to decode: linear and slof raised AttributeError on the removed calling_instance attribute, and pic plus the three 'followed by zlib' terms (MS:1002746-MS:1002748) were not recognized and raised ValueError: Unsupported data type: None. Map all six CV terms to their decoder, zlib-decompress first where the term says so, return the decoded array directly, and support the pure Python fallback.
|
MKoesters
self-requested a review
October 26, 2026 13:31
MKoesters
approved these changes
Oct 26, 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.



pymzml 2.7.0 cannot read the m/z or intensity array of any spectrum that uses MS-Numpress.
AttributeError: 'Spectrum' object has no attribute 'calling_instance'.ValueError: Unsupported data type: None.Why:
_decodeNumpress_to_arraystill looks upself.calling_instance.OT.calling_instancewas removed in 174193e (2023) when Spectrum got its ownobo_translator, and nothing sets it anymore._decode_to_numpyonly checks for the linear and slof names, not pic or the "followed by zlib" names. Those terms are all children of MS:1000572 (binary data compression type) in the PSI-MS CV, and msconvert and OpenMS write them._get_encoding_parametersreturnsd_type = Noneon purpose, but_decode_to_numpythen always reachesraise ValueError(f"Unsupported data type: {data_type}"), even after a successful decode.#332 looks like the same problem for the "followed by zlib" term.
Fix: map the six numpress CV names (plus the legacy
ms-np-*names) to their method, zlib-decompress first when the term says so, and return the decoded float64 array directly. The pure PythonMSNumpressfallback is stateful (MSNumpress(bytearray).decode_linear()), so it is called that way when pynumpress is not installed.Tested:
tests/numpress_spectrum_test.pycovers linear, pic, slof and the three zlib variants, with pynumpress and with the Python fallback. It fails on dev (8 subtests) and passes with the fix.plot_spec_test.pyand fail the same way before and after, because plotly is not installed.black --check pymzmlis clean (black 26.5.1, as in CI).Note: the legacy
MS_Spectrumclass inspec.pykeeps its own copy of the old decoding code.Readerdoes not use it, so this PR leaves it alone.