cobra.io.yaml

Provide functions for I/O in YAML format.

Module Contents

Classes

CobraYAML

Define custom subclass for YAML I/O.

Functions

to_yaml(→ str)

Return the model as a YAML string.

from_yaml(→ cobra.Model)

Load a cobra model from a YAML string.

save_yaml_model(→ None)

Write the cobra model to a file in YAML format.

load_yaml_model(→ cobra.Model)

Load a cobra model from a file in YAML format.

Attributes

YAML_SPEC

yaml

cobra.io.yaml.YAML_SPEC = 1.2[source]
class cobra.io.yaml.CobraYAML(*, typ: ruamel.yaml.nodes.Any = None, pure: ruamel.yaml.events.Optional[ruamel.yaml.nodes.Text] = False, output: ruamel.yaml.nodes.Any = None, plug_ins: ruamel.yaml.nodes.Any = None)[source]

Bases: ruamel.yaml.main.YAML

Define custom subclass for YAML I/O.

dump(data: Dict, stream: Optional[io.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

str

cobra.io.yaml.yaml[source]
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

str

See also

save_yaml_model

Write directly to a file.

ruamel.yaml.dump

Base 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

cobra.Model

See also

load_yaml_model

Load 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_yaml

Return a string representation.

ruamel.yaml.dump

Base function.

cobra.io.yaml.load_yaml_model(filename: Union[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

cobra.Model

See also

from_yaml

Load from a string.