Next version of JABA
[jabaws.git] / binaries / src / muscle / clust.h
1 #ifndef Clust_h\r
2 #define Clust_h\r
3 \r
4 class Clust;\r
5 class ClustNode;\r
6 class ClustSet;\r
7 class Phylip;\r
8 class SortedNode;\r
9 \r
10 const unsigned RB_NIL = ((unsigned) 0xfff0);\r
11 \r
12 class ClustNode\r
13         {\r
14 public:\r
15         ClustNode()\r
16                 {\r
17                 m_uIndex = uInsane;\r
18                 m_uSize = uInsane;\r
19                 m_dLength = (float) dInsane;\r
20                 m_ptrLeft = 0;\r
21                 m_ptrRight = 0;\r
22                 m_ptrParent = 0;\r
23                 m_ptrNextCluster = 0;\r
24                 m_ptrPrevCluster = 0;\r
25                 m_uLeafIndexes = 0;\r
26                 }\r
27         ~ClustNode()\r
28                 {\r
29                 delete[] m_uLeafIndexes;\r
30                 }\r
31         unsigned m_uIndex;\r
32         unsigned m_uSize;\r
33         float m_dLength;\r
34         ClustNode *m_ptrLeft;\r
35         ClustNode *m_ptrRight;\r
36         ClustNode *m_ptrParent;\r
37         ClustNode *m_ptrNextCluster;\r
38         ClustNode *m_ptrPrevCluster;\r
39         unsigned *m_uLeafIndexes;\r
40         };\r
41 \r
42 class Clust\r
43         {\r
44 public:\r
45         Clust();\r
46         virtual ~Clust();\r
47 \r
48         void Create(ClustSet &Set, CLUSTER Method);\r
49 \r
50         unsigned GetLeafCount() const;\r
51 \r
52         unsigned GetClusterCount() const;\r
53         unsigned GetClusterSize(unsigned uNodeIndex) const;\r
54         unsigned GetLeaf(unsigned uClusterIndex, unsigned uLeafIndex) const;\r
55 \r
56         unsigned GetNodeCount() const { return 2*m_uLeafCount - 1; }\r
57         const ClustNode &GetRoot() const { return m_Nodes[GetRootNodeIndex()]; }\r
58         unsigned GetRootNodeIndex() const { return m_uNodeCount - 1; }\r
59 \r
60         const ClustNode &GetNode(unsigned uNodeIndex) const;\r
61         bool IsLeaf(unsigned uNodeIndex) const;\r
62         unsigned GetLeftIndex(unsigned uNodeIndex) const;\r
63         unsigned GetRightIndex(unsigned uNodeIndex) const;\r
64         float GetLength(unsigned uNodeIndex) const;\r
65         float GetHeight(unsigned uNodeIndex) const;\r
66         const char *GetNodeName(unsigned uNodeIndex) const;\r
67         unsigned GetNodeId(unsigned uNodeIndex) const;\r
68 \r
69         JOIN GetJoinStyle() const { return m_JoinStyle; }\r
70         LINKAGE GetCentroidStyle() const { return m_CentroidStyle; }\r
71 \r
72         void SetDist(unsigned uIndex1, unsigned uIndex2, float dDist);\r
73         float GetDist(unsigned uIndex1, unsigned uIndex2) const;\r
74 \r
75         void ToPhylip(Phylip &tree);\r
76 \r
77         void LogMe() const;\r
78 \r
79 //private:\r
80         void SetLeafCount(unsigned uLeafCount);\r
81 \r
82         void CreateCluster();\r
83         void JoinNodes(unsigned uLeftNodeIndex, unsigned uRightNodeIndex, \r
84           float dLeftLength, float dRightLength, unsigned uNewNodeIndex);\r
85 \r
86         void ChooseJoin(unsigned *ptruLeftIndex, unsigned *ptruRightIndex,\r
87           float *ptrdLeftLength, float *ptrdRightLength);\r
88         void ChooseJoinNeighborJoining(unsigned *ptruLeftIndex, unsigned *ptruRightIndex,\r
89           float *ptrdLeftLength, float *ptrdRightLength);\r
90         void ChooseJoinNearestNeighbor(unsigned *ptruLeftIndex, unsigned *ptruRightIndex,\r
91           float *ptrdLeftLength, float *ptrdRightLength);\r
92 \r
93         float ComputeDist(unsigned uNewNodeIndex, unsigned uNodeIndex);\r
94         float ComputeDistAverageLinkage(unsigned uNewNodeIndex, unsigned uNodeIndex);\r
95         float ComputeDistMinLinkage(unsigned uNewNodeIndex, unsigned uNodeIndex);\r
96         float ComputeDistMaxLinkage(unsigned uNewNodeIndex, unsigned uNodeIndex);\r
97         float ComputeDistNeighborJoining(unsigned uNewNewIndex, unsigned uNodeIndex);\r
98         float ComputeDistMAFFT(unsigned uNewNewIndex, unsigned uNodeIndex);\r
99 \r
100         float Calc_r(unsigned uNodeIndex) const;\r
101 \r
102         unsigned VectorIndex(unsigned uIndex1, unsigned uIndex2) const;\r
103 \r
104         unsigned GetFirstCluster() const;\r
105         unsigned GetNextCluster(unsigned uNodeIndex) const;\r
106 \r
107         float ComputeMetric(unsigned uIndex1, unsigned uIndex2) const;\r
108         float ComputeMetricNearestNeighbor(unsigned i, unsigned j) const;\r
109         float ComputeMetricNeighborJoining(unsigned i, unsigned j) const;\r
110 \r
111         void InitMetric(unsigned uMaxNodeIndex);\r
112         void InsertMetric(unsigned uIndex1, unsigned uIndex2, float dMetric);\r
113         float GetMinMetric(unsigned *ptruIndex1, unsigned *ptruIndex2) const;\r
114         float GetMinMetricBruteForce(unsigned *ptruIndex1, unsigned *ptruIndex2) const;\r
115         void DeleteMetric(unsigned uIndex);\r
116         void DeleteMetric(unsigned uIndex1, unsigned uIndex2);\r
117         void ListMetric() const;\r
118 \r
119         void DeleteFromClusterList(unsigned uNodeIndex);\r
120         void AddToClusterList(unsigned uNodeIndex);\r
121 \r
122         void RBDelete(unsigned RBNode);\r
123         unsigned RBInsert(unsigned i, unsigned j, float fMetric);\r
124 \r
125         unsigned RBNext(unsigned RBNode) const;\r
126         unsigned RBPrev(unsigned RBNode) const;\r
127         unsigned RBMin(unsigned RBNode) const;\r
128         unsigned RBMax(unsigned RBNode) const;\r
129 \r
130         void ValidateRB(const char szMsg[] = 0) const;\r
131         void ValidateRBNode(unsigned Node, const char szMsg[]) const;\r
132 \r
133 //private:\r
134         JOIN m_JoinStyle;\r
135         LINKAGE m_CentroidStyle;\r
136         ClustNode *m_Nodes;\r
137         unsigned *m_ClusterIndexToNodeIndex;\r
138         unsigned *m_NodeIndexToClusterIndex;\r
139         unsigned m_uLeafCount;\r
140         unsigned m_uNodeCount;\r
141         unsigned m_uClusterCount;\r
142         unsigned m_uTriangularMatrixSize;\r
143         float *m_dDist;\r
144         ClustSet *m_ptrSet;\r
145         ClustNode *m_ptrClusterList;\r
146         };\r
147 \r
148 #endif // Clust_h\r