emmanuelparadis / ape

analysis of phylogenetics and evolution
http://ape-package.ird.fr/
GNU General Public License v2.0
52 stars 11 forks source link

v5.8 drop.tip unexpected behavior #118

Open colejensen opened 3 months ago

colejensen commented 3 months ago

Hello,

I was checking some functions with the new update and noticed that drop.tip was producing some interesting results. Specifically when trim.internal = FALSE and subtree = FALSE.

I've attached a small example tree to highlight the problem. In this example, all the tips other than the "Germline" are supposed to be dropped. I would expect this to produce a tree with the germline and another branch that highlights that the others were dropped, not a number of branches as I currently get.

Best, Cole forApe.zip

emmanuelparadis commented 3 months ago

Hello,

The effect of trim.internal = FALSE affects only the internal branches; the terminal ones are always deleted (if they are targeted by the other options). I think these commands can help to see more clearly what's going on there:

layout(matrix(1:2, 2))
plot(phy, show.node.label = TRUE, tip.color = "green")
plot(tphy, show.node.label = TRUE, tip.color = "green")

Best, Emmanuel

colejensen commented 3 months ago

Hello,

I see, thank you. I was hoping to find something that did trim the tree to the node that connected the dropped tips to the remaining tree. I found that the options trim.internal = FALSE coupled with subtree = TRUE did something along those lines. Does this seem like an appropriate way to do this?

For example:

target_node <- 16 tphy <- ape::drop.tip(phy, collapse.singles = TRUE, trim.internal = FALSE, tip = ape::extract.clade(phy, node = target_node)$tip.label, subtree = TRUE)

Best, Cole

emmanuelparadis commented 3 months ago

I'm not 100% sure to see what you want to do, but what about calling drop.tip() several times playing with its options? If you use it first with trim.internal = FALSE, then some (previously) internal branches become terminal and you can delete them selectively calling drop.tip() again but keeping trim.internal = TRUE.

As a side note, you can see ?identify.phylo and the options described: this could help you select the tip(s) you want to delete (unless you want to run this one many trees...)

Best, Emmanuel