net.sourceforge.olduvai.treejuxtaposer.drawer
Class Tree

java.lang.Object
  extended by net.sourceforge.olduvai.treejuxtaposer.drawer.Tree

public class Tree
extends java.lang.Object

A public class representing a (phylognenetic) tree. Nodes of the tree are of type TreeNode. Nodes are traversed in pre- and post-orders.

Version:
2.1
Author:
Yunhong Zhou, Li Zhang
See Also:
TreeNode

Field Summary
private  java.lang.String fileName
          File name for this tree.
private  int height
          Height of tree, which is also the longest path from the root to some leaf node.
private  int key
          key should be unique for each tree, set by object that creates trees
private  StaticSplitAxis leafSplitAxis
          Split axis reference for leaf recovery (leaves are attached to split line culling objects)
private  int nexusIndex
          Index of tree in nexus file, if this tree is from a nexus file.
 java.util.ArrayList nodes
          The list of nodes of the tree indexed by their keys, indexed by key
private  java.util.HashMap nodesByName
          Most internal nodes don't have names.
private  int numLeaves
          Leaf counter, for determining grid size, making arrays for tree comparisons
protected  TreeNode root
          Root node of this tree
 
Constructor Summary
Tree()
          Default tree constructor.
Tree(Tree treeToCopy)
          Copy constructor used to create versions of trees that are identical to the supplied input tree.
 
Method Summary
 void close()
          Clean up method, called when the tree is deleted.
protected  void finalize()
          Calls to #close() when tree is deleted.
protected  int getHeight()
          Accessor for height of tree.
private  int getInteriorCount()
          Returns the number of interior nodes in this tree.
 int getKey()
          Accessor for key.
 TreeNode getLeaf(int index)
          Get the leaf associated with the given leaf index.
 int getLeafCount()
          Returns the number of leaves in this tree.
 java.util.LinkedList getLeaves(TreeNode node)
          Get the leaves under this node.
 TreeNode getLeftmostLeaf()
          Left most leaf accessor.
 float getMaxObjectValue()
          Stub function
 float getMinObjectValue()
          Stub function
 java.lang.String getName()
          File name accessor.
 int getNexusIndex()
           
 TreeNode getNodeByKey(int key)
          Returns the node indexed by the given key.
 TreeNode getNodeByName(java.lang.String s)
          Returns the node given by the string.
 TreeNode getRoot()
          Root accessor.
protected  int getTotalNodeCount()
          Returns the node count, for internal and leaf nodes.
private  void linkLeaves(javax.swing.JProgressBar jpb)
          Links leaves of the tree in pre-order, check to see whether leaves have distinct names.
private  void linkNodesInPreorder()
          Wrapper for initiating linkSubtreeNodesInPreorder(TreeNode) with the root node.
private  void linkSubtreeNodesInPreorder(TreeNode n)
          Traverses the subtree rooted at TreeNode n in pre-order, stores the ordering in the preorderNext field of TreeNodes.
 void postProcess(javax.swing.JProgressBar jpb)
          Post processing includes computing size of each node, linking nodes in different order, etc.
private  void preorderPostProcess()
          Traverses the tree in pre-order, stores the ordering in the preorderNext field of TreeNodes Sets node count for the tree.
 void setFileName(java.lang.String tn)
          Sets the file name.
 void setKey(int i)
          Mutator for key
 void setLeafSplitAxis(StaticSplitAxis leafSplitAxis)
           
 void setRootNode(TreeNode newRoot)
           
 void setUpNameLists()
          Traverse the tree and initialize the nodesByName and nodes data structures.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

nodes

public java.util.ArrayList nodes
The list of nodes of the tree indexed by their keys, indexed by key


nodesByName

private java.util.HashMap nodesByName
Most internal nodes don't have names. Do we assign a unique name to each of them? No! each node has a key and the key is unique for nodes.


key

private int key
key should be unique for each tree, set by object that creates trees


numLeaves

private int numLeaves
Leaf counter, for determining grid size, making arrays for tree comparisons


leafSplitAxis

private StaticSplitAxis leafSplitAxis
Split axis reference for leaf recovery (leaves are attached to split line culling objects)


height

private int height
Height of tree, which is also the longest path from the root to some leaf node.


fileName

private java.lang.String fileName
File name for this tree.


nexusIndex

private int nexusIndex
Index of tree in nexus file, if this tree is from a nexus file.


root

protected TreeNode root
Root node of this tree

Constructor Detail

Tree

public Tree()
Default tree constructor. Nodes are created by parser and added in later.


Tree

