当Biopython读取结点树时,行中缺少"",""



我想编辑从BEAST2树注释器以nexus格式获得的树。通常我使用Biopython中的模块Phylo进行此类工作,但Phylo.read(r"filename.tree", "nexus")给了我下一个例外:

---------------------------------------------------------------------------
NexusError                                Traceback (most recent call last)
Input In [29], in <cell line: 1>()
----> 1 Phylo.read(r"filename.tree", "nexus")
File ~miniconda3libsite-packagesBioPhylo_io.py:60, in read(file, format, **kwargs)
58 try:
59     tree_gen = parse(file, format, **kwargs)
---> 60     tree = next(tree_gen)
61 except StopIteration:
62     raise ValueError("There are no trees in this file.") from None
File ~miniconda3libsite-packagesBioPhylo_io.py:49, in parse(file, format, **kwargs)
34 """Parse a file iteratively, and yield each of the trees it contains.
35 
36 If a file only contains one tree, this still returns an iterable object that
(...)
46 
47 """
48 with File.as_handle(file) as fp:
---> 49     yield from getattr(supported_formats[format], "parse")(fp, **kwargs)
File ~miniconda3libsite-packagesBioPhyloNexusIO.py:40, in parse(handle)
32 def parse(handle):
33     """Parse the trees in a Nexus file.
34 
35     Uses the old Nexus.Trees parser to extract the trees, converts them back to
(...)
38     eventually change Nexus to use the new NewickIO parser directly.)
39     """
---> 40     nex = Nexus.Nexus(handle)
42     # NB: Once Nexus.Trees is modified to use Tree.Newick objects, do this:
43     # return iter(nex.trees)
44     # Until then, convert the Nexus.Trees.Tree object hierarchy:
45     def node2clade(nxtree, node):
File ~miniconda3libsite-packagesBioNexusNexus.py:668, in Nexus.__init__(self, input)
665 self.options["gapmode"] = "missing"
667 if input:
--> 668     self.read(input)
669 else:
670     self.read(DEFAULTNEXUS)
File ~miniconda3libsite-packagesBioNexusNexus.py:718, in Nexus.read(self, input)
716     break
717 if title in KNOWN_NEXUS_BLOCKS:
--> 718     self._parse_nexus_block(title, contents)
719 else:
720     self._unknown_nexus_block(title, contents)
File ~miniconda3libsite-packagesBioNexusNexus.py:759, in Nexus._parse_nexus_block(self, title, contents)
757 for line in block.commandlines:
758     try:
--> 759         getattr(self, "_" + line.command)(line.options)
760     except AttributeError:
761         raise NexusError("Unknown command: %s " % line.command) from None
File ~miniconda3libsite-packagesBioNexusNexus.py:1144, in Nexus._translate(self, options)
1142         break
1143     elif c != ",":
-> 1144         raise NexusError("Missing ',' in line %s." % options)
1145 except NexusError:
1146     raise
NexusError: Missing ',' in line 1 AB298157.1_2015_-7.9133750332192605_114.8086828279248, 2 AB298158.1_2007_-8.41698974207…

使用CCD_ 3也得到了相同的结果。有人能帮忙吗?我无法理解这个错误的原因,因为nexus文件看起来是正确的。

原因是Biopython无法读取带有链接的nexus树,这些链接是翻译的组成部分&纽威克树。因此,之前需要将其转换为具有完整名称的形式,并将其转换到树中(如下所述(。

Begin
tree TREE1 = (((your,tree),(in,(the, newick))),format);
End;

附言:在newick格式中,允许在标签周围加引号,&一些程序或脚本将它们添加到那些具有模糊字符的名称中。但在接下来的系统发育分析中,它可能会导致异常,例如在BEAST中。我希望你小心点。

最新更新