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


Python TreeStyle.branch_vertical_margin方法代码示例

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


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

示例1: render_annotate

# 需要导入模块: from ete2 import TreeStyle [as 别名]
# 或者: from ete2.TreeStyle import branch_vertical_margin [as 别名]
    def render_annotate(newick_path, output_path):
        """Render the annotated tree, showing internal node names.
           The output_path should end in .PNG, .PDF or .SVG: this will determine the format.

           To aid in testing, if output_path is None, the tree is shown rather than rendered.
        """
        tree = Tree(newick_path, format=1)

        ts = TreeStyle()
        ts.show_leaf_name = True
        ts.branch_vertical_margin = 15

        ns = NodeStyle()
        ns["size"] = 1

        edge = 0
        for node in tree.traverse():
            node.name = node.name.replace("'", "")
            node.name = node.name.replace("+", ",")
            if not node.is_leaf() and node.name != "NoName":
                f = TextFace(node.name)
                f.margin_top = 5
                f.margin_bottom = 5
                f.margin_right = 10
                f.margin_left = 10
                edge += 1
                node.add_face(f, column=0, position="branch-top")

        if output_path is None:
            tree.show(tree_style=ts)
        else:
            tree.render(output_path)
开发者ID:williamdlees,项目名称:TRIgS,代码行数:34,代码来源:RenderTree.py

示例2: make_tree

# 需要导入模块: from ete2 import TreeStyle [as 别名]
# 或者: from ete2.TreeStyle import branch_vertical_margin [as 别名]
def make_tree(treefile, image_file, clone_info):
    colour_list = ['MidnightBlue','RoyalBlue', 'LightSkyBlue', 'Aquamarine', 'SpringGreen', 'GreenYellow',\
                   'Gold','DarkOrange']
    weeks = ['16', '30', '38', '48', '59', '119', '176', '206']
    weeks = ['6', '14', '53', '92','144']
    t = Tree(treefile,format = 1)
    ts = TreeStyle()
    for i in range(5):
        ts.legend.add_face(CircleFace(20, colour_list[i]), column=0)
        ts.legend.add_face(TextFace('week' + weeks[i]), column=1)
    ts.legend_position = 2
    ts.show_leaf_name = True
    ts.branch_vertical_margin = 15
    ts.rotation = 90
    ns = NodeStyle()
    ns["size"] = 1
    ns.hz_line_width = 10
    ns.vt_line_width = 10
    edge = 0
    for node in t.traverse():
        node.name = node.name.replace("'", "")
        node.name = node.name.replace(".", ",")
        name = node.name.split(' ')[0]
        print name
        if name in clone_info.keys():
            style_node(node, colour_list[int(clone_info[name][0])-1], int(int(clone_info[name][1])/10)+5)
        if not node.is_leaf() and node.name != 'NoName':
                f = TextFace(node.name)
                f.margin_top = 2.5
                f.margin_bottom = 2.5
                f.margin_right = 2.5
                f.margin_left = 2.5
                node.add_face(f, column=0, position="branch-top")
    t.render(image_file, tree_style = ts)
开发者ID:AnnaLaddach,项目名称:MRes-project,代码行数:36,代码来源:tree_functions3.py

示例3: draw_tree

# 需要导入模块: from ete2 import TreeStyle [as 别名]
# 或者: from ete2.TreeStyle import branch_vertical_margin [as 别名]
def draw_tree(tree, file):
    root = tree.get_midpoint_outgroup()
    try:
      tree.set_outgroup(root)
    except:
      pass
    root = tree.get_tree_root()
    root.dist = 0
    add_sig(tree)
    ts = TreeStyle()
    ts.branch_vertical_margin = 1
    #ts.scale = 1500
    ts.show_leaf_name = False
    #ts.show_branch_support = True
    leg_file = path.join(path.expanduser('~'), 'Perl', 'Modules', 'TreeLegend.png')   
    leg_face= ImgFace(img_file=leg_file)
    leg_face.margin_left, leg_face.margin_top = 5, 5
    ts.legend.add_face(leg_face, column=1)
    ts.legend_position=1

    title_face = TextFace(text=file.split('.')[0])
    title_face.margin_left, title_face.margin_top = 10, 5
    ts.title.add_face(title_face, column=1)
    (ts.margin_left, ts.margin_right) = (5,5)
    tree.render(file, tree_style=ts, w=6000, units='mm')
开发者ID:hobrien,项目名称:Python,代码行数:27,代码来源:ColourTree.py

示例4: plotTree

# 需要导入模块: from ete2 import TreeStyle [as 别名]
# 或者: from ete2.TreeStyle import branch_vertical_margin [as 别名]
 def plotTree(self, tree, out_fn=None, rotation=270, show_leaf_name=False, 
               show_branch_length=False, circularTree=False, show_division_nodes=True, 
               distance_between_branches=4, show_border=False, width=None, height=None):            
     from ete2 import TreeStyle        
     from PyQt4 import QtSvg, QtCore, QtGui
     from ete2.treeview import qt4_render, drawer, main
     
       
     ts = TreeStyle()   
     ts.show_scale = False
     ts.show_border = show_border
     ts.orientation = 1 # 0, tree is drawn from left-to-right. 1, tree is drawn from right-to-left
     ts.rotation = rotation
     ts.show_leaf_name = show_leaf_name
     ts.show_branch_length = show_branch_length
     if circularTree:
         ts.mode = 'c'
     else:
         ts.mode = 'r'
     ts.branch_vertical_margin = distance_between_branches
     
     
     def hideInternalNodesLayout(node):
         if not node.is_leaf():
             node.img_style["size"] = 0
     
     if show_division_nodes is False:
         ts.layout_fn = hideInternalNodesLayout
     
     if out_fn is not None:        
         scene  = qt4_render._TreeScene()
         img = ts
         
         tree_item, n2i, n2f = qt4_render.render(tree, img)
         scene.init_data(tree, img, n2i, n2f)
         tree_item.setParentItem(scene.master_item)
         scene.master_item.setPos(0,0)
         scene.addItem(scene.master_item)      
         main.save(scene, out_fn, w=width, h=height, dpi=600)    
           
     else:
         scene, img = drawer.init_scene(tree, None, ts)
         tree_item, n2i, n2f = qt4_render.render(tree, img)
         scene.init_data(tree, img, n2i, n2f)
     
         tree_item.setParentItem(scene.master_item)
         scene.addItem(scene.master_item)
     
         size = tree_item.rect()
         w, h = size.width(), size.height()
     
         svg = QtSvg.QSvgGenerator()
         svg.setFileName("test.svg")
         svg.setSize(QtCore.QSize(w, h))
         svg.setViewBox(size)
         pp = QtGui.QPainter()
         pp.begin(svg)            
         scene.render(pp, tree_item.rect(), tree_item.rect(), QtCore.Qt.KeepAspectRatio)
开发者ID:kkiefer,项目名称:ilastik,代码行数:60,代码来源:trackingUtilities.py

示例5: draw_tree

# 需要导入模块: from ete2 import TreeStyle [as 别名]
# 或者: from ete2.TreeStyle import branch_vertical_margin [as 别名]
def draw_tree(tree, file):
    ts = TreeStyle()
    ts.branch_vertical_margin = 1
    ts.show_leaf_name = False
    if '.svg' in file:
      ts.scale = 3000
      tree.render(file, tree_style=ts, h=300, units='mm')
    else:
      ts.scale = 1500 
      tree.render(file, tree_style=ts, w=3000, units='mm')
开发者ID:hobrien,项目名称:PhotobiontDiversity,代码行数:12,代码来源:FormatTree.py

示例6: drawTree

# 需要导入模块: from ete2 import TreeStyle [as 别名]
# 或者: from ete2.TreeStyle import branch_vertical_margin [as 别名]
def drawTree(nwfile, outfile):
    from ete2 import Tree, TreeStyle, TextFace
    ts = TreeStyle()
    ts.show_leaf_name = False
    ts.layout_fn = my_layout
    ts.branch_vertical_margin = 12.75
    ts.orientation = 1
    titleFace = TextFace("Phylogenetic Tree", fsize=18, fgcolor="white")
    titleFace.margin_top = 15
    ts.title.add_face(titleFace, column=1)

    t = Tree(nwfile)
    t.render(outfile, tree_style=ts)
