Skip to content

Commit

Permalink
Refactor pathway prediction (#230)
Browse files Browse the repository at this point in the history
* style: correct new flake8 errors

* refactor: make low flux not count towards maximum

* Pathways found with a low flux value should not count towards the
  maximum number of desired pathways.
* A pathway with a low flux will now issue only a warning message not an
  error message.
* Callbacks are only called on successful pathways.
  • Loading branch information
Midnighter authored and phantomas1234 committed Feb 6, 2019
1 parent b02668e commit 83dc314
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions cameo/strain_design/pathway_prediction/pathway_predictor.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,9 +299,9 @@ def run(self, product=None, max_predictions=float("inf"), min_production=.1,
logger.debug('Predicting pathway No. %d' % counter)
try:
self.model.slim_optimize(error_value=None)
except OptimizationError as e:
except OptimizationError as err:
logger.error('No pathway could be predicted. Terminating pathway predictions.')
logger.error(e)
logger.error(err)
break

vars_to_cut = list()
Expand Down Expand Up @@ -355,28 +355,28 @@ def run(self, product=None, max_predictions=float("inf"), min_production=.1,
# Test pathway in the original model
with self.original_model:
pathway.apply(self.original_model)
self.original_model.objective = pathway.product.id
try:
solution = fba(self.original_model, objective=pathway.product.id)
except OptimizationError as e:
logger.error(e)
value = self.original_model.slim_optimize(error_value=None)
except OptimizationError as err:
logger.error(err)
logger.error(
"Addition of pathway {} made the model unsolvable. "
"Skipping pathway.".format(pathway))
continue
else:
if solution[pathway.product.id] > non_zero_flux_threshold:
if value > non_zero_flux_threshold:
pathways.append(pathway)
if not silent:
print("Max flux: %.5f" % solution[pathway.product.id])
logger.info("Max flux: %.5G", value)
counter += 1
if callback is not None:
callback(pathway)
else:
logger.error(
"Pathway {} couldn't be verified. Production flux {}"
"is below requirement {}. Skipping pathway.".format(
pathway, solution[pathway.product.id], non_zero_flux_threshold))
finally:
counter += 1
if callback is not None:
callback(pathway)
logger.warning(
"Pathway %r could not be verified. Production "
"flux %.5G is below the requirement %.5G. "
"Skipping.", pathway, value,
non_zero_flux_threshold)

return PathwayPredictions(pathways)

Expand Down

0 comments on commit 83dc314

Please sign in to comment.