本文整理汇总了Python中psamm.database.DictDatabase.get_reaction方法的典型用法代码示例。如果您正苦于以下问题:Python DictDatabase.get_reaction方法的具体用法?Python DictDatabase.get_reaction怎么用?Python DictDatabase.get_reaction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类psamm.database.DictDatabase
的用法示例。
在下文中一共展示了DictDatabase.get_reaction方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestMetabolicDatabase
# 需要导入模块: from psamm.database import DictDatabase [as 别名]
# 或者: from psamm.database.DictDatabase import get_reaction [as 别名]
class TestMetabolicDatabase(unittest.TestCase):
def setUp(self):
self.database = DictDatabase()
self.database.set_reaction('rxn_1', parse_reaction('=> (2) |A|'))
self.database.set_reaction('rxn_2', parse_reaction('|A| <=> |B|'))
self.database.set_reaction('rxn_3', parse_reaction('|A| => |D[e]|'))
self.database.set_reaction('rxn_4', parse_reaction('|A| => |C|'))
self.database.set_reaction('rxn_5', parse_reaction('|C| => |D[e]|'))
self.database.set_reaction('rxn_6', parse_reaction('|D[e]| =>'))
def test_reactions(self):
self.assertEqual(
set(self.database.reactions),
{'rxn_1', 'rxn_2', 'rxn_3', 'rxn_4', 'rxn_5', 'rxn_6'})
def test_compounds(self):
self.assertEqual(
set(self.database.compounds),
{Compound('A'), Compound('B'), Compound('C'), Compound('D', 'e')})
def test_compartments(self):
self.assertEqual(set(self.database.compartments), {None, 'e'})
def test_has_reaction_existing(self):
self.assertTrue(self.database.has_reaction('rxn_3'))
def test_has_reaction_not_existing(self):
self.assertFalse(self.database.has_reaction('rxn_7'))
def test_is_reversible_is_true(self):
self.assertTrue(self.database.is_reversible('rxn_2'))
def test_is_reversible_is_false(self):
self.assertFalse(self.database.is_reversible('rxn_5'))
def test_get_reaction_values(self):
self.assertEqual(set(self.database.get_reaction_values('rxn_2')),
{ (Compound('A'), -1), (Compound('B'), 1) })
def test_get_compound_reactions(self):
self.assertEqual(set(self.database.get_compound_reactions(Compound('A'))),
{ 'rxn_1', 'rxn_2', 'rxn_3', 'rxn_4' })
def test_reversible(self):
self.assertEqual(set(self.database.reversible), { 'rxn_2' })
def test_get_reaction(self):
reaction = parse_reaction('|A| => |D[e]|')
self.assertEqual(self.database.get_reaction('rxn_3'), reaction)
def test_set_reaction_with_zero_coefficient(self):
reaction = Reaction(
Direction.Both, [(Compound('A'), 1), (Compound('B'), 0)],
[(Compound('C'), 1)])
self.database.set_reaction('rxn_new', reaction)
self.assertNotIn('rxn_new', self.database.get_compound_reactions(Compound('B')))
def test_matrix_get_item(self):
self.assertEqual(self.database.matrix[Compound('A'), 'rxn_1'], 2)
self.assertEqual(self.database.matrix[Compound('A'), 'rxn_2'], -1)
self.assertEqual(self.database.matrix[Compound('B'), 'rxn_2'], 1)
self.assertEqual(self.database.matrix[Compound('A'), 'rxn_4'], -1)
self.assertEqual(self.database.matrix[Compound('C'), 'rxn_4'], 1)
self.assertEqual(self.database.matrix[Compound('C'), 'rxn_5'], -1)
self.assertEqual(self.database.matrix[Compound('D', 'e'), 'rxn_5'], 1)
def test_matrix_get_item_invalid_key(self):
with self.assertRaises(KeyError):
a = self.database.matrix[Compound('A'), 'rxn_5']
with self.assertRaises(KeyError):
b = self.database.matrix['rxn_1']
def test_matrix_set_item_is_invalid(self):
with self.assertRaises(TypeError):
self.database.matrix[Compound('A'), 'rxn_1'] = 4
def test_matrix_iter(self):
matrix_keys = { (Compound('A'), 'rxn_1'),
(Compound('A'), 'rxn_2'),
(Compound('B'), 'rxn_2'),
(Compound('A'), 'rxn_3'),
(Compound('D', 'e'), 'rxn_3'),
(Compound('A'), 'rxn_4'),
(Compound('C'), 'rxn_4'),
(Compound('C'), 'rxn_5'),
(Compound('D', 'e'), 'rxn_5'),
(Compound('D', 'e'), 'rxn_6') }
self.assertEqual(set(iter(self.database.matrix)), matrix_keys)
def test_matrix_len(self):
self.assertEqual(len(self.database.matrix), 10)