我试图在python中创建一个数组,它将包含系统发育树上每一对节点之间的所有配对距离。我现在用树枝状来做这件事。(我一开始看过生物工程,但找不到一个选项来做这个)。到目前为止,我的代码如下所示:
import dendropy
tree_data = []
tree = dendropy.Tree.get(path="gonno_microreact_tree.nwk",schema="newick")
pdc = tree.phylogenetic_distance_matrix()
for i, t1 in enumerate(tree.taxon_namespace[:-1]):
for t2 in tree.taxon_namespace[i+1:]:
tip_pair = {}
tip_dist_list = []
tip_pair[t1] = t2
distance = pdc(t1, t2)
tip_dist_list.append(tip_pair)
tip_dist_list.append(distance)
tree_data.append(tip_dist_list)
print tree_data除了它编写提示标签的方式外,它工作得很好。例如,tree_data列表中的一个条目如下所示:
[{<Taxon 0x7fc4c160b090 'ERS135651'>: <Taxon 0x7fc4c160b150 'ERS135335'>}, 0.0001294946558138355]但是newick文件中的提示只分别标记为ERS135651和ERS135335。如何才能使用原始提示标签来编写数组,以便该条目看起来如下所示:
[{ERS135651:ERS135335}, 0.0001294946558138355](我还阅读了树枝状文档,我知道它说要使用treecalc来这样做,如:
pdc = treecalc.PatristicDistanceMatrix(tree)但是,我只收到一个错误,即该命令不存在:
AttributeError: 'module' object has no attribute 'PairisticDistanceMatrix')
有什么建议可以让我这样做吗?
发布于 2017-04-04 14:46:40
将提示标签转换为字符串将其转换为由语音标记包围的名称,例如:
t1 = str(t1)
print t1给予:
"'ERS135651'"因此,使用字符串拼接删除额外的语音标记可以将提示标签转换回它的正确名称,例如:
t1 = t1.replace("'","")https://stackoverflow.com/questions/43065864
复制相似问题