- seq.nod <- .Call("seq_root2tip", phy$edge, n,
- phy$Nnode, PACKAGE = "ape")
- sn <- seq.nod[outgroup]
- ## We go from the root to the tips: the sequence of nodes
- ## is identical until the MRCA:
- newroot <- ROOT
- i <- 2 # we start at the 2nd position since the root
- # of the tree is a common ancestor to all tips
- repeat {
- x <- unique(unlist(lapply(sn, "[", i)))
- if (length(x) != 1) break
- newroot <- x
- i <- i + 1
- }
- ## Check that all descendants of this node
- ## are included in the outgroup.
- ## (below is slightly faster than calling "bipartition")
- desc <- which(unlist(lapply(seq.nod,
- function(x) any(x %in% newroot))))
- msg <- "the specified outgroup is not monophyletic"