Back to index

python-biopython  1.60
Public Member Functions | Public Attributes | Private Member Functions
Bio.Phylo.BaseTree.TreeMixin Class Reference
Inheritance diagram for Bio.Phylo.BaseTree.TreeMixin:
Inheritance graph
[legend]

List of all members.

Public Member Functions

def find_any
def find_elements
def find_clades
def get_path
def get_nonterminals
def get_terminals
def trace
def common_ancestor
def count_terminals
def depths
def distance
def is_bifurcating
def is_monophyletic
def is_parent_of
def is_preterminal
def total_branch_length
def collapse
def collapse_all
def ladderize
def prune
def split

Public Attributes

 root

Private Member Functions

def _filter_search

Detailed Description

Methods for Tree- and Clade-based classes.

This lets `Tree` and `Clade` support the same traversal and searching
operations without requiring Clade to inherit from Tree, so Clade isn't
required to have all of Tree's attributes -- just ``root`` (a Clade
instance) and ``is_terminal``.

Definition at line 232 of file BaseTree.py.


Member Function Documentation

def Bio.Phylo.BaseTree.TreeMixin._filter_search (   self,
  filter_func,
  order,
  follow_attrs 
) [private]
Perform a BFS or DFS traversal through all elements in this tree.

:returns: generator of all elements for which `filter_func` is True.

Definition at line 242 of file BaseTree.py.

00242 
00243     def _filter_search(self, filter_func, order, follow_attrs):
00244         """Perform a BFS or DFS traversal through all elements in this tree.
00245 
00246         :returns: generator of all elements for which `filter_func` is True.
00247         """
00248         order_opts = {'preorder': _preorder_traverse,
00249                       'postorder': _postorder_traverse,
00250                       'level': _level_traverse}
00251         try:
00252             order_func = order_opts[order]
00253         except KeyError:
00254             raise ValueError("Invalid order '%s'; must be one of: %s"
00255                              % (order, tuple(order_opts.keys())))
00256         if follow_attrs:
00257             get_children = _sorted_attrs
00258             root = self
00259         else:
00260             get_children = lambda elem: elem.clades
00261             root = self.root
00262         return itertools.ifilter(filter_func, order_func(root, get_children))

Here is the caller graph for this function:

def Bio.Phylo.BaseTree.TreeMixin.collapse (   self,
  target = None,
  kwargs 
)
Deletes target from the tree, relinking its children to its parent.

:returns: the parent clade.

Definition at line 534 of file BaseTree.py.

00534 
00535     def collapse(self, target=None, **kwargs):
00536         """Deletes target from the tree, relinking its children to its parent.
00537 
00538         :returns: the parent clade.
00539         """
00540         path = self.get_path(target, **kwargs)
00541         if not path:
00542             raise ValueError("couldn't collapse %s in this tree"
00543                              % (target or kwargs))
00544         if len(path) == 1:
00545             parent = self.root
00546         else:
00547             parent = path[-2]
00548         popped = parent.clades.pop(parent.clades.index(path[-1]))
00549         extra_length = popped.branch_length or 0
00550         for child in popped:
00551             child.branch_length += extra_length
00552         parent.clades.extend(popped.clades)
00553         return parent

Here is the call graph for this function:

Here is the caller graph for this function:

def Bio.Phylo.BaseTree.TreeMixin.collapse_all (   self,
  target = None,
  kwargs 
)
Collapse all the descendents of this tree, leaving only terminals.

Total branch lengths are preserved, i.e. the distance to each terminal
stays the same.

For example, this will safely collapse nodes with poor bootstrap
support:

    >>> tree.collapse_all(lambda c: c.confidence is not None and
    ...                   c.confidence < 70)

This implementation avoids strange side-effects by using level-order
traversal and testing all clade properties (versus the target
specification) up front. In particular, if a clade meets the target
specification in the original tree, it will be collapsed.  For example,
if the condition is:

    >>> tree.collapse_all(lambda c: c.branch_length < 0.1)

