[Biopython] Bio.Phylo: writing newick trees with internal node names

Tanya Golubchik golubchi at stats.ox.ac.uk
Wed Mar 21 06:12:27 EDT 2012


Hi Eric,

It works in Biopython 1.59; I was using 1.58 originally. So problem solved.

There's a few other strange things in Phylo that I can't work out,
though -- for instance, what happens to 'PhyloXML.Other' attributes -- I
can write these on the tree, and save the tree, but it can't be
re-opened because the parser rejects it as improperly formatted. The
documentation is a bit vague on this; in particular, passing None to
'attributes' when creating Phylo.Other objects fails, while passing an
empty dictionary works... what is meant to be in 'attributes' when
creating an Other object?

Also, the 'is_aligned' sequence property disappears when a tree is saved
in phyloxml format and then read back using Phylo.read:

>>> print tree
Phylogeny(rooted=True, branch_length_unit='SNV')
    Clade(branch_length=0.0, name='N1')
        Clade(branch_length=0.0, name='C00000761')
            BranchColor(blue=0, green=128, red=0)
            Sequence(type='dna')
                MolSeq(value='CCTTTCTATGTTCTGGACTGACGTTAAACGA',
is_aligned=True)
        Clade(branch_length=0.0, name='C00000763')
            BranchColor(blue=0, green=0, red=255)
            Sequence(type='dna')
                MolSeq(value='CCTTTcTATGTtCTGGACTGACGTTAAACGA',
is_aligned=True)

>>> Phylo.write(tree, myfile, 'phyloxml')
1
>>> tree2 = Phylo.read(myfile, 'phyloxml')
>>> print tree2
Phylogeny(rooted=True, branch_length_unit='SNV')
    Clade(branch_length=0.0, name='N1')
        Clade(branch_length=0.0, name='C00000761')
            BranchColor(blue=0, green=128, red=0)
            Sequence(type='dna')
                MolSeq(value='CCTTTCTATGTTCTGGACTGACGTTAAACGA')
        Clade(branch_length=0.0, name='C00000763')
            BranchColor(blue=0, green=0, red=255)
            Sequence(type='dna')
                MolSeq(value='CCTTTcTATGTtCTGGACTGACGTTAAACGA')



Cheers
Tanya





On 20/03/12 22:11, Eric Talevich wrote:
> Hi Tanya,
> 
> In case you haven't solved this yet, could you post some small portion
> of the Newick tree you're working with? It's possible that your tree is
> oddly formatted, and the Newick parser isn't picking up the internal
> node labels in the first place.
> 
> In the current version of Biopython (1.59), this seems to work fine:
> 
> from Bio import Phylo
> # Example file from our test suite
> tree = Phylo.read("Tests/Nexus/int_node_labels.nwk", "newick")
> # Print to the console
> print tree.format("newick")
> # To write the tree to a file, this is preferred:
> Phylo.write(tree, "my_new_file.nwk", "newick")
> 
> 
> Cheers,
> Eric
> 
> 
> On Fri, Mar 16, 2012 at 8:13 AM, Tanya Golubchik
> <golubchi at stats.ox.ac.uk <mailto:golubchi at stats.ox.ac.uk>> wrote:
> 
>     Dear all,
> 
>     I may be missing something in the documentation, but I can't seem to
>     figure out how to write newick trees with internal node names (preserved
>     as plain text). I think in some versions of Bio.Phylo a call to
>     tree.format('newick') accomplished this by default, but currently I
>     can't replicate this behaviour and get a tree with unnamed internal
>     nodes.
> 
>     Any pointers would be appreciated!
> 
>     Thanks
>     Tanya
>     _______________________________________________
>     Biopython mailing list  -  Biopython at lists.open-bio.org
>     <mailto:Biopython at lists.open-bio.org>
>     http://lists.open-bio.org/mailman/listinfo/biopython
> 
> 


More information about the Biopython mailing list