Repository navigation
[FEAT] ThermoRawFile: extract full mzML metadata + fix polarity - #9623
Conversation
Extend the in-process Thermo RAW reader to populate the MSExperiment with the metadata msconvert/ProteoWizard writes, all mapped to their PSI-MS CV terms: - per spectrum: total ion current, base peak m/z + intensity, lowest/highest observed m/z, scan filter string, scan window (parsed from the filter), ion injection time (stored on an Acquisition so it serializes as MS:1000927 under <scan>), and FAIMS compensation voltage (driftTime + FAIMS_COMPENSATION_VOLTAGE) - instrument: ion source, mass analyzer(s), ion detector(s), software version - experiment: creation date, sample name - a total ion current chromatogram Fix the spectrum polarity mapping: the bridge returns the raw Thermo PolarityType enum (Negative=0, Positive=1, Any=2); the previous mapping (1->POSITIVE, 2->NEGATIVE) mislabeled negative/any scans. Verified empirically against real RAW data. Also map activation independently of collision energy (so zero-CE ETD scans keep their activation method) and add PQD. Extend ThermoRawFile_test with assertions covering the new metadata and its mzML round-trip. Co-Authored-By: Claude Opus 4.8 <[email protected]>
📝 WalkthroughWalkthrough
ChangesThermoRawFile metadata enrichment and TIC chromatogram
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/openms/source/FORMAT/ThermoRawFile.cpp (1)
56-72: 💤 Low valueConsider using
OpenMS::Stringfor locale-independent parsing.
std::stodrespects the current C locale, so on systems where the decimal separator is comma (e.g., German locale), strings like"12.34"may parse incorrectly.OpenMS::String::toDouble()is locale-independent.♻️ Suggested change
bool parseDouble(const std::string& s, double& out) { if (s.empty()) { return false; } try { - size_t pos = 0; - out = std::stod(s, &pos); - // Reject trailing garbage (e.g. "12.3abc") but tolerate surrounding whitespace. - while (pos < s.size() && std::isspace(static_cast<unsigned char>(s[pos]))) { ++pos; } - return pos == s.size(); + out = OpenMS::String(s).trim().toDouble(); + return true; } - catch (...) + catch (const Exception::ConversionError&) { return false; } }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/openms/source/FORMAT/ThermoRawFile.cpp` around lines 56 - 72, The parseDouble function uses std::stod for parsing doubles, which is locale-dependent and will fail in locales where the decimal separator is comma instead of dot (e.g., German locale). Replace the std::stod call in the parseDouble function with OpenMS::String::toDouble(), which is locale-independent and will correctly parse double values regardless of the system locale setting.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/tests/class_tests/openms/source/ThermoRawFile_test.cpp`:
- Around line 143-144: The test currently validates the TIC type for the
reloaded object only but does not explicitly validate the TIC type for the
original object. After the TEST_EQUAL statement that checks if
original.getChromatograms() is not empty, add a type-specific assertion that
validates the TIC type of the original object (mirroring the validation already
in place for reloaded) to ensure the extraction contract is explicitly tested
for both the original and reloaded chromatogram objects.
---
Nitpick comments:
In `@src/openms/source/FORMAT/ThermoRawFile.cpp`:
- Around line 56-72: The parseDouble function uses std::stod for parsing
doubles, which is locale-dependent and will fail in locales where the decimal
separator is comma instead of dot (e.g., German locale). Replace the std::stod
call in the parseDouble function with OpenMS::String::toDouble(), which is
locale-independent and will correctly parse double values regardless of the
system locale setting.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 05348132-5230-4329-91e2-3c2e28030d17
📒 Files selected for processing (2)
src/openms/source/FORMAT/ThermoRawFile.cppsrc/tests/class_tests/openms/source/ThermoRawFile_test.cpp
| TEST_EQUAL(original.getChromatograms().empty(), false) | ||
| TEST_EQUAL(reloaded.getChromatograms().empty(), false) |
There was a problem hiding this comment.
Assert TIC type in original, not only non-empty chromatograms.
This currently validates TIC type for reloaded only. Add a type-specific assertion for original as well so the extraction contract is explicitly covered.
Suggested test tightening
- TEST_EQUAL(original.getChromatograms().empty(), false)
- TEST_EQUAL(reloaded.getChromatograms().empty(), false)
+ TEST_EQUAL(original.getChromatograms().empty(), false)
+ TEST_EQUAL(reloaded.getChromatograms().empty(), false)
+ bool original_has_tic = false;
+ for (const MSChromatogram& c : original.getChromatograms())
+ {
+ if (c.getChromatogramType() == ChromatogramSettings::ChromatogramType::TOTAL_ION_CURRENT_CHROMATOGRAM)
+ {
+ original_has_tic = true;
+ }
+ }
+ TEST_EQUAL(original_has_tic, true)
bool reloaded_has_tic = false;
for (const MSChromatogram& c : reloaded.getChromatograms())
{
if (c.getChromatogramType() == ChromatogramSettings::ChromatogramType::TOTAL_ION_CURRENT_CHROMATOGRAM)
{
reloaded_has_tic = true;
}
}
TEST_EQUAL(reloaded_has_tic, true)🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/tests/class_tests/openms/source/ThermoRawFile_test.cpp` around lines 143
- 144, The test currently validates the TIC type for the reloaded object only
but does not explicitly validate the TIC type for the original object. After the
TEST_EQUAL statement that checks if original.getChromatograms() is not empty,
add a type-specific assertion that validates the TIC type of the original object
(mirroring the validation already in place for reloaded) to ensure the
extraction contract is explicitly tested for both the original and reloaded
chromatogram objects.
Add entries for all substantive non-test PRs merged since the last changelog update: - #9623 ThermoRawFile full mzML metadata extraction + polarity fix - #9602 New FileInfo library class usable from C++ and pyOpenMS - #9521 IMAGING multi-region support (add missing PR reference) - #9620 Deisotoper::isToleranceSupported + ProSE/SSE crash fix on low-res data - #9610 DistanceMatrix::setValue cached-minimum guard fix - #9497 DistanceMatrix::operator==, ClusteringGrid, File path guard fixes - #9583 LogStreamBuf thread-safety fix - #9514 CI Windows migration to Visual Studio 2026 Claude-Session: https://claude.ai/code/session_01YLg6pWyjyTxpWAU6mgrDzC Co-authored-by: Claude <[email protected]>
What
Extends the in-process Thermo RAW reader (
ThermoRawFile, theWITH_THERMO_RAWpath) to populate theMSExperimentwith the metadatamsconvert/ProteoWizard writes, all mapped to their PSI-MS CV terms so it round-trips to mzML identically to how OpenMS reads an msconvert file:MS:1000285), base peak m/z + intensity (MS:1000504/505), lowest/highest observed m/z (MS:1000528/527), scan filter string, scan window (parsed from the filter), ion injection time (stored on anAcquisitionso it serializes asMS:1000927under<scan>), and FAIMS compensation voltage (setDriftTime+DriftTimeUnit::FAIMS_COMPENSATION_VOLTAGE→MS:1001581).Bug fix: spectrum polarity
The bridge's
polarity()returns the raw ThermoPolarityTypeenum —Negative=0, Positive=1, Any=2— which is the opposite of what the bridge's own header comment andcv_polarity()helper claim. The previous mapping (1→POSITIVE, 2→NEGATIVE) mislabeled negative/any scans. Verified empirically: all 1775 positive-mode scans of the test file return1.Activation methods are now mapped independently of collision energy (so zero-CE ETD scans keep their method), and PQD was added.
Validation
Built with the real
.NET 8managed bridge (no stubs) and ranThermoRawFile_testagainst the realAngiotensin_AllScans.raw(1775 scans, positive ESI, FTMS/Orbitrap, HCD/ETD): passes, including new assertions for every field above and their mzML round-trip. mzML serialization of each CV param was separately verified.Notes
WITH_THERMO_RAWbuild; the default build is unchanged.Instrumentper experiment, so Thermo's multiple instrument configurations (e.g. FTMS + ion trap) collapse into one component list (union of analyzers); per-spectruminstrumentConfigurationRefis not representable.🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Bug Fixes
Tests