-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgenerate_clade-defs.py
More file actions
42 lines (30 loc) · 872 Bytes
/
generate_clade-defs.py
File metadata and controls
42 lines (30 loc) · 872 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
35
36
37
38
39
40
41
42
# generate_clade-defs.py
# Author: Juse
import sys
import os
header = "Clade Name\tClade Definition\tSection\tLetter\tComponents\tShow\tComments\n"
annofile = open(sys.argv[1], 'r')
outpfile = open(sys.argv[2], 'w')
group_spe = {}
all_spe = []
for line in annofile:
spe = line.split()[0]
if spe not in all_spe:
all_spe.append(spe)
group = line.split()[1]
if group not in group_spe:
group_spe[group] = [spe]
else:
group_spe[group].append(spe)
content = ''
for group, spes in group_spe.items():
if len(spes) == 1:
content += f'{group}\t{spes[0]}\tNone\t\t0\t\t\n'
else:
definition = '+'.join(spes)
content += f'{group}\t{definition}\tNone\t\t1\t\t\n'
species = '+'.join(all_spe)
content += f'All\t{species}\tNone\t\t0\t\t\n'
outpfile.write(header)
outpfile.write(content)
print('Done!')