+ minor fixes
[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
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.sizeMatchmatrix[0]\
66 *Configuration.sizeMatchmatrix[1]
67 totalQualSP = Configuration.totalQualSuppPoints
68
69 ####################
70 # Gapfunktion
71 ####################
72 h.limits = logspace(math.log(min_intron_len,10),math.log(max_intron_len,10),30)
73 h.penalties = param[0:lengthSP].flatten().tolist()[0]
74 #h.transform = '+1'
75 h.transform = ''
76 h.name = 'h'
77 h.max_len = 100000
78 h.min_len = 4
79 h.id = 1
80 h.use_svm = 0
81 h.next_id = 0
82
83
84 ####################
85 # Donorfunktion
86 ####################
87 d.limits = linspace(min_svm_score,max_svm_score,30)
88 d.penalties = param[lengthSP:lengthSP+donSP].flatten().tolist()[0]
89 #d.transform = '+1'
90 d.transform = ''
91 d.name = 'd'
92 d.max_len = 100
93 d.min_len = -100
94 d.id = 1
95 d.use_svm = 0
96 d.next_id = 0
97
98
99 ####################
100 # Acceptorfunktion
101 ####################
102 a.limits = linspace(min_svm_score,max_svm_score,30)
103 a.penalties = param[lengthSP+donSP:lengthSP+donSP+accSP].flatten().tolist()[0]
104 #a.transform = '+1'
105 a.transform = ''
106 a.name = 'a'
107 a.max_len = 100
108 a.min_len = -100
109 a.id = 1
110 a.use_svm = 0
111 a.next_id = 0
112
113 ####################
114 # Matchmatrix
115 ####################
116 mmatrix = numpy.matlib.mat(param[lengthSP+donSP+accSP:lengthSP+donSP+accSP+mmatrixSP])
117 mmatrix.reshape(Configuration.sizeMatchmatrix[0],Configuration.sizeMatchmatrix[1])
118
119 ####################
120 # Quality Plifs
121 ####################
122 for idx in range(Configuration.numQualPlifs):
123 currentPlif = Plf()
124 currentPlif.limits = linspace(Configuration.min_qual,Configuration.max_qual,Configuration.numQualSuppPoints)
125 begin = lengthSP+donSP+accSP+mmatrixSP+(idx*Configuration.numQualSuppPoints)
126 end = lengthSP+donSP+accSP+mmatrixSP+((idx+1)*Configuration.numQualSuppPoints)
127 currentPlif.penalties = param[begin:end].flatten().tolist()[0]
128 currentPlif.transform = ''
129 currentPlif.name = 'q'
130 currentPlif.max_len = Configuration.max_qual
131 currentPlif.min_len = Configuration.min_qual
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)