Repository navigation
pyopenms: add string accessors for activationmethods - #7876
Conversation
WalkthroughThe changes extend the Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant Precursor
participant DataStore
User ->> Precursor: getActivationMethodsAsString()
Precursor ->> DataStore: Retrieve full method names
DataStore -->> Precursor: Return full names
Precursor -->> User: Return full names StringList
User ->> Precursor: getActivationMethodsAsShortString()
Precursor ->> DataStore: Retrieve short method names
DataStore -->> Precursor: Return short names
Precursor -->> User: Return short names StringList
User ->> Precursor: getAllNamesOfActivationMethods()
Precursor ->> DataStore: Iterate over full names array
DataStore -->> Precursor: Return full names
Precursor -->> User: Return full names list
User ->> Precursor: getAllShortNamesOfActivationMethods()
Precursor ->> DataStore: Iterate over short names array
DataStore -->> Precursor: Return short names
Precursor -->> User: Return short names list
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms (6)
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (5)
src/pyOpenMS/tests/unittests/test000.py (2)
4479-4487: Add more robust assertions for static activation method accessors.The current test checks only one activation method (CID) for each accessor. While this is valid, it would be more comprehensive to test multiple methods or verify all methods are correctly represented.
# Test static methods for all activation methods all_names = pyopenms.Precursor.getNamesOfAllActivationMethods() assert len(all_names) == pyopenms.Precursor.ActivationMethod.SIZE_OF_ACTIVATIONMETHOD assert all_names[pyopenms.Precursor.ActivationMethod.CID].decode() == "Collision-induced dissociation" + assert all_names[pyopenms.Precursor.ActivationMethod.HCD].decode() == "beam-type collision-induced dissociation" all_short_names = pyopenms.Precursor.getShortNamesOfAllActivationMethods() assert len(all_short_names) == pyopenms.Precursor.ActivationMethod.SIZE_OF_ACTIVATIONMETHOD assert all_short_names[pyopenms.Precursor.ActivationMethod.CID].decode() == "CID" + assert all_short_names[pyopenms.Precursor.ActivationMethod.HCD].decode() == "HCD"
4462-4467: Consider using an enumeration approach for better test maintenance.Since you're testing both the presence of activation methods and their string representations, consider using a dictionary mapping that connects the enum value, short name, and long name. This makes the test more maintainable if new activation methods are added.
- methods = set([pyopenms.Precursor.ActivationMethod.CID, - pyopenms.Precursor.ActivationMethod.HCD]) - methods_short = ["CID", "HCD"] - methods_long = ["Collision-induced dissociation", "beam-type collision-induced dissociation"] + # Define a mapping of activation methods to their expected string representations + activation_method_mapping = { + pyopenms.Precursor.ActivationMethod.CID: { + "short": "CID", + "long": "Collision-induced dissociation" + }, + pyopenms.Precursor.ActivationMethod.HCD: { + "short": "HCD", + "long": "beam-type collision-induced dissociation" + } + } + methods = set(activation_method_mapping.keys()) + methods_short = [info["short"] for info in activation_method_mapping.values()] + methods_long = [info["long"] for info in activation_method_mapping.values()]src/openms/source/METADATA/Precursor.cpp (1)
151-152: Remove unnecessary blank lines.There are two consecutive blank lines here that aren't needed.
return am; } - - void Precursor::setActivationMethods(const set<Precursor::ActivationMethod> & activation_methods)src/tests/class_tests/openms/source/Precursor_test.cpp (2)
108-109: Consider adding additional validation for method content.While the size check is good, the test could be more robust by also verifying the contents of at least one element in the returned StringList. This would ensure the correctness of the values being returned, not just the count.
StringList result = Precursor::getNamesOfAllActivationMethods(); TEST_EQUAL(result.size(), Precursor::SIZE_OF_ACTIVATIONMETHOD); + // Verify the first element matches the expected value + TEST_EQUAL(result[0], "Collision-induced dissociation");
113-114: Consider adding additional validation for method content.As with the previous test, consider verifying the content of at least one element in the returned StringList to ensure the values are correct.
StringList result = Precursor::getShortNamesOfAllActivationMethods(); TEST_EQUAL(result.size(), Precursor::SIZE_OF_ACTIVATIONMETHOD); + // Verify the first element matches the expected value + TEST_EQUAL(result[0], "CID");
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
src/openms/include/OpenMS/METADATA/Precursor.h(1 hunks)src/openms/source/METADATA/Precursor.cpp(1 hunks)src/pyOpenMS/pxds/Precursor.pxd(1 hunks)src/pyOpenMS/tests/unittests/test000.py(1 hunks)src/tests/class_tests/openms/source/Precursor_test.cpp(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (6)
- GitHub Check: build-and-test (ubuntu-22.04, clang++, 15)
- GitHub Check: build-and-test (ubuntu-22.04, g++, 11)
- GitHub Check: build-and-test (macos-14, xcode, 15.0.1)
- GitHub Check: build-and-test (macos-13, xcode, 14.2)
- GitHub Check: build-and-test (windows-2022, cl.exe, default)
- GitHub Check: cppcheck-test
🔇 Additional comments (12)
src/openms/include/OpenMS/METADATA/Precursor.h (1)
96-101: Well-structured method additions with clear namingThese new accessor methods are well-designed with clear intentions:
getActivationMethodsAsShortString()complements the existing string method with a shortened representation- The static methods provide comprehensive access to all available activation method names
- Method signatures follow the established class conventions
The methods have appropriate modifiers (const, static) and return types that are consistent with the existing pattern.
src/pyOpenMS/pxds/Precursor.pxd (2)
26-27: Good implementation of Python string accessorsThe Python bindings for these methods are well-implemented:
- Return type
libcpp_vector[String]is appropriate for exposing string collections to Python- Exception handling with
except + nogilis correctly applied- Documentation comments clearly describe the purpose of each method
30-33: Well-implemented static methods for PythonThe static accessor methods are correctly implemented:
@staticmethoddecorator is properly applied- Method signatures match their C++ counterparts
- Documentation comments clearly describe what these methods return
- Empty line after the static methods maintains code organization
These will be useful for Python users who need to enumerate all possible activation methods.
src/pyOpenMS/tests/unittests/test000.py (2)
4464-4465: LGTM! String constant definitions for testing.The string constants for short and long activation method names are correctly defined and will be used in assertions later.
4473-4478: LGTM! Thorough tests for activation method string accessors.The test properly verifies that both short and long string representations of activation methods are correctly returned. The use of
sorted()in the assertions is a good practice since it ensures the test is resilient to order changes.src/openms/source/METADATA/Precursor.cpp (3)
118-127: LGTM! Implementation of getActivationMethodsAsShortString is clean and consistent.The implementation mirrors the existing getActivationMethodsAsString() method but returns short names instead of full names. Good use of reserve() to avoid unnecessary reallocations.
129-138: LGTM! Well-implemented static method for retrieving all activation method names.This static method properly iterates through all available activation methods and returns their full names in a StringList. The use of reserve() is a good performance optimization.
140-149: LGTM! Well-implemented static method for retrieving all short activation method names.This static method follows the same pattern as getNamesOfAllActivationMethods() but returns the short names. Consistent implementation and good memory management with reserve().
src/tests/class_tests/openms/source/Precursor_test.cpp (4)
87-96: LGTM! Comprehensive test for getActivationMethodsAsString().This test properly verifies that the method returns a StringList with the expected content. Good validation of both the size and the actual string value.
97-106: LGTM! Comprehensive test for getActivationMethodsAsShortString().The test mirrors the previous one for getActivationMethodsAsString() but verifies the short form instead. Good consistency in testing approach.
107-111: LGTM! Appropriate test for getNamesOfAllActivationMethods().The test confirms that the static method returns a StringList with the correct number of elements.
112-116: LGTM! Appropriate test for getShortNamesOfAllActivationMethods().Similar to the previous test, this verifies that the static method returns a StringList with the correct number of elements.
| Precursor(Precursor &) except + nogil | ||
|
|
||
| libcpp_set[ActivationMethod] getActivationMethods() except + nogil # wrap-doc:Returns the activation methods | ||
| libcpp_vector[String] getActivationMethodsAsString() except + nogil # wrap-doc:Returns the activation methods as strings |
There was a problem hiding this comment.
Still confusing IMHO. What is the difference between this and "All"?
There was a problem hiding this comment.
each precursor can have multiple activation methods and that method already existed on the c++ side.
There was a problem hiding this comment.
but I agree that it is a bit confusing. do you have a quick suggestion? I can implement
There was a problem hiding this comment.
that was before "getAllActivationMethods" was added. I think now it needs additional clarification.
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (2)
src/pyOpenMS/pxds/Precursor.pxd (1)
25-34: Consider adding a usage example to further clarify the differences between methods.While the documentation for each method is good individually, a short usage example in the class-level documentation (around line 21) might help users understand the relationship between these five related methods more easily:
getActivationMethods()- enum valuesgetActivationMethodsAsString()/getActivationMethodsAsShortString()- instance-specific stringsgetAllNamesOfActivationMethods()/getAllShortNamesOfActivationMethods()- all possible stringsExample for class documentation:
# ... # - selected ion (m/z, intensity, charge, possible charge states) # - ion mobility drift time +# +# Example: +# ``` +# precursor = Precursor() +# precursor.setActivationMethods([Precursor.CID, Precursor.HCD]) +# +# # Get enum values for this instance +# methods = precursor.getActivationMethods() # Returns {CID, HCD} +# +# # Get string representations for this instance +# method_names = precursor.getActivationMethodsAsString() # ["Collision-induced dissociation", "beam-type collision-induced dissociation"] +# method_abbreviations = precursor.getActivationMethodsAsShortString() # ["CID", "HCD"] +# +# # Get ALL possible activation methods (static methods) +# all_names = Precursor.getAllNamesOfActivationMethods() # Returns all names including those not set on this instance +# all_abbreviations = Precursor.getAllShortNamesOfActivationMethods() # Returns all abbreviations +# ```src/openms/source/METADATA/Precursor.cpp (1)
150-152: Remove unnecessary blank lines.There are two consecutive empty lines here that aren't necessary according to the coding style in the rest of the file, which typically uses only one blank line as a separator.
return am; } - - void Precursor::setActivationMethods(const set<Precursor::ActivationMethod> & activation_methods)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
src/openms/include/OpenMS/METADATA/Precursor.h(2 hunks)src/openms/source/METADATA/Precursor.cpp(1 hunks)src/pyOpenMS/pxds/Precursor.pxd(1 hunks)src/pyOpenMS/tests/unittests/test000.py(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- src/openms/include/OpenMS/METADATA/Precursor.h
⏰ Context from checks skipped due to timeout of 90000ms (6)
- GitHub Check: build-and-test (ubuntu-22.04, clang++, 15)
- GitHub Check: build-and-test (ubuntu-22.04, g++, 11)
- GitHub Check: build-and-test (macos-14, xcode, 15.0.1)
- GitHub Check: build-and-test (macos-13, xcode, 14.2)
- GitHub Check: build-and-test (windows-2022, cl.exe, default)
- GitHub Check: cppcheck-test
🔇 Additional comments (9)
src/pyOpenMS/pxds/Precursor.pxd (2)
26-27: Well-implemented instance methods with clear documentation.These new methods provide a valuable way to get string representations of activation methods, making them more human-readable. The documentation clearly specifies that these return the methods set on this specific instance.
30-34: Good addition of static methods for accessing all possible activation methods.These static methods are well-implemented and solve the confusion mentioned in previous review comments. The documentation now explicitly distinguishes between instance-specific methods and methods that return all possible values.
The naming convention and documentation directly address the confusion mentioned by @jpfeuffer in previous comments by making it clear these return ALL possible activation methods, not just the ones set on a specific instance.
src/pyOpenMS/tests/unittests/test000.py (3)
4464-4466: Good addition of test constants for expected values.These constants provide expected values for both short and long forms of activation method names, making the subsequent assertions more maintainable and readable.
4473-4477: Well-structured test for string representation of activation methods.This test verifies that the newly added methods
getActivationMethodsAsShortString()andgetActivationMethodsAsString()correctly return the expected string representations of activation methods. The test handles the byte strings returned from C++ appropriately by decoding them before comparison.
4479-4487: Comprehensive testing of static methods for activation method names.This section thoroughly tests the new static methods
getAllNamesOfActivationMethods()andgetAllShortNamesOfActivationMethods(). It verifies both the length of the returned lists and the correctness of specific entries. The implementation correctly checks that the number of elements matchesSIZE_OF_ACTIVATIONMETHODand validates the actual string content with specific assertions.src/openms/source/METADATA/Precursor.cpp (4)
118-127: Well-implemented accessor for activation method short names.This method nicely parallels the existing
getActivationMethodsAsString()method but returns short form identifiers instead of full names. The implementation correctly reserves memory for optimal performance and maintains consistency with the class's code style.
129-138:Details
❓ Verification inconclusive
Static method implementation looks good.
This static utility method provides access to all possible activation method names, which is useful for clients that need to enumerate all available options. The implementation uses appropriate memory reservation for optimization.
🏁 Script executed:
#!/bin/bash # Verify that this method is declared as static in the header file rg "static\s+StringList\s+getAllNamesOfActivationMethods" include/OpenMS/METADATA/Precursor.hLength of output: 171
Action Required: Please verify the correct header file path for the static declaration
- The implementation in
src/openms/source/METADATA/Precursor.cpplooks good, with optimal memory reservation for returning all activation method names.- The shell script checked for the static declaration in
include/OpenMS/METADATA/Precursor.h, but it failed to locate the file. This suggests that either the header is in a different location or there's a path misconfiguration.- Please manually verify that
getAllNamesOfActivationMethods()is declared as static in the proper header file. If the header file exists elsewhere (e.g., undersrc/openms/include/METADATA/Precursor.h), update the verification command accordingly.
16-58:Details
❓ Verification inconclusive
Verify activation method arrays have consistent lengths.
The
NamesOfActivationMethodandNamesOfActivationMethodShortarrays both need to have the same number of elements (equal toSIZE_OF_ACTIVATIONMETHOD). This ensures that the index-based lookups in the new methods will work correctly. Both arrays currently have 19 elements, which seems consistent.
🏁 Script executed:
#!/bin/bash # Check the definition of SIZE_OF_ACTIVATIONMETHOD and verify it matches the array sizes rg "SIZE_OF_ACTIVATIONMETHOD" include/OpenMS/METADATA/Precursor.hLength of output: 141
Action Required: Verify
SIZE_OF_ACTIVATIONMETHODin the HeaderBoth arrays in
src/openms/source/METADATA/Precursor.cppcontain 19 elements, ensuring consistency with each other. However, since the initial search forSIZE_OF_ACTIVATIONMETHODininclude/OpenMS/METADATA/Precursor.hdid not yield any results, please manually verify that the header file (or the appropriate location whereSIZE_OF_ACTIVATIONMETHODis defined) sets this constant to 19. This manual check is necessary to ensure that the index-based lookups using these arrays remain valid.
- Confirm the existence and location of the
Precursor.hfile (or equivalent) in the repository.- Ensure that
SIZE_OF_ACTIVATIONMETHODis defined and matches the expected value of 19.
140-149:Details
✅ Verification successful
Static method properly returns all short names of activation methods.
This implementation correctly provides access to all short form identifiers. The code maintains consistency with the previous static method and follows good memory optimization practices.
🏁 Script executed:
#!/bin/bash # Verify that this method is declared as static in the header file rg "static\s+StringList\s+getAllShortNamesOfActivationMethods" include/OpenMS/METADATA/Precursor.hLength of output: 176
Below is a new shell script to search the repository for any header files named “Precursor.h”. This will help us locate where the declaration for
getAllShortNamesOfActivationMethodsmight reside:Additionally, you can run the following command to search across all header files for the method declaration:
Review Update:
The implementation insrc/openms/source/METADATA/Precursor.cppcorrectly returns all short names of activation methods with good memory optimization. However, the initial verification for a static declaration ininclude/OpenMS/METADATA/Precursor.hdid not yield any results—likely because either the header file is located elsewhere or the file path is outdated. Please verify the correct location ofPrecursor.hand ensure the declaration (including thestaticspecifier) is present.
🏁 Script executed:
#!/bin/bash # Find all files named Precursor.h in the repository find . -type f -name "Precursor.h"Length of output: 205
🏁 Script executed:
#!/bin/bash rg "static\s+StringList\s+getAllShortNamesOfActivationMethods" -g "*.h"Length of output: 303
Static method declaration and implementation verified
- The header file was found at
src/openms/include/OpenMS/METADATA/Precursor.h, and the declaration
static StringList getAllShortNamesOfActivationMethods();
is correctly present.- The implementation in
src/openms/source/METADATA/Precursor.cppis consistent with the header and follows good memory optimization practices.
|
Not really. getActivationMethodEnumPossibleValues? Extend docs? You know that docs do not need to fit into one line right? Ideally the enums should be its own namespace. We have the thing with string values for enums so often that it might be worth it to write a wrapper around such things: |
|
ok I updated the doc. |
Description
Provides stable string identifier for pyopenms. requested by @ypriverol
Checklist
How can I get additional information on failed tests during CI
Click to expand
If your PR is failing you can check outIf you click in the column that lists the failed tests you will get detailed error messages.
Advanced commands (admins / reviewer only)
Click to expand
/reformat(experimental) applies the clang-format style changes as additional commit. Note: your branch must have a different name (e.g., yourrepo:feature/XYZ) than the receiving branch (e.g., OpenMS:develop). Otherwise, reformat fails to push.rebuild jenkinswill retrigger Jenkins-based CI buildsSummary by CodeRabbit
New Features
Tests