source: branches/stable/GDE/MUSCLE/src/clust.h

Last change on this file was 10390, checked in by aboeckma, 11 years ago

added muscle sourcles amd makefile

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