Skip to content
Dom Bennett edited this page Oct 2, 2017 · 13 revisions

The TreeMan object comprises a list containing all the nodes in a tree. It also has additional key statistics or data slots that can be accessed using [] or [[]] and the character string of whatever you want: tips, nodes, phylogenetic diversity etc. To get an idea of how this works, we can generate a small tree using the randTree() function.

library(treeman)
# Generate random tree
tree <- randTree(10)
# Use summary to get basic stats
summary(tree)

Now we have a tree, we can then use it to access a range of different information.

tree['tips']   # return all tips IDs
tree['nds']    # return all internal node IDs
tree['all']    # return boths tips and nodes
tree['ntips']  # count all tips
tree['nnds']   # count all internal nodes
tree['root']   # identify root node
tree['pd']     # return phylogenetic diversity
tree['ply']    # is polytomous?
tree['ultr']   # is ultrametric?
tree['age']    # return tree age
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 to the above slots, a user can also define their own slots and extract them using [].

We can also use it to investigate nodes individually using the [[]]. To do this, however, we need to know the ID of the node we're interested in.

# list internal nodes
(tree['nds'])
node <- tree[['n2']]
(node)

The returned Node object also has a similar functionality to the tree; we can access information again using [].

node['age']
node['id']
node['spn']
node['prid']
node['ptid']
node['kids']
node['nkids']
node['txnym']
node['pd']
node['prdst']
node['root']
node['tip']

These sets of methods make navigating the tree quite easy, particularly for a taxonomically 'informed' tree like the mammalian supertree that comes with the package. This example tree demonstrates how txnyms or taxonyms can be added to nodes in a tree to give the tree a taxonomic backbone. This is useful for exploring the tree but also enables makes the extraction from a tree of a particular clade easier (see getSubtree()) or it can be used as a basis to add new tips (see pinTips()).

# get mammal supertree
data(mammals)
# print basic info
summary(mammals)
# look up H. sapiens
mammals[['Homo_sapiens']]
# look-up the prid, i.e. the parent node
mammals[['n2939']]
mammals[['n2940']]
mammals[['n2942']]
mammals[['n2961']]
# ... look up the tree to find all apes (Hominoidea)
mammals[['n2962']]
# and extract an ape tree
apes <- getSubtree(mammals, id='n2962')
summary(apes)

When using the [ or [[ treeman tries to be forgiving. It will suggest what you might be looking for.

mammals[['Hmo_sapiens']]
mammals['Homo_sapiens']

Next page: Reading and writing

Clone this wiki locally