本文整理汇总了Python中ete2.TreeStyle.show_branch_length方法的典型用法代码示例。如果您正苦于以下问题:Python TreeStyle.show_branch_length方法的具体用法?Python TreeStyle.show_branch_length怎么用?Python TreeStyle.show_branch_length使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ete2.TreeStyle
的用法示例。
在下文中一共展示了TreeStyle.show_branch_length方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_example_tree
# 需要导入模块: from ete2 import TreeStyle [as 别名]
# 或者: from ete2.TreeStyle import show_branch_length [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
示例2: showTreeWithPictures
# 需要导入模块: from ete2 import TreeStyle [as 别名]
# 或者: from ete2.TreeStyle import show_branch_length [as 别名]
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)
示例3: plotTree
# 需要导入模块: from ete2 import TreeStyle [as 别名]
# 或者: from ete2.TreeStyle import show_branch_length [as 别名]
def plotTree(self, tree, out_fn=None, rotation=270, show_leaf_name=False,
show_branch_length=False, circularTree=False, show_division_nodes=True,
distance_between_branches=4, show_border=False, width=None, height=None):
from ete2 import TreeStyle
from PyQt4 import QtSvg, QtCore, QtGui
from ete2.treeview import qt4_render, drawer, main
ts = TreeStyle()
ts.show_scale = False
ts.show_border = show_border
ts.orientation = 1 # 0, tree is drawn from left-to-right. 1, tree is drawn from right-to-left
ts.rotation = rotation
ts.show_leaf_name = show_leaf_name
ts.show_branch_length = show_branch_length
if circularTree:
ts.mode = 'c'
else:
ts.mode = 'r'
ts.branch_vertical_margin = distance_between_branches
def hideInternalNodesLayout(node):
if not node.is_leaf():
node.img_style["size"] = 0
if show_division_nodes is False:
ts.layout_fn = hideInternalNodesLayout
if out_fn is not None:
scene = qt4_render._TreeScene()
img = ts
tree_item, n2i, n2f = qt4_render.render(tree, img)
scene.init_data(tree, img, n2i, n2f)
tree_item.setParentItem(scene.master_item)
scene.master_item.setPos(0,0)
scene.addItem(scene.master_item)
main.save(scene, out_fn, w=width, h=height, dpi=600)
else:
scene, img = drawer.init_scene(tree, None, ts)
tree_item, n2i, n2f = qt4_render.render(tree, img)
scene.init_data(tree, img, n2i, n2f)
tree_item.setParentItem(scene.master_item)
scene.addItem(scene.master_item)
size = tree_item.rect()
w, h = size.width(), size.height()
svg = QtSvg.QSvgGenerator()
svg.setFileName("test.svg")
svg.setSize(QtCore.QSize(w, h))
svg.setViewBox(size)
pp = QtGui.QPainter()
pp.begin(svg)
scene.render(pp, tree_item.rect(), tree_item.rect(), QtCore.Qt.KeepAspectRatio)
示例4: showTreeWithPictures
# 需要导入模块: from ete2 import TreeStyle [as 别名]
# 或者: from ete2.TreeStyle import show_branch_length [as 别名]
def showTreeWithPictures(tree = None, alignment=None, branchLengths=True, bootstrapSupport=True, tolabel=None,showZScores=False,showLogs=False ):
print(PICS)
print("ShowTreeWithPictures",tree, alignment, branchLengths,bootstrapSupport, tolabel,showZScores,showLogs )
if not alignment:
nsFG = NodeStyle()
nsFG["fgcolor"] = "darkgreen"
nsFG["size"] = 8
t = EvolTree(tree)
#todo:label
#
for node in t.traverse():
print(node.node_id)
if tolabel:
if str(node.node_id) in tolabel:
node.set_style(nsFG)
#q'n'd
if (node.name.split("_")[0]+".png" in PICS):
print(node.name.split("_")[0]+".png")
node.add_face(ImgFace(PICDIR+os.sep+node.name.split("_")[0]+".png", height=50), column=1, position="aligned")
#non GRZM identifier
elif (node.name+".png" in PICS):
print(node.name+".png")
node.add_face(ImgFace(PICDIR+os.sep+node.name+".png", height=50), column=1, position="aligned")
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"
if Z:
out+="_Z"
if L:
out+="_L"
t.render(out+"_tree.pdf",tree_style=ts)
t.render(out+"_tree.png",tree_style=ts)
if INTERACTIVE:
t.show(tree_style=ts)
else:
t = EvolTree(tree, alignment,alg_format="paml")
t.link_to_alignment(alignment,alg_format="paml")
#todo label
#todo check treestyle
#ts = TreeStyle()
#ts.show_leaf_name = True
#ts.show_branch_length = branchLength
#ts.show_branch_support = bootstrapSupport
t.show()
示例5: main
# 需要导入模块: from ete2 import TreeStyle [as 别名]
# 或者: from ete2.TreeStyle import show_branch_length [as 别名]
def main(argv):
print argv
br = mechanize.Browser()
directoryhtml = br.open(argv)
t_soup = BeautifulSoup(directoryhtml.read())
t_tables = t_soup.findAll('table',{"id":"people"})
t_tbody = t_tables[0].findAll('tbody')
t_trs = t_tbody[0].findAll('tr')
for t_tr in t_trs:
t_tds = t_tr.findAll('td')
username = t_tds[0].find('a').find(text=True)
email = t_tds[1].find('p').find(text=True)
department = t_tds[2].find('p').find(text=True)
title = t_tds[3].find('p').find(text=True)
manager = t_tds[4].find('p').find(text=True)
skypeid = t_tds[5].find('p').find(text=True)
username_list.append(username)
email_list.append(email[:email.find("@")])
manager_list.append(manager)
#Get the root manager
rootname = getRootName()
#Make the tree variable
treeStr = getTree(rootname, "(", ")" + rootname + ";")
treeStr = treeStr.replace("(,", "(")
treeStr = treeStr.replace(",)", ")")
treeStr = treeStr.replace(",,", ",")
ts = TreeStyle()
# Do not add leaf names automatically
ts.show_leaf_name = False
ts.show_branch_length = False
ts.show_scale = False
# Use my custom layout
ts.layout_fn = my_layout
t = Tree(treeStr, format=8)
for n in t.traverse():
nstyle = NodeStyle()
nstyle["fgcolor"] = "red"
nstyle["size"] = 15
n.set_style(nstyle)
count = 0
addNodeCount(t, 0)
#t.add_face(TextFace(str(addNodeCount(t, 0))), column=1, position = "branch-bottom")
# Tell ETE to use your custom Tree Style
t.show(tree_style=ts)
t.render("tree_structure.png", w=183, units="mm")
示例6: load_tree
# 需要导入模块: from ete2 import TreeStyle [as 别名]
# 或者: from ete2.TreeStyle import show_branch_length [as 别名]
def load_tree(f_tree, f_align):
# Tree style
ts = TreeStyle()
ts.show_leaf_name = True
ts.show_branch_length = True
ts.show_branch_support = True
ts.branch_vertical_margin = 10
# Load phylogenetic tree
tree = PhyloTree(f_tree.read())
if f_align is not None:
tree.link_to_alignment(f_align.read())
return tree, ts
示例7: get_tree_style
# 需要导入模块: from ete2 import TreeStyle [as 别名]
# 或者: from ete2.TreeStyle import show_branch_length [as 别名]
def get_tree_style(tree_file, abund, rownames):
with open("matrix.txt", "w") as temp:
cols = len(abund[0])
header = "#Names"
for i in xrange(cols):
header += "\tOTU%d" % i
temp.write("%s\n" % header)
for i, row in enumerate(abund):
temp.write("%s\t%s\n" % (rownames[i], '\t'.join([str(i) for i in row])))
t = Tree(tree_file)
t.convert_to_ultrametric(10)
assert isinstance(abund, numpy.ndarray)
assert isinstance(rownames, numpy.ndarray)
ts = TreeStyle()
ts.mode = "r"
ts.show_leaf_name = False
ts.show_scale = False
ts.show_branch_length = False
ts.branch_vertical_margin = 20
ts.force_topology = True
ts.optimal_scale_level = "full"
ts.scale = 50
ts.draw_guiding_lines = True
ts.guiding_lines_type = 0
ts.guiding_lines_color = "black"
for n in t.traverse():
if not n.is_leaf():
nstyle = NodeStyle()
n.set_style(nstyle)
nstyle['size'] = 0
nstyle['hz_line_width'] = 3
nstyle['vt_line_width'] = 3
else:
nstyle = NodeStyle()
n.set_style(nstyle)
nstyle['size'] = 0
nstyle['hz_line_width'] = 3
nstyle['vt_line_width'] = 3
nstyle['fgcolor'] = "Black"
nstyle['shape'] = "square"
name_face = AttrFace("name", fsize=14, ftype="Arial", fgcolor="black", penwidth=10, text_prefix=" ", text_suffix=" ")
n.add_face(name_face, column=0, position="aligned")
row_index = rownames.tolist().index(n.name)
col = 1
for i in xrange(10):
col += 1
n.add_face(CircleFace(5, color=get_color(abund, row_index, i)), column=col, position="aligned")
return t, ts
示例8: get_tree_style
# 需要导入模块: from ete2 import TreeStyle [as 别名]
# 或者: from ete2.TreeStyle import show_branch_length [as 别名]
def get_tree_style(tree, metadata, colors):
assert isinstance(tree, TreeNode)
ts = TreeStyle()
ts.mode = "c"
ts.show_leaf_name = False
ts.show_scale = False
ts.show_branch_length = False
ts.force_topology = True
ts.optimal_scale_level = "mid"
get_node_styles(tree, metadata, colors)
for site, color in colors.items():
if 'Gastro' in site:
site = "GI"
ts.legend.add_face(CircleFace(7, color), column=0)
ts.legend.add_face(TextFace(" %s" % site, fsize=20), column=1)
return ts
示例9: render_tree
# 需要导入模块: from ete2 import TreeStyle [as 别名]
# 或者: from ete2.TreeStyle import show_branch_length [as 别名]
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)
示例10: plot_tree
# 需要导入模块: from ete2 import TreeStyle [as 别名]
# 或者: from ete2.TreeStyle import show_branch_length [as 别名]
def plot_tree(fixedTree,fileName):
## plot the tree
def my_layout(node):
if node.is_leaf():
name_face = AttrFace("name",fsize=25)
faces.add_face_to_node(name_face, node, column=0, position="branch-right")
else:
name_face = AttrFace("name", fsize=20, fgcolor="red")
faces.add_face_to_node(name_face, node, column=0, position="branch-right")
ts = TreeStyle()
ts.show_leaf_name = False
ts.show_branch_length = True
ts.show_branch_support = True
ts.scale = 180
ts.layout_fn = my_layout
out = fixedTree.render(fileName, units="mm",tree_style=ts,dpi=400)
示例11: main
# 需要导入模块: from ete2 import TreeStyle [as 别名]
# 或者: from ete2.TreeStyle import show_branch_length [as 别名]
def main(argv):
inputfile = ''
outgroup = ''
outputfile = ''
ts = TreeStyle()
ts.show_leaf_name = True
ts.show_branch_length = False
ts.show_branch_support = True
ns = NodeStyle()
ns["size"] = 0
ns["vt_line_width"] = 2
ns["hz_line_width"] = 2
try:
opts, args = getopt.getopt(argv,"hi:o:p:",["input=","outgroup=","-prefix-svg="])
except getopt.GetoptError:
print 'print-single-nwk.py -i <inputfile> -o <outgroup> -p <prefixsvg>'
sys.exit(2)
for opt, arg in opts:
if opt == '-h':
print 'print-single-nwk.py -i <inputfile> -o <outgroup> -p <prefixsvg>'
sys.exit()
elif opt in ("-i", "--input"):
inputfile = arg
elif opt in ("-o", "--outgroup"):
outgroup = arg
elif opt in ("-p", "--prefix-svg"):
outputfile = arg
# read tree
t = Tree(inputfile)
t.set_outgroup(outgroup)
t.ladderize(1)
for node in t.traverse():
node.set_style(ns)
# print final tree
t.render(outputfile + ".svg", tree_style=ts)
示例12: showAlignmentWithTree
# 需要导入模块: from ete2 import TreeStyle [as 别名]
# 或者: from ete2.TreeStyle import show_branch_length [as 别名]
def showAlignmentWithTree(tree,alignment):
print(tree)
t = EvolTree(tree, alignment,alg_format="paml")
nsFG = NodeStyle()
nsFG["fgcolor"] = "darkgreen"
nsFG["size"] = 15
#print(t)
#t.run_model ('fb.example')
# t.show()
t.link_to_alignment(alignment, alg_format="paml")
for node in t.traverse():
print(node)
#if (node.name.split("_")[0] in GENES):
# print(node.name, node.node_id)
# if (node.name.split("_")[0] == "GRMZM2G083841"):
# node.add_face(ImgFace("83841.1.png", height=50, width=50), column=1, position="aligned")
# if (node.name.split("_")[0] == "GRMZM2G473001"):
# node.add_face(ImgFace("473001.png", height=50, width=50), column=1, position="aligned")
node.add_face(TextFace(str(node.node_id)),column=0)
#node.add_face(ImgFace("tux.png", height=50), column=1)
# node.set_style(nsFG)
leaves = node.get_leaf_names()
#leaves = [l for l in leaves if l.split("_")[0] in GENES ]
if leaves !=[]:
print(node.name, node.node_id)
#print(node.node_id)
#t.mark_tree([8], marks=["#1"])
#print(t.write())
#print(alignment)
#print(t)
#t.show() #layout=evol_clean_layout)
ts = TreeStyle()
ts.show_leaf_name = True
ts.show_branch_length = True
ts.show_branch_support = True
t = fakeUnroot(t)
t.show(tree_style=ts)
t.render("tree.pdf", tree_style=ts)
示例13: setTreeStyle
# 需要导入模块: from ete2 import TreeStyle [as 别名]
# 或者: from ete2.TreeStyle import show_branch_length [as 别名]
def setTreeStyle(style, layoutfunction):
#consolidate options for showing trees
#pass in string "circle" or "rect" and a layout function
I = TreeStyle()
if style == "circle":
I.tree_width = 1200
I.layout_fn = layoutfunction
I.show_branch_length = False
#I.show_branch_support = True
I.show_leaf_name = False
I.mode = "c"
I.force_topology = True
#I.legend_position = 3
I.extra_branch_line_type = 1
I.guiding_lines_type = 1
I.guiding_lines_color = "#666666"
I.extra_branch_line_color = "#666666"
I.optimal_scale_level = "full"
I.root_opening_factor = 0
elif style =="rect":
I = TreeStyle()
I.layout_fn = layoutfunction
I.show_leaf_name = False
I.force_topology = True
I.optimal_scale_level = "semi"
else:
I.layout_fn = layoutfunction
I.show_leaf_name = False
I.force_topology = True
I.optimal_scale_level = "semi"
return I
示例14: cluster
# 需要导入模块: from ete2 import TreeStyle [as 别名]
# 或者: from ete2.TreeStyle import show_branch_length [as 别名]
#.........这里部分代码省略.........
plt.tight_layout() # fixes margins
## Conversion to Newick/ETE
# Stuff we need
from scipy.cluster.hierarchy import average, linkage, to_tree
#from hcluster import linkage, to_tree
from ete2 import Tree, TreeStyle, NodeStyle
# Change it to a distance matrix
T = to_tree(Z)
# ete2 section
root = Tree()
root.dist = 0
root.name = "root"
item2node = {T: root}
to_visit = [T]
while to_visit:
node = to_visit.pop()
cl_dist = node.dist /2.0
for ch_node in [node.left, node.right]:
if ch_node:
ch = Tree()
ch.dist = cl_dist
ch.name = str(ch_node.id)
item2node[node].add_child(ch)
item2node[ch_node] = ch
to_visit.append(ch_node)
# This is the ETE tree structure
tree = root
ts = TreeStyle()
ts.show_leaf_name = True
ts.show_branch_length = True
ts.show_scale = False
ts.scale = None
if orientation == "top":
ts.rotation = 90
ts.branch_vertical_margin = 10 # 10 pixels between adjacent branches
# Draws nodes as small red spheres of diameter equal to 10 pixels
nstyle = NodeStyle()
nstyle["size"] = 0
# Replace the node labels
for leaf in tree:
k = leaf.name
k = int(k)
leaf.name = labels[k]
# Apply node styles to nodes
for n in tree.traverse():
n.set_style(nstyle)
# Convert the ETE tree to Newick
newick = tree.write()
f = open('C:\\Users\\Scott\\Documents\\GitHub\\d3-dendro\\newickStr.txt', 'w')
f.write(newick)
f.close()
# Save the image as .png...
from os import path, makedirs
# Using ETE
folder = pathjoin(session_manager.session_folder(), constants.RESULTS_FOLDER)
if (not os.path.isdir(folder)):
makedirs(folder)
# saves dendrogram as a .png with pyplot
plt.savefig(path.join(folder, constants.DENDROGRAM_PNG_FILENAME))
plt.close()
# if orientation == "top":
# plt.figure(figsize=(20,80))
# else:
# plt.figure(figsize=(80,20))
pdfPageNumber, score, inconsistentMax, maxclustMax, distanceMax, distanceMin, monocritMax, monocritMin, threshold = utility.generateDendrogram(
fileManager)
session['dengenerated'] = True
labels = fileManager.getActiveLabels()
inconsistentOp = "0 " + leq + " t " + leq + " " + str(inconsistentMax)
maxclustOp = "2 " + leq + " t " + leq + " " + str(maxclustMax)
distanceOp = str(distanceMin) + " " + leq + " t " + leq + " " + str(distanceMax)
monocritOp = str(monocritMin) + " " + leq + " t " + leq + " " + str(monocritMax)
thresholdOps = {"inconsistent": inconsistentOp, "maxclust": maxclustOp, "distance": distanceOp,
"monocrit": monocritOp}
managers.utility.saveFileManager(fileManager)
session_manager.cacheAnalysisOption()
session_manager.cacheHierarchyOption()
import random
ver = random.random() * 100
return render_template('cluster.html', labels=labels, pdfPageNumber=pdfPageNumber, score=score,
inconsistentMax=inconsistentMax, maxclustMax=maxclustMax, distanceMax=distanceMax,
distanceMin=distanceMin, monocritMax=monocritMax, monocritMin=monocritMin,
threshold=threshold, thresholdOps=thresholdOps, ver=ver)
示例15: TreeStyle
# 需要导入模块: from ete2 import TreeStyle [as 别名]
# 或者: from ete2.TreeStyle import show_branch_length [as 别名]
#!/usr/bin/py
from ete2 import Tree
import sys
from ete2 import Tree, TreeStyle
from Bio import SeqIO
import os
import numpy as np
circular_style = TreeStyle()
circular_style.mode = "c" # draw tree in circular mode
circular_style.scale = 20
ts = TreeStyle()
ts.show_leaf_name = True
ts.show_branch_length = False
ts.show_branch_support = False
#need the Tree and sys packages
#script stole from https://www.biostars.org/p/97409/
def mean(array):
return sum(array)/float(len(array))
def cache_distances(tree):
''' precalculate distances of all nodes to the root'''
node2rootdist = {tree:0}
for node in tree.iter_descendants('preorder'):
node2rootdist[node] = node.dist + node2rootdist[node.up]
return node2rootdist
def collapse(tree, min_dist):
# cache the tip content of each node to reduce the number of times the tree is traversed
#Because the collapsing is happening from the inner nodes, we could iterate over the collapsing several times, but we will not.
num_tips=len(tree.get_leaves())