This is a test version of Biostars. For the public version, visit https://www.biostars.org.
changing species names in phylogeny in R

I have a column of species in the order in which they appear in my phylogeny (output from $tip.labels). I want to swap out this list of species with a new species list such that is in the same order as my original species list and replaces all the species in $tip.labels from an R phylo object.

phylogenetics r

Without an example it is impossible to reproduce the problem.

1 answer

You don't really have a question above, you haven't provided an example, etc. Perhaps starting here will help? That said, I'm going to guess that you want to rename labels on a phylo object based on another character vector of equal length. This is straightforward.

library(ape)

rename_labels <- function(tree, vec) {
 tree$tip.label <- vec
 return(tree)
}

a <- read.tree("your_tree.tre")
b <- c("your", "vector", "of", "species")
renamed_tree <- rename_labels(tree = a, vec = b)

You obviously don't need the function if you're just doing this as a one-off.

Log in to answer this question.