1 | #include <stdio.h> |
---|
2 | #include <stdlib.h> |
---|
3 | #include <math.h> |
---|
4 | #include "clustalw.h" |
---|
5 | |
---|
6 | #define MAX(a,b) ((a)>(b)?(a):(b)) |
---|
7 | #define MIN(a,b) ((a)<(b)?(a):(b)) |
---|
8 | |
---|
9 | /* |
---|
10 | * Prototypes |
---|
11 | */ |
---|
12 | |
---|
13 | static sint count_gaps(sint s1, sint s2, sint l); |
---|
14 | |
---|
15 | /* |
---|
16 | * Global Variables |
---|
17 | */ |
---|
18 | |
---|
19 | extern float gap_open; |
---|
20 | extern sint nseqs; |
---|
21 | extern sint *seqlen_array; |
---|
22 | extern short blosum45mt[]; |
---|
23 | extern short def_aa_xref[]; |
---|
24 | extern sint debug; |
---|
25 | extern sint max_aa; |
---|
26 | extern char **seq_array; |
---|
27 | |
---|
28 | |
---|
29 | void aln_score(void) |
---|
30 | { |
---|
31 | static short *mat_xref, *matptr; |
---|
32 | static sint maxres; |
---|
33 | static sint s1,s2,c1,c2; |
---|
34 | static sint ngaps; |
---|
35 | static sint i,l1,l2; |
---|
36 | static lint score; |
---|
37 | static sint matrix[NUMRES][NUMRES]; |
---|
38 | |
---|
39 | /* calculate an overall score for the alignment by summing the |
---|
40 | scores for each pairwise alignment */ |
---|
41 | |
---|
42 | matptr = blosum45mt; |
---|
43 | mat_xref = def_aa_xref; |
---|
44 | maxres = get_matrix(matptr, mat_xref, matrix, TRUE, 100); |
---|
45 | if (maxres == 0) |
---|
46 | { |
---|
47 | fprintf(stdout,"Error: matrix blosum30 not found\n"); |
---|
48 | return; |
---|
49 | } |
---|
50 | |
---|
51 | score=0; |
---|
52 | for (s1=1;s1<=nseqs;s1++) |
---|
53 | { |
---|
54 | for (s2=1;s2<s1;s2++) |
---|
55 | { |
---|
56 | |
---|
57 | l1 = seqlen_array[s1]; |
---|
58 | l2 = seqlen_array[s2]; |
---|
59 | for (i=1;i<l1 && i<l2;i++) |
---|
60 | { |
---|
61 | c1 = seq_array[s1][i]; |
---|
62 | c2 = seq_array[s2][i]; |
---|
63 | if ((c1>=0) && (c1<=max_aa) && (c2>=0) && (c2<=max_aa)) |
---|
64 | score += matrix[c1][c2]; |
---|
65 | } |
---|
66 | |
---|
67 | ngaps = count_gaps(s1, s2, l1); |
---|
68 | |
---|
69 | score -= 100 * gap_open * ngaps; |
---|
70 | |
---|
71 | } |
---|
72 | } |
---|
73 | |
---|
74 | score /= 100; |
---|
75 | |
---|
76 | info("Alignment Score %d", (pint)score); |
---|
77 | |
---|
78 | } |
---|
79 | |
---|
80 | static sint count_gaps(sint s1, sint s2, sint l) |
---|
81 | { |
---|
82 | sint i, g; |
---|
83 | sint q, r, *Q, *R; |
---|
84 | |
---|
85 | |
---|
86 | Q = (sint *)ckalloc((l+2) * sizeof(sint)); |
---|
87 | R = (sint *)ckalloc((l+2) * sizeof(sint)); |
---|
88 | |
---|
89 | Q[0] = R[0] = g = 0; |
---|
90 | |
---|
91 | for (i=1;i<l;i++) |
---|
92 | { |
---|
93 | if (seq_array[s1][i] > max_aa) q = 1; |
---|
94 | else q = 0; |
---|
95 | if (seq_array[s2][i] > max_aa) r = 1; |
---|
96 | else r = 0; |
---|
97 | |
---|
98 | if (((Q[i-1] <= R[i-1]) && (q != 0) && (1-r != 0)) || |
---|
99 | ((Q[i-1] >= R[i-1]) && (1-q != 0) && (r != 0))) |
---|
100 | g += 1; |
---|
101 | if (q != 0) Q[i] = Q[i-1]+1; |
---|
102 | else Q[i] = 0; |
---|
103 | |
---|
104 | if (r != 0) R[i] = R[i-1]+1; |
---|
105 | else R[i] = 0; |
---|
106 | } |
---|
107 | |
---|
108 | Q=ckfree((void *)Q); |
---|
109 | R=ckfree((void *)R); |
---|
110 | |
---|
111 | return(g); |
---|
112 | } |
---|
113 | |
---|
114 | |
---|