Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding alternative tree metrics #8

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: treespace
Title: Statistical Exploration of Landscapes of Phylogenetic Trees
Date: 2019-12-05
Date: 2020-07-29
Version: 1.1.3.2
Authors@R: c(TJ = person("Thibaut", "Jombart", email="thibautjombart@gmail.com", role = "aut", comment = c(ORCID = "0000-0003-2226-8692")),
MK = person("Michelle", "Kendall", email="michelle.kendall@bdi.ox.ac.uk", role = c("aut", "cre"), comment = c(ORCID = "0000-0001-7344-7071")),
Expand All @@ -14,7 +14,7 @@ Description: Tools for the exploration of distributions of phylogenetic trees.
Depends: R (>= 3.4.0), ape, ade4
Imports: adegenet, adegraphics, adephylo, combinat, compiler, distory,
fields, htmlwidgets, MASS, methods, parallel, phangorn, phytools, Rcpp,
rgl, RLumShiny, scatterD3, shiny, shinyBS, utils
rgl, RLumShiny, scatterD3, shiny, shinyBS, TreeDist, utils
LinkingTo: Rcpp
Suggests: ggplot2, igraph, knitr, pander, RColorBrewer, reshape2,
rmarkdown, testthat
Expand All @@ -24,7 +24,8 @@ Collate: RcppExports.R metrics.R medTree.R treespace.R findGroves.R
plotGroves.R plotTreeDiff.R servers.R transmissionTrees.R
data.R makeCollapsedTree.R relatedTreeDist.R simulateIndTree.R
tipsMRCAdepths.R treeConcordance.R
RoxygenNote: 7.0.2
Encoding: UTF-8
RoxygenNote: 7.1.1
VignetteBuilder: knitr
URL: https://cran.r-project.org/package=treespace,
https://github.com/thibautjombart/treespace
Expand Down
4 changes: 4 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ import(shiny)
importFrom(MASS,Shepard)
importFrom(RLumShiny,jscolorInput)
importFrom(Rcpp,evalCpp)
importFrom(TreeDist,ClusteringInfoDistance)
importFrom(TreeDist,MatchingSplitDistance)
importFrom(TreeDist,MatchingSplitInfoDistance)
importFrom(TreeDist,PhylogeneticInfoDistance)
importFrom(ade4,cailliez)
importFrom(ade4,dudi.pco)
importFrom(ade4,is.euclid)
Expand Down
52 changes: 50 additions & 2 deletions R/treespace.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
#' \item \code{wRF} the weighted Robinson Foulds metric using \code{wRF.dist} from package \code{phangorn} (considers the trees unrooted)
#' \item \code{nNodes} the Steel & Penny tip-tip path difference metric, (topological, ignoring branch lengths), using \code{path.dist} from package \code{phangorn} (considers the trees unrooted)
#' \item \code{patristic} the Steel & Penny tip-tip path difference metric, using branch lengths, calling \code{path.dist} from package \code{phangorn} (considers the trees unrooted)
#' \item \code{CID} the clustering information difference metric, calling \code{ClusteringInformationDistance()} from package \pkg{TreeDist} (considers the trees unrooted)
#' \item \code{PID} the phylogenetic information difference metric, calling \code{PhylogeneticInformationDistance()} from package \pkg{TreeDist} (considers the trees unrooted)
#' \item \code{MS} the matching splits distance, calling \code{MatchingSplitsDistance()} from package \pkg{TreeDist} (considers the trees unrooted)
#' \item \code{MSID} the matching splits information difference metric, calling \code{ClusteringInformationDistance()} from package \pkg{TreeDist} (considers the trees unrooted)
#' \item \code{Abouheif}: performs Abouheif's test, inherited from \code{distTips} in \code{adephylo}. See Pavoine et al. (2008) and \code{adephylo}.
#' \item \code{sumDD}: sum of direct descendants of all nodes on the path, related to Abouheif's test, inherited from \code{distTips} in \code{adephylo}.
#' }
Expand All @@ -36,6 +40,8 @@
#' @importFrom phangorn RF.dist
#' @importFrom phangorn wRF.dist
#' @importFrom parallel mcmapply
#' @importFrom TreeDist ClusteringInfoDistance MatchingSplitDistance
#' MatchingSplitInfoDistance PhylogeneticInfoDistance
#'
#' @examples
#'
Expand All @@ -47,6 +53,15 @@
#' res <- treespace(x, nf=3)
#' table.paint(as.matrix(res$D))
#' scatter(res$pco)
#'
#' ## Consider trees rooted:
#' rootedtrees <- structure(lapply(x, function (tr){
#' tr$edge.length <- NULL
#' TreeTools::AddTip(tr, where=0)
#' }), class='multiPhylo')
#' rootedres <- treespace(rootedtrees,nf=3)
#' table.paint(as.matrix(rootedres$D))
#' scatter(rootedres$pco)
#'
#' data(woodmiceTrees)
#' woodmiceDists <- treespace(woodmiceTrees,nf=3)
Expand All @@ -67,6 +82,27 @@
#' }
#' }
#'
#' @encoding UTF-8
#' @references
#' Bogdanowicz D, Giaro K (2012). “Matching split distance for unrooted binary
#' phylogenetic trees.” IEEE/ACM Transactions on Computational Biology and
#' Bioinformatics, 9(1), 150–160. doi: 10.1109/TCBB.2011.48.
#'
#' Kendall M, Colijn C (2016). “Mapping phylogenetic trees to reveal distinct
#' patterns of evolution.” Molecular Biology and Evolution, 33(10), 2735--2743.
#' doi: 10.1093/molbev/msw124
#'
#' Robinson DF, Foulds LR (1981). “Comparison of phylogenetic trees.”
#' Mathematical Biosciences, 53(1-2), 131–147.
#' doi: 10.1016/0025-5564(81)90043-2.
#'
#' Smith MR (2020). “Information theoretic Generalized Robinson-Foulds metrics
#' for comparing phylogenetic trees.” Bioinformatics, in production.
#' doi: 10.1093/bioinformatics/btaa614.
#'
#' Steel, M. A., & Penny, D. (1993). Distributions of tree comparison
#' metrics—some new results. Systematic Biology, 42 (2), 126–141.
#' doi: 10.1093/sysbio/42.2.126
#'
#' @export
treespace <- function(x, method="treeVec", nf=NULL, lambda=0, return.tree.vectors=FALSE, processors=1, ...){
Expand Down Expand Up @@ -144,6 +180,18 @@ treespace <- function(x, method="treeVec", nf=NULL, lambda=0, return.tree.vector
D <- ade4::cailliez(D, print=FALSE)
}
}
else if (method == 'CID') {
D <- as.dist(ClusteringInfoDistance(x))
}
else if (method == 'PID') {
D <- as.dist(PhylogeneticInfoDistance(x))
}
else if (method == 'MS') {
D <- as.dist(MatchingSplitDistance(x))
}
else if (method == 'MSID') {
D <- as.dist(MatchingSplitInfoDistance(x))
}

## restore labels
attr(D,"Labels") <- lab
Expand All @@ -154,10 +202,10 @@ treespace <- function(x, method="treeVec", nf=NULL, lambda=0, return.tree.vector

## BUILD RESULT AND RETURN ##
if (return.tree.vectors==TRUE) {
out <- list(D=D, pco=pco, vectors=df)
out <- list(D=D, pco=pco, vectors=df)
}
else {
out <- list(D=D, pco=pco)
out <- list(D=D, pco=pco)
}
return(out)
} # end treespace
4 changes: 3 additions & 1 deletion man/DengueBEASTMCC.Rd

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

4 changes: 3 additions & 1 deletion man/DengueSeqs.Rd

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

4 changes: 3 additions & 1 deletion man/DengueTrees.Rd

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

4 changes: 3 additions & 1 deletion man/fluTrees.Rd

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

34 changes: 34 additions & 0 deletions man/treespace.Rd

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

4 changes: 3 additions & 1 deletion man/woodmiceTrees.Rd

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

2 changes: 1 addition & 1 deletion vignettes/tipCategories.Rmd
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: "Comparing trees by tip label categories"
title: "treespace worked example: comparing by tip categories"
author: "Michelle Kendall"
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
Expand Down