def flattenMotif(combined): #flatten the combined model by converting it to sbml and then converting back to Antimony antimony.clearPreviousLoads() code = antimony.loadAntimonyString(combined) if code <= 0: textfile = open('combined.txt', 'w') textfile.write(combined) textfile.close() raise AssertionError( 'combined model is not flattenable. Are you using the right species names? ' + 'Combined model saved as: ' + str(os.getcwd()) + '\\combined.txt') sbmlStr = antimony.getSBMLString('combined') antimony.loadSBMLString(sbmlStr) flatComb = antimony.getAntimonyString('combined') ####TODO #Delete extraneous mRNA -> Protein reactions at P_c connections #look for p_c#, regex #delete second equation with occurance of p_c#curr, regex #todo: remove extraneous species + parameters in the removed equation ####TODO return (flatComb)
def cellmlStrToAntimony(CellMLStr): """Convert a cellml string into the equivalent antimony string: ant = cellMLStrToAntimony('mymodel.cellml') """ if antimony.loadCellMLFile(CellMLStr) < 0: raise Exception("Error calling cellMLStrToAntimony" + antimony.getLastError()) return antimony.getAntimonyString(None)
def cellmlFileToAntimony(CellMLFileName): """Load a cellml file and return the equivalent antimony string: ant = cellMLToAntimony('mymodel.cellml') """ if antimony.loadCellMLFile(CellMLFileName) == -1: raise Exception("Error calling loadCellMLFile") antimony.loadCellMLFile(CellMLFileName) return antimony.getAntimonyString(None)
def sbmlToAntimony(str): """Convert a SBML string into Antimony: sbmlStr = sbmlToAntimony (antimonyStr) """ err = antimony.loadSBMLString(str) if err < 0: raise Exception("Antimony: " + antimony.getLastError()) return antimony.getAntimonyString(None)
def translate_sbml(cls, sbml_file: str): """ Translate SBML file to Antimony model specification. cayenne's model specification is loosely based on Antimony's model specification. """ er_code = sb.loadSBMLFile(sbml_file) if er_code == -1: raise ModelError("Error while parsing model") sb_module = sb.getMainModuleName() sb_string = sb.getAntimonyString(sb_module) return sb_string
def cellmlToAntimony(cellml): """ Convert CellML to antimony string. :param cellml: CellML string or file :type cellml: str | file :return: antimony :rtype: str """ if os.path.isfile(cellml): code = antimony.loadCellMLFile(cellml) else: code = antimony.loadCellMLString(cellml) _checkAntimonyReturnCode(code) return antimony.getAntimonyString(None)
def sbmlToAntimony(sbml): """ Convert SBML to antimony string. :param sbml: SBML string or file :type sbml: str | file :return: Antimony :rtype: str """ if os.path.isfile(sbml): code = antimony.loadSBMLFile(sbml) else: code = antimony.loadSBMLString(sbml) _checkAntimonyReturnCode(code) return antimony.getAntimonyString(None)
def cellmlFileToAntimony(self, sbml_path): """ Converts a CellML file to Antimony source. :param sbml_path: The path to the CellML file :returns: A 2-tuple (module_name, antimony_source) """ import antimony as sb # try to load the Antimony code` code = sb.loadCellMLFile(sbml_path) # if errors, bail if self.checkAntimonyReturnCode(code): errors = sb.getLastError() raise RuntimeError('Errors encountered when trying to load model:\n{}'.format(errors)) module = sb.getMainModuleName() sb_source = sb.getAntimonyString(module) return (module, sb_source)
def sbmlToAntimony(self, sbml, addSBO=False): """ Converts a raw SBML string to Antimony source. :param sbml: The raw SBML string :returns: A 2-tuple (module_name, antimony_source) """ import antimony as sb # try to load the Antimony code` code = sb.loadSBMLString(sbml) # if errors, bail if self.checkAntimonyReturnCode(code): errors = sb.getLastError() raise RuntimeError('Errors encountered when trying to load model:\n{}'.format(errors)) module = sb.getMainModuleName() sb_source = sb.getAntimonyString(module) if addSBO: sb_source = self.tryAddSBOTerms(sb_source, sbml_str=sbml) return (module, sb_source)
# A : model1(); # B : model2(); # #repeat for all models I have # #specify a global input node # var species p_c; # A.p_input is p_c; # B.p_output is p_c; # #repeat for n-1 modules # end # ''' #properly flatten the combined model antimony.loadAntimonyString(combined) sbmlstr = antimony.getSBMLString('combined') antimony.loadSBMLString(sbmlstr) flatcomb = antimony.getAntimonyString('combined') r = te.loada(flatcomb) r.exportToAntimony('combined.txt') r.draw(layout='dot') #combined = reads + ''' #model combined # var species p_c; # #!!module names have to be identical to model names from imported models!! # A : ffl1(); # B : ffl1(); # A.p_input is p_c; # B.p_output is p_c; #end #'''