From 7679b19b6bb7f8fcb7ffa10e4e1e59d37870f31c Mon Sep 17 00:00:00 2001 From: Daniel Weindl Date: Fri, 20 Dec 2024 14:52:37 +0100 Subject: [PATCH] Create output directories in write_* --- petab/v1/conditions.py | 4 +++- petab/v1/core.py | 4 +++- petab/v1/mapping.py | 4 +++- petab/v1/measurements.py | 4 +++- petab/v1/observables.py | 4 +++- petab/v1/parameters.py | 4 +++- petab/v1/yaml.py | 3 ++- petab/v2/experiments.py | 4 +++- 8 files changed, 23 insertions(+), 8 deletions(-) diff --git a/petab/v1/conditions.py b/petab/v1/conditions.py index 4e691d62..5a856c84 100644 --- a/petab/v1/conditions.py +++ b/petab/v1/conditions.py @@ -60,9 +60,11 @@ def write_condition_df(df: pd.DataFrame, filename: str | Path) -> None: Arguments: df: PEtab condition table - filename: Destination file name + filename: Destination file name. Parent directories are created if + necessary. """ df = get_condition_df(df) + Path(filename).parent.mkdir(parents=True, exist_ok=True) df.to_csv(filename, sep="\t", index=True) diff --git a/petab/v1/core.py b/petab/v1/core.py index 10274b8c..3b4a4082 100644 --- a/petab/v1/core.py +++ b/petab/v1/core.py @@ -60,8 +60,10 @@ def write_simulation_df(df: pd.DataFrame, filename: str | Path) -> None: Arguments: df: PEtab simulation table - filename: Destination file name + filename: Destination file name. The parent directory will be created + if necessary. """ + Path(filename).parent.mkdir(parents=True, exist_ok=True) df.to_csv(filename, sep="\t", index=False) diff --git a/petab/v1/mapping.py b/petab/v1/mapping.py index bae9d5fb..7d1b25aa 100644 --- a/petab/v1/mapping.py +++ b/petab/v1/mapping.py @@ -60,9 +60,11 @@ def write_mapping_df(df: pd.DataFrame, filename: str | Path) -> None: Arguments: df: PEtab mapping table - filename: Destination file name + filename: Destination file name. Parent directories are created if + necessary. """ df = get_mapping_df(df) + Path(filename).parent.mkdir(parents=True, exist_ok=True) df.to_csv(filename, sep="\t", index=True) diff --git a/petab/v1/measurements.py b/petab/v1/measurements.py index 757ce9ce..9c730578 100644 --- a/petab/v1/measurements.py +++ b/petab/v1/measurements.py @@ -58,9 +58,11 @@ def write_measurement_df(df: pd.DataFrame, filename: str | Path) -> None: Arguments: df: PEtab measurement table - filename: Destination file name + filename: Destination file name. Parent directories are created if + necessary. """ df = get_measurement_df(df) + Path(filename).parent.mkdir(parents=True, exist_ok=True) df.to_csv(filename, sep="\t", index=False) diff --git a/petab/v1/observables.py b/petab/v1/observables.py index 1485302d..bcd0f05a 100644 --- a/petab/v1/observables.py +++ b/petab/v1/observables.py @@ -67,9 +67,11 @@ def write_observable_df(df: pd.DataFrame, filename: str | Path) -> None: Arguments: df: PEtab observable table - filename: Destination file name + filename: Destination file name. Parent directories are created if + necessary. """ df = get_observable_df(df) + Path(filename).parent.mkdir(parents=True, exist_ok=True) df.to_csv(filename, sep="\t", index=True) diff --git a/petab/v1/parameters.py b/petab/v1/parameters.py index 20457dcb..1696cc0c 100644 --- a/petab/v1/parameters.py +++ b/petab/v1/parameters.py @@ -112,9 +112,11 @@ def write_parameter_df(df: pd.DataFrame, filename: str | Path) -> None: Arguments: df: PEtab parameter table - filename: Destination file name + filename: Destination file name. Parent directories are created if + necessary. """ df = get_parameter_df(df) + Path(filename).parent.mkdir(parents=True, exist_ok=True) df.to_csv(filename, sep="\t", index=True) diff --git a/petab/v1/yaml.py b/petab/v1/yaml.py index 51159453..afb83df3 100644 --- a/petab/v1/yaml.py +++ b/petab/v1/yaml.py @@ -238,8 +238,9 @@ def write_yaml(yaml_config: dict[str, Any], filename: str | Path) -> None: Arguments: yaml_config: Data to write - filename: File to create + filename: File to create. Parent directories are created if necessary. """ + Path(filename).parent.mkdir(parents=True, exist_ok=True) with open(filename, "w") as outfile: yaml.dump( yaml_config, outfile, default_flow_style=False, sort_keys=False diff --git a/petab/v2/experiments.py b/petab/v2/experiments.py index 7833fa1f..def98bd7 100644 --- a/petab/v2/experiments.py +++ b/petab/v2/experiments.py @@ -34,7 +34,9 @@ def write_experiment_df(df: pd.DataFrame, filename: str | Path) -> None: Arguments: df: PEtab experiments table - filename: Destination file name + filename: Destination file name. Parent directories are created if + necessary. """ df = get_experiment_df(df) + Path(filename).parent.mkdir(parents=True, exist_ok=True) df.to_csv(filename, sep="\t", index=False)