【问题标题】:Collapse a clade by tip labels while maintaining phylogenetic position通过尖端标签折叠进化枝,同时保持系统发育位置
【发布时间】:2016-09-09 03:34:02
【问题描述】:

我可能可以更好地措辞标题,但我想折叠系统发育树中的任何进化枝(即使进化枝有一个成员),其尖端标签为“foo”,然后计算尖端的数量从那个特定的进化枝上掉下来,并创建一个带有显示 35 foos 的尖端标签的分支。

计数部分很容易;但是,当我使用

drop.tip(rooted.tree,tip=which(rooted.tree$tip.label=='foo'),subtree=TRUE)

丢弃的提示不会保持其在树中的位置。相反,它们都在最后分组(但是正确计算)。有没有办法通过尖端标签折叠进化枝并保持其在树上的位置?

【问题讨论】:

    标签: r phylogeny ape-phylo


    【解决方案1】:

    棘手的部分是确定您拥有多少个单独的单系进化枝。这个函数应该可以解决问题。

    collapse_identical_tips <- function(phy,tip_label){
      matching_tips <- which(phy$tip.label==tip_label)
      nt <- length(phy$tip.label) # number of tips in tree
      nm <- length(matching_tips) # Number of tips matching the label
      keep <- numeric(nm)
    
      cur_tip <- 1
      while(cur_tip<=nm){
        if(cur_tip == nm){
          keep[cur_tip] <- 1
          break
        }
        next_tip <- cur_tip + 1
        mrca_ <- getMRCA(phy,c(matching_tips[cur_tip],matching_tips[next_tip]))
        descendants <- getDescendants(phy, mrca_)
        descendant_tips <- descendants[descendants<=nt]
        if(all(descendant_tips %in% matching_tips)){
          keep[cur_tip] <- 1
          cur_tip <- cur_tip + length(descendant_tips)
        }else{
          keep[cur_tip] <- 1
          cur_tip <- cur_tip + 1
        }
      }
      to_drop <- matching_tips[!keep]
      new_phy <- drop.tip(phy,to_drop)
      return(new_phy)
    }
    

    测试一下:

    tc <- "(A:3.135206161,(B:2.757615245,(((C:0.5796267872,((foo:0.1917981792,(foo:0.08246947568,foo:0.08246947568):0.1093287035):0.2328473818,(D:0.3107268924,E:0.3107268924):0.1139186686):0.1549812262):0.3387382152,F:0.9183650024):1.172666972,(((G:0.02437174382,H:0.02437174382):0.4727952475,foo:0.4971669913):0.8701228492,(foo:1.124632261,(foo:0.6503599778,foo:0.6503599778):0.4742722831):0.2426575797):0.7237421344):0.6665832698):0.3775909166);"
    phy <- read.tree(textConnection(tc))
    
    plot(phy)
    

    plot(collapse_identical_tips(phy,"foo"))
    

    【讨论】:

    • 你的方法有效;但是,使用它时,我不确定如何计算折叠后的“foos”。例如,我希望提示是“2 foo's, 1 foo, 1 foo, two foo's”。有什么方法可以编辑代码以使其做到这一点,或者给我一些关于如何去做的想法?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-09
    相关资源
    最近更新 更多