Package Bio :: Package Graphics :: Package GenomeDiagram :: Module _Colors :: Class ColorTranslator
[hide private]
[frames] | no frames]

Class ColorTranslator

source code

object --+
         |
        ColorTranslator

Class providing methods for translating representations of color into.

Example:

>>> from Bio.Graphics import GenomeDiagram
>>> gdct=GenomeDiagram._Colors.ColorTranslator()
>>> print(gdct.float1_color((0.5, 0.5, 0.5)))
Color(.5,.5,.5,1)
>>> print(gdct.int255_color((1, 75, 240)))
Color(.003922,.294118,.941176,1)
>>> print(gdct.artemis_color(7))
Color(1,1,0,1)
>>> print(gdct.scheme_color(2))
Color(1,0,0,1)
>>> gdct.get_artemis_colorscheme()
{0: (Color(1,1,1,1), 'pathogenicity, adaptation, chaperones'), 1: (Color(.39,.39,.39,1), 'energy metabolism'), 2: (Color(1,0,0,1), 'information transfer'), 3: (Color(0,1,0,1), 'surface'), 4: (Color(0,0,1,1), 'stable RNA'), 5: (Color(0,1,1,1), 'degradation of large molecules'), 6: (Color(1,0,1,1), 'degradation of small molecules'), 7: (Color(1,1,0,1), 'central/intermediary/miscellaneous metabolism'), 8: (Color(.6,.98,.6,1), 'unknown'), 9: (Color(.53,.81,.98,1), 'regulators'), 10: (Color(1,.65,0,1), 'conserved hypotheticals'), 11: (Color(.78,.59,.39,1), 'pseudogenes and partial genes'), 12: (Color(1,.78,.78,1), 'phage/IS elements'), 13: (Color(.7,.7,.7,1), 'some miscellaneous information'), 14: (Color(0,0,0,1), ''), 15: (Color(1,.25,.25,1), 'secondary metabolism'), 16: (Color(1,.5,.5,1), ''), 17: (Color(1,.75,.75,1), '')}
>>> print(gdct.translate((0.5, 0.5, 0.5)))
Color(.5,.5,.5,1)
>>> print(gdct.translate((1, 75, 240)))
Color(.003922,.294118,.941176,1)
>>> print(gdct.translate(7))
Color(1,1,0,1)
>>> print(gdct.translate(2))
Color(1,0,0,1)
Instance Methods [hide private]
 
__init__(self, filename=None)
Initialize.
source code
 
translate(self, color=None, colour=None)
Translate a color into a ReportLab Color object.
source code
 
read_colorscheme(self, filename)
Load colour scheme from file.
source code
 
get_artemis_colorscheme(self)
Return the Artemis color scheme as a dictionary.
source code
 
artemis_color(self, value)
Artemis color (integer) to ReportLab Color object.
source code
 
get_colorscheme(self)
Return the user-defined color scheme as a dictionary.
source code
 
scheme_color(self, value)
Map a user-defined color integer to a ReportLab Color object.
source code
 
int255_color(self, values)
Map integer (red, green, blue) tuple to a ReportLab Color object.
source code
 
float1_color(self, values)
Map float (red, green, blue) tuple to a ReportLab Color object.
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, filename=None)
(Constructor)

source code 

Initialize.

Argument filename is the location of a file containing colorscheme information.

Overrides: object.__init__

translate(self, color=None, colour=None)

source code 

Translate a color into a ReportLab Color object.

Arguments:

  • 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).
  • colour - Backards compatible alias using UK spelling (which will over-ride any color argument).

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

read_colorscheme(self, filename)

source code 

Load colour scheme from file.

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

Argument filename is 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

artemis_color(self, value)

source code 

Artemis color (integer) to ReportLab Color object.

Arguments:

  • 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

scheme_color(self, value)

source code 

Map a user-defined color integer to a ReportLab Color object.

  • 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.

int255_color(self, values)

source code 

Map integer (red, green, blue) tuple to a ReportLab Color object.

  • 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.

float1_color(self, values)

source code 

Map float (red, green, blue) tuple to a ReportLab Color object.

  • 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.