Package jebl.evolution.trees
Class MutableRootedTree
- java.lang.Object
-
- jebl.evolution.trees.MutableRootedTree
-
- All Implemented Interfaces:
Graph,RootedTree,Tree,Attributable
public class MutableRootedTree extends java.lang.Object implements RootedTree
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
Constructors Constructor Description MutableRootedTree(RootedTree tree)Construct a rooted tree from an immutable rooted tree.MutableRootedTree(Tree tree, Node outGroup)Construct a rooted tree from unrooted.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddChild(Node child, Node parent)Insert a child node.booleanconceptuallyUnrooted()Due to current implementation limitations, trees store "branch" information in nodes.NodecreateExternalNode(Taxon taxon)Creates a new external node with the given taxon.jebl.evolution.trees.MutableRootedTree.MutableRootedNodecreateInternalNode(java.util.List<? extends Node> children)Once a SimpleRootedTree has been created, the node stucture can be created by calling createExternalNode and createInternalNode.NodedetachChildren(Node node, java.util.List<java.lang.Integer> split)java.util.List<Node>getAdjacencies(Node node)Returns a list of nodes connected to this node by an edgejava.lang.ObjectgetAttribute(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)EdgegetEdge(Node node1, Node node2)Returns the Edge that connects these two nodesdoublegetEdgeLength(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()doublegetHeight(Node node)java.util.Set<Edge>getInternalEdges()The set of internal edges.java.util.Set<Node>getInternalNodes()doublegetLength(Node node)NodegetNode(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.NodegetParent(Node node)EdgegetParentEdge(Node node)NodegetRootNode()The root of the tree has the largest node height of all nodes in the tree.java.util.Set<Taxon>getTaxa()TaxongetTaxon(Node node)booleanhasHeights()booleanhasLengths()booleanisExternal(Node node)booleanisRoot(Node node)voidrefineNode(Node node, int[] leftSet)voidremoveAttribute(java.lang.String name)voidremoveChild(Node child, Node parent)Remove a child node.voidremoveInternalNode(Node node)Remove internal node.voidrenameTaxa(Taxon from, Taxon to)voidreRootWithOutgroup(Node outGroup, java.util.Set<java.lang.String> attributeNames)Re-root tree using an outgroup.voidsetAttribute(java.lang.String name, java.lang.Object value)Sets an named attribute for this object.voidsetConceptuallyUnrooted(boolean intent)voidsetHeight(Node node, double height)voidsetLength(Node node, double length)voidsetRoot(Node root)Set the root node.
-
-
-
Constructor Detail
-
MutableRootedTree
public MutableRootedTree(Tree tree, Node outGroup)
Construct a rooted tree from unrooted.- Parameters:
tree- Unrooted tree to rootoutGroup- Node in tree assumed to be the outgroup
-
MutableRootedTree
public MutableRootedTree(RootedTree tree)
Construct a rooted tree from an immutable rooted tree.- Parameters:
tree- Rooted tree to copy
-
-
Method Detail
-
removeInternalNode
public void removeInternalNode(Node node)
Remove internal node. Move all children to their grandparent.- Parameters:
node- to be removed
-
addChild
public void addChild(Node child, Node parent)
Insert a child node.- Parameters:
child- to be addedparent- into which it should be added
-
removeChild
public void removeChild(Node child, Node parent)
Remove a child node.- Parameters:
child- to be removedparent- from which it should be removed
-
setRoot
public void setRoot(Node root)
Set the root node.- Parameters:
root- the new root node
-
refineNode
public void refineNode(Node node, int[] leftSet)
- Parameters:
node- Node to refineleftSet- indices of children in the left new subtree.
-
reRootWithOutgroup
public void reRootWithOutgroup(Node outGroup, java.util.Set<java.lang.String> attributeNames)
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.
-
createExternalNode
public Node createExternalNode(Taxon taxon)
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(java.util.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
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)
- Specified by:
getChildrenin 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:
hasHeightsin interfaceRootedTree- Returns:
- Whether this tree has node heights available
-
getHeight
public double getHeight(Node node)
- Specified by:
getHeightin 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:
hasLengthsin interfaceRootedTree- Returns:
- Whether this tree has branch lengths available
-
getLength
public double getLength(Node node)
- Specified by:
getLengthin 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
public Node getParent(Node node)
- Specified by:
getParentin 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.
-
getRootNode
public Node getRootNode()
The root of the tree has the largest node height of all nodes in the tree.- Specified by:
getRootNodein interfaceRootedTree- Returns:
- the root of the tree.
-
isRoot
public boolean isRoot(Node node)
- Specified by:
isRootin interfaceRootedTree- Parameters:
node- the node- Returns:
- true if the node is the root of this tree.
-
getExternalNodes
public java.util.Set<Node> getExternalNodes()
- Specified by:
getExternalNodesin interfaceTree- 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()
- Specified by:
getInternalNodesin interfaceTree- 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()
-
isExternal
public boolean isExternal(Node node)
- Specified by:
isExternalin interfaceTree- Parameters:
node- the node- Returns:
- true if the node is of degree 1.
-
renameTaxa
public void renameTaxa(Taxon from, Taxon to)
- Specified by:
renameTaxain interfaceTree
-
getEdges
public java.util.List<Edge> getEdges(Node node)
Returns a list of edges connected to this node
-
getNodes
public Node[] getNodes(Edge edge)
Returns an array of 2 nodes which are the nodes at either end of the edge.
-
getAdjacencies
public java.util.List<Node> getAdjacencies(Node node)
Description copied from interface:GraphReturns a list of nodes connected to this node by an edge- Specified by:
getAdjacenciesin interfaceGraph- 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- Specified by:
getEdgein interfaceGraph- 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:GraphReturns the length of the edge that connects these two nodes- Specified by:
getEdgeLengthin 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
public java.util.Set<Node> getNodes()
-
getEdges
public java.util.Set<Edge> getEdges()
-
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.- Specified by:
getExternalEdgesin interfaceTree- 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.- Specified by:
getInternalEdgesin interfaceTree- Returns:
- the set of internal edges.
-
getNodes
public java.util.Set<Node> getNodes(int degree)
-
setConceptuallyUnrooted
public void setConceptuallyUnrooted(boolean intent)
-
conceptuallyUnrooted
public boolean conceptuallyUnrooted()
Description copied from interface:RootedTreeDue 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:
conceptuallyUnrootedin interfaceRootedTree- Returns:
- true if tree(s) are to be viewed as unrooted
-
setAttribute
public void setAttribute(java.lang.String name, java.lang.Object value)Description copied from interface:AttributableSets an named attribute for this object.- Specified by:
setAttributein interfaceAttributable- Parameters:
name- the name of the attribute.value- the new value of the attribute.
-
getAttribute
public java.lang.Object getAttribute(java.lang.String name)
- Specified by:
getAttributein 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
public void removeAttribute(java.lang.String name)
- Specified by:
removeAttributein interfaceAttributable- Parameters:
name- name of attribute to remove
-
getAttributeNames
public java.util.Set<java.lang.String> getAttributeNames()
- Specified by:
getAttributeNamesin interfaceAttributable- 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:AttributableGets the entire attribute map.- Specified by:
getAttributeMapin interfaceAttributable- Returns:
- an unmodifiable map
-
-