Skip to content

Commit

Permalink
..
Browse files Browse the repository at this point in the history
  • Loading branch information
dweindl committed Jun 29, 2024
1 parent 4b6cfae commit face12f
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions petab/v2/petab1to2.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from itertools import chain
from pathlib import Path

from pandas.io.common import get_handle, is_url

import petab.C
from petab.yaml import get_path_prefix

Expand Down Expand Up @@ -56,38 +58,53 @@ def petab1to2(yaml_config: Path | str, output_dir: Path | str = None):
# Write new YAML file
output_dir = Path(output_dir)
output_dir.mkdir(parents=True, exist_ok=True)
output_file = output_dir / Path(yaml_file).name
write_yaml(new_yaml_config, output_file)
new_yaml_file = output_dir / Path(yaml_file).name
write_yaml(new_yaml_config, new_yaml_file)

# Update tables
# condition tables, observable tables, SBML files, parameter table:
# no changes - just copy
file = yaml_config[petab.C.PARAMETER_FILE]
shutil.copy(get_src_path(file), get_dest_path(file))
_copy_file(get_src_path(file), get_dest_path(file))

for problem_config in yaml_config[petab.C.PROBLEMS]:
for file in chain(
problem_config[petab.C.CONDITION_FILES],
problem_config[petab.C.OBSERVABLE_FILES],
problem_config[petab.C.SBML_FILES],
):
shutil.copy(get_src_path(file), get_dest_path(file))
_copy_file(get_src_path(file), get_dest_path(file))

# TODO: Measurements: preequilibration to experiments/timecourses
# TODO: ...
...

# validate updated Problem
# TODO validate_problem(new_yaml_file)


def _update_yaml(yaml_config: dict) -> dict:
"""Update PEtab 1.0 YAML to PEtab 2.0 format."""
yaml_config = yaml_config.copy()

# Update format_version
yaml_config["format_version"] = 2
yaml_config["format_version"] = "2.0.0"

# Add extensions
yaml_config["extensions"] = []

# TODO models needs ID and format

return yaml_config


def _copy_file(src: Path | str, dest: Path | str):
"""Copy file."""
src = str(src)
dest = str(dest)

if is_url(src):
with get_handle(src, mode="r") as src_handle:
with open(dest, "w") as dest_handle:
dest_handle.write(src_handle.handle.read())
return

shutil.copy(str(src), str(dest))

0 comments on commit face12f

Please sign in to comment.