Example #1
0
def layout(n):
    nstyle = NodeStyle()
    nstyle['shape'] = 'sphere'
    nstyle['size'] = 0
    nstyle['fgcolor'] = 'black'
    nstyle["hz_line_width"] = 2
    nstyle["vt_line_width"] = 2
    n.set_style(nstyle)

    clustering = None
    subclustering = None
    if args.clusters:
        clustering = read_clusters(args.clusters)
    if args.subclusters:
        subclustering = read_clusters(args.subclusters)

    if n.is_leaf():
        s = samples[n.name]
        if args.circular:
            radius=12
        else:
            radius=4
        c = CircleFace(radius=radius, color=s['prefec__colour'], style='circle')
        n.add_face(c, column=0)

        offset = 1
        if not args.hide_annotations:
            offset += 5
            tf = MyTextFace(s['id'], fsize=8, tight_text=False)
            n.add_face(tf, column=1, position="aligned")
            n.add_face(MyTextFace(s['prefec'], fsize=8, tight_text=False), column=2, position="aligned")
            n.add_face(MyTextFace(s['subprefec'], fsize=8, tight_text=False), column=3, position="aligned")
            n.add_face(MyTextFace(s['village'], fsize=8, tight_text=False), column=4, position="aligned")
            n.add_face(MyTextFace(s['date'], fsize=8, tight_text=False), column=5, position="aligned")

        if clustering:
            n.add_face(MyBorderFace(clustering[n.name], fsize=20, tight_text=False), column=offset, position="aligned")
            offset += 1

        if subclustering:
            n.add_face(MyBorderFace(subclustering[n.name], fsize=20, tight_text=False), column=offset, position="aligned")
            offset += 1

        if hasattr(n, 'sequence'):
            sf = faces.SequenceFace(n.sequence, "aa", fsize=10, fg_colors=blackcolors, bg_colors=seqcolors, col_w=11)
            n.add_face(sf, column=offset, position="aligned")
            offset += 1
Example #2
0
from ete3 import TreeStyle
from ete3 import EvolTree
from ete3 import faces

tree = EvolTree("data/S_example/measuring_S_tree.nw")
tree.link_to_alignment('data/S_example/alignment_S_measuring_evol.fasta')

print(tree)

print('\n Running free-ratio model with calculation of ancestral sequences...')

tree.run_model('fb_anc')
#tree.link_to_evol_model('/tmp/ete3-codeml/fb_anc/out', 'fb_anc')

I = TreeStyle()
I.force_topology = False
I.draw_aligned_faces_as_table = True
I.draw_guiding_lines = True
I.guiding_lines_type = 2
I.guiding_lines_color = "#CCCCCC"
for n in sorted(tree.get_descendants() + [tree], key=lambda x: x.node_id):
    if n.is_leaf(): continue
    anc_face = faces.SequenceFace(n.sequence, 'aa', fsize=10, bg_colors={})
    I.aligned_foot.add_face(anc_face, 1)
    I.aligned_foot.add_face(
        faces.TextFace('node_id: #%d ' % (n.node_id), fsize=8), 0)
print('display result of bs_anc model, with ancestral amino acid sequences.')
tree.show(tree_style=I)

print('\nThe End.')