Skip to content

[FIX] mzML writer: write all scan attributes in the scan, also those kept under their accession - #10323

Merged
timosachsenberg merged 1 commit into
developfrom
claude/nifty-hypatia-gsjz1a
Sep 29, 2026
Merged

timosachsenberg merged 1 commit into
developfrom
claude/nifty-hypatia-gsjz1a

Conversation

@timosachsenberg

@timosachsenberg timosachsenberg commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Description

A follow-up to #10313, which fixed this for the mass resolving power. When OpenMS reads an mzML file and writes it again, CV terms of <scan> come out as userParams. OpenMS reads them back correctly, but other software looks them up by accession and no longer finds them. This PR fixes the two causes.

1. Scan attributes the reader keeps with the spectrum

The reader stores nine scan attributes on the spectrum, because MSSpectrum has no member for them:

  • dwell time, mass resolution, scan rate, elution time
  • filter string, analyzer scan offset, preset scan configuration, mass resolving power, interchannel delay

mzML allows them only in <scan>. So the writer wrote them as userParams of the spectrum:

<!-- msconvert, ThermoRawFileParser -->
<scan>
  <cvParam cvRef="MS" accession="MS:1000512" name="filter string" value="FTMS + p NSI Full ms [350.0000-1400.0000]"/>
  <cvParam cvRef="MS" accession="MS:1000616" name="preset scan configuration" value="1"/>

<!-- the same spectrum after OpenMS, before this PR -->
<spectrum ...>
  <userParam name="filter string" type="xsd:string" value="FTMS + p NSI Full ms [350.0000-1400.0000]"/>
  <userParam name="preset scan configuration" type="xsd:string" value="1"/>
  • Where they go now: all nine are written as CV terms in the first scan, as [FIX] mzML, Thermo and timsTOF readers: keep the mass resolving power; read timsTOF acquisition metadata #10313 does for MS:1000800, in the order the reader handles them. A value of the scan itself takes precedence.
  • By accession: the writer names the terms by accession, because "mass resolving power" is the name of two terms (MS:1000234 and MS:1000800).
  • Elution time: the reader keeps it in seconds without a unit, so it is written with UO:0000010 (second).
  • Not included: scan direction and scan law are not scan attributes. The reader stores them as words ("decreasing", "linear"), and they occur in no test data, so they stay as they are.

2. Scan terms kept under their accession

  • Cause: the reader has special cases for only some scan terms. It keeps the others, e.g. the ion injection time (MS:1000927), on the scan under their accession. QcMLFile and QualityControl's Ms2SpectrumStats look them up there, so the reader stays as it is.
  • The bug: the writer looked meta values up by term name only, so these came out as <userParam name="MS:1000927" ...>.
  • The fix: the writer now also resolves keys that are accessions. It writes a CV term where the mzML mapping allows one, with value and unit as before.
  • Older files: files OpenMS wrote before are repaired when they are written again, because OpenMS reads such a userParam back under the same key.

The in-memory model and the reader are unchanged, so everything reads back as before.

Tests

  • MzMLFile_test: the section from [FIX] mzML, Thermo and timsTOF readers: keep the mass resolving power; read timsTOF acquisition metadata #10313 now covers all nine attributes and the injection time. It checks that:

    • none is left as a userParam or at spectrum level;
    • the CV terms, with their units, are in the scan;
    • schema and semantic validation report no errors or warnings;
    • the values read back.

    It fails with develop's writer.

  • TOPP references: 21 mzML outputs change:

    • which: ExternalCalibration_1/2, FileConverter_4/23, FileFilter_12/28–34/43/44, FileMerger_6/10, HighResPrecursorMassCorrector_1–5;
    • what: 534 userParams became CV terms in the scan and the index offsets changed; no other line changed;
    • how: a script rewrote them in the writer's layout. On the new writer's own outputs that script changes nothing.
  • Verification of the references: I ran the 22 comparisons that use these references with the 2026-09-27 nightly tools:

    • with the new writer, all 22 pass;
    • with develop's writer, all 22 pass against the old references and fail against the new ones.
  • MaRaCluster reference: THIRDPARTY/MaRaClusterAdapter_1_out_1.part1.mzML has these userParams too. MaRaCluster writes that file itself, from test inputs that an older OpenMS wrote, so it does not change.

  • Other class tests: the other mzML class tests in my local build pass with the new writer: CachedMzML*, IndexedMzML*, MSData*Consumer, OnDiscMSExperiment, SpectrumMetaDataLookup and FileHandler.

  • Compiler warnings: GCC 13 and Clang with -Wall -Wextra report no new warnings.

