ete2.treeview.layouts

Package ete2 :: Package treeview :: Module layouts |
[hide private]
[frames] | no frames]

# Source Code for Module ete2.treeview.layouts

      1  __VERSION__="ete2-2.0rev95"
      2  # #START_LICENSE###########################################################
      3  #
      4  # Copyright (C) 2009 by Jaime Huerta Cepas. All rights reserved.
      5  # email: jhcepas@gmail.com
      6  #
      7  # This file is part of the Environment for Tree Exploration program (ETE).
      8  # http://ete.cgenomics.org
      9  #
     10  # ETE is free software: you can redistribute it and/or modify it
     11  # under the terms of the GNU General Public License as published by
     12  # the Free Software Foundation, either version 3 of the License, or
     13  # (at your option) any later version.
     14  #
     15  # ETE is distributed in the hope that it will be useful,
     16  # but WITHOUT ANY WARRANTY; without even the implied warranty of
     17  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     18  # GNU General Public License for more details.
     19  #
     20  # You should have received a copy of the GNU General Public License
     21  # along with ETE.  If not, see <http://www.gnu.org/licenses/>.
     22  #
     23  # #END_LICENSE#############################################################
     24
     25  import numpy
     26  import faces
     27
     28 -def basic(node):
     29      if node.is_leaf():
     30          node.img_style["size"]=1
     31          node.img_style["shape"] = "circle"
     32          faces.add_face_to_node(faces.AttrFace("name","Arial",10,"#4f8f0f",None), node, 0 )
     33
     34 -def phylogeny(node):
     35      leaf_color = "#000000"
     36      node.img_style["shape"] = "circle"
     37      if hasattr(node,"evoltype"):
     38          if node.evoltype == 'D':
     39              node.img_style["fgcolor"] = "#1d176e"
     40              node.img_style["hz_line_color"] = "#1d176e"
     41              node.img_style["vt_line_color"] = "#1d176e"
     42          elif node.evoltype == 'S':
     43              node.img_style["fgcolor"] = "#FF0000"
     44              node.img_style["line_color"] = "#FF0000"
     45          elif node.evoltype == 'L':
     46              node.img_style["fgcolor"] = "#777777"
     47              node.img_style["vt_line_color"] = "#777777"
     48              node.img_style["hz_line_color"] = "#777777"
     49              node.img_style["line_type"] = 1
     50              leaf_color = "#777777"
     51
     52      if node.is_leaf():
     53          node.img_style["shape"] = "square"
     54          node.img_style["size"] = 4
     55          node.img_style["fgcolor"] = leaf_color
     56          faces.add_face_to_node( faces.AttrFace("name","Arial",11,leaf_color,None), node, 0 )
     57          if hasattr(node,"sequence"):
     58              SequenceFace =  faces.SequenceFace(node.sequence,"aa",13)
     59              faces.add_face_to_node(SequenceFace, node, 1, aligned=True)
     60      else:
     61          node.img_style["size"] = 6
     62
     63 -def heatmap(node):
     64      square_size = 10
     65      # Extras node info
     66      node.collapsed = False
     67
     68      # Color and style
     69      node.img_style["fgcolor"] = "#3333FF"
     70      node.img_style["size"] =  0
     71
     72      ncols = node.arraytable.matrix.shape[1]
     73
     74      matrix_max = numpy.max(node.arraytable._matrix_max)
     75      matrix_min = numpy.min(node.arraytable._matrix_min)
     76      matrix_avg = matrix_min+((matrix_max-matrix_min)/2)
     77      ProfileFace = faces.ProfileFace(\
     78        matrix_max,\
     79          matrix_min,\
     80          matrix_avg,\
     81          square_size*ncols,\
     82          square_size,\
     83          "heatmap")
     84      ProfileFace.ymargin=0
     85      if node.is_leaf():
     86          # Set colors
     87          faces.add_face_to_node(ProfileFace, node, 0, aligned=True )
     88
     89
     90
     91
     92 -def cluster_cbars(node):
     93      # Extras node info
     94      node.collapsed = False
     95      # Color and style
     96      node.img_style["fgcolor"] = "#3333FF"
     97      node.img_style["size"] =  4
     98      matrix_max = numpy.max(node.arraytable._matrix_max)
     99      matrix_min = numpy.min(node.arraytable._matrix_min)
    100      matrix_avg = matrix_min+((matrix_max-matrix_min)/2)
    101      ProfileFace = faces.ProfileFace(\
    102                                          matrix_max,\
    103                                          matrix_min,\
    104                                          matrix_avg,\
    105                                          200,\
    106                                          60,\
    107                                          "cbars")
    108
    109      if node.is_leaf():
    110          nameFace = faces.AttrFace("name",fsize=6 )
    111          faces.add_face_to_node(nameFace, node, 1, aligned=True )
    112          faces.add_face_to_node(ProfileFace, node, 0,  aligned=True )
    113      else:
    114          # Set custom faces
    115          faces.add_face_to_node(ProfileFace, node, 0, aligned=True )
    116
    117 -def cluster_lines(node):
    118      # Extras node info
    119      node.collapsed = False
    120      # Color and style
    121      node.img_style["fgcolor"] = "#3333FF"
    122      node.img_style["size"] = 4
    123      matrix_max = numpy.max(node.arraytable._matrix_max)
    124      matrix_min = numpy.min(node.arraytable._matrix_min)
    125      matrix_avg = matrix_min+((matrix_max-matrix_min)/2)
    126      ProfileFace = faces.ProfileFace(\
    127        matrix_max,\
    128          matrix_min,\
    129          matrix_avg,\
    130          200,\
    131          50,\
    132          "lines")
    133
    134      if node.is_leaf():
    135          nameFace = faces.AttrFace("name",fsize=6 )
    136          faces.add_face_to_node(nameFace, node, 1,  aligned=True )
    137          faces.add_face_to_node(ProfileFace, node, 0, aligned=True )
    138      else:
    139          # Set custom faces
    140          faces.add_face_to_node(ProfileFace, node, 0, aligned=True )
    141
    142 -def cluster_bars(node):
    143      # Extras node info
    144      node.collapsed = False
    145      # Color and style
    146      node.img_style["fgcolor"] = "#3333FF"
    147      node.img_style["size"] = 4
    148
    149      if node.is_leaf():
    150          matrix_max = numpy.max(node.arraytable._matrix_max)
    151          matrix_min = numpy.min(node.arraytable._matrix_min)
    152          matrix_avg = matrix_min+((matrix_max-matrix_min)/2)
    153          ProfileFace = faces.ProfileFace(\
    154            matrix_max,\
    155              matrix_min,\
    156              matrix_avg,\
    157              200,\
    158              40,\
    159              "bars")
    160          nameFace = faces.AttrFace("name",fsize=6 )
    161          faces.add_face_to_node(nameFace, node, 1, aligned=True )
    162          faces.add_face_to_node(ProfileFace, node, 0, aligned=True )
    163
    164 -def large(node):
    165      # Color and style
    166      node.img_style["fgcolor"] = "#3333FF"
    167      node.img_style["size"] = 0
    168
    169
    170  # Labels to show in qt application menu
    171  layout_functions = {
    172          "Basic": basic,
    173          "Phylogenetic tree": phylogeny,
    174          "Clustering heatmap": heatmap,
    175          "Clustering validation (bars)": cluster_bars,
    176          "Clustering validation (profiles)": cluster_cbars,
    177          "Very large topology": large
    178          }
    179