1010from pandas .io .common import get_handle , is_url
1111
1212from .. import v1 , v2
13- from ..v1 import Problem as ProblemV1
14- from ..v1 .yaml import get_path_prefix , load_yaml , validate , write_yaml
13+ from ..v1 .yaml import get_path_prefix , load_yaml , validate
1514from ..versions import get_major_version
1615from .models import MODEL_TYPE_SBML
16+ from .problem import ProblemConfig
1717
1818__all__ = ["petab1to2" ]
1919
@@ -59,7 +59,7 @@ def petab1to2(yaml_config: Path | str, output_dir: Path | str = None):
5959 validate (yaml_config , path_prefix = path_prefix )
6060 if get_major_version (yaml_config ) != 1 :
6161 raise ValueError ("PEtab problem is not version 1." )
62- petab_problem = ProblemV1 .from_yaml (yaml_file or yaml_config )
62+ petab_problem = v1 . Problem .from_yaml (yaml_file or yaml_config )
6363 # get rid of conditionName column if present (unsupported in v2)
6464 petab_problem .condition_df = petab_problem .condition_df .drop (
6565 columns = [v1 .C .CONDITION_NAME ], errors = "ignore"
@@ -71,26 +71,24 @@ def petab1to2(yaml_config: Path | str, output_dir: Path | str = None):
7171
7272 # Update YAML file
7373 new_yaml_config = _update_yaml (yaml_config )
74+ new_yaml_config = ProblemConfig (** new_yaml_config )
7475
7576 # Update tables
7677 # condition tables, observable tables, SBML files, parameter table:
7778 # no changes - just copy
7879 file = yaml_config [v2 .C .PARAMETER_FILE ]
7980 _copy_file (get_src_path (file ), Path (get_dest_path (file )))
8081
81- for problem_config in yaml_config [ v2 . C . PROBLEMS ] :
82+ for problem_config in new_yaml_config . problems :
8283 for file in chain (
83- problem_config .get (v2 .C .OBSERVABLE_FILES , []),
84- (
85- model [v2 .C .MODEL_LOCATION ]
86- for model in problem_config .get (v2 .C .MODEL_FILES , {}).values ()
87- ),
88- problem_config .get (v2 .C .VISUALIZATION_FILES , []),
84+ problem_config .observable_files ,
85+ (model .location for model in problem_config .model_files .values ()),
86+ problem_config .visualization_files ,
8987 ):
9088 _copy_file (get_src_path (file ), Path (get_dest_path (file )))
9189
9290 # Update condition table
93- for condition_file in problem_config .get ( v2 . C . CONDITION_FILES , []) :
91+ for condition_file in problem_config .condition_files :
9492 condition_df = v1 .get_condition_df (get_src_path (condition_file ))
9593 condition_df = v1v2_condition_df (condition_df , petab_problem .model )
9694 v2 .write_condition_df (condition_df , get_dest_path (condition_file ))
@@ -159,12 +157,12 @@ def create_experiment_id(sim_cond_id: str, preeq_cond_id: str) -> str:
159157 raise ValueError (
160158 f"Experiment table file { exp_table_path } already exists."
161159 )
162- problem_config [ v2 . C . EXPERIMENT_FILES ] = [ exp_table_path . name ]
160+ problem_config . experiment_files . append ( "experiments.tsv" )
163161 v2 .write_experiment_df (
164162 v2 .get_experiment_df (pd .DataFrame (experiments )), exp_table_path
165163 )
166164
167- for measurement_file in problem_config .get ( v2 . C . MEASUREMENT_FILES , []) :
165+ for measurement_file in problem_config .measurement_files :
168166 measurement_df = v1 .get_measurement_df (
169167 get_src_path (measurement_file )
170168 )
@@ -221,7 +219,7 @@ def create_experiment_id(sim_cond_id: str, preeq_cond_id: str) -> str:
221219
222220 # Write new YAML file
223221 new_yaml_file = output_dir / Path (yaml_file ).name
224- write_yaml ( new_yaml_config , new_yaml_file )
222+ new_yaml_config . to_yaml ( new_yaml_file )
225223
226224 # validate updated Problem
227225 validation_issues = v2 .lint_problem (new_yaml_file )
0 commit comments