12 #define AA "GAVLIFPSTCMWYNQDEKRH"
25 #define MAX(a,b) ((a)>(b)?(a):(b))
26 #define MIN(a,b) ((a)<(b)?(a):(b))
54 void read_mat(char *path, char *fn, double **MAT, double *matave);
55 int getargs(char *line,char *args[],int max);
56 void read_ref(char *path, char *fn, double **REF);
57 void Get_Histo( P_STR *PARAMS, char *path, char *);
58 double **DMatrix(int n_rows, int n_cols);
59 void *my_malloc(size_t size);
60 void IUPred(SEQ_STR *SEQ, P_STR *PARAMS);
61 void getRegions(SEQ_STR *SEQ );
62 void Get_Seq(char *fn, SEQ_STR *SEQ);
63 void createOutputFiles(int type);
64 void closeOutputFiles(int type);
77 int main(int argc, char **argv)
86 printf(" Usage: %s seqfile type \n",argv[0]);
87 printf(" where type stands for one of the options of \n");
88 printf(" \"long\", \"short\", \"glob\" or \"all\"\n");
91 if ((path=getenv("IUPred_PATH"))==NULL) {
92 fprintf(stderr,"IUPred_PATH environment variable is not set\n");
96 printf("# IUPred \n");
97 printf("# Copyright (c) Zsuzsanna Dosztanyi, 2005\n");
99 printf("# Z. Dosztanyi, V. Csizmok, P. Tompa and I. Simon\n");
100 printf("# J. Mol. Biol. (2005) 347, 827-839. \n");
102 printf("# Modified to work within JABAWS (http://www.compbio.dundee.ac.uk/jabaws) framework by \n");
103 printf("# Peter Troshin (pvtroshin@dundee.ac.uk) and Geoff Barton gjbarton@dundee.ac.uk\n");
104 printf("# June, 2011\n");
109 if ((strncmp(argv[2],"long",4))==0) {
112 else if ((strncmp(argv[2],"short",5))==0) {
115 else if ((strncmp(argv[2],"glob",4))==0) {
118 else if ((strncmp(argv[2],"all",3))==0) {
122 printf("No disorder type is given assuming long\n");
126 /* Creating output files depending on the type */
127 createOutputFiles(type);
130 /* Read input file sequence by sequence */
133 fasta = fopen(argv[1], "r");
137 fastaseq = gseq_fasta(fasta);
141 SEQ=malloc(sizeof(SEQ_STR));
143 //printf("No: %s\n",fastaseq->id );
144 //printf("L: %d\n",fastaseq->slen);
146 SEQ->name=fastaseq->id;
147 SEQ->seq=fastaseq->seq;
148 SEQ->le=fastaseq->slen;
151 printf("N: %s\n",SEQ->name);
152 printf("S: %s\n",SEQ->seq);
153 printf("L: %d\n",SEQ->le);
157 if (SEQ->le==0) {printf(" Sequence length 0\n");exit(1);}
160 printf("%s %d\n%s\n",SEQ->name,SEQ->le,SEQ->seq);
164 PARAMS=malloc(sizeof(P_STR));
165 PARAMS->CC= DMatrix(AAN,AAN);
167 /* LONG - DISORDER */
168 if (type==0 || type==3) {
174 read_ref(path,"ss",PARAMS->CC);
175 Get_Histo(PARAMS, path, "histo");
179 fprintf(longout, "# %s\n",SEQ->name);
181 for (i=0;i<SEQ->le;i++)
182 fprintf(longout, "%5d %c %10.4f\n",i+1,SEQ->seq[i],SEQ->en[i]);
185 /* SHORT - DISORDER */
186 if (type==1 || type==3) {
193 read_ref(path,"ss_casp",PARAMS->CC);
194 Get_Histo(PARAMS, path, "histo_casp");
198 fprintf(shortout, "# %s\n",SEQ->name);
199 for (i=0;i<SEQ->le;i++)
200 fprintf(shortout, "%5d %c %10.4f\n",i+1,SEQ->seq[i],SEQ->en[i]);
203 /* GLOB - GLOBULAR DOMAINS */
204 if (type==2 || type==3) {
212 read_ref(path,"ss",PARAMS->CC);
213 Get_Histo(PARAMS,path,"histo");
222 globseq=malloc((SEQ->le+1)*sizeof(char));
223 for (i=0;i<SEQ->le;i++) globseq[i]=tolower(SEQ->seq[i]);
225 fprintf(globout,"# %s\n",SEQ->name);
226 fprintf(globout,"Number of globular domains: %5d \n",SEQ->ngr);
227 for (i=0;i<SEQ->ngr;i++) {
228 fprintf(globout," globular domain %5d. %d - %d \n",
229 i+1,SEQ->gr[i][0]+1,SEQ->gr[i][1]+1);
230 for (j=SEQ->gr[i][0];j<SEQ->gr[i][1]+1;j++) {
231 globseq[j]=toupper(globseq[j]);
234 fprintf(globout,">%s\n",SEQ->name);
235 for (i=0;i<SEQ->le;i++) {
236 if ((i>0)&&(i%60==0)) fprintf(globout,"\n");
237 else if ((i>0)&&(i%10==0)) fprintf(globout," ");
238 fprintf(globout,"%c",globseq[i]);
240 fprintf(globout,"\n");
245 for (i=0;i<SEQ->le;i++)
246 printf("%5d %c %10.4f\n",i,SEQ->seq[i],SEQ->en[i]);
255 } while(fastaseq != NULL);
258 closeOutputFiles(type);
264 void closeOutputFiles(int type) {
281 void createOutputFiles(int type) {
283 longout = fopen("out.long", "w");
286 shortout = fopen("out.short", "w");
289 globout = fopen("out.glob", "w");
292 longout = fopen("out.long", "w");
293 shortout = fopen("out.short", "w");
294 globout = fopen("out.glob", "w");
298 void IUPred(SEQ_STR *SEQ, P_STR *PARAMS)
303 double min, max, step;
306 min=PARAMS->min; max=PARAMS->max;step=PARAMS->step;
308 SEQ->eprof=malloc(naa*sizeof(double));
309 for (i=0;i<naa;i++) SEQ->eprof[i]=0;
310 SEQ->en=malloc(naa*sizeof(double));
311 for (i=0;i<naa;i++) SEQ->en[i]=0;
312 SEQ->smp=malloc(naa*sizeof(double));
314 for (i=0;i<naa;i++) SEQ->smp[i]=0;
317 for (i=0;i<naa;i++) {
318 a1=strchr(AA,((toupper(SEQ->seq[i]))))-AA;
319 if ((a1<0) || (a1>=AAN)) continue;
321 for (j=0;j<naa;j++) if (((abs(i-j))>LC)&&((abs(i-j))<UC)) {
322 a2=strchr(AA,((toupper(SEQ->seq[j]))))-AA;
323 if ((a2<0) || (a2>=AAN)) continue;
324 SEQ->eprof[i]+=PARAMS->CC[a1][a2];
327 SEQ->expscore+=SEQ->eprof[i]/(naa*n2);
333 for (i=0;i<naa;i++) {
335 for (j=MAX(0,i-WS);j<=MIN(naa,i+WS+1);j++) {
336 SEQ->smp[i]+=SEQ->eprof[j];
342 for (i=0;i<naa;i++) {
344 for (j=i-WS;j<i+WS;j++) {
345 if ((j<0)||(j>=naa)) SEQ->smp[i]+=EP;
346 else SEQ->smp[i]+=SEQ->eprof[j];
354 for (i=0;i<naa;i++) {
356 if (SEQ->smp[i]<=min+2*step) SEQ->en[i]=1;
357 if (SEQ->smp[i]>=max-2*step) SEQ->en[i]=0;
358 if ((SEQ->smp[i]>min+2*step)&&(SEQ->smp[i]<max-2*step)) {
359 p=(int)((SEQ->smp[i]-min)*(1.0/step));
360 SEQ->en[i]=PARAMS->distro[p];
364 printf("%5d %10.4f %10.4f %10.4f\n",
365 i,SEQ->eprof[i], SEQ->smp[i],SEQ->en[i]);
374 void getRegions(SEQ_STR *SEQ )
394 for (i=0;i<naa;i++) {
396 if ((in_GR==1)&&(SEQ->smp[i]<=Min_Ene)) {
397 GR=realloc(GR,(nr+1)*sizeof(int *));
398 GR[nr]=malloc(2*sizeof(int));
406 if ((SEQ->smp[i]>Min_Ene)&&(in_GR==0)) {
413 GR=realloc(GR,(nr+1)*sizeof(int *));
414 GR[nr]=malloc(2*sizeof(int));
426 beg=GR[0][0];end=GR[0][1];
429 if ((kk<nr)&&(GR[kk][0]-end)<JOIN) {
434 else if ((end-beg+1)<DEL) {
442 mGR=realloc(mGR,(mnr+1)*sizeof(int*));
443 mGR[mnr]=malloc(2*sizeof(int));
457 for (i=0;i<nr;i++) free(GR[i]);
468 void Get_Histo(P_STR *PARAMS, char *path, char *fn)
473 double v, min, max, cutoff, c;
477 sl=strlen(path)+strlen(fn)+2;
478 fullfn=malloc(sl*sizeof(char));
479 sprintf(fullfn,"%s/%s",path,fn);
481 if ((f=fopen(fullfn,"r"))==NULL) {
482 printf("Could not open %s\n",fullfn);
488 fscanf(f,"%*s %lf %lf %d\n",&min, &max, &nb);
490 PARAMS->distro=malloc(nb*sizeof(double ));
491 for (i=0;i<nb;i++) PARAMS->distro[i]=0;
494 for (i=0,set=0;i<nb;i++) {
497 if (ln[0]=='#') continue;
499 sscanf(ln,"%*s %lf %*s %*s %lf\n", &c,&v);
500 if ((set==0)&&(v<=0.5)) {set=1;cutoff=c;}
508 PARAMS->cutoff=cutoff;
511 PARAMS->step=(max-min)/nb;
512 PARAMS->cutoff-=PARAMS->step;
517 void read_ref(char *path, char *fn, double **REF)
523 char line[1000],s[20];
528 sl=strlen(path)+strlen(fn)+2;
529 fullfn=malloc(sl*sizeof(char));
530 sprintf(fullfn,"%s/%s",path,fn);
532 if ((f=fopen(fullfn,"r"))==NULL) {
533 printf("Could not open %s\n",fullfn);
541 sscanf(line,"%d",&p1);
542 sscanf(&line[8],"%d",&p2);
543 sscanf(&line[17],"%s",s);
551 for (i=0;i<AAN;i++) for (j=0;j<AAN;j++)
562 void read_mat(char *path, char *fn, double **MAT, double *matave)
567 char *args[AAN+2], AAL[AAN],a1,a2;
573 sl=strlen(path)+strlen(fn)+2;
574 fullfn=malloc(sl*sizeof(char));
575 sprintf(fullfn,"%s/%s",path,fn);
577 if ((f=fopen(fullfn,"r"))==NULL) {
578 printf("Could not open %s\n",fullfn);
584 sprintf(AAL,"%s",ln);
592 if (ln[0] == '\n') continue;
593 if (ln[0] == '#') continue;
594 numargs = getargs(ln,args,AAN+2);
598 for (j=0;j<numargs;j++) {
613 for (i=0;i<AAN;i++) for (j=0;j<AAN;j++) *matave+=MAT[i][j];
623 int getargs(char *line,char *args[],int max)
629 for (i=0;i<max;i++) {
630 if ((args[i]=strtok(inptr," \t\n"))==NULL)
640 void *my_malloc(size_t size)
647 new_mem = malloc(size);
648 if (new_mem == NULL) {
649 fprintf(stderr, "can't allocate enough memory: %d bytes\n", size);
656 double **DMatrix(int n_rows, int n_cols)
661 matrix = (double **) my_malloc(n_rows*sizeof(double *));
662 matrix[0] = (double *) my_malloc(n_rows*n_cols*sizeof(double));
664 for (i = 1; i < n_rows; i++)
665 matrix[i] = matrix[i-1] + n_cols;
666 for (i=0;i<n_rows;i++) for (j=0;j<n_cols;j++) matrix[i][j]=0;
674 void Get_Seq(char *fn, SEQ_STR *SEQ)
681 if ((fn==NULL)||(strlen(fn)==0)) {
682 printf("No sequence filename\n"),exit(1);
685 if ((f=fopen(fn,"r"))==NULL) {
686 printf("Could not open %s\n",fn),exit(1);
690 SEQ->seq=calloc(MSL,sizeof(char));
693 sscanf(&line[1],"%s",SEQ->name);
697 while ((c!='>') && (!feof(f))) {
699 if (isalpha((int)(c))) {
702 if ((j>0)&&(j%MSL==0)) {
703 SEQ->seq=realloc(SEQ->seq,(j+MSL)*sizeof(char));
710 printf("%s %5d\n%s\n",SEQ->name,SEQ->le,SEQ->seq);