diff --git a/src/gotranx/cli/__init__.py b/src/gotranx/cli/__init__.py index e53eada..c0deb14 100644 --- a/src/gotranx/cli/__init__.py +++ b/src/gotranx/cli/__init__.py @@ -214,6 +214,60 @@ def cellml2ode( _main(fname=fname, outname=outname, verbose=verbose) +@app.command() +def ode2cellml( + fname: typing.Optional[Path] = typer.Argument( + None, + exists=True, + file_okay=True, + dir_okay=False, + writable=False, + readable=True, + resolve_path=True, + ), + outname: typing.Optional[str] = typer.Option( + None, + "-o", + "--outname", + help="Output name", + ), + version: bool = typer.Option( + None, + "--version", + callback=version_callback, + is_eager=True, + help="Show version", + ), + license: bool = typer.Option( + None, + "--license", + callback=license_callback, + is_eager=True, + help="Show license", + ), + config: typing.Optional[Path] = typer.Option( + None, + "--config", + help="Read configuration options from a configuration file", + ), + verbose: bool = typer.Option( + False, + "--verbose", + "-v", + help="Verbose output", + ), +): + if fname is None: + return typer.echo("No file specified") + + config_data = utils.read_config(config) + verbose = config_data.get("verbose", verbose) + + from .ode2cellml import main as _main + + _main(fname=fname, outname=outname, verbose=verbose) + + @app.command() def ode2py( fname: typing.Optional[Path] = typer.Argument( diff --git a/src/gotranx/cli/ode2cellml.py b/src/gotranx/cli/ode2cellml.py new file mode 100644 index 0000000..18fb1dc --- /dev/null +++ b/src/gotranx/cli/ode2cellml.py @@ -0,0 +1,27 @@ +from __future__ import annotations +from pathlib import Path +import logging +import structlog + +from ..myokit import gotran_to_cellml +from ..load import load_ode + +logger = structlog.get_logger() + + +def main( + fname: Path, + outname: str | None = None, + verbose: bool = False, +) -> None: + loglevel = logging.DEBUG if verbose else logging.INFO + structlog.configure( + wrapper_class=structlog.make_filtering_bound_logger(loglevel), + ) + assert fname.suffix in ".ode", f"File {fname} must be an ode file" + assert fname.exists(), f"File {fname} does not exist" + ode = load_ode(fname) + logger.info(f"Converting {fname} to CellML") + cellml_file = fname.with_suffix(".cellml") if outname is None else Path(outname) + gotran_to_cellml(ode, filename=cellml_file) + logger.info(f"Wrote {cellml_file}")