AccordionTreeDrawer
Class Tree

java.lang.Object
  |
  +--AccordionTreeDrawer.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:
Author:
Yunhong Zhou, Li Zhang
See Also:
TreeNode, Newick, Nexus, Status

Field Summary
private  int height
           
private  int key
          key should be unique for each tree, set by object that creates trees
private  int leafCount
          the number of leave nodes
(package private)  float leafSpace
           
(package private)  TreeNode leftmostLeaf
           
(package private)  java.lang.String name
           
private  int nodeCount
          total number of nodes for the tree
 java.util.ArrayList nodes
          The list of nodes of the tree indexed by their keys, indexed by key
(package private)  java.util.HashMap nodesByName
          Most internal nodes don't have names.
(package private) static Newick parser
          the parser responsible for parsing Newick format file, normally with a suffix nh
(package private) static Parser.nexus.Nexus parser_nexus
          the parser responsible for parsing Nexus format file, normally with a suffix nexus or nxs
 TreeNode posorderStartNode
          the start node for postorder list of all the nodes
 TreeNode preorderStartNode
          the start node for preorder list of all the nodes
(package private)  TreeNode root
           
 
Constructor Summary
Tree()
           
Tree(java.lang.String tn)
           
Tree(Tree t)
           
Tree(TreeNode rn)
           
 
Method Summary
 void close()
          clean up method, called when the tree is deleted
 int computeBin(int fontRange)
           
protected  void finalize()
           
(package private)  int getGapDistanceFromLeaves(TreeNode n1, TreeNode n2)
           
(package private)  int getHeight()
           
(package private)  int getInteriorCount()
           
 int getKey()
           
(package private)  int getLCADistanceFromLeaves(TreeNode n1, TreeNode n2)
           
 int getLeafCount()
           
 TreeNode getLeftmostLeaf()
           
 java.lang.String getName()
           
 TreeNode getNodeByKey(int key)
           
 TreeNode getNodeByName(java.lang.String s)
           
 TreeNode getRightmostLeaf()
           
 TreeNode getRoot()
           
 int getSize()
           
(package private)  int getTotalNodeCount()
           
private  void linkLeaves()
          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 ":"
private  void linkNodesInPosorder()
          Traverses the tree in pos-order, stores the ordering in the posorderNext field of TreeNodes
private  void linkNodesInPreorder()
          Traverses the tree in pre-order, stores the ordering in the preorderNext field of TreeNodes Sets nodecount for the tree
private  void linkSubtreeNodesInPosorder(TreeNode n)
          Traverses the subtree rooted at TreeNode n in post-order, stores the ordering in the posorderNext field of TreeNodes.
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 load_nexus(java.lang.String fname, int index)
          Reads a tree with giving index in a file fname with Nexus format and initiates the Tree object.
 void load(java.lang.String fname)
          Reads a tree in file fname described in Newick format and initiate the tree object.
 void postProcess()
          Post processing includes computing size of each node, linking nodes in different order, etc.
 void printLeaves()
           
(package private)  void printName()
           
 void setKey(int i)
           
(package private)  void setName(java.lang.String tn)
           
 void setNodeFontSize(int maxFontSize, int minFontSize)
           
(package private)  void setRoot(TreeNode rn)
           
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

parser

static Newick parser
the parser responsible for parsing Newick format file, normally with a suffix nh


parser_nexus

static Parser.nexus.Nexus parser_nexus
the parser responsible for parsing Nexus format file, normally with a suffix nexus or nxs


nodes

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


nodesByName

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.


nodeCount

private int nodeCount
total number of nodes for the tree


key

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


height

private int height

name

java.lang.String name

root

TreeNode root

leftmostLeaf

TreeNode leftmostLeaf

leafSpace

float leafSpace

leafCount

private int leafCount
the number of leave nodes


preorderStartNode

public TreeNode preorderStartNode
the start node for preorder list of all the nodes


posorderStartNode

public TreeNode posorderStartNode
the start node for postorder list of all the nodes

Constructor Detail

Tree

public Tree()

Tree

public Tree(java.lang.String tn)

Tree

public Tree(TreeNode rn)

Tree

public Tree(Tree t)
Method Detail

close

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

See Also:
TreeJuxtaposer.TreeJuxtaposer.deleteTree, TreeNode.close

finalize

protected void finalize()
                 throws java.lang.Throwable
Overrides:
finalize in class java.lang.Object
java.lang.Throwable

load

public void load(java.lang.String fname)
Reads a tree in file fname described in Newick format and initiate the tree object. Function load reads in the file, call the newick parser to parse it, and do some post processing afterwards. The tree object is originally empty. After calling the parser, it generates all the nodes decedant to the root. For each node of the tree, its name and edge weight will be set after parsing is complete. If the node has no name (internal nodes) or weight (some trees have no edge weight), then these fields will take the default value.

Parameters:
fname - The file name
See Also:
Newick

load_nexus

public void load_nexus(java.lang.String fname,
                       int index)
Reads a tree with giving index in a file fname with Nexus format and initiates the Tree object. Function load_nexus reads in the file, call the nexus parser to parse it, and do some post processing afterwards. The tree object is originally empty. After calling the parser, it generates all the nodes decedant to the root. For each node of the tree, its name and edge weight will be set after parsing is complete. If the node has no name (internal nodes) or weight (some trees have no edge weight), then these fields will take the default value.

Parameters:
fname - The file name
index - Index of the tree in the nexus file
See Also:
Nexus

getGapDistanceFromLeaves

int getGapDistanceFromLeaves(TreeNode n1,
                             TreeNode n2)

getLCADistanceFromLeaves

int getLCADistanceFromLeaves(TreeNode n1,
                             TreeNode n2)

getInteriorCount

int getInteriorCount()

getTotalNodeCount

int getTotalNodeCount()

getNodeByKey

public TreeNode getNodeByKey(int key)

getNodeByName

public TreeNode getNodeByName(java.lang.String s)

getHeight

int getHeight()

setKey

public void setKey(int i)

getKey

public int getKey()

getName

public java.lang.String getName()

getSize

public int getSize()

getLeftmostLeaf

public TreeNode getLeftmostLeaf()

getRightmostLeaf

public TreeNode getRightmostLeaf()

getRoot

public TreeNode getRoot()

setRoot

void setRoot(TreeNode rn)

setName

void setName(java.lang.String tn)

printName

void printName()

getLeafCount

public int getLeafCount()

postProcess

public void postProcess()
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!

See Also:
TreeNode

linkNodesInPreorder

private void linkNodesInPreorder()
Traverses the tree in pre-order, stores the ordering in the preorderNext field of TreeNodes Sets nodecount for the tree

See Also:
TreeNode

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

linkNodesInPosorder

private void linkNodesInPosorder()
Traverses the tree in pos-order, stores the ordering in the posorderNext field of TreeNodes

See Also:
TreeNode

linkSubtreeNodesInPosorder

private void linkSubtreeNodesInPosorder(TreeNode n)
Traverses the subtree rooted at TreeNode n in post-order, stores the ordering in the posorderNext field of TreeNodes.

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

linkLeaves

private void linkLeaves()
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 ":"

See Also:
linkNodesInPreorder(), TreeNode, NameComparator

printLeaves

public void printLeaves()

computeBin

public int computeBin(int fontRange)

setNodeFontSize

public void setNodeFontSize(int maxFontSize,
                            int minFontSize)