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


Python Tree.search_nodes方法代码示例

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


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

示例1: WebTreeHandler

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

#.........这里部分代码省略.........
           self.tree.tree_style = TreeStyle()
        else:
           self.tree.tree_style = style

    def set_tree_config(self, tcofg):
        self.treeconfig_obj = tcofg

    @timeit
    def redraw(self, top_offset=0,left_offset=0):
        #print "Inside redraw calling tree.render()"
        #os.environ["DISPLAY"]=":0" # Used by ete to render images
        base64_img, img_map = self.tree.render("%%return.PNG", tree_style=self.tree.tree_style)
        #print "Inside redraw calling get_html_map()...."
        html_map = self.get_html_map(img_map)

        ete_link = '<div style="margin:0px;padding:0px;text-align:left;"><a href="http://etetoolkit.org" style="font-size:7pt;" target="_blank" >Powered by etetoolkit</a></div>'
        html_img = """<img id="%s" class="ete_tree_img" USEMAP="#%s" onLoad="javascript:bind_popup(%s,%s);" src="data:image/gif;base64,%s">""" %(self.imgid, self.mapid, left_offset, top_offset, base64_img)

        tree_div_id = self.boxid
        #print "returning html from redraw method...."
        return html_map+ '<div id="%s" >'%tree_div_id + html_img + ete_link + "</div>"

    #------------------------------------------
    def save_image(self, img_format):
        img_url = os.path.join("http://phylo.cs.nmsu.edu:8080/TreeViewer/demo/tmp_dev/", self.treeid+"."+img_format)
        img_path = os.path.join("/var/www/html/TreeViewer/demo/tmp_dev/", self.treeid+"."+img_format)        
        img = self.tree.render(img_path, tree_style=self.tree.tree_style)
        #print "returning from save image"
        return '<a target="_blank" href="%s">Download Image</a>' %(img_url)
    #------------------------------------------
    def get_html_map(self, img_map):
        html_map = '<MAP NAME="%s" class="ete_tree_img">' %(self.mapid)
        #print "get_html_map method called......."
        if img_map["nodes"]:
            for x1, y1, x2, y2, nodeid, text in img_map["nodes"]:
                text = "" if not text else text
                area = img_map["node_areas"].get(int(nodeid), [0,0,0,0])
                html_map += """ <AREA SHAPE="rect" COORDS="%s,%s,%s,%s"
                                onMouseOut='unhighlight_node();'
                                onMouseOver='highlight_node("%s", "%s", "%s", %s, %s, %s, %s);'
                                onClick='show_actions("%s", "%s");'
                                href="javascript:void('%s');">""" %\
                    (int(x1), int(y1), int(x2), int(y2),
                     self.treeid, nodeid, text, area[0], area[1], area[2]-area[0], area[3]-area[1],
                     self.treeid, nodeid,
                     nodeid)

        if img_map["faces"]:
            for x1, y1, x2, y2, nodeid, text in img_map["faces"]:
                text = "" if not text else text
                area = img_map["node_areas"].get(int(nodeid), [0,0,0,0])
                html_map += """ <AREA SHAPE="rect" COORDS="%s,%s,%s,%s"
                                onMouseOut='unhighlight_node();'
                                onMouseOver='highlight_node("%s", "%s", "%s", %s, %s, %s, %s);'
                                onClick='show_actions("%s", "%s", "%s");'
                                href='javascript:void("%s");'>""" %\
                    (int(x1),int(y1),int(x2),int(y2),
                     self.treeid, nodeid, text, area[0], area[1], area[2]-area[0], area[3]-area[1],
                     self.treeid, nodeid, text,
                     text,
                     )
        html_map += '</MAP>'
        #print "returning html from get_html_map()...."
        return html_map
    
    #---------------------------------------
    def get_tree_node(self, nodeid):
        target_node = self.tree.search_nodes(_nid=int(nodeid))[0]
        return target_node

    def get_node_name(self, nodeid):
        target_node = self.get_tree_node(nodeid)
        return target_node.name

    #--------------------------------------
    def get_avail_actions(self, nodeid):
        target = self.tree.search_nodes(_nid=int(nodeid))[0]
        action_list = []
        for aindex, aname, aorder, show_fn, run_fn, html_generator in self.tree.actions:
            if show_fn(target):
                action_list.append([aindex, aname, aorder, html_generator])
        action_list.sort(key=lambda x: x[2])
        return action_list

    def run_action(self, aindex, nodeid):
        target = self.tree.search_nodes(_nid=int(nodeid))[0]
        run_fn = self.tree.actions.actions[aindex][3]
        return run_fn(self.tree, target)
    #----------------------------------------
    def run_tree_action(self, color_code,line_width):
        #print "run_tree_action called..."
        return self.treeconfig_obj.run_action_linecolorwidth(self.tree, color_code, line_width)

    def run_tree_ladderize(self):
        #print "run_tree_action called..."
        return self.treeconfig_obj.run_action_ladderize(self.tree)

    def run_tree_customize(self, branch, internal):
        #print "run_tree_customize called..."
        return self.treeconfig_obj.set_custom_options(branch, internal)
