user11501147
user11501147

Reputation: 41

Change tip labels in phylogeny in R

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
...

Upvotes: 1

Views: 7555

Answers (1)

Dunois
Dunois

Reputation: 1843

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. enter image description here

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.

Upvotes: 2

Related Questions