Package jebl.evolution.trees
Class Utils
java.lang.Object
jebl.evolution.trees.Utils
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
Modifier and TypeMethodDescriptionstatic voidassertAllTreesHaveTheSameTaxa(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 Stringstatic String[]static RootedTreecopyTree(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 Comparator<Node>static Comparator<Node>static StringDEBUGsubTreeRep(RootedTree tree, Node node) static intgetExternalNodeCount(RootedTree tree, Node node) Return the number of external nodes under this node.static doublegetLength(RootedTree tree) static doublestatic doublegetMinNodeHeight(RootedTree tree, Node node) getNodes(RootedTree tree, Node node) All nodes in subtree - parents before children (pre - order).static doublegetPathLength(Tree tree, Node node1, Node node2) static booleanisBinary(RootedTree rootedTree) static booleanisUltrametric(RootedTree rootedTree) static NodeleftNb(RootedTree tree, Node node) Left Neighbour of a tip (taxon).static intmaxLevels(RootedTree tree) static NoderightNb(RootedTree tree, Node tipNode) Right Neighbour of a tip (taxon).static RootedTreerootTheTree(Tree tree) Return a rooted tree from any tree.static RootedTreerootTreeAtCenter(Tree tree) Root any tree by locating the "center" of tree and adding a new root node at that pointstatic doublesafeNodeHeight(RootedTree tree, Node node) static StringtoNewick(RootedTree tree) static StringtoUniqueNewick(RootedTree tree) Constructs a unique newick representation of a treestatic StringtoUniqueNewickByAttribute(RootedTree tree, String attribute) Constructs a unique newick representation of a tree print only an attribute
-
Method Details
-
toNewick
- Parameters:
tree-- Returns:
- the rooted tree as a newick format string
-
toUniqueNewick
Constructs a unique newick representation of a tree- Parameters:
tree-
-
toUniqueNewickByAttribute
Constructs a unique newick representation of a tree print only an attribute- Parameters:
tree-
-
safeNodeHeight
-
maxLevels
-
asText
-
asText
-
rootTheTree
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
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
- Parameters:
tree- the treenode1-node2-- Returns:
- the path length between the two nodes
-
isBinary
- 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
- Parameters:
rootedTree- the rooted tree- Returns:
- true if all the external nodes in the tree have a height of 0.0
-
getLength
- Parameters:
tree- the tree- Returns:
- the sum of all the branch lengths
-
getLength
- Parameters:
tree- the tree- Returns:
- the sum of all the branch lengths
-
getExternalNodeCount
Return the number of external nodes under this node.- Parameters:
tree-node-- Returns:
- the number of external nodes under this node.
-
getNodes
All nodes in subtree - parents before children (pre - order).- Parameters:
tree-node-- Returns:
- nodes in pre-order
-
rightNb
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
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
- Parameters:
tree-node-- Returns:
- the minimum node height
-
createNodeDensityComparator
-
createNodeDensityMinNodeHeightComparator
-
assertAllTreesHaveTheSameTaxa
public static void assertAllTreesHaveTheSameTaxa(List<? extends Tree> trees) throws 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:
IllegalArgumentException- if not all of the trees have the same taxaNullPointerException- if trees is null
-
DEBUGsubTreeRep
-
copyTree
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)
-