From 5cbff387ee39cd855f7e7dbc34d5c480c0d72860 Mon Sep 17 00:00:00 2001 From: "Martin R. Smith" <1695515+ms609@users.noreply.github.com> Date: Thu, 29 Feb 2024 07:58:16 +0000 Subject: [PATCH] KCDiameter.multiPhylo() (#114) --- DESCRIPTION | 2 +- NEWS.md | 5 ++++- R/parallel.R | 2 +- R/tree_distance_kendall-colijn.R | 10 ++++++---- man/KendallColijn.Rd | 2 +- man/StartParallel.Rd | 2 +- tests/testthat/test-tree_distance_kc.R | 6 ++++++ 7 files changed, 20 insertions(+), 9 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index b4790f17c..da45e9d3f 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: TreeDist Type: Package Title: Calculate and Map Distances Between Phylogenetic Trees -Version: 2.7.0.9000 +Version: 2.7.0.9001 Authors@R: c(person("Martin R.", "Smith", email = "martin.smith@durham.ac.uk", role = c("aut", "cre", "cph", "prg"), diff --git a/NEWS.md b/NEWS.md index 81ffcde89..bbce4f2c4 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,7 +1,10 @@ -# TreeDist 2.7.0.9000 (development) +# TreeDist 2.7.0.9001 (development) - Fix dead links in documentation +- Fix `KCDiameter.multiPhylo()` for multiple trees. + + # TreeDist 2.7.0 (2023-10-25) - Fix calculation error in `StrainCol()`. diff --git a/R/parallel.R b/R/parallel.R index 541172194..1e86e1ee1 100644 --- a/R/parallel.R +++ b/R/parallel.R @@ -21,7 +21,7 @@ #' @examples #' if (interactive()) { # Only run in terminal #' library("TreeTools", quietly = TRUE) -#' nCores <- ceiling(detectCores() / 2) +#' nCores <- ceiling(parallel::detectCores() / 2) #' StartParallel(nCores) # Takes a few seconds to set up processes #' GetParallel() #' ClusteringInfoDistance(as.phylo(0:6, 100)) diff --git a/R/tree_distance_kendall-colijn.R b/R/tree_distance_kendall-colijn.R index d88724941..3657c0828 100644 --- a/R/tree_distance_kendall-colijn.R +++ b/R/tree_distance_kendall-colijn.R @@ -214,8 +214,8 @@ SplitVector <- function(tree) { #' metric. #' #' @examples -#' KCDiameter(trees) #' KCDiameter(4) +#' KCDiameter(trees) #' @importFrom TreeTools PectinateTree #' @rdname KendallColijn #' @export @@ -237,10 +237,12 @@ KCDiameter.numeric <- function(tree) { Euclid(nTip - mat[lower.tri(mat)] + 1L, t(mat)[lower.tri(mat)]) } -#' @export -KCDiameter.multiPhylo <- KCDiameter.phylo - #' @export KCDiameter.list <- function(tree) { lapply(tree, KCDiameter) } + +#' @export +KCDiameter.multiPhylo <- function(tree) { + vapply(tree, KCDiameter, double(1)) +} \ No newline at end of file diff --git a/man/KendallColijn.Rd b/man/KendallColijn.Rd index cbea16de3..dbf9cb956 100644 --- a/man/KendallColijn.Rd +++ b/man/KendallColijn.Rd @@ -113,8 +113,8 @@ tree3 <- ape::read.tree(text = "(a, (b, (c, (d, (e, ((f, g), h))))));") trees <- c(tree1, tree2, tree3) KendallColijn(trees) KendallColijn(trees, Vector = SplitVector) -KCDiameter(trees) KCDiameter(4) +KCDiameter(trees) } \references{ \insertAllCited{} diff --git a/man/StartParallel.Rd b/man/StartParallel.Rd index f52611992..71d5efc88 100644 --- a/man/StartParallel.Rd +++ b/man/StartParallel.Rd @@ -50,7 +50,7 @@ cluster. \examples{ if (interactive()) { # Only run in terminal library("TreeTools", quietly = TRUE) - nCores <- ceiling(detectCores() / 2) + nCores <- ceiling(parallel::detectCores() / 2) StartParallel(nCores) # Takes a few seconds to set up processes GetParallel() ClusteringInfoDistance(as.phylo(0:6, 100)) diff --git a/tests/testthat/test-tree_distance_kc.R b/tests/testthat/test-tree_distance_kc.R index 3f055b594..30063673f 100644 --- a/tests/testthat/test-tree_distance_kc.R +++ b/tests/testthat/test-tree_distance_kc.R @@ -44,4 +44,10 @@ test_that("KCDiameter() calculated", { } Test(4) Test(40) + tree1 <- ape::read.tree(text = "(a, (b, (c, (d, (e, (f, (g, h)))))));") + tree2 <- ape::read.tree(text = "(a, ((b, c), (d, (e, (f, (g, h))))));") + tree3 <- ape::read.tree(text = "(a, (b, (c, (d, (e, (f, g))))));") + trees <- c(tree1, tree2, tree3) + expect_equal(KCDiameter(trees), + c(KCDiameter(tree1), KCDiameter(tree2), KCDiameter(tree3))) })