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


Python Tree.iter_leaves方法代码示例

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


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

示例1: check_hgt

# 需要导入模块: from ete3 import Tree [as 别名]
# 或者: from ete3.Tree import iter_leaves [as 别名]
def check_hgt(tree_path, taxid_dict, bootstrap_threshold=70.0):

    tree = Tree(tree_path)
    tree = remove_bad_nodes(tree, support_threshold=bootstrap_threshold)

    leaf_tags = get_tags_leaves(tree, taxid_dict)

    dpapi_leaf = None
    for leaf in tree.iter_leaves():
        if leaf_tags[leaf.name] == "dpapi":
            if not dpapi_leaf:
                dpapi_leaf = leaf
            else:
                print ("More than one Dpapi leaf!\n" + tree_path + "\n")

    farthest_node = dpapi_leaf.get_farthest_node(topology_only=True)[0]
    if farthest_node.up == tree:
        return False
    else:
        tree.set_outgroup(farthest_node.up)

    edited_tree_path = tree_path + "_edited.tree"
    tree.write(outfile=edited_tree_path)

    if check_sisters_bacteria(dpapi_leaf, leaf_tags) and check_sisters_bacteria(dpapi_leaf.up, leaf_tags):
        return True
    else:
        return False
开发者ID:AnnaNenarokova,项目名称:ngs,代码行数:30,代码来源:check_hgt_trees.py

示例2: get_example_tree

# 需要导入模块: from ete3 import Tree [as 别名]
# 或者: from ete3.Tree import iter_leaves [as 别名]
def get_example_tree():

    t = Tree()
    t.populate(8)

    # Node style handling is no longer limited to layout functions. You
    # can now create fixed node styles and use them many times, save them
    # or even add them to nodes before drawing (this allows to save and
    # reproduce an tree image design)

    # Set bold red branch to the root node
    style = NodeStyle()
    style["fgcolor"] = "#0f0f0f"
    style["size"] = 0
    style["vt_line_color"] = "#ff0000"
    style["hz_line_color"] = "#ff0000"
    style["vt_line_width"] = 8
    style["hz_line_width"] = 8
    style["vt_line_type"] = 0 # 0 solid, 1 dashed, 2 dotted
    style["hz_line_type"] = 0
    t.set_style(style)

    #Set dotted red lines to the first two branches
    style1 = NodeStyle()
    style1["fgcolor"] = "#0f0f0f"
    style1["size"] = 0
    style1["vt_line_color"] = "#ff0000"
    style1["hz_line_color"] = "#ff0000"
    style1["vt_line_width"] = 2
    style1["hz_line_width"] = 2
    style1["vt_line_type"] = 2 # 0 solid, 1 dashed, 2 dotted
    style1["hz_line_type"] = 2
    t.children[0].img_style = style1
    t.children[1].img_style = style1

    # Set dashed blue lines in all leaves
    style2 = NodeStyle()
    style2["fgcolor"] = "#000000"
    style2["shape"] = "circle"
    style2["vt_line_color"] = "#0000aa"
    style2["hz_line_color"] = "#0000aa"
    style2["vt_line_width"] = 2
    style2["hz_line_width"] = 2
    style2["vt_line_type"] = 1 # 0 solid, 1 dashed, 2 dotted
    style2["hz_line_type"] = 1
    for l in t.iter_leaves():
        l.img_style = style2

    ts = TreeStyle()
    ts.layout_fn = layout
    ts.show_leaf_name = False

    return t, ts
开发者ID:AlishaMechtley,项目名称:ete,代码行数:55,代码来源:node_style.py

示例3: replace_names

# 需要导入模块: from ete3 import Tree [as 别名]
# 或者: from ete3.Tree import iter_leaves [as 别名]
def replace_names(tree_file, replacer):
    tree = Tree(tree_file)
    errored = False
    for tip in tree.iter_leaves():
        try:
            newname = replacer[tip.name.strip("'")]
            tip.name = newname
        except KeyError as exc:
            print("ERROR: Tip is missing from replacement file: '{}'".format(
                  tip.name), file=sys.stderr)
            errored = True
    return tree.write()
开发者ID:lteasdale,项目名称:ltbio,代码行数:14,代码来源:tree_renamer_no_errors.py

示例4: get_example_tree

