[Biopython] parsing newick trees in memory

Peter biopython at maubp.freeserve.co.uk
Sun Oct 10 20:10:30 UTC 2010


On Sun, Oct 10, 2010 at 6:22 PM, Michael Thon wrote:
>
> I could not get StringIO to work in this case... that
> is, until I learned that I have to ensure that I can
> read from the beginning of the buffer:
>
>    out_h = StringIO.StringIO()
>    out_h.write(tree_text)
>    out_h.seek(0)
>    tree = Phylo.read(out_h, 'newick')
>    print tree
>

This way is shorter ;)

from StringIO import StringIO
from Bio import Phylo
tree = Phylo.read(StringIO(tree_text), 'newick')
print tree

Eric - we should probably have an example of using
StringIO in the Phlyo chapter as we do in the SeqIO
chapter.

Peter




More information about the Biopython mailing list