Collapsing a clade's parent node adds the parent's branch length to the
child, so during the execution of collapse_all, a clade's branch_length
may increase. In this implementation, clades are collapsed according to
their properties in the original tree, not the properties when tree
traversal reaches the clade. (It's easier to debug.) If you want the
other behavior (incremental testing), modifying the source code of this
function is straightforward.

Definition at line 554 of file BaseTree.py.

00554 
00555     def collapse_all(self, target=None, **kwargs):
00556         """Collapse all the descendents of this tree, leaving only terminals.
00557 
00558         Total branch lengths are preserved, i.e. the distance to each terminal
00559         stays the same.
00560 
00561         For example, this will safely collapse nodes with poor bootstrap
00562         support:
00563 
00564             >>> tree.collapse_all(lambda c: c.confidence is not None and
00565             ...                   c.confidence < 70)
00566 
00567         This implementation avoids strange side-effects by using level-order
00568         traversal and testing all clade properties (versus the target
00569         specification) up front. In particular, if a clade meets the target
00570         specification in the original tree, it will be collapsed.  For example,
00571         if the condition is:
00572 
00573             >>> tree.collapse_all(lambda c: c.branch_length < 0.1)
00574 
00575         Collapsing a clade's parent node adds the parent's branch length to the
00576         child, so during the execution of collapse_all, a clade's branch_length
00577         may increase. In this implementation, clades are collapsed according to
00578         their properties in the original tree, not the properties when tree
00579         traversal reaches the clade. (It's easier to debug.) If you want the
00580         other behavior (incremental testing), modifying the source code of this
00581         function is straightforward.
00582         """
00583         # Read the iterable into a list to protect against in-place changes
00584         matches = list(self.find_clades(target, False, 'level', **kwargs))
00585         if not matches:
00586             # No matching nodes to collapse
00587             return
00588         # Skip the root node -- it can't be collapsed
00589         if matches[0] == self.root:
00590             matches.pop(0)
00591         for clade in matches:
00592             self.collapse(clade)

Here is the call graph for this function:

def Bio.Phylo.BaseTree.TreeMixin.common_ancestor (   self,
  targets,
  more_targets 
)
Most recent common ancestor (clade) of all the given targets.

Edge cases:
- If no target is given, returns self.root
- If 1 target is given, returns the target
- If any target is not found in this tree, raises a ValueError

Definition at line 390 of file BaseTree.py.

00390 
00391     def common_ancestor(self, targets, *more_targets):
00392         """Most recent common ancestor (clade) of all the given targets.
00393 
00394         Edge cases:
00395         - If no target is given, returns self.root
00396         - If 1 target is given, returns the target
00397         - If any target is not found in this tree, raises a ValueError
00398         """
00399         paths = [self.get_path(t)
00400                  for t in _combine_args(targets, *more_targets)]
00401         # Validation -- otherwise izip throws a spooky error below
00402         for p, t in zip(paths, targets):
00403             if p is None:
00404                 raise ValueError("target %s is not in this tree" % repr(t))
00405         mrca = self.root
00406         for level in itertools.izip(*paths):
00407             ref = level[0]
00408             for other in level[1:]:
00409                 if ref is not other:
00410                     break
00411             else:
00412                 mrca = ref
00413             if ref is not mrca:
00414                 break
00415         return mrca

Here is the call graph for this function:

Here is the caller graph for this function:

Counts the number of terminal (leaf) nodes within this tree.

Definition at line 416 of file BaseTree.py.

00416 
00417     def count_terminals(self):
00418         """Counts the number of terminal (leaf) nodes within this tree."""
00419         return _sugar.iterlen(self.find_clades(terminal=True))

Here is the call graph for this function:

def Bio.Phylo.BaseTree.TreeMixin.depths (   self,
  unit_branch_lengths = False 
)
Create a mapping of tree clades to depths (by branch length).

:Parameters:
    unit_branch_lengths : bool
If True, count only the number of branches (levels in the tree).
By default the distance is the cumulative branch length leading
to the clade.

:returns: dict of {clade: depth}, where keys are all of the Clade
    instances in the tree, and values are the distance from the root to
    each clade (including terminals).

Definition at line 420 of file BaseTree.py.

00420 
00421     def depths(self, unit_branch_lengths=False):
00422         """Create a mapping of tree clades to depths (by branch length).
00423 
00424         :Parameters:
00425             unit_branch_lengths : bool
00426                 If True, count only the number of branches (levels in the tree).
00427                 By default the distance is the cumulative branch length leading
00428                 to the clade.
00429 
00430         :returns: dict of {clade: depth}, where keys are all of the Clade
00431             instances in the tree, and values are the distance from the root to
00432             each clade (including terminals).
00433         """
00434         if unit_branch_lengths:
00435             depth_of = lambda c: 1
00436         else:
00437             depth_of = lambda c: c.branch_length or 0
00438         depths = {}
00439         def update_depths(node, curr_depth):
00440             depths[node] = curr_depth
00441             for child in node.clades:
00442                 new_depth = curr_depth + depth_of(child)
00443                 update_depths(child, new_depth)
00444         update_depths(self.root, self.root.branch_length or 0)
00445         return depths

Here is the caller graph for this function:

def Bio.Phylo.BaseTree.TreeMixin.distance (   self,
  target1,
  target2 = None 
)
Calculate the sum of the branch lengths between two targets.

If only one target is specified, the other is the root of this tree.

Definition at line 446 of file BaseTree.py.

00446 
00447     def distance(self, target1, target2=None):
00448         """Calculate the sum of the branch lengths between two targets.
00449 
00450         If only one target is specified, the other is the root of this tree.
00451         """
00452         if target2 is None:
00453             return sum(n.branch_length for n in self.get_path(target1)
00454                        if n.branch_length is not None)
00455         mrca = self.common_ancestor(target1, target2)
00456         return mrca.distance(target1) + mrca.distance(target2)

Here is the call graph for this function:

def Bio.Phylo.BaseTree.TreeMixin.find_any (   self,
  args,
  kwargs 
)
Return the first element found by find_elements(), or None.

This is also useful for checking whether any matching element exists in
the tree, and can be used in a conditional expression.

Definition at line 263 of file BaseTree.py.

00263 
00264     def find_any(self, *args, **kwargs):
00265         """Return the first element found by find_elements(), or None.
00266 
00267         This is also useful for checking whether any matching element exists in
00268         the tree, and can be used in a conditional expression.
00269         """
00270         hits = self.find_elements(*args, **kwargs)
00271         try:
00272             return hits.next()
00273         except StopIteration:
00274             return None

Here is the call graph for this function:

def Bio.Phylo.BaseTree.TreeMixin.find_clades (   self,
  target = None,
  terminal = None,
  order = 'preorder',
  kwargs 
)
Find each clade containing a matching element.

That is, find each element as with find_elements(), but return the
corresponding clade object. (This is usually what you want.)

:returns: an iterable through all matching objects, searching
    depth-first (preorder) by default.

Definition at line 324 of file BaseTree.py.

00324 
00325             **kwargs):
00326         """Find each clade containing a matching element.
00327 
00328         That is, find each element as with find_elements(), but return the
00329         corresponding clade object. (This is usually what you want.)
00330 
00331         :returns: an iterable through all matching objects, searching
00332             depth-first (preorder) by default.
00333         """
00334         def match_attrs(elem):
00335             orig_clades = elem.__dict__.pop('clades')
00336             found = elem.find_any(target, **kwargs)
00337             elem.clades = orig_clades
00338             return (found is not None)
00339         if terminal is None:
00340             is_matching_elem = match_attrs
00341         else:
00342             def is_matching_elem(elem):
00343                 return ((elem.is_terminal() == terminal) and
00344                         match_attrs(elem))
00345         return self._filter_search(is_matching_elem, order, False)

