def testConstructorWithError(self):
     if IGNORE_TEST:
         return
     shim = SBMLShim(sbmlstr="", is_ignore_errors=True)
     self.assertIsNone(shim._exception)
     with self.assertRaises(Exception):
         SBMLShim(sbmlstr="")
 def testCreateReaction(self):
     if IGNORE_TEST:
         return
     reactants = ["A"]
     products = ["B", "C"]
     sbmlstr = SBMLShim.createSBMLReaction(reactants, products)
     shim = SBMLShim(sbmlstr=sbmlstr)
     self.assertTrue(len(shim.getReactants(0)), len(reactants))
     self.assertTrue(len(shim.getProducts(0)), len(products))
 def _testTransformStatistic(self, reactants, products, key, value):
     """
 :param list-of-str reactants:
 :param list-of-str products:
 :param str key: key in the result
 :param float value: value in the result
 """
     sbmlstr = SBMLShim.createSBMLReaction(reactants, products)
     shim = SBMLShim(sbmlstr=sbmlstr)
     complex = ComplexTransformationReactionStatistic(shim)
     self.assertEqual(complex._addValues({}, 0)[key], [value])
 def testGetReactionIndicies(self):
     antimonystr = '''
 A -> B; 1
 C -> D; 1
 A = 1
 B = 1
 C = 1
 D =1
 '''
     sbmlstr = SBMLShim.createSBML(antimonystr)
     shim = SBMLShim(sbmlstr=sbmlstr)
     reaction_indicies = shim.getReactionIndicies()
     self.assertEqual(len(reaction_indicies), 2)
Exemple #5
0
 def next(self):
   """
   :return SBMLShim: next bio model
   :raises StopIteration:
   """
   if self._idx < len(self._ids):
     shim = SBMLShim.getShimForBiomodel(self._ids[self._idx])
     self._idx += 1
     return shim
   else:
     raise StopIteration()
 def testcreateSBML(self):
     if IGNORE_TEST:
         return
     sbmlstr = SBMLShim.createSBML("A + B -> C; 1")
     shim = SBMLShim(sbmlstr=sbmlstr)
     reaction = shim.getReactions()[0]
     reactants = set([r.getSpecies() for r in shim.getReactants(reaction)])
     self.assertEqual(reactants, set(["A", "B"]))
     self.assertEqual(shim.getProducts(reaction)[0].getSpecies(), "C")
 def setUp(self):
     self.shim = SBMLShim(filepath=TEST_FILE)
 def testStatisticError(self):
     shim = SBMLShim.getShimForBiomodel("BIOMD0000000020")
     statistics = Statistic.getAllStatistics(self.shim)
     self.assertTrue(len(statistics.keys()) > 10)
 def testReactionStatisticError(self):
     #if IGNORE_TEST:
     #  return
     shim = SBMLShim.getShimForBiomodel("BIOMD0000000020")
     statistics = Statistic.getAllStatistics(shim)
     self.assertEqual(statistics["Num_Reactions"], 0)
 def testGetShimForBiomodel(self):
     if IGNORE_TEST:
         return
     shim = SBMLShim.getShimForBiomodel(BIOMODEL)
     self.assertTrue(len(shim.getReactions()) > 0)
     self.assertEqual(shim.getBiomodelId(), BIOMODEL)
class TestSBMLShim(unittest.TestCase):
    def setUp(self):
        self.shim = SBMLShim(filepath=TEST_FILE)

    def testConstructorWithFile(self):
        if IGNORE_TEST:
            return
        self.assertEqual(len(self.shim.getReactions()), NUM_REACTIONS)
        for reaction in self.shim.getReactions():
            self.assertTrue(isinstance(reaction, libsbml.Reaction))
            self.assertLessEqual(reaction.getNumReactants(), MAX_REACTANTS)
        self.assertEqual(len(self.shim.getParameters()), NUM_PARAMETERS)
        for parameter in self.shim.getParameters():
            self.assertTrue(isinstance(parameter, libsbml.Parameter))

    def testConstructorWithError(self):
        if IGNORE_TEST:
            return
        shim = SBMLShim(sbmlstr="", is_ignore_errors=True)
        self.assertIsNone(shim._exception)
        with self.assertRaises(Exception):
            SBMLShim(sbmlstr="")

    def testGetShimForBiomodel(self):
        if IGNORE_TEST:
            return
        shim = SBMLShim.getShimForBiomodel(BIOMODEL)
        self.assertTrue(len(shim.getReactions()) > 0)
        self.assertEqual(shim.getBiomodelId(), BIOMODEL)

    def testcreateSBML(self):
        if IGNORE_TEST:
            return
        sbmlstr = SBMLShim.createSBML("A + B -> C; 1")
        shim = SBMLShim(sbmlstr=sbmlstr)
        reaction = shim.getReactions()[0]
        reactants = set([r.getSpecies() for r in shim.getReactants(reaction)])
        self.assertEqual(reactants, set(["A", "B"]))
        self.assertEqual(shim.getProducts(reaction)[0].getSpecies(), "C")

    def testCreateReaction(self):
        if IGNORE_TEST:
            return
        reactants = ["A"]
        products = ["B", "C"]
        sbmlstr = SBMLShim.createSBMLReaction(reactants, products)
        shim = SBMLShim(sbmlstr=sbmlstr)
        self.assertTrue(len(shim.getReactants(0)), len(reactants))
        self.assertTrue(len(shim.getProducts(0)), len(products))

    def testGetReactionIndicies(self):
        antimonystr = '''
    A -> B; 1
    C -> D; 1
    A = 1
    B = 1
    C = 1
    D =1
    '''
        sbmlstr = SBMLShim.createSBML(antimonystr)
        shim = SBMLShim(sbmlstr=sbmlstr)
        reaction_indicies = shim.getReactionIndicies()
        self.assertEqual(len(reaction_indicies), 2)

    def testExecFunction(self):
        num_errors = self.shim.execFunction("getNumErrors")
        self.assertEqual(num_errors, 0)
        num_params = self.shim.execFunction("getNumParameters",
                                            attribute="model")
        self.assertGreater(num_params, 0)