+ extended evaluation function to return positionwise deviations
[qpalma.git] / qpalma / 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 import Configuration
9 from Plif import *
10
11 def set_params_pa():
12 h = plf()
13 h.len = int(model.intron_len_bins)
14 h.limits = model.intron_len_limits
15 h.penalties = model.intron_len_penalties
16 h.name = 'h'
17 h.max_len = int(max_intron_len)
18 h.min_len = int(min_intron_len)
19 h.transform = model.intron_len_transform
20
21 d = plf()
22 d.len = int(model.donor_bins)
23 d.limits = model.donor_limits
24 d.penalties = model.donor_penalties
25 d.name = 'd'
26 d.max_len = 100
27 d.min_len = -100
28
29 a = plf()
30 a.len = int(model.acceptor_bins)
31 a.limits = model.acceptor_limits
32 a.penalties = model.acceptor_penalties
33 a.name = 'a'
34 a.max_len = 100
35 a.min_len = -100
36
37 mmatrix = model.substitution_matrix
38
39
40 def set_param_palma(param, train_with_intronlengthinformation,\
41 min_intron_len=None, max_intron_len=None, min_svm_score=None, max_svm_score=None):
42
43 print 'Setting parameters ...'
44
45 #if min_intron_len == None:
46 # if train_with_intronlengthinformation:
47 # min_intron_len=20
48 # max_intron_len=1000
49 # else:
50 # min_intron_len = 1
51 # max_intron_len = 2
52 min_intron_len=4
53 max_intron_len=10000
54
55 #if min_intron_len != None and max_intron_len != None:
56 # min_svm_score=-5
57 # max_svm_score=5
58 min_svm_score=-3
59 max_svm_score=1
60
61 h = Plf()
62 d = Plf()
63 a = Plf()
64 qualityPlifs = [None]*Configuration.numQualPlifs
65
66 donSP = Configuration.numDonSuppPoints
67 accSP = Configuration.numAccSuppPoints
68 lengthSP = Configuration.numLengthSuppPoints
69 mmatrixSP = Configuration.sizeMatchmatrix[0]\
70 *Configuration.sizeMatchmatrix[1]
71 totalQualSP = Configuration.totalQualSuppPoints
72
73 ####################
74 # Gapfunktion
75 ####################
76 h.limits = logspace(math.log(min_intron_len,10),math.log(max_intron_len,10),30)
77 #h.limits = linspace(min_intron_len,max_intron_len,30)
78 h.penalties = param[0:lengthSP].flatten().tolist()[0]
79 #h.transform = '+1'
80 h.transform = ''
81 h.name = 'h'
82 h.max_len = max_intron_len
83 h.min_len = min_intron_len
84 h.id = 1
85 h.use_svm = 0
86 h.next_id = 0
87
88 ####################
89 # Donorfunktion
90 ####################
91 d.limits = linspace(min_svm_score,max_svm_score,30)
92 d.penalties = param[lengthSP:lengthSP+donSP].flatten().tolist()[0]
93 #d.transform = '+1'
94 d.transform = ''
95 d.name = 'd'
96 d.max_len = max_svm_score
97 d.min_len = min_svm_score
98 d.id = 1
99 d.use_svm = 0
100 d.next_id = 0
101
102 ####################
103 # Acceptorfunktion
104 ####################
105 a.limits = linspace(min_svm_score,max_svm_score,30)
106 a.penalties = param[lengthSP+donSP:lengthSP+donSP+accSP].flatten().tolist()[0]
107 #a.transform = '+1'
108 a.transform = ''
109 a.name = 'a'
110 a.max_len = max_svm_score
111 a.min_len = min_svm_score
112 a.id = 1
113 a.use_svm = 0
114 a.next_id = 0
115
116 ####################
117 # Matchmatrix
118 ####################
119 mmatrix = numpy.matlib.mat(param[lengthSP+donSP+accSP:lengthSP+donSP+accSP+mmatrixSP])
120 mmatrix.reshape(Configuration.sizeMatchmatrix[0],Configuration.sizeMatchmatrix[1])
121
122 ####################
123 # Quality Plifs
124 ####################
125 for idx in range(Configuration.numQualPlifs):
126 currentPlif = Plf()
127 currentPlif.limits = linspace(Configuration.min_qual,Configuration.max_qual,Configuration.numQualSuppPoints)
128 begin = lengthSP+donSP+accSP+mmatrixSP+(idx*Configuration.numQualSuppPoints)
129 end = lengthSP+donSP+accSP+mmatrixSP+((idx+1)*Configuration.numQualSuppPoints)
130 currentPlif.penalties = param[begin:end].flatten().tolist()[0]
131 currentPlif.transform = ''
132 currentPlif.name = 'q'
133 currentPlif.max_len = Configuration.max_qual
134 currentPlif.min_len = Configuration.min_qual
135 qualityPlifs[idx] = currentPlif
136
137 return h,d,a,mmatrix,qualityPlifs
138
139 if __name__ == '__main__':
140 min_svm_score=-5
141 max_svm_score=5
142 print linspace(min_svm_score,max_svm_score,30)