<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Thu, Dec 4, 2014 at 10:24 AM, Tiago Antao <span dir="ltr"><<a href="mailto:tra@popgen.net" target="_blank">tra@popgen.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Sorry, sent this to Eric and forgot to Cc the list...<br>
<br>
<br>
<br>
Begin forwarded message:<br>
<br>
Date: Thu, 4 Dec 2014 18:23:29 +0000<br>
From: Tiago Antao <<a href="mailto:tra@popgen.net" target="_blank">tra@popgen.net</a>><br>
To: Eric Talevich <<a href="mailto:eric.talevich@gmail.com" target="_blank">eric.talevich@gmail.com</a>><br>
Subject: Re: [Biopython-dev] Bio.Phylo tutorial<br>
<div><div><br>
<br>
Hi,<br>
<br>
<br>
There are 3 problems:<br>
<br>
Problem 1:<br>
On Python 2 this (from the Tutorial) is failing:<br>
<br>
trees = Phylo.parse("data/phyloxml_examples.xml", "phyloxml")<br>
trees = list(trees)<br>
for tree in trees:<br>
print(tree)<br>
<br>
With:<br>
<br>
Bio/Phylo/BaseTree.pyc in print_tree(obj, indent)<br>
953 This closes over textlines and modifies it in-place.<br>
954 """<br>
--> 955 textlines.append(TAB * indent + repr(obj))<br>
956 indent += 1<br>
957 for attr in obj.__dict__:<br>
<br>
UnicodeEncodeError: 'ascii' codec can't encode character u'\xfc' in<br>
position 24: ordinal not in range(128)<br>
<br>
This works on Python 3! But see problem 3 below<br>
<br></div></div></blockquote><div> </div><div>OK, I see the problem and I'm working on it now.<br></div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div>
<br>
Problem 2:<br>
<br>
On Python 3 this dialect does not work<br>
<br>
trees = list(Phylo.parse("../../Tests/PhyloXML/phyloxml_examples.xml",<br>
"phyl oxml"))<br>
>>> tree1 = trees[0]<br>
>>> others = trees[1:]<br>
<br>
(trees is a generator). There are different solutions here (like doing<br>
trees=list(trees))<br>
<br></div></div></blockquote><div><br></div><div>In this example and in the tutorial, the call to Phylo.parse is already wrapped in list(). What was the problem?<br><br></div><div>Also: I notice that in the first example, you changed the directory "Tests/PhyloXML" to "data", but in this example you did not. Was that intentional?<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div>
Problem 3:<br>
<br>
While the code of problem 1 works on Python 3, the bit after does not<br>
(I do not know with Python 2):<br>
<br>
Phylo.write(tree1, "data/tree1.xml", "phyloxml")<br>
<br>
Error:<br>
<br>
Bio/Phylo/PhyloXMLIO.py in write(self, file, encoding, indent)<br>
675 if indent:<br>
676 _indent(self._tree.getroot())<br>
--> 677 self._tree.write(file, encoding)<br>
678 return len(self._tree.getroot())<br>
<br>
<br>
TypeError: must be str, not bytes<br>
<br></div></div></blockquote><div>This snippet works for me in both Python 2 and 3, and we do have unit tests for writing phyloXML. Is there a different setup I need to try to replicate the error?<br> <br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div>
Maybe putting all this on automated docstring test would be a good<br>
idea...<br></div></div></blockquote><div><br></div><div>Certainly.<br><br><br></div><div>-Eric</div></div><br></div></div>