示例#1
0
def set_node_style(node, status, n_gl_sets, ref_label=None):
    if status != 'internal':
        if status not in scolors:
            raise Exception('status \'%s\' not in scolors' % status)
        node.img_style['bgcolor'] = scolors[status]
        if status not in used_colors:
            used_colors[status] = scolors[status]

        if glutils.is_novel(node.name):
            node.add_face(ete3.CircleFace(args.novel_dot_size, scolors['novel']), column=1) #, position='float') # if args.leaf_names else 'branch')

    # linewidth = 2
    # node.img_style['hz_line_width'] = linewidth
    # node.img_style['vt_line_width'] = linewidth

    names = status.split('-&-')
    if node.is_leaf():
        if args.pie_chart_faces and len(names) > 1:
            pcf = ete3.PieChartFace(percents=[100./len(names) for _ in range(len(names))], width=args.leafheight, height=args.leafheight, colors=[scolors[n] for n in names], line_color=None)
            # pcf = ete3.StackedBarFace(percents=[100./len(names) for _ in range(len(names))], width=30, height=50, colors=[scolors[n] for n in names], line_color=None)
            node.add_face(pcf, column=0, position='aligned')
        elif len(names) == 1 and names[0] in used_faces:
            node.add_face(ete3.RectFace(width=5, height=args.leafheight, bgcolor=used_faces[names[0]], fgcolor=None), column=0, position='aligned')
        elif n_gl_sets > 2:
            rectnames = [n for n in names if n in used_faces]
            node.add_face(ete3.StackedBarFace(percents=[100./len(names) for _ in range(len(rectnames))], width=5 * len(rectnames), height=args.leafheight, colors=[used_faces[rn] for rn in rectnames], line_color=None), column=0, position='aligned')
        else:  # every leaf has to have a face, so that every leaf takes up the same vertical space
            node.add_face(ete3.RectFace(width=1, height=args.leafheight, bgcolor=None, fgcolor=None), column=0, position='aligned')
示例#2
0
def multiplicity_legend(ts):
    ts.legend.add_face(ete3.faces.TextFace(""), 0)
    ts.legend.add_face(ete3.faces.TextFace("Multiplicity"), 1)
    for multiplicity in [1, 10, 100]:
        size = scale_node(multiplicity)
        pie_face = ete3.PieChartFace([100],
                                     width=size,
                                     height=size,
                                     colors=['grey'])
        ts.legend.add_face(pie_face, 0)
        ts.legend.add_face(ete3.faces.TextFace(str(multiplicity)), 1)
示例#3
0
def leaf_style(node, seqmeta, tp_colors, highlight_node=None):
    name = node.name + " (mf={}) ".format(round(float(seqmeta['mut_freq']), 3))
    F = ete3.faces.TextFace(name, fsize=9)
    ete3.add_face_to_node(F, node, column=1, position='branch-right')
    ## Style the node with color corresponding to timepoint
    nstyle = ete3.NodeStyle()
    #if node.name == highlight_node:
    #nstyle['fgcolor'] = 'brown'
    #else:
    #nstyle['fgcolor'] = tp_colors[seqmeta['timepoint']]
    nstyle['size'] = 0
    node.set_style(nstyle)
    # Style the node with color corresponding to timepoint
    if False:
        nstyle = ete3.NodeStyle()
        if node.name == highlight_node:
            nstyle['fgcolor'] = 'brown'
        else:
            nstyle['fgcolor'] = tp_colors[seqmeta['timepoint']]
        nstyle['size'] = 14
        node.set_style(nstyle)
    timepoints = filter(
        lambda x: x,
        seqmeta.get('cluster_timepoints', seqmeta['timepoints']).split(':'))
    duplicities = [
        int(n)
        for n in seqmeta.get('cluster_timepoint_multiplicities',
                             seqmeta['timepoint_multiplicities']).split(':')
        if n
    ]
    multiplicity = int(
        seqmeta.get('cluster_multiplicity', seqmeta['multiplicity']))
    percents = [d * 100 / multiplicity for d in duplicities]
    colors = [tp_colors[t] for t in timepoints]
    pie_node = ete3.PieChartFace(percents,
                                 width=scale_node(multiplicity),
                                 height=scale_node(multiplicity),
                                 colors=colors,
                                 line_color='black')
    ete3.add_face_to_node(pie_node, node, column=0)