python - 如何将变量文件名传递给 python ete?

标签 python variables tree etetoolkit

我正在尝试使用以下代码从文件中加载 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/

相关文章:

python 错误 - "IndexError: list index out of range"

在线程中写入的python文件不写入所有行

python - 在 while 循环之外访问变量,Python

javascript - 检查 Javascript 中是否存在变量的最佳方法?

recursion - 如何在 Clojure 中递归地展平任意嵌套的向量和映射?

具有先前值的 Python Pandas iterrows()

java - 变量的范围

graph - 如何使 graphviz 重复图中的节点以创建树状图像?

algorithm - 哈希表与树

python - 在python的List中通过其成员查找对象