本文整理汇总了Python中ete3.Tree.support方法的典型用法代码示例。如果您正苦于以下问题:Python Tree.support方法的具体用法?Python Tree.support怎么用?Python Tree.support使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ete3.Tree
的用法示例。
在下文中一共展示了Tree.support方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_tree_object_in_newick
# 需要导入模块: from ete3 import Tree [as 别名]
# 或者: from ete3.Tree import support [as 别名]
def get_tree_object_in_newick(tree, id_to_sample_dict=None):
"""Take a tree object, and create a newick formatted representation of it"""
new_tree = Tree()
new_tree.dist = 0
new_tree.name = "root"
node_id = 0
node_id_to_node_in_old_tree = {node_id: tree}
node_id_to_node_in_new_tree = {node_id: new_tree}
node_ids_to_visit_in_old_tree = [node_id]
while node_ids_to_visit_in_old_tree:
node_id_in_old_tree = node_ids_to_visit_in_old_tree.pop()
node_in_old_tree = node_id_to_node_in_old_tree[node_id_in_old_tree]
cl_dist = node_in_old_tree.dist / 2.0
for ch_node_in_old_tree in [node_in_old_tree.left, node_in_old_tree.right]:
if ch_node_in_old_tree:
ch_for_new_tree = Tree()
ch_for_new_tree.dist = cl_dist
node_id += 1
node_id_to_node_in_new_tree[node_id] = ch_for_new_tree
if ch_node_in_old_tree.is_leaf():
if id_to_sample_dict:
ch_for_new_tree.name = id_to_sample_dict[ch_node_in_old_tree.id]
else:
ch_for_new_tree.name = ch_node_in_old_tree.id
else:
# we used to export our trees with internal node labels so we could
# do various interface operations more easily:
#
# ch_for_new_tree.name = 'Int' + str(ch_node_in_old_tree.id)
#
# but our new interface design does not require such addditions to
# dendrograms. Although here we add 0 branch support for our
# dendrograms since we wish to use a standard format to export these
# data as a tree.
ch_for_new_tree.support = 0.0
node_id_to_node_in_new_tree[node_id_in_old_tree].add_child(ch_for_new_tree)
node_id_to_node_in_old_tree[node_id] = ch_node_in_old_tree
node_ids_to_visit_in_old_tree.append(node_id)
for node in new_tree.traverse("preorder"):
if node.is_leaf():
continue
has_child_with_dist_or_int = False
for child in node.get_children():
if not child.is_leaf() or child.dist > 0:
has_child_with_dist_or_int = True
break
if has_child_with_dist_or_int:
continue
# swap childs alphabetically
node.children = sorted(node.get_children(), key=lambda x:x.name, reverse=True)
return new_tree.write(format=2)