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


Python Tree.add_child方法代码示例

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


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

示例1: ConvertListofClustersToTree

# 需要导入模块: from ete3 import Tree [as 别名]
# 或者: from ete3.Tree import add_child [as 别名]
def ConvertListofClustersToTree(cluster_list):
    """ FIXME: recurse this function"""
    t = Tree()
    for i, node in enumerate(cluster_list):
        print "Cluster %d"%i
        if (len(node)) >= 1:
            print "We have a node of size : %d" % len(node)
            child = t.add_child(name="Cluster %d"%i)
            for subnode in node:
                if len(subnode.child) >= 1:
                    print "Adding subnode of size : %d"%len(subnode.child)
                    for subsubnode in subnode.child:
                        print "Adding subsubnode of %s"%subsubnode.child
                        child.add_child(name=subsubnode.child, dist=subsubnode.distance)
    return t
开发者ID:sameerd,项目名称:ppmi,代码行数:17,代码来源:test_corex_updrs3.py

示例2: neighbor_based_method

# 需要导入模块: from ete3 import Tree [as 别名]
# 或者: from ete3.Tree import add_child [as 别名]
def neighbor_based_method(M, names, closest_neighbors_fn, new_dist_fn, parent_dist_fn):
    def search_nodes(trees ,name):
        for tree in trees:
            if tree.name == name:
                return tree
    trees = []
    while True:
        taxa1, taxa2 = closest_neighbors_fn(M)
        if taxa1 > taxa2:
            tmp = taxa1
            taxa1 = taxa2
            taxa1 = tmp
        #define a new parent for the join
        t = Tree()
        #search for the children in trees and add them
        A = search_nodes(trees, names[taxa1])
        if A == None:
            A = t.add_child(name = names[taxa1])
        else:
            t.add_child(A)
            trees.remove(A)
        B = search_nodes(trees, names[taxa2])
        if B == None:
            B = t.add_child(name = names[taxa2])
        else:
            t.add_child(B)
            trees.remove(B)
        #delete old taxa names and update the new name
        new_names = [names[taxa1] + names[taxa2]]
        del names[taxa2]
        del names[taxa1]
        [new_names.append(name) for name in names]
        names = new_names
        #create the distance between children and parent
        A.dist, B.dist = parent_dist_fn(M, taxa1, taxa2)
        #name the parent
        t.name = names[0]
        #add the new subtree
        trees.append(t)

        if len(M) <= 2:
            break
        M = update_matrix(M, taxa1, taxa2, new_dist_fn)
    return trees[0]
开发者ID:nixonpjoshua,项目名称:Math127,代码行数:46,代码来源:distance_based_trees.py

示例3: open

# 需要导入模块: from ete3 import Tree [as 别名]
# 或者: from ete3.Tree import add_child [as 别名]
data = open(read_path+filename+'.txt').read().replace(',',' ').replace('\n',' ')
x = data.split()
ParentChild = np.array(x).astype(str)
y = len(ParentChild)/5
ParentChild1 = np.reshape(ParentChild, (y,5))
firsttwo = ParentChild1[:,0:2] #chops off first line which encodes parameters of simulation and third column which is not yet used
parents = []
children = []

for row in range(0, len(firsttwo)): 
	for column in range(0,2): 
		firsttwo[row,column] = 'r'+firsttwo[row,column]

t = Tree() # Creates an empty tree

r1 = t.add_child(name="r1")
lookup = {"r1": r1}
prune_list = ['r1']

for pair in sorted(firsttwo, key=sort_pairs):
    parentname = pair[0]
    childname = pair[1]
    if childname not in lookup:
        if parentname in lookup:
            newchild = lookup[parentname].add_child(name = childname)
            lookup.update({childname: newchild})
            if parentname not in parents:
                prune_list.append(lookup[parentname])
            parents.append(parentname) #make list of unique terminal nodes (no children of children)
            children.append(newchild)
        else:
开发者ID:cancerconnector,项目名称:clonal-evolution,代码行数:33,代码来源:treebuilder.py

示例4: Tree

# 需要导入模块: from ete3 import Tree [as 别名]
# 或者: from ete3.Tree import add_child [as 别名]
from ete3 import Tree
# Creates an empty tree and populates it with some new
# nodes
t = Tree()
A = t.add_child(name="A")
B = t.add_child(name="B")
C = A.add_child(name="C")
D = A.add_child(name="D")
print t
#                    /-C
#          /--------|
#---------|          \-D
#         |
#          \-B
print 'is "t" the root?', t.is_root() # True
print 'is "A" a terminal node?', A.is_leaf() # False
print 'is "B" a terminal node?', B.is_leaf() # True
print 'B.get_tree_root() is "t"?', B.get_tree_root() is t # True
print 'Number of leaves in tree:', len(t) # returns number of leaves under node (3)
print 'is C in tree?', C in t # Returns true
print "All leaf names in tree:", [node.name for node in t]
开发者ID:AlishaMechtley,项目名称:ete,代码行数:23,代码来源:tree_basis.py

示例5: Tree

# 需要导入模块: from ete3 import Tree [as 别名]
# 或者: from ete3.Tree import add_child [as 别名]
from ete3 import Tree 
import numpy as np

