Edit Model

Add a single reaction

Forward reaction

[2]:
import modelseedpy
from modelseedpy.biochem import from_local
import cobra
import sys

# locally importing the ModelSEEDpy editor API
sys.path.insert(1, 'C:\\Users\\Andrew Freiburger\\Dropbox\\My PC (DESKTOP-M302P50)\\Documents\\UVic Civil Engineering\\Internships\\Agronne\\ModelSEEDpy\\modelseedpy\\core')
import mseditorapi

# locally import a BiGG model and the ModelSEEDpy
bigg_model_path = '.\e_coli_core metabolism from BiGG.json'
model = cobra.io.load_json_model(bigg_model_path)
modelseed_path = '..\..\..\..\..\..\Biofilm growth code\GSWL code\ModelSEEDDatabase'
modelseed = modelseedpy.biochem.from_local(modelseed_path)

# demonstrating the addition of the reaction to the model
example_reaction = 'rxn00002'

print('Attempt 1:')
try:
    print(model.reactions.get_by_id(example_reaction))
except:
    print('ERROR: The modelseed reaction {} is absent from the model.'.format(example_reaction))

mseditorapi.MSEditorAPI.add_ms_reaction(model, rxn_id = example_reaction, modelseed = modelseed, compartment_equivalents = {'0':'c0', '1':'e0'}, direction = '>')

print('\nAttempt 2:')
try:
    print(model.reactions.get_by_id(example_reaction))
except:
    print('ERROR: The modelseed reaction {} is absent from the model.'.format(example_reaction))

# remove the reaction from the model
model.reactions.get_by_id(example_reaction).remove_from_model()
Attempt 1:
ERROR: The modelseed reaction rxn00002 is absent from the model.

Attempt 2:
rxn00002: cpd00001 + 3.0 cpd00067 + cpd00742 --> 2.0 cpd00011 + 2.0 cpd00013

Backward and reversible reactions

The directionality of the modelseed reaction may be either >, <, or =.

[33]:
# add a backward reaction
print('Backward reaction:')
mseditorapi.MSEditorAPI.add_ms_reaction(model, rxn_id = example_reaction, modelseed = modelseed, compartment_equivalents = {'0':'c0', '1':'e0'}, direction = '<')

try:
    print(model.reactions.get_by_id(example_reaction))
except:
    print('ERROR: The modelseed reaction {} is absent from the model.'.format(example_reaction))

model.reactions.get_by_id(example_reaction).remove_from_model()

# add a reversible reaction
print('\nReversible reaction:')
mseditorapi.MSEditorAPI.add_ms_reaction(model, rxn_id = example_reaction, modelseed = modelseed, compartment_equivalents = {'0':'c0', '1':'e0'}, direction = '=')

try:
    print(model.reactions.get_by_id(example_reaction))
except:
    print('ERROR: The modelseed reaction {} is absent from the model.'.format(example_reaction))

model.reactions.get_by_id(example_reaction).remove_from_model()
Backward reaction:
rxn00002: cpd00001 + 3.0 cpd00067 + cpd00742 <-- 2.0 cpd00011 + 2.0 cpd00013

Reversible reaction:
rxn00002: cpd00001 + 3.0 cpd00067 + cpd00742 <=> 2.0 cpd00011 + 2.0 cpd00013