1 #include "AlifoldMEA.h"
5 const int AlifoldMEA::TURN = 3;
11 makeProfileBPPMatrix(alignment);
19 makeProfileBPPMatrix(const MultiSequence *Sequences)
21 int length = Sequences->GetSequence(0)->GetLength();
23 Trimat<float> *consBppMat = new Trimat<float>(length + 1);
24 fill(consBppMat->begin(), consBppMat->end(), 0);
26 for(int i = 1; i <= length; i++)
27 for (int j = i; j <= length; j++)
31 int number = Sequences->GetNumSequences();
32 for(int seqNum = 0; seqNum < number; seqNum++) {
33 SafeVector<int> *tmpMap = Sequences->GetSequence(seqNum)->GetMappingNumber();
34 int label = Sequences->GetSequence(seqNum)->GetLabel();
35 BPPMatrix *tmpBppMatrix = BPPMatrices[label];
37 for(int i = 1; i <= length ; i++) {
38 int originI = tmpMap->at(i);
39 for(int j = i; j <= length; j++) {
40 int originJ = tmpMap->at(j);
41 if(originI != 0 && originJ != 0) {
42 float tmpProb = tmpBppMatrix->GetProb(originI, originJ);
43 bppMat.ref(i, j) += tmpProb;
49 /* compute the mean of base pairing probability */
50 for(int i = 1; i <= length; i++) {
51 for(int j = i; j <= length; j++) {
52 bppMat.ref(i,j) = bppMat.ref(i,j)/(float)number;
56 for (int i = 1; i <= length; i++) {
58 for (int j = i; j <= length; j++) {
59 sum += bppMat.ref(i,j);
64 for (int i = 1; i <= length; i++) {
66 for (int j = i; j >= 1; j--) {
67 sum += bppMat.ref(j, i);
77 int length = alignment->GetSequence(0)->GetLength();
79 for (int i = 1; i <= length; i++) {
80 for (int j = i; j <= length; j++) {
87 for (int i = 1; i <= length; i++) {
93 for (int i = 1; i <= length - 1; i++) {
94 M.ref(i, i+1) = Qi[i+1];
95 traceI.ref(i,i + 1) = 0;
96 traceJ.ref(i,i + 1) = 0;
99 for (int i = 0; i <= length; i++) {
108 float g = BasePairConst; // see scarna.hpp
109 int length = alignment->GetSequence(0)->GetLength();
111 for (int i = length - 1; i >= 1; i--) {
112 for (int j = i + TURN + 1; j <= length; j++) {
115 float p = bppMat.ref(i,j);
118 float maxScore = qi + M.ref(i+1, j);
122 float tmpScore = qj + M.ref(i, j-1);
123 if (tmpScore > maxScore) {
129 tmpScore = g*2*p + M.ref(i+1, j-1);
130 if (tmpScore > maxScore) {
136 for (int k = i + 1; k < j - 1; k++) {
137 tmpScore = M.ref(i,k) + M.ref(k+1,j);
138 if (tmpScore > maxScore) {
144 M.ref(i,j) = maxScore;
145 traceI.ref(i, j) = tmpI;
146 traceJ.ref(i, j) = tmpJ;
156 int length = alignment->GetSequence(0)->GetLength();
157 SafeVector<int> stackI((length + 1)*(length+1));
158 SafeVector<int> stackJ((length + 1)*(length+1));
161 stackI[pt] = traceI.ref(1, length);
162 stackJ[pt] = traceJ.ref(1, length);
167 int tmpI = stackI[pt];
168 int tmpJ = stackJ[pt];
169 int nextI = traceI.ref(tmpI, tmpJ);
170 int nextJ = traceJ.ref(tmpI, tmpJ);
173 if (tmpI + 1 == nextI && tmpJ == nextJ) {
178 else if (tmpI == nextI && tmpJ - 1 == nextJ) {
183 else if (tmpI + 1 == nextI && tmpJ - 1== nextJ) {
190 else if (tmpI == nextI && tmpJ == nextJ) {
191 float maxScore = IMPOSSIBLE;
194 for (int k = tmpI + 1; k < tmpJ - 1; k++) {
195 float tmpScore = M.ref(tmpI,k) + M.ref(k+1,tmpJ);
196 if (tmpScore > maxScore) {
201 stackI[pt] = traceI.ref(tmpI, maxK);
202 stackJ[pt] = traceJ.ref(tmpI, maxK);
204 stackI[pt] = traceI.ref(maxK+1, tmpJ);
205 stackJ[pt] = traceJ.ref(maxK+1, tmpJ);