Drawing lines between nodes of a phylogeny

151 views
Skip to first unread message

Bastien Boussau

unread,
Dec 10, 2015, 11:17:00 AM12/10/15
to The ETE toolkit
Hi, 

I'd like to draw lines to connect two nodes of a plotted tree. The idea behind this is to plot gene transfers along a species tree phylogeny. Ideally I would control the appearance of the line (thickness, transparency, color...). Even more ideally the lines could be curved, with an arrow at the end, for a nicer visualization.
Is there a way to do some version of this using ete3?

Thanks very much!

Bastien

Luiz Thiberio Rangel

unread,
Dec 10, 2015, 3:41:52 PM12/10/15
to The ETE toolkit
Hi Bastien

    I made something similar using matplotlib itself, but hardcoded to a set of trees. What I can say is that it ended up too polluted. The solution I am using right now to highlight HGT is using nodeface and colormatching donnor/recipient.

    If you have too many transfer it is still a little harder to differentiate the different events but using the right colorscheme helps a lot.

thiberio,

Bastien Boussau

unread,
Dec 11, 2015, 5:51:30 AM12/11/15
to The ETE toolkit
Hi Thiberio,

Thanks very much for your input. I would still like to try this line thing: indeed I can choose how many transfers I want to show so that it is not too cluttered. If you have some code/guidance on how to add lines to an ete3 plot, and how to get the coordinates of the nodes, or if you already have some code to do that, I would like to try!

Thanks again, 

Bastien 

Jaime Huerta Cepas

unread,
Dec 11, 2015, 11:56:01 AM12/11/15
to eteto...@googlegroups.com
time ago a wrote some ad hoc code to draw things like in the screenshots attached. 
If useful, I think I could add it to core set to features of ETE 3. 
I will need to find a couple of days to work on it, but any feedback on what would you expect from a feature like this, might help

cheers, 
-jaime

--
You received this message because you are subscribed to the Google Groups "The ETE toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to etetoolkit+...@googlegroups.com.
To post to this group, send email to eteto...@googlegroups.com.
Visit this group at http://groups.google.com/group/etetoolkit.
For more options, visit https://groups.google.com/d/optout.

ideaHGT.png
snapshot1.png

Luiz Thiberio Rangel

unread,
Dec 11, 2015, 2:03:03 PM12/11/15
to eteto...@googlegroups.com
It looks like Jaime has it in a much better way than I did (as expected, =P). But when you render the tree it is returned a dict with the coordinates of each node, sorry but I don't have any code for that anymore.... =/
--
L Thiberio Rangel

Jaime Huerta Cepas

unread,
Dec 11, 2015, 2:16:32 PM12/11/15
to eteto...@googlegroups.com
my code is still too crappy..., I would not really say I have anything at all yet :)

You approach is actually on the good track. Indeed, the dictionary returned by tree.render has the absolute coordinates of nodes, so you could easily hack something around that...

Bastien Boussau

unread,
Dec 15, 2015, 7:21:52 AM12/15/15
to The ETE toolkit
Thanks very much Jaime and Thiberio, 

I think what you have in the figures you sent is quite nice and pretty close to what I had in mind (except that I would use it on a rooted/dated tree). I'd like to be able to draw lines between branches (e.g. between the middle of branches, but that could perhaps be controlled), not nodes, including ancestral branches, not just tips. Ideally I'd like to be able to control the width of the lines, their curvature, their color and their transparency, and possibly to place an arrowhead at one of the two ends. I know that's a lot to ask, so if that's not a feature you think would fit well within ete, I could also try to play around with the dictionary returned by tree.render.

Thanks very much again!

Bastien

Luiz Thiberio Rangel

unread,
Dec 15, 2015, 10:57:45 AM12/15/15
to The ETE toolkit
Hey, Bastien,

if you don't really mind about using straight arrows it should be fairly easy. Take a look at this matplotlib example: http://matplotlib.org/examples/pylab_examples/arrow_simple_demo.html

You can easily control transparency, width, line and background color.


For more options, visit https://groups.google.com/d/optout.

Bastien Boussau

unread,
Dec 17, 2015, 4:28:07 AM12/17/15
to The ETE toolkit
Thanks very much, but I have not been able yet to draw the tree, get the coordinates of the nodes, and plot something on top of it... 
I have not been able to understand the structure that tree.render returns... It does not seem to be a simple dictionary, is it?
Sorry I'm so slow!

Bastien

Bastien Boussau

unread,
Dec 17, 2015, 7:59:26 AM12/17/15
to The ETE toolkit
Probably this last email was not very informative.
here is the type of things that I have tried, in a Jupyter notebook (which maybe is a problem...): 

t.render("%%inline", tree_style=ts) 

works and displays the tree.

I tried to store the output of render:

coord = t.render("%%inline", tree_style=ts)  

But then I don't know what to do with it... I have seen it is a IPython.core.display.Image, but calling imshow on it does not work. And I don't know how to get the coordinates of nodes out of coord...

Again, sorry I'm so slow, and thanks very much!

Bastien

Jaime Huerta Cepas

unread,
Dec 17, 2015, 12:07:28 PM12/17/15
to eteto...@googlegroups.com
no problem. I am actually quite interested in having a proper way to visualize HGT events. I will try to add some generic code in the following weeks...  

Bastien Boussau

unread,
Jan 18, 2016, 5:17:54 AM1/18/16
to The ETE toolkit
Great, thanks very much, please keep me posted when you're done!

donova...@gmail.com

unread,
Nov 18, 2016, 2:25:12 PM11/18/16
to The ETE toolkit
Hello,

I would also be interested in being able to add custom visual elements (namely, lines) to an ETE rendering. Is there an example showing how a line can be drawn between two nodes, or two arbitrary points in a plot?

Cheers,
Donovan

Jaime Huerta Cepas

unread,
Nov 24, 2016, 9:38:55 AM11/24/16
to eteto...@googlegroups.com
Hi Donovan, 
this is not support yet. At least not in a user friendly manner... 
There is some recent progress that I hope to integrate soon in the main branch. 

thanks. 

To unsubscribe from this group and stop receiving emails from it, send an email to etetoolkit+unsubscribe@googlegroups.com.

j.co...@gmail.com

unread,
Dec 15, 2017, 1:58:07 AM12/15/17
to The ETE toolkit
On Friday, December 11, 2015 at 11:56:01 AM UTC-5, Jaime wrote:
> time ago a wrote some ad hoc code to draw things like in the screenshots attached. 
> If useful, I think I could add it to core set to features of ETE 3. 
> I will need to find a couple of days to work on it, but any feedback on what would you expect from a feature like this, might help
>
>
> cheers, 
> -jaime
>

Jaime,
Is there a program to make visualizations like the ones you posted?
Thanks.

Jaime Huerta Cepas

unread,
Dec 18, 2017, 4:12:56 AM12/18/17
to eteto...@googlegroups.com
there is only an open development branch trying to implement it: 
cheers, 
-jaime

--
You received this message because you are subscribed to the Google Groups "The ETE toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to etetoolkit+unsubscribe@googlegroups.com.

To post to this group, send email to eteto...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages