Learn R Programming

treeman (version 1.1.4)

TreeMan-class: TreeMan-class

Description

S4 class for representing phylogenetic trees as a list of nodes.

Usage

# S4 method for TreeMan,character
[[(x, i)

# S4 method for TreeMan,character,missing,missing [(x, i, j, ..., drop = TRUE)

# S4 method for TreeMan as.character(x)

# S4 method for TreeMan show(object)

# S4 method for TreeMan print(x)

# S4 method for TreeMan str(object, max.level = 2L, ...)

# S4 method for TreeMan summary(object)

# S4 method for TreeMan cTrees(x, ...)

Arguments

x

TreeMan object

i

node ID or slot name

j

missing

...

additional tree objects

drop

missing

object

TreeMan object

max.level

str() maximum number of levels to show

Slots

ndlst

list of nodes

nds

vector of node ids that are internal nodes

nnds

numeric of number of internal nodes in tree

tips

vector of node ids that are tips

ntips

numeric of number of internal nodes in tree

all

vector of all node ids

nall

numeric of number of all nodes in tree

pd

numeric of total branch length of tree

tinds

indexes of all tip nodes in tree

prinds

indexes of all pre-nodes in tree

wspn

logical, do nodes have spans

wtxnyms

logical, do nodes have txnyms

ply

logical, is tree bifurcating

root

character of node id of root, if no root then empty character

updtd

logical, if tree slots have been updated since initiation or change

othr_slt_nms

vector, character list of additional data slots added to nodes

ndmtrx

matrix, T/Fs representing tree structure

Details

A TreeMan object holds a list of nodes. The idea of the TreeMan class is to make adding and removing nodes as similar as possible to adding and removing elements in a list. Note that internal nodes and tips are both considered nodes. Trees can be polytomous but not unrooted.

Each node within the TreeMan ndlst contains the following data slots:

  • id: character string for the node ID

  • txnym: name of taxonomic clade (optional)

  • spn: length of the preceding branch

  • prid: ID of the immediately preceding node, NULL if root

  • ptid: IDs of the immediately connecting nodes

See below in 'Examples' for these methods in use.

See Also

randTree, Node-class, phylo-to-TreeMan, TreeMan-to-phylo

Examples

Run this code
# NOT RUN {
library(treeman)
# Generate random tree
tree <- randTree(10)
# Print to get basic stats
summary(tree)
# Slots....
tree['tips']   # return all tips IDs
tree['nds']    # return all internal node IDs
tree['ntips']  # count all tips
tree['nnds']   # count all internal nodes
tree['root']   # identify root node
tree[['t1']]   # return t1 node object
tree['pd']     # return phylogenetic diversity
tree['ply']    # is polytomous?
# Additional special slots (calculated upon call)
tree['age']   # get tree's age
tree['ultr']  # determine if tree is ultrametric
tree['spns']  # get all the spans of the tree IDs
tree['prids'] # get all the IDs of preceding nodes
tree['ptids'] # get all the IDs of following nodes
tree['txnyms'] # get all the taxonyms of all nodes
# In addition [] can be used for any user-defined slot
# Because all nodes are lists with metadata we can readily
#  get specific information on nodes of interest
nd <- tree[['n2']]
summary(nd)
# And then use the same syntax for the tree
nd['nkids']  # .... nkids, pd, etc.

# Convert to phylo and plot
library(ape)
tree <- as(tree, 'phylo')
plot(tree)
# }

Run the code above in your browser using DataLab