Next version of JABA
[jabaws.git] / binaries / src / clustalw / src / tree / UPGMA / UPGMAAlgorithm.h
1 #ifndef __UPGMAALGORITHM_H
2 #define __UPGMAALGORITHM_H
3
4 #include "Node.h" 
5 #include <limits>
6 #include "../../general/clustalw.h"
7 #include "../AlignmentSteps.h"
8 #include "RootedGuideTree.h"
9 #include <list>
10 #include <memory>
11
12 namespace clustalw
13 {
14
15 using namespace std;
16
17 class UPGMAAlgorithm
18 {
19     public:
20         bool overwriteMatrix; 
21
22         UPGMAAlgorithm();
23         auto_ptr<AlignmentSteps> generateTree(RootedGuideTree* phyTree, 
24                                     DistMatrix* distMat, SeqInfo* seqInfo,
25                                     bool overwrite, ofstream* tree = 0);
26         void setVerbose(bool _verbose){verbose = _verbose;}                            
27                   
28     private:
29         Node **initialiseNodes(double *distanceMatrix, int firstSeq);
30
31         Node *doUPGMA(Node **nodes, ofstream* tree);
32         void printAllNodes(Node** nodes);
33         void addAlignmentStep(vector<int>* group1, vector<int>* group2);
34         Node** getNodeWithMinDist(Node** clusters);
35         void recomputeNodeToJoin1DistMatRow(Node* nodeToJoin1, double** nodeToJoin2DistIter);
36         void computeAllOtherDistsToNewNode(Node* nodeToJoin1, Node* nodeToJoin2,
37                                                    double** nodeToJoin2DistIter);
38         void computeDistsUpToNodeToJoin2(Node* nToJoin1, Node* nToJoin2, 
39                                          double** nodeToJoin2DistIter);
40         void computeDistsForNodesAfterNode2(Node* nToJoin2);
41         void movePtrPastUnusedDistances(double** ptrToDist)
42         {            
43             while(**ptrToDist < 0)
44             {
45                 (*ptrToDist)++;
46             }
47         }
48         double calcNewDist(double dist1, double dist2);                             
49         //vector<Node*>::iterator getIterToNodeWithMinDist(vector<Node*>* nodesLeft);
50         
51         auto_ptr<AlignmentSteps> progSteps;
52         int numSeqs; 
53         bool verbose;
54         int orderNode1, orderNode2, orderNewNode;
55 };
56
57 }
58
59 #endif