How can I get the corresponding bootstrap number to a split (bipartition)?

92 views
Skip to first unread message

Will Chandler

unread,
Jun 8, 2016, 12:08:43 AM6/8/16
to DendroPy Users
I have a set of files, each containing one tree in Newick format, with bootstrap numbers. How can I get the bootstrap value corresponding to the edge which was removed to make a split?

I got the splits and edges as so:

tree = Tree.get_from_path(file_path, "newick", taxon_namespace=namespace)
_all_splits = tree.bipartition_edge_map

Then I loop through the _all_splits dictionary [using _all_splits.iteritems()] for each key (Bipartition object) and value (Edge object). As a placeholder for what I need, I've been using Edge.length. Since the Edge value for each Bipartition key is the edge corresponding to that split, basically I just need to know how to get the Edge's bootstrap number without having to read through the file and extract them myself.

Thanks for any help.

Jeet Sukumaran

unread,
Jun 8, 2016, 12:12:33 AM6/8/16
to dendrop...@googlegroups.com
How are the bootstrap values stored in the file? As internal node
labels? As comments? As edge lengths?

On 6/8/16 12:08 AM, Will Chandler wrote:
> I have a set of files, each containing one tree in Newick format, with
> bootstrap numbers. How can I get the bootstrap value corresponding to
> the edge which was removed to make a split?
>
> I got the splits and edges as so:
>
> tree = Tree.get_from_path(file_path, "newick", taxon_namespace=namespace)
> _all_splits = tree.bipartition_edge_map
>
> Then I loop through the _all_splits dictionary [using
> _all_splits.iteritems()] for each key (Bipartition object) and
> value (Edge object). As a placeholder for what I need, I've been using
> Edge.length. Since the Edgevalue for each Bipartition key is the edge
> corresponding to that split, basically I just need to know how to get
> the Edge's bootstrap number without having to read through the file and
> extract them myself.
>
> Thanks for any help.
>
> --
> You received this message because you are subscribed to the Google
> Groups "DendroPy Users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to dendropy-user...@googlegroups.com
> <mailto:dendropy-user...@googlegroups.com>.
> For more options, visit https://groups.google.com/d/optout.

--



--------------------------------------
Jeet Sukumaran
--------------------------------------
jeetsu...@gmail.com
--------------------------------------
Blog/Personal Pages:
http://jeetworks.org/
GitHub Repositories:
http://github.com/jeetsukumaran
Photographs (as stream):
http://www.flickr.com/photos/jeetsukumaran/
Photographs (by galleries):
http://www.flickr.com/photos/jeetsukumaran/sets/
--------------------------------------

Will Chandler

unread,
Jun 8, 2016, 12:45:51 AM6/8/16
to DendroPy Users
They're stored like in this format:


I am using this "hack" function to pull out the numbers, but would rather use something built-in.

def get_bootstraps(data):
return [piece[:2] for piece in data.split(')') if piece[:2].isdigit()]

Where "data" is the raw file contents -- the newick string.




On Wednesday, June 8, 2016 at 12:12:33 AM UTC-4, Jeet Sukumaran wrote:
How are the bootstrap values stored in the file? As internal node
labels? As comments? As edge lengths?

On 6/8/16 12:08 AM, Will Chandler wrote:
> I have a set of files, each containing one tree in Newick format, with
> bootstrap numbers. How can I get the bootstrap value corresponding to
> the edge which was removed to make a split?
>
> I got the splits and edges as so:
>
> tree = Tree.get_from_path(file_path, "newick", taxon_namespace=namespace)
> _all_splits = tree.bipartition_edge_map
>
> Then I loop through the _all_splits dictionary [using
> _all_splits.iteritems()] for each key (Bipartition object) and
> value (Edge object). As a placeholder for what I need, I've been using
> Edge.length. Since the Edgevalue for each Bipartition key is the edge
> corresponding to that split, basically I just need to know how to get
> the Edge's bootstrap number without having to read through the file and
> extract them myself.
>
> Thanks for any help.
>
> --
> You received this message because you are subscribed to the Google
> Groups "DendroPy Users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to dendropy-user...@googlegroups.com

Jeet Sukumaran

unread,
Jun 8, 2016, 8:37:01 AM6/8/16
to dendrop...@googlegroups.com
This information will by default be parsed as (string) labels on the
associated nodes.

~~~
tree.encode_bipartitions()
for b in tree.bipartition_edge_map:
edge = tree.bipartition_edge_map[b]
support = float(edge.head_node.label)
print(support)
~~~

