File: is.compatible.R

package info (click to toggle)
r-cran-ape 5.8-1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,676 kB
  • sloc: ansic: 7,676; cpp: 116; sh: 17; makefile: 2
file content (36 lines) | stat: -rw-r--r-- 808 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
## is.compatible.R (2017-06-03)

##   Check Compatibility of Splits

## Copyright 2011 Andrei-Alin Popescu

## This file is part of the R-package `ape'.
## See the file ../COPYING for licensing issues.

is.compatible <- function(obj) UseMethod("is.compatible")

is.compatible.bitsplits <- function(obj)
{
    m <- obj$matsplit
    n <- ncol(m)
    ntaxa <- length(obj$labels)
    for (i in 1:(n - 1))
        for (j in (i + 1):n)
            if (!arecompatible(m[, i], m[, j], ntaxa))
                return(FALSE)
    TRUE
}

arecompatible <-function(x, y, n)
{
    msk <- !as.raw(2^(8 - (n %% 8)) - 1)

    foo <- function(v) {
        lv <- length(v)
        v[lv] <- v[lv] & msk
        as.integer(all(v == as.raw(0)))
    }

    nE <- foo(x & y) + foo(x & !y) + foo(!x & y) + foo(!x & !y)
    nE >= 1
}