【问题标题】:Convert phylogenetic tree into dataframe将系统发育树转换为数据框
【发布时间】:2019-07-15 13:55:34
【问题描述】:

我正在寻找一种在 R 中将系统发育树(Newick 格式或“phylo”类)转换为数据框的方法。目标是很好地了解哪些提示从树的每个节点下降。有没有人遇到过这个问题?

我可以从系统发育树中获取所有尖端标签,或者从一个节点中获取所有后代节点,但我无法获取属于某个节点的尖端标签。

#for a random tree x
x <- rtree(10, tip.label = LETTERS[1:10])

#get all tip labels by asking for tree information
> x

Phylogenetic tree with 10 tips and 9 internal nodes.

Tip labels:
    H, G, D, B, I, C, ...

Rooted; includes branch lengths.

#descendant nodes from a node
test <- phytools::getDescendants(x, node=5, curr=NULL)

#the package ggphylo seemed to have the answer to my problem, but it is no longer supported (last updates were in 2012)
ggphylo::tree.as.data.frame(x)

(我认为转换为数据框是最简单的方法,但如果您知道另一种从节点获取后代提示的方法,我愿意接受所有可能的解决方案)

【问题讨论】:

    标签: r dataframe phylogeny


    【解决方案1】:

    您是否在寻找边缘表(即显示每个尖端和节点之间连接的表)?您可以直接在phylo 对象中使用:

    ## The edge table
    x$edge
    

    您可以在following SO question 中找到更精美的可视化。

    【讨论】:

      【解决方案2】:

      phytools 包中的函数 compute.mr 将系统发育转换为其矩阵表示,这可能就是您要寻找的。​​p>

      x <- rtree(10, tip.label = LETTERS[1:10])
      phytools::compute.mr(x, type = "matrix")
      #   [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8]
      # H "1"  "1"  "1"  "0"  "0"  "0"  "0"  "0" 
      # E "1"  "1"  "1"  "0"  "0"  "0"  "0"  "0" 
      # C "1"  "1"  "0"  "1"  "1"  "0"  "0"  "0" 
      # I "1"  "1"  "0"  "1"  "1"  "0"  "0"  "0" 
      # J "1"  "1"  "0"  "1"  "0"  "0"  "0"  "0" 
      # F "1"  "0"  "0"  "0"  "0"  "1"  "0"  "0" 
      # A "1"  "0"  "0"  "0"  "0"  "1"  "0"  "0" 
      # D "0"  "0"  "0"  "0"  "0"  "0"  "1"  "0" 
      # G "0"  "0"  "0"  "0"  "0"  "0"  "1"  "1" 
      # B "0"  "0"  "0"  "0"  "0"  "0"  "1"  "1" 
      

      【讨论】:

        【解决方案3】:

        感谢您的建议。 我找到了一位同事,给出了我正在寻找的答案。 ape 包中的函数 prop.part 很好地概述了每个节点的所有提示。结果是一个列表而不是一个数据框,但它可以解决问题。

        list_all_tips <- c(prop.part(tree, check.labels = TRUE)) 
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2022-11-17
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多