本文整理汇总了Python中ete3.TreeStyle.show_leaf_name方法的典型用法代码示例。如果您正苦于以下问题:Python TreeStyle.show_leaf_name方法的具体用法?Python TreeStyle.show_leaf_name怎么用?Python TreeStyle.show_leaf_name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ete3.TreeStyle
的用法示例。
在下文中一共展示了TreeStyle.show_leaf_name方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_example_tree
# 需要导入模块: from ete3 import TreeStyle [as 别名]
# 或者: from ete3.TreeStyle import show_leaf_name [as 别名]
def get_example_tree():
# Set dashed blue lines in all leaves
nst1 = NodeStyle()
nst1["bgcolor"] = "LightSteelBlue"
nst2 = NodeStyle()
nst2["bgcolor"] = "Moccasin"
nst3 = NodeStyle()
nst3["bgcolor"] = "DarkSeaGreen"
nst4 = NodeStyle()
nst4["bgcolor"] = "Khaki"
t = Tree("((((a1,a2),a3), ((b1,b2),(b3,b4))), ((c1,c2),c3));")
for n in t.traverse():
n.dist = 0
n1 = t.get_common_ancestor("a1", "a2", "a3")
n1.set_style(nst1)
n2 = t.get_common_ancestor("b1", "b2", "b3", "b4")
n2.set_style(nst2)
n3 = t.get_common_ancestor("c1", "c2", "c3")
n3.set_style(nst3)
n4 = t.get_common_ancestor("b3", "b4")
n4.set_style(nst4)
ts = TreeStyle()
ts.layout_fn = layout
ts.show_leaf_name = False
ts.mode = "c"
ts.root_opening_factor = 1
return t, ts
示例2: get_example_tree
# 需要导入模块: from ete3 import TreeStyle [as 别名]
# 或者: from ete3.TreeStyle import show_leaf_name [as 别名]
def get_example_tree():
# Random tree
t = Tree()
t.populate(20, random_branches=True)
# Some random features in all nodes
for n in t.traverse():
n.add_features(weight=random.randint(0, 50))
# Create an empty TreeStyle
ts = TreeStyle()
# Set our custom layout function
ts.layout_fn = layout
# Draw a tree
ts.mode = "c"
# We will add node names manually
ts.show_leaf_name = False
# Show branch data
ts.show_branch_length = True
ts.show_branch_support = True
return t, ts
示例3: ete_draw
# 需要导入模块: from ete3 import TreeStyle [as 别名]
# 或者: from ete3.TreeStyle import show_leaf_name [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
示例4: get_example_tree
# 需要导入模块: from ete3 import TreeStyle [as 别名]
# 或者: from ete3.TreeStyle import show_leaf_name [as 别名]
def get_example_tree():
t = Tree()
ts = TreeStyle()
ts.layout_fn = layout
ts.mode = "r"
ts.show_leaf_name = False
t.populate(10)
return t, ts
示例5: get_tree_style
# 需要导入模块: from ete3 import TreeStyle [as 别名]
# 或者: from ete3.TreeStyle import show_leaf_name [as 别名]
def get_tree_style(self):
ts = TreeStyle()
ts.layout_fn = self.custom_layout
ts.show_leaf_name = False
ts.draw_guiding_lines = True
#ts.guiding_lines_type = 1
self._treestyle = ts
return ts
示例6: get_example_tree
# 需要导入模块: from ete3 import TreeStyle [as 别名]
# 或者: from ete3.TreeStyle import show_leaf_name [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
示例7: export_tree
# 需要导入模块: from ete3 import TreeStyle [as 别名]
# 或者: from ete3.TreeStyle import show_leaf_name [as 别名]
def export_tree(tree, filename, insignif_color, signif_color, i_group, width):
'''
exports the given tree to the given filename
'''
ts = TreeStyle()
ts.show_leaf_name = False
ts.show_scale = False
ts.layout_fn = generate_layout(insignif_color, signif_color, i_group)
tree.render(filename, w=width, tree_style=ts)
示例8: get_example_tree
# 需要导入模块: from ete3 import TreeStyle [as 别名]
# 或者: from ete3.TreeStyle import show_leaf_name [as 别名]
def get_example_tree():
t = Tree()
ts = TreeStyle()
ts.layout_fn = layout
ts.mode = "c"
ts.show_leaf_name = True
ts.min_leaf_separation = 15
t.populate(100)
return t, ts
示例9: balanceplot
# 需要导入模块: from ete3 import TreeStyle [as 别名]
# 或者: from ete3.TreeStyle import show_leaf_name [as 别名]
def balanceplot(balances, tree,
layout=None,
mode='c'):
""" Plots balances on tree.
Parameters
----------
balances : np.array
A vector of internal nodes and their associated real-valued balances.
The order of the balances will be assumed to be in level order.
tree : skbio.TreeNode
A strictly bifurcating tree defining a hierarchical relationship
between all of the features within `table`.
layout : function, optional
A layout for formatting the tree visualization. Must take a
`ete.tree` as a parameter.
mode : str
Type of display to show the tree. ('c': circular, 'r': rectangular).
Note
----
The `tree` is assumed to strictly bifurcating and
whose tips match `balances.
See Also
--------
TreeNode.levelorder
"""
# The names aren't preserved - let's pray that the topology is consistent.
ete_tree = Tree(str(tree))
# Some random features in all nodes
i = 0
for n in ete_tree.traverse():
if not n.is_leaf():
n.add_features(weight=balances[-i])
i += 1
# Create an empty TreeStyle
ts = TreeStyle()
# Set our custom layout function
if layout is None:
ts.layout_fn = default_layout
else:
ts.layout_fn = layout
# Draw a tree
ts.mode = mode
# We will add node names manually
ts.show_leaf_name = False
# Show branch data
ts.show_branch_length = True
ts.show_branch_support = True
return ete_tree, ts
示例10: get_example_tree
# 需要导入模块: from ete3 import TreeStyle [as 别名]
# 或者: from ete3.TreeStyle import show_leaf_name [as 别名]
def get_example_tree():
t = Tree()
t.populate(8)
# Node style handling is no longer limited to layout functions. You
# can now create fixed node styles and use them many times, save them
# or even add them to nodes before drawing (this allows to save and
# reproduce an tree image design)
# Set bold red branch to the root node
style = NodeStyle()
style["fgcolor"] = "#0f0f0f"
style["size"] = 0
style["vt_line_color"] = "#ff0000"
style["hz_line_color"] = "#ff0000"
style["vt_line_width"] = 8
style["hz_line_width"] = 8
style["vt_line_type"] = 0 # 0 solid, 1 dashed, 2 dotted
style["hz_line_type"] = 0
t.set_style(style)
#Set dotted red lines to the first two branches
style1 = NodeStyle()
style1["fgcolor"] = "#0f0f0f"
style1["size"] = 0
style1["vt_line_color"] = "#ff0000"
style1["hz_line_color"] = "#ff0000"
style1["vt_line_width"] = 2
style1["hz_line_width"] = 2
style1["vt_line_type"] = 2 # 0 solid, 1 dashed, 2 dotted
style1["hz_line_type"] = 2
t.children[0].img_style = style1
t.children[1].img_style = style1
# Set dashed blue lines in all leaves
style2 = NodeStyle()
style2["fgcolor"] = "#000000"
style2["shape"] = "circle"
style2["vt_line_color"] = "#0000aa"
style2["hz_line_color"] = "#0000aa"
style2["vt_line_width"] = 2
style2["hz_line_width"] = 2
style2["vt_line_type"] = 1 # 0 solid, 1 dashed, 2 dotted
style2["hz_line_type"] = 1
for l in t.iter_leaves():
l.img_style = style2
ts = TreeStyle()
ts.layout_fn = layout
ts.show_leaf_name = False
return t, ts
示例11: drawTree
# 需要导入模块: from ete3 import TreeStyle [as 别名]
# 或者: from ete3.TreeStyle import show_leaf_name [as 别名]
def drawTree(treeFile, ShowBool):
"""
Draw a tree from a phy file
"""
t = Tree(treeFile)
imgFile = treeFile.replace(".tree", ".tree.png")
# Basic tree style
ts = TreeStyle()
ts.show_leaf_name = True
ts.show_branch_support = True
ts.scale = 160
# Draws nodes as small red spheres of diameter equal to 10 pixels
nstyle = NodeStyle()
nstyle["shape"] = "sphere"
nstyle["size"] = 10
nstyle["fgcolor"] = "darkred"
#nstyle["faces_bgcolor"] = "pink"
nstyle2 = NodeStyle()
nstyle2["shape"] = "sphere"
nstyle2["size"] = 10
nstyle2["fgcolor"] = "darkblue"
# Gray dashed branch lines
nstyle["hz_line_type"] = 1
nstyle["hz_line_color"] = "#cccccc"
# 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():
if n.is_leaf():
if n.name.split("|")[-1] == "GI":
n.set_style(nstyle)
if n.name.split("|")[-1] == "plasmid":
n.set_style(nstyle2)
gi = n.name.split("|")[1]
n.name = n.name.split("|")[0] #+ " " + n.name.split("|")[1]
n.name = n.name.replace("_tRNA_modification_GTPase_", "")
n.name = n.name.replace("_DNA", "")
n.name = " " + n.name + " "
if n.name[-1] == "_": n.name.rstrip()
taxon, color = taxonToColour(gi)
n.add_face(TextFace(taxon, fgcolor = color, fsize = 8), column=1, position="branch-right")
#n.img_style["bgcolor"] = color
if ShowBool == True: #permet de flipper les braches pour avoir des topologies similaires
t.show(tree_style=ts)
t.render(imgFile, w=393, units="mm", tree_style=ts)
示例12: _get_motif_tree
# 需要导入模块: from ete3 import TreeStyle [as 别名]
# 或者: from ete3.TreeStyle import show_leaf_name [as 别名]
def _get_motif_tree(tree, data, circle=True, vmin=None, vmax=None):
try:
from ete3 import Tree, NodeStyle, TreeStyle
except ImportError:
print("Please install ete3 to use this functionality")
sys.exit(1)
t = Tree(tree)
# Determine cutoff for color scale
if not(vmin and vmax):
for i in range(90, 101):
minmax = np.percentile(data.values, i)
if minmax > 0:
break
if not vmin:
vmin = -minmax
if not vmax:
vmax = minmax
norm = Normalize(vmin=vmin, vmax=vmax, clip=True)
mapper = cm.ScalarMappable(norm=norm, cmap="RdBu_r")
m = 25 / data.values.max()
for node in t.traverse("levelorder"):
val = data[[l.name for l in node.get_leaves()]].values.mean()
style = NodeStyle()
style["size"] = 0
style["hz_line_color"] = to_hex(mapper.to_rgba(val))
style["vt_line_color"] = to_hex(mapper.to_rgba(val))
v = max(np.abs(m * val), 5)
style["vt_line_width"] = v
style["hz_line_width"] = v
node.set_style(style)
ts = TreeStyle()
ts.layout_fn = _tree_layout
ts.show_leaf_name= False
ts.show_scale = False
ts.branch_vertical_margin = 10
if circle:
ts.mode = "c"
ts.arc_start = 180 # 0 degrees = 3 o'clock
ts.arc_span = 180
return t, ts
示例13: run_action_change_style
# 需要导入模块: from ete3 import TreeStyle [as 别名]
# 或者: from ete3.TreeStyle import show_leaf_name [as 别名]
def run_action_change_style(self, tree, a_data):
#print "action change style called.."
if tree.tree_style == self._treestyle:
ts2 = TreeStyle()
ts2.layout_fn = self.custom_layout
ts2.show_leaf_name = False
ts2.draw_guiding_lines = True
ts2.guiding_lines_type = 0 #solid line
ts2.guiding_lines_color = a_data
tree.tree_style = ts2
self._treestyle = ts2
else:
tree.tree_style = self._treestyle
示例14: argument
# 需要导入模块: from ete3 import TreeStyle [as 别名]
# 或者: from ete3.TreeStyle import show_leaf_name [as 别名]
def argument(name):
g.name = name
argument_file = "static/inputs/%s.txt" % name
g.argument_tree = "/static/outputs/%s.png" % name
argument_tree = "static/outputs/%s.png" % name
try:
f = open(argument_file) # open the file
except:
abort(404)
g.premises = []
g.conclusion = None
for line in f:
g.premises.append(line.strip())
g.conclusion = g.premises[-1]
g.premises = g.premises[:-1]
stmt_set = main.open_argument(argument_file)
print stmt_set
g.sat, tree = satisfiable.satisfiable(stmt_set)
existing = os.listdir("static/outputs")
for f in existing:
if f == name + ".png":
return render_template("argument.html")
# set teh tree style...
ts = TreeStyle()
# don't show the name of the leaf nodes (which are just a x/o for a open/closed branch) in the final graph
ts.show_leaf_name = False
for child in tree.traverse():
# add a marker with the name of each node, at each node
child.add_face(TextFace(child.name), column=0, position="branch-top")
# render the file and save it
tree.render(argument_tree, tree_style=ts, w=5000)
# crop out the unwanted part of the image...
im = Image.open(argument_tree)
(x, y) = im.size
draw = ImageDraw.Draw(im)
draw.rectangle((0, y*.5, x*.25, y), fill="white")
im.save(argument_tree, "PNG")
return render_template("argument.html")
示例15: get_tree_style
# 需要导入模块: from ete3 import TreeStyle [as 别名]
# 或者: from ete3.TreeStyle import show_leaf_name [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