Local setup: built against the 2026-09-27 nightly SDK, with the changed source preloaded. Two MzMLFile_test sections added by #10317 fail in that setup, with develop's writer as well. The SDK predates #10317's library changes.

Checklist

  • Make sure that you are listed in the AUTHORS file
  • Add relevant changes and new features to the CHANGELOG file
  • I have commented my code, particularly in hard-to-understand areas
  • New and existing unit tests pass locally with my changes (against the nightly SDK, see above)
  • Updated or added python bindings for changed or new classes (Tick if no updates were necessary.) (none needed: no API change)

How can I get additional information on failed tests during CI

Click to expand If your PR is failing you can check out

Advanced commands (admins / reviewer only)

Click to expand
  • /reformat (experimental) applies the clang-format style changes as additional commit. Note: your branch must have a different name (e.g., yourrepo:feature/XYZ) than the receiving branch (e.g., OpenMS:develop). Otherwise, reformat fails to push.
  • setting the label "NoJenkins" will skip tests for this PR on jenkins (saves resources e.g., on edits that do not affect tests)
  • commenting with rebuild jenkins will retrigger Jenkins-based CI builds

🤖 Generated with Claude Code

https://claude.ai/code/session_01Av5w5vHqBTv3wPygrM7FSU


Generated by Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Improved mzML export so scan details retained during reading—such as filter settings, scan configuration, resolution, scan rate, and timing information—are written in the appropriate scan records.
    • Recognized scan terms, including ion injection time, are now preserved as controlled-vocabulary terms rather than generic user parameters. This keeps scan metadata more accurately represented and available when exported files are read again.

…kept under their accession

The mzML reader keeps nine scan attributes with the spectrum, as MSSpectrum has
no member for them: dwell time, mass resolution, scan rate, elution time, filter
string, analyzer scan offset, preset scan configuration, mass resolving power
and interchannel delay. mzML allows them only in a scan, so the writer wrote them
as userParams of the spectrum, and other readers lost them once OpenMS had
written a file. #10313 fixed this for the mass resolving power; all of them are
now written as CV terms in the first scan, in the order the reader handles them.
A value of the scan itself takes precedence.

Scan terms the reader has no special case for, such as the ion injection time
(MS:1000927), are kept with the scan under their accession, which is where
QcMLFile and QualityControl look them up. The writer looked meta values up by
term name only, so it wrote these as userParams named after the accession. It
now also resolves accessions and writes a CV term where the mapping allows one.
Files OpenMS wrote before are repaired when they are written again.

The in-memory model and the reader are unchanged.

Tests:
- MzMLFile_test: the resolving power section now covers all nine attributes and
  the injection time: no userParams, the CV terms (with units) in the scan,
  schema and semantic validity, values read back. It fails with develop's writer.
- TOPP references: 21 mzML outputs (ExternalCalibration, FileConverter,
  FileFilter, FileMerger, HighResPrecursorMassCorrector) have the attributes in
  the scan instead of the spectrum, with index offsets recomputed; nothing else
  changes. Run with the 2026-09-27 nightly tools, all 22 comparisons that use
  them pass with the new writer; with develop's writer they pass against the old
  references and fail against the new ones.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Av5w5vHqBTv3wPygrM7FSU
@coderabbitai

coderabbitai Bot commented Sep 29, 2026

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: f2b008b4-c6d5-4c2b-a0a4-c82567fb5746

📥 Commits

Reviewing files that changed from the base of the PR and between 83fc232 and 8bf1bae.

