jebl.evolution.trees
Class Utils

java.lang.Object
  extended by jebl.evolution.trees.Utils

public final class Utils
extends java.lang.Object

A collection of utility functions for trees.

Version:
$Id: Utils.java 979 2009-02-24 11:15:18Z rambaut $
Author:
rambaut, Alexei Drummond

Method Summary
static void assertAllTreesHaveTheSameTaxa(java.util.List<? extends Tree> trees)
          Checks whether all of the trees passed in have the same taxa sets (ignoring order of taxa), and throws an IllegalArgumentException if this is not the case.
static java.lang.String asText(Tree tree)
           
static java.lang.String[] asText(Tree tree, int widthGuide)
           
static RootedTree copyTree(RootedTree treeToCopy)
          This method creates an unattached copy of the given rooted tree such that changes to the copied tree do not affect the original tree.
static java.util.Comparator<Node> createNodeDensityComparator(RootedTree tree)
           
static java.util.Comparator<Node> createNodeDensityMinNodeHeightComparator(RootedTree tree)
           
static java.lang.String DEBUGsubTreeRep(RootedTree tree, Node node)
           
static int getExternalNodeCount(RootedTree tree, Node node)
          Return the number of external nodes under this node.
static double getMinNodeHeight(RootedTree tree, Node node)
           
static java.util.List<Node> getNodes(RootedTree tree, Node node)
          All nodes in subtree - parents before children (pre - order).
static double getPathLength(Tree tree, Node node1, Node node2)
           
static boolean isBinary(RootedTree rootedTree)
           
static boolean isUltrametric(RootedTree rootedTree)
           
static Node leftNb(RootedTree tree, Node node)
          Left Neighbour of a tip (taxon).
static int maxLevels(RootedTree tree)
           
static Node rightNb(RootedTree tree, Node tipNode)
          Right Neighbour of a tip (taxon).
static RootedTree rootTheTree(Tree tree)
          Return a rooted tree from any tree.
static RootedTree rootTreeAtCenter(Tree tree)
          Root any tree by locating the "center" of tree and adding a new root node at that point

for any point on the tree x let D(x) = Max{distance between x and t : for all tips t} The "center" c is the point with the smallest distance, i.e.

static double safeNodeHeight(RootedTree tree, Node node)
           
static java.lang.String toNewick(RootedTree tree)
           
static java.lang.String toUniqueNewick(RootedTree tree)
          Constructs a unique newick representation of a tree
static java.lang.String toUniqueNewickByAttribute(RootedTree tree, java.lang.String attribute)
          Constructs a unique newick representation of a tree print only an attribute
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

toNewick

public static java.lang.String toNewick(RootedTree tree)
Parameters:
tree -
Returns:
the rooted tree as a newick format string

toUniqueNewick

public static java.lang.String toUniqueNewick(RootedTree tree)
Constructs a unique newick representation of a tree

Parameters:
tree -

toUniqueNewickByAttribute

public static java.lang.String toUniqueNewickByAttribute(RootedTree tree,
                                                         java.lang.String attribute)
Constructs a unique newick representation of a tree print only an attribute

Parameters:
tree -

safeNodeHeight

public static double safeNodeHeight(RootedTree tree,
                                    Node node)

maxLevels

public static int maxLevels(RootedTree tree)

asText

public static java.lang.String asText(Tree tree)

asText

public static java.lang.String[] asText(Tree tree,
                                        int widthGuide)

rootTheTree

public static RootedTree rootTheTree(Tree tree)
Return a rooted tree from any tree.

If tree already rooted, return it. Otherwise if there is a "natuarl root" (i.e. a node of degree 2) use it as root. Otherwise use an internal node close to the center of the tree as a root.

Parameters:
tree - to root
Returns:
rooted representation

rootTreeAtCenter

public static RootedTree rootTreeAtCenter(Tree tree)
Root any tree by locating the "center" of tree and adding a new root node at that point

for any point on the tree x let D(x) = Max{distance between x and t : for all tips t} The "center" c is the point with the smallest distance, i.e. D(c) = min{ D(x) : x in tree }

Parameters:
tree - to root
Returns:
rooted tree

getPathLength

public static double getPathLength(Tree tree,
                                   Node node1,
                                   Node node2)
Parameters:
tree - the tree
node1 -
node2 -
Returns:
the path length between the two nodes

isBinary

public static boolean isBinary(RootedTree rootedTree)
Parameters:
rootedTree - the rooted tree
Returns:
true if all internal nodes in the given tree are of degree 3, except the root which must have a degree of 2.

isUltrametric

public static boolean isUltrametric(RootedTree rootedTree)
Parameters:
rootedTree - the rooted tree
Returns:
true if all the external nodes in the tree have a height of 0.0

getExternalNodeCount

public static int getExternalNodeCount(RootedTree tree,
                                       Node node)
Return the number of external nodes under this node.

Parameters:
tree -
node -
Returns:
the number of external nodes under this node.

getNodes

public static java.util.List<Node> getNodes(RootedTree tree,
                                            Node node)
All nodes in subtree - parents before children (pre - order).

Parameters:
tree -
node -
Returns:
nodes in pre-order

rightNb

public static Node rightNb(RootedTree tree,
                           Node tipNode)
Right Neighbour of a tip (taxon).

When tree is laid with children in given order, this would be the taxon to the right.

Parameters:
tree -
tipNode -
Returns:
Right Neighbour. null if node is the rightmost in tree or not a tip.

leftNb

public static Node leftNb(RootedTree tree,
                          Node node)
Left Neighbour of a tip (taxon).

When tree is laid with children in given order, this would be the taxon to the left.

Parameters:
tree -
node -
Returns:
Left Neighbour. null if node is the leftmost in tree or not a tip.

getMinNodeHeight

public static double getMinNodeHeight(RootedTree tree,
                                      Node node)
Parameters:
tree -
node -
Returns:
the minimum node height

createNodeDensityComparator

public static java.util.Comparator<Node> createNodeDensityComparator(RootedTree tree)

createNodeDensityMinNodeHeightComparator

public static java.util.Comparator<Node> createNodeDensityMinNodeHeightComparator(RootedTree tree)

assertAllTreesHaveTheSameTaxa

public static void assertAllTreesHaveTheSameTaxa(java.util.List<? extends Tree> trees)
                                          throws java.lang.IllegalArgumentException
Checks whether all of the trees passed in have the same taxa sets (ignoring order of taxa), and throws an IllegalArgumentException if this is not the case. If no tree or only one tree is passed in, immediately returns without throwing an exception.

Parameters:
trees - Zero or more trees
Throws:
java.lang.IllegalArgumentException - if not all of the trees have the same taxa
java.lang.NullPointerException - if trees is null

DEBUGsubTreeRep

public static java.lang.String DEBUGsubTreeRep(RootedTree tree,
                                               Node node)

copyTree

public static RootedTree copyTree(RootedTree treeToCopy)
This method creates an unattached copy of the given rooted tree such that changes to the copied tree do not affect the original tree.

Parameters:
treeToCopy - the tree to copy
Returns:
an equivalent tree to treeToCopy (NB this may not be of the same RootedTree subclass as treeToCopy)


http://code.google.com/p/jebl2/