Repository navigation
Fix FLASHDeconv negative mass/charge handling and TOPPAS file type detection - #9054
Conversation
|
Understand this PR’s impact Explore downstream dependencies and potential security impact with Blast Radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (2)
Included review availability: Your plan provides up to 4 included reviews per hour; 3 remain after this review. 📝 WalkthroughWalkthroughThe pull request changes ChangesTOPPASEdge Pointer Safety
FLASHDeconv Charge Normalization
Priority: ⬇️ Low Change: Bug fix 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 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. A rabbit checks each guarded link Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/topp/FLASHDeconv.cpp`:
- Around line 191-192: The code currently uses mzml_charge =
abs(getIntOption_("mzml_mass_charge")) which silently converts negative user
input to positive; either enforce/validate the option to disallow negative
values or keep coercion but emit a clear warning when
getIntOption_("mzml_mass_charge") < 0 and document this behavior. Update the
option registration/help text for "mzml_mass_charge" to reflect the actual
allowed range/semantics and adjust the runtime handling (the mzml_charge
assignment and the option registration block where the option is declared) so
help text and validation/warning are consistent with the implemented
coercion/behavior.
🪄 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: 19d14ebb-a67b-4225-8bc4-7375d3c2ea1b
📒 Files selected for processing (2)
src/openms_gui/include/OpenMS/VISUAL/TOPPASEdge.hsrc/topp/FLASHDeconv.cpp
| // The charge state CV param (MS:1000041) for mzML expects a positive number | ||
| int mzml_charge = abs(getIntOption_("mzml_mass_charge")); |
There was a problem hiding this comment.
mzml_mass_charge behavior now conflicts with documented CLI semantics
Line 192 converts -1 to +1, but the option help still advertises -1: -1 charged. Please align docs/validation with the new behavior (or emit a warning when coercing negative values) to avoid silent surprises.
Suggested adjustment
- // The charge state CV param (MS:1000041) for mzML expects a positive number
- int mzml_charge = abs(getIntOption_("mzml_mass_charge"));
+ // The charge state CV param (MS:1000041) for mzML expects a non-negative number.
+ const int mzml_mass_charge_opt = getIntOption_("mzml_mass_charge");
+ if (mzml_mass_charge_opt < 0)
+ {
+ OPENMS_LOG_WARN << "Parameter 'mzml_mass_charge' < 0 is coerced to +1 for mzML export.\n";
+ }
+ const int mzml_charge = std::abs(mzml_mass_charge_opt);Also update the option description/range near registration so help text matches runtime behavior.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@src/topp/FLASHDeconv.cpp` around lines 191 - 192, The code currently uses
mzml_charge = abs(getIntOption_("mzml_mass_charge")) which silently converts
negative user input to positive; either enforce/validate the option to disallow
negative values or keep coercion but emit a clear warning when
getIntOption_("mzml_mass_charge") < 0 and document this behavior. Update the
option registration/help text for "mzml_mass_charge" to reflect the actual
allowed range/semantics and adjust the runtime handling (the mzml_charge
assignment and the option registration block where the option is declared) so
help text and validation/warning are consistent with the implemented
coercion/behavior.
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Find FLASHDeconvSpectrumFile::writeMzML implementation
rg -n "writeMzML" --type=cpp -A5 -B2
# Also check the declaration
rg -n "writeMzML" --type=h -A5 -B2
Length of output: 6483
🏁 Script executed:
#!/bin/bash
# Get the full writeMzML implementation to see how mzml_charge is used
rg -n "mzml_charge" --type=cpp -A3 -B3
Length of output: 6081
🏁 Script executed:
#!/bin/bash
# Check how toSpectrum uses mzml_charge
rg -n "toSpectrum" --type=cpp -A10 -B2
rg -n "toSpectrum" --type=h -A10 -B2
Length of output: 21130
@timosachsenberg — the concern is confirmed valid, and it's actually more serious than the original comment indicated.
Root cause: DeconvolvedSpectrum::toSpectrum is explicitly designed to handle signed charges. At src/openms/source/ANALYSIS/TOPDOWN/DeconvolvedSpectrum.cpp, line 37:
double charge_mass_offset = (double)abs(to_charge) * FLASHHelperClasses::getChargeMass(to_charge >= 0);It uses abs() for the magnitude but uses the sign (to_charge >= 0) to select between positive and negative charge mass. Passing abs(mzml_mass_charge) strips that sign before it ever reaches toSpectrum, so -1 (negative ion mode) and +1 (positive ion mode) now produce identical output — the negative ion mode path is silently broken.
The correct fix should not apply abs() here, but instead:
- Pass the raw signed value through to
toSpectrum(which already handles it correctly). - Update the option registration help text and/or add a note documenting that
-1means "negative ion mode output".
Suggested correction:
- // The charge state CV param (MS:1000041) for mzML expects a positive number
- int mzml_charge = abs(getIntOption_("mzml_mass_charge"));
+ // mzml_mass_charge: 0 = uncharged, +1 = positive ion mode, -1 = negative ion mode.
+ // toSpectrum() uses the sign to select the correct charge mass (positive vs negative).
+ int mzml_charge = getIntOption_("mzml_mass_charge");The mzML CV term MS:1000041 concern in the comment is separate and lives inside toSpectrum/the mzML writer — that layer already handles the mapping appropriately via getChargeMass. The abs() at the TOPP layer is unnecessary and destructive.
🧠 Learnings used
Learnt from: CR
Repo: OpenMS/OpenMS PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-03-31T13:53:50.710Z
Learning: Applies to src/topp/*.cpp : Define TOPP parameters in `registerOptionsAndFlags_()`; read with `getStringOption_` and related helpers
Learnt from: timosachsenberg
Repo: OpenMS/OpenMS PR: 8975
File: src/openms/source/FORMAT/BrukerTimsFile.cpp:559-568
Timestamp: 2026-03-24T08:16:16.811Z
Learning: In OpenMS BrukerTimsFile.cpp (WITH_OPENTIMS), the correct PSI-MS CV term for Bruker TimsTOF TDF nativeID format is MS:1002818 ("Bruker TDF nativeID format"), not MS:1000776 ("scan number only nativeID format"). The mandated nativeID string pattern for MS:1002818 is `frame=<FRAME_ID> scan=<SCAN_ID>`. The SourceFile metadata call should use setNativeIDTypeAccession("MS:1002818") and setNativeIDType("Bruker TDF nativeID format").
Learnt from: timosachsenberg
Repo: OpenMS/OpenMS PR: 8841
File: src/topp/MascotAdapterOnline.cpp:143-145
Timestamp: 2026-03-06T11:18:36.359Z
Learning: In OpenMS, for MascotAdapterOnline.cpp and similar TOPP tools, paths created with File::getTempDirectory() + File::getUniqueName() are ASCII-only. Wrapping them with std::filesystem::path for Unicode/non-ASCII safety is unnecessary and should not be flagged during code reviews. Apply this guidance to all TOPP tools under src/topp. If a non-ASCII path handling is actually needed elsewhere, handle it explicitly there.
There was a problem hiding this comment.
the change looks good
There was a problem hiding this comment.
very sharp detect indeed
There was a problem hiding this comment.
Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!
|
The Description in the PR does not match the implementation. Please update |
|
Adversarial review result: no blocking behavioral issue found in the small TOPPASEdge/FLASHDeconv changes. Cleanup required: |
KyowonJeong
left a comment
There was a problem hiding this comment.
Very sharp bug finding!
| // The charge state CV param (MS:1000041) for mzML expects a positive number | ||
| int mzml_charge = abs(getIntOption_("mzml_mass_charge")); |
There was a problem hiding this comment.
the change looks good
| // The charge state CV param (MS:1000041) for mzML expects a positive number | ||
| int mzml_charge = abs(getIntOption_("mzml_mass_charge")); |
There was a problem hiding this comment.
very sharp detect indeed
…10226) Adds CHANGELOG entries for merged PRs not yet reflected: FLASHDeconv negative mass/charge handling and TOPPAS file type detection (#9054), ConsensusID handling of empty idXML runs (#10203), the Applications install-component casing fix (#10199), and the implementing PR for the glycan/glycopeptide fragment generator (#10204). Also fills in the PR references on two existing Robustness entries (mzIdentML Measure definitions #10213, XIC chromatogram native IDs #10214) that were merged without one. Claude-Session: https://claude.ai/code/session_01CVWcsWWMa4DHbvKMhi9G8n Co-authored-by: Claude <[email protected]>
Summary
This PR fixes two independent bugs in FLASHDeconv and TOPPAS components.
Bug Fixes
FLASHDeconv: Handle Negative Mass/Charge Values
File:
src/topp/FLASHDeconv.cppProblem: FLASHDeconv crashed when encountering negative
mzml_mass_chargevalues in input data.Solution: Added validation to skip spectra with non-positive mass/charge values with appropriate warning message.
Impact: Prevents crashes when processing malformed or unusual mzML files.
TOPPAS: Improve File Type Detection Robustness
Files:
src/openms_gui/include/OpenMS/VISUAL/TOPPASEdge.hProblem: File type detection could fail when content-based detection returned UNKNOWN, leading to incorrect file naming/handling in TOPPAS workflows.
Solution: Added fallback to extension-based file type detection when content-based detection fails.
Impact: More robust file handling in TOPPAS workflows, especially for edge cases where file content doesn't match expectations.
Testing
Type of Change
Related Issues
None (discovered during development)
Summary by CodeRabbit