Esempio n. 1
0
    def testGetXMLString(self):
        def test(xml):
            reader = tesbml.SBMLReader()
            document = reader.readSBMLFromString(xml)
            util.checkSBMLDocument(document)
            model = document.getModel()
            self.assertTrue('Reaction' in str(type(model.getReaction(0))))

        def getString(path):
            with open(path, 'r') as fd:
                lines = '\n'.join(fd.readlines())
            return lines

        #
        for path in [cn.TEST_FILE2, cn.TEST_FILE3]:
            test(util.getXML(path))
            test(util.getXML(getString(path)))
Esempio n. 2
0
 def testIsSBMLModel(self):
     return
     self.assertFalse(util.isSBMLModel("dummy"))
     xml = util.getXML(cn.TEST_FILE2)
     reader = tesbml.SBMLReader()
     document = reader.readSBMLFromString(xml)
     util.checkSBMLDocument(document)
     model = document.getModel()
     self.assertTrue(util.isSBMLModel(model))
Esempio n. 3
0
 def initialize(self, model_reference):
     """
 Initializes the instance variables in the model.
 :param str or libsbml.model: for str may be path or model string
    and file/str may be xml or antimony.
 """
     if util.isSBMLModel(model_reference):
         model = model_reference
     else:
         xml = util.getXML(model_reference)
         reader = libsbml.SBMLReader()
         document = reader.readSBMLFromString(xml)
         util.checkSBMLDocument(document, model_reference=model_reference)
         model = document.getModel()
     # Do the initializations
     self.reactions = self._getReactions(model)
     self.molecules = self._getMolecules()
     self.moietys = self._getMoietys()
Esempio n. 4
0
def prettyPrint(model_reference, file_out=sys.stdout, **kwargs):
    """
  Prints the reactions in a model.
  :param str model_reference: file, xml string, antimony string
  :param dict kwargs: arguments to Reaction.getId
  """
    xml = util.getXML(model_reference)
    reader = libsbml.SBMLReader()
    document = reader.readSBMLFromString(xml)
    util.checkSBMLDocument(document)
    model = document.getModel()
    simple = SimpleSBML()
    simple.initialize(model)
    stgs = []
    for reaction in simple.reactions:
        stg = reaction.getId(**kwargs)
        stgs.append(stg)
        file_out.write("%s\n" % stg)
    return stgs
Esempio n. 5
0
def lint(model_reference=None,
         file_out=sys.stdout,
         mass_balance_check=GAMES,
         config_fid=None,
         is_report=True,
         implicit_games=False):
    """
  Reports on errors found in a model
  :param str model_reference: 
      libsbml_model file in
      file, antimony string, xml string
  :param TextIOWrapper model_fid: fid for an XML file
  :param TextIOWrapper file_out:
  :param str mass_balance_check: how check for mass balance
  :param TextIOWrapper config_fid: readable stream
  :param bool is_report: print result
  :return MoietyComparatorResult/null/None:
  """
    config.setConfiguration(fid=config_fid)
    config_dct = config.getConfiguration()
    if util.isSBMLModel(model_reference):
        model = model_reference
    else:
        xml = util.getXML(model_reference)
        reader = libsbml.SBMLReader()
        document = reader.readSBMLFromString(xml)
        util.checkSBMLDocument(document)
        model = document.getModel()
    #
    simple = SimpleSBML()
    simple.initialize(model)
    if mass_balance_check == cn.MOIETY_ANALYSIS:
        result = MoietyComparator.analyzeReactions(simple)
        if is_report:
            for line in result.report.split('\n'):
                file_out.write("%s\n" % line)
        return result
    elif mass_balance_check == GAMES:
        if implicit_games:
            for ignored in config_dct[cn.CFG_IGNORED_MOLECULES]:
                simple = removeIgnored(simple, ignored)
        m = GAMES_PP(simple)
        games_result = m.analyze(simple.reactions)
        if games_result and is_report:
            gr = GAMESReport(
                m, explain_threshold=config_dct[cn.CFG_GAMES_THRESHOLD])
            errortype_dic = {
                TYPE_I: gr.reportTypeOneError,
                TYPE_II: gr.reportTypeTwoError,
                TYPE_III: gr.reportTypeThreeError,
                CANCELING: gr.reportCancelingError,
                ECHELON: gr.reportEchelonError
            }
            for errors in m.error_summary:
                for category in errortype_dic.keys():
                    if errors.type == category:
                        func = errortype_dic[category]
                        report, _ = func(errors.errors, explain_details=True)
                        print(report)
        return games_result
    else:
        print("Specified method doesn't exist")
        return None