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


Python TreeStyle.branch_vertical_margin方法代码示例

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


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

示例1: _get_motif_tree

# 需要导入模块: from ete3 import TreeStyle [as 别名]
# 或者: from ete3.TreeStyle import branch_vertical_margin [as 别名]
def _get_motif_tree(tree, data, circle=True, vmin=None, vmax=None):
    try:
        from ete3 import Tree, NodeStyle, TreeStyle
    except ImportError:
        print("Please install ete3 to use this functionality")
        sys.exit(1)

    t = Tree(tree)
    
    # Determine cutoff for color scale
    if not(vmin and vmax):
        for i in range(90, 101):
            minmax = np.percentile(data.values, i)
            if minmax > 0:
                break
    if not vmin:
        vmin = -minmax
    if not vmax:
        vmax = minmax
    
    norm = Normalize(vmin=vmin, vmax=vmax, clip=True)
    mapper = cm.ScalarMappable(norm=norm, cmap="RdBu_r")
    
    m = 25 / data.values.max()
    
    for node in t.traverse("levelorder"):
        val = data[[l.name for l in node.get_leaves()]].values.mean()
        style = NodeStyle()
        style["size"] = 0
        
        style["hz_line_color"] = to_hex(mapper.to_rgba(val))
        style["vt_line_color"] = to_hex(mapper.to_rgba(val))
        
        v = max(np.abs(m * val), 5)
        style["vt_line_width"] = v
        style["hz_line_width"] = v

        node.set_style(style)
    
    ts = TreeStyle()

    ts.layout_fn = _tree_layout
    ts.show_leaf_name= False
    ts.show_scale = False
    ts.branch_vertical_margin = 10

    if circle:
        ts.mode = "c"
        ts.arc_start = 180 # 0 degrees = 3 o'clock
        ts.arc_span = 180
    
    return t, ts
开发者ID:simonvh,项目名称:gimmemotifs,代码行数:54,代码来源:plot.py

示例2: NodeStyle

# 需要导入模块: from ete3 import TreeStyle [as 别名]
# 或者: from ete3.TreeStyle import branch_vertical_margin [as 别名]
circular_style.show_branch_length = True
circular_style.show_branch_support = True
t.render("mytree.png", tree_style=circular_style)


nstyle = NodeStyle()
nstyle["hz_line_width"] = 3
nstyle["vt_line_width"] = 3

# Applies the same static style to all nodes in the tree. Note that,
# if "nstyle" is modified, changes will affect to all nodes
for n in t.traverse():
   n.set_style(nstyle)



ts = TreeStyle()
ts.branch_vertical_margin = 10
ts.show_leaf_name = True
ts.rotation = 90
ts.scale=100
t.render("tree_test100.png",tree_style=ts)

ts.scale=1000
t.render("tree_test1000.png",tree_style=ts)
## compare to

#t = Tree( '("[a,b]",c);' )
#t.show()

# []
开发者ID:tristanlmiller,项目名称:Topic-Ontology,代码行数:33,代码来源:wikitree.py

示例3: showTree

# 需要导入模块: from ete3 import TreeStyle [as 别名]
# 或者: from ete3.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()
    tree._faces = _FaceAreas()
    for node in tree.get_descendants():
        node.set_style(style0)
        node.img_style["size"] = 0
        node._faces = _FaceAreas()
        #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:zhangjiajie,项目名称:PTP,代码行数:68,代码来源:ptpllh.py

示例4: run

# 需要导入模块: from ete3 import TreeStyle [as 别名]
# 或者: from ete3.TreeStyle import branch_vertical_margin [as 别名]
def run(args):
    if args.text_mode:
        from ete3 import Tree
        for tindex, tfile in enumerate(args.src_tree_iterator):
            #print tfile
            if args.raxml:
                nw = re.sub(":(\d+\.\d+)\[(\d+)\]", ":\\1[&&NHX:support=\\2]", open(tfile).read())
                t = Tree(nw)
            else:
                t = Tree(tfile)

            print(t.get_ascii(show_internal=args.show_internal_names,
                              attributes=args.show_attributes))
        return

    import random
    import re
    import colorsys
    from collections import defaultdict
    from ete3 import (Tree, PhyloTree, TextFace, RectFace, faces, TreeStyle,
                         add_face_to_node, random_color)

    global FACES

    if args.face:
        FACES = parse_faces(args.face)
    else:
        FACES = []

    # VISUALIZATION
    ts = TreeStyle()
    ts.mode = args.mode
    ts.show_leaf_name = True
    ts.tree_width = args.tree_width


    for f in FACES:
        if f["value"] == "@name":
            ts.show_leaf_name = False
            break

    if args.as_ncbi:
        ts.show_leaf_name = False
        FACES.extend(parse_faces(
            ['value:@sci_name, size:10, fstyle:italic',
             'value:@taxid, color:grey, size:6, format:" - %s"',
             'value:@sci_name, color:steelblue, size:7, pos:b-top, nodetype:internal',
             'value:@rank, color:indianred, size:6, pos:b-bottom, nodetype:internal',
         ]))


    if args.alg:
        FACES.extend(parse_faces(
            ['value:@sequence, size:10, pos:aligned, ftype:%s' %args.alg_type]
         ))

    if args.heatmap:
        FACES.extend(parse_faces(
            ['value:@name, size:10, pos:aligned, ftype:heatmap']
         ))

    if args.bubbles:
        for bubble in args.bubbles:
            FACES.extend(parse_faces(
                ['value:@%s, pos:float, ftype:bubble, opacity:0.4' %bubble,
             ]))

    ts.branch_vertical_margin = args.branch_separation
    if args.show_support:
        ts.show_branch_support = True
    if args.show_branch_length:
        ts.show_branch_length = True
    if args.force_topology:
        ts.force_topology = True
    ts.layout_fn = lambda x: None

    for tindex, tfile in enumerate(args.src_tree_iterator):
        #print tfile
        if args.raxml:
            nw = re.sub(":(\d+\.\d+)\[(\d+)\]", ":\\1[&&NHX:support=\\2]", open(tfile).read())
            t = PhyloTree(nw)
        else:
            t = PhyloTree(tfile)


        if args.alg:
            t.link_to_alignment(args.alg, alg_format=args.alg_format)

        if args.heatmap:
            DEFAULT_COLOR_SATURATION = 0.3
            BASE_LIGHTNESS = 0.7
            def gradient_color(value, max_value, saturation=0.5, hue=0.1):
                def rgb2hex(rgb):
                    return '#%02x%02x%02x' % rgb
                def hls2hex(h, l, s):
                    return rgb2hex( tuple([int(x*255) for x in colorsys.hls_to_rgb(h, l, s)]))

                lightness = 1 - (value * BASE_LIGHTNESS) / max_value
                return hls2hex(hue, lightness, DEFAULT_COLOR_SATURATION)

#.........这里部分代码省略.........
开发者ID:Ward9250,项目名称:ete,代码行数:103,代码来源:ete_view.py


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