Exemplo n.º 1
0
def python_main():
    sys.path.append('../python')
    from training_data import TrainingData
    from component_contribution import ComponentContribution
    from kegg_model import KeggModel

    reaction_strings = open(REACTION_FNAME, 'r').readlines()
    model = KeggModel.from_formulas(reaction_strings)    

    td = TrainingData()
    cc = ComponentContribution(td)
    model.add_thermo(cc)
    
    dG0_prime, dG0_std = model.get_transformed_dG0(pH=7.5, I=0.2, T=298.15)
    
    sys.stdout.write('[' + 
                     ', '.join([str(x) for x in model.dG0.flat]) + '; ' + 
                     ', '.join([str(x) for x in dG0_prime.flat]) + 
                     ']')    
        params["contributions"] = [dG0_rc, dG0_gc]
        params["covariances"] = [V_rc, V_gc, V_inf]
        params["MSEs"] = [MSE_rc, MSE_gc, MSE_inf]
        params["projections"] = [P_R_rc, P_R_gc * G.T * P_N_rc, P_N_gc * G.T * P_N_rc, P_R_gc, P_N_rc, P_N_gc]
        params["inverses"] = [inv_S, inv_GS, inv_SWS, inv_GSWGS]

        # Calculate the total of the contributions and covariances
        cov_dG0 = V_rc * MSE_rc + V_gc * MSE_gc + V_inf * MSE_inf

        return dG0_cc, cov_dG0, params


if __name__ == "__main__":
    from kegg_model import KeggModel

    reaction_strings = sys.stdin.readlines()
    td = TrainingData()
    cc = ComponentContribution(td)
    model = KeggModel.from_formulas(reaction_strings)
    model_dG0, model_cov_dG0 = cc.estimate_kegg_model(model)

    model_dG0_prime = model_dG0 + model.get_transform_ddG0(pH=7.5, I=0.2, T=298.15)

    sys.stdout.write(
        "["
        + ", ".join([str(x) for x in model_dG0.flat])
        + "; "
        + ", ".join([str(x) for x in model_dG0_prime.flat])
        + "]"
    )
Exemplo n.º 3
0
with open('../examples/vz/StoiMat.tsv', 'r') as tsv:
    tabinput = [line.strip().split('\t') for line in tsv]

reactions = tabinput[0]
reactions = reactions[1:]
tabinput = tabinput[1:]

S = np.zeros((len(tabinput), len(tabinput[0]) - 1))
cids = list()
for i in range(len(tabinput)):
    cids.append(float(tabinput[i][0].replace('"', '')))
    for j in range(len(tabinput[0]) - 1):
        S[i, j] = tabinput[i][j + 1]

model = KeggModel(S, cids)
model = model.check_S_balance()
td = TrainingData()
cc = ComponentContribution(td)
model_dG0, model_cov_dG0 = cc.estimate_kegg_model(model)
model_dG0_prime = model_dG0 + model.get_transform_ddG0(pH=7.5, I=0.2, T=298.15)

dG0_std = np.sqrt(model_cov_dG0.diagonal())

out_file = '../examples/vz/output/cc_dG.tsv'
outf = open(out_file, "w")
outf.write("reaction\tdGr\tdGrSD\n")
for i in range(len(reactions)):
    outf.write(reactions[i] + "\t" + str(float(model_dG0_prime[i])) + "\t" +
               str(float(dG0_std[0, i])) + "\n")
        params['contributions'] = [dG0_rc, dG0_gc]
        params['covariances']   = [V_rc, V_gc, V_inf]
        params['MSEs']          = [MSE_rc, MSE_gc, MSE_inf]
        params['projections']   = [P_R_rc,
                                   P_R_gc * G.T * P_N_rc,
                                   P_N_gc * G.T * P_N_rc,
                                   P_R_gc,
                                   P_N_rc,
                                   P_N_gc]
        params['inverses']      = [inv_S, inv_GS, inv_SWS, inv_GSWGS]

        # Calculate the total of the contributions and covariances
        cov_dG0 = V_rc * MSE_rc + V_gc * MSE_gc + V_inf * MSE_inf
        
        return dG0_cc, cov_dG0, params

if __name__ == '__main__':
    from kegg_model import KeggModel
    
    reaction_strings = sys.stdin.readlines()
    td = TrainingData()
    cc = ComponentContribution(td)
    model = KeggModel.from_formulas(reaction_strings)
    model_dG0, model_cov_dG0 = cc.estimate_kegg_model(model)
    
    model_dG0_prime = model_dG0 + model.get_transform_ddG0(pH=7.5, I=0.2, T=298.15)
    
    sys.stdout.write('[' + 
                     ', '.join([str(x) for x in model_dG0.flat]) + '; ' + 
                     ', '.join([str(x) for x in model_dG0_prime.flat]) + 
                     ']')    
Exemplo n.º 5
0
with open('../examples/vz/StoiMat.tsv','r') as tsv:
    tabinput = [line.strip().split('\t') for line in tsv]

reactions = tabinput[0]
reactions = reactions[1:]
tabinput = tabinput[1:]

S = np.zeros((len(tabinput), len(tabinput[0])-1))
cids = list()
for i in range(len(tabinput)):
    cids.append(float(tabinput[i][0].replace('"','')))
    for j in range(len(tabinput[0])-1):
        S[i,j] = tabinput[i][j+1]

model = KeggModel(S, cids)
model = model.check_S_balance()
td = TrainingData()
cc = ComponentContribution(td)
model_dG0, model_cov_dG0 = cc.estimate_kegg_model(model)
model_dG0_prime = model_dG0 + model.get_transform_ddG0(pH=7.5, I=0.2, T=298.15)

dG0_std = np.sqrt(model_cov_dG0.diagonal())

out_file = '../examples/vz/output/cc_dG.tsv'
outf = open(out_file, "w")
outf.write("reaction\tdGr\tdGrSD\n")
for i in range(len(reactions)):
    outf.write(reactions[i] + "\t" + str(float(model_dG0_prime[i])) + "\t" +str(float(dG0_std[0,i]))+ "\n")

outf.close()