Here is the call graph for this function:

Here is the caller graph for this function:

def Bio.Phylo.BaseTree.TreeMixin.find_elements (   self,
  target = None,
  terminal = None,
  order = 'preorder',
  kwargs 
)
Find all tree elements matching the given attributes.

The arbitrary keyword arguments indicate the attribute name of the
sub-element and the value to match: string, integer or boolean. Strings
are evaluated as regular expression matches; integers are compared
directly for equality, and booleans evaluate the attribute's truth value
(True or False) before comparing. To handle nonzero floats, search with
a boolean argument, then filter the result manually.

If no keyword arguments are given, then just the class type is used for
matching.

The result is an iterable through all matching objects, by depth-first
search. (Not necessarily the same order as the elements appear in the
source file!)

:Parameters:
    target : TreeElement instance, type, dict, or callable
Specifies the characteristics to search for. (The default,
TreeElement, matches any standard Bio.Phylo type.)
    terminal : bool
A boolean value to select for or against terminal nodes (a.k.a.
leaf nodes). True searches for only terminal nodes, False
excludes terminal nodes, and the default, None, searches both
terminal and non-terminal nodes, as well as any tree elements
lacking the ``is_terminal`` method.
    order : {'preorder', 'postorder', 'level'}
Tree traversal order: 'preorder' (default) is depth-first
search, 'postorder' is DFS with child nodes preceding parents,
and 'level' is breadth-first search.

