-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtest_phylotastic.py
executable file
·110 lines (74 loc) · 2.85 KB
/
test_phylotastic.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
##
import sys
from ete3_webserver import NodeActions, start_server
from ete3 import TreeStyle, TextFace, add_face_to_node, ImgFace, BarChartFace, faces, AttrFace, SeqMotifFace, NodeStyle, NCBITaxa
from spongilla_layout import custom_treestyle, spongilla_predraw, init_layout
#if yoy want to use basic custom layout import basic_layout instead of spongilla_layout:
#from basic_layout import_custom_treestyle
# Custom ETE Tree styles and web actions
##
# Actions to show
def show_action_root(node):
if node.up:
return True
return False
def show_action_highlight(node):
# Any node can be highlighted
return True
def show_action_change_style(node):
return True
def show_action_delete_node(node):
return True
##
# Run actions
def run_action_root(tree, node, taxid):
tree.set_outgroup(node)
return
def toggle_highlight_node(node, prev_highlighted):
if prev_highlighted:
node.img_style['bgcolor'] = 'white'
node.img_style['size'] = 0
node.img_style['hz_line_width'] = 0
else:
node.img_style['bgcolor'] = 'pink'
node.img_style['size'] = 8
node.img_style['hz_line_width'] = 4
node.highlighted = not prev_highlighted
print(node.highlighted)
return
def run_action_highlight(tree, node, taxid):
if not "highlighted" in node.features:
node.add_feature("highlighted", False)
prev_highlighted = node.highlighted
toggle_highlight_node(node, prev_highlighted)
for child in node.traverse():
if not "highlighted" in child.features:
child.add_feature("highlighted", False)
toggle_highlight_node(child, prev_highlighted)
return
def run_action_change_style(tree, node, taxid):
if tree.tree_style == ts:
tree.tree_style = ts2
else:
tree.tree_style = ts
def run_action_delete_node(tree, node, taxid):
parent = node.up
remove_node = node.detach()
if len(parent.get_children()) == 0:
run_action_delete_node(tree, parent, taxid)
return
# Server configuration
NCBIPATH = "/home/django/taxa.sqlite"
TABLEPATH = "/home/django/spongilla_data/spongilla_protein_renamining_table.txt"
init_layout(NCBIPATH, TABLEPATH)
#custom_treestyle, is a function in spongilla_layout.py, custom_treesyle run custom_layout function
#which is also in spongilla_layout.py
ts = custom_treestyle()
ts2 = TreeStyle()
ts_coll = TreeStyle()
actions = NodeActions()
actions.add_action('Root here', show_action_root, run_action_root)
actions.add_action('Highlight', show_action_highlight, run_action_highlight)
actions.add_action('Change style', show_action_change_style, run_action_change_style)
actions.add_action('Delete node', show_action_delete_node, run_action_delete_node)
start_server(node_actions=actions, tree_style=ts, predraw_fn=spongilla_predraw)