print(yeast_model.optimize())
print(maritima_model.optimize())

print("--------------------------------------------------------------")
print("Finding transport reactions")
yeast_transport_reactions = get_transport_reaction_list(yeast_model)
maritima_transport_reactions = get_transport_reaction_list(maritima_model)

print("--------------------------------------------------------------")
print("Finding exchange reactions")
yeast_exchange_reactions = get_exchange_reaction_list(yeast_model)
maritima_exchange_reactions = get_exchange_reaction_list(maritima_model)

print("--------------------------------------------------------------")
print("Stitching models")
stitched_model = stitch_models(yeast_model,maritima_model)

print("--------------------------------------------------------------")
print("Performing FBA with a range of biomass ratios")
number_of_objective_ratios = 20
fig = plt.figure()
stitched_model.reactions.get_by_id('ETOHt_mod1').lower_bound = -10000
stitched_model.reactions.get_by_id('ETOHt_mod1').upper_bound = 10000
biomass_dataframe = simulate_variable_abundance(stitched_model,number_of_objective_ratios)
ax1 = fig.add_subplot(1,5,1)
biomass_dataframe.plot(kind='area',stacked=True,ax=ax1,sharey=True,\
        y=['Yeast biomass','Thermotoga biomass'])
ax1.xaxis.set_visible(False)

stitched_model.reactions.get_by_id('ETOHt_mod1').upper_bound = 0
biomass_dataframe = simulate_variable_abundance(stitched_model,number_of_objective_ratios)
# community_phase_plane.py
import os
import cobra
from cobra.flux_analysis import calculate_phenotype_phase_plane
import model_stitcher
import matplotlib.pyplot as plt


if __name__ == "__main__":
    os.chdir("../models")
    yeast_file = "iMM904.xml"
    maritima_file = "iLJ478.xml"
    yeast_path = "/".join([os.getcwd(), yeast_file])
    maritima_path = "/".join([os.getcwd(), maritima_file])
    yeast_model = cobra.io.sbml3.read_sbml_model(yeast_path)
    maritima_model = cobra.io.sbml3.read_sbml_model(maritima_path)
    os.chdir("..")
    stitched_model = model_stitcher.stitch_models(yeast_model, maritima_model)

    data = calculate_phenotype_phase_plane(yeast_model, "EX_glc__D_e", "EX_o2_e")
    print data
    fig = plt.figure()
    ax = data.plot_matplotlib()
    plt.show()


else:
    print "loading community_phase_plane.py"