cobra.flux_analysis.gapfilling
¶
Provide the base class and utility function for gap filling.
Module Contents¶
Classes¶
The base class for performing gap filling. 
Functions¶

Perform gap filling on a model. 
Attributes¶
 class cobra.flux_analysis.gapfilling.GapFiller(model: cobra.core.Model, universal: Optional[cobra.core.Model] = None, lower_bound: float = 0.05, penalties: Optional[Union[Dict[str, int], Dict[cobra.Reaction, int]]] = None, exchange_reactions: bool = False, demand_reactions: bool = True, integer_threshold: float = 1e06, **kwargs)[source]¶
The base class for performing gap filling.
This class implements gap filling based on a mixedinteger approach, very similar to that described in 1 and the ‘nogrowth but growth’ part of 2 but with minor adjustments. In short, we add indicator variables for using the reactions in the universal model, z_i and then solve problem
minimize: sum_i c_i * z_i s.t. : Sv = 0
v_o ge t lb_i le v_i le ub_i v_i = 0 if z_i = 0
where lb, ub are respectively the upper, lower flux bounds for reaction i, c_i is a cost parameter and the objective v_o is greater than the lower bound t. The default costs are 1 for reactions from the universal model, 100 for exchange (uptake) reactions added and 1 for added demand reactions.
Note that this is a mixedinteger linear program and as such will be expensive to solve for large models. Consider using alternatives 3 such as CORDA instead [4,5]_ .
 Parameters
model (cobra.Model) – The model to perform gap filling on.
universal (cobra.Model, optional) – A universal model with reactions that can be used to complete the model (default None).
lower_bound (float, optional) – The minimally accepted flux for the objective in the filled model (default 0.05).
penalties (dict, optional) – A dictionary with keys being ‘universal’ (all reactions included in the universal model), ‘exchange’ and ‘demand’ (all additionally added exchange and demand reactions) for the three reaction types. Can also have reaction identifiers for reaction specific costs. Defaults are 1, 100 and 1 respectively (default None).
exchange_reactions (bool, optional) – Consider adding exchange (uptake) reactions for all metabolites in the model (default False).
demand_reactions (bool, optional) – Consider adding demand reactions for all metabolites (default True).
integer_threshold (float, optional) – The threshold at which a value is considered nonzero (aka integrality threshold). If gapfilled models fail to validate, you may want to lower this value (default 1E6).
 costs¶
The dictionary with symbolic variables as keys and their cost as values.
 Type
dict of {optlang.interface.Variable: float}
References
 1
Reed, Jennifer L., Trina R. Patel, Keri H. Chen, Andrew R. Joyce, Margaret K. Applebee, Christopher D. Herring, Olivia T. Bui, Eric M. Knight, Stephen S. Fong, and Bernhard O. Palsson. “Systems Approach to Refining Genome Annotation.” Proceedings of the National Academy of Sciences 103, no. 46 (2006): 17480–17484.
 2
Kumar, Vinay Satish, and Costas D. Maranas. “GrowMatch: An Automated Method for Reconciling In Silico/In Vivo Growth Predictions.” Edited by Christos A. Ouzounis. PLoS Computational Biology 5, no. 3 (March 13, 2009): e1000308. doi:10.1371/journal.pcbi.1000308.
 3
 4
Schultz, André, and Amina A. Qutub. “Reconstruction of TissueSpecific Metabolic Networks Using CORDA.” Edited by Costas D. Maranas. PLOS Computational Biology 12, no. 3 (March 4, 2016): e1004808. doi:10.1371/journal.pcbi.1004808.
 5
Diener, Christian https://github.com/cdiener/corda
 extend_model(exchange_reactions: bool = False, demand_reactions: bool = True) None [source]¶
Extend gap filling model.
Add reactions from universal model and optionally exchange and demand reactions for all metabolites in the model to perform gap filling on.
 update_costs() None [source]¶
Update coefficients for the indicator variables in the objective.
Done incrementally so that second time the function is called, active indicators in the current solutions gets higher cost than the unused indicators.
 add_switches_and_objective() None [source]¶
Update gap filling model with switches and indicator objective.
 fill(iterations: int = 1) List[List[cobra.Reaction]] [source]¶
Perform the gap filling.
With every iteration, it solves the model, updates the costs and records the used reactions.
 Parameters
iterations (int, optional) – The number of rounds of gap filling to perform. For every iteration, the penalty for every used reaction increases linearly. This way, the algorithm is encouraged to search for alternative solutions which may include previously used reactions i.e., with enough iterations pathways including 10 steps will eventually be reported even if the shortest pathway is a single reaction (default 1).
 Returns
A list of lists where each element is a list of reactions that were used to gap fill the model.
 Return type
list of list of cobra.Reaction
 Raises
RuntimeError – If the model fails to be validated (i.e. the original model with the proposed reactions added, still cannot get the required flux through the objective).
 validate(reactions: List[cobra.Reaction]) bool [source]¶
Validate the model.
 Parameters
reactions (list of cobra.Reaction) – The reactions to add to the model for validation.
 Returns
Whether the model is valid or not.
 Return type
 cobra.flux_analysis.gapfilling.gapfill(model: cobra.core.Model, universal: Optional[cobra.core.Model] = None, lower_bound: float = 0.05, penalties: Optional[Dict[str, cobra.Reaction]] = None, demand_reactions: bool = True, exchange_reactions: bool = False, iterations: int = 1)[source]¶
Perform gap filling on a model.
 Parameters
model (cobra.Model) – The model to perform gap filling on.
universal (cobra.Model, optional) – A universal model with reactions that can be used to complete the model. Only gapfill considering demand and exchange reactions if left missing (default None).
lower_bound (float, optional) – The minimally accepted flux for the objective in the filled model. (default 0.05).
penalties (dict, optional) – A dictionary with keys being ‘universal’ (all reactions included in the universal model), ‘exchange’ and ‘demand’ (all additionally added exchange and demand reactions) for the three reaction types. Can also have reaction identifiers for reaction specific costs. Defaults are 1, 100 and 1 respectively (default None).
exchange_reactions (bool, optional) – Consider adding exchange (uptake) reactions for all metabolites in the model (default False).
demand_reactions (bool, optional) – Consider adding demand reactions for all metabolites (default True).
iterations (int, optional) – The number of rounds of gap filling to perform. For every iteration, the penalty for every used reaction increases linearly. This way, the algorithm is encouraged to search for alternative solutions which may include previously used reactions i.e., with enough iterations pathways including 10 steps will eventually be reported even if the shortest pathway is a single reaction (default 1).
 Returns
A list of lists with on set of reactions that completes the model per requested iteration.
 Return type
list of list of cobra.Reaction
Examples
>>> from cobra.io import load_model >>> from cobra import Model >>> from cobra.flux_analysis import gapfill >>> model = load_model("iYS1720") >>> universal = Model("universal") >>> universal.add_reactions([model.reactions.GF6PTA.copy()]) >>> model.remove_reactions([model.reactions.GF6PTA]) >>> gapfill(model, universal) [[<Reaction GF6PTA at 0x12206a280>]]