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 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
|
from __future__ import absolute_import
import unittest
import random
import sys
import os
ETEPATH = os.path.abspath(os.path.split(os.path.realpath(__file__))[0]+'/../')
sys.path.insert(0, ETEPATH)
from ... import Tree, TreeStyle, NodeStyle, PhyloTree, faces, random_color
from ...treeview.faces import *
from ...treeview.main import _NODE_TYPE_CHECKER, FACE_POSITIONS
from . import (face_grid, bubble_map, item_faces, node_style, node_background,
face_positions, face_rotation, seq_motif_faces,
barchart_and_piechart_faces, phylotree_visualization)
CONT = 0
class Test_Coretype_Treeview(unittest.TestCase):
""" Tests tree basics. """
def test_renderer(self):
main_tree = Tree()
main_tree.dist = 0
t, ts = face_grid.get_example_tree()
t_grid = TreeFace(t, ts)
n = main_tree.add_child()
n.add_face(t_grid, 0, "aligned")
t, ts = bubble_map.get_example_tree()
t_bubble = TreeFace(t, ts)
n = main_tree.add_child()
n.add_face(t_bubble, 0, "aligned")
t, ts = item_faces.get_example_tree()
t_items = TreeFace(t, ts)
n = main_tree.add_child()
n.add_face(t_items, 0, "aligned")
t, ts = node_style.get_example_tree()
t_nodest = TreeFace(t, ts)
n = main_tree.add_child()
n.add_face(t_nodest, 0, "aligned")
t, ts = node_background.get_example_tree()
t_bg = TreeFace(t, ts)
n = main_tree.add_child()
n.add_face(t_bg, 0, "aligned")
t, ts = face_positions.get_example_tree()
t_fpos = TreeFace(t, ts)
n = main_tree.add_child()
n.add_face(t_fpos, 0, "aligned")
t, ts = phylotree_visualization.get_example_tree()
t_phylo = TreeFace(t, ts)
n = main_tree.add_child()
n.add_face(t_phylo, 0, "aligned")
t, ts = face_rotation.get_example_tree()
temp_facet = TreeFace(t, ts)
n = main_tree.add_child()
n.add_face(temp_facet, 0, "aligned")
t, ts = seq_motif_faces.get_example_tree()
temp_facet = TreeFace(t, ts)
n = main_tree.add_child()
n.add_face(temp_facet, 0, "aligned")
t, ts = barchart_and_piechart_faces.get_example_tree()
temp_facet = TreeFace(t, ts)
n = main_tree.add_child()
n.add_face(temp_facet, 0, "aligned")
#Test orphan nodes and trees with 0 branch length
t, ts = Tree(), TreeStyle()
t.populate(5)
for n in t.traverse():
n.dist = 0
temp_tface = TreeFace(t, ts)
n = main_tree.add_child()
n.add_face(temp_tface, 0, "aligned")
ts.optimal_scale_level = "full"
temp_tface = TreeFace(t, ts)
n = main_tree.add_child()
n.add_face(temp_tface, 0, "aligned")
ts = TreeStyle()
t.populate(5)
ts.mode = "c"
temp_tface = TreeFace(t, ts)
n = main_tree.add_child()
n.add_face(temp_tface, 0, "aligned")
ts.optimal_scale_level = "full"
temp_tface = TreeFace(t, ts)
n = main_tree.add_child()
n.add_face(temp_tface, 0, "aligned")
t, ts = Tree(), TreeStyle()
temp_tface = TreeFace(Tree('node;'), ts)
n = main_tree.add_child()
n.add_face(temp_tface, 0, "aligned")
t, ts = Tree(), TreeStyle()
ts.mode = "c"
temp_tface = TreeFace(Tree('node;'), ts)
n = main_tree.add_child()
n.add_face(temp_tface, 0, "aligned")
t, ts = Tree(), TreeStyle()
ts.mode = "c"
temp_tface = TreeFace(Tree(), ts)
n = main_tree.add_child()
n.add_face(temp_tface, 0, "aligned")
t, ts = Tree(), TreeStyle()
temp_tface = TreeFace(Tree(), ts)
n = main_tree.add_child()
n.add_face(temp_tface, 0, "aligned")
# TEST TIGHT TEST WRAPPING
chars = ["." "p", "j", "jJ"]
def layout(node):
global CONT
if CONT >= len(chars):
CONT = 0
if node.is_leaf():
node.img_style["size"] = 0
F2= AttrFace("name", tight_text=True)
F= TextFace(chars[CONT], tight_text=True)
F.inner_border.width = 0
F2.inner_border.width = 0
#faces.add_face_to_node(F ,node, 0, position="branch-right")
faces.add_face_to_node(F2 ,node, 1, position="branch-right")
CONT += 1
t = Tree()
t.populate(20, random_branches=True)
ts = TreeStyle()
ts.layout_fn = layout
ts.mode = "c"
ts.show_leaf_name = False
temp_tface = TreeFace(t, ts)
n = main_tree.add_child()
n.add_face(temp_tface, 0, "aligned")
# MAIN TREE
ms = TreeStyle()
ms.mode = "r"
ms.show_leaf_name = False
main_tree.render('test.png', tree_style=ms)
main_tree.render('test.svg', tree_style=ms)
main_tree.render('test.pdf', tree_style=ms)
if __name__ == '__main__':
unittest.main()
|