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