Back to index

python-biopython  1.60
Public Member Functions
test_Phylo.TreeTests Class Reference

List of all members.

Public Member Functions

def test_root_with_outgroup
def test_root_at_midpoint
def test_str

Detailed Description

Tests for methods on BaseTree.Tree objects.

Definition at line 86 of file test_Phylo.py.


Member Function Documentation

Tree.root_at_midpoint: reroot at the tree's midpoint.

Definition at line 123 of file test_Phylo.py.

00123 
00124     def test_root_at_midpoint(self):
00125         """Tree.root_at_midpoint: reroot at the tree's midpoint."""
00126         for treefname, fmt in [(EX_APAF, 'phyloxml'),
00127                                (EX_BCL2, 'phyloxml'),
00128                                (EX_NEWICK, 'newick'),
00129                               ]:
00130             tree = Phylo.read(treefname, fmt)
00131             orig_tree_len = tree.total_branch_length()
00132             # Total branch length does not change
00133             tree.root_at_midpoint()
00134             self.assertAlmostEqual(orig_tree_len, tree.total_branch_length())
00135             # Root is bifurcating
00136             self.assertEqual(len(tree.root.clades), 2)
00137             # Deepest tips under each child of the root are equally deep
00138             deep_dist_0 = max(tree.clade[0].depths().itervalues())
00139             deep_dist_1 = max(tree.clade[1].depths().itervalues())
00140             self.assertAlmostEqual(deep_dist_0, deep_dist_1)

Tree.root_with_outgroup: reroot at a given clade.

Definition at line 88 of file test_Phylo.py.

00088 
00089     def test_root_with_outgroup(self):
00090         """Tree.root_with_outgroup: reroot at a given clade."""
00091         # On a large realistic tree, at a deep internal node
00092         tree = Phylo.read(EX_APAF, 'phyloxml')
00093         orig_num_tips = len(tree.get_terminals())
00094         orig_tree_len = tree.total_branch_length()
00095         tree.root_with_outgroup('19_NEMVE', '20_NEMVE')
00096         self.assertEqual(orig_num_tips, len(tree.get_terminals()))
00097         self.assertAlmostEqual(orig_tree_len, tree.total_branch_length())
00098         # Now, at an external node
00099         tree.root_with_outgroup('1_BRAFL')
00100         self.assertEqual(orig_num_tips, len(tree.get_terminals()))
00101         self.assertAlmostEqual(orig_tree_len, tree.total_branch_length())
00102         # Specifying outgroup branch length mustn't change the total tree size
00103         tree.root_with_outgroup('2_BRAFL', outgroup_branch_length=0.5)
00104         self.assertEqual(orig_num_tips, len(tree.get_terminals()))
00105         self.assertAlmostEqual(orig_tree_len, tree.total_branch_length())
00106         tree.root_with_outgroup('36_BRAFL', '37_BRAFL',
00107                 outgroup_branch_length=0.5)
00108         self.assertEqual(orig_num_tips, len(tree.get_terminals()))
00109         self.assertAlmostEqual(orig_tree_len, tree.total_branch_length())
00110         # On small contrived trees, testing edge cases
00111         for small_nwk in (
00112                 '(A,B,(C,D));',
00113                 '((E,F),((G,H)),(I,J));',
00114                 '((Q,R),(S,T),(U,V));',
00115                 '(X,Y);',
00116                 ):
00117             tree = Phylo.read(StringIO(small_nwk), 'newick')
00118             orig_tree_len = tree.total_branch_length()
00119             for node in list(tree.find_clades()):
00120                 tree.root_with_outgroup(node)
00121                 self.assertAlmostEqual(orig_tree_len,
00122                                        tree.total_branch_length())

Tree.__str__: pretty-print to a string.

NB: The exact line counts are liable to change if the object
constructors change.

Definition at line 142 of file test_Phylo.py.

00142 
00143     def test_str(self):
00144         """Tree.__str__: pretty-print to a string.
00145 
00146         NB: The exact line counts are liable to change if the object
00147         constructors change.
00148         """
00149         for source, count in zip((EX_APAF, EX_BCL2), (386, 747)):
00150             tree = Phylo.read(source, 'phyloxml')
00151             output = str(tree)
00152             self.assertEqual(len(output.splitlines()), count)
00153 


The documentation for this class was generated from the following file: