Skip to content

Commit

Permalink
FluxDistributionResult has objective_value property now. Also, fba re…
Browse files Browse the repository at this point in the history
…turns FluxDistributionResult now.
  • Loading branch information
phantomas1234 committed Feb 25, 2015
1 parent b61e8cc commit a6823c7
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 12 deletions.
5 changes: 5 additions & 0 deletions cameo/core/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class FluxDistributionResult(Result):
def __init__(self, solution, *args, **kwargs):
super(FluxDistributionResult, self).__init__(*args, **kwargs)
self._fluxes = solution.fluxes
self._objective_value = solution.f

@property
def data_frame(self):
Expand All @@ -76,6 +77,10 @@ def data_frame(self):
def fluxes(self):
return self._fluxes

@property
def objective_value(self):
return self._objective_value


if __name__ == '__main__':

Expand Down
11 changes: 7 additions & 4 deletions cameo/flux_analysis/distance.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

from types import DictType
from sympy import Add
from cameo.core.result import FluxDistributionResult
from cameo.core.solution import SolutionBase, Solution

add = Add._from_args
Expand Down Expand Up @@ -109,9 +110,11 @@ def __add_deviavtion_constraint(self, reaction_id, flux_value):

def minimize_L1(self, *args, **kwargs):
self.model.objective.direction = 'min'
return self.model.solve(solution_type=Solution)
solution = self.model.solve()
result = FluxDistributionResult(solution)
return result

def maximize_L1(self, *args, **kwargs):
self.model.objective.direction = 'max'
return self.model.solve(solution_type=Solution)
# def maximize_L1(self, *args, **kwargs):
# self.model.objective.direction = 'max'
# return self.model.solve(solution_type=Solution)

9 changes: 2 additions & 7 deletions cameo/flux_analysis/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,8 @@ def fba(model, objective=None, *args, **kwargs):
if objective is not None:
tm(do=partial(setattr, model, 'objective', objective),
undo=partial(setattr, model, 'objective', model.objective))
try:
solution = model.solve()
result = FluxDistributionResult(solution)
tm.reset()
return solution
except SolveError as e:
raise e
solution = model.solve()
result = FluxDistributionResult(solution)
return result

def pfba(model, objective=None, *args, **kwargs):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_flux_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def setUp(self):

def test_fba(self):
solution = fba(self.model)
self.assertAlmostEqual(solution.f, 0.873921, delta=0.000001)
self.assertAlmostEqual(solution.objective_value, 0.873921, delta=0.000001)

def test_pfba(self):
fba_solution = fba(self.model)
Expand Down

0 comments on commit a6823c7

Please sign in to comment.