python - 如何将带有元数据的 Dendropy 对象传递给 python3 中的 ete3?
问题描述
如果我有一个用一些元数据注释的 dendropy 树,例如一些分类法,我如何将带有元数据的整个树转换为 ete3 对象?
import dendropy
t = dendropy.Tree.get_from_string("(A,(B,(C,D)));", "newick")
categories = {"A" : "Human", "B": "Mouse", "C": "Bee", "D": "dolphin", "E":"Ecoli"}
for taxon in tree.taxon_namespace:
taxon.category = categories[taxon.label]
taxon.annotations.add_bound_attribute("category")
我试图直接通过它:
from ete3 import PhyloTree
tree = PhyloTree(t)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.4/dist-packages/ete3/phylo/phylotree.py", line 391, in __init__
TreeNode.__init__(self, newick=newick, format=format, **kargs)
File "/usr/local/lib/python3.4/dist-packages/ete3/coretype/tree.py", line 211, in __init__
quoted_names=quoted_node_names)
File "/usr/local/lib/python3.4/dist-packages/ete3/parser/newick.py", line 254, in read_newick
raise NewickError("'newick' argument must be either a filename or a newick string.")
ete3.parser.newick.NewickError: 'newick' argument must be either a filename or a newick string.
You may want to check other newick loading flags like 'format' or 'quoted_node_names'.
我还尝试编写为 nexml 格式并使用 nexml 解析器表单 ete3 读取它:
tree.write_to_path(output_tree_file, nexml)
from ete3 import Nexml, nexml
nexml_project = Nexml()
# Load content from NeXML file
nexml_project.build_from_file(tree)
# Extracts all the collection of trees in the project
tree_collections = nexml_project.get_trees()
# Select the first collection
collection_1 = tree_collections[0]
但是,nexml 中的树似乎是奇怪的格式,因为 ete3 的 xml 解析器无法识别它。
Traceback (most recent call last):
nexml_project.build_from_file(tree)
File "/usr/local/lib/python3.4/dist-packages/ete3/nexml/__init__.py", line 59, in build_from_file
doc = _nexml.parsexml_(fname)
File "/usr/local/lib/python3.4/dist-packages/ete3/nexml/_nexml.py", line 103, in parsexml_
doc = etree_.parse(*args, **kwargs)
File "/usr/lib/python3.4/xml/etree/ElementTree.py", line 1187, in parse
tree.parse(source, parser)
File "/usr/lib/python3.4/xml/etree/ElementTree.py", line 598, in parse
self._root = parser._parse_whole(source)
xml.etree.ElementTree.ParseError: not well-formed (invalid token): line 110886, column 107
解决方案
推荐阅读
- tensorflow.js - tensorflow.js 中的自定义激活(Swish)
- javascript - 如何合并父ID上的嵌套数组
- jsp - Struts 2 中的多个提交按钮映射
- contiki - RIOT 中固定的 RPL DIS 发送间隔是多少?
- javascript - 即使在绑定之后,反应和“this”的问题
- sql-server - SSIS 包作为作业的一部分失败
- amazon-web-services - Ubuntu UFW 是否会覆盖 Amazon Ec2 的安全组和规则?
- corda - 尝试运行 cordapp-example 时出现多个错误
- android - 有没有一种方法可以在 android studio 中使用(副本)类,一旦被弃用然后被删除?
- cmake - VSCode 任务依赖于正在运行,任务本身不