Package pal.tree
Class NodeUtils
- java.lang.Object
-
- pal.tree.NodeUtils
-
public class NodeUtils extends java.lang.ObjectHelper routines for dealing with nodes.- Version:
- $Id: NodeUtils.java,v 1.28 2003/05/14 05:53:36 matt Exp $
- Author:
- Alexei Drummond, Korbinian Strimmer, Matthew Goode
-
-
Constructor Summary
Constructors Constructor Description NodeUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidconvertNegativeBranchLengthsToZeroLength(Node node)If the given node or the sub tree defined by that node have negative branch lengths, they'll have zeron branch lengths after a call to this function!static voidexchangeInfo(Node node1, Node node2)Exchange field info between two nodes.static NodefindByIdentifier(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 NodefindByIdentifier(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 doublefindLargestChild(Node node)Finds the largest child (in terms of node height).static doublegetDistanceToRoot(Node node)determine distance to rootstatic Node[]getExternalNodes(Node root)Obtains all external nodes from tree defined by root and returns as an arraystatic voidgetExternalNodes(Node root, java.util.Vector store)Appends all external nodes from tree defined by root to Vector storestatic NodegetFirstCommonAncestor(Node[] nodes)For a set of nodes in the tree returns the common ancestor closest to all nodes (most recent common ancestor)static NodegetFirstCommonAncestor(Node nodeOne, Node nodeTwo)For two nodes in the tree returns the common ancestor closest to both nodes (most recent common ancestor)static intgetInternalNodeCount(Node root)static Node[]getInternalNodes(Node root, boolean includeRoot)Obtains all internal nodes from tree defined by root and returns as an arraystatic voidgetInternalNodes(Node root, java.util.Vector store)Appends all internal nodes from tree defined by root to Vector storestatic intgetLeafCount(Node node)Return the number of terminal leaves below this node or 1 if this is a terminal leaf.static doublegetMaximumPathLengthLengthToLeaf(Node root)static intgetMaxNodeDepth(Node root)static doublegetMinimumPathLengthLengthToLeaf(Node root)static double[]getPathLengthInfo(Node root)Calculates max/min lengths of paths from root to leaf, taking into account branch lengthsstatic intgetUnrootedBranchCount(Node center)returns number of branches centered around an internal node in an unrooted treestatic voidheights2Lengths(Node node)determines branch lengths of this and all descendent nodes from heightsstatic voidheights2Lengths(Node node, boolean respectMinimum)determines branch lengths of this and all descendent nodes from heightsstatic booleanisAncestor(Node possibleAncestor, Node node)For two nodes in the tree true if the first node is the ancestor of the secondstatic voidjoinChilds(Node node, int n1, int n2)join two childs, introducing a new node/branch in the tree that replaces the first childstatic voidlengths2Heights(Node root)Converts lengths to heights, *without* assuming contemporaneous tips.static voidlengths2HeightsKeepTips(Node node, boolean useMax)Converts lengths to heights, but maintains tip heights.static voidlocalHeights2Lengths(Node node, boolean respectMinimum)determines branch lengths of this node and its immediate descendent nodes from heights.static NodepostorderSuccessor(Node node)determine postorder successor of a nodestatic NodepreorderSuccessor(Node node)determine preorder successor of this nodestatic voidprintNH(java.io.PrintWriter out, Node node, boolean printLengths, boolean printInternalLabels)prints node in New Hamshire format.static intprintNH(java.io.PrintWriter out, Node node, boolean printLengths, boolean printInternalLabels, int column, boolean breakLines)static voidremoveBranch(Node node)remove internal branch (collapse node with its parent)static voidremoveChild(Node parent, Node child)remove childstatic voidrestoreBranch(Node node)restore internal branch
-
-
-
Method Detail
-
getExternalNodes
public static void getExternalNodes(Node root, java.util.Vector store)
Appends all external nodes from tree defined by root to Vector store- Parameters:
root- The root node defining treestore- Where leaf nodes are stored (original contents is not touched)
-
getExternalNodes
public static Node[] getExternalNodes(Node root)
Obtains all external nodes from tree defined by root and returns as an array- Parameters:
root- The root node defining tree- Returns:
- an array of nodes where each node is a leaf node, and is a member of the tree defined by root
-
getInternalNodes
public static void getInternalNodes(Node root, java.util.Vector store)
Appends all internal nodes from tree defined by root to Vector store- Parameters:
root- The root node defining treestore- Where internal nodes are stored (original contents is not touched)
-
getInternalNodes
public static Node[] getInternalNodes(Node root, boolean includeRoot)
Obtains all internal nodes from tree defined by root and returns as an array- Parameters:
root- The root node defining tree- Returns:
- an array of nodes where each node is a internal node, and is a member of the tree defined by root
-
getMaxNodeDepth
public static int getMaxNodeDepth(Node root)
- Returns:
- the maxium distance in nodes from root to a leaf
-
getPathLengthInfo
public static final double[] getPathLengthInfo(Node root)
Calculates max/min lengths of paths from root to leaf, taking into account branch lengths- Returns:
- a double array where
- The first element is the minimum length path from root to leaf.
- The second element is the second most minimum length path from root to leaf.
- The third element is the second most maximum length path from root to leaf.
- The forth element is the maximum length path from root to leaf.
- See Also:
getMaxNodeDepth()
-
getMaximumPathLengthLengthToLeaf
public static final double getMaximumPathLengthLengthToLeaf(Node root)
- Returns:
- the maximum length of a path from root to a leaf
-
getMinimumPathLengthLengthToLeaf
public static final double getMinimumPathLengthLengthToLeaf(Node root)
- Returns:
- the minimum length of a path from root to a leaf
-
lengths2Heights
public static void lengths2Heights(Node root)
Converts lengths to heights, *without* assuming contemporaneous tips.
-
getInternalNodeCount
public static int getInternalNodeCount(Node root)
- Returns:
- the number of internal nodes from a root node
-
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 childn2- 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
-
printNH
public static void printNH(java.io.PrintWriter out, Node node, boolean printLengths, boolean printInternalLabels)prints node in New Hamshire format.
-
printNH
public static int printNH(java.io.PrintWriter out, Node node, boolean printLengths, boolean printInternalLabels, int column, boolean breakLines)
-
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.
-
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 nodenode- 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
-
convertNegativeBranchLengthsToZeroLength
public static final void convertNegativeBranchLengthsToZeroLength(Node node)
If the given node or the sub tree defined by that node have negative branch lengths, they'll have zeron branch lengths after a call to this function!
-
-