Back to index

python-biopython  1.60
Public Member Functions | Public Attributes | Static Public Attributes
Bio.Phylo.BaseTree.BranchColor Class Reference
Inheritance diagram for Bio.Phylo.BaseTree.BranchColor:
Inheritance graph
[legend]

List of all members.

Public Member Functions

def __init__
def from_hex
def from_name
def to_hex
def to_rgb
def __repr__
def __str__

Public Attributes

 red
 green
 blue

Static Public Attributes

dictionary color_names

Detailed Description

Indicates the color of a clade when rendered graphically.

The color should be interpreted by client code (e.g. visualization
programs) as applying to the whole clade, unless overwritten by the
color(s) of sub-clades.

Color values must be integers from 0 to 255.

Definition at line 1037 of file BaseTree.py.


Constructor & Destructor Documentation

def Bio.Phylo.BaseTree.BranchColor.__init__ (   self,
  red,
  green,
  blue 
)

Definition at line 1086 of file BaseTree.py.

01086 
01087     def __init__(self, red, green, blue):
01088         for color in (red, green, blue):
01089             assert (isinstance(color, int) and
01090                     0 <= color <= 255
01091                     ), "Color values must be integers between 0 and 255."
01092         self.red = red
01093         self.green = green
01094         self.blue = blue


Member Function Documentation

Preserve the standard RGB order when representing this object.

Definition at line 1144 of file BaseTree.py.

01144 
01145     def __repr__(self):
01146         """Preserve the standard RGB order when representing this object."""
01147         return (u'%s(red=%d, green=%d, blue=%d)'
01148                 % (self.__class__.__name__, self.red, self.green, self.blue))

Show the color's RGB values.

Definition at line 1149 of file BaseTree.py.

01149 
01150     def __str__(self):
01151         """Show the color's RGB values."""
01152         return "(%d, %d, %d)" % (self.red, self.green, self.blue)
01153 
def Bio.Phylo.BaseTree.BranchColor.from_hex (   cls,
  hexstr 
)
Construct a BranchColor object from a hexadecimal string.

The string format is the same style used in HTML and CSS, such as
'#FF8000' for an RGB value of (255, 128, 0).

Definition at line 1096 of file BaseTree.py.

01096 
01097     def from_hex(cls, hexstr):
01098         """Construct a BranchColor object from a hexadecimal string.
01099 
01100         The string format is the same style used in HTML and CSS, such as
01101         '#FF8000' for an RGB value of (255, 128, 0).
01102         """
01103         assert (isinstance(hexstr, basestring) and
01104                 hexstr.startswith('#') and
01105                 len(hexstr) == 7
01106                 ), "need a 24-bit hexadecimal string, e.g. #000000"
01107         def unpack(cc):
01108             return int('0x'+cc, base=16)
01109         RGB = hexstr[1:3], hexstr[3:5], hexstr[5:]
01110         return cls(*map(unpack, RGB))

def Bio.Phylo.BaseTree.BranchColor.from_name (   cls,
  colorname 
)
Construct a BranchColor object by the color's name.

Definition at line 1112 of file BaseTree.py.

01112 
01113     def from_name(cls, colorname):
01114         """Construct a BranchColor object by the color's name."""
01115         return cls(*cls.color_names[colorname])

Return a 24-bit hexadecimal RGB representation of this color.

The returned string is suitable for use in HTML/CSS, as a color
parameter in matplotlib, and perhaps other situations.

Example:

    >>> bc = BranchColor(12, 200, 100)
    >>> bc.to_hex()
    '#0cc864'

Definition at line 1116 of file BaseTree.py.

01116 
01117     def to_hex(self):
01118         """Return a 24-bit hexadecimal RGB representation of this color.
01119 
01120         The returned string is suitable for use in HTML/CSS, as a color
01121         parameter in matplotlib, and perhaps other situations.
01122 
01123         Example:
01124 
01125             >>> bc = BranchColor(12, 200, 100)
01126             >>> bc.to_hex()
01127             '#0cc864'
01128         """
01129         return '#' + hex(
01130                 self.red * (16**4)
01131                 + self.green * (16**2)
01132                 + self.blue)[2:].zfill(6)

Return a tuple of RGB values (0 to 255) representing this color.

Example:

    >>> bc = BranchColor(255, 165, 0)
    >>> bc.to_rgb()
    (255, 165, 0)

Definition at line 1133 of file BaseTree.py.

01133 
01134     def to_rgb(self):
01135         """Return a tuple of RGB values (0 to 255) representing this color.
01136 
01137         Example:
01138 
01139             >>> bc = BranchColor(255, 165, 0)
01140             >>> bc.to_rgb()
01141             (255, 165, 0)
01142         """
01143         return (self.red, self.green, self.blue)


Member Data Documentation

Definition at line 1093 of file BaseTree.py.

Definition at line 1047 of file BaseTree.py.

Definition at line 1092 of file BaseTree.py.

Definition at line 1091 of file BaseTree.py.


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