def addAntimony(self, antimonyStr, filename=None): """ Adds SBML file as Antimony into COMBINE archive. :param antimonyStr: antimony string """ warnings.warn('Use inline_omex instead.', DeprecationWarning) sbmlStr = te.antimonyToSBML(antimonyStr) self.addSBML(sbmlStr, filename)
def get_sbml(self): return te.antimonyToSBML(f""" model {self.model_name()} r1: S1 -> S2 ; k1*S1*Stim; r2: S2 -> S1 ; k2*S2; Stim = 0; S1 = 10; S2 = 0; k1 = 0.1 k2 = 0.1 end """)
def _setReferencedSBML(self, phrasedmlStr): """ Set phrasedml referenced SBML for given phrasedml String. """ modelNames = [] for aStr in self.antimonyList: r = te.loada(aStr) name = r.getModel().getModelName() modelNames.append(name) sources = self._modelsFromPhrasedml(phrasedmlStr) for source, name in sources.iteritems(): # not a antimony model if name not in modelNames: continue # set as referenced model aStr = self.antimonyList[modelNames.index(name)] phrasedml.setReferencedSBML(source, te.antimonyToSBML(aStr))
def addPhrasedml(self, phrasedmlStr, antimonyStr, arcname=None): """ Adds phrasedml via conversion to SEDML. """ # FIXME: This does not work for multiple referenced models !. reModel = r"""(\w*) = model ('|")(.*)('|")""" phrasedmllines = phrasedmlStr.splitlines() for k, line in enumerate(phrasedmllines): reSearchModel = re.split(reModel, line) if len(reSearchModel) > 1: modelsource = str(reSearchModel[3]) modelname = os.path.basename(modelsource) modelname = str(modelname).replace(".xml", '') phrasedml.setReferencedSBML(modelsource, te.antimonyToSBML(antimonyStr)) sedmlstr = phrasedml.convertString(phrasedmlStr) if sedmlstr is None: raise Exception(phrasedml.getLastError()) phrasedml.clearReferencedSBML() self.addSEDML(sedmlstr, arcname)
def addPhrasedml(self, phrasedmlStr, antimonyStr, arcname=None): """ Adds SEDML file as phraSEDML string into COMBINE archive. :param phrasedmlStr: phraSEDML string :param antimonyStr: antimony string to be referenced :param arcname: (optional) desired name of SEDML file """ warnings.warn('Use inline_omex instead.', DeprecationWarning) # FIXME: This does not work for multiple referenced models !. reModel = r"""(\w*) = model ('|")(.*)('|")""" phrasedmllines = phrasedmlStr.splitlines() for k, line in enumerate(phrasedmllines): reSearchModel = re.split(reModel, line) if len(reSearchModel) > 1: modelsource = str(reSearchModel[3]) modelname = os.path.basename(modelsource) modelname = str(modelname).replace(".xml", '') phrasedml.setReferencedSBML(modelsource, te.antimonyToSBML(antimonyStr)) sedmlstr = phrasedml.convertString(phrasedmlStr) if sedmlstr is None: raise Exception(phrasedml.getLastError()) phrasedml.clearReferencedSBML() self.addSEDML(sedmlstr, arcname)
def addPhrasedml(self, phrasedmlStr, antimonyStr, arcname=None): """ Adds SEDML file as phraSEDML string into COMBINE archive. :param phrasedmlStr: phraSEDML string :param antimonyStr: antimony string to be referenced :param arcname: (optional) desired name of SEDML file """ # FIXME: This does not work for multiple referenced models !. reModel = r"""(\w*) = model ('|")(.*)('|")""" phrasedmllines = phrasedmlStr.splitlines() for k, line in enumerate(phrasedmllines): reSearchModel = re.split(reModel, line) if len(reSearchModel) > 1: modelsource = str(reSearchModel[3]) modelname = os.path.basename(modelsource) modelname = str(modelname).replace(".xml", '') phrasedml.setReferencedSBML(modelsource, te.antimonyToSBML(antimonyStr)) sedmlstr = phrasedml.convertString(phrasedmlStr) if sedmlstr is None: raise Exception(phrasedml.getLastError()) phrasedml.clearReferencedSBML() self.addSEDML(sedmlstr, arcname)
# In[1]: #!!! DO NOT CHANGE !!! THIS FILE WAS CREATED AUTOMATICALLY FROM NOTEBOOKS !!! CHANGES WILL BE OVERWRITTEN !!! CHANGE CORRESPONDING NOTEBOOK FILE !!! from __future__ import print_function import tellurium as te # antimony model ant_model = """ S1 -> S2; k1*S1; S2 -> S3; k2*S2; k1= 0.1; k2 = 0.2; S1 = 10; S2 = 0; S3 = 0; """ # convert to SBML sbml_model = te.antimonyToSBML(ant_model) # convert to CellML cellml_model = te.antimonyToCellML(ant_model) # or from the sbml cellml_model = te.sbmlToCellML(sbml_model) # In[2]:
def addAntimony(self, antimonyStr): """ Add antimony to archive. """ sbmlStr = te.antimonyToSBML(antimonyStr) self.addSBML(sbmlStr)
def test_antimonyToSBML_str(self): sbml = te.antimonyToSBML(self.ant_str) self.assertIsNotNone(sbml)
def test_antimonyToSBML_file(self): sbml = te.antimonyToSBML(self.ant_file) self.assertIsNotNone(sbml)
def setUp(self) -> None: self.sbml = te.antimonyToSBML(TEST_MODEL1) self.yaml_file = os.path.join(os.path.dirname(__file__), 'config.yaml')
# sbml = te.antimonyToSBML(antimony_string()) # print(sbml) if __name__ == '__main__': working_directory = os.path.dirname(__file__) model_combinations = create_combinations(new_reaction1(), new_reaction2()) reactions_map = {0: new_reaction1(), 1: new_reaction2()} fnames = [] for model_id, topology in model_combinations: reactions_string = '' for reaction in topology: reactions_string += reactions_map[reaction] + '\n' model_string = antimony_string(reactions_string) sbml = te.antimonyToSBML(model_string) fname = os.path.join(working_directory, 'topology{}.sbml'.format(model_id)) with open(fname, 'w') as f: f.write(sbml) print('file written to "{}"'.format(fname)) fnames.append(fname) for f in fnames: assert os.path.isfile(f) # Here's a simple example with a fake model I use for testing'
# Back to the main [Index](../index.ipynb) # #### Antimony, SBML, CellML # In[1]: #!!! DO NOT CHANGE !!! THIS FILE WAS CREATED AUTOMATICALLY FROM NOTEBOOKS !!! CHANGES WILL BE OVERWRITTEN !!! CHANGE CORRESPONDING NOTEBOOK FILE !!! from __future__ import print_function import tellurium as te # antimony model ant_model = """ S1 -> S2; k1*S1; S2 -> S3; k2*S2; k1= 0.1; k2 = 0.2; S1 = 10; S2 = 0; S3 = 0; """ # convert to SBML sbml_model = te.antimonyToSBML(ant_model) # convert to CellML cellml_model = te.antimonyToCellML(ant_model) # or from the sbml cellml_model = te.sbmlToCellML(sbml_model) # In[2]:
model myModel S1 -> S2; k1*S1 S1 = 10; S2 = 0 k1 = 1 end ''' phrasedml_str = ''' model1 = model "myModel" sim1 = simulate uniform(0, 5, 100) task1 = run sim1 on model1 plot "Figure 1" time vs S1, S2 ''' # create the sedml xml string from the phrasedml sbml_str = te.antimonyToSBML(antimony_str) phrasedml.setReferencedSBML("myModel", sbml_str) sedml_str = phrasedml.convertString(phrasedml_str) if sedml_str == None: print(phrasedml.getLastPhrasedError()) print(sedml_str) # In[2]: # Create the temporary files and execute the code import tempfile f_sbml = tempfile.NamedTemporaryFile(prefix="myModel", suffix=".xml") f_sbml.write(sbml_str) f_sbml.flush()
""" Create SBML bipartite graph with tellurium/antimony. Read the antimony tutorial for details. reversibility: reversible reaction: '->' irreversible reaction: '=>' One class is R (reaction) the other class S (species). """ import tellurium as te ant = """ model graph() // bipartite reaction-species graph (R-S graph) // all ingoing edges on the left, outgoing on the right R1: A + B => C; R2: C => D; R3: D => E; end """ sbml = te.antimonyToSBML(ant) with open("bipartite-graph.xml", "w") as f: f.write(sbml)
def addAntimony(self, antimonyStr, filename=None): """ Adds SBML file as Antimony into COMBINE archive. :param antimonyStr: antimony string """ sbmlStr = te.antimonyToSBML(antimonyStr) self.addSBML(sbmlStr, filename)
model1 = model "test1" model2 = model "test2" model3 = model model1 with S1=S2+20 sim1 = simulate uniform(0, 6, 100) task1 = run sim1 on model1 task2 = run sim1 on model2 plot "Timecourse test1" task1.time vs task1.S1, task1.S2 plot "Timecourse test2" task2.time vs task2.X1, task2.X2 """ # phrasedml.setReferencedSBML("test1") exp = te.experiment(phrasedmlList=[phrasedmlStr], antimonyList=[antTest1Str]) print(exp) # set first model phrasedml.setReferencedSBML("test1", te.antimonyToSBML(antTest1Str)) phrasedml.setReferencedSBML("test2", te.antimonyToSBML(antTest2Str)) sedmlstr = phrasedml.convertString(phrasedmlStr) if sedmlstr is None: raise Exception(phrasedml.getLastError()) print(sedmlstr) # In[3]: # In[3]:
model myModel S1 -> S2; k1*S1 S1 = 10; S2 = 0 k1 = 1 end ''' phrasedml_str = ''' model1 = model "myModel" sim1 = simulate uniform(0, 5, 100) task1 = run sim1 on model1 plot "Figure 1" time vs S1, S2 ''' # create the sedml xml string from the phrasedml sbml_str = te.antimonyToSBML(antimony_str) phrasedml.setReferencedSBML("myModel", sbml_str) sedml_str = phrasedml.convertString(phrasedml_str) if sedml_str == None: print(phrasedml.getLastPhrasedError()) print(sedml_str) # In[2]: # Create the temporary files and execute the code import tempfile f_sbml = tempfile.NamedTemporaryFile(prefix="myModel", suffix=".xml") f_sbml.write(sbml_str) f_sbml.flush() print(f_sbml.name)
def setUp(self) -> None: self.sbml = te.antimonyToSBML(TEST_MODEL2) self.config = Config(self.sbml)