ape's FAQ

  1. How do I know which version of ape I am using?
  2. Why don't you develop a GUI for ape?
  3. I posted a query about ape on the r-help mailing list, but got no answer.
  4. What tree file formats are supported by ape?
  5. 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?
  6. I have a tree file in Newick format with some comments within straight brackets: is that a problem?
  7. I have read a tree in R with ape, but how do I extract branch lengths?
  8. Is there an option to plot a tree left- or right-ladderized?
  9. I computed a distance matrix from a set of aligned DNA sequences, but the results do not make sense.
  10. I have a tree without branch lengths: how can I use it in comparative analyses?
  11. I have a tree with multichotomies: can I compute phylogenetically independent contrasts?
  12. I have computed phylogenetically independent contrasts: how do I perform the regression through the origin?
  13. compar.gee sometimes hangs indefinitely when analysing a binomial response.
  14. I have done a bootstrap analysis with boot.phylo but some bootstrap values seem at the wrong place after rooting the tree.
  15. 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."
  16. 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.
  17. I want to plot a phylogram with square angles, not rounded.
  18. 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 break them?

  1. 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.

    Back to top


  2. Why don't you develop a GUI for ape?
    There are at least three good reasons:
    Back to top


  3. 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.

    Back to top


  4. 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.

    Back to top


  5. 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.)

    Back to top


  6. 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).

    Back to top


  7. I have read a tree in R with ape, but how do I extract branch lengths?
    If your tree has been named tr:

    tr$edge.length

    Back to top


  8. 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
    plot(tr)
    tr <- ladderize(tr, FALSE) # left-ladderized
    plot(tr)

    Back to top


  9. 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.

    Back to top


  10. 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.

    Back to top


  11. 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).

    Back to top


  12. 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)

    Back to top


  13. 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'.

    Back to top


  14. 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)
    plot(tr)
    nodelabels(bp) # will have "100" at the root

    Back to top


  15. 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.:

    ((................... )seedplant:1.000000)euphyllophyte:1.000000;

    Trees in ape cannot handle this kind of tree. A solution is to fuse (by hand) the two root edges in the Newick string:

    (................... )euphyllophyte:2.000000;

    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.

    Back to top


  16. 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:

    BEGIN TREES;
    TRANSLATE
    0 Pongo,
    1 Pan,
    etc ...

    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

    Back to top


  17. I want to plot a phylogram with square angles, not rounded.
    Before plotting the tree, type the following command:

    par(ljoin = 2, lend = 2)

    Back to top


  18. 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 break them?
    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:

    plot(tr)
    edgelabels()

    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))
    edge.style[i] <- 2
    plot(tr, edge.lty = edge.style)

    Another possibility is (this can be combined with the above):

    plot(tr)
    edgelabels("//", i, frame = "n")

    A better visual effect can be achieved by drawing a white (or of the same colour than the background) symbol before printing the //:

    plot(tr)
    edgelabels(edge = i, pch = 19, col = "white")
    edgelabels("//", i, frame = "n")

    Back to top


Updated: May 28, 2016
Crédits | Legal notice