+ renamed dyn_prog directory
[qpalma.git] / scripts / check_and_init.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3
4 #
5 #
6 #
7 #
8
9 import os.path
10 import cPickle
11
12 import QPalmaConfiguration as Conf
13
14
15 def check_vmatch_params(Config):
16 #
17 # Check and set parameters for the first VMatch step
18 #
19
20 Config['mismatches_1'] = Conf.mismatches_1
21 Config['end_gap_1'] = Conf.end_gap_1
22 Config['read_length_1'] = Conf.read_length_1
23 Config['repeat_mapping_1'] = Conf.repeat_mapping_1
24 Config['seedlength_1'] = Conf.seedlength_1
25 Config['suffixtree_1'] = Conf.suffixtree_1
26
27 assert 0 <= Config['mismatches_1'] <= Config['read_size']
28 assert 0 <= Config['end_gap_1'] <= 5
29 assert 0 <= Config['repeat_mapping_1'] <= 10
30 assert 2 <= Config['seedlength_1'] <= Config['read_size']
31 assert os.path.exists( Config['suffixtree_1'] )
32
33 #
34 # Check and set parameters for the second VMatch step
35 #
36
37 Config['mismatches_2'] = Conf.mismatches_2
38 Config['sub_mismatches_2'] = Conf.sub_mismatches_2
39 Config['min_short_end_2'] = Conf.min_short_end_2
40 Config['repeat_mapping_2'] = Conf.repeat_mapping_2
41 Config['seedlength_2'] = Conf.seedlength_2
42
43 assert 0 <= Config['mismatches_2'] <= Config['read_size']
44 assert 0 <= Config['sub_mismatches_2'] <= Config['read_size']
45 assert 0 <= Config['min_short_end_2'] <= Config['read_size']
46 assert 0 <= Config['repeat_mapping_2'] <= Config['read_size']
47 assert os.path.exists( Config['suffixtree_2'] )
48
49
50 def check_and_init():
51 """
52 The purpose of this script is to take all the global variables from the
53 Configuration file and store them into a dictionary for the pipeline.
54
55 Additionally sanity checks are performed for the parameters to be sure they
56 are within a certain interval or the file they point to exists etc.
57 """
58
59 jp = os.path.join
60
61 # create a python dictionary to store all configuration parameters
62 Config = {}
63
64 result_dir = Conf.result_dir
65 assert os.path.exists(result_dir), 'Error you have to specify an existing result_dir.'
66
67 # assing main result dir in Config dictionary
68 Config['result_dir'] = result_dir
69
70 Config['reads_location'] = Conf.reads_location
71 #assert os.path.exists(Config['reads_location'])
72
73 Config['read_size'] = Conf.read_size
74 assert 2 <= Config['read_size'] <= 100
75
76 # Check VMatch related parameters
77 check_vmatch_params(Config)
78
79 subdirs = []
80
81 # create subdirs needed for mapping / alignment / remapping
82 mapping_dir = jp(result_dir,'mapping')
83 Config['mapping_dir'] = mapping_dir
84 Config['mapping_main_dir'] = jp(mapping_dir,'main')
85 Config['mapping_spliced_dir'] = jp(mapping_dir,'spliced')
86
87 subdirs.extend([Config['mapping_dir'], Config['mapping_main_dir'],\
88 Config['mapping_spliced_dir']])
89
90 Config['alignment_dir'] = jp(result_dir,'alignment')
91
92 subdirs.extend([Config['alignment_dir']])
93
94 Config['remapping_dir'] = jp(result_dir,'remapping')
95
96 subdirs.extend([Config['remapping_dir']])
97
98 #try:
99 # for current_dir in subdirs:
100 # os.mkdir(current_dir)
101 #except:
102 # print 'Error during initialization of project directories'
103
104 # store the configuration in a pickled python dictionary
105 cPickle.dump(Config,open(Conf.conf_object_path,'w+'))
106
107
108 if __name__ == '__main__':
109 check_and_init()