public Tree(Tree treeToCopy)
Copy constructor used to create versions of trees that are identical to the supplied input tree. The copying should also make copies of the nodes in the given tree with the node copy constructor. (This function isn't working properly)

Parameters:
treeToCopy - Tree used to make a copy.
Method Detail

close

public void close()
Clean up method, called when the tree is deleted.

See Also:
TreeNode.close()

finalize

protected void finalize()
                 throws java.lang.Throwable
Calls to #close() when tree is deleted.

Overrides:
finalize in class java.lang.Object
Throws:
java.lang.Throwable

getInteriorCount

private int getInteriorCount()
Returns the number of interior nodes in this tree. For debugging.

Returns:
Total number of nodes minus the number of leaves.

getTotalNodeCount

protected int getTotalNodeCount()
Returns the node count, for internal and leaf nodes.

Returns:
Size of the nodes array, which contains all nodes.

getNodeByKey

public TreeNode getNodeByKey(int key)
Returns the node indexed by the given key.

Parameters:
key - Key of the node to retrieve.
Returns:
Treenode referenced by the given key.

getNodeByName

public TreeNode getNodeByName(java.lang.String s)
Returns the node given by the string.

Parameters:
s - Name/label of node to retrieve.
Returns:
Treenode referenced by the given name.

getHeight

protected int getHeight()
Accessor for height of tree. This is also the longest path from the root to some leaf node.

Returns:
value of height.

setKey

public void setKey(int i)
Mutator for key

Parameters:
i - New value for key.

getKey

public int getKey()
Accessor for key.

Returns:
Value of key.

getName

public java.lang.String getName()
File name accessor.

Returns:
value of fileName.

getLeftmostLeaf

public TreeNode getLeftmostLeaf()
Left most leaf accessor. This is the "min leaf"

Returns:
root's left most leaf, which is the smallest indexed leaf node in the tree.

getRoot

public TreeNode getRoot()
Root accessor.

Returns:
Value of root

setRootNode

public void setRootNode(TreeNode newRoot)

setFileName

public void setFileName(java.lang.String tn)
Sets the file name. Copies the value for some reason.

Parameters:
tn - New value for file name.

getLeafCount

public int getLeafCount()
Returns the number of leaves in this tree.

Returns:
value of numLeaves.

postProcess

public void postProcess(javax.swing.JProgressBar jpb)
Post processing includes computing size of each node, linking nodes in different order, etc. Sets left and right-most leaves of the tree. Computes and stores pre- and post-orders for leaves. Can't do minmax until after linkNodesInPreorder is called to set index values!

Parameters:
jpb - Progress bar
See Also:
TreeNode

preorderPostProcess

private void preorderPostProcess()
Traverses the tree in pre-order, stores the ordering in the preorderNext field of TreeNodes Sets node count for the tree.

See Also:
TreeNode

setUpNameLists

public void setUpNameLists()
Traverse the tree and initialize the nodesByName and nodes data structures. Used when modifying the names of nodes as well as initialization.


linkNodesInPreorder

private void linkNodesInPreorder()
Wrapper for initiating linkSubtreeNodesInPreorder(TreeNode) with the root node.


linkSubtreeNodesInPreorder

private void linkSubtreeNodesInPreorder(TreeNode n)
Traverses the subtree rooted at TreeNode n in pre-order, stores the ordering in the preorderNext field of TreeNodes.

Parameters:
n - the root of the subtree
See Also:
TreeNode

linkLeaves

private void linkLeaves(javax.swing.JProgressBar jpb)
Links leaves of the tree in pre-order, check to see whether leaves have distinct names. If leaves have the same name, add a suffix index separated by " "

Parameters:
jpb - Progress bar.
See Also:
linkNodesInPreorder(), TreeNode, NameComparator

getLeaf

public TreeNode getLeaf(int index)
Get the leaf associated with the given leaf index.

Parameters:
index - A leaf index of interest.
Returns:
The leaf node at the index, or null on error.

getMinObjectValue

public float getMinObjectValue()
Stub function


getMaxObjectValue

public float getMaxObjectValue()
Stub function


getNexusIndex

public int getNexusIndex()
Returns:
Returns the index number of this tree in the nexus file it was found in. Indexing starts at 0, and 0 for non-nexus.

setLeafSplitAxis

public void setLeafSplitAxis(StaticSplitAxis leafSplitAxis)
Parameters:
leafSplitAxis - The leafSplitLine to set.

getLeaves

public java.util.LinkedList getLeaves(TreeNode node)
Get the leaves under this node. Used for tree to tree comparison, removing leaf nodes from difference calculations when they only appear in one side of the tree. This operation is constant time per leaf, since it relies on pre-ordered node links and pointers to extreme leaves. Time complexity of this function is linear in the number of leaves in the subtree under the node.

Parameters:
node - Node to get leaves under. The root node will return all leaves in the tree, leaves return a list of just themselves.
Returns:
List of leaves under this node.