-
Notifications
You must be signed in to change notification settings - Fork 2
/
run_project_on_biosimulations.py
51 lines (39 loc) · 1.36 KB
/
run_project_on_biosimulations.py
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
import os
import json
import fire
import requests
import urllib.request
def runProject(project_id, simulator='tellurium', omex_dir="./omex_files", biosimulations_runs_file = "biosimulations_runs.json"):
"""
This function runs the project on biosimulations.
"""
omex_file = os.path.join(omex_dir, project_id + ".omex")
simulation_run_data = {
'name': project_id,
'simulator': simulator,
'version': 'latest',
}
multipart_form_data = {
'file': (project_id + '.omex', open(omex_file, 'rb')),
'simulationRun': (None, json.dumps(simulation_run_data)),
}
req = requests.post(
"https://api.biosimulations.org/runs",
files=multipart_form_data)
req.raise_for_status()
res = req.json()
simulation_id = res["id"]
if(os.path.exists(biosimulations_runs_file)):
with open(biosimulations_runs_file) as f:
runs = json.load(f)
else:
runs = {}
if project_id not in runs:
runs[project_id] = []
runs[project_id].append((simulator, simulation_id))
with open(biosimulations_runs_file, 'w') as f:
json.dump(runs, f)
print("Ran " + project_id + " on biosimulations with simulation id: " + simulation_id)
print("View: https://run.biosimulations.org/runs/" + simulation_id)
if __name__ == "__main__":
fire.Fire(runProject)