开发者ID:phylotastic,项目名称:phylo_webservices,代码行数:104,代码来源:tree_handler.py

示例2: RectFace

# 需要导入模块: from ete3 import Tree [as 别名]
# 或者: from ete3.Tree import search_nodes [as 别名]
                )
            else:
                C = RectFace(triangle=True, width=size[mode], height=size[mode], bgcolor="#939393", fgcolor="#FFFFFF")
        n.add_face(C, column=1, position=position)
    tree.render(file_name=sys.argv[1] + "_" + cluster + ".pdf", tree_style=ts, w=width)


big_tree = Tree(sys.argv[1])
mode = sys.argv[2]
metadata = {}
metadata = get_meta_new(metadata, big_tree)
colourDict = get_colours(clusters, big_tree, colours)

# remove dodgy sample
big_tree.search_nodes(name="'EBOV|EMLab-RT|IPDPFHGINSP_GUI_2015_5339||GIN|Conakry|?|MinION_LQ05|2015-04-08'")[0].delete(
    preserve_branch_length=True
)
# root the same as the MCC tree
ancestor = big_tree.get_common_ancestor(
    "'EBOV|EMLab|EM_079422|KR817187|GIN|Macenta|?||2014-03-27'",
    "'EBOV|EMLab|Gueckedou-C05|KJ660348|GIN|Gueckedou|?||2014-03-19'",
)
big_tree.set_outgroup(ancestor)
big_tree.ladderize()

ts = TreeStyle()
ts.show_leaf_name = False
# ts.show_branch_support = True
ts.scale = 100000
if mode == "small":
    ts.scale = 750000
开发者ID:meren,项目名称:ebov,代码行数:33,代码来源:generate_tree_figure.py

示例3:

# 需要导入模块: from ete3 import Tree [as 别名]
# 或者: from ete3.Tree import search_nodes [as 别名]
#          /A-------|          \G-------|
#         |         |                    \-I
#         |         |
#         |          \-E
# -NoName--|
#         |                    /-L
#         |          /J-------|
#         |         |         |          /-N
#         |         |          \O-------|
#          \C-------|                    \-Q
#                   |
#                   |          /-P
#                    \M-------|
#                              \-S
# Get pointers to specific nodes
G = t.search_nodes(name="G")[0]
J = t.search_nodes(name="J")[0]
C = t.search_nodes(name="C")[0]
# If we remove J from the tree, the whole partition under J node will
# be detached from the tree and it will be considered an independent
# tree. We can do the same thing using two approaches: J.detach() or
# C.remove_child(J)
removed_node = J.detach()  # = C.remove_child(J)
# if we know print the original tree, we will see how J partition is
# no longer there.
print "Tree after REMOVING the node J"
print t.get_ascii(show_internal=True)
#                                        /-H
#                              /D-------|
#                             |          \-K
#                    /B-------|
开发者ID:abdo3a,项目名称:ete,代码行数:33,代码来源:remove_and_delete_nodes.py

示例4: TextFace

# 需要导入模块: from ete3 import Tree [as 别名]
# 或者: from ete3.Tree import search_nodes [as 别名]
        # change the branch length
        root.add_feature("dist", time_duration)
        #change node style
        root.set_style(ns_root)
        
        # set node name to face
        nameFace = TextFace(root.name)
        nameFace.fgcolor = "white"
        nameFace.fsize = 15
#        nameFace.border.width = 1
        nameFace.background.color = "green"
        node_cur.add_face(nameFace, column=1, position="branch-bottom")
    
    else:  # for child
        #### search the parent node by parent_id
        node_cur = root.search_nodes(name=str(parent_id))
        # there should be only one parent node
        if len(node_cur) == 1:
            #### set child with its id
            node_cur = node_cur[0].add_child(name=str(cell_id))  
            #### set duration
            node_cur.add_feature("dist", time_duration)
            
            # set node style
            node_cur.set_style(ns)
            
            # set node name to face
            nameFace = TextFace(node_cur.name)
            nameFace.fgcolor = "white"
            nameFace.fsize = 15
            nameFace.background.color = "green"
