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

to_json(mass_model[, sort])

Return the model as a JSON document.

from_json(document)

Load a model from a JSON document.

save_json_model(mass_model, filename[, sort, pretty])

Write the model to a file in JSON format.

load_json_model(filename)

Load the model from a file in JSON format.

Attributes

JSON_SCHEMA

The generic JSON schema for representing a model in mass.

mass.io.json.to_json(mass_model, sort=False, **kwargs)[source]

Return the model as a JSON document.

kwargs are passed on to json.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

str

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

MassModel or EnzymeModule

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 to json.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 the kwargs.

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

MassModel or EnzymeModule

See also

from_json

Load a model from a string representation in JSON format.

mass.io.json.JSON_SCHEMA[source]

The generic JSON schema for representing a model in mass.

Type

dict