Back to index

python-biopython  1.60
Public Member Functions | Private Attributes
Bio.Graphics.GenomeDiagram._Colors.ColorTranslator Class Reference

List of all members.

Public Member Functions

def __init__
def translate
def read_colorscheme
def get_artemis_colorscheme
def artemis_color
def get_colorscheme
def scheme_color
def int255_color
def float1_color

Private Attributes

 _artemis_colorscheme
 _colorscheme

Detailed Description

Class providing methods for translating representations of color into

Definition at line 26 of file _Colors.py.


Constructor & Destructor Documentation

def Bio.Graphics.GenomeDiagram._Colors.ColorTranslator.__init__ (   self,
  filename = None 
)
__init__(self, filename)

    o filename      Location of a file containing colorscheme
            information

    Optional parameters set the color scheme 

Definition at line 29 of file _Colors.py.

00029 
00030     def __init__(self, filename=None):
00031         """ __init__(self, filename)
00032 
00033             o filename      Location of a file containing colorscheme
00034                             information
00035 
00036             Optional parameters set the color scheme 
00037         """
00038         self._artemis_colorscheme = {0: (colors.Color(1, 1, 1,), "pathogenicity, adaptation, chaperones"),
00039                1: (colors.Color(0.39, 0.39, 0.39), "energy metabolism"),
00040                2: (colors.Color(1, 0, 0), "information transfer"),
00041                3: (colors.Color(0, 1, 0), "surface"),
00042                4: (colors.Color(0, 0, 1), "stable RNA"),
00043                5: (colors.Color(0, 1, 1), "degradation of large molecules"),
00044                6: (colors.Color(1, 0, 1), "degradation of small molecules"),
00045                7: (colors.Color(1, 1, 0), "central/intermediary/miscellaneous metabolism"),
00046                8: (colors.Color(0.60, 0.98, 0.60), "unknown"),
00047                9: (colors.Color(0.53, 0.81, 0.98), "regulators"),
00048                10: (colors.Color(1, 0.65, 0), "conserved hypotheticals"),
00049                11: (colors.Color(0.78, 0.59, 0.39), "pseudogenes and partial genes"),
00050                12: (colors.Color(1, 0.78, 0.78), "phage/IS elements"),
00051                13: (colors.Color(0.70, 0.70, 0.70), "some miscellaneous information"),
00052                14: (colors.Color(0, 0, 0), ""),
00053                15: (colors.Color(1, 0.25, 0.25), "secondary metabolism"),
00054                16: (colors.Color(1, 0.5, 0.5), ""),
00055                17: (colors.Color(1, 0.75, 0.75), "")
00056                 }      # Hardwired Artemis color scheme                                                                        
00057         self._colorscheme = {}
00058         if filename is not None:
00059             self.read_colorscheme(filename)# Imported color scheme
00060         else:
00061             self._colorscheme = self._artemis_colorscheme
00062 

Here is the caller graph for this function:


Member Function Documentation

artemis_color(self, value)

    o value     An int representing a functional class in the Artemis
        color scheme (see www.sanger.ac.uk for a description),
        or a string from a GenBank feature annotation for the
        color which may be dot delimited (in which case the
        first value is used).

    Takes an int representing a functional class in the Artemis color
    scheme, and returns the appropriate colors.Color object

Definition at line 134 of file _Colors.py.

00134 
00135     def artemis_color(self, value):
00136         """ artemis_color(self, value)
00137 
00138             o value     An int representing a functional class in the Artemis
00139                         color scheme (see www.sanger.ac.uk for a description),
00140                         or a string from a GenBank feature annotation for the
00141                         color which may be dot delimited (in which case the
00142                         first value is used).
00143 
00144             Takes an int representing a functional class in the Artemis color
00145             scheme, and returns the appropriate colors.Color object
00146         """
00147         try:
00148             value = int(value)
00149         except ValueError:
00150             if value.count('.'):                           # dot-delimited
00151                 value = int(artemis_color.split('.',1)[0]) # Use only first integer
00152             else:
00153                 raise
00154         if value in self._artemis_colorscheme:
00155             return self._artemis_colorscheme[value][0]
00156         else:
00157             raise ValueError, "Artemis color out of range: %d" % value
00158 

float1_color(self, values)

    o values        A tuple of (red, green, blue) intensities as floats
            in the range 0 -> 1

    Takes a tuple of (red, green, blue) intensity values in the range
    0 -> 1 and returns an appropriate colors.Color object

Definition at line 197 of file _Colors.py.

00197 
00198     def float1_color(self, values):
00199         """ float1_color(self, values)
00200 
00201             o values        A tuple of (red, green, blue) intensities as floats
00202                             in the range 0 -> 1
00203 
00204             Takes a tuple of (red, green, blue) intensity values in the range
00205             0 -> 1 and returns an appropriate colors.Color object
00206         """
00207         red, green, blue = values
00208         return colors.Color(red, green, blue)
00209 

Here is the caller graph for this function:

get_artemis_colorscheme(self)

    Return the Artemis color scheme as a dictionary

Definition at line 126 of file _Colors.py.

00126 
00127     def get_artemis_colorscheme(self):
00128         """ get_artemis_colorscheme(self)
00129 
00130             Return the Artemis color scheme as a dictionary
00131         """
00132         return self._artemis_colorscheme
00133         

