I am trying load newick string from a file using following code:
filename = templist[1].lower().replace(" ","") + ".nwk"
tt = Tree(filename, format=1)
but getting following error:
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.
I have verified the file format, and it is Ok. I think I am passing the variable in wrong way, can you please guide me to pass filename as variable.
When I pass the filename as string without using variable it is working fine, but I need to use variable value to load tree.
Are you sure the
format=1
is correct?According to documentation -
Are you sure your newick tree has named internal nodes? If not, try without passing any value to the
format
argument.Also, please make sure that the filename is either
absolute
path to the file, or if its relative path , for examplea.nwk
, then make sure the file exists in the directory from which you are running the python script.