1 | #include "muscle.h" |
---|
2 | #include "textfile.h" |
---|
3 | #include "msa.h" |
---|
4 | #include "tree.h" |
---|
5 | #include "profile.h" |
---|
6 | #include "objscore.h" |
---|
7 | |
---|
8 | bool TreeNeededForWeighting(SEQWEIGHT s) |
---|
9 | { |
---|
10 | switch (s) |
---|
11 | { |
---|
12 | case SEQWEIGHT_ClustalW: |
---|
13 | case SEQWEIGHT_ThreeWay: |
---|
14 | return true; |
---|
15 | default: |
---|
16 | return false; |
---|
17 | } |
---|
18 | } |
---|
19 | |
---|
20 | static ProfPos *ProfileFromMSALocal(MSA &msa, Tree &tree) |
---|
21 | { |
---|
22 | const unsigned uSeqCount = msa.GetSeqCount(); |
---|
23 | for (unsigned uSeqIndex = 0; uSeqIndex < uSeqCount; ++uSeqIndex) |
---|
24 | msa.SetSeqId(uSeqIndex, uSeqIndex); |
---|
25 | |
---|
26 | if (TreeNeededForWeighting(g_SeqWeight2)) |
---|
27 | { |
---|
28 | TreeFromMSA(msa, tree, g_Cluster2, g_Distance2, g_Root1); |
---|
29 | SetMuscleTree(tree); |
---|
30 | } |
---|
31 | return ProfileFromMSA(msa); |
---|
32 | } |
---|
33 | |
---|
34 | void ProfileProfile(MSA &msa1, MSA &msa2, MSA &msaOut) |
---|
35 | { |
---|
36 | //ALPHA Alpha = ALPHA_Undefined; |
---|
37 | //switch (g_SeqType) |
---|
38 | // { |
---|
39 | //case SEQTYPE_Auto: |
---|
40 | // Alpha = msa1.GuessAlpha(); |
---|
41 | // break; |
---|
42 | |
---|
43 | //case SEQTYPE_Protein: |
---|
44 | // Alpha = ALPHA_Amino; |
---|
45 | // break; |
---|
46 | |
---|
47 | //case SEQTYPE_DNA: |
---|
48 | // Alpha = ALPHA_DNA; |
---|
49 | // break; |
---|
50 | |
---|
51 | //case SEQTYPE_RNA: |
---|
52 | // Alpha = ALPHA_RNA; |
---|
53 | // break; |
---|
54 | |
---|
55 | //default: |
---|
56 | // Quit("Invalid SeqType"); |
---|
57 | // } |
---|
58 | //SetAlpha(Alpha); |
---|
59 | |
---|
60 | //msa1.FixAlpha(); |
---|
61 | //msa2.FixAlpha(); |
---|
62 | |
---|
63 | unsigned uLength1; |
---|
64 | unsigned uLength2; |
---|
65 | |
---|
66 | uLength1 = msa1.GetColCount(); |
---|
67 | uLength2 = msa2.GetColCount(); |
---|
68 | |
---|
69 | Tree tree1; |
---|
70 | Tree tree2; |
---|
71 | ProfPos *Prof1 = ProfileFromMSALocal(msa1, tree1); |
---|
72 | ProfPos *Prof2 = ProfileFromMSALocal(msa2, tree2); |
---|
73 | |
---|
74 | PWPath Path; |
---|
75 | ProfPos *ProfOut; |
---|
76 | unsigned uLengthOut; |
---|
77 | Progress("Aligning profiles"); |
---|
78 | AlignTwoProfs(Prof1, uLength1, 1.0, Prof2, uLength2, 1.0, Path, &ProfOut, &uLengthOut); |
---|
79 | |
---|
80 | Progress("Building output"); |
---|
81 | AlignTwoMSAsGivenPath(Path, msa1, msa2, msaOut); |
---|
82 | } |
---|
83 | |
---|
84 | // Do profile-profile alignment |
---|
85 | void Profile() |
---|
86 | { |
---|
87 | if (0 == g_pstrFileName1 || 0 == g_pstrFileName2) |
---|
88 | Quit("-profile needs -in1 and -in2"); |
---|
89 | |
---|
90 | SetSeqWeightMethod(g_SeqWeight1); |
---|
91 | |
---|
92 | TextFile file1(g_pstrFileName1); |
---|
93 | TextFile file2(g_pstrFileName2); |
---|
94 | |
---|
95 | MSA msa1; |
---|
96 | MSA msa2; |
---|
97 | MSA msaOut; |
---|
98 | |
---|
99 | Progress("Reading %s", g_pstrFileName1); |
---|
100 | msa1.FromFile(file1); |
---|
101 | Progress("%u seqs %u cols", msa1.GetSeqCount(), msa1.GetColCount()); |
---|
102 | |
---|
103 | Progress("Reading %s", g_pstrFileName2); |
---|
104 | msa2.FromFile(file2); |
---|
105 | Progress("%u seqs %u cols", msa2.GetSeqCount(), msa2.GetColCount()); |
---|
106 | |
---|
107 | ALPHA Alpha = ALPHA_Undefined; |
---|
108 | switch (g_SeqType) |
---|
109 | { |
---|
110 | case SEQTYPE_Auto: |
---|
111 | Alpha = msa1.GuessAlpha(); |
---|
112 | break; |
---|
113 | |
---|
114 | case SEQTYPE_Protein: |
---|
115 | Alpha = ALPHA_Amino; |
---|
116 | break; |
---|
117 | |
---|
118 | case SEQTYPE_DNA: |
---|
119 | Alpha = ALPHA_DNA; |
---|
120 | break; |
---|
121 | |
---|
122 | case SEQTYPE_RNA: |
---|
123 | Alpha = ALPHA_RNA; |
---|
124 | break; |
---|
125 | |
---|
126 | default: |
---|
127 | Quit("Invalid seq type"); |
---|
128 | } |
---|
129 | SetAlpha(Alpha); |
---|
130 | |
---|
131 | msa1.FixAlpha(); |
---|
132 | msa2.FixAlpha(); |
---|
133 | |
---|
134 | SetPPScore(); |
---|
135 | if (ALPHA_DNA == Alpha || ALPHA_RNA == Alpha) |
---|
136 | SetPPScore(PPSCORE_SPN); |
---|
137 | |
---|
138 | const unsigned uSeqCount1 = msa1.GetSeqCount(); |
---|
139 | const unsigned uSeqCount2 = msa2.GetSeqCount(); |
---|
140 | const unsigned uSumSeqCount = uSeqCount1 + uSeqCount2; |
---|
141 | MSA::SetIdCount(uSumSeqCount); |
---|
142 | |
---|
143 | ProfileProfile(msa1, msa2, msaOut); |
---|
144 | |
---|
145 | Progress("Writing output"); |
---|
146 | MuscleOutput(msaOut); |
---|
147 | } |
---|