简体   繁体   中英

Is there a way to reorder tip labels of a phylo object so that they are consistent with another phylo object?

I have two trees that I am trying to compare. One from mrbayes, another from Paup.

When I use read.nexus, the resulting phylo objects have differently ordered tip labels, despite the fact that both files have the same nexus taxa block.

I've reproduced these trees below:

library(ape)
#trees
t1 <- structure(list(edge = structure(c(29L, 30L, 30L, 30L, 30L, 31L, 
31L, 32L, 32L, 33L, 34L, 35L, 35L, 35L, 34L, 36L, 37L, 38L, 38L, 
38L, 38L, 37L, 39L, 40L, 40L, 39L, 39L, 39L, 39L, 36L, 36L, 36L, 
36L, 33L, 31L, 31L, 31L, 31L, 29L, 30L, 1L, 2L, 3L, 31L, 4L, 
32L, 5L, 33L, 34L, 35L, 6L, 7L, 8L, 36L, 37L, 38L, 9L, 10L, 11L, 
12L, 39L, 40L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 
23L, 24L, 25L, 26L, 27L, 28L), .Dim = c(39L, 2L)), Nnode = 12L, 
    tip.label = c("Metaspriggina", "Eptatretus", "Mordacia", 
    "Lasanius", "Phlebolepis", "Zenaspis", "Diademaspis", "Ukrainaspis", 
    "Tamiobatis", "Ischnacanthus", "Mesacanthus", "Tetanopsyrus", 
    "Mimipiscis", "Raynerius", "Diabolepis", "Guiyu", "Gavinia", 
    "Qingmenodus", "Kujdanowiaspis", "Cowralepis", "Jagorina", 
    "Macropetalichthys", "Polybranchiaspis", "Cyathaspis", "Irregulareaspis", 
    "Listraspis", "Unarkaspis", "Pikaia")), class = "phylo", order = "cladewise")
    
t2 <- structure(list(edge = structure(c(29L, 29L, 30L, 30L, 31L, 32L, 
33L, 33L, 32L, 31L, 31L, 31L, 31L, 31L, 31L, 34L, 35L, 36L, 37L, 
37L, 36L, 35L, 38L, 39L, 40L, 41L, 42L, 42L, 42L, 42L, 41L, 43L, 
44L, 44L, 43L, 45L, 46L, 47L, 47L, 46L, 45L, 40L, 48L, 48L, 39L, 
38L, 34L, 1L, 30L, 2L, 31L, 32L, 33L, 3L, 4L, 5L, 6L, 7L, 8L, 
9L, 10L, 34L, 35L, 36L, 37L, 11L, 12L, 13L, 38L, 39L, 40L, 41L, 
42L, 21L, 23L, 24L, 17L, 43L, 44L, 22L, 27L, 45L, 46L, 47L, 28L, 
26L, 25L, 16L, 48L, 15L, 19L, 18L, 20L, 14L), .Dim = c(47L, 2L
)), Nnode = 20L, tip.label = c("Pikaia", "Metaspriggina", "Eptatretus", 
"Mordacia", "Lasanius", "Phlebolepis", "Cyathaspis", "Irregulareaspis", 
"Listraspis", "Unarkaspis", "Zenaspis", "Diademaspis", "Ukrainaspis", 
"Polybranchiaspis", "Cowralepis", "Guiyu", "Ischnacanthus", "Jagorina", 
"Kujdanowiaspis", "Macropetalichthys", "Mesacanthus", "Mimipiscis", 
"Tamiobatis", "Tetanopsyrus", "Diabolepis", "Gavinia", "Raynerius", 
"Qingmenodus")), class = "phylo", order = "cladewise")

#tip labels are the same 
all.equal(sort(t1$tip.label), sort(t2$tip.label))
#[1] TRUE

#tip label order is different
all.equal(t1$tip.label, t2$tip.label)
#[1] "26 string mismatches" 

Is there a way to reorder the tip labels of t1, so they are consistent with t2?

The solution depends very much on what you want to do with the trees. Most phylogenetic comparative methods use identical names in trees and correctly assign them. A simple match for the two trees can be found as:

  match(match(t1$tip.label, t2$tip.label)
  # [1]  2  3  4  5  6 11 12 13 23 17 21 24 22 27 25 16 26 28 19 15 18 20 14  7  8  9 10  1

To reorder the tree, you can use ladderize(t1) , but that will only influence the plotting, not the tip label order. A nice, easy trick how to re-number the nodes and keep the tip labels in the ladderized display is to save the tree and load it again.

 write.tree(ladderize(t1), file = "t1.tre")
 t1 = read.tree("t1.tre")

However, your trees have different topologies, so matching the tip labels must be done with respect to the downstream analyses.

cophyloplot(ladderize(t1), ladderize(t2), 
            assoc = matrix(rep(t1$tip.label, 2), ncol = 2))

在此处输入图像描述

I think this is what you are after:

trees <- c(t1, t2) 
trees <- .compressTipLabel(trees)
t2 <- trees[[2]]
all.equal(t1$tip.label, t2$tip.label)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM