Example #1
0
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;
}
Example #2
0
int tests_1() {
 const int TSTRL = 128;
 char tdata[2048];
 char tstr[TSTRL];
 int fc = 0;
 bool ok = false;
 djs_tok_t res, r3;
 int aryLen = 0;

 loadFile(tdata,"inputs/example.json");

 djs_tok_t whole = djs_createFrom(tdata);

 fc += eT(ok = djs_findNamed(&whole, "this", &res));
 fc += eT(ok = djs_getStr(&res,tstr,TSTRL));
 fc += eS(tstr,"that");
 fc += eT(ok = djs_findNamed(&whole,"other",&res));
 djs_tok_t res2;
 fc += eT(ok = djs_findNamed(&res,"this",&res2));
 fc += eT(ok = djs_getStr(&res2,tstr,TSTRL));
 fc += eS(tstr,"notthat");
 fc += eT(ok = djs_findNamed(&res,"smelly",&res2));
 bool smelly = false;
 fc += eT(ok = djs_getBool(&res2,&smelly));
 fc += eT(smelly);
 fc += eT(ok = djs_findNamed(&res,"ugly",&res2));
 bool ugly = true;
 fc += eT(ok = djs_getBool(&res2,&ugly));
 fc += eF(ugly);
 fc += eT(ok = djs_findNamed(&whole,"boo",&res));
 fc += eI(aryLen = djs_getLength(&res),6);
 bool intables[] = { true, true, false, true, false, true };
 int  tvals[]    = { 11, 222, -1, 3333, -1, 55 };
 for (int i=0;i<aryLen;i++) {
  djs_tok_t r2;
  fc += eT(ok = djs_findIndex(&res,i,&r2));
  int ival;
  fc += eI(djs_getInt(&r2,&ival),intables[i]);
  if (intables[i]) {
   fc += eI(ival, tvals[i]);
  }
 }

 fc += eT(ok = djs_findNamed(&whole,"poop",&res));
 fc += eT(ok = djs_findIndex(&res,2,&r3));
 fc += eT(ok = djs_getStr(&r3,tstr,TSTRL));
 fc += eS(tstr, 
   "{ \"in\": 2, \"st\": 333333, \"rs\": [ 3,3,3,3,3,3 ] }");

 if (fc) {
  printf("---- FAIL with %d errors ----\n",fc);
 }

 return fc;
};
Example #3
0
int tests_3() {

 const int TSTRL = 128;
 char tdata[2048];
 char tstr[TSTRL];
 int fc = 0;
 bool ok = false;
 djs_tok_t res;

 loadFile(tdata,"inputs/ex2.json");

 djs_tok_t w2 = djs_createFrom(tdata);
 djs_showTok(&w2,TEST_DEBUG);

 const char *digits[] = {
  "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten"
 };
 const int ivals[]   = { 1, 2, 3, 4, 5, 6, 7, 8, 9, -10 };
 const char *svals[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9", "[ 10 ]" };


 fc += eT(djs_valid(&w2));
 for (int i=0;i<10;i++) {
  fc += eT(ok = djs_findNamed(&w2,digits[i],&res));
  fc += eT(ok = djs_getStr(&res,tstr,TSTRL));
  fc += eS(tstr,svals[i]);
  int ival = 42;
  fc += eI(djs_getInt(&res,&ival),(ivals[i] > 0));
  fc += (ivals[i] > 0) ? eI(ivals[i], ival) : 42;
 }
 return fc;
}
Example #4
0
int tests_4() {

 const int TSTRL = 128;
 char tdata[2048];
 char tstr[TSTRL];
 int fc = 0;
 bool ok = false;
 djs_tok_t res;

 loadFile(tdata,"inputs/ex3.json");

 djs_tok_t w2 = djs_createFrom(tdata);
 djs_showTok(&w2,TEST_DEBUG);

 const char *svals[] = {
  "this",
  "is",
  "a",
  "thing",
  "with,commas,n'stuff,",
  "and single quotes '",
  "and escped double quotes -- singly \\\"",
  "and in pairs \\\"ding\\\""
 };

 fc += eT(djs_valid(&w2));
 for (int i=0;i<8;i++) {
  fc += eT(ok = djs_findIndex(&w2,i,&res));
  fc += eT(ok = djs_getStr(&res,tstr,TSTRL));
  fc += eS(tstr,svals[i]);
 }
 return fc;
}
Example #5
0
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;
}
//Shel: Function for scoring a node (recursive)
int ScoreNode(TreeNode* node, int* RNA, nndb_constants* param, int length){
	int result;
	result = 0;
	int *pairedChildren;
	pairedChildren = NULL;
	int numPairedChildren;
	numPairedChildren = 0;
	int i;
	
	for (i = 0 ; i < node->numChildren ; i++){ 
       // find location and number of paired children 
       //and add scores of associated loops
		if ((node->children[i])->isPair) {
			//Manoj: Changed the code to generate warnings in case of pairing in structure which are not valid
			 /*Base lb = (node->children[i])->lowBase.base;
                                char lbChar;
                                if(lb==1)lbChar='A';else if(lb==2)lbChar='C';else if(lb==4)lbChar='G';else if(lb==8)lbChar='U';else lbChar="X";
                                Base hb = (node->children[i])->highBase.base;
                                char hbChar;
                                if(hb==1)hbChar='A';else if(hb==2)hbChar='C';else if(hb==4)hbChar='G';else if(hb==8)hbChar='U';else hbChar="X";
                                printf("CHECKING: bases %d and %d (%c%c) if they can pair!\n",(node->children[i])->lowBase.index, (node->children[i])->highBase.index,lbChar, hbChar);*/
			if(!canPair((node->children[i])->lowBase.base, (node->children[i])->highBase.base)){
				Base lb = (node->children[i])->lowBase.base;
				char lbChar;
				if(lb==1)lbChar='A';else if(lb==2)lbChar='C';else if(lb==4)lbChar='G';else if(lb==8)lbChar='U';else lbChar='X';
	                        Base hb = (node->children[i])->highBase.base;
				char hbChar;
                                if(hb==1)hbChar='A';else if(hb==2)hbChar='C';else if(hb==4)hbChar='G';else if(hb==8)hbChar='U';else hbChar='X';
				printf("WARNING: bases %d and %d (%c%c) can't pair; structure cannot be scored. Exiting.\n",(node->children[i])->lowBase.index, (node->children[i])->highBase.index,lbChar, hbChar);
				exit(-1);
				//continue;
			}
			//printf("Yes they can pair\n");
			result += ScoreNode(node->children[i], RNA, param, length);
			numPairedChildren += 1;
			pairedChildren = realloc(pairedChildren, sizeof(int) * numPairedChildren);
			pairedChildren[numPairedChildren - 1] = i;
		}
	}
	
	if (node->lowBase.index != 0) 
	{
		
		if (numPairedChildren == 0)  // must be a hairpin
		{
			
			 int energy = eH(node->lowBase.index,node->highBase.index, RNA, param);
          result += energy;
			if(printOn2)printf("%d \t %d: Hairpin Loop with energy %.2f\n",  node->lowBase.index, node->highBase.index, (double)energy/100);
		}
		else if (numPairedChildren == 1)  // must be stack, bulge, or internal
		{
			if (node->numChildren == 1)  // must be stack 
			{
          	int energy = eS(node->lowBase.index, node->highBase.index, RNA, param);
	       	result += energy; 
	     		if(printOn2)printf("%d \t %d: Stacked pair with energy %.2f\n",  node->lowBase.index, node->highBase.index, (double)energy/100);
			}
			else 
			{  // must be bulge or internal 
			   
				int energy = eL(node->lowBase.index, node->highBase.index, 
				              node->children[pairedChildren[0]]->lowBase.index,
				              node->children[pairedChildren[0]]->highBase.index,
								  RNA, param);
            result += energy;
				if(printOn2)printf("%d \t %d: Bulge or Inernal Loop with energy %.2f\n",  node->lowBase.index, node->highBase.index, (double)energy/100);
			}
		}
		else  // must be a multi-loop
		{	
			int energy = eM(node, pairedChildren, numPairedChildren, RNA, param);
			result += energy;
			if(printOn2)printf("%d \t %d: Multi-loop with energy %.2f\n",  node->lowBase.index, node->highBase.index, (double)energy/100);
		}
	}
	else { // must be external
      int energy = eE(node, pairedChildren, numPairedChildren, RNA, param, length);
		result += energy; 
		if(printOn2)printf("%d \t %d: External loop with energy %.2f\n",  node->lowBase.index, node->highBase.index, (double)energy/100);
	}

	return result;
}
Example #7
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];
}