Hclust tree to Figtree w/ branch lengths

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Hclust tree to Figtree w/ branch lengths

Julian Banchier
Hi,

I'm doing hierarchical clustering, and want to export my dendrogram to a tree-viewing/editing software. I can do this by converting the data to Newick format (hc2Newick in ctc package), but I can't get branch lengths to show in the resulting phylogram. I figured it might help to convert my hclust object into a phylo object (as.phylo in ape package), but the following lines give me this "Error in UseMethod("as.phylo") : no applicable method for 'as.phylo' applied to an object of class "character":

data = read.table("C:/path/data.txt")
d <- dist(data, method = "euclidean")
library(ape)
fit <- as.phylo(hclust(d, method="ward")
library(ctc)
write.table(as.phylo(hc2Newick(fit), file="C:/path/output.txt",row.names=FALSE,col.names=FALSE))

Would anyone have an idea about how to make this work?

Thanks so much in advance!
Julian
Reply | Threaded
Open this post in threaded view
|

Re: Hclust tree to Figtree w/ branch lengths

Julian Banchier
Hi,

This worked:

fit <- hclust(d, method="ward")
library(ape)
p <- (as.phylo(fit))
write.tree(p, file="MyNewick.tre")

Cheers,
J