Пример #1
0
def calculate_deltaG0s(model,
                       kegg_compounds,
                       pH=default_pH,
                       I=default_I,
                       T=default_T):
    """ Calculate standard Gibbs Energy for reactions in model (as many as possible) using eQuilibrator.

    Args:
        model (CBModel): model
        kegg_compounds (list): KEGG compounds accepted by eQuilibrator
        pH (float): pH (default: 7.0)
        I (float): ionic strenght (default: 0.25)
        T (float): temperature (default: 298.15 K (25.0 C))

    Returns:
        dict: standard Gibbs Energies indexed by reaction ids
        dict: estimation error indexed by reaction ids

    """
    kegg_rxns = build_kegg_reactions(model, kegg_compounds)
    kmodel = KeggModel.from_formulas(kegg_rxns.values(), raise_exception=True)
    kmodel.add_thermo(CC.init())
    dG0, sdG0, _ = kmodel.get_transformed_dG0(pH, I, T)

    dG0 = dict(zip(kegg_rxns.keys(), dG0.A1))
    sdG0 = dict(zip(kegg_rxns.keys(), sdG0.A1))

    return dG0, sdG0
Пример #2
0
    def __init__(self, reactions):

        self.cc = ComponentContribution.init()
        self.pH = 7.5
        self.I = 0.2
        self.T = default_T
        self.R = R
        self._not_balanced = []
        self.reactions = []
        self.Kmodel = self.generate_kegg_model(reactions)
        self.dG0_prime = self.add_thermodynamics(reactions)
    def __init__(self, reactions):

        self.cc = ComponentContribution.init()
        self.pH = 7.5
        self.I = 0.2
        self.T = default_T
        self.R = R
        self._not_balanced = []
        self.reactions = []    
        self.Kmodel = self.generate_kegg_model(reactions)
        self.dG0_prime = self.add_thermodynamics(reactions)
    def _component_contribution_wrapper(self, reaction_list_I, pH_I,
                                        temperature_I, ionic_strength_I):
        """wrapper for component contribution"""

        # Orginal implementation involves an input of a reaction list
        # the dG_prime and dG_std for each reaction are then calculated.
        # Because we are interested in accounting for transportation
        # and metabolite concentration,
        # we need to extraction out the dG_prime and dG_std
        # of formation and calculated the dG_prime and
        # dG_std for each reaction after accounting for
        # transportation and metabolite concentration.
        # TODO: change input from reaction list to metabolite list
        # however this may be problematic due to the implementation
        # of component_contribution (i.e., the group contribution
        # and reactant contribution are calculated along orthoganol planes
        # in order to gain greater coverage and accuracy of predicted
        # dG_f values)

        # Debugging:
        #wolf = ['C00049 + C00002 <=> C03082 + C00008',
        #        'C00026 + C00049 <=> C00025 + C00036',
        #        'C00158 <=> C00311',
        #        'C00631 <=> C00001 + C00074',
        #        'C00354 <=> C00111 + C00118',
        #        'C00020 + C00002 <=> 2 C00008',
        #        'C00002 + C00001 <=> C00008 + C00009',
        #        'C00015 + C00002 <=> C00075 + C00008',
        #        'C00033 + C00002 + C00010 <=> C00024 + C00020 + C00013']
        #model = KeggModel.from_formulas(wolf)

        model = KeggModel.from_formulas(reaction_list_I)

        td = TrainingData()
        cc = ComponentContribution(td)
        model.add_thermo(cc)

        dG0_prime_f, dG0_var_f = model.get_transformed_dG0(pH=pH_I,
                                                           I=ionic_strength_I,
                                                           T=temperature_I)

        return dG0_prime_f, dG0_var_f
