MatrixToPhyDat: Convert between matrices and 'phyDat' objects

View source: R/parse_files.R

MatrixToPhyDatR Documentation

Convert between matrices and phyDat objects

Description

MatrixToPhyDat() converts a matrix of tokens to a phyDat object; PhyDatToMatrix() converts a phyDat object to a matrix of tokens.

Usage

MatrixToPhyDat(tokens)

PhyDatToMatrix(
  dataset,
  ambigNA = FALSE,
  inappNA = ambigNA,
  parentheses = c("{", "}"),
  sep = ""
)

Arguments

tokens

Matrix of tokens, possibly created with ReadCharacters() or ReadTntCharacters(). Row names should correspond to leaf labels; column names may optionally correspond to character labels.

dataset

A dataset of class phyDat.

ambigNA, inappNA

Logical specifying whether to denote ambiguous / inapplicable characters as NA values.

parentheses

Character vector specifying style of parentheses with which to enclose ambiguous characters. c("[", "]") or "[]" will render ⁠[01]⁠. NULL will use the token specified in the phyDat object; but beware that this will be treated as a distinct (non-ambiguous) token if re-encoding with PhyDatToMatrix().

sep

Character with which to separate ambiguous tokens, e.g. ',' will render ⁠[0,1]⁠.

Value

MatrixToPhyDat() returns an object of class phyDat.

PhyDatToMatrix() returns a matrix corresponding to the uncompressed character states within a phyDat object.

Author(s)

Martin R. Smith (martin.smith@durham.ac.uk)

See Also

Other phylogenetic matrix conversion functions: StringToPhyDat()

Examples

tokens <- matrix(c(0, 0, "0", 0, 0,
                   0, 0, "1", 0, 1,
                   0, 0, "1", 0, 1,
                   0, 0, "2", 0, 1,
                   1, 1, "-", 1, 0,
                   1, 1, "2", 1, "{01}"),
                   nrow = 6, ncol = 5, byrow = TRUE,
                   dimnames = list(
                     paste0("Taxon_", LETTERS[1:6]),
                     paste0("Char_", 1:5)))
                   
MatrixToPhyDat(tokens)
data("Lobo", package = "TreeTools")
head(PhyDatToMatrix(Lobo.phy)[, 91:93])

TreeTools documentation built on Sept. 11, 2024, 8:27 p.m.