Skip to content

Commit

Permalink
Added ultr to treeman
Browse files Browse the repository at this point in the history
  • Loading branch information
DomBennett committed Jun 13, 2017
1 parent 94ae8aa commit 65ea37c
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 6 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Expand Up @@ -48,6 +48,7 @@ export(getSpnsAge)
export(getSubtree)
export(getTxnyms)
export(getUnqNds)
export(isUltrmtrc)
export(loadTreeMan)
export(pinTips)
export(pstMnp)
Expand Down
27 changes: 25 additions & 2 deletions R/get-spcl-methods.R
@@ -1,4 +1,27 @@

# ULTRAMETRIC
#' @name isUltrmtrc
#' @title Is tree ultrametric?
#' @description Return TRUE if all tips end at 0, else FALSE.
#' @details Returns a boolean. This function works in the background
#' for the \code{['ultr']} slot in a \code{TreeMan} object.
#' @param tree \code{TreeMan} object
#' @param tol zero tolerance
#' @seealso
#' \code{\link{getLvng}}, \code{\link{getDcsd}}
#' @export
#' @examples
#' library(treeman)
#' tree <- randTree(10)
#' (isUltrmtrc(tree))
isUltrmtrc <- function(tree, tol=1e-8) {
dead <- .livingOrDesceased(tree, tol=tol, bool=FALSE)
if(length(dead) > 0) {
return(FALSE)
}
TRUE
}

# EXTINCT/EXTANT
.livingOrDesceased <- function(tree, tol=1e-8, bool) {
if(!is.null(tree@ndmtrx)) {
Expand Down Expand Up @@ -29,7 +52,7 @@
#' @param tree \code{TreeMan} object
#' @param tol zero tolerance
#' @seealso
#' \code{\link{getLvng}},
#' \code{\link{getLvng}}, \code{\link{isUltrmtrc}},
#' \url{https://github.com/DomBennett/treeman/wiki/get-methods}
#' @export
#' @examples
Expand All @@ -47,7 +70,7 @@ getDcsd <- function(tree, tol=1e-8) {
#' @param tree \code{TreeMan} object
#' @param tol zero tolerance
#' @seealso
#' \code{\link{getDcsd}},
#' \code{\link{getDcsd}}, \code{\link{isUltrmtrc}},
#' \url{https://github.com/DomBennett/treeman/wiki/get-methods}
#' @export
#' @examples
Expand Down
10 changes: 8 additions & 2 deletions R/treeman-declaration.R
Expand Up @@ -130,9 +130,15 @@ setMethod('[', c('TreeMan', 'character'),
slt_nms <- slt_nms[slt_nms != 'ndmtrx']
slt_nms <- slt_nms[slt_nms != 'tinds']
slt_nms <- slt_nms[slt_nms != 'prinds']
# ultr is special, shouldn't be updated when updateSlts()
# too slow to calculate. Instead only calc if called.
if(i == 'ultr') {
return(isUltrmtrc(tree))
}
if(!i %in% slt_nms) {
slt_nms <- paste0(slt_nms, collapse=', ')
stop(paste0('`', i, '` not a tree slot. Available slots: ', slt_nms))
slt_nms <- paste0(c(slt_nms, 'ultr'), collapse=', ')
stop(paste0('`', i, '` not a tree slot. Available slots: ',
slt_nms))
}
slot(x, i)
})
Expand Down
2 changes: 1 addition & 1 deletion man/getDcsd.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/getLvng.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions man/isUltrmtrc.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions tests/testthat/test-get-spcl-methods.R
Expand Up @@ -4,6 +4,12 @@ library(testthat)

# RUNNING
context('Testing \'get-spcl-methods\'')
test_that('isUltrmtrc() works',{
tree <- randTree(10, wndmtrx=sample(c(TRUE, FALSE), 1))
expect_false(isUltrmtrc(tree))
tree <- ultrTree(tree)
expect_true(isUltrmtrc(tree))
})
test_that('getDcsd() works', {
tree <- randTree(10, wndmtrx=sample(c(TRUE, FALSE), 1))
dead <- getDcsd(tree)
Expand Down

0 comments on commit 65ea37c

Please sign in to comment.