2 # -*- coding: utf-8 -*-
5 from numpy
.matlib
import zeros
7 def calculateWeights(plf
, scores
):
9 3 * 30 supporting points: x_1 ... x_30
10 => 3 * 30 parameters (1 .. 90): y_1 ... y_30
11 piecewise linear function:
13 take score from SVM vektor (don_supp: case 1, acc_supp: case 2) and compute length of intron: case 3
14 these are our values x
19 f(x) = | y_i * ----------- + y_i+1 * ----------- if x_i <= x <= x_i+1
20 | x_i+1 - x_i x_i+1 - x_i
24 y_i and y_i+1 parameters, so the fractions are saved in the weight vectors!
27 currentWeight
= zeros((30,1))
29 for k
in range(len(scores
)):
33 Lower
= len([elem
for elem
in plf
.limits
if elem
<= value
])
34 Upper
= Lower
+1 ; # x-werte bleiben fest
37 currentWeight
[0] = currentWeight
[0] + 1;
38 elif Lower
== len(plf
.limits
):
39 currentWeight
[-1] = currentWeight
[-1] + 1;
41 weightup
= (value
- plf
.limits
[Lower
]) / (plf
.limits
[Upper
] - plf
.limits
[Lower
]) ;
42 weightlow
= (plf
.limits
[Upper
] - value
) / (plf
.limits
[Upper
] - plf
.limits
[Lower
]) ;
43 currentWeight
[Upper
] = currentWeight
[Upper
] + weightup
;
44 currentWeight
[Lower
] = currentWeight
[Lower
] + weightlow
;
49 def computeSpliceWeights(d
, a
, h
, SpliceAlign
, don_supp
, acc_supp
):
50 #assert(isempty(d.transform))
51 #assert(isempty(a.transform))
52 #assert(isempty(h.transform))
54 ####################################################################################
55 # 1. Donor: In don_supp stehen Werte der SVM., in SpliceAlign die Einsen
56 ####################################################################################
58 # Picke die Positionen raus, an denen eine Donorstelle ist
59 #DonorScores = don_supp(find(SpliceAlign==1)) ;
60 #assert(all(DonorScores~=-Inf)) ;
62 DonorScores
= [elem
for pos
,elem
in enumerate(don_supp
) if SpliceAlign
[pos
] == 1]
63 assert not ( -inf
in DonorScores
)
65 weightDon
= calculateWeights(d
,DonorScores
)
67 ####################################################################################
68 # 2. Acceptor: In acc_supp stehen Werte der SVM., in SpliceAlign die Einsen
69 ####################################################################################
71 #AcceptorScores = acc_supp(find(SpliceAlign == 2)+1) ;
72 #assert(all(AcceptorScores~=-Inf)) ;
74 #Den Vektor Acceptorstellen durchgehen und die Gewichtsvektoren belasten:
75 AcceptorScores
= [elem
for pos
,elem
in enumerate(acc_supp
) if SpliceAlign
[pos
] == 2]
76 #assert not ( -inf in AcceptorScores )
78 weightAcc
= calculateWeights(a
,AcceptorScores
)
80 ####################################################################################
81 # 3. Intron length: SpliceAlign: Gaps zaehlen und auf Gapgewichte addieren
82 ####################################################################################
84 #intron_starts = find(SpliceAlign==1) ;
85 #intron_ends = find(SpliceAlign==2) ;
87 #%assert: introns do not overlap
88 #assert(length(intron_starts) == length(intron_ends)) ;
89 #assert(all(intron_starts < intron_ends)) ;
90 #assert(all(intron_ends(1:end-1) < intron_starts(2:end))) ;
92 #weightIntron = calculateWeights(h,AcceptorScores)
93 weightIntron
= [1,2,3]
95 return weightDon
, weightAcc
, weightIntron