Skip to content

Use unordered_map for O(1) lookups in OpenSWATH code - #8651

Merged
timosachsenberg merged 3 commits into
developfrom
feature/openswath-unordered-map-optimization
Jan 14, 2026
Merged

timosachsenberg merged 3 commits into
developfrom
feature/openswath-unordered-map-optimization

Conversation

@timosachsenberg

@timosachsenberg timosachsenberg commented Jan 14, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Convert lookup-only std::map containers to std::unordered_map for O(1) average-case performance in hot paths
  • Fix double-lookup anti-patterns (find() + operator[]) by using single iterator lookups
  • Simplify redundant find-then-insert patterns in MRMAssay

Changes

File Change Impact
MRMFeatureFinderScoring.cpp chromatogram_map → unordered_map + fixed double-lookup O(1) lookups in transition mapping loop
TargetedExperiment.h Reference maps → unordered_map O(1) protein/peptide/compound lookups
OpenSwathWorkflow.cpp PeptideRTMap → unordered_map + fixed double-lookup O(1) RT normalization lookups
ChromatogramExtractor.cpp pep2tr, tr2pep → unordered_map O(1) coordinate preparation
DIAScoring.cpp/.h intensities map → unordered_map O(1) isotope scoring
MRMAssay.cpp Fixed triple-lookup pattern (2 locations) Reduced map operations by ~66%

Design Decisions

  • Maps that are iterated over (e.g., TransitionsMap in MRMAssay, transition_group_map) are intentionally kept as std::map to preserve deterministic iteration order
  • All maps converted are lookup-only (using find(), operator[], or at())
  • Thread safety is preserved: all converted maps are built before parallel regions and accessed read-only

Test plan

  • All 5 core C++ class tests pass (TargetedExperiment, MRMFeatureFinderScoring, DIAScoring, ChromatogramExtractor, MRMAssay)
  • All 160 OpenSWATH TOPP integration tests pass
  • All MRM-related tests pass (MRMDecoy, MRMFeatureFilter, MRMMapping, TransitionTSVFile, TransitionPQPFile)
  • SwathMapMassCorrection test passes

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Optimization
    • Swapped ordered containers for hash-based maps and added preallocation across multiple analysis components for faster lookups and improved processing performance.
  • Refactor
    • Simplified iteration and lookup logic to reduce overhead and clarify data population flows.
  • Chores
    • Minor comment cleanup.

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

@coderabbitai

coderabbitai Bot commented Jan 14, 2026 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

Replaced several uses of std::map with std::unordered_map across OpenMS ANALYSIS modules (DIAScoring, TargetedExperiment, ChromatogramExtractor, MRMAssay, MRMFeatureFinderScoring, OpenSwathWorkflow), added corresponding <unordered_map> includes, added reserve() in places, and adjusted access/insertion patterns to match the unordered_map semantics.

Changes

Cohort / File(s) Summary
Header type updates
src/openms/include/OpenMS/ANALYSIS/OPENSWATH/DIAScoring.h, src/openms/include/OpenMS/ANALYSIS/TARGETED/TargetedExperiment.h
Added #include <unordered_map>; changed parameter/typedef types from std::map to std::unordered_map for intensity and reference maps.
DIAScoring implementation
src/openms/source/ANALYSIS/OPENSWATH/DIAScoring.cpp
Switched local intensities container to std::unordered_map, added reserve(), and replaced some insert() calls with emplace(); updated function signatures to accept unordered_map.
Chromatogram extraction
src/openms/source/ANALYSIS/OPENSWATH/ChromatogramExtractor.cpp
Replaced peptide->transitions and transition->peptide lookup maps with std::unordered_map, added reserve() and adjusted lookup usage.
Assay building
src/openms/source/ANALYSIS/OPENSWATH/MRMAssay.cpp
Replaced index-based loops with range-based iteration and simplified map population (relying on operator[] rather than explicit find checks).
Feature scoring
src/openms/source/ANALYSIS/OPENSWATH/MRMFeatureFinderScoring.cpp, src/openms/include/OpenMS/ANALYSIS/OPENSWATH/MRMFeatureFinderScoring.h
Changed chromatogram lookup map to std::unordered_map<String,int>, added reserve(), adjusted accesses to use iterators from find(); removed a descriptive comment in header.
Workflow processing
src/openms/source/ANALYSIS/OPENSWATH/OpenSwathWorkflow.cpp
Replaced several ordered maps (peptide RT map, chromatogram maps, assay_peptide_map) with std::unordered_map, added reserve(), and updated lookup/use to employ iterator checks.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐇 I hopped through maps that walked so slow,
Swapped keys for hashes, now watch me go—
I reserved my space, threw finds aside,
O(1) tails wag as lookups glide.

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 69.70% 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: converting std::map to std::unordered_map for O(1) lookup performance across multiple OpenSWATH files.

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

✨ Finishing touches
  • 📝 Generate docstrings


📜 Recent review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 69d2395 and 9894729.

📒 Files selected for processing (4)
  • src/openms/include/OpenMS/ANALYSIS/OPENSWATH/MRMFeatureFinderScoring.h
  • src/openms/source/ANALYSIS/OPENSWATH/ChromatogramExtractor.cpp
  • src/openms/source/ANALYSIS/OPENSWATH/DIAScoring.cpp
  • src/openms/source/ANALYSIS/OPENSWATH/OpenSwathWorkflow.cpp
💤 Files with no reviewable changes (1)
  • src/openms/include/OpenMS/ANALYSIS/OPENSWATH/MRMFeatureFinderScoring.h
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/openms/source/ANALYSIS/OPENSWATH/DIAScoring.cpp
  • src/openms/source/ANALYSIS/OPENSWATH/ChromatogramExtractor.cpp
🧰 Additional context used
📓 Path-based instructions (3)
src/openms/**/*.{cpp,h,hpp,cc,cxx}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

src/openms/**/*.{cpp,h,hpp,cc,cxx}: Follow the existing C++ coding conventions in the codebase
Use the established naming patterns for classes, methods, and variables
Use OpenMS data structures (e.g., MSExperiment, FeatureMap, PeptideIdentification)
Follow the established error handling patterns
Utilize OpenMS logging mechanisms
Be mindful of memory usage when processing large datasets
Consider algorithmic complexity for data processing operations
Use appropriate OpenMS containers and algorithms

Files:

  • src/openms/source/ANALYSIS/OPENSWATH/OpenSwathWorkflow.cpp
