PTreeGenerator  1.0
Simple phylogenetic tree generation from multiple sequence alignment.
 All Classes Namespaces Files Functions Variables
Public Member Functions | Private Attributes | List of all members
ptreegen.visualization.Visualization Class Reference

Similar to the ptreegen::computation::Computation class. More...

Public Member Functions

def __init__
 Besides member initialization, it handles initial styling of the tree.
def parseOptions
 Parses options selected by the user and prepares the necessary workflow.
def saveNewick
 Creates a file in the same directory as the input alignment and saves the tree in the Newick format.
def savePNG
 Creates a file in the same directory as the input alignment and saves the tree as a PNG image.
def saveSVG
 Creates a file in the same directory as the input alignment and saves the tree as an SVG image.
def showGUI
 Shows the tree in a windowed viewer app.
def printToStdout
 Prints the tree topology to stdout.
def show
 Executes the workflow specified by the Visualization::_formatingMethods member.

Private Attributes

 _tree
 reference to the tree being displayed
 _options
 set of options (same set as in the case of the ptreegen::computation::Computation class)
 _formatingMethods
 A list of function pointers that represents the workflow of operations.
 _storageDir
 the output directory
 _filePrefix
 prefix for the output files
 _style
 Instance representing the rendered style of the tree.

Detailed Description

Similar to the ptreegen::computation::Computation class.

It manages the visual components of the computation process and displays results to the user.

Definition at line 18 of file visualization.py.

Constructor & Destructor Documentation

def ptreegen.visualization.Visualization.__init__ (   self,
  tree,
  options 
)

Besides member initialization, it handles initial styling of the tree.

Parameters
treeinput phylogenetic tree that will be processed
optionsset of options (same set as in the case of the ptreegen::computation::Computation class)

Definition at line 27 of file visualization.py.

27 
28  def __init__(self, tree, options):
29  self._tree = tree
30  self._options = options
32  self._storageDir = None
33  self._filePrefix = None
34  self._style = TreeStyle()
35  self._style.show_leaf_name = True
36  self._style.show_branch_length = False
37  self._style.scale = 80
38  self._style.branch_vertical_margin = 15
39  self._style.rotation = 90
40  self._style.arc_start = -180
41  self._style.arc_span = 180
42 
43  self.parseOptions(options)

Member Function Documentation

def ptreegen.visualization.Visualization.parseOptions (   self,
  options 
)

Parses options selected by the user and prepares the necessary workflow.

Parameters
optionsset of options (same set as in the case of the ptreegen::computation::Computation class)

Definition at line 50 of file visualization.py.

References ptreegen.visualization.Visualization._filePrefix, ptreegen.visualization.Visualization._storageDir, ptreegen.visualization.Visualization.printToStdout(), ptreegen.visualization.Visualization.saveNewick(), ptreegen.visualization.Visualization.savePNG(), ptreegen.visualization.Visualization.saveSVG(), and ptreegen.visualization.Visualization.showGUI().

50 
51  def parseOptions(self, options):
52  self._storageDir = os.path.dirname(options["alignment_file"])
53  self._filePrefix = os.path.basename(options["alignment_file"])
54  if '.' in self._filePrefix:
55  self._filePrefix = self._filePrefix[0:self._filePrefix.rfind('.')]
56  out_formats = options['out_form'].split(',')
57  for form in out_formats:
58  if form == OutputForm.NEWICK:
59  self._formatingMethods.append(self.saveNewick)
60  elif form == OutputForm.IMAGE_PNG:
61  self._formatingMethods.append(self.savePNG)
62  elif form == OutputForm.IMAGE_SVG:
63  self._formatingMethods.append(self.saveSVG)
64  elif form == OutputForm.GUI:
65  self._formatingMethods.append(self.showGUI)
66  elif form == OutputForm.PRINT:
67  self._formatingMethods.append(self.printToStdout)
68  else:
69  raise RuntimeError("Unknown output format: " + form)
70  if options['tree_type'] == TreeType.CIRC:
71  self._style.mode = 'c'
72  elif options['tree_type'] == TreeType.RECT:
73  self._style.mode = 'r'
74  else:
75  raise RuntimeError("Unknown tree type: " + options['tree_type'])
def ptreegen.visualization.Visualization.printToStdout (   self)

Prints the tree topology to stdout.

Definition at line 113 of file visualization.py.