Пример #5
0
    def __init__(self):
        self.prepare_mappings()

        reactions = self.get_reactions_from_model()
        self.reactions = []
        self._not_balanced = []

        self.rstrings = []
        for r in reactions:
            k = r.kegg_reaction
            if k:
                if k.is_balanced() and not k.is_empty():
                    self.rstrings.append(k.write_formula())
                    self.reactions.append(r)
            else:
                self._not_balanced.append(r)
        self.Kmodel = KeggModel.from_formulas(self.rstrings)

        self.cc = ComponentContribution.init()
        self.pH = 7.3
        self.I = 0.25
        self.RT = R * default_T
    def __init__(self):
        self.prepare_mappings()

        reactions = self.get_reactions_from_model()
        self.reactions = []
        self._not_balanced = []

        self.rstrings = []
        for r in reactions:
            k = r.kegg_reaction
            if k:
                if k.is_balanced() and not k.is_empty():
                    self.rstrings.append(k.write_formula())
                    self.reactions.append(r)
            else:
                self._not_balanced.append(r)
        self.Kmodel = KeggModel.from_formulas(self.rstrings)

        self.cc = ComponentContribution.init()
        self.pH = 7.3
        self.I = 0.25
        self.RT = R * default_T
        model.rids = rids
        pH = fields.GetFloatField('PH', 7.5)
        I = fields.GetFloatField('I', 0.2)
        T = fields.GetFloatField('T', 298.15)
        pathways.append({'entry': entry, 'model': model, 'fluxes': fluxes,
                         'bounds': bounds, 'pH': pH, 'I': I, 'T': T})
    return pathways

if __name__ == '__main__':
    #fname = sys.argv[1]
    fname = 'mdf_pathways'
    
    REACTION_FNAME = 'scripts/%s.txt' % fname
    pathways = KeggFile2ModelList(REACTION_FNAME)
    html_writer = HtmlWriter('res/%s.html' % fname)
    cc = ComponentContribution.init()

    matdict = {}
    for p in pathways:
        html_writer.write('<h2>%s</h2>' % p['entry'])

        p['model'].add_thermo(cc)

        mdf = MaxMinDrivingForce(p['model'], p['fluxes'], p['bounds'],
                                 pH=p['pH'], I=p['I'], T=p['T'],
                                 html_writer=html_writer)

        mdf_solution, dGm_prime, dG0_std = mdf.Solve()
        logging.info('Pathway %s: MDF = %.1f' % (p['entry'], mdf_solution))
        
        matdict[p['entry'] + '.dGm_prime'] = dGm_prime
Пример #8
0
# -*- coding: utf-8 -*-
"""
Created on Wed Jun  3 15:25:49 2015

@author: noore
"""
from component_contribution.component_contribution_trainer import ComponentContribution
from scipy.io import savemat
import argparse

if __name__ == '__main__':
    parser = argparse.ArgumentParser(
        description=
        'Prepare all thermodynamic training data in a .mat file for running '
        'component contribution.')
    parser.add_argument('out_file',
                        type=argparse.FileType('wb'),
                        help='path to the .mat file that should be written '
                        'containing the training data')

    args = parser.parse_args()
    cc = ComponentContribution()

    mdict = {
        'w': cc.train_w,
        'b': cc.train_b,
        'G': cc.create_group_incidence_matrix(),
        'cids': cc.train_cids,
        'S': cc.train_S
    }
    savemat(args.out_file, mdict, do_compression=True)
# -*- coding: utf-8 -*-
"""
Created on Wed Jun  3 15:25:49 2015

@author: noore
"""
from component_contribution.component_contribution_trainer import ComponentContribution
from scipy.io import savemat
import argparse

if __name__ == '__main__':
    parser = argparse.ArgumentParser(description=
        'Prepare all thermodynamic training data in a .mat file for running '
        'component contribution.')
    parser.add_argument('out_file', type=argparse.FileType('wb'),
                       help='path to the .mat file that should be written '
                       'containing the training data')
    
    args = parser.parse_args()
    cc = ComponentContribution()

    mdict = {
             'w': cc.train_w,
             'b': cc.train_b,
             'G': cc.create_group_incidence_matrix(),
             'cids': cc.train_cids,
             'S': cc.train_S
             }
    savemat(args.out_file, mdict, do_compression=True)
Пример #10
0
 def _CalcGibbsEnerigesFromComponentContribution(self):
     cc = ComponentContribution.init()
     self.kegg_model.add_thermo(cc)
     dG0_prime, dG0_std, sqrt_Sigma = self.kegg_model.get_transformed_dG0(
         pH=7.5, I=0.1, T=298.15)
     self.rid2dG0 = dict(zip(self.kegg_model.rids, dG0_prime.flat))