📒 Files selected for processing (24)
  • CHANGELOG
  • src/openms/source/FORMAT/HANDLERS/MzMLHandler.cpp
  • src/tests/class_tests/openms/source/MzMLFile_test.cpp
  • src/tests/topp/ExternalCalibration_1_MS1_out.mzML
  • src/tests/topp/ExternalCalibration_2_MS2_out.mzML
  • src/tests/topp/FileConverter_23_output.mzML
  • src/tests/topp/FileConverter_4_output.mzML
  • src/tests/topp/FileFilter_12_output.mzML
  • src/tests/topp/FileFilter_28_output.mzML
  • src/tests/topp/FileFilter_29_output.mzML
  • src/tests/topp/FileFilter_30_output.mzML
  • src/tests/topp/FileFilter_31_remove_collision_energy.mzML
  • src/tests/topp/FileFilter_32_select_collision_energy.mzML
  • src/tests/topp/FileFilter_33_remove_isolation_window.mzML
  • src/tests/topp/FileFilter_34_select_isolation_window.mzML
  • src/tests/topp/FileFilter_43_output.mzML
  • src/tests/topp/FileFilter_44_output.mzML
  • src/tests/topp/FileMerger_10_output.mzML
  • src/tests/topp/FileMerger_6_output.mzML
  • src/tests/topp/HighResPrecursorMassCorrector_1035_1178_4_out.mzML
  • src/tests/topp/HighResPrecursorMassCorrector_2538_1091_2_out.mzML
  • src/tests/topp/HighResPrecursorMassCorrector_2810_1091_3_out.mzML
  • src/tests/topp/HighResPrecursorMassCorrector_2860_1103_3_out.mzML
  • src/tests/topp/HighResPrecursorMassCorrector_3070_1191_3_out.mzML

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 2 remain after this review.


📝 Walkthrough

Walkthrough

The mzML writer now serializes recognized scan metadata as controlled-vocabulary terms inside scans. The change covers nine scan attributes, accession-keyed terms, unit handling for elution time, and output validation.

Changes

Scan metadata serialization

Layer / File(s) Summary
Scan attribute writing and unit validation
src/openms/source/FORMAT/HANDLERS/MzMLHandler.cpp, src/tests/class_tests/openms/source/MzMLFile_test.cpp, CHANGELOG
Recognized scan attributes are written as CV terms in scans. Scan-level values take precedence over spectrum-level values, which are emitted only in the first scan when needed. Tests check serialized placement, values, units, and readback.
Serialized output fixture updates
src/tests/topp/{ExternalCalibration*,FileConverter*,FileFilter*,FileMerger*,HighResPrecursorMassCorrector*}.mzML
Expected mzML output fixtures move scan metadata from user parameters to scan CV terms. Their indexed offsets are updated to reflect the changed XML layout.

Priority: ➖ Normal

Change: Bug fix

Merge Risk: ⚪ Minimal · up to 8bf1b

No actionable merge-blocking issue is established; the scan metadata change is ready for normal validation.

Security Architecture Review

Security architecture risk: 🔵 Low · up to 8bf1b

The output format changes in a meaningful way, but the reviewed writer paths do not show a new privilege or input boundary. External consumers and the full security exposure have not been assessed.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The affected exposure is serialized scan metadata in mzML files and software that subsequently interprets those files; no wider authority change is established by the reviewed writer paths.

Trust Boundaries and Controls

  • observed — The writer still passes metadata through XML-attribute escaping. Generic accession-keyed terms require vocabulary membership and location validation; the newly routed scan attributes instead use fixed vocabulary accessions.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 2 files. (22 skipped: 2… Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: writing all retained mzML scan attributes inside the scan, including accession-keyed terms.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 2 files. (22 skipped: 22 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

A rabbit checks each scan at night,
And sets its terms in fields just right.
The units find their proper place,
The values keep their measured trace.
New offsets mark the bytes in line,
While moonlit carrots softly shine.

Comment @coderabbitai help to get the list of available commands.

@timosachsenberg
timosachsenberg merged commit bf0570a into develop Sep 29, 2026
33 checks passed
@timosachsenberg
timosachsenberg deleted the claude/nifty-hypatia-gsjz1a branch September 29, 2026 07:33
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