Advertisement
Guest User

Untitled

a guest
Nov 27th, 2014
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. datos <- read.table("morphclustersred.csv",header=T,sep="t")
  2. head(datos)
  3. distfunc <- function(x) daisy(x,metric="gower")
  4. d <- distfunc(datos)
  5. hclustfunc <- function(x) hclust(x, method="complete")
  6. fit <- hclustfunc(d)
  7. plot(fit)
  8. plot(fit, labels=datos$Species,main='Morphological Clustering')
  9. rect.hclust(fit, k=5, border="red")
  10.  
  11. library(ape)
  12. class(fit) # must be hclust class
  13. my_tree <- as.phylo(fit)
  14. write.tree(phy=my_tree, file="exported_tree.newick") # look for the file in your working directory
  15.  
  16. # Heatmap of data frame 'data' saved as 'heat'
  17. heat <- heatmap.2(as.matrix(data))
  18.  
  19. # Extract dendrograms for rows and columns from 'heat'
  20. row.dendro <- heat$rowDendrogram
  21. col.dendro <- heat$colDendrogram
  22.  
  23. # Convert dendrograms to nwk (via .hcclust and .phylo formats!)
  24. as.hclust (row.dendro) ->row.hcclust
  25. as.phylo (row.hcclust) ->row.phylo
  26. write.tree(row.phylo) ->row.nwk
  27.  
  28. as.hclust (col.dendro) ->col.hcclust
  29. as.phylo (col.hcclust) ->col.phylo
  30. write.tree(col.phylo) ->col.nwk
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement