2 # -*- coding: utf-8 -*-
5 from numpy
.matlib
import zeros
8 # 3 * 30 supporting points: x_1 ... x_30 => 3 * 30 parameters (1 .. 90): y_1 ... y_30
9 # piecewise linear function:
10 # take score from SVM vektor (don_supp: case 1, acc_supp: case 2) and compute length of intron: case 3
11 # these are our values x
16 # f(x) = | y_i * ----------- + y_i+1 * ----------- if x_i <= x <= x_i+1
17 # | x_i+1 - x_i x_i+1 - x_i
21 # y_i and y_i+1 parameters, so the fractions are saved in the weight vectors!
23 def calculateWeights(plf
, scores
):
24 currentWeight
= zeros((30,1))
26 for k
in range(len(scores
)):
28 Lower
= len([elem
for elem
in plf
.limits
if elem
<= value
])
33 elif Lower
== len(plf
.limits
):
34 currentWeight
[-1] += 1
36 # because we count from 0 in python
38 Upper
= Lower
+1 ; # x-werte bleiben fest
39 #print value,Lower,Upper
40 weightup
= 1.0*(value
- plf
.limits
[Lower
]) / (plf
.limits
[Upper
] - plf
.limits
[Lower
])
41 weightlow
= 1.0*(plf
.limits
[Upper
] - value
) / (plf
.limits
[Upper
] - plf
.limits
[Lower
])
42 currentWeight
[Upper
] = currentWeight
[Upper
] + weightup
43 currentWeight
[Lower
] = currentWeight
[Lower
] + weightlow
45 #print plf.limits[Lower],plf.limits[Upper]
46 #print weightup,weightlow,currentWeight[Upper],currentWeight[Lower]
50 def computeSpliceWeights(d
, a
, h
, SpliceAlign
, don_supp
, acc_supp
):
51 ####################################################################################
52 # 1. Donor: In don_supp stehen Werte der SVM., in SpliceAlign die Einsen
53 ####################################################################################
55 # Picke die Positionen raus, an denen eine Donorstelle ist
56 DonorScores
= [elem
for pos
,elem
in enumerate(don_supp
) if SpliceAlign
[pos
] == 1]
57 assert not ( -inf
in DonorScores
)
60 weightDon
= calculateWeights(d
,DonorScores
)
62 ####################################################################################
63 # 2. Acceptor: In acc_supp stehen Werte der SVM., in SpliceAlign die Einsen
64 ####################################################################################
66 #Den Vektor Acceptorstellen durchgehen und die Gewichtsvektoren belasten:
67 AcceptorScores
= [elem
for pos
,elem
in enumerate(acc_supp
) if pos
> 0 and SpliceAlign
[pos
-1] == 2]
68 assert not ( -inf
in AcceptorScores
)
71 weightAcc
= calculateWeights(a
,AcceptorScores
)
73 ####################################################################################
74 # 3. Intron length: SpliceAlign: Gaps zaehlen und auf Gapgewichte addieren
75 ####################################################################################
79 for pos
,elem
in enumerate(SpliceAlign
):
81 intron_starts
.append(pos
)
84 intron_ends
.append(pos
)
86 assert len(intron_starts
) == len(intron_ends
)
88 for i
in range(len(intron_starts
)):
89 assert intron_starts
[i
] < intron_ends
[i
]
91 values
= [0.0]*len(intron_starts
)
92 for pos
in range(len(intron_starts
)):
93 values
[pos
] = intron_ends
[pos
] - intron_starts
[pos
] + 1
95 weightIntron
= calculateWeights(h
,values
)
97 return weightDon
, weightAcc
, weightIntron