liamrevell / phytools

GNU General Public License v3.0
207 stars 56 forks source link

allow adding a tip whose origin is older than the root #88

Open josephwb opened 3 years ago

josephwb commented 3 years ago

Allow adding an outgroup tip which diverged before the ingroup MRCA. The ape::bind.tree function which bind.tip wraps allows this, but the tree to which the tip is added ("x") must have a root.edge. The code submitted here does the necessary edits so that bind.tree does what is requested with no more arguments required from the user.

Examples

# this uses the existing example for `bind.tip`
tree<-pbtree(b=0.1, n=10);
plot(tree); axisPhylo();

# add an extant tip with known divergence time (4.5 units above root)
tree.extant <- bind.tip.alt(tree, tip.label="t_extant", position=4.5);

# plot
par(mfrow=c(1,2));
plot(tree); axisPhylo();
plot(tree.extant); axisPhylo();
par(mfrow=c(1,1));

# add an extinct tip that survived until 7.8 units before present
# 1. the root age of the original tree is RA=max(nodeHeights(tree))
# 2. we are adding position to that age (time to MRCA of all)
# so edge.length will be RA+position-7.8
RA=max(nodeHeights(tree))
EL <- RA + 4.5 - 7.8;
tree.extinct <- bind.tip.alt(tree, tip.label="t_extant", position=4.5, edge.length=EL);

# plot
par(mfrow=c(1,2));
plot(tree); axisPhylo();
plot(tree.extinct); axisPhylo();
par(mfrow=c(1,1));
josephwb commented 3 years ago

Anyway, this arose from a student wanting to an an extinct outgroup to her extant tree, which did not seem possible with the existing version of bind.tip.

HTH.

josephwb commented 3 years ago

Ping.

If you are not interested in this, that is totally fine. Just please reject the PR so I can delete my fork.