Example
-------

>>> from Bio.Phylo.IO import PhyloXMIO
>>> phx = PhyloXMLIO.read('phyloxml_examples.xml')
>>> matches = phx.phylogenies[5].find_elements(code='OCTVU')
>>> matches.next()
Taxonomy(code='OCTVU', scientific_name='Octopus vulgaris')

Definition at line 276 of file BaseTree.py.

00276 
00277             **kwargs):
00278         """Find all tree elements matching the given attributes.
00279 
00280         The arbitrary keyword arguments indicate the attribute name of the
00281         sub-element and the value to match: string, integer or boolean. Strings
00282         are evaluated as regular expression matches; integers are compared
00283         directly for equality, and booleans evaluate the attribute's truth value
00284         (True or False) before comparing. To handle nonzero floats, search with
00285         a boolean argument, then filter the result manually.
00286 
00287         If no keyword arguments are given, then just the class type is used for
00288         matching.
00289 
00290         The result is an iterable through all matching objects, by depth-first
00291         search. (Not necessarily the same order as the elements appear in the
00292         source file!)
00293 
00294         :Parameters:
00295             target : TreeElement instance, type, dict, or callable
00296                 Specifies the characteristics to search for. (The default,
00297                 TreeElement, matches any standard Bio.Phylo type.)
00298             terminal : bool
00299                 A boolean value to select for or against terminal nodes (a.k.a.
00300                 leaf nodes). True searches for only terminal nodes, False
00301                 excludes terminal nodes, and the default, None, searches both
00302                 terminal and non-terminal nodes, as well as any tree elements
00303                 lacking the ``is_terminal`` method.
00304             order : {'preorder', 'postorder', 'level'}
00305                 Tree traversal order: 'preorder' (default) is depth-first
00306                 search, 'postorder' is DFS with child nodes preceding parents,
00307                 and 'level' is breadth-first search.
00308 
00309         Example
00310         -------
00311 
00312         >>> from Bio.Phylo.IO import PhyloXMIO
00313         >>> phx = PhyloXMLIO.read('phyloxml_examples.xml')
00314         >>> matches = phx.phylogenies[5].find_elements(code='OCTVU')
00315         >>> matches.next()
00316         Taxonomy(code='OCTVU', scientific_name='Octopus vulgaris')
00317 
00318         """
00319         if terminal is not None:
00320             kwargs['terminal'] = terminal
00321         is_matching_elem = _combine_matchers(target, kwargs, False)
00322         return self._filter_search(is_matching_elem, order, True)

