TreeMan-class

Share:

Description

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

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
## S4 method for signature 'TreeMan,character'
x[[i]]

## S4 method for signature 'TreeMan,character'
x[i]

## S4 method for signature 'TreeMan'
as.character(x)

## S4 method for signature 'TreeMan'
show(object)

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

## S4 method for signature 'TreeMan'
print(x)

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

Arguments

x

TreeMan object

i

node ID or slot name

object

TreeMan object

max.level

str() maximum number of levels to show

...

additional tree objects

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: IDs of the preceding nodes to the root

  • ptid: IDs of the immediately connecting nodes

  • kids: descending tip IDs

  • pd: phylogenetic diversity represented by node

  • prdst: pre distance(distance to root if rooted or most distal tip if unrooted)

These data slots are updated whenever a node is modified, added or removed.

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

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

age

numeric of max root to tip distance

pd

numeric of total branch length of tree

ext

vector of node ids of all tips with 0 age

exc

vector of node ids of all tips with age > 0

wspn

logical, do nodes have spans

ultr

logical, do all tips end at 0

ply

logical, is tree bifurcating

tol

numeric of tolerance for determining extant

root

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

See Also

randTree, Node-class, viz

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
library(treeman)
# Generate random tree
tree <- randTree(10)
# Print to get basic stats
print(tree)
# Currently available methods
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['age']  # return age of tree
tree['ultr']  # is ultrametric?
tree['ply']  # is polytomous?
tree['ext']  # return all extant tip IDs
tree['exc']  # return all extinct tip IDs
tree <- setTol(tree, 10)  # reset tolerance, default 1e-8
# now tol is higher more tips will be classed as extant
tree['ext']
# Because all nodes are lists with metadata we can readily
#  get specific information on nodes of interest
nd <- tree[['n2']]
print(nd)
# And then use the same syntax for the tree
nd['age']  # .... nkids, pd, etc.

Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker.