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


Python Tree.postorder_traverse_with_cheat方法代码示例

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


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

示例1: rearr

# 需要导入模块: import Tree [as 别名]
# 或者: from Tree import postorder_traverse_with_cheat [as 别名]
	def rearr(t, log_l, rL, rU):
		for target in t.postorder_node_iter():
			if target.parent_node is None:
				break
			# first make a deep copy of the tree
			t_prime = dendropy.Tree(t)
			print "finding subtree rearrangement for {0}".format(target.label)
			dest = cello.subtree_rearrangement(t_prime, target, rL, rU)
			print "inserting subtree {0} into branch above {1}".format(target.label, dest.label)
			try:
				# attach the subtree of <target> to branch above <dest>
				t_prime, affected = Subtree.move_subtree(t_prime, target.label, dest.label)
			except Exception:
				print "could not succesfully do the move, forget it! move on!"
				continue
			cheat_order = Tree.postorder_traverse_with_cheat(t_prime, affected)
			# the three local branche we need to optimize are edges of
			# target, dest, and parent of target
			lst = []
			for i, (k, bunch) in enumerate(cheat_order):
				for j, (a, t_a) in enumerate(bunch):
					if a in (target.label, dest.label, target.parent_node.label):
						lst.append((i, j))
			print 'list is', lst
			log_l_prime = MyMat.optimize_branch_fast(lst, cheat_order, msa, single_model, paired_model, S, P)
			if log_l_prime < log_l:
				print "subtree rearrangement improved log like from {0}-->{1}, keep!".format(log_l, log_l_prime)
				t = t_prime
				log_l = log_l_prime
				# put in the fastly optimized branch lengths
				for i, j in lst:
					t.find_node_with_label(cheat_order[i][1][j][0]).edge_length = cheat_order[i][1][j][1]
				raw_input("continue?")
				return
			else:
				print "subtree rearrangment made log likelihood worse. Move on"
				raw_input("continue")
				return
		return t, log_l
开发者ID:pombredanne,项目名称:gbpML,代码行数:41,代码来源:Likelihood.py


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