**/*.{h,cpp}

📄 CodeRabbit inference engine (AGENTS.md)

**/*.{h,cpp}: Use 2-space indentation for C++ and header files; no tabs; Unix line endings (LF)
All non-template exported classes, structs, functions, and variables must use OPENMS_DLLAPI macro; templates are exempt
One class per file; class name must match file name exactly
Always pair .h header files with .cpp implementation files
Class and type names must use PascalCase; methods must use lowerCamelCase; variables must use snake_case
Private and protected member variables must end with trailing underscore _
Enum names and macro definitions must use UPPER_SNAKE_CASE; prefer enum class over C-style enums
Use OpenMS primitive types from OpenMS/CONCEPT/Types.h instead of standard C++ types
Use Size/SignedSize types for STL .size() values instead of standard integer types
Prefer references over pointers in C++ code
Use Rule-of-0 (no explicit copy/move) or Rule-of-6 (all copy/move/destroy); never use Rule-of-5
Accessor methods must use get/set pairs for protected/private members; do not return references to primitive types
All exceptions must derive from Exception::Base; throw with file, line, and OPENMS_PRETTY_FUNCTION; catch by reference
Code comments must use // style; should comprise at least ~5% of code; describe the next few lines in plain English
Use .clang-format configuration from repository root for code formatting; check with clang-format --dry-run -Werror
Use OpenMS logging macros and OpenMS::LogStream; avoid std::cout and std::cerr
Avoid std::endl; prefer \n for better performance
Prefer OpenMS::String for numeric formatting and parsing
Braces must be on their own lines and aligned; always use braces even for single-line blocks (trivial one-liners may remain single-line)
Space required after keywords (if, for, while) and around binary operators

Files:

  • src/openms/source/ANALYSIS/OPENSWATH/OpenSwathWorkflow.cpp
**

📄 CodeRabbit inference engine (AGENTS.md)

File extensions must be lowercase except for ML, XML, and mzData

Files:

  • src/openms/source/ANALYSIS/OPENSWATH/OpenSwathWorkflow.cpp
🧠 Learnings (6)
📓 Common learnings
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 appropriate OpenMS containers and algorithms
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)
Learnt from: jpfeuffer
Repo: OpenMS/OpenMS PR: 8167
File: src/topp/Digestor.cpp:200-226
Timestamp: 2025-08-14T10:19:54.371Z
Learning: In OpenMS (C++ bioinformatics framework), use boost random libraries instead of std library random distributions for cross-platform reproducible random number generation, as std library distributions are not reproducible across platforms.
Learnt from: CR
Repo: OpenMS/OpenMS PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-01-10T13:35:09.526Z
Learning: Applies to **/*.{h,cpp} : Use OpenMS primitive types from `OpenMS/CONCEPT/Types.h` instead of standard C++ types
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} : Consider algorithmic complexity for data processing operations
Learnt from: CR
Repo: OpenMS/OpenMS PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-01-10T13:35:09.526Z
Learning: Applies to **/*.{h,cpp} : Use OpenMS logging macros and `OpenMS::LogStream`; avoid `std::cout` and `std::cerr`
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
📚 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/openms/source/ANALYSIS/OPENSWATH/OpenSwathWorkflow.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} : Use appropriate OpenMS containers and algorithms

Applied to files:

  • src/openms/source/ANALYSIS/OPENSWATH/OpenSwathWorkflow.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} : Consider algorithmic complexity for data processing operations

Applied to files:

  • src/openms/source/ANALYSIS/OPENSWATH/OpenSwathWorkflow.cpp
📚 Learning: 2025-08-29T19:09:45.997Z
Learnt from: jcharkow
Repo: OpenMS/OpenMS PR: 8188
File: src/topp/OpenSwathWorkflow.cpp:1118-1123
Timestamp: 2025-08-29T19:09:45.997Z
Learning: In OpenMS OpenSwathWorkflow, the use_ms1_ion_mobility parameter should be respected when applying estimated MS1 ion mobility extraction windows. The apply_window calls for MS1 ion mobility should check both pasef AND use_ms1_ion_mobility to avoid re-enabling disabled functionality.

Applied to files:

  • src/openms/source/ANALYSIS/OPENSWATH/OpenSwathWorkflow.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/openms/source/ANALYSIS/OPENSWATH/OpenSwathWorkflow.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). (10)
  • GitHub Check: build-and-test (ubuntu-24.04, g++, 13)
  • GitHub Check: build-lnx-arm
  • GitHub Check: build-and-test (windows-2025, cl.exe, 14.44)
  • GitHub Check: build-and-test (ubuntu-24.04-arm, g++, 13)
  • GitHub Check: build-and-test (macos-14, xcode, 15.4)
  • GitHub Check: build-win
  • GitHub Check: build-macos-arm
  • GitHub Check: build-and-test (ubuntu-24.04, clang++, 17)
  • GitHub Check: build-lnx
  • GitHub Check: cppcheck-test
🔇 Additional comments (5)
src/openms/source/ANALYSIS/OPENSWATH/OpenSwathWorkflow.cpp (5)

117-122: LGTM! Good conversion to unordered_map with proper preallocation.

The change from std::map to std::unordered_map provides O(1) average-case lookups for the RT value retrieval at line 175. The reserve() call appropriately pre-allocates space based on the expected number of compounds.


176-181: LGTM! Correct fix for the double-lookup anti-pattern.

Using the iterator from find() directly avoids a redundant map lookup. This is the idiomatic approach for conditional access with map containers.


955-960: LGTM! Appropriate conversion for lookup-only map.

The map is built once and then used exclusively for lookups (lines 1060, 1062). The reserve() call correctly pre-allocates based on the input chromatogram count.


962-967: LGTM! Consistent with the optimization pattern.

The map is used for O(1) lookups when processing transitions (lines 1016, 1023). The reserve() allocation matches the expected entry count.


968-973: LGTM! Correct optimization for index lookup map.

The assay_peptide_map provides fast compound index lookups used in the main scoring loop (lines 1000, 1082).

Note: The adjacent assay_map (line 976) appropriately remains a std::map since it may require deterministic iteration order during the scoring loop iteration starting at line 994.

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.


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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/openms/source/ANALYSIS/OPENSWATH/ChromatogramExtractor.cpp (1)

286-297: Dead code: && false makes this block unreachable.

The condition ms1 && ms1_isotopes > 0 && false can never be true. This block is effectively disabled. If this feature is intentionally disabled:

  • Consider removing the code entirely, or
  • Add a comment explaining why it's disabled, or
  • Use a proper feature flag/configuration option

Dead code without explanation creates maintenance burden.

