def add_file(sbml_path, file_path, file_type): LOGGER.info("Reading SBML '%s'.", sbml_path) model = read_sbml_model(sbml_path) LOGGER.info("Writing {} '{}'.".format(file_type.upper(), file_path)) if file_type == "yaml": save_yaml_model(model, file_path, sort=True) # Use subprocess rather than gitpython because gitpython cannot get a lock # on the git DB and thus raises an exception. check_output(["git", "add", file_path])
def test_save_yaml_model(tmpdir, mini_model): jsonschema = pytest.importorskip("jsonschema") """Test the writing of YAML model.""" 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)
for g in mini.genes: try: tg = textbook.genes.get_by_id(g.id) except KeyError: continue g.name = tg.name g.annotation = tg.annotation mini.reactions.sort() mini.genes.sort() mini.metabolites.sort() # output to various formats with open("mini.pickle", "wb") as outfile: dump(mini, outfile, protocol=2) save_matlab_model(mini, "mini.mat") save_json_model(mini, "mini.json", pretty=True) save_yaml_model(mini, "mini.yml") write_sbml_model(mini, "mini_fbc2.xml") write_sbml_model(mini, "mini_fbc2.xml.bz2") write_sbml_model(mini, "mini_fbc2.xml.gz") 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) # TODO:these need a reference solutions rather than circular solution checking! # fva results fva_result = cobra.flux_analysis.flux_variability_analysis(textbook) clean_result = OrderedDict() for key in sorted(fva_result): clean_result[key] = {k: round(v, 5) for k, v in fva_result[key].items()}