Package jebl.evolution.trees
Class SimpleRootedTree
java.lang.Object
jebl.evolution.trees.SimpleRootedTree
- All Implemented Interfaces:
Graph
,RootedTree
,Tree
,Attributable
A simple, and initially immutable rooted tree implementation. All returned collections
are defensively copied. The implementation of Node is private. A number of methods are
provided that can be used to construct a tree (createExternalNode & createInternalNode).
- Version:
- $Id: SimpleRootedTree.java 1045 2010-01-13 03:09:14Z stevensh $
- Author:
- Andrew Rambaut, Alexei Drummond
-
Nested Class Summary
Nested classes/interfaces inherited from interface jebl.evolution.graphs.Graph
Graph.NoEdgeException, Graph.Utils
-
Constructor Summary
ConstructorsConstructorDescriptionSimpleRootedTree
(RootedTree tree) Make a copy of the given rooted treeSimpleRootedTree
(RootedTree tree, Map<Node, Node> nodeMapping) Make a copy of the given rooted treeSimpleRootedTree
(Tree tree, Node ingroupNode, Node outgroupNode, double ingroupBranchLength) Make a copy of the given unrooted tree -
Method Summary
Modifier and TypeMethodDescriptionAdds a new node at the midpoint of the given edgeAdds a new node at the midpoint of the edge connecting the given node to its parent.boolean
Due to current implementation limitations, trees store "branch" information in nodes.createExternalNode
(Taxon taxon) Creates a new external node with the given taxon.jebl.evolution.trees.SimpleRootedTree.SimpleRootedNode
createInternalNode
(List<? extends Node> children) Once a SimpleRootedTree has been created, the node stucture can be created by calling createExternalNode and createInternalNode.createNodes
(RootedTree tree, Node node) Clones the entire tree structure from the given RootedTree.createNodes
(Tree tree, Node parent, Node child) Clones the entire tree structure from the given (unrooted) Tree.void
deleteInternalNode
(Node node) Removes an internal node in this tree.getAdjacencies
(Node node) Returns a list of nodes connected to this node by an edgegetAttribute
(String name) Gets the entire attribute map.getChildren
(Node node) Returns the Edge that connects these two nodesdouble
getEdgeLength
(Node node1, Node node2) Returns the length of the edge that connects these two nodesgetEdges()
Returns a list of edges connected to this nodeThe set of external edges.double
The set of internal edges.double
getNodes()
getNodes
(int degree) Node[]
Returns an array of 2 nodes which are the nodes at either end of the edge.getParentEdge
(Node node) The root of the tree has the largest node height of all nodes in the tree.getTaxa()
boolean
boolean
boolean
isExternal
(Node node) boolean
void
removeAttribute
(String name) void
renameTaxa
(Taxon from, Taxon to) void
setAttribute
(String name, Object value) Sets an named attribute for this object.void
setConceptuallyUnrooted
(boolean intent) void
void
void
-
Constructor Details
-
SimpleRootedTree
public SimpleRootedTree() -
SimpleRootedTree
Make a copy of the given rooted tree- Parameters:
tree
- a rooted tree
-
SimpleRootedTree
Make a copy of the given rooted tree- Parameters:
tree
- a rooted treenodeMapping
- store {source tree node -> new tree node} mapping in here if non-null
-
SimpleRootedTree
public SimpleRootedTree(Tree tree, Node ingroupNode, Node outgroupNode, double ingroupBranchLength) throws Graph.NoEdgeException Make a copy of the given unrooted tree- Parameters:
tree
- an unrooted 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 Details
-
createNodes
Clones the entire tree structure from the given RootedTree.- Parameters:
tree
-node
-- Returns:
- created node
-
createNodes
Clones the entire tree structure from the given (unrooted) Tree.- Parameters:
tree
- the unrooted treeparent
- the parent nodechild
- the child node- Throws:
Graph.NoEdgeException
-
createExternalNode
Creates a new external node with the given taxon. See createInternalNode for a description of how to use these methods.- Parameters:
taxon
- the taxon associated with this node- Returns:
- the created node reference
-
createInternalNode
public jebl.evolution.trees.SimpleRootedTree.SimpleRootedNode createInternalNode(List<? extends Node> children) Once a SimpleRootedTree has been created, the node stucture can be created by calling createExternalNode and createInternalNode. First of all createExternalNode is called giving Taxon objects for the external nodes. Then these are put into sets and passed to createInternalNode to create a parent of these nodes. The last node created using createInternalNode is automatically the root so when all the nodes are created, the tree is complete.- Parameters:
children
- the child nodes of this nodes- Returns:
- the created node reference
-
deleteInternalNode
Removes an internal node in this tree. It must not be a child of any other node.- Parameters:
node
- the node to remove.
-
addNode
Adds a new node at the midpoint of the edge connecting the given node to its parent.- Parameters:
node
- must be a node in the tree, which has a parent- Returns:
- the newly created node
-
addNode
Adds a new node at the midpoint of the given edge- Parameters:
edge
-- Returns:
- the newly created node
-
swapNodes
-
setHeight
- Parameters:
node
- the node whose height is being setheight
- the height
-
setLength
- Parameters:
node
- the node whose branch length (to its parent) is being setlength
- the length
-
getChildren
- Specified by:
getChildren
in interfaceRootedTree
- 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()- Specified by:
hasHeights
in interfaceRootedTree
- Returns:
- Whether this tree has node heights available
-
getHeight
- Specified by:
getHeight
in interfaceRootedTree
- 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()- Specified by:
hasLengths
in interfaceRootedTree
- Returns:
- Whether this tree has branch lengths available
-
getLength
- Specified by:
getLength
in interfaceRootedTree
- 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
- Specified by:
getParent
in interfaceRootedTree
- 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.
-
getParentEdge
-
getRootNode
The root of the tree has the largest node height of all nodes in the tree.- Specified by:
getRootNode
in interfaceRootedTree
- Returns:
- the root of the tree.
-
getExternalNodes
- Specified by:
getExternalNodes
in interfaceTree
- Returns:
- a set of all nodes that have degree 1. These nodes are often refered to as 'tips'.
-
getInternalNodes
- Specified by:
getInternalNodes
in interfaceTree
- Returns:
- a set of all nodes that have degree 2 or more. These nodes are often refered to as internal nodes.
-
getTaxa
-
getTaxon
-
isExternal
- Specified by:
isExternal
in interfaceTree
- Parameters:
node
- the node- Returns:
- true if the node is of degree 1.
-
getNode
-
renameTaxa
- Specified by:
renameTaxa
in interfaceTree
-
getEdges
Returns a list of edges connected to this node -
getAdjacencies
Description copied from interface:Graph
Returns a list of nodes connected to this node by an edge- Specified by:
getAdjacencies
in interfaceGraph
- Parameters:
node
-- Returns:
- the set of nodes that are attached by edges to the given node.
-
getEdge
Returns the Edge that connects these two nodes- Specified by:
getEdge
in interfaceGraph
- Parameters:
node1
-node2
-- Returns:
- the edge object.
- Throws:
Graph.NoEdgeException
- if the nodes are not directly connected by an edge.
-
getEdgeLength
Description copied from interface:Graph
Returns the length of the edge that connects these two nodes- Specified by:
getEdgeLength
in interfaceGraph
- 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
Returns an array of 2 nodes which are the nodes at either end of the edge. -
getNodes
-
getEdges
-
getExternalEdges
The set of external edges. This is a pretty inefficient implementation because a new set is constructed each time this is called.- Specified by:
getExternalEdges
in interfaceTree
- Returns:
- the set of external edges.
-
getInternalEdges
The set of internal edges. This is a pretty inefficient implementation because a new set is constructed each time this is called.- Specified by:
getInternalEdges
in interfaceTree
- Returns:
- the set of internal edges.
-
getNodes
-
setConceptuallyUnrooted
public void setConceptuallyUnrooted(boolean intent) -
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.- Specified by:
conceptuallyUnrooted
in interfaceRootedTree
- Returns:
- true if tree(s) are to be viewed as unrooted
-
isRoot
- Specified by:
isRoot
in interfaceRootedTree
- Parameters:
node
- the node- Returns:
- true if the node is the root of this tree.
-
setAttribute
Description copied from interface:Attributable
Sets an named attribute for this object.- Specified by:
setAttribute
in interfaceAttributable
- Parameters:
name
- the name of the attribute.value
- the new value of the attribute.
-
getAttribute
- Specified by:
getAttribute
in interfaceAttributable
- 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
- Specified by:
removeAttribute
in interfaceAttributable
- Parameters:
name
- name of attribute to remove
-
getAttributeNames
- Specified by:
getAttributeNames
in interfaceAttributable
- Returns:
- an array of the attributeNames that this object has.
-
getAttributeMap
Description copied from interface:Attributable
Gets the entire attribute map.- Specified by:
getAttributeMap
in interfaceAttributable
- Returns:
- an unmodifiable map
-