问题重述
组成生命蛋白质的若干种氨基酸可以形成不同的组合。通过质谱实验测定分子量来分析某个生命蛋白质分子的组成时,遇到的首要问题如何将它的分子量X(正整数)分解为n个氨基酸的已知分子量
给定某以蛋白质的分子量X,为正整数 。要求对该实验室拥有或不拥有计算机的情况进行解答.
下面给出的C语言关于这一问题的核心求解:
/*核心搜索函数psfReal*/
void psfReal(int start ,Type sum,Type* arr,int iteratorTimes,FILE* outputFile,char* strInfo,int strPos,Type *chNArr,Type chNTotalNum)
{
int i=0;/*iterator value*/
int nowTimes;/*output value control*/
int r,l;/*str output aid value*/
int flag1=0,flag2=0;/*Constraint flag condition value*/
double bottom=83.35,top=93.33;
assertF(arr!=NULL,"In psfReal,arr is NULL/n");
assertF(chNArr!=NULL,"In psfReal,chNArr is NULL/n");
assertF(outputFile!=NULL,"In psfReal,outputFile is NULL/n");
assertF(strInfo!=NULL,"In psfReal,strInfo is NULL/n");
/*recursive caculating*/
sum+=arr[start];
chNTotalNum+=chNArr[start];
/*Str info adjust*/
if((start+1)>=10)/*only dec*/
{
r=(start+1)%10;
l=(start+1)/10;
strInfo[strPos++]=48+l;
strInfo[strPos++]=48+r;
strInfo[strPos++]=',';
}
else if((start+1)<10)
{
strInfo[strPos++]=48+start+1;
strInfo[strPos++]=',';
}
/*Outof Constraint Condition flag gives*/
/*Constraint1:Ch N's constraint*/
flag2=0;
for(i=1;i<=11;i++)/* 11=Ceil[1000/93.33]*/
{
if((sum>=bottom*i)&&(sum<=top*i))
{
flag2=1;
break;
}
}
if(sum>gNowLimitNum)
{
return;
}
/*In Constraint Condition flag gives*/
/*Constraint1:Ch N's constraint*/
flag1=((chNTotalNum>=sum*0.15/14)&&(chNTotalNum<=sum*0.17/14));
if((sum==gNowLimitNum)&&flag1&&flag2)/*end Condition*/
{
strInfo[strPos]='/0';
gTimes++;
gEachTimes++;
return ;
}
else
{
nowTimes=++iteratorTimes;
for(i=start;i<gLen;i++)
psfReal(i,sum,arr,nowTimes,outputFile,strInfo,strPos,chNArr,chNTotalNum);
}
}
主程序:
#include "SortAlgorithm.h"
#include "PartSum.h"
#include "MyAssert.h"
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
char *inFileName="inputData.txt";
char *outFileName="outputData.txt";
#define DEBUG 1
void main(int argc,char* argv[])
{
FILE *inputFile;/*input file*/
FILE *outputFile;/*output file*/
int *myArr;/*array data,should read the data from the input file*/
int *chNArr;/*chemistry's N's num for each an ji suan*/
int i=0,iterNum=0,j=0;/*iterator value*/
int tmpLen=0;
double startTime,endTime,tweenTime;/*time callopsed info*/
char *myChar;/*show combine group info*/
/*input file open*/
if(argc>1)strcpy(inFileName,argv[1]);
assertF((inputFile=fopen(inFileName,"rb"))!=NULL,"input file error");
printf("input file open success/n");
/*outpout file open*/
if(argc>2)strcpy(outFileName,argv[2]);
assertF((outputFile=fopen(outFileName,"wb"))!=NULL,"output file error");
printf("output file open success/n");
/*Read info data*/
fscanf(inputFile,"%d,%d,",&gLen,&gLimitNum);
printf("input array data len:%d,up data limit:%d;/n",gLen,gLimitNum);
/*array space located*/
myArr=(int*)malloc(sizeof(int)*gLen);
chNArr=(int*)malloc(sizeof(int)*gLen);
myChar=(char*)malloc(sizeof(char)*gLen*3);/*only could tackle with gLen<100*/
/*clean the string*/
tmpLen=sizeof(char)*gLen*3;
for(i=0;i<tmpLen;i++)
{
myChar[i]='/0';
}
/*read data from input file*/
for(i=0;i<gLen;i++)
{
fscanf(inputFile,"%d,",&myArr[i]);
}
for(i=0;i<gLen;i++)
{
fscanf(inputFile,"%d,",&chNArr[i]);
}
/*show out the input data info*/
printf("input data info :/n");
showArr(myArr,gLen);
printf("the N of each an ji suan is:/n");
showArr(chNArr,gLen);
#if DEBUG
printf("/n*******start of test program******/n");
bubbleSort(myArr,gLen);/*sort the list first*/
assertF(sortedAssert(myArr,gLen,UNDESCEND),"test arr is not sorted/n");
printf("input data have been sorted:/n");
showArr(myArr,gLen);/*show details*/
gChNNumLimit=(int)gLimitNum*0.1700/14;
printf("the limit of gChN is:%d/n",gChNNumLimit);
printf("now is runnig,please wait.../n");
startTime=(double)clock()/(double)CLOCKS_PER_SEC;
/******************Core program code*************/
for(iterNum=myArr[0];iterNum<=gLimitNum;iterNum++)
{
gEachTimes=0;
fprintf(outputFile,"*num :%d*/r/n",iterNum);
printf("%d/n",iterNum);
/*Constraint condition adjust*/
gNowLimitNum=iterNum;
for(j=0;j<gLen;j++)
psfReal(j,0,myArr,0,outputFile,myChar,0,chNArr,0);
fprintf(outputFile,"=g num:%d=/r/n/r/n",gEachTimes);
}
/******************End of Core program**********/
endTime=(double)clock()/(double)CLOCKS_PER_SEC;
tweenTime=endTime-startTime;/*Get the time collapsed*/
/*Total combine times output*/
fprintf(outputFile,"the limit of gChN is:%d/r/n",gChNNumLimit);
printf("the total combine group's num is:%d/n",gTimes);
fprintf(outputFile,"the total combine group's num is:%d/r/n",gTimes);
/*Time collapsed output*/
printf("the collapsed time in this algorithm implement is:%f/n",tweenTime);
fprintf(outputFile,"the collapsed time in this algorithm implement is:%f/r/n",tweenTime);
printf("/n*******end of test program******/n");
#endif
free(chNArr);
free(myChar);
free(myArr);
printf("program end successfully,/n you have to preess any key to clean the buffer area to output,otherwise,you wiil not get the total answer./n");
getchar();/*Screen Delay Control*/
return;
}
希望大家给出改进意见.
源码下载:
http://free3.e-168.cn/as2forward/downloads/partSumOk.rar