Skip to content

[FIX] FragmentMassError: make both compute() overloads agree (#9488 QC-3) - #9618

Merged
timosachsenberg merged 2 commits into
OpenMS:developfrom
timosachsenberg:fix/9488-fragmentmasserror-consistency
Jul 8, 2026
Merged

timosachsenberg merged 2 commits into
OpenMS:developfrom
timosachsenberg:fix/9488-fragmentmasserror-consistency

Conversation

@timosachsenberg

@timosachsenberg timosachsenberg commented Jun 17, 2026 •

Copy link
Copy Markdown
Contributor

Part of #9488 (POLS high-severity checklist — QC / SYSTEM / APPLICATIONS).

[QC-3] FragmentMassError::compute — two overloads computed average/variance differently

The PeptideIdentificationList overload accumulated ppm errors, computed the average, and called calculateVariance_ inside the per-ID loop, so the variance was accumulated against a moving/partial average. The FeatureMap overload already did it correctly in two passes, so the two overloads produced different results for the same data.

Fix: make the list overload mirror the FeatureMap overload — first pass accumulates all ppm errors and computes the final average; second pass computes the variance against that final average.

ABI: none (implementation only).
Test: FragmentMassError_test — both overloads now produce identical average_ppm / variance_ppm for the same input (non-constant errors so the variance is non-degenerate).

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes

    • Corrected fragment mass error statistics to compute average and variance consistently across the full set of peptide identifications.
    • Improved robustness for scenarios where fragment mass error varies between spectra, preventing incorrect variance outcomes.
  • Tests

    • Added a regression test for a real-world QC scenario with non-constant ppm offsets, verifying results align between analysis paths and that variance is non-zero when expected.

@coderabbitai

coderabbitai Bot commented Jun 17, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a4c28ebc-1888-4630-a524-c09d9a56c260

📥 Commits

Reviewing files that changed from the base of the PR and between c51f11c and a45e11f.

📒 Files selected for processing (2)
  • src/openms/source/QC/FragmentMassError.cpp
  • src/tests/class_tests/openms/source/FragmentMassError_test.cpp
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/openms/source/QC/FragmentMassError.cpp
  • src/tests/class_tests/openms/source/FragmentMassError_test.cpp

📝 Walkthrough

Walkthrough

FragmentMassError::compute for PeptideIdentificationList now accumulates ppm errors in a first pass, computes the final average afterward, and derives variance in a second pass. A regression test adds spectra with differing ppm offsets and checks the overload results against FeatureMap.

Changes

FragmentMassError two-pass statistics

Layer / File(s) Summary
Two-pass accumulation and variance computation
src/openms/source/QC/FragmentMassError.cpp
The per-pep_id loop now accumulates accumulator_ppm/counter_ppm fully before checking for absent matching peaks, computes result.average_ppm once, and then runs a second pass to compute variance via calculateVariance_ using the finalized average.
Regression test for non-constant ppm errors
src/tests/class_tests/openms/source/FragmentMassError_test.cpp
Adds a test with differing ppm offsets per spectrum, runs both the PeptideIdentificationList and FeatureMap overloads, and asserts non-zero variance plus matching average/variance between them.

Suggested reviewers: jpfeuffer

Poem

A rabbit hopped through two loops of ppm,
First gathered the errors, then averaged them,
Variance waited till mean was set right,
Then tests gave a cheerful green light. 🐇

🚥 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%. 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 matches the main change: aligning both FragmentMassError compute() overloads.
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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

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

Copy link
Copy Markdown
Contributor Author

Adversarial review result: no blocking behavioral issue found in this pass.

Required source cleanup before merge: the added production/test comments include tracker references. Please remove those references from source comments and keep the comments focused on the two-pass average/variance contract. I did not run the tests locally.

@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: 3

🤖 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/openms/source/QC/FragmentMassError.cpp`:
- Around line 291-294: The new comment in FragmentMassError should be rewritten
to describe the two-pass average/variance contract only, and must remove the
issue-tracker reference text (“#9488, QC-3”). Update the nearby comment in the
FragmentMassError computation block so it explains that both overloads use the
same two-pass computation and that variance is accumulated against the final
average, without mentioning any ticket or tracker identifiers.

In `@src/tests/class_tests/openms/source/FragmentMassError_test.cpp`:
- Around line 305-313: Update the regression test comment in
FragmentMassError_test.cpp to remove the issue-tracker reference and QC label,
and rewrite it to describe the behavior being verified: that the
PeptideIdentificationList and FeatureMap overloads must compute average_ppm and
variance_ppm identically using the same spectra/peptides with non-constant
per-spectrum errors. Keep the focus on the two-pass average/variance contract
and the moving-average bug that the test distinguishes, without mentioning `#9488`
or QC-3.
- Line 358: The boolean assertion in FragmentMassError_test should use the
preferred test macro style instead of comparing against true. Update the test
around list_result.variance_ppm to use TEST_TRUE with the same condition,
keeping the existing assertion intent but aligning with the coding guideline for
boolean checks.
🪄 Autofix (Beta)

❌ Autofix failed (check again to retry)

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: b7302dbe-d024-4c6f-accc-f0a9f69282b9

📥 Commits

Reviewing files that changed from the base of the PR and between 02545db and c51f11c.

📒 Files selected for processing (2)
  • src/openms/source/QC/FragmentMassError.cpp
  • src/tests/class_tests/openms/source/FragmentMassError_test.cpp

@coderabbitai

coderabbitai Bot commented Jul 1, 2026 •

Copy link
Copy Markdown
Contributor

Note

Autofix is a beta feature. Expect some limitations and changes as we gather feedback and continue to improve it.

An unexpected error occurred while generating fixes: Not Found - https://docs.github.com/rest/git/refs#get-a-reference

timosachsenberg and others added 2 commits July 8, 2026 16:54
…9488 QC-3)

