Exemple #1
0
def get_dGr0_prime(sparse):
    try:
        r = Reaction(sparse)
        if not r.check_full_reaction_balancing():
            return np.nan, np.nan, 'unbalanbed reaction'
        dG0_prime, dG0_std = equilibrator.dG0_prime(r)
        return dG0_prime, dG0_std, ''
    except ValueError as e:
        return np.nan, np.nan, 'value error: ' + str(e)
    except KeyError as e:
        return np.nan, np.nan, 'key error: ' + str(e)
    def test_reaction_balancing(self):
        warnings.simplefilter('ignore', ResourceWarning)

        kegg_id_to_coeff = {'C00011' : -1, 'C00001' : -1, 'C01353' : 1}
        reaction = Reaction(kegg_id_to_coeff)
        self.assertTrue(reaction.check_full_reaction_balancing())

        kegg_id_to_coeff = {'C00036' : -1, 'C00149' : 1}  # oxaloacetate = malate
        reaction = Reaction(kegg_id_to_coeff)
        self.assertAlmostEqual(reaction.check_half_reaction_balancing(), 2.0)

        kegg_id_to_coeff = {'C00031' : -1, 'C00469' : 2}  # missing two CO2
        reaction = Reaction(kegg_id_to_coeff)
        self.assertDictEqual(reaction._get_reaction_atom_balance(),
                             {'O': -4, 'C': -2, 'e-': -44})
Exemple #3
0
def find_thermodynamic_reversibility_index(reactions):
    u"""
    Return the reversibility index of the given reactions.

    To determine the reversibility index, we calculate
    the reversibility index ln_gamma (see [1]_ section 3.5) of each reaction
    using the eQuilibrator API [2]_.

    Parameters
    ----------
        reactions: list of cobra.Reaction
            A list of reactions for which to calculate the reversibility index.

    Returns
    -------
    tuple
        list of cobra.Reaction, index pairs
            A list of pairs of reactions and their reversibility indexes.
        list of cobra.Reaction
            A list of reactions which contain at least one metabolite that
            could not be mapped to KEGG on the basis of its annotation.
        list of cobra.Reaction
            A list of reactions for which it is not possible to calculate the
            standard change in Gibbs free energy potential. Reasons of failure
            include that participating metabolites cannot be broken down with
            the group contribution method.
        list of cobra.Reaction
            A list of reactions that are not chemically or redox balanced.


    References
    ----------
    .. [1] Elad Noor, Arren Bar-Even, Avi Flamholz, Yaniv Lubling, Dan Davidi,
           Ron Milo; An integrated open framework for thermodynamics of
           reactions that combines accuracy and coverage, Bioinformatics,
           Volume 28, Issue 15, 1 August 2012, Pages 2037–2044,
           https://doi.org/10.1093/bioinformatics/bts317
    .. [2] https://pypi.org/project/equilibrator-api/

    """
    incomplete_mapping = []
    problematic_calculation = []
    reversibility_indexes = []
    unbalanced = []
    metabolite_mapping = {}

    for rxn in reactions:
        stoich = translate_reaction(rxn, metabolite_mapping)
        if len(stoich) < len(rxn.metabolites):
            incomplete_mapping.append(rxn)
            continue
        try:
            # Remove protons from stoichiometry.
            if "C00080" in stoich:
                del stoich["C00080"]
            eq_rxn = Reaction(stoich, rxn.id)
        except KeyError:
            incomplete_mapping.append(rxn)
            continue
        if eq_rxn.check_full_reaction_balancing():
            try:
                ln_rev_index = eq_rxn.reversibility_index()
            # TODO (Moritz Beber): Which exceptions can we expect here?
            except Exception:
                problematic_calculation.append(rxn)
                continue
            reversibility_indexes.append((rxn, ln_rev_index))
        else:
            unbalanced.append(rxn)
    reversibility_indexes.sort(key=lambda p: abs(p[1]), reverse=True)
    return (reversibility_indexes, incomplete_mapping, problematic_calculation,
            unbalanced)
Exemple #4
0
def find_thermodynamic_reversibility_index(reactions):
    u"""
    Return the reversibility index of the given reactions.

    To determine the reversibility index, we calculate
    the reversibility index ln_gamma (see [1]_ section 3.5) of each reaction
    using the eQuilibrator API [2]_.

    Parameters
    ----------
        reactions: list of cobra.Reaction
            A list of reactions for which to calculate the reversibility index.

    Returns
    -------
    tuple
        list of cobra.Reaction, index pairs
            A list of pairs of reactions and their reversibility indexes.
        list of cobra.Reaction
            A list of reactions which contain at least one metabolite that
            could not be mapped to KEGG on the basis of its annotation.
        list of cobra.Reaction
            A list of reactions for which it is not possible to calculate the
            standard change in Gibbs free energy potential. Reasons of failure
            include that participating metabolites cannot be broken down with
            the group contribution method.
        list of cobra.Reaction
            A list of reactions that are not chemically or redox balanced.


    References
    ----------
    .. [1] Elad Noor, Arren Bar-Even, Avi Flamholz, Yaniv Lubling, Dan Davidi,
           Ron Milo; An integrated open framework for thermodynamics of
           reactions that combines accuracy and coverage, Bioinformatics,
           Volume 28, Issue 15, 1 August 2012, Pages 2037–2044,
           https://doi.org/10.1093/bioinformatics/bts317
    .. [2] https://pypi.org/project/equilibrator-api/

    """
    incomplete_mapping = []
    problematic_calculation = []
    reversibility_indexes = []
    unbalanced = []
    metabolite_mapping = {}

    for rxn in reactions:
        stoich = translate_reaction(rxn, metabolite_mapping)
        if len(stoich) < len(rxn.metabolites):
            incomplete_mapping.append(rxn)
            continue
        try:
            # Remove protons from stoichiometry.
            if "C00080" in stoich:
                del stoich["C00080"]
            eq_rxn = Reaction(stoich, rxn.id)
        except KeyError:
            incomplete_mapping.append(rxn)
            continue
        if eq_rxn.check_full_reaction_balancing():
            try:
                ln_rev_index = eq_rxn.reversibility_index()
            # TODO (Moritz Beber): Which exceptions can we expect here?
            except Exception:
                problematic_calculation.append(rxn)
                continue
            reversibility_indexes.append((rxn, ln_rev_index))
        else:
            unbalanced.append(rxn)
    reversibility_indexes.sort(key=lambda p: abs(p[1]), reverse=True)
    return (
        reversibility_indexes, incomplete_mapping, problematic_calculation,
        unbalanced
    )