Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: gapfind: Alternative GapFind algorithm which is more robust #209

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions psamm/commands/gapcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,10 @@ def run(self):
solver = self._get_solver(integer=True)
extracellular_comp = self._model.extracellular_compartment
epsilon = self._args.epsilon
v_max = float(self._model.default_flux_limit)

# Run GapFind on model
logger.info('Searching for blocked compounds...')
result = gapfind(self._mm, solver=solver, epsilon=epsilon, v_max=v_max)
result = gapfind(self._mm, solver=solver, epsilon=epsilon)

try:
blocked = set(compound for compound in result
Expand Down
15 changes: 12 additions & 3 deletions psamm/gapfill.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def _find_integer_tolerance(epsilon, v_max, min_tol):
return int_tol


def gapfind(model, solver, epsilon=0.001, v_max=1000, implicit_sinks=True):
def gapfind(model, solver, epsilon=0.001, implicit_sinks=True):
"""Identify compounds in the model that cannot be produced.

Yields all compounds that cannot be produced. This method
Expand All @@ -58,7 +58,9 @@ def gapfind(model, solver, epsilon=0.001, v_max=1000, implicit_sinks=True):
produced is the presence of the compounds needed to produce it.

Epsilon indicates the threshold amount of reaction flux for the products
to be considered non-blocked. V_max indicates the maximum flux.
to be considered non-blocked. The method respects the reversibility of
reactions but does not consider flux bounds of reactions i.e. every
reaction is assumed to be able to run at maximum flux.

This method is implemented as a MILP-program. Therefore it may
not be efficient for larger models.
Expand All @@ -75,6 +77,8 @@ def gapfind(model, solver, epsilon=0.001, v_max=1000, implicit_sinks=True):
"""
prob = solver.create_problem()

v_max = 1

# Set integrality tolerance such that w constraints are correct
min_tol = prob.integrality_tolerance.min
int_tol = _find_integer_tolerance(epsilon, v_max, min_tol)
Expand All @@ -96,7 +100,12 @@ def gapfind(model, solver, epsilon=0.001, v_max=1000, implicit_sinks=True):
w.define([spec])
w_var = w(spec)

lower, upper = (float(x) for x in model.limits[reaction_id])
lower, upper = 0, 0
if model.limits[reaction_id].lower < 0:
lower = -v_max
if model.limits[reaction_id].upper > 0:
upper = v_max

if value > 0:
dv = v(reaction_id)
else:
Expand Down