Skip to content

Annotate original native IDs in MaRaClusterAdapter consensus spectra - #8607

Closed
timosachsenberg wants to merge 2 commits into
developfrom
claude/fix-openms-4474-krvU7
Closed

timosachsenberg wants to merge 2 commits into
developfrom
claude/fix-openms-4474-krvU7

Conversation

@timosachsenberg

@timosachsenberg timosachsenberg commented Jan 7, 2026 •

Copy link
Copy Markdown
Contributor

When generating consensus spectra output, annotate each spectrum with
metadata about the original spectra that were clustered together:

  • maracluster_original_native_ids: comma-separated original native IDs
  • maracluster_original_file_origins: comma-separated source file paths
  • maracluster_cluster_size: number of spectra in the cluster

Uses SpectrumMetaDataLookup to efficiently map scan numbers to native IDs
from the original input files.

This preserves traceability from consensus spectra back to their source
spectra, addressing the request in issue #4474.

Summary by CodeRabbit

Release Notes

  • New Features

    • Consensus spectra output now enhanced with metadata annotations including original spectrum identifiers, source file paths, and cluster membership sizes for improved data lineage and traceability.
  • Bug Fixes

    • Improved error handling for missing spectrum metadata in consensus output with graceful fallback behavior.

✏️ Tip: You can customize this high-level summary in your review settings.

When generating consensus spectra output, annotate each spectrum with
metadata about the original spectra that were clustered together:
- maracluster_original_native_ids: comma-separated original native IDs
- maracluster_original_file_origins: comma-separated source file paths
- maracluster_cluster_size: number of spectra in the cluster

Uses SpectrumMetaDataLookup to efficiently map scan numbers to native IDs
from the original input files.

This preserves traceability from consensus spectra back to their source
spectra, addressing the request in issue #4474.
@coderabbitai

coderabbitai Bot commented Jan 7, 2026 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

The change enhances MaRaClusterAdapter.cpp to enrich consensus spectra with cluster metadata. It constructs per-file spectrum metadata lookups via SpectrumMetaDataLookup, builds reverse mappings from cluster IDs to spectrum identifiers and file origins, then annotates each consensus spectrum with cluster size, original native IDs, and source file paths, including fallback handling for missing metadata.

Changes

Cohort / File(s) Summary
MaRaCluster metadata enrichment
src/topp/MaRaClusterAdapter.cpp
Integrates SpectrumMetaDataLookup to construct per-file metadata lookups; builds reverse mapping from cluster IDs to (file_origin, original_native_id) tuples; annotates consensus spectra with maracluster_original_native_ids, maracluster_original_file_origins, and maracluster_cluster_size metadata; includes error handling with fallback to scan number format when metadata is unavailable

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related issues

Poem

🐰 Hops through clusters, mapping with care,
Each spectrum tagged with origins rare,
Native IDs dance in metadata rows,
From file to file, the rich context flows! 🌟

🚥 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%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ 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: adding annotation of original native IDs to consensus spectra in MaRaClusterAdapter, which is the core objective of the PR.

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

✨ Finishing touches
  • 📝 Generate docstrings

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.

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

🧹 Nitpick comments (1)
src/topp/MaRaClusterAdapter.cpp (1)

518-542: LGTM with optional cleanup suggestion.

The annotation logic correctly maps cluster IDs and builds the metadata. The static_cast<Int> on line 540 is appropriate.

🔎 Optional: Use StringList for cleaner string concatenation

Consider using StringList with ListUtils::concatenate for building comma-separated values:

         const auto& refs = clusterid_to_original_refs[cluster_id];
         // Build comma-separated list of original native IDs
-        String original_native_ids;
-        String original_file_origins;
-        for (Size j = 0; j < refs.size(); ++j)
-        {
-          if (j > 0)
-          {
-            original_native_ids += ",";
-            original_file_origins += ",";
-          }
-          original_file_origins += refs[j].first;
-          original_native_ids += refs[j].second;
-        }
+        StringList native_id_list;
+        StringList file_origin_list;
+        for (const auto& ref : refs)
+        {
+          file_origin_list.push_back(ref.first);
+          native_id_list.push_back(ref.second);
+        }
+        String original_native_ids = ListUtils::concatenate(native_id_list, ",");
+        String original_file_origins = ListUtils::concatenate(file_origin_list, ",");
         exp[i].setMetaValue("maracluster_original_native_ids", original_native_ids);
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 91afebf and 9411baf.

📒 Files selected for processing (1)
  • src/topp/MaRaClusterAdapter.cpp
🧰 Additional context used
📓 Path-based instructions (3)
**/*.{cpp,cc,cxx}

📄 CodeRabbit inference engine (AGENTS.md)

**/*.{cpp,cc,cxx}: Never use std::cout or std::cerr directly; use OpenMS logging macros instead
Always use braces for control structures, even for single-line blocks (trivial one-liners may stay single-line)
Braces for control structures must align with opening/closing braces on their own lines

Files:

  • src/topp/MaRaClusterAdapter.cpp
**/*.{cpp,cc,cxx,h,hpp,hxx}

📄 CodeRabbit inference engine (AGENTS.md)

**/*.{cpp,cc,cxx,h,hpp,hxx}: Never use std::endl; use \n for performance
Use 2-space indentation for C++/headers; no tabs; Unix line endings
Use classes/types/namespaces in PascalCase
Use lowerCamelCase for method names
Use snake_case for variable names
Use trailing underscore for private/protected member variable names
Use UPPER_SNAKE_CASE for enums and macros
Include space after keywords (if, for, while) and around binary operators
Avoid the C++ preprocessor; prefer enum class over macro constants

Files:

  • src/topp/MaRaClusterAdapter.cpp
src/topp/**/*.cpp

📄 CodeRabbit inference engine (AGENTS.md)

src/topp/**/*.cpp: Define tool parameters in registerOptionsAndFlags_() method and read with getStringOption_ and related helpers
Use ProgressLogger in TOPP tools for progress reporting

Files:

  • src/topp/MaRaClusterAdapter.cpp
🧠 Learnings (6)
📚 Learning: 2025-08-05T12:43:11.681Z
Learnt from: CR
Repo: OpenMS/OpenMS PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-05T12:43:11.681Z
Learning: Applies to src/openms/**/*.{cpp,h,hpp,cc,cxx} : Use OpenMS data structures (e.g., MSExperiment, FeatureMap, PeptideIdentification)

Applied to files:

  • src/topp/MaRaClusterAdapter.cpp
📚 Learning: 2025-08-05T12:43:11.681Z
Learnt from: CR
Repo: OpenMS/OpenMS PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-05T12:43:11.681Z
Learning: Applies to src/openms/**/*.{cpp,h,hpp,cc,cxx} : Follow the established error handling patterns

Applied to files:

  • src/topp/MaRaClusterAdapter.cpp
📚 Learning: 2025-08-05T12:43:11.681Z
Learnt from: CR
Repo: OpenMS/OpenMS PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-05T12:43:11.681Z
Learning: Applies to src/openms/**/*.{cpp,h,hpp,cc,cxx} : Utilize OpenMS logging mechanisms

Applied to files:

  • src/topp/MaRaClusterAdapter.cpp
📚 Learning: 2025-08-05T12:43:11.681Z
Learnt from: CR
Repo: OpenMS/OpenMS PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-05T12:43:11.681Z
Learning: Applies to src/openms/**/*.{cpp,h,hpp,cc,cxx} : Be mindful of memory usage when processing large datasets

Applied to files:

  • src/topp/MaRaClusterAdapter.cpp
📚 Learning: 2026-01-07T06:33:27.194Z
Learnt from: CR
Repo: OpenMS/OpenMS PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-01-07T06:33:27.194Z
Learning: Applies to src/openms/**/*.{cpp,cc,cxx,h,hpp,hxx} : Derive custom exceptions from `Exception::Base`; throw with file/line/`OPENMS_PRETTY_FUNCTION`; catch by reference

Applied to files:

  • src/topp/MaRaClusterAdapter.cpp
📚 Learning: 2025-08-05T12:43:11.681Z
Learnt from: CR
Repo: OpenMS/OpenMS PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-05T12:43:11.681Z
Learning: Applies to src/tests/class_tests/openms/**/*.cpp : Write unit tests for new functionality

Applied to files:

  • src/topp/MaRaClusterAdapter.cpp
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (9)
  • GitHub Check: build-macos-arm
  • GitHub Check: build-lnx
  • GitHub Check: build-lnx-arm
  • GitHub Check: build-win
  • GitHub Check: build-and-test (ubuntu-24.04, g++, 13)
  • GitHub Check: build-and-test (ubuntu-24.04-arm, g++, 13)
  • GitHub Check: build-and-test (macos-14, xcode, 15.4)
  • GitHub Check: build-and-test (windows-2025, cl.exe, 14.44)
  • GitHub Check: build-and-test (ubuntu-24.04, clang++, 17)
🔇 Additional comments (3)
src/topp/MaRaClusterAdapter.cpp (3)

18-18: LGTM!

Include added for the new metadata lookup functionality.


471-494: LGTM!

The reverse mapping construction with fallback handling is well structured. Exception handling follows OpenMS patterns (catching by reference per learnings), and the fallback to "scan=X" format provides graceful degradation when the lookup fails.


458-469: API usage is correct; no changes needed.

The SpectrumMetaDataLookup::readSpectra() method properly populates the internal lookup, and subsequent findByScanNumber() calls work as expected. The code follows all guidelines: snake_case variables, lowerCamelCase methods, PascalCase types, proper brace alignment, and 2-space indentation. The pattern matches existing usage throughout the codebase.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants