1 /* pam.c 19-June-86
2
3 copyright (c) 1987 William R. Pearson
4
5 read in the alphabet and pam matrix data
6
7 designed for universal matcher
8 */
9
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <string.h>
13 #include <ctype.h>
14
15 #define XTERNAL
16 #include "uascii.gbl"
17 #include "upam.gbl"
18
19 extern int bestoff, bestscale, bkfact, scfact, bktup, bestmax, histint;
20
initpam(mfname)21 initpam(mfname)
22 char *mfname;
23 {
24 char line[512], *lp;
25 int ggaptmp, gdeltmp;
26 int i, iaa, ipam;
27 FILE *fmat;
28
29 if (strcmp(mfname,"250")==0) {
30 pam = apam250;
31 strcpy(mfname,"PAM250");
32 bestscale = 200;
33 bestoff = 27;
34 bkfact = 5;
35 scfact = 4;
36 return 1;
37 }
38
39 if (strcmp(mfname,"BL50")==0) {
40 pam = abl50;
41 strcpy(mfname,"BLOSUM50");
42 return 1;
43 }
44
45 if (strcmp(mfname,"BL62")==0) {
46 pam = abl62;
47 strcpy(mfname,"BLOSUM62");
48 return 1;
49 }
50
51 if ((fmat=fopen(mfname,"r"))==NULL) {
52 printf(" cannot open scoring matrix file %s\n",mfname);
53 return 0;
54 }
55
56 l1: if (fgets(line,512,fmat)==NULL) {
57 printf(" pam - cannot read first line of SMATRIX file\n");
58 return(0);
59 }
60
61 if (line[0]==';') {
62 if (line[1]=='P') {
63 strcpy(sqnam,"aa"); strcpy(sqtype,"protein");}
64 else if (line[1]=='D') {
65 strcpy(sqnam,"nt"); strcpy(sqtype,"DNA");}
66 goto l1;
67 }
68
69 if (sscanf(line," %d %d %d %d %d %d %d",
70 &scfact,&bestoff,&bestscale,&bkfact,&bktup,&bestmax,&histint)!=7) {
71 printf(" bestcut parameters - bad format\n");
72 exit(1);
73 }
74
75 if (fgets(line,512,fmat)==NULL) {
76 printf(" pam - cannot read DELVAL line\n");
77 return 0;
78 }
79
80 else if (sscanf(line," %d %d",&gdeltmp,&ggaptmp)!=2) {
81 printf(" DELVAL parameters - bad format\n");
82 exit(1);
83 }
84
85 if (!gap_set) ggapval = ggaptmp;
86 if (!del_set) {
87 #ifndef GAP_OPEN
88 gdelval = gdeltmp;
89 #else
90 gdelval = gdeltmp-ggapval;
91 #endif
92 }
93
94 if (fgets(line,512,fmat)==NULL) {
95 printf(" pam - cannot read EOS line\n");
96 return 0;
97 }
98
99 /* clear out sascii */
100 for (i=0; i<=AAMASK; i++) sascii[i]= NA;
101
102 /* set end of line stop */
103 sascii[0]=sascii['\r']=sascii['\n']= EL;
104
105 /* set end of sequence stop */
106 for (i=0; line[i]; i++) if (line[i]>' ') sascii[line[i]]= ES;
107
108 if (fgets(line,512,fmat)==NULL) {
109 printf(" pam - cannot read aa line\n");
110 exit(1);
111 }
112
113 /* read the alphabet */
114 for (i=0,nsq=0; line[i]; i++) if (line[i]>' ')
115 sq[nsq++]=toupper(line[i]);
116
117 /* initialize sascii */
118 for (iaa=0; iaa<nsq; iaa++) {
119 sascii[sq[iaa]]=iaa;
120 if (sascii[aa[iaa]]<NA && sq[iaa]>='A' && sq[iaa]<='Z')
121 sascii[aa[iaa]-'A'+'a']=sascii[aa[iaa]];
122 }
123
124 /* read in hnt values */
125 for (iaa=0; iaa<nsq; iaa++)
126 if (fscanf(fmat,"%d",&hsq[iaa])!=1) {
127 printf(" error reading hsq values\n");
128 exit(1);
129 }
130
131 for (iaa=ipam=0; iaa<nsq; iaa++)
132 for (i=0; i<=iaa; i++)
133 if (fscanf(fmat,"%d",&pam[ipam++])!=1) {
134 printf(" error reading pam matrix\n");
135 exit(1);
136 }
137
138 fclose(fmat);
139 return 1;
140 }
141