cobra.io.json#
Provide functions for I/O in JSON format.
Attributes#
Functions#
|
Return the model as a JSON string. |
|
Load a cobra model from a JSON string. |
|
Write the cobra model to a file in JSON format. |
|
Load a cobra model from a file in JSON format. |
Module Contents#
- cobra.io.json.JSON_SPEC = '1'#
- cobra.io.json.to_json(model: cobra.Model, sort: bool = False, **kwargs: Any) str[source]#
Return the model as a JSON string.
- Parameters:
model (cobra.Model) – The cobra model to represent.
sort (bool, optional) – Whether to sort the metabolites, reactions, and genes or maintain the order defined in the model (default False).
**kwargs (Any) – Keyword arguments passed on to json.dumps.
- Returns:
JSON string representation of the cobra model.
- Return type:
See also
save_json_modelWrite directly to a file.
json.dumpsBase function.
- cobra.io.json.from_json(document: str) cobra.Model[source]#
Load a cobra model from a JSON string.
- Parameters:
document (str) – The JSON string representation of a cobra model.
- Returns:
The cobra model as interpreted from the JSON string.
- Return type:
See also
load_json_modelLoad directly from a file.
- cobra.io.json.save_json_model(model: cobra.Model, filename: str | pathlib.Path | IO, sort: bool = False, pretty: bool = False, **kwargs: Any) None[source]#
Write the cobra model to a file in JSON format.
- Parameters:
model (cobra.Model) – The cobra model to represent.
filename (str or file-like) – File path or descriptor that the JSON representation should be written to.
sort (bool, optional) – Whether to sort the metabolites, reactions, and genes or maintain the order defined in the model (default False).
pretty (bool, optional) – Whether to format the JSON more compactly (default) or in a more verbose but easier to read fashion. Can be partially overwritten by the **kwargs (default False).
**kwargs (Any) – Keyword arguments passed to json.dump.
- cobra.io.json.load_json_model(filename: str | pathlib.Path | IO) cobra.Model[source]#
Load a cobra model from a file in JSON format.
- Parameters:
filename (str or file-like) – File path or descriptor that contains the JSON document describing the cobra model.
- Returns:
The cobra model as represented in the JSON document.
- Return type:
See also
from_jsonLoad from a JSON string.