emmanuelparadis / ape

Analysis of Phylogenetics and Evolution
https://emmanuelparadis.github.io/
GNU General Public License v2.0
53 stars 11 forks source link

wrong behaviour of is.monophyletic() with duplicated labels #50

Closed emmanuelparadis closed 2 years ago

emmanuelparadis commented 2 years ago

(Posted to: r-sig-phylo and GitHub)

Hi all,

is.monophyletic() does not work correctly when some tip labels are duplicated. Here's a simple example:

R> tr <- read.tree(text = "((A,B),(A,C));")

The two tips labelled "A" are not sister-lineages, but the current version of ape gives:

R> is.monophyletic(tr, "A")
[1] TRUE
R> is.monophyletic(tr, c("A", "A")) # <- must interrupt
^C

The reason for this is that the function looks for the first occurrence of "A" in the tip labels of tr, even with duplicated labels. By contrast, drop.tip() looks for all occurrences; the following command drops 2 tips even if a single label is given:

R> drop.tip(tr, "A")

Phylogenetic tree with 2 tips and 1 internal nodes.

Tip labels:
  B, C

Rooted; no branch lengths.

The version of ape on GH (will be submitted to CRAN next week) now returns FALSE in both above commands. I assume this change will create no problem for the packages that use this function, but I thought it may be worth explaining this issue ahead of the CRAN submission. As usual, any feedback welcome. Best, Emmanuel