Code:
loop: while(!feof(rf))
{
fgets(line,380,rf);
// Reading a line from pdb list file printf(line);
strncpy(filename,line,4);
filename[4] ='\0';
strncpy(profile,line,5);
profile[5] = '\0';
strcpy(pdbName,profile);
strcat(profile,".profile");
strncpy(chain,line+4,1);
strcat(filename,".pdb");
char st[100] = cullpdb;
strcat(st,filename); // Getting the file name of the pdb entry
char st4[100] = psiblast;
strcat(st4,profile );
st4[strlen(psiblast)+1+13]='\0';
st[strlen(cullpdb)+1+8]='\0';
//printf("Profile File Name = %s", st4);
// These are two files I open in every iteration
if((fpro = fopen(st4,"r"))==0)
{
printf("Profile File Not found %s", st4);
goto loop;
}
if((f = fopen(st,"r")) == 0)
{ printf(" File %s is not in Directory", &st);
goto loop;
}
else
{
strcpy(pdb_list[pdbn],pdbName);
pdbn++;
}
fprintf(fp,"1 ");
featureNum = 1;
//Profile data converted into features for SVM
while(!feof(fpro))
{
fgets(proLine,380,fpro);
int k=0;
char str3[100];
for(i=0; i < strlen(proLine); i++)
{
if(proLine[i] != ' ')
{
str3[k] = proLine[i];
k++;
}
else
{
str3[k]='\0';
j = atoi(str3);
if(j!=0)
{
fprintf(fp,"%d:%d ", featureNum,j);
}
featureNum++;
k=0 ;
}
}
}
n=0;
modelFlag = 0;
while(!feof(f))
{
fgets(pline,380,f);
strncpy(st2,pline,5);
st2[5] = '\0';
if(strcmp(st2,"MODEL") ==0)
{
if(modelFlag ==0)
modelFlag = 1;
else
goto Dist;
}
strncpy(st2,pline,4);
st2[4] = '\0';
if(strcmp(st2, "ATOM") == 0)
{
strncpy(st3,pline+13,2);
st3[2] ='\0';
strncpy(seq_chain,pline+21 ,1);
seq_chain[1]='\0';
if((strcmp(st3,"CA") ==0) && (strcmp(seq_chain,chain) ==0))
{
strncpy(xc,pline+26,12);
strncpy(yc,pline+38,8);
strncpy(zc,pline+46,8);
xc[12] ='\0'; yc[8]= '\0'; zc[8] = '\0';
ca[n].x = atof(xc); ca[n].y = atof(yc); ca[n].z =atof(zc);
n++;
}
}
}
Dist:
for(i=0;i<n;i++)
// Make number 4 to n for N*N distance matrix or it will be N*4 matrix
{
for(j=i+1;j<n;j++)
{
dist = sqrt((ca[i].x -ca[j].x)*(ca[i].x-ca[j].x) + (ca[i].y -ca[j].y)*(ca[i].y-ca[j].y) + (ca[i].z -ca[j].z)*(ca[i].z-ca[j].z));
fprintf(fp,"%d:%.3lf ", featureNum,dist);
featureNum++;
}
}
fprintf(fp,"# %s %s", pdbName,seqn);
printf(".");
printf("\nDone with one vector %d pdb ID is %s Feature Number is %d",posn,pdbName,featureNum);
if(maxF<featureNum)
maxF = featureNum;
avgF = avgF+ featureNum;
posn++;
if(posn>C1000*1000)
{
sleep(200);
C1000++;
}
//scanf("%c",st2);
fclose(f); // I am closing BOth files here
fclose(fpro);
fprintf(fp,"\n");
}