Join two trees (add one tree at the tip of the other)

23 views
Skip to first unread message

Erica Fary

unread,
Oct 10, 2015, 5:35:24 PM10/10/15
to DendroPy Users
Dear all,

I am working on phylogenies by using DendroPy (thank you for this amazing library!). Now I have to import 2 trees in Newick format (this is obviously not the difficult part) and join them together, more precisely I have to add one tree at one tip/leaf of another (this is the difficult part). I have tried with add_child and new_child methods but without success.

Can anyone indicate how I could proceed ? Any help is welcome...

Thank you in advance.

Jeet Sukumaran

unread,
Oct 10, 2015, 6:34:17 PM10/10/15
to dendrop...@googlegroups.com
The basic logic would indeed be using ``add_child``, passing in the seed
node of the second tree as the node to be added.

Other issues that you might have to deal with would be taxon management.

A basic approach would be:

~~~
tns = dendropy.TaxonNamespace()
tree1 = dendropy.Tree.get(
path="tree1.tre",
schema="newick",
taxon_namespace=tns)
tree2 = dendropy.Tree.get(
path="tree2.tre",
schema="newick",
taxon_namespace=tns)
nd = tree1.find_node(...)
nd.add_child(tree2.seed_node)
~~~

It would probably be useful for you to post a minimum self-contained
example for what you tried, and what did not work.

-- jeet
> --
> You received this message because you are subscribed to the Google
> Groups "DendroPy Users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to dendropy-user...@googlegroups.com
> <mailto:dendropy-user...@googlegroups.com>.
> For more options, visit https://groups.google.com/d/optout.

--



--------------------------------------
Jeet Sukumaran
--------------------------------------
jeetsu...@gmail.com
--------------------------------------
Blog/Personal Pages:
http://jeetworks.org/
GitHub Repositories:
http://github.com/jeetsukumaran
Photographs (as stream):
http://www.flickr.com/photos/jeetsukumaran/
Photographs (by galleries):
http://www.flickr.com/photos/jeetsukumaran/sets/
--------------------------------------

Erica Fary

unread,
Oct 11, 2015, 2:47:06 PM10/11/15
to DendroPy Users
Thank you so much for your quick reply !!

Newbie's mistake: I wrote nd.add_child(tree2) instead of [...](tree2.seed_node). Now it works !

Thank you again and best regards.
Reply all
Reply to author
Forward
0 new messages