Skip to content

Commit

Permalink
Deprecated passing individual tables to amici_import_petab
Browse files Browse the repository at this point in the history
and replace deprecated `petab.Problem.from_files` in `amici.petab.cli.import_petab._main`.

Fixes #2460
  • Loading branch information
dweindl committed Jun 25, 2024
1 parent 043d13a commit f9f6c61
Showing 1 changed file with 49 additions and 16 deletions.
65 changes: 49 additions & 16 deletions python/sdist/amici/petab/cli/import_petab.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import petab

from ..petab_import import import_model_sbml
from petab.models.sbml_model import SbmlModel


def _parse_cli_args():
Expand Down Expand Up @@ -59,28 +60,33 @@ def _parse_cli_args():
)

# Call with set of files
parser.add_argument(
group = parser.add_argument_group(

Check warning on line 63 in python/sdist/amici/petab/cli/import_petab.py

View check run for this annotation

Codecov / codecov/patch

python/sdist/amici/petab/cli/import_petab.py#L63

Added line #L63 was not covered by tests
"Providing individual PEtab tables *DEPRECATED*. "
"Pass a PEtab yaml file instead."
)

group.add_argument(

Check warning on line 68 in python/sdist/amici/petab/cli/import_petab.py

View check run for this annotation

Codecov / codecov/patch

python/sdist/amici/petab/cli/import_petab.py#L68

Added line #L68 was not covered by tests
"-s", "--sbml", dest="sbml_file_name", help="SBML model filename"
)
parser.add_argument(
group.add_argument(

Check warning on line 71 in python/sdist/amici/petab/cli/import_petab.py

View check run for this annotation

Codecov / codecov/patch

python/sdist/amici/petab/cli/import_petab.py#L71

Added line #L71 was not covered by tests
"-m",
"--measurements",
dest="measurement_file_name",
help="Measurement table",
)
parser.add_argument(
group.add_argument(

Check warning on line 77 in python/sdist/amici/petab/cli/import_petab.py

View check run for this annotation

Codecov / codecov/patch

python/sdist/amici/petab/cli/import_petab.py#L77

Added line #L77 was not covered by tests
"-c",
"--conditions",
dest="condition_file_name",
help="Conditions table",
)
parser.add_argument(
group.add_argument(

Check warning on line 83 in python/sdist/amici/petab/cli/import_petab.py

View check run for this annotation

Codecov / codecov/patch

python/sdist/amici/petab/cli/import_petab.py#L83

Added line #L83 was not covered by tests
"-p",
"--parameters",
dest="parameter_file_name",
help="Parameter table",
)
parser.add_argument(
group.add_argument(

Check warning on line 89 in python/sdist/amici/petab/cli/import_petab.py

View check run for this annotation

Codecov / codecov/patch

python/sdist/amici/petab/cli/import_petab.py#L89

Added line #L89 was not covered by tests
"-b",
"--observables",
dest="observable_file_name",
Expand All @@ -90,8 +96,9 @@ def _parse_cli_args():
parser.add_argument(
"-y",
"--yaml",
dest="yaml_file_name",
help="PEtab YAML problem filename",
dest="yaml_file_name_deprecated",
help="PEtab YAML problem filename. *DEPRECATED* Pass the YAML file "
"as positional argument instead.",
)

parser.add_argument(
Expand All @@ -102,18 +109,42 @@ def _parse_cli_args():
)

args = parser.parse_args()

if not args.yaml_file_name and not all(
if any(

Check warning on line 112 in python/sdist/amici/petab/cli/import_petab.py

View check run for this annotation

Codecov / codecov/patch

python/sdist/amici/petab/cli/import_petab.py#L112

Added line #L112 was not covered by tests
[
args.sbml_file_name,
args.condition_file_name,
args.observable_file_name,
args.measurement_file_name,
args.parameter_file_name,
]
):
print(
"Passing individual tables to amico_import_petab is deprecated, "
"please pass a PEtab YAML file instead."
)
if (

Check warning on line 125 in python/sdist/amici/petab/cli/import_petab.py

View check run for this annotation

Codecov / codecov/patch

python/sdist/amici/petab/cli/import_petab.py#L125

Added line #L125 was not covered by tests
not args.yaml_file_name and not args.yaml_file_name_deprecated
) and not all(
(
args.sbml_file_name,
args.condition_file_name,
args.observable_file_name,
args.measurement_file_name,
args.parameter_file_name,
)
):
parser.error(
"When not specifying a model name or YAML file, then "
"SBML, condition and observable file must be specified"
"SBML, condition, observable, measurement and parameter file must "
"be specified."
)

if args.yaml_file_name_deprecated:
print(

Check warning on line 143 in python/sdist/amici/petab/cli/import_petab.py

View check run for this annotation

Codecov / codecov/patch

python/sdist/amici/petab/cli/import_petab.py#L142-L143

Added lines #L142 - L143 were not covered by tests
"-y/--yaml is deprecated. Pass the YAML file as positional "
"argument instead."
)
args.yaml_file_name = args.yaml_file_name_deprecated

Check warning on line 147 in python/sdist/amici/petab/cli/import_petab.py

View check run for this annotation

Codecov / codecov/patch

python/sdist/amici/petab/cli/import_petab.py#L147

Added line #L147 was not covered by tests

return args

Expand All @@ -128,12 +159,14 @@ def _main():
if args.yaml_file_name:
pp = petab.Problem.from_yaml(args.yaml_file_name)
else:
pp = petab.Problem.from_files(
sbml_file=args.sbml_file_name,
condition_file=args.condition_file_name,
measurement_file=args.measurement_file_name,
parameter_file=args.parameter_file_name,
observable_files=args.observable_file_name,
pp = petab.Problem(

Check warning on line 162 in python/sdist/amici/petab/cli/import_petab.py

View check run for this annotation

Codecov / codecov/patch

python/sdist/amici/petab/cli/import_petab.py#L162

Added line #L162 was not covered by tests
model=SbmlModel.from_file(args.sbml_file_name),
condition_df=petab.get_condition_df(args.condition_file_name),
measurement_df=petab.get_measurement_df(
args.measurement_file_name
),
parameter_df=petab.get_parameter_df(args.parameter_file_name),
observable_df=petab.get_observable_df(args.observable_file_name),
)

# Check for valid PEtab before potentially modifying it
Expand Down

0 comments on commit f9f6c61

Please sign in to comment.