本文整理汇总了Python中ete3.TreeStyle.rotation方法的典型用法代码示例。如果您正苦于以下问题:Python TreeStyle.rotation方法的具体用法?Python TreeStyle.rotation怎么用?Python TreeStyle.rotation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ete3.TreeStyle
的用法示例。
在下文中一共展示了TreeStyle.rotation方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ete_draw
# 需要导入模块: from ete3 import TreeStyle [as 别名]
# 或者: from ete3.TreeStyle import rotation [as 别名]
def ete_draw(self, fname=None):
""" Draws the tree and saves it to a file. If `fname` is None,
show the tree instead of saving it.
Args:
fname: filename to save to (default=None)
"""
if Cfg.USE_ETE3:
def layout(node):
faces.add_face_to_node(AttrFace("name"), node, column=0,
position="branch-right")
ts = TreeStyle()
ts.show_leaf_name = False
ts.layout_fn = layout
ts.rotation = 90
tree = EteTree(self.ete_str(), format=8)
if fname:
tree.render(fname, tree_style=ts)
else:
tree.show(tree_style=ts)
else:
# TODO maybe throw an error?
pass
示例2: get_example_tree
# 需要导入模块: from ete3 import TreeStyle [as 别名]
# 或者: from ete3.TreeStyle import rotation [as 别名]
def get_example_tree():
t = Tree()
t.populate(10)
ts = TreeStyle()
ts.rotation = 45
ts.show_leaf_name = False
ts.layout_fn = rotation_layout
return t, ts
示例3: draw_tree
# 需要导入模块: from ete3 import TreeStyle [as 别名]
# 或者: from ete3.TreeStyle import rotation [as 别名]
def draw_tree(tree_string):
t = Tree(tree_string, format=8)
def mylayout(node):
#if node.name != 'L':
file = 'tmp/%s.png' % node.name
new_face = faces.ImgFace(file)
new_face.rotable = True
new_face.rotation = -90
#new_face.margin_top = 50
new_face.margin_left = 15
faces.add_face_to_node(new_face, node, column=0 , position='branch-top')
ts = TreeStyle()
ts.rotation = 90
ts.layout_fn = mylayout
t.show(tree_style = ts)
plt.clf()
示例4: NodeStyle
# 需要导入模块: from ete3 import TreeStyle [as 别名]
# 或者: from ete3.TreeStyle import rotation [as 别名]
circular_style.show_branch_length = True
circular_style.show_branch_support = True
t.render("mytree.png", tree_style=circular_style)
nstyle = NodeStyle()
nstyle["hz_line_width"] = 3
nstyle["vt_line_width"] = 3
# Applies the same static style to all nodes in the tree. Note that,
# if "nstyle" is modified, changes will affect to all nodes
for n in t.traverse():
n.set_style(nstyle)
ts = TreeStyle()
ts.branch_vertical_margin = 10
ts.show_leaf_name = True
ts.rotation = 90
ts.scale=100
t.render("tree_test100.png",tree_style=ts)
ts.scale=1000
t.render("tree_test1000.png",tree_style=ts)
## compare to
#t = Tree( '("[a,b]",c);' )
#t.show()
# []
示例5: Tree
# 需要导入模块: from ete3 import TreeStyle [as 别名]
# 或者: from ete3.TreeStyle import rotation [as 别名]
root = Tree()
node_cur = root
'''#######################
Tree Style Begin
'''
ts = TreeStyle()
ts.title.add_face(TextFace("Tree example", fsize=8), column=0)
ts.scale = 50
ts.mode = 'r'
# left or right
ts.orientation = 1
ts.rotation = 270
ts.show_leaf_name = False
ts.show_branch_length = True
#ts.show_branch_length = True
'''
Tree Style End
#######################'''
'''#######################
Node Style Begin
'''
ns_root = NodeStyle()
ns_root["size"] = 10
示例6: heatmap_view
# 需要导入模块: from ete3 import TreeStyle [as 别名]
# 或者: from ete3.TreeStyle import rotation [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)