本文整理汇总了Python中dendropy.Tree.deroot方法的典型用法代码示例。如果您正苦于以下问题:Python Tree.deroot方法的具体用法?Python Tree.deroot怎么用?Python Tree.deroot使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dendropy.Tree
的用法示例。
在下文中一共展示了Tree.deroot方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_dendropy_tree_from_break_tree
# 需要导入模块: from dendropy import Tree [as 别名]
# 或者: from dendropy.Tree import deroot [as 别名]
def get_dendropy_tree_from_break_tree(self, break_tree):
nodes = self._extract_break_tree_leaves(break_tree)
sorted_break_tree_leaves_sets, max_leaves_set_size = self._sort_break_tree_leaves_sets(break_tree)
for leave_set_size in range(max_leaves_set_size):
if leave_set_size not in sorted_break_tree_leaves_sets:
continue
for leave_set in sorted_break_tree_leaves_sets[leave_set_size]:
one_step_parents = []
for leaf in leave_set:
node = self._find_node_with_same_taxon(nodes, leaf)
oldest_parent = self._get_oldest_parent(node)
if oldest_parent not in one_step_parents:
one_step_parents.append(oldest_parent)
new_oldest_parent = Node()
if len(one_step_parents) > 1:
for parent in one_step_parents:
parent.parent_node = new_oldest_parent
oldest_parents = []
for node in nodes:
oldest_parent = self._get_oldest_parent(node)
if oldest_parent not in oldest_parents:
oldest_parents.append(oldest_parent)
if len(oldest_parents) > 1:
seed = Node()
for oldest_parent in oldest_parents:
oldest_parent.parent_node = seed
elif len(oldest_parents) == 1:
seed = oldest_parents[0]
else:
seed = Node()
tree = Tree(seed_node=seed)
tree.deroot()
return tree