Skip to content

feat(MaRaClusterAdapter): annotate consensus spectra with original native IDs - #8864

Merged
timosachsenberg merged 4 commits into
developfrom
fix/maracluster-annotate-native-ids
Mar 10, 2026
Merged

timosachsenberg merged 4 commits into
developfrom
fix/maracluster-annotate-native-ids

Conversation

@timosachsenberg

@timosachsenberg timosachsenberg commented Mar 9, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #4474

Changes vs #8607

The original PR had these problems:

  1. Off-by-one bug: Used raw cluster IDs from the map as lookup keys, but consensus scan numbers are cluster_id - 1 (as documented in the existing idXML annotation code at lines 390-391, 415-416). Lookups would never match.

  2. Unnecessary memory pressure: Loaded all input files and built lookups before running maracluster consensus, keeping them in memory during the external process execution. Moved to after the consensus output is loaded.

  3. Over-engineered: Used SpectrumMetaDataLookup (caches RT, precursor info, ms_level, etc.) when only scan_nr → native_id mapping is needed. Replaced with a simple std::map<Int, String> per file using the existing getScanNumber_() method.

  4. String concatenation: Used manual loop with += instead of StringList + ListUtils::concatenate (which is the OpenMS pattern).

Test plan

  • Build succeeds (verified locally: compiles cleanly with zero warnings)
  • Run MaRaClusterAdapter with --consensus_out and verify consensus mzML contains maracluster_original_native_ids, maracluster_original_file_origins, and maracluster_cluster_size meta values
  • Verify native IDs match the original input spectra

🤖 Generated with Claude Code

Summary by CodeRabbit

Release Notes

  • New Features

    • Consensus spectra are now enriched with metadata annotations including original native IDs from all contributing spectra, their source file locations, and the total number of spectra in each cluster.
  • Chores

    • Updated development container to support multi-platform builds for ARM64 and amd64 architectures with automatic detection and optional manual configuration.

timosachsenberg and others added 2 commits March 9, 2026 14:18
Use a Dockerfile with ARG TARGETARCH (set automatically by BuildKit,
default since Docker 23.0) to select the correct base image. Falls back
to amd64 when BuildKit is not available. ARM64 users can override via
build args in devcontainer.json if auto-detection fails.

Fixes #8740

Co-Authored-By: Claude Opus 4.6 <[email protected]>
…tive IDs

Add metadata annotations to consensus spectra output preserving
traceability to original source spectra:
- 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

Builds scan_nr -> native_id maps from input files and maps cluster IDs
to consensus scan numbers using the established cluster_id - 1 offset.

Fixes #4474

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@coderabbitai

coderabbitai Bot commented Mar 9, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

The PR adds multi-architecture Docker build support to the development container through a new Dockerfile with architecture-aware base image selection, and updates the devcontainer configuration to build from this Dockerfile. Additionally, it enhances MaRaClusterAdapter to annotate consensus spectra with original source metadata including native IDs, file origins, and cluster sizes.

Changes

Cohort / File(s) Summary
Dev Container Configuration
.devcontainer/Dockerfile, .devcontainer/devcontainer.json
Introduces multi-architecture Docker build support via TARGETARCH ARG for automatic platform detection (x86_64/ARM64), and switches devcontainer from pre-built image to Dockerfile-based build.
MaRaCluster Spectrum Annotation
src/topp/MaRaClusterAdapter.cpp
Adds post-processing logic to annotate consensus spectra with original metadata: reconstructs scan-to-native-ID mappings from input files, builds consensus-to-source associations from cluster data, and attaches maracluster_original_native_ids, maracluster_original_file_origins, and maracluster_cluster_size annotations.

Sequence Diagram

sequenceDiagram
    participant Input as Input Files
    participant Adapter as MaRaClusterAdapter
    participant Cluster as Cluster Mapping
    participant Spectra as Consensus Spectra
    participant Output as Output mzML

    Input->>Adapter: Re-read each input file
    Adapter->>Adapter: Build scan → native ID map per file
    Cluster->>Adapter: Provide cluster → scan associations
    Adapter->>Adapter: Construct consensus_scan → (file_origin, native_id) mapping
    Adapter->>Spectra: Iterate over consensus spectra
    Adapter->>Spectra: Attach annotations:<br/>- maracluster_original_native_ids<br/>- maracluster_original_file_origins<br/>- maracluster_cluster_size
    Spectra->>Output: Write annotated spectra to mzML
Loading

Poem

🐰 A rabbit's ode to preservation:

Through clusters bright, we trace the way,
Each spectrum's origin we save today,
From native IDs, files they came,
Now annotated, they keep their name! 🌿

