Back to index

python-biopython  1.60
Public Member Functions | Public Attributes | Private Member Functions
Bio.Graphics.Comparative.ComparativeScatterPlot Class Reference

List of all members.

Public Member Functions

def __init__
def draw_to_file

Public Attributes

 number_of_columns
 page_size
 title_size
 output_format
 display_info
 color_choices
 shape_choices

Private Member Functions

def _draw_title
def _draw_scatter_plot
def _set_colors_and_shapes
def _find_min_max

Detailed Description

Display a scatter-type plot comparing two different kinds of info.

Attributes;

o display_info -- a 2D list of the information we'll be outputting. Each
top level list is a different data type, and each data point is a two-tuple
of the coordinates of a point. So if you had two distributions of points,
it should look like:

display_info = [[(1, 2), (3, 4)],
                [(5, 6), (7, 8)]]

if everything is just one set of points, display_info can look like:

display_info = [[(1, 2), (3, 4), (5, 6)]]

Definition at line 20 of file Comparative.py.


Constructor & Destructor Documentation

def Bio.Graphics.Comparative.ComparativeScatterPlot.__init__ (   self,
  output_format = 'pdf' 
)

Definition at line 37 of file Comparative.py.

00037 
00038     def __init__(self, output_format = 'pdf'):
00039         # customizable attributes
00040         self.number_of_columns = 1
00041         self.page_size = letter
00042         self.title_size = 20
00043 
00044         self.output_format = output_format
00045 
00046         # the information we'll be writing
00047         self.display_info = []
00048 
00049         # inital colors and shapes used for drawing points
00050         self.color_choices = [colors.red, colors.green, colors.blue,
00051                               colors.yellow, colors.orange, colors.black]
00052         self.shape_choices = [makeFilledCircle, makeEmptySquare,
00053                               makeFilledDiamond, makeFilledSquare,
00054                               makeEmptyCircle, makeSmiley]

Here is the caller graph for this function:


Member Function Documentation

def Bio.Graphics.Comparative.ComparativeScatterPlot._draw_scatter_plot (   self,
  cur_drawing,
  x_start,
  y_start,
  x_end,
  y_end 
) [private]
Draw a scatter plot on the drawing with the given coordinates.

Definition at line 89 of file Comparative.py.

00089 
00090                            x_end, y_end):
00091         """Draw a scatter plot on the drawing with the given coordinates.
00092         """
00093         scatter_plot = LinePlot()
00094 
00095         # set the dimensions of the scatter plot
00096         scatter_plot.x = x_start
00097         scatter_plot.y = y_start
00098         scatter_plot.width = abs(x_start - x_end)
00099         scatter_plot.height = abs(y_start - y_end)
00100 
00101         scatter_plot.data = self.display_info
00102 
00103         scatter_plot.joinedLines = 0
00104 
00105         # set the axes of the plot
00106         x_min, x_max, y_min, y_max = self._find_min_max(self.display_info)
00107         scatter_plot.xValueAxis.valueMin = x_min
00108         scatter_plot.xValueAxis.valueMax = x_max
00109         scatter_plot.xValueAxis.valueStep = (x_max - x_min) / 10.0
00110 
00111         scatter_plot.yValueAxis.valueMin = y_min
00112         scatter_plot.yValueAxis.valueMax = y_max
00113         scatter_plot.yValueAxis.valueStep = (y_max - y_min) / 10.0
00114 
00115         self._set_colors_and_shapes(scatter_plot, self.display_info)
00116         
00117         cur_drawing.add(scatter_plot)

Here is the call graph for this function:

Here is the caller graph for this function:

def Bio.Graphics.Comparative.ComparativeScatterPlot._draw_title (   self,
  cur_drawing,
  title,
  width,
  height 
) [private]
Add a title to the page we are outputting.

Definition at line 78 of file Comparative.py.

00078 
00079     def _draw_title(self, cur_drawing, title, width, height):
00080         """Add a title to the page we are outputting.
00081         """
00082         title_string = String(width / 2, height - inch, title)
00083         title_string.fontName = 'Helvetica-Bold'
00084         title_string.fontSize = self.title_size
00085         title_string.textAnchor = "middle"
00086 
00087         cur_drawing.add(title_string)

