Skip to content

IDMapper: prevent duplicate spectrum reference insertion - #8905

Merged
timosachsenberg merged 2 commits into
OpenMS:developfrom
ronak-15:fix-idmapper-duplicate
Mar 18, 2026
Merged

timosachsenberg merged 2 commits into
OpenMS:developfrom
ronak-15:fix-idmapper-duplicate

Conversation

@ronak-15

@ronak-15 ronak-15 commented Mar 15, 2026 •

Copy link
Copy Markdown
Contributor

Description

This PR fixes a TODO in IDMapper.cpp by preventing duplicate spectrum references from overwriting existing entries in file2nativeid2pepid.

Previously, the code inserted entries using direct assignment, which could silently overwrite an existing mapping if the same spectrum reference appeared multiple times. This change replaces the assignment with insert() and logs a warning when a duplicate spectrum reference is detected.

The change improves robustness while preserving the original mapping behavior for valid inputs.

Summary by CodeRabbit

  • Bug Fixes
    • Duplicate spectrum references now emit warning messages and preserve the first entry instead of overwriting data, reducing unintended data loss during ID mapping.

@coderabbitai

coderabbitai Bot commented Mar 15, 2026 •

Copy link
Copy Markdown
Contributor

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: 83617a25-f20a-4ad8-a86a-35c2bde967dd

📥 Commits

Reviewing files that changed from the base of the PR and between f0885d3 and 8028ca8.

📒 Files selected for processing (1)
  • src/openms/source/ANALYSIS/ID/IDMapper.cpp
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/openms/source/ANALYSIS/ID/IDMapper.cpp

📝 Walkthrough

Walkthrough

Modified spectrum reference handling in IDMapper.cpp to preserve the first entry and warn on duplicates instead of silently overwriting. Direct assignment was replaced with insertion into the inner map, logging a warning when a duplicate key is encountered while preserving existing control flow.

Changes

Cohort / File(s) Summary
Duplicate Spectrum Reference Detection
src/openms/source/ANALYSIS/ID/IDMapper.cpp
Replaced direct map assignment with insertion-based logic to detect duplicate spectrum references. Preserves the first mapping and logs a warning when a duplicate key is inserted; sets has_spectrum_references unchanged.

Poem

🐰 A cautious rabbit hops in code so neat,
Inserts the first and lets duplicates meet,
A gentle warning, not a fight,
First wins the race in morning light,
Hooray — our maps stay tidy and sweet!

🚥 Pre-merge checks | ✅ 2 | ❌ 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 (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: preventing duplicate spectrum references from being inserted into the IDMapper, which is the core objective of the PR.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
📝 Coding Plan
  • Generate coding plan for human review comments

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 and usage tips.

Tip

CodeRabbit can generate a title for your PR based on the changes.

Add @coderabbitai placeholder anywhere in the title of your PR and CodeRabbit will replace it with a title based on the changes in the PR. You can change the placeholder by changing the reviews.auto_title_placeholder setting.

@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.

🧹 Nitpick comments (1)
src/openms/source/ANALYSIS/ID/IDMapper.cpp (1)

362-364: Replace std::endl with "\n" in this warning path.

At Line 363, std::endl forces a flush each time; prefer "\n" to avoid unnecessary overhead.

Proposed change
-          OPENMS_LOG_WARN << "Duplicate spectrum reference detected: "
-                          << spectrum_reference << std::endl;
+          OPENMS_LOG_WARN << "Duplicate spectrum reference detected: "
+                          << spectrum_reference << "\n";

As per coding guidelines "**/*.{h,cpp}: Avoid std::endl for performance; prefer \n."

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/openms/source/ANALYSIS/ID/IDMapper.cpp` around lines 362 - 364, Replace
the use of std::endl in the duplicate-spectrum warning so it doesn't flush the
stream each time: in the block that logs "Duplicate spectrum reference detected:
" (use the OPENMS_LOG_WARN call that prints spectrum_reference in IDMapper.cpp)
change the trailing std::endl to a plain "\n" character to avoid unnecessary
flushes.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/openms/source/ANALYSIS/ID/IDMapper.cpp`:
- Around line 362-364: Replace the use of std::endl in the duplicate-spectrum
warning so it doesn't flush the stream each time: in the block that logs
"Duplicate spectrum reference detected: " (use the OPENMS_LOG_WARN call that
prints spectrum_reference in IDMapper.cpp) change the trailing std::endl to a
plain "\n" character to avoid unnecessary flushes.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: aa2c4ede-66ea-4a7c-9247-b588e6e05b73

📥 Commits

Reviewing files that changed from the base of the PR and between 4c934ac and f0885d3.

📒 Files selected for processing (1)
  • src/openms/source/ANALYSIS/ID/IDMapper.cpp

@jpfeuffer

Copy link
Copy Markdown
Contributor

Thanks. Please prefer \n instead of newline for warnings.

@ronak-15

Copy link
Copy Markdown
Contributor Author

Thanks for the review!

@ronak-15

Copy link
Copy Markdown
Contributor Author

Hi, this PR has been approved, but I noticed one CI test is getting cancelled after running for several hours. Could you please advise if this is expected or if anything needs to be fixed before merging?

@jpfeuffer

Copy link
Copy Markdown
Contributor

@timosachsenberg maybe some cache eviction for windows happened recently?
Or did the nanobind change cause these long build times? I don't remember them being that long!

@ronak-15

Copy link
Copy Markdown
Contributor Author

Hi, just following up here since I haven’t heard back yet. @timosachsenberg As this PR is already approved, should I wait for confirmation on the CI issue or is it okay to merge?

@timosachsenberg
timosachsenberg merged commit d12d512 into OpenMS:develop Mar 18, 2026
18 of 19 checks passed
@ronak-15

Copy link
Copy Markdown
Contributor Author

Thanks for the reviews and guidance! Merged — we can keep an eye on the CI issue separately if needed.

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