-
Notifications
You must be signed in to change notification settings - Fork 1
/
netrax_output_to_dendroscope.py
38 lines (34 loc) · 1.12 KB
/
netrax_output_to_dendroscope.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
#!/usr/bin/python
import sys
# Takes a string in Extended NEWICK Format, and drops the reticulation probabilities and support scores, keeping only the branch length.
def convert_newick_to_dendroscope(newick):
new_newick = ""
# drop probs and support scores
seenColon = False
skip = False
for c in newick:
if c == ':':
skip = seenColon
seenColon = True
elif c in [',', '(', ')', ';']:
skip = False
seenColon = False
if not skip and c != '\n':
new_newick += c
# ensure reticulations are names #H0 instead of #0 etc.
new_newick_fixed_names = ""
prev = ''
for c in new_newick:
if prev == '#' and c != 'H':
new_newick_fixed_names += 'H'
new_newick_fixed_names += c
prev = c
return new_newick_fixed_names
if __name__ == "__main__":
if len(sys.argv) != 2:
print("Usage: python3 netrax_output_to_dendroscope.py my_newick.txt")
exit()
with open(sys.argv[1]) as f:
newick = f.read()
f.close()
print(convert_newick_to_dendroscope(newick))