#include #include #include #include #include "clustalw.h" /* * Prototypes */ void calc_p_penalties(char **aln, sint n, sint fs, sint ls, sint *weight); void calc_h_penalties(char **aln, sint n, sint fs, sint ls, sint *weight); void calc_v_penalties(char **aln, sint n, sint fs, sint ls, sint *weight); sint local_penalty(sint penalty, sint n, sint *pweight, sint *hweight, sint *vweight); float percentid(char *s1, char *s2,sint length); /* * Global variables */ extern sint gap_dist; extern sint max_aa; extern sint debug; extern Boolean dnaflag; extern Boolean use_endgaps; extern Boolean endgappenalties; extern Boolean no_var_penalties, no_hyd_penalties, no_pref_penalties; extern char hyd_residues[]; extern char *amino_acid_codes; /* vwindow is the number of residues used for a window for the variable zone penalties */ /* vll is the lower limit for the variable zone penalties (vll < pen < 1.0) */ int vll=50; int vwindow=5; sint vlut[26][26] = { /* A B C D E F G H I J K L M N O P Q R S T U V W X Y Z */ /*A*/ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /*B*/ 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /*C*/ 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /*D*/ 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /*E*/ 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /*F*/ 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /*G*/ 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, /*U*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, /*V*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, /*W*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, /*X*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, /*Y*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, /*Z*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }; /* pascarella probabilities for opening a gap at specific residues */ char pr[] = {'A' , 'C', 'D', 'E', 'F', 'G', 'H', 'K', 'I', 'L', 'M' , 'N', 'P', 'Q', 'R', 'S', 'T', 'V', 'Y', 'W'}; sint pas_op[] = { 87, 87,104, 69, 80,139,100,104, 68, 79, 71,137,126, 93,128,124,111, 75,100, 77}; sint pas_op2[] ={ 88, 57,111, 98, 75,126, 95, 97, 70, 90, 60,122,110,107, 91,125,124, 81,106, 88}; sint pal_op[] = { 84, 69,128, 78, 88,176, 53, 95, 55, 49, 52,148,147,100, 91,129,105, 51,128, 88}; float reduced_gap = 0.15; Boolean nvar_pen,nhyd_pen,npref_pen; /* local copies of ho_hyd_penalties, no_pref_penalties */ sint gdist; /* local copy of gap_dist */ void calc_gap_coeff(char **alignment, sint *gaps, sint **profile, Boolean struct_penalties, char *gap_penalty_mask, sint first_seq, sint last_seq, sint prf_length, sint gapcoef, sint lencoef) { char c; sint i, j; sint is, ie; static sint numseq,val,pcid; static sint *gap_pos; static sint *v_weight, *p_weight, *h_weight; static float scale; numseq = last_seq - first_seq; if(numseq == 2) { pcid=percentid(alignment[first_seq],alignment[first_seq+1],prf_length); } else pcid=0; for (j=0; j 60) { if(debug>0) fprintf(stderr,"Using variable zones to set gap penalties (pcid = %d)\n",pcid); nhyd_pen = npref_pen = TRUE; nvar_pen = FALSE; } else { nvar_pen = TRUE; nhyd_pen = no_hyd_penalties; npref_pen = no_pref_penalties; gdist = gap_dist; } for (i=first_seq; i max_aa)) is++; else break; } for (j=prf_length-1; j>=0; j--) { c = alignment[i][j]; if ((c < 0) || (c > max_aa)) ie--; else break; } } for (j=is; j max_aa)) gaps[j]++; } } if ((!dnaflag) && (nvar_pen == FALSE)) { v_weight = (sint *) ckalloc( (prf_length+2) * sizeof (sint) ); calc_v_penalties(alignment, prf_length, first_seq, last_seq, v_weight); } if ((!dnaflag) && (npref_pen == FALSE)) { p_weight = (sint *) ckalloc( (prf_length+2) * sizeof (sint) ); calc_p_penalties(alignment, prf_length, first_seq, last_seq, p_weight); } if ((!dnaflag) && (nhyd_pen == FALSE)) { h_weight = (sint *) ckalloc( (prf_length+2) * sizeof (sint) ); calc_h_penalties(alignment, prf_length, first_seq, last_seq, h_weight); } gap_pos = (sint *) ckalloc( (prf_length+2) * sizeof (sint) ); /* mark the residues close to an existing gap (set gaps[i] = -ve) */ if (dnaflag || (gdist <= 0)) { for (i=0;i=0) && (i+j 0) { if (i>=prf_length) break; gap_pos[i] = gaps[i]; i++; } for (j = 0; j 0) break; if ((i+j>=0) && (i+j1) { fprintf(stdout,"gap open %d gap ext %d\n",(pint)gapcoef,(pint)lencoef); fprintf(stdout,"gaps:\n"); for(i=0;i 0 && val < 10) { profile[j+1][GAPCOL] *= val; profile[j+1][LENCOL] *= val; } } /* make sure no penalty is zero - even for all-gap positions */ if (profile[j+1][GAPCOL] <= 0) profile[j+1][GAPCOL] = 1; if (profile[j+1][LENCOL] <= 0) profile[j+1][LENCOL] = 1; } /* set the penalties at the beginning and end of the profile */ if(endgappenalties==TRUE) { profile[0][GAPCOL] = gapcoef; profile[0][LENCOL] = lencoef; } else { profile[0][GAPCOL] = 0; profile[0][LENCOL] = 0; profile[prf_length][GAPCOL] = 0; profile[prf_length][LENCOL] = 0; } if (debug>0) { fprintf(stdout,"Opening penalties:\n"); for(i=0;i<=prf_length;i++) fprintf(stdout," %d:%d ",i, (pint)profile[i][GAPCOL]); fprintf(stdout,"\n"); } if (debug>0) { fprintf(stdout,"Extension penalties:\n"); for(i=0;i<=prf_length;i++) fprintf(stdout,"%d:%d ",i, (pint)profile[i][LENCOL]); fprintf(stdout,"\n"); } if ((!dnaflag) && (nvar_pen == FALSE)) v_weight=ckfree((void *)v_weight); if ((!dnaflag) && (npref_pen == FALSE)) p_weight=ckfree((void *)p_weight); if ((!dnaflag) && (nhyd_pen == FALSE)) h_weight=ckfree((void *)h_weight); gap_pos=ckfree((void *)gap_pos); } void calc_v_penalties(char **aln, sint n, sint fs, sint ls, sint *weight) { char ix1,ix2; sint i,j,k,t; for (i=0;i=0 && j max_aa) || (ix2< 0) || (ix2> max_aa)) continue; weight[i] += vlut[amino_acid_codes[ix1]-'A'][amino_acid_codes[ix2]-'A']; t++; } } /* now we have a weight -t < w < t */ weight[i] +=t; if(t>0) weight[i] = (weight[i]*100)/(2*t); else weight[i] = 100; /* now we have a weight vll < w < 100 */ if (weight[i] max_aa)) continue; if (amino_acid_codes[ix] == pr[j]) { weight[i] += (180-pas_op[j]); break; } } } weight[i] /= numseq; } } void calc_h_penalties(char **aln, sint n, sint fs, sint ls, sint *weight) { /* weight[] is the length of the hydrophilic run of residues. */ char ix; sint nh,j,k; sint i,e,s; sint *hyd; float scale; hyd = (sint *)ckalloc((n+2) * sizeof(sint)); nh = (sint)strlen(hyd_residues); for (i=0;i max_aa)) continue; if (amino_acid_codes[ix] == hyd_residues[j]) { hyd[i] = 1; break; } } } i = 0; while (i < n) { if (hyd[i] == 0) i++; else { s = i; while ((hyd[i] != 0) && (i 3) for (j=s; j1) { for(i=0;i 0) { gw *= 0.5; h = TRUE; } } if ((npref_pen == FALSE) && (h==FALSE)) { gw *= ((float)pweight[n]/100.0); } gw *= penalty; return((sint)gw); } float percentid(char *s1, char *s2,sint length) { sint i; sint count,total; float score; count = total = 0; for (i=0;i=0) && (s1[i]