コード例 #1
0
 def test_addChildren(self):
     """RangeNode add_children should add specified # children to list"""
     t = RangeNode()
     t2 = RangeNode(Parent=t)
     t.addChildren(5)
     self.assertEqual(len(t.Children), 6)
     assert t.Children[0] is t2
     for c in t.Children:
         assert c.Parent is t
コード例 #2
0
 def test_init(self):
     """Make sure keyword arguments are being passed to baseclass"""
     node = RangeNode(LeafRange=1, Id=2, Name='foo', Length=42)
     self.assertEqual(node.LeafRange, 1)
     self.assertEqual(node.Id, 2)
     self.assertEqual(node.Name, 'foo')
     self.assertEqual(node.Length, 42)
コード例 #3
0
    def test_str(self):
        """RangeNode should round-trip Newick string corrrectly."""

        r = RangeNode()
        self.assertEqual(str(r), '()')

        #should work for tree with branch lengths set
        t = DndParser(self.sample_tree_string, RangeNode)
        expected = self.sample_tree_string.replace('\n', '')
        expected = expected.replace(' ', '')
        self.assertEqual(str(t), expected)
        #self.assertEqual(t.getNewick(with_distances=True), expected)
        #should also work for tree w/o branch lengths
        t2 = DndParser(self.sample_string_2, RangeNode)
        self.assertEqual(str(t2), self.sample_string_2)
コード例 #4
0
def make_tree_arb_safe(t):
    """Gives a second child to all single descendent nodes"""
    for n in t.nontips(include_self=True):
        if len(n.Children) == 1:
            n.append(RangeNode(Name="X",Length=0.0))