iPython Notebook How-To: Generating, saving, and loading models in PyFBA

Generating, saving, loading models in PyFBA

by Daniel Cuevas

Introduction

In this notebook, we will present the steps to generate a genome-scale metabolic model from RAST annotations, save the model on your computer, and load the model from your computer.


The required files and information for this notebook:

  • List of functional roles from RAST (normally labeled ‘assigned_functions’ from the Genome Directory download).
  • Organism name
  • Organism ID
  • Directory on hard disk to store model
In [1]:
import sys
import os
import PyFBA

Generate model

The first step shows how to build the model from RAST functional roles.

In [2]:
model_functions_file = "data/citrobacter.assigned_functions"
org_name = "Citrobacter sedlakii"
org_id = "Citrobacter sedlakii"
In [3]:
model = PyFBA.model.roles_to_model(model_functions_file, org_id, org_name)
The model has been generated and is now ready to use for flux-balance analysis simulations.
Note: model should not grow because it has not been gap-filled

In [4]:
# status := optimization status of FBA simplex solver
# flux_value := biomass flux value (objective function)
# growth := boolean whether the model was able to grow or not
# Note: model should not grow because it has not been gap-filled
status, flux_value, growth = model.run_fba("ArgonneLB.txt")
print("Growth:", growth)
Growth: False

Save model

The second step shows how to save the model to hard disk.

In [5]:
model_directory = "save_citrobacter_sedlakii"
PyFBA.model.save_model(model, model_directory)
Model has been stored. Here is a directory listing of the files that were created.
Note: files for gfmedia and gfreactions will be 0 Bytes in size because gap-filling was not performed.

In [6]:
for f in os.listdir(model_directory):
    fp = os.path.join(model_directory, f)
    print(f, ": ", os.path.getsize(fp), "B", sep="")
Citrobacter sedlakii.compounds: 27883B
Citrobacter sedlakii.gfmedia: 0B
Citrobacter sedlakii.gfreactions: 0B
Citrobacter sedlakii.info: 114B
Citrobacter sedlakii.reactions: 13005B
Citrobacter sedlakii.roles: 69740B

Load model

The third step shows how to load the model from hard disk.

In [7]:
loaded_model = PyFBA.model.load_model(model_directory, org_name)
The model has been loaded and is ready for use in flux-balance analysis simulations.
Note: model should not grow because it has not been gap-filled

In [8]:
# status := optimization status of FBA simplex solver
# flux_value := biomass flux value (objective function)
# growth := boolean whether the model was able to grow or not
# Note: model should not grow because it has not been gap-filled
status, flux_value, growth = loaded_model.run_fba("ArgonneLB.txt")
print("Growth:", growth)
Growth: False