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


Python TreeStyle.show_branch_length方法代码示例

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


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

示例1: get_example_tree

# 需要导入模块: from ete3 import TreeStyle [as 别名]
# 或者: from ete3.TreeStyle import show_branch_length [as 别名]
def get_example_tree():
    # Random tree
    t = Tree()
    t.populate(20, random_branches=True)

    # Some random features in all nodes
    for n in t.traverse():
        n.add_features(weight=random.randint(0, 50))

    # Create an empty TreeStyle
    ts = TreeStyle()

    # Set our custom layout function
    ts.layout_fn = layout

    # Draw a tree
    ts.mode = "c"

    # We will add node names manually
    ts.show_leaf_name = False
    # Show branch data
    ts.show_branch_length = True
    ts.show_branch_support = True

    return t, ts
开发者ID:cancerconnector,项目名称:clonal-evolution,代码行数:27,代码来源:bubble_tree_example.py

示例2: balanceplot

# 需要导入模块: from ete3 import TreeStyle [as 别名]
# 或者: from ete3.TreeStyle import show_branch_length [as 别名]
def balanceplot(balances, tree,
                layout=None,
                mode='c'):
    """ Plots balances on tree.

    Parameters
    ----------
    balances : np.array
        A vector of internal nodes and their associated real-valued balances.
        The order of the balances will be assumed to be in level order.
    tree : skbio.TreeNode
        A strictly bifurcating tree defining a hierarchical relationship
        between all of the features within `table`.
    layout : function, optional
        A layout for formatting the tree visualization. Must take a
        `ete.tree` as a parameter.
    mode : str
        Type of display to show the tree. ('c': circular, 'r': rectangular).

    Note
    ----
    The `tree` is assumed to strictly bifurcating and
    whose tips match `balances.

    See Also
    --------
    TreeNode.levelorder
    """
    # The names aren't preserved - let's pray that the topology is consistent.
    ete_tree = Tree(str(tree))
    # Some random features in all nodes
    i = 0
    for n in ete_tree.traverse():
        if not n.is_leaf():
            n.add_features(weight=balances[-i])
            i += 1

    # Create an empty TreeStyle
    ts = TreeStyle()

    # Set our custom layout function
    if layout is None:
        ts.layout_fn = default_layout
    else:
        ts.layout_fn = layout
    # Draw a tree
    ts.mode = mode

    # We will add node names manually
    ts.show_leaf_name = False
    # Show branch data
    ts.show_branch_length = True
    ts.show_branch_support = True

    return ete_tree, ts
开发者ID:mortonjt,项目名称:canvas,代码行数:57,代码来源:balances.py

示例3: get_tree_style

# 需要导入模块: from ete3 import TreeStyle [as 别名]
# 或者: from ete3.TreeStyle import show_branch_length [as 别名]
def get_tree_style():
    ts = TreeStyle()
    # ts.mode = 'c'
    ts.margin_top = 10
    ts.margin_bottom = 10
    ts.margin_left = 10
    ts.margin_right = 10
    ts.show_leaf_name = False
    ts.show_branch_length = False
    ts.show_branch_support = False
    ts.show_scale = False
    title = TextFace("     Tax Assignment Tree", fsize=10)
    title.hz_align = 2
    title.vt_align = 2
    ts.title.add_face(TextFace(" "), column=0)
    ts.title.add_face(TextFace(" "), column=0)
    ts.title.add_face(title, column=0)
    return ts
开发者ID:tianyabeef,项目名称:real_amplicon,代码行数:20,代码来源:02_plot_tax_tree.py

示例4: render_tree

# 需要导入模块: from ete3 import TreeStyle [as 别名]
# 或者: from ete3.TreeStyle import show_branch_length [as 别名]
def render_tree(tree, fname):
    # Generates tree snapshot
    npr_nodestyle = NodeStyle()
    npr_nodestyle["fgcolor"] = "red"
    for n in tree.traverse():
        if hasattr(n, "nodeid"):
            n.set_style(npr_nodestyle)
    ts = TreeStyle()
    ts.show_leaf_name = True
    ts.show_branch_length = True
    ts.show_branch_support = True
    ts.mode = "r"
    iterface = faces.TextFace("iter")
    ts.legend.add_face(iterface, 0)

    tree.dist = 0
    tree.sort_descendants()
    tree.render(fname, tree_style=ts, w=700)
开发者ID:Ward9250,项目名称:ete,代码行数:20,代码来源:utils.py

示例5: newick_to_linkage

