Package jebl.evolution.trees
Class CompactRootedTree
- java.lang.Object
-
- jebl.evolution.trees.CompactRootedTree
-
- All Implemented Interfaces:
Graph
,RootedTree
,Tree
,Attributable
public class CompactRootedTree extends java.lang.Object implements RootedTree
A memory efficient rooted tree. - Uses a compact representation for the tree structure based primarily on indices instead of pointers and objects - Minimize penalty for unused features. Trees not using attributes or edges do not require additional per node/edge memory. Limitations: - Maximun of 2^16 nodes and 2^15 external nodes. This should not be a problem with the current sizes of phlogenetic trees we currently handle. - Some of the accessors are slower, typically the ones getting all nodes, all edges, all internal nodes etc. Traversing the tree and handling attributes speed should be fine (compared to SimpkeRootedTree)- Version:
- $Id: CompactRootedTree.java 935 2008-07-22 16:52:04Z rambaut $
- Author:
- Joseph Heled
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface jebl.util.Attributable
Attributable.Utils
-
Nested classes/interfaces inherited from interface jebl.evolution.graphs.Graph
Graph.NoEdgeException, Graph.Utils
-
-
Constructor Summary
Constructors Constructor Description CompactRootedTree(RootedTree t)
Do all the hard work.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
conceptuallyUnrooted()
Due to current implementation limitations, trees store "branch" information in nodes.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()
int
getExternalNodeCount(Node node)
java.util.Set<Node>
getExternalNodes()
java.util.List<Node>
getExternalNodes(Node node)
double
getHeight(Node node)
java.util.Set<Edge>
getInternalEdges()
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.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)
void
setAttribute(java.lang.String name, java.lang.Object value)
Sets an named attribute for this object.void
setConceptuallyUnrooted(boolean conceptuallyUnrooted)
-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface jebl.util.Attributable
getAttribute, getAttributeMap, getAttributeNames, removeAttribute, setAttribute
-
-
-
-
Constructor Detail
-
CompactRootedTree
public CompactRootedTree(RootedTree t)
Do all the hard work.- Parameters:
t
-
-
-
Method Detail
-
getChildren
public java.util.List<Node> getChildren(Node node)
- 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 set may be empty for a terminal node (a tip).
-
getExternalNodeCount
public int getExternalNodeCount(Node node)
- Specified by:
getExternalNodeCount
in interfaceRootedTree
-
getExternalNodes
public java.util.List<Node> getExternalNodes(Node node)
- Specified by:
getExternalNodes
in interfaceRootedTree
- Parameters:
node
- the node whose external nodes are being requested.- Returns:
- the list of external nodes descendent of the given node. The set 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
public double getHeight(Node node)
- 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
public double getLength(Node node)
- 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).
-
isHeightsKnown
public boolean isHeightsKnown()
- Specified by:
isHeightsKnown
in interfaceRootedTree
- Returns:
- Whether the node heights are known or need to be recalculated from the lengths
-
isLengthsKnown
public boolean isLengthsKnown()
- Specified by:
isLengthsKnown
in interfaceRootedTree
- Returns:
- Whether the branch lengths are known or need to be recalculated from the heights
-
getParent
public Node getParent(Node node)
- 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.
-
getRootNode
public Node getRootNode()
Description copied from interface:RootedTree
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.
-
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
-
setConceptuallyUnrooted
public void setConceptuallyUnrooted(boolean conceptuallyUnrooted)
-
isRoot
public boolean isRoot(Node node)
- Specified by:
isRoot
in 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:
getExternalNodes
in 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:
getInternalNodes
in interfaceTree
- Returns:
- a set of all nodes that have degree 2 or more. These nodes are often refered to as internal nodes.
-
getExternalEdges
public java.util.Set<Edge> getExternalEdges()
- Specified by:
getExternalEdges
in interfaceTree
- Returns:
- a set of all edges that have a degree 1 node.
-
getInternalEdges
public java.util.Set<Edge> getInternalEdges()
- Specified by:
getInternalEdges
in interfaceTree
- Returns:
- a set of all edges for which both nodes have degree 2 or more.
-
getTaxa
public java.util.Set<Taxon> getTaxa()
-
isExternal
public boolean isExternal(Node node)
- Specified by:
isExternal
in interfaceTree
- Parameters:
node
- the node- Returns:
- true if the node is of degree 1.
-
renameTaxa
public void renameTaxa(Taxon from, Taxon to)
- Specified by:
renameTaxa
in interfaceTree
-
getEdges
public java.util.List<Edge> getEdges(Node node)
Description copied from interface:Graph
Returns a list of edges connected to this 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- Specified by:
getAdjacencies
in interfaceGraph
- 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
Description copied from interface:Graph
Returns the Edge that connects these two nodes- Specified by:
getEdge
in interfaceGraph
- 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- Specified by:
getEdgeLength
in interfaceGraph
- Returns:
- the edge length.
- Throws:
Graph.NoEdgeException
- if the nodes are not directly connected by an edge.
-
getNodes
public Node[] getNodes(Edge edge)
Description copied from interface:Graph
Returns an array of 2 nodes which are the nodes at either end of the edge.
-
getNodes
public java.util.Set<Node> getNodes()
-
getEdges
public java.util.Set<Edge> getEdges()
-
getNodes
public java.util.Set<Node> getNodes(int degree)
-
setAttribute
public void setAttribute(java.lang.String name, java.lang.Object value)
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
public java.lang.Object getAttribute(java.lang.String name)
- 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
public void removeAttribute(java.lang.String name)
- Specified by:
removeAttribute
in interfaceAttributable
- Parameters:
name
- name of attribute to remove
-
getAttributeNames
public java.util.Set<java.lang.String> getAttributeNames()
- Specified by:
getAttributeNames
in 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:Attributable
Gets the entire attribute map.- Specified by:
getAttributeMap
in interfaceAttributable
- Returns:
- an unmodifiable map
-
-