[Biopython-dev] Fw: Bio.Phylo tutorial

Eric Talevich eric.talevich at gmail.com
Sun Dec 7 07:19:35 UTC 2014


On Thu, Dec 4, 2014 at 10:24 AM, Tiago Antao <tra at popgen.net> wrote:

> 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
>
>
OK, I see the problem and I'm working on it now.


> 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))
>
>
In this example and in the tutorial, the call to Phylo.parse is already
wrapped in list(). What was the problem?

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?


> 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
>
> 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?


> Maybe putting all this on automated docstring test would be a good
> idea...
>

Certainly.


-Eric
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.open-bio.org/pipermail/biopython-dev/attachments/20141206/c50b3fff/attachment.html>


More information about the Biopython-dev mailing list