#include #include #include #include #include #include "clustalw.h" #include "matrices.h" /* * Prototypes */ static Boolean commentline(char *line); /* * Global variables */ extern char *amino_acid_codes; extern sint gap_pos1, gap_pos2; extern sint max_aa; extern short def_dna_xref[],def_aa_xref[]; extern sint mat_avscore; extern sint debug; extern Boolean dnaflag; extern Boolean user_series; extern UserMatSeries matseries; extern short usermatseries[MAXMAT][NUMRES][NUMRES]; extern short aa_xrefseries[MAXMAT][NUMRES+1]; void init_matrix(void) { char c1,c2; short i, j, maxres; max_aa = strlen(amino_acid_codes)-2; gap_pos1 = NUMRES-2; /* code for gaps inserted by clustalw */ gap_pos2 = NUMRES-1; /* code for gaps already in alignment */ /* set up cross-reference for default matrices hard-coded in matrices.h */ for (i=0;i max) max = matrix[i][j]; } av1 = av2 = av3 = 0; for (i=0;i<=max_aa;i++) { for (j=0;j<=i;j++) { av1 += matrix[i][j]; if (i==j) { av2 += matrix[i][j]; } else { av3 += matrix[i][j]; } } } av1 /= (maxres*maxres)/2; av2 /= maxres; av3 /= ((float)(maxres*maxres-maxres))/2; if (debug>1) fprintf(stdout,"average mismatch score %d\n",(pint)av3); if (debug>1) fprintf(stdout,"average match score %d\n",(pint)av2); if (debug>1) fprintf(stdout,"average score %d\n",(pint)av1); mat_avscore = -av3; /* if requested, make a positive matrix - add -(lowest score) to every entry */ if (neg_flag == FALSE) { if (debug>1) fprintf(stdout,"min %d max %d\n",(pint)min,(pint)max); if (min < 0) { for (i=0;i<=max_aa;i++) { ti = xref[i]; if (ti != -1) { for (j=0;j<=max_aa;j++) { tj = xref[j]; /* if (tj != -1) matrix[ti][tj] -= (2*av3); */ if (tj != -1) matrix[ti][tj] -= min; } } } } /* gr_score = av3; gg_score = -av3; */ } for (i=0;i 100 || ulimit <0 || ulimit>100) { error("Bad format in file %s\n",filename); fclose(fd); return((sint)0); } if(ulimit<=llimit) { error("in file %s: lower limit is greater than upper (%d-%d)\n",filename,llimit,ulimit); fclose(fd); return((sint)0); } n=read_user_matrix(mat_filename,&usermatseries[nmat][0][0],&aa_xrefseries[nmat][0]); if(n<=0) { error("Bad format in matrix file %s\n",mat_filename); fclose(fd); return((sint)0); } matseries.mat[nmat].llimit=llimit; matseries.mat[nmat].ulimit=ulimit; matseries.mat[nmat].matptr=&usermatseries[nmat][0][0]; matseries.mat[nmat].aa_xref=&aa_xrefseries[nmat][0]; nmat++; } } fclose(fd); matseries.nmat=nmat; maxres=n; return(maxres); } sint read_user_matrix(char *filename, short *usermat, short *xref) { double f; FILE *fd; sint numargs,farg; sint i, j, k = 0; char codes[NUMRES]; char inline1[1024]; char *args[NUMRES+4]; char c1,c2; sint ix1, ix = 0; sint maxres = 0; float scale; if (filename[0] == '\0') { error("comparison matrix not specified"); return((sint)0); } if ((fd=fopen(filename,"r"))==NULL) { error("cannot open %s", filename); return((sint)0); } maxres = 0; while (fgets(inline1,1024,fd) != NULL) { if (commentline(inline1)) continue; if(linetype(inline1,"CLUSTAL_SERIES")) { error("in %s - single matrix expected.", filename); fclose(fd); return((sint)0); } /* read residue characters. */ k = 0; for (j=0;jNUMRES) { error("too many entries in matrix %s",filename); fclose(fd); return((sint)0); } } codes[k] = '\0'; break; } if (k == 0) { error("wrong format in matrix %s",filename); fclose(fd); return((sint)0); } /* cross-reference the residues */ for (i=0;i