【问题标题】:Is it possible to convert the Tree object in Biopython to Newick format?是否可以将 Biopython 中的 Tree 对象转换为 Newick 格式?
【发布时间】:2015-09-03 13:01:56
【问题描述】:

我使用了 Bio.Cluster 的 treecluster,它生成了一个 Tree 对象。 我正在聚类一个基因表达矩阵。 如果需要,我想要一种简单的方法来遍历这棵树并添加一些额外的功能(一些额外的信息,如我想要的每个节点的 p 值或术语名称)。 我发现这种工作的一个很好的包是 ete2,但这需要树作为 Newick 字符串。

是否有可以将 Tree 对象转换为 Newick 的函数,或者您知道比 ete2 更好的方法吗?

提前致谢, L.

【问题讨论】:

    标签: cluster-computing biopython


    【解决方案1】:

    Bio.Cluster.Tree 转为 newick 格式,示例:

    输入文件cyano.txt github

    基因 0 15 分钟 1 小时 6 小时 15 小时 sll0617 0.0 -0.141164092921 -0.564656371686 -0.219393769051 -0.582969948517 slr0452 0.0 -0.124988599702 -0.499954398807 0.195680498436 0.0781478593432 slr1513 0.0 0.788547158236 0.228594792282 0.255819396258 0.304823683415 sll1471 0.0 -0.770355431265 -1.10115338201 -1.00607440632 -0.834932250086 sll1694 0.0 -0.328239937586 -2.16037133914 -1.184544471 -1.36760041273 sll0430 0.0 2.57611845993 0.920296714116 0.331897478085 0.353984672049 sll0851 0.0 -0.260488607867 -1.04195443147 -0.870951657169 -0.563146663432 sll1260 0.0 0.488375211397 1.03336768086 1.05808458732 1.10257501897 sll1031 0.0 2.22636090218 1.2737708006 1.22441048661 1.13556192142 ......

    python (view example source) 中使用treecluster

    from Bio import Cluster
    handle = open("cyano.txt")
    record = Cluster.read(handle)
    handle.close()
    genetree = record.treecluster(method='s')
    genetree.scale()
    exptree = record.treecluster(dist='u', transpose=1)
    record.save("cyano_result", genetree, exptree)
    

    这将创建文件cyano_result.cdtcyano_result.gtrcyano_result.atr

    现在,我们可以使用R 和 Bioconductor 将 atr 转换为 newick

    安装最新版本的R,然后通过启动R并输入命令获取最新版本的Bioconductor

    #optional, for install bioconductor and ctc library
    source("http://bioconductor.org/biocLite.R")
    biocLite()
    biocLite("ctc")
    
    #code to convert atr to newick
    library("ctc")
    h <- xcluster2r("cyano_result.atr")
    write(hc2Newick(h),file='cyano_result.newick')
    

    cyano_result,我们得到:

    (1:0.356996468574314, (2:0.0826361905178331, (5:0.0469498559561281, (3:0.513417484951725,4:0.513417484951725) :0.0469498559561281) :0.0826361905178331) :0.356996468574314);

    得到下面的情节

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-24
      • 2010-10-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多