🧹 Nitpick comments (6)
src/openms/source/ANALYSIS/OPENSWATH/DIAScoring.cpp (1)

286-299: Consider using at() for defensive lookup.

On line 299, intensities[native_id] will silently insert a default value (0.0) if the key doesn't exist. While the current code flow ensures keys are always present (same transitions vector is used to populate and query), using at() would make the expectation explicit and throw a clear exception if a key is ever missing due to future changes.

Suggested change
-      double rel_intensity = intensities[native_id];
+      double rel_intensity = intensities.at(native_id);
src/pyOpenMS/addons/PeptideIdentificationList.pyx (3)

381-393: Avoid bare except: clause; catch specific exceptions.

The bare except: clause at line 391 will catch all exceptions including SystemExit, KeyboardInterrupt, and other exceptions that shouldn't be silently ignored. This can mask bugs and make debugging difficult.

Suggested fix
         def _extract_scan_number(native_id):
             """Extract scan number using OpenMS SpectrumLookup logic."""
             if not native_id:
                 return None
             sl = _SpectrumLookup()
             for accession in _native_id_accessions:
                 try:
                     scan_num = sl.extractScanNumber(native_id, accession)
                     if scan_num >= 0:
                         return scan_num
-                except:
+                except Exception:
                     continue
             return None

481-488: Avoid bare except: clause; catch specific exceptions.

Same issue as above—use except Exception: at minimum to avoid catching SystemExit, KeyboardInterrupt, etc.

Suggested fix
                 # Calculate m/z from sequence
                 calculated_mz = None
                 if charge > 0:
                     try:
                         calculated_mz = seq.getMZ(charge)
-                    except:
+                    except Exception:
                         pass

601-651: get_psm_columns() returns columns not present in default get_psm_df() output.

The static method returns 27 columns including peak annotation fields (number_peaks, mz_array, intensity_array, charge_array, ion_type_array, ion_mobility_array), but get_psm_df() only includes these when include_peak_annotations=True (default is False). This discrepancy could confuse users expecting the returned list to match their DataFrame columns.

Consider either:

  1. Adding an include_peak_annotations parameter to get_psm_columns()
  2. Documenting this in the docstring
  3. Splitting into a base list + optional peak annotation columns
Option 1: Add parameter to match get_psm_df signature
     `@staticmethod`
-    def get_psm_columns():
+    def get_psm_columns(include_peak_annotations=False):
         """
-        get_psm_columns() -> list
+        get_psm_columns(include_peak_annotations: bool = False) -> list
 
         Return list of column names that get_psm_df() and to_qpx() produce.
 
         The columns follow the QPX PSM schema order, with additional
         OpenMS-specific fields appended.
 
+        :param include_peak_annotations: Include peak annotation columns.
+                                         Default False (matching get_psm_df default).
+        :type include_peak_annotations: bool
+
         Useful for discovering available columns before export.
 
         :return: List of column name strings.
         :rtype: list
 
         Example::
 
-            >>> PeptideIdentificationList.get_psm_columns()
+            >>> PeptideIdentificationList.get_psm_columns()  # base columns
             ['sequence', 'peptidoform', 'modifications', ...]
+            >>> PeptideIdentificationList.get_psm_columns(include_peak_annotations=True)
+            ['sequence', ..., 'number_peaks', 'mz_array', ...]
         """
-        return [
+        columns = [
             # QPX schema fields (in schema order)
             "sequence",
             "peptidoform",
             "modifications",
             "precursor_charge",
             "posterior_error_probability",
             "is_decoy",
             "calculated_mz",
             "observed_mz",
             "additional_scores",
             "protein_accessions",
             "predicted_rt",
             "reference_file_name",
             "cv_params",
             "scan",
             "rt",
             "ion_mobility",
+        ]
+        if include_peak_annotations:
+            columns.extend([
             "number_peaks",
             "mz_array",
             "intensity_array",
             "charge_array",
             "ion_type_array",
             "ion_mobility_array",
+            ])
+        columns.extend([
             # OpenMS-specific fields (not in QPX)
             "spectrum_reference",
             "score",
             "score_type",
             "rank",
             "P_ID",
-        ]
+        ])
+        return columns
src/pyOpenMS/tests/unittests/test_psm_dataframe.py (2)

271-286: Consider using _ for unused import skip return value.

Static analysis flags pa as unused. The pytest.importorskip pattern is correct for skipping tests when pyarrow isn't installed, but since the module reference isn't needed, you can use _ to indicate intentional discard.

Suggested fix
 def test_to_qpx():
     """Test to_qpx Arrow export."""
-    pa = pytest.importorskip("pyarrow")
+    pytest.importorskip("pyarrow")
+    import pyarrow as pa
 
     pep_ids = create_test_data()
     table = pep_ids.to_qpx()
 
     assert isinstance(table, pa.Table)

Or simply:

 def test_to_qpx():
     """Test to_qpx Arrow export."""
-    pa = pytest.importorskip("pyarrow")
+    _ = pytest.importorskip("pyarrow")
 
     pep_ids = create_test_data()

Apply the same pattern to test_to_qpx_with_params at line 290 and test_to_qpx_with_reference_file at line 300.

Also applies to: 288-296


310-346: Test should verify column consistency with actual DataFrame output.

This test verifies get_psm_columns() returns expected columns, but doesn't verify these match the actual DataFrame columns from get_psm_df(). Given the column mismatch issue noted in the implementation (peak annotation columns are conditional), consider adding an assertion that validates consistency.

Suggested addition
def test_get_psm_columns_matches_df():
    """Test that get_psm_columns() matches actual DataFrame columns."""
    import pyopenms as oms
    
    pep_ids = create_test_data()
    
    # Default columns (without peak annotations)
    df = pep_ids.get_psm_df()
    columns = oms.PeptideIdentificationList.get_psm_columns()
    
    # Note: get_psm_columns includes peak annotation columns that 
    # aren't present by default - document or fix this discrepancy
    base_columns = [c for c in columns if c not in [
        "number_peaks", "mz_array", "intensity_array", 
        "charge_array", "ion_type_array", "ion_mobility_array"
    ]]
    assert set(df.columns) == set(base_columns)
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2c39aba and 969fcc4.

📒 Files selected for processing (9)
  • src/openms/include/OpenMS/ANALYSIS/OPENSWATH/DIAScoring.h
  • src/openms/include/OpenMS/ANALYSIS/TARGETED/TargetedExperiment.h
  • src/openms/source/ANALYSIS/OPENSWATH/ChromatogramExtractor.cpp
  • src/openms/source/ANALYSIS/OPENSWATH/DIAScoring.cpp
  • src/openms/source/ANALYSIS/OPENSWATH/MRMAssay.cpp
  • src/openms/source/ANALYSIS/OPENSWATH/MRMFeatureFinderScoring.cpp
  • src/openms/source/ANALYSIS/OPENSWATH/OpenSwathWorkflow.cpp
  • src/pyOpenMS/addons/PeptideIdentificationList.pyx
  • src/pyOpenMS/tests/unittests/test_psm_dataframe.py
🧰 Additional context used
📓 Path-based instructions (10)
src/openms/**/*.{cpp,h,hpp,cc,cxx}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

src/openms/**/*.{cpp,h,hpp,cc,cxx}: Follow the existing C++ coding conventions in the codebase
Use the established naming patterns for classes, methods, and variables
Use OpenMS data structures (e.g., MSExperiment, FeatureMap, PeptideIdentification)
Follow the established error handling patterns
Utilize OpenMS logging mechanisms
Be mindful of memory usage when processing large datasets
Consider algorithmic complexity for data processing operations
Use appropriate OpenMS containers and algorithms

Files:

  • src/openms/source/ANALYSIS/OPENSWATH/OpenSwathWorkflow.cpp
  • src/openms/include/OpenMS/ANALYSIS/OPENSWATH/DIAScoring.h
  • src/openms/source/ANALYSIS/OPENSWATH/DIAScoring.cpp
  • src/openms/source/ANALYSIS/OPENSWATH/MRMAssay.cpp
  • src/openms/source/ANALYSIS/OPENSWATH/MRMFeatureFinderScoring.cpp
  • src/openms/source/ANALYSIS/OPENSWATH/ChromatogramExtractor.cpp
  • src/openms/include/OpenMS/ANALYSIS/TARGETED/TargetedExperiment.h
**/*.{h,cpp}

📄 CodeRabbit inference engine (AGENTS.md)

**/*.{h,cpp}: Use 2-space indentation for C++ and header files; no tabs; Unix line endings (LF)
All non-template exported classes, structs, functions, and variables must use OPENMS_DLLAPI macro; templates are exempt
One class per file; class name must match file name exactly
Always pair .h header files with .cpp implementation files
Class and type names must use PascalCase; methods must use lowerCamelCase; variables must use snake_case
Private and protected member variables must end with trailing underscore _
Enum names and macro definitions must use UPPER_SNAKE_CASE; prefer enum class over C-style enums
Use OpenMS primitive types from OpenMS/CONCEPT/Types.h instead of standard C++ types
Use Size/SignedSize types for STL .size() values instead of standard integer types
Prefer references over pointers in C++ code
Use Rule-of-0 (no explicit copy/move) or Rule-of-6 (all copy/move/destroy); never use Rule-of-5
Accessor methods must use get/set pairs for protected/private members; do not return references to primitive types
All exceptions must derive from Exception::Base; throw with file, line, and OPENMS_PRETTY_FUNCTION; catch by reference
Code comments must use // style; should comprise at least ~5% of code; describe the next few lines in plain English
Use .clang-format configuration from repository root for code formatting; check with clang-format --dry-run -Werror
Use OpenMS logging macros and OpenMS::LogStream; avoid std::cout and std::cerr
Avoid std::endl; prefer \n for better performance
Prefer OpenMS::String for numeric formatting and parsing
Braces must be on their own lines and aligned; always use braces even for single-line blocks (trivial one-liners may remain single-line)
Space required after keywords (if, for, while) and around binary operators

Files:

  • src/openms/source/ANALYSIS/OPENSWATH/OpenSwathWorkflow.cpp
  • src/openms/include/OpenMS/ANALYSIS/OPENSWATH/DIAScoring.h
  • src/openms/source/ANALYSIS/OPENSWATH/DIAScoring.cpp
  • src/openms/source/ANALYSIS/OPENSWATH/MRMAssay.cpp
  • src/openms/source/ANALYSIS/OPENSWATH/MRMFeatureFinderScoring.cpp
  • src/openms/source/ANALYSIS/OPENSWATH/ChromatogramExtractor.cpp
  • src/openms/include/OpenMS/ANALYSIS/TARGETED/TargetedExperiment.h
**

📄 CodeRabbit inference engine (AGENTS.md)

File extensions must be lowercase except for ML, XML, and mzData

Files:

  • src/openms/source/ANALYSIS/OPENSWATH/OpenSwathWorkflow.cpp
  • src/openms/include/OpenMS/ANALYSIS/OPENSWATH/DIAScoring.h
  • src/pyOpenMS/tests/unittests/test_psm_dataframe.py
  • src/openms/source/ANALYSIS/OPENSWATH/DIAScoring.cpp
  • src/openms/source/ANALYSIS/OPENSWATH/MRMAssay.cpp
  • src/pyOpenMS/addons/PeptideIdentificationList.pyx
  • src/openms/source/ANALYSIS/OPENSWATH/MRMFeatureFinderScoring.cpp
  • src/openms/source/ANALYSIS/OPENSWATH/ChromatogramExtractor.cpp
  • src/openms/include/OpenMS/ANALYSIS/TARGETED/TargetedExperiment.h
src/openms/include/OpenMS/**/*.h

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Add Doxygen comments for new public methods and classes

Files:

  • src/openms/include/OpenMS/ANALYSIS/OPENSWATH/DIAScoring.h
  • src/openms/include/OpenMS/ANALYSIS/TARGETED/TargetedExperiment.h
**/*.h

📄 CodeRabbit inference engine (AGENTS.md)

**/*.h: Do not add using namespace or using std::... in header files; allowed only in .cpp files
Prefer forward declarations in headers; include only base class headers, non-pointer members, and templates
Document possible exceptions in Doxygen comments using @throws or @exception tags
Use Doxygen /** */ block comments with @ tags (not backslash \); @brief is required and must be followed by a blank line before details
All parameter documentation in Doxygen must include direction tags: [in], [out], or [in,out]
Use @ingroup and @defgroup Doxygen tags to organize classes and functions into categories
Use @todo tags with assignee name (e.g., @todo JohnDoe fix this) in Doxygen comments
Every .h file must include a file preamble with $Maintainer:$ marker

Files:

  • src/openms/include/OpenMS/ANALYSIS/OPENSWATH/DIAScoring.h
  • src/openms/include/OpenMS/ANALYSIS/TARGETED/TargetedExperiment.h
src/pyOpenMS/tests/**/*.py

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Write pyOpenMS tests for new Python bindings

Files:

  • src/pyOpenMS/tests/unittests/test_psm_dataframe.py
