Skip to content

Commit 83dc314

Browse files
Midnighterphantomas1234
authored andcommitted
Refactor pathway prediction (#230)
* 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.
1 parent b02668e commit 83dc314

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

cameo/strain_design/pathway_prediction/pathway_predictor.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -299,9 +299,9 @@ def run(self, product=None, max_predictions=float("inf"), min_production=.1,
299299
logger.debug('Predicting pathway No. %d' % counter)
300300
try:
301301
self.model.slim_optimize(error_value=None)
302-
except OptimizationError as e:
302+
except OptimizationError as err:
303303
logger.error('No pathway could be predicted. Terminating pathway predictions.')
304-
logger.error(e)
304+
logger.error(err)
305305
break
306306

307307
vars_to_cut = list()
@@ -355,28 +355,28 @@ def run(self, product=None, max_predictions=float("inf"), min_production=.1,
355355
# Test pathway in the original model
356356
with self.original_model:
357357
pathway.apply(self.original_model)
358+
self.original_model.objective = pathway.product.id
358359
try:
359-
solution = fba(self.original_model, objective=pathway.product.id)
360-
except OptimizationError as e:
361-
logger.error(e)
360+
value = self.original_model.slim_optimize(error_value=None)
361+
except OptimizationError as err:
362+
logger.error(err)
362363
logger.error(
363364
"Addition of pathway {} made the model unsolvable. "
364365
"Skipping pathway.".format(pathway))
365366
continue
366367
else:
367-
if solution[pathway.product.id] > non_zero_flux_threshold:
368+
if value > non_zero_flux_threshold:
368369
pathways.append(pathway)
369-
if not silent:
370-
print("Max flux: %.5f" % solution[pathway.product.id])
370+
logger.info("Max flux: %.5G", value)
371+
counter += 1
372+
if callback is not None:
373+
callback(pathway)
371374
else:
372-
logger.error(
373-
"Pathway {} couldn't be verified. Production flux {}"
374-
"is below requirement {}. Skipping pathway.".format(
375-
pathway, solution[pathway.product.id], non_zero_flux_threshold))
376-
finally:
377-
counter += 1
378-
if callback is not None:
379-
callback(pathway)
375+
logger.warning(
376+
"Pathway %r could not be verified. Production "
377+
"flux %.5G is below the requirement %.5G. "
378+
"Skipping.", pathway, value,
379+
non_zero_flux_threshold)
380380

381381
return PathwayPredictions(pathways)
382382

0 commit comments

Comments
 (0)