Skip to content

Fix FLASHDeconv negative mass/charge handling and TOPPAS file type detection - #9054

Merged
timosachsenberg merged 5 commits into
developfrom
bugfix-flashdeconv-toppas
Sep 21, 2026
Merged

timosachsenberg merged 5 commits into
developfrom
bugfix-flashdeconv-toppas

Conversation

@poshul

@poshul poshul commented Apr 1, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

This PR fixes two independent bugs in FLASHDeconv and TOPPAS components.

Bug Fixes

FLASHDeconv: Handle Negative Mass/Charge Values

File: src/topp/FLASHDeconv.cpp

Problem: FLASHDeconv crashed when encountering negative mzml_mass_charge values 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.h

Problem: 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

  • ✅ Build successful
  • ✅ FLASHDeconv TOPP test passing
  • ✅ No regressions in TOPPAS functionality

Type of Change

  • FIX - Bug fixes
  • API changes
  • Breaking changes

Related Issues

None (discovered during development)

Summary by CodeRabbit

  • Bug Fixes
    • Ensured FLASHDeconv charge values are normalized to non-negative numbers before processing, improving handling of negative charge inputs.
    • Improved the reliability of TOPPAS workflow connections when referenced vertices are removed.

@poshul poshul mentioned this pull request Apr 1, 2026
5 tasks
@coderabbitai

coderabbitai Bot commented Apr 1, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

Understand this PR’s impact

Explore downstream dependencies and potential security impact with Blast Radius.

View 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: d8889cdc-f129-4d89-ae8d-f5475cdd889f

📥 Commits

Reviewing files that changed from the base of the PR and between 2e7de14 and 2d83f1f.

📒 Files selected for processing (2)
  • src/openms_gui/include/OpenMS/VISUAL/TOPPASEdge.h
  • src/topp/FLASHDeconv.cpp

Included review availability: Your plan provides up to 4 included reviews per hour; 3 remain after this review.


📝 Walkthrough

Walkthrough

The pull request changes TOPPASEdge vertex members to QPointer and converts the FLASHDeconv mzML charge option to a non-negative value before output.

Changes

TOPPASEdge Pointer Safety

Layer / File(s) Summary
Guarded vertex pointer members
src/openms_gui/include/OpenMS/VISUAL/TOPPASEdge.h
from_ and to_ now use QPointer<TOPPASVertex>. The header includes QPointer support.

FLASHDeconv Charge Normalization

Layer / File(s) Summary
Normalize mzML charge input
src/topp/FLASHDeconv.cpp
mzml_charge now uses abs(getIntOption_("mzml_mass_charge")) before it is passed to writeMzML(...).

Priority: ⬇️ Low

Change: Bug fix

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.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. 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 accurately describes the FLASHDeconv negative charge handling change. The TOPPAS file type detection claim does not match the provided implementation, which changes TOPPASEdge members to QPo…
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.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 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 guarded link
And makes the charge value positive in a blink
QPointer holds the vertex near
abs() makes the output clear
Two small fixes hop into place

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between 6e26a12 and 2e7de14.

📒 Files selected for processing (2)
  • src/openms_gui/include/OpenMS/VISUAL/TOPPASEdge.h
  • src/topp/FLASHDeconv.cpp

Comment thread src/topp/FLASHDeconv.cpp
Comment on lines +191 to +192
// The charge state CV param (MS:1000041) for mzML expects a positive number
int mzml_charge = abs(getIntOption_("mzml_mass_charge"));

@coderabbitai coderabbitai Bot Apr 1, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

please check

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧩 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:

  1. Pass the raw signed value through to toSpectrum (which already handles it correctly).
  2. Update the option registration help text and/or add a note documenting that -1 means "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.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

the change looks good

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

very sharp detect indeed

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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!

@timosachsenberg

Copy link
Copy Markdown
Contributor

The Description in the PR does not match the implementation. Please update

@poshul
poshul marked this pull request as draft April 7, 2026 08:49

Copy link
Copy Markdown
Contributor

Adversarial review result: no blocking behavioral issue found in the small TOPPASEdge/FLASHDeconv changes.

Cleanup required: src/topp/FLASHDeconv.cpp has trailing whitespace on the added comment line. I did not find tracker-style issue references in source comments. No build/tests run locally.

@KyowonJeong KyowonJeong left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Very sharp bug finding!

Comment thread src/topp/FLASHDeconv.cpp
Comment on lines +191 to +192
// The charge state CV param (MS:1000041) for mzML expects a positive number
int mzml_charge = abs(getIntOption_("mzml_mass_charge"));

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

the change looks good

Comment thread src/topp/FLASHDeconv.cpp
Comment on lines +191 to +192
// The charge state CV param (MS:1000041) for mzML expects a positive number
int mzml_charge = abs(getIntOption_("mzml_mass_charge"));

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

very sharp detect indeed

@timosachsenberg
timosachsenberg marked this pull request as ready for review July 16, 2026 12:02
@timosachsenberg
timosachsenberg merged commit b957915 into develop Sep 21, 2026
13 checks passed
@timosachsenberg
timosachsenberg deleted the bugfix-flashdeconv-toppas branch September 21, 2026 16:28
timosachsenberg added a commit that referenced this pull request Sep 22, 2026
…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]>
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.

3 participants