pal.tree
Class NodeUtils

java.lang.Object
  |
  +--pal.tree.NodeUtils

public class NodeUtils
extends java.lang.Object

Helper routines for dealing with nodes.


Constructor Summary
NodeUtils()
           
 
Method Summary
static void exchangeInfo(Node node1, Node node2)
          Exchange field info between two nodes.
static Node findByIdentifier(Node node, Identifier identifier)
          Returns the first node in this tree that has the required identifier.
static Node[] findByIdentifier(Node node, Identifier[] identifiers)
          Returns the first nodes in this tree that has the required identifiers.
static Node findByIdentifier(Node node, java.lang.String identifierName)
          Returns the first node in this tree that has the required identifier.
static Node[] findByIdentifier(Node node, java.lang.String[] identifierNames)
          Returns the first nodes in this tree that has the required identifiers.
static double findLargestChild(Node node)
          Finds the largest child (in terms of node height).
static double getDistanceToRoot(Node node)
          determine distance to root
static Node getFirstCommonAncestor(Node[] nodes)
          For a set of nodes in the tree returns the common ancestor closest to all nodes (most recent common ancestor)
static Node getFirstCommonAncestor(Node nodeOne, Node nodeTwo)
          For two nodes in the tree returns the common ancestor closest to both nodes (most recent common ancestor)
static int getLeafCount(Node node)
          Return the number of terminal leaves below this node or 1 if this is a terminal leaf.
static Node getUnrooted(Node root)
          Attempts to remove the root of a tree by making it polyficating (as opposed to bificating).
static int getUnrootedBranchCount(Node center)
          returns number of branches centered around an internal node in an unrooted tree
static void heights2Lengths(Node node)
          determines branch lengths of this and all descendent nodes from heights
static void heights2Lengths(Node node, boolean respectMinimum)
          determines branch lengths of this and all descendent nodes from heights
static boolean isAncestor(Node possibleAncestor, Node node)
          For two nodes in the tree true if the first node is the ancestor of the second
static void joinChilds(Node node, int n1, int n2)
          join two childs, introducing a new node/branch in the tree that replaces the first child
static void lengths2Heights(Node root)
          Converts lengths to heights, *without* assuming contemporaneous tips.
static void lengths2HeightsKeepTips(Node node, boolean useMax)
          Converts lengths to heights, but maintains tip heights.
static void localHeights2Lengths(Node node, boolean respectMinimum)
          determines branch lengths of this node and its immediate descendent nodes from heights.
static Node postorderSuccessor(Node node)
          determine postorder successor of a node
static Node preorderSuccessor(Node node)
          determine preorder successor of this node
static void removeBranch(Node node)
          remove internal branch (collapse node with its parent)
static void removeChild(Node parent, Node child)
          remove child
static void restoreBranch(Node node)
          restore internal branch
static Node root(Node node)
          Root tree at this node.
static Node rootAbove(Identifier id, Node root)
          Root the tree above the node with this identifier.
static Node rootAbove(Node node)
          Root tree above this node;
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NodeUtils

public NodeUtils()
Method Detail

lengths2Heights

public static void lengths2Heights(Node root)
Converts lengths to heights, *without* assuming contemporaneous tips.

lengths2HeightsKeepTips

public static void lengths2HeightsKeepTips(Node node,
                                           boolean useMax)
Converts lengths to heights, but maintains tip heights.

exchangeInfo

public static void exchangeInfo(Node node1,
                                Node node2)
Exchange field info between two nodes. Specifically identifiers, branch lengths, node heights and branch length SEs.

heights2Lengths

public static void heights2Lengths(Node node)
determines branch lengths of this and all descendent nodes from heights

heights2Lengths

public static void heights2Lengths(Node node,
                                   boolean respectMinimum)
determines branch lengths of this and all descendent nodes from heights

localHeights2Lengths

public static void localHeights2Lengths(Node node,
                                        boolean respectMinimum)
determines branch lengths of this node and its immediate descendent nodes from heights.

findLargestChild

public static double findLargestChild(Node node)
Finds the largest child (in terms of node height).

removeChild

public static void removeChild(Node parent,
                               Node child)
remove child
Parameters:
node - child node to be removed

removeBranch

public static void removeBranch(Node node)
remove internal branch (collapse node with its parent)
Parameters:
node - node associated with internal branch

restoreBranch

public static void restoreBranch(Node node)
restore internal branch
Parameters:
node - node associated with internal branch

joinChilds

public static void joinChilds(Node node,
                              int n1,
                              int n2)
join two childs, introducing a new node/branch in the tree that replaces the first child
Parameters:
n1 - number of first child
n2 - number of second child

preorderSuccessor

public static Node preorderSuccessor(Node node)
determine preorder successor of this node
Returns:
next node

postorderSuccessor

public static Node postorderSuccessor(Node node)
determine postorder successor of a node
Returns:
next node

findByIdentifier

public static final Node[] findByIdentifier(Node node,
                                            java.lang.String[] identifierNames)
Returns the first nodes in this tree that has the required identifiers.
Returns:
null if none of the identifiers names match nodes in tree, else return array which may have null "blanks" for corresponding identifiers that do not match any node in the tree

findByIdentifier

public static final Node[] findByIdentifier(Node node,
                                            Identifier[] identifiers)
Returns the first nodes in this tree that has the required identifiers.

findByIdentifier

public static final Node findByIdentifier(Node node,
                                          Identifier identifier)
Returns the first node in this tree that has the required identifier.

findByIdentifier

public static final Node findByIdentifier(Node node,
                                          java.lang.String identifierName)
Returns the first node in this tree that has the required identifier.

root

public static Node root(Node node)
Root tree at this node.

rootAbove

public static Node rootAbove(Identifier id,
                             Node root)
Root the tree above the node with this identifier.

rootAbove

public static Node rootAbove(Node node)
Root tree above this node;

getDistanceToRoot

public static double getDistanceToRoot(Node node)
determine distance to root
Returns:
distance to root

getLeafCount

public static int getLeafCount(Node node)
Return the number of terminal leaves below this node or 1 if this is a terminal leaf.

isAncestor

public static boolean isAncestor(Node possibleAncestor,
                                 Node node)
For two nodes in the tree true if the first node is the ancestor of the second
Parameters:
possibleAncestor - the node that may be the ancestor of the other node
node - the node that may have the other node as it's ancestor

getFirstCommonAncestor

public static Node getFirstCommonAncestor(Node[] nodes)
For a set of nodes in the tree returns the common ancestor closest to all nodes (most recent common ancestor)
Parameters:
nodes - the nodes to check, is okay if array elements are null!

getFirstCommonAncestor

public static Node getFirstCommonAncestor(Node nodeOne,
                                          Node nodeTwo)
For two nodes in the tree returns the common ancestor closest to both nodes (most recent common ancestor)
Parameters:
nodeOne -  
nodeTwo -  

getUnrootedBranchCount

public static final int getUnrootedBranchCount(Node center)
returns number of branches centered around an internal node in an unrooted tree

getUnrooted

public static final Node getUnrooted(Node root)
Attempts to remove the root of a tree by making it polyficating (as opposed to bificating).