当前位置: 首页>>代码示例>>Python>>正文


Python TreeNode.ChildLookup方法代码示例

本文整理汇总了Python中skbio.TreeNode.ChildLookup方法的典型用法代码示例。如果您正苦于以下问题:Python TreeNode.ChildLookup方法的具体用法?Python TreeNode.ChildLookup怎么用?Python TreeNode.ChildLookup使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在skbio.TreeNode的用法示例。


在下文中一共展示了TreeNode.ChildLookup方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: make_consensus_tree

# 需要导入模块: from skbio import TreeNode [as 别名]
# 或者: from skbio.TreeNode import ChildLookup [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
开发者ID:biocore,项目名称:tax2tree,代码行数:56,代码来源:nlevel.py


注:本文中的skbio.TreeNode.ChildLookup方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。