Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: turn compartments into objects #725

Open
wants to merge 2 commits into
base: devel
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
refactor: upgrade tests
Midnighter committed Sep 6, 2018
commit 37d33c88c2854651b20ccbcbb3e456195f09683a
5 changes: 3 additions & 2 deletions cobra/io/__init__.py
Original file line number Diff line number Diff line change
@@ -2,11 +2,12 @@

from __future__ import absolute_import

from cobra.io.schemata import MODEL_SCHEMA
from cobra.io.dict import (model_from_dict, model_to_dict)
from cobra.io.json import (
to_json, from_json, load_json_model, save_json_model)
to_json, from_json, load_json_model, save_json_model, JSON_SPEC)
from cobra.io.yaml import (
to_yaml, from_yaml, load_yaml_model, save_yaml_model)
to_yaml, from_yaml, load_yaml_model, save_yaml_model, YAML_SPEC)
from cobra.io.sbml3 import read_sbml_model, write_sbml_model
from cobra.io.sbml import read_legacy_sbml
from cobra.io.sbml import write_cobra_model_to_sbml_file as \
63 changes: 35 additions & 28 deletions cobra/io/json.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,33 @@
# -*- coding: utf-8 -*-

from __future__ import absolute_import
from importlib_resources import open_text

try:
import simplejson as json
except ImportError:
import json
import json

from six import string_types

import cobra.io.schemata
from cobra.io.dict import model_to_dict, model_from_dict

JSON_SPEC = "1"

JSON_SPEC = "1"

def to_json(model, sort=False, **kwargs):
JSON_FORMAT = {
True: {
"indent": 2,
"separators": (", ", ": "),
"sort_keys": True,
"allow_nan": False
},
False: {
"separators": (",", ":"),
"sort_keys": False,
"allow_nan": False
}
}


def to_json(model, sort=False, pretty=False, **kwargs):
"""
Return the model as a JSON document.
@@ -27,6 +40,10 @@ def to_json(model, sort=False, **kwargs):
sort : bool, optional
Whether to sort the metabolites, reactions, and genes or maintain the
order defined in the model.
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``.
Returns
-------
@@ -37,10 +54,13 @@ def to_json(model, sort=False, **kwargs):
--------
save_json_model : Write directly to a file.
json.dumps : Base function.
"""
obj = model_to_dict(model, sort=sort)
obj[u"version"] = JSON_SPEC
return json.dumps(obj, allow_nan=False, **kwargs)
options = JSON_FORMAT[pretty]
options.update(kwargs)
return json.dumps(obj, **options)


def from_json(document):
@@ -60,6 +80,7 @@ def from_json(document):
See Also
--------
load_json_model : Load directly from a file.
"""
return model_from_dict(json.loads(document))

@@ -89,25 +110,18 @@ def save_json_model(model, filename, sort=False, pretty=False, **kwargs):
--------
to_json : Return a string representation.
json.dump : Base function.
"""
obj = model_to_dict(model, sort=sort)
obj[u"version"] = JSON_SPEC

if pretty:
dump_opts = {
"indent": 4, "separators": (",", ": "), "sort_keys": True,
"allow_nan": False}
else:
dump_opts = {
"indent": 0, "separators": (",", ":"), "sort_keys": False,
"allow_nan": False}
dump_opts.update(**kwargs)
options = JSON_FORMAT[pretty]
options.update(**kwargs)

if isinstance(filename, string_types):
with open(filename, "w") as file_handle:
json.dump(obj, file_handle, **dump_opts)
json.dump(obj, file_handle, **options)
else:
json.dump(obj, filename, **dump_opts)
json.dump(obj, filename, **options)


def load_json_model(filename):
@@ -128,17 +142,10 @@ def load_json_model(filename):
See Also
--------
from_json : Load from a string.
"""
if isinstance(filename, string_types):
with open(filename, "r") as file_handle:
return model_from_dict(json.load(file_handle))
else:
return model_from_dict(json.load(filename))


def init_json_schema():
""" Import the JSON schema for schema validation. """
with open_text("cobra.io.schemata", "json_schema.json",
encoding="utf-8") as file_handle:
json_schema = json.load(file_handle)
return json_schema
11 changes: 11 additions & 0 deletions cobra/io/schemata/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
# -*- coding: utf-8 -*-

"""Provide JSON schemata that can be used for validation."""

from __future__ import absolute_import

import json

from importlib_resources import open_text


with open_text("cobra.io.schemata", "model_schema.json",
encoding="utf-8") as file_handle:
MODEL_SCHEMA = json.load(file_handle)
File renamed without changes.
1 change: 1 addition & 0 deletions cobra/io/yaml.py
Original file line number Diff line number Diff line change
@@ -14,6 +14,7 @@


class MyYAML(YAML):

def dump(self, data, stream=None, **kwargs):
inefficient = False
if stream is None:
Binary file modified cobra/test/data/iJO1366.pickle
Binary file not shown.
2,742 changes: 1,371 additions & 1,371 deletions cobra/test/data/mini.json

Large diffs are not rendered by default.

Binary file modified cobra/test/data/mini.mat
Binary file not shown.
Binary file modified cobra/test/data/mini.pickle
Binary file not shown.
704 changes: 352 additions & 352 deletions cobra/test/data/mini.yml

Large diffs are not rendered by default.

64 changes: 32 additions & 32 deletions cobra/test/data/mini_cobra.xml
Original file line number Diff line number Diff line change
@@ -201,21 +201,21 @@
<listOfReactions>
<reaction id="R_ATPM" name="ATP maintenance requirement" reversible="false">
<listOfReactants>
<speciesReference species="M_atp_c" stoichiometry="1"/>
<speciesReference species="M_h2o_c" stoichiometry="1"/>
<speciesReference species="M_atp_c" stoichiometry="1"/>
</listOfReactants>
<listOfProducts>
<speciesReference species="M_adp_c" stoichiometry="1"/>
<speciesReference species="M_h_c" stoichiometry="1"/>
<speciesReference species="M_adp_c" stoichiometry="1"/>
<speciesReference species="M_pi_c" stoichiometry="1"/>
</listOfProducts>
<kineticLaw>
<math xmlns="http://www.w3.org/1998/Math/MathML">
<ci> FLUX_VALUE </ci>
</math>
<listOfParameters>
<parameter id="LOWER_BOUND" value="8.39" units="mmol_per_gDW_per_hr"/>
<parameter id="UPPER_BOUND" value="1000" units="mmol_per_gDW_per_hr"/>
<parameter id="LOWER_BOUND" value="8.39" units="mmol_per_gDW_per_hr"/>
<parameter id="FLUX_VALUE" value="0" units="mmol_per_gDW_per_hr"/>
<parameter id="OBJECTIVE_COEFFICIENT" value="1" units="dimensionless"/>
</listOfParameters>
@@ -232,16 +232,16 @@
<speciesReference species="M_lac__D_e" stoichiometry="1"/>
</listOfReactants>
<listOfProducts>
<speciesReference species="M_h_c" stoichiometry="1"/>
<speciesReference species="M_lac__D_c" stoichiometry="1"/>
<speciesReference species="M_h_c" stoichiometry="1"/>
</listOfProducts>
<kineticLaw>
<math xmlns="http://www.w3.org/1998/Math/MathML">
<ci> FLUX_VALUE </ci>
</math>
<listOfParameters>
<parameter id="LOWER_BOUND" value="-1000" units="mmol_per_gDW_per_hr"/>
<parameter id="UPPER_BOUND" value="1000" units="mmol_per_gDW_per_hr"/>
<parameter id="LOWER_BOUND" value="-1000" units="mmol_per_gDW_per_hr"/>
<parameter id="FLUX_VALUE" value="0" units="mmol_per_gDW_per_hr"/>
<parameter id="OBJECTIVE_COEFFICIENT" value="0" units="dimensionless"/>
</listOfParameters>
@@ -257,16 +257,16 @@
<speciesReference species="M_2pg_c" stoichiometry="1"/>
</listOfReactants>
<listOfProducts>
<speciesReference species="M_pep_c" stoichiometry="1"/>
<speciesReference species="M_h2o_c" stoichiometry="1"/>
<speciesReference species="M_pep_c" stoichiometry="1"/>
</listOfProducts>
<kineticLaw>
<math xmlns="http://www.w3.org/1998/Math/MathML">
<ci> FLUX_VALUE </ci>
</math>
<listOfParameters>
<parameter id="LOWER_BOUND" value="-1000" units="mmol_per_gDW_per_hr"/>
<parameter id="UPPER_BOUND" value="1000" units="mmol_per_gDW_per_hr"/>
<parameter id="LOWER_BOUND" value="-1000" units="mmol_per_gDW_per_hr"/>
<parameter id="FLUX_VALUE" value="0" units="mmol_per_gDW_per_hr"/>
<parameter id="OBJECTIVE_COEFFICIENT" value="0" units="dimensionless"/>
</listOfParameters>
@@ -284,8 +284,8 @@
<ci> FLUX_VALUE </ci>
</math>
<listOfParameters>
<parameter id="LOWER_BOUND" value="-10" units="mmol_per_gDW_per_hr"/>
<parameter id="UPPER_BOUND" value="1000" units="mmol_per_gDW_per_hr"/>
<parameter id="LOWER_BOUND" value="-10" units="mmol_per_gDW_per_hr"/>
<parameter id="FLUX_VALUE" value="0" units="mmol_per_gDW_per_hr"/>
<parameter id="OBJECTIVE_COEFFICIENT" value="0" units="dimensionless"/>
</listOfParameters>
@@ -303,8 +303,8 @@
<ci> FLUX_VALUE </ci>
</math>
<listOfParameters>
<parameter id="LOWER_BOUND" value="-1000" units="mmol_per_gDW_per_hr"/>
<parameter id="UPPER_BOUND" value="1000" units="mmol_per_gDW_per_hr"/>
<parameter id="LOWER_BOUND" value="-1000" units="mmol_per_gDW_per_hr"/>
<parameter id="FLUX_VALUE" value="0" units="mmol_per_gDW_per_hr"/>
<parameter id="OBJECTIVE_COEFFICIENT" value="0" units="dimensionless"/>
</listOfParameters>
@@ -322,8 +322,8 @@
<ci> FLUX_VALUE </ci>
</math>
<listOfParameters>
<parameter id="LOWER_BOUND" value="0" units="mmol_per_gDW_per_hr"/>
<parameter id="UPPER_BOUND" value="1000" units="mmol_per_gDW_per_hr"/>
<parameter id="LOWER_BOUND" value="0" units="mmol_per_gDW_per_hr"/>
<parameter id="FLUX_VALUE" value="0" units="mmol_per_gDW_per_hr"/>
<parameter id="OBJECTIVE_COEFFICIENT" value="0" units="dimensionless"/>
</listOfParameters>
@@ -339,16 +339,16 @@
<speciesReference species="M_fdp_c" stoichiometry="1"/>
</listOfReactants>
<listOfProducts>
<speciesReference species="M_dhap_c" stoichiometry="1"/>
<speciesReference species="M_g3p_c" stoichiometry="1"/>
<speciesReference species="M_dhap_c" stoichiometry="1"/>
</listOfProducts>
<kineticLaw>
<math xmlns="http://www.w3.org/1998/Math/MathML">
<ci> FLUX_VALUE </ci>
</math>
<listOfParameters>
<parameter id="LOWER_BOUND" value="-1000" units="mmol_per_gDW_per_hr"/>
<parameter id="UPPER_BOUND" value="1000" units="mmol_per_gDW_per_hr"/>
<parameter id="LOWER_BOUND" value="-1000" units="mmol_per_gDW_per_hr"/>
<parameter id="FLUX_VALUE" value="0" units="mmol_per_gDW_per_hr"/>
<parameter id="OBJECTIVE_COEFFICIENT" value="0" units="dimensionless"/>
</listOfParameters>
@@ -362,21 +362,21 @@
</notes>
<listOfReactants>
<speciesReference species="M_nad_c" stoichiometry="1"/>
<speciesReference species="M_g3p_c" stoichiometry="1"/>
<speciesReference species="M_pi_c" stoichiometry="1"/>
<speciesReference species="M_g3p_c" stoichiometry="1"/>
</listOfReactants>
<listOfProducts>
<speciesReference species="M_13dpg_c" stoichiometry="1"/>
<speciesReference species="M_nadh_c" stoichiometry="1"/>
<speciesReference species="M_h_c" stoichiometry="1"/>
<speciesReference species="M_13dpg_c" stoichiometry="1"/>
</listOfProducts>
<kineticLaw>
<math xmlns="http://www.w3.org/1998/Math/MathML">
<ci> FLUX_VALUE </ci>
</math>
<listOfParameters>
<parameter id="LOWER_BOUND" value="-1000" units="mmol_per_gDW_per_hr"/>
<parameter id="UPPER_BOUND" value="1000" units="mmol_per_gDW_per_hr"/>
<parameter id="LOWER_BOUND" value="-1000" units="mmol_per_gDW_per_hr"/>
<parameter id="FLUX_VALUE" value="0" units="mmol_per_gDW_per_hr"/>
<parameter id="OBJECTIVE_COEFFICIENT" value="0" units="dimensionless"/>
</listOfParameters>
@@ -389,8 +389,8 @@
</html>
</notes>
<listOfReactants>
<speciesReference species="M_glc__D_e" stoichiometry="1"/>
<speciesReference species="M_pep_c" stoichiometry="1"/>
<speciesReference species="M_glc__D_e" stoichiometry="1"/>
</listOfReactants>
<listOfProducts>
<speciesReference species="M_g6p_c" stoichiometry="1"/>
@@ -401,8 +401,8 @@
<ci> FLUX_VALUE </ci>
</math>
<listOfParameters>
<parameter id="LOWER_BOUND" value="0" units="mmol_per_gDW_per_hr"/>
<parameter id="UPPER_BOUND" value="1000" units="mmol_per_gDW_per_hr"/>
<parameter id="LOWER_BOUND" value="0" units="mmol_per_gDW_per_hr"/>
<parameter id="FLUX_VALUE" value="0" units="mmol_per_gDW_per_hr"/>
<parameter id="OBJECTIVE_COEFFICIENT" value="0" units="dimensionless"/>
</listOfParameters>
@@ -425,8 +425,8 @@
<ci> FLUX_VALUE </ci>
</math>
<listOfParameters>
<parameter id="LOWER_BOUND" value="-1000" units="mmol_per_gDW_per_hr"/>
<parameter id="UPPER_BOUND" value="1000" units="mmol_per_gDW_per_hr"/>
<parameter id="LOWER_BOUND" value="-1000" units="mmol_per_gDW_per_hr"/>
<parameter id="FLUX_VALUE" value="0" units="mmol_per_gDW_per_hr"/>
<parameter id="OBJECTIVE_COEFFICIENT" value="0" units="dimensionless"/>
</listOfParameters>
@@ -439,21 +439,21 @@
</html>
</notes>
<listOfReactants>
<speciesReference species="M_lac__D_c" stoichiometry="1"/>
<speciesReference species="M_nad_c" stoichiometry="1"/>
<speciesReference species="M_lac__D_c" stoichiometry="1"/>
</listOfReactants>
<listOfProducts>
<speciesReference species="M_nadh_c" stoichiometry="1"/>
<speciesReference species="M_pyr_c" stoichiometry="1"/>
<speciesReference species="M_h_c" stoichiometry="1"/>
<speciesReference species="M_nadh_c" stoichiometry="1"/>
</listOfProducts>
<kineticLaw>
<math xmlns="http://www.w3.org/1998/Math/MathML">
<ci> FLUX_VALUE </ci>
</math>
<listOfParameters>
<parameter id="LOWER_BOUND" value="-1000" units="mmol_per_gDW_per_hr"/>
<parameter id="UPPER_BOUND" value="1000" units="mmol_per_gDW_per_hr"/>
<parameter id="LOWER_BOUND" value="-1000" units="mmol_per_gDW_per_hr"/>
<parameter id="FLUX_VALUE" value="0" units="mmol_per_gDW_per_hr"/>
<parameter id="OBJECTIVE_COEFFICIENT" value="0" units="dimensionless"/>
</listOfParameters>
@@ -471,16 +471,16 @@
</listOfReactants>
<listOfProducts>
<speciesReference species="M_adp_c" stoichiometry="1"/>
<speciesReference species="M_fdp_c" stoichiometry="1"/>
<speciesReference species="M_h_c" stoichiometry="1"/>
<speciesReference species="M_fdp_c" stoichiometry="1"/>
</listOfProducts>
<kineticLaw>
<math xmlns="http://www.w3.org/1998/Math/MathML">
<ci> FLUX_VALUE </ci>
</math>
<listOfParameters>
<parameter id="LOWER_BOUND" value="0" units="mmol_per_gDW_per_hr"/>
<parameter id="UPPER_BOUND" value="1000" units="mmol_per_gDW_per_hr"/>
<parameter id="LOWER_BOUND" value="0" units="mmol_per_gDW_per_hr"/>
<parameter id="FLUX_VALUE" value="0" units="mmol_per_gDW_per_hr"/>
<parameter id="OBJECTIVE_COEFFICIENT" value="1" units="dimensionless"/>
</listOfParameters>
@@ -503,8 +503,8 @@
<ci> FLUX_VALUE </ci>
</math>
<listOfParameters>
<parameter id="LOWER_BOUND" value="-1000" units="mmol_per_gDW_per_hr"/>
<parameter id="UPPER_BOUND" value="1000" units="mmol_per_gDW_per_hr"/>
<parameter id="LOWER_BOUND" value="-1000" units="mmol_per_gDW_per_hr"/>
<parameter id="FLUX_VALUE" value="0" units="mmol_per_gDW_per_hr"/>
<parameter id="OBJECTIVE_COEFFICIENT" value="0" units="dimensionless"/>
</listOfParameters>
@@ -521,16 +521,16 @@
<speciesReference species="M_atp_c" stoichiometry="1"/>
</listOfReactants>
<listOfProducts>
<speciesReference species="M_13dpg_c" stoichiometry="1"/>
<speciesReference species="M_adp_c" stoichiometry="1"/>
<speciesReference species="M_13dpg_c" stoichiometry="1"/>
</listOfProducts>
<kineticLaw>
<math xmlns="http://www.w3.org/1998/Math/MathML">
<ci> FLUX_VALUE </ci>
</math>
<listOfParameters>
<parameter id="LOWER_BOUND" value="-1000" units="mmol_per_gDW_per_hr"/>
<parameter id="UPPER_BOUND" value="1000" units="mmol_per_gDW_per_hr"/>
<parameter id="LOWER_BOUND" value="-1000" units="mmol_per_gDW_per_hr"/>
<parameter id="FLUX_VALUE" value="0" units="mmol_per_gDW_per_hr"/>
<parameter id="OBJECTIVE_COEFFICIENT" value="0" units="dimensionless"/>
</listOfParameters>
@@ -553,8 +553,8 @@
<ci> FLUX_VALUE </ci>
</math>
<listOfParameters>
<parameter id="LOWER_BOUND" value="-1000" units="mmol_per_gDW_per_hr"/>
<parameter id="UPPER_BOUND" value="1000" units="mmol_per_gDW_per_hr"/>
<parameter id="LOWER_BOUND" value="-1000" units="mmol_per_gDW_per_hr"/>
<parameter id="FLUX_VALUE" value="0" units="mmol_per_gDW_per_hr"/>
<parameter id="OBJECTIVE_COEFFICIENT" value="0" units="dimensionless"/>
</listOfParameters>
@@ -579,8 +579,8 @@
<ci> FLUX_VALUE </ci>
</math>
<listOfParameters>
<parameter id="LOWER_BOUND" value="-1000" units="mmol_per_gDW_per_hr"/>
<parameter id="UPPER_BOUND" value="1000" units="mmol_per_gDW_per_hr"/>
<parameter id="LOWER_BOUND" value="-1000" units="mmol_per_gDW_per_hr"/>
<parameter id="FLUX_VALUE" value="0" units="mmol_per_gDW_per_hr"/>
<parameter id="OBJECTIVE_COEFFICIENT" value="0" units="dimensionless"/>
</listOfParameters>
@@ -594,20 +594,20 @@
</notes>
<listOfReactants>
<speciesReference species="M_adp_c" stoichiometry="1"/>
<speciesReference species="M_h_c" stoichiometry="1"/>
<speciesReference species="M_pep_c" stoichiometry="1"/>
<speciesReference species="M_h_c" stoichiometry="1"/>
</listOfReactants>
<listOfProducts>
<speciesReference species="M_atp_c" stoichiometry="1"/>
<speciesReference species="M_pyr_c" stoichiometry="1"/>
<speciesReference species="M_atp_c" stoichiometry="1"/>
</listOfProducts>
<kineticLaw>
<math xmlns="http://www.w3.org/1998/Math/MathML">
<ci> FLUX_VALUE </ci>
</math>
<listOfParameters>
<parameter id="LOWER_BOUND" value="0" units="mmol_per_gDW_per_hr"/>
<parameter id="UPPER_BOUND" value="1000" units="mmol_per_gDW_per_hr"/>
<parameter id="LOWER_BOUND" value="0" units="mmol_per_gDW_per_hr"/>
<parameter id="FLUX_VALUE" value="0" units="mmol_per_gDW_per_hr"/>
<parameter id="OBJECTIVE_COEFFICIENT" value="0" units="dimensionless"/>
</listOfParameters>
@@ -630,8 +630,8 @@
<ci> FLUX_VALUE </ci>
</math>
<listOfParameters>
<parameter id="LOWER_BOUND" value="-1000" units="mmol_per_gDW_per_hr"/>
<parameter id="UPPER_BOUND" value="1000" units="mmol_per_gDW_per_hr"/>
<parameter id="LOWER_BOUND" value="-1000" units="mmol_per_gDW_per_hr"/>
<parameter id="FLUX_VALUE" value="0" units="mmol_per_gDW_per_hr"/>
<parameter id="OBJECTIVE_COEFFICIENT" value="0" units="dimensionless"/>
</listOfParameters>
28 changes: 14 additions & 14 deletions cobra/test/data/mini_fbc1.xml
Original file line number Diff line number Diff line change
@@ -308,12 +308,12 @@
<listOfReactions>
<reaction id="R_ATPM" name="ATP maintenance requirement" reversible="false" fast="false">
<listOfReactants>
<speciesReference species="M_atp_c" stoichiometry="1" constant="true"/>
<speciesReference species="M_h2o_c" stoichiometry="1" constant="true"/>
<speciesReference species="M_atp_c" stoichiometry="1" constant="true"/>
</listOfReactants>
<listOfProducts>
<speciesReference species="M_adp_c" stoichiometry="1" constant="true"/>
<speciesReference species="M_h_c" stoichiometry="1" constant="true"/>
<speciesReference species="M_adp_c" stoichiometry="1" constant="true"/>
<speciesReference species="M_pi_c" stoichiometry="1" constant="true"/>
</listOfProducts>
</reaction>
@@ -328,8 +328,8 @@
<speciesReference species="M_lac__D_e" stoichiometry="1" constant="true"/>
</listOfReactants>
<listOfProducts>
<speciesReference species="M_h_c" stoichiometry="1" constant="true"/>
<speciesReference species="M_lac__D_c" stoichiometry="1" constant="true"/>
<speciesReference species="M_h_c" stoichiometry="1" constant="true"/>
</listOfProducts>
</reaction>
<reaction id="R_ENO" name="enolase" reversible="true" fast="false">
@@ -342,8 +342,8 @@
<speciesReference species="M_2pg_c" stoichiometry="1" constant="true"/>
</listOfReactants>
<listOfProducts>
<speciesReference species="M_pep_c" stoichiometry="1" constant="true"/>
<speciesReference species="M_h2o_c" stoichiometry="1" constant="true"/>
<speciesReference species="M_pep_c" stoichiometry="1" constant="true"/>
</listOfProducts>
</reaction>
<reaction id="R_EX_glc__D_e" name="D-Glucose exchange" reversible="true" fast="false">
@@ -380,8 +380,8 @@
<speciesReference species="M_fdp_c" stoichiometry="1" constant="true"/>
</listOfReactants>
<listOfProducts>
<speciesReference species="M_dhap_c" stoichiometry="1" constant="true"/>
<speciesReference species="M_g3p_c" stoichiometry="1" constant="true"/>
<speciesReference species="M_dhap_c" stoichiometry="1" constant="true"/>
</listOfProducts>
</reaction>
<reaction id="R_GAPD" name="glyceraldehyde-3-phosphate dehydrogenase" reversible="true" fast="false">
@@ -392,13 +392,13 @@
</notes>
<listOfReactants>
<speciesReference species="M_nad_c" stoichiometry="1" constant="true"/>
<speciesReference species="M_g3p_c" stoichiometry="1" constant="true"/>
<speciesReference species="M_pi_c" stoichiometry="1" constant="true"/>
<speciesReference species="M_g3p_c" stoichiometry="1" constant="true"/>
</listOfReactants>
<listOfProducts>
<speciesReference species="M_13dpg_c" stoichiometry="1" constant="true"/>
<speciesReference species="M_nadh_c" stoichiometry="1" constant="true"/>
<speciesReference species="M_h_c" stoichiometry="1" constant="true"/>
<speciesReference species="M_13dpg_c" stoichiometry="1" constant="true"/>
</listOfProducts>
</reaction>
<reaction id="R_GLCpts" name="D-glucose transport via PEP:Pyr PTS" reversible="false" fast="false">
@@ -408,8 +408,8 @@
</html>
</notes>
<listOfReactants>
<speciesReference species="M_glc__D_e" stoichiometry="1" constant="true"/>
<speciesReference species="M_pep_c" stoichiometry="1" constant="true"/>
<speciesReference species="M_glc__D_e" stoichiometry="1" constant="true"/>
</listOfReactants>
<listOfProducts>
<speciesReference species="M_g6p_c" stoichiometry="1" constant="true"/>
@@ -436,13 +436,13 @@
</html>
</notes>
<listOfReactants>
<speciesReference species="M_lac__D_c" stoichiometry="1" constant="true"/>
<speciesReference species="M_nad_c" stoichiometry="1" constant="true"/>
<speciesReference species="M_lac__D_c" stoichiometry="1" constant="true"/>
</listOfReactants>
<listOfProducts>
<speciesReference species="M_nadh_c" stoichiometry="1" constant="true"/>
<speciesReference species="M_pyr_c" stoichiometry="1" constant="true"/>
<speciesReference species="M_h_c" stoichiometry="1" constant="true"/>
<speciesReference species="M_nadh_c" stoichiometry="1" constant="true"/>
</listOfProducts>
</reaction>
<reaction id="R_PFK" name="phosphofructokinase" reversible="false" fast="false">
@@ -457,8 +457,8 @@
</listOfReactants>
<listOfProducts>
<speciesReference species="M_adp_c" stoichiometry="1" constant="true"/>
<speciesReference species="M_fdp_c" stoichiometry="1" constant="true"/>
<speciesReference species="M_h_c" stoichiometry="1" constant="true"/>
<speciesReference species="M_fdp_c" stoichiometry="1" constant="true"/>
</listOfProducts>
</reaction>
<reaction id="R_PGI" name="glucose-6-phosphate isomerase" reversible="true" fast="false">
@@ -485,8 +485,8 @@
<speciesReference species="M_atp_c" stoichiometry="1" constant="true"/>
</listOfReactants>
<listOfProducts>
<speciesReference species="M_13dpg_c" stoichiometry="1" constant="true"/>
<speciesReference species="M_adp_c" stoichiometry="1" constant="true"/>
<speciesReference species="M_13dpg_c" stoichiometry="1" constant="true"/>
</listOfProducts>
</reaction>
<reaction id="R_PGM" name="phosphoglycerate mutase" reversible="true" fast="false">
@@ -525,12 +525,12 @@
</notes>
<listOfReactants>
<speciesReference species="M_adp_c" stoichiometry="1" constant="true"/>
<speciesReference species="M_h_c" stoichiometry="1" constant="true"/>
<speciesReference species="M_pep_c" stoichiometry="1" constant="true"/>
<speciesReference species="M_h_c" stoichiometry="1" constant="true"/>
</listOfReactants>
<listOfProducts>
<speciesReference species="M_atp_c" stoichiometry="1" constant="true"/>
<speciesReference species="M_pyr_c" stoichiometry="1" constant="true"/>
<speciesReference species="M_atp_c" stoichiometry="1" constant="true"/>
</listOfProducts>
</reaction>
<reaction id="R_TPI" name="triose-phosphate isomerase" reversible="true" fast="false">
Binary file modified cobra/test/data/mini_fbc2.xml.gz
Binary file not shown.
Binary file modified cobra/test/data/raven.pickle
Binary file not shown.
Binary file modified cobra/test/data/salmonella.pickle
Binary file not shown.
2 changes: 1 addition & 1 deletion cobra/test/data/textbook_fva.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"maximum": {"ACALD": 0.0, "ACALDt": 0.0, "ACKr": 0.0, "ACONTa": 6.00725, "ACONTb": 6.00725, "ACt2r": 0.0, "ADK1": -0.0, "AKGDH": 5.06438, "AKGt2r": 0.0, "ALCD2x": 0.0, "ATPM": 8.39, "ATPS4r": 45.51401, "Biomass_Ecoli_core": 0.87392, "CO2t": -22.80983, "CS": 6.00725, "CYTBD": 43.59899, "D_LACt2": 0.0, "ENO": 14.71614, "ETOHt2r": 0.0, "EX_ac_e": -0.0, "EX_acald_e": -0.0, "EX_akg_e": -0.0, "EX_co2_e": 22.80983, "EX_etoh_e": -0.0, "EX_for_e": -0.0, "EX_fru_e": -0.0, "EX_fum_e": 0.0, "EX_glc__D_e": -10.0, "EX_gln__L_e": 0.0, "EX_glu__L_e": -0.0, "EX_h_e": 17.53087, "EX_h2o_e": 29.17583, "EX_lac__D_e": -0.0, "EX_mal__L_e": -0.0, "EX_nh4_e": -4.76532, "EX_o2_e": -21.79949, "EX_pi_e": -3.2149, "EX_pyr_e": -0.0, "EX_succ_e": -0.0, "FBA": 7.47738, "FBP": -0.0, "FORt2": -0.0, "FORti": -0.0, "FRD7": 994.93562, "FRUpts2": 0.0, "FUM": 5.06438, "FUMt2_2": 0.0, "G6PDH2r": 4.95998, "GAPD": 16.02353, "GLCpts": 10.0, "GLNS": 0.22346, "GLNabc": 0.0, "GLUDy": -4.54186, "GLUN": -0.0, "GLUSy": -0.0, "GLUt2r": 0.0, "GND": 4.95998, "H2Ot": -29.17583, "ICDHyr": 6.00725, "ICL": -0.0, "LDH_D": 0.0, "MALS": -0.0, "MALt2_2": 0.0, "MDH": 5.06438, "ME1": -0.0, "ME2": -0.0, "NADH16": 38.53461, "NADTRHD": -0.0, "NH4t": 4.76532, "O2t": 21.79949, "PDH": 9.28253, "PFK": 7.47738, "PFL": -0.0, "PGI": 4.86086, "PGK": -16.02353, "PGL": 4.95998, "PGM": -14.71614, "PIt2r": 3.2149, "PPC": 2.50431, "PPCK": -0.0, "PPS": -0.0, "PTAr": -0.0, "PYK": 1.75818, "PYRt2": 0.0, "RPE": 2.67848, "RPI": -2.2815, "SUCCt2_2": -0.0, "SUCCt3": -0.0, "SUCDi": 1000.0, "SUCOAS": -5.06438, "TALA": 1.49698, "THD2": -0.0, "TKT1": 1.49698, "TKT2": 1.1815, "TPI": 7.47738}, "minimum": {"ACALD": 0.0, "ACALDt": 0.0, "ACKr": 0.0, "ACONTa": 6.00725, "ACONTb": 6.00725, "ACt2r": 0.0, "ADK1": 0.0, "AKGDH": 5.06438, "AKGt2r": 0.0, "ALCD2x": 0.0, "ATPM": 8.39, "ATPS4r": 45.51401, "Biomass_Ecoli_core": 0.87392, "CO2t": -22.80983, "CS": 6.00725, "CYTBD": 43.59899, "D_LACt2": 0.0, "ENO": 14.71614, "ETOHt2r": 0.0, "EX_ac_e": 0.0, "EX_acald_e": 0.0, "EX_akg_e": 0.0, "EX_co2_e": 22.80983, "EX_etoh_e": 0.0, "EX_for_e": 0.0, "EX_fru_e": 0.0, "EX_fum_e": 0.0, "EX_glc__D_e": -10.0, "EX_gln__L_e": 0.0, "EX_glu__L_e": 0.0, "EX_h_e": 17.53087, "EX_h2o_e": 29.17583, "EX_lac__D_e": 0.0, "EX_mal__L_e": 0.0, "EX_nh4_e": -4.76532, "EX_o2_e": -21.79949, "EX_pi_e": -3.2149, "EX_pyr_e": 0.0, "EX_succ_e": 0.0, "FBA": 7.47738, "FBP": 0.0, "FORt2": 0.0, "FORti": 0.0, "FRD7": 0.0, "FRUpts2": 0.0, "FUM": 5.06438, "FUMt2_2": 0.0, "G6PDH2r": 4.95998, "GAPD": 16.02353, "GLCpts": 10.0, "GLNS": 0.22346, "GLNabc": 0.0, "GLUDy": -4.54186, "GLUN": 0.0, "GLUSy": 0.0, "GLUt2r": 0.0, "GND": 4.95998, "H2Ot": -29.17583, "ICDHyr": 6.00725, "ICL": 0.0, "LDH_D": 0.0, "MALS": 0.0, "MALt2_2": 0.0, "MDH": 5.06438, "ME1": 0.0, "ME2": 0.0, "NADH16": 38.53461, "NADTRHD": 0.0, "NH4t": 4.76532, "O2t": 21.79949, "PDH": 9.28253, "PFK": 7.47738, "PFL": 0.0, "PGI": 4.86086, "PGK": -16.02353, "PGL": 4.95998, "PGM": -14.71614, "PIt2r": 3.2149, "PPC": 2.50431, "PPCK": 0.0, "PPS": 0.0, "PTAr": 0.0, "PYK": 1.75818, "PYRt2": 0.0, "RPE": 2.67848, "RPI": -2.2815, "SUCCt2_2": 0.0, "SUCCt3": 0.0, "SUCDi": 5.06438, "SUCOAS": -5.06438, "TALA": 1.49698, "THD2": 0.0, "TKT1": 1.49698, "TKT2": 1.1815, "TPI": 7.47738}}
{"maximum": {"MDH": 5.06438, "MALS": -0.0, "EX_pyr_e": -0.0, "PYK": 1.75818, "MALt2_2": 0.0, "PPCK": -0.0, "FBA": 7.47738, "RPE": 2.67848, "EX_fum_e": 0.0, "CS": 6.00725, "EX_o2_e": -21.79949, "FRD7": 994.93562, "AKGDH": 5.06438, "FORt2": -0.0, "GLNabc": 0.0, "EX_fru_e": -0.0, "THD2": -0.0, "FUMt2_2": 0.0, "PYRt2": 0.0, "O2t": 21.79949, "ACALDt": 0.0, "EX_acald_e": -0.0, "Biomass_Ecoli_core": 0.87392, "ACONTa": 6.00725, "TKT2": 1.1815, "TKT1": 1.49698, "LDH_D": 0.0, "GLUDy": -4.54186, "ALCD2x": 0.0, "EX_h_e": 17.53087, "EX_mal__L_e": -0.0, "NADH16": 38.53461, "TALA": 1.49698, "ME1": -0.0, "FORti": -0.0, "ME2": -0.0, "EX_nh4_e": -4.76532, "ACKr": 0.0, "ENO": 14.71614, "ACt2r": 0.0, "NH4t": 4.76532, "ACONTb": 6.00725, "EX_akg_e": -0.0, "EX_ac_e": -0.0, "ATPS4r": 45.51401, "GLUN": -0.0, "FRUpts2": 0.0, "CYTBD": 43.59899, "ATPM": 8.39, "GLNS": 0.22346, "PFK": 7.47738, "NADTRHD": -0.0, "PGK": -16.02353, "EX_succ_e": -0.0, "PGL": 4.95998, "EX_gln__L_e": 0.0, "PTAr": -0.0, "RPI": -2.2815, "GAPD": 16.02353, "ICDHyr": 6.00725, "TPI": 7.47738, "EX_glc__D_e": -10.0, "ICL": -0.0, "GLUt2r": 0.0, "ADK1": -0.0, "EX_for_e": -0.0, "EX_etoh_e": -0.0, "EX_lac__D_e": -0.0, "D_LACt2": 0.0, "PGI": 4.86086, "GND": 4.95998, "PDH": 9.28253, "EX_glu__L_e": -0.0, "PIt2r": 3.2149, "SUCDi": 1000.0, "FBP": -0.0, "EX_co2_e": 22.80983, "SUCCt2_2": -0.0, "EX_pi_e": -3.2149, "PPC": 2.50431, "PGM": -14.71614, "FUM": 5.06438, "SUCCt3": -0.0, "EX_h2o_e": 29.17583, "SUCOAS": -5.06438, "ACALD": 0.0, "H2Ot": -29.17583, "PPS": -0.0, "GLUSy": -0.0, "PFL": -0.0, "CO2t": -22.80983, "ETOHt2r": 0.0, "GLCpts": 10.0, "G6PDH2r": 4.95998, "AKGt2r": 0.0}, "minimum": {"MDH": 5.06438, "MALS": 0.0, "EX_pyr_e": 0.0, "PYK": 1.75818, "MALt2_2": 0.0, "PPCK": 0.0, "FBA": 7.47738, "RPE": 2.67848, "EX_fum_e": 0.0, "CS": 6.00725, "EX_o2_e": -21.79949, "FRD7": 0.0, "AKGDH": 5.06438, "FORt2": 0.0, "GLNabc": 0.0, "EX_fru_e": 0.0, "THD2": 0.0, "FUMt2_2": 0.0, "PYRt2": 0.0, "O2t": 21.79949, "ACALDt": 0.0, "EX_acald_e": 0.0, "Biomass_Ecoli_core": 0.87392, "ACONTa": 6.00725, "TKT2": 1.1815, "TKT1": 1.49698, "LDH_D": 0.0, "GLUDy": -4.54186, "ALCD2x": 0.0, "EX_h_e": 17.53087, "EX_mal__L_e": 0.0, "NADH16": 38.53461, "TALA": 1.49698, "ME1": 0.0, "FORti": -0.0, "ME2": 0.0, "EX_nh4_e": -4.76532, "ACKr": 0.0, "ENO": 14.71614, "ACt2r": 0.0, "NH4t": 4.76532, "ACONTb": 6.00725, "EX_akg_e": 0.0, "EX_ac_e": 0.0, "ATPS4r": 45.51401, "GLUN": 0.0, "FRUpts2": 0.0, "CYTBD": 43.59899, "ATPM": 8.39, "GLNS": 0.22346, "PFK": 7.47738, "NADTRHD": 0.0, "PGK": -16.02353, "EX_succ_e": 0.0, "PGL": 4.95998, "EX_gln__L_e": 0.0, "PTAr": 0.0, "RPI": -2.2815, "GAPD": 16.02353, "ICDHyr": 6.00725, "TPI": 7.47738, "EX_glc__D_e": -10.0, "ICL": 0.0, "GLUt2r": 0.0, "ADK1": 0.0, "EX_for_e": 0.0, "EX_etoh_e": 0.0, "EX_lac__D_e": 0.0, "D_LACt2": 0.0, "PGI": 4.86086, "GND": 4.95998, "PDH": 9.28253, "EX_glu__L_e": 0.0, "PIt2r": 3.2149, "SUCDi": 5.06438, "FBP": 0.0, "EX_co2_e": 22.80983, "SUCCt2_2": 0.0, "EX_pi_e": -3.2149, "PPC": 2.50431, "PGM": -14.71614, "FUM": 5.06438, "SUCCt3": 0.0, "EX_h2o_e": 29.17583, "SUCOAS": -5.06438, "ACALD": 0.0, "H2Ot": -29.17583, "PPS": 0.0, "GLUSy": 0.0, "PFL": 0.0, "CO2t": -22.80983, "ETOHt2r": 0.0, "GLCpts": 10.0, "G6PDH2r": 4.95998, "AKGt2r": 0.0}}
2 changes: 1 addition & 1 deletion cobra/test/data/textbook_pfba_fva.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"maximum": {"ACALD": 0.0, "ACALDt": 0.0, "ACKr": 0.0, "ACONTa": 6.00725, "ACONTb": 6.00725, "ACt2r": 0.0, "ADK1": -0.0, "AKGDH": 5.06438, "AKGt2r": 0.0, "ALCD2x": -0.0, "ATPM": 8.39, "ATPS4r": 45.51401, "Biomass_Ecoli_core": 0.87392, "CO2t": -22.80983, "CS": 6.00725, "CYTBD": 43.59899, "D_LACt2": 0.0, "ENO": 14.71614, "ETOHt2r": -0.0, "EX_ac_e": -0.0, "EX_acald_e": -0.0, "EX_akg_e": -0.0, "EX_co2_e": 22.80983, "EX_etoh_e": -0.0, "EX_for_e": -0.0, "EX_fru_e": -0.0, "EX_fum_e": 0.0, "EX_glc__D_e": -10.0, "EX_gln__L_e": 0.0, "EX_glu__L_e": -0.0, "EX_h_e": 17.53087, "EX_h2o_e": 29.17583, "EX_lac__D_e": -0.0, "EX_mal__L_e": -0.0, "EX_nh4_e": -4.76532, "EX_o2_e": -21.79949, "EX_pi_e": -3.2149, "EX_pyr_e": -0.0, "EX_succ_e": -0.0, "FBA": 7.47738, "FBP": -0.0, "FORt2": -0.0, "FORti": -0.0, "FRD7": 25.9211, "FRUpts2": 0.0, "FUM": 5.06438, "FUMt2_2": 0.0, "G6PDH2r": 4.95998, "GAPD": 16.02353, "GLCpts": 10.0, "GLNS": 0.22346, "GLNabc": 0.0, "GLUDy": -4.54186, "GLUN": -0.0, "GLUSy": -0.0, "GLUt2r": 0.0, "GND": 4.95998, "H2Ot": -29.17583, "ICDHyr": 6.00725, "ICL": -0.0, "LDH_D": 0.0, "MALS": -0.0, "MALt2_2": 0.0, "MDH": 5.06438, "ME1": -0.0, "ME2": -0.0, "NADH16": 38.53461, "NADTRHD": -0.0, "NH4t": 4.76532, "O2t": 21.79949, "PDH": 9.28253, "PFK": 7.47738, "PFL": -0.0, "PGI": 4.86086, "PGK": -16.02353, "PGL": 4.95998, "PGM": -14.71614, "PIt2r": 3.2149, "PPC": 2.50431, "PPCK": -0.0, "PPS": -0.0, "PTAr": -0.0, "PYK": 1.75818, "PYRt2": 0.0, "RPE": 2.67848, "RPI": -2.2815, "SUCCt2_2": -0.0, "SUCCt3": -0.0, "SUCDi": 30.98548, "SUCOAS": -5.06438, "TALA": 1.49698, "THD2": -0.0, "TKT1": 1.49698, "TKT2": 1.1815, "TPI": 7.47738}, "minimum": {"ACALD": 0.0, "ACALDt": 0.0, "ACKr": 0.0, "ACONTa": 6.00725, "ACONTb": 6.00725, "ACt2r": 0.0, "ADK1": 0.0, "AKGDH": 5.06438, "AKGt2r": 0.0, "ALCD2x": 0.0, "ATPM": 8.39, "ATPS4r": 45.51401, "Biomass_Ecoli_core": 0.87392, "CO2t": -22.80983, "CS": 6.00725, "CYTBD": 43.59899, "D_LACt2": 0.0, "ENO": 14.71614, "ETOHt2r": 0.0, "EX_ac_e": 0.0, "EX_acald_e": 0.0, "EX_akg_e": 0.0, "EX_co2_e": 22.80983, "EX_etoh_e": 0.0, "EX_for_e": 0.0, "EX_fru_e": 0.0, "EX_fum_e": 0.0, "EX_glc__D_e": -10.0, "EX_gln__L_e": 0.0, "EX_glu__L_e": 0.0, "EX_h_e": 17.53087, "EX_h2o_e": 29.17583, "EX_lac__D_e": 0.0, "EX_mal__L_e": 0.0, "EX_nh4_e": -4.76532, "EX_o2_e": -21.79949, "EX_pi_e": -3.2149, "EX_pyr_e": 0.0, "EX_succ_e": 0.0, "FBA": 7.47738, "FBP": 0.0, "FORt2": 0.0, "FORti": 0.0, "FRD7": 0.0, "FRUpts2": 0.0, "FUM": 5.06438, "FUMt2_2": 0.0, "G6PDH2r": 4.95998, "GAPD": 16.02353, "GLCpts": 10.0, "GLNS": 0.22346, "GLNabc": 0.0, "GLUDy": -4.54186, "GLUN": 0.0, "GLUSy": 0.0, "GLUt2r": 0.0, "GND": 4.95998, "H2Ot": -29.17583, "ICDHyr": 6.00725, "ICL": 0.0, "LDH_D": 0.0, "MALS": 0.0, "MALt2_2": 0.0, "MDH": 5.06438, "ME1": 0.0, "ME2": 0.0, "NADH16": 38.53461, "NADTRHD": 0.0, "NH4t": 4.76532, "O2t": 21.79949, "PDH": 9.28253, "PFK": 7.47738, "PFL": 0.0, "PGI": 4.86086, "PGK": -16.02353, "PGL": 4.95998, "PGM": -14.71614, "PIt2r": 3.2149, "PPC": 2.50431, "PPCK": 0.0, "PPS": 0.0, "PTAr": 0.0, "PYK": 1.75818, "PYRt2": 0.0, "RPE": 2.67848, "RPI": -2.2815, "SUCCt2_2": 0.0, "SUCCt3": 0.0, "SUCDi": 5.06438, "SUCOAS": -5.06438, "TALA": 1.49698, "THD2": 0.0, "TKT1": 1.49698, "TKT2": 1.1815, "TPI": 7.47738}}
{"maximum": {"MDH": 5.06438, "MALS": -0.0, "EX_pyr_e": -0.0, "PYK": 1.75818, "MALt2_2": 0.0, "PPCK": -0.0, "FBA": 7.47738, "RPE": 2.67848, "EX_fum_e": 0.0, "CS": 6.00725, "EX_o2_e": -21.79949, "FRD7": 25.9211, "AKGDH": 5.06438, "FORt2": -0.0, "GLNabc": 0.0, "EX_fru_e": -0.0, "THD2": -0.0, "FUMt2_2": 0.0, "PYRt2": 0.0, "O2t": 21.79949, "ACALDt": 0.0, "EX_acald_e": -0.0, "Biomass_Ecoli_core": 0.87392, "ACONTa": 6.00725, "TKT2": 1.1815, "TKT1": 1.49698, "LDH_D": 0.0, "GLUDy": -4.54186, "ALCD2x": 0.0, "EX_h_e": 17.53087, "EX_mal__L_e": -0.0, "NADH16": 38.53461, "TALA": 1.49698, "ME1": -0.0, "FORti": -0.0, "ME2": -0.0, "EX_nh4_e": -4.76532, "ACKr": 0.0, "ENO": 14.71614, "ACt2r": 0.0, "NH4t": 4.76532, "ACONTb": 6.00725, "EX_akg_e": -0.0, "EX_ac_e": -0.0, "ATPS4r": 45.51401, "GLUN": -0.0, "FRUpts2": 0.0, "CYTBD": 43.59899, "ATPM": 8.39, "GLNS": 0.22346, "PFK": 7.47738, "NADTRHD": -0.0, "PGK": -16.02353, "EX_succ_e": -0.0, "PGL": 4.95998, "EX_gln__L_e": 0.0, "PTAr": -0.0, "RPI": -2.2815, "GAPD": 16.02353, "ICDHyr": 6.00725, "TPI": 7.47738, "EX_glc__D_e": -10.0, "ICL": -0.0, "GLUt2r": 0.0, "ADK1": -0.0, "EX_for_e": -0.0, "EX_etoh_e": -0.0, "EX_lac__D_e": -0.0, "D_LACt2": 0.0, "PGI": 4.86086, "GND": 4.95998, "PDH": 9.28253, "EX_glu__L_e": -0.0, "PIt2r": 3.2149, "SUCDi": 30.98548, "FBP": -0.0, "EX_co2_e": 22.80983, "SUCCt2_2": -0.0, "EX_pi_e": -3.2149, "PPC": 2.50431, "PGM": -14.71614, "FUM": 5.06438, "SUCCt3": -0.0, "EX_h2o_e": 29.17583, "SUCOAS": -5.06438, "ACALD": 0.0, "H2Ot": -29.17583, "PPS": -0.0, "GLUSy": -0.0, "PFL": -0.0, "CO2t": -22.80983, "ETOHt2r": 0.0, "GLCpts": 10.0, "G6PDH2r": 4.95998, "AKGt2r": 0.0}, "minimum": {"MDH": 5.06438, "MALS": 0.0, "EX_pyr_e": 0.0, "PYK": 1.75818, "MALt2_2": 0.0, "PPCK": 0.0, "FBA": 7.47738, "RPE": 2.67848, "EX_fum_e": 0.0, "CS": 6.00725, "EX_o2_e": -21.79949, "FRD7": 0.0, "AKGDH": 5.06438, "FORt2": 0.0, "GLNabc": 0.0, "EX_fru_e": 0.0, "THD2": 0.0, "FUMt2_2": 0.0, "PYRt2": 0.0, "O2t": 21.79949, "ACALDt": 0.0, "EX_acald_e": 0.0, "Biomass_Ecoli_core": 0.87392, "ACONTa": 6.00725, "TKT2": 1.1815, "TKT1": 1.49698, "LDH_D": 0.0, "GLUDy": -4.54186, "ALCD2x": 0.0, "EX_h_e": 17.53087, "EX_mal__L_e": 0.0, "NADH16": 38.53461, "TALA": 1.49698, "ME1": 0.0, "FORti": 0.0, "ME2": 0.0, "EX_nh4_e": -4.76532, "ACKr": 0.0, "ENO": 14.71614, "ACt2r": 0.0, "NH4t": 4.76532, "ACONTb": 6.00725, "EX_akg_e": 0.0, "EX_ac_e": 0.0, "ATPS4r": 45.51401, "GLUN": 0.0, "FRUpts2": 0.0, "CYTBD": 43.59899, "ATPM": 8.39, "GLNS": 0.22346, "PFK": 7.47738, "NADTRHD": 0.0, "PGK": -16.02353, "EX_succ_e": 0.0, "PGL": 4.95998, "EX_gln__L_e": 0.0, "PTAr": 0.0, "RPI": -2.2815, "GAPD": 16.02353, "ICDHyr": 6.00725, "TPI": 7.47738, "EX_glc__D_e": -10.0, "ICL": 0.0, "GLUt2r": 0.0, "ADK1": 0.0, "EX_for_e": 0.0, "EX_etoh_e": 0.0, "EX_lac__D_e": 0.0, "D_LACt2": 0.0, "PGI": 4.86086, "GND": 4.95998, "PDH": 9.28253, "EX_glu__L_e": 0.0, "PIt2r": 3.2149, "SUCDi": 5.06438, "FBP": 0.0, "EX_co2_e": 22.80983, "SUCCt2_2": 0.0, "EX_pi_e": -3.2149, "PPC": 2.50431, "PGM": -14.71614, "FUM": 5.06438, "SUCCt3": 0.0, "EX_h2o_e": 29.17583, "SUCOAS": -5.06438, "ACALD": 0.0, "H2Ot": -29.17583, "PPS": 0.0, "GLUSy": 0.0, "PFL": 0.0, "CO2t": -22.80983, "ETOHt2r": 0.0, "GLCpts": 10.0, "G6PDH2r": 4.95998, "AKGt2r": 0.0}}
Binary file modified cobra/test/data/textbook_solution.pickle
Binary file not shown.
44 changes: 23 additions & 21 deletions cobra/test/data/update_pickles.py
Original file line number Diff line number Diff line change
@@ -3,38 +3,39 @@

from __future__ import absolute_import

import json
from collections import OrderedDict
from json import dump as json_dump
from builtins import open # Python 2 unicode compatibility.

import cobra
from cobra.io import (
load_matlab_model, read_sbml_model, save_json_model, save_matlab_model,
write_sbml_model)
load_matlab_model, read_sbml_model, save_json_model, save_yaml_model,
save_matlab_model, write_sbml_model)
from cobra.io.sbml3 import write_sbml2

# This script regenerates pickles of cobra Models. Should be
# performed after updating core classes to prevent subtle bugs.
try:
from cPickle import load, dump
except:
from pickle import load, dump
import cPickle as pickle
except ImportError:
import pickle


# ecoli
ecoli_model = read_sbml_model("iJO1366.xml")
with open("iJO1366.pickle", "wb") as outfile:
dump(ecoli_model, outfile, protocol=2)
with open("iJO1366.pickle", "wb", encoding=None) as outfile:
pickle.dump(ecoli_model, outfile, protocol=2)

# salmonella
salmonella = read_sbml_model("salmonella.xml")
with open("salmonella.genes", "rb") as infile:
gene_names = load(infile)
gene_names = pickle.load(infile)
for gene in salmonella.genes:
gene.name = gene_names[gene.id]
with open("salmonella.media", "rb") as infile:
salmonella.media_compositions = load(infile)
with open("salmonella.pickle", "wb") as outfile:
dump(salmonella, outfile, protocol=2)
salmonella.media_compositions = pickle.load(infile)
with open("salmonella.pickle", "wb", encoding=None) as outfile:
pickle.dump(salmonella, outfile, protocol=2)

# create mini model from textbook
textbook = read_sbml_model("textbook.xml.gz")
@@ -78,18 +79,19 @@
mini.metabolites.sort()
mini.compartments.sort()
# output to various formats
with open("mini.pickle", "wb") as outfile:
dump(mini, outfile, protocol=2)
with open("mini.pickle", "wb", encoding=None) as outfile:
pickle.dump(mini, outfile, protocol=2)
save_matlab_model(mini, "mini.mat")
save_json_model(mini, "mini.json", pretty=True)
save_json_model(mini, "mini.json", sort=True, pretty=True)
save_yaml_model(mini, "mini.yml", sort=True)
write_sbml_model(mini, "mini_fbc2.xml")
write_sbml_model(mini, "mini_fbc2.xml.bz2")
write_sbml_model(mini, "mini_fbc2.xml.gz")
write_sbml2(mini, "mini_fbc1.xml", use_fbc_package=True)
write_sbml_model(mini, "mini_cobra.xml", use_fbc_package=False)
raven = load_matlab_model("raven.mat")
with open("raven.pickle", "wb") as outfile:
dump(raven, outfile, protocol=2)
with open("raven.pickle", "wb", encoding=None) as outfile:
pickle.dump(raven, outfile, protocol=2)

# TODO:these need a reference solutions rather than circular solution checking!

@@ -99,7 +101,7 @@
for key in sorted(fva_result):
clean_result[key] = {k: round(v, 5) for k, v in fva_result[key].items()}
with open("textbook_fva.json", "w") as outfile:
json_dump(clean_result, outfile)
json.dump(clean_result, outfile)

# fva with pfba constraint
fva_result = cobra.flux_analysis.flux_variability_analysis(textbook,
@@ -108,9 +110,9 @@
for key in sorted(fva_result):
clean_result[key] = {k: round(v, 5) for k, v in fva_result[key].items()}
with open("textbook_pfba_fva.json", "w") as outfile:
json_dump(clean_result, outfile)
json.dump(clean_result, outfile)

# textbook solution
solution = cobra.flux_analysis.parsimonious.pfba(textbook)
with open('textbook_solution.pickle', 'wb') as f:
dump(solution, f, protocol=2)
with open('textbook_solution.pickle', 'wb', encoding=None) as f:
pickle.dump(solution, f, protocol=2)
1 change: 0 additions & 1 deletion cobra/test/test_io/__init__.py

This file was deleted.

1 change: 1 addition & 0 deletions cobra/test/test_io/conftest.py
Original file line number Diff line number Diff line change
@@ -19,6 +19,7 @@ def mini_model(data_directory):

def compare_models(model_1, model_2):
"""Compare two models (only for testing purposes)."""
assert len(model_1.compartments) == len(model_2.compartments)
assert len(model_1.reactions) == len(model_2.reactions)
assert len(model_1.metabolites) == len(model_2.metabolites)
assert len(model_1.genes) == len(model_2.genes)
80 changes: 80 additions & 0 deletions cobra/test/test_io/helpers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# -*- coding: utf-8 -*-

"""Define testing helper functions."""

from __future__ import absolute_import

import pytest


def assert_equal_models(model_1, model_2):
"""Compare two models (only for testing purposes)."""
assert len(model_1.compartments) == len(model_2.compartments)
assert len(model_1.reactions) == len(model_2.reactions)
assert len(model_1.metabolites) == len(model_2.metabolites)
assert len(model_1.genes) == len(model_2.genes)
assert model_1.objective.direction == model_2.objective.direction

# check Reaction attributes
for attr in ("id", "name", "lower_bound", "upper_bound",
"objective_coefficient", "gene_reaction_rule"):
assert getattr(model_1.reactions[0], attr) == getattr(
model_2.reactions[0], attr)
assert getattr(model_1.reactions[5], attr) == getattr(
model_2.reactions[5], attr)
assert getattr(model_1.reactions[-1], attr) == getattr(
model_2.reactions[-1], attr)

# check Metabolite attributes
for attr in ("id", "name", "compartment", "formula", "charge"):
assert getattr(model_1.metabolites[0], attr) == getattr(
model_2.metabolites[0], attr)
assert getattr(model_1.metabolites[5], attr) == getattr(
model_2.metabolites[5], attr)
assert getattr(model_1.metabolites[-1], attr) == getattr(
model_2.metabolites[-1], attr)
assert len(model_1.reactions[0].metabolites) == len(
model_2.reactions[0].metabolites)
# TODO: either relax gene attribute checking or fix models for testing.
# check Gene attributes
# for attr in ("id", "name"):
# assert getattr(model_1.genes[0], attr) == getattr(model_2.genes[0],
# attr)
# assert getattr(model_1.genes[10], attr) == getattr(model_2.genes[10],
# attr)
# assert getattr(model_1.genes[-1], attr) == getattr(model_2.genes[-1],
# attr)

assert len(model_1.reactions[8].metabolites) == len(
model_2.reactions[8].metabolites)
assert len(model_1.reactions[-1].metabolites) == len(
model_2.reactions[-1].metabolites)
assert len(model_1.genes) == len(model_2.genes)

# ensure they have the same solution max
solution_1 = model_1.optimize()
solution_2 = model_2.optimize()
assert abs(solution_1.objective_value -
solution_2.objective_value) == pytest.approx(0.0)

# ensure the references are correct
# metabolite -> model reference
assert model_1.metabolites[0]._model is model_1
assert model_2.metabolites[0]._model is model_2

# reaction -> model reference
assert model_1.reactions[0]._model is model_1
assert model_2.reactions[0]._model is model_2

# gene -> model reference
assert model_1.genes[0]._model is model_1
assert model_2.genes[0]._model is model_2

# extra comparisons
# assert model_1.compartments == model_2.compartments
# assert dict(model_1.metabolites[4].annotation) == dict(
# model_2.metabolites[4].annotation)
# assert dict(model_1.reactions[4].annotation) == dict(
# model_2.reactions[4].annotation)
# assert dict(model_1.genes[5].annotation) == dict(
# model_2.genes[5].annotation)
51 changes: 28 additions & 23 deletions cobra/test/test_io/test_json.py
Original file line number Diff line number Diff line change
@@ -1,40 +1,45 @@
# -*- coding: utf-8 -*-

"""Test functionalities of json.py"""
"""Test JSON input and output."""

from __future__ import absolute_import

import json
from builtins import open # Python 2 unicode compatibility.
from os.path import join

import cobra.io as cio
import pytest
from cobra.test.test_io.conftest import compare_models

import helpers

@pytest.mark.xfail(reason="schema outdated")
def test_validate_json(data_directory):
"""Validate file according to JSON-schema."""
jsonschema = pytest.importorskip("jsonschema")
with open(join(data_directory, "mini.json"),
"r", encoding="utf-8") as infile:
loaded = json.load(infile)
assert jsonschema.validate(loaded, cio.json.json_schema)

def test_from_json(data_directory, mini_model):
"""Test reading a model from a JSON string."""
with open(join(data_directory, "mini.json"), encoding="utf-8") as handle:
json_model = cio.from_json(handle.read())
helpers.assert_equal_models(mini_model, json_model)


def test_load_json_model(data_directory, mini_model):
"""Test the reading of JSON model."""
"""Test reading a model from a JSON file."""
json_model = cio.load_json_model(join(data_directory, "mini.json"))
assert compare_models(mini_model, json_model) is None
helpers.assert_equal_models(mini_model, json_model)


def test_to_json(data_directory, mini_model):
"""Test writing a model to a JSON string."""
output = cio.to_json(mini_model, sort=True, pretty=True)
with open(join(data_directory, "mini.json"), encoding="utf-8") as handle:
expected = handle.read()
assert output == expected


@pytest.mark.xfail(reason="schema outdated")
def test_save_json_model(tmpdir, mini_model):
"""Test the writing of JSON model."""
jsonschema = pytest.importorskip("jsonschema")
def test_save_json_model(tmpdir, data_directory, mini_model):
"""Test writing a model to a JSON file."""
output_file = tmpdir.join("mini.json")
cio.save_json_model(mini_model, output_file.strpath, pretty=True)
# validate against JSONSchema
with open(output_file, "r") as infile:
loaded = json.load(infile)
assert jsonschema.validate(loaded, cio.json.json_schema)
cio.save_json_model(mini_model, str(output_file), sort=True, pretty=True)
# Validate the written file.
with open(str(output_file), encoding="utf-8") as handle:
output = handle.read()
with open(join(data_directory, "mini.json"), encoding="utf-8") as handle:
expected = handle.read()
assert output == expected
32 changes: 15 additions & 17 deletions cobra/test/test_io/test_mat.py
Original file line number Diff line number Diff line change
@@ -4,27 +4,27 @@

from __future__ import absolute_import

from builtins import open # Python 2 unicode compatibility.
from os.path import join
from pickle import load

import pytest
from cobra import io
from cobra.test.test_io.conftest import compare_models
import cobra.io as cio

try:
import scipy
except ImportError:
scipy = None
import helpers


@pytest.fixture(scope="function")
scipy = pytest.importorskip("scipy")


@pytest.fixture(scope="module")
def raven_model(data_directory):
"""Fixture for RAVEN model."""
with open(join(data_directory, "raven.pickle"), "rb") as infile:
with open(join(data_directory, "raven.pickle"),
"rb", encoding=None) as infile:
return load(infile)


@pytest.mark.skipif(scipy is None, reason='scipy unavailable')
# @pytest.mark.parametrize("ref_model, filename",
# [(pytest.fixture_request("mini_model"),
# "mini.mat"),
@@ -33,14 +33,12 @@ def raven_model(data_directory):
# TODO: wait for pytest.fixture_request() to get approved
def test_load_matlab_model(data_directory, mini_model, raven_model):
"""Test the reading of MAT model."""
mini_mat_model = io.load_matlab_model(join(data_directory, "mini.mat"))
raven_mat_model = io.load_matlab_model(join(data_directory, "raven.mat"))
assert compare_models(mini_model, mini_mat_model) is None
assert compare_models(raven_model, raven_mat_model) is None
mini_mat_model = cio.load_matlab_model(join(data_directory, "mini.mat"))
raven_mat_model = cio.load_matlab_model(join(data_directory, "raven.mat"))
helpers.assert_equal_models(mini_model, mini_mat_model)
helpers.assert_equal_models(raven_model, raven_mat_model)


# @pytest.mark.xfail(reason="localPath not supported yet")
@pytest.mark.skipif(scipy is None, reason='scipy unavailable')
# @pytest.mark.parametrize("model, filename",
# [(pytest.fixture_request("mini_model"),
# "mini.mat"),
@@ -53,7 +51,7 @@ def test_save_matlab_model(tmpdir, mini_model, raven_model):
raven_output_file = tmpdir.join("raven.mat")
# scipy.io.savemat() doesn't support anything other than
# str or file-stream object, hence the str conversion
io.save_matlab_model(mini_model, str(mini_output_file))
io.save_matlab_model(raven_model, str(raven_output_file))
cio.save_matlab_model(mini_model, str(mini_output_file))
cio.save_matlab_model(raven_model, str(raven_output_file))
assert mini_output_file.check()
assert raven_output_file.check()
41 changes: 16 additions & 25 deletions cobra/test/test_io/test_pickle.py
Original file line number Diff line number Diff line change
@@ -4,41 +4,32 @@

from __future__ import absolute_import

from builtins import open # Python 2 unicode compatibility.
from os.path import join
from pickle import dump, load

import pytest
from cobra.test.test_io.conftest import compare_models

try:
import cPickle
cload = cPickle.load
cdump = cPickle.dump
except ImportError:
cload = None
cdump = None
import helpers


@pytest.mark.parametrize("load_function", [load, cload])
def test_read_pickle(data_directory, mini_model, load_function):
"""Test the reading of model from pickle."""
if load_function is None:
pytest.skip()
PICKLE_MODULES = ["pickle", "cPickle"]

with open(join(data_directory, "mini.pickle"), "rb") as infile:
pickle_model = load_function(infile)

assert compare_models(mini_model, pickle_model) is None
@pytest.mark.parametrize("module", PICKLE_MODULES)
def test_read_pickle(data_directory, mini_model, module):
"""Test the reading of model from pickle."""
pickle = pytest.importorskip(module)
with open(join(data_directory, "mini.pickle"),
"rb", encoding=None) as infile:
pickle_model = pickle.load(infile)
helpers.assert_equal_models(mini_model, pickle_model)


@pytest.mark.parametrize("dump_function", [dump, cdump])
def test_write_pickle(tmpdir, mini_model, dump_function):
@pytest.mark.parametrize("module", PICKLE_MODULES)
def test_write_pickle(tmpdir, mini_model, module):
"""Test the writing of model to pickle."""
if dump_function is None:
pytest.skip()

pickle = pytest.importorskip(module)
output_file = tmpdir.join("mini.pickle")
with open(str(output_file), "wb") as outfile:
dump_function(mini_model, outfile)

with open(str(output_file), "wb", encoding=None) as outfile:
pickle.dump(mini_model, outfile)
assert output_file.check()
36 changes: 17 additions & 19 deletions cobra/test/test_io/test_sbml.py
Original file line number Diff line number Diff line change
@@ -4,52 +4,50 @@

from __future__ import absolute_import

from os.path import getsize, join
from os.path import join

import pytest
from cobra import io
from cobra.test.test_io.conftest import compare_models

try:
import libsbml
except ImportError:
libsbml = None
import cobra.io as cio

import helpers


libsbml = pytest.importorskip("libsbml")


@pytest.fixture(scope="function")
def mini_fbc1_model(data_directory):
return io.read_legacy_sbml(join(data_directory, "mini_fbc1.xml"))
return cio.read_legacy_sbml(join(data_directory, "mini_fbc1.xml"))


@pytest.fixture(scope="function")
def mini_cobra_model(data_directory):
return io.read_legacy_sbml(join(data_directory, "mini_cobra.xml"))
return cio.read_legacy_sbml(join(data_directory, "mini_cobra.xml"))


# TODO: parametrize the arguments after pytest.fixture_request()
# is approved
@pytest.mark.skipif(libsbml is None, reason="libsbml unavailable.")
def test_read_sbml_model(data_directory, mini_fbc1_model, mini_cobra_model):
"""Test the reading of a model from SBML v2."""
mini_fbc1 = io.read_legacy_sbml(join(data_directory, "mini_fbc1.xml"))
mini_cobra = io.read_legacy_sbml(join(data_directory, "mini_cobra.xml"))
assert compare_models(mini_fbc1_model, mini_fbc1) is None
assert compare_models(mini_cobra_model, mini_cobra) is None
mini_fbc1 = cio.read_legacy_sbml(join(data_directory, "mini_fbc1.xml"))
mini_cobra = cio.read_legacy_sbml(join(data_directory, "mini_cobra.xml"))
helpers.assert_equal_models(mini_fbc1_model, mini_fbc1)
helpers.assert_equal_models(mini_cobra_model, mini_cobra)


# TODO: parametrize the arguments after pytest.fixture_request()
# is approved
@pytest.mark.skipif(libsbml is None, reason="libsbml unavailable.")
def test_write_sbml_model(tmpdir, mini_fbc1_model, mini_cobra_model):
"""Test the writing of a model to SBML v2."""
mini_fbc1_output_file = tmpdir.join("mini_fbc1.xml")
mini_cobra_output_file = tmpdir.join("mini_cobra.xml")

# convert to str object before passing the filename
io.write_legacy_sbml(mini_fbc1_model, str(mini_fbc1_output_file),
use_fbc_package=True)
io.write_legacy_sbml(mini_cobra_model, str(mini_cobra_output_file),
use_fbc_package=False)
cio.write_legacy_sbml(mini_fbc1_model, str(mini_fbc1_output_file),
use_fbc_package=True)
cio.write_legacy_sbml(mini_cobra_model, str(mini_cobra_output_file),
use_fbc_package=False)

assert mini_fbc1_output_file.check()
assert mini_cobra_output_file.check()
27 changes: 14 additions & 13 deletions cobra/test/test_io/test_sbml3.py
Original file line number Diff line number Diff line change
@@ -6,63 +6,64 @@

from os.path import join

import pytest
from six import itervalues

import pytest
from cobra import io
from cobra.test.test_io.conftest import compare_models
import cobra.io as cio

import helpers


@pytest.fixture(scope="function")
def mini_fbc2_model(data_directory):
"""Return mini_fbc2 model."""
return io.sbml3.read_sbml_model(join(data_directory, "mini_fbc2.xml"))
return cio.sbml3.read_sbml_model(join(data_directory, "mini_fbc2.xml"))


# Benchmarks
def test_benchmark_read(data_directory, benchmark):
"""Benchmark SBML read."""
benchmark(io.sbml3.read_sbml_model, join(data_directory, "mini_fbc2.xml"))
benchmark(cio.sbml3.read_sbml_model, join(data_directory, "mini_fbc2.xml"))


def test_benchmark_write(model, benchmark, tmpdir):
"""Benchmark SBML write."""
benchmark(io.sbml3.write_sbml_model, model, tmpdir.join("-bench"))
benchmark(cio.sbml3.write_sbml_model, model, tmpdir.join("-bench"))


# Tests
def test_sbml3_error(data_directory):
"""Test invalid SBML read."""
filename = join(data_directory, "invalid0.xml")
with pytest.raises(io.sbml3.CobraSBMLError):
io.read_sbml_model(filename)
with pytest.raises(cio.sbml3.CobraSBMLError):
cio.read_sbml_model(filename)


def test_validate_sbml_model(data_directory):
"""Test validation of SBML."""
# invalid SBML
for i in range(3):
filename = join(data_directory, "invalid{}.xml".format(i))
_, errors = io.sbml3.validate_sbml_model(filename)
_, errors = cio.sbml3.validate_sbml_model(filename)
assert all(len(v) >= 1 for v in itervalues(errors)) is False

# valid SBML
filename = join(data_directory, "mini_fbc2.xml")
_, errors = io.sbml3.validate_sbml_model(filename)
_, errors = cio.sbml3.validate_sbml_model(filename)
assert all(len(v) == 0 for v in itervalues(errors))


@pytest.mark.parametrize("sbml_file", ["mini_fbc2.xml", "mini_fbc2.xml.gz",
"mini_fbc2.xml.bz2"])
def test_read_sbml_model(data_directory, mini_model, sbml_file):
"""Test the reading of a model from SBML3."""
sbml3_model = io.read_sbml_model(join(data_directory, sbml_file))
assert compare_models(mini_model, sbml3_model) is None
sbml3_model = cio.read_sbml_model(join(data_directory, sbml_file))
helpers.assert_equal_models(mini_model, sbml3_model)


@pytest.mark.parametrize("ext", [".xml", ".xml.gz", ".xml.bz2"])
def test_write_sbml_model(tmpdir, mini_fbc2_model, ext):
"""Test the writing of model to SBML3."""
output_file = tmpdir.join("mini_fbc2{}".format(ext))
io.write_sbml_model(mini_fbc2_model, output_file)
cio.write_sbml_model(mini_fbc2_model, output_file)
assert output_file.check()
50 changes: 30 additions & 20 deletions cobra/test/test_io/test_yaml.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,45 @@
# -*- coding: utf-8 -*-

"""Test functionalities provided by yaml.py"""
"""Test YAML input and output."""

from __future__ import absolute_import

import json
from builtins import open # Python 2 unicode compatibility.
from os.path import join

from ruamel.yaml import YAML

import cobra.io as cio
import pytest
from cobra.test.test_io.conftest import compare_models

import helpers


def test_from_yaml(data_directory, mini_model):
"""Test reading a model from a YAML string."""
with open(join(data_directory, "mini.yml"), encoding="utf-8") as handle:
yaml_model = cio.from_yaml(handle.read())
helpers.assert_equal_models(mini_model, yaml_model)


def test_load_yaml_model(data_directory, mini_model):
"""Test the reading of YAML model."""
"""Test reading a model from a YAML file."""
yaml_model = cio.load_yaml_model(join(data_directory, "mini.yml"))
assert compare_models(mini_model, yaml_model) is None
helpers.assert_equal_models(mini_model, yaml_model)


def test_to_yaml(data_directory, mini_model):
"""Test writing a model to a YAML string."""
output = cio.to_yaml(mini_model, sort=True)
with open(join(data_directory, "mini.yml"), encoding="utf-8") as handle:
expected = handle.read()
assert output == expected


@pytest.mark.xfail(reason="schema outdated")
def test_save_yaml_model(tmpdir, mini_model):
jsonschema = pytest.importorskip("jsonschema")
"""Test the writing of YAML model."""
def test_save_yaml_model(tmpdir, data_directory, mini_model):
"""Test writing a model to a YAML file."""
output_file = tmpdir.join("mini.yml")
cio.save_yaml_model(mini_model, output_file.strpath, sort=True)
# validate against schema
yaml = YAML(typ="unsafe")
with open(output_file.strpath, "r") as infile:
yaml_to_dict = yaml.load(infile)
dict_to_json = json.dumps(yaml_to_dict)
loaded = json.loads(dict_to_json)
assert jsonschema.validate(loaded, cio.json.json_schema)
cio.save_yaml_model(mini_model, str(output_file), sort=True)
# Validate the written file.
with open(str(output_file), encoding="utf-8") as handle:
output = handle.read()
with open(join(data_directory, "mini.yml"), encoding="utf-8") as handle:
expected = handle.read()
assert output == expected