Back to index

python-biopython  1.60
Public Member Functions | Public Attributes | Private Member Functions | Private Attributes
Bio.Graphics.BasicChromosome.Chromosome Class Reference
Inheritance diagram for Bio.Graphics.BasicChromosome.Chromosome:
Inheritance graph
[legend]
Collaboration diagram for Bio.Graphics.BasicChromosome.Chromosome:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def subcomponent_size
def draw
def add
def remove
def draw

Public Attributes

 start_x_position
 end_x_position
 start_y_position
 end_y_position
 title_size
 scale_num
 label_size
 chr_percent
 label_sep_percent

Private Member Functions

def _draw_label
def _draw_labels

Private Attributes

 _name
 _color_labels

Detailed Description

Class for drawing a chromosome of an organism.

This organizes the drawing of a single organisms chromosome. This
class can be instantiated directly, but the draw method makes the
most sense to be called in the context of an organism.

Definition at line 169 of file BasicChromosome.py.


Constructor & Destructor Documentation

def Bio.Graphics.BasicChromosome.Chromosome.__init__ (   self,
  chromosome_name 
)
Initialize a Chromosome for drawing.

Arguments:

o chromosome_name - The label for the chromosome.

Attributes:

o start_x_position, end_x_position - The x positions on the page
where the chromosome should be drawn. This allows multiple
chromosomes to be drawn on a single page.

o start_y_position, end_y_position - The y positions on the page
where the chromosome should be contained.

Configuration Attributes:

o title_size - The size of the chromosome title.

o scale_num - A number of scale the drawing by. This is useful if
you want to draw multiple chromosomes of different sizes at the
same scale. If this is not set, then the chromosome drawing will
be scaled by the number of segements in the chromosome (so each
chromosome will be the exact same final size).

Definition at line 176 of file BasicChromosome.py.

00176 
00177     def __init__(self, chromosome_name):
00178         """Initialize a Chromosome for drawing.
00179 
00180         Arguments:
00181 
00182         o chromosome_name - The label for the chromosome.
00183 
00184         Attributes:
00185 
00186         o start_x_position, end_x_position - The x positions on the page
00187         where the chromosome should be drawn. This allows multiple
00188         chromosomes to be drawn on a single page.
00189 
00190         o start_y_position, end_y_position - The y positions on the page
00191         where the chromosome should be contained.
00192 
00193         Configuration Attributes:
00194 
00195         o title_size - The size of the chromosome title.
00196 
00197         o scale_num - A number of scale the drawing by. This is useful if
00198         you want to draw multiple chromosomes of different sizes at the
00199         same scale. If this is not set, then the chromosome drawing will
00200         be scaled by the number of segements in the chromosome (so each
00201         chromosome will be the exact same final size).
00202         """
00203         _ChromosomeComponent.__init__(self)
00204 
00205         self._name = chromosome_name
00206 
00207         self.start_x_position = -1
00208         self.end_x_position = -1
00209         self.start_y_position = -1
00210         self.end_y_position = -1
00211 
00212         self.title_size = 20
00213         self.scale_num = None
00214 
00215         self.label_size = 6
00216         self.chr_percent = 0.25
00217         self.label_sep_percent = self.chr_percent * 0.5
00218         self._color_labels = False

Here is the caller graph for this function:


Member Function Documentation

def Bio.Graphics.BasicChromosome.Chromosome._draw_label (   self,
  cur_drawing,
  label_name 
) [private]
Draw a label for the chromosome.

Definition at line 275 of file BasicChromosome.py.

00275 
00276     def _draw_label(self, cur_drawing, label_name):
00277         """Draw a label for the chromosome.
00278         """
00279         x_position = 0.5 * (self.start_x_position + self.end_x_position)
00280         y_position = self.end_y_position
00281 
00282         label_string = String(x_position, y_position, label_name)
00283         label_string.fontName = 'Times-BoldItalic'
00284         label_string.fontSize = self.title_size
00285         label_string.textAnchor = 'middle'
00286 
00287         cur_drawing.add(label_string)

