Как передать объект Dendropy с метаданными в ete3 в python3? - PullRequest
0 голосов
/ 07 июня 2018

Если у меня есть дерево дендропии, которое я аннотирую с некоторыми метаданными, например с некоторыми таксономиями, как я могу преобразовать все дерево с метаданными в объект 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 может быть странного формататак как он не распознается парсером xml из ete3.

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
...