Commit 0ef04306 by Chloe Dequeker

Merge branch 'testing' of github.com:Nelyah/INTBuilder into testing

updating testing branch
parents 471cdc93 a6994610
#include <string.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>
#include <math.h> #include <math.h>
#include "struct.h" #include "struct.h"
#include "fileIO.h"
#include "allocate.h" #include "allocate.h"
#include "rotation.h" #include "rotation.h"
#include "param.h" #include "param.h"
...@@ -212,288 +212,14 @@ void getInterface(struct pdb_values* pdbR, struct pdb_values* pdbL){ ...@@ -212,288 +212,14 @@ void getInterface(struct pdb_values* pdbR, struct pdb_values* pdbL){
} }
/* Output the ligand's interface */ /* Output the ligand's interface */
for(i=0;i<nbCandL;i++){ write_candidate(t_candidateL,nbCandL,outputFile_lig);
if(t_candidateL[i]->isCandidate){
fprintf(outputFile_lig,"'%s' '%c' ",strtok(t_candidateL[i]->idRes," "),t_candidateL[i]->chain);
fflush(outputFile_lig);
}
}
/* Output the receptor's interface */ /* Output the receptor's interface */
for(i=0;i<nbCandR;i++){ write_candidate(t_candidateR,nbCandR,outputFile_rec);
if(t_candidateR[i]->isCandidate){
fprintf(outputFile_rec,"'%s' '%c' ",strtok(t_candidateR[i]->idRes," "),t_candidateR[i]->chain);
fflush(outputFile_lig);
}
}
free(t_candidateL); free(t_candidateL);
free(t_candidateR); free(t_candidateR);
} }
struct docking_results* getDataForComplex(){
char* buf = NULL;
FILE* condFile_stream = NULL;
int numberOfConf = 0, rc;
int idConf = 0, buf4, prevID = -1;
float buf3 = 0;
size_t len = 2000;
struct docking_results* dock_res = NULL;
condFile_stream = fopen(dockingFile,"r");
/* Get the number of conformations */
rc = fscanf(condFile_stream,"%f",&buf3);
rc = getline(&buf,&len,condFile_stream); /* Get rid of the rest of the line */
if(buf3 > numberOfConf)
numberOfConf = (int) buf3;
while(!feof(condFile_stream)){
rc = fscanf(condFile_stream,"%f",&buf3);
rc = getline(&buf,&len,condFile_stream); /* Get rid of the rest of the line */
if(buf3 > numberOfConf)
numberOfConf = (int) buf3;
}
numberOfConf++;
rewind(condFile_stream);
/* This is with the first MAXDo format */
if(!HCMD2){
rc = getline(&buf,&len,condFile_stream); /* Get rid of the first line */
}
/* Now that we know how many conformations we are dealing with
* allocate a structure large enough
*/
dock_res = allocate_dockingResults(numberOfConf);
while(!feof(condFile_stream)){
/* HCMD2 format */
if(HCMD2){
/* We take the first value as it is the ID of the conformation
* The rest of the line doesn't interests us here
*/
rc = fscanf(condFile_stream,"%d %d %d %d",&idConf,&buf4, &buf4, &buf4);
}else{ /* First MAXDo format */
rc = fscanf(condFile_stream,"%d %d",&idConf,&buf4);
}
/* This happens when we arrive on the last line */
if(prevID == idConf){
break;
}else{
prevID = idConf;
}
rc = fscanf(condFile_stream,"%f %f %f %f %f %f",&dock_res->distCenters[idConf],&dock_res->theta[idConf],&dock_res->phi[idConf],&dock_res->alpha[idConf],&dock_res->beta[idConf],&dock_res->gamma[idConf]);
rc = getline(&buf,&len,condFile_stream); /* Get rid of the rest of the line */
/* theta and phi angles are written in Radian already
* However that is not the case for alpha, beta and gamma angles
*/
//dock_res->theta[idConf] = dock_res->theta[idConf]*COEF_DEGREE_TO_RADIAN;
//dock_res->phi[idConf] = dock_res->phi[idConf]*COEF_DEGREE_TO_RADIAN;
dock_res->alpha[idConf] = dock_res->alpha[idConf] * COEF_DEGREE_TO_RADIAN;
dock_res->beta[idConf] = dock_res->beta[idConf] * COEF_DEGREE_TO_RADIAN;
dock_res->gamma[idConf] = dock_res->gamma[idConf] * COEF_DEGREE_TO_RADIAN;
}
dock_res->nbConf = numberOfConf;
fclose(condFile_stream);
free(buf);
return dock_res;
}
struct pdb_values* readPDB(char* protein) {
/* This function reads a PDB file and fills a structure
* containing all the necessary information.
* The structure filled is of type struct pdb_values. It is
* allocated and a pointer to this structure is returned at the end
*/
int i = 0, j = 0;
int rc = 0, nbRes = 0, numCA = 0;
int curRes = 0, curAtom = 0, firstLine = 1;
size_t len = 2000;
char totalFilePath[200];
char buf2[15];
char buf3[50];
char bufID[10] = "\0";
char* buf = NULL;
FILE* pdbFile_stream = NULL;
struct pdb_values* pdb_prot = NULL;
sprintf(totalFilePath,"%s/%s.pdb",pdbDir,protein);
if(access(totalFilePath,F_OK) == -1){
/* File does not exists, 4 file in this case
* Return NULL, which should be treated accordingly
*/
fprintf(stderr,"No such file : %s\n",totalFilePath);
exit(EXIT_FAILURE);
}
pdbFile_stream = fopen(totalFilePath,"r");
if(pdbFile_stream == NULL){
perror("fopen");
exit(EXIT_FAILURE);
}
/* Get the number of residue for this protein */
strcpy(buf3,"\0");
while(!feof(pdbFile_stream)){
rc = getline(&buf,&len,pdbFile_stream);
strncpy(buf2,buf,4);
buf2[4] = '\0';
if(strcmp("ATOM",buf2) == 0){
/* get the residue ID */
strncpy(buf2,buf+22,5);
buf2[5] = '\0';
/* We make sure that we don't count twice the
* same residue
*/
if(strcmp(buf2,buf3) != 0){
nbRes++;
strcpy(buf3,buf2);
}
}
}
/* Come back at the start of the file */
rewind(pdbFile_stream);
pdb_prot = allocate_pdb(nbRes);
while(!feof(pdbFile_stream)){
rc = getline(&buf,&len,pdbFile_stream);
if(feof(pdbFile_stream)) break; /* else the last line is read twice */
strncpy(buf2,buf,4);
buf2[4] = '\0';
if(strcmp("ATOM",buf2) != 0){
continue;
}
strncpy(bufID,buf+22,5);
bufID[5] = '\0';
/* if this is not the same residue as previously */
if(firstLine || strcmp(bufID,pdb_prot->residues[curRes].idRes) != 0){
if(firstLine){
firstLine = 0;
}else{
curRes++;
}
curAtom = 0;
/* res name */
strncpy(pdb_prot->residues[curRes].resName,buf+17,3);
pdb_prot->residues[curRes].resName[3] = '\0';
/* res ID */
strncpy(pdb_prot->residues[curRes].idRes,buf+22,5);
pdb_prot->residues[curRes].idRes[5] = '\0';
/* atom chain */
pdb_prot->residues[curRes].chain = buf[21];
}
/* atom type */
strncpy(pdb_prot->residues[curRes].atomType[curAtom],buf+13,3);
pdb_prot->residues[curRes].atomType[curAtom][3] = '\0';
/* atom ID */
strncpy(buf2,buf+6,5);
buf2[5] = '\0';
pdb_prot->residues[curRes].idAtom[curAtom] = atoi(buf2);
/* atom X */
strncpy(buf2,buf+30,8);
buf2[8] = '\0';
pdb_prot->residues[curRes].x[curAtom] = atof(buf2);
/* atom Y */
strncpy(buf2,buf+38,8);
buf2[8] = '\0';
pdb_prot->residues[curRes].y[curAtom] = atof(buf2);
/* atom Z */
strncpy(buf2,buf+46,8);
buf2[8] = '\0';
pdb_prot->residues[curRes].z[curAtom] = atof(buf2);
/* If we encounter the first or fifth CA, we note their coordinates
* specifically. We need them for the rotation
*/
if(strcmp("CA ",pdb_prot->residues[curRes].atomType[curAtom]) == 0){
numCA++;
if(numCA == 1){
pdb_prot->xCA1 = pdb_prot->residues[curRes].x[curAtom];
pdb_prot->yCA1 = pdb_prot->residues[curRes].y[curAtom];
pdb_prot->zCA1 = pdb_prot->residues[curRes].z[curAtom];
}else if(numCA == 5){
pdb_prot->xCA5 = pdb_prot->residues[curRes].x[curAtom];
pdb_prot->yCA5 = pdb_prot->residues[curRes].y[curAtom];
pdb_prot->zCA5 = pdb_prot->residues[curRes].z[curAtom];
}
}
curAtom++;
pdb_prot->residues[curRes].nbAtom++;
pdb_prot->nbAtom++;
}
/* Compute the geometric center of the protein */
for(i=0;i<pdb_prot->nbRes;i++){
for(j=0;j<pdb_prot->residues[i].nbAtom;j++){
pdb_prot->centerX = pdb_prot->centerX + pdb_prot->residues[i].x[j];
pdb_prot->centerY = pdb_prot->centerY + pdb_prot->residues[i].y[j];
pdb_prot->centerZ = pdb_prot->centerZ + pdb_prot->residues[i].z[j];
}
}
pdb_prot->centerX /= pdb_prot->nbAtom;
pdb_prot->centerY /= pdb_prot->nbAtom;
pdb_prot->centerZ /= pdb_prot->nbAtom;
free(buf);
fclose(pdbFile_stream);
return pdb_prot;
}
void writePDB(struct pdb_values* pdb, char* protName, int nConf){
/* Output the PDB corresponding to the conformation nConf */
int i = 0, j = 0;
char buf[500];
FILE* fw = NULL;
sprintf(buf,"%s/%s_%d.pdb",outputPDB,protName,nConf);
fw = fopen(buf,"w");
if(fw == NULL){
perror("fopen");
exit(EXIT_FAILURE);
}
for(i=0;i<pdb->nbRes;i++){
for(j=0;j<pdb->residues[i].nbAtom;j++){
fprintf(fw,FORMAT_LINE_PDB,pdb->residues[i].idAtom[j],
pdb->residues[i].atomType[j],pdb->residues[i].resName,pdb->residues[i].chain,
pdb->residues[i].idRes,pdb->residues[i].x[j],pdb->residues[i].y[j],pdb->residues[i].z[j]);
}
}
fclose(fw);
}
int main(int argc, char** argv){ int main(int argc, char** argv){
/* Starting point of the program */ /* Starting point of the program */
......
...@@ -5,10 +5,7 @@ ...@@ -5,10 +5,7 @@
void getCandidatesForP1(struct pdb_values* pdb2, struct residue** t_candid1, struct residue** t_candid2, int* nbCand1, int* nbCand2); void getCandidatesForP1(struct pdb_values* pdb2, struct residue** t_candid1, struct residue** t_candid2, int* nbCand1, int* nbCand2);
void getInterface(struct pdb_values* pdbR, struct pdb_values* pdbL); void getInterface(struct pdb_values* pdbR, struct pdb_values* pdbL);
struct docking_results* getDataForComplex();
struct pdb_values* readPDB(char* protein) ;
void removeSpace(char* string); void removeSpace(char* string);
void writePDB(struct pdb_values* pdb, char* protName, int nbConf);
int main(int argc, char** argv); int main(int argc, char** argv);
#endif #endif
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include "struct.h"
#include "allocate.h"
struct docking_results* getDataForComplex(){
char* buf = NULL;
FILE* condFile_stream = NULL;
int numberOfConf = 0, rc;
int idConf = 0, buf4, prevID = -1;
float buf3 = 0;
size_t len = 2000;
struct docking_results* dock_res = NULL;
condFile_stream = fopen(dockingFile,"r");
/* Get the number of conformations */
rc = fscanf(condFile_stream,"%f",&buf3);
rc = getline(&buf,&len,condFile_stream); /* Get rid of the rest of the line */
if(buf3 > numberOfConf)
numberOfConf = (int) buf3;
while(!feof(condFile_stream)){
rc = fscanf(condFile_stream,"%f",&buf3);
rc = getline(&buf,&len,condFile_stream); /* Get rid of the rest of the line */
if(buf3 > numberOfConf)
numberOfConf = (int) buf3;
}
numberOfConf++;
rewind(condFile_stream);
/* This is with the first MAXDo format */
if(!HCMD2){
rc = getline(&buf,&len,condFile_stream); /* Get rid of the first line */
}
/* Now that we know how many conformations we are dealing with
* allocate a structure large enough
*/
dock_res = allocate_dockingResults(numberOfConf);
while(!feof(condFile_stream)){
/* HCMD2 format */
if(HCMD2){
/* We take the first value as it is the ID of the conformation
* The rest of the line doesn't interests us here
*/
rc = fscanf(condFile_stream,"%d %d %d %d",&idConf,&buf4, &buf4, &buf4);
}else{ /* First MAXDo format */
rc = fscanf(condFile_stream,"%d %d",&idConf,&buf4);
}
/* This happens when we arrive on the last line */
if(prevID == idConf){
break;
}else{
prevID = idConf;
}
rc = fscanf(condFile_stream,"%f %f %f %f %f %f",&dock_res->distCenters[idConf],&dock_res->theta[idConf],&dock_res->phi[idConf],&dock_res->alpha[idConf],&dock_res->beta[idConf],&dock_res->gamma[idConf]);
rc = getline(&buf,&len,condFile_stream); /* Get rid of the rest of the line */
/* theta and phi angles are written in Radian already
* However that is not the case for alpha, beta and gamma angles
*/
//dock_res->theta[idConf] = dock_res->theta[idConf]*COEF_DEGREE_TO_RADIAN;
//dock_res->phi[idConf] = dock_res->phi[idConf]*COEF_DEGREE_TO_RADIAN;
dock_res->alpha[idConf] = dock_res->alpha[idConf] * COEF_DEGREE_TO_RADIAN;
dock_res->beta[idConf] = dock_res->beta[idConf] * COEF_DEGREE_TO_RADIAN;
dock_res->gamma[idConf] = dock_res->gamma[idConf] * COEF_DEGREE_TO_RADIAN;
}
dock_res->nbConf = numberOfConf;
fclose(condFile_stream);
free(buf);
return dock_res;
}
struct pdb_values* readPDB(char* protein) {
/* This function reads a PDB file and fills a structure
* containing all the necessary information.
* The structure filled is of type struct pdb_values. It is
* allocated and a pointer to this structure is returned at the end
*/
int i = 0, j = 0;
int rc = 0, nbRes = 0, numCA = 0;
int curRes = 0, curAtom = 0, firstLine = 1;
size_t len = 2000;
char totalFilePath[200];
char buf2[15];
char buf3[50];
char bufID[10] = "\0";
char* buf = NULL;
FILE* pdbFile_stream = NULL;
struct pdb_values* pdb_prot = NULL;
sprintf(totalFilePath,"%s/%s.pdb",pdbDir,protein);
if(access(totalFilePath,F_OK) == -1){
/* File does not exists, 4 file in this case
* Return NULL, which should be treated accordingly
*/
fprintf(stderr,"No such file : %s\n",totalFilePath);
exit(EXIT_FAILURE);
}
pdbFile_stream = fopen(totalFilePath,"r");
if(pdbFile_stream == NULL){
perror("fopen");
exit(EXIT_FAILURE);
}
/* Get the number of residue for this protein */
strcpy(buf3,"\0");
while(!feof(pdbFile_stream)){
rc = getline(&buf,&len,pdbFile_stream);
strncpy(buf2,buf,4);
buf2[4] = '\0';
if(strcmp("ATOM",buf2) == 0){
/* get the residue ID */
strncpy(buf2,buf+22,5);
buf2[5] = '\0';
/* We make sure that we don't count twice the
* same residue
*/
if(strcmp(buf2,buf3) != 0){
nbRes++;
strcpy(buf3,buf2);
}
}
}
/* Come back at the start of the file */
rewind(pdbFile_stream);
pdb_prot = allocate_pdb(nbRes);
while(!feof(pdbFile_stream)){
rc = getline(&buf,&len,pdbFile_stream);
if(feof(pdbFile_stream)) break; /* else the last line is read twice */
strncpy(buf2,buf,4);
buf2[4] = '\0';
if(strcmp("ATOM",buf2) != 0){
continue;
}
strncpy(bufID,buf+22,5);
bufID[5] = '\0';
/* if this is not the same residue as previously */
if(firstLine || strcmp(bufID,pdb_prot->residues[curRes].idRes) != 0){
if(firstLine){
firstLine = 0;
}else{
curRes++;
}
curAtom = 0;
/* res name */
strncpy(pdb_prot->residues[curRes].resName,buf+17,3);
pdb_prot->residues[curRes].resName[3] = '\0';
/* res ID */
strncpy(pdb_prot->residues[curRes].idRes,buf+22,5);
pdb_prot->residues[curRes].idRes[5] = '\0';
/* atom chain */
pdb_prot->residues[curRes].chain = buf[21];
}
/* atom type */
strncpy(pdb_prot->residues[curRes].atomType[curAtom],buf+13,3);
pdb_prot->residues[curRes].atomType[curAtom][3] = '\0';
/* atom ID */
strncpy(buf2,buf+6,5);
buf2[5] = '\0';
pdb_prot->residues[curRes].idAtom[curAtom] = atoi(buf2);
/* atom X */
strncpy(buf2,buf+30,8);
buf2[8] = '\0';
pdb_prot->residues[curRes].x[curAtom] = atof(buf2);
/* atom Y */
strncpy(buf2,buf+38,8);
buf2[8] = '\0';
pdb_prot->residues[curRes].y[curAtom] = atof(buf2);
/* atom Z */
strncpy(buf2,buf+46,8);
buf2[8] = '\0';
pdb_prot->residues[curRes].z[curAtom] = atof(buf2);
/* If we encounter the first or fifth CA, we note their coordinates
* specifically. We need them for the rotation
*/
if(strcmp("CA ",pdb_prot->residues[curRes].atomType[curAtom]) == 0){
numCA++;
if(numCA == 1){
pdb_prot->xCA1 = pdb_prot->residues[curRes].x[curAtom];
pdb_prot->yCA1 = pdb_prot->residues[curRes].y[curAtom];
pdb_prot->zCA1 = pdb_prot->residues[curRes].z[curAtom];
}else if(numCA == 5){
pdb_prot->xCA5 = pdb_prot->residues[curRes].x[curAtom];
pdb_prot->yCA5 = pdb_prot->residues[curRes].y[curAtom];
pdb_prot->zCA5 = pdb_prot->residues[curRes].z[curAtom];
}
}
curAtom++;
pdb_prot->residues[curRes].nbAtom++;
pdb_prot->nbAtom++;
}
/* Compute the geometric center of the protein */
for(i=0;i<pdb_prot->nbRes;i++){
for(j=0;j<pdb_prot->residues[i].nbAtom;j++){
pdb_prot->centerX = pdb_prot->centerX + pdb_prot->residues[i].x[j];
pdb_prot->centerY = pdb_prot->centerY + pdb_prot->residues[i].y[j];
pdb_prot->centerZ = pdb_prot->centerZ + pdb_prot->residues[i].z[j];
}
}
pdb_prot->centerX /= pdb_prot->nbAtom;
pdb_prot->centerY /= pdb_prot->nbAtom;
pdb_prot->centerZ /= pdb_prot->nbAtom;
free(buf);
fclose(pdbFile_stream);
return pdb_prot;
}
void writePDB(struct pdb_values* pdb, char* protName, int nConf){
/* Output the PDB corresponding to the conformation nConf */
int i = 0, j = 0;
char buf[500];
FILE* fw = NULL;
sprintf(buf,"%s/%s_%d.pdb",outputPDB,protName,nConf);
fw = fopen(buf,"w");
if(fw == NULL){
perror("fopen");
exit(EXIT_FAILURE);
}
for(i=0;i<pdb->nbRes;i++){
for(j=0;j<pdb->residues[i].nbAtom;j++){
fprintf(fw,FORMAT_LINE_PDB,pdb->residues[i].idAtom[j],
pdb->residues[i].atomType[j],pdb->residues[i].resName,pdb->residues[i].chain,
pdb->residues[i].idRes,pdb->residues[i].x[j],pdb->residues[i].y[j],pdb->residues[i].z[j]);
}
}
fclose(fw);
}
void write_candidate(struct residue** t_candid, int sizeCand, FILE* output_stream){
/* Output the residues selected as being part of the interface in the array
* t_candid
*/
int i = 0;
for(i=0;i<sizeCand;i++){
if(t_candid[i]->isCandidate){
fprintf(output_stream,"'%s' '%c' ",strtok(t_candid[i]->idRes," "),t_candid[i]->chain);
fflush(output_stream);
}
}
}
#include "struct.h"
#ifndef FILEIO_HEADER
#define FILEIO_HEADER
void writePDB(struct pdb_values* pdb, char* protName, int nConf);
struct pdb_values* readPDB(char* protein);
struct docking_results* getDataForComplex();
void write_candidate(struct residue** t_candid, int sizeCand, FILE* output_stream);
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment