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