17.1.1.3.2.5. cobra.io.yaml
¶
Provide functions for I/O in YAML format.
17.1.1.3.2.5.1. Module Contents¶
17.1.1.3.2.5.1.1. Classes¶
Define custom subclass for YAML I/O. |
17.1.1.3.2.5.1.2. 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. |
-
class
cobra.io.yaml.
CobraYAML
(: Any, *, typ: Optional[Text] = None, pure: Any = False, output: Any = None, plug_ins: Any = None)[source]¶ Bases:
ruamel.yaml.main.YAML
Define custom subclass for YAML I/O.
-
dump
(self, data: Dict, stream: Optional['TextIOBase'] = 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.
to_yaml
(model: 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_model()
Write directly to a file.
ruamel.yaml.dump()
Base function.
-
cobra.io.yaml.
from_yaml
(document: str) → '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_model()
Load directly from a file.
-
cobra.io.yaml.
save_yaml_model
(model: 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_yaml()
Return a string representation.
ruamel.yaml.dump()
Base function.
-
cobra.io.yaml.
load_yaml_model
(filename: Union[str, Path]) → '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_yaml()
Load from a string.