# 需要导入模块: from ete3 import TreeStyle [as 别名]
# 或者: from ete3.TreeStyle import show_branch_length [as 别名]
def newick_to_linkage(filePath):
    """ converts newick tree to scipy linkage matrix """
    tree                   = ClusterTree(filePath)
    leaves                 = tree.get_leaf_names()
    ts                     = TreeStyle()
    ts.show_leaf_name      = True
    ts.show_branch_length  = True
    ts.show_branch_support = True

    idx_dict = {}
    idx = 0
    for leaf in leaves:
        idx_dict[leaf] = idx
        idx += 1

    idx_labels = [idx_dict.keys()[idx_dict.values().index(i)] for i in range(len(idx_dict))]

    dmat = np.zeros((len(leaves), len(leaves))) # FIXME need to understand

    for leaf1, leaf2 in combinations(leaves, 2):
        d = tree.get_distance(leaf1, leaf2)
        dmat[idx_dict[leaf1], idx_dict[leaf2]] = dmat[idx_dict[leaf2], idx_dict[leaf1]] = d

    schlink = sch.linkage(scipy.spatial.distance.squareform(dmat),method='average',metric='euclidean')
开发者ID:Wangmoaza,项目名称:tetra,代码行数:26,代码来源:clustering.py

示例6: get_default_tree_style

# 需要导入模块: from ete3 import TreeStyle [as 别名]
# 或者: from ete3.TreeStyle import show_branch_length [as 别名]
def get_default_tree_style(color_dict):
    ts = TreeStyle()
    ts.mode = "c"
    # ts.layout_fn = layout
    ts.margin_top = 50
    ts.margin_bottom = 0
    ts.margin_left = 50
    ts.margin_right = 50
    ts.show_scale = False
    ts.show_leaf_name = False
    ts.show_branch_length = False
    ts.show_branch_support = False
    for p, c in color_dict.iteritems():
        ts.legend.add_face(TextFace("    ", fsize=30), column=0)
        ts.legend.add_face(CircleFace(10, c), column=1)
        ts.legend.add_face(TextFace("   %s" % p, fsize=30), column=2)
    legend_margin_line = 5
    while legend_margin_line:
        ts.legend.add_face(TextFace(" "), column=0)
        ts.legend.add_face(TextFace(" "), column=1)
        ts.legend.add_face(TextFace(" "), column=2)
        legend_margin_line -= 1
    ts.legend_position = 3
    return ts
开发者ID:tianyabeef,项目名称:real_amplicon,代码行数:26,代码来源:02_plot_phylo_tree.py

示例7: open

# 需要导入模块: from ete3 import TreeStyle [as 别名]
# 或者: from ete3.TreeStyle import show_branch_length [as 别名]
from ete3 import Tree,TreeStyle,NodeStyle
import os
for tree in [file for file in os.listdir('.') if file and file.endswith('_phyml_tree.txt')]:
    #print tree
    try:
        with open( tree, 'r') as f:  # FIXME boot_trees verus phyml_tree
            t = Tree(open(tree,'r').read())
            ts = TreeStyle()
            ns = NodeStyle()
            ns['size']=0
            ts.show_leaf_name = True
            ts.show_branch_length = False
            ts.show_branch_support = True
            for n in t.traverse():
                n.set_style(ns)
            #t.show(tree_style=ts)
            t.render( os.getcwd()+'/'+tree.replace('_phyml_tree.txt', '.png'),tree_style = ts)
    except:
        pass
开发者ID:jlevy44,项目名称:Joshua-Levy-Synteny-Analysis,代码行数:21,代码来源:outputTreeTest.py

示例8: open

