1 | #include "muscle.h" |
---|
2 | #include <math.h> |
---|
3 | #include "tree.h" |
---|
4 | #include "seqvect.h" |
---|
5 | #include "profile.h" |
---|
6 | #include "msa.h" |
---|
7 | #include "pwpath.h" |
---|
8 | #include "distfunc.h" |
---|
9 | |
---|
10 | #define TRACE 0 |
---|
11 | |
---|
12 | void ProgressiveAlign(const SeqVect &v, const Tree &GuideTree, MSA &a) |
---|
13 | { |
---|
14 | assert(GuideTree.IsRooted()); |
---|
15 | |
---|
16 | #if TRACE |
---|
17 | Log("GuideTree:\n"); |
---|
18 | GuideTree.LogMe(); |
---|
19 | #endif |
---|
20 | |
---|
21 | const unsigned uSeqCount = v.Length(); |
---|
22 | const unsigned uNodeCount = 2*uSeqCount - 1; |
---|
23 | |
---|
24 | ProgNode *ProgNodes = new ProgNode[uNodeCount]; |
---|
25 | |
---|
26 | unsigned uJoin = 0; |
---|
27 | unsigned uTreeNodeIndex = GuideTree.FirstDepthFirstNode(); |
---|
28 | SetProgressDesc("Align node"); |
---|
29 | do |
---|
30 | { |
---|
31 | if (GuideTree.IsLeaf(uTreeNodeIndex)) |
---|
32 | { |
---|
33 | if (uTreeNodeIndex >= uNodeCount) |
---|
34 | Quit("TreeNodeIndex=%u NodeCount=%u\n", uTreeNodeIndex, uNodeCount); |
---|
35 | ProgNode &Node = ProgNodes[uTreeNodeIndex]; |
---|
36 | unsigned uId = GuideTree.GetLeafId(uTreeNodeIndex); |
---|
37 | if (uId >= uSeqCount) |
---|
38 | Quit("Seq index out of range"); |
---|
39 | const Seq &s = *(v[uId]); |
---|
40 | Node.m_MSA.FromSeq(s); |
---|
41 | Node.m_MSA.SetSeqId(0, uId); |
---|
42 | Node.m_uLength = Node.m_MSA.GetColCount(); |
---|
43 | } |
---|
44 | else |
---|
45 | { |
---|
46 | Progress(uJoin, uSeqCount - 1); |
---|
47 | ++uJoin; |
---|
48 | |
---|
49 | const unsigned uMergeNodeIndex = uTreeNodeIndex; |
---|
50 | ProgNode &Parent = ProgNodes[uMergeNodeIndex]; |
---|
51 | |
---|
52 | const unsigned uLeft = GuideTree.GetLeft(uTreeNodeIndex); |
---|
53 | const unsigned uRight = GuideTree.GetRight(uTreeNodeIndex); |
---|
54 | |
---|
55 | ProgNode &Node1 = ProgNodes[uLeft]; |
---|
56 | ProgNode &Node2 = ProgNodes[uRight]; |
---|
57 | |
---|
58 | PWPath Path; |
---|
59 | AlignTwoMSAs(Node1.m_MSA, Node2.m_MSA, Parent.m_MSA, Path); |
---|
60 | Parent.m_uLength = Parent.m_MSA.GetColCount(); |
---|
61 | |
---|
62 | Node1.m_MSA.Clear(); |
---|
63 | Node2.m_MSA.Clear(); |
---|
64 | } |
---|
65 | uTreeNodeIndex = GuideTree.NextDepthFirstNode(uTreeNodeIndex); |
---|
66 | } |
---|
67 | while (NULL_NEIGHBOR != uTreeNodeIndex); |
---|
68 | ProgressStepsDone(); |
---|
69 | |
---|
70 | unsigned uRootNodeIndex = GuideTree.GetRootNodeIndex(); |
---|
71 | const ProgNode &RootProgNode = ProgNodes[uRootNodeIndex]; |
---|
72 | a.Copy(RootProgNode.m_MSA); |
---|
73 | |
---|
74 | delete[] ProgNodes; |
---|
75 | ProgNodes = 0; |
---|
76 | } |
---|