Difference between revisions of "Phylogenetics: APE Lab"

From EEBedia
Jump to: navigation, search
Line 51: Line 51:
 
Black edges are the default. If you specify several edge colors, APE will alternate them as it draws the tree:
 
Black edges are the default. If you specify several edge colors, APE will alternate them as it draws the tree:
 
  > plot(t, edge.color=c("black","red","green","blue"))
 
  > plot(t, edge.color=c("black","red","green","blue"))
 +
 +
==== Make taxon labels smaller or larger ====
 +
> plot(t, cex=0.5)
 +
The cex parameter governs relative scaling of the taxon labels, with 1.0 being the default. Thus, the command above makes the taxon labels half the default size. To double the size, use
 +
> plot(t, cex=2.0)
 +
 +
==== Plot tree as an unrooted or radial tree ====
 +
> plot(t, type="u")
 +
The default type is "p" (phylogram), but "c" (cladogram), "u" (unrooted), "r" (radial) are other options. Some of these options (e.g. "r") create very funky looking trees, leading me to think there is something about the tree description in the file <tt>yule.tre</tt> that APE is not expecting.
 +
 +
==== Labeling internal nodes ====
 +
> plot(t)
 +
> nodelabels()
 +
This is primarily useful if you want to annotate one of the nodes:
 +
> plot(t)
 +
> nodelabels("Clade A", 22)
 +
> nodelabels("Clade B", 35)
 +
To put the labels inside a circle rather than a rectangle, use <tt>frame="c"</tt> rather than the default (<tt>frame="r"</tt>). To use a background color of white rather than the default "lightblue", use <tt>bg="white"</tt>:
 +
> plot(t)
 +
> nodelabels("Clade A", 22, frame="c", bg="white")
 +
> nodelabels("Clade B", 35, frame="c", bg="yellow")
 +
 +
==== Adding a scale bar ====
 +
> plot(t)
 +
> add.scale.bar(length=0.05)
 +
The above commands add a scale bar to the bottom left of the plot. To add a scale going all the way across the bottom of the plot, try this:
 +
> plot(t)
 +
> axisPhylo()
 +
  
 
== Literature Cited ==
 
== Literature Cited ==

Revision as of 01:38, 29 April 2009

Adiantum.png EEB 349: Phylogenetics
This lab is an introduction to some of the capabilities of APE, a phylogenetic analysis package written for the R language. You may want to review the R Primer lab if you've already forgotten everything you learned about R.

Installing APE and apTreeshape

APE is a package largely written and maintained by Emmanuel Paradis, who has written a very nice book[1] explaining in detail how to use APE. APE is designed to be used inside the R programming language, to which you were introduced earlier in the semester (see Phylogenetics: R Primer). apTreeshape is a different R package (written by Nicolas Bortolussi et al.) that we will use today.

To install APE and apTreeshape, start R and type the following at the R command prompt:

> install.packages("ape")
> install.packages("apTreeshape")

Assuming you are connected to the internet, R should locate these packages and install them for you. After they are installed, you will need to load them into R in order to use them (note that no quotes are used this time):

> library(ape)
> library(apTreeshape)

You should never again need to issue the install.packages command for APE and apTreeshape, but you will need to use the library command to load them whenever you want to use them.

Reading in trees from a file

Download this tree file and save it as a file named yule.tre in a new folder somewhere on your computer. Tell R where this folder is using the setwd (set working directory) command. For example, I created a folder named apelab on my desktop, so I typed this to make that folder my working directory:

> setwd("/Users/plewis/Desktop/apelab")

Now you should be able to read in the tree using this ape command:

> t <- read.nexus("yule.tre")

You can plot the tree using this ape command:

> plot(t)

This tree in the file yule.tre was obtained using PAUP from 10,000 nucleotide sites simulated in Phycas from a Yule tree (which was also generated by Phycas). The model used to generated the simulated data (HKY model, kappa = 4, base frequencies = 0.3 A, 0.2 C, 0.2 G, and 0.3 T, no rate heterogeneity) was also used in the analysis by PAUP (the final ML tree was made ultrametric by enforcing the clock constraint). I analyzed this data in BEAST for part of a lecture. See this PDF file for details.

Fun with plotting trees in APE

Let's try changing a few defaults and plot the tree in a variety of ways. All of the following change just one default option, but feel free to combine these to create the plot you want.

Left-facing, up-facing, or down-facing trees

> plot(t, direction="l")
> plot(t, direction="u")
> plot(t, direction="d")

The default is to plot the tree right-facing (direction="r").

Hide the taxon names

> plot(t, show.tip.label=FALSE)

The default behavior is to show the taxon names.

Make the edges thicker

> plot(t, edge.width=4)

An edge width of 1 is the default. If you specify several edge widths, APE will alternate them as it draws the tree:

> plot(t, edge.width=c(1,2,3,4))

Color the edges

> plot(t, edge.color="red")

Black edges are the default. If you specify several edge colors, APE will alternate them as it draws the tree:

> plot(t, edge.color=c("black","red","green","blue"))

Make taxon labels smaller or larger

> plot(t, cex=0.5)

The cex parameter governs relative scaling of the taxon labels, with 1.0 being the default. Thus, the command above makes the taxon labels half the default size. To double the size, use

> plot(t, cex=2.0)

Plot tree as an unrooted or radial tree

> plot(t, type="u")

The default type is "p" (phylogram), but "c" (cladogram), "u" (unrooted), "r" (radial) are other options. Some of these options (e.g. "r") create very funky looking trees, leading me to think there is something about the tree description in the file yule.tre that APE is not expecting.

Labeling internal nodes

> plot(t)
> nodelabels()

This is primarily useful if you want to annotate one of the nodes:

> plot(t)
> nodelabels("Clade A", 22)
> nodelabels("Clade B", 35)

To put the labels inside a circle rather than a rectangle, use frame="c" rather than the default (frame="r"). To use a background color of white rather than the default "lightblue", use bg="white":

> plot(t)
> nodelabels("Clade A", 22, frame="c", bg="white")
> nodelabels("Clade B", 35, frame="c", bg="yellow")

Adding a scale bar

> plot(t)
> add.scale.bar(length=0.05)

The above commands add a scale bar to the bottom left of the plot. To add a scale going all the way across the bottom of the plot, try this:

> plot(t)
> axisPhylo()


Literature Cited

  1. Paradis, E. 2006. Analysis of phylogenetics and evolution with R. Springer. ISBN: 0-387-32914-5