cobra.io.yaml#
Provide functions for I/O in YAML format.
Attributes#
Classes#
Define custom subclass for YAML I/O. |
Functions#
|
Return the model as a YAML string. |
|
Load a cobra model from a YAML string. |
|
Write the cobra model to a file in YAML format. |
|
Load a cobra model from a file in YAML format. |
Module Contents#
- cobra.io.yaml.YAML_SPEC = '1.2'#
- class cobra.io.yaml.CobraYAML(*, typ: List[Text] | Text | None = None, pure: Any = False, output: Any = None, plug_ins: Any = None)[source]#
Bases:
ruamel.yaml.main.YAMLDefine custom subclass for YAML I/O.
- dump(data: Dict, stream: io.TextIOBase | None = None, **kwargs: Any) str[source]#
Dump YAML data.
- Parameters:
data (dict) – A dictionary representing the cobra model and its components.
stream (TextIOBase, optional) – A text stream object inheriting from io.TextIOBase. If None, ruamel.yaml.compat.StringIO is used (default None).
**kwargs (Any) – Keyword arguments passed on to ruamel.yaml.main.YAML.dump.
- Returns:
YAML string representation of data.
- Return type:
- cobra.io.yaml.yaml#
- cobra.io.yaml.to_yaml(model: cobra.Model, sort: bool = False, **kwargs: Any) str[source]#
Return the model as a YAML 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 CobraYAML.dump.
- Returns:
YAML string representation of the cobra model.
- Return type:
See also
save_yaml_modelWrite directly to a file.
ruamel.yaml.dumpBase function.
- cobra.io.yaml.from_yaml(document: str) cobra.Model[source]#
Load a cobra model from a YAML string.
- Parameters:
document (str) – The YAML string representation of a cobra model.
- Returns:
The cobra model as interpreted from the YAML document.
- Return type:
See also
load_yaml_modelLoad directly from a file.
- cobra.io.yaml.save_yaml_model(model: cobra.Model, filename: str, sort: bool = False, **kwargs: Any) None[source]#
Write the cobra model to a file in YAML format.
- Parameters:
model (cobra.Model) – The cobra model to represent.
filename (str or file-like) – File path or descriptor that the YAML 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).
**kwargs (Any) – Keyword arguments passed to CobraYAML.dump.
See also
to_yamlReturn a string representation.
ruamel.yaml.dumpBase function.
- cobra.io.yaml.load_yaml_model(filename: str | pathlib.Path) cobra.Model[source]#
Load a cobra model from a file in YAML format.
- Parameters:
filename (str or file-like) – File path or descriptor that contains the YAML document describing the cobra model.
- Returns:
The cobra model as represented in the YAML document.
- Return type:
See also
from_yamlLoad from a string.