def fromPhrasedML(cls, phrasedmlStr, location, master=None): sedmlStr = phrasedml.convertString(phrasedmlStr) # necessary to add xml extensions to antimony models phrasedml.addDotXMLToModelSources() sedmlStr = phrasedml.getLastSEDML() if sedmlStr is None: raise Exception(phrasedml.getLastError()) return cls.fromRaw(raw=sedmlStr, location=location, filetype='sed-ml', master=master)
def __init__(self, sources): """ Converts a dictionary of PhraSEDML files and list of Antimony files into sedml/sbml. :param sources: Sources returned from partitionInlineOMEXString """ from .convert_omex import Omex, SbmlAsset, SedmlAsset, readCreator from .convert_antimony import antimonyConverter phrasedml.clearReferencedSBML() from .. import DumpJSONInfo self.omex = Omex(description=DumpJSONInfo(), creator=readCreator()) # Convert antimony to sbml for t, loc, master in ((x['source'], x['location'] if 'location' in x else None, x['master'] if 'master' in x else None) for x in sources if x['type'] == 'antimony'): modulename, sbmlstr = antimonyConverter().antimonyToSBML(t) outpath = loc if loc is not None else modulename + '.xml' self.omex.addSbmlAsset(SbmlAsset(outpath, sbmlstr, master=master)) # Convert phrasedml to sedml for t, loc, master in ((x['source'], x['location'] if 'location' in x else None, x['master'] if 'master' in x else None) for x in sources if x['type'] == 'phrasedml'): for sbml_asset in self.omex.getSbmlAssets(): if sbml_asset.location: if loc: path = os.path.relpath(sbml_asset.location, os.path.dirname(loc)) else: path = sbml_asset.location else: path = sbml_asset.getModuleName() # make windows paths like unix paths if os.path.sep == '\\': path = path.replace(os.path.sep, '/') phrasedml.setReferencedSBML(path, sbml_asset.getContent()) phrasedml.convertString(t) phrasedml.addDotXMLToModelSources(False) sedml = phrasedml.getLastSEDML() if sedml is None: raise RuntimeError( 'Unable to convert PhraSEDML to SED-ML: {}'.format( phrasedml.getLastError())) outpath = loc if loc is not None else 'main.xml' self.omex.addSedmlAsset(SedmlAsset(outpath, sedml, master=master))
def __init__(self, sources): """ Converts a dictionary of PhraSEDML files and list of Antimony files into sedml/sbml. :param sources: Sources returned from partitionInlineOMEXString """ from .convert_omex import Omex, SbmlAsset, SedmlAsset, readCreator from .convert_antimony import antimonyConverter phrasedml.clearReferencedSBML() from .. import DumpJSONInfo self.omex = Omex( description=DumpJSONInfo(), creator=readCreator() ) # Convert antimony to sbml for t, loc, master in ( (x['source'], x['location'] if 'location' in x else None, x['master'] if 'master' in x else None) for x in sources if x['type'] == 'antimony'): modulename, sbmlstr = antimonyConverter().antimonyToSBML(t) outpath = loc if loc is not None else modulename + '.xml' self.omex.addSbmlAsset(SbmlAsset(outpath, sbmlstr, master=master)) # Convert phrasedml to sedml for t, loc, master in ( (x['source'], x['location'] if 'location' in x else None, x['master'] if 'master' in x else None) for x in sources if x['type'] == 'phrasedml'): for sbml_asset in self.omex.getSbmlAssets(): if sbml_asset.location: if loc: path = os.path.relpath(sbml_asset.location, os.path.dirname(loc)) else: path = sbml_asset.location else: path = sbml_asset.getModuleName() # make windows paths like unix paths if os.path.sep == '\\': path = path.replace(os.path.sep, '/') phrasedml.setReferencedSBML(path, sbml_asset.getContent()) phrasedml.convertString(t) phrasedml.addDotXMLToModelSources(False) sedml = phrasedml.getLastSEDML() if sedml is None: raise RuntimeError('Unable to convert PhraSEDML to SED-ML: {}'.format(phrasedml.getLastError())) outpath = loc if loc is not None else 'main.xml' self.omex.addSedmlAsset(SedmlAsset(outpath, sedml, master=master))
import phrasedml, os with open('./model/BIOMD0000000144.xml') as f: sbml_str = f.read() with open('./experiment/Calzone2007-simulation-figure-1B.xml') as f: sedml_in = f.read() phrasedml.setReferencedSBML('../model/BIOMD0000000144.xml', sbml_str) phrasedml.convertString(sedml_in) phrased_str = phrasedml.getLastPhraSEDML() phrasedml.convertString(phrased_str) phrasedml.addDotXMLToModelSources() sedml_out = phrasedml.getLastSEDML() if not os.path.exists('phrased'): os.makedirs('phrased') with open('./phrased/Calzone2007-simulation-figure-1B.xml', 'w') as f: f.write(sedml_out)