Repository navigation
Use unordered_map for O(1) lookups in OpenSWATH code - #8651
Conversation
📝 WalkthroughWalkthroughReplaced 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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
📜 Recent review detailsConfiguration used: Organization UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (4)
💤 Files with no reviewable changes (1)
🚧 Files skipped from review as they are similar to previous changes (2)
🧰 Additional context used📓 Path-based instructions (3)src/openms/**/*.{cpp,h,hpp,cc,cxx}📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Files:
**/*.{h,cpp}📄 CodeRabbit inference engine (AGENTS.md)
Files:
**📄 CodeRabbit inference engine (AGENTS.md)
Files:
🧠 Learnings (6)📓 Common learnings📚 Learning: 2025-08-05T12:43:11.681ZApplied to files:
📚 Learning: 2025-08-05T12:43:11.681ZApplied to files:
📚 Learning: 2025-08-05T12:43:11.681ZApplied to files:
📚 Learning: 2025-08-29T19:09:45.997ZApplied to files:
📚 Learning: 2025-08-05T12:43:11.681ZApplied to files:
⏰ 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)
🔇 Additional comments (5)
✏️ Tip: You can disable this entire section by setting 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. Comment |
There was a problem hiding this comment.
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:&& falsemakes this block unreachable.The condition
ms1 && ms1_isotopes > 0 && falsecan 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 usingat()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 (sametransitionsvector is used to populate and query), usingat()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 bareexcept:clause; catch specific exceptions.The bare
except:clause at line 391 will catch all exceptions includingSystemExit,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 bareexcept:clause; catch specific exceptions.Same issue as above—use
except Exception:at minimum to avoid catchingSystemExit,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 defaultget_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), butget_psm_df()only includes these wheninclude_peak_annotations=True(default isFalse). This discrepancy could confuse users expecting the returned list to match their DataFrame columns.Consider either:
- Adding an
include_peak_annotationsparameter toget_psm_columns()- Documenting this in the docstring
- 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 columnssrc/pyOpenMS/tests/unittests/test_psm_dataframe.py (2)
271-286: Consider using_for unused import skip return value.Static analysis flags
paas unused. Thepytest.importorskippattern 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_paramsat line 290 andtest_to_qpx_with_reference_fileat 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 fromget_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
📒 Files selected for processing (9)
src/openms/include/OpenMS/ANALYSIS/OPENSWATH/DIAScoring.hsrc/openms/include/OpenMS/ANALYSIS/TARGETED/TargetedExperiment.hsrc/openms/source/ANALYSIS/OPENSWATH/ChromatogramExtractor.cppsrc/openms/source/ANALYSIS/OPENSWATH/DIAScoring.cppsrc/openms/source/ANALYSIS/OPENSWATH/MRMAssay.cppsrc/openms/source/ANALYSIS/OPENSWATH/MRMFeatureFinderScoring.cppsrc/openms/source/ANALYSIS/OPENSWATH/OpenSwathWorkflow.cppsrc/pyOpenMS/addons/PeptideIdentificationList.pyxsrc/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.cppsrc/openms/include/OpenMS/ANALYSIS/OPENSWATH/DIAScoring.hsrc/openms/source/ANALYSIS/OPENSWATH/DIAScoring.cppsrc/openms/source/ANALYSIS/OPENSWATH/MRMAssay.cppsrc/openms/source/ANALYSIS/OPENSWATH/MRMFeatureFinderScoring.cppsrc/openms/source/ANALYSIS/OPENSWATH/ChromatogramExtractor.cppsrc/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 useOPENMS_DLLAPImacro; templates are exempt
One class per file; class name must match file name exactly
Always pair.hheader files with.cppimplementation 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; preferenum classover C-style enums
Use OpenMS primitive types fromOpenMS/CONCEPT/Types.hinstead of standard C++ types
UseSize/SignedSizetypes 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 fromException::Base; throw with file, line, andOPENMS_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-formatconfiguration from repository root for code formatting; check withclang-format --dry-run -Werror
Use OpenMS logging macros andOpenMS::LogStream; avoidstd::coutandstd::cerr
Avoidstd::endl; prefer\nfor better performance
PreferOpenMS::Stringfor 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.cppsrc/openms/include/OpenMS/ANALYSIS/OPENSWATH/DIAScoring.hsrc/openms/source/ANALYSIS/OPENSWATH/DIAScoring.cppsrc/openms/source/ANALYSIS/OPENSWATH/MRMAssay.cppsrc/openms/source/ANALYSIS/OPENSWATH/MRMFeatureFinderScoring.cppsrc/openms/source/ANALYSIS/OPENSWATH/ChromatogramExtractor.cppsrc/openms/include/OpenMS/ANALYSIS/TARGETED/TargetedExperiment.h
**
📄 CodeRabbit inference engine (AGENTS.md)
File extensions must be lowercase except for
ML,XML, andmzData
Files:
src/openms/source/ANALYSIS/OPENSWATH/OpenSwathWorkflow.cppsrc/openms/include/OpenMS/ANALYSIS/OPENSWATH/DIAScoring.hsrc/pyOpenMS/tests/unittests/test_psm_dataframe.pysrc/openms/source/ANALYSIS/OPENSWATH/DIAScoring.cppsrc/openms/source/ANALYSIS/OPENSWATH/MRMAssay.cppsrc/pyOpenMS/addons/PeptideIdentificationList.pyxsrc/openms/source/ANALYSIS/OPENSWATH/MRMFeatureFinderScoring.cppsrc/openms/source/ANALYSIS/OPENSWATH/ChromatogramExtractor.cppsrc/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.hsrc/openms/include/OpenMS/ANALYSIS/TARGETED/TargetedExperiment.h
**/*.h
📄 CodeRabbit inference engine (AGENTS.md)
**/*.h: Do not addusing namespaceorusing std::...in header files; allowed only in.cppfiles
Prefer forward declarations in headers; include only base class headers, non-pointer members, and templates
Document possible exceptions in Doxygen comments using@throwsor@exceptiontags
Use Doxygen/** */block comments with@tags (not backslash\);@briefis 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@ingroupand@defgroupDoxygen tags to organize classes and functions into categories
Use@todotags with assignee name (e.g.,@todo JohnDoe fix this) in Doxygen comments
Every.hfile must include a file preamble with$Maintainer:$marker
Files:
src/openms/include/OpenMS/ANALYSIS/OPENSWATH/DIAScoring.hsrc/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.pysrc/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.pysrc/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.pywraps with pandas
Files:
src/pyOpenMS/tests/unittests/test_psm_dataframe.pysrc/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.pxdfiles; usesrc/pyOpenMS/addons/or_dataframes.pywrappers 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
Avoidcdeftyped variables for autowrap return values insidedefmethods; use Python type checks instead
Regenerate pyOpenMS after addon changes by removing.cpp_extension_generatedand 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.cppsrc/openms/include/OpenMS/ANALYSIS/OPENSWATH/DIAScoring.hsrc/openms/source/ANALYSIS/OPENSWATH/DIAScoring.cppsrc/openms/source/ANALYSIS/OPENSWATH/MRMAssay.cppsrc/openms/source/ANALYSIS/OPENSWATH/MRMFeatureFinderScoring.cppsrc/openms/source/ANALYSIS/OPENSWATH/ChromatogramExtractor.cppsrc/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.cppsrc/openms/include/OpenMS/ANALYSIS/OPENSWATH/DIAScoring.hsrc/openms/source/ANALYSIS/OPENSWATH/DIAScoring.cppsrc/openms/source/ANALYSIS/OPENSWATH/MRMAssay.cppsrc/openms/source/ANALYSIS/OPENSWATH/MRMFeatureFinderScoring.cppsrc/openms/source/ANALYSIS/OPENSWATH/ChromatogramExtractor.cppsrc/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.cppsrc/openms/source/ANALYSIS/OPENSWATH/MRMAssay.cppsrc/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.pysrc/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.pysrc/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.pysrc/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.pysrc/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.cppsrc/openms/source/ANALYSIS/OPENSWATH/ChromatogramExtractor.cppsrc/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.cppsrc/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.cppsrc/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 onoperator[]to create empty vectors on demand eliminates the redundantfind()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
detectingTransitionsfunction—using a const reference and lettingoperator[]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>&. Sincestd::stringis 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 viatg_it->secondeliminates the redundant map access that would occur withfind()followed byoperator[]. 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 withstd::hash<OpenMS::String>specialization—it is properly defined.The
std::unordered_map<OpenMS::String, double>usage is correct. OpenMS::String inherits fromstd::stringand astd::hash<OpenMS::String>specialization is defined in the std namespace (lines 493–499 of String.h), which delegates tostd::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 fromstd::maptostd::unordered_mapis an internal optimization with no API contract implications.The maps are used exclusively for fast lookups via
find()andoperator[], with no code iterating over them or depending on ordering. Usingunordered_mapimproves 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_mapwith appropriatereserve()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_mapis 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_mapwithreserve()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 viachrom_it->secondat line 1133, eliminating the redundant lookup that would occur withfind()followed byoperator[]. 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_mapfor O(1) lookups is appropriate here since the map is only used for key-based lookups, not ordered iteration. Thereserve()call is a good practice to minimize rehashing during insertions.
274-284: LGTM! Appropriate use of emplace.Using
emplace()is correct forunordered_mapand avoids creating temporarystd::pairobjects, making it slightly more efficient thaninsert().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 toget_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'sindex=42 → 43expectation is correct and matches SpectrumLookup implementation.The behavior is intentional, not flaky. SpectrumLookup::extractScanNumber explicitly returns
value + 1for 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 viasl.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.
|
there is also some pyopenms stuff that seems unrelated. wrong branch? is this on dev already? |
|
yeah sorry started of the wrong branch. will fix later just ignore |
|
By the way, I often wonder in OpenSwath code, if certain mappings could be avoided or combined or replaced with simple vectors. |
|
I can run a KISS agent ;) |
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]>
Co-Authored-By: Claude Opus 4.5 <[email protected]>
347c783 to
69d2395
Compare
jcharkow
left a comment
There was a problem hiding this comment.
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.
|
ah right this is AI comments. forgot to clean them up. |
Co-Authored-By: Claude Opus 4.5 <[email protected]>
|
@jcharkow actually this requires none of the new hash functions |
|
Just tested with some local data and everything seems to be working as expected except for the I don't notice any speed improvements but the library I used for testing is quite small. |
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]>
* 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]>
Summary
std::mapcontainers tostd::unordered_mapfor O(1) average-case performance in hot pathsfind()+operator[]) by using single iterator lookupsChanges
MRMFeatureFinderScoring.cppchromatogram_map→unordered_map+ fixed double-lookupTargetedExperiment.hunordered_mapOpenSwathWorkflow.cppPeptideRTMap→unordered_map+ fixed double-lookupChromatogramExtractor.cpppep2tr,tr2pep→unordered_mapDIAScoring.cpp/.hintensitiesmap →unordered_mapMRMAssay.cppDesign Decisions
TransitionsMapin MRMAssay,transition_group_map) are intentionally kept asstd::mapto preserve deterministic iteration orderfind(),operator[], orat())Test plan
🤖 Generated with Claude Code
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.