def test_room_with_reaction_filter(self): original_objective = self.model.objective pfba_solution = pfba(self.model) solution = room(self.model, reference=pfba_solution, reactions=['EX_o2_LPAREN_e_RPAREN_', 'EX_glc_LPAREN_e_RPAREN_']) self.assertEqual(len(solution.fluxes), 2) self.assertIs(self.model.objective, original_objective)
def test_room_with_reaction_filter(self): original_objective = self.model.objective pfba_solution = pfba(self.model) solution = room(self.model, reference=pfba_solution, reactions=['EX_o2_LPAREN_e_RPAREN_', 'EX_glc_LPAREN_e_RPAREN_']) self.assertEqual(len(solution.fluxes), 2) self.assertIs(self.model.objective, original_objective)
def test_room_shlomi_2005(self): reference = { "b1": -10, "v1": 10, "v2": 5, "v3": 0, "v4": 0, "v5": 0, "v6": 5, "b2": 5, "b3": 5 } TOY_MODEL_PAPIN_2004.solver = self.model.solver.interface with TimeMachine() as tm: TOY_MODEL_PAPIN_2004.reactions.v6.knock_out(tm) result = room(TOY_MODEL_PAPIN_2004, reference=reference, delta=0, epsilon=0) self.assertEquals( result.fluxes, { 'b1': 10.0, 'b2': 5.0, 'b3': 5.0, 'v1': 5.0, 'v2': 5.0, 'v3': 0.0, 'v4': 5.0, 'v5': 5.0, 'v6': 0.0 })
def test_room_shlomi_2005(self, toy_model): original_objective = toy_model.objective reference = { "b1": 10, "v1": 10, "v2": 5, "v3": 0, "v4": 0, "v5": 0, "v6": 5, "b2": 5, "b3": 5 } expected = { 'b1': 10.0, 'b2': 5.0, 'b3': 5.0, 'v1': 10.0, 'v2': 5.0, 'v3': 0.0, 'v4': 5.0, 'v5': 5.0, 'v6': 0.0 } with TimeMachine() as tm: toy_model.reactions.v6.knock_out(tm) result = room(toy_model, reference=reference, delta=0, epsilon=0) for k in reference.keys(): assert abs(expected[k] - result.fluxes[k]) < 0.1, "%s: %f | %f" assert toy_model.objective is original_objective
def test_room(self, core_model): original_objective = core_model.objective pfba_solution = pfba(core_model) solution = room(core_model, reference=pfba_solution) assert abs(0 - solution.objective_value) < 1e-6, \ "room objective without knockouts must be 0 (was %f)" % solution.objective_value assert core_model.objective is original_objective
def test_room(self): original_objective = self.model.objective pfba_solution = pfba(self.model) solution = room(self.model, reference=pfba_solution) self.assertAlmostEqual(0, solution.objective_value, delta=1e-6, msg="room objective without knockouts must be 0 (was %f)" % solution.objective_value) self.assertIs(self.model.objective, original_objective)
def test_room_with_reaction_filter(self, core_model): original_objective = core_model.objective pfba_solution = pfba(core_model) solution = room(core_model, reference=pfba_solution, reactions=['EX_o2_LPAREN_e_RPAREN_', 'EX_glc_LPAREN_e_RPAREN_']) assert len(solution.fluxes) == 2 assert core_model.objective.expression == original_objective.expression assert not any(v.name.startswith("y_") for v in core_model.solver.variables)
def test_room_with_reaction_filter(self, core_model): original_objective = core_model.objective pfba_solution = pfba(core_model) solution = room(core_model, reference=pfba_solution, reactions=['EX_o2_LPAREN_e_RPAREN_', 'EX_glc_LPAREN_e_RPAREN_']) assert len(solution.fluxes) == 2 assert core_model.objective.expression == original_objective.expression assert not any(v.name.startswith("y_") for v in core_model.solver.variables)
def test_room(self): original_objective = self.model.objective pfba_solution = pfba(self.model) solution = room(self.model, reference=pfba_solution) self.assertAlmostEqual(0, solution.objective_value, delta=1e-6, msg="room objective without knockouts must be 0 (was %f)" % solution.objective_value) self.assertIs(self.model.objective, original_objective)
def test_room_with_reaction_filter(self, core_model): original_objective = core_model.objective pfba_solution = pfba(core_model) solution = room( core_model, reference=pfba_solution, reactions=['EX_o2_LPAREN_e_RPAREN_', 'EX_glc_LPAREN_e_RPAREN_']) assert len(solution.fluxes) == 2 assert core_model.objective is original_objective
def test_room(self, core_model): original_objective = core_model.objective pfba_solution = pfba(core_model) solution = room(core_model, reference=pfba_solution) assert abs(0 - solution.objective_value) < 1e-6, \ "room objective without knockouts must be 0 (was %f)" % solution.objective_value assert core_model.objective.expression == original_objective.expression assert not any(v.name.startswith("y_") for v in core_model.solver.variables) assert not any(c.name.startswith("moma_const_") for c in core_model.solver.constraints)
def test_room(self, core_model): original_objective = core_model.objective pfba_solution = pfba(core_model) solution = room(core_model, reference=pfba_solution) assert abs(0 - solution.objective_value) < 1e-6, \ "room objective without knockouts must be 0 (was %f)" % solution.objective_value assert core_model.objective.expression == original_objective.expression assert not any(v.name.startswith("y_") for v in core_model.solver.variables) assert not any(c.name.startswith("moma_const_") for c in core_model.solver.constraints)
def test_room_shlomi_2005(self): reference = {"b1": -10, "v1": 10, "v2": 5, "v3": 0, "v4": 0, "v5": 0, "v6": 5, "b2": 5, "b3": 5} TOY_MODEL_PAPIN_2004.solver = self.model.solver.interface with TimeMachine() as tm: TOY_MODEL_PAPIN_2004.reactions.v6.knock_out(tm) result = room(TOY_MODEL_PAPIN_2004, reference=reference, delta=0, epsilon=0) self.assertEquals( result.fluxes, {'b1': 10.0, 'b2': 5.0, 'b3': 5.0, 'v1': 5.0, 'v2': 5.0, 'v3': 0.0, 'v4': 5.0, 'v5': 5.0, 'v6': 0.0})
def test_room_shlomi_2005(self): original_objective = self.model.objective reference = {"b1": 10, "v1": 10, "v2": 5, "v3": 0, "v4": 0, "v5": 0, "v6": 5, "b2": 5, "b3": 5} expected = {'b1': 10.0, 'b2': 5.0, 'b3': 5.0, 'v1': 10.0, 'v2': 5.0, 'v3': 0.0, 'v4': 5.0, 'v5': 5.0, 'v6': 0.0} TOY_MODEL_PAPIN_2003.solver = self.model.solver.interface with TimeMachine() as tm: TOY_MODEL_PAPIN_2003.reactions.v6.knock_out(tm) result = room(TOY_MODEL_PAPIN_2003, reference=reference, delta=0, epsilon=0) for k in reference.keys(): self.assertAlmostEqual(expected[k], result.fluxes[k], delta=0.1, msg="%s: %f | %f") self.assertIs(self.model.objective, original_objective)
def test_room_shlomi_2005(self): original_objective = self.model.objective reference = {"b1": 10, "v1": 10, "v2": 5, "v3": 0, "v4": 0, "v5": 0, "v6": 5, "b2": 5, "b3": 5} expected = {'b1': 10.0, 'b2': 5.0, 'b3': 5.0, 'v1': 10.0, 'v2': 5.0, 'v3': 0.0, 'v4': 5.0, 'v5': 5.0, 'v6': 0.0} TOY_MODEL_PAPIN_2003.solver = self.model.solver.interface with TimeMachine() as tm: TOY_MODEL_PAPIN_2003.reactions.v6.knock_out(tm) result = room(TOY_MODEL_PAPIN_2003, reference=reference, delta=0, epsilon=0) for k in reference.keys(): self.assertAlmostEqual(expected[k], result.fluxes[k], delta=0.1, msg="%s: %f | %f") self.assertIs(self.model.objective, original_objective)
def test_room_with_cache(self, core_model): original_objective = core_model.objective pfba_solution = pfba(core_model) essential_reactions = find_essential_reactions(core_model) cache = ProblemCache(core_model) infeasible = 0 for r in core_model.reactions: if r not in essential_reactions: with core_model: r.knock_out() try: room(core_model, reference=pfba_solution, cache=cache) assert any(v.name.startswith("y_") for v in core_model.solver.variables) assert any(c.name.startswith("room_const_") for c in core_model.solver.constraints) except OptimizationError: # TODO: room shouldn't return infeasible for non-essential reactions infeasible += 1 continue assert infeasible < len(core_model.reactions) cache.reset() assert core_model.objective.expression == original_objective.expression assert not any(v.name.startswith("y_") for v in core_model.solver.variables) assert not any(c.name.startswith("room_const_") for c in core_model.solver.constraints)
def test_room_with_cache(self, core_model): original_objective = core_model.objective pfba_solution = pfba(core_model) essential_reactions = find_essential_reactions(core_model) cache = ProblemCache(core_model) infeasible = 0 for r in core_model.reactions: if r not in essential_reactions: with core_model: r.knock_out() try: room(core_model, reference=pfba_solution, cache=cache) assert any(v.name.startswith("y_") for v in core_model.solver.variables) assert any(c.name.startswith("room_const_") for c in core_model.solver.constraints) except OptimizationError: # TODO: room shouldn't return infeasible for non-essential reactions infeasible += 1 continue assert infeasible < len(core_model.reactions) cache.reset() assert core_model.objective.expression == original_objective.expression assert not any(v.name.startswith("y_") for v in core_model.solver.variables) assert not any(c.name.startswith("room_const_") for c in core_model.solver.constraints)
def test_room_shlomi_2005(self, toy_model): if current_solver_name(toy_model) == "glpk": pytest.xfail("this test doesn't work with glpk") original_objective = toy_model.objective reference = {"b1": 10, "v1": 10, "v2": 5, "v3": 0, "v4": 0, "v5": 0, "v6": 5, "b2": 5, "b3": 5} expected = {'b1': 10.0, 'b2': 5.0, 'b3': 5.0, 'v1': 10.0, 'v2': 5.0, 'v3': 0.0, 'v4': 5.0, 'v5': 5.0, 'v6': 0.0} assert not any(v.name.startswith("y_") for v in toy_model.solver.variables) with toy_model: toy_model.reactions.v6.knock_out() result = room(toy_model, reference=reference, delta=0, epsilon=0) for k in reference.keys(): assert abs(expected[k] - result.fluxes[k]) < 0.1, "%s: %f | %f" assert toy_model.objective.expression == original_objective.expression assert not any(v.name.startswith("y_") for v in toy_model.variables)
def test_room_shlomi_2005(self, toy_model): if current_solver_name(toy_model) == "glpk": pytest.xfail("this test doesn't work with glpk") original_objective = toy_model.objective reference = {"b1": 10, "v1": 10, "v2": 5, "v3": 0, "v4": 0, "v5": 0, "v6": 5, "b2": 5, "b3": 5} expected = {'b1': 10.0, 'b2': 5.0, 'b3': 5.0, 'v1': 10.0, 'v2': 5.0, 'v3': 0.0, 'v4': 5.0, 'v5': 5.0, 'v6': 0.0} assert not any(v.name.startswith("y_") for v in toy_model.solver.variables) with toy_model: toy_model.reactions.v6.knock_out() result = room(toy_model, reference=reference, delta=0, epsilon=0) for k in reference.keys(): assert abs(expected[k] - result.fluxes[k]) < 0.1, "%s: %f | %f" assert toy_model.objective.expression == original_objective.expression assert not any(v.name.startswith("y_") for v in toy_model.variables)