Here is the call graph for this function:

Here is the caller graph for this function:

def Bio.Phylo.BaseTree.TreeMixin.get_nonterminals (   self,
  order = 'preorder' 
)
Get a list of all of this tree's nonterminal (internal) nodes.

Definition at line 370 of file BaseTree.py.

00370 
00371     def get_nonterminals(self, order='preorder'):
00372         """Get a list of all of this tree's nonterminal (internal) nodes."""
00373         return list(self.find_clades(terminal=False, order=order))

Here is the call graph for this function:

def Bio.Phylo.BaseTree.TreeMixin.get_path (   self,
  target = None,
  kwargs 
)
List the clades directly between this root and the given target.

:returns: list of all clade objects along this path, ending with the
    given target, but excluding the root clade.

Definition at line 346 of file BaseTree.py.

00346 
00347     def get_path(self, target=None, **kwargs):
00348         """List the clades directly between this root and the given target.
00349 
00350         :returns: list of all clade objects along this path, ending with the
00351             given target, but excluding the root clade.
00352         """
00353         # Only one path will work -- ignore weights and visits
00354         path = []
00355         match = _combine_matchers(target, kwargs, True)
00356         def check_in_path(v):
00357             if match(v):
00358                 path.append(v)
00359                 return True
00360             elif v.is_terminal():
00361                 return False
00362             for child in v:
00363                 if check_in_path(child):
00364                     path.append(v)
00365                     return True
00366             return False
00367         if not check_in_path(self.root):
00368             return None
00369         return path[-2::-1]

Here is the call graph for this function:

Here is the caller graph for this function:

def Bio.Phylo.BaseTree.TreeMixin.get_terminals (   self,
  order = 'preorder' 
)
Get a list of all of this tree's terminal (leaf) nodes.

Definition at line 374 of file BaseTree.py.

00374 
00375     def get_terminals(self, order='preorder'):
00376         """Get a list of all of this tree's terminal (leaf) nodes."""
00377         return list(self.find_clades(terminal=True, order=order))

Here is the call graph for this function:

Here is the caller graph for this function:

Return True if tree downstream of node is strictly bifurcating.

I.e., all nodes have either 2 or 0 children (internal or external,
respectively). The root may have 3 descendents and still be considered
part of a bifurcating tree, because it has no ancestor.

Definition at line 457 of file BaseTree.py.

00457 
00458     def is_bifurcating(self):
00459         """Return True if tree downstream of node is strictly bifurcating.
00460 
00461         I.e., all nodes have either 2 or 0 children (internal or external,
00462         respectively). The root may have 3 descendents and still be considered
00463         part of a bifurcating tree, because it has no ancestor.
00464         """
00465         # Root can be trifurcating
00466         if isinstance(self, Tree) and len(self.root) == 3:
00467             return (self.root.clades[0].is_bifurcating() and
00468                     self.root.clades[1].is_bifurcating() and
00469                     self.root.clades[2].is_bifurcating())
00470         if len(self.root) == 2:
00471             return (self.root.clades[0].is_bifurcating() and
00472                     self.root.clades[1].is_bifurcating())
00473         if len(self.root) == 0:
00474             return True
00475         return False

def Bio.Phylo.BaseTree.TreeMixin.is_monophyletic (   self,
  terminals,
  more_terminals 
)
MRCA of terminals if they comprise a complete subclade, or False.

I.e., there exists a clade such that its terminals are the same set as
the given targets.

The given targets must be terminals of the tree.

To match both `Bio.Nexus.Trees` and the other multi-target methods in
Bio.Phylo, arguments to this method can be specified either of two ways:
(i) as a single list of targets, or (ii) separately specified targets,
e.g. is_monophyletic(t1, t2, t3) -- but not both.

