Repository navigation
fix: handle missing Precursor (None) in spectrum parsing, annotation, and MS2PIP feature generation - #284
Open
rpinho wants to merge 1 commit into
Open
fix: handle missing Precursor (None) in spectrum parsing, annotation, and MS2PIP feature generation#284rpinho wants to merge 1 commit into
rpinho wants to merge 1 commit into
Conversation
… and MS2PIP feature generation Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01LKxc9GKLwnyeV2jaZBxH9N
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.
Summary
When callers construct
ms2rescore_rs.MS2Spectrum(identifier=..., mz=..., intensity=...)without aprecursor(relying on the charge in the ProForma string),annotate_spectra()produces anAnnotatedMS2Spectrumwithprecursor=None. Passing those spectra intoMS2PIPFeatureGenerator.add_features()then crashes insidems2pip._spectrum_processing._to_observed_spectrum()(ms2pip4.2.0) withAttributeError: 'NoneType' object has no attribute 'mz'. Separately,add_precursor_values()inms2rescore/parse_spectra.pyunconditionally readsms2.precursor.{rt,im,mz}and raisesAttributeErrorif a spectrum reader yieldsprecursor=None.Who hits this: Python API users passing
ms2rescore_rs.MS2Spectrumobjects without aPrecursor(charge supplied via ProForma) toannotate_spectra()andMS2PIPFeatureGenerator.add_features()(#280).Changes
ms2rescore/parse_spectra.py:_ensure_precursor()to construct a newMS2SpectrumorAnnotatedMS2Spectrumwith defaultPrecursor()whenspectrum.precursor is None, without mutating caller objects.annotate_spectra()to normalizeprecursor=Noneinputs via_ensure_precursor()so annotated spectra are directly consumable by downstream tools such asms2pip.correlate().add_precursor_values()to treatms2.precursor is Noneas(0.0, 0.0, 0.0)instead of crashing onms2.precursor.rt.ms2rescore/feature_generators/ms2pip.py:MS2PIPFeatureGenerator.add_features(), temporarily substitute_ensure_precursor()aroundms2pip.correlate()whenever anypsm.spectrum.precursor is None(zero copies when precursors are already present) and restore the original spectrum objects in afinally:block even ifcorrelate()raises.tests/test_parse_spectra.py&tests/test_feature_generators_ms2pip.py:add_precursor_values(),annotate_spectra()(withextended=False/True),MS2PIPFeatureGenerator.add_features()(raw,annotate_spectra, and pre-annotatedprecursor=Noneinputs), mixed explicit/missing precursors, and missing-charge controls (confirming zero fabricated charges or features).Note:
_to_observed_spectrum()itself lives inCompOmics/ms2pip, so a complementaryprecursor is Noneguard inms2pipwould also help directms2pip.correlate()callers.Verification
ms2pipweights, raw,annotate_spectra, and pre-annotatedprecursor=Noneinputs match all 71MS2PIPFeatureGeneratorfeatures ofprecursor=Precursor()controls bit-for-bit, explicitPrecursormetadata is preserved verbatim, and original spectrum objects are restored even after a forced exception insidecorrelate().120 passed, 4 deselectedvs110 passed, 4 deselectedonmain), along withruff check(onms2rescore/and both touched test files) andmypyon the modified modules.Fixes #280
🤖 Generated with Claude Code
https://claude.ai/code/session_01LKxc9GKLwnyeV2jaZBxH9N