-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
40 changed files
with
3,847 additions
and
507 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
|
||
``psamm.moma`` -- Minimization of metabolic adjustments | ||
======================================================= | ||
|
||
.. automodule:: psamm.moma | ||
:members: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,17 +16,18 @@ | |
# Copyright 2014-2017 Jon Lund Steffensen <[email protected]> | ||
# Copyright 2015 Keith Dufault-Thompson <[email protected]> | ||
|
||
from __future__ import unicode_literals | ||
from __future__ import unicode_literals, division | ||
|
||
import time | ||
import logging | ||
|
||
from ..command import (Command, MetabolicMixin, ObjectiveMixin, | ||
SolverCommandMixin, FilePrefixAppendAction) | ||
from .. import fluxanalysis | ||
from .. import moma | ||
from ..expression import boolean | ||
|
||
from six import string_types | ||
from six import string_types, text_type | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
@@ -42,9 +43,16 @@ def init_parser(cls, parser): | |
parser.add_argument( | ||
'--gene', metavar='genes', action=FilePrefixAppendAction, | ||
type=str, default=[], help='Delete multiple genes from model') | ||
parser.add_argument( | ||
'--method', metavar='method', | ||
choices=['fba', 'lin_moma', 'lin_moma2', 'moma', 'moma2'], | ||
type=text_type, default='fba', | ||
help='Select which method to use. (fba, lin_moma, lin_moma2, ' | ||
'moma, moma2)') | ||
super(GeneDeletionCommand, cls).init_parser(parser) | ||
|
||
def run(self): | ||
"""Delete the specified gene and solve using the desired method.""" | ||
obj_reaction = self._get_objective() | ||
|
||
genes = set() | ||
|
@@ -81,27 +89,60 @@ def run(self): | |
logger.info('Deleting reaction {}...'.format(reaction)) | ||
deleted_reactions.add(reaction) | ||
|
||
solver = self._get_solver() | ||
prob = fluxanalysis.FluxBalanceProblem(self._mm, solver) | ||
if self._args.method in ['moma', 'moma2']: | ||
solver = self._get_solver(quadratic=True) | ||
else: | ||
solver = self._get_solver() | ||
|
||
try: | ||
prob.maximize(obj_reaction) | ||
except fluxanalysis.FluxBalanceError as e: | ||
self.report_flux_balance_error(e) | ||
wild = prob.get_flux(obj_reaction) | ||
if self._args.method == 'fba': | ||
logger.info('Solving using FBA...') | ||
prob = fluxanalysis.FluxBalanceProblem(self._mm, solver) | ||
|
||
try: | ||
prob.maximize(obj_reaction) | ||
except fluxanalysis.FluxBalanceError as e: | ||
self.report_flux_balance_error(e) | ||
|
||
for reaction in deleted_reactions: | ||
flux_var = prob.get_flux_var(reaction) | ||
prob.prob.add_linear_constraints(flux_var == 0) | ||
wild = prob.get_flux(obj_reaction) | ||
|
||
prob.maximize(obj_reaction) | ||
deleteflux = prob.get_flux(obj_reaction) | ||
for reaction in deleted_reactions: | ||
flux_var = prob.get_flux_var(reaction) | ||
prob.prob.add_linear_constraints(flux_var == 0) | ||
|
||
prob.maximize(obj_reaction) | ||
deleteflux = prob.get_flux(obj_reaction) | ||
elif self._args.method in ['lin_moma', 'lin_moma2', 'moma', 'moma2']: | ||
prob = moma.MOMAProblem(self._mm, solver) | ||
wt_fluxes = prob.get_minimal_fba_flux(obj_reaction) | ||
wild = wt_fluxes[obj_reaction] | ||
|
||
for reaction in deleted_reactions: | ||
flux_var = prob.get_flux_var(reaction) | ||
prob.prob.add_linear_constraints(flux_var == 0) | ||
|
||
try: | ||
if self._args.method == 'moma': | ||
logger.info('Solving using MOMA...') | ||
prob.moma(wt_fluxes) | ||
elif self._args.method == 'lin_moma': | ||
logger.info('Solving using linear MOMA...') | ||
prob.lin_moma(wt_fluxes) | ||
elif self._args.method == 'moma2': | ||
logger.info('Solving using combined-model MOMA...') | ||
prob.moma2(obj_reaction, wild) | ||
elif self._args.method == 'lin_moma2': | ||
logger.info('Solving using combined-model linear MOMA...') | ||
prob.lin_moma2(obj_reaction, wild) | ||
except moma.MOMAError: | ||
self.fail('Error computing the MOMA result.') | ||
|
||
deleteflux = prob.get_flux(obj_reaction) | ||
|
||
logger.info( | ||
'Solving took {:.2f} seconds'.format(time.time() - start_time)) | ||
logger.info( | ||
'Objective reaction after gene deletion has flux {}'.format( | ||
abs(deleteflux) if deleteflux == 0 else deleteflux)) | ||
deleteflux + 0)) | ||
if wild != 0: | ||
logger.info( | ||
'Objective reaction has {:.2%} flux of wild type flux'.format( | ||
|
Oops, something went wrong.