def sort_tree(self, tree):
def get_labels(node):<EOL><INDENT>labels = []<EOL>for n in node.leaf_nodes():<EOL><INDENT>if n.taxon:<EOL><INDENT>labels.append(n.taxon.label)<EOL><DEDENT><DEDENT>return labels<EOL><DEDENT>internal_nodes = tree.internal_nodes()<EOL>for node in internal_nodes:<EOL><INDENT>node.set_children(<EOL>sorted(<EOL>node.child_nodes(),<EOL>key=lambda n: get_labels(n)))<EOL><DEDENT>return tree<EOL>
sort a tree according to some defined order