def translate(combine, filename):
        sbmlstrlist = []
        sedmlstrlist = []
        outputstrlist = []
        outputstr = "# -*- coding: utf-8 -*-\n\n" + '"Generated by Import Combine with PhrasedML plugin ' + time.strftime(
            "%m/%d/%Y"
        ) + '"\n"Extracted from ' + filename + '"\n\n# Translated SBML\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 = pl.convertFile(zipextloc + sedmlloclist[j])
            sedmlstr = sedmlstr.replace('"compartment"', '"compartment_"')
            sedmlstr = sedmlstr.replace("'compartment'", "'compartment_'")
            sedmlstrlist.append(sedmlstr)

        for k in range(len(sedmlstrlist)):
            outputstrlist.append(outputstr + "AntimonyModel = '''\n" +
                                 sbmlstrlist[0] +
                                 "'''\n\nPhrasedMLstr = '''\n" +
                                 sedmlstrlist[k] + "'''")

        delseq(zipextloc)
        return outputstrlist
 def load_and_translate(self, sedmlfile, pythonfile, editor, set_current=True):
     """
     Read filename as SED-ML file, translate it to PhrasedML, 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 =  '# -*- coding: utf-8 -*-\n\n' + "'Generated by Import SED-ML with PhrasedML plugin " + time.strftime('%m/%d/%Y') + "'\n'Extracted from " + fname + "'\n\n'''"
     text = temp + pl.convertFile(sedmlfile) + "'''"
     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
Beispiel #3
0
    def translate(combine, filename):
        sbmlstrlist = []
        sedmlstrlist = []
        outputstrlist = []
        outputstr = '"End of code generated by Import Combine as PhrasedML 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 = pl.convertFile(os.path.join(zipextloc, sedmlloclist[j]))
            sedmlstr = sedmlstr.replace('"compartment"', '"compartment_"')
            sedmlstr = sedmlstr.replace("'compartment'", "'compartment_'")
            sedmlstrlist.append(sedmlstr)

        for k in range(len(sedmlstrlist)):
            outputstrlist.append(
                "AntimonyModel = '''\n" + sbmlstrlist[0] +
                "'''\n\nPhrasedMLstr = '''\n" + sedmlstrlist[k] +
                "'''\n\nimport tellurium as te\n\nexp = te.experiment([AntimonyModel], [PhrasedMLstr])\nexp.execute(PhrasedMLstr)\n\n"
                + outputstr)

        delseq(zipextloc)
        return outputstrlist
Beispiel #4
0
 def toPhrasedml(self):
     if self.sedml_str:
         result = phrasedml.convertString(self.sedml_str)
         if result is None:
             raise RuntimeError(phrasedml.getLastError())
         return self.fixModelRefs(phrasedml.getLastPhraSEDML())
     elif self.sedml_path:
         result = phrasedml.convertFile(self.sedml_str)
         if result is None:
             raise RuntimeError(phrasedml.getLastError())
         return self.fixModelRefs(phrasedml.getLastPhraSEDML())
Beispiel #5
0
 def load_and_translate(self,
                        sedmlfile,
                        pythonfile,
                        editor,
                        set_current=True):
     """
     Read filename as SED-ML file, translate it to PhrasedML, 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 with PhrasedML plugin ' + time.strftime(
         '%m/%d/%Y') + '"\n"Extracted from ' + fname + '"'
     text = "import tellurium as te\n\nphrasedmlStr = '''" + pl.convertFile(
         sedmlfile
     ) + "'''\n\nte.executeSEDML(te.sedml.tephrasedml.phrasedml.convertString(phrasedmlStr))\n\n" + 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 toPhrasedml(self):
     # assign sbml resources
     # print('toPhrasedml sbml resources:')
     phrasedml.clearReferencedSBML()
     for sbml_resource in self.sbml_map:
         # print('  {} -> {}'.format(sbml_resource, self.sbml_map[sbml_resource][:30]))
         phrasedml.setReferencedSBML(sbml_resource, self.sbml_map[sbml_resource])
     # convert to phrasedml
     if self.sedml_str:
         result = phrasedml.convertString(self.sedml_str)
         if result is None:
             raise RuntimeError(phrasedml.getLastError())
         return self.fixModelRefs(phrasedml.getLastPhraSEDML())
     elif self.sedml_path:
         result = phrasedml.convertFile(self.sedml_str)
         if result is None:
             raise RuntimeError(phrasedml.getLastError())
         return self.fixModelRefs(phrasedml.getLastPhraSEDML())
 def toPhrasedml(self):
     # assign sbml resources
     # print('toPhrasedml sbml resources:')
     phrasedml.clearReferencedSBML()
     for sbml_resource in self.sbml_map:
         # print('  {} -> {}'.format(sbml_resource, self.sbml_map[sbml_resource][:30]))
         phrasedml.setReferencedSBML(sbml_resource, self.sbml_map[sbml_resource])
     # convert to phrasedml
     if self.sedml_str:
         result = phrasedml.convertString(self.sedml_str)
         if result is None:
             raise RuntimeError(phrasedml.getLastError())
         return self.fixModelRefs(phrasedml.getLastPhraSEDML())
     elif self.sedml_path:
         result = phrasedml.convertFile(self.sedml_str)
         if result is None:
             raise RuntimeError(phrasedml.getLastError())
         return self.fixModelRefs(phrasedml.getLastPhraSEDML())
 def translate(combine, filename):
     sbmlstrlist = []
     sedmlstrlist = []
     outputstrlist = []
     outputstr = "# -*- coding: utf-8 -*-\n\n" + '"Generated by Import Combine with PhrasedML plugin ' + time.strftime("%m/%d/%Y") + '"\n"Extracted from ' + filename + '"\n\n# Translated SBML\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 = pl.convertFile(zipextloc + sedmlloclist[j])
         sedmlstr = sedmlstr.replace('"compartment"', '"compartment_"')
         sedmlstr = sedmlstr.replace("'compartment'", "'compartment_'")
         sedmlstrlist.append(sedmlstr)
     
     for k in range(len(sedmlstrlist)):
         outputstrlist.append(outputstr + "AntimonyModel = '''\n" + sbmlstrlist[0] + "'''\n\nPhrasedMLstr = '''\n" + sedmlstrlist[k] + "'''")
     
     delseq(zipextloc)
     return outputstrlist
Beispiel #9
0
 def translate(combine, filename):
     sbmlstrlist = []
     sedmlstrlist = []
     outputstrlist = []
     outputstr = '"End of code generated by Import Combine as PhrasedML 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 = pl.convertFile(zipextloc + sedmlloclist[j])
         sedmlstr = sedmlstr.replace('"compartment"', '"compartment_"')
         sedmlstr = sedmlstr.replace("'compartment'", "'compartment_'")
         sedmlstrlist.append(sedmlstr)
     
     for k in range(len(sedmlstrlist)):
         outputstrlist.append("AntimonyModel = '''\n" + sbmlstrlist[0] + "'''\n\nPhrasedMLstr = '''\n" + sedmlstrlist[k] + 
         "'''\n\nimport tellurium as te\n\nexp = te.experiment([AntimonyModel], [PhrasedMLstr])\nexp.execute(PhrasedMLstr)\n\n" + outputstr)
     
     delseq(zipextloc)
     return outputstrlist
Beispiel #10
0
 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