Back to index

python-biopython  1.60
Public Member Functions | Private Member Functions | Private Attributes
Bio.Graphics.DisplayRepresentation.ChromosomeCounts Class Reference

List of all members.

Public Member Functions

def __init__
def add_count
def scale_segment_value
def add_label
def set_scale
def get_segment_info
def fill_chromosome

Private Member Functions

def _color_from_count

Private Attributes

 _names
 _count_info
 _label_info
 _scale_info
 _color_scheme

Detailed Description

Represent a chromosome with count information.

This is used to display information about counts along a chromosome.
The segments are expected to have different count information, which
will be displayed using a color scheme.

I envision using this class when you think that certain regions of
the chromosome will be especially abundant in the counts, and you
want to pick those out.

Definition at line 24 of file DisplayRepresentation.py.


Constructor & Destructor Documentation

def Bio.Graphics.DisplayRepresentation.ChromosomeCounts.__init__ (   self,
  segment_names,
  color_scheme = RAINBOW_COLORS 
)
Initialize a representation of chromosome counts.

Arguments:

o segment_names - An ordered list of all segment names along
the chromosome. The count and other information will be added to
these.

o color_scheme - A coloring scheme to use in the counts. This should
be a dictionary mapping count ranges to colors (specified in
reportlab.lib.colors).

Definition at line 35 of file DisplayRepresentation.py.

00035 
00036     def __init__(self, segment_names, color_scheme = RAINBOW_COLORS):
00037         """Initialize a representation of chromosome counts.
00038 
00039         Arguments:
00040 
00041         o segment_names - An ordered list of all segment names along
00042         the chromosome. The count and other information will be added to
00043         these.
00044 
00045         o color_scheme - A coloring scheme to use in the counts. This should
00046         be a dictionary mapping count ranges to colors (specified in
00047         reportlab.lib.colors).
00048         """
00049         self._names = segment_names
00050         self._count_info = {}
00051         self._label_info = {}
00052         self._scale_info = {}
00053         for name in self._names:
00054             self._count_info[name] = 0
00055             self._label_info[name] = None
00056             self._scale_info[name] = 1
00057         
00058         self._color_scheme = color_scheme

Here is the caller graph for this function:


Member Function Documentation

Translate the given count into a color using the color scheme.

Definition at line 172 of file DisplayRepresentation.py.

00172 
00173     def _color_from_count(self, count):
00174         """Translate the given count into a color using the color scheme.
00175         """
00176         for count_start, count_end in self._color_scheme:
00177             if count >= count_start and count <= count_end:
00178                 return self._color_scheme[(count_start, count_end)]
00179 
00180         # if we got here we didn't find a color for the count
00181         raise ValueError("Count value %s was not found in the color scheme."
00182                          % count)
00183         
00184         
00185         

Here is the caller graph for this function:

def Bio.Graphics.DisplayRepresentation.ChromosomeCounts.add_count (   self,
  segment_name,
  count = 1 
)
Add counts to the given segment name.

Arguments:

o segment_name - The name of the segment we should add counts to.
If the name is not present, a KeyError will be raised.

o count - The counts to add the current segment. This defaults to
a single count.

Definition at line 59 of file DisplayRepresentation.py.

00059 
00060     def add_count(self, segment_name, count = 1):
00061         """Add counts to the given segment name.
00062 
00063         Arguments:
00064 
00065         o segment_name - The name of the segment we should add counts to.
00066         If the name is not present, a KeyError will be raised.
00067 
00068         o count - The counts to add the current segment. This defaults to
00069         a single count.
00070         """
00071         try:
00072             self._count_info[segment_name] += count
00073         except KeyError:
00074             raise KeyError("Segment name %s not found." % segment_name)

def Bio.Graphics.DisplayRepresentation.ChromosomeCounts.add_label (   self,
  segment_name,
  label 
)
Add a label to a specfic segment.

Raises a KeyError is the specified segment name is not found.

Definition at line 87 of file DisplayRepresentation.py.

00087 
00088     def add_label(self, segment_name, label):
00089         """Add a label to a specfic segment.
00090 
00091         Raises a KeyError is the specified segment name is not found.
00092         """
00093         if segment_name in self._label_info:
00094             self._label_info[segment_name] = label
00095         else:
00096             raise KeyError("Segment name %s not found." % segment_name)

Add the collected segment information to a chromosome for drawing.

Arguments:

o chromosome - A Chromosome graphics object that we can add
chromosome segments to.

