+ modifications and bugfixes
[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 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
53 if min_intron_len != None and max_intron_len != None:
54 min_svm_score=-5
55 max_svm_score=5
56
57 h = Plf()
58 d = Plf()
59 a = Plf()
60 qualityPlifs = [None]*Configuration.numQualPlifs
61
62 donSP = Configuration.numDonSuppPoints
63 accSP = Configuration.numAccSuppPoints
64 lengthSP = Configuration.numLengthSuppPoints
65 mmatrixSP = Configuration.sizeMMatrix
66 totalQualSP = Configuration.totalQualSuppPoints
67
68 ####################
69 # Gapfunktion
70 ####################
71 h.limits = logspace(math.log(min_intron_len,10),math.log(max_intron_len,10),30)
72 h.penalties = param[0:lengthSP].flatten().tolist()[0]
73 #h.transform = '+1'
74 h.transform = ''
75 h.name = 'h'
76 h.max_len = 100000
77 h.min_len = 4
78 h.id = 1
79 h.use_svm = 0
80 h.next_id = 0
81
82
83 ####################
84 # Donorfunktion
85 ####################
86 d.limits = linspace(min_svm_score,max_svm_score,30)
87 d.penalties = param[lengthSP:lengthSP+donSP].flatten().tolist()[0]
88 #d.transform = '+1'
89 d.transform = ''
90 d.name = 'd'
91 d.max_len = 100
92 d.min_len = -100
93 d.id = 1
94 d.use_svm = 0
95 d.next_id = 0
96
97
98 ####################
99 # Acceptorfunktion
100 ####################
101 a.limits = linspace(min_svm_score,max_svm_score,30)
102 a.penalties = param[lengthSP+donSP:lengthSP+donSP+accSP].flatten().tolist()[0]
103 #a.transform = '+1'
104 a.transform = ''
105 a.name = 'a'
106 a.max_len = 100
107 a.min_len = -100
108 a.id = 1
109 a.use_svm = 0
110 a.next_id = 0
111
112 ####################
113 # Matchmatrix
114 ####################
115 mmatrix = numpy.matlib.mat(param[lengthSP+donSP+accSP:lengthSP+donSP+accSP+mmatrixSP])
116 mmatrix.reshape(6,6)
117
118 ####################
119 # Quality Plifs
120 ####################
121 for idx in range(Configuration.numQualPlifs):
122 currentPlif = Plf()
123 currentPlif.limits = linspace(min_svm_score,max_svm_score,Configuration.numQualSuppPoints)
124 begin = lengthSP+donSP+accSP+mmatrixSP+(idx*Configuration.numQualSuppPoints)
125 end = lengthSP+donSP+accSP+mmatrixSP+((idx+1)*Configuration.numQualSuppPoints)
126 currentPlif.penalties = param[begin:end].flatten().tolist()[0]
127 currentPlif.transform = ''
128 currentPlif.name = 'q'
129 currentPlif.max_len = 100
130 currentPlif.min_len = -100
131
132 qualityPlifs[idx] = currentPlif
133
134 return h,d,a,mmatrix,qualityPlifs
135
136 if __name__ == '__main__':
137 min_svm_score=-5
138 max_svm_score=5
139 print linspace(min_svm_score,max_svm_score,30)