コード例 #1
0
 def test_dendro_with_support(self):
     """exercising creating dendrograms with support measure"""
     data = {
         "newick": "(A,(B,C)edge.1,(D,E)edge.0)",
         "edge_attributes": {
             "A": {"support": 1.0, "length": 0.148},
             "B": {"support": 1.0, "length": 0.098},
             "C": {"support": 1.0, "length": 0.134},
             "edge.1": {"support": 0.8, "length": 0.016},
             "D": {"support": 1.0, "length": 0.087},
             "E": {"support": 1.0, "length": 0.048},
             "edge.0": {"support": 0.6, "length": 0.131},
             "root": {"length": None},
         },
         "type": "cogent3.core.tree.PhyloNode",
         "version": "2019.10.17a",
     }
     tree = deserialise_object(data)
     # currently not supported for "circular", "radial"
     for style in ("square", "angular"):
         y_support = Dendrogram(tree, style=style, show_support=True, threshold=0.8)
         n_support = Dendrogram(tree, style=style, show_support=False)
         self.assertEqual(
             len(y_support.figure.layout.annotations)
             - len(n_support.figure.layout.annotations),
             2,
             style,
         )
コード例 #2
0
 def test_tip_font(self):
     """test tip_font settable"""
     tree = make_tree(treestring="(a,b,(c,(d,e)e1)e2)")
     dnd = Dendrogram(tree=tree)
     dnd.tip_font |= dict(size=18)
     self.assertEqual(dnd.tip_font.size, 18)
     dnd.tip_font.size = 10
     self.assertEqual(dnd.tip_font.size, 10)
     dnd.tip_font.color = "red"
     self.assertEqual(dnd.tip_font["color"], "red")
コード例 #3
0
 def test_style_edges(self):
     """test style_edges only accepts edges present in tree"""
     tree = make_tree(treestring="(a,b,(c,(d,e)e1)e2)")
     dnd = Dendrogram(tree=tree)
     dnd.style_edges("a", line=dict(color="magenta"))
     with self.assertRaises(ValueError):
         dnd.style_edges("foo", line=dict(color="magenta"))
コード例 #4
0
 def test_dendro_shape(self):
     """exercising using different values of shape parameter"""
     tree = make_tree(treestring="(a:0.1,b:0.1,(c:0.05,(d:0.01,e:0.02):0.01):0.1)")
     for style in ("square", "angular", "circular", "radial"):
         dnd = Dendrogram(tree, style=style)
         # the figure attribute should be a dict
         fig = dnd.figure
         self.assertIsInstance(fig, UnionDict)
         # should have a layout and a data key
         self.assertTrue("layout" in fig)
         self.assertTrue("data" in fig)
         # data traces should be of type "scatter"
         self.assertEqual({tr.type for tr in fig.data}, {"scatter"})
コード例 #5
0
    def test_square_dendrogram_regression(self):
        tree = make_tree(treestring="(a:0.1,b:0.1,(c:0.05,(d:0.01,e:0.02):0.01):0.1)")
        dendrogram = Dendrogram(tree, style="square", contemporaneous=False)
        func = dendrogram.tree.get_node_matching_name
        actual_vals = [
            (func("root").x, func("root").y),
            (func("a").x, func("a").y),
            (func("b").x, func("b").y),
            (func("c").x, func("c").y),
            (func("d").x, func("d").y),
            (func("e").x, func("e").y),
        ]

        expected_vals = [
            (0, 1.3),
            (0.1, 2.6),
            (0.1, 1.3),
            (0.15, -2.6),
            (0.12, 0),
            (0.13, -1.3),
        ]

        assert_allclose(actual_vals, expected_vals)
コード例 #6
0
 def test_get_edges(self):
     """returns edge names"""
     tree = make_tree(treestring="(a,b,(c,(d,e)e1)e2)")
     dnd = Dendrogram(tree=tree)
     edges = dnd.get_edge_names("d", "c", clade=True, stem=False)
     self.assertEqual(set(edges), set(["c", "d", "e", "e1"]))