-
Notifications
You must be signed in to change notification settings - Fork 5
/
add-bl.py
executable file
·37 lines (33 loc) · 937 Bytes
/
add-bl.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
#!/usr/bin/env python
'''
Created on Jun 3, 2011
@author: smirarab
'''
import dendropy
import sys
import os
import copy
import os.path
if __name__ == '__main__':
if len(sys.argv) < 3:
print("USAGE: [postfix|-|--] treefile")
sys.exit(1)
stdout = False
if sys.argv[1] == "-":
resultsFile = sys.stdout
stdout = True
elif sys.argv[1] == "--":
postfix = "blen"
else:
postfix = sys.argv[1]
c={}
for treeName in sys.argv[2:]:
if not stdout:
resultsFile=open("%s.%s" % (treeName, postfix),'w')
trees = dendropy.TreeList.get_from_path(treeName, 'newick')
for tree in trees:
for e in tree.postorder_edge_iter():
if not e.length:
e.length = 1
sys.stderr.write("writing results to " + resultsFile.name + "\n")
trees.write(file=resultsFile,schema='newick')