Пример #1
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;
}
Пример #2
0
cv::Mat permute_e(int nc, int M)
{
	cv::Mat eM, eM1, eM2, eM3;

	// Permutation of 1 bit error
	eM1 = cv::Mat::eye(nc, nc, CV_32FC1);

	eM2 = cv::Mat::zeros(1, 1, CV_32FC1);
	eM3 = cv::Mat::zeros(1, 1, CV_32FC1);
	// Permutation of 2 bit error
	if (M > 1)
	{
		int MeM2 = (nc*(nc - 1)) / 2;
		eM2 = cv::Mat::zeros(MeM2, nc, CV_32FC1);
		eM2.at<float>(0, 0) = 1;
		eM2.at<float>(0, 1) = 1;

		int z = 0;
		
		for (int ko = 0; ko <= nc - 3;ko++)
		{
			for (int ki = 2; ki <= nc - 1 - ko; ki++)
			{
				z = z + 1;
				eM2.at<float>(z, ko + 0) = 1;
				eM2.at<float>(z, ki + ko - 1) = 0;
				eM2.at<float>(z, ki + ko) = 1;
			}
			z = z + 1;
			eM2.at<float>(z, ko + 1) = 1;
			eM2.at<float>(z, ko + 2) = 1;
		}
	}
	
	if (M>2)
	{
		int MeM3 = (nc*(nc - 1)*(nc - 2)) / 6;
		eM3 = cv::Mat::zeros(MeM3, nc, CV_32FC1);
		int arg = 0;
		for (int ko = 0; ko <= nc - 3; ko++)
		{
			for (int km = 0; km <= nc - 3; km++)
			{
				int idx = nc - 2 - km - ko;
				if (idx < 1){break;}

				cv::Mat eSub = cv::Mat::zeros(idx, nc, CV_32FC1);
				//cv::Mat m1 = cv::Mat::zeros(idx, ko, CV_32FC1);
				cv::Mat m2 = cv::Mat::ones(idx, 1, CV_32FC1);
				//cv::Mat m3 = cv::Mat::zeros(idx, km, CV_32FC1);
				cv::Mat m4 = cv::Mat::ones(idx, 1, CV_32FC1);
				cv::Mat m5 = cv::Mat::eye(idx, idx, CV_32FC1);

				//m1.copyTo(eSub(cv::Rect(0, 0, m1.cols, m1.rows)));
				m2.copyTo(eSub(cv::Rect(ko, 0, m2.cols, m2.rows)));
				//m3.copyTo(eSub(cv::Rect(m1.cols + m2.cols, 0, m3.cols, m3.rows)));
				m4.copyTo(eSub(cv::Rect(ko + 1 + km, 0, m4.cols, m4.rows)));
				m5.copyTo(eSub(cv::Rect(ko + 1 + km + 1, 0, m5.cols, m5.rows)));

				eSub.copyTo(eM3(cv::Rect(0, arg, eSub.cols, eSub.rows)));
				arg += eSub.rows;
			}
		}
	}

	eM = cv::Mat::zeros(eM1.rows + eM2.rows + eM3.rows, nc, CV_32FC1);
	eM1.copyTo(eM(cv::Rect(0, 0,					eM1.cols, eM1.rows)));
	eM2.copyTo(eM(cv::Rect(0, eM1.rows,				eM2.cols, eM2.rows)));
	eM3.copyTo(eM(cv::Rect(0, eM1.rows + eM2.rows,	eM3.cols, eM3.rows)));
	return eM;
}