fig1.show()

fig2 = plt.figure(figsize=(14, 6))
fig2.suptitle("Valdiation")
ax_enz = fig2.add_subplot(1, 2, 1, xscale="log", yscale="log")
ax_enz.set_title("eCF(1SP) Enzyme concentrations")
ax_met = fig2.add_subplot(1, 2, 2, xscale="log", yscale="log")
ax_met.set_title("eCF(1SP) Metabolite concentrations")

model.ValidateMetaboliteConcentrations(lnC_ECM, ax_met)
model.ValidateEnzymeConcentrations(lnC_ECM, ax_enz)
fig2.show()

html.write("<p>\n")
html.write("<b>Experiment name:</b> %s</br>\n" % exp_name)
html.embed_matplotlib_figure(fig1)
html.write("</p><p>\n")
html.embed_matplotlib_figure(fig2)
html.write("</p><p>\n")
model.WriteHtmlTables(lnC_ECM, html)
html.write("</p>\n")

html.close()


# make plots also in linear scale just for fun
fig3 = plt.figure(figsize=(14, 6))
fig3.suptitle("Valdiation")
ax_enz = fig3.add_subplot(1, 2, 1, xscale="linear", yscale="linear")
ax_enz.set_title("eCF3(1SP) Enzyme concentrations")
ax_met = fig3.add_subplot(1, 2, 2, xscale="linear", yscale="linear")
예제 #2
0
def main(core=True):
    main_html = HtmlWriter('res/optknock.html')
    main_html.write('<title>OptKnock</title>')
    main_html.write('<h1>OptKnock</h1>\n')

    if core:
        model = init_wt_model('core', {}, BM_lower_bound=0.1)
        knockin_reactions(model, 'EDD,EDA', 0, 1000)
        set_exchange_bounds(model, 'g6p', lower_bound=-10)
        main_html.write('<ul>\n')
        main_html.write('<li>Model used: E.coli core</li>\n')
        main_html.write(
            '<li>Carbon source: glucose-6P, v <= 10 [mmol/g(DW) h]</li>\n')
        main_html.write(
            '<li>Biomass yield lower bound: v >= 0.1 [mmol/g(DW) h]</li>\n')
    else:
        model = init_wt_model('full', {'rib_D': -10}, BM_lower_bound=0.1)
        main_html.write('<ul>\n')
        main_html.write('<li>Model used: iJO1366 (E. coli full model)</li>\n')
        main_html.write(
            '<li>Carbon source: D-ribose, v <= 10 [mmol/g(DW) h]</li>\n')
        main_html.write(
            '<li>Biomass yield lower bound: v >= 0.1 [mmol/g(DW) h]</li>\n')

    knockin_reactions(model, 'PRK,RBC', 0, 1000)
    main_html.write('<li>Added reactions: phosphoribulokinase, RuBisCo</li>\n')
    optknock_reaction = 'RBC'

    #knockin_reactions(model, 'DXS', 0, 1000)
    #main_html.write('<li>Added reactions: deoxyribose synthase</li>\n')
    #optknock_reaction = 'DXS'

    main_html.write('</ul>\n')

    print "Running standard FBA..."
    ok = OptKnock(model)
    ok.prepare_FBA_primal()
    ok.prob.writeLP('res/fba_primal.lp')
    ok.solve()
    ok.print_primal_results(short=True)

    print '-' * 50

    print "Running dual FBA..."
    ok = OptKnock(model)
    ok.prepare_FBA_dual()
    ok.prob.writeLP('res/fba_dual.lp')
    ok.solve()
    ok.print_dual_results(short=True)

    print '-' * 50

    if False:
        print "Running OptSlope..."
        ok = OptKnock(model)
        ok.prepare_optslope(optknock_reaction, num_deletions=3)
        ok.write_linear_problem('res/optslope.lp')
        solution = ok.solve()
        if solution.status is not None:
            ok.print_optknock_results(short=True)
            ok_model = ok.get_optknock_model()

            #fig, ax = plt.subplots(1)
            #plot_multi_PPP([model, ok_model],
            #               ['Wild-Type', r'OptKnock'],
            #               optknock_reaction, ax)
            #ax.set_title(title)
            #fig.savefig('res/OS_PPP.pdf')

        print '-' * 50

    print "Running OptKnock for maximizing flux in %s..." % optknock_reaction
    ok = OptKnock(model)
    ok.prepare_optknock(optknock_reaction, num_deletions=1)
    ok.write_linear_problem('res/optknock.lp')
    solution = ok.solve()
    if solution.status is not None:
        ok.print_optknock_results(short=True)
        knockouts = ok.get_optknock_knockouts()
        ko_model = clone_model(model)
        knockout_reactions(ko_model, knockouts)

        main_html.write('<h2>Knockouts: %s</h2>\n' % knockouts)

        # draw the PPP as embedded SVG
        fig, ax = plt.subplots(1, figsize=(6, 6))
        wt_PPP, wt_slope = get_PPP(model, optknock_reaction)
        ax.fill_between(wt_PPP[:, 0].flat,
                        wt_PPP[:, 1].flat,
                        wt_PPP[:, 2].flat,
                        facecolor='#E0E0E0',
                        linewidth=0)

        ko_PPP, slope = get_PPP(ko_model, optknock_reaction)
        if slope is None:
            ko_text = 'Not feasible at any Rubisco flux'
            ko_color = '#FF9073'
        else:
            slope = np.round(slope, 1)
            ko_text = ('Slope = %g' % slope)
            if slope > 0:
                ko_color = '#00B64F'
            else:
                ko_color = '#FF7060'

        ax.fill_between(ko_PPP[:, 0].flat,
                        ko_PPP[:, 1].flat,
                        ko_PPP[:, 2].flat,
                        facecolor=ko_color,
                        linewidth=1)
        main_html.embed_matplotlib_figure(fig, width=400, height=400)

        # draw the flux map as embedded SVG
        ok.draw_svg(main_html)

        # write the flux summary for the knockout model as HTML
        ok.model_summary(main_html)
