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


Python TreeStyle.margin_bottom方法代码示例

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


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

示例1: doWork

# 需要导入模块: from ete2 import TreeStyle [as 别名]
# 或者: from ete2.TreeStyle import margin_bottom [as 别名]
def doWork(args):
	# read clustering data
	geneIdToClusterId = {}
	clusterIds  = []
	for line in open(args.cluster):
		if line[0] == '%':
			clusterId = line[1:].strip()
			clusterIds.append(clusterId)
		else:
			geneIdToClusterId[line.strip()] = clusterId

	# create colour map for clusters
	clusterIdToColour = {}
	index = 0
	for clusterId in clusterIds:
		rgb = tuple([int(c*255) for c in hsv_to_rgb(float(index)/len(clusterIds), 0.4, 1.0)])
		clusterIdToColour[clusterId] = '#%02X%02X%02X' % rgb
		index += 1

	# read tree
	tree = Tree(args.tree)

	# define node properties
	for node in tree.traverse('levelorder'):
		if node.is_leaf():
			name = node.name.replace("'", '')
			clusterId = geneIdToClusterId[name]
			node.add_feature('clusterId', clusterId)
			
			if args.label:
				node.name = ' ' + name + ' [' + clusterId + ']'
			
			ns = NodeStyle()
			ns['shape'] = 'circle'
			ns['fgcolor'] = 'black'
			ns['size'] = 4
			node.set_style(ns)
		else:
			ns = NodeStyle()
			ns['size'] = 0
			node.set_style(ns)
		
	# determine colour for each node
	assignedColor = set()
	for node in tree.traverse('levelorder'):
		if node.is_leaf() or node.is_root():
			continue
			
		# determine clusters descendent from this node
		clusterSet = set()
		for leaf in node.get_leaves():
			clusterSet.add(leaf.clusterId)
			
		# check if parent has already been assigned a colour
		bContinue = False
		parentNode = node.up
		while not parentNode.is_root():
			if parentNode in assignedColor:
				bContinue = True
				break
				
			parentNode = parentNode.up
			
		if bContinue:
			continue

		# colour node if all descendants are from the same cluster
		if len(clusterSet) == 1:
			clusters = list(clusterSet)
			ns = NodeStyle()
			ns['bgcolor'] = clusterIdToColour[clusters[0]]
			ns['size'] = 0
			node.set_style(ns)
			assignedColor.add(node)

	# create tree style for plotting consisteny index trees
	treeStyle = TreeStyle()
	treeStyle.margin_left = 10
	treeStyle.margin_right = 10
	treeStyle.margin_top = 10
	treeStyle.margin_bottom = 10
	treeStyle.guiding_lines_type = 1
	treeStyle.legend_position=1
	treeStyle.scale = 500
	
	# add legend
	rowIndex = 0
	for clusterId in sorted(clusterIdToColour.keys()):
		treeStyle.legend.add_face(CircleFace(4, clusterIdToColour[clusterId]), column=0)
		treeStyle.legend.add_face(TextFace(' ' + clusterId), column=1)
		rowIndex += 1

	tree.render(args.output, dpi=args.dpi, w = int(args.width*args.dpi + 0.5), tree_style=treeStyle)
开发者ID:dparks1134,项目名称:PETs,代码行数:95,代码来源:plotTree.py


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