- How do I know which version of ape I am using?
In R, type:
library(help = ape)
In many cases, a problem can be solved by updating ape and R.
- Why don't you develop a GUI for ape?
There are at least three good reasons:
- Developing a GUI is a lot work, and its maintenance and evolution is far from being straightforward.
- Writing scripts of commands helps the users to see the logical integration of their analyses.
- Repeating commands is almost always needed.
- I posted a query about ape on the r-help mailing list, but got no answer.
The r-help mailing list is for general questions about R; ape is a specialized package (there are more than 4000 on CRAN), so you are not likely to find your answers there. If needed, you can contact the Authors of the functions you are using.
- What tree file formats are supported by ape?
ape can read and write trees in Newick and Nexus formats with its functions read.tree, write.tree, read.nexus, and write.nexus. There are a few restrictions with respect to the Newick format definition (see below). Note also the function read.caic to read trees in the specific format of the CAIC program.
- I have a tree file in Newick format where the taxa names are quoted because they contain special characters (parentheses, comma, ...): is that a problem?
Yes. At the moment, ape can read quotes in taxa names but characters within them are treated as potentially belonging to the tree structure. Note that these special characters can be used freely in R, but write.tree substitute them. These restrictions may change in the future.
(Most cases reported were not consistent as some labels were quoted whereas others were not. So it is not clear what should be expected.)
- I have a tree file in Newick format with some comments within straight brackets: is that a problem?
Yes. These are simply ignored at the moment (i.e., treated as normal characters), but comments may be inserted in the file using R's standard way (i.e., everything after a `#' is ignored).
- I have read a tree in R with ape, but how do I extract branch lengths?
If your tree has been named tr:
- Is there an option to plot a tree left- or right-ladderized?
You must first rearrange the internal structure of your tree, then you can plot it in the usual way, e.g.:
tr <- ladderize(tr) # right-ladderized by default
tr <- ladderize(tr, FALSE) # left-ladderized
- I computed a distance matrix from a set of aligned DNA sequences, but the results do not make sense.
By default, dist.dna computes distances after removing the sites with at least one missing observation. If your set of sequences is heterogeneous, this may resuls in very few sites remaining (even possibly none). Use the option pairwise.deletion = TRUE if you want to use all sites on a pairwise basis, but in that case the distances will not be computed with the same sites for all pairs of taxa.
- I have a tree without branch lengths: how can I use it in comparative analyses?
See the function compute.brlen: it has several methods to set branch lengths.
- I have a tree with multichotomies: can I compute phylogenetically independent contrasts?
Yes. You need first to resolve the multichotomies with multi2di, then you can compute the contrasts. You will certainly need to adjust the number of degrees of freedom of your subsequent analyses (to see how many nodes have been resolved, just print the tree before and after applying multi2di, or use the new function Nnode).
- I have computed phylogenetically independent contrasts: how do I perform the regression through the origin?
Say you have two sets of contrasts named picx and picy:
lm(picy ~ picx - 1)
- compar.gee sometimes hangs indefinitely when analysing a binomial response.
This should not occur now with gee 4.13-15. An error now occurs in this case: when the correlation among some taxa is very strong the effective sample size is very low and the predicted probabilities are close to 1 (or 0 which caused the freeze before the fix of gee). A work-around is still to use a different set of branch lengths as computed with compute.brlen using a low value for the option `power'.
- I have done a bootstrap analysis with boot.phylo but some bootstrap values seem at the wrong place after rooting the tree.
This is because the bootstrap values are counted as the frequencies of clades, and not as actual bipartitions. So these values are really associated to the nodes, not to the edges. A consequence is that some of the bootstrap values are lilely to loose their meaning after (re)rooting the tree since this will affect the definition of the clades in the tree. A simple solution is to include the rooting process in the definition of the function FUN that is given as argument to boot.phylo. Obviously the estimated tree must also be rooted in the same way before doing the bootstrap. In this situation, it is more convenient to define FUN beforehand. An example code would be:
outgroup <- 1 # may be several tips, numeric or tip labels
foo <- function(xx) root(nj(dist.dna(xx)), outgroup)
tr <- foo(X) # X is the matrix of DNA sequences
bp <- boot.phylo(tr, X, foo)
nodelabels(bp) # will have "100" at the root
- I tried to read a tree file from phylomatic but read.nexus returns an error message: "There is apparently two root edges in your file: cannot read tree file."
It is common that trees from phylomatic have two root edges, e.g.:
Trees in ape cannot handle this kind of tree. A solution is to fuse (by hand) the two root edges in the Newick string:
In recent versions of ape, the error is likely to be: "The tree has apparently singleton node(s): cannot read tree file." Megan Bartlett gave a detailed explanation of this problem and how to handle it on r-sig-phylo: read it here.
- I have a NEXUS tree output from Bayestrees. I can read it into R with read.nexus but when I try to plot it or do some analyses ape throws an error.
Some programs, such as Bayestrees, write NEXUS files with taxa numbered from 0 to n – 1. read.nexus can read such files but the tips are then badly numbered from 0 to n – 1, instead of 1 to n. To be sure that this is the problem, open the file and you should observe something like:
It is possible to fix the tree once it is read into R with:
s <- phy$edge[, 2] <= Ntip(phy)
phy$edge[s, 2] <- phy$edge[s, 2] + 1L
- I want to plot a phylogram with square angles, not rounded.
Before plotting the tree, type the following command:
par(ljoin = 2, lend = 2)
- UPDATED Some branches in my tree are very long so that the shorter ones are not readable when the tree is plotted: how can I
The code below is now included in ape (ver. 3.5) with the function plotBreakLongEdges
We first make a copy of the tree because we're going to modify it:
tr.bak <- tr
We then need to identify the long edge(s). This could done by plotting the tree and then printing the edge numbers:
An alternative is to find the edges longer than a given value (say 1):
i <- which(tr$edge.length > 1)
We then modify the length of these edges with a small value, for instance the mean of the shorter branch lengths:
tr$edge.length[i] <- mean(tr$edge.length[-i])
We can now plot the modified tree and show the (originally) long branches with, for instance, dashed lines:
edge.style <- rep(1, Nedge(tr))
Another possibility is (this can be combined with the above):
edge.style[i] <- 2
plot(tr, edge.lty = edge.style)
A better visual effect can be achieved by drawing a white (or of the
same colour than the background) symbol before printing the
edgelabels("//", i, frame = "n")
edgelabels(edge = i, pch = 19, col = "white")
edgelabels("//", i, frame = "n")