用动态规划法求解生物信息学中DNA序列比对的问题 (交叉学科应用实验)

 
   

#include
#include
#include
using namespace std;

stack s;//当前搜索路径的LCS
stack lcs[100];//所有的LCS

int count=0;//记录LCS的数量

bool lcs_have_exist(stack lcs[],int count,stack s)
{//判断当前搜索的LCS是否已存在于 stack_lcs[MAX]
	int i;
	bool exist=false;
	for (i=0;i &s)
{
	while(!s.empty())
	{
		s.pop();
	}
}

void out_stack()//输出栈s内容
{
	stack copy=s;
	cout<0&&j>0)
	{
		if(b[i][j]==3)//沿着对角线向上走
		{
			s.push(X[i]);
			ALL_LCS(X,b,i-1,j-1);
			s.pop();
		}
		else if(b[i][j]==1)//水平向左走
		{
		    ALL_LCS(X,b,i,j-1);
		}
	    else if(b[i][j]==2)//垂直向上走
		{
            ALL_LCS(X,b,i-1,j);
		}
	    else if(b[i][j]==4)//先向左走,再向右
		{
	    	ALL_LCS(X,b,i,j-1);
			ALL_LCS(X,b,i-1,j);
		}
	}
}



void LCS(char dna1[],char dna2[],int m,int n,int b[][100],int tag[][100])
{//生成矩阵tag[m][n],b[m][n]作为逆推的记录
	int i,j,k;
	for(k=0;k<=m;k++)
		 tag[k][0]=0;//初始化矩阵
	 for( k=0;k<=n;k++)
		 tag[0][k]=0;
	for(i=1;i<=m;i++)
		for(j=1;j<=n;j++)
		{
			if(dna1[i]==dna2[j])
			{
				tag[i][j]=tag[i-1][j-1]+1;
				b[i][j]=3;//"↖"
			}
			else if(tag[i][j-1]tag[i-1][j])
			{  
				tag[i][j]=tag[i][j-1];
				b[i][j]=1;//"←"
			}
			else
			{
				tag[i][j]=tag[i][j-1];
				b[i][j]=4;//"←↑"
			}
		}
		for(i=0;i<=m;i++)
		{
	    	cout<>dna1[i];
	 while(dna1[i]!='#')
	 {
		  i++;
	      cin>>dna1[i];
	 }
	 cout<<"DNA2:";
	 cin>>dna2[j];
	  while(dna2[j]!='#')
	 {
		  j++;
	      cin>>dna2[j];
	 }
	 cout<


你可能感兴趣的:(C/C++)