本文整理汇总了Python中ete2.TreeStyle.margin_top方法的典型用法代码示例。如果您正苦于以下问题:Python TreeStyle.margin_top方法的具体用法?Python TreeStyle.margin_top怎么用?Python TreeStyle.margin_top使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ete2.TreeStyle
的用法示例。
在下文中一共展示了TreeStyle.margin_top方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: doWork
# 需要导入模块: from ete2 import TreeStyle [as 别名]
# 或者: from ete2.TreeStyle import margin_top [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)