问题
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