SimpleSEDML 0.0.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 UW Sauro Lab
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,92 @@
1
+ Metadata-Version: 2.4
2
+ Name: SimpleSEDML
3
+ Version: 0.0.1
4
+ Summary: Python Subnet Discovery for Systems Biology
5
+ Author-email: Joseph Hellerstein <joseph.hellerstein@gmail.com>, Herbert S Sauro <hsauro@uw.edu>
6
+ License: MIT License
7
+
8
+ Copyright (c) 2025 UW Sauro Lab
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of this software and associated documentation files (the "Software"), to deal
12
+ in the Software without restriction, including without limitation the rights
13
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ copies of the Software, and to permit persons to whom the Software is
15
+ furnished to do so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in all
18
+ copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ SOFTWARE.
27
+
28
+ Project-URL: Homepage, https://github.com/sys-bio/SimpleSEDML
29
+ Requires-Python: >=3.6
30
+ Description-Content-Type: text/markdown
31
+ License-File: LICENSE
32
+ Requires-Dist: numpy
33
+ Requires-Dist: build
34
+ Requires-Dist: coverage
35
+ Requires-Dist: jupyterlab
36
+ Requires-Dist: matplotlib
37
+ Requires-Dist: nose2
38
+ Requires-Dist: pandas
39
+ Requires-Dist: phrasedml
40
+ Requires-Dist: pip
41
+ Requires-Dist: requests
42
+ Requires-Dist: tabulate
43
+ Requires-Dist: tellurium
44
+ Requires-Dist: twine
45
+ Requires-Dist: urllib3
46
+ Dynamic: license-file
47
+
48
+ [![Build](https://github.com/sys-bio/SimpleSEDML/actions/workflows/github-actions.yml/badge.svg)](https://github.com/sys-bio/SimpleSBML/actions/workflows/github-actions.yml)
49
+
50
+ # SimpleSEDML
51
+ A simple API for using the [Simulation Experiment Description Markup Language (SED-ML)](https://sed-ml.org/), a community standard for describing simulation experiments.
52
+
53
+ The project provides a python interface to generating SED-ML based on the abstractions provided by [phraSED-ML](https://pmc.ncbi.nlm.nih.gov/articles/PMC5313123/pdf/nihms846540.pdf) to describe simulation experiments. These absractions are: (a) models (including changes in values of model parameters);
54
+ (b) simulations (including deterministic, stochastic, and steady state);
55
+ (c) tasks (which specify simulations to run on tasks and repetitions for changes in parameter values);
56
+ and (d) output for data reports and plots.
57
+
58
+ ``SimpleSEDML`` generalizes the capabilities of ``PhraSEDML`` and simplifies its usage by exploiting the Python environment:
59
+
60
+ * A model source can be a file path or URL and may be in the Antimony language as well as SBML;
61
+ * Repeated tasks are defined more simply by the use of a ``pandas`` ``DataFrame``.
62
+ * Convenience methods are provided to simplify the API.
63
+
64
+ # Example
65
+
66
+ See this [Jupyter notebook](https://github.com/sys-bio/SimpleSEDML/blob/main/examples/usage_examples.ipynb) for a detailed example.
67
+
68
+ Consider the model below in the Antimony language.
69
+
70
+ mymodel = """
71
+ model myModel
72
+ J1: S1 -> S2; k1*S1;
73
+ k1 = 0.5;
74
+ end
75
+ """
76
+
77
+ We want to simulate this model and do a time course plot of all floating species in the model.
78
+
79
+ from simple_sedml import SimpleSEDML
80
+
81
+ sedml_str = SimpleSEDML.makeTimeCourse(mymodel)
82
+
83
+ We can print, save, or execute ``sedml_str``. To execute it,
84
+
85
+ SimpleSEDML.executeSEDML(sedml_str)
86
+ <img src="docs/images/phrasedml_example.png" style="width:300px;height:300px;">
87
+
88
+ # Restrictions
89
+ 1. If there are multiple task directives and/or there is a repeated task directive AND there is a report directive, SimpleSEDML.execute only returns the results of the last simulation. You can circumvent this by iterating in python to obtain the desired reports.
90
+
91
+ # Plans
92
+ 1. First implementation of ``SimpleSEDML`` with methods for ``addModel``, ``addSimulation``, ``addTask``, ``addReport``, ``execute``, and ``to_sedml``.
@@ -0,0 +1,45 @@
1
+ [![Build](https://github.com/sys-bio/SimpleSEDML/actions/workflows/github-actions.yml/badge.svg)](https://github.com/sys-bio/SimpleSBML/actions/workflows/github-actions.yml)
2
+
3
+ # SimpleSEDML
4
+ A simple API for using the [Simulation Experiment Description Markup Language (SED-ML)](https://sed-ml.org/), a community standard for describing simulation experiments.
5
+
6
+ The project provides a python interface to generating SED-ML based on the abstractions provided by [phraSED-ML](https://pmc.ncbi.nlm.nih.gov/articles/PMC5313123/pdf/nihms846540.pdf) to describe simulation experiments. These absractions are: (a) models (including changes in values of model parameters);
7
+ (b) simulations (including deterministic, stochastic, and steady state);
8
+ (c) tasks (which specify simulations to run on tasks and repetitions for changes in parameter values);
9
+ and (d) output for data reports and plots.
10
+
11
+ ``SimpleSEDML`` generalizes the capabilities of ``PhraSEDML`` and simplifies its usage by exploiting the Python environment:
12
+
13
+ * A model source can be a file path or URL and may be in the Antimony language as well as SBML;
14
+ * Repeated tasks are defined more simply by the use of a ``pandas`` ``DataFrame``.
15
+ * Convenience methods are provided to simplify the API.
16
+
17
+ # Example
18
+
19
+ See this [Jupyter notebook](https://github.com/sys-bio/SimpleSEDML/blob/main/examples/usage_examples.ipynb) for a detailed example.
20
+
21
+ Consider the model below in the Antimony language.
22
+
23
+ mymodel = """
24
+ model myModel
25
+ J1: S1 -> S2; k1*S1;
26
+ k1 = 0.5;
27
+ end
28
+ """
29
+
30
+ We want to simulate this model and do a time course plot of all floating species in the model.
31
+
32
+ from simple_sedml import SimpleSEDML
33
+
34
+ sedml_str = SimpleSEDML.makeTimeCourse(mymodel)
35
+
36
+ We can print, save, or execute ``sedml_str``. To execute it,
37
+
38
+ SimpleSEDML.executeSEDML(sedml_str)
39
+ <img src="docs/images/phrasedml_example.png" style="width:300px;height:300px;">
40
+
41
+ # Restrictions
42
+ 1. If there are multiple task directives and/or there is a repeated task directive AND there is a report directive, SimpleSEDML.execute only returns the results of the last simulation. You can circumvent this by iterating in python to obtain the desired reports.
43
+
44
+ # Plans
45
+ 1. First implementation of ``SimpleSEDML`` with methods for ``addModel``, ``addSimulation``, ``addTask``, ``addReport``, ``execute``, and ``to_sedml``.
@@ -0,0 +1,35 @@
1
+ [project]
2
+ name = "SimpleSEDML"
3
+ version = "0.0.1"
4
+ description = "Python Subnet Discovery for Systems Biology"
5
+ authors = [{ name = "Joseph Hellerstein", email = "joseph.hellerstein@gmail.com" }, {name = "Herbert S Sauro", email = "hsauro@uw.edu"}]
6
+ license = { file = "LICENSE" }
7
+ readme = "README.md"
8
+ requires-python = ">=3.6"
9
+
10
+ dependencies = [
11
+ "numpy",
12
+ "build",
13
+ "coverage",
14
+ "jupyterlab",
15
+ "matplotlib",
16
+ "nose2",
17
+ "pandas",
18
+ "phrasedml",
19
+ "pip",
20
+ "requests",
21
+ "tabulate",
22
+ "tellurium",
23
+ "twine",
24
+ "urllib3",
25
+ ]
26
+
27
+ [project.urls]
28
+ Homepage = 'https://github.com/sys-bio/SimpleSEDML'
29
+
30
+ [options.package_data]
31
+ data = "*.txt, *.csv, *.ant, *.xml"
32
+
33
+ [build-system]
34
+ requires = ["setuptools>=61.0.0", "wheel"]
35
+ build-backend = "setuptools.build_meta"
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,92 @@
1
+ Metadata-Version: 2.4
2
+ Name: SimpleSEDML
3
+ Version: 0.0.1
4
+ Summary: Python Subnet Discovery for Systems Biology
5
+ Author-email: Joseph Hellerstein <joseph.hellerstein@gmail.com>, Herbert S Sauro <hsauro@uw.edu>
6
+ License: MIT License
7
+
8
+ Copyright (c) 2025 UW Sauro Lab
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of this software and associated documentation files (the "Software"), to deal
12
+ in the Software without restriction, including without limitation the rights
13
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ copies of the Software, and to permit persons to whom the Software is
15
+ furnished to do so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in all
18
+ copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ SOFTWARE.
27
+
28
+ Project-URL: Homepage, https://github.com/sys-bio/SimpleSEDML
29
+ Requires-Python: >=3.6
30
+ Description-Content-Type: text/markdown
31
+ License-File: LICENSE
32
+ Requires-Dist: numpy
33
+ Requires-Dist: build
34
+ Requires-Dist: coverage
35
+ Requires-Dist: jupyterlab
36
+ Requires-Dist: matplotlib
37
+ Requires-Dist: nose2
38
+ Requires-Dist: pandas
39
+ Requires-Dist: phrasedml
40
+ Requires-Dist: pip
41
+ Requires-Dist: requests
42
+ Requires-Dist: tabulate
43
+ Requires-Dist: tellurium
44
+ Requires-Dist: twine
45
+ Requires-Dist: urllib3
46
+ Dynamic: license-file
47
+
48
+ [![Build](https://github.com/sys-bio/SimpleSEDML/actions/workflows/github-actions.yml/badge.svg)](https://github.com/sys-bio/SimpleSBML/actions/workflows/github-actions.yml)
49
+
50
+ # SimpleSEDML
51
+ A simple API for using the [Simulation Experiment Description Markup Language (SED-ML)](https://sed-ml.org/), a community standard for describing simulation experiments.
52
+
53
+ The project provides a python interface to generating SED-ML based on the abstractions provided by [phraSED-ML](https://pmc.ncbi.nlm.nih.gov/articles/PMC5313123/pdf/nihms846540.pdf) to describe simulation experiments. These absractions are: (a) models (including changes in values of model parameters);
54
+ (b) simulations (including deterministic, stochastic, and steady state);
55
+ (c) tasks (which specify simulations to run on tasks and repetitions for changes in parameter values);
56
+ and (d) output for data reports and plots.
57
+
58
+ ``SimpleSEDML`` generalizes the capabilities of ``PhraSEDML`` and simplifies its usage by exploiting the Python environment:
59
+
60
+ * A model source can be a file path or URL and may be in the Antimony language as well as SBML;
61
+ * Repeated tasks are defined more simply by the use of a ``pandas`` ``DataFrame``.
62
+ * Convenience methods are provided to simplify the API.
63
+
64
+ # Example
65
+
66
+ See this [Jupyter notebook](https://github.com/sys-bio/SimpleSEDML/blob/main/examples/usage_examples.ipynb) for a detailed example.
67
+
68
+ Consider the model below in the Antimony language.
69
+
70
+ mymodel = """
71
+ model myModel
72
+ J1: S1 -> S2; k1*S1;
73
+ k1 = 0.5;
74
+ end
75
+ """
76
+
77
+ We want to simulate this model and do a time course plot of all floating species in the model.
78
+
79
+ from simple_sedml import SimpleSEDML
80
+
81
+ sedml_str = SimpleSEDML.makeTimeCourse(mymodel)
82
+
83
+ We can print, save, or execute ``sedml_str``. To execute it,
84
+
85
+ SimpleSEDML.executeSEDML(sedml_str)
86
+ <img src="docs/images/phrasedml_example.png" style="width:300px;height:300px;">
87
+
88
+ # Restrictions
89
+ 1. If there are multiple task directives and/or there is a repeated task directive AND there is a report directive, SimpleSEDML.execute only returns the results of the last simulation. You can circumvent this by iterating in python to obtain the desired reports.
90
+
91
+ # Plans
92
+ 1. First implementation of ``SimpleSEDML`` with methods for ``addModel``, ``addSimulation``, ``addTask``, ``addReport``, ``execute``, and ``to_sedml``.
@@ -0,0 +1,22 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ src/__init__.py
5
+ src/constants.py
6
+ src/model.py
7
+ src/plot.py
8
+ src/report.py
9
+ src/simple_sedml.py
10
+ src/simulation.py
11
+ src/task.py
12
+ src/SimpleSEDML.egg-info/PKG-INFO
13
+ src/SimpleSEDML.egg-info/SOURCES.txt
14
+ src/SimpleSEDML.egg-info/dependency_links.txt
15
+ src/SimpleSEDML.egg-info/requires.txt
16
+ src/SimpleSEDML.egg-info/top_level.txt
17
+ tests/test_model.py
18
+ tests/test_plot.py
19
+ tests/test_report.py
20
+ tests/test_simple_sedml.py
21
+ tests/test_simulation.py
22
+ tests/test_task.py
@@ -0,0 +1,14 @@
1
+ numpy
2
+ build
3
+ coverage
4
+ jupyterlab
5
+ matplotlib
6
+ nose2
7
+ pandas
8
+ phrasedml
9
+ pip
10
+ requests
11
+ tabulate
12
+ tellurium
13
+ twine
14
+ urllib3
@@ -0,0 +1,8 @@
1
+ __init__
2
+ constants
3
+ model
4
+ plot
5
+ report
6
+ simple_sedml
7
+ simulation
8
+ task
@@ -0,0 +1 @@
1
+ __version__ = "0.0.1"
@@ -0,0 +1,4 @@
1
+ import os
2
+
3
+ PROJECT_DIR = os.path.dirname(os.path.dirname(__file__))
4
+ TEST_DIR = os.path.join(PROJECT_DIR, "tests")
@@ -0,0 +1,188 @@
1
+ '''Class that handles model definitions and their parameters.'''
2
+
3
+ import codecs
4
+ import urllib3
5
+ import os
6
+ import tellurium as te # type: ignore
7
+ from typing import Optional, List
8
+ import warnings
9
+
10
+ SBML_STR = "sbml_str"
11
+ ANT_STR = "ant_str"
12
+ SBML_FILE = "sbml_file"
13
+ ANT_FILE = "ant_file"
14
+ SBML_URL = "sbml_url"
15
+ MODEL_ID = "model_id"
16
+ MODEL_REF_TYPES = [SBML_STR, ANT_STR, SBML_FILE, ANT_FILE, SBML_URL, MODEL_ID]
17
+
18
+ """
19
+ Issues
20
+ 1. To eliminate the warning for urllib3, need to create a virtual environment with a higher version of python.
21
+ """
22
+
23
+ class Model:
24
+ def __init__(self, id:str, model_ref:Optional[str]=None, ref_type:Optional[str]=None,
25
+ model_source:Optional[str]=None,
26
+ is_overwrite:bool=False,
27
+ **kwargs):
28
+ """Provide information about the model and a model identifier.
29
+
30
+ Args:
31
+ id (str): identifier for the model
32
+ model_ref (str): reference to the file; reference type is specified separately
33
+ ref_type (str):
34
+ - "sbml_str": string representation of the SBML model
35
+ - "ant_str": string representation of the SBML model
36
+ - "sbml_file": file path to the SBML model
37
+ - "ant_file": file path to the Antimony model
38
+ - "sbml_url": URL to the SBML model
39
+ - "model_id": ID of a previously defined model
40
+ is_overwrite (bool): if True, overwrite the model if it already exists
41
+ model_source (str): source for the SBML model. If None, the source is a file with the same name as the model ID
42
+ in the current directory.
43
+ """
44
+ # Handle defaults
45
+ if model_ref is None:
46
+ # id is a file path to an SBML model
47
+ model_ref = id
48
+ _, filename = os.path.split(id)
49
+ splits = filename.split(".")
50
+ id = splits[0]
51
+ ref_type = SBML_FILE
52
+ elif ref_type is None:
53
+ ref_type = SBML_STR
54
+ # id, model_ref, ref_type should all be assigned
55
+ self.id = id
56
+ self.model_ref = model_ref
57
+ self.ref_type = ref_type
58
+ self.param_change_dct = kwargs
59
+ self.is_overwrite = is_overwrite
60
+ #
61
+ self.sbml_str = self._getSBMLFromReference()
62
+ self.model_source_path = self._makeModelSource(model_source)
63
+
64
+ def _makeModelSource(self, source:Optional[str])->str:
65
+ """Saves the model to a file. The file name is the model ID.
66
+ """
67
+ if self.ref_type == MODEL_ID:
68
+ # model_ref is the ID of a previously defined model
69
+ return self.model_ref
70
+ # FIXME: Model source should be the filename in the path
71
+ if source is None:
72
+ # Use the current directory
73
+ source = os.getcwd()
74
+ source = os.path.join(source, self.id)
75
+ source = str(source)
76
+ if self.is_overwrite or not os.path.exists(source):
77
+ with open(source, "wb") as f:
78
+ f.write(self.sbml_str.encode('utf-8'))
79
+ f.flush()
80
+ print(f"**Model saved to {source}")
81
+ if (not self.is_overwrite and os.path.exists(source)):
82
+ msg = "*** File {model_source_path} already exists and will be used as model source."
83
+ msg += "\n Use is_overwrite=True to overwrite."
84
+ warnings.warn(msg)
85
+ return source
86
+
87
+ def _getSBMLFromReference(self)->str:
88
+ """Extracts an SBML strong from the model reference
89
+
90
+ Args:
91
+ self.model_ref (str): reference to the file; reference type is specified separately
92
+ self.ref_type (str): One of self.MODEL_self.REF_TYPES
93
+
94
+ Returns:
95
+ SBML string
96
+ """
97
+ if self.ref_type in [SBML_FILE, ANT_FILE]:
98
+ with open(self.model_ref, "r") as f:
99
+ lines = f.read()
100
+ if self.ref_type == SBML_FILE:
101
+ sbml_str = lines
102
+ else:
103
+ sbml_str = te.antimonyToSBML(lines)
104
+ elif self.ref_type == SBML_STR:
105
+ sbml_str = self.model_ref
106
+ elif self.ref_type == ANT_STR:
107
+ sbml_str = te.antimonyToSBML(self.model_ref)
108
+ elif self.ref_type == MODEL_ID:
109
+ # self.model_ref is the ID of a previously defined model
110
+ sbml_str = ""
111
+ else:
112
+ # self.ref_type == SBML_URL
113
+ response = urllib3.request("GET", self.model_ref)
114
+ if response.status == 200:
115
+ sbml_str = codecs.decode(response.data, 'utf-8')
116
+ else:
117
+ raise ValueError(f"Failed to fetch SBML from URL: {self.model_ref}")
118
+ return sbml_str
119
+
120
+ def __str__(self):
121
+ params = ", ".join(f"{param} = {val}" for param, val in self.param_change_dct.items())
122
+ if len(params) > 0:
123
+ params = f" with {params}"
124
+ if self.ref_type == MODEL_ID:
125
+ source = self.id
126
+ else:
127
+ source = f'"{self.model_source_path}"'
128
+ return f'{self.id} = model {source} {params}'
129
+
130
+ @staticmethod
131
+ def findReferenceType(model_ref:str, model_ids:List[str], ref_type:Optional[str]=None)->str:
132
+ """Infers the reference type from the model reference.
133
+
134
+ Args:
135
+ model_ref (str): reference to the file; reference type is specified separately
136
+ model_ids (List[str]): List of known model IDs
137
+ refer_type (str): One of self.MODEL_REF_TYPES
138
+
139
+ Returns:
140
+ str: reference type
141
+ """
142
+ # Use the ref_type if it is specified
143
+ if ref_type is not None:
144
+ return ref_type
145
+ # Check if this is a model ID
146
+ if model_ref in model_ids:
147
+ try:
148
+ is_file = os.path.exists(model_ref)
149
+ except:
150
+ is_file = False
151
+ if is_file:
152
+ warnings.warn(f"Model ID {model_ref} is also a file path. Using model ID.")
153
+ return MODEL_ID
154
+ # Check for Antimony string
155
+ try:
156
+ _ = te.loada(model_ref)
157
+ return ANT_STR
158
+ except:
159
+ pass
160
+ # Check for SBML string
161
+ try:
162
+ _ = te.loadSBMLModel(model_ref)
163
+ if "sbml" in model_ref:
164
+ return SBML_STR
165
+ except:
166
+ pass
167
+ # Check if this is a URL
168
+ if ("http://" in model_ref) or ("https://" in model_ref):
169
+ return SBML_URL
170
+ # Check if this is a file path
171
+ try:
172
+ is_file = os.path.exists(model_ref)
173
+ except:
174
+ is_file = False
175
+ if is_file:
176
+ try:
177
+ with open(model_ref, "r") as f:
178
+ lines = f.read()
179
+ if lines.startswith("<"):
180
+ return SBML_FILE
181
+ else:
182
+ return ANT_FILE
183
+ except:
184
+ pass
185
+ # Report error
186
+ msg = f"Unidentifiable model reference: {model_ref}. "
187
+ msg += f"\nFix the reference and/or specify the reference type.\nMust be one of {MODEL_REF_TYPES}."
188
+ raise ValueError(msg)
@@ -0,0 +1,41 @@
1
+ from typing import Optional, List, Union
2
+
3
+ class Plot:
4
+ def __init__(self, x_var:str, y_var:Union[str, List[str]], z_var:Optional[str]=None, title:Optional[str]=None,
5
+ is_plot:bool=True)->None:
6
+ """
7
+ Plot class to represent a plot in the script. The following cases are supported:
8
+ plot x vs y (z is None, y is str)
9
+ plot x vs y1, y2, y3 (z is None, y is a list of str)
10
+ plot x vs y vs z (z is a str, y is str)
11
+
12
+ Args:
13
+ x_var (str): x variable
14
+ y_var (str): y variable
15
+ z_var (str, optional): z variable. Defaults to None.
16
+ title (str, optional): title of the plot. Defaults to None.
17
+ """
18
+ self.x_var = x_var
19
+ self.y_var = y_var
20
+ self.z_var = z_var
21
+ self.title = title
22
+ self.is_plot = is_plot
23
+
24
+ # FIXME: Support the above use cases
25
+ def __str__(self)->str:
26
+ if not self.is_plot:
27
+ return ""
28
+ if self.z_var is None:
29
+ if isinstance(self.y_var, str):
30
+ y_vars = [self.y_var]
31
+ else:
32
+ y_vars = self.y_var
33
+ var_clause = f'{self.x_var} vs {", ".join(y_vars)}'
34
+ else:
35
+ if not isinstance(self.y_var, str):
36
+ raise ValueError("y_var must be a string when z_var is provided")
37
+ var_clause = f"{self.x_var} vs {self.y_var} vs {self.z_var}"
38
+ if self.title is None:
39
+ return f"plot {var_clause}"
40
+ else:
41
+ return f"plot \"{self.title}\" {var_clause}"
@@ -0,0 +1,26 @@
1
+ from typing import Optional
2
+
3
+ class Report:
4
+ def __init__(self, metadata:Optional[dict]=None, title:str=""):
5
+ """Reports data after a simulation.
6
+
7
+ Args:
8
+ metadata (Optional[dict], optional): A dictionary of values saved in the
9
+ 'attrs' attribute of the DataFrame generated.
10
+ title (str, optional): Saved in the SEDML
11
+ """
12
+ self.metadata = metadata
13
+ self.title = title
14
+ self.variables:list = []
15
+
16
+ def addVariables(self, *args):
17
+ """
18
+ List of data to report
19
+
20
+ Args:
21
+ *args: list of report variables
22
+ """
23
+ self.variables.extend(args)
24
+
25
+ def __str__(self)->str:
26
+ return "\n".join([f'report "{self.title}" {", ".join(self.variables)}'])