How do I fix a "badly conformed" phylogenetic tree in order to plot it in R?

334 views Asked by At

I am trying to plot a tree of an inferred eucalypt phylogeny in R using the package ape. The tree is from a nexus file (Eucalypt_Bayes_dated_character_mapped.nex) that I downloaded from CSIRO's website (https://data.csiro.au/collection/csiro:33546v2).

I get the following error:

> plot(euc.tr)
Error in plot.phylo(euc.tr) : tree badly conformed; cannot plot. Check the edge matrix.

I tried looking at euc.tr$edge to see if I could find any errors, but am struggling to understand how the numbers in the matrix should correspond to the tree, and I am not sure what is meant by "badly conformed", even after searching Google and the ape manual.

When I open the nexus file in Mesquite instead of R I can't see anything unusual about the tree.

Summary of the phylogenetic tree object in R:

> summary(euc.tr)

Phylogenetic tree: euc.tr 

  Number of tips: 674 
  Number of nodes: 568 
  Branch lengths:
    mean: 2.436121 
    variance: 23.99677 
    distribution summary:
     Min.   1st Qu.    Median   3rd Qu.      Max. 
 0.000728  0.118585  0.477268  2.297975 50.513412 
  No root edge.
  First ten tip labels: Angophora_bakeri 
                        Angophora_costata
                        Angophora_exul
                        Angophora_floribunda
                        Angophora_hispida
                        Angophora_inopina
                        Angophora_melanoxylon
                        Angophora_robur
                        Angophora_subvelutina
                        Angophora_woodsiana
  No node labels.

Head of the edge matrix (of which there are 1241 rows):

> head(euc.tr$edge)
     [,1] [,2]
[1,]  675  676
[2,]  676  677
[3,]  677  678
[4,]  678 6240
[5,]  678  679
[6,]  679  680
1

There are 1 answers

1
Martin Smith On BEST ANSWER

The problem is arising because the edge matrix contains incorrect values: tail(euc.tr$edge) includes an entry 62283, but all values should refer to a tip or an internal node so should be < nTip + nNode, i.e. 674+568 = 1242.

As such it looks like you've encountered a bug in the ape function read.nexus(), possibly caused by the function struggling to parse Mesquite's formatting of the nexus file: specifically, the translation table uses n### instead of just numbers (###) to specify how tips are translated. I'd suggest filing this as a bug in the ape package.

In the meantime, I managed to get the tree to plot by editing the nexus file:

  • On line 1377, replace everything after TREE tree_1 = with the content from between the single quote marks ' in the setTree command on line 1497 of the file.

  • Delete everything after the END; command on line 1379.