+ removed accidently checked in vim swap files
[qpalma.git] / python / set_param_palma.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3
4 import math
5 import numpy.matlib
6 import QPalmaDP
7 import pdb
8
9 def linspace(a,b,n):
10 intervalLength = b-a
11 stepSize = 1.0*intervalLength / (n-1)
12
13 interval = [0]*n
14 interval[0] = a
15 interval[-1] = b
16 for i in range(1,n-1):
17 interval[i] = a+(i*stepSize)
18
19 return interval
20
21 def logspace(a,b,n):
22 interval = [0]*n
23 begin = 10.0**a
24 end = 10.0**b
25 intervalSize = 1.0*(b-a)/(n-1)
26 interval[0] = begin
27 interval[-1] = end
28
29 for i in range(1,n-1):
30 interval[i] = 10**(a+i*intervalSize)
31
32 return interval
33
34 def log10(x):
35 return math.log(x)/math.log(10)
36
37 class Plf: #means piecewise linear function
38
39 def __init_(self):
40 self.len = 0
41 self.limits = []
42 self.penalties = []
43 self.transform = ''
44 self.name = ''
45 self.max_len = 0
46 self.min_len = 0
47
48 def convert2SWIG(self):
49 ps = QPalmaDP.penalty_struct()
50
51 ps.limits = QPalmaDP.createDoubleArrayFromList(self.limits)
52 ps.penalties = QPalmaDP.createDoubleArrayFromList(self.penalties)
53
54 ps.max_len = self.max_len
55 ps.min_len = self.min_len
56 ps.transform = 0
57 ps.name = self.name
58
59 return ps
60
61
62 def set_params_pa():
63 h = plf()
64 h.len = int(model.intron_len_bins)
65 h.limits = model.intron_len_limits
66 h.penalties = model.intron_len_penalties
67 h.name = 'h'
68 h.max_len = int(max_intron_len)
69 h.min_len = int(min_intron_len)
70 h.transform = model.intron_len_transform
71
72 d = plf()
73 d.len = int(model.donor_bins)
74 d.limits = model.donor_limits
75 d.penalties = model.donor_penalties
76 d.name = 'd'
77 d.max_len = 100
78 d.min_len = -100
79
80 a = plf()
81 a.len = int(model.acceptor_bins)
82 a.limits = model.acceptor_limits
83 a.penalties = model.acceptor_penalties
84 a.name = 'a'
85 a.max_len = 100
86 a.min_len = -100
87
88 mmatrix = model.substitution_matrix
89
90
91 def set_param_palma(param, train_with_intronlengthinformation,\
92 min_intron_len=None, max_intron_len=None, min_svm_score=None, max_svm_score=None):
93
94 print 'Setting parameters ...'
95
96 if min_intron_len == None:
97 if train_with_intronlengthinformation:
98 min_intron_len=20
99 max_intron_len=1000
100 else:
101 min_intron_len = 1
102 max_intron_len = 2
103
104 if min_intron_len != None and max_intron_len != None:
105 min_svm_score=-5
106 max_svm_score=5
107
108 h = Plf()
109 d = Plf()
110 a = Plf()
111
112 ####################
113 # Gapfunktion
114 ####################
115 h.limits = logspace(math.log(min_intron_len,10),math.log(max_intron_len,10),30)
116 h.penalties = param[0:30].flatten().tolist()[0]
117 #h.transform = '+1'
118 h.transform = ''
119 h.name = 'h'
120 h.max_len = 100000
121 h.min_len = 4
122 h.id = 1
123 h.use_svm = 0
124 h.next_id = 0
125
126
127 ####################
128 # Donorfunktion
129 ####################
130 d.limits = linspace(min_svm_score,max_svm_score,30)
131 d.penalties = param[30:60].flatten().tolist()[0]
132 #d.transform = '+1'
133 d.transform = ''
134 d.name = 'd'
135 d.max_len = 100
136 d.min_len = -100
137 d.id = 1
138 d.use_svm = 0
139 d.next_id = 0
140
141
142 ####################
143 # Acceptorfunktion
144 ####################
145 a.limits = linspace(min_svm_score,max_svm_score,30)
146 a.penalties = param[60:90].flatten().tolist()[0]
147 #a.transform = '+1'
148 a.transform = ''
149 a.name = 'a'
150 a.max_len = 100
151 a.min_len = -100
152 a.id = 1
153 a.use_svm = 0
154 a.next_id = 0
155
156
157 ####################
158 # Matchmatrix
159 ####################
160 mmatrix = numpy.matlib.mat(param[90:126])
161 mmatrix.reshape(6,6)
162
163 return h,d,a,mmatrix
164
165 if __name__ == '__main__':
166 #min_intron_len=20
167 #max_intron_len=1000
168 #print logspace(math.log(min_intron_len,10),math.log(max_intron_len,10),30)
169
170 min_svm_score=-5
171 max_svm_score=5
172 print linspace(min_svm_score,max_svm_score,30)