本文整理汇总了Python中ete2.TreeStyle.layout_fn方法的典型用法代码示例。如果您正苦于以下问题:Python TreeStyle.layout_fn方法的具体用法?Python TreeStyle.layout_fn怎么用?Python TreeStyle.layout_fn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ete2.TreeStyle
的用法示例。
在下文中一共展示了TreeStyle.layout_fn方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_example_tree
# 需要导入模块: from ete2 import TreeStyle [as 别名]
# 或者: from ete2.TreeStyle import layout_fn [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: build_vis
# 需要导入模块: from ete2 import TreeStyle [as 别名]
# 或者: from ete2.TreeStyle import layout_fn [as 别名]
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
示例3: generateImage
# 需要导入模块: from ete2 import TreeStyle [as 别名]
# 或者: from ete2.TreeStyle import layout_fn [as 别名]
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)
示例4: visualizeTree
# 需要导入模块: from ete2 import TreeStyle [as 别名]
# 或者: from ete2.TreeStyle import layout_fn [as 别名]
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
示例5: get_example_tree
# 需要导入模块: from ete2 import TreeStyle [as 别名]
# 或者: from ete2.TreeStyle import layout_fn [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
示例6: render_tree
# 需要导入模块: from ete2 import TreeStyle [as 别名]
# 或者: from ete2.TreeStyle import layout_fn [as 别名]
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
示例7: get_example_tree
# 需要导入模块: from ete2 import TreeStyle [as 别名]
# 或者: from ete2.TreeStyle import layout_fn [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
示例8: plotTree
# 需要导入模块: from ete2 import TreeStyle [as 别名]
# 或者: from ete2.TreeStyle import layout_fn [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)
示例9: get_example_tree
# 需要导入模块: from ete2 import TreeStyle [as 别名]
# 或者: from ete2.TreeStyle import layout_fn [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
示例10: get_example_tree
# 需要导入模块: from ete2 import TreeStyle [as 别名]
# 或者: from ete2.TreeStyle import layout_fn [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
示例11: get_example_tree
# 需要导入模块: from ete2 import TreeStyle [as 别名]
# 或者: from ete2.TreeStyle import layout_fn [as 别名]
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
示例12: taxo_msa
# 需要导入模块: from ete2 import TreeStyle [as 别名]
# 或者: from ete2.TreeStyle import layout_fn [as 别名]
def taxo_msa(outfile='taxo_msa.svg',taxids=[],annotation='',msa=[],title='',width=2000):
"""
Visualize MSA together with a taxonomy tree
taxids - list of taxids in the same order as seqs in msa
"""
# taxid2gi={f_df.loc[f_df.gi==int(gi),'taxid'].values[0]:gi for gi in list(f_df['gi'])}
# gi2variant={gi:f_df.loc[f_df.gi==int(gi),'hist_var'].values[0] for gi in list(f_df['gi'])}
# msa_dict={i.id:i.seq for i in msa_tr}
ncbi = NCBITaxa()
taxids=map(int,taxids)
t = ncbi.get_topology(taxids,intermediate_nodes=False)
a=t.add_child(name='annotation')
a.add_feature('sci_name','annotation')
t.sort_descendants(attr='sci_name')
ts = TreeStyle()
def layout(node):
# print node.rank
# print node.sci_name
if getattr(node, "rank", None):
if(node.rank in ['order','class','phylum','kingdom']):
rank_face = AttrFace("sci_name", fsize=7, fgcolor="indianred")
node.add_face(rank_face, column=0, position="branch-top")
if node.is_leaf():
sciname_face = AttrFace("sci_name", fsize=9, fgcolor="steelblue")
node.add_face(sciname_face, column=0, position="branch-right")
if node.is_leaf() and not node.name=='annotation':
s=str(msa[taxids.index(int(node.name))].seq)
seqFace = SeqMotifFace(s,[[0,len(s), "seq", 10, 10, None, None, None]],scale_factor=1)
add_face_to_node(seqFace, node, 0, position="aligned")
# gi=taxid2gi[int(node.name)]
add_face_to_node(TextFace(' '+msa[taxids.index(int(node.name))].id),node,column=1, position = "aligned")
# add_face_to_node(TextFace(' '+str(int(node.name))+' '),node,column=2, position = "aligned")
# add_face_to_node(TextFace(' '+str(gi2variant[gi])+' '),node,column=3, position = "aligned")
if node.is_leaf() and node.name=='annotation':
if(annotation):
s=annotation
# get_hist_ss_in_aln_as_string(msa_tr)
else:
s=' '*len(msa[0].seq)
seqFace = SeqMotifFace(s,[[0,len(s), "seq", 10, 10, None, None, None]],scale_factor=1)
add_face_to_node(seqFace, node, 0, position="aligned")
add_face_to_node(TextFace(' '+'SEQ_ID'),node,column=1, position = "aligned")
# add_face_to_node(TextFace(' '+'NCBI_TAXID'+' '),node,column=2, position = "aligned")
# add_face_to_node(TextFace(' '+'Variant'+' '),node,column=3, position = "aligned")
ts.layout_fn = layout
ts.show_leaf_name = False
ts.title.add_face(TextFace(title, fsize=20), column=0)
t.render(outfile, w=width, dpi=300, tree_style=ts)
示例13: main
# 需要导入模块: from ete2 import TreeStyle [as 别名]
# 或者: from ete2.TreeStyle import layout_fn [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")
示例14: get_example_tree
# 需要导入模块: from ete2 import TreeStyle [as 别名]
# 或者: from ete2.TreeStyle import layout_fn [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
示例15: drawTree
# 需要导入模块: from ete2 import TreeStyle [as 别名]
# 或者: from ete2.TreeStyle import layout_fn [as 别名]
def drawTree(nwfile, outfile):
from ete2 import Tree, TreeStyle, TextFace
ts = TreeStyle()
ts.show_leaf_name = False
ts.layout_fn = my_layout
ts.branch_vertical_margin = 12.75
ts.orientation = 1
titleFace = TextFace("Phylogenetic Tree", fsize=18, fgcolor="white")
titleFace.margin_top = 15
ts.title.add_face(titleFace, column=1)
t = Tree(nwfile)
t.render(outfile, tree_style=ts)