straindesign.networktools

Functions for metabolic network compression and extension with GPR rules

Module Contents

straindesign.networktools.bound_blocked_or_irrevers_fva(model, solver=None)[source]

Use FVA to determine the flux ranges. Use this information to update the model bounds

If flux ranges for a reaction are narrower than its bounds in the mode, these bounds can be omitted, since other reactions must constrain the reaction flux. If (upper or lower) flux bounds are found to be zero, the model bounds are updated to reduce the model complexity.

straindesign.networktools.compress_ki_ko_cost(kocost, kicost, cmp_mapReac)[source]

Compress knockout/addition cost vectors to match with a compressed model

When knockout/addition cost vectors have been specified (as dicts) and the original metabolic model was compressed, one needs to update the knockout/addition cost vectors. This function takes care of this. In particular it makes sure that the resulting costs are calculated correctly.

E.g.: r_ko_a (cost 1) and r_ko_b (cost 2) are lumped parallel: The resulting cost of r_ko_ab is 3 If they are lumped as dependent reactions the resulting cost is 1. If one of the two reactions is an addition candidate, the resulting reaction will be an addition candidate when lumped as dependent reactions and a knockout candidate when lumped in parallel. There are various possible cases that are treated by this function.

Example

kocost, kicost, cmp_mapReac = compress_ki_ko_cost(kocost, kicost, cmp_mapReac)

Parameters:
  • kocost (dict) – Knockout and addition cost vectors

  • kicost (dict) – Knockout and addition cost vectors

  • cmp_mapReac (list of dicts) – Compression map obtained from cmp_mapReac = compress_model(model)

Returns:

Updated vectors of KO costs and KI costs and an updated compression map that contains information on how to expand strain designs and correctly distinguish between knockouts and additions.

Return type:

(Tuple)

straindesign.networktools.compress_model(model, no_par_compress_reacs=set())[source]

Compress a metabolic model with a number of different techniques

The network compression routine removes blocked reactions, removes conservation relations and then performs alternatingly lumps dependent (compress_model_efmtool) and parallel (compress_model_parallel) reactions. The compression returns a compressed network and a list of compression maps. Each map consists of a dictionary that contains complete information for reversing the compression steps successively and expand information obtained from the compressed model to the full model. Each entry of each map contains the id of a compressed reaction, associated with the original reaction names and their factor (provided as a rational number) with which they were lumped.

Furthermore, the user can select reactions that should be exempt from the parallel compression. This is a critical feature for strain design computations. There is currently no way to exempt reactions from the efmtool/dependency compression.

Example

comression_map = compress_model(model,set(‘EX_etoh_e’,’PFL’))

Parameters:
  • model (cobra.Model) – A metabolic model that is an instance of the cobra.Model class

  • no_par_compress_reacs (set or list of str) – (Default: set()) A set of reaction identifiers whose reactions should not be lumped with other parallel reactions.

Returns:

A list of compression maps. Each map is a dict that contains information for reversing the compression steps successively and expand information obtained from the compressed model to the full model. Each entry of each map contains the id of a compressed reaction, associated with the original reaction identifiers and their factor with which they are represented in the lumped reaction (provided as a rational number) with which they were lumped.

Return type:

(list of dict)

straindesign.networktools.compress_model_efmtool(model)[source]

Compress model by lumping dependent reactions using the efmtool compression approach

Example

cmp_mapReac = compress_model_efmtool(model)

Parameters:

model (cobra.Model) – A metabolic model that is an instance of the cobra.Model class

Returns:

A dict that contains information about the lumping done in the compression process. process. E.g.: {‘reaction_lumped1’ : {‘reaction_orig1’ : 2/3 ‘reaction_orig2’ : 1/2}, …}

Return type:

(dict)

straindesign.networktools.compress_model_parallel(model, protected_rxns=set())[source]

Compress model by lumping parallel reactions

Example

cmp_mapReac = compress_model_parallel(model)

Parameters:

model (cobra.Model) – A metabolic model that is an instance of the cobra.Model class

Returns:

A dict that contains information about the lumping done in the compression process. E.g.: {‘reaction_lumped1’ : {‘reaction_orig1’ : 1 ‘reaction_orig2’ : 1}, …}

Return type:

(dict)

straindesign.networktools.compress_modules(sd_modules, cmp_mapReac)[source]

