medusa.reconstruct.expand

Module Contents

medusa.reconstruct.expand.REACTION_ATTRIBUTES = ['lower_bound', 'upper_bound']
medusa.reconstruct.expand.MISSING_ATTRIBUTE_DEFAULT
medusa.reconstruct.expand.gapfill_to_ensemble(model, iterations=1, universal=None, lower_bound=0.05, penalties=None, exchange_reactions=False, demand_reactions=False, integer_threshold=1e-06)

Performs gapfilling on model, pulling reactions from universal. Any existing constraints on base_model are maintained during gapfilling, so these should be set before calling gapfill_to_ensemble (e.g. secretion of metabolites, choice of objective function etc.).

Currently, only iterative solutions are supported with accumulating penalties (i.e. after each iteration, the penalty for each reaction doubles).

Parameters:
  • model (cobra.Model) – The model to perform gap filling on.
  • universal (cobra.Model) – A universal model with reactions that can be used to complete the model.
  • lower_bound (float, 0.05) – The minimally accepted flux for the objective in the filled model.
  • penalties (dict, None) – 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.
  • integer_threshold (float, 1e-6) – The threshold at which a value is considered non-zero (aka integrality threshold). If gapfilled models fail to validate, you may want to lower this value. However, picking a threshold that is too low may also result in reactions being added that are not essential to meet the imposed constraints.
  • exchange_reactions (bool, False) – Consider adding exchange (uptake) reactions for all metabolites in the model.
  • demand_reactions (bool, False) – Consider adding demand reactions for all metabolites.
Returns:

ensemble – The ensemble object created from the gapfill solutions.

Return type:

medusa.core.Ensemble

medusa.reconstruct.expand.iterative_gapfill_from_binary_phenotypes(model, universal, phenotype_dict, output_ensemble_size, gapfill_type='continuous', iterations_per_condition=1, lower_bound=0.05, penalties=None, exchange_reactions=False, demand_reactions=False, inclusion_threshold=1e-06, exchange_prefix='EX_')

Performs gapfilling on model, pulling reactions from universal. Any existing constraints on base_model are maintained during gapfilling, so these should be set before calling gapfill_to_ensemble (e.g. secretion of metabolites, choice of objective function etc.).

Cycles through each key:value pair in phenotype_dict, iterating over every condition and performing gapfilling on that condition until the number of cycles over all conditions is equal to output_ensemble_size. For each cycle, the order of conditions is randomized, which generally leads to unique sets of solutions for each cycle.

Currently only supports a single iteration for each condition within each cycle (i.e. for each gapfill in a single condition, only one solution is returned). Currently only supports gapfilling to positive growth conditions.

Generally, solutions are easier to find and more likely to exist if users ensure that transporters for metabolites exist in the model already or at minimum are present in the universal model.

Parameters:
  • model (cobra.Model) – The model to perform gap filling on.
  • universal (cobra.Model) – A universal model with reactions that can be used to complete the model.
  • phenotype_dict (dict) – A dictionary of condition_name:media_dict, where condition name is a unique string describing the condition (such as the name of a single carbon source) and media_dict is a dictionary of exchange reactions to bounds, as set in cobra.core.model.medium. Exchange reactions are provided with reaction.id, not cobra.core.reaction objects.
  • output_ensemble_size (int) – Number of cycles over all conditions provided to perform. Equal to the number of lists returned in ‘solutions’. When the ensemble is constructed, the number of members may be lower than output_ensemble_size if any duplicate solutions were found across cycles.
  • iterations_per_condition (int, 1) – The number of gapfill solutions to return in each condition within each cycle. Currently only supports returning a single solution.
  • lower_bound (float, 0.05) – The minimally accepted flux for the objective in the filled model.
  • penalties (dict, None) – 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.
  • inclusion_threshold (float, 1e-6) – The threshold at which a value is considered non-zero (aka integrality threshold in the integer formulation, or the flux threshold in the continuous formulation). If gapfilled models fail to validate, you may want to lower this valu. However, picking a threshold that is too low may also result in reactions being added that are not essential to meet the imposed constraints.
  • exchange_reactions (bool, False) – Consider adding exchange (uptake) reactions for all metabolites in the model.
  • demand_reactions (bool, False) – Consider adding demand reactions for all metabolites.
  • exchange_prefix (string, “EX_”) – the default reaction ID prefix to search for when identifying exchange reactions. “EX_” is standard for modelSEED models. This will be updated to be more database-agnostic when cobrapy boundary determination is finalized for cobrapy version 1.0.
Returns:

solutions – list of lists; each list contains a gapfill solution for a single cycle. Number of lists is equal to output_ensemble_size.

Return type:

list

medusa.reconstruct.expand._continuous_iterative_binary_gapfill(model, phenotype_dict, cycle_order, universal=None, output_ensemble_size=1, lower_bound=0.05, penalties=None, demand_reactions=False, exchange_reactions=False, flux_cutoff=1e-08, exchange_prefix='EX_')
medusa.reconstruct.expand._integer_iterative_binary_gapfill(model, phenotype_dict, cycle_order, universal=None, output_ensemble_size=0, lower_bound=0.05, penalties=False, demand_reactions=False, exchange_reactions=False, integer_threshold=1e-06)
medusa.reconstruct.expand._build_ensemble_from_gapfill_solutions(model, solutions, universal=None)
medusa.reconstruct.expand.validate(original_model, reactions, lower_bound)