Beispiel #1
0
 def plotTree(self, tree, out_fn=None, rotation=270, show_leaf_name=False, 
               show_branch_length=False, circularTree=False, show_division_nodes=True, 
               distance_between_branches=4, show_border=False, width=None, height=None):            
     from ete2 import TreeStyle        
     from PyQt4 import QtSvg, QtCore, QtGui
     from ete2.treeview import qt4_render, drawer, main
     
       
     ts = TreeStyle()   
     ts.show_scale = False
     ts.show_border = show_border
     ts.orientation = 1 # 0, tree is drawn from left-to-right. 1, tree is drawn from right-to-left
     ts.rotation = rotation
     ts.show_leaf_name = show_leaf_name
     ts.show_branch_length = show_branch_length
     if circularTree:
         ts.mode = 'c'
     else:
         ts.mode = 'r'
     ts.branch_vertical_margin = distance_between_branches
     
     
     def hideInternalNodesLayout(node):
         if not node.is_leaf():
             node.img_style["size"] = 0
     
     if show_division_nodes is False:
         ts.layout_fn = hideInternalNodesLayout
     
     if out_fn is not None:        
         scene  = qt4_render._TreeScene()
         img = ts
         
         tree_item, n2i, n2f = qt4_render.render(tree, img)
         scene.init_data(tree, img, n2i, n2f)
         tree_item.setParentItem(scene.master_item)
         scene.master_item.setPos(0,0)
         scene.addItem(scene.master_item)      
         main.save(scene, out_fn, w=width, h=height, dpi=600)    
           
     else:
         scene, img = drawer.init_scene(tree, None, ts)
         tree_item, n2i, n2f = qt4_render.render(tree, img)
         scene.init_data(tree, img, n2i, n2f)
     
         tree_item.setParentItem(scene.master_item)
         scene.addItem(scene.master_item)
     
         size = tree_item.rect()
         w, h = size.width(), size.height()
     
         svg = QtSvg.QSvgGenerator()
         svg.setFileName("test.svg")
         svg.setSize(QtCore.QSize(w, h))
         svg.setViewBox(size)
         pp = QtGui.QPainter()
         pp.begin(svg)            
         scene.render(pp, tree_item.rect(), tree_item.rect(), QtCore.Qt.KeepAspectRatio)
Beispiel #2
0
 def plotTree(self, tree, out_fn=None, rotation=270, show_leaf_name=False, 
               show_branch_length=False, circularTree=False, show_division_nodes=True, 
               distance_between_branches=4, show_border=False, width=None, height=None):            
     from ete2 import TreeStyle        
     from PyQt4 import QtSvg, QtCore, QtGui
     from ete2.treeview import qt4_render, drawer, main
     
       
     ts = TreeStyle()   
     ts.show_scale = False
     ts.show_border = show_border
     ts.orientation = 1 # 0, tree is drawn from left-to-right. 1, tree is drawn from right-to-left
     ts.rotation = rotation
     ts.show_leaf_name = show_leaf_name
     ts.show_branch_length = show_branch_length
     if circularTree:
         ts.mode = 'c'
     else:
         ts.mode = 'r'
     ts.branch_vertical_margin = distance_between_branches
     
     
     def hideInternalNodesLayout(node):
         if not node.is_leaf():
             node.img_style["size"] = 0
     
     if show_division_nodes is False:
         ts.layout_fn = hideInternalNodesLayout
     
     if out_fn is not None:        
         scene  = qt4_render._TreeScene()
         img = ts
         
         tree_item, n2i, n2f = qt4_render.render(tree, img)
         scene.init_data(tree, img, n2i, n2f)
         tree_item.setParentItem(scene.master_item)
         scene.master_item.setPos(0,0)
         scene.addItem(scene.master_item)      
         main.save(scene, out_fn, w=width, h=height, dpi=600)    
           
     else:
         scene, img = drawer.init_scene(tree, None, ts)
         tree_item, n2i, n2f = qt4_render.render(tree, img)
         scene.init_data(tree, img, n2i, n2f)
     
         tree_item.setParentItem(scene.master_item)
         scene.addItem(scene.master_item)
     
         size = tree_item.rect()
         w, h = size.width(), size.height()
     
         svg = QtSvg.QSvgGenerator()
         svg.setFileName("test.svg")
         svg.setSize(QtCore.QSize(w, h))
         svg.setViewBox(size)
         pp = QtGui.QPainter()
         pp.begin(svg)            
         scene.render(pp, tree_item.rect(), tree_item.rect(), QtCore.Qt.KeepAspectRatio)