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


Python TreeStyle.force_topology方法代码示例

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


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

示例1: get_tree_style

# 需要导入模块: from ete2 import TreeStyle [as 别名]
# 或者: from ete2.TreeStyle import force_topology [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

示例2: setTreeStyle

# 需要导入模块: from ete2 import TreeStyle [as 别名]
# 或者: from ete2.TreeStyle import force_topology [as 别名]
def setTreeStyle(style, layoutfunction):
    #consolidate options for showing trees
    #pass in string "circle" or "rect" and a layout function
    I = TreeStyle()
    if style == "circle":
        I.tree_width = 1200
        I.layout_fn = layoutfunction
        I.show_branch_length = False
        #I.show_branch_support = True
        I.show_leaf_name = False
        I.mode = "c"
        I.force_topology = True
        #I.legend_position = 3
        I.extra_branch_line_type = 1
        I.guiding_lines_type = 1
        I.guiding_lines_color = "#666666"
        I.extra_branch_line_color = "#666666"
        I.optimal_scale_level = "full"
        I.root_opening_factor = 0
        
    elif style =="rect":
        I = TreeStyle()
        I.layout_fn = layoutfunction
        I.show_leaf_name = False
        I.force_topology = True
        I.optimal_scale_level = "semi"
        
    else:
        I.layout_fn = layoutfunction
        I.show_leaf_name = False
        I.force_topology = True
        I.optimal_scale_level = "semi"
    return I

    

    
开发者ID:michaelalfaro,项目名称:tools,代码行数:35,代码来源:phy_utils.py

示例3: get_tree_style

# 需要导入模块: from ete2 import TreeStyle [as 别名]
# 或者: from ete2.TreeStyle import force_topology [as 别名]
def get_tree_style(tree, metadata, colors):
    assert isinstance(tree, TreeNode)
    ts = TreeStyle()
    ts.mode = "c"
    ts.show_leaf_name = False
    ts.show_scale = False
    ts.show_branch_length = False
    ts.force_topology = True
    ts.optimal_scale_level = "mid"
    get_node_styles(tree, metadata, colors)

    for site, color in colors.items():
        if 'Gastro' in site:
            site = "GI"
        ts.legend.add_face(CircleFace(7, color), column=0)
        ts.legend.add_face(TextFace(" %s" % site, fsize=20), column=1)
    return ts
开发者ID:alexwaldrop123,项目名称:bayesiansimulation,代码行数:19,代码来源:draw_dacc_tree.py

示例4: EvolTree

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


tree = EvolTree("data/S_example/measuring_S_tree.nw")
tree.link_to_alignment("data/S_example/alignment_S_measuring_evol.fasta")

print tree

print "\n Running free-ratio model with calculation of ancestral sequences..."

tree.run_model("fb_anc")
# tree.link_to_evol_model('/tmp/ete2-codeml/fb_anc/out', 'fb_anc')

I = TreeStyle()
I.force_topology = False
I.draw_aligned_faces_as_table = True
I.draw_guiding_lines = True
I.guiding_lines_type = 2
I.guiding_lines_color = "#CCCCCC"
for n in sorted(tree.get_descendants() + [tree], key=lambda x: x.node_id):
    if n.is_leaf():
        continue
    anc_face = faces.SequenceFace(n.sequence, "aa", fsize=10, bg_colors={})
    I.aligned_foot.add_face(anc_face, 1)
    I.aligned_foot.add_face(faces.TextFace("node_id: #%d " % (n.node_id), fsize=8), 0)
print "display result of bs_anc model, with ancestral amino acid sequences."
tree.show(tree_style=I)

print "\nThe End."
开发者ID:jerryatmda,项目名称:ete,代码行数:32,代码来源:6_ancestral_sequence.py

示例5: layout

# 需要导入模块: from ete2 import TreeStyle [as 别名]
# 或者: from ete2.TreeStyle import force_topology [as 别名]
            for child in node.children[:-options.children]:
                child.detach()

    def layout(node):
        def color(node):
            if type(node.item) is Value:
                return "Red"
            elif type(node.item) is Parameter:
                return "Yellow"
            elif node.item.leaf:
                return "Green"
            else:
                return "RoyalBlue"
        N = AttrFace("name", fsize=14, fgcolor="black")
        faces.add_face_to_node(N, node, 0)
        C = CircleFace(radius=node.weight, color=color(node), style="sphere")
        C.opacity = 0.3
        faces.add_face_to_node(C, node, 0, position="float")

    ts = TreeStyle()
    ts.layout_fn = layout
    ts.mode = "c"
    ts.show_leaf_name = False
    ts.force_topology = True
    root.node.show(tree_style=ts)
else:
    root.print_data(sort_field=options.field, reverse=options.reverse)



开发者ID:justin-sousa-kanban,项目名称:google-analytiception,代码行数:29,代码来源:analyse.py

示例6: run

# 需要导入模块: from ete2 import TreeStyle [as 别名]
# 或者: from ete2.TreeStyle import force_topology [as 别名]
def run(args):
    if args.text_mode:
        from ete2 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 ete2 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(map(lambda x: int(x*255), colorsys.hls_to_rgb(h, l, s))))

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

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


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