本文整理汇总了Python中ete3.TreeStyle类的典型用法代码示例。如果您正苦于以下问题:Python TreeStyle类的具体用法?Python TreeStyle怎么用?Python TreeStyle使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TreeStyle类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: createImg
def createImg(filename, thres=0, samples=1):
count = parseLineage(filename)
suffix, matrix, taxo = getSuffixandMatrixandNewick(count,thres,samples)
newick = convert(taxo,suffix)
newick += ';'
t = Tree(newick, format=1)
ct = ClusterTree(t.write(), text_array=matrix)
addColors(ct)
# nodes are linked to the array table
array = ct.arraytable
# Calculates some stats on the matrix. Needed to establish the color gradients.
matrix_dist = [i for r in xrange(len(array.matrix))for i in array.matrix[r] if np.isfinite(i)]
matrix_max = np.max(matrix_dist)
matrix_min = np.min(matrix_dist)
matrix_avg = (matrix_max+matrix_min)/2
# Creates a profile face that will represent node's profile as a heatmap
profileFace = ProfileFace(matrix_max, matrix_min, matrix_avg, 200, 14, "heatmap",colorscheme=3)
# Creates my own layout function that uses previous faces
def mylayout(node):
# If node is a leaf
if node.is_leaf():
# And a line profile
add_face_to_node(profileFace, node, 0, aligned=True)
node.img_style["size"]=2
# Use my layout to visualize the tree
ts = TreeStyle()
ts.layout_fn = mylayout
# ct.show(tree_style=ts)
filedir = '/'.join(filename.split('/')[:-1])
# t.write(format=9, outfile="output/newick/"+param+".nw")
ct.render(filedir+'/phylo.png',tree_style=ts)
示例2: show_tree
def show_tree(experiment_folder):
model = MDPD.Hierachical_MDPD(1)
model.load(os.path.join(experiment_folder, 'model.p'))
width, depth = model.width, model.depth
root = Tree()
cache = [(0, root)]
for i in range(depth + 1):
foo = []
for idx, node in cache:
paren = int((idx - 1) / width)
kid = idx - paren * width
face = faces.ImgFace(os.path.join(experiment_folder, 'images', '{}_{}_{}.png'.format(idx, paren, kid)))
node.add_face(face, 0)
if i < depth:
for k in range(width):
foo.append((idx * width + k + 1, node.add_child()))
cache = foo
ts = TreeStyle()
ts.mode = "c"
root.render(os.path.join(experiment_folder, 'images', 'tree_plot.png'), tree_style=ts)
return root
示例3: 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
示例4: ete_draw
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
示例5: get_tree_style
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
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
示例7: get_example_tree
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
示例8: get_example_tree
def get_example_tree():
t = Tree()
t.populate(8, reuse_names=False)
ts = TreeStyle()
ts.layout_fn = master_ly
ts.title.add_face(faces.TextFace("Drawing your own Qt Faces", fsize=15), 0)
return t, ts
示例9: export_tree
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)
示例10: get_example_tree
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
示例11: drawTree
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_example_tree
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
示例13: argument
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")
示例14: get_example_tree
def get_example_tree():
# Create a random tree and add to each leaf a random set of motifs
# from the original set
t = Tree()
t.populate(10)
# for l in t.iter_leaves():
# seq_motifs = [list(m) for m in motifs] #sample(motifs, randint(2, len(motifs)))
# seqFace = SeqMotifFace(seq, seq_motifs, intermotif_format="line",
# seqtail_format="compactseq", scale_factor=1)
# seqFace.margin_bottom = 4
# f = l.add_face(seqFace, 0, "aligned")
ts = TreeStyle()
ts.layout_fn = layout
return t, ts
示例15: render_tree
def render_tree(tree, fname):
# Generates tree snapshot
npr_nodestyle = NodeStyle()
npr_nodestyle["fgcolor"] = "red"
for n in tree.traverse():
if hasattr(n, "nodeid"):
n.set_style(npr_nodestyle)
ts = TreeStyle()
ts.show_leaf_name = True
ts.show_branch_length = True
ts.show_branch_support = True
ts.mode = "r"
iterface = faces.TextFace("iter")
ts.legend.add_face(iterface, 0)
tree.dist = 0
tree.sort_descendants()
tree.render(fname, tree_style=ts, w=700)