开发者ID:dayin1989,项目名称:hal,代码行数:15,代码来源:treeCommon.py

示例7: load_tree

# 需要导入模块: from ete2 import TreeStyle [as 别名]
# 或者: from ete2.TreeStyle import branch_vertical_margin [as 别名]
def load_tree(f_tree, f_align):
    # Tree style
    ts = TreeStyle()
    ts.show_leaf_name = True
    ts.show_branch_length = True
    ts.show_branch_support = True
    ts.branch_vertical_margin = 10    

    # Load phylogenetic tree
    tree = PhyloTree(f_tree.read())
    if f_align is not None:    
        tree.link_to_alignment(f_align.read())
    return tree, ts
开发者ID:eubrazilcc,项目名称:leishmaniasis-virtual-lab,代码行数:15,代码来源:tree-generator.py

示例8: get_tree_style

# 需要导入模块: from ete2 import TreeStyle [as 别名]
# 或者: from ete2.TreeStyle import branch_vertical_margin [as 别名]
def get_tree_style(tree_file, abund, rownames):

    with open("matrix.txt", "w") as temp:
        cols = len(abund[0])
        header = "#Names"
        for i in xrange(cols):
            header += "\tOTU%d" % i
        temp.write("%s\n" % header)
        for i, row in enumerate(abund):
            temp.write("%s\t%s\n" % (rownames[i], '\t'.join([str(i) for i in row])))

    t = Tree(tree_file)
    t.convert_to_ultrametric(10)

    assert isinstance(abund, numpy.ndarray)
    assert isinstance(rownames, numpy.ndarray)
    ts = TreeStyle()
    ts.mode = "r"
    ts.show_leaf_name = False
    ts.show_scale = False
    ts.show_branch_length = False
    ts.branch_vertical_margin = 20
    ts.force_topology = True
    ts.optimal_scale_level = "full"
    ts.scale = 50
    ts.draw_guiding_lines = True
    ts.guiding_lines_type = 0
    ts.guiding_lines_color = "black"
    for n in t.traverse():
        if not n.is_leaf():
            nstyle = NodeStyle()
            n.set_style(nstyle)
            nstyle['size'] = 0
            nstyle['hz_line_width'] = 3
            nstyle['vt_line_width'] = 3
        else:
            nstyle = NodeStyle()
            n.set_style(nstyle)
            nstyle['size'] = 0
            nstyle['hz_line_width'] = 3
            nstyle['vt_line_width'] = 3
            nstyle['fgcolor'] = "Black"
            nstyle['shape'] = "square"
            name_face = AttrFace("name", fsize=14, ftype="Arial", fgcolor="black", penwidth=10, text_prefix=" ", text_suffix=" ")
            n.add_face(name_face, column=0, position="aligned")
            row_index = rownames.tolist().index(n.name)
            col = 1
            for i in xrange(10):
                col += 1
                n.add_face(CircleFace(5, color=get_color(abund, row_index, i)), column=col, position="aligned")
    return t, ts
开发者ID:alexwaldrop123,项目名称:bayesiansimulation,代码行数:53,代码来源:draw_sim_tree_with_matrix.py

示例9: draw_ete_tree

