Package Bio :: Package Nexus :: Module Trees :: Class Tree
[hide private]
[frames] | no frames]

Class Tree

source code

 object --+    
          |    
Nodes.Chain --+
              |
             Tree

Represents a tree using a chain of nodes with on predecessor (=ancestor)
and multiple successors (=subclades).

Instance Methods [hide private]
 
__init__(self, tree=None, weight=1.0, rooted=False, name='', data=<class 'Bio.Nexus.Trees.NodeData'>, values_are_support=False, max_support=1.0)
Ntree(self,tree).
source code
 
_parse(self, tree)
Parses (a,b,c...)[[[xx]:]yy] into subcomponents and travels down recursively.
source code
 
_add_subtree(self, parent_id=None, tree=None)
Adds leaf or tree (in newick format) to a parent_id.
source code
 
_add_nodedata(self, nd, st)
Add data to the node parsed from the comments, taxon and support.
source code
 
_get_values(self, text)
Extracts values (support/branchlength) from xx[:yyy], xx.
source code
 
_walk(self, node=None)
Return all node_ids downwards from a node.
source code
 
node(self, node_id)
Return the instance of node_id.
source code
 
split(self, parent_id=None, n=2, branchlength=1.0)
Speciation: generates n (default two) descendants of a node.
source code
 
search_taxon(self, taxon)
Returns the first matching taxon in self.data.taxon.
source code
 
prune(self, taxon)
Prunes a terminal taxon from the tree.
source code
 
get_taxa(self, node_id=None)
Return a list of all otus downwards from a node.
source code
 
get_terminals(self)
Return a list of all terminal nodes.
source code
 
is_terminal(self, node)
Returns True if node is a terminal node.
source code
 
is_internal(self, node)
Returns True if node is an internal node.
source code
 
is_preterminal(self, node)
Returns True if all successors of a node are terminal ones.
source code
 
count_terminals(self, node=None)
Counts the number of terminal nodes that are attached to a node.
source code
 
collapse_genera(self, space_equals_underscore=True)
Collapses all subtrees which belong to the same genus (i.e share the same first word in their taxon name.)
source code
 
sum_branchlength(self, root=None, node=None)
Adds up the branchlengths from root (default self.root) to node.
source code
 
set_subtree(self, node)
Return subtree as a set of nested sets.
source code
 
is_identical(self, tree2)
Compare tree and tree2 for identity.
source code
 
is_compatible(self, tree2, threshold, strict=True)
Compares branches with support>threshold for compatibility.
source code
 
common_ancestor(self, node1, node2)
Return the common ancestor that connects two nodes.
source code
 
distance(self, node1, node2)
Add and return the sum of the branchlengths between two nodes.
source code
 
is_monophyletic(self, taxon_list)
Return node_id of common ancestor if taxon_list is monophyletic, -1 otherwise.
source code
 
is_bifurcating(self, node=None)
Return True if tree downstream of node is strictly bifurcating.
source code
 
branchlength2support(self)
Move values stored in data.branchlength to data.support, and set branchlength to 0.0
source code
 
convert_absolute_support(self, nrep)
Convert absolute support (clade-count) to rel.
source code
 
has_support(self, node=None)
Returns True if any of the nodes has data.support != None.
source code
 
randomize(self, ntax=None, taxon_list=None, branchlength=1.0, branchlength_sd=None, bifurcate=True)
Generates a random tree with ntax taxa and/or taxa from taxlabels.
source code
 
display(self)
Quick and dirty lists of all nodes.
source code
 
to_string(self, support_as_branchlengths=False, branchlengths_only=False, plain=True, plain_newick=False, ladderize=None, ignore_comments=True)
Return a paup compatible tree line.
source code
 
__str__(self)
Short version of to_string(), gives plain tree
source code
 
unroot(self)
Defines a unrooted Tree structure, using data of a rooted Tree.
source code
 
root_with_outgroup(self, outgroup=None) source code
 
merge_with_support(self, bstrees=None, constree=None, threshold=0.5, outgroup=None)
Merges clade support (from consensus or list of bootstrap-trees) with phylogeny.
source code

Inherited from Nodes.Chain: add, all_ids, collapse, is_parent_of, kill, link, trace, unlink

Inherited from Nodes.Chain (private): _get_id

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __subclasshook__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, tree=None, weight=1.0, rooted=False, name='', data=<class 'Bio.Nexus.Trees.NodeData'>, values_are_support=False, max_support=1.0)
(Constructor)

source code 
Ntree(self,tree).

Overrides: object.__init__

node(self, node_id)

source code 
Return the instance of node_id.

node = node(self,node_id)

split(self, parent_id=None, n=2, branchlength=1.0)

source code 
Speciation: generates n (default two) descendants of a node.

[new ids] = split(self,parent_id=None,n=2,branchlength=1.0):

search_taxon(self, taxon)

source code 
Returns the first matching taxon in self.data.taxon. Not restricted to terminal nodes.

node_id = search_taxon(self,taxon)

prune(self, taxon)

source code 
Prunes a terminal taxon from the tree.

id_of_previous_node = prune(self,taxon)
If taxon is from a bifurcation, the connectiong node will be collapsed
and its branchlength added to remaining terminal node. This might be no
longer a meaningful value'

get_taxa(self, node_id=None)

source code 
Return a list of all otus downwards from a node.

nodes = get_taxa(self,node_id=None)

sum_branchlength(self, root=None, node=None)

source code 
Adds up the branchlengths from root (default self.root) to node.

sum = sum_branchlength(self,root=None,node=None)

set_subtree(self, node)

source code 
Return subtree as a set of nested sets.

sets = set_subtree(self,node)

is_identical(self, tree2)

source code 
Compare tree and tree2 for identity.

result = is_identical(self,tree2)

is_compatible(self, tree2, threshold, strict=True)

source code 
Compares branches with support>threshold for compatibility.

result = is_compatible(self,tree2,threshold)

common_ancestor(self, node1, node2)

source code 
Return the common ancestor that connects two nodes.

node_id = common_ancestor(self,node1,node2)

distance(self, node1, node2)

source code 
Add and return the sum of the branchlengths between two nodes.
dist = distance(self,node1,node2)

is_monophyletic(self, taxon_list)

source code 
Return node_id of common ancestor if taxon_list is monophyletic, -1 otherwise.

result = is_monophyletic(self,taxon_list)

branchlength2support(self)

source code 
Move values stored in data.branchlength to data.support, and set branchlength to 0.0

This is necessary when support has been stored as branchlength (e.g. paup), and has thus
been read in as branchlength.

convert_absolute_support(self, nrep)

source code 
Convert absolute support (clade-count) to rel. frequencies.

Some software (e.g. PHYLIP consense) just calculate how often clades appear, instead of
calculating relative frequencies.

randomize(self, ntax=None, taxon_list=None, branchlength=1.0, branchlength_sd=None, bifurcate=True)

source code 
Generates a random tree with ntax taxa and/or taxa from taxlabels.

new_tree = randomize(self,ntax=None,taxon_list=None,branchlength=1.0,branchlength_sd=None,bifurcate=True)
Trees are bifurcating by default. (Polytomies not yet supported).

__str__(self)
(Informal representation operator)

source code 
Short version of to_string(), gives plain tree

Overrides: object.__str__

merge_with_support(self, bstrees=None, constree=None, threshold=0.5, outgroup=None)

source code 
Merges clade support (from consensus or list of bootstrap-trees) with phylogeny.

tree=merge_bootstrap(phylo,bs_tree=<list_of_trees>)
or
tree=merge_bootstrap(phylo,consree=consensus_tree with clade support)