t = Tree(name = "Lisa")
t.add_child(name = "Alex")
t.add_child(name = "Dilly")

t = Tree(name = "GATTACA") 

def uniform_killing(pop, proportion):
    return filter(lambda y: np.random.rand() < proportion, pop) # filter keeps values less than proportion

pop = [t.name]*10

for i in xrange(0,5):
	print(uniform_killing(pop,.9))














开发者ID:nixonpjoshua,项目名称:Math127,代码行数:18,代码来源:tree_exs.py

示例6: Tree

# 需要导入模块: from ete3 import Tree [as 别名]
# 或者: from ete3.Tree import add_child [as 别名]
from ete3 import Tree
t = Tree() # Creates an empty tree
A = t.add_child(name="A") # Adds a new child to the current tree root
                           # and returns it
B = t.add_child(name="B") # Adds a second child to the current tree
                           # root and returns it
C = A.add_child(name="C") # Adds a new child to one of the branches
D = C.add_sister(name="D") # Adds a second child to same branch as
                             # before, but using a sister as the starting
                             # point
R = A.add_child(name="R") # Adds a third child to the
                           # branch. Multifurcations are supported
# Next, I add 6 random leaves to the R branch names_library is an
# optional argument. If no names are provided, they will be generated
# randomly.
R.populate(6, names_library=["r1","r2","r3","r4","r5","r6"])
# Prints the tree topology
print t
#                     /-C
#                    |
#                    |--D
#                    |
#           /--------|                              /-r4
#          |         |                    /--------|
#          |         |          /--------|          \-r3
#          |         |         |         |
#          |         |         |          \-r5
#          |          \--------|
# ---------|                   |                    /-r6
#          |                   |          /--------|
#          |                    \--------|          \-r2
开发者ID:AlishaMechtley,项目名称:ete,代码行数:33,代码来源:create_trees_from_scratch.py

示例7: final_tree

# 需要导入模块: from ete3 import Tree [as 别名]
# 或者: from ete3.Tree import add_child [as 别名]
 def final_tree(sortedDM):
     tree_list = []
     parse_states = [chunk for chunk in sortedDM\
                           if chunk[0].typename == "parse_state" and\
                              chunk[0].daughter1 != None]
     words = set(str(chunk[0].form) for chunk in sortedDM\
                                    if chunk[0].typename == "word")
     nodes = [chunk for chunk in parse_states
                 if chunk[0].node_cat == "S"]
     while nodes:
         current_chunk = nodes.pop(0)
         current_node = str(current_chunk[0].node_cat) + " " +\
                     str(current_chunk[1])
         current_tree = Tree(name=current_node)
         if current_chunk[0].daughter2 != None:
             child_categs = [current_chunk[0].daughter1,\
                             current_chunk[0].daughter2]
         else:
             child_categs = [current_chunk[0].daughter1]
         children = []
         for cat in child_categs:
             if cat == 'NP':
                 chunkFromCat = [chunk for chunk in parse_states\
                                 if chunk[0].node_cat == cat and\
                                 chunk[0].mother ==\
                                     current_chunk[0].node_cat]
                 if chunkFromCat:
                     children += chunkFromCat
                     current_child = str(chunkFromCat[-1][0].node_cat)\
                                     + " " + str(chunkFromCat[-1][1])
                     current_tree.add_child(name=current_child)
             elif cat == 'ProperN':
                 chunkFromCat = [chunk for chunk in parse_states if\
                                 chunk[0].node_cat == cat and\
                                 chunk[0].daughter1 ==\
                                     current_chunk[0].lex_head]
                 if chunkFromCat:
                     children += chunkFromCat
                     current_child = str(chunkFromCat[-1][0].node_cat)\
                                     + " " + str(chunkFromCat[-1][1])
                     current_tree.add_child(name=current_child)
             elif cat in words:
                 last_act_time = [chunk[1][-1]
                                 for chunk in dm.items()\
                                 if chunk[0].typename == "word"\
                                 and str(chunk[0].form) == cat]
                 current_child = cat + " " + str(last_act_time[0])
                 current_tree.add_child(name=current_child)
             else:
                 chunkFromCat = [chunk for chunk in parse_states\
                                 if chunk[0].node_cat == cat]
                 if chunkFromCat:
                     children += chunkFromCat
                     current_child = str(chunkFromCat[-1][0].node_cat)\
                                     + " " + str(chunkFromCat[-1][1])
                     current_tree.add_child(name=current_child)
         tree_list.append(current_tree)
         nodes += children
     final_tree = tree_list[0]
     tree_list.remove(final_tree)
     while tree_list:
         leaves = final_tree.get_leaves()
         for leaf in leaves:
             subtree_list = [tree for tree in tree_list\
                                  if tree.name == leaf.name]
             if subtree_list:
                 subtree = subtree_list[0]
                 tree_list.remove(subtree)
                 leaf.add_sister(subtree)
                 leaf.detach()
     return final_tree
开发者ID:jakdot,项目名称:pyactr,代码行数:73,代码来源:ch4_leftcorner_parser.py


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