# 需要导入模块: from ete2 import TreeStyle [as 别名]
# 或者: from ete2.TreeStyle import branch_vertical_margin [as 别名]
    def draw_ete_tree(self, corpus, fontsize=5,
                      color_leafs=False,
                      save_newick=True, mode='c',
                      outputfile=None,
                      return_svg=True, show=False,
                      save=False):
        root = self.to_ete(labels=corpus.titles)

        def layout(node):
            if node.is_leaf():
                N = AttrFace("name", fsize=7)
                faces.add_face_to_node(faces.AttrFace("name","Arial",10, None), node, 0, position='branch-right')
                # problems: aligment of labels to branch, left padding of labels

        ts = TreeStyle()
        ts.mode = mode
        ts.show_leaf_name = False
        ts.scale = 120
        ts.show_scale = False
        ts.branch_vertical_margin = 10

        nstyle = NodeStyle()
        nstyle["fgcolor"] = "#0f0f0f"
        nstyle["size"] = 0
        nstyle["vt_line_color"] = "#0f0f0f"
        nstyle["hz_line_color"] = "#0f0f0f"
        nstyle["vt_line_width"] = 1
        nstyle["hz_line_width"] = 1
        nstyle["vt_line_type"] = 0
        nstyle["hz_line_type"] = 0

        for n in root.traverse():
           n.set_style(nstyle)
        
        ts.layout_fn = layout

        if outputfile:
            outputfile = os.path.expanduser(outputfile)

        if save_newick: # save tree in newick format for later manipulation in e.g. FigTree:
            root.write(outfile=os.path.splitext(outputfile)[0]+'.newick')

        if save:
            root.render(outputfile, tree_style=ts)
        if show:
            root.show(tree_style=ts) 
        if return_svg: # return the SVG as a string
            return root.render("%%return")[0]
开发者ID:akvankorlaar,项目名称:pystyl,代码行数:50,代码来源:dendrogram.py

示例10: get_tree_style

# 需要导入模块: from ete2 import TreeStyle [as 别名]
# 或者: from ete2.TreeStyle import branch_vertical_margin [as 别名]
def get_tree_style(scale=None, vertical_margin=None):

    """Setups the tree-style used when rendering the tree"""

    style = TreeStyle()
    style.show_leaf_name = False

    if scale:
        style.scale = scale

    style.show_border = True

    if vertical_margin:
        style.branch_vertical_margin = vertical_margin

    return style
开发者ID:Jakob37,项目名称:RASP,代码行数:18,代码来源:run_ete.py

示例11: drawete2PhylTree

# 需要导入模块: from ete2 import TreeStyle [as 别名]
# 或者: from ete2.TreeStyle import branch_vertical_margin [as 别名]
def drawete2PhylTree(treeFilePath):
    tree = Tree(treeFilePath)
    treeStyle = TreeStyle()
    treeStyle.show_scale = False
    #treeStyle.margin_left = 0
    #treeStyle.margin_right = 0
    #treeStyle.margin_top = 0
    #treeStyle.margin_bottom = 0
    #treeStyle.tree_width = treeWidth
    no_of_nodes = countNodes(tree)
    treeStyle.scale = 120#finalImageHeightinMM/no_of_nodes
    treeStyle.branch_vertical_margin = 10#finalImageHeightinMM/no_of_nodes
    #treeStyle.draw_aligned_faces_as_table = False
    tree = changeNodeStyle(tree)
    #tree.img_style["size"] = 30
    #tree.img_style["fgcolor"] = "blue"
    #tree.show(tree_style=treeStyle)
    tree.render("tree.PNG",tree_style=treeStyle,units="mm")
开发者ID:ashishjain1988,项目名称:Scripts,代码行数:20,代码来源:createPhyloTreeFromete2.py

示例12: render_tree_image

# 需要导入模块: from ete2 import TreeStyle [as 别名]
# 或者: from ete2.TreeStyle import branch_vertical_margin [as 别名]
	def render_tree_image(self, filename):
		def my_layout(node):
			name_faces = AttrFace("name", fsize=10, fgcolor = "#0000FF")
			faces.add_face_to_node(name_faces, node, column=0, position="branch-right")
		t = Tree("%s;" % self.newick_string(), format = 1)
		s = "0"	
		for n in t.iter_descendants():
			text = TextFace(s)
			if s == "0": s = "1"
			else: s = "0"
			text.fgcolor = "#FF0000";
			nstyle = NodeStyle()
			nstyle['size'] = 15
			nstyle['fgcolor'] = "#333"
			n.set_style(nstyle)
			n.add_face(text, column = 0, position = "branch-top")
		ts = TreeStyle()
		ts.rotation = 90
		ts.show_leaf_name = False
		ts.layout_fn = my_layout
		ts.margin_left = 0
		ts.branch_vertical_margin = 50
		ts.show_scale = False
		t.render(filename, tree_style = ts, w = 2000)