**/*.{py,pyx,pxd}

📄 CodeRabbit inference engine (AGENTS.md)

Use 4-space indentation for Python and Cython files per PEP 8; no tabs; Unix line endings (LF)

Files:

  • src/pyOpenMS/tests/unittests/test_psm_dataframe.py
  • src/pyOpenMS/addons/PeptideIdentificationList.pyx
src/pyOpenMS/**/*.{pyx,pxd,py}

📄 CodeRabbit inference engine (AGENTS.md)

Use snake_case for all Python-facing names and DataFrame column names in pyOpenMS

Files:

  • src/pyOpenMS/tests/unittests/test_psm_dataframe.py
  • src/pyOpenMS/addons/PeptideIdentificationList.pyx
src/pyOpenMS/**/*.{pyx,py}

📄 CodeRabbit inference engine (AGENTS.md)

pyOpenMS DataFrame pattern: get_data_dict() in addon returns numpy arrays; get_df() in _dataframes.py wraps with pandas

Files:

  • src/pyOpenMS/tests/unittests/test_psm_dataframe.py
  • src/pyOpenMS/addons/PeptideIdentificationList.pyx
src/pyOpenMS/addons/*.pyx

📄 CodeRabbit inference engine (AGENTS.md)

src/pyOpenMS/addons/*.pyx: Python addon methods must not be added to .pxd files; use src/pyOpenMS/addons/ or _dataframes.py wrappers instead
pyOpenMS addons must use 4-space indentation and maintain minimal code; avoid redundant aliases
Do not add custom __init__ methods in pyOpenMS unless required; it overrides autowrap dispatchers
Autowrap returns Python strings; do NOT call .decode() on autowrap string return values
Avoid cdef typed variables for autowrap return values inside def methods; use Python type checks instead
Regenerate pyOpenMS after addon changes by removing .cpp_extension_generated and rebuilding with --target pyopenms

Files:

  • src/pyOpenMS/addons/PeptideIdentificationList.pyx
🧠 Learnings (25)
📓 Common learnings
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 appropriate OpenMS containers and algorithms
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)
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} : Consider algorithmic complexity for data processing operations
Learnt from: CR
Repo: OpenMS/OpenMS PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-01-10T13:35:09.526Z
Learning: Applies to src/pyOpenMS/**/*.{pyx,py} : pyOpenMS DataFrame pattern: `get_data_dict()` in addon returns numpy arrays; `get_df()` in `_dataframes.py` wraps with pandas
📚 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/openms/source/ANALYSIS/OPENSWATH/OpenSwathWorkflow.cpp
  • src/openms/include/OpenMS/ANALYSIS/OPENSWATH/DIAScoring.h
  • src/openms/source/ANALYSIS/OPENSWATH/DIAScoring.cpp
  • src/openms/source/ANALYSIS/OPENSWATH/MRMAssay.cpp
  • src/openms/source/ANALYSIS/OPENSWATH/MRMFeatureFinderScoring.cpp
  • src/openms/source/ANALYSIS/OPENSWATH/ChromatogramExtractor.cpp
  • src/openms/include/OpenMS/ANALYSIS/TARGETED/TargetedExperiment.h
📚 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 appropriate OpenMS containers and algorithms

Applied to files:

  • src/openms/source/ANALYSIS/OPENSWATH/OpenSwathWorkflow.cpp
  • src/openms/include/OpenMS/ANALYSIS/OPENSWATH/DIAScoring.h
  • src/openms/source/ANALYSIS/OPENSWATH/DIAScoring.cpp
  • src/openms/source/ANALYSIS/OPENSWATH/MRMAssay.cpp
  • src/openms/source/ANALYSIS/OPENSWATH/MRMFeatureFinderScoring.cpp
  • src/openms/source/ANALYSIS/OPENSWATH/ChromatogramExtractor.cpp
  • src/openms/include/OpenMS/ANALYSIS/TARGETED/TargetedExperiment.h
📚 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} : Consider algorithmic complexity for data processing operations

Applied to files:

  • src/openms/source/ANALYSIS/OPENSWATH/OpenSwathWorkflow.cpp
  • src/openms/source/ANALYSIS/OPENSWATH/MRMAssay.cpp
  • src/openms/source/ANALYSIS/OPENSWATH/ChromatogramExtractor.cpp
📚 Learning: 2025-10-15T07:49:09.293Z
Learnt from: timosachsenberg
Repo: OpenMS/OpenMS PR: 8177
File: src/openms/include/OpenMS/PROCESSING/CENTROIDING/PeakPickerIM.h:11-14
Timestamp: 2025-10-15T07:49:09.293Z
Learning: In OpenMS, DefaultParamHandler.h is located under OpenMS/DATASTRUCTURES/, not OpenMS/CONCEPT/. The correct include is: `#include <OpenMS/DATASTRUCTURES/DefaultParamHandler.h>`

Applied to files:

  • src/openms/include/OpenMS/ANALYSIS/OPENSWATH/DIAScoring.h
📚 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/pyOpenMS/tests/**/*.py : Write pyOpenMS tests for new Python bindings

Applied to files:

  • src/pyOpenMS/tests/unittests/test_psm_dataframe.py
📚 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/pyOpenMS/tests/unittests/test_psm_dataframe.py
  • src/openms/source/ANALYSIS/OPENSWATH/ChromatogramExtractor.cpp
📚 Learning: 2026-01-10T13:35:09.526Z
Learnt from: CR
Repo: OpenMS/OpenMS PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-01-10T13:35:09.526Z
Learning: PR checklist: update `AUTHORS` and `CHANGELOG`, run/extend tests, update pyOpenMS bindings when needed

Applied to files:

  • src/pyOpenMS/tests/unittests/test_psm_dataframe.py
📚 Learning: 2026-01-10T13:35:09.526Z
Learnt from: CR
Repo: OpenMS/OpenMS PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-01-10T13:35:09.526Z
Learning: Applies to src/pyOpenMS/**/*.{pyx,py} : pyOpenMS DataFrame pattern: `get_data_dict()` in addon returns numpy arrays; `get_df()` in `_dataframes.py` wraps with pandas

Applied to files:

  • src/pyOpenMS/tests/unittests/test_psm_dataframe.py
  • src/pyOpenMS/addons/PeptideIdentificationList.pyx
📚 Learning: 2026-01-10T13:35:09.526Z
Learnt from: CR
Repo: OpenMS/OpenMS PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-01-10T13:35:09.526Z
Learning: Applies to src/pyOpenMS/**/*.{pyx,pxd,py} : Use snake_case for all Python-facing names and DataFrame column names in pyOpenMS

