Package jebl.evolution.trees
Class ReRootedTree
- java.lang.Object
-
- jebl.evolution.trees.AbstractRootedTree
-
- jebl.evolution.trees.ReRootedTree
-
- All Implemented Interfaces:
Graph
,RootedTree
,Tree
,Attributable
public final class ReRootedTree extends AbstractRootedTree
A rooted tree concrete class that wraps another tree and provides a differently rooted view of that tree.- Author:
- Andrew Rambaut
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface jebl.evolution.graphs.Graph
Graph.NoEdgeException, Graph.Utils
-
-
Constructor Summary
Constructors Constructor Description ReRootedTree(RootedTree source, Node ingroupNode, Node outgroupNode, double ingroupBranchLength)
Make a copy of the given unrooted tree
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
conceptuallyUnrooted()
Due to current implementation limitations, trees store "branch" information in nodes.Node
createNodes(RootedTree tree, Node parent, Node child)
Clones the entire tree structure from the given (unrooted) Tree.java.util.List<Node>
getAdjacencies(Node node)
Returns a list of nodes connected to this node by an edgejava.lang.Object
getAttribute(java.lang.String name)
java.util.Map<java.lang.String,java.lang.Object>
getAttributeMap()
Gets the entire attribute map.java.util.Set<java.lang.String>
getAttributeNames()
java.util.List<Node>
getChildren(Node node)
Edge
getEdge(Node node1, Node node2)
Returns the Edge that connects these two nodesdouble
getEdgeLength(Node node1, Node node2)
Returns the length of the edge that connects these two nodesjava.util.Set<Edge>
getEdges()
java.util.List<Edge>
getEdges(Node node)
Returns a list of edges connected to this nodejava.util.Set<Edge>
getExternalEdges()
The set of external edges.java.util.Set<Node>
getExternalNodes()
double
getHeight(Node node)
java.util.Set<Edge>
getInternalEdges()
The set of internal edges.java.util.Set<Node>
getInternalNodes()
double
getLength(Node node)
Node
getNode(Taxon taxon)
java.util.Set<Node>
getNodes()
java.util.Set<Node>
getNodes(int degree)
Node[]
getNodes(Edge edge)
Returns an array of 2 nodes which are the nodes at either end of the edge.Node
getParent(Node node)
Edge
getParentEdge(Node node)
Node
getRootNode()
The root of the tree has the largest node height of all nodes in the tree.Node
getSourceNode(Node node)
java.util.Set<Taxon>
getTaxa()
Taxon
getTaxon(Node node)
boolean
hasHeights()
boolean
hasLengths()
boolean
isExternal(Node node)
boolean
isHeightsKnown()
boolean
isLengthsKnown()
boolean
isRoot(Node node)
void
removeAttribute(java.lang.String name)
void
renameTaxa(Taxon from, Taxon to)
static RootedTree
rootTreeAtCenter(RootedTree tree)
Root any tree by locating the "center" of tree and adding a new root node at that pointvoid
setAttribute(java.lang.String name, java.lang.Object value)
Sets an named attribute for this object.void
setHeight(Node node, double height)
void
setLength(Node node, double length)
-
Methods inherited from class jebl.evolution.trees.AbstractRootedTree
getExternalNodeCount, getExternalNodes
-
-
-
-
Constructor Detail
-
ReRootedTree
public ReRootedTree(RootedTree source, Node ingroupNode, Node outgroupNode, double ingroupBranchLength) throws Graph.NoEdgeException
Make a copy of the given unrooted tree- Parameters:
source
- an unrooted source treeingroupNode
- the node on one side of the rootoutgroupNode
- the node on the other side of the rootingroupBranchLength
- the branch length from the root to the ingroup node- Throws:
Graph.NoEdgeException
-
-
Method Detail
-
createNodes
public Node createNodes(RootedTree tree, Node parent, Node child) throws Graph.NoEdgeException
Clones the entire tree structure from the given (unrooted) Tree.- Parameters:
tree
- the unrooted treeparent
- the parent nodechild
- the child node- Throws:
Graph.NoEdgeException
-
setHeight
public void setHeight(Node node, double height)
- Parameters:
node
- the node whose height is being setheight
- the height
-
setLength
public void setLength(Node node, double length)
- Parameters:
node
- the node whose branch length (to its parent) is being setlength
- the length
-
getChildren
public java.util.List<Node> getChildren(Node node)
- Parameters:
node
- the node whose children are being requested.- Returns:
- the list of nodes that are the children of the given node. The list may be empty for a terminal node (a tip).
-
hasHeights
public boolean hasHeights()
- Returns:
- Whether this tree has node heights available
-
isHeightsKnown
public boolean isHeightsKnown()
- Returns:
- Whether the node heights are known or need to be recalculated from the lengths
-
getHeight
public double getHeight(Node node)
- Parameters:
node
- the node whose height is being requested.- Returns:
- the height of the given node. The height will be less than the parent's height and greater than it children's heights.
-
hasLengths
public boolean hasLengths()
- Returns:
- Whether this tree has branch lengths available
-
isLengthsKnown
public boolean isLengthsKnown()
- Returns:
- Whether the branch lengths are known or need to be recalculated from the heights
-
getLength
public double getLength(Node node)
- Parameters:
node
- the node whose branch length (to its parent) is being requested.- Returns:
- the length of the branch to the parent node (0.0 if the node is the root).
-
getParent
public Node getParent(Node node)
- Parameters:
node
- the node whose parent is requested- Returns:
- the parent node of the given node, or null if the node is the root node.
-
getRootNode
public Node getRootNode()
The root of the tree has the largest node height of all nodes in the tree.- Returns:
- the root of the tree.
-
getExternalNodes
public java.util.Set<Node> getExternalNodes()
- Returns:
- a set of all nodes that have degree 1. These nodes are often refered to as 'tips'.
-
getInternalNodes
public java.util.Set<Node> getInternalNodes()
- Returns:
- a set of all nodes that have degree 2 or more. These nodes are often refered to as internal nodes.
-
getTaxa
public java.util.Set<Taxon> getTaxa()
- Returns:
- the set of taxa associated with the external nodes of this tree. The size of this set should be the same as the size of the external nodes set.
-
getTaxon
public Taxon getTaxon(Node node)
- Parameters:
node
- the node whose associated taxon is being requested.- Returns:
- the taxon object associated with the given node, or null if the node is an internal node.
-
isExternal
public boolean isExternal(Node node)
- Parameters:
node
- the node- Returns:
- true if the node is of degree 1.
-
getNode
public Node getNode(Taxon taxon)
- Parameters:
taxon
- the taxon- Returns:
- the external node associated with the given taxon, or null if the taxon is not a member of the taxa set associated with this tree.
-
getEdges
public java.util.List<Edge> getEdges(Node node)
Returns a list of edges connected to this node- Parameters:
node
-- Returns:
- the set of nodes that are attached by edges to the given node.
-
getAdjacencies
public java.util.List<Node> getAdjacencies(Node node)
Description copied from interface:Graph
Returns a list of nodes connected to this node by an edge- Parameters:
node
-- Returns:
- the set of nodes that are attached by edges to the given node.
-
getEdge
public Edge getEdge(Node node1, Node node2) throws Graph.NoEdgeException
Returns the Edge that connects these two nodes- Parameters:
node1
-node2
-- Returns:
- the edge object.
- Throws:
Graph.NoEdgeException
- if the nodes are not directly connected by an edge.
-
getEdgeLength
public double getEdgeLength(Node node1, Node node2) throws Graph.NoEdgeException
Description copied from interface:Graph
Returns the length of the edge that connects these two nodes- Parameters:
node1
-node2
-- Returns:
- the length of the edge connecting node1 and node2.
- Throws:
Graph.NoEdgeException
- if the nodes are not directly connected by an edge.
-
getNodes
public Node[] getNodes(Edge edge)
Returns an array of 2 nodes which are the nodes at either end of the edge.- Parameters:
edge
-- Returns:
- an array of 2 edges
-
getNodes
public java.util.Set<Node> getNodes()
- Returns:
- the set of all nodes in this graph.
-
getEdges
public java.util.Set<Edge> getEdges()
- Returns:
- the set of all edges in this graph.
-
getExternalEdges
public java.util.Set<Edge> getExternalEdges()
The set of external edges. This is a pretty inefficient implementation because a new set is constructed each time this is called.- Returns:
- the set of external edges.
-
getInternalEdges
public java.util.Set<Edge> getInternalEdges()
The set of internal edges. This is a pretty inefficient implementation because a new set is constructed each time this is called.- Returns:
- the set of internal edges.
-
getNodes
public java.util.Set<Node> getNodes(int degree)
- Parameters:
degree
- the number of edges connected to a node- Returns:
- a set containing all nodes in this graph of the given degree.
-
conceptuallyUnrooted
public boolean conceptuallyUnrooted()
Description copied from interface:RootedTree
Due to current implementation limitations, trees store "branch" information in nodes. So, internally rooted trees are genetrated when un-rooted would be more natural. This should be removed. If this is a rooted tree then it is rooted. This can really only confuse things. Trees are unrooted, RootedTrees are rooted. This is not an implementation limitation. It may be that a RootedTree has an arbitrary root but it is still rooted. With a rooted tree, it is convenient to store branch information at the node (i.e., for the branch above the node) because there is no "branch" object. Andrew. This function will probably become deprecated once the "development" tree viewer becomes in sync with the main tree viewer branch and some method of handling this concept has been introduced. Until then, this method remains.- Returns:
- true if tree(s) are to be viewed as unrooted
-
isRoot
public boolean isRoot(Node node)
- Parameters:
node
- the node- Returns:
- true if the node is the root of this tree.
-
setAttribute
public void setAttribute(java.lang.String name, java.lang.Object value)
Description copied from interface:Attributable
Sets an named attribute for this object.- Parameters:
name
- the name of the attribute.value
- the new value of the attribute.
-
getAttribute
public java.lang.Object getAttribute(java.lang.String name)
- Parameters:
name
- the name of the attribute of interest, or null if the attribute doesn't exist.- Returns:
- an object representing the named attributed for this object.
-
removeAttribute
public void removeAttribute(java.lang.String name)
- Parameters:
name
- name of attribute to remove
-
getAttributeNames
public java.util.Set<java.lang.String> getAttributeNames()
- Returns:
- an array of the attributeNames that this object has.
-
getAttributeMap
public java.util.Map<java.lang.String,java.lang.Object> getAttributeMap()
Description copied from interface:Attributable
Gets the entire attribute map.- Returns:
- an unmodifiable map
-
rootTreeAtCenter
public static RootedTree rootTreeAtCenter(RootedTree 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
-
-