For convenience, this method returns the common ancestor (MCRA) of the
targets if they are monophyletic (instead of the value True), and False
otherwise.

:returns: common ancestor if terminals are monophyletic, otherwise False.

Definition at line 476 of file BaseTree.py.

00476 
00477     def is_monophyletic(self, terminals, *more_terminals):
00478         """MRCA of terminals if they comprise a complete subclade, or False.
00479 
00480         I.e., there exists a clade such that its terminals are the same set as
00481         the given targets.
00482 
00483         The given targets must be terminals of the tree.
00484 
00485         To match both `Bio.Nexus.Trees` and the other multi-target methods in
00486         Bio.Phylo, arguments to this method can be specified either of two ways:
00487         (i) as a single list of targets, or (ii) separately specified targets,
00488         e.g. is_monophyletic(t1, t2, t3) -- but not both.
00489 
00490         For convenience, this method returns the common ancestor (MCRA) of the
00491         targets if they are monophyletic (instead of the value True), and False
00492         otherwise.
00493 
00494         :returns: common ancestor if terminals are monophyletic, otherwise False.
00495         """
00496         target_set = set(_combine_args(terminals, *more_terminals))
00497         current = self.root
00498         while True:
00499             if set(current.get_terminals()) == target_set:
00500                 return current
00501             # Try a narrower subclade
00502             for subclade in current.clades:
00503                 if set(subclade.get_terminals()).issuperset(target_set):
00504                     current = subclade
00505                     break
00506             else:
00507                 return False

Here is the call graph for this function:

def Bio.Phylo.BaseTree.TreeMixin.is_parent_of (   self,
  target = None,
  kwargs 
)
True if target is a descendent of this tree.

Not required to be a direct descendent.

To check only direct descendents of a clade, simply use list membership
testing: ``if subclade in clade: ...``

Definition at line 508 of file BaseTree.py.

00508 
00509     def is_parent_of(self, target=None, **kwargs):
00510         """True if target is a descendent of this tree.
00511 
00512         Not required to be a direct descendent.
00513 
00514         To check only direct descendents of a clade, simply use list membership
00515         testing: ``if subclade in clade: ...``
00516         """
00517         return self.get_path(target, **kwargs) is not None

Here is the call graph for this function:

True if all direct descendents are terminal.

Definition at line 518 of file BaseTree.py.

00518 
00519     def is_preterminal(self):
00520         """True if all direct descendents are terminal."""
00521         if self.root.is_terminal():
00522             return False
00523         for clade in self.root.clades:
00524             if not clade.is_terminal():
00525                 return False
00526         return True

def Bio.Phylo.BaseTree.TreeMixin.ladderize (   self,
  reverse = False 
)
Sort clades in-place according to the number of terminal nodes.

Deepest clades are last by default. Use ``reverse=True`` to sort clades
deepest-to-shallowest.

Definition at line 593 of file BaseTree.py.

00593 
00594     def ladderize(self, reverse=False):
00595         """Sort clades in-place according to the number of terminal nodes.
00596 
00597         Deepest clades are last by default. Use ``reverse=True`` to sort clades
00598         deepest-to-shallowest.
00599         """
00600         self.root.clades.sort(key=lambda c: c.count_terminals(),
00601                               reverse=reverse)
00602         for subclade in self.root.clades:
00603             subclade.ladderize(reverse=reverse)

def Bio.Phylo.BaseTree.TreeMixin.prune (   self,
  target = None,
  kwargs 
)
Prunes a terminal clade from the tree.

If taxon is from a bifurcation, the connecting node will be collapsed
and its branch length added to remaining terminal node. This might be no
longer be a meaningful value.

:returns: parent clade of the pruned target

Definition at line 604 of file BaseTree.py.