Applied to files:

  • src/pyOpenMS/tests/unittests/test_psm_dataframe.py
📚 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/pyOpenMS/**/*.h : Add Doxygen comments for new public methods and classes in pyOpenMS bindings

Applied to files:

  • src/pyOpenMS/tests/unittests/test_psm_dataframe.py
  • src/pyOpenMS/addons/PeptideIdentificationList.pyx
📚 Learning: 2026-01-10T13:35:09.526Z
Learnt from: CR
Repo: OpenMS/OpenMS PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-01-10T13:35:09.526Z
Learning: Applies to src/pyOpenMS/pxds/*.pxd : pyOpenMS `.pxd` signatures must stay synchronized with corresponding C++ API changes

Applied to files:

  • src/pyOpenMS/tests/unittests/test_psm_dataframe.py
  • src/pyOpenMS/addons/PeptideIdentificationList.pyx
📚 Learning: 2026-01-04T21:35:37.785Z
Learnt from: timosachsenberg
Repo: OpenMS/OpenMS PR: 8588
File: src/pyOpenMS/tests/unittests/test_TargetedQuantitation.py:1-456
Timestamp: 2026-01-04T21:35:37.785Z
Learning: For Python files in the repository, follow PEP 8: use 4-space indentation, avoid tabs, and ensure Unix LF line endings. The 2-space indentation and Unix line endings guideline applies to C/Cython in their respective languages; Python files should adhere to Python style (PEP 8) regardless of other language rules.

Applied to files:

  • src/pyOpenMS/tests/unittests/test_psm_dataframe.py
📚 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/openms/source/ANALYSIS/OPENSWATH/MRMAssay.cpp
  • src/openms/source/ANALYSIS/OPENSWATH/ChromatogramExtractor.cpp
  • src/openms/include/OpenMS/ANALYSIS/TARGETED/TargetedExperiment.h
📚 Learning: 2025-10-21T13:02:16.431Z
Learnt from: timosachsenberg
Repo: OpenMS/OpenMS PR: 8318
File: src/openms/include/OpenMS/ML/CLUSTERING/HashGrid.h:466-480
Timestamp: 2025-10-21T13:02:16.431Z
Learning: In OpenMS, when making internal methods public (e.g., in HashGrid.h), remove XXX/TODO comments about implementation details rather than documenting them in the public API documentation.

Applied to files:

  • src/openms/source/ANALYSIS/OPENSWATH/MRMAssay.cpp
  • src/openms/source/ANALYSIS/OPENSWATH/ChromatogramExtractor.cpp
📚 Learning: 2026-01-10T13:35:09.526Z
Learnt from: CR
Repo: OpenMS/OpenMS PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-01-10T13:35:09.526Z
Learning: Applies to src/pyOpenMS/addons/*.pyx : Python addon methods must not be added to `.pxd` files; use `src/pyOpenMS/addons/` or `_dataframes.py` wrappers instead

Applied to files:

  • src/pyOpenMS/addons/PeptideIdentificationList.pyx
📚 Learning: 2025-06-16T15:49:26.504Z
Learnt from: FreezB11
Repo: OpenMS/OpenMS PR: 7969
File: src/pyOpenMS/pxds/TMTThirtyTwoPlexQuantitationMethod.pxd:1-3
Timestamp: 2025-06-16T15:49:26.504Z
Learning: In OpenMS Python bindings (.pxd files), derived quantitation method classes like TMTThirtyTwoPlexQuantitationMethod only need to declare their constructors. All other public methods (getName, getChannelInformation, getNumberOfChannels, getIsotopeCorrectionMatrix, getReferenceChannel) are inherited from the base IsobaricQuantitationMethod class and don't need to be redeclared explicitly.

Applied to files:

  • src/pyOpenMS/addons/PeptideIdentificationList.pyx
📚 Learning: 2026-01-10T13:35:09.526Z
Learnt from: CR
Repo: OpenMS/OpenMS PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-01-10T13:35:09.526Z
Learning: Applies to **/*.{h,cpp} : Use OpenMS primitive types from `OpenMS/CONCEPT/Types.h` instead of standard C++ types

Applied to files:

  • src/openms/source/ANALYSIS/OPENSWATH/ChromatogramExtractor.cpp
  • src/openms/include/OpenMS/ANALYSIS/TARGETED/TargetedExperiment.h
📚 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/include/OpenMS/**/*.h : Add Doxygen comments for new public methods and classes

Applied to files:

  • src/openms/source/ANALYSIS/OPENSWATH/ChromatogramExtractor.cpp
📚 Learning: 2025-08-14T10:19:54.371Z
Learnt from: jpfeuffer
Repo: OpenMS/OpenMS PR: 8167
File: src/topp/Digestor.cpp:200-226
Timestamp: 2025-08-14T10:19:54.371Z
Learning: In OpenMS (C++ bioinformatics framework), use boost random libraries instead of std library random distributions for cross-platform reproducible random number generation, as std library distributions are not reproducible across platforms.

Applied to files:

  • src/openms/source/ANALYSIS/OPENSWATH/ChromatogramExtractor.cpp
