def load_and_translate(self, sedmlfile, pythonfile, editor, set_current=True): """ Read filename as SED-ML file, translate it to Python, and create an editor instance and return it *Warning* This is loading file, creating editor but not executing the source code analysis -- the analysis must be done by the editor plugin (in case multiple editorstack instances are handled) """ #sedmlfile = to_text_string(sedmlfile) sedmlfile = str(sedmlfile) self.emit(SIGNAL('starting_long_process(QString)'), _("Loading %s...") % sedmlfile) text, enc = encoding.read(sedmlfile) fname = os.path.basename(sedmlfile) temp = '"End of code generated by Import SED-ML plugin ' + time.strftime("%m/%d/%Y") + '"\n"Extracted from ' + fname + '"\n\n' text = te.sedmlToPython(sedmlfile) + temp widgeteditor = editor.editorstacks[0] finfo = widgeteditor.create_new_editor(pythonfile, enc, text, set_current, new=True) index = widgeteditor.data.index(finfo) widgeteditor._refresh_outlineexplorer(index, update=True) self.emit(SIGNAL('ending_long_process(QString)'), "") if widgeteditor.isVisible() and widgeteditor.checkeolchars_enabled \ and sourcecode.has_mixed_eol_chars(text): name = os.path.basename(pythonfile) QMessageBox.warning(self, widgeteditor.title, _("<b>%s</b> contains mixed end-of-line " "characters.<br>Spyder will fix this " "automatically.") % name, QMessageBox.Ok) widgeteditor.set_os_eol_chars(index) widgeteditor.is_analysis_done = False finfo.editor.set_cursor_position('eof') finfo.editor.insert_text(os.linesep) return finfo, sedmlfile
def translate(combine, filename): sbmlstrlist = [] sedmlstrlist = [] outputstrlist = [] rePath = r"loadSBMLModel\((.*)\)" reFig = r"savefig\((.*)\)" outputstr = '"End of code generated by Import Combine plugin ' + time.strftime( "%m/%d/%Y") + '"\n"Extracted from ' + filename + '"\n' zipextloc, sbmlloclist, sedmlloclist = manifestsearch(combine) for i in range(len(sbmlloclist)): sbml = te.readFromFile(os.path.join(zipextloc, sbmlloclist[i])) try: transtext = te.sbmlToAntimony(sbml) except Exception as e: transtext = """*********************WARNING********************* Failed to translate the SBML model to Antimony string. Please check that the SBML file is valid. *********************WARNING*********************""" transtext = transtext + "\n\n" + str(e) sbmlstrlist.append(transtext) for j in range(len(sedmlloclist)): sedmlstr = te.sedmlToPython( os.path.join(zipextloc, sedmlloclist[j])) lines = sedmlstr.splitlines() for i, s in enumerate(lines): reSearchPath = re.split(rePath, s) if len(reSearchPath) > 1: s = s.replace("loadSBMLModel", "loada") s = s.replace(reSearchPath[1], "AntimonyModel") lines[i] = s lines.insert( i - 1, "AntimonyModel = '''\n" + sbmlstrlist[0] + "'''\n") for i, s in enumerate(lines): reSearchFig = re.split(reFig, s) if len(reSearchFig) > 1: del lines[i] sedmlstr = '\n'.join(lines) sedmlstrlist.append(sedmlstr) for k in range(len(sedmlstrlist)): outputstrlist.append(sedmlstrlist[k] + '\n\n' + outputstr) delseq(zipextloc) return outputstrlist
def load_and_translate(self, sedmlfile, pythonfile, editor, set_current=True): """ Read filename as SED-ML file, translate it to Python, and create an editor instance and return it *Warning* This is loading file, creating editor but not executing the source code analysis -- the analysis must be done by the editor plugin (in case multiple editorstack instances are handled) """ #sedmlfile = to_text_string(sedmlfile) sedmlfile = str(sedmlfile) self.emit(SIGNAL('starting_long_process(QString)'), _("Loading %s...") % sedmlfile) text, enc = encoding.read(sedmlfile) fname = os.path.basename(sedmlfile) temp = '"End of code generated by Import SED-ML plugin ' + time.strftime( "%m/%d/%Y") + '"\n"Extracted from ' + fname + '"\n\n' text = te.sedmlToPython(sedmlfile) + temp widgeteditor = editor.editorstacks[0] finfo = widgeteditor.create_new_editor(pythonfile, enc, text, set_current, new=True) index = widgeteditor.data.index(finfo) widgeteditor._refresh_outlineexplorer(index, update=True) self.emit(SIGNAL('ending_long_process(QString)'), "") if widgeteditor.isVisible() and widgeteditor.checkeolchars_enabled \ and sourcecode.has_mixed_eol_chars(text): name = os.path.basename(pythonfile) QMessageBox.warning( self, widgeteditor.title, _("<b>%s</b> contains mixed end-of-line " "characters.<br>Spyder will fix this " "automatically.") % name, QMessageBox.Ok) widgeteditor.set_os_eol_chars(index) widgeteditor.is_analysis_done = False finfo.editor.set_cursor_position('eof') finfo.editor.insert_text(os.linesep) return finfo, sedmlfile
def translate(combine, filename): sbmlstrlist = [] sedmlstrlist = [] outputstrlist = [] rePath = r"loadSBMLModel\((.*)\)" reFig = r"savefig\((.*)\)" outputstr = '"End of code generated by Import Combine plugin ' + time.strftime("%m/%d/%Y") + '"\n"Extracted from ' + filename + '"\n' zipextloc, sbmlloclist, sedmlloclist = manifestsearch(combine) for i in range(len(sbmlloclist)): sbml = te.readFromFile(zipextloc + sbmlloclist[i]) sbmlstrlist.append(te.sbmlToAntimony(sbml)) for j in range(len(sedmlloclist)): sedmlstr = te.sedmlToPython(zipextloc + sedmlloclist[j]) lines = sedmlstr.splitlines() for i,s in enumerate(lines): reSearchPath = re.split(rePath, s) if len(reSearchPath) > 1: s = s.replace("loadSBMLModel", "loada") s = s.replace(reSearchPath[1],"AntimonyModel") lines[i] = s lines.insert(i - 1, "AntimonyModel = '''\n" + sbmlstrlist[0] + "'''\n") for i,s in enumerate(lines): reSearchFig = re.split(reFig, s) if len(reSearchFig) > 1: del lines[i] sedmlstr = '\n'.join(lines) sedmlstrlist.append(sedmlstr) for k in range(len(sedmlstrlist)): outputstrlist.append(sedmlstrlist[k] + '\n\n' + outputstr) delseq(zipextloc) return outputstrlist
def load_and_translate(self, inputfile, pythonfile, editor, action, set_current=True): """ If the input is COMBINE archive, read filename as combine archive, unzip, translate, reconstitute in Python or PhrasedML, and create an editor instance and return it If the input is SED-ML file, read filename as SED-ML file, translate it to Python, and create an editor instance and return it *Warning* This is loading file, creating editor but not executing the source code analysis -- the analysis must be done by the editor plugin (in case multiple editorstack instances are handled) """ inputfile = str(inputfile) text, enc = encoding.read(inputfile) if action == 'c2p': fformat = '.py' text = Translatecombine2P(inputfile) zipextloctemp, sbmlloclisttemp, sedmlloclisttemp = manifestsearch( inputfile) elif action == 'c2pwp': fformat = '_phrasedml.py' text = Translatecombine2WP(inputfile) zipextloctemp, sbmlloclisttemp, sedmlloclisttemp = manifestsearch( inputfile) elif action == 's2p': fname = os.path.basename(inputfile) temp = '"End of code generated by Import SED-ML plugin ' + time.strftime( "%m/%d/%Y") + '"\n"Extracted from ' + fname + '"\n\n' text = te.sedmlToPython(inputfile) + temp else: fname = os.path.basename(inputfile) temp = '"End of code generated by Import SED-ML with PhrasedML plugin ' + time.strftime( '%m/%d/%Y') + '"\n"Extracted from ' + fname + '"' text = "import tellurium as te\n\nphrasedmlStr = '''" + pl.convertFile( inputfile ) + "'''\n\nte.executeSEDML(te.sedml.tephrasedml.phrasedml.convertString(phrasedmlStr))\n\n" + temp if action == 'c2p' or action == 'c2pwp': for i in range(len(text)): widgeteditor = editor.editorstacks[0] widgeteditor.starting_long_process.emit( _("Loading %s...") % inputfile) sedmlfname = os.path.basename(sedmlloclisttemp[i]) finfo = widgeteditor.create_new_editor( os.path.splitext(sedmlfname)[0] + fformat, enc, text[i], set_current, new=True) index = widgeteditor.data.index(finfo) widgeteditor._refresh_outlineexplorer(index, update=True) widgeteditor.ending_long_process.emit("") if widgeteditor.isVisible() and widgeteditor.checkeolchars_enabled \ and sourcecode.has_mixed_eol_chars(text[i]): if action == 'c2p': name = os.path.basename( os.path.splitext(sedmlfname)[0] + fformat) else: name = os.path.basename(pythonfile[:-3] + fformat) QMessageBox.warning( self, widgeteditor.title, _("<b>%s</b> contains mixed end-of-line " "characters.<br>Spyder will fix this " "automatically.") % name, QMessageBox.Ok) widgeteditor.set_os_eol_chars(index) widgeteditor.is_analysis_done = False finfo.editor.set_cursor_position('eof') finfo.editor.insert_text(os.linesep) else: widgeteditor = editor.editorstacks[0] widgeteditor.starting_long_process.emit( _("Loading %s...") % inputfile) finfo = widgeteditor.create_new_editor(pythonfile, enc, text, set_current, new=True) index = widgeteditor.data.index(finfo) widgeteditor._refresh_outlineexplorer(index, update=True) widgeteditor.ending_long_process.emit("") if widgeteditor.isVisible() and widgeteditor.checkeolchars_enabled \ and sourcecode.has_mixed_eol_chars(text): name = os.path.basename(pythonfile) QMessageBox.warning( self, widgeteditor.title, _("<b>%s</b> contains mixed end-of-line " "characters.<br>Spyder will fix this " "automatically.") % name, QMessageBox.Ok) widgeteditor.set_os_eol_chars(index) widgeteditor.is_analysis_done = False finfo.editor.set_cursor_position('eof') finfo.editor.insert_text(os.linesep) return finfo, inputfile