本文整理汇总了Python中ete2.TreeStyle.margin_left方法的典型用法代码示例。如果您正苦于以下问题:Python TreeStyle.margin_left方法的具体用法?Python TreeStyle.margin_left怎么用?Python TreeStyle.margin_left使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ete2.TreeStyle
的用法示例。
在下文中一共展示了TreeStyle.margin_left方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: render_tree_image
# 需要导入模块: from ete2 import TreeStyle [as 别名]
# 或者: from ete2.TreeStyle import margin_left [as 别名]
def render_tree_image(self, filename):
def my_layout(node):
name_faces = AttrFace("name", fsize=10, fgcolor = "#0000FF")
faces.add_face_to_node(name_faces, node, column=0, position="branch-right")
t = Tree("%s;" % self.newick_string(), format = 1)
s = "0"
for n in t.iter_descendants():
text = TextFace(s)
if s == "0": s = "1"
else: s = "0"
text.fgcolor = "#FF0000";
nstyle = NodeStyle()
nstyle['size'] = 15
nstyle['fgcolor'] = "#333"
n.set_style(nstyle)
n.add_face(text, column = 0, position = "branch-top")
ts = TreeStyle()
ts.rotation = 90
ts.show_leaf_name = False
ts.layout_fn = my_layout
ts.margin_left = 0
ts.branch_vertical_margin = 50
ts.show_scale = False
t.render(filename, tree_style = ts, w = 2000)
示例2: doWork
# 需要导入模块: from ete2 import TreeStyle [as 别名]
# 或者: from ete2.TreeStyle import margin_left [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)