from __future__ import print_function
import mackinac
import cobra
from cobra import Model, Reaction, Metabolite
import os
from os.path import join
def boundary_list(model):
"""Creates and returns the list of boundary reactions (exchange, demand and sink-type reactions)
"""
exList = []
for rxn in model.reactions:
if (rxn.boundary == True):
exList.append(rxn)
return exList
"""Defining parameters"""
modelseed_id = '266.10'
first_run = False
validate = False
perform_fva = True
export_to_escher = True
block_nitrite_EX = True
precision_fva = 0.999
rxns_KO = ['EX_cpd00644_e', 'EX_cpd10516_e', 'EX_cpd00060_e', 'rxn_cpd14010_c', 'rxn_cpd00109_c', 'rxn_cpd00570_c', 'rxn_cpd14202_c', 'rxn_cpd06111_c', 'rxn_cpd05625_c', 'EX_cpd00528_e']
simult_KO = ['rxn0625_c', 'EX_cpd00528_e']
data_dir = os.getcwd()
print("Script directory: ", data_dir)
token_username = ''
token_password = ''
if(first_run):
mackinac.get_token(token_username, token_password, token_type = 'rast')
mackinac.reconstruct_modelseed_model(modelseed_id)
mackinac.gapfill_modelseed_model(modelseed_id)
mackinac.optimize_modelseed_model(modelseed_id)
MODEL = mackinac.create_cobra_model_from_modelseed_model(modelseed_id, validate = True)
cobra.io.save_json_model(MODEL, "initMODEL.json")
if(not(first_run)):
MODEL = cobra.io.load_json_model(join(data_dir, "initMODEL.json"))
print("Model loaded from an existing file: ", join(data_dir, "initMODEL.json\n"))
if(validate):
print("---- MODEL VALIDATION BEGINS ----")
print(cobra.manipulation.validate.check_mass_balance(MODEL))
print(cobra.manipulation.validate.check_metabolite_compartment_formula(MODEL))
print(cobra.manipulation.validate.check_reaction_bounds(MODEL))
print("---- END OF VALIDATION ----")
#SO NOW THE MODEL IS IMPORTED AS IS FROM MODELSEED AND CONVERTED TO COBRA MODEL
#ADD NEW HETEROLOGOUS REACTIONS
#nitric-oxide: ferricytomchrome-c oxireductase (EC 1.7.2.1)
#NO2 + H+ + cyt c2 <=> NO + H2O + cyt c3+
#cpd00075_c + cpd00067_c + cpd00110_c <=> cpd00418_c + cpd00001_c + cpd00109_c
cpd00418_c = MODEL.metabolites.get_by_id('cpd00418_c')
cpd00110_c = MODEL.metabolites.get_by_id('cpd00110_c')
cpd00109_c = MODEL.metabolites.get_by_id('cpd00109_c')
cpd00075_c = MODEL.metabolites.get_by_id('cpd00075_c')
cpd00067_c = MODEL.metabolites.get_by_id('cpd00067_c')
cpd00001_c = MODEL.metabolites.get_by_id('cpd00001_c')
cpd00659_c = MODEL.metabolites.get_by_id('cpd00659_c')
cpd00075_e = MODEL.metabolites.get_by_id('cpd00075_e')
rxn05889_c = Reaction('rxn05889_c')
rxn05889_c.name = 'nitrite reductase (NO-forming)'
rxn05889_c.subsystem = 'Denitrification'
rxn05889_c.lower_bound = -1000.
rxn05889_c.upper_bound = 1000.
rxn05889_c.gene_reaction_rule = "( 266.10.peg.2397 )"
rxn05889_c.add_metabolites({
cpd00075_c: -1.0,
cpd00067_c: -1.0,
cpd00110_c: -1.0,
cpd00418_c: 1.0,
cpd00001_c: 1.0,
cpd00109_c: 1.0
})
cpd00528_c = MODEL.metabolites.get_by_id('cpd00528_c')
cpd00528_e = Metabolite(
'cpd00528_e',
formula='N2',
name='N2_e',
compartment='e')
rxn10577_c = Reaction('rxn10577_c')
rxn10577_c.name = 'Nitrogen exchange, diffusion'
rxn10577_c.subsystem = 'Transport'
rxn10577_c.lower_bound = -1000.
rxn10577_c.upper_bound = 1000.
rxn10577_c.add_metabolites({
cpd00528_c: -1.0,
cpd00528_e: 1.0
})
#add the exchange reactions got N2_e
MODEL.add_boundary(cpd00528_e, type="exchange", reaction_id="EX_cpd00528_e", ub=1000.)
MODEL.add_reactions([rxn05889_c, rxn10577_c])
#Excess NH3 inhibits NH-3 forming Nitrite reductase
MODEL.reactions.get_by_id('rxn00568_c').knock_out()
MODEL.reactions.get_by_id('rxn00569_c').knock_out()
#Block NO2- exchange, block one of the loop
#if(block_nitrite_EX):
# MODEL.reactions.get_by_id('cpd00075_e').knock_out()
#nitrate and nitrite reductatse only catalyze the forward reation in excess of ammonia
MODEL.reactions.get_by_id('rxn10121_c').bounds = (-10.,1000.)
print('')
print(len(MODEL.reactions), "reactions initially")
print(len(MODEL.metabolites), "metabolites initially")
print(len(MODEL.genes), "genes initially")
#Locally execute FBA on the model.
sol_1 = MODEL.optimize()
print('Unmodified objective value: %3.15f\n' % sol_1.objective_value)
#Performs FVA on the model. The result is a pandas.data_frame that contains the minimum and maximum flux range for exchnage reactions within 0.1% of the optimal solution
rxnList=boundary_list(MODEL)
print(sol_1)