mass.io.json
¶
Create or load models in JSON format.
Models created in JSON format can also be viewed using the Escher network visualization tool. See the Escher web-based tool or the Python package documentation for more information on Escher.
To enable faster JSON export, the simplejson
package can be installed
during the mass
installation process as follows:
# Installs simplejson package.
pip install masspy["json"]
# Or to install all additional packages.
pip install masspy["all"]
If the visualization
submodule is installed, see the
mass.visualiation.escher
documentation for more information on using
mass
with escher
(Coming soon).
Module Contents¶
Functions¶
|
Return the model as a JSON document. |
|
Load a model from a JSON document. |
|
Write the model to a file in JSON format. |
|
Load the model from a file in JSON format. |
-
mass.io.json.
to_json
(mass_model, sort=False, **kwargs)[source]¶ Return the model as a JSON document.
kwargs
are passed on tojson.dumps
- Parameters
mass_model (MassModel or EnzymeModule) – The
mass
model to represent.sort (bool) – Whether to sort the objects in the lists representing attributes, or to maintain the order defined in the model. Default is
False
.
- Returns
String representation of the
mass
model as a JSON document.- Return type
See also
save_json_model()
Write directly to a file.
json.dumps()
Base function.
-
mass.io.json.
from_json
(document)[source]¶ Load a model from a JSON document.
- Parameters
document (str) – The JSON document representation of a
mass
model.- Returns
The
mass
model as represented in the JSON document.- Return type
See also
load_json_model()
Load directly from a file.
-
mass.io.json.
save_json_model
(mass_model, filename, sort=False, pretty=False, **kwargs)[source]¶ Write the model to a file in JSON format.
kwargs
are passed on tojson.dump
- Parameters
mass_model (MassModel or EnzymeModule) – The
mass
model to represent.filename (str or file-like) – File path or descriptor the the JSON representation should be written to.
sort (bool) – Whether to sort the objects in the lists representing attributes, or to maintain the order defined in the model. Default is
False
.pretty (bool) – Whether to format the JSON more compactly (default), or in a more verbose but easier to read fashion. Default is
False
. Can be partially overwritten by thekwargs
.
See also
to_json()
Create a string represenation of the model in JSON format.
json.dump()
Base function.
-
mass.io.json.
load_json_model
(filename)[source]¶ Load the model from a file in JSON format.
- Parameters
filename (str or file-like) – File path or descriptor the contains JSON document describing the
mass
model to be loaded.- Returns
The
mass
model as represented in the JSON formatted file.- Return type
See also
from_json()
Load a model from a string representation in JSON format.