本文整理汇总了Python中ete3.TreeStyle.margin_left方法的典型用法代码示例。如果您正苦于以下问题:Python TreeStyle.margin_left方法的具体用法?Python TreeStyle.margin_left怎么用?Python TreeStyle.margin_left使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ete3.TreeStyle
的用法示例。
在下文中一共展示了TreeStyle.margin_left方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_tree_style
# 需要导入模块: from ete3 import TreeStyle [as 别名]
# 或者: from ete3.TreeStyle import margin_left [as 别名]
def get_tree_style():
ts = TreeStyle()
# ts.mode = 'c'
ts.margin_top = 10
ts.margin_bottom = 10
ts.margin_left = 10
ts.margin_right = 10
ts.show_leaf_name = False
ts.show_branch_length = False
ts.show_branch_support = False
ts.show_scale = False
title = TextFace(" Tax Assignment Tree", fsize=10)
title.hz_align = 2
title.vt_align = 2
ts.title.add_face(TextFace(" "), column=0)
ts.title.add_face(TextFace(" "), column=0)
ts.title.add_face(title, column=0)
return ts
示例2: get_default_tree_style
# 需要导入模块: from ete3 import TreeStyle [as 别名]
# 或者: from ete3.TreeStyle import margin_left [as 别名]
def get_default_tree_style(color_dict):
ts = TreeStyle()
ts.mode = "c"
# ts.layout_fn = layout
ts.margin_top = 50
ts.margin_bottom = 0
ts.margin_left = 50
ts.margin_right = 50
ts.show_scale = False
ts.show_leaf_name = False
ts.show_branch_length = False
ts.show_branch_support = False
for p, c in color_dict.iteritems():
ts.legend.add_face(TextFace(" ", fsize=30), column=0)
ts.legend.add_face(CircleFace(10, c), column=1)
ts.legend.add_face(TextFace(" %s" % p, fsize=30), column=2)
legend_margin_line = 5
while legend_margin_line:
ts.legend.add_face(TextFace(" "), column=0)
ts.legend.add_face(TextFace(" "), column=1)
ts.legend.add_face(TextFace(" "), column=2)
legend_margin_line -= 1
ts.legend_position = 3
return ts
示例3: heatmap_view
# 需要导入模块: from ete3 import TreeStyle [as 别名]
# 或者: from ete3.TreeStyle import margin_left [as 别名]
def heatmap_view(tree, orthologous_groups, save_dir):
"""Generates a heatmap of regulation states in all species."""
light_tree = copy.deepcopy(tree) # Tree copy for the light heatmap
# Heat map settings
rect_face_fgcolor = 'black'
locus_tag_len = max(len(gene.locus_tag) + 5
for ortho_grp in orthologous_groups
for gene in ortho_grp.genes)
rect_face_width = locus_tag_len * 8
light_rect_face_width = 20
rect_face_height = 20
rotation = 90
# Sort orthologous groups by the number of regulated genes in each group
orthologous_groups = filter_and_sort_orthologous_grps(orthologous_groups)
# For each species and its gene in each orthologous group, draw a rectangle
for node, light_node in zip(tree.get_leaves(), light_tree.get_leaves()):
for i, orthologous_grp in enumerate(orthologous_groups, start=1):
#get all orthologs in group
matching_genes = [g for g in orthologous_grp.genes \
if g.genome.strain_name == node.name]
#if there is ortholog
if len(matching_genes) > 0:
# Get the first ortholog from the genome in the group
#this is the one with higher probability of regulation.
#so this probability will be displayed for the group
gene = matching_genes[0]
p_regulation = gene.operon.regulation_probability
p_notregulation = 1.0 - p_regulation
p_absence = 0
# No ortholog from this genome
else:
gene = None
p_regulation = 0
p_notregulation = 0
p_absence = 1
# Color of the rectangle is based on probabilities
rect_face_bgcolor = rgb2hex(
p_notregulation, p_regulation, p_absence)
rect_face_text = ('%s [%d]' % (gene.locus_tag, gene.operon.operon_id)
if gene else '')
rect_face_label = {'text': rect_face_text,
'font': 'Courier',
'fontsize': 8,
'color': 'black'}
# Create the rectangle
rect_face = RectFace(rect_face_width, rect_face_height,
rect_face_fgcolor, rect_face_bgcolor,
label=rect_face_label)
light_rect_face = RectFace(light_rect_face_width, rect_face_height,
rect_face_fgcolor, rect_face_bgcolor,
label='')
rect_face.rotation = -rotation
light_rect_face.rotation = -rotation
# Add the rectangle to the corresponding column
node.add_face(rect_face, column=i, position='aligned')
light_node.add_face(light_rect_face, column=i, position='aligned')
ts = TreeStyle()
# Add orthologous group descriptions
descriptions = ['-'.join([grp.description, str(grp.NOGs)]) for grp in orthologous_groups]
max_description_len = max(map(len, descriptions))
descriptions = [
'[%d]' % i + description + ' '*(max_description_len-len(description))
for i, description in enumerate(descriptions, start=1)]
for i, description in enumerate(descriptions, start=1):
text_face = TextFace(description, ftype='Courier')
text_face.hz_align = 1
text_face.vt_align = 1
text_face.rotation = -rotation
ts.aligned_header.add_face(text_face, column=i)
# Rotate the generated heatmap.
ts.margin_left = 10
ts.margin_top = 20
ts.rotation = rotation
ts.show_scale = False
# For some reason, it can't render to PDF in color
tree.render(os.path.join(save_dir, 'heatmap.svg'), tree_style=ts)
light_tree.render(os.path.join(save_dir, 'heatmap_light.svg'), tree_style=ts)