[Biopython-dev] Fw: Bio.Phylo tutorial
Tiago Antao
tra at popgen.net
Thu Dec 4 18:24:22 UTC 2014
Sorry, sent this to Eric and forgot to Cc the list...
Begin forwarded message:
Date: Thu, 4 Dec 2014 18:23:29 +0000
From: Tiago Antao <tra at popgen.net>
To: Eric Talevich <eric.talevich at gmail.com>
Subject: Re: [Biopython-dev] Bio.Phylo tutorial
Hi,
There are 3 problems:
Problem 1:
On Python 2 this (from the Tutorial) is failing:
trees = Phylo.parse("data/phyloxml_examples.xml", "phyloxml")
trees = list(trees)
for tree in trees:
print(tree)
With:
Bio/Phylo/BaseTree.pyc in print_tree(obj, indent)
953 This closes over textlines and modifies it in-place.
954 """
--> 955 textlines.append(TAB * indent + repr(obj))
956 indent += 1
957 for attr in obj.__dict__:
UnicodeEncodeError: 'ascii' codec can't encode character u'\xfc' in
position 24: ordinal not in range(128)
This works on Python 3! But see problem 3 below
Problem 2:
On Python 3 this dialect does not work
trees = list(Phylo.parse("../../Tests/PhyloXML/phyloxml_examples.xml",
"phyl oxml"))
>>> tree1 = trees[0]
>>> others = trees[1:]
(trees is a generator). There are different solutions here (like doing
trees=list(trees))
Problem 3:
While the code of problem 1 works on Python 3, the bit after does not
(I do not know with Python 2):
Phylo.write(tree1, "data/tree1.xml", "phyloxml")
Error:
Bio/Phylo/PhyloXMLIO.py in write(self, file, encoding, indent)
675 if indent:
676 _indent(self._tree.getroot())
--> 677 self._tree.write(file, encoding)
678 return len(self._tree.getroot())
TypeError: must be str, not bytes
Maybe putting all this on automated docstring test would be a good
idea...
Tiago
More information about the Biopython-dev
mailing list