def setUp(self): self.model = native.NativeModel() self.model.reactions.update([ entry.DictReactionEntry({ 'id': 'EX_g6p', 'equation': parse_reaction('g6p[e] <=>') }), entry.DictReactionEntry({ 'id': 'EX_glc-D', 'equation': parse_reaction('glc-D[e] <=>') }), entry.DictReactionEntry({ 'id': 'SINK_glc-D', 'equation': parse_reaction('glc-D[c] <=>') }), entry.DictReactionEntry({ 'id': 'rxn_1', 'equation': parse_reaction('g6p[c] <=> glc-D[c]') }), entry.DictReactionEntry({ 'id': 'TP_glc-D', 'equation': parse_reaction('glc-D[c] <=> glc-D[e]') }) ])
def test_write_reactions(self): stream = StringIO() reactions = [ entry.DictReactionEntry({ 'id': 'r1', 'name': 'Reaction 1', 'equation': Reaction(Direction.Both, {}) }), entry.DictReactionEntry({ 'id': 'r2', 'name': 'Reaction 2', 'equation': Reaction(Direction.Forward, { Compound('c1', 'c'): -1, Compound('c2', 'c'): 2 }) }) ] self.writer.write_reactions(stream, reactions) # The reaction equation for r1 is invalid (no compounds) and is # therefore skipped. self.assertEqual(yaml.safe_load(stream.getvalue()), [{ 'id': 'r1', 'name': 'Reaction 1' }, { 'id': 'r2', 'name': 'Reaction 2', 'equation': 'c1[c] => (2) c2[c]' }])
def test_merge(self): model = native.NativeModel() model.compounds.update([ entry.DictCompoundEntry({ 'id': 'g6p_c', 'name': 'G6P' }), entry.DictCompoundEntry({ 'id': 'g6p_e', 'name': 'G6P' }) ]) model.reactions.update([ entry.DictReactionEntry({ 'id': 'TP_g6p', 'equation': parse_reaction('g6p_c[c] <=> g6p_e[e]') }) ]) exchange_compound = Compound('g6p_e', 'e') model.exchange[exchange_compound] = (exchange_compound, 'EX_g6p_e', -10, 0) sbml.merge_equivalent_compounds(model) self.assertEqual({entry.id for entry in model.compounds}, {'g6p'}) self.assertEqual(model.reactions['TP_g6p'].equation, parse_reaction('g6p[c] <=> g6p[e]')) new_exchange_compound = Compound('g6p', 'e') self.assertEqual(model.exchange[new_exchange_compound], (new_exchange_compound, 'EX_g6p_e', -10, 0))
def test_use_reaction_dict_entry_setters(self): e = entry.DictReactionEntry({}, id='reaction_1') e.name = 'Reaction 1' e.equation = 'A => B' e.genes = 'gene_1 and gene_2' self.assertEqual(e.name, 'Reaction 1') self.assertEqual(e.equation, 'A => B') self.assertEqual(e.genes, 'gene_1 and gene_2') self.assertEqual(e.properties['genes'], 'gene_1 and gene_2')
def test_convert_reaction_entry(self): equation = Reaction(Direction.Both, { Compound('c1', 'c'): -1, Compound('c2', 'c'): 1 }) reaction = entry.DictReactionEntry({ 'id': 'rxn01234', 'name': 'Test reaction', 'equation': equation, 'custom_property': -34, 'another_custom_property': None }) d = self.writer.convert_reaction_entry(reaction) self.assertIsInstance(d, OrderedDict) self.assertEqual(d['id'], 'rxn01234') self.assertEqual(d['name'], 'Test reaction') self.assertEqual(d['equation'], equation) self.assertEqual(d['custom_property'], -34) self.assertNotIn('another_custom_property', d)
def test_create_reaction_entry_from_compound_entry(self): e = entry.DictCompoundEntry({'id': 'compound_1', 'name': 'Compound 1'}) with self.assertRaises(ValueError): e2 = entry.DictReactionEntry(e)
def test_create_reaction_entry(self): props = {'id': 'reaction_1', 'name': 'Reaction 1'} e = entry.DictReactionEntry(props) self.assertIsInstance(e, entry.ReactionEntry) self.assertEqual(e.id, 'reaction_1') self.assertEqual(e.name, 'Reaction 1')