Class MP

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

public class MP
extends Algorithm

This class implements the Maximum Parsimony 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
MP(PTCControls inPhyTreesControls)
          Initializes specific GUI components used in the MP 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 MP algorithm.
 java.lang.String buildAns1()
          Generates the answers for the type 1 questions in the MP algorithm.
 java.lang.String buildAnswer2()
          Generates the answers for the type 2 questions in the MP algorithm.
 void calculateNewDistance()
          This method does nothing in the MP algorithm
 void calculateNumOfSubstitutions()
          Defines how to calculate the number of substitutions table in the MP algorithm
 void calculateTotalNumOfSubstitutions(int columns, int[][] subs)
          Defines how to calculate the total number of substitutions for a given column in a given table
 void computeAllSitesSubstitutions(java.util.Vector bestInterNodes, java.lang.String[][] bestCharacters, int[][] allNumOfSubs)
          Defines how to calculate the total number of substitutions table for all sites in the MP algorithm
 int computeNumOfTrees(int n)
          Computes the number of different trees for the given number of species.
 BestTreeMP constructBestTreeFrame(int x, int y)
          Constructs the best tree window used in the MP algorithm.
 void displayOneBestTree(java.util.Vector bestInterNodes, java.lang.String[][] bestCharacters, int[][] allNumOfSubs, TreeDisplay bestTreeDisplay, javax.swing.JFrame bestTreeFrame)
          Defines how to display one tree in the MP algorithm.
 void find()
          Defines how to find the nodes to join in the MP algorithm.
 void findInformativeSites()
          Finds the informative sites for a given input
 void findMiniMinj()
          Finds the next two nodes to be joined in the MP algorithm.
 boolean findOne()
          Implements the method in the Algorithm class and indicates if one tree is found in the MP algorithm.
 boolean finishStepTwo()
          Indicates if the algorithm has finished the second step of the MP algorithm.
 void generateRandom_ij()
          Generates random numbers for pop up questions in the MP algorithm.
 int getAllSitesSubs()
          Gets the total number of substituions for all sites used in the MP algorithm.
 int getBestTotalNumOfSubstitutions()
          Gets the best minimum total number of substituions for informative sites used in the MP algorithm.
 java.lang.String[][] getCharacters()
          Gets the characters table used in the MP algorithm.
 boolean getFind()
          Gets the status if the one tree has finished to compute the number of substitutions table.
 java.util.Vector getInfoSites()
          Gets the informative sites found in the MP algorithm.
 java.util.Vector getInterNodes()
          Gets the names of the inter nodes used in the MP algorithm.
 java.lang.String getInterSection(java.lang.String s1, java.lang.String s2)
          Defines the set intersection operation
 boolean getNoInfoSites()
          Gets the status if any informative sites are found in the MP algorithm.
 int[][] getNumOfSubstitutions()
          Gets the number of substituions table used in the MP algorithm.
 int getTotalNumOfSubstitutions()
          Gets the total number of substituions for informative sites used in the MP algorithm.
 java.lang.String getUnion(java.lang.String s1, java.lang.String s2)
          Defines the set union operation
 boolean init()
          Overrides the method in the Algorithm class and initializes specific data components used in the MP algorithm.
 boolean interSection(java.lang.String s1, java.lang.String s2)
          Indicates if the intersection of two sets are empty
 boolean isEnd()
          Implements the method in the Algorithm class and indicates if the algorithm terminates in the MP algorithm.
 void joinAndCalculate()
          Defines how to join nodes and calculates the characters in the MP algorithm.
 void joinLastTwoNodes()
          Defines how to join the last two nodes in the MP algorithm.
 void popUpQuestion1(int random_site)
          Generates type 1 pop up questions in the MP algorithm.
 void popUpQuestion2()
          Generates type 2 pop up questions in the MP algorithm.
 void processLastTwoNodes()
          Defines how to join last two nodes in the MP algorithm.
 void processMoreThanTwoNodes()
          Defines how to join more than two nodes in the MP algorithm.
 void processOneTree()
          Defines how to find one tree in the MP algorithm.
 void reset()
          Overrides the method in the Algorithm class and resets all components in the MP algorithm.
 void run()
          Implements the method in the Algorithm classs and defines how to run the FM algorithm.
 void trace()
          Implements the method in the Algorithm class and defines how to trace the MP algorithm.
 void updateAllNodes(java.util.Vector roots, java.lang.String[][] bestCharacters)
          Defines how to update all nodes information in the best tree window to display all sites in the MP algorithm
 void updateBestTree()
          Defines how to update the best tree window in the MP algorithm.
 void updateBestTreeFrameUI(javax.swing.JFrame bestTreeFrame, int[][] allNumOfSubs)
          Defines how to update the best tree window to add the number of substitutions table in the MP algorithm
 void updateMiniMinj()
          Updates the index of the nodes to be joined in the MP algorithm.
 void updateNodeSeq(Node node, java.lang.String[][] bestCharacters)
          Defines how to update one node information in the best tree window to display all sites in the MP algorithm
 void updateOneBestTree()
          Defines how to update one tree in the MP algorithm.
 void updateUI()
          Defines how to update the tree and the intermediate number of substitutions table in the MP algorithm.
 void updateUILastTwoNodes()
          Defines how to update the tree and the intermediate distance table when there are only two nodes left in the MP algorithm.
 void updateXY()
          Updates the position of the next best tree window.
 
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

