-
Notifications
You must be signed in to change notification settings - Fork 0
/
pseudoScore.py
65 lines (52 loc) · 1.43 KB
/
pseudoScore.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import scoreMatrix as s
import amino
from math import copysign
aminoList = amino.getOrderedArray()
aminoPolarity = amino.getPolarity()
aminoHydrop = amino.getHydrop()
scoreMatrix = s.ScoreMatrix()
tol = 0.001 #tolerance for comparing polarity of amino acids
cmpF = lambda x,y: abs(x - y) < tol
#calculate maximum hydrophilic
mxPhil = 0.0
for i in aminoHydrop:
if aminoHydrop[i] < mxPhil:
mxPhil = aminoHydrop[i]
pMxPhil = -mxPhil
if(pMxPhil <0):
raise RuntimeWarning
def calcScore(aa1, aa2, hWeight, pWeight):
return hWeight*calcHydropScore(aa1, aa2) + pWeight*calcPolScore(aa1, aa2)
def calcPolScore(aa1, aa2):
pol1 = aminoPolarity[aa1]
pol2 = aminoPolarity[aa2]
if(cmpF(pol1,0) or cmpF(pol2,0)):
return 0
s1 = copysign(1,pol1)
s2 = copysign(1,pol2)
if(s1 != s2):
return 1
else:
return -1
def calcHydropScore(aa1, aa2):
hy1 = aminoHydrop[aa1]
hy2 = aminoHydrop[aa2]
s1 = copysign(1,hy1)
s2 = copysign(1,hy2)
if(cmpF(hy1,0) or cmpF(hy2,0)):
return 0 #no data is assumed for a score of 0
if(s1 == -1 and s2 == -1):
#mxPhil
avg = (hy1 + hy2)/2
score = abs(avg)/pMxPhil
return score*0.3 + 0.1 #return score between 0.1 and 0.4
else:
return 0
def getScoreMatrix(hWeight, pWeight):
scoreMatrix = s.ScoreMatrix()
for i in xrange(len(aminoList)):
for j in xrange(i,len(aminoList)):
aa1 = aminoList[i]
aa2 = aminoList[j]
scoreMatrix.set(aa1,aa2, calcScore(aa1,aa2, hWeight, pWeight))
return scoreMatrix