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


Python Tree.get_children方法代码示例

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


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

示例1: len

# 需要导入模块: from ete3 import Tree [as 别名]
# 或者: from ete3.Tree import get_children [as 别名]
					# NB. using the node.prune() function is too slow

					# actualize "mergedInd" feature of new leaf
					newLeaf[0].mergedInd = mergedLeaves

				else:

					# populate "mergedInd" feature for future SFS
					mergedLeaves = ""
					for l in node.iter_leaves():
						mergedLeaves = mergedLeaves+" "+l.name

					# collapse the subtree
					newLeaf = t.get_farthest_leaf()
					for child in t.get_children():
						child.detach()
					node.add_child(newLeaf[0], newLeaf[0].name, newLeaf[1])

					# actualize "mergedInd" feature of new leaf
					newLeaf[0].mergedInd = mergedLeaves

nTrueSpecies = len(t)
sys.stdout.write('C')

#======================================================#
# COMPUTE & EXPORT the SFS (full names & numerical)

f = open(osfs+"_allinds.txt", 'w+')
fn = open(osfs, 'w+')
fn.write("Tip_label\t" + "\t".join("Isl_"+str(x) for x in range(0, nPops)) + "\n")
开发者ID:sunyatin,项目名称:vanaprabhava,代码行数:32,代码来源:VPB.py

示例2: Tree

# 需要导入模块: from ete3 import Tree [as 别名]
# 或者: from ete3.Tree import get_children [as 别名]
from ete3 import Tree
t = Tree()
# We create a random tree topology
t.populate(15)
print t
print t.children
print t.get_children()
print t.up
print t.name
print t.dist
print t.is_leaf()
print t.get_tree_root()
print t.children[0].get_tree_root()
print t.children[0].children[0].get_tree_root()
# You can also iterate over tree leaves using a simple syntax
for leaf in t:
      print leaf.name
开发者ID:Tancata,项目名称:phylo,代码行数:19,代码来源:etetest.py

示例3: __init__

# 需要导入模块: from ete3 import Tree [as 别名]
# 或者: from ete3.Tree import get_children [as 别名]
class exponential_mixture:
    """ML search PTP, to use: __init__(), search() and count_species()"""
    def __init__(self, tree, sp_rate = 0, fix_sp_rate = False, max_iters = 20000, min_br = 0.0001):
        self.min_brl = min_br
        self.tree = Tree(tree, format = 1)
        self.tree.resolve_polytomy(recursive=True)
        self.tree.dist = 0.0
        self.fix_spe_rate = fix_sp_rate
        self.fix_spe = sp_rate
        self.max_logl = float("-inf") 
        self.max_setting = None
        self.null_logl = 0.0
        self.null_model()
        self.species_list = None
        self.counter = 0
        self.setting_set = set([])
        self.max_num_search = max_iters


    def null_model(self):
        coa_br = []
        all_nodes = self.tree.get_descendants()
        for node in all_nodes:
            if node.dist > self.min_brl:
                coa_br.append(node.dist)
        e1 = exp_distribution(coa_br)
        self.null_logl = e1.sum_log_l()
        return e1.rate


    def __compare_node(self, node):
        return node.dist


    def re_rooting(self):
        node_list = self.tree.get_descendants()
        node_list.sort(key=self.__compare_node)
        node_list.reverse()
        rootnode = node_list[0]
        self.tree.set_outgroup(rootnode)
        self.tree.dist = 0.0


    def comp_num_comb(self):
        for node in self.tree.traverse(strategy='postorder'):
            if node.is_leaf():
                node.add_feature("cnt", 1.0)
            else:
                acum = 1.0
                for child in node.get_children():
                    acum = acum * child.cnt
                acum = acum + 1.0
                node.add_feature("cnt", acum)
        return self.tree.cnt


    def next(self, sp_setting):
        self.setting_set.add(frozenset(sp_setting.spe_nodes))
        logl = sp_setting.get_log_l()
        if logl > self.max_logl:
            self.max_logl = logl
            self.max_setting = sp_setting
        for node in sp_setting.active_nodes:
            if node.is_leaf():
                pass
            else:
                childs = node.get_children()
                sp_nodes = []
                for child in childs:
                    sp_nodes.append(child)
                for nod in sp_setting.spe_nodes:
                    sp_nodes.append(nod)
                new_sp_setting = species_setting(spe_nodes = sp_nodes, root = sp_setting.root, sp_rate = sp_setting.spe_rate, fix_sp_rate = sp_setting.fix_spe_rate, minbr = self.min_brl)
                if frozenset(sp_nodes) in self.setting_set:
                    pass
                else:
                    self.next(new_sp_setting)


    def H0(self, reroot = True):
        self.H1(reroot)
        self.H2(reroot = False)
        self.H3(reroot = False)


    def H1(self, reroot = True):
        if reroot:
            self.re_rooting()
            
        #self.init_tree()
        sorted_node_list = self.tree.get_descendants()
        sorted_node_list.sort(key=self.__compare_node)
        sorted_node_list.reverse()
        
        first_node_list = []
        first_node_list.append(self.tree)
        first_childs = self.tree.get_children()
        for child in first_childs:
            first_node_list.append(child)
        first_setting = species_setting(spe_nodes = first_node_list, root = self.tree, sp_rate = self.fix_spe, fix_sp_rate = self.fix_spe_rate, minbr = self.min_brl)
#.........这里部分代码省略.........
开发者ID:zhangjiajie,项目名称:PTP,代码行数:103,代码来源:ptpllh.py


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