Compress strain design modules to match with a compressed model

When a strain design task has been specified with modules and the original metabolic model was compressed, one needs to refit the strain design modules (objects of the SDModule class) to the new compressed model. This function takes a list of modules and a compression map and returns the strain design modules for a compressed network.

Example

comression_map = compress_modules(sd_modules, cmp_mapReac)

Parameters:
  • model (list of SDModule) – A list of strain design modules

  • cmp_mapReac (list of dicts) – Compression map obtained from cmp_mapReac = compress_model(model)

Returns:

A list of strain design modules for the compressed network

Return type:

(list of SDModule)

straindesign.networktools.expand_sd(sd, cmp_mapReac)[source]

Expand computed strain designs from a compressed to a full model

Needed after computing strain designs in a compressed model

Example

expanded_sd = expand_sd(compressed_sds, cmp_mapReac)

Parameters:
  • sd (SDSolutions) – Solutions of a strain design computation that refer to a compressed model

  • cmp_mapReac (list of dicts) – Compression map obtained from cmp_mapReac = compress_model(model) and updated with kocost, kicost, cmp_mapReac = compress_ki_ko_cost(kocost, kicost, cmp_mapReac)

Returns:

Strain design solutions that refer to the uncompressed model

Return type:

(SDSolutions)

straindesign.networktools.extend_model_gpr(model, use_names=False)[source]

Integrate GPR-rules into a metabolic model as pseudo metabolites and reactions

COBRA modules often have gene-protein-reaction (GPR) rules associated with each reaction. These can be integrated into the metabolic network structure through pseudo reactions and variables. As GPR rules are integrated into the metabolic network, the metabolic flux space does not change. After integration, the gene-pseudoreactions can be fixed to a flux of zero to simulate gene knockouts. Gene pseudoreactions are referenced either by the gene name or the gene identifier (user selected).

GPR-rule integration enables the computation of strain designs based on genetic interventions.

This function requires all GPR-rules to be provided in DNF (disjunctive normal form). (e.g. g1 and g2 or g1 and g3, NOT g1 and (g2 or g3)). Brackets are allowed but not required. If reversible reactions are associated with GPR-rules, these reactions are spit during GPR-integration. The function returns a mapping of old and new reaction identifiers.

Example

reac_map = extend_model_gpr(model):

Parameters:
  • model (cobra.Model) – A metabolic model that is an instance of the cobra.Model class containing GPR rules in DNF

  • use_names (bool) – (Default: False) If set to True, the gene pseudoreactions will carry the gene name as reaction identifier. If False, the gene identifier will be used. By default this option is turned off because many models do not provide gene names.

Returns:

A dictionary to reference old and new reaction identifiers, for reversible reactions that were split (when they are associated with GPR rules). Entries have the form: {‘Reaction1’ : {‘Reaction1’ : 1, ‘Reaction1_reverse_a59c’ : -1}}

Return type:

(dict)

straindesign.networktools.extend_model_regulatory(model, reg_itv)[source]

Extend a metabolic model to account for regulatory constraints

This function emulates regulatory interventions in a network. These can either be added permanently or linked to a pseudoreation whose boundaries can be fixed to zero used to activate the regulatory constraint.

Accounting for regulatory interventions, such as applying an upper or lower bound to a reaction or gene pseudoreaction, can be achieved by combining different pseudometabolites and reactions. For instance, to introduce the regulatory constraint:

2*r_1 + 3*r_2 <= 4

and make it ‘toggleable’, one adds 1 metabolite ‘m’ and 2 reactions, ‘r_bnd’ to account for the bound/rhs and r_ctl to control whether the regulatory intervention is active or not:

dm/dt = 2*r_1 + 3*r_2 - r_bnd + r_ctl = 0, -inf <= r_bnd <= 4, -inf <= r_ctl <= inf

When r_ctl is fixed to zero, the constraint 2*r_1 + 3*r_2 <= 4 is enforced, otherwise, the constraint is non binding, thus virtually non-existant. To use this mechanism for strain design, we add the metabolite and reactions as described above and tag r_ctl as knockout candidate. If the algorithm decides to knockout r_ctl, this means, it choses to add the regulatory intervention 2*r_1 + 3*r_2 <= 4.

If the constraint is be added permanently, this function completely omits the r_ctl reaction.

Example

