-
Notifications
You must be signed in to change notification settings - Fork 42
/
annoGroupUseEnsembl.py
executable file
·164 lines (161 loc) · 7 KB
/
annoGroupUseEnsembl.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#from __future__ import division, with_statement
'''
Copyright 2010, 陈同 (chentong_biology@163.com).
Please see the license file for legal information.
===========================================================
'''
__author__ = 'chentong & ct586[9]'
__author_email__ = 'chentong_biology@163.com'
#=========================================================
import sys
read=1
out=1
def main():
print >>sys.stderr, "Print the result to screen"
if len(sys.argv) < 3:
print >>sys.stderr, 'Using python %s groupfile annofile [annofile]' \
% sys.argv[0]
sys.exit(0)
#------------------------------------------------------
global read
global out
annodict={}
'''
annodict={ locus : \n \tdescription or
interprodescription\nCC:\tGoid:\tGoterm\n
MF:\tGoid:\tGoterm\n \tGoid:\tGoterm\nBP:\tGoid:\tGoterm\n\n\n
}
'''
list42 = (0, 3, 5, 1)
dict42 = {3:"CC:", 5:"MF:", 1:"BP:"}
#description0 1bp_id 2bp_name 3cc_id 4cc_name 5mf_id 6mf_name 7interpro 8interpro_description
for file in sys.argv[2:]:
header = 1
locus = ''
annolist = []
for line in open(file):
if header:
header -= 1
else:
locus1, anno = line.split('\t',1)
if locus1 != locus:
if locus:
if read:
print >>sys.stderr, locus
annodict[locus]='\n'
lenannolist = len(annolist)
for i42 in list42:
if not i42:
hasDes = 0
for i in range(lenannolist):
if annolist[i][0]:
annodict[locus] += annolist[i][0]+'\n'
hasDes = 1
break
interprodict = {}
for i in range(lenannolist):
interproid = annolist[i][7]
if interproid:
hasDes = 1
if interprodict.has_key(interproid):
continue
else:
interprodict[interproid] =\
annolist[i][8]
if len(interprodict):
for keyvalue in interprodict.items():
annodict[locus] += ':\t'.join(keyvalue)
#annodict[locus] += ''.join(interprodict.values())
if not hasDes:
annodict[locus] += 'No description\n'
#------------------------------------------------
else:
godict = {}
for i in range(lenannolist):
gokey = annolist[i][i42]
if gokey:
if godict.has_key(gokey):
continue
else:
godict[gokey]= '\t'+gokey+':\t'+annolist[i][i42+1]+'\n'
if len(godict):
annodict[locus] += dict42[i42]+\
''.join(godict.values())
#---else------------------------------------------
#---for--i42 in list42--------------------------------
#-------if--locus-----------------------------------------
annolist = []
locus = locus1
#-----------if--locus1 != locus----------------------------------
annolist.append(anno.split('\t'))
#-----else-----------------------------------------------------------
#deal with the last one
if read:
print >>sys.stderr, locus
annodict[locus]='\n'
lenannolist = len(annolist)
for i42 in list42:
if not i42:
hasDes = 0
for i in range(lenannolist):
if annolist[i][0]:
annodict[locus] += annolist[i][0]+'\n'
hasDes = 1
break
interprodict = {}
for i in range(lenannolist):
interproid = annolist[i][7]
if interproid:
hasDes = 1
if interprodict.has_key(interproid):
continue
else:
interprodict[interproid] =\
annolist[i][8]
if len(interprodict):
for keyvalue in interprodict.items():
annodict[locus] += ':\t'.join(keyvalue)
#annodict[locus] += ''.join(interprodict.values())
if not hasDes:
annodict[locus] += 'No description\n'
#------------------------------------------------
else:
godict = {}
for i in range(lenannolist):
if annolist[i][i42]:
gokey = annolist[i][i42]
if gokey:
if godict.has_key(gokey):
continue
else:
godict[gokey]= '\t'+gokey+':\t'+annolist[i][i42+1]+'\n'
if len(godict):
annodict[locus] += dict42[i42]+\
''.join(godict.values())
#---else------------------------------------------
#---End with the last one-----------------------------
#-------End reading one file----------------------------
if 0:
for key118, value118 in annodict.items():
print key118
print value118
#-----------End reading multiple file--------------------
#--------------------------------------------------------------------------------
for line in open(sys.argv[1]):
print line,
if line[0].isalnum():
locus = line.split('\t',2)[1]
locus = locus.split()[0]
if out:
print >>sys.stderr, "-----------", locus
if annodict.has_key(locus):
print annodict[locus]
else:
print 'No this locusus'
#print >>sys.stderr, 'No this locusus'
#sys.exit(0)
#--------------------------------------------------
if __name__ == '__main__':
main()