Package jebl.evolution.trees
Class SimpleTree
java.lang.Object
jebl.evolution.trees.SimpleTree
- All Implemented Interfaces:
Graph
,Tree
,Attributable
A basic implementation on an unrooted tree.
- Version:
- $Id: SimpleTree.java 956 2008-11-30 01:18:20Z rambaut $
- Author:
- Joseph Heled
-
Nested Class Summary
Nested classes/interfaces inherited from interface jebl.evolution.graphs.Graph
Graph.NoEdgeException, Graph.Utils
-
Constructor Summary
ConstructorsConstructorDescriptionTree (to be constructed by subsequent calls).SimpleTree
(Tree tree) Duplicate a tree. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Add a new edge between two existing (non adjacent yet) nodes.createExternalNode
(Taxon taxon) Creates a new external node with the given taxon.createInternalNode
(List<Node> adjacencies) Once a SimpleTree has been created, the node stucture can be created by calling createExternalNode and createInternalNode.getAdjacencies
(Node node) Returns a list of nodes connected to this node by an edgegetAttribute
(String name) Gets the entire attribute map.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.The set of internal edges.getNodes()
getNodes
(int degree) Node[]
Returns an array of 2 nodes which are the nodes at either end of the edge.getTaxa()
boolean
isExternal
(Edge edge) boolean
isExternal
(Node node) void
removeAttribute
(String name) void
renameTaxa
(Taxon from, Taxon to) void
setAttribute
(String name, Object value) Sets an named attribute for this object.void
setEdgeLength
(Edge edge, double length) Change length of an existing edge.void
setEdgeLength
(Node node1, Node node2, double length) Set edge distance between two adjacent nodes.
-
Constructor Details
-
SimpleTree
public SimpleTree()Tree (to be constructed by subsequent calls). -
SimpleTree
Duplicate a tree.- Parameters:
tree
-
-
-
Method Details
-
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
Once a SimpleTree 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 new internal nodes. It is the caller responsibility to insure no cycles are created.- Parameters:
adjacencies
- the child nodes of this node- Returns:
- the created node.
-
setEdgeLength
Set edge distance between two adjacent nodes.- Parameters:
node1
-node2
-length
-
-
setEdgeLength
Change length of an existing edge.- Parameters:
edge
-length
-
-
addEdge
Add a new edge between two existing (non adjacent yet) nodes.- Parameters:
node1
-node2
-length
-
-
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.
-
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.
-
isExternal
- Parameters:
edge
- the edge- Returns:
- true if the edge has a node of degree 1.
-
getNode
-
renameTaxa
- Specified by:
renameTaxa
in interfaceTree
-
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
-
getNodes
-
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.
-
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
-