Thursday, February 28, 2013

Using bind.tip (or bind.tree) on a tree with node labels

Just a quick point of (searchable) clarification for both phytools bind.tip and the ape function bind.tree (bind.tip, after all, uses bind.tree interally; 1, 2). Regardless of whether or not your tree contains node labels (or tip labels, for that matter), the argument where should give the node number (from the matrix tree$edge), at or below which the tip or subtree should be bound.

Node numbers can be seen using:
plotTree(tree,node.numbers=T)
## OR
plot(tree)
nodelabels() # i.e., no arguments

If you want to bind a new tip or subtree to a terminal edge (i.e., an edge ending with a tip), then the 'node number' is just the index of the species in tree$tip.label. We can get this by (for tip name tip) setting where=which(tree$tip.label==tip). Alternatively, if we want to see the node & tip numbers plotted on the tree we could do:
> tree<-pbtree(n=20)
> plot(tree,no.margin=T,label.offset=0.1) # offset may vary
> nodelabels()
> tiplabels()
If adding multiple tips to the tree, remember to keep in mind that each time a new tip is added, the set of node numbers will change. For example:
> tree2<-bind.tip(tree,"t21",where=23,position= 0.5*tree$edge.length[which(tree$edge[,2]==23)])
> ## this just added a new tip halfway along the edge
> ## ending at node 23
> plot(tree2,no.margin=T,label.offset=0.1)
> nodelabels()
> tiplabels()

That's all for now!

6 comments:

  1. Of course, I should have mentioned that to get a node number from the node label we should do:

    which(node==tree$node.label)

    - Liam

    ReplyDelete
  2. Hi Liam, thanks for this post! I'm wondering how you can bind a new tip to an edge, rather than a node or tip. For example, I want to bind a new species "X" to the tree. The species is related to t8 and t7, but t8 and t7 are more closely related to each other than X. How would you go about this? My understanding is that bind.tip(newtree, tip.label="X", where=41) would result in a polytomy, but using the tip number references "20" or "19" would not result in the phylogeny I require as I want X as the outgroup. Thanks for your help!

    ReplyDelete
    Replies
    1. Dear Hester. bind.tip has an additional argument, position, which allows you to attach the tip along an edge rather than at a node. See the documentation page for the function & let us know if it provides sufficient guidance. -- Liam

      Delete
  3. Hi Liam, thank you for your reply. What about the case the tip needs binding beyond the root? I.e. where bind.tip creates a trichotomy at the root. I find the documentation mentions this but I cannot find a solution to create an outgroup beyond the root.

    ReplyDelete
  4. Hi Liam, thank you all your work!
    I would like to know if it is possible to bind several tips at once with bind.tip()? If yes, could you provide an example?
    Thank you!
    A

    ReplyDelete

Note: due to the very large amount of spam, all comments are now automatically submitted for moderation.