"""Build a database of organism metabolic models."""importpandasaspdimportosfromosimportpathfromzipfileimportZipFile
[docs]defload_manifest(folder):"""Get the manifest from a model DB."""mpath=path.join(folder,"manifest.csv")ifnotpath.exists(mpath):raiseValueError("No manifest found. `%s` does not look like a valid ""model database."%folder)manifest=pd.read_csv(path.join(folder,"manifest.csv"))if"file"notinmanifest.columns:raiseValueError("Invalid manifest for model database :(")manifest.file=[path.join(folder,f)forfinmanifest.file]returnmanifest
[docs]defload_zip_model_db(artifact,extract_path):"""Prepare a model database for use."""ifnotpath.exists(extract_path):os.mkdir(extract_path)withZipFile(artifact)aszf:zf.extractall(extract_path)manifest=load_manifest(extract_path)manifest["file"]=[path.join(extract_path,f)forfinmanifest.file]returnmanifest