开发者ID:lbalbastre,项目名称:Huffman-python,代码行数:26,代码来源:HuffmanImpl.py

示例13: TreeStyle

# 需要导入模块: from ete2 import TreeStyle [as 别名]
# 或者: from ete2.TreeStyle import branch_vertical_margin [as 别名]
width = 600 # For other output args, see http://etetoolkit.org/docs/latest/tutorial/tutorial_drawing.html#rendering-trees-as-images

# Configure tree styles
ts = TreeStyle()
ts.show_leaf_name = True
ts.show_branch_length = True
ts.show_scale = False
ts.scale =  None

ts.mode = "c" # draw tree in circular style
ts.arc_start = 0
ts.arc_span = 360

if orientation == "top":
    ts.rotation = 90
    ts.branch_vertical_margin = 10 # 10 pixels between adjacent branches

# Remove the default small red spheres for each node
nstyle = NodeStyle()
nstyle["size"] = 0
for leaf in tree:
    k = leaf.name
    k = int(k)
    leaf.name = labels[k]

# Apply node styles to nodes
for n in tree.traverse():
   n.set_style(nstyle)

# Plot the tree
tree.show(tree_style=ts)
开发者ID:WheatonCS,项目名称:aGoodMystery,代码行数:33,代码来源:dendroToNewick.py

示例14: showTree

# 需要导入模块: from ete2 import TreeStyle [as 别名]
# 或者: from ete2.TreeStyle import branch_vertical_margin [as 别名]
def showTree(delimitation, scale = 500, render = False, fout = "", form = "svg", show_support = False):
	"""delimitation: species_setting class"""
	tree = delimitation.root
	style0 = NodeStyle()
	style0["fgcolor"] = "#000000"
	style0["vt_line_color"] = "#0000aa"
	style0["hz_line_color"] = "#0000aa"
	style0["vt_line_width"] = 2
	style0["hz_line_width"] = 2
	style0["vt_line_type"] = 0 
	style0["hz_line_type"] = 0
	style0["size"] = 0
	
	tree.clear_face()
	for node in tree.get_descendants():
		node.set_style(style0)
		node.img_style["size"] = 0
		node.clear_face()
	
	tree.set_style(style0)
	tree.img_style["size"] = 0
	
	style1 = NodeStyle()
	style1["fgcolor"] = "#000000"
	style1["vt_line_color"] = "#ff0000"
	style1["hz_line_color"] = "#0000aa"
	style1["vt_line_width"] = 2
	style1["hz_line_width"] = 2
	style1["vt_line_type"] = 0 
	style1["hz_line_type"] = 0
	style1["size"] = 0
	
	style2 = NodeStyle()
	style2["fgcolor"] = "#0f0f0f"
	style2["vt_line_color"] = "#ff0000"
	style2["hz_line_color"] = "#ff0000"
	style2["vt_line_width"] = 2
	style2["hz_line_width"] = 2
	style2["vt_line_type"] = 0 
	style2["hz_line_type"] = 0
	style2["size"] = 0
	
	for node in delimitation.active_nodes:
		node.set_style(style1)
		node.img_style["size"] = 0
		for des in node.get_descendants():
			des.set_style(style2)
			des.img_style["size"] = 0
	
	for node in delimitation.root.traverse(strategy='preorder'):
		if show_support and hasattr(node, "bs"):
			if node.bs == 0.0:
				node.add_face(TextFace("0", fsize = 8), column=0, position = "branch-top")
			else:
				node.add_face(TextFace("{0:.2f}".format(node.bs), fsize = 8), column=0, position = "branch-top")
			
	ts = TreeStyle()
	"""scale pixels per branch length unit"""
	ts.scale =  scale 
	ts.branch_vertical_margin = 7
	if render:
		tree.render(fout+"."+form, tree_style=ts)
	else:
		tree.show(tree_style=ts)
开发者ID:nishmadahal,项目名称:PTP,代码行数:66,代码来源:PTPLLH.py