# 需要导入模块: from ete3 import Tree [as 别名]
# 或者: from ete3.Tree import iter_leaves [as 别名]
def get_example_tree():
    t = Tree("((a,b),c);")

    right_c0_r0 = TextFace("right_col0_row0")
    right_c0_r1 = TextFace("right_col0_row1")
    right_c1_r0 = TextFace("right_col1_row0")
    right_c1_r1 = TextFace("right_col1_row1")
    right_c1_r2 = TextFace("right_col1_row2")

    top_c0_r0 = TextFace("top_col0_row0")
    top_c0_r1 = TextFace("top_col0_row1")

    bottom_c0_r0 = TextFace("bottom_col0_row0")
    bottom_c1_r0 = TextFace("bottom_col1_row0")

    aligned_c0_r0 = TextFace("aligned_col0_row0")
    aligned_c0_r1 = TextFace("aligned_col0_row1")

    aligned_c1_r0 = TextFace("aligned_col1_row0")
    aligned_c1_r1 = TextFace("aligned_col1_row1")


    t.add_face(right_c0_r1, column=1, position="branch-right")
    t.add_face(right_c0_r0, column=0, position="branch-right")

    t.add_face(right_c1_r2, column=2, position="branch-right")
    t.add_face(right_c1_r1, column=1, position="branch-right")
    t.add_face(right_c1_r0, column=0, position="branch-right")

    t.add_face(top_c0_r1, column=1, position="branch-top")
    t.add_face(top_c0_r0, column=0, position="branch-top")

    t.add_face(bottom_c0_r0, column=0, position="branch-bottom")
    t.add_face(bottom_c1_r0, column=1, position="branch-bottom")

    for leaf in t.iter_leaves():
        leaf.add_face(aligned_c0_r1, 0, "aligned")
        leaf.add_face(aligned_c0_r0, 0, "aligned")
        leaf.add_face(aligned_c1_r1, 0, "aligned")
        leaf.add_face(aligned_c1_r0, 0, "aligned")

    return t, TreeStyle()
开发者ID:AlishaMechtley,项目名称:ete,代码行数:44,代码来源:face_grid.py

示例5: Tree

# 需要导入模块: from ete3 import Tree [as 别名]
# 或者: from ete3.Tree import iter_leaves [as 别名]
#!/usr/bin/env python

from ete3 import Tree
import sys

tree = sys.argv[1]
root = sys.argv[2]

t = Tree(tree)
t.set_outgroup(t & root)

for leaf in t.iter_leaves():
	cols = leaf.name.split("|")
	if cols[0] == 'EBOV':
		leaf.name = cols[1]
	elif cols[1] == 'SLE':
		leaf.name = cols[0]

print t.write()


开发者ID:meren,项目名称:ebov,代码行数:21,代码来源:root_and_deheader.py

示例6: Tree

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

# Creates a random tree with 10,000 leaf nodes
tree = Tree()
tree.populate(10000)
# This code should be faster
t1 = time.time()
for leaf in tree.iter_leaves():
    if "aw" in leaf.name:
        print "found a match:", leaf.name,
        break
print "Iterating: ellapsed time:", time.time() - t1
# This slower
t1 = time.time()
for leaf in tree.get_leaves():
    if "aw" in leaf.name:
        print "found a match:", leaf.name,
        break
print "Getting: ellapsed time:", time.time() - t1
# Results in something like:
# found a match: guoaw Iterating: ellapsed time: 0.00436091423035 secs
# found a match: guoaw Getting: ellapsed time: 0.124316930771 secs
开发者ID:abdo3a,项目名称:ete,代码行数:25,代码来源:iterators.py

示例7: len

# 需要导入模块: from ete3 import Tree [as 别名]
# 或者: from ete3.Tree import iter_leaves [as 别名]
#  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
# values. For example, we can calculate some values and store them
# within nodes.
#
# Let's detect leaf nodes under "ancestor" with distance higher thatn
# 1. Note that I'm traversing a subtree which starts from "ancestor"
matches = [leaf for leaf in ancestor.traverse() if leaf.dist>1.0]
# And save this pre-computed information into the ancestor node
ancestor.add_feature("long_branch_nodes", matches)
# Prints the precomputed nodes
print "These are nodes under ancestor with long branches", \
    [n.name for n in ancestor.long_branch_nodes]
# We can also use the add_feature() method to dynamically add new features.
label = raw_input("custom label:")
value = raw_input("custom label value:")
开发者ID:AlishaMechtley,项目名称:ete,代码行数:33,代码来源:add_features.py

示例8: expression

# 需要导入模块: from ete3 import Tree [as 别名]
# 或者: from ete3.Tree import iter_leaves [as 别名]
    help=('A regular expression (for taxa names). The lowest common parent of '
          'any matching taxa will be used as an outgroup.'))

parser.add_argument(
    '--verbose', action='store_true',
    help=('Print information about the outgroup (if any) taxa to standard '
          'error'))

args = parser.parse_args()

tree = Tree(args.treeFile.read())

if args.outgroupRegex:
    from re import compile
    regex = compile(args.outgroupRegex)
    taxa = [leaf.name for leaf in tree.iter_leaves() if regex.match(leaf.name)]

    if taxa:
        ca = tree.get_common_ancestor(taxa)
        if args.verbose:
            print('Taxa for outgroup:', taxa, file=sys.stderr)
            print('Common ancestor:', ca.name, file=sys.stderr)
            print('Common ancestor is tree:', tree == ca, file=sys.stderr)

        if len(taxa) == 1:
            tree.set_outgroup(tree & taxa[0])
        else:
            if ca == tree:
                tree.set_outgroup(tree.get_midpoint_outgroup())
            else:
                tree.set_outgroup(tree.get_common_ancestor(taxa))
开发者ID:acorg,项目名称:dark-matter,代码行数:33,代码来源:newick-to-ascii.py


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