65c98249fb79ec5831eaa63c2792a6c1bb5a210d
1 # This program is free software; you can redistribute it and/or modify
2 # it under the terms of the GNU General Public License as published by
3 # the Free Software Foundation; either version 2 of the License, or
4 # (at your option) any later version.
6 # Written (W) 2008 Fabio De Bona
7 # Copyright (C) 2008 Max-Planck-Society
10 # This file contains the main interface to the QPalma pipeline.
20 def parseSettingsFile(filename
):
22 This function parse all key value pairs from the given filename
25 for line
in open(filename
):
26 if (not line
.strip()) or line
.startswith('#'):
29 key
, val
= line
.strip().replace(' ', '').split('=')
35 def makeSettings(settings
):
39 assert os
.path
.exists(settings
['result_dir']),'Error: You have to specify a existing result directory!'
40 result_dir
= settings
['result_dir']
41 settings
['approximation_dir'] = jp(result_dir
, 'approximation')
42 settings
['dataset_dir'] = jp(result_dir
, 'dataset')
43 settings
['preproc_dir'] = jp(result_dir
, 'preprocessing')
44 settings
['postproc_dir'] = jp(result_dir
, 'postprocessing')
45 settings
['prediction_dir'] = jp(result_dir
, 'prediction')
46 settings
['training_dir'] = jp(result_dir
, 'training')
48 for dir_name
in ['approximation_dir','dataset_dir', 'preproc_dir', 'postproc_dir',\
49 'prediction_dir', 'training_dir']:
51 os
.mkdir(settings
[dir_name
])
54 print ('Error: There was a problem generating the subdirectory: %s' % dir_name
)
56 assert checkSettings(settings
),'Check your settings some entries were invalid!'
58 ddir
= settings
['dataset_dir']
59 settings
['prediction_dataset_fn'] = jp(ddir
,'prediction_data.pickle')
60 settings
['prediction_dataset_keys_fn'] = jp(ddir
,'prediction_data.keys.pickle')
61 settings
['training_dataset_fn'] = jp(ddir
,'training_data.pickle')
62 settings
['training_dataset_keys_fn'] = jp(ddir
,'training_data.keys.pickle')
65 os
.mkdir(settings
['global_log_fn'])
67 print 'Error: There was a problem generating the logfile %s' % settings
['global_log_fn']
70 settings
['num_splits'] = int(settings
['num_splits'])
72 print 'Error: num_splits has to be a positive integer'
74 settings
['allowed_fragments'] = eval(settings
['allowed_fragments'])
75 settings
['half_window_size'] = int(settings
['half_window_size'])
80 def checkSettings(settings
):
81 for (key
, val
,) in settings
.items():
82 if key
.endswith('_fn'):
83 assert os
.path
.exists(val
), 'Error: Path/File %s with value %s does not seem to exist!' % (key
,val
)
84 if key
.endswith('_dir'):
85 assert os
.path
.exists(val
), 'Error: Path/File %s with value %s does not seem to exist!' % (key
,val
)
90 def parseSettings(filename
):
91 settings
= parseSettingsFile(filename
)
92 settings
= makeSettings(settings
)