:mod:`geckopy` ============== .. py:module:: geckopy Subpackages ----------- .. toctree:: :titlesonly: :maxdepth: 3 experimental/index.rst integration/index.rst Submodules ---------- .. toctree:: :titlesonly: :maxdepth: 1 flux_analysis/index.rst io/index.rst model/index.rst protein/index.rst reaction/index.rst Package Contents ---------------- Classes ~~~~~~~ .. autoapisummary:: geckopy.Model geckopy.Protein Functions ~~~~~~~~~ .. autoapisummary:: geckopy.flux_variability_analysis .. function:: 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. 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: #. Since there are duplicated reactions (for each direction), the complementary reaction must be blocked to remove artificial flux variation. #. Some reactions might be fixed (the glucose exchange reaction in the paper) to compare them with non-EC models. #. The final reported flux is :math:`v_{max}, v_{max}^{rev} \forall v \in \text{reactions}` Additionally, just the combined reaction `arm_` is reported for isozymes. .. seealso:: :py:func:`cobrapy:cobra.flux_analysis.flux_variability_analysis` :param model: :type model: geckopy.Model :param fixed_reactions: List of reactions to be fixed (as in the second point in the description) :type fixed_reactions: Optional[List[str]] :param ignored_reactions: List of reactions to be ignored :type ignored_reactions: Optional[List[str]] :param n_proc: Number of processes to use. Default: the number of logical CPUs. :type n_proc: int :param inplace: Whether to copy the model to then apply the changes :type inplace: bool :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 :rtype: pandas.DataFrame .. class:: Model(id_or_model: Union[(str, cobra.Model)] = None, name: str = None, hardcoded_rev_reactions: bool = True) Bases: :class:`cobra.Model` Extension of cobra.Model providing an API for proteins in EC models. .. attribute:: reactions A DictList where the key is the reaction identifier and the value a Reaction. :type: DictList .. attribute:: metabolites A DictList where the key is the metabolite identifier and the value a Metabolite. :type: DictList .. attribute:: proteins A DictList where the key is the metabolite identifier and the value a Protein. :type: DictList .. attribute:: genes A DictList where the key is the gene identifier and the value a Gene. :type: DictList .. attribute:: groups A DictList where the key is the group identifier and the value a Group. :type: DictList .. attribute:: solution # TODO: separate proteins from cobra.Reactions The last obtained solution from optimizing the model. :type: Solution .. method:: __setstate__(self, state: Dict) Make sure all cobra.Objects in the model point to the model. .. method:: from_cobra(self, model: cobra.Model, name: str) Initialize from cobra model. .. method:: get_total_measured_proteins(self) -> float Sum of all `Proteins` in the model that has a concentration. .. method:: 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. :param p_total: measured total protein fraction in cell in g protein / gDW :type p_total: float :param sigma_saturation_factor: part of proteome that can be used by metabolism :type sigma_saturation_factor: float :param fn_mass_fraction_unmeasured_matched: 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. :type fn_mass_fraction_unmeasured_matched: float :param protein_list: list of ids of proteins to constrain. This is useful for inspecting the protein utilization of, e.g., a heterologous pathway. :type protein_list: List[str] .. method:: 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. :param read_id: id of the common protein pool pseudorreaction to add. :type read_id: str :param met_id: id of the common protein pool metabolite to add. :type met_id: str .. method:: 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. .. method:: _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. .. method:: add_proteins(self, protein_list: Iterator[Protein]) Add proteins to the model, in the same fashion as `.add_metabollites`. .. method:: 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. :param reaction_list: A list of `cobra.Reaction` objects :type reaction_list: list .. method:: optimize(self, objective_sense: Optional[str] = None, raise_error: bool = False) -> Tuple[(cobra.Solution, cobra.Solution)] Optimize the model using flux balance analysis. :param objective_sense: Whether fluxes should be maximized or minimized. In case of None, the previous direction is used. :type objective_sense: {None, 'maximize' 'minimize'}, optional :param raise_error: If true, raise an OptimizationError if solver status is not optimal. :type raise_error: bool .. rubric:: 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. .. method:: 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:: Protein(id: Union[(str, Metabolite)] = None, concentration: float = None, molecular_weight: float = 0.0, name: str = '') Bases: :class:`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). .. attribute:: id identifier of protein, should be an Uniprot ID or "prot_" :type: str .. attribute:: name human readable name :type: str .. attribute:: concentration parsed from `initialAmount` of `Species` in the SBML specification. :type: float .. attribute:: kcats 1 / stoichimetry coefficients of its reactions. :type: Kcats .. attribute:: mw TODO: parsed from initalParameters/calculate from formula :type: float .. attribute:: contribution value of flux of variable, only accessible after optimizing the model. :type: float .. attribute:: lower_bound should be 0 :type: float .. attribute:: upper_bound concentration * kcat if there is a concentration, mmw if is part of the pool constraint (unmeasured proteins) or 1000. :type: float .. attribute:: formula :type: str .. attribute:: charge :type: float .. method:: _set_id_with_model(self, value) Overwrite parent id setter to change constraints and variables. .. method:: from_metabolite(self, met: cobra.Metabolite) Initialize `Protein` from `Metabolite`; i.e., when reading from SBML. .. method:: update_variable_bounds(self) Sync object bounds with inner model variable bounds. .. method:: suscribe_to_pool(self, mmw: float) Change internal pseudorreaction to have the common pool as reactant. .. method:: unsuscribe_to_pool(self) Change internal pseudorreaction to have the common pool as reactant. .. method:: concentration(self) -> float :property: 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). .. method:: upper_bound(self) -> float :property: 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). .. method:: add_concentration(self, value: float) Add concentration value. It will unsuscribe the protein to the common protein pool, if suscribed. .. method:: reverse_id(self) -> str :property: Generate the id of reverse_variable from the reaction's id. .. method:: contribution(self) -> str :property: Get primal value (analogous to flux) in the most recent solution. .. method:: flux(self) -> float :property: 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. :raises OptimizationError: If the solver status is anything other than 'optimal'. :raises AssertionError: If the flux value is not within the bounds. .. method:: forward_variable(self) -> optlang.Variable :property: 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. :rtype: optlang.interface.Variable .. method:: reverse_variable(self) -> optlang.Variable :property: 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. :rtype: optlang.interface.Variable .. method:: objective_coefficient(self) -> float :property: 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. .. method:: bounds(self) -> Tuple[(float, float)] :property: 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. .. method:: _metabolites(self) :property: Get metabolites. .. method:: metabolites(self) -> Dict :property: Get metabolite of the protein pseudoreaction as the protein itself. .. method:: reactions(self) -> FrozenSet[Reaction] :property: Retrieve immutable private reactions property. .. method:: model(self) :property: Retrieve the model the reaction is a part of. .. method:: reactants(self) :property: Return a list of reactants for the reaction. .. method:: products(self) :property: Return a list of products for the reaction. .. method:: __setstate__(self, state) Set attribute to point to model, mimicking `cobra.Reaction`. .. method:: __str__(self) -> str Print str representation as id. .. method:: _repr_html_(self) -> str