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