Here is the caller graph for this function:

def Bio.Graphics.BasicChromosome.Chromosome._draw_labels (   self,
  cur_drawing,
  left_labels,
  right_labels 
) [private]
Layout and draw sub-feature labels for the chromosome.

Tries to place each label at the same vertical position as the
feature it applies to, but will adjust the positions to avoid or
at least reduce label overlap.

Draws the label text and a coloured line linking it to the
location (i.e. feature) it applies to.

Definition at line 288 of file BasicChromosome.py.

00288 
00289     def _draw_labels(self, cur_drawing, left_labels, right_labels):
00290         """Layout and draw sub-feature labels for the chromosome.
00291 
00292         Tries to place each label at the same vertical position as the
00293         feature it applies to, but will adjust the positions to avoid or
00294         at least reduce label overlap.
00295 
00296         Draws the label text and a coloured line linking it to the
00297         location (i.e. feature) it applies to.
00298         """
00299         if not self._sub_components:
00300             return
00301         color_label = self._color_labels
00302 
00303         segment_width = (self.end_x_position - self.start_x_position) \
00304                         * self.chr_percent
00305         label_sep = (self.end_x_position - self.start_x_position) \
00306                         * self.label_sep_percent
00307         segment_x = self.start_x_position \
00308                   + 0.5 * (self.end_x_position - self.start_x_position - segment_width)
00309 
00310         y_limits = []
00311         for sub_component in self._sub_components:
00312             y_limits.extend((sub_component.start_y_position, sub_component.end_y_position))
00313         y_min = min(y_limits)
00314         y_max = max(y_limits)
00315         del y_limits
00316         #Now do some label placement magic...
00317         #from reportlab.pdfbase import pdfmetrics
00318         #font = pdfmetrics.getFont('Helvetica')
00319         #h = (font.face.ascent + font.face.descent) * 0.90
00320         h = self.label_size
00321         left_labels = _place_labels(left_labels, y_min, y_max, h)
00322         right_labels = _place_labels(right_labels, y_min, y_max, h)
00323         x1 = segment_x
00324         x2 = segment_x - label_sep
00325         for (y1, y2, color, name) in left_labels:
00326             cur_drawing.add(Line(x1, y1, x2, y2,
00327                                  strokeColor = color,
00328                                  strokeWidth = 0.25))
00329             label_string = String(x2, y2, name,
00330                                   textAnchor="end")
00331             label_string.fontName = 'Helvetica'
00332             label_string.fontSize = self.label_size
00333             if color_label:
00334                 label_string.fillColor = color
00335             cur_drawing.add(label_string)
00336         x1 = segment_x + segment_width
00337         x2 = segment_x + segment_width + label_sep
00338         for (y1, y2, color, name) in right_labels:
00339             cur_drawing.add(Line(x1, y1, x2, y2,
00340                                  strokeColor = color,
00341                                  strokeWidth = 0.25))
00342             label_string = String(x2, y2, name)
00343             label_string.fontName = 'Helvetica'
00344             label_string.fontSize = self.label_size
00345             if color_label:
00346                 label_string.fillColor = color
00347             cur_drawing.add(label_string)
00348 
00349 

Here is the call graph for this function:

Here is the caller graph for this function:

def Bio.Graphics.BasicChromosome._ChromosomeComponent.add (   self,
  component 
) [inherited]
Add a sub_component to the list of components under this item.

Definition at line 63 of file BasicChromosome.py.

00063 
00064     def add(self, component):
00065         """Add a sub_component to the list of components under this item.
00066         """
00067         assert isinstance(component, _ChromosomeComponent), \
00068                "Expected a _ChromosomeComponent object, got %s" % component
00069         
00070         self._sub_components.append(component)

Here is the caller graph for this function:

Draw the specified component.

Definition at line 83 of file BasicChromosome.py.

