Skip to content

Expose getPeptideResults and getProteinResults in pyOpenMS - #8543

Merged
timosachsenberg merged 3 commits into
developfrom
copilot/add-getpeptideresults-method
Mar 16, 2026
Merged

timosachsenberg merged 3 commits into
developfrom
copilot/add-getpeptideresults-method

Conversation

Copilot AI commented Dec 21, 2025 •

Copy link
Copy Markdown
Contributor

This pull request adds and tests support for automatic conversion of C++ STL container types (such as libcpp_map, libcpp_vector, and libcpp_set) in the pyOpenMS Python bindings, specifically for the PeptideAndProteinQuant class. The main focus is enabling direct access to peptide and protein quantification results as Python dictionaries, with proper object wrapping for both keys and values. Comprehensive unit tests and sample input files are also introduced to ensure correctness and address a previously reported issue.

Container Type Support and PyOpenMS API Improvements:

  • Updated the wrapping documentation (README_WRAPPING_NEW_CLASSES) to describe new autowrap support for automatic conversion of STL containers, allowing methods returning libcpp_map, libcpp_vector, and libcpp_set to be exposed as native Python types (dict, list, set). This also documents support for maps with OpenMS class keys and values, requiring no manual addon code.
  • Modified the PeptideAndProteinQuant.pxd Cython declaration to expose getPeptideResults() and getProteinResults() as returning libcpp_map[AASequence, PeptideData] and libcpp_map[String, ProteinData] respectively, enabling their direct use as Python dictionaries with appropriate key and value types. [1] [2]

Testing and Validation:

  • Added a comprehensive unit test file test_PeptideAndProteinQuant.py that verifies the correct exposure and behavior of getPeptideResults() and getProteinResults(), including checking key types, value contents, and statistics. This ensures that the new container conversion functionality works as expected and resolves GitHub issue 'pyopenms.pyopenms_4.PeptideAndProteinQuant' object has no attribute 'getPeptideResults' #5657.
  • Introduced two new sample input files (ProteinQuantifier_input.featureXML and ProteinQuantifier_input.consensusXML) for use in the unit tests, providing realistic data for peptide and protein quantification scenarios. [1] [2]

@coderabbitai

coderabbitai Bot commented Dec 21, 2025

Copy link
Copy Markdown
Contributor

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Comment @coderabbitai help to get the list of available commands and usage tips.

Copilot AI changed the title [WIP] Add getPeptideResults method to PeptideAndProteinQuant Expose getPeptideResults and getProteinResults in pyOpenMS Dec 21, 2025
@timosachsenberg

Copy link
Copy Markdown
Contributor

@copilot don’t change the c++ api! Why should this be necessary? Perform a deeper research how this works in OpenMS

Copilot AI commented Dec 21, 2025

Copy link
Copy Markdown
Contributor Author

@copilot don’t change the c++ api! Why should this be necessary? Perform a deeper research how this works in OpenMS

You're right! I've reverted the C++ API changes. The solution now follows the existing pattern used in OpenMS (like ConsensusMap.getColumnHeaders):

  • Added typedefs in the pxd file for the complex map types
  • Used #wrap-ignore on the original C++ methods
  • Manually wrapped them in the addon file by directly calling the C++ API

No C++ changes needed. Commit: 7f13831

@timosachsenberg

Copy link
Copy Markdown
Contributor

@copilot Shouldn't using strings a key already work in autowrap 0.24 ?
There should be a way without pyx file

Copilot AI commented Dec 25, 2025

Copy link
Copy Markdown
Contributor Author

@copilot Shouldn't using strings a key already work in autowrap 0.24 ?
There should be a way without pyx file

You're absolutely right! I've updated the implementation to use autowrap 0.24's native support for libcpp_map[String, WrappedClass]:

  • getProteinResults(): Now uses autowrap automatically (no addon needed!)
  • getPeptideResults(): Only this needs a minimal addon since it uses AASequence keys (wrapped class as key not supported)

Much cleaner approach. Commit: 8e83b43

@timosachsenberg
timosachsenberg marked this pull request as ready for review December 30, 2025 18:14
@jpfeuffer

Copy link
Copy Markdown
Contributor

What happened with the autowrap PR for maps of wrapped classes? The only problem was missing hashes or warnings if a custom hash does not exist and I think you fixed most of that.

@timosachsenberg

Copy link
Copy Markdown
Contributor

I think it already works

@jpfeuffer

Copy link
Copy Markdown
Contributor

Yeah and you can merge it but you don't want to do this for every map manually of it comes up again.

@jpfeuffer

Copy link
Copy Markdown
Contributor

Aaah sorry. There is no pyx. Then the OP description is just outdated

@timosachsenberg

Copy link
Copy Markdown
Contributor

Ah ok I updated the the comment on the top.

@timosachsenberg
timosachsenberg force-pushed the copilot/add-getpeptideresults-method branch from 441d571 to 09c3da1 Compare March 9, 2026 13:50
@timosachsenberg
timosachsenberg force-pushed the copilot/add-getpeptideresults-method branch from 09c3da1 to 4b3626b Compare March 10, 2026 17:36
…bind bindings

Add nanobind bindings for PeptideAndProteinQuant methods:
- getPeptideResults(): returns dict mapping AASequence to PeptideData
- getProteinResults(): returns dict mapping protein accession to ProteinData
- No-arg quantifyPeptides() and quantifyProteins() overloads

Includes comprehensive Python tests with FeatureMap and ConsensusMap
input data. Resolves #5657.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@timosachsenberg
timosachsenberg force-pushed the copilot/add-getpeptideresults-method branch from 4b3626b to f752952 Compare March 10, 2026 18:20
timosachsenberg and others added 2 commits March 10, 2026 14:35
nanobind's String type caster converts OpenMS::String to Python str,
not bytes. Fix all dict key lookups and setValue calls accordingly.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@timosachsenberg
timosachsenberg merged commit 819795d into develop Mar 16, 2026
18 of 19 checks passed
@timosachsenberg
timosachsenberg deleted the copilot/add-getpeptideresults-method branch March 16, 2026 14:38
github-actions Bot pushed a commit that referenced this pull request Mar 17, 2026
Add missing changelog entries for changes merged in the past 7 days:

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

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

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

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