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 void
assertAllTreesHaveTheSameTaxa
(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 String
static String[]
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 Comparator<Node>
static Comparator<Node>
static 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) 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 pointstatic double
safeNodeHeight
(RootedTree tree, Node node) static String
toNewick
(RootedTree tree) static String
toUniqueNewick
(RootedTree tree) Constructs a unique newick representation of a treestatic String
toUniqueNewickByAttribute
(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
-
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)
-