MP

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

Parameters:
inPhyTreesControls - the PTCControls object
Method Detail

getFind

public boolean getFind()
Gets the status if the one tree has finished to compute the number of substitutions table.

Returns:
true - the one tree has finished to compute the number of substitutions table
false - the one tree has not finished to compute the number of substitutions table

getNumOfSubstitutions

public int[][] getNumOfSubstitutions()
Gets the number of substituions table used in the MP algorithm.

Returns:
the number of substituions table

getCharacters

public java.lang.String[][] getCharacters()
Gets the characters table used in the MP algorithm.

Returns:
the characters table

getInfoSites

public java.util.Vector getInfoSites()
Gets the informative sites found in the MP algorithm.

Returns:
the informative sites

getInterNodes

public java.util.Vector getInterNodes()
Gets the names of the inter nodes used in the MP algorithm.

Returns:
the names of the inter nodes

getTotalNumOfSubstitutions

public int getTotalNumOfSubstitutions()
Gets the total number of substituions for informative sites used in the MP algorithm.

Returns:
the total number of substituions table

getBestTotalNumOfSubstitutions

public int getBestTotalNumOfSubstitutions()
Gets the best minimum total number of substituions for informative sites used in the MP algorithm.

Returns:
the best minimum total number of substituions

getAllSitesSubs

public int getAllSitesSubs()
Gets the total number of substituions for all sites used in the MP algorithm.

Returns:
the minimum total number of substituions

getNoInfoSites

public boolean getNoInfoSites()
Gets the status if any informative sites are found in the MP algorithm.

Returns:
true - there are informative sites in the input
false - no informative sites are found in the input

init

public boolean init()
Overrides the method in the Algorithm class and initializes specific data components used in the MP 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 MP algorithm.

Specified by:
trace in class Algorithm

run

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

Specified by:
run in class Algorithm

findInformativeSites

public void findInformativeSites()
Finds the informative sites for a given input


processOneTree

public void processOneTree()
Defines how to find one tree in the MP algorithm.


displayOneBestTree

public void displayOneBestTree(java.util.Vector bestInterNodes,
                               java.lang.String[][] bestCharacters,
                               int[][] allNumOfSubs,
                               TreeDisplay bestTreeDisplay,
                               javax.swing.JFrame bestTreeFrame)
Defines how to display one tree in the MP algorithm.

Parameters:
bestInterNodes - the interior nodes in the best tree in the MP algorithm
bestCharacters - the characters of the nodes in the best tree in the MP algorithm
allNumOfSubs - the total number of subsititutions table in the best tree in the MP algorithm
bestTreeDisplay - the tree display object in the best tree in the MP algorithm
bestTreeFrame - the best tree window in the MP algorithm

updateOneBestTree

public void updateOneBestTree()
Defines how to update one tree in the MP algorithm.


processMoreThanTwoNodes

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


processLastTwoNodes

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


updateBestTree

public void updateBestTree()
Defines how to update the best tree window in the MP algorithm.


constructBestTreeFrame

public BestTreeMP constructBestTreeFrame(int x,
                                         int y)
Constructs the best tree window used in the MP algorithm.

Parameters:
x - the x axis position in the screen
y - the y axis position in the screen

updateXY

public void updateXY()
Updates the position of the next best tree window.


find

public void find()
Defines how to find the nodes to join in the MP algorithm.