get_colorscheme(self)

    Return the user-defined color scheme as a dictionary

Definition at line 159 of file _Colors.py.

00159 
00160     def get_colorscheme(self):
00161         """ get_colorscheme(self)
00162 
00163             Return the user-defined color scheme as a dictionary
00164         """
00165         return self._colorscheme
00166 

int255_color(self, values)

    o values        A tuple of (red, green, blue) intensities as
            integers in the range 0->255

    Takes a tuple of (red, green, blue) intensity values in the range
    0 -> 255 and returns an appropriate colors.Color object

Definition at line 182 of file _Colors.py.

00182 
00183     def int255_color(self, values):
00184         """ int255_color(self, values)
00185 
00186             o values        A tuple of (red, green, blue) intensities as
00187                             integers in the range 0->255
00188 
00189             Takes a tuple of (red, green, blue) intensity values in the range
00190             0 -> 255 and returns an appropriate colors.Color object
00191         """
00192         red, green, blue = values
00193         factor = 1/255.
00194         red, green, blue = red * factor, green * factor, blue * factor
00195         return colors.Color(red, green, blue)
00196 

Here is the caller graph for this function:

read_colorscheme(self, filename)

    o filename      The location of a file defining colors in tab-separated
            format plaintext as:
            INT \t RED \t GREEN \t BLUE \t Comment
            Where RED, GREEN and BLUE are intensities in the range
            0 -> 255
            e.g.
            2 \t 255 \t 0 \t 0 \t Red: Information transfer

    Reads information from a file containing color information and
    stores it internally

Definition at line 97 of file _Colors.py.

00097 
00098     def read_colorscheme(self, filename):
00099         """ read_colorscheme(self, filename)
00100 
00101             o filename      The location of a file defining colors in tab-separated
00102                             format plaintext as:
00103                             INT \t RED \t GREEN \t BLUE \t Comment
00104                             Where RED, GREEN and BLUE are intensities in the range
00105                             0 -> 255
00106                             e.g.
00107                             2 \t 255 \t 0 \t 0 \t Red: Information transfer
00108 
00109             Reads information from a file containing color information and
00110             stores it internally
00111         """
00112         lines = open(filename, 'r').readlines()
00113         for line in lines:
00114             data = line.strip().split('\t')
00115             try:
00116                 label = int(data[0])
00117                 red, green, blue = int(data[1]), int(data[2]), int(data[3])
00118                 if len(data) > 4:
00119                     comment = data[4]
00120                 else:
00121                     comment = ""
00122                 self._colorscheme[label] = (self.int255_color((red, green, blue)),
00123                                              comment)
00124             except:
00125                 raise IOError, "Expected INT \t INT \t INT \t INT \t string input"

Here is the call graph for this function:

scheme_color(self, value)

    o value     An int representing a single color in the user-defined
        color scheme

    Takes an int representing a user-defined color and returns the
    appropriate colors.Color object

Definition at line 167 of file _Colors.py.

00167 
00168     def scheme_color(self, value):
00169         """ scheme_color(self, value)
00170 
00171             o value     An int representing a single color in the user-defined
00172                         color scheme
00173 
00174             Takes an int representing a user-defined color and returns the
00175             appropriate colors.Color object
00176         """
00177         if value in self._colorscheme:
00178             return self._colorscheme[value][0]
00179         else:
00180             raise ValueError, "Scheme color out of range: %d" % value
00181 

Here is the caller graph for this function:

def Bio.Graphics.GenomeDiagram._Colors.ColorTranslator.translate (   self,
  color = None,
  colour = None 
)
translate(self, color)

    o color    Color defined as an int, a tuple of three ints 0->255
       or a tuple of three floats 0 -> 1, or a string giving
       one of the named colors defined by ReportLab, or a
       ReportLab color object (returned as is).

       (This argument is overridden by a backwards compatible
       argument with UK spelling, colour).

    Returns a colors.Color object, determined semi-intelligently
    depending on the input values

Definition at line 63 of file _Colors.py.

00063 
00064     def translate(self, color=None, colour=None):
00065         """ translate(self, color)
00066 
00067             o color    Color defined as an int, a tuple of three ints 0->255
00068                        or a tuple of three floats 0 -> 1, or a string giving
00069                        one of the named colors defined by ReportLab, or a
00070                        ReportLab color object (returned as is).
00071 
00072                        (This argument is overridden by a backwards compatible
00073                        argument with UK spelling, colour).
00074 
00075             Returns a colors.Color object, determined semi-intelligently
00076             depending on the input values
00077         """
00078         #Let the UK spelling (colour) override the USA spelling (color)
00079         if colour is not None:
00080             color = colour
00081         
00082         if color is None:
00083             raise ValueError, "Passed color (or colour) must be a valid color type"
00084         elif isinstance(color, int):
00085             color = self.scheme_color(color)
00086         elif isinstance(color, colors.Color):
00087             return color
00088         elif isinstance(color, basestring):
00089             #Assume its a named reportlab color like "red".
00090             color = colors.toColor(color)
00091         elif type(color) == type((1., 2., 3.)) and type(color[0]) == type(1.):
00092             color = self.float1_color(color)        
00093         elif type(color) == type((1, 2, 3)) and type(color[0]) == type(1):
00094             color = self.int255_color(color)
00095         return color
00096         

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 37 of file _Colors.py.

Definition at line 56 of file _Colors.py.


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