Alternatively:

~~~
tree.encode_bipartitions()
for nd in tree:
support = float(nd.label)
bipartition = nd.edge.bipartition
print("{}: {}".format(bipartition, support))
~~~
> > an email to dendropy-user...@googlegroups.com <javascript:>
> > <mailto:dendropy-user...@googlegroups.com <javascript:>>.
> > For more options, visit https://groups.google.com/d/optout
> <https://groups.google.com/d/optout>.
>
> --
>
>
>
> --------------------------------------
> Jeet Sukumaran
> --------------------------------------
> jeetsu...@gmail.com <javascript:>
> --------------------------------------
> Blog/Personal Pages:
> http://jeetworks.org/
> GitHub Repositories:
> http://github.com/jeetsukumaran <http://github.com/jeetsukumaran>
> <http://www.flickr.com/photos/jeetsukumaran/sets/>
> --------------------------------------
>
> --
> You received this message because you are subscribed to the Google
> Groups "DendroPy Users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to dendropy-user...@googlegroups.com
> <mailto:dendropy-user...@googlegroups.com>.

Will Chandler

unread,
Jun 8, 2016, 2:34:50 PM6/8/16
to DendroPy Users
Sorry, I may have been a bit misleading. The link I posted is just the format of the Newick file with bootstraps I'm using -- my actual files have no strings in them. An example:

(0:0.0101840927893,((8:7.47093214137e-07,6:0.00972396196851)48:7.47093214137e-07,(((9:0.0206723482777,(((4:7.47093214137e-07,1:7.47093214137e-07)31:7.47093214137e-07,7:7.47093214137e-07)51:7.47093214137e-07,10:0.0100623536065)38:7.47093214137e-07)71:0.00999640825353,(5:7.47093214137e-07,2:7.47093214137e-07)95:0.0215823143978)33:7.47093214137e-07,3:0.0321207186687)84:0.0204664382225):0.0101840927893);

Where the bootstrap numbers are bold.

When I run the code you gave, head_node_label has NoneType.

>     > <mailto:dendropy-users+unsub...@googlegroups.com <javascript:>>.
>     > For more options, visit https://groups.google.com/d/optout
>     <https://groups.google.com/d/optout>.
>
>     --
>
>
>
>     --------------------------------------
>     Jeet Sukumaran
>     --------------------------------------
>     jeetsu...@gmail.com <javascript:>
>     --------------------------------------
>     Blog/Personal Pages:
>         http://jeetworks.org/
>     GitHub Repositories:
>         http://github.com/jeetsukumaran <http://github.com/jeetsukumaran>
>     Photographs (as stream):
>         http://www.flickr.com/photos/jeetsukumaran/
>     <http://www.flickr.com/photos/jeetsukumaran/>
>     Photographs (by galleries):
>         http://www.flickr.com/photos/jeetsukumaran/sets/
>     <http://www.flickr.com/photos/jeetsukumaran/sets/>
>     --------------------------------------
>
> --
> You received this message because you are subscribed to the Google
> Groups "DendroPy Users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to dendropy-user...@googlegroups.com

Jeet Sukumaran

unread,
Jun 8, 2016, 2:59:36 PM6/8/16
to dendrop...@googlegroups.com
Those numbers in bold are parsed as strings. It is up to you to coerce
them to values of types that you know them to be.

The "None" type is for cases where there are no internal node labels.
You will need special logic to handle those cases, e.g.

~~~
if nd.label is None:
support = 0.0 # (or None or something else)
else:
support = float(nd.label)
~~~

A full working example is at the bottom of this email.

There are some quirks with the NEWICK format you need to be aware of
when using bipartitions. These are covered in the Primer, and I suggest
you look through that carefully. The two biggest ones are:

(1) You will need to be sure to use the same taxon namespace instance to
manage all trees if you want to relate splits across trees or across files.
(2) The basal bifurcation of unrooted trees will be collapsed when
encoding bipartitions. DendroPy assumes trees are unrooted unless
explicitly told otherwise using either a "[&R]" token in the data string
or a ``rooting='force-rooted'`` in the read instruction.

I should also note that, for future reference, either with this software
or any other, issues such as this could be handle a lot more efficiently
if you were to provide a minimum working example (MWE) in your question,
as well as the fundamental/basic information required for someone else
to understand your problem. In this case, a sample tree would have been
not just helpful, but actually necessary.

~~~
#! /usr/bin/env python

import dendropy