This creates ChromosomeSegment (and TelomereSegment) objects to
fill in the chromosome. The information is derived from the
label and count information, with counts transformed to the
specified color map.

Returns the chromosome with all of the segments added.

Definition at line 126 of file DisplayRepresentation.py.

00126 
00127     def fill_chromosome(self, chromosome):
00128         """Add the collected segment information to a chromosome for drawing.
00129 
00130         Arguments:
00131 
00132         o chromosome - A Chromosome graphics object that we can add
00133         chromosome segments to.
00134 
00135         This creates ChromosomeSegment (and TelomereSegment) objects to
00136         fill in the chromosome. The information is derived from the
00137         label and count information, with counts transformed to the
00138         specified color map.
00139 
00140         Returns the chromosome with all of the segments added.
00141         """
00142         for seg_num in range(len(self._names)):
00143             is_end_segment = 0
00144             # make the top and bottom telomeres
00145             if seg_num == 0:
00146                 cur_segment = TelomereSegment()
00147                 is_end_segment = 1
00148             elif seg_num == len(self._names) - 1:
00149                 cur_segment = TelomereSegment(1)
00150                 is_end_segment = 1
00151             # otherwise, they are just regular segments
00152             else:
00153                 cur_segment = ChromosomeSegment()
00154 
00155             seg_name = self._names[seg_num]
00156             if self._count_info[seg_name] > 0:
00157                 color = self._color_from_count(self._count_info[seg_name])
00158                 cur_segment.fill_color = color
00159             
00160             if self._label_info[seg_name] is not None:
00161                 cur_segment.label = self._label_info[seg_name]
00162 
00163             # give end segments extra size so they look right
00164             if is_end_segment:
00165                 cur_segment.scale = 3
00166             else:
00167                 cur_segment.scale = self._scale_info[seg_name]
00168 
00169             chromosome.add(cur_segment)
00170 
00171         return chromosome

Here is the call graph for this function:

Retrieve the color and label info about the segments.

Returns a list consiting of two tuples specifying the counts and
label name for each segment. The list is ordered according to the
original listing of names. Labels are set as None if no label
was specified.

Definition at line 110 of file DisplayRepresentation.py.

00110 
00111     def get_segment_info(self):
00112         """Retrieve the color and label info about the segments.
00113 
00114         Returns a list consiting of two tuples specifying the counts and
00115         label name for each segment. The list is ordered according to the
00116         original listing of names. Labels are set as None if no label
00117         was specified.
00118         """
00119         order_info = []
00120 
00121         for seg_name in self._names:
00122             order_info.append((self._count_info[seg_name],
00123                                self._label_info[seg_name]))
00124 
00125         return order_info

def Bio.Graphics.DisplayRepresentation.ChromosomeCounts.scale_segment_value (   self,
  segment_name,
  scale_value = None 
)
Divide the counts for a segment by some kind of scale value.

This is useful if segments aren't represented by raw counts, but
are instead counts divided by some number.

Definition at line 75 of file DisplayRepresentation.py.

00075 
00076     def scale_segment_value(self, segment_name, scale_value = None):
00077         """Divide the counts for a segment by some kind of scale value.
00078 
00079         This is useful if segments aren't represented by raw counts, but
00080         are instead counts divided by some number.
00081         """
00082         try:
00083             self._count_info[segment_name] = \
00084               float(self._count_info[segment_name]) / float(scale_value)
00085         except KeyError:
00086             raise KeyError("Segment name %s not found." % segment_name)

def Bio.Graphics.DisplayRepresentation.ChromosomeCounts.set_scale (   self,
  segment_name,
  scale 
)
Set the scale for a specific chromosome segment.

By default all segments have the same scale -- this allows scaling
by the size of the segment.

Raises a KeyError is the specified segment name is not found.

Definition at line 97 of file DisplayRepresentation.py.

00097 
00098     def set_scale(self, segment_name, scale):
00099         """Set the scale for a specific chromosome segment.
00100 
00101         By default all segments have the same scale -- this allows scaling
00102         by the size of the segment.
00103 
00104         Raises a KeyError is the specified segment name is not found.
00105         """
00106         if segment_name in self._label_info:
00107             self._scale_info[segment_name] = scale
00108         else:
00109             raise KeyError("Segment name %s not found." % segment_name)


Member Data Documentation

Definition at line 57 of file DisplayRepresentation.py.

Definition at line 49 of file DisplayRepresentation.py.

Definition at line 50 of file DisplayRepresentation.py.

Definition at line 48 of file DisplayRepresentation.py.

Definition at line 51 of file DisplayRepresentation.py.


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