forked from eukref/pipeline
-
Notifications
You must be signed in to change notification settings - Fork 0
/
eukref_dbparser02.py
69 lines (53 loc) · 1.58 KB
/
eukref_dbparser02.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
'''
usage
python annotateclusters.py thecamoebids.clustered.fasttree.txt thecamoebids.clusters.uc expandedclusters.txt
'''
import sys
infile = open(sys.argv[1], "r") # tab delimited outfile of annotatetree.py
lines = infile.readlines()
infile.close()
clusterfile = open(sys.argv[2], "r") # *.uc file
clusterlines = clusterfile.readlines()
clusterfile.close()
outfile = open('temp_expandedcluster.txt', "w") # tab delimited outfile
for line in clusterlines:
cluster = line.split("\t")[9]
cluster = cluster.strip()
fullname = line.split("\t")[8]
if fullname.count("noginumber") > 0:
accession = line.split('|')[-1]
accession = accession.split()[0]
elif fullname.startswith("gi+"):
accession = fullname.split('+')[3]
elif fullname.startswith("gi|"):
accession = fullname.split("|")[3]
else:
pass
accession.strip()
if cluster == "*":
for i in lines:
if i.startswith(accession):
outfile.write(i)
else:
pass
else:
for i in lines:
if cluster.count(i.split()[0]) > 0:
annotation = i.split("\t")[1]
outfile.write(accession + "\t" + annotation)
else:
pass
outfile.close()
# remove duplicated lines
infile = open('temp_expandedcluster.txt')
lines = infile.readlines()
infile.close()
list_lines = []
for line in lines:
list_lines.append(line.strip())
new_lines = set(list_lines)
out = open(sys.argv[3], 'w')
for i in new_lines:
out.write('%s\n' % (i))
out.close()
sys.exit()