Skip to content

Commit

Permalink
PairwiseQuartets()
Browse files Browse the repository at this point in the history
  • Loading branch information
ms609 committed Jan 16, 2025
1 parent 4066d50 commit f6f8293
Show file tree
Hide file tree
Showing 16 changed files with 159 additions and 7 deletions.
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package: Quartet
Version: 1.2.7
Version: 1.3.0
Title: Comparison of Phylogenetic Trees Using Quartet and Split Measures
Description: Calculates the number of four-taxon subtrees consistent with a pair
of cladograms, calculating the symmetric quartet distance of Bandelt & Dress
Expand Down Expand Up @@ -46,6 +46,7 @@ Suggests:
Rcpp,
rmarkdown,
testthat,
TreeDist,
usethis,
vdiffr,
Config/Needs/check:
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export(PairSharedQuartetStatus)
export(PairSharedSplitStatus)
export(PairsQuartetDistance)
export(PairsTripletDistance)
export(PairwiseQuartets)
export(PlotQuartet)
export(QuartetAgreement)
export(QuartetDistance)
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Quartet v1.3.0 (2025-01-16)

- `PairwiseQuartets()` compares quartet statuses between all pairs of trees.

# Quartet v1.2.7 (2024-10-31)

- `VizualizeQuartet()` now returns calculation results.
Expand Down
1 change: 1 addition & 0 deletions Quartet.Rproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Version: 1.0
ProjectId: 69de0ca2-bd58-49e4-8173-98d3d2d703f4

RestoreWorkspace: Yes
SaveWorkspace: No
Expand Down
40 changes: 40 additions & 0 deletions R/PairwiseQuartets.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#' Pairwise quartet distances
#'
#' Computes the quartet distance between each pair of trees in a list.
#'
#' @inheritParams QuartetStatus
#' @param Measure a function that calculates tree similarity or difference
#' from quartet statuses. Default is [`QuartetDivergence()`].
#' @return a matrix specifying the distance between each tree and
#' each other tree in the `trees`.
#'
#' @template MRS
#'
#' @examples
#' data("sq_trees")
#' # Calculate the status of each quartet relative to the first entry in
#' # sq_trees
#' sq_status <- QuartetStatus(sq_trees)
#'
#' # Calculate Estabrook et al's similarity measures:
#' SimilarityMetrics(sq_status)
#'
#' # Compare trees that include a subset of the taxa 1..10
#' library("TreeTools", quietly = TRUE, warn.conflict = FALSE)
#' QuartetStatus(BalancedTree(1:5), BalancedTree(3:8), nTip = 10)
#'
#' # If all taxa studied occur in `trees` or `cf`, set `nTip = TRUE`
#' QuartetStatus(BalancedTree(1:5), BalancedTree(3:10), nTip = TRUE)
#'
#' @family element-by-element comparisons
#' @seealso
#' - Use splits (groups/clades defined by nodes or edges of the tree) instead
#' of quartets as the unit of comparison: [`SplitStatus()`].
#'
#' - Generate distance metrics from quartet statuses: [`SimilarityMetrics()`].
#'
#' @references \insertAllCited{}
#' @export
PairwiseQuartets <- function(trees, Measure = QuartetDivergence) {
Measure(ManyToManyQuartetAgreement(trees))
}
7 changes: 4 additions & 3 deletions R/tqDist.r
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@
#' - Use splits (groups/clades defined by nodes or edges of the tree) instead
#' of quartets as the unit of comparison: [`SplitStatus()`].
#'
#' - Generate distance metrics from quartet statuses: [`SimilarityMetrics()`].
#' - Generate distance metrics from quartet statuses: [`SimilarityMetrics()`],
#' `[PairwiseQuartets()]`.
#'
#' @references \insertAllCited{}
#'
Expand Down Expand Up @@ -249,8 +250,8 @@ ManyToManyQuartetAgreement <- function (trees, nTip = NULL) {
}
}

#' @describeIn QuartetStatus Agreement of each quartet in trees in one list with
#' each quartet in trees in a second list.
#' @describeIn QuartetStatus Agreement of each quartet in trees in `trees1` with
#' each quartet in trees in `trees2`.
#' @param trees1,trees2 List or `multiPhylo` objects containing
#' trees of class `phylo`.
#' @return `TwoListQuartetAgreement()` returns a three-dimensional array listing,
Expand Down
1 change: 1 addition & 0 deletions man/CompareQuartets.Rd

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

1 change: 1 addition & 0 deletions man/CompareQuartetsMulti.Rd

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

1 change: 1 addition & 0 deletions man/CompareSplits.Rd

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

1 change: 1 addition & 0 deletions man/PairSharedQuartetStatus.Rd

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

63 changes: 63 additions & 0 deletions man/PairwiseQuartets.Rd

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

1 change: 1 addition & 0 deletions man/QuartetState.Rd

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

8 changes: 5 additions & 3 deletions man/QuartetStatus.Rd

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

1 change: 1 addition & 0 deletions man/SplitStatus.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-PairwiseQuartets.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
test_that("PairwiseQuartets() works", {
expect_equal(PairwiseQuartets(sq_trees),
QuartetDivergence(ManyToManyQuartetAgreement(sq_trees)))
expect_equal(PairwiseQuartets(sq_trees, DoNotConflict),
DoNotConflict(ManyToManyQuartetAgreement(sq_trees)))
})
27 changes: 27 additions & 0 deletions vignettes/Using-Quartet.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,33 @@ status <- TwoListQuartetAgreement(forest[1:4], forest[5:6])
QuartetDivergence(status, similarity = FALSE)
```

## Pairwise comparison

To compute distances between all pairs of trees in a list, use the `PairwiseQuartets()` function:

```{r allpairs}
PairwiseQuartets(forest)
# equivalent to QuartetDivergence(ManyToManyQuartetAgreement(forest))
```

This function can help to summarise sets of trees:

```{r treedist}
# Map distances between trees
forestDist <- PairwiseQuartets(forest)
mapping <- cmdscale(as.dist(forestDist))
plot(mapping, asp = 1, axes = FALSE, frame.plot = FALSE,
xlab = "", ylab = "", col = seq_along(forest), type = "n")
text(mapping, names(forest))
# The TreeDist library is used to compute the median tree
if (requireNamespace("TreeDist", quietly = TRUE)) {
library("TreeDist")
# Plot the median tree:
plot(median(forest, distance = PairwiseQuartets))
}
```

## Trees with different tip labels

"Quartet" can compare trees of different sizes or with non-identical sets of
Expand Down

0 comments on commit f6f8293

Please sign in to comment.