Exemplo n.º 1
0
def default_layout(node):
    if node.is_leaf():
        # Add node name to leaf nodes
        N = AttrFace("name", fsize=14, fgcolor="black")

        faces.add_face_to_node(N, node, 0)
    if "weight" in node.features:
        # Creates a sphere face whose size is proportional to node's
        # feature "weight"
        C = CircleFace(radius=node.weight, color="Red", style="sphere")
        # Let's make the sphere transparent
        C.opacity = 0.5
        # Rotate the faces by 90*
        C.rotation = 90
        # And place as a float face over the tree
        faces.add_face_to_node(C, node, 0, position="float")
Exemplo n.º 2
0
 def my_layout(node):
     circle_color = 'lightgray' if colormap is None or node.name not in colormap else colormap[
         node.name]
     text_color = 'black'
     if isinstance(circle_color, str):
         C = CircleFace(radius=max(3, 10 * scipy.sqrt(node.frequency)),
                        color=circle_color,
                        label={
                            'text': str(node.frequency),
                            'color': text_color
                        } if node.frequency > 0 else None)
         C.rotation = -90
         C.hz_align = 1
         faces.add_face_to_node(C, node, 0)
     else:
         P = PieChartFace(
             [100 * x / node.frequency for x in circle_color.values()],
             2 * 10 * scipy.sqrt(node.frequency),
             2 * 10 * scipy.sqrt(node.frequency),
             colors=[(color if color != 'None' else 'lightgray')
                     for color in list(circle_color.keys())],
             line_color=None)
         T = TextFace(' '.join(
             [str(x) for x in list(circle_color.values())]),
                      tight_text=True)
         T.hz_align = 1
         T.rotation = -90
         faces.add_face_to_node(P, node, 0, position='branch-right')
         faces.add_face_to_node(T, node, 1, position='branch-right')
     if idlabel:
         T = TextFace(node.name, tight_text=True, fsize=6)
         T.rotation = -90
         T.hz_align = 1
         faces.add_face_to_node(
             T,
             node,
             1 if isinstance(circle_color, str) else 2,
             position='branch-right')
Exemplo n.º 3
0
def default_layout(node):
    """
    Specifies the layout for the ete.TreeStyle object.

    Parameters
    ----------
    node: ete.Tree
        Input node for specifying which attributes.
    """
    if node.is_leaf():
        # Add node name to leaf nodes
        N = AttrFace("name", fsize=14, fgcolor="black")

        faces.add_face_to_node(N, node, 0)
    if "weight" in node.features:
        # Creates a sphere face whose size is proportional to node's
        # feature "weight"
        C = CircleFace(radius=node.weight, color="Red", style="sphere")
        # Let's make the sphere transparent
        C.opacity = 0.5
        # Rotate the faces by 90*
        C.rotation = 90
        # And place as a float face over the tree
        faces.add_face_to_node(C, node, 0, position="float")
Exemplo n.º 4
0
 def my_layout(node):
     circle_color = 'lightgray' if colormap is None or node.name not in colormap else colormap[
         node.name]
     text_color = 'black'
     if isinstance(circle_color, str):
         if isolabel and hasattr(node, 'isotype'):
             nl = ''.join(
                 sorted(set([ISO_SHORT[iss] for iss in node.isotype]),
                        key=lambda x: ISO_TYPE_charORDER[x]))
         else:
             nl = str(node.frequency)
         C = CircleFace(radius=max(3, 10 * scipy.sqrt(node.frequency)),
                        color=circle_color,
                        label={
                            'text': nl,
                            'color': text_color
                        } if node.frequency > 0 else None)
         C.rotation = -90
         C.hz_align = 1
         faces.add_face_to_node(C, node, 0)
     else:
         P = PieChartFace(
             [100 * x / node.frequency for x in circle_color.values()],
             2 * 10 * scipy.sqrt(node.frequency),
             2 * 10 * scipy.sqrt(node.frequency),
             colors=[(color if color != 'None' else 'lightgray')
                     for color in list(circle_color.keys())],
             line_color=None)
         T = TextFace(' '.join(
             [str(x) for x in list(circle_color.values())]),
                      tight_text=True)
         T.hz_align = 1
         T.rotation = -90
         faces.add_face_to_node(P, node, 0, position='branch-right')
         faces.add_face_to_node(T, node, 1, position='branch-right')
     if idlabel:
         T = TextFace(node.name, tight_text=True, fsize=6)
         T.rotation = -90
         T.hz_align = 1
         faces.add_face_to_node(
             T,
             node,
             1 if isinstance(circle_color, str) else 2,
             position='branch-right')
     elif isolabel and hasattr(node, 'isotype') and False:
         iso_name = ''.join(
             sorted(set([ISO_SHORT[iss] for iss in node.isotype]),
                    key=lambda x: ISO_TYPE_charORDER[x]))
         #T = TextFace(iso_name, tight_text=True, fsize=6)
         #T.rotation = -90
         #T.hz_align = 1
         #faces.add_face_to_node(T, node, 1 if isinstance(circle_color, str) else 2, position='branch-right')
         C = CircleFace(radius=max(3, 10 * scipy.sqrt(node.frequency)),
                        color=circle_color,
                        label={
                            'text': iso_name,
                            'color': text_color
                        } if node.frequency > 0 else None)
         C.rotation = -90
         C.hz_align = 1
         faces.add_face_to_node(C, node, 0)