ReadCharacters {TreeTools}R Documentation

Read phylogenetic characters from file

Description

Parse a Nexus (Maddison et al. 1997) or TNT (Goloboff et al. 2008) file, reading character states and names.

Usage

ReadCharacters(filepath, character_num = NULL, encoding = "UTF8")

ReadTntCharacters(
  filepath,
  character_num = NULL,
  type = NULL,
  encoding = "UTF8"
)

ReadNotes(filepath, encoding = "UTF8")

ReadAsPhyDat(...)

ReadTntAsPhyDat(...)

PhyDat(dataset)

Arguments

filepath

character string specifying location of file, or a connection to the file.

character_num

Index of character(s) to return. NULL, the default, returns all characters.

encoding

Character encoding of input file.

type

Character vector specifying categories of data to extract from file. Setting type = c("num", "dna") will return only characters following a ⁠&[num]⁠ or ⁠&[dna]⁠ tag in a TNT input file, listing num character blocks before dna characters. Leave as NULL (the default) to return all characters in their original sequence.

...

Parameters to pass to ⁠Read[Tnt]Characters()⁠.

dataset

list of taxa and characters, in the format produced by read.nexus.data(): a list of sequences each made of a single character vector, and named with the taxon name.

Details

Tested with matrices downloaded from MorphoBank (O’Leary and Kaufman 2011), but should also work more widely; please report incompletely or incorrectly parsed files.

Matrices must contain only continuous or only discrete characters; maximum one matrix per file. Continuous characters will be read as strings (i.e. base type "character").

The encoding of an input file will be automatically determined by R. Errors pertaining to an ⁠invalid multibyte string⁠ or ⁠string invalid at that locale⁠ indicate that R has failed to detect the appropriate encoding. Either re-save the file in a supported encoding (UTF-8 is a good choice) or specify the file encoding (which you can find by, for example, opening in Notepad++ and identifying the highlighted option in the "Encoding" menu) following the example below.

Value

ReadCharacters() and ReadTNTCharacters() return a matrix whose row names correspond to tip labels, and column names correspond to character labels, with the attribute state.labels listing the state labels for each character; or a list of length one containing a character string explaining why the function call was unsuccessful.

ReadAsPhyDat() and ReadTntAsPhyDat() return a phyDat object.

ReadNotes() returns a list in which each entry corresponds to a single character, and itself contains a list of with two elements:

  1. A single character object listing any notes associated with the character

  2. A named character vector listing the notes associated with each taxon for that character, named with the names of each note-bearing taxon.

Functions

Author(s)

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

References

Goloboff PA, Farris JS, Nixon KC (2008). “TNT, a free program for phylogenetic analysis.” Cladistics, 24(5), 774–786.

Maddison DR, Swofford DL, Maddison WP (1997). “Nexus: an extensible file format for systematic information.” Systematic Biology, 46, 590–621. doi:10.1093/sysbio/46.4.590.

O’Leary MA, Kaufman S (2011). “MorphoBank: phylophenomics in the "cloud".” Cladistics, 27(5), 529–537.

See Also

Examples

fileName <- paste0(system.file(package = "TreeTools"),
                   "/extdata/input/dataset.nex")
ReadCharacters(fileName)

fileName <- paste0(system.file(package = "TreeTools"),
                   "/extdata/tests/continuous.nex")

continuous <- ReadCharacters(fileName, encoding = "UTF8")

# To convert from strings to numbers:
at <- attributes(continuous)
continuous <- suppressWarnings(as.numeric(continuous))
attributes(continuous) <- at
continuous

[Package TreeTools version 1.12.0 Index]