-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathvisualize.py
62 lines (59 loc) · 2.02 KB
/
visualize.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
#!/usr/bin/env python
"""
Created on Wed Jul 6 16:14:23 2016
@author: huyn
@purpose: visualize professor John output
"""
from ete3 import *
from findParent_local import *
def parse(myfile):
data = open(myfile,'r')
data = data.readlines()
tree = data[0]
tree = Tree(tree,format = 1)
dic = {}
for index in range(1,len(data)):
array = data[index].split(':')
name = array[0]
info = array[1].split('(')
if len(info) >1:
gene_block = info[0].split(' ')[1]
distances = info[1].split(')')[0]
distances = distances.split(',')
deletion = int(distances[0])
duplication = int(distances[1])
split = int(distances[2])
distances = [deletion,duplication,split]
dic[name] ={}
dic[name]['gene_block']=gene_block
dic[name]['distances'] = distances
else:
dic[name]= {}
dic[name]['gene_block']=''
dic[name]['distances']=[]
for node in tree.traverse('postorder'):
name = node.name
node.add_features(gene_block = dic[name]['gene_block'],distances=dic[name]['distances'])
return dic,tree
def display(tree):
for node in tree.traverse('postorder'):
string = node.name +': '+node.gene_block
gene_block = TextFace(string)
distances = TextFace(node.distances)
if node.is_leaf():
node.add_face(gene_block, column=0, position = "branch-right")
else:
node.add_face(gene_block, column=0, position = "branch-top")
node.add_face(distances, column=0, position = "branch-top")
return tree
dic,tree = parse('sample_out.txt')
# print dic
tree = display(tree)
tree_style = TreeStyle()
tree_style.show_leaf_name = False
tree_style.min_leaf_separation = 5
tree_style.extra_branch_line_type = 0
tree_style.draw_guiding_lines=True
tree_style.guiding_lines_type = 1
tree.render('output_prof.pdf',dpi=1000,tree_style=tree_style)
tree.show(tree_style=tree_style)