Package jebl.evolution.trees
Class CompactRootedTree
java.lang.Object
jebl.evolution.trees.CompactRootedTree
- All Implemented Interfaces:
Graph,RootedTree,Tree,Attributable
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.UtilsNested classes/interfaces inherited from interface jebl.evolution.graphs.Graph
Graph.NoEdgeException, Graph.Utils -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanDue to current implementation limitations, trees store "branch" information in nodes.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 nodesdoublegetEdgeLength(Node node1, Node node2) Returns the length of the edge that connects these two nodesgetEdges()Returns a list of edges connected to this nodeintgetExternalNodeCount(Node node) getExternalNodes(Node node) doubledoublegetNodes()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()booleanbooleanbooleanisExternal(Node node) booleanbooleanbooleanvoidremoveAttribute(String name) voidrenameTaxa(Taxon from, Taxon to) voidsetAttribute(String name, Object value) Sets an named attribute for this object.voidsetConceptuallyUnrooted(boolean conceptuallyUnrooted) Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface jebl.util.Attributable
getAttribute, getAttributeMap, getAttributeNames, removeAttribute, setAttribute
-
Constructor Details
-
CompactRootedTree
Do all the hard work.- Parameters:
t-
-
-
Method Details
-
getChildren
- 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 set may be empty for a terminal node (a tip).
-
getExternalNodeCount
- Specified by:
getExternalNodeCountin interfaceRootedTree
-
getExternalNodes
- Specified by:
getExternalNodesin 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:
hasHeightsin interfaceRootedTree- Returns:
- Whether this tree has node heights available
-
getHeight
- 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
- 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).
-
isHeightsKnown
public boolean isHeightsKnown()- Specified by:
isHeightsKnownin interfaceRootedTree- Returns:
- Whether the node heights are known or need to be recalculated from the lengths
-
isLengthsKnown
public boolean isLengthsKnown()- Specified by:
isLengthsKnownin interfaceRootedTree- Returns:
- Whether the branch lengths are known or need to be recalculated from the heights
-
getParent
- 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.
-
getParentEdge
-
getRootNode
Description copied from interface:RootedTreeThe 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.
-
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
-
setConceptuallyUnrooted
public void setConceptuallyUnrooted(boolean conceptuallyUnrooted) -
isRoot
- Specified by:
isRootin interfaceRootedTree- Parameters:
node- the node- Returns:
- true if the node is the root of this tree.
-
getExternalNodes
- Specified by:
getExternalNodesin interfaceTree- Returns:
- a set of all nodes that have degree 1. These nodes are often refered to as 'tips'.
-
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.
-
getExternalEdges
- Specified by:
getExternalEdgesin interfaceTree- Returns:
- a set of all edges that have a degree 1 node.
-
getInternalEdges
- Specified by:
getInternalEdgesin interfaceTree- Returns:
- a set of all edges for which both nodes have degree 2 or more.
-
getTaxa
-
getTaxon
-
isExternal
- Specified by:
isExternalin interfaceTree- Parameters:
node- the node- Returns:
- true if the node is of degree 1.
-
getNode
-
renameTaxa
- Specified by:
renameTaxain interfaceTree
-
getEdges
Description copied from interface:GraphReturns a list of edges connected to this node -
getAdjacencies
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
Description copied from interface:GraphReturns 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
Description copied from interface:GraphReturns the length of the edge that connects these two nodes- Specified by:
getEdgeLengthin interfaceGraph- Parameters:
node1-node2-- Returns:
- the edge length.
- Throws:
Graph.NoEdgeException- if the nodes are not directly connected by an edge.
-
getNodes
Description copied from interface:GraphReturns an array of 2 nodes which are the nodes at either end of the edge. -
getNodes
-
getEdges
-
getNodes
-
setAttribute
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
- 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
- Specified by:
removeAttributein interfaceAttributable- Parameters:
name- name of attribute to remove
-
getAttributeNames
- Specified by:
getAttributeNamesin interfaceAttributable- Returns:
- an array of the attributeNames that this object has.
-
getAttributeMap
Description copied from interface:AttributableGets the entire attribute map.- Specified by:
getAttributeMapin interfaceAttributable- Returns:
- an unmodifiable map
-