Package jebl.evolution.trees

# Class SimpleTree

java.lang.Object
jebl.evolution.trees.SimpleTree

All Implemented Interfaces:
  `Graph`, `Tree`, `Attributable`

public final class SimpleTree extends Object implements Tree
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

Constructors
Constructor
Description
`SimpleTree()`
Tree (to be constructed by subsequent calls).
`SimpleTree(Tree tree)`
Duplicate a tree.

## Method Summary

Modifier and Type
Method
Description
`void`
`addEdge(Node node1, Node node2, double length)`
Add a new edge between two existing (non adjacent yet) nodes.
`Node`
`createExternalNode(Taxon taxon)`
Creates a new external node with the given taxon.
`Node`
`createInternalNode(List<Node> adjacencies)`
Once a SimpleTree has been created, the node stucture can be created by calling createExternalNode and createInternalNode.
`List<Node>`
`getAdjacencies(Node node)`
Returns a list of nodes connected to this node by an edge
`Object`
`getAttribute(String name)`
`Map<String,Object>`
`getAttributeMap()`
Gets the entire attribute map.
`Set<String>`
`getAttributeNames()`
`Edge`
`getEdge(Node node1, Node node2)`
Returns the Edge that connects these two nodes
`double`
`getEdgeLength(Node node1, Node node2)`
Returns the length of the edge that connects these two nodes
`Set<Edge>`
`getEdges()`
`List<Edge>`
`getEdges(Node node)`
Returns a list of edges connected to this node
`Set<Edge>`
`getExternalEdges()`
The set of external edges.
`Set<Node>`
`getExternalNodes()`
`Set<Edge>`
`getInternalEdges()`
The set of internal edges.
`Set<Node>`
`getInternalNodes()`
`Node`
`getNode(Taxon taxon)`
`Set<Node>`
`getNodes()`
`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.
`Set<Taxon>`
`getTaxa()`
`Taxon`
`getTaxon(Node node)`
`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.

### Methods inherited from class java.lang.Object

`equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### SimpleTree

public SimpleTree()
Tree (to be constructed by subsequent calls).

### SimpleTree

public SimpleTree(Tree tree)
Duplicate a tree.

Parameters:
  `tree` -

## Method Details

### 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 Node createInternalNode(List<Node> adjacencies)
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

public void setEdgeLength(Node node1, Node node2, double length)
Set edge distance between two adjacent nodes.

Parameters:
  `node1` -
  `node2` -
  `length` -

### setEdgeLength

public void setEdgeLength(Edge edge, double length)
Change length of an existing edge.

Parameters:
  `edge` -
  `length` -

### addEdge

public void addEdge(Node node1, Node node2, double length)
Add a new edge between two existing (non adjacent yet) nodes.

Parameters:
  `node1` -
  `node2` -
  `length` -

### getEdges

public List<Edge> getEdges(Node node)
Returns a list of edges connected to this node

Specified by:
  `getEdges` in interface `Graph`
Parameters:
  `node` -
Returns:
  the set of nodes that are attached by edges to the given node.

### getAdjacencies

public 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 interface `Graph`
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:
  `getEdge` in interface `Graph`
Parameters:
  `node1` -
  `node2` -
Returns:
  the edge object.
Throws:
  `Graph.NoEdgeException` - if the nodes are not directly connected by an edge.

### getExternalNodes

public Set<Node> getExternalNodes()

Specified by:
  `getExternalNodes` in interface `Tree`
Returns:
  a set of all nodes that have degree 1. These nodes are often refered to as 'tips'.

### getInternalNodes

public Set<Node> getInternalNodes()

Specified by:
  `getInternalNodes` in interface `Tree`
Returns:
  a set of all nodes that have degree 2 or more. These nodes are often refered to as internal nodes.

### getTaxa

public Set<Taxon> getTaxa()

Specified by:
  `getTaxa` in interface `Tree`
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

public Taxon getTaxon(Node node)

Specified by:
  `getTaxon` in interface `Tree`
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

public boolean isExternal(Node node)

Specified by:
  `isExternal` in interface `Tree`
Parameters:
  `node` - the node
Returns:
  true if the node is of degree 1.

### isExternal

public boolean isExternal(Edge edge)

Parameters:
  `edge` - the edge
Returns:
  true if the edge has a node of degree 1.

### getNode

public Node getNode(Taxon taxon)

Specified by:
  `getNode` in interface `Tree`
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

public void renameTaxa(Taxon from, Taxon to)

Specified by:
  `renameTaxa` in interface `Tree`

### 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 interface `Graph`
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 Node[] getNodes(Edge edge)
Returns an array of 2 nodes which are the nodes at either end of the edge.

Specified by:
  `getNodes` in interface `Graph`
Parameters:
  `edge` -
Returns:
  an array of 2 edges

### getNodes

public Set<Node> getNodes()

Specified by:
  `getNodes` in interface `Graph`
Returns:
  the set of all nodes in this graph.

### getEdges

public Set<Edge> getEdges()

Specified by:
  `getEdges` in interface `Graph`
Returns:
  the set of all edges in this graph.

### getNodes

public Set<Node> getNodes(int degree)

Specified by:
  `getNodes` in interface `Graph`
Parameters:
  `degree` - the number of edges connected to a node
Returns:
  a set containing all nodes in this graph of the given degree.

### getExternalEdges

public 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:
  `getExternalEdges` in interface `Tree`
Returns:
  the set of external edges.

### getInternalEdges

public 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:
  `getInternalEdges` in interface `Tree`
Returns:
  the set of internal edges.

### setAttribute

public void setAttribute(String name, Object value)
Description copied from interface: `Attributable`
Sets an named attribute for this object.

Specified by:
  `setAttribute` in interface `Attributable`
Parameters:
  `name` - the name of the attribute.
  `value` - the new value of the attribute.

### getAttribute

public Object getAttribute(String name)

Specified by:
  `getAttribute` in interface `Attributable`
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(String name)

Specified by:
  `removeAttribute` in interface `Attributable`
Parameters:
  `name` - name of attribute to remove

### getAttributeNames

public Set<String> getAttributeNames()

Specified by:
  `getAttributeNames` in interface `Attributable`
Returns:
  an array of the attributeNames that this object has.

### getAttributeMap

public Map<String,Object> getAttributeMap()
Description copied from interface: `Attributable`
Gets the entire attribute map.

Specified by:
  `getAttributeMap` in interface `Attributable`
Returns:
  an unmodifiable map