其他
进化树改名
I don't know whether 'rename taxa' is a common task or not. It seems not a good idea to rename taxa in Newick tree text, since it may introduce problems when mapping the original sequence alignment to the tree.
If you just want to show different or additional information when plotting the tree, it is fine and easy to do it using ggtree
:
require(treeio)
require(ggtree)
tr <- read.tree(text = "((a,(b,c)),d);")
genus <- c("Gorilla", "Pan", "Homo", "Pongo")
species <- c("gorilla", "spp.", "sapiens", "pygmaeus")
geo <- c("Africa", "Africa", "World", "Asia")
d <- data.frame(label = tr$tip.label, genus = genus,
species = species, geo = geo)
ggtree(tr) %<+% d + xlim(NA, 5) +
geom_tiplab(aes(label=paste0('italic(', genus, ')~bolditalic(', species, ')~', geo)), parse=T)
treedata
or phylo
) in treeio
:
tr2 = rename_taxa(tr, d, label, genus)
write.tree(tr2)
d2 = dplyr::mutate(d, newlab = paste(genus, species, sep='|'))
tr3 = rename_taxa(tr, d2, label, newlab)
write.tree(tr3)
If the input tree object is a treedata
instance, you can use write.beast
to export the tree with associated data to a BEAST compatible NEXUS file.