joinAndCalculate

public void joinAndCalculate()
Defines how to join nodes and calculates the characters in the MP algorithm.


updateUI

public void updateUI()
Defines how to update the tree and the intermediate number of substitutions table in the MP algorithm.


joinLastTwoNodes

public void joinLastTwoNodes()
Defines how to join the last two nodes in the MP 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 MP algorithm.


calculateNumOfSubstitutions

public void calculateNumOfSubstitutions()
Defines how to calculate the number of substitutions table in the MP algorithm


interSection

public boolean interSection(java.lang.String s1,
                            java.lang.String s2)
Indicates if the intersection of two sets are empty

Parameters:
s1 - the one set to be operated
s2 - the other set to be operated
Returns:
true - the intersection of the two sets are not empty
false - the intersection of the two sets is empty

getInterSection

public java.lang.String getInterSection(java.lang.String s1,
                                        java.lang.String s2)
Defines the set intersection operation

Parameters:
s1 - the one set to be operated
s2 - the other set to be operated
Returns:
the intersection of the two sets

getUnion

public java.lang.String getUnion(java.lang.String s1,
                                 java.lang.String s2)
Defines the set union operation

Parameters:
s1 - the one set to be operated
s2 - the other set to be operated
Returns:
the union of the two sets

calculateTotalNumOfSubstitutions

public void calculateTotalNumOfSubstitutions(int columns,
                                             int[][] subs)
Defines how to calculate the total number of substitutions for a given column in a given table

Parameters:
columns - the column index
subs - the number of substitutions table

updateBestTreeFrameUI

public void updateBestTreeFrameUI(javax.swing.JFrame bestTreeFrame,
                                  int[][] allNumOfSubs)
Defines how to update the best tree window to add the number of substitutions table in the MP algorithm

Parameters:
bestTreeFrame - the best tree window
allNumOfSubs - the total number of substitutions table for all sites

computeAllSitesSubstitutions

public void computeAllSitesSubstitutions(java.util.Vector bestInterNodes,
                                         java.lang.String[][] bestCharacters,
                                         int[][] allNumOfSubs)
Defines how to calculate the total number of substitutions table for all sites in the MP algorithm

Parameters:
bestInterNodes - the names of the interior nodes in the best tree
bestCharacters - the characters of the interior nodes in the best tree
allNumOfSubs - the total number of substitutions table for all sites

updateAllNodes

public void updateAllNodes(java.util.Vector roots,
                           java.lang.String[][] bestCharacters)
Defines how to update all nodes information in the best tree window to display all sites in the MP algorithm

Parameters:
roots - the roots of the best tree
bestCharacters - the characters of the interior nodes in the best tree

updateNodeSeq

public void updateNodeSeq(Node node,
                          java.lang.String[][] bestCharacters)
Defines how to update one node information in the best tree window to display all sites in the MP algorithm

Parameters:
node - the node to be updated
bestCharacters - the characters of the node in the best tree

updateMiniMinj

public void updateMiniMinj()
Updates the index of the nodes to be joined in the MP algorithm.


findMiniMinj

public void findMiniMinj()
Finds the next two nodes to be joined in the MP algorithm.


computeNumOfTrees

public int computeNumOfTrees(int n)
Computes the number of different trees for the given number of species.

Parameters:
n - the number of species
Returns:
the number of trees

findOne

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

Specified by:
findOne in class Algorithm
Returns:
true - one tree is found
false - one tree is not found

isEnd

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

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

finishStepTwo

public boolean finishStepTwo()
Indicates if the algorithm has finished the second step of the MP algorithm.
The second step is to examine all trees for the informative sites.

Returns:
true - the algorithm has finished the second step
false - the algorithm has not finished the second step

calculateNewDistance

public void calculateNewDistance()
This method does nothing in the MP algorithm

Specified by:
calculateNewDistance in class Algorithm

reset

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

Overrides:
reset in class Algorithm

generateRandom_ij

public void generateRandom_ij()
Generates random numbers for pop up questions in the MP algorithm.


popUpQuestion1

public void popUpQuestion1(int random_site)
Generates type 1 pop up questions in the MP algorithm.


buildAns1

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

Returns:
the answer

popUpQuestion2

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


buildAnswer2

public java.lang.String buildAnswer2()
Generates the answers for the type 2 questions in the MP 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 MP algorithm.

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