straindesign.networktools ========================= .. py:module:: straindesign.networktools .. autoapi-nested-parse:: Functions for metabolic network extension with GPR rules and strain design module handling. Compression functions have been moved to straindesign.compression. This module re-exports them for backwards compatibility. Module Contents --------------- .. py:function:: bound_blocked_or_irrevers_fva(model, solver=None) 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. .. py:function:: compress_ki_ko_cost(kocost, kicost, cmp_mapReac) 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. .. rubric:: Example kocost, kicost, cmp_mapReac = compress_ki_ko_cost(kocost, kicost, cmp_mapReac) :param kocost: Knockout and addition cost vectors :type kocost: dict :param kicost: Knockout and addition cost vectors :type kicost: dict :param cmp_mapReac: Compression map obtained from cmp_mapReac = compress_model(model) :type cmp_mapReac: list of dicts :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. :rtype: (Tuple) .. py:function:: compress_modules(sd_modules, cmp_mapReac) 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. .. rubric:: Example comression_map = compress_modules(sd_modules, cmp_mapReac) :param model: A list of strain design modules :type model: list of SDModule :param cmp_mapReac: Compression map obtained from cmp_mapReac = compress_model(model) :type cmp_mapReac: list of dicts :returns: A list of strain design modules for the compressed network :rtype: (list of SDModule) .. py:function:: expand_sd(sd, cmp_mapReac) Expand computed strain designs from a compressed to a full model Needed after computing strain designs in a compressed model .. rubric:: Example expanded_sd = expand_sd(compressed_sds, cmp_mapReac) :param sd: Solutions of a strain design computation that refer to a compressed model :type sd: SDSolutions :param cmp_mapReac: Compression map obtained from cmp_mapReac = compress_model(model) and updated with kocost, kicost, cmp_mapReac = compress_ki_ko_cost(kocost, kicost, cmp_mapReac) :type cmp_mapReac: list of dicts :returns: Strain design solutions that refer to the uncompressed model :rtype: (SDSolutions) .. py:function:: extend_model_gpr(model, use_names=False) Integrate GPR-rules into a metabolic model as pseudo metabolites and reactions using AST parsing 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 now uses AST parsing to handle both DNF (disjunctive normal form) and non-DNF GPR rules. It processes the reaction.gpr.body AST structure directly, enabling proper handling of complex nested boolean expressions. .. rubric:: Example reac_map = extend_model_gpr(model): :param model: A metabolic model that is an instance of the cobra.Model class containing GPR rules :type model: cobra.Model :param use_names: (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. :type use_names: bool :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}} :rtype: (dict) .. py:function:: extend_model_regulatory(model, reg_itv) 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. .. rubric:: Example reg_itv_costs = extend_model_regulatory(model, {'1 PDH + 1 PFL <= 5' : 1, '-EX_o2_e <= 2' : 1.5}) :param model: A metabolic model that is an instance of the cobra.Model class :type model: cobra.Model :param reg_itv: 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. :type reg_itv: dict or list of str or str :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} :rtype: (dict) .. py:function:: filter_sd_maxcost(sd, max_cost, kocost, kicost) Filter out strain designs that exceed the maximum allowed intervention costs :returns: Strain design solutions complying with the intervention costs limit :rtype: (SDSolutions) .. py:function:: modules_coeff2float(sd_modules) Convert coefficients occurring in SDModule objects to floats .. py:function:: modules_coeff2rational(sd_modules) Convert coefficients to rational numbers using sympy.Rational .. py:function:: remove_irrelevant_genes(model, essential_reacs, gkis, gkos) Remove genes whose that do not affect the flux space of the model using AST-based GPR parsing 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 using AST parsing for both DNF and non-DNF rules. .. rubric:: Example remove_irrelevant_genes(model, essential_reacs, gkis, gkos): :param model: A metabolic model that is an instance of the cobra.Model class containing GPR rules :type model: cobra.Model :param essential_reacs: A list of identifiers of essential reactions. :type essential_reacs: list of str :param gkis: Dictionaries that contain the costs for gene knockouts and additions. E.g., gkos={'adhE': 1.0, 'ldhA' : 1.0 ...} :type gkis: dict :param gkos: Dictionaries that contain the costs for gene knockouts and additions. E.g., gkos={'adhE': 1.0, 'ldhA' : 1.0 ...} :type gkos: dict :returns: An updated dictionary of the knockout costs in which irrelevant genes are removed. :rtype: (dict)