我正在尝试使用以下代码从文件中加载 newick 字符串:
filename = templist[1].lower().replace(" ","") + ".nwk"
tt = Tree(filename, format=1)
但出现以下错误:
tt = Tree(filename, format=1) # Loads a tree structure from a newick string. The returned variable tt is the root node for the tree.
File "/python2.7/dist-packages/ete2-2.2.1072-py2.7.egg/ete2/coretype/tree.py", line 225, in __init__
read_newick(newick, root_node = self, format=format)
File "/python2.7/dist-packages/ete2-2.2.1072-py2.7.egg/ete2/parser/newick.py", line 237, in read_newick
'Unexisting tree file or Malformed newick tree structure.'
ete2.parser.newick.NewickError: Unexisting tree file or Malformed newick tree structure.
文件格式我已经验证过了,没问题。我想我以错误的方式传递了变量,你能指导我将文件名作为变量传递吗?
当我在不使用变量的情况下将文件名作为字符串传递时,它工作正常,但我需要使用变量值来加载树。
最佳答案
你确定 format=1
是正确的吗?
根据 documentation -
for named internal nodes we will use format 1
您确定您的 newick 树已命名内部节点吗?如果不是,请尝试不向 format
参数传递任何值。
此外,请确保文件名是文件的绝对
路径,或者如果是相对路径,例如a.nwk
,则确保文件存在于您运行 python 脚本的目录中。
关于python - 如何将变量文件名传递给 python ete?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30950502/