📚 Learning: 2026-01-10T13:35:09.526Z
Learnt from: CR
Repo: OpenMS/OpenMS PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-01-10T13:35:09.526Z
Learning: Applies to **/*.{h,cpp} : Use OpenMS logging macros and `OpenMS::LogStream`; avoid `std::cout` and `std::cerr`

Applied to files:

  • src/openms/source/ANALYSIS/OPENSWATH/ChromatogramExtractor.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/openms/source/ANALYSIS/OPENSWATH/ChromatogramExtractor.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/openms/source/ANALYSIS/OPENSWATH/ChromatogramExtractor.cpp
📚 Learning: 2025-07-29T10:05:48.015Z
Learnt from: poshul
Repo: OpenMS/OpenMS PR: 8133
File: src/openms/source/ANALYSIS/OPENSWATH/OpenSwathHelper.cpp:0-0
Timestamp: 2025-07-29T10:05:48.015Z
Learning: In LightTargetedExperiment, all entity types (peptides, nucleotides, compounds, oligos) are intentionally stored in a unified collection called `compounds` (later renamed to `peptideNuctideCompounds`). This means that when processing oligos, the code correctly accesses `targeted_exp.compounds[i].oligo_refs` rather than a separate oligo-specific collection, as the design uses a unified data structure approach.

Applied to files:

  • src/openms/include/OpenMS/ANALYSIS/TARGETED/TargetedExperiment.h
📚 Learning: 2026-01-10T13:35:09.526Z
Learnt from: CR
Repo: OpenMS/OpenMS PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-01-10T13:35:09.526Z
Learning: Applies to src/topp/*.cpp : TOPP tool source files must be registered in `src/topp/executables.cmake` and added to `src/openms/source/APPLICATIONS/ToolHandler.cpp`

Applied to files:

  • src/openms/include/OpenMS/ANALYSIS/TARGETED/TargetedExperiment.h
🪛 Ruff (0.14.11)
src/pyOpenMS/tests/unittests/test_psm_dataframe.py

290-290: Local variable pa is assigned to but never used

Remove assignment to unused variable pa

(F841)


300-300: Local variable pa is assigned to but never used

Remove assignment to unused variable pa

(F841)

⏰ 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). (10)
  • GitHub Check: build-and-test (ubuntu-24.04-arm, g++, 13)
  • GitHub Check: build-and-test (ubuntu-24.04, clang++, 17)
  • GitHub Check: build-and-test (ubuntu-24.04, g++, 13)
  • GitHub Check: build-and-test (windows-2025, cl.exe, 14.44)
  • GitHub Check: build-and-test (macos-14, xcode, 15.4)
  • GitHub Check: build-macos-arm
  • GitHub Check: build-lnx-arm
  • GitHub Check: build-lnx
  • GitHub Check: build-win
  • GitHub Check: cppcheck-test
🔇 Additional comments (23)
src/openms/source/ANALYSIS/OPENSWATH/MRMAssay.cpp (2)

906-908: LGTM! Clean optimization of the map population pattern.

Using const ReactionMonitoringTransition& avoids unnecessary copying, and relying on operator[] to create empty vectors on demand eliminates the redundant find() lookup. This is a correct and idiomatic simplification. Based on learnings, this aligns with considering algorithmic complexity for data processing operations.


1087-1089: LGTM! Consistent application of the same optimization.

Same pattern as the detectingTransitions function—using a const reference and letting operator[] handle key creation. This maintains consistency across the codebase.

src/openms/include/OpenMS/ANALYSIS/OPENSWATH/DIAScoring.h (2)

14-15: LGTM!

The <unordered_map> include is correctly added for the new container types used in the private method signatures.


148-161: LGTM!

The private method signatures are correctly updated to use std::unordered_map<std::string, double>&. Since std::string is used as the key type, the standard hash function is available. The changes are internal to the class and don't affect the public API.

src/openms/source/ANALYSIS/OPENSWATH/OpenSwathWorkflow.cpp (3)

176-180: Good fix for double-lookup anti-pattern.

Using the iterator result from find() directly via tg_it->second eliminates the redundant map access that would occur with find() followed by operator[]. This is a correct and efficient pattern.


956-976: LGTM!

The reserve() calls are appropriately placed to pre-allocate capacity based on known sizes, which avoids rehashing during population. This is a good practice for performance optimization.


116-122: No concerns with std::hash<OpenMS::String> specialization—it is properly defined.

The std::unordered_map<OpenMS::String, double> usage is correct. OpenMS::String inherits from std::string and a std::hash<OpenMS::String> specialization is defined in the std namespace (lines 493–499 of String.h), which delegates to std::hash<string>. The code change is valid.

src/openms/include/OpenMS/ANALYSIS/TARGETED/TargetedExperiment.h (2)

20-21: LGTM!

The <unordered_map> include is correctly placed alongside other standard library includes.


67-69: No public API impact from this change.

The typedefs are public declarations, but the actual map instances (protein_reference_map_, peptide_reference_map_, compound_reference_map_) are private mutable members of the class. They are not exposed to external callers and changing from std::map to std::unordered_map is an internal optimization with no API contract implications.

The maps are used exclusively for fast lookups via find() and operator[], with no code iterating over them or depending on ordering. Using unordered_map improves performance (O(1) average vs O(log n) for map operations) for the intended use case.

src/openms/source/ANALYSIS/OPENSWATH/ChromatogramExtractor.cpp (3)

15-16: LGTM!

The <unordered_map> include is correctly added.


110-119: LGTM!

The conversion to std::unordered_map with appropriate reserve() call aligns with the PR objective of O(1) lookups. The comment clearly documents the intent.


195-196: LGTM!

The typedef change to std::unordered_map is consistent with the other overload and the PR objectives.

src/openms/source/ANALYSIS/OPENSWATH/MRMFeatureFinderScoring.cpp (3)

27-27: LGTM!

The <unordered_map> include is correctly added.


1100-1106: LGTM!

The conversion to std::unordered_map with reserve() pre-allocation is appropriate for the lookup-only use case.


1116-1133: Good fix for double-lookup anti-pattern.

The code now uses a single find() call and reuses the iterator result via chrom_it->second at line 1133, eliminating the redundant lookup that would occur with find() followed by operator[]. This is the correct pattern for efficient map access.

src/openms/source/ANALYSIS/OPENSWATH/DIAScoring.cpp (2)

105-109: LGTM! Good optimization with reserve().

The conversion to unordered_map for O(1) lookups is appropriate here since the map is only used for key-based lookups, not ordered iteration. The reserve() call is a good practice to minimize rehashing during insertions.


274-284: LGTM! Appropriate use of emplace.

Using emplace() is correct for unordered_map and avoids creating temporary std::pair objects, making it slightly more efficient than insert().

src/pyOpenMS/addons/PeptideIdentificationList.pyx (2)

305-359: Well-documented QPX PSM export method.

The docstring is comprehensive, covering all parameters, return types, and providing usage examples. The method correctly differentiates from get_df() by supporting all hits with ranking information.


553-599: LGTM!

The to_qpx() method properly delegates to get_psm_df() and converts to Arrow Table. The docstring clearly documents both QPX schema fields and OpenMS-specific fields.

src/pyOpenMS/tests/unittests/test_psm_dataframe.py (4)

1-62: Comprehensive test setup with good coverage.

The create_test_data() helper creates realistic test data with multiple hits, protein evidences, and metadata. The test structure follows pytest best practices with clear docstrings and focused assertions.


64-97: Good coverage for basic and top-hit-only export.

Tests verify row counts, ranking, and P_ID tracking correctly for both all-hits and top-hit-only modes.


141-165: Thorough testing of metadata extraction.

Good coverage for decoy detection, PEP score extraction, protein accessions, additional scores, and modification handling with position/mass validation.

Also applies to: 167-186, 188-225


112-139: The test's index=42 → 43 expectation is correct and matches SpectrumLookup implementation.

The behavior is intentional, not flaky. SpectrumLookup::extractScanNumber explicitly returns value + 1 for MS:1000774 (index format) with a documented reason: "the scan number is usually considered index+1 (especially for pepXML)". This is tested in the official OpenMS C++ unit tests and is the documented behavior. The pyOpenMS implementation directly delegates to this tested C++ function via sl.extractScanNumber(native_id, accession), so the test accurately reflects the expected behavior.

Likely an incorrect or invalid review comment.

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.

@jpfeuffer

Copy link
Copy Markdown
Contributor

there is also some pyopenms stuff that seems unrelated. wrong branch? is this on dev already?

@timosachsenberg

Copy link
Copy Markdown
Contributor Author

yeah sorry started of the wrong branch. will fix later just ignore

@jpfeuffer

Copy link
Copy Markdown
Contributor

By the way, I often wonder in OpenSwath code, if certain mappings could be avoided or combined or replaced with simple vectors.

@timosachsenberg

Copy link
Copy Markdown
Contributor Author

I can run a KISS agent ;)

timosachsenberg and others added 2 commits January 14, 2026 16:30
Convert lookup-only std::map containers to std::unordered_map for
improved performance in hot paths:

- MRMFeatureFinderScoring: chromatogram_map for transition mapping
- TargetedExperiment: protein/peptide/compound reference maps
- OpenSwathWorkflow: PeptideRTMap for RT normalization
- ChromatogramExtractor: pep2tr and tr2pep coordinate maps
- DIAScoring: intensities map for isotope scoring

Also fix double-lookup anti-patterns (find + operator[]) by using
single iterator lookups, and simplify redundant find-then-insert
patterns in MRMAssay.

Maps that are iterated over are intentionally kept as std::map to
preserve deterministic iteration order.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@timosachsenberg
timosachsenberg force-pushed the feature/openswath-unordered-map-optimization branch from 347c783 to 69d2395 Compare January 14, 2026 15:31

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

Code looks good, however I would like to test it locally with real data before merging to make sure nothing is breaking.

Out of curiosity is this only possible now because of the added hash functions or has this always been possible.

@timosachsenberg

Copy link
Copy Markdown
Contributor Author

ah right this is AI comments. forgot to clean them up.
I am not 100% sure but it could well be that this is only now possible.

@timosachsenberg

Copy link
Copy Markdown
Contributor Author

@jcharkow actually this requires none of the new hash functions

@timosachsenberg
timosachsenberg merged commit 037c9ba into develop Jan 14, 2026
@timosachsenberg
timosachsenberg deleted the feature/openswath-unordered-map-optimization branch January 14, 2026 19:23
@jcharkow

Copy link
Copy Markdown
Collaborator

Just tested with some local data and everything seems to be working as expected except for the FEATURE_MS1_VAR_ISOTOPE_CORRELATION_SCORE is different from OpenMS 3.5 results. I don't think that this is related to this PR though. Will Open a separate issue on that.

I don't notice any speed improvements but the library I used for testing is quite small.

claude Bot pushed a commit that referenced this pull request Jan 18, 2026
Added 19 missing PRs to OpenMS 3.6.0 changelog:

PyOpenMS:
- #8530: Build system modernization with py-build-cmake
- #8633: SpectrumNativeIDParser wrapper
- #8655: Arrow/Parquet export with DataFrame methods (BREAKING: method renames)
- #8661: Build dependency docs
- #8664: Biosaur2Algorithm wrap-inherits
- #8668: wrap-doc documentation
- #8674: Docstring validation tests

TOPP tools:
- #8643: FileInfo FASTA stats
- #8650: FileConverter MSP support
- #8649: PeakPickerHiRes parameter

OpenMS Library:
- #8633: SpectrumNativeIDParser class
- #8655: ArrowExport helper
- #8651, #8656, #8659, #8660, #8662: Performance optimizations

Fixes:
- #8645: DataArray handling in filters
- #8672: Test file correction
- #8678: UniqueIdGenerator seed collision fix

Build System:
- #8675, #8676: Claude CI workflows

Also reorganized misplaced entries from lines 122-129.

Co-authored-by: Timo Sachsenberg <[email protected]>
timosachsenberg added a commit that referenced this pull request Jan 18, 2026
* Add comprehensive changelog for OpenMS 3.6.0

Includes changes from 96 merged PRs since version 3.5.0:

- General: macOS Intel discontinued, Ubuntu 24.04, notarization in CI
- Dependencies: Autowrap >= 0.26.0, Eigen minimum 3.4.0
- PyOpenMS: Pythonic methods (__len__, __str__, __repr__, __hash__),
  DataFrame support, new wrappers, string handling improvements
- TOPP tools: MapAligner spectra transformation, FileInfo improvements,
  IsobaricWorkflow fixes, SageAdapter thread handling
- OpenMS Library: PeakFileOptions, ParamIterator, SpectrumAnnotator
- Breaking changes: Matrix<T> Eigen decoupling, API renames, FileWatcher move
- Bug fixes: NucleicAcidSearchEngine, LogConfigHandler, decoy generation
- Documentation: Targeted Quantitation, parameter annotations, AGENTS.md
- Build: macOS notarization, Parquet support, pytest fixtures

Co-Authored-By: Claude Opus 4.5 <[email protected]>

* Add missing changelog entries for recently merged PRs

Added 19 missing PRs to OpenMS 3.6.0 changelog:

PyOpenMS:
- #8530: Build system modernization with py-build-cmake
- #8633: SpectrumNativeIDParser wrapper
- #8655: Arrow/Parquet export with DataFrame methods (BREAKING: method renames)
- #8661: Build dependency docs
- #8664: Biosaur2Algorithm wrap-inherits
- #8668: wrap-doc documentation
- #8674: Docstring validation tests

TOPP tools:
- #8643: FileInfo FASTA stats
- #8650: FileConverter MSP support
- #8649: PeakPickerHiRes parameter

OpenMS Library:
- #8633: SpectrumNativeIDParser class
- #8655: ArrowExport helper
- #8651, #8656, #8659, #8660, #8662: Performance optimizations

Fixes:
- #8645: DataArray handling in filters
- #8672: Test file correction
- #8678: UniqueIdGenerator seed collision fix

Build System:
- #8675, #8676: Claude CI workflows

Also reorganized misplaced entries from lines 122-129.

Co-authored-by: Timo Sachsenberg <[email protected]>

---------

Co-authored-by: Claude Opus 4.5 <[email protected]>
Co-authored-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com>
Co-authored-by: Timo Sachsenberg <[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