References ptreegen.visualization.Visualization._tree, ptreegen.parsimony.SmallParsimony._tree, and ptreegen.parsimony.LargeParsimony._tree.

Referenced by ptreegen.visualization.Visualization.parseOptions().

114  def printToStdout(self):
115  print self._tree
def ptreegen.visualization.Visualization.saveNewick (   self)

Creates a file in the same directory as the input alignment and saves the tree in the Newick format.

Definition at line 81 of file visualization.py.

References ptreegen.visualization.Visualization._filePrefix, and ptreegen.visualization.Visualization._storageDir.

Referenced by ptreegen.visualization.Visualization.parseOptions().

81 
82  def saveNewick(self):
83  file_path = os.path.join(self._storageDir, self._filePrefix + ".newick")
84  with codecs.open(file_path, "w", "utf-8") as outfile:
outfile.write(self._tree.write(format=5))
def ptreegen.visualization.Visualization.savePNG (   self)

Creates a file in the same directory as the input alignment and saves the tree as a PNG image.

Definition at line 90 of file visualization.py.

References ptreegen.visualization.Visualization._filePrefix, ptreegen.visualization.Visualization._storageDir, and ptreegen.visualization.Visualization._style.

Referenced by ptreegen.visualization.Visualization.parseOptions().

90 
91  def savePNG(self):
92  file_path = os.path.join(self._storageDir, self._filePrefix + ".png")
93  self._tree.render(file_path, tree_style=self._style, dpi=300)
def ptreegen.visualization.Visualization.saveSVG (   self)

Creates a file in the same directory as the input alignment and saves the tree as an SVG image.

Definition at line 99 of file visualization.py.

References ptreegen.visualization.Visualization._filePrefix, ptreegen.visualization.Visualization._storageDir, and ptreegen.visualization.Visualization._style.

Referenced by ptreegen.visualization.Visualization.parseOptions().

99 
100  def saveSVG(self):
101  file_path = os.path.join(self._storageDir, self._filePrefix + ".svg")
102  self._tree.render(file_path, tree_style=self._style, dpi=300)
def ptreegen.visualization.Visualization.show (   self)

Executes the workflow specified by the Visualization::_formatingMethods member.

See Also
Visualization::_formatingMethods

Definition at line 122 of file visualization.py.

References ptreegen.visualization.Visualization._formatingMethods.

123  def show(self):
124  for func in self._formatingMethods:
125  func()
def ptreegen.visualization.Visualization.showGUI (   self)

Shows the tree in a windowed viewer app.

Definition at line 107 of file visualization.py.

References ptreegen.visualization.Visualization._style.

Referenced by ptreegen.visualization.Visualization.parseOptions().

108  def showGUI(self):
109  self._tree.show(tree_style=self._style)

Member Data Documentation

ptreegen.visualization.Visualization._filePrefix
private

prefix for the output files

Definition at line 32 of file visualization.py.

Referenced by ptreegen.visualization.Visualization.parseOptions(), ptreegen.visualization.Visualization.saveNewick(), ptreegen.visualization.Visualization.savePNG(), and ptreegen.visualization.Visualization.saveSVG().

ptreegen.visualization.Visualization._formatingMethods
private

A list of function pointers that represents the workflow of operations.

Definition at line 30 of file visualization.py.

Referenced by ptreegen.visualization.Visualization.show().

ptreegen.visualization.Visualization._options
private

set of options (same set as in the case of the ptreegen::computation::Computation class)

Definition at line 29 of file visualization.py.

ptreegen.visualization.Visualization._storageDir
private

the output directory

Definition at line 31 of file visualization.py.

Referenced by ptreegen.visualization.Visualization.parseOptions(), ptreegen.visualization.Visualization.saveNewick(), ptreegen.visualization.Visualization.savePNG(), and ptreegen.visualization.Visualization.saveSVG().

ptreegen.visualization.Visualization._style
private

Instance representing the rendered style of the tree.

Definition at line 33 of file visualization.py.

Referenced by ptreegen.visualization.Visualization.savePNG(), ptreegen.visualization.Visualization.saveSVG(), and ptreegen.visualization.Visualization.showGUI().

ptreegen.visualization.Visualization._tree
private

reference to the tree being displayed

Definition at line 28 of file visualization.py.

Referenced by ptreegen.visualization.Visualization.printToStdout().


The documentation for this class was generated from the following file: