Beispiel #1
0
    def show(self, layout=None, tree_style=None, histfaces=None):
        '''
        call super show of PhyloTree
        histface should be a list of models to be displayes as histfaces

        :argument layout: a layout function
        :argument None tree_style: tree_style object
        :argument Nonehistface: an histogram face function. This is only to plot selective pressure among sites

        '''
        if TREEVIEW:
            if not tree_style:
                ts = TreeStyle()
            else:
                ts = tree_style
            if histfaces:
                for hist in histfaces:
                    try:
                        mdl = self.get_evol_model(hist)
                    except AttributeError:
                        warn('model %s not computed' % (hist))
                    if not 'histface' in mdl.properties:
                        if len(histfaces) > 1 and histfaces.index(hist) != 0:
                            mdl.set_histface(up=False)
                        else:
                            mdl.set_histface()
                    if mdl.properties['histface'].up:
                        ts.aligned_header.add_face(mdl.properties['histface'],
                                                   1)
                    else:
                        ts.aligned_foot.add_face(mdl.properties['histface'], 1)
            super(EvolTree, self).show(layout=layout, tree_style=ts)
        else:
            raise ValueError("Treeview module is disabled")
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
    if options.gene is None:
        gene = options.clusterrunid
    else:
        gene = options.gene

    # FIXME - if we declare this as a PhyloTree rather than just a Tree, ETE for some reason creates an
    # EXTRA COPY of the names (try it and see!) and therefore if you set show_leaf_names to True it shows
    # TWO copies of the leaf name at each leaf node (and if you set it to False it shows one, making it look
    # like it's ignoring you when you set it to False). The Tree class works as expected.
    #
    # Since we only need PhyloTree when we want to export to PhyloXML (not implemented yet), we should only create one
    # in that instance (due to the brokenness)
#    t = PhyloTree(treeinfile, sp_naming_function=parse_sp_name)
    t = Tree(treeinfile)
    ts = TreeStyle()

    con = sqlite3.connect(locateDatabase())
    cur = con.cursor()

    tempdir = tempfile.mkdtemp()

    t, ts = draw_tree_regions(clusterrunid,
                              t,
                              ts,
                              cur,
                              greyout=options.cutoff,
                              tempdir=tempdir,
                              label=options.label)

    # Now that we don't need to reference anything with the gene IDs any more, try to change them into