Beispiel #1
0
    def sel_mylayout(node):
        node.set_style(my_node_style)

        if node.is_leaf():
            # add names in larger font + italics
            species_name = AttrFace("name", fsize=12, fstyle="italic")
            add_face_to_node(species_name,
                             node,
                             column=0,
                             position="branch-right")
            # add absence/presence matrix
            for i, value in enumerate(getattr(node, "profile", [])):
                if value > 0:
                    color = "#FF0000"
                else:
                    color = "#EEEEEE"
                my_face = CircleFace(8, color, style="circle")
                my_face.margin_right = 3
                my_face.margin_bottom = 3
                add_face_to_node(my_face, node, position="aligned", column=i)
def build_colorful_tree(newick, filename=""):
    """
    Note that these will fail if we dont have all the pre-reqs and it is not triival to get them all.
    This stuff is NOT general purpose.
    """
    from ete3 import Tree, TreeStyle, CircleFace, TextFace
    tree = Tree(newick)

    #setup colors and treestyle
    ts = TreeStyle()
    ts.show_leaf_name = True
    ts.mode = "c"
    ts.arc_start = -180  # 0 degrees = 3 o'clock
    ts.force_topology = True
    ts.arc_span = 360

    face = CircleFace(30, "MediumSeaGreen")
    face.margin_top = 1000
    ts.legend.add_face(face, column=0)
    face = TextFace("Normal B-cell", fsize=64)
    face.margin_right = 100
    face.margin_top = 1000
    ts.legend.add_face(face, column=1)

    ts.legend.add_face(CircleFace(30, "SeaGreen"), column=0)
    face = TextFace("Normal B CD19pcell", fsize=64)
    face.margin_right = 100
    ts.legend.add_face(face, column=1)

    ts.legend.add_face(CircleFace(30, "ForestGreen"), column=0)
    face = TextFace("Normal B CD19pCD27pcell", fsize=64)
    face.margin_right = 100
    ts.legend.add_face(face, column=1)

    ts.legend.add_face(CircleFace(30, "Green"), column=0)
    face = TextFace("Normal B CD19pCD27mcell", fsize=64)
    face.margin_right = 100
    ts.legend.add_face(face, column=1)

    ts.legend.add_face(CircleFace(30, "RoyalBlue"), column=0)
    face = TextFace("CLL all-batches", fsize=64)
    face.margin_right = 100
    ts.legend.add_face(face, column=1)

    #draw tree
    from ete3 import NodeStyle
    styles = {}
    styles["normal_B"] = NodeStyle(bgcolor="MediumSeaGreen",
                                   hz_line_color="Black",
                                   vt_line_color="Black")
    styles["NormalBCD19pcell"] = NodeStyle(bgcolor="SeaGreen",
                                           hz_line_color="Black",
                                           vt_line_color="Black")
    styles["NormalBCD19pCD27pcell"] = NodeStyle(bgcolor="ForestGreen",
                                                hz_line_color="Black",
                                                vt_line_color="Black")
    styles["NormalBCD19pCD27mcell"] = NodeStyle(bgcolor="Green",
                                                hz_line_color="Black",
                                                vt_line_color="Black")
    styles["CLL"] = NodeStyle(bgcolor="RoyalBlue",
                              hz_line_color="Black",
                              vt_line_color="Black")

    for node in tree.traverse("postorder"):
        #print node.set_style()
        if len(node.get_leaf_names()) == 1:
            name = node.get_leaf_names()[0]
            if "normal_B" in name:
                node.set_style(styles["normal_B"])
            elif "NormalBCD19pcell" in name:
                node.set_style(styles["NormalBCD19pcell"])

            elif "NormalBCD19pCD27pcell" in name:
                node.set_style(styles["NormalBCD19pCD27pcell"])

            elif "NormalBCD19pCD27mcell" in name:
                node.set_style(styles["NormalBCD19pCD27mcell"])
            else:
                node.set_style(styles["CLL"])
    #lol
    tree.render(filename, w=10, dpi=600, units='in', tree_style=ts)