🚥 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 pull request title clearly and concisely summarizes the main change: annotating consensus spectra with original native IDs in the MaRaClusterAdapter.
Linked Issues check ✅ Passed The code changes implement the core requirement from issue #4474 by annotating consensus spectra with metadata about their original sources, including native IDs, file origins, and cluster size.
Out of Scope Changes check ✅ Passed Changes to .devcontainer files address a separate infrastructure concern (#8740) while the core MaRaClusterAdapter changes directly address issue #4474; the devcontainer changes are reasonably scoped.

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

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/maracluster-annotate-native-ids

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

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

497-512: Consider adding bounds validation for res.file_idx.

While the file index is validated implicitly via filename_to_file_idx.at() in readMClusterOutputAsMap_() (which throws on missing keys), if that exception propagates it may produce a confusing error message. An explicit bounds check here would provide clearer diagnostics:

if (res.file_idx < 0 || static_cast<Size>(res.file_idx) >= file_scan_to_nativeid.size())
{
  OPENMS_LOG_WARN << "Invalid file index " << res.file_idx << " in cluster output, skipping." << std::endl;
  continue;
}

This is a minor defensive improvement—the current code should work correctly for valid inputs.

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

In `@src/topp/MaRaClusterAdapter.cpp` around lines 497 - 512, Add an explicit
bounds check for res.file_idx before accessing
file_scan_to_nativeid[res.file_idx] inside the loop in MaRaClusterAdapter (the
block building consensus_scan_to_refs), e.g. verify res.file_idx is non-negative
and less than file_scan_to_nativeid.size(), log a warning mentioning the invalid
res.file_idx and skip that entry (continue) to avoid confusing exceptions when
filename_to_file_idx errors would otherwise propagate.
🤖 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/MaRaClusterAdapter.cpp`:
- Around line 488-511: The current native-ID parsing uses getScanNumber_ which
only handles a few formats and can mismatch entries in file_scan_to_nativeid
when building consensus_scan_to_refs; replace calls to getScanNumber_ (used when
populating file_scan_to_nativeid and when resolving native_id from
MaRaClusterResult res) with
SpectrumNativeIDParser::extractScanNumber(spec.getNativeID(),
native_id_type_accession) (or the appropriate SpectrumNativeIDParser API) so you
canonicalize scan numbers consistently for all native ID types (handle
WIFF/index offsets per parser), ensuring lookups by res.file_idx/res.scan_nr
against file_scan_to_nativeid succeed and original native IDs from in_list are
preserved instead of falling back to synthetic "scan=" strings.

---

Nitpick comments:
In `@src/topp/MaRaClusterAdapter.cpp`:
- Around line 497-512: Add an explicit bounds check for res.file_idx before
accessing file_scan_to_nativeid[res.file_idx] inside the loop in
MaRaClusterAdapter (the block building consensus_scan_to_refs), e.g. verify
res.file_idx is non-negative and less than file_scan_to_nativeid.size(), log a
warning mentioning the invalid res.file_idx and skip that entry (continue) to
avoid confusing exceptions when filename_to_file_idx errors would otherwise
propagate.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 6442b622-f52e-4d95-b938-7f77bc1ea900

📥 Commits

Reviewing files that changed from the base of the PR and between 661f3fc and 5438bba.

📒 Files selected for processing (3)
  • .devcontainer/Dockerfile
  • .devcontainer/devcontainer.json
  • src/topp/MaRaClusterAdapter.cpp

Comment thread src/topp/MaRaClusterAdapter.cpp Resolved
@timosachsenberg
timosachsenberg merged commit 1012db2 into develop Mar 10, 2026
41 checks passed
@timosachsenberg
timosachsenberg deleted the fix/maracluster-annotate-native-ids branch March 10, 2026 11:21
github-actions Bot pushed a commit that referenced this pull request Mar 17, 2026
Add missing changelog entries for changes merged in the past 7 days:

- PyOpenMS: PeptideAndProteinQuant.getPeptideResults/getProteinResults exposed (#8543)
- PyOpenMS BREAKING: zero-copy _mv methods renamed to _view (#8857)
- TOPP BREAKING: FeatureFinderMultiplex/MultiplexResolver parameter missed_cleavages renamed to max_nr_labelled_aas (#8911)
- TOPP: MaRaClusterAdapter annotates consensus spectra with native IDs and cluster metadata (#8864)
- TOPP: MetaboliteAdductDecharger adds multimer detection (#8888)
- OpenMS Library BREAKING: ChromatogramPeak::IntensityType changed double -> float (#8857)
- Build: CMake 4.x compat fix for Windows packaging (#8880)
- Build: Fix pyOpenMS dev build RPATH (#8892)
- Build: Correctly locate locally installed nanobind (#8874)

Co-authored-by: Copilot <[email protected]>
github-actions Bot pushed a commit that referenced this pull request Mar 17, 2026
…ions

Add documentation for the three metadata values now added to each
consensus spectrum in the output mzML (introduced in #8864):
- maracluster_original_native_ids: original native IDs of source spectra
- maracluster_original_file_origins: source file paths
- maracluster_cluster_size: number of merged spectra

Co-authored-by: Copilot <[email protected]>
timosachsenberg pushed a commit that referenced this pull request Mar 17, 2026
Add missing changelog entries for changes merged in the past 7 days:

- PyOpenMS: PeptideAndProteinQuant.getPeptideResults/getProteinResults exposed (#8543)
- PyOpenMS BREAKING: zero-copy _mv methods renamed to _view (#8857)
- TOPP BREAKING: FeatureFinderMultiplex/MultiplexResolver parameter missed_cleavages renamed to max_nr_labelled_aas (#8911)
- TOPP: MaRaClusterAdapter annotates consensus spectra with native IDs and cluster metadata (#8864)
- TOPP: MetaboliteAdductDecharger adds multimer detection (#8888)
- OpenMS Library BREAKING: ChromatogramPeak::IntensityType changed double -> float (#8857)
- Build: CMake 4.x compat fix for Windows packaging (#8880)
- Build: Fix pyOpenMS dev build RPATH (#8892)
- Build: Correctly locate locally installed nanobind (#8874)

Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
timosachsenberg pushed a commit that referenced this pull request Mar 17, 2026
…ions (#8918)

Add documentation for the three metadata values now added to each
consensus spectrum in the output mzML (introduced in #8864):
- maracluster_original_native_ids: original native IDs of source spectra
- maracluster_original_file_origins: source file paths
- maracluster_cluster_size: number of merged spectra

Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[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.

MaRaClusterAdapter should annotate original native id of spectra

1 participant