-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathannotate_blast_part2.py
More file actions
35 lines (30 loc) · 837 Bytes
/
Copy pathannotate_blast_part2.py
File metadata and controls
35 lines (30 loc) · 837 Bytes
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
#usage python score.blast.py <sorted.annotated.blast.output>
# 0 1
import sys
filein = open(sys.argv[1], 'r')
out1 = sys.argv[1] + '.richness'
fileout = open(out1, 'w')
family_dict = {}
gi_tracker = []
family_tracker = []
for line in filein:
# print line
line = line.lstrip(" ")
line = line.rstrip("\n ")
line = line.split('\t')
# print line
gi = line[1]
family = line[3]
if family not in family_tracker:
gi_tracker = []
gi_tracker.append(gi)
family_tracker.append(family)
else:
gi_tracker.append(gi)
# print family, len(gi_tracker)
family_dict[family] = gi_tracker
for key, value in family_dict.iteritems():
# print sys.argv[1], key, len(set(value))
fileout.write("%s\t%s\t%d\n" %(sys.argv[1], key, len(set(value))))
fileout.close()
filein.close()