R/is.compatible.R

Defines functions arecompatible is.compatible.bitsplits is.compatible

Documented in arecompatible is.compatible is.compatible.bitsplits

## 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)
    if (nE >= 1) TRUE else FALSE
}

Try the ape package in your browser

Any scripts or data that you put into this service are public.

ape documentation built on March 31, 2023, 6:56 p.m.