-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathmip_hedwig.py
66 lines (49 loc) · 1.43 KB
/
mip_hedwig.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
60
61
62
63
64
65
66
'''
Hedwig wrapper for the HBP medical platform.
@author: anze.vavpetic@ijs.si
'''
import tempfile
import os
import logging
from subprocess import call
from mip_helper import io_helper, parameters, shapes, utils
import preprocess
# Configure logging
logging.basicConfig(level=logging.INFO)
DEFAULT_DOCKER_IMAGE = 'python-jsi-hedwig'
@utils.catch_user_error
def main(clean_files=False):
"""
:param clean_files: if True, clean files afterwards
"""
# Read inputs
inputs = io_helper.fetch_data()
data = inputs["data"]
beam = parameters.get_parameter('beam', int, 10)
support = parameters.get_parameter('support', float, '0.00001')
out_file = 'input.csv'
rules_out_file = 'rules.txt'
matrix, attributes = preprocess.to_matrix(data)
preprocess.dump_to_csv(matrix, attributes, out_file)
# Call hedwig with sensible defaults
examples_file = out_file
empty_bk = tempfile.mkdtemp()
call([
'python', '-m' 'hedwig.__main__',
empty_bk,
examples_file,
'--beam', str(beam),
'--support', str(support),
'-f', 'csv',
'-l',
'-o', rules_out_file,
'--nocache'
])
with open(rules_out_file) as f:
results = f.read()
if clean_files:
os.remove(out_file)
os.remove(rules_out_file)
io_helper.save_results(results.replace('less_than', '<'), shapes.Shapes.TEXT)
if __name__ == '__main__':
main()