Input and output¶
Currently, the only supported approach for loading and saving ensembles
in medusa
is via
pickle. pickle
is the Python module that serializes and de-serializes Python objects
(i.e. converts to/from a binary representation). This is an intentional
design choice–as medusa
matures, we will identify a feasible route
for standardization through an extension to the Systems Biology Markup
Language (SBML), which is the de facto standard for sharing
genome-scale metabolic network reconstructions.
To load an ensemble, use the load
function from the pickle
module:
In [1]:
import medusa
from pickle import load
with open("../medusa/test/data/Staphylococcus_aureus_ensemble.pickle", 'rb') as infile:
ensemble = load(infile)
To save an ensemble, you can pickle it with:
In [2]:
save_dir = ("../medusa/test/data/Staphylococcus_aureus_repickled.pickle")
ensemble.to_pickle(save_dir)
You can always save the base model for an ensemble using the standard
cobrapy I/O
functions, but
keep in mind the states for each feature will be set statically–the
model you save will only represent one of the ensemble members, and will
likely have many features shut off (e.g. there will be many closed
reactions if the features for those reactions are not present in the
ensemble member that the state reflects). When publishing ensembles, we
recommend including the pickled medusa
ensemble, an SBML file for
the base model, and a spreadsheet of feature states for each member.