int traceVBI(int i, int j) { int VBIij; int ip, jp; int ifinal, jfinal; ifinal = 0; jfinal = 0; for (ip = i + 1; ip < j - 1; ip++) { for (jp = ip + 1; jp < j; jp++) { VBIij = eL(i, j, ip, jp)+ V(ip,jp); if (VBIij == VBI(i,j) || forcePair(ip,jp)){ ifinal = ip; jfinal = jp; break; } } if (jp != j) break; } if (print_energy_decompose==1) fprintf(energy_decompose_outfile, " %12.2f\n", eL(i, j, ifinal, jfinal)/100.00); total_en += eL(i, j, ifinal, jfinal); return traceV(ifinal, jfinal); }
int traceV(int i, int j) { int a, b, c, d, Vij; if (j-i < TURN) return INFINITY_; a = canHairpin(i,j)?eH(i, j):INFINITY_; b = canStack(i,j)?eS(i, j) + V(i + 1, j - 1):INFINITY_; c = canStack(i,j)?VBI(i,j):INFINITY_; d = canStack(i,j)?VM(i,j):INFINITY_; Vij = V(i,j); structure[i] = j; structure[j] = i; if (Vij == a ) { if (print_energy_decompose == 1) fprintf(energy_decompose_outfile, "i %5d j %5d Hairpin %12.2f\n", i, j, eH(i, j)/100.00); total_en += eH(i,j); return Vij; } else if (Vij == b) { if (print_energy_decompose == 1) fprintf(energy_decompose_outfile, "i %5d j %5d Stack %12.2f\n", i, j, eS(i, j)/100.00); total_en += eS(i,j); traceV(i + 1, j - 1); return Vij; } else if (Vij == c) { if (print_energy_decompose == 1) fprintf(energy_decompose_outfile, "i %5d j %5d IntLoop ", i, j); traceVBI(i, j); return Vij; } else if (Vij == d) { int eVM = traceVM(i, j); if (print_energy_decompose ==1) fprintf(energy_decompose_outfile, "i %5d j %5d MultiLoop %12.2f\n", i, j, (Vij-eVM)/100.0); total_en += (Vij-eVM); return Vij; } return 0; }
int traceVBI(int i, int j) { int VBIij_temp; int ip, jp, el, v; int ifinal, jfinal; ifinal = 0; jfinal = 0; for (ip = i + 1; ip < j - 1; ip++) { for (jp = ip + 1; jp < j; jp++) { if (check_iloop(i,j,ip,jp)) continue; el = eL(i, j, ip, jp); v = V(ip, jp); VBIij_temp = el + v; if (VBIij_temp == VBI(i,j)) { ifinal = ip; jfinal = jp; break; } } if (jp != j) break; } structure[ifinal] = jfinal; structure[jfinal] = ifinal; if (verbose==1) printf(" %12.2f\n", eL(i, j, ifinal, jfinal)/100.00); total_en += eL(i, j, ifinal, jfinal); int eVI = traceV(ifinal, jfinal); return eVI ; }
int traceV(int i, int j) { int a, b, c, d, Vij; if (j-i < TURN) return INFINITY_; a = eH(i, j); b = eS(i, j) + V(i + 1, j - 1); if (eS(i, j) == 0) b = INFINITY_; c = VBI(i,j); d = VM(i,j); Vij = MIN(MIN(a, b), MIN(c, d)); if (Vij == a && Vij != b && Vij != c && Vij != d) { if (verbose == 1) printf("i %5d j %5d Hairpin %12.2f\n", i, j, eH(i, j)/100.00); total_en += eH(i,j); return Vij; } else if (Vij == b) { if (verbose == 1) printf("i %5d j %5d Stack %12.2f\n", i, j, eS(i, j)/100.00); total_en += eS(i,j); structure[i + 1] = j - 1; structure[j - 1] = i + 1; traceV(i + 1, j - 1); return Vij; } else if (Vij == c) { if (verbose == 1) printf("i %5d j %5d IntLoop ", i, j); traceVBI(i, j); return Vij; } else if (Vij == d && Vij != a && Vij != b && Vij != c) { int eVM = traceVM(i, j); if (verbose ==1) printf("i %5d j %5d MultiLoop %12.2f\n", i, j, (Vij-eVM)/100.0); total_en += (Vij-eVM); return Vij; } return 0; }
int calculate(int len, int nThreads) { int b, i, j; #ifdef _OPENMP if (nThreads>0) omp_set_num_threads(nThreads); #endif #ifdef _OPENMP #pragma omp parallel #pragma omp master fprintf(stdout,"Thread count: %3d \n",omp_get_num_threads()); #endif for (b = TURN+1; b <= len-1; b++) { #ifdef _OPENMP #pragma omp parallel for private (i,j) schedule(guided) #endif for (i = 1; i <= len - b; i++) { j = i + b; int flag = 0, newWM = INFINITY_; if (canPair(RNA[i], RNA[j])) { flag = 1; int eh = canHairpin(i,j)?eH(i,j):INFINITY_; //hair pin int es = canStack(i,j)?eS(i,j)+getShapeEnergy(i)+getShapeEnergy(j)+V(i+1,j-1):INFINITY_; // stack if (j-i > 6) { // Internal Loop BEGIN int p=0, q=0; int VBIij = INFINITY_; for (p = i+1; p <= MIN(j-2-TURN,i+MAXLOOP+1) ; p++) { int minq = j-i+p-MAXLOOP-2; if (minq < p+1+TURN) minq = p+1+TURN; int maxq = (p==i+1)?(j-2):(j-1); for (q = minq; q <= maxq; q++) { if (!canPair(RNA[p], RNA[q])) continue; if (!canILoop(i,j,p,q)) continue; VBIij = MIN(eL(i, j, p, q) + V(p,q), VBIij); } } VBI(i,j) = VBIij; V(i,j) = V(i,j) + getShapeEnergy(i) + getShapeEnergy(j); } // Internal Loop END if (j-i > 10) { // Multi Loop BEGIN int h; int VMij, VMijd, VMidj, VMidjd; VMij = VMijd = VMidj = VMidjd = INFINITY_; for (h = i+TURN+1; h <= j-1-TURN; h++) { VMij = MIN(VMij, WMU(i+1,h-1) + WML(h,j-1)); VMidj = MIN(VMidj, WMU(i+2,h-1) + WML(h,j-1)); VMijd = MIN(VMijd, WMU(i+1,h-1) + WML(h,j-2)); VMidjd = MIN(VMidjd, WMU(i+2,h-1) + WML(h,j-2)); } int d3 = canSS(j-1)?Ed3(i,j,j-1):INFINITY_; int d5 = canSS(i+1)?Ed5(i,j,i+1):INFINITY_; VMij = MIN(VMij, (VMidj + d5 +Ec)) ; VMij = MIN(VMij, (VMijd + d3 +Ec)); VMij = MIN(VMij, (VMidjd + d5 + d3+ 2*Ec)); VMij = VMij + Ea + Eb + auPenalty(i,j); VM(i,j) = canStack(i,j)?VMij:INFINITY_; } // Multi Loop END V(i,j) = MIN4(eh,es,VBI(i,j),VM(i,j)); } else V(i,j) = INFINITY_; if (j-i > 4) { // WM BEGIN int h; for (h = i+TURN+1 ; h <= j-TURN-1; h++) { //ZS: This sum corresponds to when i,j are NOT paired with each other. //So we need to make sure only terms where i,j aren't pairing are considered. newWM = (!forcePair(i,j))?MIN(newWM, WMU(i,h-1) + WML(h,j)):newWM; } newWM = MIN(V(i,j) + auPenalty(i,j) + Eb, newWM); newWM = canSS(i)?MIN(V(i+1,j) + Ed3(j,i+1,i) + auPenalty(i+1,j) + Eb + Ec, newWM):newWM; //i dangle newWM = canSS(j)?MIN(V(i,j-1) + Ed5(j-1,i,j) + auPenalty(i,j-1) + Eb + Ec, newWM):newWM; //j dangle newWM = (canSS(i)&&canSS(j))?MIN(V(i+1,j-1) + Ed3(j-1,i+1,i) + Ed5(j-1,i+1,j) + auPenalty(i+1,j-1) + Eb + 2*Ec, newWM):newWM; //i,j dangle newWM = canSS(i)?MIN(WMU(i+1,j) + Ec, newWM):newWM; //i dangle newWM = canSS(j)?MIN(WML(i,j-1) + Ec, newWM):newWM; //j dangle WMU(i,j) = WML(i,j) = newWM; } // WM END } } for (j = TURN+2; j <= len; j++) { int i, Wj, Widjd, Wijd, Widj, Wij, Wim1; Wj = INFINITY_; for (i = 1; i < j-TURN; i++) { Wij = Widjd = Wijd = Widj = INFINITY_; Wim1 = MIN(0, W[i-1]); Wij = V(i, j) + auPenalty(i, j) + Wim1; Widjd = (canSS(i)&&canSS(j))?V(i+1,j-1) + auPenalty(i+1,j-1) + Ed3(j-1,i + 1,i) + Ed5(j-1,i+1,j) + Wim1:Widjd; Wijd = canSS(j)?V(i,j-1) + auPenalty(i,j-1) + Ed5(j-1,i,j) + Wim1:Wijd; Widj = canSS(i)?V(i+1, j) + auPenalty(i+1,j) + Ed3(j,i + 1,i) + Wim1:Widj; Wj = MIN(MIN4(Wij, Widjd, Wijd, Widj), Wj); } W[j] = canSS(j)?MIN(Wj, W[j-1]):Wj; } return W[len]; }