This code through explores [ape], a useful package for building and analyzing phylogenetic trees.
Specifically, we’ll explore how you can use [ape] to generate, save, and label trees. We’ll also take a peek at some of the analysis that can be done with this package!
Phylogenetic trees, as a concept, are a useful way for biologists and
geneticists to analyze the (often complex) relationships between
different species. They help us to identify how and when related species
split off from a common ancestor, and how much genetic change has taken
place since then. Historically, this has involved a lot of math!
Although the examples shown here are fairly basic, [ape] is a powerful
package that allows us to simplify the math involved and reduce the
potential for human error. The package can be downloaded from CRAN.
Specifically, you’ll learn how to: * Generate a random phylogenetic tree * Save a phylogenetic tree as a variable * Name the tips (i.e., species) on your tree * Anchor your tree with an outgroup * Use R to calculate the evolutionary distances between the groups on your tree
Here, we’ll show you how to get started with creating and customizing your own phylogenetic trees for basic analysis.
A basic example shows how you can use [ape] to generate and plot a random tree:
##
## Phylogenetic tree with 10 tips and 9 internal nodes.
##
## Tip labels:
## t6, t9, t3, t1, t4, t10, ...
##
## Rooted; includes branch length(s).
Or, you can save a tree as a variable:
##
## Phylogenetic tree with 6 tips and 5 internal nodes.
##
## Tip labels:
## t3, t4, t5, t1, t2, t6
##
## Rooted; includes branch length(s).
It’s fun to generate phylogenetic trees, but how does that actually help us? Well, once you’ve built your tree, you can name the labels…
tree$tip.label <- c(
"Tiger",
"Lion",
"Leopard",
"Jaguar",
"Snow Leopard",
"Domestic Cat"
)
plot(tree)Except, this isn’t exactly right – domestic cats are not as closely related to snow leopards & jaguars as this tree would make it seem! Fortunately, you can pick a species to serve as the root:
Once you have your tree properly labeled, you can use this package to analyze your data. For example, cophenetic() allows you to calculate the evolutionary distances between species:
kitty.distance <- cophenetic(tree.root)
# This returns the evolutionary distances between each species, gridded as a matrix.
kitty.distance## Tiger Lion Leopard Jaguar Snow Leopard Domestic Cat
## Tiger 0.0000000 0.9278898 0.7216671 1.179288 1.670499 0.2071812
## Lion 0.9278898 0.0000000 0.9813620 1.702746 2.193958 1.0066087
## Leopard 0.7216671 0.9813620 0.0000000 1.496524 1.987735 0.8003860
## Jaguar 1.1792879 1.7027465 1.4965238 0.000000 1.286084 1.2580068
## Snow Leopard 1.6704994 2.1939580 1.9877353 1.286084 0.000000 1.7492183
## Domestic Cat 0.2071812 1.0066087 0.8003860 1.258007 1.749218 0.0000000
Learn more about [ape] with the following:
GitHub guide to using [ape]: Practical: Introduction to Phylogenetics in R
Bioinformatics journal on the [ape] package: APE: Analyses of Phylogenetics and Evolution in R language
Download the package at CRAN: package ape
This code through references and cites the following sources:
Khan Academy (n.d.). Phylogeny. Phylogeny (article)
UC Berkeley Museum of Paleontology (n.d.). Understanding Evolution. Evo 101