| 1 | #include <stdio.h> |
|---|
| 2 | #include <math.h> |
|---|
| 3 | #include <stdlib.h> |
|---|
| 4 | #include <string.h> |
|---|
| 5 | #include "clustalw.h" |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | /* |
|---|
| 9 | * Prototypes |
|---|
| 10 | */ |
|---|
| 11 | |
|---|
| 12 | /* |
|---|
| 13 | * Global variables |
|---|
| 14 | */ |
|---|
| 15 | |
|---|
| 16 | extern sint max_aa,gap_pos1,gap_pos2; |
|---|
| 17 | |
|---|
| 18 | void calc_prf1(sint **profile, char **alignment, sint *gaps, |
|---|
| 19 | sint matrix[NUMRES][NUMRES], |
|---|
| 20 | sint *seq_weight, sint prf_length, sint first_seq, sint last_seq) |
|---|
| 21 | { |
|---|
| 22 | |
|---|
| 23 | sint **weighting, sum2, d, i, res; |
|---|
| 24 | sint numseq; |
|---|
| 25 | sint r, pos; |
|---|
| 26 | int f; |
|---|
| 27 | float scale; |
|---|
| 28 | |
|---|
| 29 | weighting = (sint **) ckalloc( (NUMRES+2) * sizeof (sint *) ); |
|---|
| 30 | for (i=0;i<NUMRES+2;i++) |
|---|
| 31 | weighting[i] = (sint *) ckalloc( (prf_length+2) * sizeof (sint) ); |
|---|
| 32 | |
|---|
| 33 | numseq = last_seq-first_seq; |
|---|
| 34 | |
|---|
| 35 | sum2 = 0; |
|---|
| 36 | for (i=first_seq; i<last_seq; i++) |
|---|
| 37 | sum2 += seq_weight[i]; |
|---|
| 38 | |
|---|
| 39 | for (r=0; r<prf_length; r++) |
|---|
| 40 | { |
|---|
| 41 | for (d=0; d<=max_aa; d++) |
|---|
| 42 | { |
|---|
| 43 | weighting[d][r] = 0; |
|---|
| 44 | for (i=first_seq; i<last_seq; i++) |
|---|
| 45 | if (d == alignment[i][r]) weighting[d][r] += seq_weight[i]; |
|---|
| 46 | } |
|---|
| 47 | weighting[gap_pos1][r] = 0; |
|---|
| 48 | for (i=first_seq; i<last_seq; i++) |
|---|
| 49 | if (gap_pos1 == alignment[i][r]) weighting[gap_pos1][r] += seq_weight[i]; |
|---|
| 50 | weighting[gap_pos2][r] = 0; |
|---|
| 51 | for (i=first_seq; i<last_seq; i++) |
|---|
| 52 | if (gap_pos2 == alignment[i][r]) weighting[gap_pos2][r] += seq_weight[i]; |
|---|
| 53 | } |
|---|
| 54 | |
|---|
| 55 | for (pos=0; pos< prf_length; pos++) |
|---|
| 56 | { |
|---|
| 57 | if (gaps[pos] == numseq) |
|---|
| 58 | { |
|---|
| 59 | for (res=0; res<=max_aa; res++) |
|---|
| 60 | { |
|---|
| 61 | profile[pos+1][res] = matrix[res][gap_pos1]; |
|---|
| 62 | } |
|---|
| 63 | profile[pos+1][gap_pos1] = matrix[gap_pos1][gap_pos1]; |
|---|
| 64 | profile[pos+1][gap_pos2] = matrix[gap_pos2][gap_pos1]; |
|---|
| 65 | } |
|---|
| 66 | else |
|---|
| 67 | { |
|---|
| 68 | scale = (float)(numseq-gaps[pos]) / (float)numseq; |
|---|
| 69 | for (res=0; res<=max_aa; res++) |
|---|
| 70 | { |
|---|
| 71 | f = 0; |
|---|
| 72 | for (d=0; d<=max_aa; d++) |
|---|
| 73 | f += (weighting[d][pos] * matrix[d][res]); |
|---|
| 74 | f += (weighting[gap_pos1][pos] * matrix[gap_pos1][res]); |
|---|
| 75 | f += (weighting[gap_pos2][pos] * matrix[gap_pos2][res]); |
|---|
| 76 | profile[pos+1][res] = (sint )(((float)f / (float)sum2)*scale); |
|---|
| 77 | } |
|---|
| 78 | f = 0; |
|---|
| 79 | for (d=0; d<=max_aa; d++) |
|---|
| 80 | f += (weighting[d][pos] * matrix[d][gap_pos1]); |
|---|
| 81 | f += (weighting[gap_pos1][pos] * matrix[gap_pos1][gap_pos1]); |
|---|
| 82 | f += (weighting[gap_pos2][pos] * matrix[gap_pos2][gap_pos1]); |
|---|
| 83 | profile[pos+1][gap_pos1] = (sint )(((float)f / (float)sum2)*scale); |
|---|
| 84 | f = 0; |
|---|
| 85 | for (d=0; d<=max_aa; d++) |
|---|
| 86 | f += (weighting[d][pos] * matrix[d][gap_pos2]); |
|---|
| 87 | f += (weighting[gap_pos1][pos] * matrix[gap_pos1][gap_pos2]); |
|---|
| 88 | f += (weighting[gap_pos2][pos] * matrix[gap_pos2][gap_pos2]); |
|---|
| 89 | profile[pos+1][gap_pos2] = (sint )(((float)f / (float)sum2)*scale); |
|---|
| 90 | } |
|---|
| 91 | } |
|---|
| 92 | |
|---|
| 93 | for (i=0;i<NUMRES+2;i++) |
|---|
| 94 | weighting[i]=ckfree((void *)weighting[i]); |
|---|
| 95 | weighting=ckfree((void *)weighting); |
|---|
| 96 | |
|---|
| 97 | } |
|---|
| 98 | |
|---|
| 99 | |
|---|