# 需要导入模块: from ete3 import TreeStyle [as 别名]
# 或者: from ete3.TreeStyle import show_branch_length [as 别名]
"""

from ete3 import Tree, TreeStyle, NodeStyle

with open('/Users/diyadas/cdips/Topic-Ontology/SimpleWikiTree_u.txt','r') as f:
    treestr = f.readlines()[0]    
    

t = Tree( treestr.rstrip(),format=8)

circular_style = TreeStyle()
circular_style.mode = "c" # draw tree in circular mode
circular_style.scale = 120
circular_style.show_leaf_name = True
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)


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

示例9: TreeStyle

# 需要导入模块: from ete3 import TreeStyle [as 别名]
# 或者: from ete3.TreeStyle import show_branch_length [as 别名]
node_cur = root

'''#######################
 Tree Style Begin
'''
ts = TreeStyle()
ts.title.add_face(TextFace("Tree example", fsize=8), column=0)
ts.scale = 50
ts.mode = 'r'

# left or right
ts.orientation = 1

ts.rotation = 270
ts.show_leaf_name = False
ts.show_branch_length = True
#ts.show_branch_length = True
'''
 Tree Style End
#######################'''




'''#######################
 Node Style Begin
'''
ns_root = NodeStyle()
ns_root["size"] = 10
ns_root['fgcolor'] = "red"
开发者ID:joe8767,项目名称:treeDrawing,代码行数:32,代码来源:lineageTree.py

示例10: balancetest

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

#.........这里部分代码省略.........
        these could be strings or integers denoting which group a sample
        belongs to.  It must be the same length as the samples in `table`.
        The index must be the same on `table` and `grouping` but need not be
        in the same order.
    tree : skbio.TreeNode
        A strictly bifurcating tree defining a hierarchical relationship
        between all of the features within `table`
    significance_test : function, optional
        A statistical significance function to test for significance between
        classes.  This function must be able to accept at least two 1D
        array_like arguments of floats and returns a test statistic and a
        p-value, or a single statistic. By default ``scipy.stats.f_oneway``
        is used.
    layout : function, optional
        A layout for formatting the tree visualization. Must take a
        `ete.tree` as a parameter.
    mode : str
        Type of display to show the tree. ('c': circular, 'r': rectangular).

    Returns
    -------
    ete_tree : ete.Tree
        ETE tree converted from the `skbio.TreeNode` object
    ts : ete.TreeStyle
        ETE tree style used for formatting the visualized tree,
        with the test statistic plotted on each of the internal nodes.

    Note
    ----
    The `skbio.TreeNode` is assumed to strictly bifurcating and
    whose tips match `table`.  Also, it is assumed that none
    of the values in `table` are zero.  Replace with a pseudocount
    if necessary.

    See also
    --------
    skbio.TreeNode.bifurcate
    skbio.stats.composition.ilr
    skbio.stats.multiplicative_replacement
    scipy.stats.f_oneway
    """

    if np.any(table <= 0):
        raise ValueError('Cannot handle zeros or negative values in `table`. '
                         'Use pseudo counts or ``multiplicative_replacement``.'
                         )

    if significance_test is None:
        significance_test = scipy.stats.f_oneway

    sorted_features = [n.name for n in tree.tips()][::-1]
    if len(sorted_features) != len(table.columns):
        raise ValueError('The number of tips (%d) in the tree must be equal '
                         'to the number features in the table (%d).' %
                         (len(sorted_features), len(table.columns)))
    table = table.reindex(columns=sorted_features)

    mat, cats = check_table_grouping(table, grouping)

    basis, nodes = phylogenetic_basis(tree)
    ilr_coords = ilr(mat, basis=basis)

    ete_tree = Tree(str(tree))

    _cats = set(cats)
    i = 0
    for n in ete_tree.traverse():
        if not n.is_leaf():
            diffs = [ilr_coords[(cats == x).values, i] for x in _cats]

            stat = significance_test(*diffs)
            if len(stat) == 2:
                n.add_features(weight=-np.log(stat[1]))
            elif len(stat) == 1:
                n.add_features(weight=stat)
            else:
                raise ValueError(
                    "Too many arguments returned by %s" %
                    significance_test.__name__)
            i += 1

    # Create an empty TreeStyle
    ts = TreeStyle()

    # Set our custom layout function
    if layout is None:
        ts.layout_fn = default_layout
    else:
        ts.layout_fn = layout

    # Draw a tree
    ts.mode = mode

    # We will add node names manually
    ts.show_leaf_name = False
    # Show branch data
    ts.show_branch_length = True
    ts.show_branch_support = True

    return ete_tree, ts
开发者ID:mortonjt,项目名称:canvas,代码行数:104,代码来源:balances.py

示例11: Tree

# 需要导入模块: from ete3 import TreeStyle [as 别名]
# 或者: from ete3.TreeStyle import show_branch_length [as 别名]
    args, unknown = parser.parse_known_args()
    
    t = Tree(args.i)
    ts = TreeStyle()
    
    if args.colorleaf:
        
        with open(args.colorleaf,'rU') as file_map:
            for line in file_map:
                if line:
                    leaf_color = list(map(str.strip,line.split('\t')))
                    print leaf_color
                    for leaf in t.get_leaves_by_name(leaf_color[0]):
                        leaf.set_style(NodeStyle())
                        
                        if leaf.name == leaf_color[0]:
                            leaf.img_style["bgcolor"] = leaf_color[1]
                        
    ts.show_leaf_name = not args.noleaf
    ts.show_branch_length = not args.nolength
    ts.show_branch_support = not args.nosupport

    if args.circular:
        ts.mode = "c"
        
    ext="svg"
    if args.ext:
       ext = args.ext
       
    t.render(args.o+ext, w=183, tree_style=ts, units="mm")
开发者ID:C3BI-pasteur-fr,项目名称:phylogeny.fr_v2,代码行数:32,代码来源:ETETree.py

示例12: run

# 需要导入模块: from ete3 import TreeStyle [as 别名]
# 或者: from ete3.TreeStyle import show_branch_length [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.show_branch_length方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。