def test_long_string_model(self): long_string = '''--- name: Test model biomass: rxn_1 reactions: - id: rxn_1 equation: '|A_\u2206[e]| => |B[c]|' genes: - gene_1 - gene_2 - id: rxn_2_\u03c0 equation: '|B[c]| => |C[e]|' genes: 'gene_3 or (gene_4 and gene_5)' compounds: - id: A_\u2206 - id: B - id: C exchange: - compartment: e compounds: - id: A_\u2206 - id: C limits: - reaction: rxn_2_\u03c0 upper: 100 ''' m = native.ModelReader(long_string) self.assertEqual(m.name, 'Test model') self.assertEqual(m.biomass_reaction, 'rxn_1') self.assertEqual(m.extracellular_compartment, 'e') reactions = list(m.parse_reactions()) self.assertEqual(reactions[0].id, 'rxn_1')
def test_long_string_model_include(self): longString = '''--- name: Test model biomass: rxn_1 reactions: - include: exchange.yaml ''' m = native.ModelReader(longString) with self.assertRaises(context.ContextError): list(m.parse_reactions())
def setUp(self): reader = native.ModelReader({ 'compartments': [{ 'id': 'c', 'adjacent_to': 'e' }, { 'id': 'e' }], 'reactions': [{ 'id': 'rxn_1', 'equation': 'A[e] <=> B[c]' }, { 'id': 'rxn_2', 'equation': 'A[e] => C[c]' }, { 'id': 'rxn_3', 'equation': 'A[e] => D[e]' }, { 'id': 'rxn_4', 'equation': 'C[c] => D[e]' }], 'compounds': [{ 'id': 'A' }, { 'id': 'B' }, { 'id': 'C' }, { 'id': 'D' }], 'exchange': [{ 'compartment': 'e', 'compounds': [{ 'id': 'A', 'reaction': 'rxn_5' }, { 'id': 'D', 'reaction': 'rxn_6' }] }], 'model': [{ 'reactions': ['rxn_1', 'rxn_2'] }] }) self._model = reader.create_model()
def test_dict_model(self): dict_model = { 'name': 'Test model', 'biomass': 'rxn_1', 'reactions': [{ 'id': 'rxn_1', 'equation': '|A_\u2206[e]| => |B[c]|', 'genes': ['gene_1', 'gene_2'] }, { 'id': 'rxn_2_\u03c0', 'equation': '|B[c]| => |C[e]|', 'genes': 'gene_3 or (gene_4 and gene_5)' }], 'compounds': [{ 'id': 'A_\u2206' }, { 'id': 'B' }, { 'id': 'C' }], 'exchange': [{ 'compartment': 'e', 'compounds': [{ 'id': 'A_\u2206' }, { 'id': 'C' }] }], 'limits': [{ 'reaction': 'rxn_2_\u03c0', 'upper': 100 }] } dmodel = native.ModelReader(dict_model) self.assertEqual(dmodel.name, 'Test model') self.assertEqual(dmodel.biomass_reaction, 'rxn_1') self.assertEqual(dmodel.extracellular_compartment, 'e')
def test_parse_compartments(self): model_dict = { 'compartments': [{ 'id': 'e', 'name': 'Extracellular' }, { 'id': 'p', 'name': 'Periplasm', 'adjacent_to': ['e', 'c'] }, { 'id': 'c', 'name': 'Cytosol', 'adjacent_to': 'p' }, { 'id': 'internal', 'name': 'Internal compartment', 'adjacent_to': 'c' }] } reader = native.ModelReader(model_dict) compartment_iter, boundaries = reader.parse_compartments() compartments = list(compartment_iter) self.assertEqual(len(compartments), 4) self.assertEqual(compartments[0].id, 'e') self.assertEqual(compartments[0].name, 'Extracellular') self.assertEqual(compartments[1].id, 'p') self.assertEqual(compartments[1].name, 'Periplasm') self.assertEqual(compartments[2].id, 'c') self.assertEqual(compartments[2].name, 'Cytosol') self.assertEqual(compartments[3].id, 'internal') self.assertEqual(compartments[3].name, 'Internal compartment') normalized_boundaries = set( tuple(sorted((c1, c2))) for c1, c2 in boundaries) self.assertSetEqual(normalized_boundaries, {('c', 'internal'), ('c', 'p'), ('e', 'p')})
def test_invalid_model_type(self): with self.assertRaises(ValueError): native.ModelReader(42.2)
def setUp(self): reader = native.ModelReader({ 'name': 'Test model', 'biomass': 'rxn_1', 'compartments': [{ 'id': 'e', 'name': 'Extracellular', 'adjacent_to': ['c'] }, { 'id': 'c', 'name': 'Cytosol', 'adjacent_to': 'e' }], 'reactions': [{ 'id': 'rxn_1', 'name': 'Reaction 1', 'equation': '|A_\u2206[e]| => |B[c]|', 'genes': ['gene_1', 'gene_2'] }, { 'id': 'rxn_2_\u03c0', 'name': 'Reaction 2', 'equation': 'atp[c] + (2) |B[c]| <=> adp[c] + |C[e]|', 'genes': 'gene_3 or (gene_4 and gene_5)' }, { 'id': 'rxn_3', 'equation': 'D[c] => E[c]' }], 'compounds': [{ 'id': 'A_\u2206', 'name': 'Compound A', 'charge': 0 }, { 'id': 'B', 'name': 'Compound B', 'formula': 'H2O', 'charge': -1 }, { 'id': 'C', 'charge': -1, 'formula': 'O2' }, { 'id': 'atp', 'name': '\u2192 ATP ', 'charge': -4, 'formula': 'C10H12N5O13P3' }, { 'id': 'adp', 'name': ' ADP', 'charge': -3, 'formula': 'C10H12N5O10P2' }], 'exchange': [{ 'compartment': 'e', 'compounds': [{ 'id': 'A_\u2206' }, { 'id': 'C' }] }], 'limits': [{ 'reaction': 'rxn_2_\u03c0', 'upper': 100 }] }) self._model = reader.create_model() reader = native.ModelReader({ 'biomass': 'rxn_1', 'reactions': [{ 'id': 'rxn_1', 'equation': 'A[c] => B[c]' }], 'limits': [{ 'reaction': 'rxn_1', 'fixed': 10 }] }) self._infeasible_model = reader.create_model()