forked from canc1993/cheshire-gapfilling
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalidate.py
59 lines (50 loc) · 1.91 KB
/
validate.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
52
53
54
55
56
57
58
59
import cobra
import optlang
import os
import pandas as pd
from copy import deepcopy
from joblib import Parallel, delayed
import read_paras
import fba
import sys
import warnings
warnings.filterwarnings("ignore")
def validate():
# we currently only support cplex
solvers = [match.split("_interface")[0] for match in dir(optlang) if "_interface" in match]
if "cplex" not in solvers:
raise RuntimeError("cplex not found.")
# read in arguments
if len(sys.argv) > 2:
raise RuntimeError('at most one parameter is supplied.')
if len(sys.argv) == 2:
input_file = sys.argv[1]
else:
if os.path.exists('input_parameters.txt'):
input_file = 'input_parameters.txt'
else:
raise RuntimeError(
'input file not specified and the default input_parameters.txt cannot be found as well.'
)
# read input parameters
paras = read_paras.read(input_file)
# load reaction pools
universe = cobra.io.read_sbml_model(paras['REACTION_POOL'])
universe.solver = 'cplex'
# ***********************************************************************
# add gapfilled reactions or random reactions selected from reaction pools
# ***********************************************************************
# compute fermentation flux
print('-------------------------------------------------------')
df_output = None
retLst = Parallel(n_jobs=int(paras['NUM_CPUS']))(
delayed(fba.predict_fermentation)(gem_file, universe, paras) for gem_file in paras['GEMs'].split(';')
)
if df_output is None:
df_output = deepcopy(pd.concat(retLst))
else:
df_output = pd.concat([df_output, pd.concat(retLst)])
# write intermediate results to file
output_file: str = "%s/%s" % (paras['OUTPUT_DIRECTORY'], paras['OUTPUT_FILENAME'])
df_output.to_csv(output_file, index=False)
print('done!')