예제 #3
0
def main():
    main_html = HtmlWriter('res/fba.html')
    main_html.write('<h1>Flux Balance Analysis</h1>\n')

    carbon_sources = {}
    BM_lower_bound = 0.01
    ko_reactions = ''
    ki_reactions = ''
    PPP_reaction = ''

    # full model carbon sources: glc, fru, xyl__D, succ, ac, rib__D, pyr

    #########################################
    # Core model for testing glycolysis KOs #
    #########################################
    #model = init_wt_model('core', {'ac' : -10}); ko_reactions = 'PGM'; ki_reactions = 'RED';
    #model = init_wt_model('core', {'glc' : -10}); ko_reactions = 'PFK'; ki_reactions = 'RED';

    #######################################
    # Full model Rubisco optimization KOs #
    #######################################
    #model = init_wt_model('full', {'ac' : -10}); ko_reactions = 'PGM,TRSARr,HPYRRx,HPYRRy'; ki_reactions = 'RED';
    #model = init_wt_model('full', {'rib_D' : -10}); ko_reactions = 'TKT1'; ki_reactions = 'RBC,PRK'; PPP_reaction = 'RBC';
    model = init_wt_model('full', {'xyl_D': -10})
    ko_reactions = 'RPI'
    ki_reactions = 'RBC,PRK'
    PPP_reaction = 'RBC'
    #model = init_wt_model('full', {'xyl_D' : -10}); ko_reactions = 'G6PDH2r,PFK,F6PA,FRUK,PFK_3,DRPA'; ki_reactions = 'RBC,PRK';
    #model = init_wt_model('full', {'fru' : -10, 'rib_D' : -10}); ko_reactions = 'G6PDH2r,PFK,F6PA,FRUK,PFK_3,DRPA,TKT1,TKT2'; ki_reactions = 'PKT';

    ###############################
    # Shikimate generating strain #
    ###############################
    #model = init_wt_model('full', {'fru' : -10});
    #ko_reactions = 'G6PDH2r,TALA'; ki_reactions = 'EX_3dhsk_c'; PPP_reaction = 'EX_3dhsk_c';
    #ko_reactions = 'G6PDH2r,PFK,F6PA,FRUK,PFK_3,DRPA'; ki_reactions = 'PKT'; PPP_reaction = 'PKT';

    ##########################################################
    # Testing no growth when electrons are provided directly #
    ##########################################################
    #model = init_wt_model('full', {}); ki_reactions = 'RED';
    #ko_reactions = "POR5,MCITL2";
    #ko_reactions = "POR5,FTHFLi,GART,RPI";

    models = {'WT': model}

    if ko_reactions:
        for k in models.keys():
            m = deepcopy(models[k])
            knockout_reactions(m, ko_reactions)
            models[k + ' -%s' % ko_reactions] = m

    if ki_reactions:
        for k in models.keys():
            m = deepcopy(models[k])
            knockin_reactions(m, ki_reactions)
            models[k + ' +%s' % ki_reactions] = m

    # Run the optimization for the objective reaction and medium composition
    # set in the file.
    main_html.write('<table border="1">\n')
    main_html.write(
        '<tr><td><b>Model Name</b></td><td><b>Growth Yield</b></td></tr>\n')
    growths = {}
    for name, model in sorted(models.iteritems()):
        print "solving %50s model" % name,
        ok = OptKnock(model)
        ok.prepare_FBA_primal()
        ok.solve()
        growths[name] = ok.get_objective_value()

        if growths[name] is None:
            main_html.write('<tr><td>%s</td><td>infeasible</td></tr>\n' % name)
        else:
            print ': f = %.3g' % growths[name]
            main_html.write('<tr><td>')
            html = main_html.branch(name)
            main_html.write('</td><td>%.3g</td></tr>\n' % growths[name])
            html.write('<h1>Model name: %s</h1>\n' % name)
            html.write('<h2>Growth Yield: %.3g</h2>\n' % growths[name])
            ok.draw_svg(html)
            ok.model_summary(html)
    main_html.write('</table>\n')

    if PPP_reaction:
        print 'Calculating Phenotypic Phase Plane for phosphoketolase ...'
        fig, ax = plt.subplots(1, figsize=(6, 6))
        plot_multi_PPP(models, PPP_reaction, ax)
        ax.set_title('Phenotypic Phase Plane')
        main_html.embed_matplotlib_figure(fig, width=400, height=400)
