etetoolkit / ete

Python package for building, comparing, annotating, manipulating and visualising trees. It provides a comprehensive API and a collection of command line tools, including utilities to work with the NCBI taxonomy tree.
http://etetoolkit.org
GNU General Public License v3.0
782 stars 212 forks source link

PhyloNodes styles not working like TreeNodes #693

Open mwodring opened 1 year ago

mwodring commented 1 year ago

Hi,

I got some code working with a base tree. It simply takes some user input and generates a dictionary of name to colour and colours the nodes based on that. The working one is like so:

#colour_map is defined above, but it's a simple dict of search parameter to colour. like {'cat' : pink}. The quotes are an artefact of how the Newick file is generated.

def NewNodeStyle(colour: str) -> NodeStyle:
    ns = NodeStyle()
    ns['shape'] = "sphere"
    ns['size'] = 10
    ns['fgcolor'] = colour
    return ns

for term, colour in colour_map.items():
    nodes = t.search_nodes(name=term)
    for node in nodes:
        colour_nodes(colour, node)
       node.set_style(NewNodeStyle(colour))

Then I render it. Works fine, if I say 'Cat' and I want it to be "pink" (or "Pink") I get all species called 'Cat' labelled as a pink sphere. However, if I make a PhyloTree instead, I cannot recolour nodes. The same exact code but with PhyloTree instead does nothing. I even wrote something to trace the node back up to the root and give each node this style but no good.

Mapping species to node works fine of course, as does searching by the species derived from the name (which is species + NCBI accession). If I print the 'node' here it prints the node. It just will not recolour or change the style of the nodes I want. Is the issue between keyboard and screen or is this a quirk with PhyloTree? From the docs I understand it extends the Tree base so it SHOULD work the same and appears to from the doc.

I ran it with a dummy file generated to be small and easy like the doc but that also didn't work.

Some notes: Jupyter Lab in a Conda environment on Windows. Version is latest Conda version so 3.1.3. Many apologies if this is my error, the docs are excellent but I've been at this for about six hours so I figured it was time to submit an issue.