Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add script for converting ode2cellml #162

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions src/gotranx/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
27 changes: 27 additions & 0 deletions src/gotranx/cli/ode2cellml.py
Original file line number Diff line number Diff line change
@@ -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}")
Loading