[Biopython-dev] PhyloXML.BranchColor methods

Eric Talevich eric.talevich at gmail.com
Fri Apr 9 06:19:17 UTC 2010


On Wed, Apr 7, 2010 at 5:31 PM, Peter <biopython at maubp.freeserve.co.uk>wrote:

> On Wed, Apr 7, 2010 at 10:06 PM, Eric Talevich <eric.talevich at gmail.com>
> wrote:
> > On Wed, Apr 7, 2010 at 4:29 PM, Peter <biopython at maubp.freeserve.co.uk
> >wrote:
> >>
> >> I was suggesting adding a property to the clade (which could for
> >> example map color names or RBG triples to the BranchColor
> >> objects automatically). It would still be:
> >>
> >> from Bio import Phylo
> >> from Bio.Phylo import PhyloXML as PX
> >> tree = Phylo.read(..., 'phyloxml')
> >> critters = tree.find(name='Rattus')
> >> critters.color = PX.BranchColor(0, 128, 0)
> >>
> >> BUT, you could choose to allow:
> >>
> >> critters.color = (0, 128, 0)
> >>
> >> Or a named color,
> >>
> >> critters.color = "green"
> >>
> >> Or a hex string.
> >>
> >> critters.color = "#008000"
> >>
> >> and have the property set method convert these into
> >> the same result, BranchColor(0, 128, 0).
> >>
> >
> > It's pretty magical, but the convenience of "critters.color = 'green'"
> wins.
> > I'll implement the property to accept a BranchColor, RGB triple, color
> name,
> > or hex string, and raise a ValueError otherwise.
>
> Yeah - it feels right to me ;)
>

I implemented this property; it's in GitHub now.

>> Hmm, to_hex seems OK to me.
> >>
> >
> > My only concern: the builtin hex() returns a string formatted a little
> > differently. Matching that format would be useless here, but I was
> worried
> > about people being confused. But if you're OK with to/from_hex, then I am
> > too.
>

I left these as from_hex and to_hex. The docstrings are clear enough about
what the methods do, I think.

 >  > 3. Drop the to_rgb method; it's confusing and floating-point
> >> > conversions lead to bugs.
> >>
> >> I had assumed to_rgb would give a tuple of ints in the range
> >> 0 to 255 (following HTML/CSS color conventions). That would
> >> avoid the rounding issue.
>

At some point I changed to_rgb to return a tuple as you'd expect, without
rescaling. It's basically the constructor in reverse now.

Cheers,
Eric



More information about the Biopython-dev mailing list