forked from fak/mapChEMBLPfam
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprepRank.py
71 lines (53 loc) · 1.46 KB
/
prepRank.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
66
67
"""
Function: prepRank
--------------------
Prepare the data for the rank plot.
"""
def prepRank():
import parse
from operator import itemgetter
keyIndex = 0
valIndex = 1
header = True
genFreq = parse.parse2col('data/genFreq.tab', header, keyIndex, valIndex)
ligFreq = parse.parse2col('data/domLigs.tab', header, keyIndex, valIndex)
ligRankTups = sorted(ligFreq.items(), key = itemgetter(1), reverse = True)
genRankTups = sorted(genFreq.items(), key = itemgetter(1), reverse = True)
i = 1
tb = 0
ligRanks = {}
for tup in ligRankTups:
dom = tup[0]
if tb > tup[1]:
i += 1
ligRanks[dom] = i
tb = tup[1]
i = 1
tb = 0
genRanks = {}
for tup in genRankTups:
dom = tup[0]
if tb > tup[1]:
i += 1
genRanks[dom] = i
tb = tup[1]
genRankL = []
ligRankL = []
for dom in ligRanks.keys():
genRankL.append(genRanks[dom]+1)
ligRankL.append(ligRanks[dom]+1)
## Pepare the rectangular limits
yr2 = []
for threshold in [8,40,200, 1000]:
for tup in ligRankTups:
if tup[1] < threshold:
#print tup[0], ' has less than %s ligands' %threshold
yr2.append(ligRanks[tup[0]])
break
out = open('data/temp.tab','w')
out.write('domain\tgenFreq\tligFreq\n')
for dom in ligFreq.keys():
out.write('%s\t%s\t%s\n'%(dom, genFreq[dom], ligFreq[dom]))
out.close()
return genRankL, ligRankL, yr2