1 | #include "muscle.h" |
---|
2 | #include "tree.h" |
---|
3 | #include "clust.h" |
---|
4 | |
---|
5 | void Tree::InitCache(unsigned uCacheCount) |
---|
6 | { |
---|
7 | m_uCacheCount = uCacheCount; |
---|
8 | |
---|
9 | m_uNeighbor1 = new unsigned[m_uCacheCount]; |
---|
10 | m_uNeighbor2 = new unsigned[m_uCacheCount]; |
---|
11 | m_uNeighbor3 = new unsigned[m_uCacheCount]; |
---|
12 | |
---|
13 | m_Ids = new unsigned[m_uCacheCount]; |
---|
14 | |
---|
15 | m_dEdgeLength1 = new double[m_uCacheCount]; |
---|
16 | m_dEdgeLength2 = new double[m_uCacheCount]; |
---|
17 | m_dEdgeLength3 = new double[m_uCacheCount]; |
---|
18 | m_dHeight = new double[m_uCacheCount]; |
---|
19 | |
---|
20 | m_bHasEdgeLength1 = new bool[m_uCacheCount]; |
---|
21 | m_bHasEdgeLength2 = new bool[m_uCacheCount]; |
---|
22 | m_bHasEdgeLength3 = new bool[m_uCacheCount]; |
---|
23 | m_bHasHeight = new bool[m_uCacheCount]; |
---|
24 | |
---|
25 | m_ptrName = new char *[m_uCacheCount]; |
---|
26 | |
---|
27 | for (unsigned uNodeIndex = 0; uNodeIndex < m_uNodeCount; ++uNodeIndex) |
---|
28 | { |
---|
29 | m_uNeighbor1[uNodeIndex] = NULL_NEIGHBOR; |
---|
30 | m_uNeighbor2[uNodeIndex] = NULL_NEIGHBOR; |
---|
31 | m_uNeighbor3[uNodeIndex] = NULL_NEIGHBOR; |
---|
32 | m_bHasEdgeLength1[uNodeIndex] = false; |
---|
33 | m_bHasEdgeLength2[uNodeIndex] = false; |
---|
34 | m_bHasEdgeLength3[uNodeIndex] = false; |
---|
35 | m_bHasHeight[uNodeIndex] = false; |
---|
36 | m_dEdgeLength1[uNodeIndex] = dInsane; |
---|
37 | m_dEdgeLength2[uNodeIndex] = dInsane; |
---|
38 | m_dEdgeLength3[uNodeIndex] = dInsane; |
---|
39 | m_dHeight[uNodeIndex] = dInsane; |
---|
40 | m_ptrName[uNodeIndex] = 0; |
---|
41 | m_Ids[uNodeIndex] = uInsane; |
---|
42 | } |
---|
43 | } |
---|
44 | |
---|
45 | void Tree::FromClust(Clust &C) |
---|
46 | { |
---|
47 | Clear(); |
---|
48 | |
---|
49 | m_uNodeCount = C.GetNodeCount(); |
---|
50 | InitCache(m_uNodeCount); |
---|
51 | |
---|
52 | // Cluster is always rooted. An unrooted cluster |
---|
53 | // is represented by a pseudo-root, which we fix later. |
---|
54 | m_bRooted = true; |
---|
55 | const unsigned uRoot = C.GetRootNodeIndex(); |
---|
56 | m_uRootNodeIndex = uRoot; |
---|
57 | m_uNeighbor1[uRoot] = NULL_NEIGHBOR; |
---|
58 | m_bHasEdgeLength1[uRoot] = false; |
---|
59 | |
---|
60 | for (unsigned uNodeIndex = 0; uNodeIndex < m_uNodeCount; ++uNodeIndex) |
---|
61 | { |
---|
62 | if (C.IsLeaf(uNodeIndex)) |
---|
63 | { |
---|
64 | const char *ptrName = C.GetNodeName(uNodeIndex); |
---|
65 | m_ptrName[uNodeIndex] = strsave(ptrName); |
---|
66 | m_Ids[uNodeIndex] = C.GetNodeId(uNodeIndex); |
---|
67 | continue; |
---|
68 | } |
---|
69 | |
---|
70 | const unsigned uLeft = C.GetLeftIndex(uNodeIndex); |
---|
71 | const unsigned uRight = C.GetRightIndex(uNodeIndex); |
---|
72 | |
---|
73 | const double dLeftLength = C.GetLength(uLeft); |
---|
74 | const double dRightLength = C.GetLength(uRight); |
---|
75 | |
---|
76 | m_uNeighbor2[uNodeIndex] = uLeft; |
---|
77 | m_uNeighbor3[uNodeIndex] = uRight; |
---|
78 | |
---|
79 | m_dEdgeLength1[uLeft] = dLeftLength; |
---|
80 | m_dEdgeLength1[uRight] = dRightLength; |
---|
81 | |
---|
82 | m_uNeighbor1[uLeft] = uNodeIndex; |
---|
83 | m_uNeighbor1[uRight] = uNodeIndex; |
---|
84 | |
---|
85 | m_bHasEdgeLength1[uLeft] = true; |
---|
86 | m_bHasEdgeLength1[uRight] = true; |
---|
87 | |
---|
88 | m_dEdgeLength2[uNodeIndex] = dLeftLength; |
---|
89 | m_dEdgeLength3[uNodeIndex] = dRightLength; |
---|
90 | |
---|
91 | m_bHasEdgeLength2[uNodeIndex] = true; |
---|
92 | m_bHasEdgeLength3[uNodeIndex] = true; |
---|
93 | } |
---|
94 | Validate(); |
---|
95 | } |
---|