Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PEtab v1 to v2 converter #281

Merged
merged 3 commits into from
Jun 29, 2024
Merged

Conversation

dweindl
Copy link
Member

@dweindl dweindl commented Jun 26, 2024

Converter for PEtab v1 problems to PEtab v2 problems.

Allows converting a set of PEtab v1 files to v2 files or creating a petab.v2.Problem from v1 yaml file.

To be extended/adapted as v2 matures.

Closes #272.

@codecov-commenter
Copy link

codecov-commenter commented Jun 26, 2024

Codecov Report

Attention: Patch coverage is 79.51807% with 17 lines in your changes missing coverage. Please review.

Project coverage is 74.01%. Comparing base (9398e77) to head (09a8cc3).

Files Patch % Lines
petab/v2/petab1to2.py 82.08% 7 Missing and 5 partials ⚠️
petab/v2/problem.py 68.75% 4 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #281      +/-   ##
===========================================
+ Coverage    72.92%   74.01%   +1.08%     
===========================================
  Files           72       73       +1     
  Lines         4717     4798      +81     
  Branches      1012     1029      +17     
===========================================
+ Hits          3440     3551     +111     
+ Misses         983      953      -30     
  Partials       294      294              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@dweindl dweindl linked an issue Jun 28, 2024 that may be closed by this pull request
@dweindl dweindl force-pushed the feature_272_petab1to2 branch from 9613b58 to face12f Compare June 29, 2024 10:50
@dweindl dweindl marked this pull request as ready for review June 29, 2024 12:05
@dweindl dweindl requested a review from a team as a code owner June 29, 2024 12:05
Copy link
Member

@dilpath dilpath left a comment

Choose a reason for hiding this comment

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

👍

petab/v2/petab1to2.py Show resolved Hide resolved
if str(yaml_config[petab.C.FORMAT_VERSION]) != "1":
# TODO: Other valid version numbers?
Copy link
Member

Choose a reason for hiding this comment

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

Comment on lines +39 to +54
if output_dir is None:
# TODO requires petab.v2.Problem
raise NotImplementedError("Not implemented yet.")
elif isinstance(yaml_config, dict):
raise ValueError("If output_dir is given, yaml_config must be a file.")

if isinstance(yaml_config, Path | str):
yaml_file = str(yaml_config)
path_prefix = get_path_prefix(yaml_file)
yaml_config = load_yaml(yaml_config)
get_src_path = lambda filename: f"{path_prefix}/{filename}" # noqa: E731
else:
yaml_file = None
path_prefix = None
get_src_path = lambda filename: filename # noqa: E731

get_dest_path = lambda filename: f"{output_dir}/{filename}" # noqa: E731
Copy link
Member

Choose a reason for hiding this comment

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

Keeping file names the same when upgrading is nice, but this is more intuitive to me. Fine as is, if you think this is nicer for most users.

problem1 = petab.v1.Problem.get_problem(yaml_config, validate=True)

experiment_df, measurement_df = convert_measurement_df_1to2(problem1)
problem2 = petab.v2.Problem(
    problem1.condition_df,
    experiment_df,
    measurement_df,
    ...,
)

problem2.validate(raise=True)

if output_dir:
    # alternatively `to_files` if you want to keep file names consistent...
    problem2.to_files_generic(output_dir)

return problem2

Copy link
Member Author

Choose a reason for hiding this comment

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

The thing is, if you had multiple measurement files, condition files, ... then you most likely still want to have them as separate files in your v2 problem. That's not possible anymore once you read them into a v1 Problem, they will all get merged. And I don't want to rename all files afterwards.

Copy link
Member

Choose a reason for hiding this comment

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

Makes sense! I have thought elsewhere that tracking a file ID for e.g. measurements, as an index subset, could improve things a bit. If you're not against this, I can open an issue for it.

Copy link
Member

Choose a reason for hiding this comment

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

Also happy to add that to this PR, today or tomorrow.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm generally open to tracking that information somewhere. To be discussed how that could look in details.

Copy link
Member Author

@dweindl dweindl Jun 29, 2024

Choose a reason for hiding this comment

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

Also happy to add that to this PR, today or tomorrow.

I'd rather have it done separately. (That doesn't preclude changing anything that was introduced here.)

petab/v2/problem.py Show resolved Hide resolved
tests/v2/test_problem.py Outdated Show resolved Hide resolved
tests/v2/test_conversion.py Outdated Show resolved Hide resolved
@dweindl dweindl force-pushed the feature_272_petab1to2 branch from 5b3405a to 9222a64 Compare June 29, 2024 14:32
dweindl and others added 2 commits June 29, 2024 16:39
Co-authored-by: Dilan Pathirana <59329744+dilpath@users.noreply.github.com>
@dweindl dweindl merged commit eeb3dcd into PEtab-dev:develop Jun 29, 2024
7 checks passed
@dweindl dweindl deleted the feature_272_petab1to2 branch June 29, 2024 15:03
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.

Add converter for PEtab v1 problems to v2
3 participants