reg_itv_costs = extend_model_regulatory(model, {‘1 PDH + 1 PFL <= 5’ : 1, ‘-EX_o2_e <= 2’ : 1.5})

Parameters:
  • model (cobra.Model) – A metabolic model that is an instance of the cobra.Model class

  • reg_itv (dict or list of str or str) – A set of regulatory constraints that should be added to the model. If reg_itv is a string or a list of strings, regulatory constraints are added permanently. If reg_itv is a dict, regulatory interventions are added in a controllable manner. The id of the reaction that controls the constraint is contained in the return variable. The constraint to be added will be parsed from strings, so ensure that you use the correct reaction identifiers. Valid inputs are: reg_itv = ‘-EX_o2_e <= 2’ # A single permanent regulatory constraint reg_itv = [‘1 PDH + 1 PFL <= 5’, ‘-EX_o2_e <= 2’] # Two permanent constraints reg_itv = {‘1 PDH + 1 PFL <= 5’ : 1, ‘-EX_o2_e <= 2’ : 1.5} # Two controllable constraints # one costs ‘1’ and the other one ‘1.5’ to be added. The function returns a dict with # {‘p1_PDH_p1_PFK_le_5’ : 1 ‘nEX_o2_e_le_2’ : 1.5}. Fixing the reaction # p1_PDH_p1_PFK_le_5 to zero will activate the constraint in the model.

Returns:

A dictionary that contains the cost of adding each constraint; e.g., {‘p1_PDH_p1_PFK_le_5’ : 1 ‘n1EX_o2_e_le_2’ : 1.5}

Return type:

(dict)

straindesign.networktools.filter_sd_maxcost(sd, max_cost, kocost, kicost)[source]

Filter out strain designs that exceed the maximum allowed intervention costs

Returns:

Strain design solutions complying with the intervention costs limit

Return type:

(SDSolutions)

straindesign.networktools.modules_coeff2float(sd_modules)[source]

Convert coefficients occurring in SDModule objects to floats

straindesign.networktools.modules_coeff2rational(sd_modules)[source]

Convert coefficients occurring in SDModule objects to rational numbers

straindesign.networktools.remove_blocked_reactions(model) List[source]

Remove blocked reactions from a network

straindesign.networktools.remove_conservation_relations(model)[source]

Remove conservation relations in a model

This reduces the number of metabolites in a model while maintaining the original flux space. This is a compression technique.

straindesign.networktools.remove_dummy_bounds(model)[source]

Replace COBRA standard bounds with +/-inf

Retrieve the standard bounds from the COBRApy Configuration and replace model bounds of the same value with +/-inf.

straindesign.networktools.remove_ext_mets(model)[source]

Remove (unbalanced) external metabolites from the compartment External_Species

straindesign.networktools.remove_irrelevant_genes(model, essential_reacs, gkis, gkos)[source]

Remove genes whose that do not affect the flux space of the model

This function is used in preprocessing of computational strain design computations. Often, certain reactions, for instance, reactions essential for microbial growth can/must not be targeted by interventions. That can be exploited to reduce the set of genes in which interventions need to be considered.

Given a set of essential reactions that is to be maintained operational, some genes can be removed from a metabolic model, either because they only affect only blocked reactions or essential reactions, or because they are essential reactions and must not be removed. As a consequence, the GPR rules of a model can be simplified.

Example

remove_irrelevant_genes(model, essential_reacs, gkis, gkos):

Parameters:
  • model (cobra.Model) – A metabolic model that is an instance of the cobra.Model class containing GPR rules

  • essential_reacs (list of str) – A list of identifiers of essential reactions.

  • gkis (dict) – Dictionaries that contain the costs for gene knockouts and additions. E.g., gkos={‘adhE’: 1.0, ‘ldhA’ : 1.0 …}

  • gkos (dict) – Dictionaries that contain the costs for gene knockouts and additions. E.g., gkos={‘adhE’: 1.0, ‘ldhA’ : 1.0 …}

Returns:

An updated dictionary of the knockout costs in which irrelevant genes are removed.

Return type:

(dict)

straindesign.networktools.stoichmat_coeff2float(model)[source]

Convert coefficients from to stoichiometric matrix to floats

straindesign.networktools.stoichmat_coeff2rational(model)[source]

Convert coefficients from to stoichiometric matrix to rational numbers