BioPython中系统发育树的子树

时间:2016-08-19 00:41:48

标签: python tree bioinformatics biopython

我有一个新的格式的系统发育树。我想根据终端节点的标签拉出一个子树(所以基于物种列表)。我正在使用的树的副本可以在这里找到:http://hgdownload.soe.ucsc.edu/goldenPath/dm6/multiz27way/dm6.27way.nh

目前我已经使用BioPython在树中阅读了这样的内容:

from Bio import Phylo
#read in Phylogenetic Tree
tree = Phylo.read('dm6.27way.nh', 'newick')
#list of species of interest
species_list = ['dm6', 'droSim1', 'droSec1', 'droYak3', 'droEre2', 'droBia2', 'droSuz1', 'droAna3', 'droBip2', 'droEug2', 'droEle2', 'droKik2', 'droTak2', 'droRho2', 'droFic2']

我如何在species_list中仅提取物种的子树?

2 个答案:

答案 0 :(得分:3)

好的是,假设您想要物种列表中包含所有物种的最小树,您希望此树的根节点是列表中所有物种的最新共同祖先(MRCA),幸好已经在Phylo中实施:

from Bio import Phylo

#read in Phylogenetic Tree
tree = Phylo.read('dm6.27way.nh', 'newick')
#list of species of interest
species_list = ['dm6',
                'droSim1',
                'droSec1',
                'droYak3',
                'droEre2',
                'droBia2',
                'droSuz1',
                'droAna3',
                'droBip2',
                'droEug2',
                'droEle2',
                'droKik2',
                'droTak2',
                'droRho2',
                'droFic2']

common_ancestor = tree.common_ancestor(species_list)
Phylo.draw_ascii(common_ancestor)

输出:

Clade
                                           ___ dm6
                                       ___|
                                      |   | , droSim1
                                      |   |_|
                            __________|     | droSec1
                           |          |
                           |          |  _____ droYak3
                          ,|          |_|
                          ||            |____ droEre2
                          ||
                          ||      _______ droBia2
                          ||_____|
                          |      |_____ droSuz1
                          |
                        __|                                  _______ droAna3
                       |  |_________________________________|
                       |  |                                 |________ droBip2
                       |  |
                       |  |___________________ droEug2
                       |
                       |_____________ droEle2
                      ,|
                      ||______________________________ droKik2
                    __||
                   |  ||______________ droTak2
___________________|  |
                   |  |____________ droRho2
                   |
                   |_______________ droFic2

答案 1 :(得分:0)

使用ete3

,而不是使用BioPython
from ete3 import Tree
t = Tree('dm6.27way.nh')
t.prune(species_list, preserve_branch_length=True)
t.write()

从文档中

从版本2.2开始,此函数还包含preserve_branch_length标志,该标志允许从树中删除节点,同时保持其余节点之间的原始距离。