本文整理汇总了Python中ete3.TreeStyle.legend_position方法的典型用法代码示例。如果您正苦于以下问题:Python TreeStyle.legend_position方法的具体用法?Python TreeStyle.legend_position怎么用?Python TreeStyle.legend_position使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ete3.TreeStyle
的用法示例。
在下文中一共展示了TreeStyle.legend_position方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_default_tree_style
# 需要导入模块: from ete3 import TreeStyle [as 别名]
# 或者: from ete3.TreeStyle import legend_position [as 别名]
def get_default_tree_style(color_dict):
ts = TreeStyle()
ts.mode = "c"
# ts.layout_fn = layout
ts.margin_top = 50
ts.margin_bottom = 0
ts.margin_left = 50
ts.margin_right = 50
ts.show_scale = False
ts.show_leaf_name = False
ts.show_branch_length = False
ts.show_branch_support = False
for p, c in color_dict.iteritems():
ts.legend.add_face(TextFace(" ", fsize=30), column=0)
ts.legend.add_face(CircleFace(10, c), column=1)
ts.legend.add_face(TextFace(" %s" % p, fsize=30), column=2)
legend_margin_line = 5
while legend_margin_line:
ts.legend.add_face(TextFace(" "), column=0)
ts.legend.add_face(TextFace(" "), column=1)
ts.legend.add_face(TextFace(" "), column=2)
legend_margin_line -= 1
ts.legend_position = 3
return ts
示例2: draw_tree
# 需要导入模块: from ete3 import TreeStyle [as 别名]
# 或者: from ete3.TreeStyle import legend_position [as 别名]
#.........这里部分代码省略.........
pass
def ly_block_alg(node):
if node.is_leaf():
if 'sequence' in node.features:
seqFace = SeqMotifFace(node.sequence, [])
# [10, 100, "[]", None, 10, "black", "rgradient:blue", "arial|8|white|domain Name"],
motifs = []
last_lt = None
for c, lt in enumerate(node.sequence):
if lt != '-':
if last_lt is None:
last_lt = c
if c+1 == len(node.sequence):
start, end = last_lt, c
motifs.append([start, end, "()", 0, 12, "slategrey", "slategrey", None])
last_lt = None
elif lt == '-':
if last_lt is not None:
start, end = last_lt, c-1
motifs.append([start, end, "()", 0, 12, "grey", "slategrey", None])
last_lt = None
seqFace = SeqMotifFace(node.sequence, motifs,
intermotif_format="line",
seqtail_format="line", scale_factor=ALG_SCALE)
add_face_to_node(seqFace, node, ALG_START_COL, aligned=True)
TRACKED_CLADES = ["Eukaryota", "Viridiplantae", "Fungi",
"Alveolata", "Metazoa", "Stramenopiles", "Rhodophyta",
"Amoebozoa", "Crypthophyta", "Bacteria",
"Alphaproteobacteria", "Betaproteobacteria", "Cyanobacteria",
"Gammaproteobacteria",]
# ["Opisthokonta", "Apicomplexa"]
colors = random_color(num=len(TRACKED_CLADES), s=0.45)
lin2color = dict([(ln, colors[i]) for i, ln in enumerate(TRACKED_CLADES)])
NAME_FACE = AttrFace('name', fsize=10, fgcolor='#444444')
LABEL_START_COL = 10
ALG_START_COL = 40
ts = TreeStyle()
ts.draw_aligned_faces_as_table = False
ts.draw_guiding_lines = False
ts.show_leaf_name = False
ts.show_branch_support = False
ts.scale = 160
ts.layout_fn = [ly_basic, ly_leaf_names, ly_supports, ly_tax_labels]
MIXED_RES = set()
MAX_SEQ_LEN = 0
NPR_TREES = []
for n in tree.traverse():
if hasattr(n, "tree_seqtype"):
MIXED_RES.add(n.tree_seqtype)
if hasattr(n, "tree_type"):
NPR_TREES.append(n.tree_type)
seq = getattr(n, "sequence", "")
MAX_SEQ_LEN = max(len(seq), MAX_SEQ_LEN)
if MAX_SEQ_LEN:
ALG_SCALE = min(1, 1000./MAX_SEQ_LEN)
ts.layout_fn.append(ly_block_alg)
if len(NPR_TREES) > 1:
rF = RectFace(4, 4, "steelblue", "steelblue")
rF.margin_right = 10
rF.margin_left = 10
ts.legend.add_face(rF, 0)
ts.legend.add_face(TextFace(" NPR node"), 1)
ts.legend_position = 3
if len(MIXED_RES) > 1:
rF = RectFace(20, 20, "#CFE6CA", "#CFE6CA")
rF.margin_right = 10
rF.margin_left = 10
ts.legend.add_face(rF, 0)
ts.legend.add_face(TextFace(" Nucleotide based alignment"), 1)
ts.legend_position = 3
try:
tree.set_species_naming_function(spname)
annotate_tree_with_ncbi(tree)
a = tree.search_nodes(species='Dictyostelium discoideum')[0]
b = tree.search_nodes(species='Chondrus crispus')[0]
#out = tree.get_common_ancestor([a, b])
#out = tree.search_nodes(species='Haemophilus parahaemolyticus')[0].up
tree.set_outgroup(out)
tree.swap_children()
except Exception:
pass
tree.render(outfile, tree_style=ts, w=170, units='mm', dpi=150)
tree.render(outfile+'.svg', tree_style=ts, w=170, units='mm', dpi=150)
tree.render(outfile+'.pdf', tree_style=ts, w=170, units='mm', dpi=150)
示例3: main
# 需要导入模块: from ete3 import TreeStyle [as 别名]
# 或者: from ete3.TreeStyle import legend_position [as 别名]
def main(args):
if args.alignment:
t = PhyloTree(args.tree, alignment=args.alignment, alg_format='fasta')
else:
t = PhyloTree(args.tree)
if args.highlight_new:
runs = read_runs(args.highlight_new)
t.set_outgroup('EM_079422')
t.ladderize()
ts = TreeStyle()
ts.show_leaf_name = False
ts.show_branch_support = False
ts.layout_fn = layout
thick_hz_line = NodeStyle()
thick_hz_line["hz_line_width"] = 8
t.set_style(thick_hz_line)
#t.children[0].set_style(thick_hz_line)
#t.children[1].set_style(thick_hz_line)
thick_vt_line = NodeStyle()
thick_vt_line["vt_line_width"] = 4
t.set_style(thick_vt_line)
# header
if not args.hide_annotations:
ts.aligned_header.add_face(MyTextFace('Sample identifier', fstyle='Bold', fsize=8, tight_text=False), column = 1)
ts.aligned_header.add_face(MyTextFace('Prefecture', fstyle='Bold', fsize=8, tight_text=False), column = 2)
ts.aligned_header.add_face(MyTextFace('Sous-prefecture', fstyle='Bold', fsize=8, tight_text=False), column = 3)
ts.aligned_header.add_face(MyTextFace('Village', fstyle='Bold', fsize=8, tight_text=False), column = 4)
ts.aligned_header.add_face(MyTextFace('Sample received', fstyle='Bold', fsize=8, tight_text=False), column = 5)
if args.positions:
positions = read_positions(args.positions)
alg_header = RulerFace(positions,
col_width=11,
height=0, # set to 0 if dont want to use values
kind="stick",
hlines = [0],
hlines_col = ["white"], # trick to hide hz line
)
ts.aligned_header.add_face(alg_header, 6)
#legend
if args.legend:
legend = {}
for s in samples.values():
legend[s['prefec']] = s['prefec__colour']
for p in sorted(legend.keys()):
ts.legend.add_face(CircleFace(4, legend[p]), column=0)
ts.legend.add_face(MyTextFace(p, fsize=6, tight_text=False), column=1)
ts.legend_position=1
if args.circular:
ts.mode = "c"
ts.arc_start = -180 # 0 degrees = 3 o'clock
ts.arc_span = 180
# t.show(tree_style=ts)
t.render(args.output, tree_style=ts, w=1024)