s =
"(0:0.0101840927893,((8:7.47093214137e-07,6:0.00972396196851)48:7.47093214137e-07,(((9:0.0206723482777,(((4:7.47093214137e-07,1:7.47093214137e-07)31:7.47093214137e-07,7:7.47093214137e-07)51:7.47093214137e-07,10:0.0100623536065)38:7.47093214137e-07)71:0.00999640825353,(5:7.47093214137e-07,2:7.47093214137e-07)95:0.0215823143978)33:7.47093214137e-07,3:0.0321207186687)84:0.0204664382225):0.0101840927893);"
tree = dendropy.Tree.get(data=s, schema="newick")
tree.encode_bipartitions()
for nd in tree:
try:
nd.support = float(nd.label)
except TypeError:
nd.support = None
if nd.support is not None:
print("{}: {}".format(
nd.bipartition.split_as_bitstring(),
nd.support))

~~~



On 6/8/16 2:34 PM, Will Chandler wrote:
> Sorry, I may have been a bit misleading. The link I posted is just the
> format of the Newick file with bootstraps I'm using -- my actual files
> have no strings in them. An example:
>
> (0:0.0101840927893,((8:7.47093214137e-07,6:0.00972396196851)*48*:7.47093214137e-07,(((9:0.0206723482777,(((4:7.47093214137e-07,1:7.47093214137e-07)*31*:7.47093214137e-07,7:7.47093214137e-07)*51*:7.47093214137e-07,10:0.0100623536065)*38*:7.47093214137e-07)*71*:0.00999640825353,(5:7.47093214137e-07,2:7.47093214137e-07)*95*:0.0215823143978)*33*:7.47093214137e-07,3:0.0321207186687)*84*:0.0204664382225):0.0101840927893);
> > > <mailto:dendropy-user...@googlegroups.com
> <javascript:> <javascript:>>.
> > > For more options, visit https://groups.google.com/d/optout
> <https://groups.google.com/d/optout>
> > <https://groups.google.com/d/optout
> <https://groups.google.com/d/optout>>.
> >
> > --
> >
> >
> >
> > --------------------------------------
> > Jeet Sukumaran
> > --------------------------------------
> > jeetsu...@gmail.com <javascript:>
> > --------------------------------------
> > Blog/Personal Pages:
> > http://jeetworks.org/
> > GitHub Repositories:
> > http://github.com/jeetsukumaran
> <http://github.com/jeetsukumaran> <http://github.com/jeetsukumaran
> <http://github.com/jeetsukumaran>>
> > Photographs (as stream):
> > http://www.flickr.com/photos/jeetsukumaran/
> <http://www.flickr.com/photos/jeetsukumaran/>
> > <http://www.flickr.com/photos/jeetsukumaran/
> <http://www.flickr.com/photos/jeetsukumaran/>>
> > Photographs (by galleries):
> > http://www.flickr.com/photos/jeetsukumaran/sets/
> <http://www.flickr.com/photos/jeetsukumaran/sets/>
> > <http://www.flickr.com/photos/jeetsukumaran/sets/
> <http://www.flickr.com/photos/jeetsukumaran/sets/>>
> > --------------------------------------
> >
> > --
> > You received this message because you are subscribed to the Google
> > Groups "DendroPy Users" group.
> > To unsubscribe from this group and stop receiving emails from it,
> send
> > an email to dendropy-user...@googlegroups.com <javascript:>
> > <mailto:dendropy-user...@googlegroups.com <javascript:>>.
> > For more options, visit https://groups.google.com/d/optout
> <https://groups.google.com/d/optout>.
>
> --
>
>
>
> --------------------------------------
> Jeet Sukumaran
> --------------------------------------
> jeetsu...@gmail.com <javascript:>
> --------------------------------------
> Blog/Personal Pages:
> http://jeetworks.org/
> GitHub Repositories:
> http://github.com/jeetsukumaran <http://github.com/jeetsukumaran>
> Photographs (as stream):
> http://www.flickr.com/photos/jeetsukumaran/
> <http://www.flickr.com/photos/jeetsukumaran/>
> Photographs (by galleries):
> http://www.flickr.com/photos/jeetsukumaran/sets/
> <http://www.flickr.com/photos/jeetsukumaran/sets/>
> --------------------------------------
>
> --
> You received this message because you are subscribed to the Google
> Groups "DendroPy Users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to dendropy-user...@googlegroups.com
> <mailto:dendropy-user...@googlegroups.com>.
Reply all
Reply to author
Forward
0 new messages