geckopy

Package Contents

Classes

Model

Extension of cobra.Model providing an API for proteins in EC models.

Protein

Representation of an enzyme.

Functions

flux_variability_analysis(ec_model: geckopy.model.Model, fixed_reactions: Optional[List[str]] = None, ignored_reactions: Optional[List[str]] = None, n_proc: Optional[int] = config.processes, inplace: bool = False) → pandas.DataFrame

Flux variability analysis for EC models.

geckopy.flux_variability_analysis(ec_model: geckopy.model.Model, fixed_reactions: Optional[List[str]] = None, ignored_reactions: Optional[List[str]] = None, n_proc: Optional[int] = config.processes, inplace: bool = False)pandas.DataFrame[source]

Flux variability analysis for EC models.

This method is detailed in the Supplementary material of [Domenzain et al., 2021](https://www.biorxiv.org/content/10.1101/2021.03.05.433259v1.full.pdf).

For a fair comparison of flux distributions, EC models require some adjustments:

  1. Since there are duplicated reactions (for each direction), the complementary reaction must be blocked to remove artificial flux variation.

  2. Some reactions might be fixed (the glucose exchange reaction in the paper) to compare them with non-EC models.

  3. The final reported flux is \(v_{max}, v_{max}^{rev} \forall v \in \text{reactions}\)

Additionally, just the combined reaction arm_ is reported for isozymes.

Parameters
  • model (geckopy.Model) –

  • fixed_reactions (Optional[List[str]]) – List of reactions to be fixed (as in the second point in the description)

  • ignored_reactions (Optional[List[str]]) – List of reactions to be ignored

  • n_proc (int) – Number of processes to use. Default: the number of logical CPUs.

  • inplace (bool) – Whether to copy the model to then apply the changes

Returns

fva_result – A data frame with reaction identifiers as the index and two columns: - maximum: indicating the highest possible flux - minimum: indicating the lowest possible flux

Return type

pandas.DataFrame

class geckopy.Model(id_or_model: Union[str, cobra.Model] = None, name: str = None, hardcoded_rev_reactions: bool = True)[source]

Bases: cobra.Model

Extension of cobra.Model providing an API for proteins in EC models.

reactions

A DictList where the key is the reaction identifier and the value a Reaction.

Type

DictList

metabolites

A DictList where the key is the metabolite identifier and the value a Metabolite.

Type

DictList

proteins

A DictList where the key is the metabolite identifier and the value a Protein.

Type

DictList

genes

A DictList where the key is the gene identifier and the value a Gene.

Type

DictList

groups

A DictList where the key is the group identifier and the value a Group.

Type

DictList

solution

# TODO: separate proteins from cobra.Reactions The last obtained solution from optimizing the model.

Type

Solution

__setstate__(self, state: Dict)

Make sure all cobra.Objects in the model point to the model.

from_cobra(self, model: cobra.Model, name: str)

Initialize from cobra model.

get_total_measured_proteins(self)float

Sum of all Proteins in the model that has a concentration.

constrain_pool(self, p_total: float, sigma_saturation_factor: float, fn_mass_fraction_unmeasured_matched: float, protein_list: List[str] = None)

Constrain the draw reactions for the unmeasured (common protein pool) proteins.

Adapted from [geckopy] (https://github.com/SysBioChalmers/GECKO/blob/master/geckopy/geckopy/gecko.py#L184)

Proteins without their own protein pool are collectively constrained by the common protein pool. Remove protein pools for all proteins that don’t have measurements, along with corresponding draw reactions, and add these to the common protein pool and reaction.

Parameters
  • p_total (float) – measured total protein fraction in cell in g protein / gDW

  • sigma_saturation_factor (float) – part of proteome that can be used by metabolism

  • fn_mass_fraction_unmeasured_matched (float) – TODO: add convenience function to handle this sum of the product of average abundances of unmesured proteins (from, e.g., paxDB) times their molecular weight.

  • protein_list (List[str]) – list of ids of proteins to constrain. This is useful for inspecting the protein utilization of, e.g., a heterologous pathway.

add_pool(self, reac_id: str = 'prot_pool_exchange', met_id: str = 'prot_pool')

Add the reaction and metabolite to constraint the common pool of proteins.

Parameters
  • read_id (str) – id of the common protein pool pseudorreaction to add.

  • met_id (str) – id of the common protein pool metabolite to add.

copy(self)

Provide a partial ‘deepcopy’ of the Model.

All of the Metabolite, Gene, and Reaction objects are created anew but in a faster fashion than deepcopy. Enzyme constrained changes: also deepcopy proteins.

_populate_solver(self, reaction_list: Iterator[Reaction], metabolite_list: Iterator[Metabolite] = None, protein_list: Iterator[Protein] = None)

Populate attached solver with LP problem given reactions + proteins.

Note that proteins are added both as Constraints and Variables.

add_proteins(self, protein_list: Iterator[Protein])

Add proteins to the model, in the same fashion as .add_metabollites.

add_reactions(self, reaction_list: Iterator[Reaction])

Add reactions to the model.

Reactions with identifiers identical to a reaction already in the model are ignored. The change is reverted upon exit when using the model as a context. Enzyme Constrained changes: avoid adding proteins as metabolites.

Parameters

reaction_list (list) – A list of cobra.Reaction objects

optimize(self, objective_sense: Optional[str] = None, raise_error: bool = False)Tuple[cobra.Solution, cobra.Solution]

Optimize the model using flux balance analysis.

Parameters
  • objective_sense ({None, 'maximize' 'minimize'}, optional) – Whether fluxes should be maximized or minimized. In case of None, the previous direction is used.

  • raise_error (bool) –

    If true, raise an OptimizationError if solver status is not

    optimal.

Notes

Only the most commonly used parameters are presented here. Additional parameters for cobra.solvers may be available and specified with the appropriate keyword argument.

add_boundary(self, metabolite: Union[cobra.Metabolite, Protein], type: str = 'exchange', reaction_id: Optional[str] = None, lb: Optional[float] = None, ub: Optional[float] = None, sbo_term: Optional[str] = None)geckopy.reaction.Reaction

Add a boundary reaction for a given metabolite.

Enzyme constraint changes: return an geckopy.Reaction.

class geckopy.Protein(id: Union[str, Metabolite] = None, concentration: float = None, molecular_weight: float = 0.0, name: str = '')[source]

Bases: cobra.Object

Representation of an enzyme.

A protein sets an upper bound to a set of reactions, given the kcat and concentration. Adapted from cobra.Reaction.

In terms of the inner LP model, Proteins populates both variables (as pseudorreactions with the mentioned upper_bound) and constraints (as metabolites).

id

identifier of protein, should be an Uniprot ID or “prot_<Uniprot ID>”

Type

str

name

human readable name

Type

str

concentration

parsed from initialAmount of Species in the SBML specification.

Type

float

kcats

1 / stoichimetry coefficients of its reactions.

Type

Kcats

mw

TODO: parsed from initalParameters/calculate from formula

Type

float

contribution

value of flux of variable, only accessible after optimizing the model.

Type

float

lower_bound

should be 0

Type

float

upper_bound

concentration * kcat if there is a concentration, mmw if is part of the pool constraint (unmeasured proteins) or 1000.

Type

float

formula
Type

str

charge
Type

float

_set_id_with_model(self, value)

Overwrite parent id setter to change constraints and variables.

from_metabolite(self, met: cobra.Metabolite)

Initialize Protein from Metabolite; i.e., when reading from SBML.

update_variable_bounds(self)

Sync object bounds with inner model variable bounds.

suscribe_to_pool(self, mmw: float)

Change internal pseudorreaction to have the common pool as reactant.

unsuscribe_to_pool(self)

Change internal pseudorreaction to have the common pool as reactant.

property concentration(self)float

Get upper bounds as [E] (conventionally in $frac{mmol}{gDW}$).

[E] multiplied by the kcat (expressed in the reaction stoichiometry as 1/kcat) yields $frac{mmol}/{gDW h}$.

Taken from [Benjamín J Sánchez et al., 2016] (https://www.embopress.org/doi/full/10.15252/msb.20167411).

property upper_bound(self)float

Get upper bounds as [E] (conventionally in $frac{mmol}{gDW}$).

[E] multiplied by the kcat (expressed in the reaction stoichiometry as 1/kcat) yields $frac{mmol}/{gDW h}$.

Taken from [Benjamín J Sánchez et al., 2016] (https://www.embopress.org/doi/full/10.15252/msb.20167411).

add_concentration(self, value: float)

Add concentration value.

It will unsuscribe the protein to the common protein pool, if suscribed.

property reverse_id(self)str

Generate the id of reverse_variable from the reaction’s id.

property contribution(self)str

Get primal value (analogous to flux) in the most recent solution.

property flux(self)float

Get flux value in the most recent solution.

Flux is the primal value of the corresponding variable in the model.

Warning

  • Accessing reaction fluxes through a Solution object is the safer, preferred, and only guaranteed to be correct way. You can see how to do so easily in the examples.

  • Reaction flux is retrieved from the currently defined self._model.solver. The solver status is checked but there are no guarantees that the current solver state is the one you are looking for.

  • If you modify the underlying model after an optimization, you will retrieve the old optimization values.

Raises
  • RuntimeError – If the underlying model was never optimized beforehand or the reaction is not part of a model.

  • OptimizationError – If the solver status is anything other than ‘optimal’.

  • AssertionError – If the flux value is not within the bounds.

property forward_variable(self)optlang.Variable

Get optlang.Variable representing the forward flux.

Returns

An optlang variable for the forward flux or None if reaction is not associated with a model.

Return type

optlang.interface.Variable

property reverse_variable(self)optlang.Variable

Get optlang.Variable representing the reverse flux.

Returns

An optlang variable for the reverse flux or None if reaction is not associated with a model.

Return type

optlang.interface.Variable

property objective_coefficient(self)float

Get the coefficient for this reaction in a linear objective (float).

Assuming that the objective of the associated model is summation of fluxes from a set of reactions, the coefficient for each reaction can be obtained individually using this property. A more general way is to use the model.objective property directly.

property bounds(self)Tuple[float, float]

Get or set the bounds directly from a tuple.

Convenience method for setting upper and lower bounds in one line using a tuple of lower and upper bound. Invalid bounds will raise an AssertionError. When using a HistoryManager context, this attribute can be set temporarily, reversed when the exiting the context.

property _metabolites(self)

Get metabolites.

property metabolites(self)Dict

Get metabolite of the protein pseudoreaction as the protein itself.

property reactions(self)FrozenSet[Reaction]

Retrieve immutable private reactions property.

property model(self)

Retrieve the model the reaction is a part of.

property reactants(self)

Return a list of reactants for the reaction.

property products(self)

Return a list of products for the reaction.

__setstate__(self, state)

Set attribute to point to model, mimicking cobra.Reaction.

__str__(self)str

Print str representation as id.

_repr_html_(self)str