-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconvert_models
More file actions
executable file
·79 lines (66 loc) · 2.51 KB
/
Copy pathconvert_models
File metadata and controls
executable file
·79 lines (66 loc) · 2.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import sys
from pathlib import Path
import shutil
import subprocess
import json
def load_genomes_file(filename):
with open(filename, "r") as f:
data = json.load(f)
return data["models"]
ORIGINAL_MODEL_DIRECTORY = Path.cwd() / Path("original_models/")
CONVERTED_MODEL_DIRECTORY = Path.cwd() / Path("models/")
ENVIRONMENTS_DIRECTORY = Path.cwd() / Path("old_cobra_environments/")
ENVIRONMENTS = {
"cobra_0.14.2": "cobra_0.14.2",
"cobra_0.15.4": "cobra_0.15.4",
}
USER_ID = os.geteuid()
GROUP_ID = os.getegid()
def build_environments():
envs = list(set(ENVIRONMENTS.values()))
for env in envs:
completed_process = subprocess.run(
["docker", "build", ".", "-f", f"Dockerfile.{env}", "-t", env],
cwd=ENVIRONMENTS_DIRECTORY,
)
completed_process.check_returncode()
def main(filename):
build_environments()
model_genomes = load_genomes_file(filename)
for model_data in model_genomes:
model_filename = model_data["filename"]
cobra_environment = model_data.get("cobra_env", "latest")
original_filename = ORIGINAL_MODEL_DIRECTORY / model_filename
converted_filename = CONVERTED_MODEL_DIRECTORY / model_filename
if converted_filename.exists() and converted_filename.is_file():
print(f"{model_filename}: Exists, skipping")
continue
if cobra_environment == "latest":
print(f"{model_filename}: latest (copy file)")
shutil.copy(original_filename, converted_filename)
elif not (environment := ENVIRONMENTS.get(cobra_environment)) is None:
print(f"{model_filename}: {cobra_environment}({environment})")
completed_process = subprocess.run(
[
"docker",
"run",
"--user",
f"{USER_ID}:{GROUP_ID}",
"-v",
f"{ORIGINAL_MODEL_DIRECTORY}:/models/",
"-v",
f"{CONVERTED_MODEL_DIRECTORY}:/converted_models",
environment,
Path("/models") / model_filename,
Path("/converted_models") / model_filename,
]
)
completed_process.check_returncode()
else:
print(f"{model_filename}: {cobra_environment}(ERROR)")
raise ValueError(f"Unknown environment '{environment}'")
if __name__ == "__main__":
main(sys.argv[1])