JPRED-2 Add alscript to the Git repository
[jpred.git] / sources / alscript / src / mzcons.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <gjutil.h>
5
6 int GJindex(char *str,char c);
7
8 float mzcons(unsigned char *pos,int n)
9
10 /* calculate conservation value according to Zvelebil et al for a set
11    of amino acids and gaps stored in string pos of length n
12
13    Copyright:  Geoffrey J. Barton (1992,1997)
14
15    email: geoff@ebi.ac.uk
16    Please see the README file for details of conditions for use of this program.
17
18    $Id: mzcons.c,v 1.2 1998/09/17 16:55:07 geoff Exp $
19    $Log: mzcons.c,v $
20    Revision 1.2  1998/09/17 16:55:07  geoff
21    Check consistency with archive
22
23
24 */
25
26 {
27
28 /* --  conmat contains a table like that shown in the JMB paper
29        order of amino acids is GAP,ARNDCQEGHILKMFPSTWYBZX
30 */
31     static char *acids = " ARNDCQEGHILKMFPSTWYBZX";
32     static int conmat[24][10] = {
33         {1,1,1,1,1,1,1,1,1,1},
34         {1,0,0,0,0,1,1,0,0,0},
35         {0,1,0,1,1,0,0,0,0,0},
36         {0,0,0,1,0,1,0,0,0,0},
37         {0,0,1,1,1,1,0,0,0,0}, 
38         {1,0,0,0,0,1,0,0,0,0},
39         {0,0,0,1,0,0,0,0,0,0},
40         {0,0,1,1,1,0,0,0,0,0},
41         {1,0,0,0,0,1,1,0,0,0}, 
42         {1,1,0,1,1,0,0,0,1,0},
43         {1,0,0,0,0,0,0,1,0,0},
44         {1,0,0,0,0,0,0,1,0,0},
45         {1,1,0,1,1,0,0,0,0,0},
46         {1,0,0,0,0,0,0,0,0,0},
47         {1,0,0,0,0,0,0,0,1,0},
48         {0,0,0,0,0,1,0,0,0,1},
49         {0,0,0,1,0,1,1,0,0,0},
50         {1,0,0,1,0,1,0,0,0,0},
51         {1,0,0,1,0,0,0,0,1,0},
52         {1,0,0,1,0,0,0,0,1,0},
53         {1,0,0,0,0,1,0,1,0,0},
54         {0,0,0,1,0,0,0,0,0,0},
55         {0,0,0,1,0,0,0,0,0,0},
56         {1,1,1,1,1,1,1,1,1,1}
57     };
58
59     int concnt,it,i,j,k,l,tcnt,ibseq;
60     int nide, facid;
61
62     concnt = 0;
63     for(j=0;j<10;++j){
64         /*found: outer loop over properties
65         set IT to the value of the first amino acid*/
66         it = conmat[GJindex(acids,pos[0])][j];
67         /*loop over remaining acids, if a difference occurs then
68         set tcnt to 1*/
69         tcnt = 0;
70         for(k=1;k<n;++k){
71            if(it != conmat[GJindex(acids,pos[k])][j]){
72                 tcnt = 1;
73            }
74         }
75         /*add tcnt to concnt*/
76         concnt += tcnt;
77     }
78     /* check for total identity at this position*/
79     facid = pos[0];
80     nide = 0;
81     for(k=1;k<n;++k){
82         if(facid == pos[k]){
83              ++nide;
84         }
85     }
86
87     /*calculate the conservation*/
88     if(concnt == 10){
89       con = 0.0;
90     }else if(concnt == 0){
91         if(nide == n){
92             /*total identity*/
93             con = 1.0;
94         }else{
95             /*not identity, but same properties*/
96               con = 0.9;
97         }
98     }else{
99         con = 0.9 - 0.1 * concnt;
100     }
101     return con;
102 }
103
104
105 int GJindex(char *str,char c)
106 {
107     char *t;
108     t = strchr(str,c);
109     if(t == NULL) return NULL;
110     return (int) (t - str);
111 }
112
113
114
115
116
117
118
119
120
121
122