本文整理汇总了Python中skbio.TreeNode.Rank方法的典型用法代码示例。如果您正苦于以下问题:Python TreeNode.Rank方法的具体用法?Python TreeNode.Rank怎么用?Python TreeNode.Rank使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类skbio.TreeNode
的用法示例。
在下文中一共展示了TreeNode.Rank方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: make_consensus_tree
# 需要导入模块: from skbio import TreeNode [as 别名]
# 或者: from skbio.TreeNode import Rank [as 别名]
def make_consensus_tree(cons_split, check_for_rank=True, tips=None):
"""Returns a mapping by rank for names to their parent names and counts"""
god_node = TreeNode(name=None)
god_node.Rank = None
base = list(cons_split)[0]
cur_node = god_node
# create a base path in the tree
for rank, name in enumerate(base):
new_node = TreeNode(name=name)
new_node.Rank = rank
cur_node.append(new_node)
cur_node = new_node
# setup the initial childlookup structure so taht we don't have to
# always iterate over .children
for n in god_node.traverse(include_self=True):
if n.is_tip():
n.ChildLookup = {}
continue
n.ChildLookup = {n.children[0].name: n.children[0]}
# for every consensus string, start at the "god" node
for idx, con in enumerate(cons_split):
cur_node = god_node
# for each name, see if we've seen it, if not, add that puppy on
for rank, name in enumerate(con):
if name in cur_node.ChildLookup:
cur_node = cur_node.ChildLookup[name]
else:
new_node = TreeNode(name=name)
new_node.Rank = rank
new_node.ChildLookup = {}
cur_node.append(new_node)
cur_node.ChildLookup[name] = new_node
cur_node = new_node
if tips is not None:
cur_node.append(TreeNode(name=tips[idx]))
# build an assist lookup dict
lookup = {}
for node in god_node.traverse():
if node.name is None:
continue
if check_for_rank and '__' in node.name and \
node.name.split('__')[1] == '':
continue
lookup[node.name] = node
return god_node, lookup