combine_brts_and_topology: Substitute branching times keeping the topology

View source: R/combine_brts_and_topology.R

combine_brts_and_topologyR Documentation

Substitute branching times keeping the topology

Description

Set the branching times (in time units before the present) of a phylogeny, while preserving its topology.

Usage

combine_brts_and_topology(brts, tree)

Arguments

brts

numeric vector of (all postive) branching times, in time units before the present. Assuming no stem, the heighest value equals the crown age.

tree

an ultrametric phylogenetic tree of class phylo

Value

a phylogeny of class phylo

Author(s)

Giovanni Laudanno, David Bapst, Richèl J.C. Bilderbeek

Examples

# Branching times as 3 (crown age) and 2 (branch of A and B) time units ago
phylogeny <- ape::read.tree(text = "((A:2, B:2):1, C:3);")
# Branching times will be c(3, 2)
as.numeric(ape::branching.times(phylogeny))
# Will be 2
ape::dist.nodes(phylogeny)[1, ape::getMRCA(phylogeny, c("A", "B"))]

# Create a new phylogeny with the same topology, but with
# branching times at 5 (crown age) and 4 (branch of A and B) time units ago
new_phylogeny <- combine_brts_and_topology(
  brts = c(5, 4),
  tree = phylogeny
)
# Will be c(5, 4)
as.numeric(ape::branching.times(new_phylogeny))
# Will be 4
ape::dist.nodes(new_phylogeny)[
    1, ape::getMRCA(new_phylogeny, c("A", "B"))
]

richelbilderbeek/pirouette documentation built on Oct. 18, 2023, 3:09 p.m.