00604 
00605     def prune(self, target=None, **kwargs):
00606         """Prunes a terminal clade from the tree.
00607 
00608         If taxon is from a bifurcation, the connecting node will be collapsed
00609         and its branch length added to remaining terminal node. This might be no
00610         longer be a meaningful value.
00611 
00612         :returns: parent clade of the pruned target
00613         """
00614         if 'terminal' in kwargs and kwargs['terminal']:
00615             raise ValueError("target must be terminal")
00616         path = self.get_path(target, terminal=True, **kwargs)
00617         if not path:
00618             raise ValueError("can't find a matching target below this root")
00619         if len(path) == 1:
00620             parent = self.root
00621         else:
00622             parent = path[-2]
00623         parent.clades.remove(path[-1])
00624         if len(parent) == 1:
00625             # We deleted a branch from a bifurcation
00626             if parent == self.root:
00627                 # If we're at the root, move the root upwards
00628                 # NB: This loses the length of the original branch
00629                 newroot = parent.clades[0]
00630                 newroot.branch_length = None
00631                 parent = self.root = newroot
00632             else:
00633                 # If we're not at the root, collapse this parent
00634                 child = parent.clades[0]
00635                 if child.branch_length is not None:
00636                     child.branch_length += (parent.branch_length or 0.0)
00637                 if len(path) < 3:
00638                     grandparent = self.root
00639                 else:
00640                     grandparent = path[-3]
00641                 # Replace parent with child at the same place in grandparent
00642                 index = grandparent.clades.index(parent)
00643                 grandparent.clades.pop(index)
00644                 grandparent.clades.insert(index, child)
00645                 parent = grandparent
00646         return parent

Here is the call graph for this function:

def Bio.Phylo.BaseTree.TreeMixin.split (   self,
  n = 2,
  branch_length = 1.0 
)
Generate n (default 2) new descendants.

In a species tree, this is a speciation event.

New clades have the given branch_length and the same name as this
clade's root plus an integer suffix (counting from 0). For example,
splitting a clade named "A" produces sub-clades named "A0" and "A1".

Definition at line 647 of file BaseTree.py.

00647 
00648     def split(self, n=2, branch_length=1.0):
00649         """Generate n (default 2) new descendants.
00650 
00651         In a species tree, this is a speciation event.
00652 
00653         New clades have the given branch_length and the same name as this
00654         clade's root plus an integer suffix (counting from 0). For example,
00655         splitting a clade named "A" produces sub-clades named "A0" and "A1".
00656         """
00657         clade_cls = type(self.root)
00658         base_name = self.root.name or ''
00659         for i in range(n):
00660             clade = clade_cls(name=base_name+str(i),
00661                                 branch_length=branch_length)
00662             self.root.clades.append(clade)
00663 

Calculate the sum of all the branch lengths in this tree.

Definition at line 527 of file BaseTree.py.

00527 
00528     def total_branch_length(self):
00529         """Calculate the sum of all the branch lengths in this tree."""
00530         return sum(node.branch_length
00531                    for node in self.find_clades(branch_length=True))

Here is the call graph for this function:

def Bio.Phylo.BaseTree.TreeMixin.trace (   self,
  start,
  finish 
)
List of all clade object between two targets in this tree.

Excluding `start`, including `finish`.

Definition at line 378 of file BaseTree.py.

00378 
00379     def trace(self, start, finish):
00380         """List of all clade object between two targets in this tree.
00381 
00382         Excluding `start`, including `finish`.
00383         """
00384         mrca = self.common_ancestor(start, finish)
00385         fromstart = mrca.get_path(start)[-2::-1]
00386         to = mrca.get_path(finish)
00387         return fromstart + [mrca] + to

Here is the call graph for this function:


Member Data Documentation

Reimplemented in Bio.Phylo.BaseTree.Tree, and Bio.Phylo.PhyloXML.Phylogeny.

Definition at line 630 of file BaseTree.py.


The documentation for this class was generated from the following file: