Skip to content

Sort by measurement group feature#80

Merged
haeussma merged 16 commits intomainfrom
sort-by-measurement-group-feature
Aug 6, 2025
Merged

Sort by measurement group feature#80
haeussma merged 16 commits intomainfrom
sort-by-measurement-group-feature

Conversation

@haeussma
Copy link
Member

@haeussma haeussma commented Aug 5, 2025

This PR introduces a convenience method pe.group_measurements() that assigns a group_id to all Measurement entries within an EnzymeMLDocument. The method compares all MeasurementData associated with each species and groups those sharing identical initial conditions under the same group_id.

Additionally, this PR refactors internal imports by replacing top-level import pyenzyme statements with explicit submodule imports. This change mitigates circular import issues, particularly when pyenzyme is used as a dependency in third-party packages.


This change is Reviewable

haeussma added 11 commits August 5, 2025 16:36
…me as pe`. This avoids circular import issues when pyenzyme is used in 3rd party libraries
…ts function to organize measurement data by conditions. Update get_all_parameters to use Parameter directly.

Added `group_measurements` method. Allowing to assign measurement.group_id based on uniqueness of initial conditions of MeasurementData.
Introduced a new test suite in `test_group_measurements.py` to validate the functionality of `_get_measurement_conditions` and `group_measurements` functions. The tests cover various scenarios including prepared and initial values, precedence rules, and grouping behavior based on identical and differing conditions. This enhances the test coverage for measurement data handling in the project.
…d tolerance-based grouping

Updated the `group_measurements` function to allow selection of concentration attributes ('initial' or 'prepared') and introduced a tolerance parameter for numerical comparisons when grouping measurements. Added helper functions for matching conditions within tolerance and checking value matches.
@haeussma
Copy link
Member Author

haeussma commented Aug 6, 2025

Enhances group_measurements by the attribute attribute: Literal['initial', 'prepared'] = 'initial' and tolerance: float = 0.0, allowing to choose which condition attribute should be used to group measurements.

From my side, this PR is completed.

@haeussma haeussma requested a review from JR-1991 August 6, 2025 08:19
@JR-1991 JR-1991 requested a review from Copilot August 6, 2025 08:21
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces a measurement grouping feature that assigns group IDs to measurements with identical initial conditions, facilitating analysis of related experimental data. Additionally, it refactors internal imports to use explicit submodule imports instead of top-level pyenzyme imports to prevent circular import issues.

  • Adds a new group_measurements() function with tolerance-based matching capabilities
  • Refactors imports throughout the codebase to use specific submodule imports
  • Updates version number from 2.0.0 to 2.0.1

Reviewed Changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
tests/unit/test_group_measurements.py Comprehensive test suite for the new grouping functionality
pyenzyme/tools.py Implementation of group_measurements and supporting functions
pyenzyme/init.py Exports the new group_measurements function
pyproject.toml Version bump to 2.0.1
pyenzyme/suite.py Import refactoring for EnzymeMLDocument and EnzymeMLHandler
pyenzyme/sbml/versions/v2.py Import refactoring for DataTypes and Measurement
pyenzyme/sbml/versions/v1.py Import refactoring for DataTypes and Measurement
pyenzyme/sbml/validation.py Import refactoring for various EnzymeML types
pyenzyme/sbml/serializer.py Import order adjustment
pyenzyme/petab/io.py Import order adjustment

*tools.extract(obj=doc, target=pe.MeasurementData),
*tools.extract(obj=doc, target=MeasurementData),
]
print(f"Found {len(mandatory_unit_objects)} mandatory unit objects.")
Copy link

Copilot AI Aug 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debug print statement should be removed before production. Use logger.debug() instead if debug information is needed.

Suggested change
print(f"Found {len(mandatory_unit_objects)} mandatory unit objects.")
logger.debug(f"Found {len(mandatory_unit_objects)} mandatory unit objects.")

Copilot uses AI. Check for mistakes.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could use the global logger to keep the logging consistent, but I am also fine with using print or rich (for some color and formatting)

attribute: Literal["initial", "prepared"] = "initial",
) -> dict:
"""
Extract measurement conditions as a dictionary, inclding pH and temperature.
Copy link

Copilot AI Aug 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo in docstring: 'inclding' should be 'including'.

Suggested change
Extract measurement conditions as a dictionary, inclding pH and temperature.
Extract measurement conditions as a dictionary, including pH and temperature.

Copilot uses AI. Check for mistakes.
Copy link
Member

@JR-1991 JR-1991 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some minor comments, overall LGTM

list[Parameter]: A list of all parameters in the EnzymeMLDocument.
"""
return find_unique(enzmldoc, target=pe.Parameter)
return find_unique(enzmldoc, target=Parameter)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use the parameter array directly. Since the last version, we’ve consolidated all parameters into enzmldoc.parameters.


# Add species conditions using the specified attribute
for species_data in measurement.species_data:
if attribute == "initial":
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use getattr to retrieve any of these without needing to branch, but this is fine.

…plifying measurement condition extraction. Updated import statements and fixed a typo in the docstring for _get_measurement_conditions.
…function and directly access parameters from the document. Updated import statements accordingly.
…tion, directly accessing parameters from the document instead. Updated import statements accordingly.
@haeussma haeussma merged commit 9431c6e into main Aug 6, 2025
6 checks passed
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