-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakeTreeList.py
70 lines (54 loc) · 2.06 KB
/
MakeTreeList.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
70
#!/usr/bin/env python
import Header
from Header import *
##-----------------------------------------------------
''' this function is useful to parse various options for input data processing '''
##-----------------------------------------------------
def parse_options():
parser = OptionParser()
parser.add_option("-D", "--INPDIR", \
type="string", \
action="store", \
dest="INP_DIR", \
default="", \
help="path of the input directory containing all species genome in subdirectory")
parser.add_option("-C", "--CASES", \
type="string", \
action="store", \
dest="CASES", \
default="", \
help="Case numbers to be considered for analysis")
opts, args = parser.parse_args()
return opts, args
#-------------------------------------------------------------------------------------------------
# This program make the treelist by merging the trees generated by different cases
#-------------------------------------------------------------------------------------------------
def TreeListing(INP_DIR, CASES):
rootDir = INP_DIR
#print 'Making Treelist: ', INP_DIR
#CASES = opts.CASES.split('|')
write_flag = 0
for dirName, subdirList, fileList in os.walk(rootDir):
if 'tree_1.tre' in fileList:
treelist = dendropy.TreeList()
for case in CASES:
# tree = dendropy.Tree()
fname = 'tree_' + case + '.tre'
if fname in fileList:
filename = dirName + '/' + fname
# tree.read_from_path(filename, 'newick')
tree = Tree.get(path=filename, schema='newick', preserve_underscores=True)
treelist.append(tree)
write_flag = 1
#if fname == 'tree_1.tre' or fname == 'tree_2.tre':
#filename = dirName + '/' + fname
#tree.read_from_path(filename, 'newick')
#treelist.append(tree)
#write_flag = 1
if write_flag == 1:
treelist_file = dirName+'/TreeList.newick'
treelist.write(path=treelist_file,schema='newick',unquoted_underscores=True)
write_flag = 0
#---------------------------------------------------------------------------------------
if __name__=='__main__':
main()