Class NJ

java.lang.Object
  |
  +--Algorithm
        |
        +--NJ
All Implemented Interfaces:
java.awt.event.ActionListener, java.util.EventListener

public class NJ
extends Algorithm

This class implements the Neighbor Joining algorithm described in the package.


Field Summary
 
Fields inherited from class Algorithm
ansField, ansFrame, ansLabel, answer, count, display, infoArea, inputTable, interNode, interTable, maxLength, maxName, mini, minj, minLength, names, nodes, numOfNodes, numOfNodesLeft, okAnsButton, okQuesButton, phyTreesControls, popUpQues, quesFrame, quesLabel, question, random_i, random_j, roots, runType, treeDisplay
 
Constructor Summary
NJ(PTCControls inPhyTreesControls)
          Initializes specific GUI components used in the NJ algorithm.
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent e)
          Defines how to handle the actions of the OK buttons for the question and the answer windows in the NJ algorithm.
 java.lang.String buildAnswer1()
          Generates the answers for the type 1 questions in the NJ algorithm.
 java.lang.String buildAnswer2()
          Generates the answers for the type 2 questions in the NJ algorithm.
 void calculateNewDistance()
          Implements the method in the Algorithm calss and defines how to calculate new distance matrix in the NJ algorithm.
 void calculateSumAndR()
          Defines how to calculate sum and r values in the NJ algorithm.
 void calculateTransformDistance()
          Defines how to calculate transform distance table in the NJ algorithm.
 void constructTransFrame()
          Constructs the tranform distance table window.
 void displayTransformDistance()
          Defines how to display transform distance table in the NJ algorithm.
 void findAndCalculate()
          Defines how to find the nodes to join and calculate branch lengths in the NJ algorithm.
 boolean findOne()
          Implements the method in the Algorithm class and indicates if one tree is found.
 void generateRandom_ij()
          Generates random numbers for pop up questions involved the new distance table in the NJ algorithm.
 void generateRandom_mn()
          Generates random numbers for pop up questions involved the transform distance table in the NJ algorithm.
 double[][] getDistance()
          Gets the distance matrix used in the NJ algorithm.
 TransDistanceModel getPTransDistanceModel()
          Gets the transform distance model used in the transform distance table in the NJ algorithm.
 double[][] getTransDistance()
          Gets the transform distance matrix used in the NJ algorithm.
 boolean init()
          Overrides the method in the Algorithm class and initializes specific data components used in the NJ algorithm.
 boolean isEnd()
          Implements the method in the Algorithm class and indicates if the algorithm terminates in the NJ algorithm.
 void join()
          Defines how to join the two nodes when there are more than two nodes left in the NJ algorithm.
 void joinLastTwoNodes()
          Defines how to joins the last two nodes in the NJ algorithm.
 void popUpQuestion1()
          Generates type 1 pop up questions in the NJ algorithm.
 void popUpQuestion2()
          Generates type 2 pop up questions in the NJ algorithm.
 void processLastTwoNodes()
          Defines how to join last two nodes in the NJ algorithm.
 void processMoreThanTwoNodes()
          Defines how to join more than two nodes in the NJ algorithm.
 void reset()
          Overrides the method in the Algorithm class and resets all components in the NJ algorithm.
 void run()
          Implements the method in the Algorithm classs and defines how to run the NJ algorithm.
 void trace()
          Implements the method in the Algorithm class and defines how to trace the NJ algorithm.
 void updateTransformDistance()
          Defines how to update transform distance table in the NJ algorithm.
 void updateUI()
          Defines how to update the tree and the intermediate distance table when there are more than two nodes left in the NJ algorithm.
 void updateUILastTwoNodes()
          Defines how to update the tree and the intermediate distance table when there are only two nodes left in the NJ algorithm.
 
Methods inherited from class Algorithm
computeMaxName, computeMinMaxLength, constructAnsFrame, constructButton, constructQuesFrame, deleteNodes, findMin, getCount, getDisplay, getInterNode, getMaxLength, getMaxName, getMinLength, getNames, getNode, getNodes, getNumOfNodes, getNumOfNodesLeft, getRoots, randomInt, setPopUpQues, setRoots, setRunType, setThreeFractionDigit, updateTree
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NJ

public NJ(PTCControls inPhyTreesControls)
Initializes specific GUI components used in the NJ algorithm.