Part of OpenMS#9488 (POLS high-severity checklist — **QC / SYSTEM / APPLICATIONS**).

### [QC-3] `FragmentMassError::compute` — two overloads computed average/variance differently
The `PeptideIdentificationList` overload accumulated ppm errors, computed the average, and called `calculateVariance_` **inside** the per-ID loop, so the variance was accumulated against a *moving/partial* average. The `FeatureMap` overload already did it correctly in two passes, so the two overloads produced different results for the same data.

**Fix:** make the list overload mirror the `FeatureMap` overload — first pass accumulates all ppm errors and computes the final average; second pass computes the variance against that final average.

**ABI:** none (implementation only).
**Test:** `FragmentMassError_test` — both overloads now produce identical `average_ppm` / `variance_ppm` for the same input (non-constant errors so the variance is non-degenerate).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Rewrite the FragmentMassError source/test comments to describe the
two-pass average/variance contract without issue-tracker identifiers,
and switch the variance assertion to TEST_TRUE.

Co-Authored-By: Claude Fable 5 <[email protected]>
@timosachsenberg
timosachsenberg force-pushed the fix/9488-fragmentmasserror-consistency branch from c51f11c to a45e11f Compare July 8, 2026 14:55
@timosachsenberg
timosachsenberg merged commit 9b1ae6e into OpenMS:develop Jul 8, 2026
10 checks passed
timosachsenberg added a commit that referenced this pull request Jul 10, 2026
Adds entries for PRs merged in the last couple of days that were missing
changelog coverage: the TOPPView precursor-highlighting feature (#9715),
the Xerces-C++ PRIVATE-linkage/XMLHandler API change (#9712, which also
supersedes a stale note left by the LibSVM PRIVATE-linkage entry), the
FragmentMassError variance fix (#9618), the PepXMLFile duplicate Comet
metavalue fix (#9089), and the clang/OpenMP and TextExporter USI
documentation additions (#9162, #9173).

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.

1 participant