Here is the call graph for this function:

Here is the caller graph for this function:

Find the min and max for the x and y coordinates in the given data.

Definition at line 145 of file Comparative.py.

00145 
00146     def _find_min_max(self, info):
00147         """Find the min and max for the x and y coordinates in the given data.
00148         """
00149         x_min = info[0][0][0]
00150         x_max = info[0][0][0]
00151         y_min = info[0][0][1]
00152         y_max = info[0][0][1]
00153 
00154         for two_d_list in info:
00155             for x, y in two_d_list:
00156                 if x > x_max:
00157                     x_max = x
00158                 if x < x_min:
00159                     x_min = x
00160                 if y > y_max:
00161                     y_max = y
00162                 if y < y_min:
00163                     y_min = y
00164 
00165         return x_min, x_max, y_min, y_max

Here is the caller graph for this function:

def Bio.Graphics.Comparative.ComparativeScatterPlot._set_colors_and_shapes (   self,
  scatter_plot,
  display_info 
) [private]
Set the colors and shapes of the points displayed.

By default this just sets all of the points according to the order
of colors and shapes defined in self.color_choices and
self.shape_choices. The first 5 shapes and colors are unique, the
rest of them are just set to the same color and shape (since I
ran out of shapes!).

You can change how this function works by either changing the
values of the color_choices and shape_choices attributes, or
by inheriting from this class and overriding this function.

Definition at line 118 of file Comparative.py.

00118 
00119     def _set_colors_and_shapes(self, scatter_plot, display_info):
00120         """Set the colors and shapes of the points displayed.
00121 
00122         By default this just sets all of the points according to the order
00123         of colors and shapes defined in self.color_choices and
00124         self.shape_choices. The first 5 shapes and colors are unique, the
00125         rest of them are just set to the same color and shape (since I
00126         ran out of shapes!).
00127 
00128         You can change how this function works by either changing the
00129         values of the color_choices and shape_choices attributes, or
00130         by inheriting from this class and overriding this function.
00131         """
00132         for value_num in range(len(display_info)):
00133             # if we have unique colors, add them
00134             if (value_num + 1) < len(self.color_choices):
00135                 scatter_plot.lines[value_num].strokeColor = \
00136                     self.color_choices[value_num]
00137                 scatter_plot.lines[value_num].symbol = \
00138                     self.shape_choices[value_num]
00139             # otherwise just use the last number
00140             else:
00141                 scatter_plot.lines[value_num].strokeColor = \
00142                   self.color_choices[-1]
00143                 scatter_plot.lines[value_num].symbol = \
00144                   self.shape_choices[-1]

Here is the caller graph for this function:

def Bio.Graphics.Comparative.ComparativeScatterPlot.draw_to_file (   self,
  output_file,
  title 
)
Write the comparative plot to a file.

Arguments:

o output_file - The name of the file to output the information to,
        or a handle to write to.

o title - A title to display on the graphic.

Definition at line 55 of file Comparative.py.

00055 
00056     def draw_to_file(self, output_file, title):
00057         """Write the comparative plot to a file.
00058 
00059         Arguments:
00060 
00061         o output_file - The name of the file to output the information to,
00062                         or a handle to write to.
00063 
00064         o title - A title to display on the graphic.
00065         """
00066         width, height = self.page_size
00067         cur_drawing = Drawing(width, height)
00068 
00069         self._draw_title(cur_drawing, title, width, height)
00070 
00071         start_x = inch * .5
00072         end_x = width - inch * .5
00073         end_y = height - 1.5 * inch
00074         start_y = .5 * inch
00075         self._draw_scatter_plot(cur_drawing, start_x, start_y, end_x, end_y)
00076 
00077         return _write(cur_drawing, output_file, self.output_format)

Here is the call graph for this function:


Member Data Documentation

Definition at line 49 of file Comparative.py.

Definition at line 46 of file Comparative.py.

Definition at line 39 of file Comparative.py.

Definition at line 43 of file Comparative.py.

Definition at line 40 of file Comparative.py.

Definition at line 51 of file Comparative.py.

Definition at line 41 of file Comparative.py.


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