4

I've imported a ClustalW2 tree in R using the ape function and read.tree function of the ape package. I estimate molecular ages using the chronopl function, resulting in a ultrametric, binary tree. From which I want to create a R build in dendrogram object.

The tree plots fine, and is a real phylo object. However i'm running into problems when trying to convert it:

Minimal Working Example:

require(ape)
test.tree <- read.tree(file = "testree.phylip", text = NULL, tree.names = NULL, skip = 0,
    comment.char = "#", keep.multi = FALSE)

test.tree.nu <- chronopl(test.tree, 0, age.min = 1, age.max = NULL,
node = "root", S = 1, tol = 1e-8,
CV = FALSE, eval.max = 500, iter.max = 500)

is.ultrametric(test.tree.nu)
is.binary.tree(test.tree.nu)
treeclust <- as.hclust.phylo(test.tree.nu)

The resulting tree "looks" fine, I test to make sure the tree is not ultrametric and binary, and want to convert it into a hclust object, to make eventually a dendrogram object of it.

> is.binary.tree(test.tree.nu)
[1] TRUE
> is.ultrametric(test.tree.nu)
[1] TRUE

After trying to make a hclust object out of the tree, I get an error:

> tree.phylo <- as.hclust.phylo(test.tree.nu)
Error in if (tmp <= n) -tmp else nm[tmp] : 
  missing value where TRUE/FALSE needed
In addition: Warning message:
In nm[inode] <- 1:N :
  number of items to replace is not a multiple of replacement length

I realize this is a very detailed question, and perhaps such questions which are specifically related to certain packages are better asked somewhere else, but I hope someone is able to help me.

All help is much appreciated,

Regards,

File download

The Phylip file can be downloaded here http://www.box.net/shared/rnbdk973ja

C_Z_
  • 7,427
  • 5
  • 44
  • 81
Timtico
  • 377
  • 1
  • 4
  • 14
  • A minimal working example would include the testfile you use in your code. As you can't include that, please tell us whether that one is contained within the package, and, if so, where. If I use the example trees in ape, it works (given I change your last line of code to `treeclust <- as.hclust.phylo(test.tree.nu)` – Joris Meys Dec 13 '10 at 16:23
  • Just added a file link. I realize now that this question is better asked at Biostar, and I've copied it there. I will keep this version here in case people are already trying to help me out :) – Timtico Dec 13 '10 at 16:27
  • 1
    great Q now that the file is available. One point, in future, just give the filename, e.g. `"testree.phylip"` not the windows path plus filename. – Gavin Simpson Dec 13 '10 at 16:41
  • Ok, I will do that in future. – Timtico Dec 13 '10 at 16:46

2 Answers2

2

I can reproduce this with version 2.6-2 of ape under R 2.12.1 beta (2010-12-07 r53808) on Linux, but your code works in version 2.5-3 of ape.

This would suggest a bug has crept into the package and you should inform the developers of the problem to ask for expert advice. The email address of the maintainer, Emmanuel Paradis, is on the CRAN package for ape

Gavin Simpson
  • 170,508
  • 25
  • 396
  • 453
  • Thanks, I've added myself to the mailing list of ape AND sent Emmanuel Paradis an email regarding this. I will try to downgrade to version 2.5-3 – Timtico Dec 13 '10 at 16:48
2

looks like the problem is that chronopl returns a tree which is either unrooted, or has a multifurcating root (depending on how it's interpreted). Also as.hclust.phylo has/had unhelpful error messages.

This:

modded.tree <- drop.tip(test.tree.nu,c(
'An16g06590','An02g12505','An11g00390','An14g01130'))

removes all tips from one of the three clades descending from the root, thus

is.ultrametric(modded.tree)
is.binary.tree(modded.tree)
is.rooted(modded.tree)

all return TRUE, and you can do

treeclust <- as.hclust.phylo(modded.tree)

. Though I think you really want an hclust object representing the multifurcating tree, and though hclust objects can handle those, as.hclust.phylo (from package 'ape') doesn't work on multifurcations for some reason. If you know a way to import newick files into hclust objects, that might be a way forward - ade has write.tree() to generate newick files.

user116293
  • 5,534
  • 4
  • 25
  • 17