Exemplo n.º 1
0
class ReactionTestCase(unittest.TestCase):
    def setUp(self):
        self.r_empty = Reaction()
        self.r_prod = Reaction({"a": 1})
        self.r_dest = Reaction({"a": -1})
        self.r_1 = Reaction({"a": -1, "b": 1})
        self.r_1i = Reaction({"a": -1, "b": 1, "c": 0})
        self.r_2 = Reaction({"b": -1, "c": 1})
        self.r_3 = Reaction({"a": -1, "d": 2})
        self.r_4 = Reaction({"c": -1, "d": -1, "a": 1, "e": 2})

    def test_eq(self):
        self.assertEqual(self.r_1, self.r_1i)  # , "not equal to similar")
        self.assertNotEqual(self.r_3, self.r_4)  # , "equal to different")

    def test_rev(self):
        self.assertEqual(self.r_empty.reverse(), self.r_empty,
                         "empty reversed not empty")
        self.assertEqual(self.r_prod.reverse(), self.r_dest,
                         "reversed reaction not equal to similar")
        self.assertEqual(self.r_4.reverse(),
                         Reaction({
                             "c": 1,
                             "d": 1,
                             "a": -1,
                             "e": -2
                         }), "reversed reaction not equal to similar")
        self.assertEqual(self.r_3.reverse().reverse(), self.r_3,
                         "double reversal not identity")
Exemplo n.º 2
0
 def setUp(self):
     self.r_empty = Reaction()
     self.r_prod = Reaction({"a": 1})
     self.r_dest = Reaction({"a": -1})
     self.r_1 = Reaction({"a": -1, "b": 1})
     self.r_1i = Reaction({"a": -1, "b": 1, "c": 0})
     self.r_2 = Reaction({"b": -1, "c": 1})
     self.r_3 = Reaction({"a": -1, "d": 2})
     self.r_4 = Reaction({"c": -1, "d": -1, "a": 1, "e": 2})
Exemplo n.º 3
0
def parse(handle):
    """Parse a KEGG pathway map."""
    for line in handle:
        data, catalysts, reaction = line.split(":")
        catalysts = [(catalysts, )]
        reactants = {}
        before, after = reaction.split("<=>")
        compounds = before.split(" + ")
        for compound in compounds:
            compound = compound.strip()
            try:
                number, compound = compound.split()
                number = -int(number)
            except ValueError:
                number = -1
            reactants[compound] = number
        compounds = after.split(" + ")
        for compound in compounds:
            compound = compound.strip()
            try:
                number, compound = compound.split()
                number = int(number)
            except ValueError:
                number = +1
            reactants[compound] = number
        yield Reaction(reactants, catalysts, True, data)
Exemplo n.º 4
0
 def test_rev(self):
     self.assertEqual(self.r_empty.reverse(), self.r_empty,
                      "empty reversed not empty")
     self.assertEqual(self.r_prod.reverse(), self.r_dest,
                      "reversed reaction not equal to similar")
     self.assertEqual(self.r_4.reverse(),
                      Reaction({
                          "c": 1,
                          "d": 1,
                          "a": -1,
                          "e": -2
                      }), "reversed reaction not equal to similar")
     self.assertEqual(self.r_3.reverse().reverse(), self.r_3,
                      "double reversal not identity")
Exemplo n.º 5
0
class ReactionTestCase(unittest.TestCase):

    def setUp(self):
        self.r_empty = Reaction()
        self.r_prod = Reaction({"a": 1})
        self.r_dest = Reaction({"a": -1})
        self.r_1 = Reaction({"a": -1, "b": 1})
        self.r_1i = Reaction({"a": -1, "b": 1, "c": 0})
        self.r_2 = Reaction({"b": -1, "c": 1})
        self.r_3 = Reaction({"a": -1, "d": 2})
        self.r_4 = Reaction({"c": -1, "d": -1, "a": 1, "e": 2})

    def testEq(self):
        self.assertEqual(self.r_1, self.r_1i)  # , "not equal to similar")
        self.assertNotEqual(self.r_3, self.r_4)  # , "equal to different")

    def testRev(self):
        self.assertEqual(self.r_empty.reverse(), self.r_empty, "empty reversed not empty")
        self.assertEqual(self.r_prod.reverse(), self.r_dest,
                          "reversed reaction not equal to similar")
        self.assertEqual(self.r_4.reverse(), Reaction({"c": 1, "d": 1, "a": -1, "e": -2}),
                         "reversed reaction not equal to similar")
        self.assertEqual(self.r_3.reverse().reverse(), self.r_3,
                          "double reversal not identity")
Exemplo n.º 6
0
 def setUp(self):
     self.r_empty = Reaction()
     self.r_prod = Reaction({"a": 1})
     self.r_dest = Reaction({"a": -1})
     self.r_1 = Reaction({"a": -1, "b": 1})
     self.r_1i = Reaction({"a": -1, "b": 1, "c": 0})
     self.r_2 = Reaction({"b": -1, "c": 1})
     self.r_3 = Reaction({"a": -1, "d": 2})
     self.r_4 = Reaction({"c": -1, "d": -1, "a": 1, "e": 2})