-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcolor_tree.py
More file actions
57 lines (52 loc) · 1.4 KB
/
color_tree.py
File metadata and controls
57 lines (52 loc) · 1.4 KB
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
import os
import sys
import glob
def process_files(treefile, outfile):
infile = open(treefile)
line = infile.read()
infile.close()
try:
crap = line.split('TAXLABELS')[1]
out = open(outfile, 'w')
startshit = line.split('TAXLABELS')[0]
out.write(startshit)
out.write('TAXLABELS\n')
taxashit = line.split('TAXLABELS')[1]
taxa = taxashit.split(';\nEND;')[0]
endfile = taxashit.split(';\nEND;')[1]
for taxon in taxa.split('\n'):
if taxon.strip() in to_color:
out.write('\t%s[&!color=#d92124]\n' % (taxon))
else:
out.write('\t%s\n' % (taxon))
out.write(';\nEND;')
out.write(endfile)
out.close()
except IndexError:
crap = line.split('taxlabels')[1]
out = open(outfile, 'w')
startshit = line.split('taxlabels')[0]
out.write(startshit)
out.write('taxlabels\n')
taxashit = line.split('taxlabels')[1]
taxa = taxashit.split(';\nend;')[0]
endfile = taxashit.split(';\nend;')[1]
for taxon in taxa.split('\n'):
if taxon.strip() in to_color:
out.write('\t%s[&!color=#d92124]\n' % (taxon))
else:
out.write('\t%s\n' % (taxon))
out.write(';\nend;')
out.write(endfile)
out.close()
files = [fname for fname in glob.glob('*.nex')]
infile = open('GoodApiHomologs.list')
lines = infile.readlines()
infile.close()
to_color = []
for i in lines:
to_color.append(i.strip())
print(to_color)
for fname in files:
print(fname)
process_files(fname, '%s_colored.tre' % (fname))