예제 #1
0
def layout(node):
    node.img_style["size"] = 5
    node.img_style["hz_line_width"] = 0
    node.img_style["vt_line_width"] = 0
    if node.is_leaf():
        f = faces.AttrFace("name", fgcolor="steelblue", fsize=20)
        faces.add_face_to_node(f, node, 0, position="aligned")

        f = faces.AttrFace("name", fsize=15)
        faces.add_face_to_node(f, node, 0, position="branch-right")
    else:
        f = faces.TextFace("uno", fsize=8)
        for x in xrange(random.randint(1, 5)):
            faces.add_face_to_node(f, node, 0, position="branch-top")

        f = faces.TextFace("otromassssssssssss", fsize=8)
        for x in xrange(random.randint(1, 5)):
            faces.add_face_to_node(f, node, 0, position="branch-bottom")

    f = faces.CircleFace(20, "red")
    f.opacity = 0.3
    faces.add_face_to_node(f, node, 0, position="float")
    f = faces.CircleFace(23, "blue")
    f.opacity = 0.3
    faces.add_face_to_node(f, node, 0, position="float-behind")
예제 #2
0
def prettifyTree(ete_tree,
                 leaf_font_size=32,
                 branch_support_size=20,
                 show_bootstraps=True,
                 title=None,
                 ts=None):
    ''' Perform standardized functions to make the ETE trees easier to read:
    - Make the branch support bigger
    - Make the leaf fonts bigger
    - Turn off elongating branches for visualization purposes (i.e. make sure the real branch lengths are represented)
    - Change both to standard font (Times)
    - Standardize the tree's width (calculate based on the maximum length from the root to a tip)
    - (optional) add title to tree
    '''

    for node in ete_tree.traverse():
        if node.is_leaf():
            # Make text faces with name = the existing node name but with big font.
            # A side effect of this is that we also get the annotations lined up
            F = faces.TextFace(node.name, ftype="Times", fsize=leaf_font_size)
            node.add_face(F, 0, position="aligned")
        else:
            if show_bootstraps:
                # Make branch support bigger
                F = faces.TextFace(node._support,
                                   ftype="Times",
                                   fsize=branch_support_size)
                node.add_face(F, 0, position="branch-top")

    #correct the long root node bug (fixed in next release)
    ete_tree.dist = 0

    # Optionally create a new TreeStyle if we are not passing in an old one.
    if ts is None:
        ts = TreeStyle()

    # This "fixes" the dashed line issue but makes the tree look terrible.
    # There may be no way around this (and it's likely other tree viewers do the same thing
    # but just don't tell you).
    #ts.optimal_scale_level = "full"

    # We made these bigger so lets turn off the default ones too.
    ts.show_branch_support = False
    ts.show_leaf_name = False

    if title is not None:
        ts.title.clear()
        title = TextFace(title)
        title.hz_align = True
        title.fsize = 52
        ts.title.add_face(title, 0)

    return ete_tree, ts
def layout(node):
    node.img_style["size"] = random.randint(5,100)
    node.img_style["hz_line_width"] = 5
    node.img_style["vt_line_width"] = 10
    if node.is_leaf():
        #node.img_style["size"] = random.randint(50, 50)
        f = faces.TextFace("alignedFace", fsize=8, fgcolor="blue")
        #f = faces.AttrFace("name", fsize=random.randint(20,20))
        faces.add_face_to_node(f, node, 0, position="aligned")
        f.border.width = 0
        #f = faces.CircleFace(20, "red")
        #f = faces.AttrFace("name", fsize=20)
        f = faces.TextFace("NAME", fsize=10)
        #faces.add_face_to_node(f, node, 0, position="branch-right")
        f.border.width = 0
예제 #4
0
    # Max, Min, Center, Width, Height, Type)
    # I give it 60 pixels per column by default
    # (so that the width doesn't shrink down too much when we have more than a few columns)
    # However, the user has the ability to change thsi if they need to / want to for larger data sets
    profileFace  = ProfileFace(matrix_max, matrix_min, matrix_avg, width=numcols*options.data_width, height=35, style="heatmap")
    for node in t.traverse():
        if node.is_leaf():
            node.add_face(profileFace, 1, position = "aligned")
    
    # Add the color bar (kind of hacked in from matplotlib since there is no convenient way to get it from ETE)
    # I could generate this in situ... for now I just have a file I like and run with it.
    # This doesn't match exactlty becuase I don't have the time or motivation now to mess with QT to do it.
    # It should be pretty close though...
    from ete2 import ImgFace
    imgloc = os.path.join(locateRootDirectory(), "src", "internal", "Colormap.png")
    F1 = faces.TextFace("Minimum: %1.1f" %(matrix_min), ftype="Times", fsize=32 )
    F2 = faces.ImgFace(imgloc)
    F3 = faces.TextFace("%1.1f : Maximum" %(matrix_max), ftype="Times", fsize=32 )
    ts.legend.add_face(F1, 0)
    ts.legend.add_face(F2, 1)
    ts.legend.add_face(F3, 2)
    # Put it on the Bottom-left
    ts.legend_position = 3

if options.savenewick:
    t.write(outfile="%s.nwk" %(options.basename), format=0)

if options.savesvg:
    # Some versions of ETE create a "test.svg" and others do not.
    # To avoid confusion (and in case TreeStyle isn't enforced)
    # I just create a new one.