[Biopython-dev] [Bug 3046] PhyloXML, please define get/set methods

bugzilla-daemon at portal.open-bio.org bugzilla-daemon at portal.open-bio.org
Tue Apr 6 23:09:34 UTC 2010


http://bugzilla.open-bio.org/show_bug.cgi?id=3046


biopython-bugzilla at maubp.freeserve.co.uk changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |biopython-
                   |                            |bugzilla at maubp.freeserve.co.
                   |                            |uk




------- Comment #4 from biopython-bugzilla at maubp.freeserve.co.uk  2010-04-06 19:09 EST -------
Taking a specific example, you suggested adding this helper function:

def set_color(node, red, green,  blue):
    node.color =  PhyloXML.BranchColor(red, green, blue)

I might advocate adding a color property to the tree/node class, with
a set method which accepts either a PhyloXML.BranchColor instance or
perhaps for convenience a RGB tuple. Something like this:

    def _set_color(self, color):
        if isinstance(color, PhyloXML.BranchColor):
            self._color = color
        elif len(color)==3:
            self.color = PhyloXML.BranchColor(red=color[0], green=color[1],
blue=color[2])
        else:
            raise ValueError("Bad color")
    def _get_color(self):
        return self._color
    color = Property(_get_color, _set_color, doc="Node color")

(It would be nice to make the color object similar to the ReportLab and
GenomeDiagram conventions used elsewhere in Biopython).

The point of that would be you would then use it like this:

for node in tree.find(terminal=False):
    node.color = PhyloXML.BranchColor(255, 0, 0)
for node in tree.find(terminal=True):
    node.color = PhyloXML.BranchColor(0, 0, 255)

if you explicitly wanted to make all the internal nodes red and all the
terminal nodes blue. Or, as discussed on Bug 3047 do this implicitly:

tree.color = (255, 0, 0) #implicitly applies to children
for node in tree.find(terminal=True):
    node.color = PhyloXML.BranchColor(0, 0, 255)

Eric - how would this example be done with the current code base?

Peter


-- 
Configure bugmail: http://bugzilla.open-bio.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.



More information about the Biopython-dev mailing list