示例15: cluster

# 需要导入模块: from ete2 import TreeStyle [as 别名]
# 或者: from ete2.TreeStyle import branch_vertical_margin [as 别名]

#.........这里部分代码省略.........

        plt.tight_layout()  # fixes margins

        ## Conversion to Newick/ETE
        # Stuff we need
        from scipy.cluster.hierarchy import average, linkage, to_tree
        #from hcluster import linkage, to_tree
        from ete2 import Tree, TreeStyle, NodeStyle

        # Change it to a distance matrix
        T = to_tree(Z)

        # ete2 section
        root = Tree()
        root.dist = 0
        root.name = "root"
        item2node = {T: root}

        to_visit = [T]
        while to_visit:
            node = to_visit.pop()
            cl_dist = node.dist /2.0
            for ch_node in [node.left, node.right]:
                if ch_node:
                    ch = Tree()
                    ch.dist = cl_dist
                    ch.name = str(ch_node.id)
                    item2node[node].add_child(ch)
                    item2node[ch_node] = ch
                    to_visit.append(ch_node)

        # This is the ETE tree structure
        tree = root
        ts = TreeStyle()
        ts.show_leaf_name = True
        ts.show_branch_length = True
        ts.show_scale = False
        ts.scale =  None
        if orientation == "top":
            ts.rotation = 90
            ts.branch_vertical_margin = 10 # 10 pixels between adjacent branches

        # Draws nodes as small red spheres of diameter equal to 10 pixels
        nstyle = NodeStyle()
        nstyle["size"] = 0

        # Replace the node labels
        for leaf in tree:
            k = leaf.name
            k = int(k)
            leaf.name = labels[k]

        # Apply node styles to nodes
        for n in tree.traverse():
           n.set_style(nstyle)

        # Convert the ETE tree to Newick
        newick = tree.write()
        f = open('C:\\Users\\Scott\\Documents\\GitHub\\d3-dendro\\newickStr.txt', 'w')
        f.write(newick)
        f.close()

        # Save the image as .png...
        from os import path, makedirs

        # Using ETE
        folder = pathjoin(session_manager.session_folder(), constants.RESULTS_FOLDER)
        if (not os.path.isdir(folder)):
            makedirs(folder)

        # saves dendrogram as a .png with pyplot
        plt.savefig(path.join(folder, constants.DENDROGRAM_PNG_FILENAME))
        plt.close()
        # if orientation == "top":
        #     plt.figure(figsize=(20,80))
        # else:
        #     plt.figure(figsize=(80,20))

        pdfPageNumber, score, inconsistentMax, maxclustMax, distanceMax, distanceMin, monocritMax, monocritMin, threshold = utility.generateDendrogram(
            fileManager)
        session['dengenerated'] = True
        labels = fileManager.getActiveLabels()

        inconsistentOp = "0 " + leq + " t " + leq + " " + str(inconsistentMax)
        maxclustOp = "2 " + leq + " t " + leq + " " + str(maxclustMax)
        distanceOp = str(distanceMin) + " " + leq + " t " + leq + " " + str(distanceMax)
        monocritOp = str(monocritMin) + " " + leq + " t " + leq + " " + str(monocritMax)

        thresholdOps = {"inconsistent": inconsistentOp, "maxclust": maxclustOp, "distance": distanceOp,
                        "monocrit": monocritOp}

        managers.utility.saveFileManager(fileManager)
        session_manager.cacheAnalysisOption()
        session_manager.cacheHierarchyOption()
        import random
        ver = random.random() * 100
        return render_template('cluster.html', labels=labels, pdfPageNumber=pdfPageNumber, score=score,
                               inconsistentMax=inconsistentMax, maxclustMax=maxclustMax, distanceMax=distanceMax,
                               distanceMin=distanceMin, monocritMax=monocritMax, monocritMin=monocritMin,
                               threshold=threshold, thresholdOps=thresholdOps, ver=ver)
开发者ID:bbrule,项目名称:Lexos,代码行数:104,代码来源:dendroToNewick.py


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