[Biopython] help with confidence values on PhyloXML tree objects?
Eric Talevich
eric.talevich at gmail.com
Fri Dec 9 23:26:46 UTC 2011
Hi Jon,
On Fri, Dec 9, 2011 at 4:53 PM, Jon Sanders <jsanders at oeb.harvard.edu>wrote:
> So I have two problems.
>
>
> Problem 1: when importing my newick-formatted trees, which were generated
> in PyCogent, the terminal labels and branch labels are read in as
> confidence values because they're numerical. So
>
> ((((41:0.01494,44:0.00014)0.604:0...
>
> is read in with blank name='' values and 41, 44, 0.605, etc. as
> 'confidence' values.
>
Hmm, I'll take a look at the Newick parser. I think I've used numeric taxon
labels before without a problem, but PyCogent wasn't involved.
It might work if you can coax PyCogent into writing the Newick files with
an extra colon:
((((:41:0.01494,:44:0.00014):0.604:0...
> Problem 2: I would like to store multiple confidence values per node, but I
> can't figure out how to do it.
>
> I can get the plain old 'confidence' attribute set by:
>
> clade.confidence = .05
>
> but can't figure out how to add and set new confidence types. Any
> suggestions?
>
The confidence types are instances of the Bio.Phylo.PhyloXML.Confidence
class.
In PhyloXML trees, the attribute "clade.confidence" is actually a Python
property pointing to the first element of "clade.confidences", a list of
Confidence objects. It's syntax sugar to keep compatibility with Newick,
which just has a numeric value there.
You can use it like this:
from Bio.Phylo import PhyloXML
# Create new Confidence instances
a_bootstrap_value = PhyloXML.Confidence(83, type="bootstrap")
# The second argument is optional
a_posterior_probability = PhyloXML.Confidence(0.99)
# Select a clade from your tree to modify
a_clade = mytree.clade[...]
# Modify the list of Confidences directly
a_clade.confidences.append(a_bootstrap_value)
a_clade.confidences.append(a_posterior_probability)
If you've assigned multiple confidence values to a clade, using the
PhyloXML class, then the "clade.confidence" shortcut won't work anymore
because it's not clear which confidence you mean. So you'll have to use
e.g. clade.confidences[0] or clade.confidences[1], and save it the tree in
PhyloXML format to preserve the extra data.
Hope that helps.
Best regards,
Eric
More information about the Biopython
mailing list