Package jebl.evolution.trees
Class MutableRootedTree
java.lang.Object
jebl.evolution.trees.AbstractRootedTree
jebl.evolution.trees.MutableRootedTree
- All Implemented Interfaces:
Graph
,RootedTree
,Tree
,Attributable
A simple rooted tree providing some ability to manipulate the tree.
- Root an unrooted tree using an outgroup.
- Remove internal node: all children of node are adopted by it's parent.
- Split/Refine node by creating two new children and distributing the children to new nodes.
- Re-root a rooted tree given an outgroup.
- Version:
- $Id: MutableRootedTree.java 935 2008-07-22 16:52:04Z rambaut $
- Author:
- Joseph Heled
-
Nested Class Summary
Nested classes/interfaces inherited from interface jebl.evolution.graphs.Graph
Graph.NoEdgeException, Graph.Utils
-
Constructor Summary
ConstructorsConstructorDescriptionMutableRootedTree
(RootedTree tree) Construct a rooted tree from an immutable rooted tree.MutableRootedTree
(Tree tree, Node outGroup) Construct a rooted tree from unrooted. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Insert a child node.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.MutableRootedTree.MutableRootedNode
createInternalNode
(List<? extends Node> children) Once a SimpleRootedTree has been created, the node stucture can be created by calling createExternalNode and createInternalNode.detachChildren
(Node node, List<Integer> split) 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
boolean
boolean
void
refineNode
(Node node, int[] leftSet) void
removeAttribute
(String name) void
removeChild
(Node child, Node parent) Remove a child node.void
removeInternalNode
(Node node) Remove internal node.void
renameTaxa
(Taxon from, Taxon to) void
reRootWithOutgroup
(Node outGroup, Set<String> attributeNames) Re-root tree using an outgroup.void
setAttribute
(String name, Object value) Sets an named attribute for this object.void
setConceptuallyUnrooted
(boolean intent) void
void
void
Set the root node.Methods inherited from class jebl.evolution.trees.AbstractRootedTree
getExternalNodeCount, getExternalNodes
-
Constructor Details
-
MutableRootedTree
Construct a rooted tree from unrooted.- Parameters:
tree
- Unrooted tree to rootoutGroup
- Node in tree assumed to be the outgroup
-
MutableRootedTree
Construct a rooted tree from an immutable rooted tree.- Parameters:
tree
- Rooted tree to copy
-
-
Method Details
-
removeInternalNode
Remove internal node. Move all children to their grandparent.- Parameters:
node
- to be removed
-
addChild
Insert a child node.- Parameters:
child
- to be addedparent
- into which it should be added
-
removeChild
Remove a child node.- Parameters:
child
- to be removedparent
- from which it should be removed
-
setRoot
Set the root node.- Parameters:
root
- the new root node
-
refineNode
- Parameters:
node
- Node to refineleftSet
- indices of children in the left new subtree.
-
reRootWithOutgroup
Re-root tree using an outgroup.- Parameters:
outGroup
-attributeNames
- Move those attributes (if they exist in node) to their previous parent. The idea is to preserve "branch" attributes which we now store in the child since only "node" properties are supported.
-
detachChildren
-
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.MutableRootedTree.MutableRootedNode 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
-
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
- 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
-
getHeight
- 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
-
isHeightsKnown
public boolean isHeightsKnown()- Returns:
- Whether the node heights are known or need to be recalculated from the lengths
-
isLengthsKnown
public boolean isLengthsKnown()- Returns:
- Whether the branch lengths are known or need to be recalculated from the heights
-
getLength
- 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
- 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.- Returns:
- the root of the tree.
-
isRoot
- Parameters:
node
- the node- Returns:
- true if the node is the root of this tree.
-
getExternalNodes
- Returns:
- a set of all nodes that have degree 1. These nodes are often refered to as 'tips'.
-
getInternalNodes
- Returns:
- a set of all nodes that have degree 2 or more. These nodes are often refered to as internal nodes.
-
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
- 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
- Parameters:
node
- the node- Returns:
- true if the node is of degree 1.
-
getNode
- 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.
-
renameTaxa
-
getEdges
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.
-
getNodes
Returns an array of 2 nodes which are the nodes at either end of the edge.- Parameters:
edge
-- Returns:
- an array of 2 edges
-
getAdjacencies
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
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
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
- Returns:
- the set of all nodes in this graph.
-
getEdges
- Returns:
- the set of all edges in this graph.
-
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
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
- Parameters:
degree
- the number of edges connected to a node- Returns:
- a set containing all nodes in this graph of the given degree.
-
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.- Returns:
- true if tree(s) are to be viewed as unrooted
-
setAttribute
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
- 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
- Parameters:
name
- name of attribute to remove
-
getAttributeNames
- Returns:
- an array of the attributeNames that this object has.
-
getAttributeMap
Description copied from interface:Attributable
Gets the entire attribute map.- Returns:
- an unmodifiable map
-