开发者ID:joe8767,项目名称:treeDrawing,代码行数:33,代码来源:lineageTree.py

示例5: Tree

# 需要导入模块: from ete3 import Tree [as 别名]
# 或者: from ete3.Tree import search_nodes [as 别名]
import random
from ete3 import Tree
# Creates a normal tree
t = Tree( '((H:0.3,I:0.1):0.5, A:1, (B:0.4,(C:0.5,(J:1.3, (F:1.2, D:0.1):0.5):0.5):0.5):0.5);' )
print t
# Let's locate some nodes using the get common ancestor method
ancestor=t.get_common_ancestor("J", "F", "C")
# the search_nodes method (I take only the first match )
A = t.search_nodes(name="A")[0]
# and using the shorcut to finding nodes by name
C= t&"C"
H= t&"H"
I= t&"I"
# Let's now add some custom features to our nodes. add_features can be
#  used to add many features at the same time.
C.add_features(vowel=False, confidence=1.0)
A.add_features(vowel=True, confidence=0.5)
ancestor.add_features(nodetype="internal")
# Or, using the oneliner notation
(t&"H").add_features(vowel=False, confidence=0.2)
# But we can automatize this. (note that i will overwrite the previous
# values)
for leaf in t.traverse():
    if leaf.name in "AEIOU":
        leaf.add_features(vowel=True, confidence=random.random())
    else:
        leaf.add_features(vowel=False, confidence=random.random())
# Now we use these information to analyze the tree.
print "This tree has", len(t.search_nodes(vowel=True)), "vowel nodes"
print "Which are", [leaf.name for leaf in t.iter_leaves() if leaf.vowel==True]
# But features may refer to any kind of data, not only simple
开发者ID:AlishaMechtley,项目名称:ete,代码行数:33,代码来源:add_features.py

示例6: WebTreeHandler

# 需要导入模块: from ete3 import Tree [as 别名]
# 或者: from ete3.Tree import search_nodes [as 别名]
class WebTreeHandler(object):
    def __init__(self, newick, tid, actions, style):
        try:
            self.tree = Tree(newick)
        except NewickError:
            self.tree = Tree(newick, format=1)

        self.tree.actions = actions
        self.tree.tree_style = style

        self.treeid = tid
        self.mapid = "map_" + tid
        self.imgid = "img_" + tid
        self.boxid = 'box_' + tid
        # Initialze node internal IDs
        for index, n in enumerate(self.tree.traverse('preorder')):
            n._nid = index

    @timeit
    def redraw(self):
        base64_img, img_map = self.tree.render("%%return.PNG", tree_style=self.tree.tree_style)
        html_map = self.get_html_map(img_map)

        ete_link = '<div style="margin:0px;padding:0px;text-align:left;"><a href="http://etetoolkit.org" style="font-size:7pt;" target="_blank" >Powered by etetoolkit</a></div>'
        html_img = """<img id="%s" class="ete_tree_img" USEMAP="#%s" onLoad="javascript:bind_popup();" src="data:image/gif;base64,%s">""" %(self.imgid, self.mapid, base64_img)

        tree_div_id = self.boxid
        return html_map+ '<div id="%s" >'%tree_div_id + html_img + ete_link + "</div>"

    def get_html_map(self, img_map):
        html_map = '<MAP NAME="%s" class="ete_tree_img">' %(self.mapid)
        if img_map["nodes"]:
            for x1, y1, x2, y2, nodeid, text in img_map["nodes"]:
                text = "" if not text else text
                area = img_map["node_areas"].get(int(nodeid), [0,0,0,0])
                html_map += """ <AREA SHAPE="rect" COORDS="%s,%s,%s,%s"
                                onMouseOut='unhighlight_node();'
                                onMouseOver='highlight_node("%s", "%s", "%s", %s, %s, %s, %s);'
                                onClick='show_actions("%s", "%s");'
                                href="javascript:void('%s');">""" %\
                    (int(x1), int(y1), int(x2), int(y2),
                     self.treeid, nodeid, text, area[0], area[1], area[2]-area[0], area[3]-area[1],
                     self.treeid, nodeid,
                     nodeid)

        if img_map["faces"]:
            for x1, y1, x2, y2, nodeid, text in img_map["faces"]:
                text = "" if not text else text
                area = img_map["node_areas"].get(int(nodeid), [0,0,0,0])
                html_map += """ <AREA SHAPE="rect" COORDS="%s,%s,%s,%s"
                                onMouseOut='unhighlight_node();'
                                onMouseOver='highlight_node("%s", "%s", "%s", %s, %s, %s, %s);'
                                onClick='show_actions("%s", "%s", "%s");'
                                href='javascript:void("%s");'>""" %\
                    (int(x1),int(y1),int(x2),int(y2),
                     self.treeid, nodeid, text, area[0], area[1], area[2]-area[0], area[3]-area[1],
                     self.treeid, nodeid, text,
                     text,
                     )
        html_map += '</MAP>'
        return html_map

    def get_avail_actions(self, nodeid):
        target = self.tree.search_nodes(_nid=int(nodeid))[0]
        action_list = []
        for aindex, aname, show_fn, run_fn in self.tree.actions:
            if show_fn(target):
                action_list.append([aindex, aname])
        return action_list

    def run_action(self, aindex, nodeid):
        target = self.tree.search_nodes(_nid=int(nodeid))[0]
        run_fn = self.tree.actions.actions[aindex][2]
        return run_fn(self.tree, target)
