5. ME-model Saving and Loading¶
There are currently 3 methods that can be used to save/load an ME-model using COBRAme: 1. As a full JSON file 2. As a reduced JSON file 3. As a pickle file
5.1. As a full JSON file¶
This is the recommended way to save, load and share COBRAme
ME-models in full detail. This will include all of the model’s
functionality and information (MEReaction
, ProcessData
, etc). It
uses a defined JSONSCHEMA found in cobrame.io
.
Saving and loading a full ME-model (me_model
) as a JSON can be done
using:
In [ ]:
from cobrame.io.json import save_json_me_model, load_json_me_model
save_json_me_model(me_model, '[save_loc]/model.json')
Then loading can be done with
In [ ]:
new_me_model = load_json_me_model('[save_loc]/model.json')
where new_me_model
is of type cobrame.MEModel
5.2. As a reduced JSON file¶
Alternatively, ME-models can be saved as a COBRApy
model. This
storage type loses all the additional information contained in a full
ME-model, but retains the stoichiometry of all the reactions. In other
words, it behaves like an M-model with symbolic mu terms in metabolic
coefficients and reaction bounds. Therefore it will give identical
solutions compared to the full model, but all additional ME-model
functionality will be lost.
Saving and loading a reduced Me-model (me_model
) as a JSON can be
done using:
In [ ]:
from cobrame.io.json import save_reduced_json_me_model, load_reduced_json_me_model
save_reduced_json_me_model(me_model, '[save_loc]/model.json')
Then loading can be done with
In [ ]:
new_me_model = load_reduced_json_me_model('[save_loc]/model.json')
where new_me_model
is of type cobra.Model
5.3. As a pickle file¶
This is the quickest way to save a ME-model in full detail. It can be
accomplished using python’s pickle dump/load methods. A ME-model named
me_model
can be saved follows.
In [ ]:
import pickle
with open('[save_loc]/model.pickle', 'wb') as f:
pickle.dump(me_model, f)
It can then be loaded with:
In [ ]:
with open('[save_loc]/model.pickle', 'wb') as f:
new_me_model = pickle.load(f)
This is not a recommended way to save a ME-model when sharing or for use over the long term as it can break when using different software versions.