-
Notifications
You must be signed in to change notification settings - Fork 0
/
runner.py
50 lines (38 loc) · 1.21 KB
/
runner.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
from app import run
import dill as pickle
import os
def put_anndata(name, data):
if 'adata' in data.keys():
import anndata as ad
filename, ext = os.path.splitext(name)
filename = f'{filename}.h5ad'
try:
ad.AnnData.write(data['adata'], filename)
except TypeError:
print('cannot convert anndata to h5ad, skipping')
else:
return
def get(name):
filename, ext = os.path.splitext(name)
filename = f'{filename}.pickle'
with open(filename, "rb") as infile:
data = pickle.load(infile)
return data
def put(name, data):
filename, ext = os.path.splitext(name)
filename = f'{filename}.pickle'
with open(filename, "wb") as outfile:
pickle.dump(data, outfile)
if __name__ == '__main__':
env = os.environ.get("VIRTUAL_ENV", None)
if env is None:
env = os.environ.get("CONDA_PREFIX", None)
print(f'current env: {env}')
try:
result = run(**get(__file__))
if not (result and len(result.keys()) > 0):
exit(2)
put(__file__, result)
put_anndata(__file__, result)
except Exception as e:
raise e