开发者ID:etetoolkit,项目名称:webplugin,代码行数:76,代码来源:tree_handler.py

示例7: get_rooting

# 需要导入模块: from ete3 import Tree [as 别名]
# 或者: from ete3.Tree import search_nodes [as 别名]
def get_rooting(tol, seed_species, agename = False):
    '''
    returns dict of species age for a given TOL and a given seed

    **Example:**

    ::

      tol  = "((((((((Drosophila melanogaster,(Drosophila simulans,Drosophila secchellia)),(Drosophila yakuba,Drosophila erecta))[&&NHX:name=melanogaster subgroup],Drosophila ananassae)[&&NHX:name=melanogaster group],(Drosophila pseudoobscura,Drosophila persimilis)[&&NHX:name=obscura group])[&&NHX:name=Sophophora Old World],Drosophila willistoni)[&&NHX:name=subgenus Sophophora],(Drosophila grimshawi,(Drosophila virilis,Drosophila mojavensis))[&&NHX:name=subgenus Drosophila])[&&NHX:name=genus Drosophila],(Anopheles gambiae,Aedes aegypti)[&&NHX:name=Culicidae])[&&NHX:name=Arthropoda],Caenorhabditis elegans)[&&NHX:name=Animalia];"
      seed = "Drosophila melanogaster"
      ROOTING, age2name = get_rooting (tol, seed, True)

      ROOTING == {"Aedes aegypti"           : 7,
                  "Anopheles gambiae"       : 7,
                  "Caenorhabditis elegans"  : 8,
                  "Drosophila ananassae"    : 3,
                  "Drosophila erecta"       : 2,
                  "Drosophila grimshawi"    : 6,
                  "Drosophila melanogaster" : 1,
                  "Drosophila mojavensis"   : 6,
                  "Drosophila persimilis"   : 4,
                  "Drosophila pseudoobscura": 4,
                  "Drosophila secchellia"   : 1,
                  "Drosophila simulans"     : 1,
                  "Drosophila virilis"      : 6,
                  "Drosophila willistoni"   : 5,
                  "Drosophila yakuba"       : 2}

      age2name == {1: "Drosophila melanogaster. Drosophila simulans. Drosophila secchellia",
                   2: "melanogaster subgroup",
                   3: "melanogaster group",
                   4: "Sophophora Old World",
                   5: "subgenus Sophophora",
                   6: "genus Drosophila",
                   7: "Arthropoda",
                   8: "Animalia"}

    :argument seed_species: species name
    :argument False agename: if True, also returns the inverse dictionary

    :returns: ROOTING dictionary with age of each species

    '''

    tol = Tree (tol)
    try:
        node = tol.search_nodes (name=seed_species)[0]
    except IndexError:
        exit ('ERROR: Seed species not found in tree\n')
    age = 1
    ROOTING = {}
    if agename:
        age2name = {}
    while not node.is_root():
        node = node.up
        for leaf in node.get_leaf_names():
            if agename:
                if node.name == 'NoName':
                    nam = '.'.join (node.get_leaf_names())
                else:
                    nam = node.name
                age2name.setdefault (age, nam)
            ROOTING.setdefault (leaf, age)
        age += 1
    if agename:
        return ROOTING, age2name
    return ROOTING
开发者ID:Ward9250,项目名称:ete,代码行数:69,代码来源:utils.py

示例8: ClusterIdentification

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

