tree2mat: tree2mat

View source: R/tree2mat.r

tree2matR Documentation

tree2mat

Description

Transforms a phylogenetic tree into a dist object containing patristic distances between tips. Dists are just lower triangles of matrices, and the rows and columns of that matrix are defined by a user-supplied vector of tip labels, which can include duplicate values. Contrast with ape::cophenetic.phylo, which produces a distance matrix containing only unique pairwise patristic distances within the phylogeny.

Usage

tree2mat(tree, x, n_cores = 1)

Arguments

tree

phylo object. Tree containing all unique species in x as tips. May contain tips that are not in x.

x

character vector. Vector of species identities, each of which must be in tree as a tip label. May contain any given species identity more than once.

n_cores

integer. Number of CPU cores to use for parallel operations. Multithreading should only be used for large trees where x has low redundancy. If set to 1, sapply will be used instead of mclapply. A warning will be shown if n_cores > 1 on Windows, which does not support forked parallelism (default: 1).

Value

dist object, of vector length equal to (l^2-l)/2 where l is length(x); i.e. values are the lower triangle of a patristic distance matrix with rows=x and cols=x.

Author(s)

John L. Darcy

Examples

# library(specificity)
# library(ape)
# example_tree <- ape::read.tree(text=" ((((a:1,b:1):1,c:2):1,d:3):1,(e:1,f:1):3);")
# example_x <- c("a", "a", "a", "b", "c", "d", "c", "a", "f")
# # unique patristic distance matrix:
# ape::cophenetic.phylo(example_tree)
# # dist object for example_x:
# tree2mat(tree=example_tree, x=example_x)


darcyj/specificity documentation built on Aug. 1, 2023, 8 a.m.