本文整理汇总了Python中ete2.TreeStyle类的典型用法代码示例。如果您正苦于以下问题:Python TreeStyle类的具体用法?Python TreeStyle怎么用?Python TreeStyle使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TreeStyle类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: generateImage
def generateImage(self, tree):
ts = TreeStyle()
ts.layout_fn = self.__layout__
ts.mode = "c"
ts.show_leaf_name = False
tree.render(self.treePNGFile, w=1000, tree_style = ts)
tree.render(self.treeSVGFile, w=250, tree_style = ts)
示例2: get_example_tree
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
示例3: print_colored_host_tree
def print_colored_host_tree(host_tree_fp, host_colors, output_fp, treefmt=5):
with open(host_tree_fp) as tree_f:
treestring = remove_newick_node_labels(tree_f.readline().strip())
tree = Tree(newick=treestring, format=treefmt)
for host in host_colors:
if tree.get_leaves_by_name(host) == []:
tip = "'%s'" % host
else:
tip = host
node = tree.get_leaves_by_name(tip)[0]
node.add_face(AttrFace("name", fsize=14, fgcolor=host_colors[host]), 0)
# remove stupid blue circles on nodes
style = NodeStyle()
style["size"] = 0
for l in tree.traverse():
l.set_style(style)
# get rid of default rendered leaf labels
ts = TreeStyle()
ts.show_leaf_name = False
tree.render(output_fp, tree_style = ts)
return
示例4: show
def show(self, i=0):
t = Tree(str(self)+";")
ts = TreeStyle()
ts.show_leaf_name = True
ts.rotation = 90
t.render("mytree-{0}.png".format(i), w=183, units="mm", tree_style=ts)
t.show(tree_style=ts)
示例5: render_tree
def render_tree(sk_tree, tip_hues, tip_lums, saturation=0.9, output_fp=None, supress_display=False):
ete_tree = Tree(str(sk_tree))
tree_tips = [x.name for x in sk_tree.tips()]
for ete_leaf in ete_tree.iter_leaves():
if (ete_leaf.name not in tree_tips) and (ete_leaf.name[1:-1] in tree_tips):
ete_leaf.name = ete_leaf.name[1:-1]
elif ete_leaf.name not in tree_tips:
print 'leaf {0} in ete-parsed tree not found in skbio tree {1}'.format(ete_leaf.name,str(sk_tree.ascii_art()))
raise KeyError
for n in ete_tree.traverse():
if n.is_leaf():
hex_color = hls_to_rgb_hex(tip_hues[n.name], tip_lums[n.name], saturation)
n.add_features(tip_color=hex_color)
style = NodeStyle()
style["size"] = 0
for l in ete_tree.traverse():
l.set_style(style)
ts = TreeStyle()
ts.layout_fn = layout
ts.show_leaf_name = False
if output_fp:
ete_tree.render(output_fp, tree_style = ts)
if not supress_display:
ete_tree.show(tree_style = ts)
return
示例6: build_vis
def build_vis():
ts = TreeStyle()
ts.mode = "c"
ts.arc_start = 0 # 0 degrees = 3 o'clock
ts.arc_span = 360
ts.layout_fn = my_layout # Use custom layout
return ts
示例7: print_colored_host_tree
def print_colored_host_tree(host_tree_fp, host_colors, output_fp):
tree = Tree(host_tree_fp)
for host in host_colors:
if tree.get_leaves_by_name(host) == []:
tip = "'%s'" % host
else:
tip = host
node = tree.get_leaves_by_name(tip)[0]
node.add_face(AttrFace("name", fsize=14, fgcolor=host_colors[host]), 0)
# remove stupid blue circles on nodes
style = NodeStyle()
style["size"] = 0
for l in tree.traverse():
l.set_style(style)
# get rid of default rendered leaf labels
ts = TreeStyle()
ts.show_leaf_name = False
tree.render(output_fp, tree_style = ts)
return
示例8: showTreeWithPictures
def showTreeWithPictures(tree = None, alignment=None, branchLengths=True, bootstrapSupport=True, tolabel=None):
print("ShowTreeWithPictures",tree, alignment, branchLengths,bootstrapSupport, tolabel)
if alignment:
t = EvolTree(tree, alignment,alg_format="paml")
t.link_to_alignment(alignment,alg_format="paml")
else:
t = EvolTree(tree)
nsFG = NodeStyle()
nsFG["fgcolor"] = "darkgreen"
nsFG["size"] = 8
for node in t.traverse():
print(node.node_id)
if tolabel:
if str(node.node_id) in tolabel:
node.set_style(nsFG)
ts = TreeStyle()
ts.show_leaf_name = True
ts.show_branch_length = branchLengths
ts.show_branch_support = bootstrapSupport
out = FILE
if branchLengths:
out+="_Len"
if bootstrapSupport:
out+="_Boot"
t.render(out+"_tree.pdf",tree_style=ts)
t.render(out+"_tree.png",tree_style=ts)
if INTERACTIVE:
t.show(tree_style=ts)
示例9: render_annotate
def render_annotate(newick_path, output_path):
"""Render the annotated tree, showing internal node names.
The output_path should end in .PNG, .PDF or .SVG: this will determine the format.
To aid in testing, if output_path is None, the tree is shown rather than rendered.
"""
tree = Tree(newick_path, format=1)
ts = TreeStyle()
ts.show_leaf_name = True
ts.branch_vertical_margin = 15
ns = NodeStyle()
ns["size"] = 1
edge = 0
for node in tree.traverse():
node.name = node.name.replace("'", "")
node.name = node.name.replace("+", ",")
if not node.is_leaf() and node.name != "NoName":
f = TextFace(node.name)
f.margin_top = 5
f.margin_bottom = 5
f.margin_right = 10
f.margin_left = 10
edge += 1
node.add_face(f, column=0, position="branch-top")
if output_path is None:
tree.show(tree_style=ts)
else:
tree.render(output_path)
示例10: ETETree
def ETETree(seqs, ref, metric):
"""Tree showing bola alleles covered by tepitope"""
from ete2 import Tree,PhyloTree,TreeStyle,NodeStyle
aln = Genome.clustalAlignment(seqs=seqs)
t = Tree('temp.dnd')
#t.set_outgroup(t&ref)
ts = TreeStyle()
ts.show_leaf_name = True
ts.mode = "c"
ts.arc_start = -180
ts.arc_span = 180
cutoff=0.25
def func(node):
if node.name=='NoName' or not node.name in metric:
return False
if metric[node.name]<=cutoff:
return True
matches = filter(func, t.traverse())
print len(matches), "nodes have distance <=%s" %cutoff
nst1 = NodeStyle()
nst1["bgcolor"] = "Yellow"
for n in matches:
n.set_style(nst1)
nst2 = NodeStyle()
nst2["bgcolor"] = "LightGreen"
hlanodes = [t.get_leaves_by_name(name=r)[0] for r in refalleles]
for n in hlanodes:
n.set_style(nst2)
t.show(tree_style=ts)
return
示例11: make_tree
def make_tree(treefile, image_file, clone_info):
colour_list = ['MidnightBlue','RoyalBlue', 'LightSkyBlue', 'Aquamarine', 'SpringGreen', 'GreenYellow',\
'Gold','DarkOrange']
weeks = ['16', '30', '38', '48', '59', '119', '176', '206']
weeks = ['6', '14', '53', '92','144']
t = Tree(treefile,format = 1)
ts = TreeStyle()
for i in range(5):
ts.legend.add_face(CircleFace(20, colour_list[i]), column=0)
ts.legend.add_face(TextFace('week' + weeks[i]), column=1)
ts.legend_position = 2
ts.show_leaf_name = True
ts.branch_vertical_margin = 15
ts.rotation = 90
ns = NodeStyle()
ns["size"] = 1
ns.hz_line_width = 10
ns.vt_line_width = 10
edge = 0
for node in t.traverse():
node.name = node.name.replace("'", "")
node.name = node.name.replace(".", ",")
name = node.name.split(' ')[0]
print name
if name in clone_info.keys():
style_node(node, colour_list[int(clone_info[name][0])-1], int(int(clone_info[name][1])/10)+5)
if not node.is_leaf() and node.name != 'NoName':
f = TextFace(node.name)
f.margin_top = 2.5
f.margin_bottom = 2.5
f.margin_right = 2.5
f.margin_left = 2.5
node.add_face(f, column=0, position="branch-top")
t.render(image_file, tree_style = ts)
示例12: draw_tree
def draw_tree(tree, file):
root = tree.get_midpoint_outgroup()
try:
tree.set_outgroup(root)
except:
pass
root = tree.get_tree_root()
root.dist = 0
add_sig(tree)
ts = TreeStyle()
ts.branch_vertical_margin = 1
#ts.scale = 1500
ts.show_leaf_name = False
#ts.show_branch_support = True
leg_file = path.join(path.expanduser('~'), 'Perl', 'Modules', 'TreeLegend.png')
leg_face= ImgFace(img_file=leg_file)
leg_face.margin_left, leg_face.margin_top = 5, 5
ts.legend.add_face(leg_face, column=1)
ts.legend_position=1
title_face = TextFace(text=file.split('.')[0])
title_face.margin_left, title_face.margin_top = 10, 5
ts.title.add_face(title_face, column=1)
(ts.margin_left, ts.margin_right) = (5,5)
tree.render(file, tree_style=ts, w=6000, units='mm')
示例13: showTreeInGrid
def showTreeInGrid(gid,biome,grid_level=14,taxonomic_level='sp'):
"""
Performs a selection, spatial filter and returns an image.
grid_level is the grid layer.
taxonomic_level is the taxonomic level to be shown. Options are:
sp, gns, fam, ord, cls, phy, king
"""
mesh = initMesh(grid_level)
try:
cell = mesh.objects.get(id=id)
except:
logger.error("Selected id does not exist in selected grid")
return None
gb=GriddedTaxonomy(biome,cell,generate_tree_now=True)
forest = gb.taxonomies[0].forest
ts = TreeStyle()
ts.show_leaf_name = True
ts.mode = "c"
ts.arc_start = -180 # 0 degrees = 3 o'clock
ts.arc_span = 360
forest[taxonomic_level].show(tree_style=ts)
return 'Parece que se tiene que ver algo'
示例14: visualizeTree
def visualizeTree(sTreePath, pathToSfamilies, bootValue, width, height):
# Random tree
stree = Tree()
stree = readTreeFromFile(sTreePath)
snodesStatDic={}
snodesStatDic= getFamiliesStatisticsForEachNode(pathToSfamilies, bootValue)
#print snodesStatDic
# Some random features in all nodes
for n in stree.traverse():
if n.name in snodesStatDic.keys():
total= reduce(lambda x,y: x+y, snodesStatDic[n.name])
#norm= [(x*100)/total for x in snodesStatDic[n.name]]
norm= [x for x in snodesStatDic[n.name]]
n.add_features(pie_data=norm)
# Create an empty TreeStyle
ts = TreeStyle()
# Set our custom layout function
ts.layout_fn=layout
# Draw a tree
ts.mode = "r"
#ts.force_topology= False
ts.complete_branch_lines_when_necessary= True
# 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 stree, ts
示例15: get_example_tree
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