#.........这里部分代码省略.........
        if not nodecomb or not nodecombRev in self.monoFinalRes:
            if not node1 in self.nodesRemoved:
                if not node2 in self.nodesRemoved:
                    # Collect all common ancestors for each pair of variants
                    ancestor = self.t.get_common_ancestor(n)
                    for i in ancestor:
                        ancestorList.append(i.name)
                        ancestorShort = i.name[idStart:idLen]
                        if not ancestorShort in PhyloOutliers:
                            PhyloOutliers[ancestorShort] = []
                        PhyloOutliers[ancestorShort].append(1)

                    # Sum the variants for each sample, if < 3, store variant as outlier
                    for k, v in PhyloOutliers.iteritems():
                        vsum = sum(v)
                        if vsum < 3:
                            for item in ancestorList:
                                if item[idStart:idLen] == k:
                                    if not item in self.nodesRemoved:
                                        if node1short in self.SerialNodes:
                                            if not node2short in self.SerialNodes[node1short]:
                                                ancestorList.remove(item)
                                                self.nodesRemoved.append(item)
                                        elif node2short in self.SerialNodes:
                                            if not node1short in self.SerialNodes[node2short]:
                                                ancestorList.remove(item)
                                                self.nodesRemoved.append(item)
                                        else:
                                            ancestorList.remove(item)
                                            self.nodesRemoved.append(item)
            for i in self.nodesRemoved:
                if not i in self.nodecheck:
                    try:
                        item = self.t.search_nodes(name=item)[0]
                        i.delete()
                        self.nodecheck.append(i)
                    except:
                        pass

        return ancestorList

    # Create all combinations of intrahost sample identifiers for each respective sequential sample set
    # These results are used to assist in PhylyOutlierRem
    def intraComb(self, infile):

        with open(IntraFile) as f:
            for line in f:
                line = line.rstrip("\n")
                linesp = line.split(",")

                length = len(linesp)
                comb = int(length)
                for i in linesp:
                    self.SerialNodes[i] = []
                    for pair in itertools.combinations(linesp, 2):

                        for item in pair:
                            if i != item:
                                if not item in self.SerialNodes[i]:
                                    self.SerialNodes[i].append(item)

        return self.SerialNodes

    # First step of merging overlapping pairs of connected samples
    def ClusterKeys(self, values, node1, node2):
开发者ID:vmon588,项目名称:Intra-Clust,代码行数:69,代码来源:ete.DeepSequencingClusterID.py

示例9: Tree

# 需要导入模块: from ete3 import Tree [as 别名]
# 或者: from ete3.Tree import search_nodes [as 别名]
from ete3 import Tree
t = Tree( '(A:1,(B:1,(C:1,D:1):0.5):0.5);' )
# Browse the tree from a specific leaf to the root
node = t.search_nodes(name="C")[0]
while node:
    print node
    node = node.up
# --C
#           /-C
# ---------|
#           \-D
#
#           /-B
# ---------|
#          |          /-C
#           \--------|
#                     \-D
#
#           /-A
# ---------|
#          |          /-B
#           \--------|
#                    |          /-C
#                     \--------|
#                               \-D
开发者ID:AlishaMechtley,项目名称:ete,代码行数:27,代码来源:custom_tree_traversing.py

示例10:

# 需要导入模块: from ete3 import Tree [as 别名]
# 或者: from ete3.Tree import search_nodes [as 别名]
#  ---------|
#           |          /-F
#            \--------|
#                      \-G
print "Tree3:", t3
#            /-H
#           |
#  ---------|                    /-I
#           |          /--------|
#           |         |          \-J
#            \--------|
#                     |          /-K
#                      \--------|
#                                \-L
# Locates a terminal node in the first tree
A = t1.search_nodes(name='A')[0]
# and adds the two other trees as children.
A.add_child(t2)
A.add_child(t3)
print "Resulting concatenated tree:", t1
#                                          /-D
#                                /--------|
#                               |          \-E
#                      /--------|
#                     |         |          /-F
#                     |          \--------|
#            /--------|                    \-G
#           |         |
#           |         |          /-H
#           |         |         |
#           |          \--------|                    /-I
开发者ID:AlishaMechtley,项目名称:ete,代码行数:33,代码来源:copy_and_paste_trees.py

示例11: Tree

# 需要导入模块: from ete3 import Tree [as 别名]
# 或者: from ete3.Tree import search_nodes [as 别名]
from ete3 import Tree
#Loads a tree
t = Tree( '((H:1,I:1):0.5, A:1, (B:1,(C:1,D:1):0.5):0.5);' )
print t
#                    /-H
#          /--------|
#         |          \-I
#         |
#---------|--A
#         |
#         |          /-B
#          \--------|
#                   |          /-C
#                    \--------|
#                              \-D
# I get D
D = t.search_nodes(name="D")
# I get all nodes with distance=0.5
nodes = t.search_nodes(dist=0.5)
print len(nodes), "nodes have distance=0.5"
开发者ID:AlishaMechtley,项目名称:ete,代码行数:22,代码来源:search_nodes.py


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