Skip to content

[API,FEATURE,FORMAT,GUI] Add fragment m/z errors to peak annotations - #9822

Draft
timosachsenberg wants to merge 2 commits into
OpenMS:developfrom
timosachsenberg:agent/peak-annotation-mz-errors-4414
Draft

timosachsenberg wants to merge 2 commits into
OpenMS:developfrom
timosachsenberg:agent/peak-annotation-mz-errors-4414

Conversation

@timosachsenberg

@timosachsenberg timosachsenberg commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

Description

Fixes #4414.

Peak annotations previously retained only the observed peak position. That made fragment errors unavailable after annotations had been persisted or loaded.

This PR adds one canonical optional value, PeakAnnotation::theoretical_mz, and derives both signed error representations from it:

  • getMZError(): observed minus theoretical m/z in Th
  • getMZErrorPPM(): the same error normalized by theoretical m/z

Unknown theoretical positions remain distinguishable from a real zero error. Ppm error is undefined when the theoretical m/z is zero.

Changes

  • PeptideHit::PeakAnnotation: new std::optional<double> theoretical_mz, getMZError(), getMZErrorPPM(); comparison and hashing include the new field
  • idXML: theoretical m/z is an optional fifth field of the fragment_annotation records (four-field records still load)
  • mzIdentML:
    • writing: product ion m/z error arrays (Measure_error, unit m/z); annotations with and without a theoretical m/z go to separate IonTypes so the parallel arrays stay aligned and a missing error is never written as 0
    • reading: fragment annotations are now read for regular (non-cross-link) PSMs too; Measure references are resolved through their CV terms, and error arrays in m/z or ppm are converted to theoretical m/z; arrays that do not match the IonType index raise a ParseError
    • the parser is written against the libxml2-based MzIdentMLDOMHandler on develop
  • OMS: new peak_theoretical_mz column; schema version 7 (version 6 is already taken on develop by the processing actions); older files load without the value
  • producers that now set the theoretical m/z: SpectrumAnnotator, OpenPepXL (OPXLHelper), SimpleSearchEngine, ProSE (both annotation paths in PROSE/ProSEHits.cpp; with fragment recalibration the error is relative to the reported, uncorrected m/z), MetaboliteSpectralMatching (hyperscore and MVH, i.e. also NucleicAcidSearchEngine), MSP import (/delta and /deltappm), Sage import (fragment_mz_calculated), mzPAF toPeakAnnotation()
  • mzPAF: MzPAFDeltaUnit::MZ names the default unitless delta (an m/z delta, per the mzPAF spec); DALTON stays as an alias
  • pyOpenMS: theoretical_mz (None when unknown), getMZError(), getMZErrorPPM(), MzPAFDeltaUnit.MZ
  • TextExporter: id:annotations documentation mentions the optional fifth field
  • SimpleSearchEngine fix: fragment annotations, and the meta values derived from the same alignment (median fragment error, longest ion run, matched ion current), now use the search's fragment:mass_tolerance instead of a default SpectrumAlignment with a fixed 0.3 Da window, as ProSE already does. The new errors made this visible: with a 10 ppm search tolerance, a b3++ 1157 ppm away was annotated.

User impact

API users and downstream tools can read both absolute (Th) and ppm fragment errors without storing two redundant values that could become inconsistent. The value survives idXML, mzIdentML and OMS round-trips.

Compatibility: idXML files that carry the fifth field cannot be read by OpenMS releases before this change (their reader requires exactly four fields per annotation). OMS files written with schema version 7 are not readable by older versions either.

SimpleSearchEngine: identifications and scores are unchanged, but PSMs carry fewer fragment annotations (only those within the fragment tolerance), and their median fragment error, matched ion current and longest ion run change accordingly. OpenNuXL's autotune (on by default) runs SimpleSearchEngine and sets its fragment tolerance from these median errors, which now only include fragments within the initial tolerance; on real data the tuned tolerance will usually be tighter. Autotune only applies with more than 100 PSMs at 1% FDR, so the OpenNuXL tests are not affected.

Tests

  • Class tests: PeptideHit, IdXMLFile, MzIdentMLFile (regular and cross-link round trips, ppm input, custom Measure IDs, legacy Measure_ref, misaligned arrays), OMSFile (round trip and a legacy v3 file), MzPAF, MSPFile, SpectrumAnnotator, OPXLHelper, ProSEAlgorithm, MetaboliteSpectralMatching
  • pyOpenMS: test_peak_annotation.py
  • TOPP reference files:
    • THIRDPARTY/SageAdapter_1_out.idXML: theoretical m/z values as reported by Sage, taken from a CI run of this branch (identical on all five platforms)
    • OpenPepXL_output.mzid (real Measure_error arrays), OpenPepXL_output.idXML and NucleicAcidSearchEngine_11_out.idXML: the changed lines were taken from the tool output of a CI run of this branch (identical on Linux x86 g++ and clang++, Linux ARM and macOS). Only the fragment annotation lines change; the existing fields of every annotation are unchanged. All errors are within the tool's fragment tolerance.
    • SimpleSearchEngine_1_out.idXML (0.1 Da) and SimpleSearchEngine_2_out.idXML (10 ppm): taken from a CI run with the annotation tolerance fix (identical within the comparison tolerance on all five platforms). Besides the theoretical m/z, annotations outside the search tolerance are gone (largest error now 0.091 Th and 9.3 ppm), and the median fragment error, matched ion current and one longest ion run change accordingly. SimpleSearchEngine_3 (FASTA alias) produces the same output as SimpleSearchEngine_1.
    • Two numbers were partly hidden by GitHub's secret masking in the CI logs: an unchanged intensity keeps its previous value, and one OpenPepXL theoretical m/z is cut off after the sixth decimal, well within the comparison tolerance.
    • The TOPP test definitions are the same as on develop: no fragment_annotation or Measure_error whitelists are added.

Validation

Follow-ups

  • TOPPView: develop moved the GUI to OpenMS-TOPP-GUI, so the theoretical m/z and Th/ppm error columns for TOPPView have to be a separate PR there.
  • OpenNuXL producers and QPX/Arrow/DataFrame exports do not yet populate or preserve theoretical_mz.

AI disclosure

  • This PR contains substantial AI-generated work (Claude Code). The commits carry Co-authored-by: trailers. The human author has to review, understand and test the change before it is merged.

https://claude.ai/code/session_0149aXmbE4Uu2whvKADHjd7e


Generated by Claude Code

Store an optional theoretical m/z on peak annotations and derive signed errors in Th and ppm. Persist the value through idXML, mzIdentML, and OMS, expose it in TOPPView and pyOpenMS, and populate it in annotation producers.

Fixes OpenMS#4414

@timosachsenberg timosachsenberg left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed optional theoretical m/z propagation, missing-versus-zero handling, idXML/OMS persistence, mzIdentML array parsing/writing and GUI annotation conversion at b1e7c3c. No additional substantive runtime defect found in those paths. The build/test workflow is still red: the GCC job reports PeptideHit_test (line 330) and TOPP_SageAdapter_1_out1 failing; the Sage comparison still expects four-field annotations while output now includes theoretical m/z. Those test expectations need reconciliation before the checks can pass. Wheel CI passed. I inspected the existing test logs rather than rebuilding OpenMS locally.

This branch has not been deployed

No deployments
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.

add fragment error to peak annotation class

1 participant