Change tip labels in phylogeny in R

岁酱吖の 提交于 2019-12-11 05:22:00

问题


I have a csv file which consists of species names for several hundred species in the same order in which they appear in $tip.labels from my phylogeny. I want to swap out these species names with new species names such that is in the same order as my original species names output from $tip.labels. I want to preserve my tree topology, just trying to update my phylogeny with new taxonomic names.

output from $tip.labels:

old_taxonomic_names
old_species_name_1
old_species_name_2
old_species_name_3
...

input with updated taxonomy:

new_taxonomic_names
new_species_name_1
new_species_name_2
new_species_name_3
...

回答1:


Consider the following toy example:

library("ape")

orig_tiplabels <- c("Alice", "Bob", "Cindy")
orig_tree <- rtree(n = 3, tip.label = orig_tiplabels)
plot(orig_tree)

new_tiplabels <- c("Debbie", "Elrond", "Frank")
orig_tree$tip.label <- new_tiplabels
plot(orig_tree)

orig_tree is the following tree:

Since we only want to change the tip labels, we can simply update the $tip.label attribute directly. This yields us a "new" tree with updated tip labels, but the topology preserved, as shown below.

This will work as long as the number of new labels is the same as the number of existing labels (in the tree), and the same tree object is used.



来源:https://stackoverflow.com/questions/57547769/change-tip-labels-in-phylogeny-in-r

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!