예제 #4
0
파일: fba.py 프로젝트: eladnoor/optslope
def main():
    main_html = HtmlWriter('res/fba.html')
    main_html.write('<h1>Flux Balance Analysis</h1>\n')
    
    carbon_sources = {}
    BM_lower_bound = 0.01
    ko_reactions = ''
    ki_reactions = ''
    PPP_reaction = ''
    
    # full model carbon sources: glc, fru, xyl__D, succ, ac, rib__D, pyr
    
    #########################################
    # Core model for testing glycolysis KOs #
    #########################################
    #model = init_wt_model('core', {'ac' : -10}); ko_reactions = 'PGM'; ki_reactions = 'RED';
    #model = init_wt_model('core', {'glc' : -10}); ko_reactions = 'PFK'; ki_reactions = 'RED';

    #######################################
    # Full model Rubisco optimization KOs #
    #######################################
    #model = init_wt_model('full', {'ac' : -10}); ko_reactions = 'PGM,TRSARr,HPYRRx,HPYRRy'; ki_reactions = 'RED';
    #model = init_wt_model('full', {'rib_D' : -10}); ko_reactions = 'TKT1'; ki_reactions = 'RBC,PRK'; PPP_reaction = 'RBC';
    model = init_wt_model('full', {'xyl_D' : -10}); ko_reactions = 'RPI'; ki_reactions = 'RBC,PRK'; PPP_reaction = 'RBC';
    #model = init_wt_model('full', {'xyl_D' : -10}); ko_reactions = 'G6PDH2r,PFK,F6PA,FRUK,PFK_3,DRPA'; ki_reactions = 'RBC,PRK';
    #model = init_wt_model('full', {'fru' : -10, 'rib_D' : -10}); ko_reactions = 'G6PDH2r,PFK,F6PA,FRUK,PFK_3,DRPA,TKT1,TKT2'; ki_reactions = 'PKT';
    
    ###############################
    # Shikimate generating strain #
    ###############################
    #model = init_wt_model('full', {'fru' : -10});
    #ko_reactions = 'G6PDH2r,TALA'; ki_reactions = 'EX_3dhsk_c'; PPP_reaction = 'EX_3dhsk_c';
    #ko_reactions = 'G6PDH2r,PFK,F6PA,FRUK,PFK_3,DRPA'; ki_reactions = 'PKT'; PPP_reaction = 'PKT';

    ##########################################################
    # Testing no growth when electrons are provided directly #
    ##########################################################
    #model = init_wt_model('full', {}); ki_reactions = 'RED';
    #ko_reactions = "POR5,MCITL2";
    #ko_reactions = "POR5,FTHFLi,GART,RPI"; 
    
    models = {'WT' : model}

    if ko_reactions:
        for k in models.keys():
            m = deepcopy(models[k])
            knockout_reactions(m, ko_reactions)
            models[k + ' -%s' % ko_reactions] = m

    if ki_reactions:
        for k in models.keys():
            m = deepcopy(models[k])
            knockin_reactions(m, ki_reactions)
            models[k + ' +%s' % ki_reactions] = m

    # Run the optimization for the objective reaction and medium composition
    # set in the file.
    main_html.write('<table border="1">\n')
    main_html.write('<tr><td><b>Model Name</b></td><td><b>Growth Yield</b></td></tr>\n')
    growths = {}
    for name, model in sorted(models.iteritems()):
        print "solving %50s model" % name,
        ok = OptKnock(model)
        ok.prepare_FBA_primal()
        ok.solve()
        growths[name] = ok.get_objective_value()
    
        if growths[name] is None:
            main_html.write('<tr><td>%s</td><td>infeasible</td></tr>\n' % name)
        else:
            print ': f = %.3g' % growths[name]
            main_html.write('<tr><td>')
            html = main_html.branch(name)
            main_html.write('</td><td>%.3g</td></tr>\n' % growths[name])
            html.write('<h1>Model name: %s</h1>\n' % name)
            html.write('<h2>Growth Yield: %.3g</h2>\n' % growths[name])
            ok.draw_svg(html)
            ok.model_summary(html)
    main_html.write('</table>\n')

    if PPP_reaction:
        print 'Calculating Phenotypic Phase Plane for phosphoketolase ...'
        fig, ax = plt.subplots(1, figsize=(6,6))
        plot_multi_PPP(models, PPP_reaction, ax)
        ax.set_title('Phenotypic Phase Plane')
        main_html.embed_matplotlib_figure(fig, width=400, height=400)