Package Bio :: Package Phylo :: Module BaseTree
[hide private]
[frames] | no frames]

Module BaseTree

source code

Base classes for Bio.Phylo objects.

All object representations for phylogenetic trees should derive from these base classes in order to use the common methods defined on them.

Classes [hide private]
  TreeElement
Base class for all Bio.Phylo classes.
  TreeMixin
Methods for Tree- and Clade-based classes.
  Tree
A phylogenetic tree, containing global info for the phylogeny.
  Clade
A recursively defined sub-tree.
  BranchColor
Indicates the color of a clade when rendered graphically.
Functions [hide private]
 
_level_traverse(root, get_children)
Traverse a tree in breadth-first (level) order.
source code
 
_preorder_traverse(root, get_children)
Traverse a tree in depth-first pre-order (parent before children).
source code
 
_postorder_traverse(root, get_children)
Traverse a tree in depth-first post-order (children before parent).
source code
 
_sorted_attrs(elem)
Get a flat list of elem's attributes, sorted for consistency.
source code
 
_identity_matcher(target)
Match a node to the target object by identity.
source code
 
_class_matcher(target_cls)
Match a node if it's an instance of the given class.
source code
 
_string_matcher(target) source code
 
_attribute_matcher(kwargs)
Match a node by specified attribute values.
source code
 
_function_matcher(matcher_func)
Safer attribute lookup -- returns False instead of raising an error.
source code
 
_object_matcher(obj)
Retrieve a matcher function by passing an arbitrary object.
source code
 
_combine_matchers(target, kwargs, require_spec)
Merge target specifications with keyword arguments.
source code
 
_combine_args(first, *rest)
Convert [targets] or *targets arguments to a single iterable.
source code
Variables [hide private]
  __package__ = 'Bio.Phylo'
Function Details [hide private]

_attribute_matcher(kwargs)

source code 

Match a node by specified attribute values.

terminal is a special case: True restricts the search to external (leaf) nodes, False restricts to internal nodes, and None allows all tree elements to be searched, including phyloXML annotations.

Otherwise, for a tree element to match the specification (i.e. for the function produced by _attribute_matcher to return True when given a tree element), it must have each of the attributes specified by the keys and match each of the corresponding values -- think 'and', not 'or', for multiple keys.

_object_matcher(obj)

source code 

Retrieve a matcher function by passing an arbitrary object.

i.e. passing a TreeElement such as a Clade or Tree instance returns an identity matcher, passing a type such as the PhyloXML.Taxonomy class returns a class matcher, and passing a dictionary returns an attribute matcher.

The resulting 'match' function returns True when given an object matching the specification (identity, type or attribute values), otherwise False. This is useful for writing functions that search the tree, and probably shouldn't be used directly by the end user.

_combine_matchers(target, kwargs, require_spec)

source code 

Merge target specifications with keyword arguments.

Dispatch the components to the various matcher functions, then merge into a single boolean function.

_combine_args(first, *rest)

source code 

Convert [targets] or *targets arguments to a single iterable.

This helps other functions work like the built-in functions max and min.