/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ** ** ** ** ** ** ** ** ** ** ** ********* ** ** ** ********** ********** *** *** ** ** ** ********** ** **** **** ** ********** ** ** ** ** ** ** ** ** ** ********** ** ** ** ******** ** ** ** ** ** ** ** ** ****** ******** ** ** ** ** ** ** ** ****** *** ** ** ** ************** ** ** ** *** ** ********** ** ************** ** ** ** *** ***************** ******** ** ** ** *********** ********* ** ********* ** ** ** *********** ** ** ** *** ** ********** ** ** ** ** ** ****** ** ** ********** ** ** ** ** ** ****** ******** ** ** ** * ** ** ********* ** ** ** * ** ** ** ** ** ** ** *** ********** ** ** ** ** ** *** ********** ********** ** ** ********* ** ** ** ** ** ** E N S E M B L E T O O L S ** ** ** ** Version 2.1 ** ** ** ** ** ** Principal Investigator: Julie D. Forman-Kay ** ** ** ** Author: Mickaƫl Krzeminski ** ** ** ** Date: November 2012 ** ** ** ** ** ************************************************************************************* ** ** ** ** ** Copyright (C) The Hospital for Sick Children, 2001 ** ** ** ** Distribution of substantively modified versions of this module is prohibited ** ** without the explicit permission of the copyright holder. ** ** ** ** Any use of this work or derivative works in whole or in part for any ** ** commercial purpose or for monetary gain is prohibited. ** ** ** ** ** ** NO WARRANTY ** ** This software package is provided 'as is' without warranty of any kind, ** ** expressed or implied. ** ** ** ** ** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * \* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ #ifndef __MAP_HEADER__ #define __MAP_HEADER__ void _cleanMap(PDBListData *ENSData, residueList *residueNbs, flaver **distances, char *PDBListFileName, char *outFileName, char *epsOutFileName, char *epsOutStdvFileName) { counter residueNb; _cleanPDB(ENSData); if (residueNbs != NULL) { free((*residueNbs).nbs); (*residueNbs).nbs = NULL; for (residueNb=0; residueNb<(*residueNbs).nb; residueNb++) free(distances[residueNb]); } free(distances); free(PDBListFileName); PDBListFileName = NULL; free(outFileName); outFileName = NULL; free(epsOutFileName); epsOutFileName = NULL; free(epsOutStdvFileName); epsOutStdvFileName = NULL; } int caca_map(flaver ***distances, PDBListData *ENSData, residueList *residueNbs, char *epsOutFileName, char *epsOutStdvFileName, float lowerDistance, float upperDistance, float upStdv, color *ldRGB, color *udRGB) { counter residueNb, subResidueNb, confNb; int resiMin, resiMax, resiRange; float *CaCaDistances; color colFactor, colFactorStdv, effRGB; FILE *epsOutFile, *epsOutStdvFile; (*distances) = malloc((*residueNbs).nb * sizeof(flaver *)); // Calculating average distances between Ca-Ca atoms and their standard deviations if ((CaCaDistances = malloc((*ENSData).nbConfs * sizeof(float *))) == NULL) fatal_error("MEMORY", "instance avgDistances variable"); for (residueNb=0; residueNb<(*residueNbs).nb; residueNb++) { (*distances)[residueNb] = malloc((*residueNbs).nb * sizeof(flaver)); (*distances)[residueNb][residueNb].average = 0; (*distances)[residueNb][residueNb].stdv = 0; } for (residueNb=0; residueNb<(*residueNbs).nb-1; residueNb++) { for (subResidueNb=residueNb+1; subResidueNb<(*residueNbs).nb; subResidueNb++) { (*distances)[residueNb][subResidueNb].average = 0.; for (confNb=0; confNb<(*ENSData).nbConfs; confNb++) { CaCaDistances[confNb] = distance((*ENSData).atomCoords[confNb][residueNb], (*ENSData).atomCoords[confNb][subResidueNb]); (*distances)[residueNb][subResidueNb].average += CaCaDistances[confNb]; } (*distances)[residueNb][subResidueNb].average /= (*ENSData).nbConfs; (*distances)[subResidueNb][residueNb].average = (*distances)[residueNb][subResidueNb].average; (*distances)[residueNb][subResidueNb].stdv = 0.; for (confNb=0; confNb<(*ENSData).nbConfs; confNb++) { (*distances)[residueNb][subResidueNb].stdv += (CaCaDistances[confNb] - (*distances)[residueNb][subResidueNb].average) * (CaCaDistances[confNb] - (*distances)[residueNb][subResidueNb].average); } (*distances)[residueNb][subResidueNb].stdv = sqrt((*distances)[residueNb][subResidueNb].stdv/(*ENSData).nbConfs); (*distances)[subResidueNb][residueNb].stdv = (*distances)[residueNb][subResidueNb].stdv; } } // Releasing memory free(CaCaDistances); // Writing the eps files resiMin = (*residueNbs).nbs[0]; resiMax = (*residueNbs).nbs[(*residueNbs).nb-1]; resiRange = resiMax - resiMin + 1; colFactor.r = ((*udRGB).r - (*ldRGB).r) / (upperDistance - lowerDistance); colFactor.g = ((*udRGB).g - (*ldRGB).g) / (upperDistance - lowerDistance); colFactor.b = ((*udRGB).b - (*ldRGB).b) / (upperDistance - lowerDistance); colFactorStdv.r = ((*udRGB).r - (*ldRGB).r) / upperDistance; colFactorStdv.g = ((*udRGB).g - (*ldRGB).g) / upperDistance; colFactorStdv.b = ((*udRGB).b - (*ldRGB).b) / upperDistance; struct tm d; char dateTime[24]; time_t now = time(NULL); d = *(localtime(&now)); strftime(dateTime, 24, "%b %d, %Y at %I:%M%p", &d); if ((epsOutFile = fopen(epsOutFileName, "wt")) == NULL) fatal_error("CREATION_FILE", epsOutFileName); if ((epsOutStdvFile = fopen(epsOutStdvFileName, "wt")) == NULL) fatal_error("CREATION_FILE", epsOutStdvFileName); fprintf(epsOutFile, "%%!PS-Adobe-3.0 EPSF-3.0\n%%Creator: ENSEMBLE, from Julie Forman-Kay's lab\n%%Title: %s\n%%CreationDate: %s\n%%DocumentData: Clean7Bit\n%%Origin: 0 0\n%%BoundingBox: 0 0 %d %d\n%%LanguageLevel: 2\n%%Pages: 1\n%%EndComments\n\n", epsOutFileName, dateTime, 10*resiRange+56, 10*resiRange+60); fputs("/csquare\n{\n newpath\n 0 0 moveto\n 0 1 rlineto\n 1 0 rlineto\n 0 -1 rlineto\n closepath\n setrgbcolor\n fill\n} def\n\n", epsOutFile); fprintf(epsOutFile, "2 setlinecap\nnewpath\n28 %d moveto\n0 -%d rlineto\n%d 0 rlineto\n1 0 0 setrgbcolor\n3 setlinewidth\nstroke\n%%EndProlog\n\n", 18 + 10*resiRange, 10*resiRange, 10*resiRange); fprintf(epsOutStdvFile, "%%!PS-Adobe-3.0 EPSF-3.0\n%%Creator: ENSEMBLE, from Julie Forman-Kay's lab\n%%Title: %s\n%%CreationDate: %s\n%%DocumentData: Clean7Bit\n%%Origin: 0 0\n%%BoundingBox: 0 0 %d %d\n%%LanguageLevel: 2\n%%Pages: 1\n%%EndComments\n\n", epsOutFileName, dateTime, 10*resiRange+56, 10*resiRange+60); fputs("/csquare\n{\n newpath\n 0 0 moveto\n 0 1 rlineto\n 1 0 rlineto\n 0 -1 rlineto\n closepath\n setrgbcolor\n fill\n} def\n\n", epsOutStdvFile); fprintf(epsOutStdvFile, "2 setlinecap\nnewpath\n28 %d moveto\n0 -%d rlineto\n%d 0 rlineto\n1 0 0 setrgbcolor\n3 setlinewidth\nstroke\n%%EndProlog\n\n", 18 + 10*resiRange, 10*resiRange, 10*resiRange); fputs ("0 0 0 setrgbcolor\n/Monospace-Bold findfont 12 scalefont setfont\n", epsOutFile); fputs ("0 0 0 setrgbcolor\n/Monospace-Bold findfont 12 scalefont setfont\n", epsOutStdvFile); for (residueNb=0; residueNb<(*residueNbs).nb-1; residueNb++) { if (!((*residueNbs).nbs[residueNb]%10) || residueNb==0) { fprintf(epsOutFile, "%d 1 moveto (%d) show\n", 30 + 10 * residueNb, (*residueNbs).nbs[residueNb]); fprintf(epsOutFile, "1 %d moveto (%d) show\n", 20 + 10 * residueNb, (*residueNbs).nbs[residueNb]); fprintf(epsOutStdvFile, "%d 1 moveto (%d) show\n", 30 + 10 * residueNb, (*residueNbs).nbs[residueNb]); fprintf(epsOutStdvFile, "1 %d moveto (%d) show\n", 20 + 10 * residueNb, (*residueNbs).nbs[residueNb]); } } fprintf(epsOutFile, "30 20 translate\n10 10 scale\n\n"); fprintf(epsOutStdvFile, "30 20 translate\n10 10 scale\n\n"); for (residueNb=0; residueNb<(*residueNbs).nb; residueNb++) { for (subResidueNb=0; subResidueNb<(*residueNbs).nb; subResidueNb++) { if ((*distances)[residueNb][subResidueNb].average < lowerDistance) { effRGB.r = (*ldRGB).r; effRGB.g = (*ldRGB).g; effRGB.b = (*ldRGB).b; } else if ((*distances)[residueNb][subResidueNb].average > upperDistance) { effRGB.r = (*udRGB).r; effRGB.g = (*udRGB).g; effRGB.b = (*udRGB).b; } else { effRGB.r = (*ldRGB).r + colFactor.r * ((*distances)[residueNb][subResidueNb].average - lowerDistance); effRGB.g = (*ldRGB).g + colFactor.g * ((*distances)[residueNb][subResidueNb].average - lowerDistance); effRGB.b = (*ldRGB).b + colFactor.b * ((*distances)[residueNb][subResidueNb].average - lowerDistance); } fprintf(epsOutFile, "%.2f %.2f %.2f csquare\n", effRGB.r, effRGB.g, effRGB.b); fputs("1 0 translate\n", epsOutFile); if ((*distances)[residueNb][subResidueNb].average > upStdv) { effRGB.r = (*udRGB).r; effRGB.g = (*udRGB).g; effRGB.b = (*udRGB).b; } else { effRGB.r = (*ldRGB).r + colFactorStdv.r * (*distances)[residueNb][subResidueNb].stdv; effRGB.g = (*ldRGB).g + colFactorStdv.g * (*distances)[residueNb][subResidueNb].stdv; effRGB.b = (*ldRGB).b + colFactorStdv.b * (*distances)[residueNb][subResidueNb].stdv; } fprintf(epsOutStdvFile, "%.2f %.2f %.2f csquare\n", effRGB.r, effRGB.g, effRGB.b); fputs("1 0 translate\n", epsOutStdvFile); } fprintf(epsOutFile, "\n-%d 1 translate\n", (*residueNbs).nb); fprintf(epsOutStdvFile, "\n-%d 1 translate\n", (*residueNbs).nb); } fputs("showpage\n\n%%EOF\n", epsOutFile); fputs("showpage\n\n%%EOF\n", epsOutStdvFile); fclose(epsOutFile); fclose(epsOutStdvFile); return 0; } #endif