Esempio n. 1
0
def test_all_modules():
    from pygibbs.groups import GroupContribution
    gc = GroupContribution(sqlite_name="gibbs.sqlite", html_name="dG0_test")
    gc.init()
    c_range = (1e-6, 1e-2)
    c_mid = 1e-3
    pH = 8
    I = 0.1
    T = 300
    map_cid = {201:2, 454:8} # CIDs that should be mapped to other CIDs because they are unspecific (like NTP => ATP)
    
    cids_with_missing_dG_f = set()
    
    f = open("../res/feasibility.csv", "w")
    csv_output = csv.writer(f)
    csv_output.writerow(("MID", "module name", "pH", "I", "T", "pCr", "MTDF"))
    for mid in sorted(gc.kegg().mid2rid_map.keys()):
        module_name = gc.kegg().mid2name_map[mid]
        try:
            S, _rids, _fluxes, cids = gc.kegg().get_module(mid)
        except KeggMissingModuleException as e:
            sys.stderr.write("WARNING: " + str(e) + "\n")
            continue
        _Nr, Nc = S.shape
        for pH in [5, 6, 7, 8, 9]:
            for I in [0.0, 0.1, 0.2, 0.3, 0.4]:
                dG0_f = pylab.zeros((Nc, 1))
                bounds = []
                for c in range(Nc):
                    cid = map_cid.get(cids[c], cids[c])
                    try:
                        pmap = gc.cid2PseudoisomerMap(cid)
                        dG0_f[c] = gc.pmap_to_dG0(pmap, pH, I, T)
                    except MissingCompoundFormationEnergy as e:
                        if (cid not in cids_with_missing_dG_f):
                            sys.stderr.write("Setting the dG0_f of C%05d to NaN because: %s\n"\
                                             % (cid, str(e)))
                            cids_with_missing_dG_f.add(cid)
                        dG0_f[c] = pylab.nan
            
                bounds = [gc.kegg().cid2bounds.get(cid, (None, None)) for cid in cids]

                try:
                    _dG_f, _concentrations, pCr = find_pCr(S, dG0_f, c_mid=c_mid, ratio=3.0, bounds=bounds)
                except LinProgNoSolutionException:
                    sys.stderr.write("M%05d: Pathway is theoretically infeasible\n" % mid)
                    pCr = None

                try:
                    _dG_f, _concentrations, MTDF = find_mtdf(S, dG0_f, c_range=c_range, bounds=bounds)
                except LinProgNoSolutionException:
                    sys.stderr.write("M%05d: Pathway is theoretically infeasible\n" % mid)
                    MTDF = None
                
                csv_output.writerow([mid, module_name, pH, I, T, pCr, MTDF])
                        
    f.close()
Esempio n. 2
0
def test_all_modules():
    from pygibbs.groups import GroupContribution
    gc = GroupContribution(sqlite_name="gibbs.sqlite", html_name="dG0_test")
    gc.init()
    c_range = (1e-6, 1e-2)
    c_mid = 1e-3
    pH = 8
    I = 0.1
    T = 300
    map_cid = {
        201: 2,
        454: 8
    }  # CIDs that should be mapped to other CIDs because they are unspecific (like NTP => ATP)

    cids_with_missing_dG_f = set()

    f = open("../res/feasibility.csv", "w")
    csv_output = csv.writer(f)
    csv_output.writerow(("MID", "module name", "pH", "I", "T", "pCr", "MTDF"))
    for mid in sorted(gc.kegg().mid2rid_map.keys()):
        module_name = gc.kegg().mid2name_map[mid]
        try:
            S, _rids, _fluxes, cids = gc.kegg().get_module(mid)
        except KeggMissingModuleException as e:
            sys.stderr.write("WARNING: " + str(e) + "\n")
            continue
        _Nr, Nc = S.shape
        for pH in [5, 6, 7, 8, 9]:
            for I in [0.0, 0.1, 0.2, 0.3, 0.4]:
                dG0_f = pylab.zeros((Nc, 1))
                bounds = []
                for c in range(Nc):
                    cid = map_cid.get(cids[c], cids[c])
                    try:
                        pmap = gc.cid2PseudoisomerMap(cid)
                        dG0_f[c] = gc.pmap_to_dG0(pmap, pH, I, T)
                    except MissingCompoundFormationEnergy as e:
                        if (cid not in cids_with_missing_dG_f):
                            sys.stderr.write("Setting the dG0_f of C%05d to NaN because: %s\n"\
                                             % (cid, str(e)))
                            cids_with_missing_dG_f.add(cid)
                        dG0_f[c] = pylab.nan

                bounds = [
                    gc.kegg().cid2bounds.get(cid, (None, None)) for cid in cids
                ]

                try:
                    _dG_f, _concentrations, pCr = find_pCr(S,
                                                           dG0_f,
                                                           c_mid=c_mid,
                                                           ratio=3.0,
                                                           bounds=bounds)
                except LinProgNoSolutionException:
                    sys.stderr.write(
                        "M%05d: Pathway is theoretically infeasible\n" % mid)
                    pCr = None

                try:
                    _dG_f, _concentrations, MTDF = find_mtdf(S,
                                                             dG0_f,
                                                             c_range=c_range,
                                                             bounds=bounds)
                except LinProgNoSolutionException:
                    sys.stderr.write(
                        "M%05d: Pathway is theoretically infeasible\n" % mid)
                    MTDF = None

                csv_output.writerow([mid, module_name, pH, I, T, pCr, MTDF])

    f.close()