Parameters:
inPhyTreesControls - the PTCControls object
Method Detail

getDistance

public double[][] getDistance()
Gets the distance matrix used in the NJ algorithm.

Returns:
the distance matrix used in the NJ algorithm

getTransDistance

public double[][] getTransDistance()
Gets the transform distance matrix used in the NJ algorithm.

Returns:
the transform distance matrix used in the NJ algorithm.

getPTransDistanceModel

public TransDistanceModel getPTransDistanceModel()
Gets the transform distance model used in the transform distance table in the NJ algorithm.

Returns:
the transform distance model

init

public boolean init()
Overrides the method in the Algorithm class and initializes specific data components used in the NJ algorithm.

Overrides:
init in class Algorithm
Returns:
true - the algorithm is properly initialized
false - input data is not right

trace

public void trace()
Implements the method in the Algorithm class and defines how to trace the NJ algorithm.

Specified by:
trace in class Algorithm

run

public void run()
Implements the method in the Algorithm classs and defines how to run the NJ algorithm.

Specified by:
run in class Algorithm

processMoreThanTwoNodes

public void processMoreThanTwoNodes()
Defines how to join more than two nodes in the NJ algorithm.


processLastTwoNodes

public void processLastTwoNodes()
Defines how to join last two nodes in the NJ algorithm.


findAndCalculate

public void findAndCalculate()
Defines how to find the nodes to join and calculate branch lengths in the NJ algorithm.


join

public void join()
Defines how to join the two nodes when there are more than two nodes left in the NJ algorithm.


updateUI

public void updateUI()
Defines how to update the tree and the intermediate distance table when there are more than two nodes left in the NJ algorithm.


joinLastTwoNodes

public void joinLastTwoNodes()
Defines how to joins the last two nodes in the NJ algorithm.


updateUILastTwoNodes

public void updateUILastTwoNodes()
Defines how to update the tree and the intermediate distance table when there are only two nodes left in the NJ algorithm.


calculateTransformDistance

public void calculateTransformDistance()
Defines how to calculate transform distance table in the NJ algorithm.


displayTransformDistance

public void displayTransformDistance()
Defines how to display transform distance table in the NJ algorithm.


updateTransformDistance

public void updateTransformDistance()
Defines how to update transform distance table in the NJ algorithm.


calculateNewDistance

public void calculateNewDistance()
Implements the method in the Algorithm calss and defines how to calculate new distance matrix in the NJ algorithm.

Specified by:
calculateNewDistance in class Algorithm

calculateSumAndR

public void calculateSumAndR()
Defines how to calculate sum and r values in the NJ algorithm.


constructTransFrame

public void constructTransFrame()
Constructs the tranform distance table window.


reset

public void reset()
Overrides the method in the Algorithm class and resets all components in the NJ algorithm.

Overrides:
reset in class Algorithm

isEnd

public boolean isEnd()
Implements the method in the Algorithm class and indicates if the algorithm terminates in the NJ algorithm.

Specified by:
isEnd in class Algorithm
Returns:
true - the algorithm terminates
false - the algorithm does not terminate

findOne

public boolean findOne()
Implements the method in the Algorithm class and indicates if one tree is found.

Specified by:
findOne in class Algorithm
Returns:
false for the NJ algorithm

generateRandom_mn

public void generateRandom_mn()
Generates random numbers for pop up questions involved the transform distance table in the NJ algorithm.


generateRandom_ij

public void generateRandom_ij()
Generates random numbers for pop up questions involved the new distance table in the NJ algorithm.


popUpQuestion1

public void popUpQuestion1()
Generates type 1 pop up questions in the NJ algorithm.


buildAnswer1

public java.lang.String buildAnswer1()
Generates the answers for the type 1 questions in the NJ algorithm.

Returns:
the answer

popUpQuestion2

public void popUpQuestion2()
Generates type 2 pop up questions in the NJ algorithm.


buildAnswer2

public java.lang.String buildAnswer2()
Generates the answers for the type 2 questions in the NJ algorithm.

Returns:
the answer

actionPerformed

public void actionPerformed(java.awt.event.ActionEvent e)
Defines how to handle the actions of the OK buttons for the question and the answer windows in the NJ algorithm.

Parameters:
e - the ActionEvent object which is responsible for the action