]> git.donarmstrong.com Git - ape.git/blob - R/is.compatible.R
fix in birthdeath()
[ape.git] / R / is.compatible.R
1 ## is.compatible.R (2011-10-11)
2
3 ##   Check Compatibility of Splits
4
5 ## Copyright 2011 Andrei-Alin Popescu
6
7 ## This file is part of the R-package `ape'.
8 ## See the file ../COPYING for licensing issues.
9
10 is.compatible <- function(obj) UseMethod("is.compatible")
11
12 is.compatible.bitsplits <- function(obj)
13 {
14     m <- obj$matsplit
15     n <- ncol(m)
16     ntaxa <- length(obj$labels)
17     for (i in 1:(n - 1))
18         for (j in (i + 1):n)
19             if (!arecompatible(m[, i], m[, j], ntaxa))
20                 return(FALSE)
21     TRUE
22 }
23
24 arecompatible <-function(x, y, n)
25 {
26     msk <- !as.raw(2^(8 - (n %% 8)) - 1)
27
28     foo <- function(v) {
29         lv <- length(v)
30         v[lv] <- v[lv] & msk
31         as.integer(all(v == as.raw(0)))
32     }
33
34     nE <- foo(x & y) + foo(x & !y) + foo(!x & y) + foo(!x & !y)
35     if (nE == 1) TRUE else FALSE
36 }