00083 
00084     def draw(self):
00085         """Draw the specified component.
00086         """
        raise AssertionError("Subclasses must implement.")
def Bio.Graphics.BasicChromosome.Chromosome.draw (   self,
  cur_drawing 
)
Draw a chromosome on the specified template.

Ideally, the x_position and y_*_position attributes should be
set prior to drawing -- otherwise we're going to have some problems.

Definition at line 228 of file BasicChromosome.py.

00228 
00229     def draw(self, cur_drawing):
00230         """Draw a chromosome on the specified template.
00231 
00232         Ideally, the x_position and y_*_position attributes should be
00233         set prior to drawing -- otherwise we're going to have some problems.
00234         """
00235         for position in (self.start_x_position, self.end_x_position,
00236                          self.start_y_position, self.end_y_position):
00237             assert position != -1, "Need to set drawing coordinates."
00238 
00239         # first draw all of the sub-sections of the chromosome -- this
00240         # will actually be the picture of the chromosome
00241         cur_y_pos = self.start_y_position
00242         if self.scale_num:
00243             y_pos_change = ((self.start_y_position * .95 - self.end_y_position)
00244                             / self.scale_num)
00245         elif len(self._sub_components) > 0:
00246             y_pos_change = ((self.start_y_position * .95 - self.end_y_position)
00247                             / self.subcomponent_size())
00248         # no sub_components to draw
00249         else:
00250             pass
00251         
00252         left_labels = []
00253         right_labels = []
00254         for sub_component in self._sub_components:
00255             this_y_pos_change = sub_component.scale * y_pos_change
00256             
00257             # set the location of the component to draw
00258             sub_component.start_x_position = self.start_x_position
00259             sub_component.end_x_position = self.end_x_position
00260             sub_component.start_y_position = cur_y_pos
00261             sub_component.end_y_position = cur_y_pos - this_y_pos_change
00262 
00263             # draw the sub component
00264             sub_component._left_labels = []
00265             sub_component._right_labels = []
00266             sub_component.draw(cur_drawing)
00267             left_labels += sub_component._left_labels
00268             right_labels += sub_component._right_labels
00269 
00270             # update the position for the next component
00271             cur_y_pos -= this_y_pos_change
00272 
00273         self._draw_labels(cur_drawing, left_labels, right_labels)
00274         self._draw_label(cur_drawing, self._name)

Here is the call graph for this function:

def Bio.Graphics.BasicChromosome._ChromosomeComponent.remove (   self,
  component 
) [inherited]
Remove the specified component from the subcomponents.

Raises a ValueError if the component is not registered as a
sub_component.

Definition at line 71 of file BasicChromosome.py.

00071 
00072     def remove(self, component):
00073         """Remove the specified component from the subcomponents.
00074 
00075         Raises a ValueError if the component is not registered as a
00076         sub_component.
00077         """
00078         try:
00079             self._sub_components.remove(component)
00080         except ValueError:
00081             raise ValueError("Component %s not found in sub_components." %
00082                              component)

Return the scaled size of all subcomponents of this component.

Definition at line 219 of file BasicChromosome.py.

00219 
00220     def subcomponent_size(self):
00221         """Return the scaled size of all subcomponents of this component.
00222         """
00223         total_sub = 0
00224         for sub_component in self._sub_components:
00225             total_sub += sub_component.scale
00226 
00227         return total_sub

Here is the caller graph for this function:


Member Data Documentation

Definition at line 217 of file BasicChromosome.py.

Definition at line 204 of file BasicChromosome.py.

Definition at line 215 of file BasicChromosome.py.

Definition at line 207 of file BasicChromosome.py.

Definition at line 209 of file BasicChromosome.py.

Definition at line 216 of file BasicChromosome.py.

Definition at line 214 of file BasicChromosome.py.

Definition at line 212 of file BasicChromosome.py.

Definition at line 206 of file BasicChromosome.py.

Definition at line 208 of file BasicChromosome.py.

Definition at line 211 of file BasicChromosome.py.


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