x86 clustalo binary
[jabaws.git] / binaries / src / fasta34 / fasta-34.26.5.shar
1 #!/bin/sh
2 # This is a shell archive (produced by shar 3.49)
3 # To extract the files from this archive, save it to a file, remove
4 # everything above the "!/bin/sh" line above, and type "sh file_name".
5 #
6 # made 04/29/2007 13:53 UTC by wrp@wrpsun2.bioch.Virginia.EDU
7 # Source directory /home2.t2/users/wrp/fa_cvs/fasta-34.26.5
8 #
9 # existing files will NOT be overwritten unless -c is specified
10 #
11 # This shar contains:
12 # length  mode       name
13 # ------ ---------- ------------------------------------------
14 #   1018 -rw-r--r-- COPYRIGHT
15 #    373 -rw-r--r-- FASTA_LIST
16 #   4638 -rw-r--r-- FileDlog.c
17 #   1580 -rw-r--r-- Makefile
18 #    831 -rw-r--r-- Makefile.NetBSD
19 #    684 -rw-r--r-- Makefile.cray_pvp
20 #   8454 -rw-r--r-- Makefile.fcom
21 #   2135 -rw-r--r-- Makefile.freebsd
22 #   1484 -rw-r--r-- Makefile.hpux_it
23 #    740 -rw-r--r-- Makefile.ibm
24 #   1580 -rw-r--r-- Makefile.linux
25 #   1577 -rw-r--r-- Makefile.linux_mysql
26 #   1581 -rw-r--r-- Makefile.linux_pgsql
27 #   1548 -rw-r--r-- Makefile.linux_sql
28 #   1671 -rw-r--r-- Makefile.linux_sse2
29 #  13073 -rw-r--r-- Makefile.mpcom
30 #   1600 -rw-r--r-- Makefile.mpi4
31 #   1602 -rw-r--r-- Makefile.mpi4_bluegene
32 #   1509 -rw-r--r-- Makefile.mpi4_sql
33 #   8182 -rwxr-xr-x Makefile.nm_fcom
34 #  27480 -rwxr-xr-x Makefile.nm_pcom
35 #    905 -rwxr-xr-x Makefile.nmk_icl
36 #   2116 -rw-r--r-- Makefile.os_x
37 #   1917 -rw-r--r-- Makefile.os_x86
38 #   1922 -rw-r--r-- Makefile.pLinux
39 #   1946 -rw-r--r-- Makefile.pLinux_sql
40 #  24893 -rw-r--r-- Makefile.pcom
41 #  13214 -rw-r--r-- Makefile.pvcom
42 #   1344 -rw-r--r-- Makefile.pvm4
43 #   1264 -rw-r--r-- Makefile.pvm4_sql
44 #   1238 -rw-r--r-- Makefile.sgi
45 #   1150 -rw-r--r-- Makefile.sun
46 #   1264 -rw-r--r-- Makefile.sun_x86
47 #   9746 -rw-r--r-- Makefile.tc
48 #   1304 -rw-r--r-- Makefile34.common
49 #   1330 -rw-r--r-- Makefile34.common_sql
50 #    765 -rwxr-xr-x Makefile34.nmk_com
51 #   1311 -rw-r--r-- Makefile34m.common
52 #   1395 -rw-r--r-- Makefile34m.common_mysql
53 #   1407 -rw-r--r-- Makefile34m.common_pgsql
54 #   1406 -rw-r--r-- Makefile34m.common_sql
55 #    722 -rw-r--r-- README
56 #   2614 -rw-r--r-- README.versions
57 #   1332 -rw-r--r-- Readme.Mac
58 #    321 -rw-r--r-- a_mark.h
59 #    504 -rw-r--r-- aamap.h
60 #   3021 -rw-r--r-- ag_stats.c
61 #    758 -rw-r--r-- aln_structs.h
62 #  10311 -rw-r--r-- alt_parms.h
63 #   2319 -rw-r--r-- altlib.h
64 #  10085 -rw-r--r-- apam.c
65 #   1922 -rw-r--r-- blosum45.mat
66 #   1921 -rw-r--r-- blosum50.mat
67 #   1922 -rw-r--r-- blosum62.mat
68 #   1924 -rw-r--r-- blosum80.mat
69 #   2528 -rw-r--r-- bovgh.seq
70 #    986 -rw-r--r-- bovprl.seq
71 #  11467 -rw-r--r-- c_dispn.c
72 #   3492 -rw-r--r-- checkevent.c
73 #  55202 -rw-r--r-- comp_lib.c
74 #  21270 -rw-r--r-- compacc.c
75 #    536 -rw-r--r-- create_seq_demo.sql
76 #     81 -rw-r--r-- cvs_id
77 #   6955 -rw-r--r-- dec_pthr_subs.c
78 #   1116 -rw-r--r-- dec_pthr_subs.h
79 #   3530 -rw-r--r-- defs.h
80 #    976 -rw-r--r-- dna.mat
81 #  10740 -rw-r--r-- doinit.c
82 #   3226 -rw-r--r-- drop_func.h
83 #  48853 -rw-r--r-- dropff2.c
84 #  59078 -rw-r--r-- dropfs2.c
85 #  73324 -rw-r--r-- dropfx.c
86 #  77360 -rw-r--r-- dropfz2.c
87 #  55870 -rw-r--r-- dropgsw.c
88 #    677 -rw-r--r-- dropgsw.h
89 #  70110 -rw-r--r-- dropnfa.c
90 #   1882 -rw-r--r-- dropnfa.h
91 #  34172 -rw-r--r-- dropnsw.c
92 #   1286 -rw-r--r-- egmsmg.aa
93 #  13742 -rw-r--r-- faatran.c
94 #   1959 -rw-r--r-- fast_new
95 #    529 -rw-r--r-- fasta.defaults
96 #   1670 -rw-r--r-- fasta.options
97 #  49762 -rw-r--r-- fasta20.doc
98 #  10345 -rw-r--r-- fasta3.1
99 #    177 -rw-r--r-- fasta3.rsp
100 #  41617 -rw-r--r-- fasta3x.doc
101 #  39642 -rw-r--r-- fasta3x.me
102 #   9645 -rw-r--r-- fasta_func.doc
103 #   4824 -rw-r--r-- fastf3.1
104 #   2173 -rw-r--r-- fastlibs
105 #   4556 -rw-r--r-- fasts3.1
106 #    203 -rw-r--r-- fasts3.rsp
107 #   1036 -rw-r--r-- getenv.c
108 #   1174 -rw-r--r-- getopt.c
109 #   9431 -rw-r--r-- getseq.c
110 #    806 -rw-r--r-- grou_drome.pseg
111 #  18633 -rw-r--r-- gst.nlib
112 #   1405 -rw-r--r-- gst.seq
113 #    300 -rw-r--r-- gtm1_human.aa
114 #    291 -rw-r--r-- gtt1_drome.aa
115 #    247 -rw-r--r-- h10_human.aa
116 #    691 -rw-r--r-- h_altlib.h
117 #    225 -rw-r--r-- hahu.aa
118 #   1466 -rw-r--r-- hostacc.c
119 #   7118 -rw-r--r-- hsgstm1b.gcg
120 #   2788 -rw-r--r-- hsgstm1b.seq
121 #    674 -rw-r--r-- htime.c
122 #   1323 -rw-r--r-- humgstd.seq
123 #   2210 -rw-r--r-- idn_aa.mat
124 #  54882 -rw-r--r-- initfa.c
125 #  13727 -rw-r--r-- karlin.c
126 #   4128 -rw-r--r-- last_tat.c
127 #    271 -rw-r--r-- lcbo.aa
128 #   7638 -rw-r--r-- lib_sel.c
129 #   5150 -rw-r--r-- list_db.c
130 #  10617 -rw-r--r-- llgetaa.c
131 #     56 -rw-r--r-- m1r.aa
132 #     50 -rw-r--r-- m2.aa
133 #    312 -rwxr-xr-x make_osx_univ.sh
134 #    948 -rw-r--r-- map_db.1
135 #  10852 -rw-r--r-- map_db.c
136 #    212 -rw-r--r-- mchu.aa
137 #   2255 -rw-r--r-- md_10.mat
138 #   2256 -rw-r--r-- md_20.mat
139 #   2255 -rw-r--r-- md_40.mat
140 #    284 -rw-r--r-- mgstm1.aa
141 #    310 -rw-r--r-- mgstm1.aaa
142 #   1220 -rw-r--r-- mgstm1.e05
143 #   1122 -rw-r--r-- mgstm1.eeq
144 #   1116 -rw-r--r-- mgstm1.esq
145 #    406 -rw-r--r-- mgstm1.gcg
146 #    282 -rw-r--r-- mgstm1.lc
147 #    677 -rw-r--r-- mgstm1.nt
148 #    160 -rw-r--r-- mgstm1.nts
149 #    259 -rw-r--r-- mgstm1.raa
150 #   1167 -rw-r--r-- mgstm1.rev
151 #   1158 -rw-r--r-- mgstm1.seq
152 #   1286 -rw-r--r-- mgtt2_x.seq
153 #   3057 -rw-r--r-- mm_file.h
154 #  21318 -rw-r--r-- mmgetaa.c
155 #     43 -rw-r--r-- ms1.aa
156 #   1085 -rw-r--r-- msg.h
157 #  17780 -rw-r--r-- mshowalign.c
158 #  14393 -rw-r--r-- mshowbest.c
159 #   2361 -rw-r--r-- mu.lib
160 #    953 -rw-r--r-- musplfm.aa
161 #   1042 -rw-r--r-- mw.h
162 #   2047 -rw-r--r-- mwkw.aa
163 #    500 -rw-r--r-- mwrtc1.aa
164 #   1294 -rw-r--r-- myosin_bp.aa
165 #    340 -rw-r--r-- mysql_demo1.sql
166 #    381 -rw-r--r-- mysql_demo_pv.sql
167 #  16406 -rw-r--r-- mysql_lib.c
168 #     26 -rw-r--r-- n0.aa
169 #     47 -rw-r--r-- n1.aa
170 #    692 -rw-r--r-- n2.aa
171 #   1482 -rw-r--r-- n2_fs.lib
172 #    178 -rw-r--r-- n2s.aa
173 #    243 -rw-r--r-- n2t.aa
174 #    330 -rw-r--r-- n_fs.lib
175 #    882 -rw-r--r-- ncbl2_head.h
176 #  42930 -rw-r--r-- ncbl2_mlib.c
177 #   1034 -rw-r--r-- ncbl_head.h
178 #  12694 -rw-r--r-- ncbl_lib.c
179 #    217 -rw-r--r-- ngt.aa
180 #    111 -rw-r--r-- ngts.aa
181 #  36301 -rw-r--r-- nmgetlib.c
182 #   2452 -rwxr-xr-x nr_to_sql.pl
183 #    566 -rw-r--r-- nrand.c
184 #    533 -rw-r--r-- nrand48.c
185 #    532 -rw-r--r-- nrandom.c
186 #    385 -rw-r--r-- oohu.aa
187 #    401 -rw-r--r-- oohu.raa
188 #  55578 -rw-r--r-- p2_complib.c
189 #  37611 -rw-r--r-- p2_workcomp.c
190 #   1096 -rw-r--r-- p_mw.h
191 #   1922 -rw-r--r-- pam120.mat
192 #   1923 -rw-r--r-- pam250.mat
193 #   3002 -rw-r--r-- param.h
194 #  16978 -rw-r--r-- pgsql_lib.c
195 #    230 -rw-r--r-- pirpsd.sql
196 #  11147 -rw-r--r-- print_pssm.c
197 #    340 -rw-r--r-- prio_atepa.aa
198 #   2741 -rw-r--r-- prot_test.lib
199 #   2786 -rw-r--r-- prot_test.lseg
200 #   4969 -rw-r--r-- prss3.1
201 #    119 -rw-r--r-- prss3.rsp
202 #    317 -rw-r--r-- psql_demo.sql
203 #    366 -rw-r--r-- psql_demo1.sql
204 #    336 -rw-r--r-- psql_demo_pv.sql
205 #  26268 -rw-r--r-- pssm_asn_subs.c
206 #   1301 -rw-r--r-- pthr_subs.h
207 #   7689 -rw-r--r-- pthr_subs2.c
208 #   6657 -rw-r--r-- pvcomp.1
209 #    914 -rw-r--r-- qrhuld.aa
210 #    339 -rw-r--r-- randtest.c
211 #   1184 -rw-r--r-- re_getlib.c
212 #   1994 -rw-r--r-- readme.mpi_3.3
213 #   1404 -rw-r--r-- readme.pvm_3.2
214 #   7535 -rw-r--r-- readme.pvm_3.3
215 #   3539 -rw-r--r-- readme.pvm_3.4
216 #   1070 -rw-r--r-- readme.v30
217 #   1871 -rw-r--r-- readme.v30t6
218 #   5283 -rw-r--r-- readme.v30t7
219 #   4461 -rw-r--r-- readme.v31t0
220 #   3632 -rw-r--r-- readme.v31t1
221 #  15841 -rw-r--r-- readme.v32t0
222 #  50697 -rw-r--r-- readme.v33t0
223 #  66121 -rw-r--r-- readme.v34t0
224 #   2402 -rw-r--r-- readme.w32
225 #  16277 -rw-r--r-- res_stats.c
226 #    998 -rw-r--r-- rna.mat
227 #   1427 -rw-r--r-- sc_to_e.c
228 #  69722 -rw-r--r-- scaleswn.c
229 #  37581 -rw-r--r-- scaleswt.c
230 #   5247 -rw-r--r-- search.html
231 #   2033 -rw-r--r-- showrss.c
232 #  12412 -rw-r--r-- showsum.c
233 # 113815 -rw-r--r-- smith_waterman_altivec.c
234 #   1144 -rw-r--r-- smith_waterman_altivec.h
235 #  12106 -rw-r--r-- smith_waterman_sse2.c
236 #   1723 -rwxr-xr-x smith_waterman_sse2.h
237 #   4279 -rw-r--r-- structs.h
238 #  12998 -rw-r--r-- tatstats.c
239 #   4126 -rw-r--r-- tatstats.h
240 #   2891 -rw-r--r-- test.bat
241 #   2996 -rwxr-xr-x test.sh
242 #   2775 -rwxr-xr-x test2.bat
243 #   2429 -rwxr-xr-x test_osx.sh
244 #   1597 -rwxr-xr-x test_s.sh
245 #   1312 -rwxr-xr-x test_z.sh
246 #    203 -rw-r--r-- tfasts3.rsp
247 #   1144 -rw-r--r-- thr.h
248 #  27376 -rw-r--r-- titin_hum.aa
249 #  83286 -rw-r--r-- titin_hum.seq
250 #   2006 -rw-r--r-- uascii.h
251 #  16008 -rw-r--r-- upam.h
252 #   3335 -rw-r--r-- url_subs.c
253 #   1229 -rw-r--r-- uthr_subs.h
254 #   2771 -rw-r--r-- vtml160.mat
255 #   2899 -rw-r--r-- w_mw.h
256 #   7001 -rw-r--r-- work_thr.c
257 #   5262 -rw-r--r-- workacc.c
258 #    302 -rw-r--r-- xurt8c.aa
259 #    302 -rw-r--r-- xurt8c.lc
260 #    281 -rw-r--r-- xurtg.aa
261 #
262 # ============= COPYRIGHT ==============
263 if test -f 'COPYRIGHT' -a X"$1" != X"-c"; then
264         echo 'x - skipping COPYRIGHT (File already exists)'
265 else
266 echo 'x - extracting COPYRIGHT (Text)'
267 sed 's/^X//' << 'SHAR_EOF' > 'COPYRIGHT' &&
268 X
269 X     Copyright 1988, 1991, 1992, 1993, 1994 1995, by William
270 X     R. Pearson and the University of Virginia.  All rights
271 X     reserved. The FASTA program and documentation may not be sold or
272 X     incorporated into a commercial product, in whole or in part,
273 X     without written consent of William R. Pearson and the University
274 X     of Virginia.  For further information regarding permission for
275 X     use or reproduction, please contact:
276 X
277 X            David Hudson
278 X            Assistant Provost for Research
279 X            University of Virginia
280 X            P.O. Box 400301
281 X            Charlottesville, VA  22906-9025
282 X
283 X            (434) 924-3606
284 X
285 X     Code in the smith_waterman_sse2.c and smith_waterman_sse2.h files
286 X     is copyright (c) 2006 by Michael Farrar.
287 X
288 X     This program may not be sold or incorporated into a commercial
289 X     product, in whole or in part, without written consent of Michael
290 X     Farrar.  For further information regarding permission for use or
291 X     reproduction, please contact: Michael Farrar at
292 X     farrar.michael@gmail.com.
293 X
294 SHAR_EOF
295 chmod 0644 COPYRIGHT ||
296 echo 'restore of COPYRIGHT failed'
297 Wc_c="`wc -c < 'COPYRIGHT'`"
298 test 1018 -eq "$Wc_c" ||
299         echo 'COPYRIGHT: original size 1018, current size' "$Wc_c"
300 fi
301 # ============= FASTA_LIST ==============
302 if test -f 'FASTA_LIST' -a X"$1" != X"-c"; then
303         echo 'x - skipping FASTA_LIST (File already exists)'
304 else
305 echo 'x - extracting FASTA_LIST (Text)'
306 sed 's/^X//' << 'SHAR_EOF' > 'FASTA_LIST' &&
307 X
308 X
309 30 July 2003
310 X
311 If you regularly install the latest version of the fasta3 package from
312 ftp://ftp.virginia.edu/pub/fasta, you may want to join the fasta_list
313 majordomo mailing list.  I plan to use this list to announce new
314 releases and solicit bug reports.
315 X
316 To join the mailing list, go to the WWW page at:
317 X
318 X       list.mail.virginia.edu/mailman/listinfo/fasta_list
319 X
320 Bill Pearson
321 SHAR_EOF
322 chmod 0644 FASTA_LIST ||
323 echo 'restore of FASTA_LIST failed'
324 Wc_c="`wc -c < 'FASTA_LIST'`"
325 test 373 -eq "$Wc_c" ||
326         echo 'FASTA_LIST: original size 373, current size' "$Wc_c"
327 fi
328 # ============= FileDlog.c ==============
329 if test -f 'FileDlog.c' -a X"$1" != X"-c"; then
330         echo 'x - skipping FileDlog.c (File already exists)'
331 else
332 echo 'x - extracting FileDlog.c (Text)'
333 sed 's/^X//' << 'SHAR_EOF' > 'FileDlog.c' &&
334 X
335 /* copyright (c) 1997 William R. Pearson */
336 X
337 /* used only in Mac versions for file selection */
338 /* should use navigation services if available */
339 X
340 X
341 #include <Dialogs.h>
342 #include <Fonts.h>
343 #include <Types.h>
344 #include <Gestalt.h>
345 #include <Resources.h>
346 #include <Controls.h>
347 #include <StandardFile.h>
348 #include <Files.h>
349 #include <Folders.h>
350 X
351 #include <stdio.h>
352 #include <string.h>
353 #include <stdlib.h>
354 X
355 #define NIL nil
356 #define PauseID 301
357 #define ExitID  302
358 #define FileDID 204
359 #define SFileDID 205
360 X
361 void HiliteDlog(DialogPtr);
362 X
363 SFTypeList tlist={'TEXT',0L,0L,0L};
364 X
365 extern Point wpos;
366 X       
367 FileDlog(prompt,freply)
368 X       char *prompt;
369 X       StandardFileReply *freply;
370 {
371 X       Point dpos={-1,-1};
372 X       if (GetResource('DLOG',SFileDID)==NIL) {
373 X               fprintf(stderr," cannot load %d DLOG resource\n",SFileDID); exit(1);
374 X               }
375 X       CtoPstr(prompt);
376 X       ParamText((StringPtr)prompt,"\p","\p","\p");
377 /*      SFPGetFile(wpos, (StringPtr)prompt, 0L,(short)1, tlist, 0L, freply, FileDID, NIL); */
378 X       CustomGetFile(NIL,
379 X                               -1,
380 X                               nil,
381 X                               freply,
382 X                               SFileDID,
383 X                               dpos,
384 X                               nil,
385 X                               nil,nil,nil,nil);
386 X
387 X       ParamText("\p","\p","\p","\p");
388 X       PtoCstr((StringPtr)prompt);
389 X       }
390 X       
391 TFileDlog(prompt,freply,plist,nl)
392 X       char *prompt;
393 X       StandardFileReply *freply;
394 X       SFTypeList plist;
395 X       int nl;
396 {
397 X       Point dpos={-1,-1};
398 X       if (GetResource('DLOG',SFileDID)==NIL) {
399 X               fprintf(stderr," cannot load %d TFile DLOG resource\n",SFileDID); exit(1);
400 X               }
401 X       CtoPstr(prompt);
402 X       ParamText((StringPtr)prompt,"\p","\p","\p");
403 /*      SFPGetFile(wpos,(StringPtr)prompt,0L,(short)nl,plist,0L,freply,FileDID,NIL); */
404 X       CustomGetFile(NIL,
405 X                               nl,
406 X                               plist,
407 X                               freply,
408 X                               SFileDID,
409 X                               dpos,
410 X                               nil,
411 X                               nil,nil,nil,nil);
412 X       ParamText("\p","\p","\p","\p");
413 X       PtoCstr((StringPtr)prompt);
414 X       }
415 X
416 SFileDlog(prompt,freply)
417 X       char *prompt;
418 X       StandardFileReply *freply;
419 {
420 X       Point dpos={-1,-1};
421 X
422 X       if (GetResource('DLOG',SFileDID)==NIL) {
423 X               fprintf(stderr," cannot load %d DLOG resource\n",SFileDID); exit(1);
424 X               }
425 X
426 X       CtoPstr(prompt);
427 X       ParamText((StringPtr)prompt,"\p","\p","\p");
428 X
429 /*      StandardGetFile(NIL,(short)1,tlist,freply); */
430 X       CustomGetFile(NIL,
431 X                               -1,
432 X                               nil,
433 X                               freply,
434 X                               SFileDID,
435 X                               dpos,
436 X                               nil,
437 X                               nil,nil,nil,nil);
438 X       ParamText("\p","\p","\p","\p");
439 X       PtoCstr((StringPtr)prompt);
440 X       }
441 X       
442 STFileDlog(char *prompt, StandardFileReply *freply,
443 X          SFTypeList plist, int nl)
444 {
445 X  Point dpos={-1,-1};
446 X
447 X  if (GetResource('DLOG',SFileDID)==NIL) {
448 X    fprintf(stderr," cannot load %d TFile DLOG resource\n",SFileDID); exit(1);
449 X  }
450 X  CtoPstr(prompt);
451 X  ParamText((StringPtr)prompt,"\p","\p","\p");
452 X
453 X  CustomGetFile(NIL,
454 X               -1,
455 X               nil,
456 X               freply,
457 X               SFileDID,
458 X               dpos,
459 X               nil,
460 X               nil,nil,nil,nil);
461 X  ParamText("\p","\p","\p","\p");
462 X  PtoCstr((StringPtr)prompt);
463 }
464 X       
465 PauseAlert(unsigned char *prompt)
466 {
467 X  if (GetResource('DLOG',PauseID)==NIL) {
468 X    fprintf(stderr," cannot load %d TFile DLOG resource\n",PauseID); exit(1);
469 X  }
470 X  CtoPstr((char *)prompt);
471 X  ParamText(prompt,"\p","\p","\p");
472 X  CautionAlert(PauseID,NULL);
473 X  ParamText("\p","\p","\p","\p");
474 }
475 X
476 IntroDlog(int DlogID, unsigned char *prompt)
477 {
478 X  short itemHit;
479 X  DialogPtr DP;
480 X
481 X  CtoPstr((char *)prompt);
482 X  ParamText(prompt,"\p","\p","\p");
483 X
484 X  if (GetResource('DLOG',DlogID)==NIL) {
485 X    fprintf(stderr," cannot load %d Intro DLOG resource\n",DlogID); exit(1);
486 X  }
487 X  DP = GetNewDialog(DlogID,NULL,(WindowPtr)-1);
488 X  ShowWindow(DP);
489 X  SelectWindow(DP);
490 X  HiliteDlog(DP);
491 X       
492 X  ModalDialog(0L,&itemHit);
493 X  DisposeDialog(DP);
494 X  ParamText("\p","\p","\p","\p");
495 X  PtoCstr(prompt);
496 }
497 X
498 NIntroDlog(int DlogID,unsigned char *p0,unsigned char *p1,
499 X          unsigned char *p2,unsigned char *p3)
500 {
501 X  short itemHit;
502 X  DialogPtr DP;
503 X  unsigned char *p;
504 X
505 X  for (p=p0; *p; p++) if (*p=='\n') *p=' ';
506 X  for (p=p1; *p; p++) if (*p=='\n') *p=' ';
507 X  for (p=p2; *p; p++) if (*p=='\n') *p=' ';
508 X  for (p=p2; *p; p++) if (*p=='\n') *p=' ';
509 X
510 X  CtoPstr((char *)p0);
511 X  CtoPstr((char *)p1);
512 X  CtoPstr((char *)p2);
513 X  CtoPstr((char *)p3);
514 X  ParamText(p0,p1,p2,p3);
515 X
516 X  if (GetResource('DLOG',DlogID)==NIL) {
517 X    fprintf(stderr," cannot load %d Intro DLOG resource\n",DlogID); exit(1);
518 X  }
519 X  DP = GetNewDialog(DlogID,NULL,(WindowPtr)-1);
520 X  ShowWindow(DP);
521 X  SelectWindow(DP);
522 X  HiliteDlog(DP);
523 X       
524 X  ModalDialog(0L,&itemHit);
525 X  DisposeDialog(DP);
526 X  ParamText("\p","\p","\p","\p");
527 X  PtoCstr(p0);
528 X  PtoCstr(p1);
529 X  PtoCstr(p2);
530 X  PtoCstr(p3);
531 }
532 X
533 void
534 HiliteDlog(DialogPtr DP)
535 {
536 X  Rect tRect;
537 X  short  tType;
538 X  Handle tItem;
539 X
540 X  SetPort(DP);
541 X  GetDialogItem(DP,1,&tType,&tItem,&tRect);
542 X  PenSize(3, 3);               /* Change pen to draw thick default outline */
543 X  InsetRect(&tRect, -4, -4);           /* Draw outside the button by 1 pixel */
544 X  FrameRoundRect(&tRect, 16, 16); /* Draw the outline */
545 X  PenSize(1, 1);               /* Restore the pen size to the default value */
546 }
547 SHAR_EOF
548 chmod 0644 FileDlog.c ||
549 echo 'restore of FileDlog.c failed'
550 Wc_c="`wc -c < 'FileDlog.c'`"
551 test 4638 -eq "$Wc_c" ||
552         echo 'FileDlog.c: original size 4638, current size' "$Wc_c"
553 fi
554 # ============= Makefile ==============
555 if test -f 'Makefile' -a X"$1" != X"-c"; then
556         echo 'x - skipping Makefile (File already exists)'
557 else
558 echo 'x - extracting Makefile (Text)'
559 sed 's/^X//' << 'SHAR_EOF' > 'Makefile' &&
560 #
561 # makefile for fasta3, fasta3_t.  Use makefile.pvm for pvcompxx.
562 #
563 #
564 # Dec 8, 2005 - with gcc4.0.2 (or .1) under Redhat Linux Fedora FC4 -03 breaks the alignment code
565 #
566 X
567 CC= gcc -g -O2
568 X
569 #CC=gcc -Wall -pedantic -ansi -g -O
570 #CC = gcc -g -DDEBUG
571 #CC= /usr/local/parasoft/bin.linux2/insure -g -DDEBUG
572 X
573 # EBI uses the following with pgcc, -O3 does not work:
574 # CC= pgcc -O2 -pipe -mcpu=pentiumpro -march=pentiumpro -fomit-frame-pointer
575 X
576 # this file works for x86 LINUX
577 X
578 # use options below for superfamily validations
579 #CFLAGS= -DSHOWSIM -DUNIX -DTIMES -DHZ=100 -DSFCHAR="'|'" -c -DMAX_WORKERS=2 -DTHR_EXIT=pthread_exit -DPROGRESS -DSUPERFAMNUM -DUSE_MMAP -D_REENTRANT -DBIG_LIB64 -D_LARGE_FILE_SOURCE -DUSE_FSEEKO -D_FILE_OFFSET_BITS=64 -DHAS_INTTYPES -DSAMP_STATS
580 X
581 # standard options
582 CFLAGS= -DSHOWSIM -DUNIX -DTIMES -DHZ=100 -DSFCHAR="':'" -c -DMAX_WORKERS=2 -DTHR_EXIT=pthread_exit -DPROGRESS -DFASTA_HOST='"your_fasta_host_here"' -DUSE_MMAP -D_REENTRANT -DHAS_INTTYPES -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -DUSE_FSEEKO -DSAMP_STATS -DPGM_DOC
583 # -I/usr/local/include/mysql -DMYSQL_DB 
584 #
585 #(for mySQL databases)  (also requires change to Makefile34.common)
586 X
587 LIB_M = -lm
588 #LIB_M = -L/usr/local/lib/mysql -lmysqlclient -lm
589 # for mySQL databases
590 X
591 HFLAGS= -o
592 NFLAGS= -o
593 X
594 # for Linux
595 THR_SUBS = pthr_subs2
596 THR_LIBS = -lpthread
597 THR_CC =
598 X
599 XXDIR = /seqprg/bin
600 X
601 DROPNFA_O = drop_nfa.o
602 DROPGSW_O = dropgsw.o
603 DROPRSS_O = dropnsw.o
604 DROPTFA_O = drop_tfa.o
605 X
606 # renamed (fasta33)  programs
607 include Makefile34m.common
608 # conventional (fasta3) names
609 # include Makefile.common
610 X
611 SHAR_EOF
612 chmod 0644 Makefile ||
613 echo 'restore of Makefile failed'
614 Wc_c="`wc -c < 'Makefile'`"
615 test 1580 -eq "$Wc_c" ||
616         echo 'Makefile: original size 1580, current size' "$Wc_c"
617 fi
618 # ============= Makefile.NetBSD ==============
619 if test -f 'Makefile.NetBSD' -a X"$1" != X"-c"; then
620         echo 'x - skipping Makefile.NetBSD (File already exists)'
621 else
622 echo 'x - extracting Makefile.NetBSD (Text)'
623 sed 's/^X//' << 'SHAR_EOF' > 'Makefile.NetBSD' &&
624 #
625 # makefile for fasta3, fasta3_t.  Use makefile.pvm for pvcompxx.
626 # this file works for NetBSD
627 #
628 # provided by Marc Baudoin <babafou@babafou.eu.org>
629 #
630 X
631 CC= cc -O
632 #CC= cc -g -DDEBUG
633 #CC= gcc -g -Wall
634 #
635 # standard line for normal searching
636 CFLAGS= -DM10_CONS -DUNIX -DTIMES -DHZ=60 -DMAX_WORKERS=4 -DTHR_EXIT=pthread_exit -DPROGRESS -DFASTA_HOST='"your.host.here/fasta/cgi"' -DUSE_MMAP
637 X
638 # special options for SUPERFAMLIES
639 #CFLAGS= -DM10_CONS -DUNIX -DTIMES -DHZ=60 -DSFCHAR="'|'" -c -DMAX_WORKERS=4 -DTHR_EXIT=pthread_exit -DPROGRESS -DSUPERFAMNUM -DUSE_MMAP
640 X
641 LIB_M= -lm
642 HFLAGS= -o
643 NFLAGS= -o
644 X
645 # for NetBSD
646 THR_SUBS = pthr_subs2
647 THR_LIBS = -L/usr/pkg/pthreads/lib -lpthread
648 THR_CC = -I/usr/pkg/pthreads/include
649 X
650 XXDIR = /seqprg/slib/bin
651 X
652 DROPNFA_O = drop_nfa.o
653 DROPGSW_O = dropgsw.o
654 DROPRSS_O = dropnsw.o
655 X
656 include Makefile34m.common
657 SHAR_EOF
658 chmod 0644 Makefile.NetBSD ||
659 echo 'restore of Makefile.NetBSD failed'
660 Wc_c="`wc -c < 'Makefile.NetBSD'`"
661 test 831 -eq "$Wc_c" ||
662         echo 'Makefile.NetBSD: original size 831, current size' "$Wc_c"
663 fi
664 # ============= Makefile.cray_pvp ==============
665 if test -f 'Makefile.cray_pvp' -a X"$1" != X"-c"; then
666         echo 'x - skipping Makefile.cray_pvp (File already exists)'
667 else
668 echo 'x - extracting Makefile.cray_pvp (Text)'
669 sed 's/^X//' << 'SHAR_EOF' > 'Makefile.cray_pvp' &&
670 #
671 # makefile for fasta33
672 #
673 # for more information on FASTA on CRAY's, see:
674 #
675 #       http://home.cray.com/~cpsosa/ChemApps/BioInf/fasta/fasta.html
676 #       provided by: Carlos P. Sosa, cpsosa@cray.com
677 #
678 X
679 CC= cc -h inline1,scalar3,task0,vector2
680 X
681 HFLAGS= -o
682 NFLAGS= -o
683 X
684 LIB_M=
685 #
686 X
687 CFLAGS= -DUNIX -DTIMES -DSFCHAR="':'" -DMAX_WORKERS=4
688 -DTHR_EXIT=pthread_exit -DPROGRESS
689 -DFASTA_HOST='"crick.med.virginia.edu/fasta/cgi"' -DIS_BIG_ENDIAN
690 X
691 THR_SUBS = pthr_subs
692 THR_LIBS = -lpthread
693 THR_CC =
694 X
695 XXDIR = /seqprg/slib/bin
696 X
697 DROPNFA_O = drop_nfa.o
698 DROPGSW_O = dropgsw.o
699 DROPRSS_O = dropnsw.o
700 X
701 # renamed (fasta33)  programs
702 include Makefile33.nommap
703 # conventional (fasta3) names
704 # include Makefile.common
705 SHAR_EOF
706 chmod 0644 Makefile.cray_pvp ||
707 echo 'restore of Makefile.cray_pvp failed'
708 Wc_c="`wc -c < 'Makefile.cray_pvp'`"
709 test 684 -eq "$Wc_c" ||
710         echo 'Makefile.cray_pvp: original size 684, current size' "$Wc_c"
711 fi
712 # ============= Makefile.fcom ==============
713 if test -f 'Makefile.fcom' -a X"$1" != X"-c"; then
714         echo 'x - skipping Makefile.fcom (File already exists)'
715 else
716 echo 'x - extracting Makefile.fcom (Text)'
717 sed 's/^X//' << 'SHAR_EOF' > 'Makefile.fcom' &&
718 X
719 #================ common .o files 
720 X
721 doinit.o : doinit.c defs.h param.h upam.h structs.h uascii.h
722 X       $(CC) $(THR_CC) $(CFLAGS) -c doinit.c
723 X
724 init_sw.o : initfa.c defs.h param.h upam.h structs.h
725 X       $(CC) $(THR_CC) $(CFLAGS) -c -DSSEARCH initfa.c -o init_sw.o
726 X
727 init_ssw.o : initfa.c defs.h param.h upam.h structs.h
728 X       $(CC) $(THR_CC) $(CFLAGS) -c -DOSEARCH initfa.c -o init_ssw.o
729 X
730 init_rss.o : initfa.c defs.h param.h upam.h structs.h
731 X       $(CC) $(THR_CC) $(CFLAGS) -c -DPRSS initfa.c -o init_rss.o
732 X
733 init_rfx.o : initfa.c defs.h param.h upam.h structs.h
734 X       $(CC) $(THR_CC) $(CFLAGS) -c -DPRSS -DFASTX initfa.c -o init_rfx.o
735 X
736 init_fa.o : initfa.c defs.h param.h upam.h structs.h
737 X       $(CC) $(THR_CC) $(CFLAGS) -c -DFASTA initfa.c -o init_fa.o
738 X
739 init_ff.o : initfa.c defs.h param.h upam.h structs.h
740 X       $(CC) $(THR_CC) $(CFLAGS) -c -DFASTF initfa.c -o init_ff.o
741 X
742 init_tf.o : initfa.c defs.h param.h upam.h structs.h
743 X       $(CC) $(THR_CC) $(CFLAGS) -c -DFASTF -DTFAST initfa.c -o init_tf.o
744 X
745 init_fs.o : initfa.c defs.h param.h upam.h structs.h
746 X       $(CC) $(THR_CC) $(CFLAGS) -c -DFASTS initfa.c -o init_fs.o
747 X
748 init_fm.o : initfa.c defs.h param.h upam.h structs.h
749 X       $(CC) $(THR_CC) $(CFLAGS) -c -DFASTM initfa.c -o init_fm.o
750 X
751 init_tfs.o : initfa.c defs.h param.h upam.h structs.h
752 X       $(CC) $(THR_CC) $(CFLAGS) -c -DFASTS -DTFAST  initfa.c -o init_tfs.o
753 X
754 init_tfm.o : initfa.c defs.h param.h upam.h structs.h
755 X       $(CC) $(THR_CC) $(CFLAGS) -c -DFASTM -DTFAST  initfa.c -o init_tfm.o
756 X
757 init_tfa.o : initfa.c defs.h param.h upam.h structs.h
758 X       $(CC) $(THR_CC) $(CFLAGS) -c -DFASTA -DTFAST initfa.c -o init_tfa.o
759 X
760 init_fx.o : initfa.c defs.h param.h upam.h structs.h
761 X       $(CC) $(THR_CC) $(CFLAGS) -c -DFASTX initfa.c -o init_fx.o
762 X
763 init_tfx.o : initfa.c defs.h param.h upam.h structs.h
764 X       $(CC) $(THR_CC) $(CFLAGS) -c -DFASTX -DTFAST initfa.c -o init_tfx.o
765 X
766 init_fy.o : initfa.c defs.h param.h upam.h structs.h
767 X       $(CC) $(THR_CC) $(CFLAGS) -c -DFASTY initfa.c -o init_fy.o
768 X
769 init_tfy.o : initfa.c defs.h param.h upam.h structs.h
770 X       $(CC) $(THR_CC) $(CFLAGS) -c -DFASTY -DTFAST initfa.c -o init_tfy.o
771 X
772 #================ miscellaneous
773 X
774 htime.o : htime.c
775 X       $(CC) $(THR_CC) $(CFLAGS) -c htime.c
776 X
777 compacc.o : compacc.c upam.h uascii.h param.h structs.h $(MWH) defs.h
778 X       $(CC) $(THR_CC) $(CFLAGS) -c compacc.c
779 X
780 pssm_asn_subs.o : pssm_asn_subs.c defs.h
781 X       $(CC) $(THR_CC) $(CFLAGS) -c pssm_asn_subs.c
782 X
783 #================ display list of best hits / alignments
784 X
785 showbest.o : $(SHOWBESTC) $(MWH) defs.h param.h structs.h  aln_structs.h drop_func.h
786 X       $(CC) $(THR_CC) $(CFLAGS) -c $(SHOWBESTC) -o showbest.o
787 X
788 showrss.o : showrss.c $(MWH) defs.h param.h structs.h  aln_structs.h drop_func.h
789 X       $(CC) $(THR_CC) $(CFLAGS) -c showrss.c
790 X
791 showun.o : mshowbest.c $(MWH) defs.h aln_structs.h drop_func.h
792 X       $(CC) $(THR_CC) $(CFLAGS) -c -DSHOWUN mshowbest.c -o showun.o
793 X
794 showrel.o : $(SHOWBESTC) $(MWH) defs.h aln_structs.h drop_func.h
795 X       $(CC) $(THR_CC) $(CFLAGS) -c -DSHOWREL $(SHOWBESTC) -o showrel.o
796 X
797 showsum.o : showsum.c $(MWH) defs.h drop_func.h
798 X       $(CC) $(THR_CC) $(CFLAGS) -c showsum.c
799 X
800 $(SHOWALIGN).o : $(SHOWALIGN).c $(MWHP) defs.h structs.h param.h aln_structs.h drop_func.h
801 X       $(CC) $(THR_CC) $(CFLAGS) -c $(SHOWALIGN).c -o $(SHOWALIGN).o
802 X
803 $(SHOWALIGN)_u.o : $(SHOWALIGN).c $(MWHP) defs.h structs.h param.h aln_structs.h drop_func.h
804 X       $(CC) $(THR_CC) $(CFLAGS) -DSHOWUN -c -o $(SHOWALIGN)_u.o $(SHOWALIGN).c
805 re_getlib.o : re_getlib.c mw.h mm_file.h
806 X       $(CC) $(THR_CC) $(CFLAGS) -c re_getlib.c
807 X
808 lib_sel.o : lib_sel.c defs.h structs.h
809 X       $(CC) $(THR_CC) $(CFLAGS) -c lib_sel.c
810 X
811 c_dispn.o : c_dispn.c defs.h structs.h param.h 
812 X       $(CC) $(THR_CC) $(CFLAGS) -c c_dispn.c
813 X
814 #================ statistical functions
815 X
816 karlin.o : karlin.c param.h
817 X       $(CC) $(THR_CC) $(CFLAGS) -c karlin.c
818 X
819 scaleswn.o : scaleswn.c defs.h param.h structs.h $(MWH) alt_parms.h
820 X       $(CC) $(THR_CC) $(CFLAGS) -c scaleswn.c
821 X
822 scaleswtf.o : scaleswt.c defs.h param.h structs.h $(MWH) alt_parms.h
823 X       $(CC) $(THR_CC) $(CFLAGS) -DFASTF -c scaleswt.c -o scaleswtf.o
824 X
825 scaleswts.o : scaleswt.c defs.h param.h structs.h $(MWH) alt_parms.h
826 X       $(CC) $(THR_CC) $(CFLAGS) -c scaleswt.c -o scaleswts.o
827 X
828 tatstats_fs.o : tatstats.c tatstats.h
829 X       $(CC) $(THR_CC) $(CFLAGS) -c -DFASTS tatstats.c -o tatstats_fs.o
830 X
831 tatstats_ff.o : tatstats.c tatstats.h
832 X       $(CC) $(THR_CC) $(CFLAGS) -c -DFASTF tatstats.c -o tatstats_ff.o
833 X
834 tatstats_fm.o : tatstats.c tatstats.h
835 X       $(CC) $(THR_CC) $(CFLAGS) -c -DFASTM tatstats.c -o tatstats_fm.o
836 X
837 last_tat.o : last_tat.c defs.h mm_file.h structs.h param.h
838 X       $(CC) $(THR_CC) $(CFLAGS) -c last_tat.c
839 X
840 #================ drop functions - actual scores/alignments
841 X
842 drop_nfa.o : dropnfa.c dropnfa.h param.h defs.h drop_func.h
843 X       $(CC) $(THR_CC) $(CFLAGS) -c dropnfa.c -o drop_nfa.o
844 X
845 # drop_ff, _fs, _fm must define FASTF, FASTS, and FASTM to ensure
846 # that tatstats.h is built appropriately
847 X
848 drop_ff.o : dropff2.c param.h defs.h tatstats.h drop_func.h
849 X       $(CC) $(THR_CC) $(CFLAGS) -DFASTF -c dropff2.c -o drop_ff.o
850 X
851 drop_tff.o : dropff2.c param.h defs.h tatstats.h drop_func.h
852 X       $(CC) $(THR_CC) $(CFLAGS) -DFASTF -DTFAST -c dropff2.c -o drop_tff.o
853 X
854 drop_ff2.o : dropff2.c param.h defs.h tatstats.h drop_func.h
855 X       $(CC) $(THR_CC) $(CFLAGS) -c -DFASTF  dropff2.c -o drop_ff2.o
856 X
857 drop_tff2.o : dropff2.c param.h defs.h tatstats.h drop_func.h
858 X       $(CC) $(THR_CC) $(CFLAGS) -c -DFASTF -DTFAST dropff2.c -o drop_tff.o
859 X
860 drop_fs.o : dropfs2.c param.h defs.h tatstats.h drop_func.h
861 X       $(CC) $(THR_CC) $(CFLAGS) -DFASTS -c dropfs2.c -o drop_fs.o
862 X
863 drop_tfs.o : dropfs2.c param.h defs.h drop_func.h
864 X       $(CC) $(THR_CC) $(CFLAGS) -c -DTFAST -DFASTS dropfs2.c -o drop_tfs.o
865 X
866 drop_fm.o : dropfs2.c param.h defs.h drop_func.h
867 X       $(CC) $(THR_CC) $(CFLAGS) -c -DFASTM dropfs2.c -o drop_fm.o
868 X
869 drop_tfm.o : dropfs2.c param.h defs.h drop_func.h
870 X       $(CC) $(THR_CC) $(CFLAGS) -c -DTFAST -DFASTM dropfs2.c -o drop_tfm.o
871 X
872 drop_tfa.o : dropnfa.c dropnfa.h upam.h param.h defs.h
873 X       $(CC) $(THR_CC) $(CFLAGS) -c -DTFASTA dropnfa.c -o drop_tfa.o
874 X
875 drop_fx.o : dropfx.c upam.h param.h defs.h drop_func.h
876 X       $(CC) $(THR_CC) $(CFLAGS) -c dropfx.c -o drop_fx.o
877 X
878 drop_tfx.o : dropfx.c upam.h param.h defs.h drop_func.h
879 X       $(CC) $(THR_CC) $(CFLAGS) -c -DTFAST dropfx.c -o drop_tfx.o
880 X
881 drop_fz.o : dropfz2.c upam.h param.h defs.h aamap.h drop_func.h
882 X       $(CC) $(THR_CC) $(CFLAGS) -c dropfz2.c -o drop_fz.o
883 X
884 drop_tfz.o : dropfz2.c upam.h param.h defs.h aamap.h drop_func.h
885 X       $(CC) $(THR_CC) $(CFLAGS) -c -DTFAST dropfz2.c -o drop_tfz.o
886 X
887 dropnsw.o : dropnsw.c upam.h param.h structs.h drop_func.h
888 X       $(CC) $(THR_CC) $(CFLAGS) -c dropnsw.c
889 X
890 dropgsw.o : dropgsw.c dropgsw.h upam.h param.h structs.h drop_func.h
891 X       $(CC) $(THR_CC) $(CFLAGS) -c dropgsw.c
892 X
893 smith_waterman_altivec.o : smith_waterman_altivec.c smith_waterman_altivec.h dropgsw.h defs.h param.h
894 X       $(CC) $(THR_CC) $(CFLAGS) -c smith_waterman_altivec.c
895 X
896 smith_waterman_sse2.o : smith_waterman_sse2.c smith_waterman_sse2.h dropgsw.h defs.h param.h
897 X       $(CC) $(THR_CC) $(CFLAGS) -c smith_waterman_sse2.c
898 X
899 dropnw.o : dropnw.c upam.h param.h structs.h drop_func.h
900 X       $(CC) $(THR_CC) $(CFLAGS) -c dropnw.c
901 X
902 #================ reading query, libraries
903 X
904 getseq.o : getseq.c defs.h uascii.h structs.h upam.h mm_file.h
905 X       $(CC) $(THR_CC) $(CFLAGS) -c getseq.c
906 X
907 llgetaa.o : llgetaa.c upam.h uascii.h mm_file.h
908 X       $(CC) $(THR_CC) $(CFLAGS) -c -DNOLIB llgetaa.c
909 X
910 lgetlib.o : $(NGETLIB).c altlib.h upam.h uascii.h mm_file.h
911 X       $(CC) $(THR_CC) $(CFLAGS) -c $(NGETLIB).c -o lgetlib.o
912 X
913 lgetaa_m.o : mmgetaa.c altlib.h ncbl2_head.h upam.h uascii.h mm_file.h
914 X       $(CC) $(THR_CC) $(CFLAGS) -c mmgetaa.c -o lgetaa_m.o
915 X
916 ncbl_lib.o : ncbl_lib.c ncbl_head.h
917 X       $(CC) $(THR_CC) $(CFLAGS) -c ncbl_lib.c
918 X
919 ncbl2_mlib.o : ncbl2_mlib.c ncbl2_head.h mm_file.h
920 X       $(CC) $(THR_CC) $(CFLAGS) -c ncbl2_mlib.c
921 X
922 mysql_lib.o : mysql_lib.c mm_file.h
923 X       $(CC) $(THR_CC) $(CFLAGS) -c mysql_lib.c
924 X
925 pgsql_lib.o : pgsql_lib.c mm_file.h
926 X       $(CC) $(THR_CC) $(CFLAGS) -c pgsql_lib.c
927 X
928 #================ threading functions
929 X
930 pthr_subs2.o : pthr_subs2.c thr.h pthr_subs.h
931 X       $(CC) $(THR_CC) $(CFLAGS) -c pthr_subs2.c
932 X
933 uthr_subs.o : uthr_subs.c thr.h uthr_subs.h 
934 X       $(CC) $(THR_CC) $(CFLAGS) -c uthr_subs.c
935 X
936 #================ translation
937 X
938 faatran.o : faatran.c upam.h uascii.h
939 X       $(CC) $(THR_CC) $(CFLAGS) -c faatran.c
940 X
941 url_subs.o : url_subs.c structs.h param.h
942 X       $(CC) $(THR_CC) $(CFLAGS) -c url_subs.c
943 X
944 $(NRAND).o : $(NRAND).c
945 X       $(CC) $(THR_CC) $(CFLAGS) -c $(NRAND).c
946 #================ pvm/mpi specific functions
947 X
948 hostacc.o : hostacc.c upam.h uascii.h
949 X       $(CC) $(THR_CC) $(CFLAGS) hostacc.c
950 X
951 workacc.o : workacc.c upam.h uascii.h param.h
952 X       $(NCC) $(THR_CC) $(CFLAGS) workacc.c -o workacc.o
953 SHAR_EOF
954 chmod 0644 Makefile.fcom ||
955 echo 'restore of Makefile.fcom failed'
956 Wc_c="`wc -c < 'Makefile.fcom'`"
957 test 8454 -eq "$Wc_c" ||
958         echo 'Makefile.fcom: original size 8454, current size' "$Wc_c"
959 fi
960 # ============= Makefile.freebsd ==============
961 if test -f 'Makefile.freebsd' -a X"$1" != X"-c"; then
962         echo 'x - skipping Makefile.freebsd (File already exists)'
963 else
964 echo 'x - extracting Makefile.freebsd (Text)'
965 sed 's/^X//' << 'SHAR_EOF' > 'Makefile.freebsd' &&
966 #
967 # Makefile for building fasta3 on FreeBSD
968 #
969 # Fernan Aguero - <fernan@iib.unsam.edu.ar>
970 X
971 # we take care of doing variable assignment using the '?=' and '+='
972 # operators to preserve the value of variables if they are already
973 # defined. In FreeBSD this happens when fasta3 is build from the port or
974 # when the user has set these variables -- most notably CC and/or CFLAGS
975 # -- in /etc/make.conf
976 X
977 # Compiler executable, and optional flags
978 CC?=            gcc
979 CFLAGS?=        -g -O2
980 X
981 # your FASTA host
982 FASTA_HOST?=    "your_fasta_host"
983 X
984 # common CFLAGS. These are the set of CFLAGS that are always used
985 COMMON_CFLAGS=  -DSHOWSIM -DUNIX -DTIMES -DHZ=100 -c -DMAX_WORKERS=2 \
986 X               -DTHR_EXIT=pthread_exit -DPROGRESS -DUSE_MMAP -D_REENTRANT \
987 X               -D_LARGE_FILE_SOURCE -D_FILE_OFFSET_BITS=64 -DUSE_FSEEKO \
988 X               -DHAS_INTTYPES -DSAMP_STATS
989 X
990 # standard options, these will be added to the common CFLAGS if
991 # selected below
992 STANDARD_CFLAGS=        -DSFCHAR="':'" -DFASTA_HOST='${FASTA_HOST}' \
993 X                       -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -DPGM_DOC
994 X
995 # options for superfamily validations, these will be added to the common
996 # CFLAGS if selected below
997 SUPERFAMILY_CFLAGS=     -DSFCHAR="'|'" -DSUPERFAMNUM -DBIG_LIB64
998 X
999 # here we define CFLAGS to be the sum of common flags plus a subset of
1000 # optional flags that define our intended use.
1001 # The default standard flags are selected by default, although the user
1002 # can override this if s/he wants
1003 CFLAGS+=        ${COMMON_CFLAGS} ${STANDARD_CFLAGS}
1004 X
1005 XXDIR?=         /usr/local/bin
1006 X
1007 LIB_M+=         -lm
1008 X
1009 HFLAGS+=        -o
1010 NFLAGS+=        -o
1011 X
1012 # FreeBSD users BEWARE! Different threading models ahead!
1013 X
1014 # The threading model has changed along the way from FreeBSD-4 to
1015 # FreeBSD-6. If you're building fasta3 on your own, you will need to
1016 # adjust this accordingly. The default works in FreeBSD-6x (currently
1017 # the recommended major version for use in production). Or better yet,
1018 # use the biology/fasta3 port from the ports collection, which will use
1019 # the correct threading library for your OSVERSION
1020 X
1021 THR_SUBS?=      pthr_subs2
1022 THR_LIBS?=      -lpthread
1023 THR_CC?=        
1024 X
1025 DROPNFA_O = drop_nfa.o
1026 DROPGSW_O = dropgsw.o
1027 DROPRSS_O = dropnsw.o
1028 DROPTFA_O = drop_tfa.o
1029 X
1030 include Makefile34m.common
1031 SHAR_EOF
1032 chmod 0644 Makefile.freebsd ||
1033 echo 'restore of Makefile.freebsd failed'
1034 Wc_c="`wc -c < 'Makefile.freebsd'`"
1035 test 2135 -eq "$Wc_c" ||
1036         echo 'Makefile.freebsd: original size 2135, current size' "$Wc_c"
1037 fi
1038 # ============= Makefile.hpux_it ==============
1039 if test -f 'Makefile.hpux_it' -a X"$1" != X"-c"; then
1040         echo 'x - skipping Makefile.hpux_it (File already exists)'
1041 else
1042 echo 'x - extracting Makefile.hpux_it (Text)'
1043 sed 's/^X//' << 'SHAR_EOF' > 'Makefile.hpux_it' &&
1044 #
1045 # makefile for fasta3, fasta3_t
1046 #
1047 # flags for HP-UX #
1048 X
1049 CC= cc -g -O2 +Onolimit -Wl,+pi,1M -Wl,+pd,1M -Wl,+mergeseg
1050 #CC = gcc -g -DDEBUG
1051 X
1052 #CC=gcc -Wall -pedantic -ansi -g -O
1053 #CC= /usr/local/parasoft/bin.linux2/insure -g -DDEBUG
1054 X
1055 # EBI uses the following with pgcc, -O3 does not work:
1056 # CC= pgcc -O2 -pipe -mcpu=pentiumpro -march=pentiumpro -fomit-frame-pointer
1057 X
1058 # this file works for x86 LINUX
1059 X
1060 # use options below for superfamily validations
1061 #CFLAGS= -DSHOWSIM -DUNIX -DTIMES -DHZ=100 -DSFCHAR="'|'" -c -DMAX_WORKERS=2 -DTHR_EXIT=pthread_exit -DPROGRESS -DSUPERFAMNUM -DUSE_MMAP -DBIG_LIB64 -D_LARGE_FILE_SOURCE -DUSE_FSEEKO -D_FILE_OFFSET_BITS=64 -DHAS_INTTYPES -DSAMP_STATS
1062 X
1063 # standard options
1064 CFLAGS= -DSHOWSIM -DUNIX -DTIMES -DHZ=100 -DSFCHAR="':'" -c -DMAX_WORKERS=2 -DTHR_EXIT=pthread_exit -DPROGRESS -DFASTA_HOST='"your_fasta_host_here"' -DUSE_MMAP -DHAS_INTTYPES -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -DUSE_FSEEKO -DSAMP_STATS -DPGM_DOC
1065 # -I/usr/local/include/mysql -DMYSQL_DB 
1066 #
1067 #(for mySQL databases)  (also requires change to Makefile34.common)
1068 X
1069 LIB_M = -lm
1070 #LIB_M = -L/usr/local/lib/mysql -lmysqlclient -lm
1071 # for mySQL databases
1072 X
1073 HFLAGS= -o
1074 NFLAGS= -o
1075 X
1076 # for Linux
1077 THR_SUBS = pthr_subs2
1078 THR_LIBS = -lpthread
1079 THR_CC =
1080 X
1081 XXDIR = /seqprg/bin
1082 X
1083 DROPNFA_O = drop_nfa.o
1084 DROPGSW_O = dropgsw.o
1085 DROPRSS_O = dropnsw.o
1086 DROPTFA_O = drop_tfa.o
1087 X
1088 # renamed (fasta33)  programs
1089 include Makefile34m.common
1090 # conventional (fasta3) names
1091 # include Makefile.common
1092 X
1093 SHAR_EOF
1094 chmod 0644 Makefile.hpux_it ||
1095 echo 'restore of Makefile.hpux_it failed'
1096 Wc_c="`wc -c < 'Makefile.hpux_it'`"
1097 test 1484 -eq "$Wc_c" ||
1098         echo 'Makefile.hpux_it: original size 1484, current size' "$Wc_c"
1099 fi
1100 # ============= Makefile.ibm ==============
1101 if test -f 'Makefile.ibm' -a X"$1" != X"-c"; then
1102         echo 'x - skipping Makefile.ibm (File already exists)'
1103 else
1104 echo 'x - extracting Makefile.ibm (Text)'
1105 sed 's/^X//' << 'SHAR_EOF' > 'Makefile.ibm' &&
1106 #
1107 # makefile for fasta3, fasta3_t.  Use makefile.pvm for pvcompxx.
1108 #
1109 X
1110 CC= xlc_r -O3 -qarch=auto -qtune=auto -qcache=auto
1111 X
1112 # for IBM with current pthreads
1113 CFLAGS= -DUNIX -DTIMES -DSFCHAR="':'" -DMAX_WORKERS=4 -DTHR_EXIT=pthread_exit -DPROGRESS -DIS_BIG_ENDIAN -DUSE_MMAP -DIBM_AIX -D_LARGE_FILES -DHAS_INTTYPES -D_LARGE_FILES -UMAXSEG -DSAMP_STATS -DPGM_DOC
1114 X
1115 # consider -D_LARGE_FILE_API -D_LARGE_FILES for files > 2 GB
1116 X
1117 LIB_M = -lm
1118 X
1119 HFLAGS= -o
1120 NFLAGS= -o
1121 X
1122 THR_SUBS = pthr_subs2
1123 THR_LIBS = -lpthreads
1124 THR_CC =
1125 X
1126 XXDIR = /seqprg/slib/bin
1127 X
1128 DROPNFA_O = drop_nfa.o
1129 DROPGSW_O = dropgsw.o
1130 DROPRSS_O = dropnsw.o
1131 DROPTFA_O = drop_tfa.o
1132 X
1133 # renamed (fasta34)  programs
1134 include Makefile34m.common
1135 # conventional (fasta3) names
1136 # include Makefile.common
1137 X
1138 SHAR_EOF
1139 chmod 0644 Makefile.ibm ||
1140 echo 'restore of Makefile.ibm failed'
1141 Wc_c="`wc -c < 'Makefile.ibm'`"
1142 test 740 -eq "$Wc_c" ||
1143         echo 'Makefile.ibm: original size 740, current size' "$Wc_c"
1144 fi
1145 # ============= Makefile.linux ==============
1146 if test -f 'Makefile.linux' -a X"$1" != X"-c"; then
1147         echo 'x - skipping Makefile.linux (File already exists)'
1148 else
1149 echo 'x - extracting Makefile.linux (Text)'
1150 sed 's/^X//' << 'SHAR_EOF' > 'Makefile.linux' &&
1151 #
1152 # makefile for fasta3, fasta3_t.  Use makefile.pvm for pvcompxx.
1153 #
1154 #
1155 # Dec 8, 2005 - with gcc4.0.2 (or .1) under Redhat Linux Fedora FC4 -03 breaks the alignment code
1156 #
1157 X
1158 CC= gcc -g -O
1159 #CC = gcc -g -DDEBUG
1160 X
1161 #CC=gcc -Wall -pedantic -ansi -g -O
1162 #CC= /usr/local/parasoft/bin.linux2/insure -g -DDEBUG
1163 X
1164 # EBI uses the following with pgcc, -O3 does not work:
1165 # CC= pgcc -O2 -pipe -mcpu=pentiumpro -march=pentiumpro -fomit-frame-pointer
1166 X
1167 # this file works for x86 LINUX
1168 X
1169 # standard options
1170 CFLAGS= -DSHOWSIM -DUNIX -DTIMES -DHZ=100 -DSFCHAR="':'" -c -DMAX_WORKERS=8 -DTHR_EXIT=pthread_exit -DPROGRESS -DFASTA_HOST='"your_fasta_host_here"' -DUSE_MMAP -D_REENTRANT -DHAS_INTTYPES -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -DUSE_FSEEKO -DSAMP_STATS -DPGM_DOC
1171 X
1172 # use options below for superfamily validations
1173 #CFLAGS= -DSHOWSIM -DUNIX -DTIMES -DHZ=100 -DSFCHAR="'|'" -c -DMAX_WORKERS=8 -DTHR_EXIT=pthread_exit -DPROGRESS -DSUPERFAMNUM -DUSE_MMAP -D_REENTRANT -DBIG_LIB64 -D_LARGE_FILE_SOURCE -DUSE_FSEEKO -D_FILE_OFFSET_BITS=64 -DHAS_INTTYPES -DSAMP_STATS
1174 X
1175 # -I/usr/local/include/mysql -DMYSQL_DB 
1176 #
1177 #(for mySQL databases)  (also requires change to Makefile34.common)
1178 X
1179 LIB_M = -lm
1180 #LIB_M = -L/usr/local/lib/mysql -lmysqlclient -lm
1181 # for mySQL databases
1182 X
1183 HFLAGS= -o
1184 NFLAGS= -o
1185 X
1186 # for Linux
1187 THR_SUBS = pthr_subs2
1188 THR_LIBS = -lpthread
1189 THR_CC =
1190 X
1191 XXDIR = /seqprg/bin
1192 X
1193 DROPNFA_O = drop_nfa.o
1194 DROPTFA_O = drop_tfa.o
1195 DROPGSW_O = dropgsw.o
1196 DROPRSS_O = dropnsw.o
1197 X
1198 # renamed (fasta33)  programs
1199 include Makefile34m.common
1200 # conventional (fasta3) names
1201 # include Makefile.common
1202 X
1203 SHAR_EOF
1204 chmod 0644 Makefile.linux ||
1205 echo 'restore of Makefile.linux failed'
1206 Wc_c="`wc -c < 'Makefile.linux'`"
1207 test 1580 -eq "$Wc_c" ||
1208         echo 'Makefile.linux: original size 1580, current size' "$Wc_c"
1209 fi
1210 # ============= Makefile.linux_mysql ==============
1211 if test -f 'Makefile.linux_mysql' -a X"$1" != X"-c"; then
1212         echo 'x - skipping Makefile.linux_mysql (File already exists)'
1213 else
1214 echo 'x - extracting Makefile.linux_mysql (Text)'
1215 sed 's/^X//' << 'SHAR_EOF' > 'Makefile.linux_mysql' &&
1216 #
1217 # makefile for fasta3, fasta3_t.  Use makefile.pvm for pvcompxx.
1218 #
1219 # On the version of linux that I use, MININT is defined and causes a warning
1220 # as dropnfa.c is compiled.  Unfortunately, using the Linux definition of
1221 # MININT causes the code to break. Do not change the MININT definition
1222 # in dropnfa.c  (wrp 3/19/1998)
1223 #
1224 # for DEC/Compaq Alpha/LINUX, use gcc -mieee -g to avoid buggy compilers
1225 X
1226 CC= gcc -g -O2
1227 X
1228 #CC= gcc -g -DDEBUG
1229 #CC=/opt/parasoft/bin.linux2/insure -g -DDEBUG
1230 X
1231 # this file works for x86 LINUX
1232 X
1233 # standard options
1234 CFLAGS= -DSHOWSIM -DUNIX -DTIMES -DHZ=100 -DSFCHAR="':'" -c -DMAX_WORKERS=2 -DTHR_EXIT=pthread_exit -DPROGRESS -DFASTA_HOST='"your_fasta_host_here"' -DUSE_MMAP -D_REENTRANT -I/usr/include/mysql -DMYSQL_DB -D_FILE_OFFSET_BITS=64 -DUSE_FSEEKO -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -DHAS_INTTYPES -DSAMP_STATS -DPGM_DOC -DM10_CONS
1235 X
1236 # use options below for superfamily validations
1237 #CFLAGS= -DSHOWSIM -DUNIX -DTIMES -DHZ=100 -DSFCHAR="'|'" -c -DMAX_WORKERS=2 -DTHR_EXIT=pthread_exit -DPROGRESS -DSUPERFAMNUM -DUSE_MMAP -D_REENTRANT
1238 X
1239 # -I/usr/local/include/mysql -DMYSQL_DB 
1240 #
1241 #(for mySQL databases)  (also requires change to Makefile34.common)
1242 X
1243 #LIB_M = -lm
1244 #LIB_M = -L/usr/lib/mysql -lmysqlclient -lm
1245 # for mySQL databases
1246 X
1247 HFLAGS= -o
1248 NFLAGS= -o
1249 X
1250 # for Linux
1251 THR_SUBS = pthr_subs2
1252 THR_LIBS = -lpthread
1253 THR_CC =
1254 X
1255 XXDIR = /seqprg/bin
1256 X
1257 DROPNFA_O = drop_nfa.o
1258 DROPGSW_O = dropgsw.o
1259 DROPRSS_O = dropnsw.o
1260 DROPTFA_O = drop_tfa.o
1261 X
1262 # renamed (fasta34)  programs
1263 include Makefile34m.common_mysql
1264 # conventional (fasta3) names
1265 # include Makefile.common
1266 SHAR_EOF
1267 chmod 0644 Makefile.linux_mysql ||
1268 echo 'restore of Makefile.linux_mysql failed'
1269 Wc_c="`wc -c < 'Makefile.linux_mysql'`"
1270 test 1577 -eq "$Wc_c" ||
1271         echo 'Makefile.linux_mysql: original size 1577, current size' "$Wc_c"
1272 fi
1273 # ============= Makefile.linux_pgsql ==============
1274 if test -f 'Makefile.linux_pgsql' -a X"$1" != X"-c"; then
1275         echo 'x - skipping Makefile.linux_pgsql (File already exists)'
1276 else
1277 echo 'x - extracting Makefile.linux_pgsql (Text)'
1278 sed 's/^X//' << 'SHAR_EOF' > 'Makefile.linux_pgsql' &&
1279 #
1280 # makefile for fasta3, fasta3_t.  Use makefile.pvm for pvcompxx.
1281 #
1282 # On the version of linux that I use, MININT is defined and causes a warning
1283 # as dropnfa.c is compiled.  Unfortunately, using the Linux definition of
1284 # MININT causes the code to break. Do not change the MININT definition
1285 # in dropnfa.c  (wrp 3/19/1998)
1286 #
1287 # for DEC/Compaq Alpha/LINUX, use gcc -mieee -g to avoid buggy compilers
1288 X
1289 CC= gcc -g -O
1290 #CC= gcc -g -DDEBUG
1291 #CC=/opt/parasoft/bin.linux2/insure -g -DDEBUG
1292 X
1293 # this file works for x86 LINUX
1294 X
1295 # standard options
1296 CFLAGS= -DSHOWSIM -DUNIX -DTIMES -DHZ=100 -DSFCHAR="':'" -c -DMAX_WORKERS=2 -DTHR_EXIT=pthread_exit -DPROGRESS -DFASTA_HOST='"your_fasta_host_here"' -DUSE_MMAP -D_REENTRANT -I/usr/local/pgsql/include -DPGSQL_DB -D_FILE_OFFSET_BITS=64 -DUSE_FSEEKO -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -DHAS_INTTYPES -DSAMP_STATS -DPGM_DOC -DM10_CONS
1297 X
1298 # use options below for superfamily validations
1299 #CFLAGS= -DSHOWSIM -DUNIX -DTIMES -DHZ=100 -DSFCHAR="'|'" -c -DMAX_WORKERS=2 -DTHR_EXIT=pthread_exit -DPROGRESS -DSUPERFAMNUM -DUSE_MMAP -D_REENTRANT
1300 X
1301 # -I/usr/local/include/mysql -DMYSQL_DB 
1302 #
1303 #(for mySQL databases)  (also requires change to Makefile34.common)
1304 X
1305 #LIB_M = -lm
1306 #LIB_M = -L/usr/lib/mysql -lmysqlclient -lm
1307 # for mySQL databases
1308 X
1309 HFLAGS= -o
1310 NFLAGS= -o
1311 X
1312 # for Linux
1313 THR_SUBS = pthr_subs2
1314 THR_LIBS = -lpthread
1315 THR_CC =
1316 X
1317 XXDIR = /seqprg/bin
1318 X
1319 DROPNFA_O = drop_nfa.o
1320 DROPGSW_O = dropgsw.o
1321 DROPRSS_O = dropnsw.o
1322 DROPTFA_O = drop_tfa.o
1323 X
1324 # renamed (fasta34)  programs
1325 include Makefile34m.common_pgsql
1326 # conventional (fasta3) names
1327 # include Makefile.common
1328 SHAR_EOF
1329 chmod 0644 Makefile.linux_pgsql ||
1330 echo 'restore of Makefile.linux_pgsql failed'
1331 Wc_c="`wc -c < 'Makefile.linux_pgsql'`"
1332 test 1581 -eq "$Wc_c" ||
1333         echo 'Makefile.linux_pgsql: original size 1581, current size' "$Wc_c"
1334 fi
1335 # ============= Makefile.linux_sql ==============
1336 if test -f 'Makefile.linux_sql' -a X"$1" != X"-c"; then
1337         echo 'x - skipping Makefile.linux_sql (File already exists)'
1338 else
1339 echo 'x - extracting Makefile.linux_sql (Text)'
1340 sed 's/^X//' << 'SHAR_EOF' > 'Makefile.linux_sql' &&
1341 #
1342 # makefile for fasta3, fasta3_t.  Use makefile.pvm for pvcompxx.
1343 #
1344 # On the version of linux that I use, MININT is defined and causes a warning
1345 # as dropnfa.c is compiled.  Unfortunately, using the Linux definition of
1346 # MININT causes the code to break. Do not change the MININT definition
1347 # in dropnfa.c  (wrp 3/19/1998)
1348 #
1349 X
1350 X
1351 CC= gcc -g -O
1352 #CC= gcc -g -DDEBUG
1353 #CC=/opt/parasoft/bin.linux2/insure -g -DDEBUG
1354 X
1355 # this file works for x86 LINUX
1356 X
1357 # standard options
1358 CFLAGS= -DSHOWSIM -DUNIX -DTIMES -DHZ=100 -DSFCHAR="':'" -c -DMAX_WORKERS=2 -DTHR_EXIT=pthread_exit -DPROGRESS -DFASTA_HOST='"your_fasta_host_here"' -DUSE_MMAP -D_REENTRANT -I/usr/local/pgsql/include -I/usr/include/mysql -DPGSQL_DB -DMYSQL_DB -D_FILE_OFFSET_BITS=64 -DUSE_FSEEKO -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -DHAS_INTTYPES -DSAMP_STATS -DPGM_DOC -DM10_CONS
1359 X
1360 # use options below for superfamily validations
1361 #CFLAGS= -DSHOWSIM -DLINUX6 -DUNIX -DTIMES -DHZ=100 -DSFCHAR="'|'" -c -DMAX_WORKERS=2 -DTHR_EXIT=pthread_exit -DPROGRESS -DSUPERFAMNUM -DUSE_MMAP -D_REENTRANT
1362 X
1363 # -I/usr/local/include/mysql -DMYSQL_DB 
1364 #
1365 #(for mySQL databases)  (also requires change to Makefile34.common)
1366 X
1367 #LIB_M = -lm
1368 #LIB_M = -L/usr/lib/mysql -lmysqlclient -lm
1369 # for mySQL databases
1370 X
1371 HFLAGS= -o
1372 NFLAGS= -o
1373 X
1374 # for Linux
1375 THR_SUBS = pthr_subs2
1376 THR_LIBS = -lpthread
1377 THR_CC =
1378 X
1379 XXDIR = /seqprg/bin
1380 X
1381 DROPNFA_O = drop_nfa.o
1382 DROPGSW_O = dropgsw.o
1383 DROPRSS_O = dropnsw.o
1384 DROPTFA_O = drop_tfa.o
1385 X
1386 # renamed (fasta34)  programs
1387 include Makefile34m.common_sql
1388 # conventional (fasta3) names
1389 # include Makefile.common
1390 SHAR_EOF
1391 chmod 0644 Makefile.linux_sql ||
1392 echo 'restore of Makefile.linux_sql failed'
1393 Wc_c="`wc -c < 'Makefile.linux_sql'`"
1394 test 1548 -eq "$Wc_c" ||
1395         echo 'Makefile.linux_sql: original size 1548, current size' "$Wc_c"
1396 fi
1397 # ============= Makefile.linux_sse2 ==============
1398 if test -f 'Makefile.linux_sse2' -a X"$1" != X"-c"; then
1399         echo 'x - skipping Makefile.linux_sse2 (File already exists)'
1400 else
1401 echo 'x - extracting Makefile.linux_sse2 (Text)'
1402 sed 's/^X//' << 'SHAR_EOF' > 'Makefile.linux_sse2' &&
1403 #
1404 # makefile for fasta3, fasta3_t.  Use makefile.pvm for pvcompxx.
1405 #
1406 #
1407 # Dec 8, 2005 - with gcc4.0.2 (or .1) under Redhat Linux Fedora FC4 -03 breaks the alignment code
1408 #
1409 X
1410 CC= gcc -g -O -DSW_SSE2 -msse2
1411 #CC = gcc -g -DDEBUG -DSW_SSE2 -msse2
1412 X
1413 #CC=gcc -Wall -pedantic -ansi -g -O
1414 #CC= /usr/local/parasoft/bin/insure -g -DDEBUG
1415 X
1416 # EBI uses the following with pgcc, -O3 does not work:
1417 # CC= pgcc -O2 -pipe -mcpu=pentiumpro -march=pentiumpro -fomit-frame-pointer
1418 X
1419 # this file works for x86 LINUX
1420 X
1421 # standard options
1422 CFLAGS= -DSHOWSIM -DUNIX -DTIMES -DHZ=100 -DSFCHAR="':'" -c -DMAX_WORKERS=8 -DTHR_EXIT=pthread_exit -DPROGRESS -DFASTA_HOST='"your_fasta_host_here"' -DUSE_MMAP -D_REENTRANT -DHAS_INTTYPES -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -DUSE_FSEEKO -DSAMP_STATS -DPGM_DOC
1423 X
1424 # use options below for superfamily validations
1425 #CFLAGS= -DSHOWSIM -DUNIX -DTIMES -DHZ=100 -DSFCHAR="'|'" -c -DMAX_WORKERS=4 -DTHR_EXIT=pthread_exit -DPROGRESS -DSUPERFAMNUM -DUSE_MMAP -D_REENTRANT -DBIG_LIB64 -D_LARGE_FILE_SOURCE -DUSE_FSEEKO -D_FILE_OFFSET_BITS=64 -DHAS_INTTYPES -DSAMP_STATS
1426 X
1427 # -I/usr/local/include/mysql -DMYSQL_DB 
1428 #
1429 #(for mySQL databases)  (also requires change to Makefile34.common)
1430 X
1431 LIB_M = -lm
1432 #LIB_M = -L/usr/local/lib/mysql -lmysqlclient -lm
1433 # for mySQL databases
1434 X
1435 HFLAGS= -o
1436 NFLAGS= -o
1437 X
1438 # for Linux
1439 THR_SUBS = pthr_subs2
1440 THR_LIBS = -lpthread
1441 THR_CC =
1442 X
1443 XXDIR = /seqprg/bin
1444 #XDIR = ~/bin/LINUX
1445 X
1446 DROPNFA_O = drop_nfa.o
1447 DROPTFA_O = drop_tfa.o
1448 DROPGSW_O = dropgsw.o smith_waterman_sse2.o
1449 DROPRSS_O = dropgsw.o smith_waterman_sse2.o
1450 X
1451 # renamed (fasta33)  programs
1452 include Makefile34m.common
1453 # conventional (fasta3) names
1454 # include Makefile.common
1455 X
1456 SHAR_EOF
1457 chmod 0644 Makefile.linux_sse2 ||
1458 echo 'restore of Makefile.linux_sse2 failed'
1459 Wc_c="`wc -c < 'Makefile.linux_sse2'`"
1460 test 1671 -eq "$Wc_c" ||
1461         echo 'Makefile.linux_sse2: original size 1671, current size' "$Wc_c"
1462 fi
1463 # ============= Makefile.mpcom ==============
1464 if test -f 'Makefile.mpcom' -a X"$1" != X"-c"; then
1465         echo 'x - skipping Makefile.mpcom (File already exists)'
1466 else
1467 echo 'x - extracting Makefile.mpcom (Text)'
1468 sed 's/^X//' << 'SHAR_EOF' > 'Makefile.mpcom' &&
1469 X
1470 PROGS= mp34compfa mp34compsw mp34compfx mp34comptfx mp34compfy mp34comptfy mp34compfs mp34comptfs
1471 X
1472 # ms34compfa, etc provides a summaries of effectiveness, require
1473 # superfamily annotated database. ms34compss uses dropnsw.c instead of
1474 # dropgsw.c, thus allowing high gap penalties.
1475 X
1476 SPROGS = ms34compfa ms34compsw ms34compss ms34compfx ms34compfy ms34comptfx ms34comptfy
1477 X
1478 # report highest unrelated sequences
1479 UPROGS = mu34compfa mu34compsw mu34compfx mu34comptfx mu34compfy mu34comptfy
1480 X
1481 vall : $(PROGS) $(WPROGS)
1482 X
1483 uall : $(UPROGS) $(WPROGS)
1484 X
1485 sall : $(SPROGS) $(WPROGS)
1486 X
1487 all : $(PROGS) $(UPROGS) $(SPROGS) $(WPROGS)
1488 X
1489 clean-up:
1490 X       rm -f *.o $(PROGS) $(WPROGS) $(SPROGS) $(UPROGS)
1491 X
1492 install : $(PROGS) $(WPROGS)
1493 X       cp $(PROGS) $(WPROGS) $(XDIR)
1494 X
1495 sinstall : $(SPROGS) $(WPROGS)
1496 X       cp $(SPROGS) $(WPROGS) $(XDIR)
1497 X
1498 uinstall : $(UPROGS) $(WPROGS)
1499 X       cp $(UPROGS) $(WPROGS) $(XDIR)
1500 X
1501 mp34compfa : p2_complib.o compacc.o lib_sel.o url_subs.o showbest.o $(SHOWALIGN).o htime.o hostacc.o $(LGETLIB) $(NCBL_LIB) apam.o doinit.o init_fa.o scaleswn.o karlin.o c_dispn.o p2_workcomp.o $(DROPNFA_O) workacc.o faatran.o $(NRAND).o
1502 X       $(LCC) $(LFLAGS) mp34compfa p2_complib.o compacc.o lib_sel.o url_subs.o showbest.o $(SHOWALIGN).o htime.o hostacc.o $(LGETLIB) $(NCBL_LIB) apam.o doinit.o init_fa.o scaleswn.o karlin.o c_dispn.o  p2_workcomp.o $(DROPNFA_O) workacc.o faatran.o $(NRAND).o $(PLIB) $(LIB_M)
1503 X
1504 ms34compfa : p2_complib.o compacc.o lib_sel.o url_subs.o showsum.o htime.o hostacc.o $(LGETLIB) $(NCBL_LIB) apam.o doinit.o init_fa.o scaleswn.o karlin.o p2_workcomp.o $(DROPNFA_O) workacc.o faatran.o $(NRAND).o
1505 X       $(LCC) $(LFLAGS) ms34compfa p2_complib.o compacc.o lib_sel.o url_subs.o showsum.o htime.o hostacc.o $(LGETLIB) $(NCBL_LIB) apam.o doinit.o init_fa.o scaleswn.o karlin.o p2_workcomp.o $(DROPNFA_O) workacc.o faatran.o $(NRAND).o $(PLIB) $(LIB_M)
1506 X
1507 mu34compfa : p2_complib.o compacc.o lib_sel.o url_subs.o showun.o $(SHOWALIGN)_u.o htime.o hostacc.o $(LGETLIB) $(NCBL_LIB) apam.o doinit.o init_fa.o scaleswn.o karlin.o p2_workcomp.o $(DROPNFA_O) workacc.o faatran.o $(NRAND).o c_dispn.o
1508 X       $(LCC) $(LFLAGS) mu34compfa p2_complib.o compacc.o lib_sel.o url_subs.o showun.o $(SHOWALIGN)_u.o htime.o hostacc.o $(LGETLIB) $(NCBL_LIB) apam.o doinit.o init_fa.o scaleswn.o karlin.o p2_workcomp.o $(DROPNFA_O) workacc.o faatran.o $(NRAND).o c_dispn.o $(PLIB) $(LIB_M)
1509 X
1510 mr34compfa : p2_complib.o compacc.o lib_sel.o url_subs.o manshowrel.o htime.o hostacc.o $(LGETLIB) $(NCBL_LIB) apam.o doinit.o init_fa.o scaleswn.o karlin.o p2_workcomp.o $(DROPNFA_O) workacc.o faatran.o $(NRAND).o
1511 X       $(LCC) $(LFLAGS) mr34compfa p2_complib.o compacc.o lib_sel.o url_subs.o manshowrel.o htime.o hostacc.o $(LGETLIB) $(NCBL_LIB) apam.o doinit.o init_fa.o scaleswn.o karlin.o p2_workcomp.o $(DROPNFA_O) workacc.o faatran.o $(NRAND).o $(PLIB) $(LIB_M)
1512 X
1513 mp34compsw : p2_complib.o compacc.o lib_sel.o url_subs.o showbest.o $(SHOWALIGN).o htime.o hostacc.o pssm_asn_subs.o $(LGETLIB) $(NCBL_LIB) apam.o doinit.o init_sw.o scaleswn.o karlin.o c_dispn.o p2_workcomp.o $(DROPGSW_O) workacc.o faatran.o $(NRAND).o
1514 X       $(LCC) $(LFLAGS) mp34compsw p2_complib.o compacc.o lib_sel.o url_subs.o showbest.o $(SHOWALIGN).o htime.o hostacc.o pssm_asn_subs.o $(LGETLIB) $(NCBL_LIB) apam.o doinit.o init_sw.o scaleswn.o karlin.o c_dispn.o p2_workcomp.o $(DROPGSW_O) workacc.o faatran.o $(NRAND).o $(PLIB) $(LIB_M)
1515 X
1516 ms34compsw : p2_complib.o compacc.o lib_sel.o url_subs.o showsum.o htime.o hostacc.o pssm_asn_subs.o $(LGETLIB) $(NCBL_LIB) apam.o doinit.o init_sw.o scaleswn.o karlin.o p2_workcomp.o $(DROPGSW_O) workacc.o faatran.o $(NRAND).o
1517 X       $(LCC) $(LFLAGS) ms34compsw p2_complib.o compacc.o lib_sel.o url_subs.o showsum.o htime.o hostacc.o pssm_asn_subs.o $(LGETLIB) $(NCBL_LIB) apam.o doinit.o init_sw.o scaleswn.o karlin.o p2_workcomp.o $(DROPGSW_O) workacc.o faatran.o $(NRAND).o $(PLIB) $(LIB_M)
1518 X
1519 mu34compsw : p2_complib.o compacc.o lib_sel.o url_subs.o showun.o $(SHOWALIGN)_u.o htime.o hostacc.o pssm_asn_subs.o $(LGETLIB) $(NCBL_LIB) apam.o doinit.o init_sw.o scaleswn.o karlin.o p2_workcomp.o $(DROPGSW_O) workacc.o faatran.o $(NRAND).o c_dispn.o
1520 X       $(LCC) $(LFLAGS) mu34compsw p2_complib.o compacc.o lib_sel.o url_subs.o showun.o $(SHOWALIGN)_u.o htime.o hostacc.o pssm_asn_subs.o $(LGETLIB) $(NCBL_LIB) apam.o doinit.o init_sw.o scaleswn.o karlin.o p2_workcomp.o $(DROPGSW_O) workacc.o faatran.o $(NRAND).o c_dispn.o $(PLIB) $(LIB_M)
1521 X
1522 mp34compss : p2_complib.o compacc.o lib_sel.o url_subs.o showbest.o $(SHOWALIGN).o htime.o hostacc.o $(LGETLIB) $(NCBL_LIB) apam.o doinit.o init_sw.o scaleswn.o karlin.o c_dispn.o p2_workcomp.o dropnsw.o workacc.o faatran.o $(NRAND).o
1523 X       $(LCC) $(LFLAGS) mp34compss p2_complib.o compacc.o lib_sel.o url_subs.o showbest.o $(SHOWALIGN).o htime.o hostacc.o $(LGETLIB) $(NCBL_LIB) apam.o doinit.o init_sw.o scaleswn.o karlin.o c_dispn.o p2_workcomp.o dropnsw.o workacc.o faatran.o $(NRAND).o $(PLIB) $(LIB_M)
1524 X
1525 ms34compss : p2_complib.o compacc.o lib_sel.o url_subs.o showsum.o htime.o hostacc.o $(LGETLIB) $(NCBL_LIB) apam.o doinit.o init_sw.o scaleswn.o karlin.o p2_workcomp.o dropnsw.o workacc.o faatran.o $(NRAND).o
1526 X       $(LCC) $(LFLAGS) ms34compss p2_complib.o compacc.o lib_sel.o url_subs.o showsum.o htime.o hostacc.o $(LGETLIB) $(NCBL_LIB) apam.o doinit.o init_sw.o scaleswn.o karlin.o p2_workcomp.o dropnsw.o workacc.o faatran.o $(NRAND).o $(PLIB) $(LIB_M)
1527 X
1528 mu34compss : p2_complib.o compacc.o lib_sel.o url_subs.o showun.o $(SHOWALIGN)_u.o htime.o hostacc.o $(LGETLIB) $(NCBL_LIB) apam.o doinit.o init_sw.o scaleswn.o karlin.o p2_workcomp.o dropnsw.o workacc.o faatran.o $(NRAND).o c_dispn.o
1529 X       $(LCC) $(LFLAGS) mu34compss p2_complib.o compacc.o lib_sel.o url_subs.o showun.o $(SHOWALIGN)_u.o htime.o hostacc.o $(LGETLIB) $(NCBL_LIB) apam.o doinit.o init_sw.o scaleswn.o karlin.o p2_workcomp.o dropnsw.o workacc.o faatran.o $(NRAND).o c_dispn.o $(PLIB) $(LIB_M)
1530 X
1531 mp34compfx : p2_complib.o compacc.o lib_sel.o url_subs.o showbest.o $(SHOWALIGN).o htime.o hostacc.o $(LGETLIB) $(NCBL_LIB) apam.o doinit.o init_fx.o scaleswn.o karlin.o c_dispn.o p2_workcomp.o drop_fx.o workacc.o $(NRAND).o faatran.o
1532 X       $(LCC) $(LFLAGS) mp34compfx p2_complib.o compacc.o lib_sel.o url_subs.o showbest.o $(SHOWALIGN).o htime.o hostacc.o $(LGETLIB) $(NCBL_LIB) apam.o doinit.o init_fx.o scaleswn.o karlin.o c_dispn.o p2_workcomp.o drop_fx.o workacc.o $(NRAND).o faatran.o $(PLIB) $(LIB_M)
1533 X
1534 ms34compfx : p2_complib.o compacc.o lib_sel.o url_subs.o showsum.o htime.o hostacc.o $(LGETLIB) $(NCBL_LIB) apam.o doinit.o init_fx.o scaleswn.o karlin.o p2_workcomp.o drop_fx.o workacc.o $(NRAND).o faatran.o
1535 X       $(LCC) $(LFLAGS) ms34compfx p2_complib.o compacc.o lib_sel.o url_subs.o showsum.o htime.o hostacc.o $(LGETLIB) $(NCBL_LIB) apam.o doinit.o init_fx.o scaleswn.o karlin.o p2_workcomp.o drop_fx.o workacc.o $(NRAND).o faatran.o $(PLIB) $(LIB_M)
1536 X
1537 mu34compfx : p2_complib.o compacc.o lib_sel.o url_subs.o showun.o $(SHOWALIGN)_u.o htime.o hostacc.o $(LGETLIB) $(NCBL_LIB) apam.o doinit.o init_fx.o scaleswn.o karlin.o c_dispn.o p2_workcomp.o drop_fx.o workacc.o $(NRAND).o faatran.o
1538 X       $(LCC) $(LFLAGS) mu34compfx p2_complib.o compacc.o lib_sel.o url_subs.o showun.o $(SHOWALIGN)_u.o htime.o hostacc.o $(LGETLIB) $(NCBL_LIB) apam.o doinit.o init_fx.o scaleswn.o karlin.o c_dispn.o p2_workcomp.o drop_fx.o workacc.o $(NRAND).o faatran.o $(PLIB) $(LIB_M)
1539 X
1540 mp34compfy : p2_complib.o compacc.o lib_sel.o url_subs.o showbest.o $(SHOWALIGN).o htime.o hostacc.o $(LGETLIB) $(NCBL_LIB) apam.o doinit.o init_fy.o scaleswn.o karlin.o c_dispn.o p2_workcomp.o drop_fz.o workacc.o $(NRAND).o faatran.o
1541 X       $(LCC) $(LFLAGS) mp34compfy p2_complib.o compacc.o lib_sel.o url_subs.o showbest.o $(SHOWALIGN).o htime.o hostacc.o $(LGETLIB) $(NCBL_LIB) apam.o doinit.o init_fy.o scaleswn.o karlin.o c_dispn.o p2_workcomp.o drop_fz.o workacc.o $(NRAND).o faatran.o $(PLIB) $(LIB_M)
1542 X
1543 ms34compfy : p2_complib.o compacc.o lib_sel.o url_subs.o showsum.o htime.o hostacc.o $(LGETLIB) $(NCBL_LIB) apam.o doinit.o init_fy.o scaleswn.o karlin.o p2_workcomp.o drop_fz.o workacc.o $(NRAND).o faatran.o
1544 X       $(LCC) $(LFLAGS) ms34compfy p2_complib.o compacc.o lib_sel.o url_subs.o showsum.o htime.o hostacc.o $(LGETLIB) $(NCBL_LIB) apam.o doinit.o init_fy.o scaleswn.o karlin.o p2_workcomp.o drop_fz.o workacc.o $(NRAND).o faatran.o $(PLIB) $(LIB_M)
1545 X
1546 mu34compfy : p2_complib.o compacc.o lib_sel.o url_subs.o showun.o $(SHOWALIGN)_u.o htime.o hostacc.o $(LGETLIB) $(NCBL_LIB) apam.o doinit.o init_fy.o scaleswn.o karlin.o c_dispn.o p2_workcomp.o drop_fz.o workacc.o $(NRAND).o faatran.o
1547 X       $(LCC) $(LFLAGS) mu34compfy p2_complib.o compacc.o lib_sel.o url_subs.o showun.o $(SHOWALIGN)_u.o htime.o hostacc.o $(LGETLIB) $(NCBL_LIB) apam.o doinit.o init_fy.o scaleswn.o karlin.o c_dispn.o p2_workcomp.o drop_fz.o workacc.o $(NRAND).o faatran.o $(PLIB) $(LIB_M)
1548 X
1549 mp34compfs : p2_complib.o compacc.o lib_sel.o url_subs.o showbest.o $(SHOWALIGN).o htime.o hostacc.o $(LGETLIB) $(NCBL_LIB) apam.o doinit.o init_fs.o scaleswts.o tatstats_fs.o last_tat.o karlin.o c_dispn.o p2_workcomp.o drop_fs.o workacc.o faatran.o $(NRAND).o
1550 X       $(LCC) $(LFLAGS) mp34compfs p2_complib.o compacc.o lib_sel.o url_subs.o showbest.o $(SHOWALIGN).o htime.o hostacc.o $(LGETLIB) $(NCBL_LIB) apam.o doinit.o init_fs.o scaleswts.o tatstats_fs.o last_tat.o karlin.o c_dispn.o p2_workcomp.o drop_fs.o workacc.o faatran.o $(NRAND).o $(PLIB) $(LIB_M)
1551 X
1552 mp34comptfs : p2_complib.o compacc.o lib_sel.o url_subs.o showbest.o $(SHOWALIGN).o htime.o hostacc.o $(LGETLIB) $(NCBL_LIB) apam.o doinit.o init_tfs.o scaleswts.o tatstats_fs.o last_tat.o karlin.o c_dispn.o p2_workcomp.o drop_tfs.o workacc.o $(NRAND).o faatran.o
1553 X       $(LCC) $(LFLAGS) mp34comptfs p2_complib.o compacc.o lib_sel.o url_subs.o showbest.o $(SHOWALIGN).o htime.o hostacc.o $(LGETLIB) $(NCBL_LIB) apam.o doinit.o init_fs.o scaleswts.o tatstats_fs.o last_tat.o karlin.o c_dispn.o p2_workcomp.o drop_fz.o workacc.o $(NRAND).o faatran.o $(PLIB) $(LIB_M)
1554 X
1555 mp34comptfx : p2_complib.o compacc.o lib_sel.o url_subs.o showbest.o $(SHOWALIGN).o htime.o hostacc.o $(LGETLIB) $(NCBL_LIB) apam.o doinit.o init_tfx.o scaleswn.o karlin.o c_dispn.o p2_workcomp.o drop_tfx.o workacc.o $(NRAND).o faatran.o
1556 X       $(LCC) $(LFLAGS) mp34comptfx p2_complib.o compacc.o lib_sel.o url_subs.o showbest.o $(SHOWALIGN).o htime.o hostacc.o $(LGETLIB) $(NCBL_LIB) apam.o doinit.o init_tfx.o scaleswn.o karlin.o c_dispn.o p2_workcomp.o drop_tfx.o workacc.o $(NRAND).o faatran.o $(PLIB) $(LIB_M)
1557 X
1558 ms34comptfx : p2_complib.o compacc.o lib_sel.o url_subs.o showsum.o htime.o hostacc.o $(LGETLIB) $(NCBL_LIB) apam.o doinit.o init_tfx.o scaleswn.o karlin.o p2_workcomp.o drop_tfx.o workacc.o $(NRAND).o faatran.o
1559 X       $(LCC) $(LFLAGS) ms34comptfx p2_complib.o compacc.o lib_sel.o url_subs.o showsum.o htime.o hostacc.o $(LGETLIB) $(NCBL_LIB) apam.o doinit.o init_tfx.o scaleswn.o karlin.o p2_workcomp.o drop_tfx.o workacc.o $(NRAND).o faatran.o $(PLIB) $(LIB_M)
1560 X
1561 mu34comptfx : p2_complib.o compacc.o lib_sel.o url_subs.o showun.o $(SHOWALIGN)_u.o htime.o hostacc.o $(LGETLIB) $(NCBL_LIB) apam.o doinit.o init_tfx.o scaleswn.o karlin.o c_dispn.o p2_workcomp.o drop_tfx.o workacc.o $(NRAND).o faatran.o
1562 X       $(LCC) $(LFLAGS) mu34comptfx p2_complib.o compacc.o lib_sel.o url_subs.o showun.o $(SHOWALIGN)_u.o htime.o hostacc.o $(LGETLIB) $(NCBL_LIB) apam.o doinit.o init_tfx.o scaleswn.o karlin.o c_dispn.o p2_workcomp.o drop_tfx.o workacc.o $(NRAND).o faatran.o $(PLIB) $(LIB_M)
1563 X
1564 mp34comptfy : p2_complib.o compacc.o lib_sel.o url_subs.o showbest.o $(SHOWALIGN).o htime.o hostacc.o $(LGETLIB) $(NCBL_LIB) apam.o doinit.o init_tfy.o scaleswn.o karlin.o c_dispn.o p2_workcomp.o drop_tfz.o workacc.o $(NRAND).o faatran.o
1565 X       $(LCC) $(LFLAGS) mp34comptfy p2_complib.o compacc.o lib_sel.o url_subs.o showbest.o $(SHOWALIGN).o htime.o hostacc.o $(LGETLIB) $(NCBL_LIB) apam.o doinit.o init_tfy.o scaleswn.o karlin.o c_dispn.o p2_workcomp.o drop_tfz.o workacc.o $(NRAND).o faatran.o $(PLIB) $(LIB_M)
1566 X
1567 ms34comptfy : p2_complib.o compacc.o lib_sel.o url_subs.o showsum.o htime.o hostacc.o $(LGETLIB) $(NCBL_LIB) apam.o doinit.o init_tfy.o scaleswn.o karlin.o p2_workcomp.o drop_tfz.o workacc.o $(NRAND).o faatran.o
1568 X       $(LCC) $(LFLAGS) ms34comptfy p2_complib.o compacc.o lib_sel.o url_subs.o showsum.o htime.o hostacc.o $(LGETLIB) $(NCBL_LIB) apam.o doinit.o init_tfy.o scaleswn.o karlin.o p2_workcomp.o drop_tfz.o workacc.o $(NRAND).o faatran.o $(PLIB) $(LIB_M)
1569 X
1570 mu34comptfy : p2_complib.o compacc.o lib_sel.o url_subs.o showun.o $(SHOWALIGN)_u.o htime.o hostacc.o $(LGETLIB) $(NCBL_LIB) apam.o doinit.o init_tfy.o scaleswn.o karlin.o c_dispn.o p2_workcomp.o drop_tfz.o workacc.o $(NRAND).o faatran.o
1571 X       $(LCC) $(LFLAGS) mu34comptfy p2_complib.o compacc.o lib_sel.o url_subs.o showun.o $(SHOWALIGN)_u.o htime.o hostacc.o $(LGETLIB) $(NCBL_LIB) apam.o doinit.o init_tfy.o scaleswn.o karlin.o c_dispn.o p2_workcomp.o drop_tfz.o workacc.o $(NRAND).o faatran.o $(PLIB) $(LIB_M)
1572 X
1573 p2_complib.o : p2_complib.c msg.h defs.h upam.h uascii.h param.h structs.h
1574 X       $(CC) $(CFLAGS) p2_complib.c -o p2_complib.o 
1575 X
1576 p2_workcomp.o : p2_workcomp.c structs.h msg.h defs.h mw.h upam.h uascii.h param.h
1577 X       $(NCC) $(CFLAGS) p2_workcomp.c
1578 SHAR_EOF
1579 chmod 0644 Makefile.mpcom ||
1580 echo 'restore of Makefile.mpcom failed'
1581 Wc_c="`wc -c < 'Makefile.mpcom'`"
1582 test 13073 -eq "$Wc_c" ||
1583         echo 'Makefile.mpcom: original size 13073, current size' "$Wc_c"
1584 fi
1585 # ============= Makefile.mpi4 ==============
1586 if test -f 'Makefile.mpi4' -a X"$1" != X"-c"; then
1587         echo 'x - skipping Makefile.mpi4 (File already exists)'
1588 else
1589 echo 'x - extracting Makefile.mpi4 (Text)'
1590 sed 's/^X//' << 'SHAR_EOF' > 'Makefile.mpi4' &&
1591 #
1592 # $Name: fa_34_26_5 $ - $Id: Makefile.mpi4,v 1.26 2006/12/12 16:58:51 wrp Exp $
1593 #
1594 # 21 July, 2000
1595 #
1596 # Makefile for MPI versions of the parallel library comparison programs.
1597 # this file is derived from Makefile.pvm, with only a few differences:
1598 # (1) -DMPI_SRC instead of -DPVM_SRC
1599 # (2) programs are mp34comp*, ms34comp*, and mu34comp* rather than pv34comp*, etc.
1600 # (3) MPI does not require/allow a "worker" program, thus no c3.work*
1601 #
1602 X
1603 # setenv MPI_CC gcc-3.3 for best performance
1604 X
1605 MPI_ROOT = /m0/xshare/mpich2
1606 MPICC = ${MPI_ROOT}/bin/mpicc
1607 X
1608 CC= ${MPICC} -g -falign-loops=32 -O3 -mcpu=7450 -faltivec -DSW_ALTIVEC
1609 NCC= ${MPICC} -g -falign-loops=32 -O3 -mcpu=7450 -faltivec -DSW_ALTIVEC
1610 LCC= ${MPICC}
1611 X
1612 #ARCH   =       ALPHAMP  (get from $ARCH)
1613 X
1614 PLIB    =       -L${MPI_ROOT}/lib -lmpich
1615 XXDIR    =       /home/slib/mpi/bin/
1616 SDIR    =       .
1617 X
1618 CFLAGS= -DMPI_SRC -DUNIX -DPCOMPLIB -DBFR=120 -DSHOWSIM -I${MPI_ROOT}/include -DSRAND=srand -DRAND=random -c -DHAS_INTTYPES -DSAMP_STATS -DSW_ALTIVEC
1619 # -DMYSQL_DB -I/usr/include/mysql
1620 # -DSFCHAR="'|'" -DSUPERFAMNUM 
1621 X
1622 # standard nxgetaa, no memory mapping for 0 - 6
1623 #LGETLIB=getseq.o lgetlib.o
1624 #NGETLIB=nmgetlib
1625 X
1626 # memory mapping for 0FASTA, 5PIRVMS, 6GCGBIN
1627 LGETLIB=getseq.o lgetlib.o lgetaa_m.o
1628 NGETLIB=nmgetlib
1629 X
1630 NRAND=nrandom
1631 X
1632 SHOWBESTC = mshowbest.c
1633 SHOWALIGN = mshowalign
1634 MWH = p_mw.h
1635 MWHP = p_mw.h w_mw.h
1636 X
1637 #NCBL_LIB=ncbl2_mlib.o mysql_lib.o
1638 NCBL_LIB=ncbl2_mlib.o
1639 #LIB_M= -L/usr/lib/mysql -lmysqlclient -lz -lm
1640 LIB_M= -lm
1641 X
1642 LFLAGS= -o
1643 X
1644 DROPGSW_O = dropgsw.o smith_waterman_altivec.o
1645 DROPNFA_O = drop_nfa.o
1646 X
1647 include Makefile.mpcom
1648 X
1649 include Makefile.fcom
1650 X
1651 SHAR_EOF
1652 chmod 0644 Makefile.mpi4 ||
1653 echo 'restore of Makefile.mpi4 failed'
1654 Wc_c="`wc -c < 'Makefile.mpi4'`"
1655 test 1600 -eq "$Wc_c" ||
1656         echo 'Makefile.mpi4: original size 1600, current size' "$Wc_c"
1657 fi
1658 # ============= Makefile.mpi4_bluegene ==============
1659 if test -f 'Makefile.mpi4_bluegene' -a X"$1" != X"-c"; then
1660         echo 'x - skipping Makefile.mpi4_bluegene (File already exists)'
1661 else
1662 echo 'x - extracting Makefile.mpi4_bluegene (Text)'
1663 sed 's/^X//' << 'SHAR_EOF' > 'Makefile.mpi4_bluegene' &&
1664 #
1665 # $Name: fa_34_26_5 $ - $Id: Makefile.mpi4_bluegene,v 1.1 2006/04/01 14:09:11 wrp Exp $
1666 #
1667 # 21 July, 2000
1668 #
1669 # Makefile for MPI versions of the parallel library comparison programs.
1670 # this file is derived from Makefile.pvm, with only a few differences:
1671 # (1) -DMPI_SRC instead of -DPVM_SRC
1672 # (2) programs are mp34comp*, ms34comp*, and mu34comp* rather than pv34comp*, etc.
1673 # (3) MPI does not require/allow a "worker" program, thus no c3.work*
1674 #
1675 # 1-April-2006 - Makefile for IBM BlueGene - use -DMAXWRKR to set the
1676 # maximum number of workers.
1677 #
1678 CC= blrts_xlc -O3 -qsource -qlist -qarch=440d -qtune=440
1679 NCC= blrts_xlc -O3  -qsource -qlist -qarch=440d -qtune=440
1680 LCC= blrts_xlc -O3
1681 X
1682 MPI_ROOT = /bgl/BlueLight/ppcfloor/bglsys
1683 PLIB    =      -L${MPI_ROOT}/lib -lmpich.rts -lrts.rts -ldevices.rts -lmsglayer.rts -ldevices.440
1684 XXDIR    =       /home/slib/mpi/bin/
1685 SDIR    =       .
1686 X
1687 CFLAGS= -DMPI_SRC -DMAXWRKR=128 -DUNIX -DPCOMPLIB -DBFR=1200 -I${MPI_ROOT}/include -DSRAND=srand -DRAND=random -c -DHAS_INTTYPES -DSAMP_STATS
1688 # -DMYSQL_DB -I/usr/include/mysql
1689 # -DSFCHAR="'|'" -DSUPERFAMNUM 
1690 X
1691 # standard nxgetaa, no memory mapping for 0 - 6
1692 #LGETLIB=getseq.o lgetlib.o
1693 #NGETLIB=nmgetlib
1694 X
1695 # memory mapping for 0FASTA, 5PIRVMS, 6GCGBIN
1696 LGETLIB=getseq.o lgetlib.o lgetaa_m.o
1697 NGETLIB=nmgetlib
1698 X
1699 NRAND=nrandom
1700 X
1701 SHOWBESTC = mshowbest.c
1702 SHOWALIGN = mshowalign
1703 MWH = p_mw.h
1704 MWHP = p_mw.h w_mw.h
1705 X
1706 #NCBL_LIB=ncbl2_mlib.o mysql_lib.o
1707 NCBL_LIB=ncbl2_mlib.o
1708 #LIB_M= -L/usr/lib/mysql -lmysqlclient -lz -lm
1709 LIB_M= -lm
1710 X
1711 LFLAGS= -o
1712 X
1713 DROPGSW_O = dropgsw.o
1714 DROPNFA_O = drop_nfa.o
1715 X
1716 include Makefile.mpcom
1717 X
1718 include Makefile.fcom
1719 X
1720 SHAR_EOF
1721 chmod 0644 Makefile.mpi4_bluegene ||
1722 echo 'restore of Makefile.mpi4_bluegene failed'
1723 Wc_c="`wc -c < 'Makefile.mpi4_bluegene'`"
1724 test 1602 -eq "$Wc_c" ||
1725         echo 'Makefile.mpi4_bluegene: original size 1602, current size' "$Wc_c"
1726 fi
1727 # ============= Makefile.mpi4_sql ==============
1728 if test -f 'Makefile.mpi4_sql' -a X"$1" != X"-c"; then
1729         echo 'x - skipping Makefile.mpi4_sql (File already exists)'
1730 else
1731 echo 'x - extracting Makefile.mpi4_sql (Text)'
1732 sed 's/^X//' << 'SHAR_EOF' > 'Makefile.mpi4_sql' &&
1733 #
1734 # $Name: fa_34_26_5 $ - $Id: Makefile.mpi4_sql,v 1.19 2004/11/19 15:28:26 wrp Exp $
1735 #
1736 # 21 July, 2000
1737 #
1738 # Makefile for MPI versions of the parallel library comparison programs.
1739 # this file is derived from Makefile.pvm, with only a few differences:
1740 # (1) -DMPI_SRC instead of -DPVM_SRC
1741 # (2) programs are mp34comp*, ms34comp*, and mu34comp* rather than pv34comp*, etc.
1742 # (3) MPI does not require/allow a "worker" program, thus no c3.work*
1743 #
1744 X
1745 CC= mpicc -g -O
1746 NCC= mpicc -O
1747 LCC= mpicc -O
1748 X
1749 #ARCH   =       ALPHAMP  (get from $ARCH)
1750 X
1751 #MPI_ROOT = /opt/share/mpi
1752 #PLIB    =       -L${MPI_ROOT}/lib -lmpich
1753 #XDIR    =       /seqprg/pvm3/bin/LINUX
1754 XXDIR    =       ${HOME}/pvm3/bin/LINUX
1755 SDIR    =       .
1756 X
1757 CFLAGS= -DMPI_SRC -DUNIX -DPCOMPLIB -DBFR=1200 -I${MPI_ROOT}/include -DSRAND=srand -DRAND=random -c -DHAS_INTTYPES -DSAMP_STATS -DMYSQL_DB -I/usr/include/mysql -DPGSQL_DB -I/usr/include/pgsql
1758 # -DMYSQL_DB -I/usr/include/mysql
1759 # -DSFCHAR="'|'" -DSUPERFAMNUM 
1760 X
1761 # standard nxgetaa, no memory mapping for 0 - 6
1762 #LGETLIB=getseq.o lgetlib.o
1763 #NGETLIB=nmgetlib
1764 X
1765 # memory mapping for 0FASTA, 5PIRVMS, 6GCGBIN
1766 LGETLIB=getseq.o lgetlib.o lgetaa_m.o
1767 NGETLIB=nmgetlib
1768 X
1769 NRAND=nrandom
1770 X
1771 SHOWBESTC = mshowbest.c
1772 SHOWALIGN = mshowalign
1773 MWH = p_mw.h
1774 MWHP = p_mw.h w_mw.h
1775 X
1776 NCBL_LIB=ncbl2_mlib.o mysql_lib.o
1777 #NCBL_LIB=ncbl2_mlib.o
1778 LIB_M= -L/usr/lib/mysql -lmysqlclient -lz -lm -L/usr/lib/pgsql -lpq -lcrypt -lssl
1779 #LIB_M= -lm
1780 X
1781 LFLAGS= -o
1782 X
1783 DROPGSW_O = dropgsw.o
1784 DROPNFA_O = drop_nfa.o
1785 X
1786 include Makefile.mpcom
1787 X
1788 include Makefile.fcom
1789 X
1790 SHAR_EOF
1791 chmod 0644 Makefile.mpi4_sql ||
1792 echo 'restore of Makefile.mpi4_sql failed'
1793 Wc_c="`wc -c < 'Makefile.mpi4_sql'`"
1794 test 1509 -eq "$Wc_c" ||
1795         echo 'Makefile.mpi4_sql: original size 1509, current size' "$Wc_c"
1796 fi
1797 # ============= Makefile.nm_fcom ==============
1798 if test -f 'Makefile.nm_fcom' -a X"$1" != X"-c"; then
1799         echo 'x - skipping Makefile.nm_fcom (File already exists)'
1800 else
1801 echo 'x - extracting Makefile.nm_fcom (Text)'
1802 sed 's/^X//' << 'SHAR_EOF' > 'Makefile.nm_fcom' &&
1803 X
1804 #================ common .obj files 
1805 X
1806 doinit.obj : doinit.c defs.h param.h upam.h structs.h uascii.h
1807 X       $(CC) $(CFLAGS) -c doinit.c
1808 X
1809 init_sw.obj : initfa.c defs.h param.h upam.h structs.h
1810 X       $(CC) $(CFLAGS) -c -DSSEARCH initfa.c /Foinit_sw.obj
1811 X
1812 init_ssw.obj : initfa.c defs.h param.h upam.h structs.h
1813 X       $(CC) $(CFLAGS) -c -DOSEARCH initfa.c /Foinit_ssw.obj
1814 X
1815 init_rss.obj : initfa.c defs.h param.h upam.h structs.h
1816 X       $(CC) $(CFLAGS) -c -DPRSS initfa.c /Foinit_rss.obj
1817 X
1818 init_rfx.obj : initfa.c defs.h param.h upam.h structs.h
1819 X       $(CC) $(CFLAGS) -c -DPRSS -DFASTX initfa.c /Foinit_rfx.obj
1820 X
1821 init_fa.obj : initfa.c defs.h param.h upam.h structs.h
1822 X       $(CC) $(CFLAGS) -c -DFASTA initfa.c /Foinit_fa.obj
1823 X
1824 init_ff.obj : initfa.c defs.h param.h upam.h structs.h
1825 X       $(CC) $(CFLAGS) -c -DFASTF initfa.c /Foinit_ff.obj
1826 X
1827 init_tf.obj : initfa.c defs.h param.h upam.h structs.h
1828 X       $(CC) $(CFLAGS) -c -DFASTF -DTFAST initfa.c /Foinit_tf.obj
1829 X
1830 init_fs.obj : initfa.c defs.h param.h upam.h structs.h
1831 X       $(CC) $(CFLAGS) -c -DFASTS initfa.c /Foinit_fs.obj
1832 X
1833 init_fm.obj : initfa.c defs.h param.h upam.h structs.h
1834 X       $(CC) $(CFLAGS) -c -DFASTM initfa.c /Foinit_fm.obj
1835 X
1836 init_tfs.obj : initfa.c defs.h param.h upam.h structs.h
1837 X       $(CC) $(CFLAGS) -c -DFASTS -DTFAST  initfa.c /Foinit_tfs.obj
1838 X
1839 init_tfm.obj : initfa.c defs.h param.h upam.h structs.h
1840 X       $(CC) $(CFLAGS) -c -DFASTM -DTFAST  initfa.c /Foinit_tfm.obj
1841 X
1842 init_tfa.obj : initfa.c defs.h param.h upam.h structs.h
1843 X       $(CC) $(CFLAGS) -c -DFASTA -DTFAST initfa.c /Foinit_tfa.obj
1844 X
1845 init_fx.obj : initfa.c defs.h param.h upam.h structs.h
1846 X       $(CC) $(CFLAGS) -c -DFASTX initfa.c /Foinit_fx.obj
1847 X
1848 init_tfx.obj : initfa.c defs.h param.h upam.h structs.h
1849 X       $(CC) $(CFLAGS) -c -DFASTX -DTFAST initfa.c /Foinit_tfx.obj
1850 X
1851 init_fy.obj : initfa.c defs.h param.h upam.h structs.h
1852 X       $(CC) $(CFLAGS) -c -DFASTY initfa.c /Foinit_fy.obj
1853 X
1854 init_tfy.obj : initfa.c defs.h param.h upam.h structs.h
1855 X       $(CC) $(CFLAGS) -c -DFASTY -DTFAST initfa.c /Foinit_tfy.obj
1856 X
1857 #================ miscellaneous
1858 X
1859 htime.obj : htime.c
1860 X       $(CC) $(CFLAGS) -c htime.c
1861 X
1862 compacc.obj : compacc.c upam.h uascii.h param.h structs.h $(MWH) defs.h
1863 X       $(CC) $(CFLAGS) -c compacc.c
1864 X
1865 pssm_asn_subs.obj : pssm_asn_subs.c defs.h
1866 X       $(CC) $(CFLAGS) -c pssm_asn_subs.c
1867 X
1868 #================ display list of best hits / alignments
1869 X
1870 showbest.obj : $(SHOWBESTC) $(MWH) defs.h param.h structs.h  aln_structs.h drop_func.h
1871 X       $(CC) $(CFLAGS) -c $(SHOWBESTC) /Foshowbest.obj
1872 X
1873 showrss.obj : showrss.c $(MWH) defs.h param.h structs.h  aln_structs.h drop_func.h
1874 X       $(CC) $(CFLAGS) -c showrss.c
1875 X
1876 showun.obj : mshowbest.c $(MWH) defs.h aln_structs.h drop_func.h
1877 X       $(CC) $(CFLAGS) -c -DSHOWUN mshowbest.c /Foshowun.obj
1878 X
1879 showrel.obj : $(SHOWBESTC) $(MWH) defs.h aln_structs.h drop_func.h
1880 X       $(CC) $(CFLAGS) -c -DSHOWREL $(SHOWBESTC) /Foshowrel.obj
1881 X
1882 showsum.obj : showsum.c $(MWH) defs.h drop_func.h
1883 X       $(CC) $(CFLAGS) -c showsum.c
1884 X
1885 $(SHOWALIGN).obj : $(SHOWALIGN).c $(MWHP) defs.h structs.h param.h aln_structs.h drop_func.h
1886 X       $(CC) $(CFLAGS) -c $(SHOWALIGN).c /Fo$(SHOWALIGN).obj
1887 X
1888 $(SHOWALIGN)_u.obj : $(SHOWALIGN).c $(MWHP) defs.h structs.h param.h aln_structs.h drop_func.h
1889 X       $(CC) $(CFLAGS) -DSHOWUN -c /Fo$(SHOWALIGN)_u.obj $(SHOWALIGN).c
1890 re_getlib.obj : re_getlib.c mw.h mm_file.h
1891 X       $(CC) $(CFLAGS) -c re_getlib.c
1892 X
1893 lib_sel.obj : lib_sel.c defs.h structs.h
1894 X       $(CC) $(CFLAGS) -c lib_sel.c
1895 X
1896 c_dispn.obj : c_dispn.c defs.h structs.h param.h 
1897 X       $(CC) $(CFLAGS) -c c_dispn.c
1898 X
1899 #================ statistical functions
1900 X
1901 karlin.obj : karlin.c param.h
1902 X       $(CC) $(CFLAGS) -c karlin.c
1903 X
1904 scaleswn.obj : scaleswn.c defs.h param.h structs.h $(MWH) alt_parms.h
1905 X       $(CC) $(CFLAGS) -c scaleswn.c
1906 X
1907 scaleswtf.obj : scaleswt.c defs.h param.h structs.h $(MWH) alt_parms.h
1908 X       $(CC) $(CFLAGS) -DFASTF -c scaleswt.c /Foscaleswtf.obj
1909 X
1910 scaleswts.obj : scaleswt.c defs.h param.h structs.h $(MWH) alt_parms.h
1911 X       $(CC) $(CFLAGS) -c scaleswt.c /Foscaleswts.obj
1912 X
1913 tatstats_fs.obj : tatstats.c tatstats.h
1914 X       $(CC) $(CFLAGS) -c -DFASTS tatstats.c /Fotatstats_fs.obj
1915 X
1916 tatstats_ff.obj : tatstats.c tatstats.h
1917 X       $(CC) $(CFLAGS) -c -DFASTF tatstats.c /Fotatstats_ff.obj
1918 X
1919 tatstats_fm.obj : tatstats.c tatstats.h
1920 X       $(CC) $(CFLAGS) -c -DFASTM tatstats.c /Fotatstats_fm.obj
1921 X
1922 last_tat.obj : last_tat.c defs.h mm_file.h structs.h param.h
1923 X       $(CC) $(CFLAGS) -c last_tat.c
1924 X
1925 #================ drop functions - actual scores/alignments
1926 X
1927 drop_nfa.obj : dropnfa.c dropnfa.h param.h defs.h drop_func.h
1928 X       $(CC) $(CFLAGS) -c dropnfa.c /Fodrop_nfa.obj
1929 X
1930 # drop_ff, _fs, _fm must define FASTF, FASTS, and FASTM to ensure
1931 # that tatstats.h is built appropriately
1932 X
1933 drop_ff.obj : dropff2.c param.h defs.h tatstats.h drop_func.h
1934 X       $(CC) $(CFLAGS) -DFASTF -c dropff2.c /Fodrop_ff.obj
1935 X
1936 drop_tff.obj : dropff2.c param.h defs.h tatstats.h drop_func.h
1937 X       $(CC) $(CFLAGS) -DFASTF -DTFAST -c dropff2.c /Fodrop_tff.obj
1938 X
1939 drop_ff2.obj : dropff2.c param.h defs.h tatstats.h drop_func.h
1940 X       $(CC) $(CFLAGS) -c -DFASTF  dropff2.c /Fodrop_ff2.obj
1941 X
1942 drop_tff2.obj : dropff2.c param.h defs.h tatstats.h drop_func.h
1943 X       $(CC) $(CFLAGS) -c -DFASTF -DTFAST dropff2.c /Fodrop_tff.obj
1944 X
1945 drop_fs.obj : dropfs2.c param.h defs.h tatstats.h drop_func.h
1946 X       $(CC) $(CFLAGS) -DFASTS -c dropfs2.c /Fodrop_fs.obj
1947 X
1948 drop_tfs.obj : dropfs2.c param.h defs.h drop_func.h
1949 X       $(CC) $(CFLAGS) -c -DTFAST -DFASTS dropfs2.c /Fodrop_tfs.obj
1950 X
1951 drop_fm.obj : dropfs2.c param.h defs.h drop_func.h
1952 X       $(CC) $(CFLAGS) -c -DFASTM dropfs2.c /Fodrop_fm.obj
1953 X
1954 drop_tfm.obj : dropfs2.c param.h defs.h drop_func.h
1955 X       $(CC) $(CFLAGS) -c -DTFAST -DFASTM dropfs2.c /Fodrop_tfm.obj
1956 X
1957 drop_tfa.obj : dropnfa.c dropnfa.h upam.h param.h defs.h
1958 X       $(CC) $(CFLAGS) -c -DTFASTA dropnfa.c /Fodrop_tfa.obj
1959 X
1960 drop_fx.obj : dropfx.c upam.h param.h defs.h drop_func.h
1961 X       $(CC) $(CFLAGS) -c dropfx.c /Fodrop_fx.obj
1962 X
1963 drop_tfx.obj : dropfx.c upam.h param.h defs.h drop_func.h
1964 X       $(CC) $(CFLAGS) -c -DTFAST dropfx.c /Fodrop_tfx.obj
1965 X
1966 drop_fz.obj : dropfz2.c upam.h param.h defs.h aamap.h drop_func.h
1967 X       $(CC) $(CFLAGS) -c dropfz2.c /Fodrop_fz.obj
1968 X
1969 drop_tfz.obj : dropfz2.c upam.h param.h defs.h aamap.h drop_func.h
1970 X       $(CC) $(CFLAGS) -c -DTFAST dropfz2.c /Fodrop_tfz.obj
1971 X
1972 dropnsw.obj : dropnsw.c upam.h param.h structs.h drop_func.h
1973 X       $(CC) $(CFLAGS) -c dropnsw.c
1974 X
1975 dropgsw.obj : dropgsw.c dropgsw.h upam.h param.h structs.h drop_func.h
1976 X       $(CC) $(CFLAGS) -c dropgsw.c
1977 X
1978 dropgsw_sse2.obj : dropgsw.c dropgsw.h upam.h param.h structs.h drop_func.h
1979 X       $(CC) $(CFLAGS) -DSW_SSE2 -c dropgsw.c /Fodropgsw_sse2.obj
1980 X
1981 smith_waterman_altivec.obj : smith_waterman_altivec.c smith_waterman_altivec.h dropgsw.h defs.h param.h
1982 X       $(CC) $(CFLAGS) -c smith_waterman_altivec.c
1983 X
1984 smith_waterman_sse2.obj : smith_waterman_sse2.c smith_waterman_sse2.h dropgsw.h defs.h param.h
1985 X       $(CC) $(CFLAGS) -DSW_SSE2 -c smith_waterman_sse2.c
1986 X
1987 dropnw.obj : dropnw.c upam.h param.h structs.h drop_func.h
1988 X       $(CC) $(CFLAGS) -c dropnw.c
1989 X
1990 #================ reading query, libraries
1991 X
1992 getseq.obj : getseq.c defs.h uascii.h structs.h upam.h 
1993 X       $(CC) $(CFLAGS) -c getseq.c
1994 X
1995 llgetaa.obj : llgetaa.c upam.h uascii.h
1996 X       $(CC) $(CFLAGS) -c -DNOLIB llgetaa.c
1997 X
1998 lgetlib.obj : $(NGETLIB).c altlib.h upam.h uascii.h mm_file.h
1999 X       $(CC) $(CFLAGS) -c $(NGETLIB).c /Folgetlib.obj
2000 X
2001 lgetaa_m.obj : mmgetaa.c altlib.h ncbl2_head.h upam.h uascii.h mm_file.h
2002 X       $(CC) $(CFLAGS) -c mmgetaa.c /Folgetaa_m.obj
2003 X
2004 ncbl_lib.obj : ncbl_lib.c ncbl_head.h
2005 X       $(CC) $(CFLAGS) -c ncbl_lib.c
2006 X
2007 ncbl2_mlib.obj : ncbl2_mlib.c ncbl2_head.h mm_file.h
2008 X       $(CC) $(CFLAGS) -c ncbl2_mlib.c
2009 X
2010 mysql_lib.obj : mysql_lib.c mm_file.h
2011 X       $(CC) $(CFLAGS) -c mysql_lib.c
2012 X
2013 pgsql_lib.obj : pgsql_lib.c mm_file.h
2014 X       $(CC) $(CFLAGS) -c pgsql_lib.c
2015 X
2016 #================ threading functions
2017 X
2018 pthr_subs2.obj : pthr_subs2.c thr.h pthr_subs.h
2019 X       $(CC) $(CFLAGS) -c pthr_subs2.c
2020 X
2021 uthr_subs.obj : uthr_subs.c thr.h uthr_subs.h 
2022 X       $(CC) $(CFLAGS) -c uthr_subs.c
2023 X
2024 #================ translation
2025 X
2026 faatran.obj : faatran.c upam.h uascii.h
2027 X       $(CC) $(CFLAGS) -c faatran.c
2028 X
2029 url_subs.obj : url_subs.c structs.h param.h
2030 X       $(CC) $(CFLAGS) -c url_subs.c
2031 X
2032 $(NRAND).obj : $(NRAND).c
2033 X       $(CC) $(CFLAGS) -c $(NRAND).c
2034 #================ pvm/mpi specific functions
2035 X
2036 hostacc.obj : hostacc.c upam.h uascii.h
2037 X       $(CC) $(CFLAGS) hostacc.c
2038 X
2039 workacc.obj : workacc.c upam.h uascii.h param.h
2040 X       $(NCC) $(CFLAGS) workacc.c /Foworkacc.obj
2041 X
2042 #================ windows getopt()
2043 X
2044 getopt.obj : getopt.c
2045 X       $(CC) $(CFLAGS) -c getopt.c
2046 SHAR_EOF
2047 chmod 0755 Makefile.nm_fcom ||
2048 echo 'restore of Makefile.nm_fcom failed'
2049 Wc_c="`wc -c < 'Makefile.nm_fcom'`"
2050 test 8182 -eq "$Wc_c" ||
2051         echo 'Makefile.nm_fcom: original size 8182, current size' "$Wc_c"
2052 fi
2053 # ============= Makefile.nm_pcom ==============
2054 if test -f 'Makefile.nm_pcom' -a X"$1" != X"-c"; then
2055         echo 'x - skipping Makefile.nm_pcom (File already exists)'
2056 else
2057 echo 'x - extracting Makefile.nm_pcom (Text)'
2058 sed 's/^X//' << 'SHAR_EOF' > 'Makefile.nm_pcom' &&
2059 X
2060 SHOWBESTC = mshowbest.c
2061 SHOWALIGN = mshowalign
2062 MWH = mw.h 
2063 MWHP = mw.h
2064 X
2065 TPROGS = ssearch34_t.exe ssearch34sse2_t.exe fasta34_t.exe fasts34_t.exe fastx34_t.exe tfastx34_t.exe fasty34_t.exe tfasty34_t.exe tfasts34_t.exe fastm34_t.exe fastf34_t.exe tfastf34_t.exe prss34_t.exe prss34sse2_t.exe prfx34_t.exe
2066 X
2067 SPROGS = fasta34.exe ssearch34.exe ssearch34sse2.exe fasts34.exe fastx34.exe tfastx34.exe fasty34.exe tfasty34.exe tfasts34.exe fastm34.exe tfastm34.exe prss34.exe prss34sse2.exe prfx34.exe fastf34.exe tfastf34.exe
2068 X
2069 MAPROGS = map_db.exe
2070 X
2071 XXTPROGS = fastx34_t.exe tfastx34_t.exe fasty34_t.exe tfasty34_t.exe
2072 XXPROGS = fastx34.exe tfastx34.exe .exe fasty34 tfasty34.exe
2073 X
2074 PROGS = $(SPROGS) $(TPROGS)
2075 X
2076 all : $(PROGS)
2077 X
2078 tall: $(TPROGS)
2079 X
2080 sall: $(SPROGS)
2081 X
2082 xall: $(XTPROGS) $(XPROGS) $(ZTPROGS) $(ZPROGS) 
2083 X
2084 clean-up:
2085 X       del *.obj $(PROGS)
2086 X
2087 install: $(PROGS)
2088 X       copy $(PROGS) $(XDIR)
2089 X
2090 sinstall: $(SPROGS)
2091 X       copy $(SPROGS) $(XDIR)
2092 X
2093 tinstall: $(TPROGS)
2094 X       cp $(TPROGS) $(XDIR)
2095 X
2096 fasta34.exe : $(COMP_LIBO) compacc.obj showbest.obj re_getlib.obj $(SHOWALIGN).obj htime.obj apam.obj doinit.obj init_fa.obj scaleswn.obj karlin.obj $(DROPNFA_O) $(LGETLIB) c_dispn.obj $(NCBL_LIB) lib_sel.obj $(NRAND).obj url_subs.obj getopt.obj
2097 X       $(CL) /Fefasta34.exe $(COMP_LIBO) compacc.obj showbest.obj re_getlib.obj $(SHOWALIGN).obj htime.obj apam.obj doinit.obj init_fa.obj $(DROPNFA_O) scaleswn.obj karlin.obj $(LGETLIB) c_dispn.obj $(NCBL_LIB) lib_sel.obj url_subs.obj $(NRAND).obj getopt.obj
2098 X
2099 fastx34.exe : $(COMP_LIBO) compacc.obj showbest.obj re_getlib.obj $(SHOWALIGN).obj htime.obj apam.obj doinit.obj init_fx.obj scaleswn.obj karlin.obj drop_fx.obj $(LGETLIB) c_dispn.obj $(NCBL_LIB) lib_sel.obj faatran.obj url_subs.obj $(NRAND).obj getopt.obj
2100 X       $(CL) /Fefastx34.exe $(COMP_LIBO) compacc.obj showbest.obj re_getlib.obj $(SHOWALIGN).obj htime.obj apam.obj doinit.obj init_fx.obj drop_fx.obj scaleswn.obj karlin.obj $(LGETLIB) c_dispn.obj $(NCBL_LIB) lib_sel.obj faatran.obj url_subs.obj $(NRAND).obj getopt.obj
2101 X
2102 fasty34.exe : $(COMP_LIBO) compacc.obj showbest.obj re_getlib.obj $(SHOWALIGN).obj htime.obj apam.obj doinit.obj init_fy.obj scaleswn.obj karlin.obj drop_fz.obj $(LGETLIB) c_dispn.obj $(NCBL_LIB) lib_sel.obj faatran.obj url_subs.obj $(NRAND).obj getopt.obj
2103 X       $(CL) /Fefasty34.exe $(COMP_LIBO) compacc.obj showbest.obj re_getlib.obj $(SHOWALIGN).obj htime.obj apam.obj doinit.obj init_fy.obj drop_fz.obj scaleswn.obj karlin.obj $(LGETLIB) c_dispn.obj $(NCBL_LIB) lib_sel.obj faatran.obj url_subs.obj $(NRAND).obj getopt.obj
2104 X
2105 fastf34.exe : $(COMP_LIBO) compacc.obj showbest.obj re_getlib.obj $(SHOWALIGN).obj htime.obj apam.obj doinit.obj init_ff.obj scaleswts.obj last_tat.obj tatstats_ff.obj karlin.obj drop_ff.obj $(LGETLIB) c_dispn.obj $(NCBL_LIB) lib_sel.obj $(NRAND).obj url_subs.obj getopt.obj
2106 X       $(CL) /Fefastf34.exe $(COMP_LIBO) compacc.obj showbest.obj re_getlib.obj $(SHOWALIGN).obj htime.obj apam.obj doinit.obj init_ff.obj drop_ff.obj scaleswts.obj last_tat.obj tatstats_ff.obj karlin.obj $(LGETLIB) c_dispn.obj $(NCBL_LIB) lib_sel.obj $(NRAND).obj url_subs.obj getopt.obj
2107 X
2108 fastf34u : $(COMP_LIBO) compacc.obj showun.obj $(SHOWALIGN).obj htime.obj apam.obj doinit.obj init_ff.obj scaleswtf.obj karlin.obj drop_ff.obj $(LGETLIB) c_dispn.obj $(NCBL_LIB) lib_sel.obj $(NRAND).obj url_subs.obj getopt.obj
2109 X       $(CL) /Fefastf34u.exe $(COMP_LIBO) compacc.obj showun.obj $(SHOWALIGN).obj htime.obj apam.obj doinit.obj init_ff.obj drop_ff.obj scaleswtf.obj karlin.obj $(LGETLIB) c_dispn.obj $(NCBL_LIB) lib_sel.obj $(NRAND).obj url_subs.obj getopt.obj
2110 X
2111 fastf34s : $(COMP_LIBO) compacc.obj showsum.obj $(SHOWALIGN).obj htime.obj apam.obj doinit.obj init_ff.obj scaleswtf.obj karlin.obj drop_ff.obj $(LGETLIB) c_dispn.obj $(NCBL_LIB) lib_sel.obj $(NRAND).obj url_subs.obj getopt.obj
2112 X       $(CL) /Fefastf34s.exe $(COMP_LIBO) compacc.obj showsum.obj $(SHOWALIGN).obj htime.obj apam.obj doinit.obj init_ff.obj drop_ff.obj scaleswtf.obj karlin.obj $(LGETLIB) c_dispn.obj $(NCBL_LIB) lib_sel.obj $(NRAND).obj url_subs.obj getopt.obj
2113 X
2114 fasts34.exe : $(COMP_LIBO) compacc.obj showbest.obj re_getlib.obj $(SHOWALIGN).obj htime.obj apam.obj doinit.obj init_fs.obj scaleswts.obj last_tat.obj tatstats_fs.obj karlin.obj drop_fs.obj $(LGETLIB) c_dispn.obj $(NCBL_LIB) lib_sel.obj $(NRAND).obj url_subs.obj getopt.obj
2115 X       $(CL) /Fefasts34.exe $(COMP_LIBO) compacc.obj showbest.obj re_getlib.obj $(SHOWALIGN).obj htime.obj apam.obj doinit.obj init_fs.obj drop_fs.obj scaleswts.obj last_tat.obj tatstats_fs.obj karlin.obj $(LGETLIB) c_dispn.obj $(NCBL_LIB) lib_sel.obj $(NRAND).obj url_subs.obj getopt.obj
2116 X
2117 fastm34.exe : $(COMP_LIBO) compacc.obj showbest.obj re_getlib.obj $(SHOWALIGN).obj htime.obj apam.obj doinit.obj init_fm.obj scaleswts.obj last_tat.obj tatstats_fm.obj karlin.obj drop_fm.obj $(LGETLIB) c_dispn.obj $(NCBL_LIB) lib_sel.obj $(NRAND).obj url_subs.obj getopt.obj
2118 X       $(CL) /Fefastm34.exe $(COMP_LIBO) compacc.obj showbest.obj re_getlib.obj $(SHOWALIGN).obj htime.obj apam.obj doinit.obj init_fm.obj drop_fm.obj scaleswts.obj last_tat.obj tatstats_fm.obj karlin.obj $(LGETLIB) c_dispn.obj $(NCBL_LIB) lib_sel.obj $(NRAND).obj url_subs.obj getopt.obj
2119 X
2120 tfastx34.exe : $(COMP_LIBO) compacc.obj showbest.obj re_getlib.obj $(SHOWALIGN).obj htime.obj apam.obj doinit.obj init_tfx.obj scaleswn.obj karlin.obj drop_tfx.obj $(LGETLIB) c_dispn.obj $(NCBL_LIB) lib_sel.obj faatran.obj url_subs.obj $(NRAND).obj getopt.obj
2121 X       $(CL) /Fetfastx34.exe $(COMP_LIBO) compacc.obj showbest.obj re_getlib.obj $(SHOWALIGN).obj htime.obj apam.obj doinit.obj init_tfx.obj drop_tfx.obj scaleswn.obj karlin.obj $(LGETLIB) c_dispn.obj $(NCBL_LIB) lib_sel.obj faatran.obj url_subs.obj $(NRAND).obj getopt.obj
2122 X
2123 tfasty34.exe : $(COMP_LIBO) compacc.obj showbest.obj re_getlib.obj $(SHOWALIGN).obj htime.obj apam.obj doinit.obj init_tfy.obj scaleswn.obj karlin.obj drop_tfz.obj $(LGETLIB) c_dispn.obj $(NCBL_LIB) lib_sel.obj faatran.obj url_subs.obj $(NRAND).obj getopt.obj
2124 X       $(CL) /Fetfasty34.exe $(COMP_LIBO) compacc.obj showbest.obj re_getlib.obj $(SHOWALIGN).obj htime.obj apam.obj doinit.obj init_tfy.obj drop_tfz.obj scaleswn.obj karlin.obj $(LGETLIB) c_dispn.obj $(NCBL_LIB) lib_sel.obj faatran.obj url_subs.obj $(NRAND).obj getopt.obj
2125 X
2126 tfastf34.exe : $(COMP_LIBO) compacc.obj showbest.obj re_getlib.obj $(SHOWALIGN).obj htime.obj apam.obj doinit.obj init_tf.obj scaleswtf.obj last_tat.obj tatstats_ff.obj karlin.obj drop_tff.obj $(LGETLIB) c_dispn.obj $(NCBL_LIB) lib_sel.obj faatran.obj $(NRAND).obj url_subs.obj getopt.obj
2127 X       $(CL) /Fetfastf34.exe $(COMP_LIBO) compacc.obj showbest.obj re_getlib.obj $(SHOWALIGN).obj htime.obj apam.obj doinit.obj init_tf.obj drop_tff.obj scaleswtf.obj last_tat.obj tatstats_ff.obj karlin.obj $(LGETLIB) c_dispn.obj $(NCBL_LIB) lib_sel.obj faatran.obj $(NRAND).obj url_subs.obj getopt.obj
2128 X
2129 tfastf34s : $(COMP_LIBO) compacc.obj showsum.obj $(SHOWALIGN).obj htime.obj apam.obj doinit.obj init_tf.obj scaleswtf.obj karlin.obj drop_tff.obj $(LGETLIB) c_dispn.obj $(NCBL_LIB) lib_sel.obj faatran.obj $(NRAND).obj url_subs.obj getopt.obj
2130 X       $(CL) /Fetfastf34s.exe $(COMP_LIBO) compacc.obj showsum.obj $(SHOWALIGN).obj htime.obj apam.obj doinit.obj init_tf.obj drop_tff.obj scaleswtf.obj karlin.obj $(LGETLIB) c_dispn.obj $(NCBL_LIB) lib_sel.obj faatran.obj $(NRAND).obj url_subs.obj getopt.obj
2131 X
2132 tfasts34.exe : $(COMP_LIBO) compacc.obj showbest.obj re_getlib.obj $(SHOWALIGN).obj htime.obj apam.obj doinit.obj init_tfs.obj scaleswts.obj tatstats_fs.obj last_tat.obj karlin.obj drop_tfs.obj $(LGETLIB) c_dispn.obj $(NCBL_LIB) lib_sel.obj faatran.obj $(NRAND).obj url_subs.obj getopt.obj
2133 X       $(CL) /Fetfasts34.exe $(COMP_LIBO) compacc.obj showbest.obj re_getlib.obj $(SHOWALIGN).obj htime.obj apam.obj doinit.obj init_tfs.obj drop_tfs.obj scaleswts.obj tatstats_fs.obj last_tat.obj karlin.obj $(LGETLIB) c_dispn.obj $(NCBL_LIB) lib_sel.obj faatran.obj $(NRAND).obj url_subs.obj getopt.obj
2134 X
2135 tfastm34.exe : $(COMP_LIBO) compacc.obj showbest.obj re_getlib.obj $(SHOWALIGN).obj htime.obj apam.obj doinit.obj init_tfm.obj scaleswts.obj tatstats_fm.obj last_tat.obj karlin.obj drop_tfm.obj $(LGETLIB) c_dispn.obj $(NCBL_LIB) lib_sel.obj faatran.obj $(NRAND).obj url_subs.obj getopt.obj
2136 X       $(CL) /Fetfastm34.exe $(COMP_LIBO) compacc.obj showbest.obj re_getlib.obj $(SHOWALIGN).obj htime.obj apam.obj doinit.obj init_tfm.obj drop_tfm.obj scaleswts.obj tatstats_fm.obj last_tat.obj karlin.obj $(LGETLIB) c_dispn.obj $(NCBL_LIB) lib_sel.obj faatran.obj $(NRAND).obj url_subs.obj getopt.obj
2137 X
2138 ssearch34.exe : $(COMP_LIBO) compacc.obj showbest.obj re_getlib.obj $(SHOWALIGN).obj htime.obj apam.obj doinit.obj init_sw.obj scaleswn.obj karlin.obj $(DROPGSW_O) $(LGETLIB) c_dispn.obj $(NCBL_LIB) lib_sel.obj url_subs.obj $(NRAND).obj pssm_asn_subs.obj getopt.obj
2139 X       $(CL) /Fessearch34.exe $(COMP_LIBO) compacc.obj showbest.obj re_getlib.obj $(SHOWALIGN).obj htime.obj apam.obj doinit.obj init_sw.obj $(DROPGSW_O) scaleswn.obj karlin.obj $(LGETLIB) c_dispn.obj $(NCBL_LIB) lib_sel.obj url_subs.obj $(NRAND).obj pssm_asn_subs.obj getopt.obj
2140 X
2141 ssearch34sse2.exe : $(COMP_LIBO) compacc.obj showbest.obj re_getlib.obj $(SHOWALIGN).obj htime.obj apam.obj doinit.obj init_sw.obj scaleswn.obj karlin.obj $(DROPGSW_SSE2_O) $(LGETLIB) c_dispn.obj $(NCBL_LIB) lib_sel.obj url_subs.obj $(NRAND).obj pssm_asn_subs.obj getopt.obj
2142 X       $(CL) /Fessearch34sse2.exe $(COMP_LIBO) compacc.obj showbest.obj re_getlib.obj $(SHOWALIGN).obj htime.obj apam.obj doinit.obj init_sw.obj $(DROPGSW_SSE2_O) scaleswn.obj karlin.obj $(LGETLIB) c_dispn.obj $(NCBL_LIB) lib_sel.obj url_subs.obj $(NRAND).obj pssm_asn_subs.obj getopt.obj
2143 X
2144 osearch34.exe : $(COMP_LIBO) compacc.obj showbest.obj re_getlib.obj $(SHOWALIGN).obj htime.obj apam.obj doinit.obj init_ssw.obj scaleswn.obj karlin.obj dropnsw.obj $(LGETLIB) c_dispn.obj $(NCBL_LIB) lib_sel.obj url_subs.obj $(NRAND).obj getopt.obj
2145 X       $(CL) /Feosearch34.exe $(COMP_LIBO) compacc.obj showbest.obj re_getlib.obj $(SHOWALIGN).obj htime.obj apam.obj doinit.obj init_ssw.obj dropnsw.obj scaleswn.obj karlin.obj $(LGETLIB) c_dispn.obj $(NCBL_LIB) lib_sel.obj url_subs.obj $(NRAND).obj getopt.obj
2146 X
2147 usearch34.exe : $(COMP_LIBO) compacc.obj showbest.obj re_getlib.obj $(SHOWALIGN).obj htime.obj apam.obj doinit.obj init_sw.obj scaleswn.obj karlin.obj dropnsw.obj $(LGETLIB) c_dispn.obj $(NCBL_LIB) lib_sel.obj url_subs.obj $(NRAND).obj getopt.obj
2148 X       $(CL) /Feusearch34.exe $(COMP_LIBO) compacc.obj showbest.obj re_getlib.obj $(SHOWALIGN).obj htime.obj apam.obj doinit.obj init_sw.obj dropnsw.obj scaleswn.obj karlin.obj $(LGETLIB) c_dispn.obj $(NCBL_LIB) lib_sel.obj url_subs.obj $(NRAND).obj getopt.obj
2149 X
2150 prss34.exe : rcomp_lib.obj compacc.obj htime.obj apam.obj doinit.obj init_rss.obj scaleswn.obj karlin.obj $(DROPRSS_O) llgetaa.obj showbest.obj mshowalign.obj c_dispn.obj lib_sel.obj url_subs.obj $(NRAND).obj pssm_asn_subs.obj
2151 X       $(CL) /Feprss34.exe rcomp_lib.obj compacc.obj htime.obj apam.obj doinit.obj init_rss.obj $(DROPRSS_O) scaleswn.obj karlin.obj llgetaa.obj showbest.obj mshowalign.obj c_dispn.obj lib_sel.obj url_subs.obj $(NRAND).obj pssm_asn_subs.obj getopt.obj
2152 X
2153 prss34sse2.exe : rcomp_lib.obj compacc.obj htime.obj apam.obj doinit.obj init_rss.obj scaleswn.obj karlin.obj $(DROPRSS_SSE2_O) llgetaa.obj showbest.obj mshowalign.obj c_dispn.obj lib_sel.obj url_subs.obj $(NRAND).obj pssm_asn_subs.obj
2154 X       $(CL) /Feprss34sse2.exe rcomp_lib.obj compacc.obj htime.obj apam.obj doinit.obj init_rss.obj $(DROPRSS_SSE2_O) scaleswn.obj karlin.obj llgetaa.obj showbest.obj mshowalign.obj c_dispn.obj lib_sel.obj url_subs.obj $(NRAND).obj pssm_asn_subs.obj getopt.obj
2155 X
2156 prfx34.exe : rcomp_lib.obj compacc.obj htime.obj apam.obj doinit.obj init_rfx.obj scaleswn.obj karlin.obj drop_fx.obj llgetaa.obj showbest.obj mshowalign.obj c_dispn.obj lib_sel.obj url_subs.obj $(NRAND).obj faatran.obj
2157 X       $(CL) /Feprfx34.exe rcomp_lib.obj compacc.obj htime.obj apam.obj doinit.obj init_rfx.obj drop_fx.obj scaleswn.obj karlin.obj llgetaa.obj showbest.obj mshowalign.obj c_dispn.obj lib_sel.obj faatran.obj url_subs.obj $(NRAND).obj getopt.obj
2158 X
2159 prss34o : rcomp_lib.obj compacc.obj htime.obj apam.obj doinit.obj init_rss.obj scaleswn.obj karlin.obj $(DROPRSS_O) llgetaa.obj showrss.obj lib_sel.obj $(NRAND).obj pssm_asn_subs.obj
2160 X       $(CL) /Feprss34o.exe rcomp_lib.obj compacc.obj htime.obj apam.obj doinit.obj init_rss.obj $(DROPRSS_O) scaleswn.obj karlin.obj llgetaa.obj showrss.obj lib_sel.obj $(NRAND).obj pssm_asn_subs.obj getopt.obj
2161 X
2162 prfx34o : rcomp_lib.obj compacc.obj htime.obj apam.obj doinit.obj init_rfx.obj scaleswn.obj karlin.obj drop_fx.obj llgetaa.obj showrss.obj lib_sel.obj $(NRAND).obj faatran.obj
2163 X       $(CL) /Feprfx34o.exe rcomp_lib.obj compacc.obj htime.obj apam.obj doinit.obj init_rfx.obj drop_fx.obj scaleswn.obj karlin.obj llgetaa.obj showrss.obj lib_sel.obj faatran.obj $(NRAND).obj getopt.obj
2164 X
2165 ssearch34_t.exe : $(COMP_THRO) work_thr.obj $(THR_SUBS).obj compacc.obj showbest.obj re_getlib.obj $(SHOWALIGN).obj htime.obj apam.obj doinit.obj init_sw.obj scaleswn.obj karlin.obj $(DROPGSW_O) $(LGETLIB) c_dispn.obj $(NCBL_LIB) lib_sel.obj url_subs.obj $(NRAND).obj pssm_asn_subs.obj getopt.obj
2166 X       $(CL) /Fessearch34_t.exe $(COMP_THRO) work_thr.obj $(THR_SUBS).obj compacc.obj showbest.obj re_getlib.obj $(SHOWALIGN).obj htime.obj apam.obj doinit.obj init_sw.obj $(DROPGSW_O) scaleswn.obj karlin.obj $(LGETLIB) c_dispn.obj $(NCBL_LIB) lib_sel.obj url_subs.obj $(NRAND).obj pssm_asn_subs.obj getopt.obj $(THR_LIBS)
2167 X
2168 ssearch34sse2_t.exe : $(COMP_THRO) work_thr.obj $(THR_SUBS).obj compacc.obj showbest.obj re_getlib.obj $(SHOWALIGN).obj htime.obj apam.obj doinit.obj init_sw.obj scaleswn.obj karlin.obj $(DROPGSW_SSE2_O) $(LGETLIB) c_dispn.obj $(NCBL_LIB) lib_sel.obj url_subs.obj $(NRAND).obj pssm_asn_subs.obj getopt.obj
2169 X       $(CL) /Fessearch34sse2_t.exe $(COMP_THRO) work_thr.obj $(THR_SUBS).obj compacc.obj showbest.obj re_getlib.obj $(SHOWALIGN).obj htime.obj apam.obj doinit.obj init_sw.obj $(DROPGSW_SSE2_O) scaleswn.obj karlin.obj $(LGETLIB) c_dispn.obj $(NCBL_LIB) lib_sel.obj url_subs.obj $(NRAND).obj pssm_asn_subs.obj getopt.obj $(THR_LIBS)
2170 X
2171 osearch34_t.exe : $(COMP_THRO) work_thr.obj $(THR_SUBS).obj compacc.obj showbest.obj re_getlib.obj $(SHOWALIGN).obj htime.obj apam.obj doinit.obj init_sw.obj scaleswn.obj karlin.obj dropnsw.obj $(LGETLIB) c_dispn.obj $(NCBL_LIB) lib_sel.obj url_subs.obj $(NRAND).obj getopt.obj
2172 X       $(CL) /Feosearch34_t.exe $(COMP_THRO) work_thr.obj $(THR_SUBS).obj compacc.obj showbest.obj re_getlib.obj $(SHOWALIGN).obj htime.obj apam.obj doinit.obj init_sw.obj dropnsw.obj scaleswn.obj karlin.obj $(LGETLIB) c_dispn.obj $(NCBL_LIB) lib_sel.obj url_subs.obj $(NRAND).obj getopt.obj $(THR_LIBS)
2173 X
2174 usearch34_t.exe : $(COMP_THRO) work_thr.obj $(THR_SUBS).obj compacc.obj showbest.obj re_getlib.obj $(SHOWALIGN).obj htime.obj apam.obj doinit.obj init_sw.obj scaleswn.obj karlin.obj dropnsw.obj $(LGETLIB) c_dispn.obj $(NCBL_LIB) lib_sel.obj url_subs.obj $(NRAND).obj getopt.obj
2175 X       $(CL) /Feusearch34_t.exe $(COMP_THRO) work_thr.obj $(THR_SUBS).obj compacc.obj showbest.obj re_getlib.obj $(SHOWALIGN).obj htime.obj apam.obj doinit.obj init_sw.obj dropnsw.obj scaleswn.obj karlin.obj $(LGETLIB) c_dispn.obj $(NCBL_LIB) lib_sel.obj url_subs.obj $(NRAND).obj getopt.obj $(THR_LIBS)
2176 X
2177 fasta34_t.exe : $(COMP_THRO) work_thr.obj $(THR_SUBS).obj compacc.obj showbest.obj re_getlib.obj $(SHOWALIGN).obj htime.obj apam.obj doinit.obj init_fa.obj scaleswn.obj karlin.obj $(DROPNFA_O) $(LGETLIB) c_dispn.obj $(NCBL_LIB) lib_sel.obj url_subs.obj $(NRAND).obj getopt.obj
2178 X       $(CL) /Fefasta34_t.exe $(COMP_THRO) work_thr.obj $(THR_SUBS).obj compacc.obj showbest.obj re_getlib.obj $(SHOWALIGN).obj htime.obj apam.obj doinit.obj init_fa.obj $(DROPNFA_O) scaleswn.obj karlin.obj $(LGETLIB) c_dispn.obj $(NCBL_LIB) lib_sel.obj url_subs.obj $(NRAND).obj getopt.obj $(THR_LIBS)
2179 X
2180 fasta34s_t.exe : $(COMP_THRO) work_thr.obj $(THR_SUBS).obj compacc.obj showsum.obj re_getlib.obj $(SHOWALIGN).obj htime.obj apam.obj doinit.obj init_fa.obj scaleswn.obj karlin.obj $(DROPNFA_O) $(LGETLIB) c_dispn.obj $(NCBL_LIB) lib_sel.obj url_subs.obj $(NRAND).obj getopt.obj
2181 X       $(CL) /Fefasta34s_t.exe $(COMP_THRO) work_thr.obj $(THR_SUBS).obj compacc.obj showsum.obj re_getlib.obj $(SHOWALIGN).obj htime.obj apam.obj doinit.obj init_fa.obj $(DROPNFA_O) scaleswn.obj karlin.obj $(LGETLIB) c_dispn.obj $(NCBL_LIB) lib_sel.obj url_subs.obj $(NRAND).obj getopt.obj $(THR_LIBS)
2182 X
2183 fasta34u_t.exe : $(COMP_THRO) work_thr.obj $(THR_SUBS).obj compacc.obj showun.obj $(SHOWALIGN).obj htime.obj apam.obj doinit.obj init_fa.obj scaleswn.obj karlin.obj $(DROPNFA_O) $(LGETLIB) c_dispn.obj $(NCBL_LIB) lib_sel.obj $(NRAND).obj url_subs.obj getopt.obj
2184 X       $(CL) /Fefasta34u_t.exe $(COMP_THRO) work_thr.obj $(THR_SUBS).obj compacc.obj showun.obj $(SHOWALIGN).obj htime.obj apam.obj doinit.obj init_fa.obj $(DROPNFA_O) scaleswn.obj karlin.obj $(LGETLIB) c_dispn.obj $(NCBL_LIB) lib_sel.obj $(NRAND).obj url_subs.obj getopt.obj $(THR_LIBS)
2185 X
2186 fasta34r_t.exe : $(COMP_THRO) work_thr.obj $(THR_SUBS).obj compacc.obj showrel.obj $(SHOWALIGN).obj htime.obj apam.obj doinit.obj init_fa.obj scaleswn.obj karlin.obj $(DROPNFA_O) $(LGETLIB) c_dispn.obj $(NCBL_LIB) lib_sel.obj $(NRAND).obj url_subs.obj getopt.obj
2187 X       $(CL) /Fefasta34r_t.exe $(COMP_THRO) work_thr.obj $(THR_SUBS).obj compacc.obj showrel.obj $(SHOWALIGN).obj htime.obj apam.obj doinit.obj init_fa.obj $(DROPNFA_O) scaleswn.obj karlin.obj $(LGETLIB) c_dispn.obj $(NCBL_LIB) lib_sel.obj $(NRAND).obj url_subs.obj getopt.obj $(THR_LIBS)
2188 X
2189 fastf34_t.exe : $(COMP_THRO) work_thr.obj $(THR_SUBS).obj compacc.obj showbest.obj re_getlib.obj $(SHOWALIGN).obj htime.obj apam.obj doinit.obj init_ff.obj scaleswtf.obj last_tat.obj tatstats_ff.obj karlin.obj drop_ff.obj $(LGETLIB) c_dispn.obj $(NCBL_LIB) lib_sel.obj $(NRAND).obj url_subs.obj getopt.obj
2190 X       $(CL) /Fefastf34_t.exe $(COMP_THRO) work_thr.obj $(THR_SUBS).obj compacc.obj showbest.obj re_getlib.obj $(SHOWALIGN).obj htime.obj apam.obj doinit.obj init_ff.obj drop_ff.obj scaleswtf.obj last_tat.obj tatstats_ff.obj karlin.obj $(LGETLIB) c_dispn.obj $(NCBL_LIB) lib_sel.obj $(NRAND).obj url_subs.obj getopt.obj $(THR_LIBS)
2191 X
2192 fastf34s_t.exe : $(COMP_THRO) work_thr.obj $(THR_SUBS).obj compacc.obj showsum.obj $(SHOWALIGN).obj htime.obj apam.obj doinit.obj init_ff.obj scaleswtf.obj karlin.obj drop_ff.obj $(LGETLIB) c_dispn.obj $(NCBL_LIB) lib_sel.obj $(NRAND).obj url_subs.obj getopt.obj
2193 X       $(CL) /Fefastf34s_t.exe $(COMP_THRO) work_thr.obj $(THR_SUBS).obj compacc.obj showsum.obj $(SHOWALIGN).obj htime.obj apam.obj doinit.obj init_ff.obj drop_ff.obj scaleswtf.obj karlin.obj $(LGETLIB) c_dispn.obj $(NCBL_LIB) lib_sel.obj $(NRAND).obj url_subs.obj getopt.obj $(THR_LIBS)
2194 X
2195 fasts34_t.exe : $(COMP_THRO) work_thr.obj $(THR_SUBS).obj compacc.obj showbest.obj re_getlib.obj $(SHOWALIGN).obj htime.obj apam.obj doinit.obj init_fs.obj scaleswts.obj last_tat.obj tatstats_fs.obj karlin.obj drop_fs.obj $(LGETLIB) c_dispn.obj $(NCBL_LIB) lib_sel.obj $(NRAND).obj url_subs.obj getopt.obj
2196 X       $(CL) /Fefasts34_t.exe $(COMP_THRO) work_thr.obj $(THR_SUBS).obj compacc.obj showbest.obj re_getlib.obj $(SHOWALIGN).obj htime.obj apam.obj doinit.obj init_fs.obj drop_fs.obj scaleswts.obj last_tat.obj tatstats_fs.obj karlin.obj $(LGETLIB) c_dispn.obj $(NCBL_LIB) lib_sel.obj $(NRAND).obj url_subs.obj getopt.obj $(THR_LIBS)
2197 X
2198 fastm34_t.exe : $(COMP_THRO) work_thr.obj $(THR_SUBS).obj compacc.obj showbest.obj re_getlib.obj $(SHOWALIGN).obj htime.obj apam.obj doinit.obj init_fs.obj scaleswts.obj last_tat.obj tatstats_fm.obj karlin.obj drop_fm.obj $(LGETLIB) c_dispn.obj $(NCBL_LIB) lib_sel.obj $(NRAND).obj url_subs.obj getopt.obj
2199 X       $(CL) /Fefastm34_t.exe $(COMP_THRO) work_thr.obj $(THR_SUBS).obj compacc.obj showbest.obj re_getlib.obj $(SHOWALIGN).obj htime.obj apam.obj doinit.obj init_fs.obj drop_fm.obj scaleswts.obj last_tat.obj tatstats_fm.obj karlin.obj $(LGETLIB) c_dispn.obj $(NCBL_LIB) lib_sel.obj $(NRAND).obj url_subs.obj getopt.obj $(THR_LIBS)
2200 X
2201 fastx34_t.exe : $(COMP_THRO) work_thr.obj $(THR_SUBS).obj compacc.obj showbest.obj re_getlib.obj $(SHOWALIGN).obj c_dispn.obj htime.obj apam.obj doinit.obj init_fx.obj faatran.obj scaleswn.obj karlin.obj drop_fx.obj $(LGETLIB) c_dispn.obj $(NCBL_LIB) lib_sel.obj url_subs.obj $(NRAND).obj getopt.obj
2202 X       $(CL) /Fefastx34_t.exe $(COMP_THRO) work_thr.obj $(THR_SUBS).obj compacc.obj showbest.obj re_getlib.obj $(SHOWALIGN).obj htime.obj apam.obj doinit.obj init_fx.obj drop_fx.obj faatran.obj scaleswn.obj karlin.obj $(LGETLIB) c_dispn.obj $(NCBL_LIB) lib_sel.obj url_subs.obj $(NRAND).obj getopt.obj $(THR_LIBS)
2203 X
2204 fasty34_t.exe : $(COMP_THRO) work_thr.obj $(THR_SUBS).obj compacc.obj showbest.obj re_getlib.obj $(SHOWALIGN).obj c_dispn.obj htime.obj apam.obj doinit.obj init_fy.obj faatran.obj scaleswn.obj karlin.obj drop_fz.obj $(LGETLIB) c_dispn.obj $(NCBL_LIB) lib_sel.obj url_subs.obj $(NRAND).obj getopt.obj
2205 X       $(CL) /Fefasty34_t.exe $(COMP_THRO) work_thr.obj $(THR_SUBS).obj compacc.obj showbest.obj re_getlib.obj $(SHOWALIGN).obj htime.obj apam.obj doinit.obj init_fy.obj drop_fz.obj faatran.obj scaleswn.obj karlin.obj $(LGETLIB) c_dispn.obj $(NCBL_LIB) lib_sel.obj url_subs.obj $(NRAND).obj getopt.obj $(THR_LIBS)
2206 X
2207 tfasta34.exe : $(COMP_LIBO) compacc.obj showbest.obj re_getlib.obj $(SHOWALIGN).obj htime.obj apam.obj doinit.obj init_tfa.obj scaleswn.obj karlin.obj $(DROPTFA_O) $(LGETLIB) c_dispn.obj $(NCBL_LIB) lib_sel.obj faatran.obj url_subs.obj $(NRAND).obj getopt.obj
2208 X       $(CL) /Fetfasta34.exe $(COMP_LIBO) compacc.obj showbest.obj re_getlib.obj $(SHOWALIGN).obj htime.obj apam.obj doinit.obj init_tfa.obj $(DROPTFA_O) scaleswn.obj karlin.obj $(LGETLIB) c_dispn.obj $(NCBL_LIB) lib_sel.obj faatran.obj url_subs.obj $(NRAND).obj getopt.obj
2209 X
2210 tfasta34_t.exe : $(COMP_THRO) work_thr.obj $(THR_SUBS).obj compacc.obj showbest.obj re_getlib.obj $(SHOWALIGN).obj c_dispn.obj htime.obj apam.obj doinit.obj init_tfa.obj scaleswn.obj karlin.obj $(DROPTFA_O) $(LGETLIB) c_dispn.obj $(NCBL_LIB) lib_sel.obj faatran.obj url_subs.obj $(NRAND).obj getopt.obj
2211 X       $(CL) /Fetfasta34_t.exe $(COMP_THRO) work_thr.obj $(THR_SUBS).obj compacc.obj showbest.obj re_getlib.obj $(SHOWALIGN).obj htime.obj apam.obj doinit.obj init_tfa.obj $(DROPTFA_O) scaleswn.obj karlin.obj $(LGETLIB) c_dispn.obj $(NCBL_LIB) lib_sel.obj faatran.obj url_subs.obj $(NRAND).obj getopt.obj $(THR_LIBS)
2212 X
2213 tfastf34_t.exe : $(COMP_THRO) work_thr.obj $(THR_SUBS).obj compacc.obj showbest.obj re_getlib.obj $(SHOWALIGN).obj c_dispn.obj htime.obj apam.obj doinit.obj init_tf.obj  scaleswtf.obj last_tat.obj tatstats_ff.obj karlin.obj drop_tff.obj $(LGETLIB) c_dispn.obj $(NCBL_LIB) lib_sel.obj faatran.obj $(NRAND).obj url_subs.obj getopt.obj
2214 X       $(CL) /Fetfastf34_t.exe $(COMP_THRO) work_thr.obj $(THR_SUBS).obj compacc.obj showbest.obj re_getlib.obj $(SHOWALIGN).obj htime.obj apam.obj doinit.obj init_tf.obj drop_tff.obj scaleswtf.obj last_tat.obj tatstats_ff.obj karlin.obj $(LGETLIB) c_dispn.obj $(NCBL_LIB) lib_sel.obj faatran.obj $(NRAND).obj url_subs.obj getopt.obj $(THR_LIBS)
2215 X
2216 tfasts34_t.exe : $(COMP_THRO) work_thr.obj $(THR_SUBS).obj compacc.obj showbest.obj re_getlib.obj $(SHOWALIGN).obj c_dispn.obj htime.obj apam.obj doinit.obj init_tfs.obj scaleswts.obj last_tat.obj tatstats_fs.obj karlin.obj drop_tfs.obj $(LGETLIB) c_dispn.obj $(NCBL_LIB) lib_sel.obj faatran.obj $(NRAND).obj url_subs.obj getopt.obj
2217 X       $(CL) /Fetfasts34_t.exe $(COMP_THRO) work_thr.obj $(THR_SUBS).obj compacc.obj showbest.obj re_getlib.obj $(SHOWALIGN).obj htime.obj apam.obj doinit.obj init_tfs.obj drop_tfs.obj scaleswts.obj last_tat.obj tatstats_fs.obj karlin.obj $(LGETLIB) c_dispn.obj $(NCBL_LIB) lib_sel.obj faatran.obj $(NRAND).obj url_subs.obj getopt.obj $(THR_LIBS)
2218 X
2219 tfastx34_t.exe : $(COMP_THRO) work_thr.obj $(THR_SUBS).obj compacc.obj showbest.obj re_getlib.obj $(SHOWALIGN).obj htime.obj apam.obj doinit.obj init_tfx.obj scaleswn.obj karlin.obj drop_tfx.obj $(LGETLIB) c_dispn.obj $(NCBL_LIB) lib_sel.obj faatran.obj url_subs.obj $(NRAND).obj getopt.obj
2220 X       $(CL) /Fetfastx34_t.exe $(COMP_THRO) work_thr.obj $(THR_SUBS).obj compacc.obj showbest.obj re_getlib.obj $(SHOWALIGN).obj htime.obj apam.obj doinit.obj init_tfx.obj drop_tfx.obj scaleswn.obj karlin.obj $(LGETLIB) c_dispn.obj $(NCBL_LIB) lib_sel.obj faatran.obj url_subs.obj $(NRAND).obj getopt.obj $(THR_LIBS)
2221 X
2222 tfasty34_t.exe : $(COMP_THRO) work_thr.obj $(THR_SUBS).obj compacc.obj showbest.obj re_getlib.obj $(SHOWALIGN).obj htime.obj apam.obj doinit.obj init_tfy.obj scaleswn.obj karlin.obj drop_tfz.obj $(LGETLIB) c_dispn.obj $(NCBL_LIB) lib_sel.obj faatran.obj url_subs.obj $(NRAND).obj getopt.obj
2223 X       $(CL) /Fetfasty34_t.exe $(COMP_THRO) work_thr.obj $(THR_SUBS).obj compacc.obj showbest.obj re_getlib.obj $(SHOWALIGN).obj htime.obj apam.obj doinit.obj init_tfy.obj drop_tfz.obj scaleswn.obj karlin.obj $(LGETLIB) c_dispn.obj $(NCBL_LIB) lib_sel.obj faatran.obj url_subs.obj $(NRAND).obj getopt.obj $(THR_LIBS)
2224 X
2225 prss34_t.exe : rcomp_thr.obj work_thr.obj $(THR_SUBS).obj compacc.obj htime.obj apam.obj doinit.obj init_rss.obj scaleswn.obj karlin.obj $(DROPRSS_O) llgetaa.obj showbest.obj $(SHOWALIGN).obj c_dispn.obj url_subs.obj lib_sel.obj $(NRAND).obj pssm_asn_subs.obj
2226 X       $(CL) /Feprss34_t.exe rcomp_thr.obj work_thr.obj $(THR_SUBS).obj compacc.obj htime.obj apam.obj doinit.obj init_rss.obj $(DROPRSS_SSE2_O) scaleswn.obj karlin.obj llgetaa.obj showbest.obj  $(SHOWALIGN).obj c_dispn.obj url_subs.obj lib_sel.obj $(NRAND).obj pssm_asn_subs.obj getopt.obj $(THR_LIBS)
2227 X
2228 prss34sse2_t.exe : rcomp_thr.obj work_thr.obj $(THR_SUBS).obj compacc.obj htime.obj apam.obj doinit.obj init_rss.obj scaleswn.obj karlin.obj $(DROPRSS_O) llgetaa.obj showbest.obj $(SHOWALIGN).obj c_dispn.obj url_subs.obj lib_sel.obj $(NRAND).obj pssm_asn_subs.obj
2229 X       $(CL) /Feprss34sse2_t.exe rcomp_thr.obj work_thr.obj $(THR_SUBS).obj compacc.obj htime.obj apam.obj doinit.obj init_rss.obj $(DROPRSS_SSE2_O) scaleswn.obj karlin.obj llgetaa.obj showbest.obj  $(SHOWALIGN).obj c_dispn.obj url_subs.obj lib_sel.obj $(NRAND).obj pssm_asn_subs.obj getopt.obj $(THR_LIBS)
2230 X
2231 prfx34_t.exe : rcomp_thr.obj work_thr.obj $(THR_SUBS).obj compacc.obj htime.obj apam.obj doinit.obj init_rfx.obj scaleswn.obj karlin.obj drop_fx.obj llgetaa.obj showbest.obj mshowalign.obj c_dispn.obj lib_sel.obj url_subs.obj $(NRAND).obj faatran.obj
2232 X       $(CL) /Feprfx34_t.exe rcomp_thr.obj work_thr.obj $(THR_SUBS).obj compacc.obj htime.obj apam.obj doinit.obj init_rfx.obj drop_fx.obj scaleswn.obj karlin.obj llgetaa.obj showbest.obj mshowalign.obj c_dispn.obj lib_sel.obj faatran.obj url_subs.obj $(NRAND).obj getopt.obj $(THR_LIBS)
2233 X
2234 comp_lib.obj : comp_lib.c mw.h structs.h defs.h param.h
2235 X       $(CC) $(CFLAGS) -c comp_lib.c
2236 X
2237 comp_mlib.obj : comp_lib.c mw.h structs.h defs.h param.h
2238 X       $(CC) $(CFLAGS) -DCOMP_MLIB -c comp_lib.c /Focomp_mlib.obj
2239 X
2240 rcomp_lib.obj : comp_lib.c mw.h structs.h defs.h param.h
2241 X       $(CC) $(CFLAGS) -c -DPRSS comp_lib.c /Forcomp_lib.obj
2242 X
2243 comp_thr.obj : comp_lib.c mw.h structs.h defs.h param.h thr.h
2244 X       $(CC) $(CFLAGS) -DCOMP_THR -c comp_lib.c /Focomp_thr.obj
2245 X
2246 comp_mthr.obj : comp_lib.c mw.h structs.h defs.h param.h thr.h
2247 X       $(CC) $(CFLAGS) -DCOMP_THR -DCOMP_MLIB -c comp_lib.c /Focomp_mthr.obj
2248 X
2249 rcomp_thr.obj : comp_lib.c mw.h structs.h defs.h param.h thr.h
2250 X       $(CC) $(CFLAGS) -DPRSS -DCOMP_THR -c comp_lib.c /Forcomp_thr.obj
2251 X
2252 work_thr.obj : work_thr.c mw.h structs.h defs.h param.h thr.h
2253 X       $(CC) $(CFLAGS) -c work_thr.c
2254 X
2255 print_pssm.exe : print_pssm.c getseq.c karlin.c apam.c
2256 X       $(CC) /Feprint_pssm.exe $(CFLAGS) print_pssm.c getseq.c karlin.c apam.c getopt.obj
2257 X
2258 map_db.exe : map_db.c  uascii.h ncbl2_head.h
2259 X       $(CC) /Femap_db.exe map_db.c
2260 X
2261 list_db.exe : list_db.c
2262 X       $(CC) /Felist_db.exe list_db.c
2263 X
2264 SHAR_EOF
2265 chmod 0755 Makefile.nm_pcom ||
2266 echo 'restore of Makefile.nm_pcom failed'
2267 Wc_c="`wc -c < 'Makefile.nm_pcom'`"
2268 test 27480 -eq "$Wc_c" ||
2269         echo 'Makefile.nm_pcom: original size 27480, current size' "$Wc_c"
2270 fi
2271 # ============= Makefile.nmk_icl ==============
2272 if test -f 'Makefile.nmk_icl' -a X"$1" != X"-c"; then
2273         echo 'x - skipping Makefile.nmk_icl (File already exists)'
2274 else
2275 echo 'x - extracting Makefile.nmk_icl (Text)'
2276 sed 's/^X//' << 'SHAR_EOF' > 'Makefile.nmk_icl' &&
2277 #
2278 # makefile for fasta3, fasta3_t.  Use makefile.pvm for pvcompxx.
2279 #
2280 # options for Intel C compiler (v9.1) 
2281 #
2282 # must be compiled/linked with /MT (or /MTd for debugging) to ensure
2283 # multi-threaded staticly linked executables.  /MD uses dynamic
2284 # linking to DLL's, which may not be available on the users machine
2285 X
2286 CC= icl /O2 /MT /W1
2287 #CC= icl /Zi /MTd /W1
2288 CL= icl /O2 /MT
2289 #CL= icl /Zi /MTd
2290 X
2291 # standard options
2292 CFLAGS= -DSHOWSIM -DWIN32 -DHZ=100 -DPROGRESS -DSAMP_STATS -DPGM_DOC -DTHR_EXIT=pthread_exit -D_CRT_SECURE_NO_WARNINGS=1
2293 X
2294 XXDIR = /seqprg/bin
2295 X
2296 THR_SUBS = pthr_subs2
2297 THR_LIBS= pthreadVC2.lib
2298 X
2299 DROPNFA_O = drop_nfa.obj
2300 DROPGSW_O = dropgsw.obj
2301 DROPGSW_SSE2_O = dropgsw_sse2.obj smith_waterman_sse2.obj
2302 DROPRSS_O = dropnsw.obj
2303 DROPRSS_SSE2_O = dropgsw_sse2.obj smith_waterman_sse2.obj
2304
2305 X
2306 # renamed (fasta33)  programs
2307 include Makefile34.nmk_com
2308 # conventional (fasta3) names
2309 # include Makefile.common
2310 X
2311 SHAR_EOF
2312 chmod 0755 Makefile.nmk_icl ||
2313 echo 'restore of Makefile.nmk_icl failed'
2314 Wc_c="`wc -c < 'Makefile.nmk_icl'`"
2315 test 905 -eq "$Wc_c" ||
2316         echo 'Makefile.nmk_icl: original size 905, current size' "$Wc_c"
2317 fi
2318 # ============= Makefile.os_x ==============
2319 if test -f 'Makefile.os_x' -a X"$1" != X"-c"; then
2320         echo 'x - skipping Makefile.os_x (File already exists)'
2321 else
2322 echo 'x - extracting Makefile.os_x (Text)'
2323 sed 's/^X//' << 'SHAR_EOF' > 'Makefile.os_x' &&
2324 # makefile for fasta3, fasta3_t.  Use makefile.pvm for pvcompxx.
2325 # this file works for DEC Alphas
2326 #
2327 # this file supports mmap()'ed databases in BLAST2 format use -DUSE_MMAP
2328 # for mmap()ed BLAST2 format.
2329 X
2330 # the -DDEBUG option provides additional debugging information, particularly
2331 # with -D on the command line.
2332 X
2333 # use -DBIG_LIB64 to generate 64-bit offsets in map_db .xin files
2334 X
2335 # changed to gcc-3.3 for MacOSX Tiger because of problems with Altivec
2336 #
2337 X
2338 # in my hands, gcc-4.0 is about 40% slower than gcc-3.3 on the Altivec code
2339 #CC= gcc-4.0 -g -falign-loops=32 -O3 -mcpu=7450 -maltivec -mpim-altivec -DSW_ALTIVEC
2340 X
2341 CC= gcc-3.3 -g -falign-loops=32 -O3 -mcpu=7450 -faltivec -DSW_ALTIVEC
2342 #CC= gcc-3.3 -g -DDEBUG -mcpu=7450 -faltivec -DSW_ALTIVEC
2343 #CC= cc -g -Wall -pedantic -faltivec -DSW_ALTIVEC
2344 #
2345 # standard line for normal searching
2346 CFLAGS= -DSHOWSIM -DM10_CONS -DUNIX -DTIMES -DHZ=100 -DMAX_WORKERS=4 -DTHR_EXIT=pthread_exit -DPROGRESS -DFASTA_HOST='"xs00.achs.virginia.edu/fasta_www/cgi"' -DUSE_MMAP -DUSE_FSEEKO -DHAS_INTTYPES -DSAMP_STATS -DPGM_DOC
2347 X
2348 #CFLAGS= -DSHOWSIM -DM10_CONS -DUNIX -DTIMES -DHZ=60 -DMAX_WORKERS=2 -DTHR_EXIT=pthread_exit -DPROGRESS -DFASTA_HOST='"xs00.achs.virginia.edu/fasta_www/cgi"' -DUSE_MMAP -DUSE_FSEEKO -DHAS_INTTYPES -DSAMP_STATS -DPGM_DOC -DSUPERFAMNUM -DSFCHAR="'|'"
2349 X
2350 # add for MySQL support
2351 # -I/usr/local/mysql/include -DMYSQL_DB
2352 X
2353 HFLAGS= -o
2354 NFLAGS= -o
2355 X
2356 #for DEC Unix V4.0 
2357 THR_SUBS = pthr_subs2
2358 THR_LIBS =
2359 THR_CC =
2360 X
2361 #for Sun
2362 #THR_SUBS = uthr_subs2
2363 #THR_LIBS = -lthread
2364 #THR_CC =
2365 #
2366 # for SGI with current pthreads
2367 #THR_SUBS = pthr_subs2
2368 #THR_LIBS = -lpthreads
2369 #THR_CC = 
2370 #
2371 # for IBM with current pthreads
2372 #CC= xlc_r -v -g
2373 #THR_SUBS = ibm_pthr_subs2
2374 #THR_LIBS = -lpthreads
2375 #THR_CC =
2376 X
2377 X
2378 #XDIR = ${HOME}/bin
2379 #XDIR = /home/slib/bin/MACOSX/
2380 #XDIR = /Users/seqprg/bin
2381 XXDIR = /seqprg/bin
2382 #XDIR = ./ppc
2383 X
2384 DROPNFA_O = drop_nfa.o
2385 DROPTFA_O = drop_tfa.o
2386 DROPGSW_O = dropgsw.o smith_waterman_altivec.o
2387 DROPRSS_O = dropgsw.o smith_waterman_altivec.o
2388 #DROPGSW_O = dropgsw.o
2389 #DROPRSS_O = dropgsw.o
2390 X
2391 # provide mysql function
2392 #include Makefile34m.common_sql
2393 X
2394 # no mysql
2395 include Makefile34m.common
2396 SHAR_EOF
2397 chmod 0644 Makefile.os_x ||
2398 echo 'restore of Makefile.os_x failed'
2399 Wc_c="`wc -c < 'Makefile.os_x'`"
2400 test 2116 -eq "$Wc_c" ||
2401         echo 'Makefile.os_x: original size 2116, current size' "$Wc_c"
2402 fi
2403 # ============= Makefile.os_x86 ==============
2404 if test -f 'Makefile.os_x86' -a X"$1" != X"-c"; then
2405         echo 'x - skipping Makefile.os_x86 (File already exists)'
2406 else
2407 echo 'x - extracting Makefile.os_x86 (Text)'
2408 sed 's/^X//' << 'SHAR_EOF' > 'Makefile.os_x86' &&
2409 # makefile for fasta3, fasta3_t.  Use makefile.pvm for pvcompxx.
2410 # this file works for DEC Alphas
2411 #
2412 # this file supports mmap()'ed databases in BLAST2 format use -DUSE_MMAP
2413 # for mmap()ed BLAST2 format.
2414 X
2415 # the -DDEBUG option provides additional debugging information, particularly
2416 # with -D on the command line.
2417 X
2418 # use -DBIG_LIB64 to generate 64-bit offsets in map_db .xin files
2419 X
2420 # changed to gcc-3.3 for MacOSX Tiger because of problems with Altivec
2421 #
2422 X
2423 CC= gcc -g -O3 -DSW_SSE2 -msse2 -arch i386 -isysroot /Developer/SDKs/MacOSX10.4u.sdk 
2424 #CC= gcc -g -DDEBUG
2425 #CC= cc -g -Wall -pedantic
2426 #
2427 # standard line for normal searching
2428 CFLAGS= -DSHOWSIM -DM10_CONS -DUNIX -DTIMES -DHZ=100 -DMAX_WORKERS=4 -DTHR_EXIT=pthread_exit -DPROGRESS -DFASTA_HOST='"xs00.achs.virginia.edu/fasta_www/cgi"' -DIS_LITTLE_ENDIAN -DUSE_MMAP -DUSE_FSEEKO -DHAS_INTTYPES -DSAMP_STATS -DPGM_DOC
2429 X
2430 #CFLAGS= -DSHOWSIM -DM10_CONS -DUNIX -DTIMES -DHZ=60 -DMAX_WORKERS=4 -DTHR_EXIT=pthread_exit -DPROGRESS -DFASTA_HOST='"xs00.achs.virginia.edu/fasta_www/cgi"' -DIS_LITTLE_ENDIAN -DUSE_MMAP -DUSE_FSEEKO -DHAS_INTTYPES -DSAMP_STATS -DPGM_DOC -DSUPERFAMNUM -DSFCHAR="'|'"
2431 X
2432 LDFLAGS= -arch i386
2433 X
2434 # add for MySQL support
2435 # -I/usr/local/mysql/include -DMYSQL_DB
2436 X
2437 HFLAGS= -o
2438 NFLAGS= -o
2439 X
2440 #for DEC Unix V4.0 
2441 THR_SUBS = pthr_subs2
2442 THR_LIBS =
2443 THR_CC =
2444 X
2445 #for Sun
2446 #THR_SUBS = uthr_subs2
2447 #THR_LIBS = -lthread
2448 #THR_CC =
2449 #
2450 # for SGI with current pthreads
2451 #THR_SUBS = pthr_subs2
2452 #THR_LIBS = -lpthreads
2453 #THR_CC = 
2454 #
2455 # for IBM with current pthreads
2456 #CC= xlc_r -v -g
2457 #THR_SUBS = ibm_pthr_subs2
2458 #THR_LIBS = -lpthreads
2459 #THR_CC =
2460 X
2461 X
2462 #XDIR = ${HOME}/bin
2463 #XDIR = /home/slib/bin/MACOSX/
2464 #XDIR = /Users/seqprg/bin
2465 XXDIR = /seqprg/bin
2466 #XDIR = ./i386
2467 X
2468 DROPNFA_O = drop_nfa.o
2469 DROPTFA_O = drop_tfa.o
2470 DROPGSW_O = dropgsw.o smith_waterman_sse2.o
2471 DROPRSS_O = dropgsw.o smith_waterman_sse2.o
2472 X
2473 # provide mysql function
2474 #include Makefile34m.common_sql
2475 X
2476 # no mysql
2477 include Makefile34m.common
2478 SHAR_EOF
2479 chmod 0644 Makefile.os_x86 ||
2480 echo 'restore of Makefile.os_x86 failed'
2481 Wc_c="`wc -c < 'Makefile.os_x86'`"
2482 test 1917 -eq "$Wc_c" ||
2483         echo 'Makefile.os_x86: original size 1917, current size' "$Wc_c"
2484 fi
2485 # ============= Makefile.pLinux ==============
2486 if test -f 'Makefile.pLinux' -a X"$1" != X"-c"; then
2487         echo 'x - skipping Makefile.pLinux (File already exists)'
2488 else
2489 echo 'x - extracting Makefile.pLinux (Text)'
2490 sed 's/^X//' << 'SHAR_EOF' > 'Makefile.pLinux' &&
2491 # $Name: fa_34_26_5 $ - $Id: Makefile.pLinux,v 1.4 2004/11/19 15:28:26 wrp Exp $
2492 #
2493 # makefile for fasta3, fasta3_t.  Use makefile.pvm for pvcompxx.
2494 # this file works for DEC Alphas
2495 #
2496 # this file supports mmap()'ed databases in BLAST2 format use -DUSE_MMAP
2497 # for mmap()ed BLAST2 format.
2498 X
2499 # the -DDEBUG option provides additional debugging information, particularly
2500 # with -D on the command line.
2501 X
2502 # use -DBIG_LIB64 to generate and use 64-bit offsets in map_db .xin
2503 # files
2504 X
2505 # for Tru64 4.0F, no "<inttypes.h>" 4.0G has inttypes.h
2506 X
2507 CC= xlc_r
2508 X
2509 #CC= cc -g3 -O -std1
2510 #CC= insure -g -DDEBUG
2511 #CC= cc -g -DDEBUG -std1
2512 X
2513 #CC= gcc -g -Wall
2514 #
2515 # standard line for normal searching
2516 CFLAGS= -O3 -qtune=auto -qarch=auto -DUNIX -DTIMES -DBIGMEM -DMAX_WORKERS=4 -DSFCHAR="':'" -DTHR_EXIT=pthread_exit -DPROGRESS -DUSE_MMAP -DIS_BIG_ENDIAN -DSAMP_STATS -DPGM_DOC -D_LARGE_FILES -DHAS_INTTYPES -D__pLinux__
2517 #
2518 #(-DMYSQL_DB for mySQL databases)  (also requires change to Makefile34.common)
2519 X
2520 # special options for SUPERFAMLIES
2521 #CFLAGS= -DM10_CONS -DUNIX -DTIMES -DHZ=60 -DBIGMEM -DSFCHAR="'|'" -DMAX_WORKERS=4 -DTHR_EXIT=pthread_exit -DPROGRESS -DSUPERFAMNUM -DIS_LITTLE_ENDIAN -DUSE_MMAP -DMAXBEST=200000
2522
2523 LIB_M = -lm
2524 #LIB_M = -L/usr/local/lib/mysql -lmysqlclient -lm
2525 # for mySQL databases
2526 X
2527 HFLAGS= -o
2528 NFLAGS= -o
2529 X
2530 #for DEC Unix V4.0 
2531 #THR_SUBS = pthr_subs2
2532 #THR_LIBS = -lpthreads
2533 #THR_CC =
2534 X
2535 #for Sun
2536 #THR_SUBS = uthr_subs
2537 #THR_LIBS = -lthread
2538 #THR_CC =
2539 #
2540 # for SGI with current pthreads
2541 #THR_SUBS = pthr_subs
2542 #THR_LIBS = -lpthreads
2543 #THR_CC = 
2544 #
2545 # for IBM with current pthreads
2546 #CC= xlc_r -v -g
2547 #THR_SUBS = ibm_pthr_subs
2548 #THR_LIBS = -lpthreads
2549 #THR_CC =
2550 X
2551 X
2552 # for IBM Linux with current pthreads
2553 THR_SUBS = pthr_subs2
2554 THR_LIBS = -lpthread
2555 X
2556 XXDIR = /seqprg/slib/bin
2557 X
2558 DROPNFA_O = drop_nfa.o
2559 DROPGSW_O = dropgsw.o
2560 DROPRSS_O = dropnsw.o
2561 DROPTFA_O = drop_tfa.o
2562 X
2563 # renamed (fasta34)  programs
2564 #include Makefile34m.common_sql
2565 include Makefile34m.common
2566 X
2567 SHAR_EOF
2568 chmod 0644 Makefile.pLinux ||
2569 echo 'restore of Makefile.pLinux failed'
2570 Wc_c="`wc -c < 'Makefile.pLinux'`"
2571 test 1922 -eq "$Wc_c" ||
2572         echo 'Makefile.pLinux: original size 1922, current size' "$Wc_c"
2573 fi
2574 # ============= Makefile.pLinux_sql ==============
2575 if test -f 'Makefile.pLinux_sql' -a X"$1" != X"-c"; then
2576         echo 'x - skipping Makefile.pLinux_sql (File already exists)'
2577 else
2578 echo 'x - extracting Makefile.pLinux_sql (Text)'
2579 sed 's/^X//' << 'SHAR_EOF' > 'Makefile.pLinux_sql' &&
2580 # $Name: fa_34_26_5 $ - $Id: Makefile.pLinux_sql,v 1.4 2004/11/19 15:28:26 wrp Exp $
2581 #
2582 # makefile for fasta3, fasta3_t.  Use makefile.pvm for pvcompxx.
2583 # this file works for DEC Alphas
2584 #
2585 # this file supports mmap()'ed databases in BLAST2 format use -DUSE_MMAP
2586 # for mmap()ed BLAST2 format.
2587 X
2588 # the -DDEBUG option provides additional debugging information, particularly
2589 # with -D on the command line.
2590 X
2591 # use -DBIG_LIB64 to generate and use 64-bit offsets in map_db .xin
2592 # files
2593 X
2594 # for Tru64 4.0F, no "<inttypes.h>" 4.0G has inttypes.h
2595 X
2596 CC= xlc_r
2597 X
2598 #CC= cc -g3 -O -std1
2599 #CC= insure -g -DDEBUG
2600 #CC= cc -g -DDEBUG -std1
2601 X
2602 #CC= gcc -g -Wall
2603 #
2604 X
2605 CFLAGS= -O3 -qtune=auto -qarch=auto -DUNIX -DTIMES -DBIGMEM -DMAX_WORKERS=4 -DSFCHAR="':'" -DTHR_EXIT=pthread_exit -DPROGRESS -DUSE_MMAP -DIS_BIG_ENDIAN -DSAMP_STATS -DPGM_DOC -D_LARGE_FILES -DHAS_INTTYPES -D__pLinux__ -DFASTA_HOST='"fasta.bioch.virginia.edu/fasta/cgi"' -I/usr/include/mysql -DMYSQL_DB   
2606 #
2607 #(-DMYSQL_DB for mySQL databases)  (also requires change to Makefile34.common)
2608 X
2609 # special options for SUPERFAMLIES
2610 #CFLAGS= -DM10_CONS -DUNIX -DTIMES -DHZ=60 -DBIGMEM -DSFCHAR="'|'" -DMAX_WORKERS=4 -DTHR_EXIT=pthread_exit -DPROGRESS -DSUPERFAMNUM -DIS_LITTLE_ENDIAN -DUSE_MMAP -DMAXBEST=200000
2611
2612 #LIB_M = -lm
2613 LIB_M = -L/usr/local/lib/mysql -lmysqlclient -lm
2614 # for mySQL databases
2615 X
2616 HFLAGS= -o
2617 NFLAGS= -o
2618 X
2619 #for DEC Unix V4.0 
2620 #THR_SUBS = pthr_subs2
2621 #THR_LIBS = -threads
2622 #THR_CC =
2623 X
2624 #for Sun
2625 #THR_SUBS = uthr_subs
2626 #THR_LIBS = -lthread
2627 #THR_CC =
2628 #
2629 # for SGI with current pthreads
2630 #THR_SUBS = pthr_subs
2631 #THR_LIBS = -lpthreads
2632 #THR_CC = 
2633 #
2634 # for IBM with current pthreads
2635 #CC= xlc_r -v -g
2636 #THR_SUBS = ibm_pthr_subs
2637 #THR_LIBS = -lpthreads
2638 #THR_CC =
2639 X
2640 # for IBM Linux with current pthreads
2641 THR_SUBS = pthr_subs2
2642 THR_LIBS = -lpthread
2643 X
2644 XXDIR = /seqprg/slib/bin
2645 X
2646 DROPNFA_O = drop_nfa.o
2647 DROPGSW_O = dropgsw.o
2648 DROPRSS_O = dropnsw.o
2649 DROPTFA_O = drop_tfa.o
2650 X
2651 # renamed (fasta34)  programs
2652 include Makefile34m.common_sql
2653 X
2654 SHAR_EOF
2655 chmod 0644 Makefile.pLinux_sql ||
2656 echo 'restore of Makefile.pLinux_sql failed'
2657 Wc_c="`wc -c < 'Makefile.pLinux_sql'`"
2658 test 1946 -eq "$Wc_c" ||
2659         echo 'Makefile.pLinux_sql: original size 1946, current size' "$Wc_c"
2660 fi
2661 # ============= Makefile.pcom ==============
2662 if test -f 'Makefile.pcom' -a X"$1" != X"-c"; then
2663         echo 'x - skipping Makefile.pcom (File already exists)'
2664 else
2665 echo 'x - extracting Makefile.pcom (Text)'
2666 sed 's/^X//' << 'SHAR_EOF' > 'Makefile.pcom' &&
2667 X
2668 SHOWBESTC = mshowbest.c
2669 SHOWALIGN = mshowalign
2670 MWH = mw.h 
2671 MWHP = mw.h
2672 X
2673 TPROGS = ssearch34_t fasta34_t  fasts34_t tfasta34_t fastx34_t tfastx34_t fasty34_t tfasty34_t tfasts34_t fastm34_t fastf34_t tfastf34_t prss34_t prfx34_t
2674 X
2675 SPROGS = fasta34 ssearch34  fasts34 tfasta34 fastx34 tfastx34 fasty34 tfasty34 tfasts34 fastm34 tfastm34 prss34 prfx34 fastf34 tfastf34
2676 X
2677 APROGS = map_db
2678 X
2679 XXTPROGS = fastx34_t tfastx34_t fasty34_t tfasty34_t
2680 XXPROGS = fastx34 tfastx34  fasty34 tfasty34
2681 X
2682 PROGS = $(SPROGS) $(TPROGS)
2683 X
2684 all : $(PROGS)
2685 X
2686 tall: $(TPROGS)
2687 X
2688 sall: $(SPROGS)
2689 X
2690 xall: $(XTPROGS) $(XPROGS) $(ZTPROGS) $(ZPROGS) 
2691 X
2692 clean-up:
2693 X       rm -f *.o $(PROGS)
2694 X
2695 install: $(PROGS)
2696 X       cp $(PROGS) $(XDIR)
2697 X
2698 sinstall: $(SPROGS)
2699 X       cp $(SPROGS) $(XDIR)
2700 X
2701 tinstall: $(TPROGS)
2702 X       cp $(TPROGS) $(XDIR)
2703 X
2704 fasta34 : $(COMP_LIBO) compacc.o showbest.o re_getlib.o $(SHOWALIGN).o htime.o apam.o doinit.o init_fa.o scaleswn.o karlin.o $(DROPNFA_O) $(LGETLIB) c_dispn.o $(NCBL_LIB) lib_sel.o $(NRAND).o url_subs.o
2705 X       $(CC) $(HFLAGS) fasta34 $(COMP_LIBO) compacc.o showbest.o re_getlib.o $(SHOWALIGN).o htime.o apam.o doinit.o init_fa.o $(DROPNFA_O) scaleswn.o karlin.o $(LGETLIB) c_dispn.o $(NCBL_LIB) lib_sel.o url_subs.o $(NRAND).o $(LIB_M)
2706 X
2707 fasta34u : $(COMP_LIBO) compacc.o showun.o re_getlib.o $(SHOWALIGN).o htime.o apam.o doinit.o init_fa.o scaleswn.o karlin.o $(DROPNFA_O) $(LGETLIB) c_dispn.o $(NCBL_LIB) lib_sel.o url_subs.o $(NRAND).o
2708 X       $(CC) $(HFLAGS) fasta34u $(COMP_LIBO) compacc.o showun.o re_getlib.o $(SHOWALIGN).o htime.o apam.o doinit.o init_fa.o $(DROPNFA_O) scaleswn.o karlin.o $(LGETLIB) c_dispn.o $(NCBL_LIB) lib_sel.o url_subs.o $(NRAND).o$(LIB_M)
2709 X
2710 fasta34r : $(COMP_LIBO) compacc.o showrel.o $(SHOWALIGN).o htime.o apam.o doinit.o init_fa.o scaleswn.o karlin.o $(DROPNFA_O) $(LGETLIB) c_dispn.o $(NCBL_LIB) lib_sel.o url_subs.o $(NRAND).o
2711 X       $(CC) $(HFLAGS) fasta34r $(COMP_LIBO) compacc.o showrel.o $(SHOWALIGN).o htime.o apam.o doinit.o init_fa.o $(DROPNFA_O) scaleswn.o karlin.o $(LGETLIB) c_dispn.o $(NCBL_LIB) lib_sel.o url_subs.o $(NRAND).o$(LIB_M)
2712 X
2713 fasta34s : $(COMP_LIBO) compacc.o showsum.o re_getlib.o $(SHOWALIGN).o htime.o apam.o doinit.o init_fa.o scaleswn.o karlin.o $(DROPNFA_O) $(LGETLIB) c_dispn.o $(NCBL_LIB) lib_sel.o url_subs.o $(NRAND).o
2714 X       $(CC) $(HFLAGS) fasta34s $(COMP_LIBO) compacc.o showsum.o re_getlib.o $(SHOWALIGN).o htime.o apam.o doinit.o init_fa.o $(DROPNFA_O) scaleswn.o karlin.o $(LGETLIB) c_dispn.o $(NCBL_LIB) lib_sel.o url_subs.o $(NRAND).o $(LIB_M)
2715 X
2716 fastx34 : $(COMP_LIBO) compacc.o showbest.o re_getlib.o $(SHOWALIGN).o htime.o apam.o doinit.o init_fx.o scaleswn.o karlin.o drop_fx.o $(LGETLIB) c_dispn.o $(NCBL_LIB) lib_sel.o faatran.o url_subs.o $(NRAND).o
2717 X       $(CC) $(HFLAGS) fastx34 $(COMP_LIBO) compacc.o showbest.o re_getlib.o $(SHOWALIGN).o htime.o apam.o doinit.o init_fx.o drop_fx.o scaleswn.o karlin.o $(LGETLIB) c_dispn.o $(NCBL_LIB) lib_sel.o faatran.o url_subs.o $(NRAND).o $(LIB_M)
2718 X
2719 fastx34u_t : $(COMP_THRO) work_thr.o $(THR_SUBS).o compacc.o showun.o $(SHOWALIGN)_u.o c_dispn.o htime.o apam.o doinit.o init_fx.o faatran.o scaleswn.o karlin.o drop_fx.o $(LGETLIB) c_dispn.o $(NCBL_LIB) lib_sel.o url_subs.o $(NRAND).o
2720 X       $(CC) $(HFLAGS) fastx34u_t $(COMP_THRO) work_thr.o $(THR_SUBS).o compacc.o showun.o $(SHOWALIGN)_u.o htime.o apam.o doinit.o init_fx.o drop_fx.o faatran.o scaleswn.o karlin.o $(LGETLIB) c_dispn.o $(NCBL_LIB) lib_sel.o url_subs.o $(NRAND).o $(LIB_M) $(THR_LIBS)
2721 X
2722 fasty34 : $(COMP_LIBO) compacc.o showbest.o re_getlib.o $(SHOWALIGN).o htime.o apam.o doinit.o init_fy.o scaleswn.o karlin.o drop_fz.o $(LGETLIB) c_dispn.o $(NCBL_LIB) lib_sel.o faatran.o url_subs.o $(NRAND).o
2723 X       $(CC) $(HFLAGS) fasty34 $(COMP_LIBO) compacc.o showbest.o re_getlib.o $(SHOWALIGN).o htime.o apam.o doinit.o init_fy.o drop_fz.o scaleswn.o karlin.o $(LGETLIB) c_dispn.o $(NCBL_LIB) lib_sel.o faatran.o url_subs.o $(NRAND).o $(LIB_M)
2724 X
2725 fastf34 : $(COMP_LIBO) compacc.o showbest.o re_getlib.o $(SHOWALIGN).o htime.o apam.o doinit.o init_ff.o scaleswts.o last_tat.o tatstats_ff.o karlin.o drop_ff.o $(LGETLIB) c_dispn.o $(NCBL_LIB) lib_sel.o $(NRAND).o url_subs.o
2726 X       $(CC) $(HFLAGS) fastf34 $(COMP_LIBO) compacc.o showbest.o re_getlib.o $(SHOWALIGN).o htime.o apam.o doinit.o init_ff.o drop_ff.o scaleswts.o last_tat.o tatstats_ff.o karlin.o $(LGETLIB) c_dispn.o $(NCBL_LIB) lib_sel.o $(NRAND).o url_subs.o $(LIB_M)
2727 X
2728 fastf34u : $(COMP_LIBO) compacc.o showun.o $(SHOWALIGN).o htime.o apam.o doinit.o init_ff.o scaleswtf.o karlin.o drop_ff.o $(LGETLIB) c_dispn.o $(NCBL_LIB) lib_sel.o $(NRAND).o url_subs.o
2729 X       $(CC) $(HFLAGS) fastf34u $(COMP_LIBO) compacc.o showun.o $(SHOWALIGN).o htime.o apam.o doinit.o init_ff.o drop_ff.o scaleswtf.o karlin.o $(LGETLIB) c_dispn.o $(NCBL_LIB) lib_sel.o $(NRAND).o url_subs.o $(LIB_M)
2730 X
2731 fastf34s : $(COMP_LIBO) compacc.o showsum.o $(SHOWALIGN).o htime.o apam.o doinit.o init_ff.o scaleswtf.o karlin.o drop_ff.o $(LGETLIB) c_dispn.o $(NCBL_LIB) lib_sel.o $(NRAND).o url_subs.o
2732 X       $(CC) $(HFLAGS) fastf34s $(COMP_LIBO) compacc.o showsum.o $(SHOWALIGN).o htime.o apam.o doinit.o init_ff.o drop_ff.o scaleswtf.o karlin.o $(LGETLIB) c_dispn.o $(NCBL_LIB) lib_sel.o $(NRAND).o url_subs.o $(LIB_M)
2733 X
2734 fasts34 : $(COMP_LIBO) compacc.o showbest.o re_getlib.o $(SHOWALIGN).o htime.o apam.o doinit.o init_fs.o scaleswts.o last_tat.o tatstats_fs.o karlin.o drop_fs.o $(LGETLIB) c_dispn.o $(NCBL_LIB) lib_sel.o $(NRAND).o url_subs.o
2735 X       $(CC) $(HFLAGS) fasts34 $(COMP_LIBO) compacc.o showbest.o re_getlib.o $(SHOWALIGN).o htime.o apam.o doinit.o init_fs.o drop_fs.o scaleswts.o last_tat.o tatstats_fs.o karlin.o $(LGETLIB) c_dispn.o $(NCBL_LIB) lib_sel.o $(NRAND).o url_subs.o $(LIB_M)
2736 X
2737 fastm34 : $(COMP_LIBO) compacc.o showbest.o re_getlib.o $(SHOWALIGN).o htime.o apam.o doinit.o init_fm.o scaleswts.o last_tat.o tatstats_fm.o karlin.o drop_fm.o $(LGETLIB) c_dispn.o $(NCBL_LIB) lib_sel.o $(NRAND).o url_subs.o
2738 X       $(CC) $(HFLAGS) fastm34 $(COMP_LIBO) compacc.o showbest.o re_getlib.o $(SHOWALIGN).o htime.o apam.o doinit.o init_fm.o drop_fm.o scaleswts.o last_tat.o tatstats_fm.o karlin.o $(LGETLIB) c_dispn.o $(NCBL_LIB) lib_sel.o $(NRAND).o url_subs.o $(LIB_M)
2739 X
2740 tfastx34 : $(COMP_LIBO) compacc.o showbest.o re_getlib.o $(SHOWALIGN).o htime.o apam.o doinit.o init_tfx.o scaleswn.o karlin.o drop_tfx.o $(LGETLIB) c_dispn.o $(NCBL_LIB) lib_sel.o faatran.o url_subs.o $(NRAND).o
2741 X       $(CC) $(HFLAGS) tfastx34 $(COMP_LIBO) compacc.o showbest.o re_getlib.o $(SHOWALIGN).o htime.o apam.o doinit.o init_tfx.o drop_tfx.o scaleswn.o karlin.o $(LGETLIB) c_dispn.o $(NCBL_LIB) lib_sel.o faatran.o url_subs.o $(NRAND).o $(LIB_M)
2742 X
2743 tfasty34 : $(COMP_LIBO) compacc.o showbest.o re_getlib.o $(SHOWALIGN).o htime.o apam.o doinit.o init_tfy.o scaleswn.o karlin.o drop_tfz.o $(LGETLIB) c_dispn.o $(NCBL_LIB) lib_sel.o faatran.o url_subs.o $(NRAND).o
2744 X       $(CC) $(HFLAGS) tfasty34 $(COMP_LIBO) compacc.o showbest.o re_getlib.o $(SHOWALIGN).o htime.o apam.o doinit.o init_tfy.o drop_tfz.o scaleswn.o karlin.o $(LGETLIB) c_dispn.o $(NCBL_LIB) lib_sel.o faatran.o url_subs.o $(NRAND).o $(LIB_M)
2745 X
2746 tfastf34 : $(COMP_LIBO) compacc.o showbest.o re_getlib.o $(SHOWALIGN).o htime.o apam.o doinit.o init_tf.o scaleswtf.o last_tat.o tatstats_ff.o karlin.o drop_tff.o $(LGETLIB) c_dispn.o $(NCBL_LIB) lib_sel.o faatran.o $(NRAND).o url_subs.o
2747 X       $(CC) $(HFLAGS) tfastf34 $(COMP_LIBO) compacc.o showbest.o re_getlib.o $(SHOWALIGN).o htime.o apam.o doinit.o init_tf.o drop_tff.o scaleswtf.o last_tat.o tatstats_ff.o karlin.o $(LGETLIB) c_dispn.o $(NCBL_LIB) lib_sel.o faatran.o $(NRAND).o url_subs.o $(LIB_M)
2748 X
2749 tfastf34s : $(COMP_LIBO) compacc.o showsum.o $(SHOWALIGN).o htime.o apam.o doinit.o init_tf.o scaleswtf.o karlin.o drop_tff.o $(LGETLIB) c_dispn.o $(NCBL_LIB) lib_sel.o faatran.o $(NRAND).o url_subs.o
2750 X       $(CC) $(HFLAGS) tfastf34s $(COMP_LIBO) compacc.o showsum.o $(SHOWALIGN).o htime.o apam.o doinit.o init_tf.o drop_tff.o scaleswtf.o karlin.o $(LGETLIB) c_dispn.o $(NCBL_LIB) lib_sel.o faatran.o $(NRAND).o url_subs.o $(LIB_M)
2751 X
2752 tfasts34 : $(COMP_LIBO) compacc.o showbest.o re_getlib.o $(SHOWALIGN).o htime.o apam.o doinit.o init_tfs.o scaleswts.o tatstats_fs.o last_tat.o karlin.o drop_tfs.o $(LGETLIB) c_dispn.o $(NCBL_LIB) lib_sel.o faatran.o $(NRAND).o url_subs.o
2753 X       $(CC) $(HFLAGS) tfasts34 $(COMP_LIBO) compacc.o showbest.o re_getlib.o $(SHOWALIGN).o htime.o apam.o doinit.o init_tfs.o drop_tfs.o scaleswts.o tatstats_fs.o last_tat.o karlin.o $(LGETLIB) c_dispn.o $(NCBL_LIB) lib_sel.o faatran.o $(NRAND).o url_subs.o $(LIB_M)
2754 X
2755 tfastm34 : $(COMP_LIBO) compacc.o showbest.o re_getlib.o $(SHOWALIGN).o htime.o apam.o doinit.o init_tfm.o scaleswts.o tatstats_fm.o last_tat.o karlin.o drop_tfm.o $(LGETLIB) c_dispn.o $(NCBL_LIB) lib_sel.o faatran.o $(NRAND).o url_subs.o
2756 X       $(CC) $(HFLAGS) tfastm34 $(COMP_LIBO) compacc.o showbest.o re_getlib.o $(SHOWALIGN).o htime.o apam.o doinit.o init_tfm.o drop_tfm.o scaleswts.o tatstats_fm.o last_tat.o karlin.o $(LGETLIB) c_dispn.o $(NCBL_LIB) lib_sel.o faatran.o $(NRAND).o url_subs.o $(LIB_M)
2757 X
2758 ssearch34 : $(COMP_LIBO) compacc.o showbest.o re_getlib.o $(SHOWALIGN).o htime.o apam.o doinit.o init_sw.o scaleswn.o karlin.o $(DROPGSW_O) $(LGETLIB) c_dispn.o $(NCBL_LIB) lib_sel.o url_subs.o $(NRAND).o pssm_asn_subs.o
2759 X       $(CC) $(HFLAGS) ssearch34 $(COMP_LIBO) compacc.o showbest.o re_getlib.o $(SHOWALIGN).o htime.o apam.o doinit.o init_sw.o $(DROPGSW_O) scaleswn.o karlin.o $(LGETLIB) c_dispn.o $(NCBL_LIB) lib_sel.o url_subs.o $(NRAND).o pssm_asn_subs.o $(LIB_M)
2760 X
2761 osearch34 : $(COMP_LIBO) compacc.o showbest.o re_getlib.o $(SHOWALIGN).o htime.o apam.o doinit.o init_ssw.o scaleswn.o karlin.o dropnsw.o $(LGETLIB) c_dispn.o $(NCBL_LIB) lib_sel.o url_subs.o $(NRAND).o
2762 X       $(CC) $(HFLAGS) osearch34 $(COMP_LIBO) compacc.o showbest.o re_getlib.o $(SHOWALIGN).o htime.o apam.o doinit.o init_ssw.o dropnsw.o scaleswn.o karlin.o $(LGETLIB) c_dispn.o $(NCBL_LIB) lib_sel.o url_subs.o $(NRAND).o $(LIB_M)
2763 X
2764 usearch34 : $(COMP_LIBO) compacc.o showbest.o re_getlib.o $(SHOWALIGN).o htime.o apam.o doinit.o init_sw.o scaleswn.o karlin.o dropnsw.o $(LGETLIB) c_dispn.o $(NCBL_LIB) lib_sel.o url_subs.o $(NRAND).o
2765 X       $(CC) $(HFLAGS) usearch34 $(COMP_LIBO) compacc.o showbest.o re_getlib.o $(SHOWALIGN).o htime.o apam.o doinit.o init_sw.o dropnsw.o scaleswn.o karlin.o $(LGETLIB) c_dispn.o $(NCBL_LIB) lib_sel.o url_subs.o $(NRAND).o $(LIB_M)
2766 X
2767 prss34 : rcomp_lib.o compacc.o htime.o apam.o doinit.o init_rss.o scaleswn.o karlin.o $(DROPRSS_O) llgetaa.o showbest.o mshowalign.o c_dispn.o lib_sel.o url_subs.o $(NRAND).o pssm_asn_subs.o
2768 X       $(CC) $(HFLAGS) prss34 rcomp_lib.o compacc.o htime.o apam.o doinit.o init_rss.o $(DROPRSS_O) scaleswn.o karlin.o llgetaa.o showbest.o mshowalign.o c_dispn.o lib_sel.o url_subs.o $(NRAND).o pssm_asn_subs.o $(LIB_M)
2769 X
2770 prfx34 : rcomp_lib.o compacc.o htime.o apam.o doinit.o init_rfx.o scaleswn.o karlin.o drop_fx.o llgetaa.o showbest.o mshowalign.o c_dispn.o lib_sel.o url_subs.o $(NRAND).o faatran.o
2771 X       $(CC) $(HFLAGS) prfx34 rcomp_lib.o compacc.o htime.o apam.o doinit.o init_rfx.o drop_fx.o scaleswn.o karlin.o llgetaa.o showbest.o mshowalign.o c_dispn.o lib_sel.o faatran.o url_subs.o $(NRAND).o $(LIB_M)
2772 X
2773 prss34o : rcomp_lib.o compacc.o htime.o apam.o doinit.o init_rss.o scaleswn.o karlin.o $(DROPRSS_O) llgetaa.o showrss.o lib_sel.o $(NRAND).o pssm_asn_subs.o
2774 X       $(CC) $(HFLAGS) prss34o rcomp_lib.o compacc.o htime.o apam.o doinit.o init_rss.o $(DROPRSS_O) scaleswn.o karlin.o llgetaa.o showrss.o lib_sel.o $(NRAND).o pssm_asn_subs.o $(LIB_M)
2775 X
2776 prfx34o : rcomp_lib.o compacc.o htime.o apam.o doinit.o init_rfx.o scaleswn.o karlin.o drop_fx.o llgetaa.o showrss.o lib_sel.o $(NRAND).o faatran.o
2777 X       $(CC) $(HFLAGS) prfx34o rcomp_lib.o compacc.o htime.o apam.o doinit.o init_rfx.o drop_fx.o scaleswn.o karlin.o llgetaa.o showrss.o lib_sel.o faatran.o $(NRAND).o $(LIB_M)
2778 X
2779 ssearch34_t : $(COMP_THRO) work_thr.o $(THR_SUBS).o compacc.o showbest.o re_getlib.o $(SHOWALIGN).o htime.o apam.o doinit.o init_sw.o scaleswn.o karlin.o $(DROPGSW_O) $(LGETLIB) c_dispn.o $(NCBL_LIB) lib_sel.o url_subs.o $(NRAND).o pssm_asn_subs.o
2780 X       $(CC) $(HFLAGS) ssearch34_t $(COMP_THRO) work_thr.o $(THR_SUBS).o compacc.o showbest.o re_getlib.o $(SHOWALIGN).o htime.o apam.o doinit.o init_sw.o $(DROPGSW_O) scaleswn.o karlin.o $(LGETLIB) c_dispn.o $(NCBL_LIB) lib_sel.o url_subs.o $(NRAND).o pssm_asn_subs.o $(LIB_M) $(THR_LIBS)
2781 X
2782 ssearch34s_t : $(COMP_THRO) work_thr.o $(THR_SUBS).o compacc.o showsum.o re_getlib.o $(SHOWALIGN).o htime.o apam.o doinit.o init_sw.o scaleswn.o karlin.o $(DROPGSW_O) $(LGETLIB) c_dispn.o $(NCBL_LIB) lib_sel.o url_subs.o $(NRAND).o
2783 X       $(CC) $(HFLAGS) ssearch34s_t $(COMP_THRO) work_thr.o $(THR_SUBS).o compacc.o showsum.o re_getlib.o $(SHOWALIGN).o htime.o apam.o doinit.o init_sw.o $(DROPGSW_O) scaleswn.o karlin.o $(LGETLIB) c_dispn.o $(NCBL_LIB) lib_sel.o url_subs.o $(NRAND).o $(LIB_M) $(THR_LIBS)
2784 X
2785 ssearch34u_t : $(COMP_THRO) work_thr.o $(THR_SUBS).o compacc.o showun.o $(SHOWALIGN)_u.o htime.o apam.o doinit.o init_sw.o scaleswn.o karlin.o $(DROPGSW_O) $(LGETLIB) c_dispn.o $(NCBL_LIB) lib_sel.o url_subs.o $(NRAND).o
2786 X       $(CC) $(HFLAGS) ssearch34u_t $(COMP_THRO) work_thr.o $(THR_SUBS).o compacc.o showun.o $(SHOWALIGN)_u.o htime.o apam.o doinit.o init_sw.o $(DROPGSW_O) scaleswn.o karlin.o $(LGETLIB) c_dispn.o $(NCBL_LIB) lib_sel.o url_subs.o $(NRAND).o $(LIB_M) $(THR_LIBS)
2787 X
2788 osearch34_t : $(COMP_THRO) work_thr.o $(THR_SUBS).o compacc.o showbest.o re_getlib.o $(SHOWALIGN).o htime.o apam.o doinit.o init_sw.o scaleswn.o karlin.o dropnsw.o $(LGETLIB) c_dispn.o $(NCBL_LIB) lib_sel.o url_subs.o $(NRAND).o
2789 X       $(CC) $(HFLAGS) osearch34_t $(COMP_THRO) work_thr.o $(THR_SUBS).o compacc.o showbest.o re_getlib.o $(SHOWALIGN).o htime.o apam.o doinit.o init_sw.o dropnsw.o scaleswn.o karlin.o $(LGETLIB) c_dispn.o $(NCBL_LIB) lib_sel.o url_subs.o $(NRAND).o $(LIB_M) $(THR_LIBS)
2790 X
2791 usearch34_t : $(COMP_THRO) work_thr.o $(THR_SUBS).o compacc.o showbest.o re_getlib.o $(SHOWALIGN).o htime.o apam.o doinit.o init_sw.o scaleswn.o karlin.o dropnsw.o $(LGETLIB) c_dispn.o $(NCBL_LIB) lib_sel.o url_subs.o $(NRAND).o
2792 X       $(CC) $(HFLAGS) usearch34_t $(COMP_THRO) work_thr.o $(THR_SUBS).o compacc.o showbest.o re_getlib.o $(SHOWALIGN).o htime.o apam.o doinit.o init_sw.o dropnsw.o scaleswn.o karlin.o $(LGETLIB) c_dispn.o $(NCBL_LIB) lib_sel.o url_subs.o $(NRAND).o $(LIB_M) $(THR_LIBS)
2793 X
2794 fasta34_t : $(COMP_THRO) work_thr.o $(THR_SUBS).o compacc.o showbest.o re_getlib.o $(SHOWALIGN).o htime.o apam.o doinit.o init_fa.o scaleswn.o karlin.o $(DROPNFA_O) $(LGETLIB) c_dispn.o $(NCBL_LIB) lib_sel.o url_subs.o $(NRAND).o
2795 X       $(CC) $(HFLAGS) fasta34_t $(COMP_THRO) work_thr.o $(THR_SUBS).o compacc.o showbest.o re_getlib.o $(SHOWALIGN).o htime.o apam.o doinit.o init_fa.o $(DROPNFA_O) scaleswn.o karlin.o $(LGETLIB) c_dispn.o $(NCBL_LIB) lib_sel.o url_subs.o $(NRAND).o $(LIB_M) $(THR_LIBS)
2796 X
2797 fasta34s_t : $(COMP_THRO) work_thr.o $(THR_SUBS).o compacc.o showsum.o re_getlib.o $(SHOWALIGN).o htime.o apam.o doinit.o init_fa.o scaleswn.o karlin.o $(DROPNFA_O) $(LGETLIB) c_dispn.o $(NCBL_LIB) lib_sel.o url_subs.o $(NRAND).o
2798 X       $(CC) $(HFLAGS) fasta34s_t $(COMP_THRO) work_thr.o $(THR_SUBS).o compacc.o showsum.o re_getlib.o $(SHOWALIGN).o htime.o apam.o doinit.o init_fa.o $(DROPNFA_O) scaleswn.o karlin.o $(LGETLIB) c_dispn.o $(NCBL_LIB) lib_sel.o url_subs.o $(NRAND).o $(LIB_M) $(THR_LIBS)
2799 X
2800 fasta34u_t : $(COMP_THRO) work_thr.o $(THR_SUBS).o compacc.o showun.o $(SHOWALIGN).o htime.o apam.o doinit.o init_fa.o scaleswn.o karlin.o $(DROPNFA_O) $(LGETLIB) c_dispn.o $(NCBL_LIB) lib_sel.o $(NRAND).o url_subs.o
2801 X       $(CC) $(HFLAGS) fasta34u_t $(COMP_THRO) work_thr.o $(THR_SUBS).o compacc.o showun.o $(SHOWALIGN).o htime.o apam.o doinit.o init_fa.o $(DROPNFA_O) scaleswn.o karlin.o $(LGETLIB) c_dispn.o $(NCBL_LIB) lib_sel.o $(NRAND).o url_subs.o $(LIB_M) $(THR_LIBS)
2802 X
2803 fasta34r_t : $(COMP_THRO) work_thr.o $(THR_SUBS).o compacc.o showrel.o $(SHOWALIGN).o htime.o apam.o doinit.o init_fa.o scaleswn.o karlin.o $(DROPNFA_O) $(LGETLIB) c_dispn.o $(NCBL_LIB) lib_sel.o $(NRAND).o url_subs.o
2804 X       $(CC) $(HFLAGS) fasta34r_t $(COMP_THRO) work_thr.o $(THR_SUBS).o compacc.o showrel.o $(SHOWALIGN).o htime.o apam.o doinit.o init_fa.o $(DROPNFA_O) scaleswn.o karlin.o $(LGETLIB) c_dispn.o $(NCBL_LIB) lib_sel.o $(NRAND).o url_subs.o $(LIB_M) $(THR_LIBS)
2805 X
2806 fastf34_t : $(COMP_THRO) work_thr.o $(THR_SUBS).o compacc.o showbest.o re_getlib.o $(SHOWALIGN).o htime.o apam.o doinit.o init_ff.o scaleswtf.o last_tat.o tatstats_ff.o karlin.o drop_ff.o $(LGETLIB) c_dispn.o $(NCBL_LIB) lib_sel.o $(NRAND).o url_subs.o
2807 X       $(CC) $(HFLAGS) fastf34_t $(COMP_THRO) work_thr.o $(THR_SUBS).o compacc.o showbest.o re_getlib.o $(SHOWALIGN).o htime.o apam.o doinit.o init_ff.o drop_ff.o scaleswtf.o last_tat.o tatstats_ff.o karlin.o $(LGETLIB) c_dispn.o $(NCBL_LIB) lib_sel.o $(NRAND).o url_subs.o $(LIB_M) $(THR_LIBS)
2808 X
2809 fastf34s_t : $(COMP_THRO) work_thr.o $(THR_SUBS).o compacc.o showsum.o $(SHOWALIGN).o htime.o apam.o doinit.o init_ff.o scaleswtf.o karlin.o drop_ff.o $(LGETLIB) c_dispn.o $(NCBL_LIB) lib_sel.o $(NRAND).o url_subs.o
2810 X       $(CC) $(HFLAGS) fastf34s_t $(COMP_THRO) work_thr.o $(THR_SUBS).o compacc.o showsum.o $(SHOWALIGN).o htime.o apam.o doinit.o init_ff.o drop_ff.o scaleswtf.o karlin.o $(LGETLIB) c_dispn.o $(NCBL_LIB) lib_sel.o $(NRAND).o url_subs.o $(LIB_M) $(THR_LIBS)
2811 X
2812 fasts34_t : $(COMP_THRO) work_thr.o $(THR_SUBS).o compacc.o showbest.o re_getlib.o $(SHOWALIGN).o htime.o apam.o doinit.o init_fs.o scaleswts.o last_tat.o tatstats_fs.o karlin.o drop_fs.o $(LGETLIB) c_dispn.o $(NCBL_LIB) lib_sel.o $(NRAND).o url_subs.o
2813 X       $(CC) $(HFLAGS) fasts34_t $(COMP_THRO) work_thr.o $(THR_SUBS).o compacc.o showbest.o re_getlib.o $(SHOWALIGN).o htime.o apam.o doinit.o init_fs.o drop_fs.o scaleswts.o last_tat.o tatstats_fs.o karlin.o $(LGETLIB) c_dispn.o $(NCBL_LIB) lib_sel.o $(NRAND).o url_subs.o $(LIB_M) $(THR_LIBS)
2814 X
2815 fastm34_t : $(COMP_THRO) work_thr.o $(THR_SUBS).o compacc.o showbest.o re_getlib.o $(SHOWALIGN).o htime.o apam.o doinit.o init_fs.o scaleswts.o last_tat.o tatstats_fm.o karlin.o drop_fm.o $(LGETLIB) c_dispn.o $(NCBL_LIB) lib_sel.o $(NRAND).o url_subs.o
2816 X       $(CC) $(HFLAGS) fastm34_t $(COMP_THRO) work_thr.o $(THR_SUBS).o compacc.o showbest.o re_getlib.o $(SHOWALIGN).o htime.o apam.o doinit.o init_fs.o drop_fm.o scaleswts.o last_tat.o tatstats_fm.o karlin.o $(LGETLIB) c_dispn.o $(NCBL_LIB) lib_sel.o $(NRAND).o url_subs.o $(LIB_M) $(THR_LIBS)
2817 X
2818 fastx34_t : $(COMP_THRO) work_thr.o $(THR_SUBS).o compacc.o showbest.o re_getlib.o $(SHOWALIGN).o c_dispn.o htime.o apam.o doinit.o init_fx.o faatran.o scaleswn.o karlin.o drop_fx.o $(LGETLIB) c_dispn.o $(NCBL_LIB) lib_sel.o url_subs.o $(NRAND).o
2819 X       $(CC) $(HFLAGS) fastx34_t $(COMP_THRO) work_thr.o $(THR_SUBS).o compacc.o showbest.o re_getlib.o $(SHOWALIGN).o htime.o apam.o doinit.o init_fx.o drop_fx.o faatran.o scaleswn.o karlin.o $(LGETLIB) c_dispn.o $(NCBL_LIB) lib_sel.o url_subs.o $(NRAND).o $(LIB_M) $(THR_LIBS)
2820 X
2821 fasty34_t : $(COMP_THRO) work_thr.o $(THR_SUBS).o compacc.o showbest.o re_getlib.o $(SHOWALIGN).o c_dispn.o htime.o apam.o doinit.o init_fy.o faatran.o scaleswn.o karlin.o drop_fz.o $(LGETLIB) c_dispn.o $(NCBL_LIB) lib_sel.o url_subs.o $(NRAND).o
2822 X       $(CC) $(HFLAGS) fasty34_t $(COMP_THRO) work_thr.o $(THR_SUBS).o compacc.o showbest.o re_getlib.o $(SHOWALIGN).o htime.o apam.o doinit.o init_fy.o drop_fz.o faatran.o scaleswn.o karlin.o $(LGETLIB) c_dispn.o $(NCBL_LIB) lib_sel.o url_subs.o $(NRAND).o $(LIB_M) $(THR_LIBS)
2823 X
2824 tfasta34 : $(COMP_LIBO) compacc.o showbest.o re_getlib.o $(SHOWALIGN).o htime.o apam.o doinit.o init_tfa.o scaleswn.o karlin.o $(DROPTFA_O) $(LGETLIB) c_dispn.o $(NCBL_LIB) lib_sel.o faatran.o url_subs.o $(NRAND).o
2825 X       $(CC) $(HFLAGS) tfasta34 $(COMP_LIBO) compacc.o showbest.o re_getlib.o $(SHOWALIGN).o htime.o apam.o doinit.o init_tfa.o $(DROPTFA_O) scaleswn.o karlin.o $(LGETLIB) c_dispn.o $(NCBL_LIB) lib_sel.o faatran.o url_subs.o $(NRAND).o $(LIB_M)
2826 X
2827 tfasta34_t : $(COMP_THRO) work_thr.o $(THR_SUBS).o compacc.o showbest.o re_getlib.o $(SHOWALIGN).o c_dispn.o htime.o apam.o doinit.o init_tfa.o scaleswn.o karlin.o $(DROPTFA_O) $(LGETLIB) c_dispn.o $(NCBL_LIB) lib_sel.o faatran.o url_subs.o $(NRAND).o
2828 X       $(CC) $(HFLAGS) tfasta34_t $(COMP_THRO) work_thr.o $(THR_SUBS).o compacc.o showbest.o re_getlib.o $(SHOWALIGN).o htime.o apam.o doinit.o init_tfa.o $(DROPTFA_O) scaleswn.o karlin.o $(LGETLIB) c_dispn.o $(NCBL_LIB) lib_sel.o faatran.o url_subs.o $(NRAND).o $(LIB_M) $(THR_LIBS)
2829 X
2830 tfastf34_t : $(COMP_THRO) work_thr.o $(THR_SUBS).o compacc.o showbest.o re_getlib.o $(SHOWALIGN).o c_dispn.o htime.o apam.o doinit.o init_tf.o  scaleswtf.o last_tat.o tatstats_ff.o karlin.o drop_tff.o $(LGETLIB) c_dispn.o $(NCBL_LIB) lib_sel.o faatran.o $(NRAND).o url_subs.o
2831 X       $(CC) $(HFLAGS) tfastf34_t $(COMP_THRO) work_thr.o $(THR_SUBS).o compacc.o showbest.o re_getlib.o $(SHOWALIGN).o htime.o apam.o doinit.o init_tf.o drop_tff.o scaleswtf.o last_tat.o tatstats_ff.o karlin.o $(LGETLIB) c_dispn.o $(NCBL_LIB) lib_sel.o faatran.o $(NRAND).o url_subs.o $(LIB_M) $(THR_LIBS)
2832 X
2833 tfasts34_t : $(COMP_THRO) work_thr.o $(THR_SUBS).o compacc.o showbest.o re_getlib.o $(SHOWALIGN).o c_dispn.o htime.o apam.o doinit.o init_tfs.o scaleswts.o last_tat.o tatstats_fs.o karlin.o drop_tfs.o $(LGETLIB) c_dispn.o $(NCBL_LIB) lib_sel.o faatran.o $(NRAND).o url_subs.o
2834 X       $(CC) $(HFLAGS) tfasts34_t $(COMP_THRO) work_thr.o $(THR_SUBS).o compacc.o showbest.o re_getlib.o $(SHOWALIGN).o htime.o apam.o doinit.o init_tfs.o drop_tfs.o scaleswts.o last_tat.o tatstats_fs.o karlin.o $(LGETLIB) c_dispn.o $(NCBL_LIB) lib_sel.o faatran.o $(NRAND).o url_subs.o $(LIB_M) $(THR_LIBS)
2835 X
2836 tfastx34_t : $(COMP_THRO) work_thr.o $(THR_SUBS).o compacc.o showbest.o re_getlib.o $(SHOWALIGN).o htime.o apam.o doinit.o init_tfx.o scaleswn.o karlin.o drop_tfx.o $(LGETLIB) c_dispn.o $(NCBL_LIB) lib_sel.o faatran.o url_subs.o $(NRAND).o
2837 X       $(CC) $(HFLAGS) tfastx34_t $(COMP_THRO) work_thr.o $(THR_SUBS).o compacc.o showbest.o re_getlib.o $(SHOWALIGN).o htime.o apam.o doinit.o init_tfx.o drop_tfx.o scaleswn.o karlin.o $(LGETLIB) c_dispn.o $(NCBL_LIB) lib_sel.o faatran.o url_subs.o $(NRAND).o $(LIB_M) $(THR_LIBS)
2838 X
2839 tfasty34_t : $(COMP_THRO) work_thr.o $(THR_SUBS).o compacc.o showbest.o re_getlib.o $(SHOWALIGN).o htime.o apam.o doinit.o init_tfy.o scaleswn.o karlin.o drop_tfz.o $(LGETLIB) c_dispn.o $(NCBL_LIB) lib_sel.o faatran.o url_subs.o $(NRAND).o
2840 X       $(CC) $(HFLAGS) tfasty34_t $(COMP_THRO) work_thr.o $(THR_SUBS).o compacc.o showbest.o re_getlib.o $(SHOWALIGN).o htime.o apam.o doinit.o init_tfy.o drop_tfz.o scaleswn.o karlin.o $(LGETLIB) c_dispn.o $(NCBL_LIB) lib_sel.o faatran.o url_subs.o $(NRAND).o $(LIB_M) $(THR_LIBS)
2841 X
2842 prss34_t : rcomp_thr.o work_thr.o $(THR_SUBS).o compacc.o htime.o apam.o doinit.o init_rss.o scaleswn.o karlin.o $(DROPRSS_O) llgetaa.o showbest.o $(SHOWALIGN).o c_dispn.o url_subs.o lib_sel.o $(NRAND).o pssm_asn_subs.o
2843 X       $(CC) $(HFLAGS) prss34_t rcomp_thr.o work_thr.o $(THR_SUBS).o compacc.o htime.o apam.o doinit.o init_rss.o $(DROPRSS_O) scaleswn.o karlin.o llgetaa.o showbest.o  $(SHOWALIGN).o c_dispn.o url_subs.o lib_sel.o $(NRAND).o pssm_asn_subs.o $(LIB_M) $(THR_LIBS)
2844 X
2845 prss34o_t : rcomp_thr.o work_thr.o $(THR_SUBS).o compacc.o htime.o apam.o doinit.o init_rss.o scaleswn.o karlin.o $(DROPRSS_O) llgetaa.o showrss.o lib_sel.o $(NRAND).o pssm_asn_subs.o
2846 X       $(CC) $(HFLAGS) prss34o_t rcomp_thr.o work_thr.o $(THR_SUBS).o compacc.o htime.o apam.o doinit.o init_rss.o $(DROPRSS_O) scaleswn.o karlin.o llgetaa.o showrss.o lib_sel.o $(NRAND).o pssm_asn_subs.o $(LIB_M) $(THR_LIBS)
2847 X
2848 prfx34_t : rcomp_thr.o work_thr.o $(THR_SUBS).o compacc.o htime.o apam.o doinit.o init_rfx.o scaleswn.o karlin.o drop_fx.o llgetaa.o showbest.o mshowalign.o c_dispn.o lib_sel.o url_subs.o $(NRAND).o faatran.o
2849 X       $(CC) $(HFLAGS) prfx34_t rcomp_thr.o work_thr.o $(THR_SUBS).o compacc.o htime.o apam.o doinit.o init_rfx.o drop_fx.o scaleswn.o karlin.o llgetaa.o showbest.o mshowalign.o c_dispn.o lib_sel.o faatran.o url_subs.o $(NRAND).o $(LIB_M) $(THR_LIBS)
2850 X
2851 comp_lib.o : comp_lib.c mw.h structs.h defs.h param.h
2852 X       $(CC) $(THR_CC) $(CFLAGS) -c comp_lib.c
2853 X
2854 comp_mlib.o : comp_lib.c mw.h structs.h defs.h param.h
2855 X       $(CC) $(THR_CC) $(CFLAGS) -DCOMP_MLIB -c comp_lib.c -o comp_mlib.o
2856 X
2857 rcomp_lib.o : comp_lib.c mw.h structs.h defs.h param.h
2858 X       $(CC) $(THR_CC) $(CFLAGS) -c -DPRSS comp_lib.c -o rcomp_lib.o
2859 X
2860 comp_thr.o : comp_lib.c mw.h structs.h defs.h param.h thr.h
2861 X       $(CC) $(THR_CC) $(CFLAGS) -DCOMP_THR -c comp_lib.c -o comp_thr.o
2862 X
2863 comp_mthr.o : comp_lib.c mw.h structs.h defs.h param.h thr.h
2864 X       $(CC) $(THR_CC) $(CFLAGS) -DCOMP_THR -DCOMP_MLIB -c comp_lib.c -o comp_mthr.o
2865 X
2866 rcomp_thr.o : comp_lib.c mw.h structs.h defs.h param.h thr.h
2867 X       $(CC) $(THR_CC) $(CFLAGS) -DPRSS -DCOMP_THR -c comp_lib.c -o rcomp_thr.o
2868 X
2869 work_thr.o : work_thr.c mw.h structs.h defs.h param.h thr.h
2870 X       $(CC) $(THR_CC) $(CFLAGS) -c work_thr.c
2871 X
2872 print_pssm : print_pssm.c getseq.c karlin.c apam.c
2873 X       $(CC) -o print_pssm $(CFLAGS) print_pssm.c getseq.c karlin.c apam.c $(LIB_M)
2874 X
2875 map_db : map_db.c  uascii.h ncbl2_head.h
2876 X       $(CC) -o map_db map_db.c
2877 X
2878 list_db : list_db.c
2879 X       $(CC) -o list_db list_db.c
2880 X
2881 SHAR_EOF
2882 chmod 0644 Makefile.pcom ||
2883 echo 'restore of Makefile.pcom failed'
2884 Wc_c="`wc -c < 'Makefile.pcom'`"
2885 test 24893 -eq "$Wc_c" ||
2886         echo 'Makefile.pcom: original size 24893, current size' "$Wc_c"
2887 fi
2888 # ============= Makefile.pvcom ==============
2889 if test -f 'Makefile.pvcom' -a X"$1" != X"-c"; then
2890         echo 'x - skipping Makefile.pvcom (File already exists)'
2891 else
2892 echo 'x - extracting Makefile.pvcom (Text)'
2893 sed 's/^X//' << 'SHAR_EOF' > 'Makefile.pvcom' &&
2894 X
2895 SHOWBESTC = mshowbest.c
2896 SHOWALIGN = mshowalign
2897 MWH = p_mw.h
2898 MWHP = p_mw.h w_mw.h
2899 X
2900 # normal search programs are pv3compfa, etc.
2901 # each main program requires a worker pv3compfa/c34.workfa
2902 X
2903 PROGS= pv34compfa pv34compsw pv34compfx pv34comptfx pv34compfy pv34comptfy pv34compfs pv34comptfs
2904 X
2905 WPROGS = c34.workfa c34.worksw c34.workgsw c34.workfx c34.worktfx c34.workfy c34.worktfy c34.workfs c34.worktfs
2906 # ps4compfa, etc provides a summaries of effectiveness, require superfamily
2907 # annotated database. ps4compss uses c34.worksw instead of c34.workgsw, thus
2908 # allowing high gap penalties.
2909 X
2910 SPROGS = ps34compfa ps34compsw ps34compss ps34compfx ps34compfy ps34comptfx ps34comptfy
2911 X
2912 # report highest unrelated sequences
2913 UPROGS = pu34compfa pu34compsw pu34compfx pu34comptfx pu34compfy pu34comptfy
2914 X
2915 vall : $(PROGS) $(WPROGS)
2916 X
2917 uall : $(UPROGS) $(WPROGS)
2918 X
2919 sall : $(SPROGS) $(WPROGS)
2920 X
2921 all : $(PROGS) $(UPROGS) $(SPROGS) $(WPROGS)
2922 X
2923 clean-up:
2924 X       rm -f *.o $(PROGS) $(WPROGS) $(SPROGS) $(UPROGS)
2925 X
2926 install : $(PROGS) $(WPROGS)
2927 X       cp $(PROGS) $(WPROGS) $(XDIR)
2928 X
2929 sinstall : $(SPROGS) $(WPROGS)
2930 X       cp $(SPROGS) $(WPROGS) $(XDIR)
2931 X
2932 uinstall : $(UPROGS) $(WPROGS)
2933 X       cp $(UPROGS) $(WPROGS) $(XDIR)
2934 X
2935 pv34compfa : p2_complib.o compacc.o showbest.o $(SHOWALIGN).o htime.o hostacc.o apam.o doinit.o init_fa.o scaleswn.o $(NRAND).o karlin.o c_dispn.o lib_sel.o url_subs.o ${LGETLIB} $(NCBL_LIB)
2936 X       $(CC) $(HFLAGS) pv34compfa p2_complib.o compacc.o showbest.o $(SHOWALIGN).o htime.o hostacc.o apam.o doinit.o init_fa.o scaleswn.o $(NRAND).o karlin.o c_dispn.o lib_sel.o url_subs.o ${LGETLIB} $(NCBL_LIB) $(PLIB) $(LIB_M)
2937 X
2938 ps34compfa : p2_complib.o compacc.o showsum.o htime.o hostacc.o apam.o doinit.o init_fa.o scaleswn.o $(NRAND).o karlin.o lib_sel.o url_subs.o $(LGETLIB) $(NCBL_LIB)
2939 X       $(CC) $(HFLAGS) ps34compfa p2_complib.o compacc.o showsum.o htime.o hostacc.o apam.o doinit.o init_fa.o scaleswn.o $(NRAND).o karlin.o lib_sel.o url_subs.o $(LGETLIB) $(NCBL_LIB) $(PLIB) $(LIB_M)
2940 X
2941 pu34compfa : p2_complib.o compacc.o showun.o $(SHOWALIGN)_u.o htime.o hostacc.o apam.o doinit.o init_fa.o scaleswn.o $(NRAND).o karlin.o lib_sel.o url_subs.o c_dispn.o $(LGETLIB) $(NCBL_LIB)
2942 X       $(CC) $(HFLAGS) pu34compfa p2_complib.o compacc.o showun.o $(SHOWALIGN)_u.o htime.o hostacc.o apam.o doinit.o init_fa.o scaleswn.o $(NRAND).o karlin.o lib_sel.o url_subs.o c_dispn.o $(LGETLIB) $(NCBL_LIB) $(PLIB) $(LIB_M)
2943 X
2944 pr4compfa : p2_complib.o compacc.o showrel.o htime.o hostacc.o apam.o doinit.o init_fa.o scaleswn.o $(NRAND).o karlin.o lib_sel.o url_subs.o $(LGETLIB) $(NCBL_LIB)
2945 X       $(CC) $(HFLAGS) pr4compfa p2_complib.o compacc.o showrel.o htime.o hostacc.o apam.o doinit.o init_fa.o scaleswn.o $(NRAND).o karlin.o lib_sel.o url_subs.o $(LGETLIB) $(NCBL_LIB) $(PLIB) $(LIB_M)
2946 X
2947 pv34compsw : p2_complib.o compacc.o showbest.o $(SHOWALIGN).o htime.o hostacc.o apam.o doinit.o init_sw.o scaleswn.o $(NRAND).o karlin.o c_dispn.o lib_sel.o url_subs.o pssm_asn_subs.o $(LGETLIB) $(NCBL_LIB)
2948 X       $(CC) $(HFLAGS) pv34compsw p2_complib.o compacc.o showbest.o $(SHOWALIGN).o htime.o hostacc.o apam.o doinit.o init_sw.o scaleswn.o $(NRAND).o karlin.o c_dispn.o  lib_sel.o url_subs.o pssm_asn_subs.o $(LGETLIB) $(NCBL_LIB) $(PLIB) $(LIB_M)
2949 X
2950 ps34compsw : p2_complib.o compacc.o showsum.o htime.o hostacc.o apam.o doinit.o init_sw.o scaleswn.o $(NRAND).o karlin.o lib_sel.o url_subs.o pssm_asn_subs.o $(LGETLIB) $(NCBL_LIB)
2951 X       $(CC) $(HFLAGS) ps34compsw p2_complib.o compacc.o showsum.o htime.o hostacc.o apam.o doinit.o init_sw.o scaleswn.o $(NRAND).o karlin.o lib_sel.o url_subs.o pssm_asn_subs.o $(LGETLIB) $(NCBL_LIB) $(PLIB) $(LIB_M)
2952 X
2953 pu34compsw : p2_complib.o compacc.o showun.o $(SHOWALIGN)_u.o htime.o hostacc.o apam.o doinit.o init_sw.o scaleswn.o $(NRAND).o karlin.o lib_sel.o url_subs.o c_dispn.o pssm_asn_subs.o $(LGETLIB) $(NCBL_LIB)
2954 X       $(CC) $(HFLAGS) pu34compsw p2_complib.o compacc.o showun.o $(SHOWALIGN)_u.o htime.o hostacc.o apam.o doinit.o init_sw.o scaleswn.o $(NRAND).o karlin.o lib_sel.o url_subs.o c_dispn.o pssm_asn_subs.o $(LGETLIB) $(NCBL_LIB) $(PLIB) $(LIB_M)
2955 X
2956 pv34compss : p2_complib.o compacc.o showbest.o $(SHOWALIGN).o htime.o hostacc.o apam.o doinit.o init_ssw.o scaleswn.o $(NRAND).o karlin.o c_dispn.o lib_sel.o url_subs.o $(LGETLIB) $(NCBL_LIB)
2957 X       $(CC) $(HFLAGS) pv34compss p2_complib.o compacc.o showbest.o $(SHOWALIGN).o htime.o hostacc.o apam.o doinit.o init_ssw.o scaleswn.o $(NRAND).o karlin.o c_dispn.o lib_sel.o url_subs.o $(LGETLIB) $(NCBL_LIB) $(PLIB) $(LIB_M)
2958 X
2959 ps34compss : p2_complib.o compacc.o showsum.o htime.o hostacc.o apam.o doinit.o init_ssw.o scaleswn.o $(NRAND).o karlin.o lib_sel.o url_subs.o $(LGETLIB) $(NCBL_LIB)
2960 X       $(CC) $(HFLAGS) ps34compss p2_complib.o compacc.o showsum.o htime.o hostacc.o apam.o doinit.o init_ssw.o scaleswn.o $(NRAND).o karlin.o lib_sel.o url_subs.o $(LGETLIB) $(NCBL_LIB) $(PLIB) $(LIB_M)
2961 X
2962 pu34compss : p2_complib.o compacc.o showun.o $(SHOWALIGN)_u.o htime.o hostacc.o apam.o doinit.o init_ssw.o scaleswn.o $(NRAND).o karlin.o lib_sel.o url_subs.o c_dispn.o $(LGETLIB) $(NCBL_LIB)
2963 X       $(CC) $(HFLAGS) pu34compss p2_complib.o compacc.o showun.o $(SHOWALIGN)_u.o htime.o hostacc.o apam.o doinit.o init_ssw.o scaleswn.o $(NRAND).o karlin.o lib_sel.o url_subs.o c_dispn.o $(LGETLIB) $(NCBL_LIB) $(PLIB) $(LIB_M)
2964 X
2965 pv34compfs : p2_complib.o compacc.o showbest.o $(SHOWALIGN).o htime.o hostacc.o apam.o doinit.o init_fs.o scaleswts.o $(NRAND).o tatstats_fs.o last_tat.o karlin.o c_dispn.o lib_sel.o url_subs.o $(LGETLIB) $(NCBL_LIB)
2966 X       $(CC) $(HFLAGS) pv34compfs p2_complib.o compacc.o showbest.o $(SHOWALIGN).o htime.o hostacc.o apam.o doinit.o init_fs.o scaleswts.o $(NRAND).o tatstats_fs.o last_tat.o karlin.o c_dispn.o lib_sel.o url_subs.o $(LGETLIB) $(NCBL_LIB) $(PLIB) $(LIB_M)
2967 X
2968 pv34compfx : p2_complib.o compacc.o showbest.o $(SHOWALIGN).o htime.o hostacc.o apam.o doinit.o init_fx.o scaleswn.o $(NRAND).o karlin.o c_dispn.o lib_sel.o url_subs.o $(LGETLIB) $(NCBL_LIB)
2969 X       $(CC) $(HFLAGS) pv34compfx p2_complib.o compacc.o showbest.o $(SHOWALIGN).o htime.o hostacc.o apam.o doinit.o init_fx.o scaleswn.o $(NRAND).o karlin.o c_dispn.o lib_sel.o url_subs.o $(LGETLIB) $(NCBL_LIB) $(PLIB) $(LIB_M)
2970 X
2971 ps34compfx : p2_complib.o compacc.o showsum.o htime.o hostacc.o apam.o doinit.o init_fx.o scaleswn.o $(NRAND).o karlin.o c_dispn.o lib_sel.o url_subs.o $(LGETLIB) $(NCBL_LIB)
2972 X       $(CC) $(HFLAGS) ps34compfx p2_complib.o compacc.o showsum.o htime.o hostacc.o apam.o doinit.o init_fx.o scaleswn.o $(NRAND).o karlin.o c_dispn.o lib_sel.o url_subs.o $(LGETLIB) $(NCBL_LIB) $(PLIB) $(LIB_M)
2973 X
2974 pu34compfx : p2_complib.o compacc.o showun.o $(SHOWALIGN)_u.o htime.o hostacc.o apam.o doinit.o init_fx.o scaleswn.o $(NRAND).o karlin.o c_dispn.o lib_sel.o url_subs.o $(LGETLIB) $(NCBL_LIB)
2975 X       $(CC) $(HFLAGS) pu34compfx p2_complib.o compacc.o showun.o $(SHOWALIGN)_u.o htime.o hostacc.o apam.o doinit.o init_fx.o scaleswn.o $(NRAND).o karlin.o c_dispn.o lib_sel.o url_subs.o $(LGETLIB) $(NCBL_LIB) $(PLIB) $(LIB_M)
2976 X
2977 pv34compfy : p2_complib.o compacc.o showbest.o $(SHOWALIGN).o htime.o hostacc.o apam.o doinit.o init_fy.o scaleswn.o $(NRAND).o karlin.o c_dispn.o lib_sel.o url_subs.o $(LGETLIB) $(NCBL_LIB)
2978 X       $(CC) $(HFLAGS) pv34compfy p2_complib.o compacc.o showbest.o $(SHOWALIGN).o htime.o hostacc.o apam.o doinit.o init_fy.o scaleswn.o $(NRAND).o karlin.o c_dispn.o lib_sel.o url_subs.o $(LGETLIB) $(NCBL_LIB) $(PLIB) $(LIB_M)
2979 X
2980 ps34compfy : p2_complib.o compacc.o showsum.o htime.o hostacc.o apam.o doinit.o init_fy.o scaleswn.o $(NRAND).o karlin.o c_dispn.o lib_sel.o url_subs.o $(LGETLIB) $(NCBL_LIB)
2981 X       $(CC) $(HFLAGS) ps34compfy p2_complib.o compacc.o showsum.o htime.o hostacc.o apam.o doinit.o init_fy.o scaleswn.o $(NRAND).o karlin.o c_dispn.o lib_sel.o url_subs.o $(LGETLIB) $(NCBL_LIB) $(PLIB) $(LIB_M)
2982 X
2983 pu34compfy : p2_complib.o compacc.o showun.o $(SHOWALIGN)_u.o htime.o hostacc.o apam.o doinit.o init_fy.o scaleswn.o $(NRAND).o karlin.o c_dispn.o lib_sel.o url_subs.o $(LGETLIB) $(NCBL_LIB)
2984 X       $(CC) $(HFLAGS) pu34compfy p2_complib.o compacc.o showun.o $(SHOWALIGN)_u.o htime.o hostacc.o apam.o doinit.o init_fy.o scaleswn.o $(NRAND).o karlin.o c_dispn.o lib_sel.o url_subs.o $(LGETLIB) $(NCBL_LIB) $(PLIB) $(LIB_M)
2985 X
2986 pv34comptfx : p2_complib.o compacc.o showbest.o $(SHOWALIGN).o htime.o hostacc.o apam.o doinit.o init_tfx.o scaleswn.o $(NRAND).o karlin.o c_dispn.o lib_sel.o url_subs.o $(LGETLIB) $(NCBL_LIB)
2987 X       $(CC) $(HFLAGS) pv34comptfx p2_complib.o compacc.o showbest.o $(SHOWALIGN).o htime.o hostacc.o apam.o doinit.o init_tfx.o scaleswn.o $(NRAND).o karlin.o c_dispn.o lib_sel.o url_subs.o $(LGETLIB) $(NCBL_LIB) $(PLIB) $(LIB_M)
2988 X
2989 ps34comptfx : p2_complib.o compacc.o showsum.o htime.o hostacc.o apam.o doinit.o init_tfx.o scaleswn.o $(NRAND).o karlin.o c_dispn.o lib_sel.o url_subs.o $(LGETLIB) $(NCBL_LIB)
2990 X       $(CC) $(HFLAGS) ps34comptfx p2_complib.o compacc.o showsum.o htime.o hostacc.o apam.o doinit.o init_tfx.o scaleswn.o $(NRAND).o karlin.o c_dispn.o lib_sel.o url_subs.o $(LGETLIB) $(NCBL_LIB) $(PLIB) $(LIB_M)
2991 X
2992 pu34comptfx : p2_complib.o compacc.o showun.o $(SHOWALIGN)_u.o htime.o hostacc.o apam.o doinit.o init_tfx.o scaleswn.o $(NRAND).o karlin.o c_dispn.o lib_sel.o url_subs.o $(LGETLIB) $(NCBL_LIB)
2993 X       $(CC) $(HFLAGS) pu34comptfx p2_complib.o compacc.o showun.o $(SHOWALIGN)_u.o htime.o hostacc.o apam.o doinit.o init_tfx.o scaleswn.o $(NRAND).o karlin.o c_dispn.o lib_sel.o url_subs.o $(LGETLIB) $(NCBL_LIB) $(PLIB) $(LIB_M)
2994 X
2995 pv34comptfy : p2_complib.o compacc.o showbest.o $(SHOWALIGN).o htime.o hostacc.o apam.o doinit.o init_tfy.o scaleswn.o $(NRAND).o karlin.o c_dispn.o lib_sel.o url_subs.o $(LGETLIB) $(NCBL_LIB)
2996 X       $(CC) $(HFLAGS) pv34comptfy p2_complib.o compacc.o showbest.o $(SHOWALIGN).o htime.o hostacc.o apam.o doinit.o init_tfy.o scaleswn.o $(NRAND).o karlin.o c_dispn.o lib_sel.o url_subs.o $(LGETLIB) $(NCBL_LIB) $(PLIB) $(LIB_M)
2997 X
2998 ps34comptfy : p2_complib.o compacc.o showsum.o htime.o hostacc.o apam.o doinit.o init_tfy.o scaleswn.o $(NRAND).o karlin.o c_dispn.o lib_sel.o url_subs.o $(LGETLIB) $(NCBL_LIB)
2999 X       $(CC) $(HFLAGS) ps34comptfy p2_complib.o compacc.o showsum.o htime.o hostacc.o apam.o doinit.o init_tfy.o scaleswn.o $(NRAND).o karlin.o c_dispn.o lib_sel.o url_subs.o $(LGETLIB) $(NCBL_LIB) $(PLIB) $(LIB_M)
3000 X
3001 pu34comptfy : p2_complib.o compacc.o showun.o $(SHOWALIGN)_u.o htime.o hostacc.o apam.o doinit.o init_tfy.o scaleswn.o $(NRAND).o karlin.o c_dispn.o lib_sel.o url_subs.o $(LGETLIB) $(NCBL_LIB)
3002 X       $(CC) $(HFLAGS) pu34comptfy p2_complib.o compacc.o showun.o $(SHOWALIGN)_u.o htime.o hostacc.o apam.o doinit.o init_tfy.o scaleswn.o $(NRAND).o karlin.o c_dispn.o lib_sel.o url_subs.o $(LGETLIB) $(NCBL_LIB) $(PLIB) $(LIB_M)
3003 X
3004 pv34comptfs : p2_complib.o compacc.o showbest.o $(SHOWALIGN).o htime.o hostacc.o apam.o doinit.o init_tfs.o scaleswts.o $(NRAND).o tatstats_fs.o last_tat.o karlin.o c_dispn.o lib_sel.o url_subs.o $(LGETLIB) $(NCBL_LIB)
3005 X       $(CC) $(HFLAGS) pv34comptfs p2_complib.o compacc.o showbest.o $(SHOWALIGN).o htime.o hostacc.o apam.o doinit.o init_tfs.o scaleswts.o $(NRAND).o tatstats_fs.o last_tat.o karlin.o c_dispn.o lib_sel.o url_subs.o $(LGETLIB) $(NCBL_LIB) $(PLIB) $(LIB_M)
3006 X
3007 c34.workfa : p2_workcomp.o $(DROPNFA_O) workacc.o $(NRAND).o faatran.o karlin.o
3008 X       $(NCC) $(NFLAGS) c34.workfa p2_workcomp.o $(DROPNFA_O) workacc.o $(NRAND).o faatran.o karlin.o $(PLIB) $(LIB_WM)
3009 X
3010 c34.worksw : p2_workcomp.o dropnsw.o workacc.o $(NRAND).o faatran.o karlin.o
3011 X       $(NCC) $(NFLAGS) c34.worksw p2_workcomp.o dropnsw.o workacc.o $(NRAND).o faatran.o karlin.o $(PLIB) $(LIB_WM)
3012 X
3013 c34.workgsw : p2_workcomp.o $(DROPGSW_O) workacc.o $(NRAND).o faatran.o karlin.o
3014 X       $(NCC) $(NFLAGS) c34.workgsw p2_workcomp.o $(DROPGSW_O) workacc.o $(NRAND).o faatran.o karlin.o $(PLIB) $(LIB_WM)
3015 X
3016 c34.worknw : p2_workcomp.o dropnw.o workacc.o $(NRAND).o faatran.o karlin.o
3017 X       $(NCC) $(NFLAGS) c34.worknw p2_workcomp.o dropnw.o workacc.o $(NRAND).o faatran.o karlin.o $(PLIB) $(LIB_WM)
3018 X
3019 c34.workfx : p2_workcomp.o drop_fx.o workacc.o $(NRAND).o faatran.o karlin.o
3020 X       $(NCC) $(NFLAGS) c34.workfx p2_workcomp.o drop_fx.o workacc.o $(NRAND).o faatran.o karlin.o $(PLIB) $(LIB_WM)
3021 X
3022 c34.workfs : p2_workcomp.o drop_fs.o workacc.o $(NRAND).o tatstats_fs.o faatran.o
3023 X       $(NCC) $(NFLAGS) c34.workfs p2_workcomp.o drop_fs.o workacc.o $(NRAND).o tatstats_fs.o faatran.o $(PLIB) $(LIB_WM)
3024 X
3025 c34.worktfs : p2_workcomp.o drop_tfs.o workacc.o $(NRAND).o tatstats_fs.o faatran.o
3026 X       $(NCC) $(NFLAGS) c34.worktfs p2_workcomp.o drop_tfs.o workacc.o $(NRAND).o tatstats_fs.o faatran.o $(PLIB) $(LIB_WM)
3027 X
3028 c34.workfy : p2_workcomp.o drop_fz.o workacc.o $(NRAND).o faatran.o karlin.o
3029 X       $(NCC) $(NFLAGS) c34.workfy p2_workcomp.o drop_fz.o workacc.o $(NRAND).o karlin.o faatran.o $(PLIB) $(LIB_WM)
3030 X
3031 c34.worktfx : p2_workcomp.o drop_tfx.o workacc.o $(NRAND).o faatran.o karlin.o
3032 X       $(NCC) $(NFLAGS) c34.worktfx p2_workcomp.o drop_tfx.o workacc.o $(NRAND).o karlin.o faatran.o $(PLIB) $(LIB_WM)
3033 X
3034 c34.worktfy : p2_workcomp.o drop_tfz.o workacc.o $(NRAND).o faatran.o karlin.o
3035 X       $(NCC) $(NFLAGS) c34.worktfy p2_workcomp.o drop_tfz.o workacc.o $(NRAND).o karlin.o  faatran.o $(PLIB) $(LIB_WM)
3036 X
3037 p2_complib.o : p2_complib.c msg.h defs.h upam.h uascii.h param.h structs.h
3038 X       $(CC) -DWORKERPGM=\"c34.work\" $(CFLAGS) p2_complib.c
3039 X
3040 p2_workcomp.o : p2_workcomp.c structs.h msg.h defs.h p_mw.h w_mw.h upam.h uascii.h param.h
3041 X       $(NCC) $(CFLAGS) p2_workcomp.c
3042 X
3043 SHAR_EOF
3044 chmod 0644 Makefile.pvcom ||
3045 echo 'restore of Makefile.pvcom failed'
3046 Wc_c="`wc -c < 'Makefile.pvcom'`"
3047 test 13214 -eq "$Wc_c" ||
3048         echo 'Makefile.pvcom: original size 13214, current size' "$Wc_c"
3049 fi
3050 # ============= Makefile.pvm4 ==============
3051 if test -f 'Makefile.pvm4' -a X"$1" != X"-c"; then
3052         echo 'x - skipping Makefile.pvm4 (File already exists)'
3053 else
3054 echo 'x - extracting Makefile.pvm4 (Text)'
3055 sed 's/^X//' << 'SHAR_EOF' > 'Makefile.pvm4' &&
3056 #
3057 # $Name: fa_34_26_5 $ - $Id: Makefile.pvm4,v 1.35 2006/12/06 16:53:12 wrp Exp $
3058 #
3059 # tested with pvm3.4.beta7 and pvm3.3.11.  Tested on DEC Alpha, x86
3060 # and Alpha LINUX for DEC/Compaq Alpha/LINUX
3061 #
3062 X
3063 #CC=/opt/parasoft/bin.linux2/insure -g -DDEBUG
3064 #CC= cc -O -ggdb -DDEBUG
3065 CC= cc -ggdb -O3 -falign-loops=32 -mcpu=7450 -DMacOSX -faltivec -DSW_ALTIVEC
3066 X
3067 X
3068 #NCC= cc -O3 -ggdb 
3069 NCC= cc -g -falign-loops=32 -O3 -mcpu=7450 -DMacOSX -faltivec -DSW_ALTIVEC
3070 X
3071 #ARCH   =       NETBSDPOWERPC
3072 X
3073 PLIB    =       ${PVM_ROOT}/lib/$(ARCH)/libpvm3.a
3074 XXDIR    =       /home/slib/pvm3/bin/$(ARCH)
3075 #XDIR    =       /wrpx00.p0/users/wrp/pvm3/bin/$(ARCH)
3076 SDIR    =       .
3077 PVMSRC  =       ${PVM_ROOT}/src
3078 X
3079 CFLAGS= -DPVM_SRC -DUNIX -DPCOMPLIB -DBFR=1200 -I${PVM_ROOT}/include -DSRAND=srandom -DRAND=random -c -DHAS_INTTYPES  -DSAMP_STATS -DSHOWSIM
3080 X
3081 HFLAGS= -o
3082 NFLAGS= -o
3083 X
3084 #NCBL_LIB=ncbl2_mlib.o mysql_lib.o
3085 NCBL_LIB=ncbl2_mlib.o
3086 #LIB_M= -L/usr/lib/mysql -lmysqlclient -lm -lz
3087 LIB_M=  -lm
3088 LIB_WM= -lm
3089 X
3090 # standard nxgetaa, no memory mapping for 0 - 6
3091 #LGETLIB=lgetlib.o
3092 #NGETLIB=nmgetlib
3093 X
3094 # memory mapping for 0FASTA, 5PIRVMS, 6GCGBIN
3095 LGETLIB=lgetlib.o lgetaa_m.o
3096 NGETLIB=nmgetlib
3097 X
3098 NRAND=nrandom
3099 X
3100 DROPGSW_O = dropgsw.o smith_waterman_altivec.o
3101 DROPNFA_O = drop_nfa.o
3102 X
3103 # common pv34comp programs
3104 include Makefile.pvcom
3105 X
3106 # common *.o files for all environments
3107 include Makefile.fcom
3108 SHAR_EOF
3109 chmod 0644 Makefile.pvm4 ||
3110 echo 'restore of Makefile.pvm4 failed'
3111 Wc_c="`wc -c < 'Makefile.pvm4'`"
3112 test 1344 -eq "$Wc_c" ||
3113         echo 'Makefile.pvm4: original size 1344, current size' "$Wc_c"
3114 fi
3115 # ============= Makefile.pvm4_sql ==============
3116 if test -f 'Makefile.pvm4_sql' -a X"$1" != X"-c"; then
3117         echo 'x - skipping Makefile.pvm4_sql (File already exists)'
3118 else
3119 echo 'x - extracting Makefile.pvm4_sql (Text)'
3120 sed 's/^X//' << 'SHAR_EOF' > 'Makefile.pvm4_sql' &&
3121 #
3122 # $Name: fa_34_26_5 $ - $Id: Makefile.pvm4_sql,v 1.26 2006/05/19 16:29:45 wrp Exp $
3123 #
3124 # tested with pvm3.4.beta7 and pvm3.3.11.  Tested on DEC Alpha, x86
3125 # and Alpha LINUX for DEC/Compaq Alpha/LINUX
3126 #
3127 X
3128 #CC=/opt/parasoft/bin.linux2/insure -g -DDEBUG
3129 CC= cc -g
3130 NCC= cc -O -g
3131 X
3132 #ARCH   =       NETBSDPOWERPC
3133 X
3134 PLIB    =       ${PVM_ROOT}/lib/$(ARCH)/libpvm3.a
3135 XXDIR    =       /seqprg/pvm3/bin/$(ARCH)
3136 #XDIR    =       /wrpx00.p0/users/wrp/pvm3/bin/$(ARCH)
3137 SDIR    =       .
3138 PVMSRC  =       ${PVM_ROOT}/src
3139 X
3140 CFLAGS= -DPVM_SRC -DUNIX -DPCOMPLIB -DBFR=1200 -DBIGMEM -I${PVM_ROOT}/include -DSRAND=srandom -DRAND=random -c -DHAS_INTTYPES  -DSAMP_STATS -DMYSQL_DB -I/usr/include/mysql -DM10_CONS  -DSHOWSIM
3141 # -DSFCHAR="'|'" -DSUPERFAMNUM
3142 X
3143 HFLAGS= -o
3144 NFLAGS= -o
3145 X
3146 NCBL_LIB=ncbl2_mlib.o mysql_lib.o
3147 #  pgsql_lib.o
3148 #NCBL_LIB=ncbl2_mlib.o
3149 LIB_M= -L/usr/lib/mysql -lmysqlclient -lm
3150 #LIB_M=  -lm
3151 LIB_WM= -lm
3152 X
3153 # standard nxgetaa, no memory mapping for 0 - 6
3154 #LGETLIB=lgetlib.o
3155 #NGETLIB=nmgetlib
3156 X
3157 # memory mapping for 0FASTA, 5PIRVMS, 6GCGBIN
3158 LGETLIB=lgetlib.o lgetaa_m.o
3159 NGETLIB=nmgetlib
3160 X
3161 NRAND=nrandom
3162 X
3163 # non-ALTIVEC versions
3164 DROPGSW_O = dropgsw.o
3165 DROPNFA_O = drop_nfa.o
3166 X
3167 # common pv34comp programs
3168 include Makefile.pvcom
3169 X
3170 # common *.o files for all environments
3171 include Makefile.fcom
3172 X
3173 SHAR_EOF
3174 chmod 0644 Makefile.pvm4_sql ||
3175 echo 'restore of Makefile.pvm4_sql failed'
3176 Wc_c="`wc -c < 'Makefile.pvm4_sql'`"
3177 test 1264 -eq "$Wc_c" ||
3178         echo 'Makefile.pvm4_sql: original size 1264, current size' "$Wc_c"
3179 fi
3180 # ============= Makefile.sgi ==============
3181 if test -f 'Makefile.sgi' -a X"$1" != X"-c"; then
3182         echo 'x - skipping Makefile.sgi (File already exists)'
3183 else
3184 echo 'x - extracting Makefile.sgi (Text)'
3185 sed 's/^X//' << 'SHAR_EOF' > 'Makefile.sgi' &&
3186 #
3187 # makefile for fasta3, fasta3_t.  Use makefile.pvm for pvcompxx.
3188 #
3189 # for more information on FASTA on SGI's, see:
3190 #
3191 #       http://www.sgi.com/chembio/resources/fasta/index.html
3192 #
3193 # use -DBIG_LIB64 to generate 64-bit offsets in map_db .xin files.  This
3194 # only works on SGI's with the -64 option.
3195 X
3196 CC= cc -w -64 -mips4 -O2 -TENV:X=3 -DSGI_BUG -Wl,-multigot -DIRIX
3197 #CC= cc -64 -mips4 -g -DSGI_BUG -DDEBUG -DIRIX
3198 X
3199 HFLAGS= -64 -mips4 -o
3200 NFLAGS= -64 -mips4 -o
3201 X
3202 #CC= cc -g
3203 #HFLAGS= -o
3204 #NFLAGS= -o
3205 X
3206 LIB_M= -lm
3207 # For R2000/R3000 MIPS Processors, use -mips1
3208 #
3209 #CC= cc -mips1 -O2 
3210 #HFLAGS= -mips1 -o
3211 #NFLAGS= -mips1 -o
3212 #
3213 # For R4000 MIPS Processors, use -mips2:
3214 #
3215 #CC = cc -mips2 -O2
3216 #HFLAGS= -mips2 -o
3217 #NFLAGS= -mips2 -o
3218 #
3219 X
3220 CFLAGS= -DSHOWSIM -DUNIX -DTIMES -DHZ=100 -DBIGMEM -DSFCHAR="':'" -DMAX_WORKERS=4 -DTHR_EXIT=pthread_exit -DPROGRESS -DFASTA_HOST='"crick.med.virginia.edu/fasta/cgi"' -DIS_BIG_ENDIAN -DUSE_MMAP -DBIG_LIB64 -DHAS_INTTYPES -DSAMP_STATS -DPGM_DOC
3221 X
3222 THR_SUBS = pthr_subs2
3223 THR_LIBS = -lpthread
3224 THR_CC =
3225 X
3226 XXDIR = /seqprg/slib/bin
3227 X
3228 DROPNFA_O = drop_nfa.o
3229 DROPGSW_O = dropgsw.o
3230 DROPRSS_O = dropnsw.o
3231 DROPTFA_O = drop_tfa.o
3232 X
3233 # renamed (fasta34)  programs
3234 include Makefile34m.common
3235 # conventional (fasta3) names
3236 # include Makefile.common
3237 SHAR_EOF
3238 chmod 0644 Makefile.sgi ||
3239 echo 'restore of Makefile.sgi failed'
3240 Wc_c="`wc -c < 'Makefile.sgi'`"
3241 test 1238 -eq "$Wc_c" ||
3242         echo 'Makefile.sgi: original size 1238, current size' "$Wc_c"
3243 fi
3244 # ============= Makefile.sun ==============
3245 if test -f 'Makefile.sun' -a X"$1" != X"-c"; then
3246         echo 'x - skipping Makefile.sun (File already exists)'
3247 else
3248 echo 'x - extracting Makefile.sun (Text)'
3249 sed 's/^X//' << 'SHAR_EOF' > 'Makefile.sun' &&
3250 #
3251 # makefile for fasta3, fasta3_t.  Use makefile.pvm for pvcompxx.
3252 X
3253 #CC= cc -g -xarch=v8plusa
3254 X
3255 # switches for 64-bit addressing
3256 CC= cc -fast -xO4 -xarch=v9
3257 #CC= cc -g -xarch=v9
3258 X
3259 # for SUNMP, use -DTHR_EXIT=thr_exit
3260 # HZ=100 for Solaris x86
3261 # -DIS_LITTLE_ENDIAN for Solaris x86
3262 X
3263 CFLAGS= -DSHOWSIM -DUNIX -DTIMES -DHZ=100 -DBIGMEM -DSFCHAR="':'" -DMAX_WORKERS=2 -DTHR_EXIT=thr_exit -DPROGRESS -DFASTA_setscope -DUSE_MMAP -DBIG_LIB64 -DHAS_INTTYPES -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -DUSE_FSEEKO -DM10_CONS -DSAMP_STATS -DPGM_DOC
3264 HFLAGS= -o
3265 NFLAGS= -o
3266 X
3267 # use -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
3268 # for files > 2 GB
3269 X
3270 #for Sun pthreads (preferred, pthreads used on all other platforms)
3271 THR_SUBS = pthr_subs2
3272 THR_LIBS = -lpthread
3273 THR_CC =
3274 X
3275 #for Sun threads (no longer necessary as Sun supports pthreads)
3276 #THR_SUBS = uthr_subs2
3277 #THR_LIBS = -lthread
3278 #THR_CC =
3279 X
3280 LIB_M= -lmopt
3281 XXDIR = /seqprg/bin
3282 X
3283 DROPNFA_O = drop_nfa.o
3284 DROPGSW_O = dropgsw.o
3285 DROPRSS_O = dropnsw.o
3286 DROPTFA_O = drop_tfa.o
3287 X
3288 # renamed (fasta34)  programs
3289 include Makefile34m.common
3290 # conventional (fasta3) names
3291 # include Makefile.common
3292 SHAR_EOF
3293 chmod 0644 Makefile.sun ||
3294 echo 'restore of Makefile.sun failed'
3295 Wc_c="`wc -c < 'Makefile.sun'`"
3296 test 1150 -eq "$Wc_c" ||
3297         echo 'Makefile.sun: original size 1150, current size' "$Wc_c"
3298 fi
3299 # ============= Makefile.sun_x86 ==============
3300 if test -f 'Makefile.sun_x86' -a X"$1" != X"-c"; then
3301         echo 'x - skipping Makefile.sun_x86 (File already exists)'
3302 else
3303 echo 'x - extracting Makefile.sun_x86 (Text)'
3304 sed 's/^X//' << 'SHAR_EOF' > 'Makefile.sun_x86' &&
3305 #
3306 # makefile for fasta3, fasta3_t.  Use makefile.pvm for pvcompxx.
3307 X
3308 # switches for 64-bit addressing - AMD64
3309 CC= cc -g -fast -xarch=amd64 -DSW_SSE2
3310 X
3311 # debugging options
3312 #CC= cc -g -DDEBUG -xarch=amd64 -DSW_SSE2
3313 X
3314 # for SUNMP, use -DTHR_EXIT=thr_exit
3315 # HZ=100 for Solaris x86
3316 # Solaris X86 is little endian - be certain IS_BIG_ENDIAN is not defined
3317 X
3318 CFLAGS= -DSHOWSIM -DUNIX -DTIMES -DHZ=100 -DBIGMEM -DSFCHAR="':'" -DMAX_WORKERS=2 -DTHR_EXIT=thr_exit -DPROGRESS -DFASTA_setscope -DUSE_MMAP -DBIG_LIB64 -DHAS_INTTYPES -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -DUSE_FSEEKO -DM10_CONS -DSAMP_STATS -DPGM_DOC
3319 HFLAGS= -o
3320 NFLAGS= -o
3321 X
3322 # use -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
3323 # for files > 2 GB
3324 X
3325 #for Sun pthreads (preferred, pthreads used on all other platforms)
3326 THR_SUBS = pthr_subs2
3327 THR_LIBS = -lpthread
3328 THR_CC =
3329 X
3330 #for Sun threads (no longer necessary as Sun supports pthreads)
3331 #THR_SUBS = uthr_subs2
3332 #THR_LIBS = -lthread
3333 #THR_CC =
3334 X
3335 LIB_M= -lmopt
3336 XXDIR = /seqprg/bin
3337 X
3338 DROPNFA_O = drop_nfa.o
3339 DROPTFA_O = drop_tfa.o
3340 DROPGSW_O = dropgsw.o smith_waterman_sse2.o
3341 DROPRSS_O = dropnsw.o smith_waterman_sse2.o
3342 X
3343 # renamed (fasta34)  programs
3344 include Makefile34m.common
3345 # conventional (fasta3) names
3346 # include Makefile.common
3347 SHAR_EOF
3348 chmod 0644 Makefile.sun_x86 ||
3349 echo 'restore of Makefile.sun_x86 failed'
3350 Wc_c="`wc -c < 'Makefile.sun_x86'`"
3351 test 1264 -eq "$Wc_c" ||
3352         echo 'Makefile.sun_x86: original size 1264, current size' "$Wc_c"
3353 fi
3354 # ============= Makefile.tc ==============
3355 if test -f 'Makefile.tc' -a X"$1" != X"-c"; then
3356         echo 'x - skipping Makefile.tc (File already exists)'
3357 else
3358 echo 'x - extracting Makefile.tc (Text)'
3359 sed 's/^X//' << 'SHAR_EOF' > 'Makefile.tc' &&
3360 #
3361 # makefile for fasta3, fasta3_t.  Use makefile.pvm for pvcompxx.
3362 X
3363 # MSDOS Borland C commands
3364 #CC= bcc -mm -w-rvl -w-pro -3 -O
3365 CC= bcc32 -WC -w-rvl -w-pro -3 -O
3366 #CFLAGS= -IC:\bc5\include -DFAR_PTR -DALLOCN0 -DMSDOS 
3367 CFLAGS=-IC:\bc5\include -DBIGMEM -DALLOCN0 -DMSDOS
3368 #CL= bcc -mm
3369 CL= bcc32 -WC
3370 LFLAGS= -LC:\bc5\lib
3371 NRAND= nrand
3372 HZ=100
3373 X
3374 X
3375 XXDIR = /seqprg/slib/bin
3376 X
3377 SPROGS = fasta34.exe ssearch34.exe fastx34.exe tfastx34.exe fasty34.exe tfasty34.exe fasts34.exe tfasts34.exe prss34.exe prfx34.exe
3378 X
3379 PROGS = $(SPROGS)
3380 X
3381 all : $(PROGS)
3382 X
3383 sall: $(SPROGS)
3384 X
3385 clean-up:
3386 X       del *.obj $(PROGS)
3387 X
3388 install:
3389 X       cp $(PROGS) $(XDIR)
3390 X
3391 fasta34.exe : comp_lib.obj compacc.obj showbest.obj showalig.obj htime.obj apam.obj doinit.obj init_fa.obj scaleswn.obj karlin.obj drop_nfa.obj getseq.obj lgetlib.obj regetlib.obj ncbl2_lib.obj c_dispn.obj lib_sel.obj url_subs.obj nrand.obj getopt.obj
3392 X       $(CL) $(LFLAGS) -efasta34.exe comp_lib.obj showalig.obj init_fa.obj drop_nfa.obj getseq.obj  @fasta3.rsp -lm
3393 X
3394 fastx34.exe : comp_lib.obj compacc.obj showbest.obj showalig.obj htime.obj apam.obj doinit.obj init_fx.obj scaleswn.obj karlin.obj drop_fx.obj getseq.obj lgetlib.obj regetlib.obj ncbl2_lib.obj c_dispn.obj lib_sel.obj faatran.obj url_subs.obj nrand.obj getopt.obj
3395 X       $(CL) $(LFLAGS) -efastx34.exe comp_lib.obj showalig.obj init_fx.obj drop_fx.obj faatran.obj getseq.obj  @fasta3.rsp -lm
3396 X
3397 fasty34.exe : comp_lib.obj compacc.obj showbest.obj showalig.obj htime.obj apam.obj doinit.obj init_fy.obj scaleswn.obj karlin.obj drop_fz.obj getseq.obj lgetlib.obj regetlib.obj ncbl2_lib.obj c_dispn.obj lib_sel.obj faatran.obj url_subs.obj nrand.obj
3398 X       $(CL) $(LFLAGS) -efasty34.exe comp_lib.obj showalig.obj init_fy.obj drop_fz.obj faatran.obj getseq.obj  @fasta3.rsp -lm
3399 X
3400 tfastx34.exe : comp_lib.obj compacc.obj showbest.obj showalig.obj htime.obj apam.obj doinit.obj init_tfx.obj getseq.obj lgetlib.obj regetlib.obj ncbl2_lib.obj scaleswn.obj karlin.obj tdropfx.obj c_dispn.obj lib_sel.obj faatran.obj url_subs.obj nrand.obj
3401 X       $(CL) $(LFLAGS) -etfastx34.exe comp_lib.obj showalig.obj init_tfx.obj tdropfx.obj faatran.obj getseq.obj @fasta3.rsp -lm
3402 X
3403 tfasty34.exe : comp_lib.obj compacc.obj showbest.obj showalig.obj htime.obj apam.obj doinit.obj init_tfy.obj getseq.obj lgetlib.obj regetlib.obj ncbl2_lib.obj scaleswn.obj karlin.obj tdropfz.obj c_dispn.obj lib_sel.obj faatran.obj url_subs.obj nrand.obj
3404 X       $(CL) $(LFLAGS) -etfasty34.exe comp_lib.obj showalig.obj init_tfy.obj tdropfz.obj faatran.obj getseq.obj @fasta3.rsp -lm
3405 X
3406 ssearch34.exe : comp_lib.obj compacc.obj showbest.obj showalig.obj htime.obj apam.obj doinit.obj init_sw.obj scaleswn.obj karlin.obj dropgsw.obj getseq.obj lgetlib.obj regetlib.obj ncbl2_lib.obj c_dispn.obj lib_sel.obj url_subs.obj nrand.obj pssm_asn_subs.obj
3407 X       $(CL) $(LFLAGS) -essearch34.exe comp_lib.obj showalig.obj init_sw.obj dropgsw.obj getseq.obj pssm_asn_subs.obj @fasta3.rsp -lm
3408 X
3409 fasts34.exe : comp_lib.obj compacc.obj showbest.obj showalig.obj htime.obj apam.obj doinit.obj init_fs.obj dropfs2.obj scaleswt.obj karlin.obj tatsta_s.obj last_tat.obj getseq.obj lgetlib.obj regetlib.obj ncbl2_lib.obj c_dispn.obj lib_sel.obj url_subs.obj nrand.obj getopt.obj
3410 X       $(CL) $(LFLAGS) -efasts34.exe comp_lib.obj showalig.obj init_fs.obj dropfs2.obj getseq.obj @fasts3.rsp -lm
3411 X
3412 tfasts34.exe : comp_lib.obj compacc.obj showbest.obj showalig.obj htime.obj apam.obj doinit.obj init_tfs.obj droptfs2.obj scaleswt.obj karlin.obj tatsttfs.obj last_tat.obj getseq.obj lgetlib.obj regetlib.obj ncbl2_lib.obj c_dispn.obj lib_sel.obj url_subs.obj nrand.obj faatran.obj getopt.obj
3413 X       $(CL) $(LFLAGS) -etfasts34.exe comp_lib.obj showalig.obj init_tfs.obj droptfs2.obj getseq.obj faatran.obj @tfasts3.rsp -lm
3414 X
3415 prss34.exe : rcomplib.obj compacc.obj htime.obj apam.obj doinit.obj init_rss.obj scaleswn.obj karlin.obj dropgsw.obj llgetaa.obj showrss.obj lib_sel.obj nrand.obj getopt.obj pssm_asn_subs.obj
3416 X       $(CL) $(LFLAGS) -eprss34.exe rcomplib.obj init_rss.obj dropgsw.obj llgetaa.obj nrand.obj @prss3.rsp -lm
3417 X
3418 prfx34.exe : rcomplib.obj compacc.obj htime.obj apam.obj doinit.obj init_rfx.obj scaleswn.obj karlin.obj drop_fx.obj llgetaa.obj faatran.obj showrss.obj lib_sel.obj nrand.obj getopt.obj
3419 X       $(CL) $(LFLAGS) -eprfx34.exe rcomplib.obj init_rfx.obj drop_fx.obj faatran.obj llgetaa.obj  nrand.obj @prss3.rsp -lm
3420 X
3421 comp_lib.obj : comp_lib.c mw.h structs.h defs.h param.h
3422 X       $(CC) $(CFLAGS) -DPGM_DOC -ocomp_lib.obj -c comp_lib.c
3423 X
3424 rcomplib.obj : comp_lib.c mw.h structs.h defs.h param.h
3425 X       $(CC) $(CFLAGS) -DPRSS -orcomplib.obj -c comp_lib.c
3426 X
3427 htime.obj : htime.c
3428 X       $(CC) $(CFLAGS) -c htime.c
3429 X
3430 hxgetaa.obj : hxgetaa.c altlib.h upam.h uascii.h
3431 X       $(CC) $(CFLAGS) -c hxgetaa.c
3432 X
3433 init_sw.obj : initfa.c defs.h param.h upam.h structs.h
3434 X       $(CC) $(THR_CC) $(CFLAGS) -c -DSSEARCH -oinit_sw.obj initfa.c
3435 X
3436 init_ssw.obj : initfa.c defs.h param.h upam.h structs.h
3437 X       $(CC) $(THR_CC) $(CFLAGS) -c -DOSEARCH -oinit_ssw.obj initfa.c
3438 X
3439 init_rss.obj : initfa.c defs.h param.h upam.h structs.h
3440 X       $(CC) $(THR_CC) $(CFLAGS) -c -DPRSS -oinit_rss.obj initfa.c
3441 X
3442 init_rfx.obj : initfa.c defs.h param.h upam.h structs.h
3443 X       $(CC) $(THR_CC) $(CFLAGS) -c -DPRFX -oinit_rfx.obj initfa.c
3444 X
3445 init_fa.obj : initfa.c defs.h param.h upam.h structs.h
3446 X       $(CC) $(THR_CC) $(CFLAGS) -c -DFASTA -oinit_fa.obj initfa.c
3447 X
3448 init_ff.obj : initfa.c defs.h param.h upam.h structs.h
3449 X       $(CC) $(THR_CC) $(CFLAGS) -c -DFASTF -oinit_ff.obj initfa.c
3450 X
3451 init_tf.obj : initfa.c defs.h param.h upam.h structs.h
3452 X       $(CC) $(THR_CC) $(CFLAGS) -c -DFASTF -DTFAST -oinit_tf.obj initfa.c
3453 X
3454 init_fs.obj : initfa.c defs.h param.h upam.h structs.h
3455 X       $(CC) $(THR_CC) $(CFLAGS) -c -DFASTS -oinit_fs.obj initfa.c
3456 X
3457 init_fm.obj : initfa.c defs.h param.h upam.h structs.h
3458 X       $(CC) $(THR_CC) $(CFLAGS) -c -DFASTM -oinit_fm.obj initfa.c
3459 X
3460 init_tfs.obj : initfa.c defs.h param.h upam.h structs.h
3461 X       $(CC) $(THR_CC) $(CFLAGS) -c -DFASTS -DTFAST  -oinit_tfs.obj initfa.c
3462 X
3463 init_tfm.obj : initfa.c defs.h param.h upam.h structs.h
3464 X       $(CC) $(THR_CC) $(CFLAGS) -c -DFASTM -DTFAST  -oinit_tfm.obj initfa.c
3465 X
3466 init_tfa.obj : initfa.c defs.h param.h upam.h structs.h
3467 X       $(CC) $(THR_CC) $(CFLAGS) -c -DFASTA -DTFAST -oinit_tfa.obj initfa.c
3468 X
3469 init_fx.obj : initfa.c defs.h param.h upam.h structs.h
3470 X       $(CC) $(THR_CC) $(CFLAGS) -c -DFASTX -oinit_fx.obj initfa.c
3471 X
3472 init_tfx.obj : initfa.c defs.h param.h upam.h structs.h
3473 X       $(CC) $(THR_CC) $(CFLAGS) -c -DFASTX -DTFAST -oinit_tfx.obj initfa.c
3474 X
3475 init_fy.obj : initfa.c defs.h param.h upam.h structs.h
3476 X       $(CC) $(THR_CC) $(CFLAGS) -c -DFASTY -oinit_fy.obj initfa.c
3477 X
3478 init_tfy.obj : initfa.c defs.h param.h upam.h structs.h
3479 X       $(CC) $(THR_CC) $(CFLAGS) -c -DFASTY -DTFAST -oinit_tfy.obj initfa.c
3480 X
3481 doinit.obj : doinit.c defs.h param.h upam.h structs.h
3482 X       $(CC) $(CFLAGS) -c doinit.c
3483 X
3484 compacc.obj : compacc.c upam.h uascii.h param.h structs.h mw.h defs.h
3485 X       $(CC) $(CFLAGS) -c compacc.c
3486 X
3487 showbest.obj : mshowbest.c mw.h defs.h param.h structs.h mm_file.h
3488 X       $(CC) $(CFLAGS) -oshowbest.obj -c mshowbest.c
3489 X
3490 showrss.obj : showrss.c mw.h defs.h param.h structs.h
3491 X       $(CC) $(CFLAGS) -c showrss.c
3492 X
3493 showalig.obj : mshowalign.c mw.h defs.h structs.h param.h
3494 X       $(CC) $(CFLAGS) -oshowalig.obj -c mshowalign.c
3495 X
3496 c_dispn.obj : c_dispn.c defs.h structs.h param.h 
3497 X       $(CC) $(CFLAGS) -c c_dispn.c
3498 X
3499 lib_sel.obj : lib_sel.c defs.h structs.h
3500 X       $(CC) $(CFLAGS) -c lib_sel.c
3501 X
3502 scaleswn.obj : scaleswn.c defs.h mw.h alt_parms.h
3503 X       $(CC) $(CFLAGS) -c scaleswn.c
3504 X
3505 scaleswt.obj : scaleswt.c defs.h mw.h alt_parms.h
3506 X       $(CC) $(CFLAGS) -c scaleswt.c
3507 X
3508 tatsta_s.obj : tatstats.c defs.h mw.h alt_parms.h tatstats.h
3509 X       $(CC) $(CFLAGS) -DFASTS -otatsta_s.obj -c tatstats.c
3510 X
3511 tatsttfs.obj : tatstats.c defs.h mw.h alt_parms.h tatstats.h
3512 X       $(CC) $(CFLAGS) -DTFAST -DFASTS -otatsttfs.obj -c tatstats.c
3513 X
3514 karlin.obj : karlin.c param.h
3515 X       $(CC) $(CFLAGS) -c karlin.c
3516 X
3517 scaleswg.obj : scaleswg.c defs.h mw.h alt_parms.h
3518 X       $(CC) $(CFLAGS) -c scaleswg.c
3519 X
3520 drop_nfa.obj : dropnfa.c param.h defs.h
3521 X       $(CC) $(CFLAGS) -odrop_nfa.obj -c dropnfa.c
3522 X
3523 drop_ff.obj : dropffa.c mw.h param.h defs.h
3524 X       $(CC) $(CFLAGS) -odrop_ff.obj -c dropffa.c
3525 X
3526 drop_tff.obj : dropffa.c mw.h param.h defs.h
3527 X       $(CC) $(CFLAGS) -DTFAST -odrop_tff.obj -c dropffa.c
3528 X
3529 drop_fx.obj : dropfx.c mw.h upam.h param.h defs.h
3530 X       $(CC) $(CFLAGS) -DFASTX -odrop_fx.obj -c dropfx.c
3531 X
3532 dropfs2.obj : dropfs2.c mw.h upam.h param.h defs.h tatstats.h
3533 X       $(CC) $(CFLAGS) -DFASTS  -c dropfs2.c
3534 X
3535 droptfs2.obj : dropfs2.c mw.h upam.h param.h defs.h tatstats.h
3536 X       $(CC) $(CFLAGS) -DTFAST -DFASTS -c -odroptfs2.obj dropfs2.c
3537 X
3538 tdropfx.obj : dropfx.c mw.h upam.h param.h defs.h
3539 X       $(CC) $(CFLAGS) -DTFAST -otdropfx.obj -c dropfx.c
3540 X
3541 drop_fz.obj : dropfz2.c mw.h upam.h param.h defs.h aamap.h
3542 X       $(CC) $(CFLAGS) -odrop_fz.obj -c dropfz2.c
3543 X
3544 tdropfz.obj : dropfz2.c mw.h upam.h param.h defs.h aamap.h
3545 X       $(CC) $(CFLAGS) -DTFAST -otdropfz.obj -c dropfz2.c
3546 X
3547 dropnsw.obj : dropnsw.c mw.h upam.h param.h structs.h
3548 X       $(CC) $(CFLAGS) -c dropnsw.c
3549 X
3550 dropgsw.obj : dropgsw.c mw.h upam.h param.h structs.h
3551 X       $(CC) $(CFLAGS) -c dropgsw.c
3552 X
3553 dropnw.obj : dropnw.c mw.h upam.h param.h structs.h
3554 X       $(CC) $(CFLAGS) -c dropnw.c
3555 X
3556 llgetaa.obj : llgetaa.c altlib.h upam.h uascii.h
3557 X       $(CC) $(CFLAGS) -DNOLIB -c llgetaa.c
3558 X
3559 lgetlib.obj : nmgetlib.c altlib.h upam.h uascii.h
3560 X       $(CC) $(CFLAGS) -olgetlib.obj  -c nmgetlib.c
3561 X
3562 regetlib.obj : re_getlib.c mw.h mm_file.h
3563 X       $(CC) $(CFLAGS) -oregetlib.obj -c re_getlib.c
3564 X
3565 getseq.obj : getseq.c defs.h uascii.h structs.h upam.h 
3566 X       $(CC) $(CFLAGS) -c getseq.c
3567 X
3568 ncbl_lib.obj : ncbl_lib.c ncbl_head.h
3569 X       $(CC) $(CFLAGS) -c ncbl_lib.c
3570 X
3571 ncbl2_lib.obj : ncbl2_mlib.c ncbl2_head.h
3572 X       $(CC) $(CFLAGS) -c ncbl2_mlib.c
3573 X
3574 faatran.obj : faatran.c upam.h uascii.h
3575 X       $(CC) $(CFLAGS) -c faatran.c
3576 X
3577 url_subs.obj : url_subs.c structs.h param.h
3578 X       $(CC) $(CFLAGS) -c url_subs.c
3579 X
3580 nrand48.obj : nrand48.c
3581 X       $(CC) $(CFLAGS) -c nrand48.c
3582 X
3583 nrand.obj : nrand.c
3584 X       $(CC) $(CFLAGS) -c nrand.c
3585 X
3586 getopt.obj : getopt.c
3587 X       $(CC) $(CFLAGS) -c getopt.c
3588 SHAR_EOF
3589 chmod 0644 Makefile.tc ||
3590 echo 'restore of Makefile.tc failed'
3591 Wc_c="`wc -c < 'Makefile.tc'`"
3592 test 9746 -eq "$Wc_c" ||
3593         echo 'Makefile.tc: original size 9746, current size' "$Wc_c"
3594 fi
3595 # ============= Makefile34.common ==============
3596 if test -f 'Makefile34.common' -a X"$1" != X"-c"; then
3597         echo 'x - skipping Makefile34.common (File already exists)'
3598 else
3599 echo 'x - extracting Makefile34.common (Text)'
3600 sed 's/^X//' << 'SHAR_EOF' > 'Makefile34.common' &&
3601 #
3602 # $Name: fa_34_26_5 $ - $Id: Makefile34.common,v 1.9 2004/02/19 18:29:43 wrp Exp $
3603 #
3604 # commands common to all architectures
3605 # if your architecture does not support "include", append at the end.
3606 #
3607 X
3608 # use for "normal" fasta34(_t) programs - only one query
3609 # COMP_LIBO=comp_lib.o
3610 # COMP_THRO=comp_thr.o
3611 # GETSEQO = getseq.o
3612 X
3613 # use for multiple query sequences
3614 # work with prss34 (yet)
3615 COMP_LIBO=comp_mlib.o
3616 COMP_THRO=comp_mthr.o
3617 GETSEQO = 
3618 X
3619 # standard nxgetaa, no memory mapping for 0 - 6
3620 LGETLIB=getseq.o lgetlib.o
3621 NGETLIB=nmgetlib
3622 X
3623 # memory mapping for 0FASTA, 5PIRVMS, 6GCGBIN
3624 LGETLIB=getseq.o lgetlib.o lgetaa_m.o
3625 NGETLIB=nmgetlib
3626 X
3627 NRAND=nrandom
3628 X
3629 # use ncbl_lib.c for BLAST1.4 support instead of ncbl2_mlib.c
3630 #NCBL_LIB=ncbl_lib.o
3631 X
3632 # this option should support both formats (BLAST1.4 not currently supported): 
3633 #NCBL_LIB=ncbl_lib.o ncbl2_mlib.o
3634 X
3635 # normally use ncbl2_mlib.c
3636 #NCBL_LIB=ncbl2_mlib.o
3637 #LIB_M= -lm
3638 X
3639 # this option supports NCBI BLAST2 and mySQL
3640 # it requires  "-I/usr/local/include/mysql -DMYSQL_DB" in CFLAGS
3641 # and "-L/usr/local/lib/mysql -lmysqlclient -lz" in LIB_M
3642 # some systems may also require a LD_LIBRARY_PATH change
3643 #LIB_M= -L/usr/local/lib/mysql -lmysqlclient -lz -lm
3644 LIB_M= -lm
3645 #NCBL_LIB=ncbl2_mlib.o mysql_lib.o
3646 NCBL_LIB=ncbl2_mlib.o
3647 X
3648 include Makefile.pcom
3649 X
3650 include Makefile.fcom
3651 SHAR_EOF
3652 chmod 0644 Makefile34.common ||
3653 echo 'restore of Makefile34.common failed'
3654 Wc_c="`wc -c < 'Makefile34.common'`"
3655 test 1304 -eq "$Wc_c" ||
3656         echo 'Makefile34.common: original size 1304, current size' "$Wc_c"
3657 fi
3658 # ============= Makefile34.common_sql ==============
3659 if test -f 'Makefile34.common_sql' -a X"$1" != X"-c"; then
3660         echo 'x - skipping Makefile34.common_sql (File already exists)'
3661 else
3662 echo 'x - extracting Makefile34.common_sql (Text)'
3663 sed 's/^X//' << 'SHAR_EOF' > 'Makefile34.common_sql' &&
3664 #
3665 # $Name: fa_34_26_5 $ - $Id: Makefile34.common_sql,v 1.10 2005/12/07 17:22:02 wrp Exp $
3666 #
3667 # commands common to all architectures
3668 # if your architecture does not support "include", append at the end.
3669 #
3670 X
3671 # use for "normal" fasta34(_t) programs - only one query
3672 COMP_LIBO=comp_lib.o
3673 COMP_THRO=comp_thr.o
3674 GETSEQO = getseq.o
3675 # use for multiple query sequences, requires "-n" for DNA fasta, does not
3676 # work with prss34 (yet)
3677 #COMP_LIB=comp_mlib.o
3678 #COMP_THRO=comp_mthr.o
3679 #
3680 # standard nxgetaa, no memory mapping for 0 - 6
3681 LGETLIB=getseq.o lgetlib.o lgetaa_m.o
3682 NGETLIB=nmgetlib
3683 X
3684 # memory mapping for 0FASTA, 5PIRVMS, 6GCGBIN
3685 # LGETLIB=getseq.o lgetlib.o lgetaa_m.o
3686 # NGETLIB=nmgetlib
3687 X
3688 NRAND=nrandom
3689 X
3690 # use ncbl_lib.c for BLAST1.4 support instead of ncbl2_mlib.c
3691 #NCBL_LIB=ncbl_lib.o
3692 X
3693 # this option should support both formats (BLAST1.4 not currently supported): 
3694 #NCBL_LIB=ncbl_lib.o ncbl2_mlib.o
3695 X
3696 # normally use ncbl2_mlib.c
3697 #NCBL_LIB=ncbl2_mlib.o
3698 #LIB_M= -lm
3699 X
3700 # this option supports NCBI BLAST2 and mySQL
3701 # it requires  "-I/usr/include/mysql -DMYSQL_DB" in CFLAGS
3702 # and "-L/usr/lib/mysql -lmysqlclient -lz" in LIB_M
3703 # some systems may also require a LD_LIBRARY_PATH change
3704 LIB_M= -L/usr/lib/mysql -lmysqlclient -lz -lm
3705 #LIB_M= -lm
3706 NCBL_LIB=ncbl2_mlib.o mysql_lib.o
3707 #NCBL_LIB=ncbl2_mlib.o
3708 X
3709 include Makefile.pcom
3710 X
3711 include Makefile.fcom
3712 X
3713 SHAR_EOF
3714 chmod 0644 Makefile34.common_sql ||
3715 echo 'restore of Makefile34.common_sql failed'
3716 Wc_c="`wc -c < 'Makefile34.common_sql'`"
3717 test 1330 -eq "$Wc_c" ||
3718         echo 'Makefile34.common_sql: original size 1330, current size' "$Wc_c"
3719 fi
3720 # ============= Makefile34.nmk_com ==============
3721 if test -f 'Makefile34.nmk_com' -a X"$1" != X"-c"; then
3722         echo 'x - skipping Makefile34.nmk_com (File already exists)'
3723 else
3724 echo 'x - extracting Makefile34.nmk_com (Text)'
3725 sed 's/^X//' << 'SHAR_EOF' > 'Makefile34.nmk_com' &&
3726 #
3727 # $Name: fa_34_26_5 $ - $Id: Makefile34.nmk_com,v 1.2 2006/10/06 17:26:47 wrp Exp $
3728 #
3729 # commands common to all architectures
3730 # if your architecture does not support "include", append at the end.
3731 #
3732 X
3733 # use for "normal" fasta34(_t) programs - only one query
3734 # COMP_LIBO=comp_lib.obj
3735 # COMP_THRO=comp_thr.obj
3736 # GETSEQO = getseq.obj
3737 X
3738 # use for multiple query sequences
3739 COMP_LIBO=comp_mlib.obj
3740 COMP_THRO=comp_mthr.obj
3741 GETSEQO = 
3742 X
3743 # standard nxgetaa, no memory mapping for 0 - 6
3744 LGETLIB=getseq.obj lgetlib.obj 
3745 NGETLIB=nmgetlib
3746 X
3747 # memory mapping for 0FASTA, 5PIRVMS, 6GCGBIN
3748 # no memory mapping for Win32
3749 #LGETLIB= lgetlib.obj lgetaa_m.obj
3750 X
3751 NRAND=nrand
3752 X
3753 # normally use ncbl2_mlib.c
3754 NCBL_LIB=ncbl2_mlib.obj
3755 #LIB_M= -lm
3756 X
3757 include Makefile.nm_pcom
3758 X
3759 include Makefile.nm_fcom
3760 SHAR_EOF
3761 chmod 0755 Makefile34.nmk_com ||
3762 echo 'restore of Makefile34.nmk_com failed'
3763 Wc_c="`wc -c < 'Makefile34.nmk_com'`"
3764 test 765 -eq "$Wc_c" ||
3765         echo 'Makefile34.nmk_com: original size 765, current size' "$Wc_c"
3766 fi
3767 # ============= Makefile34m.common ==============
3768 if test -f 'Makefile34m.common' -a X"$1" != X"-c"; then
3769         echo 'x - skipping Makefile34m.common (File already exists)'
3770 else
3771 echo 'x - extracting Makefile34m.common (Text)'
3772 sed 's/^X//' << 'SHAR_EOF' > 'Makefile34m.common' &&
3773 #
3774 # $Name: fa_34_26_5 $ - $Id: Makefile34m.common,v 1.11 2003/02/27 14:26:14 wrp Exp $
3775 #
3776 # commands common to all architectures
3777 # if your architecture does not support "include", append at the end.
3778 #
3779 X
3780 # use for "normal" fasta34(_t) programs - only one query
3781 # COMP_LIBO=comp_lib.o
3782 # COMP_THRO=comp_thr.o
3783 # GETSEQO = getseq.o
3784 X
3785 # use for multiple query sequences
3786 # work with prss34 (yet)
3787 COMP_LIBO=comp_mlib.o
3788 COMP_THRO=comp_mthr.o
3789 GETSEQO = 
3790 X
3791 # standard nxgetaa, no memory mapping for 0 - 6
3792 #LGETLIB=getseq.o lgetlib.o
3793 #NGETLIB=nmgetlib
3794 X
3795 # memory mapping for 0FASTA, 5PIRVMS, 6GCGBIN
3796 LGETLIB= $(GETSEQO) lgetlib.o lgetaa_m.o
3797 NGETLIB=nmgetlib
3798 X
3799 NRAND=nrandom
3800 X
3801 # use ncbl_lib.c for BLAST1.4 support instead of ncbl2_mlib.c
3802 #NCBL_LIB=ncbl_lib.o
3803 X
3804 # this option should support both formats (BLAST1.4 not currently supported): 
3805 #NCBL_LIB=ncbl_lib.o ncbl2_mlib.o
3806 X
3807 # normally use ncbl2_mlib.c
3808 #NCBL_LIB=ncbl2_mlib.o
3809 #LIB_M= -lm
3810 X
3811 # this option supports NCBI BLAST2 and mySQL
3812 # it requires  "-I/usr/local/include/mysql -DMYSQL_DB" in CFLAGS
3813 # and "-L/usr/local/lib/mysql -lmysqlclient -lz" in LIB_M
3814 # some systems may also require a LD_LIBRARY_PATH change
3815 #LIB_M= -L/usr/local/lib/mysql -lmysqlclient -lz -lm
3816 LIB_M= -lm
3817 #NCBL_LIB=ncbl2_mlib.o mysql_lib.o
3818 NCBL_LIB=ncbl2_mlib.o
3819 X
3820 include Makefile.pcom
3821 X
3822 include Makefile.fcom
3823 SHAR_EOF
3824 chmod 0644 Makefile34m.common ||
3825 echo 'restore of Makefile34m.common failed'
3826 Wc_c="`wc -c < 'Makefile34m.common'`"
3827 test 1311 -eq "$Wc_c" ||
3828         echo 'Makefile34m.common: original size 1311, current size' "$Wc_c"
3829 fi
3830 # ============= Makefile34m.common_mysql ==============
3831 if test -f 'Makefile34m.common_mysql' -a X"$1" != X"-c"; then
3832         echo 'x - skipping Makefile34m.common_mysql (File already exists)'
3833 else
3834 echo 'x - extracting Makefile34m.common_mysql (Text)'
3835 sed 's/^X//' << 'SHAR_EOF' > 'Makefile34m.common_mysql' &&
3836 #
3837 # $Name: fa_34_26_5 $ - $Id: Makefile34m.common_mysql,v 1.3 2005/12/07 17:22:02 wrp Exp $
3838 #
3839 # commands common to all architectures
3840 # if your architecture does not support "include", append at the end.
3841 #
3842 X
3843 # use for "normal" fasta34(_t) programs - only one query
3844 #COMP_LIBO=comp_lib.o
3845 #COMP_THRO=comp_thr.o
3846 #GETSEQO = getseq.o
3847 X
3848 # use for multiple query sequences
3849 # work with prss34 (yet)
3850 COMP_LIBO=comp_mlib.o
3851 COMP_THRO=comp_mthr.o
3852 GETSEQO = 
3853 X
3854 # standard nxgetaa, no memory mapping for 0 - 6
3855 #LGETLIB=getseq.o lgetlib.o
3856 #NGETLIB=nmgetlib
3857 X
3858 # memory mapping for 0FASTA, 5PIRVMS, 6GCGBIN
3859 LGETLIB= $(GETSEQO) lgetlib.o lgetaa_m.o
3860 NGETLIB=nmgetlib
3861 X
3862 NRAND=nrandom
3863 X
3864 # use ncbl_lib.c for BLAST1.4 support instead of ncbl2_mlib.c
3865 #NCBL_LIB=ncbl_lib.o
3866 X
3867 # this option should support both formats (BLAST1.4 not currently supported): 
3868 #NCBL_LIB=ncbl_lib.o ncbl2_mlib.o
3869 X
3870 # normally use ncbl2_mlib.c
3871 #NCBL_LIB=ncbl2_mlib.o
3872 #LIB_M= -lm
3873 X
3874 # this option supports NCBI BLAST2 and mySQL
3875 # it requires  "-I/usr/local/include/mysql -DMYSQL_DB" in CFLAGS
3876 # and "-L/usr/local/lib/mysql -lmysqlclient -lz" in LIB_M
3877 # some systems may also require a LD_LIBRARY_PATH change
3878 LIB_M= -L/usr/lib/mysql -lmysqlclient -lz -lm
3879 #LIB_M= -L/usr/lib/pgsql/ -lpq -lm -lcrypto -lssl
3880 # LIB_M= -lm
3881 NCBL_LIB=ncbl2_mlib.o mysql_lib.o
3882 #NCBL_LIB=ncbl2_mlib.o pgsql_lib.o
3883 # NCBL_LIB=ncbl2_mlib.o
3884 X
3885 include Makefile.pcom
3886 X
3887 include Makefile.fcom
3888 X
3889 SHAR_EOF
3890 chmod 0644 Makefile34m.common_mysql ||
3891 echo 'restore of Makefile34m.common_mysql failed'
3892 Wc_c="`wc -c < 'Makefile34m.common_mysql'`"
3893 test 1395 -eq "$Wc_c" ||
3894         echo 'Makefile34m.common_mysql: original size 1395, current size' "$Wc_c"
3895 fi
3896 # ============= Makefile34m.common_pgsql ==============
3897 if test -f 'Makefile34m.common_pgsql' -a X"$1" != X"-c"; then
3898         echo 'x - skipping Makefile34m.common_pgsql (File already exists)'
3899 else
3900 echo 'x - extracting Makefile34m.common_pgsql (Text)'
3901 sed 's/^X//' << 'SHAR_EOF' > 'Makefile34m.common_pgsql' &&
3902 #
3903 # $Name: fa_34_26_5 $ - $Id: Makefile34m.common_pgsql,v 1.3 2005/12/07 17:22:02 wrp Exp $
3904 #
3905 # commands common to all architectures
3906 # if your architecture does not support "include", append at the end.
3907 #
3908 X
3909 # use for "normal" fasta34(_t) programs - only one query
3910 #COMP_LIBO=comp_lib.o
3911 #COMP_THRO=comp_thr.o
3912 #GETSEQO = getseq.o
3913 X
3914 # use for multiple query sequences
3915 # work with prss34 (yet)
3916 COMP_LIBO=comp_mlib.o
3917 COMP_THRO=comp_mthr.o
3918 GETSEQO = 
3919 X
3920 # standard nxgetaa, no memory mapping for 0 - 6
3921 #LGETLIB=getseq.o lgetlib.o
3922 #NGETLIB=nmgetlib
3923 X
3924 # memory mapping for 0FASTA, 5PIRVMS, 6GCGBIN
3925 LGETLIB= $(GETSEQO) lgetlib.o lgetaa_m.o
3926 NGETLIB=nmgetlib
3927 X
3928 NRAND=nrandom
3929 X
3930 # use ncbl_lib.c for BLAST1.4 support instead of ncbl2_mlib.c
3931 #NCBL_LIB=ncbl_lib.o
3932 X
3933 # this option should support both formats (BLAST1.4 not currently supported): 
3934 #NCBL_LIB=ncbl_lib.o ncbl2_mlib.o
3935 X
3936 # normally use ncbl2_mlib.c
3937 #NCBL_LIB=ncbl2_mlib.o
3938 #LIB_M= -lm
3939 X
3940 # this option supports NCBI BLAST2 and mySQL
3941 # it requires  "-I/usr/local/include/mysql -DMYSQL_DB" in CFLAGS
3942 # and "-L/usr/local/lib/mysql -lmysqlclient -lz" in LIB_M
3943 # some systems may also require a LD_LIBRARY_PATH change
3944 # LIB_M= -L/usr/local/lib/mysql -lmysqlclient -lz -lm
3945 LIB_M= -L/usr/local/pgsql/lib -lpq -lm -lcrypto -lssl
3946 # LIB_M= -lm
3947 #NCBL_LIB=ncbl2_mlib.o mysql_lib.o
3948 NCBL_LIB=ncbl2_mlib.o pgsql_lib.o
3949 # NCBL_LIB=ncbl2_mlib.o
3950 X
3951 include Makefile.pcom
3952 X
3953 include Makefile.fcom
3954 X
3955 SHAR_EOF
3956 chmod 0644 Makefile34m.common_pgsql ||
3957 echo 'restore of Makefile34m.common_pgsql failed'
3958 Wc_c="`wc -c < 'Makefile34m.common_pgsql'`"
3959 test 1407 -eq "$Wc_c" ||
3960         echo 'Makefile34m.common_pgsql: original size 1407, current size' "$Wc_c"
3961 fi
3962 # ============= Makefile34m.common_sql ==============
3963 if test -f 'Makefile34m.common_sql' -a X"$1" != X"-c"; then
3964         echo 'x - skipping Makefile34m.common_sql (File already exists)'
3965 else
3966 echo 'x - extracting Makefile34m.common_sql (Text)'
3967 sed 's/^X//' << 'SHAR_EOF' > 'Makefile34m.common_sql' &&
3968 #
3969 # $Name: fa_34_26_5 $ - $Id: Makefile34m.common_sql,v 1.14 2005/12/07 17:22:02 wrp Exp $
3970 #
3971 # commands common to all architectures
3972 # if your architecture does not support "include", append at the end.
3973 #
3974 X
3975 # use for "normal" fasta34(_t) programs - only one query
3976 #COMP_LIBO=comp_lib.o
3977 #COMP_THRO=comp_thr.o
3978 #GETSEQO = getseq.o
3979 X
3980 # use for multiple query sequences
3981 # work with prss34 (yet)
3982 COMP_LIBO=comp_mlib.o
3983 COMP_THRO=comp_mthr.o
3984 GETSEQO = 
3985 X
3986 # standard nxgetaa, no memory mapping for 0 - 6
3987 #LGETLIB=getseq.o lgetlib.o
3988 #NGETLIB=nmgetlib
3989 X
3990 # memory mapping for 0FASTA, 5PIRVMS, 6GCGBIN
3991 LGETLIB= $(GETSEQO) lgetlib.o lgetaa_m.o
3992 NGETLIB=nmgetlib
3993 X
3994 NRAND=nrandom
3995 X
3996 # use ncbl_lib.c for BLAST1.4 support instead of ncbl2_mlib.c
3997 #NCBL_LIB=ncbl_lib.o
3998 X
3999 # this option should support both formats (BLAST1.4 not currently supported): 
4000 #NCBL_LIB=ncbl_lib.o ncbl2_mlib.o
4001 X
4002 # normally use ncbl2_mlib.c
4003 #NCBL_LIB=ncbl2_mlib.o
4004 #LIB_M= -lm
4005 X
4006 # this option supports NCBI BLAST2 and mySQL
4007 # it requires  "-I/usr/local/include/mysql -DMYSQL_DB" in CFLAGS
4008 # and "-L/usr/lib/mysql -lmysqlclient -lz" in LIB_M
4009 # some systems may also require a LD_LIBRARY_PATH change
4010 # LIB_M= -L/usr/lib/mysql -lmysqlclient -lz -lm
4011 LIB_M= -L/usr/lib/mysql -lmysqlclient -lz -L/usr/local/pgsql/lib -lpq -lm -lcrypto -lssl
4012 # LIB_M= -lm
4013 NCBL_LIB=ncbl2_mlib.o mysql_lib.o pgsql_lib.o
4014 # NCBL_LIB=ncbl2_mlib.o
4015 X
4016 include Makefile.pcom
4017 X
4018 include Makefile.fcom
4019 X
4020 SHAR_EOF
4021 chmod 0644 Makefile34m.common_sql ||
4022 echo 'restore of Makefile34m.common_sql failed'
4023 Wc_c="`wc -c < 'Makefile34m.common_sql'`"
4024 test 1406 -eq "$Wc_c" ||
4025         echo 'Makefile34m.common_sql: original size 1406, current size' "$Wc_c"
4026 fi
4027 # ============= README ==============
4028 if test -f 'README' -a X"$1" != X"-c"; then
4029         echo 'x - skipping README (File already exists)'
4030 else
4031 echo 'x - extracting README (Text)'
4032 sed 's/^X//' << 'SHAR_EOF' > 'README' &&
4033 X
4034 Up to date release notes are available in the file readme.v34t0
4035 X
4036 Documentation on the fasta3 version programs is available in the files:
4037 X
4038 X       fasta3.1        (unix man page)
4039 X       ssearch3.1      (unix man page)
4040 X
4041 X       readme.v34t0    (text descriptions of bug fixes and version history)
4042 X
4043 X       fasta3x.me      (unix -me nroff file)
4044 X       fasta3x.doc     (text version of fast3x.me)
4045 X
4046 The latter two files provide background information on installing the
4047 fasta programs (in particular, the FASTLIBS file), that new users of
4048 the fasta3 package may find useful.  Note that many non-database
4049 searching programs are available in the fasta20 package.
4050 X
4051 X
4052 Documentation on the pvm3/mpi versions of the programs is available
4053 in:
4054 X       readme.pvm_3.4
4055 X
4056 X       
4057 Bill Pearson
4058 wrp@virginia.edu
4059 SHAR_EOF
4060 chmod 0644 README ||
4061 echo 'restore of README failed'
4062 Wc_c="`wc -c < 'README'`"
4063 test 722 -eq "$Wc_c" ||
4064         echo 'README: original size 722, current size' "$Wc_c"
4065 fi
4066 # ============= README.versions ==============
4067 if test -f 'README.versions' -a X"$1" != X"-c"; then
4068         echo 'x - skipping README.versions (File already exists)'
4069 else
4070 echo 'x - extracting README.versions (Text)'
4071 sed 's/^X//' << 'SHAR_EOF' > 'README.versions' &&
4072 X
4073 August, 2002
4074 X
4075 The latest versions of the FASTA search programs are in fasta3.shar.Z.
4076 This file contains the fasta34 series of programs.  fasta34 also runs
4077 the exact same functions threaded (fasta33, fasta33_t) and in parallel
4078 using PVM and MPI.
4079 X
4080 Here is a list of the programs, and where they can be found:
4081 X
4082 program         fasta2          fasta34                 replaced by
4083 X
4084 fasta           yes             fasta34, fasta34_t
4085 X
4086 ssearch         yes             ssearch34, ssearch34_t
4087 X
4088 tfasta          yes             tfasta34, tfasta34_t    (tfastx34 preferred)
4089 X
4090 fastx           yes             fastx34, fastx34_t
4091 fasty           no              fasty34, fasty34_t
4092 X
4093 tfastx          yes             tfastx34, tfastx34_t
4094 tfasty          no              tfasty34, tfasty34_t
4095 X
4096 fasts/tfasts    no              fasts34(_t), tfasts34(_t)
4097 X
4098 fastf/tfastf    no              fastf34(_t), tfastf34(_t)
4099 X
4100 prss            yes             prss34
4101 X
4102 prfx            no              prfx34
4103 X
4104 ================
4105 X
4106 The following programs are part of the fasta2 program package.  The
4107 latest version of fasta2 is fasta20u66.shar.Z.
4108 X
4109 The most useful fasta2 programs are lalign and plalign, which calculate
4110 multiple non-intersecting local alignments using Webb Miller's "sim"
4111 implementation of the Waterman-Eggert algorithm.
4112 X
4113 You should not use the fasta2 programs for library searching; the
4114 fasta3 programs are more sensitive and have better statistics.
4115 X
4116 lalign          yes             no
4117 X
4118 plalign         yes             no
4119 X
4120 flalign         yes             no
4121 X
4122 align           yes             no
4123 X
4124 align0          yes             no
4125 X
4126 lfasta          yes             no
4127 X
4128 randseq         yes             no
4129 X
4130 crandseq        yes             no
4131 X
4132 aacomp          yes             no
4133 X
4134 bestscor        yes             no
4135 X
4136 grease          yes             no
4137 X
4138 tgrease         yes             no
4139 X
4140 garnier         yes             no
4141 X
4142 ================
4143 X
4144 The fasta3.shar.Z and fasta2.shar.Z files a Unix "shell archive" files.
4145 To unpack them, go into an empty directory and type:
4146 X
4147 X        zcat fasta3.shar.Z | sh
4148 X
4149 You can then make the programs by typing:
4150 X
4151 X        make all
4152 X
4153 Makefile's are available for many platforms, e.g.
4154 X
4155 X        make -f Makefile.linux
4156 X        make -f Makefile.sun
4157 X
4158 etc.  You are much better off using the pre-configured Makefile.???
4159 than trying to edit the Makefile (which is designed for a Compaq/HP
4160 Alpha).
4161 X
4162 Precompiled versions of the programs for Mac and Windows are available
4163 in the mac_fasta and win32_fasta directories.  If you are running
4164 MacOSX from the command line, use the Unix version (fasta3.shar.Z and
4165 Makefile.os_x).
4166 X
4167 SHAR_EOF
4168 chmod 0644 README.versions ||
4169 echo 'restore of README.versions failed'
4170 Wc_c="`wc -c < 'README.versions'`"
4171 test 2614 -eq "$Wc_c" ||
4172         echo 'README.versions: original size 2614, current size' "$Wc_c"
4173 fi
4174 # ============= Readme.Mac ==============
4175 if test -f 'Readme.Mac' -a X"$1" != X"-c"; then
4176         echo 'x - skipping Readme.Mac (File already exists)'
4177 else
4178 echo 'x - extracting Readme.Mac (Text)'
4179 sed 's/^X//' << 'SHAR_EOF' > 'Readme.Mac' &&
4180 X
4181 X                       1-January-2002
4182 X
4183 X
4184 This is the first release of the fasta34t10 distribution for the 
4185 Macintosh.  In addition to the traditional "classic" applications that have 
4186 been available in the past for Macintosh FASTA distributions, this release 
4187 also includes "Carbon" versions of the FASTA programs.  Carbon 
4188 applications are designed to work under both MacOSX and under MacOS8.6 and 
4189 later.
4190 X
4191 This is the first "Carbon" implementation of the FASTA programs.  In this 
4192 first implementation, the Mac-like interface for selecting sequence files 
4193 has been disabled, as the older file interface I used is not available 
4194 under Carbon.  This should be implemented in the future.
4195 X
4196 Today, the main advantage of the Carbon implementation is its ability to 
4197 run under MacOSX without needing the classic environment.  However, the 
4198 unix version of the FASTA programs compiles and runs fine under MacOSX, 
4199 simply type:
4200 X
4201 X       make -f Makefile.os_x all
4202 X
4203 However, the Unix version of the FASTA programs expects sequence files and 
4204 libraries to have lines that ends with a linefeed characther ('\n', \012), 
4205 which is different from the traditional Mac return ('\r', \015) end-of-line 
4206 character.  If you work with Mac-like text files under MacOSX, try the "carbon"
4207 FASTA programs.  If you work with Unix-like text files, use the Unix 
4208 version.
4209 X
4210 Bill Pearson
4211 SHAR_EOF
4212 chmod 0644 Readme.Mac ||
4213 echo 'restore of Readme.Mac failed'
4214 Wc_c="`wc -c < 'Readme.Mac'`"
4215 test 1332 -eq "$Wc_c" ||
4216         echo 'Readme.Mac: original size 1332, current size' "$Wc_c"
4217 fi
4218 # ============= a_mark.h ==============
4219 if test -f 'a_mark.h' -a X"$1" != X"-c"; then
4220         echo 'x - skipping a_mark.h (File already exists)'
4221 else
4222 echo 'x - extracting a_mark.h (Text)'
4223 sed 's/^X//' << 'SHAR_EOF' > 'a_mark.h' &&
4224 /* a_mark.h - symbols used to indicate match/mismatch alignment code */
4225 X
4226 /* copyright (c) 2003 William R. Pearson and the U. of Virginia */
4227 X
4228 /* $Name: fa_34_26_5 $ - $Id: a_mark.h,v 1.1 2003/06/26 19:36:32 wrp Exp $ */
4229 X
4230 #define M_BLANK 0
4231 #define M_NEG 1
4232 #define M_ZERO 2
4233 #define M_POS 3
4234 #define M_IDENT 4
4235 #define M_DEL 5
4236 SHAR_EOF
4237 chmod 0644 a_mark.h ||
4238 echo 'restore of a_mark.h failed'
4239 Wc_c="`wc -c < 'a_mark.h'`"
4240 test 321 -eq "$Wc_c" ||
4241         echo 'a_mark.h: original size 321, current size' "$Wc_c"
4242 fi
4243 # ============= aamap.h ==============
4244 if test -f 'aamap.h' -a X"$1" != X"-c"; then
4245         echo 'x - skipping aamap.h (File already exists)'
4246 else
4247 echo 'x - extracting aamap.h (Text)'
4248 sed 's/^X//' << 'SHAR_EOF' > 'aamap.h' &&
4249 X
4250 /*      aamap.gbl       character and number translations */
4251 X
4252 /* $Name: fa_34_26_5 $ - $Id: aamap.h,v 1.1.1.1 1999/10/22 20:55:59 wrp Exp $ */
4253 X
4254 char aacmap[64]={
4255 X       'K','N','K','N','T','T','T','T','R','S','R','S','I','I','M','I',
4256 X       'Q','H','Q','H','P','P','P','P','R','R','R','R','L','L','L','L',
4257 X       'E','D','E','D','A','A','A','A','G','G','G','G','V','V','V','V',
4258 X       'X','Y','X','Y','S','S','S','S','X','C','W','C','L','F','L','F'
4259 X       };
4260 X
4261 int aamap[64];  /* integer aa values */
4262 int aamapr[64]; /* reverse sequence map */
4263 X
4264 X
4265 SHAR_EOF
4266 chmod 0644 aamap.h ||
4267 echo 'restore of aamap.h failed'
4268 Wc_c="`wc -c < 'aamap.h'`"
4269 test 504 -eq "$Wc_c" ||
4270         echo 'aamap.h: original size 504, current size' "$Wc_c"
4271 fi
4272 # ============= ag_stats.c ==============
4273 if test -f 'ag_stats.c' -a X"$1" != X"-c"; then
4274         echo 'x - skipping ag_stats.c (File already exists)'
4275 else
4276 echo 'x - extracting ag_stats.c (Text)'
4277 sed 's/^X//' << 'SHAR_EOF' > 'ag_stats.c' &&
4278 /* this procedure implements Altschul's pre-calculated values for lambda, K */
4279 X
4280 /* $Name: fa_34_26_5 $ - $Id: ag_stats.c,v 1.5 2006/04/12 18:00:01 wrp Exp $ */
4281 X
4282 #include <stdio.h>
4283 #include <stdlib.h>
4284 #include <math.h>
4285 X
4286 #include "alt_parms.h"
4287 X
4288 static double K, Lambda, H;
4289 X
4290 int
4291 ag_parm(char *pam_type, int gdelval, int ggapval)
4292 {
4293 X  int r_v, t_gdelval, t_ggapval;
4294 X
4295 #ifdef OLD_FASTA_GAP
4296 X  t_gdelval = gdelval;
4297 X  t_ggapval = ggapval;
4298 #else
4299 X  t_gdelval = gdelval+ggapval;
4300 X  t_ggapval = ggapval;
4301 #endif
4302 X
4303 X  if (strcmp(pam_type,"BL50")==0 || strcmp(pam_type,"BLOSUM50")==0)
4304 X      r_v = look_p(bl50_p,t_gdelval,t_ggapval,&K,&Lambda,&H);
4305 X  else if (strcmp(pam_type,"BL62")==0 || strcmp(pam_type,"BLOSUM62")==0)
4306 X      r_v = look_p(bl62_p,t_gdelval,t_ggapval,&K,&Lambda,&H);
4307 X  else if (strcmp(pam_type,"P250")==0)
4308 X      r_v = look_p(p250_p,t_gdelval,t_ggapval,&K,&Lambda,&H);
4309 X  else if (strcmp(pam_type,"P120")==0)
4310 X      r_v = look_p(p120_p,t_gdelval,t_ggapval,&K,&Lambda,&H);
4311 X  else if (strcmp(pam_type,"MD_10")==0)
4312 X      r_v = look_p(md10_p,t_gdelval,t_ggapval,&K,&Lambda,&H);
4313 X  else if (strcmp(pam_type,"MD_20")==0)
4314 X      r_v = look_p(md20_p,t_gdelval,t_ggapval,&K,&Lambda,&H);
4315 X  else if (strcmp(pam_type,"MD_40")==0)
4316 X      r_v = look_p(md40_p,t_gdelval,t_ggapval,&K,&Lambda,&H);
4317 X  else if (strcmp(pam_type,"DNA")==0 || strcmp(pam_type,"+5/-4")==0)
4318 X      r_v = look_p(nt54_p,t_gdelval,t_ggapval,&K,&Lambda,&H);
4319 X  else r_v = 0;
4320 X
4321 X  return r_v;
4322 }
4323 X
4324 int
4325 look_p(struct alt_p parm[], int gap, int ext,
4326 X       double *K, double *Lambda, double *H)
4327 {
4328 X  int i;
4329 X
4330 X  gap = -gap;
4331 X  ext = -ext;
4332 X
4333 X  if (gap > parm[1].gap) {
4334 X    *K = parm[0].K;
4335 X    *Lambda = parm[0].Lambda;
4336 X    *H = parm[0].H;
4337 X    return 1;
4338 X  }
4339 X
4340 X  for (i=1; parm[i].gap > 0; i++) {
4341 X    if (parm[i].gap > gap) continue;
4342 X    else if (parm[i].gap == gap && parm[i].ext > ext ) continue;
4343 X    else if (parm[i].gap == gap && parm[i].ext == ext) {
4344 X      *K = parm[i].K;
4345 X      *Lambda = parm[i].Lambda;
4346 X      *H = parm[i].H;
4347 X      return 1;
4348 X    }
4349 X    else break;
4350 X  }
4351 X  return 0;
4352 }
4353 X
4354 int E1_to_s(double e_val, int n0, int n1) {
4355 X  double mp, np, a_n0, a_n0f, a_n1, a_n1f, u;
4356 X  int score;
4357 X
4358 X  a_n0 = (double)n0;
4359 X  a_n0f = log(a_n0)/H;
4360 X
4361 X  a_n1 = (double)n1;
4362 X  a_n1f = log(a_n1)/H;
4363 X
4364 X  mp = a_n0 - a_n0f - a_n1f;
4365 X  np = a_n1 - a_n0f - a_n1f;
4366 X
4367 X  if (np < 1.0) np = 1.0;
4368 X  if (mp < 1.0) mp = 1.0;
4369 X
4370 X  /*
4371 X  e_val = K * np * mp * exp ( - Lambda * score);
4372 X  log(e_val) = log(K np mp) - Lambda * score;
4373 X  (log(K np mp)-log(e_val)) / Lambda = score;
4374 X  */
4375 X  score = (int)((log( K * mp * np) - log(e_val))/Lambda +0.5);
4376 X  if (score < 0) score = 0;
4377 X  return score;
4378 }
4379 X
4380 double s_to_E4(int score, int n0, int  n1)
4381 {
4382 X  double p_val;
4383 X  double mp, np, a_n0, a_n0f, a_n1, a_n1f, u;
4384 X  
4385 X  a_n0 = (double)n0;
4386 X  a_n0f = log(a_n0)/H;
4387 X
4388 X  a_n1 = (double)n1;
4389 X  a_n1f = log(a_n1)/H;
4390 X
4391 X  mp = a_n0 - a_n0f - a_n1f;
4392 X  np = a_n1 - a_n0f - a_n1f;
4393 X
4394 X  if (np < 1.0) np = 1.0;
4395 X  if (mp < 1.0) mp = 1.0;
4396 X
4397 X  p_val = K * np * mp * exp ( - Lambda * score);
4398 X
4399 X  if (p_val > 0.01) p_val = 1.0 - exp(-p_val);
4400 X
4401 X  return p_val * 10000.0;
4402 }
4403 X
4404 SHAR_EOF
4405 chmod 0644 ag_stats.c ||
4406 echo 'restore of ag_stats.c failed'
4407 Wc_c="`wc -c < 'ag_stats.c'`"
4408 test 3021 -eq "$Wc_c" ||
4409         echo 'ag_stats.c: original size 3021, current size' "$Wc_c"
4410 fi
4411 # ============= aln_structs.h ==============
4412 if test -f 'aln_structs.h' -a X"$1" != X"-c"; then
4413         echo 'x - skipping aln_structs.h (File already exists)'
4414 else
4415 echo 'x - extracting aln_structs.h (Text)'
4416 sed 's/^X//' << 'SHAR_EOF' > 'aln_structs.h' &&
4417 X
4418 #ifndef A_STRUCT
4419 #define A_STRUCT
4420 X
4421 struct a_struct {
4422 X  int smin0;           /* coordinate of display start in seqc0 */
4423 X  int smin1;           /* coordinate of display start in seqc1 */
4424 X  int amin0, amax0;    /* coordinate of alignment start in seqc0 */
4425 X  int amin1, amax1;    /* coordinate of alignment start in seqc1 */
4426 X
4427 X  int llen;
4428 X  int llcntx, llcntx_flg, showall;
4429 X
4430 X  int qlrev, qlfact;
4431 X  int llrev, llfact, llmult;
4432 X  int frame;
4433 X
4434 X  int a_len;                   /* consensus alignment length */
4435 X  int nident, nsim, ngap_q, ngap_l, nfs;       /* number of identities, gaps in q, l */
4436 X  long d_start0,d_stop0;
4437 X  long d_start1,d_stop1;
4438 };
4439 X
4440 struct a_res_str {
4441 X  int min0, max0;      /* boundaries of alignment in aa0 */
4442 X  int min1, max1;      /* boundaries of alignment in aa1 */
4443 X  int *res;
4444 X  int nres;
4445 };
4446 #endif
4447 SHAR_EOF
4448 chmod 0644 aln_structs.h ||
4449 echo 'restore of aln_structs.h failed'
4450 Wc_c="`wc -c < 'aln_structs.h'`"
4451 test 758 -eq "$Wc_c" ||
4452         echo 'aln_structs.h: original size 758, current size' "$Wc_c"
4453 fi
4454 # ============= alt_parms.h ==============
4455 if test -f 'alt_parms.h' -a X"$1" != X"-c"; then
4456         echo 'x - skipping alt_parms.h (File already exists)'
4457 else
4458 echo 'x - extracting alt_parms.h (Text)'
4459 sed 's/^X//' << 'SHAR_EOF' > 'alt_parms.h' &&
4460 /* tables of Altschul-Gish parameters */
4461 X
4462 /* $Name: fa_34_26_5 $ - $Id: alt_parms.h,v 1.4 2003/09/08 18:40:04 wrp Exp $ */
4463 X
4464 X
4465 /* first entry must be for (inf,inf) penalty */
4466 X
4467 struct alt_p {
4468 X  int gap;
4469 X  int ext;
4470 X  float Lambda;
4471 X  float K;
4472 X  float H;
4473 };
4474 X
4475 /* BL80 1/2 bit */
4476 struct alt_p bl80_p[] = {
4477 X  {0, 0, 0.343, 0.177, 0.66},
4478 X  {14, 2, 0.336, 0.150, 0.62},
4479 X  {12, 2, 0.328, 0.130, 0.54},
4480 X  {12, 1, 0.314, 0.096, 0.41},
4481 X  {11, 2, 0.320, 0.110, 0.51},
4482 X  {11, 1, 0.296, 0.066, 0.36},
4483 X  {10, 2, 0.311, 0.097, 0.46},
4484 X  {10, 1, 0.282, 0.052, 0.29},
4485 X  { 9, 2, 0.292, 0.069, 0.33},
4486 X  { 9, 1, 0.248, 0.026, 0.18},
4487 X  { 8, 2, 0.271, 0.050, 0.27},
4488 X  { 8, 1, 0.189, 0.0071, 0.07}
4489 };
4490 X
4491 /* BL62 1/2 bit */
4492 struct alt_p bl62_p[] = {
4493 X  {0, 0, 0.318, 0.13, 0.40},
4494 X  {12, 3, 0.305, 0.10, 0.38},
4495 X  {12, 2, 0.300, 0.09, 0.34},
4496 X  {12, 1, 0.275, 0.05, 0.25},
4497 X  {11, 3, 0.301, 0.09, 0.36},
4498 X  {11, 2, 0.286, 0.07, 0.29},
4499 X  {11, 1, 0.255, 0.035, 0.19},
4500 X  {10, 4, 0.293, 0.08, 0.33},
4501 X  {10, 3, 0.281, 0.06, 0.29},
4502 X  {10, 2, 0.266, 0.04, 0.24},
4503 X  {10, 1, 0.216, 0.014, 0.12},
4504 X  {9, 5, 0.286, 0.08, 0.29},
4505 X  {9, 4, 0.273, 0.06, 0.25},
4506 X  {9, 4, 0.273, 0.06, 0.25},
4507 X  {9, 2, 0.244, 0.030, 0.18},
4508 X  {9, 1, 0.176, 0.008, 0.06},
4509 X  {8, 8, 0.270, 0.06, 0.25},
4510 X  {8, 7, 0.270, 0.06, 0.25},
4511 X  {8, 6, 0.262, 0.05, 0.23},
4512 X  {8, 5, 0.262, 0.05, 0.23},
4513 X  {8, 4, 0.262, 0.05, 0.23},
4514 X  {8, 3, 0.243, 0.035, 0.18},
4515 X  {8, 2, 0.215, 0.021, 0.12},
4516 X  {7, 7, 0.247, 0.05, 0.18},
4517 X  {7, 6, 0.247, 0.05, 0.18},
4518 X  {7, 5, 0.230, 0.030, 0.15},
4519 X  {7, 4, 0.230, 0.030, 0.15},
4520 X  {7, 3, 0.208, 0.021, 0.11},
4521 X  {7, 2, 0.164, 0.009, 0.06},
4522 X  {6, 6, 0.200, 0.021, 0.10},
4523 X  {6, 5, 0.200, 0.021, 0.10},
4524 X  {6, 4, 0.179, 0.014, 0.08},
4525 X  {6, 3, 0.153, 0.010, 0.05},
4526 X  {5, 5, 0.131, 0.009, 0.04},
4527 X  {-1, -1, -1.0, -1.0, -1.0},
4528 };
4529 X
4530 /* BL50 1/3 bit */
4531 X
4532 struct alt_p bl50_p[] = {
4533 X  {0, 0, 0.232, 0.11, 0.34},
4534 X  {16, 4, 0.222, 0.08, 0.31},
4535 X  {16, 3, 0.213, 0.06, 0.27},
4536 X  {16, 2, 0.207, 0.05, 0.24},
4537 X  {16, 1, 0.180, 0.024, 0.15},
4538 X  {15, 8, 0.222, 0.09, 0.31},
4539 X  {15, 7, 0.219, 0.08, 0.29},
4540 X  {15, 6, 0.219, 0.08, 0.29},
4541 X  {15, 5, 0.216, 0.07, 0.28},
4542 X  {15, 4, 0.216, 0.07, 0.28},
4543 X  {15, 3, 0.210, 0.06, 0.25},
4544 X  {15, 2, 0.202, 0.05, 0.22},
4545 X  {15, 1, 0.166, 0.018, 0.11},
4546 X  {14, 8, 0.218, 0.08, 0.29},
4547 X  {14, 7, 0.214, 0.07, 0.27},
4548 X  {14, 6, 0.214, 0.07, 0.27},
4549 X  {14, 5, 0.214, 0.07, 0.27},
4550 X  {14, 4, 0.205, 0.05, 0.24},
4551 X  {14, 3, 0.201, 0.05, 0.22},
4552 X  {14, 2, 0.188, 0.034, 0.17},
4553 X  {14, 1, 0.140, 0.009, 0.07},
4554 X  {13, 8, 0.211, 0.06, 0.27},
4555 X  {13, 7, 0.205, 0.05, 0.24},
4556 X  {13, 6, 0.205, 0.05, 0.24},
4557 X  {13, 5, 0.205, 0.05, 0.24},
4558 X  {13, 4, 0.202, 0.05, 0.22},
4559 X  {13, 3, 0.188, 0.034, 0.18},
4560 X  {13, 2, 0.174, 0.025, 0.13},
4561 X  {13, 1, 0.114, 0.006, 0.04},
4562 X  {12, 7, 0.205, 0.06, 0.24},
4563 X  {12, 6, 0.197, 0.05, 0.21},
4564 X  {12, 5, 0.197, 0.05, 0.21},
4565 X  {12, 4, 0.192, 0.04, 0.18},
4566 X  {12, 3, 0.178, 0.028, 0.15},
4567 X  {12, 2, 0.158, 0.019, 0.10},
4568 X  {11, 8, 0.197, 0.05, 0.21},
4569 X  {11, 7, 0.190, 0.04, 0.19},
4570 X  {11, 6, 0.190, 0.04, 0.19},
4571 X  {11, 5, 0.184, 0.04, 0.17},
4572 X  {11, 4, 0.177, 0.031, 0.15},
4573 X  {11, 3, 0.167, 0.028, 0.11},
4574 X  {11, 2, 0.130, 0.009, 0.06},
4575 X  {10, 8, 0.183, 0.04, 0.17},
4576 X  {10, 7, 0.178, 0.035, 0.16},
4577 X  {10, 6, 0.178, 0.035, 0.16},
4578 X  {10, 5, 0.168, 0.026, 0.13},
4579 X  {10, 4, 0.156, 0.020, 0.10},
4580 X  {10, 3, 0.139, 0.013, 0.07},
4581 X  {10, 2, 0.099, 0.007, 0.03},
4582 X  {9, 7, 0.164, 0.029, 0.13},
4583 X  {9, 6, 0.152, 0.021, 0.10},
4584 X  {9, 5, 0.152, 0.021, 0.10},
4585 X  {9, 4, 0.134, 0.014, 0.07},
4586 X  {9, 3, 0.107, 0.008, 0.04},
4587 X  {8, 8, 0.139, 0.017, 0.08},
4588 X  {8, 7, 0.134, 0.015, 0.07},
4589 X  {8, 6, 0.127, 0.013, 0.06},
4590 X  {8, 5, 0.117, 0.011, 0.05},
4591 X  {8, 4, 0.101, 0.009, 0.03},
4592 X  {7, 7, 0.100, 0.010, 0.04},
4593 X  {7, 6, 0.094, 0.010, 0.03},
4594 X  {-1, -1, -1.0, -1.0, -1.0},
4595 };
4596 X
4597 struct alt_p p250_p[] = {
4598 X  {0, 0, 0.229, 0.09, 0.23},
4599 X  {16, 4, 0.217, 0.07, 0.21},
4600 X  {16, 3, 0.208, 0.05, 0.18},
4601 X  {16, 2, 0.200, 0.04, 0.16},
4602 X  {16, 1, 0.172, 0.018, 0.09},
4603 X  {15, 5, 0.215, 0.06, 0.20},
4604 X  {15, 4, 0.208, 0.05, 0.18},
4605 X  {15, 3, 0.203, 0.04, 0.16},
4606 X  {15, 2, 0.193, 0.035, 0.14},
4607 X  {15, 1, 0.154, 0.012, 0.07},
4608 X  {14, 6, 0.212, 0.06, 0.19},
4609 X  {14, 5, 0.204, 0.05, 0.17},
4610 X  {14, 4, 0.204, 0.05, 0.17},
4611 X  {14, 3, 0.194, 0.035, 0.14},
4612 X  {14, 2, 0.180, 0.025, 0.11},
4613 X  {14, 1, 0.131, 0.008, 0.04},
4614 X  {13, 6, 0.206, 0.06, 0.17},
4615 X  {13, 5, 0.196, 0.04, 0.14},
4616 X  {13, 4, 0.196, 0.04, 0.14},
4617 X  {13, 3, 0.184, 0.029, 0.12},
4618 X  {13, 2, 0.163, 0.016, 0.08},
4619 X  {13, 1, 0.110, 0.008, 0.03},
4620 X  {12, 7, 0.199, 0.05, 0.15},
4621 X  {12, 6, 0.191, 0.04, 0.13},
4622 X  {12, 5, 0.191, 0.04, 0.13},
4623 X  {12, 4, 0.181, 0.029, 0.12},
4624 X  {12, 3, 0.170, 0.022, 0.10},
4625 X  {12, 2, 0.145, 0.012, 0.06},
4626 X  {11, 7, 0.186, 0.04, 0.13},
4627 X  {11, 6, 0.180, 0.034, 0.11},
4628 X  {11, 5, 0.180, 0.034, 0.11},
4629 X  {11, 4, 0.165, 0.021, 0.09},
4630 X  {11, 3, 0.153, 0.017, 0.07},
4631 X  {11, 2, 0.122, 0.009, 0.04},
4632 X  {10, 8, 0.175, 0.031, 0.11},
4633 X  {10, 7, 0.171, 0.029, 0.10},
4634 X  {10, 6, 0.165, 0.024, 0.09},
4635 X  {10, 5, 0.158, 0.020, 0.08},
4636 X  {10, 4, 0.148, 0.017, 0.07},
4637 X  {10, 3, 0.129, 0.012, 0.05},
4638 X  {9, 7, 0.151, 0.020, 0.07},
4639 X  {9, 6, 0.146, 0.019, 0.06},
4640 X  {9, 5, 0.137, 0.015, 0.05},
4641 X  {9, 4, 0.121, 0.011, 0.04},
4642 X  {9, 3, 0.102, 0.010, 0.03},
4643 X  {8, 8, 0.123, 0.014, 0.05},
4644 X  {8, 7, 0.123, 0.014, 0.05},
4645 X  {8, 6, 0.115, 0.012, 0.04},
4646 X  {8, 5, 0.107, 0.011, 0.03},
4647 X  {7, 7, 0.090, 0.014, 0.02},
4648 X  {-1, -1, -1.0, -1.0, -1.0},
4649 };
4650 X
4651 struct alt_p p120_p[] = {
4652 X  {0, 0, 0.342, 0.19, 0.63},
4653 X  {12, 4, 0.334, 0.14, 0.60},
4654 X  {12, 3, 0.330, 0.13, 0.57},
4655 X  {12, 2, 0.330, 0.13, 0.57},
4656 X  {12, 1, 0.219, 0.11, 0.46},
4657 X  {11, 3, 0.330, 0.13, 0.57},
4658 X  {11, 2, 0.323, 0.12, 0.51},
4659 X  {11, 1, 0.296, 0.06, 0.38},
4660 X  {10, 5, 0.323, 0.12, 0.54},
4661 X  {10, 4, 0.314, 0.09, 0.50},
4662 X  {10, 3, 0.314, 0.09, 0.50},
4663 X  {10, 2, 0.301, 0.07, 0.42},
4664 X  {10, 1, 0.273, 0.04, 0.28},
4665 X  {9, 5, 0.316, 0.11, 0.49},
4666 X  {9, 4, 0.311, 0.10, 0.45},
4667 X  {9, 3, 0.311, 0.10, 0.45},
4668 X  {9, 2, 0.284, 0.05, 0.35},
4669 X  {9, 1, 0.239, 0.023, 0.18},
4670 X  {8, 6, 0.307, 0.10, 0.43},
4671 X  {8, 5, 0.295, 0.08, 0.39},
4672 X  {8, 4, 0.295, 0.08, 0.39},
4673 X  {8, 3, 0.284, 0.06, 0.34},
4674 X  {8, 2, 0.262, 0.04, 0.26},
4675 X  {8, 1, 0.183, 0.009, 0.08},
4676 X  {7, 7, 0.286, 0.08, 0.34},
4677 X  {7, 6, 0.286, 0.08, 0.34},
4678 X  {7, 5, 0.276, 0.06, 0.31},
4679 X  {7, 4, 0.276, 0.06, 0.31},
4680 X  {7, 3, 0.255, 0.04, 0.24},
4681 X  {7, 2, 0.224, 0.023, 0.16},
4682 X  {6, 6, 0.248, 0.04, 0.23},
4683 X  {6, 5, 0.248, 0.04, 0.23},
4684 X  {6, 4, 0.234, 0.033, 0.19},
4685 X  {6, 3, 0.216, 0.025, 0.15},
4686 X  {6, 2, 0.160, 0.009, 0.06},
4687 X  {5, 5, 0.191, 0.019, 0.11},
4688 X  {5, 4, 0.173, 0.013, 0.09},
4689 X  {5, 3, 0.134, 0.006, 0.05},
4690 X  {-1, -1, -1.0, -1.0, -1.0}
4691 };
4692 X
4693 struct alt_p bl55_p[] = {
4694 X  {0, 0, 0.224, 0.12, 0.36},
4695 X  {16, 4, 0.213, 0.08, 0.32},
4696 X  {16, 3, 0.205, 0.07, 0.28},
4697 X  {16, 2, 0.198, 0.06, 0.23},
4698 X  {16, 1, 0.164, 0.020, 0.12},
4699 X  {15, 8, 0.212, 0.09, 0.31},
4700 X  {15, 7, 0.209, 0.08, 0.30},
4701 X  {15, 6, 0.209, 0.08, 0.30},
4702 X  {15, 5, 0.205, 0.07, 0.28},
4703 X  {15, 4, 0.205, 0.07, 0.28},
4704 X  {15, 3, 0.199, 0.06, 0.25},
4705 X  {15, 2, 0.190, 0.05, 0.20},
4706 X  {15, 1, 0.146, 0.013, 0.09},
4707 X  {14, 7, 0.207, 0.08, 0.29},
4708 X  {14, 6, 0.203, 0.07, 0.27},
4709 X  {14, 5, 0.203, 0.07, 0.27},
4710 X  {14, 4, 0.195, 0.05, 0.24},
4711 X  {14, 3, 0.189, 0.04, 0.21},
4712 X  {14, 2, 0.175, 0.030, 0.16},
4713 X  {14, 1, 0.119, 0.006, 0.05},
4714 X  {13, 8, 0.201, 0.07, 0.27},
4715 X  {13, 7, 0.196, 0.06, 0.24},
4716 X  {13, 6, 0.196, 0.06, 0.24},
4717 X  {13, 5, 0.196, 0.06, 0.24},
4718 X  {13, 4, 0.191, 0.05, 0.21},
4719 X  {13, 3, 0.176, 0.032, 0.17},
4720 X  {13, 2, 0.158, 0.020, 0.12},
4721 X  {12, 8, 0.195, 0.06, 0.24},
4722 X  {12, 7, 0.188, 0.05, 0.21},
4723 X  {12, 6, 0.188, 0.05, 0.21},
4724 X  {12, 5, 0.188, 0.05, 0.21},
4725 X  {12, 4, 0.180, 0.04, 0.18},
4726 X  {12, 3, 0.165, 0.026, 0.14},
4727 X  {12, 2, 0.140, 0.014, 0.08},
4728 X  {11, 8, 0.185, 0.05, 0.20},
4729 X  {11, 7, 0.179, 0.04, 0.18},
4730 X  {11, 6, 0.179, 0.04, 0.18},
4731 X  {11, 5, 0.171, 0.033, 0.16},
4732 X  {11, 4, 0.163, 0.027, 0.13},
4733 X  {11, 3, 0.151, 0.022, 0.10},
4734 X  {11, 2, 0.110, 0.008, 0.04},
4735 X  {10, 10, 0.173, 0.04, 0.16},
4736 X  {10, 9, 0.173, 0.04, 0.16},
4737 X  {10, 8, 0.167, 0.035, 0.15},
4738 X  {10, 7, 0.167, 0.035, 0.15},
4739 X  {10, 6, 0.167, 0.035, 0.15},
4740 X  {10, 5, 0.155, 0.025, 0.12},
4741 X  {10, 4, 0.142, 0.017, 0.09},
4742 X  {10, 3, 0.121, 0.011, 0.06},
4743 X  {9, 9, 0.152, 0.026, 0.11},
4744 X  {9, 8, 0.152, 0.026, 0.11},
4745 X  {9, 7, 0.152, 0.026, 0.11},
4746 X  {9, 6, 0.137, 0.018, 0.08},
4747 X  {9, 5, 0.137, 0.018, 0.08},
4748 X  {9, 4, 0.117, 0.011, 0.05},
4749 X  {9, 3, 0.090, 0.007, 0.03},
4750 X  {8, 8, 0.125, 0.014, 0.07},
4751 X  {8, 7, 0.119, 0.013, 0.06},
4752 X  {8, 6, 0.113, 0.012, 0.05},
4753 X  {8, 5, 0.102, 0.010, 0.04},
4754 X  {8, 4, 0.085, 0.009, 0.03},
4755 X  {7, 7, 0.087, 0.010, 0.03},
4756 X  {-1, -1, -1.0, -1.0, -1.0}
4757 };
4758 X
4759 struct alt_p nt54_p[] =
4760 {
4761 X  {0, 0, 0.192, 0.173, 0.36},
4762 X  {16, 4, 0.192, 0.177, 0.36},
4763 X  {-1, -1, -1.0, -1.0, -1.0}
4764 };
4765 X
4766 struct alt_p rnt54_p[] =
4767 {
4768 X  {0, 0, 0.192, 0.173, 0.36},
4769 X  {16, 4, 0.192, 0.177, 0.36},
4770 X  {-1, -1, -1.0, -1.0, -1.0}
4771 };
4772 X
4773 struct alt_p nt32_p[] = {
4774 X  {0,  0, 0.2712, 0.131, 0.22},
4775 X  {18, 2, 0.2620, 0.100, 0.22},
4776 X  {16, 4, 0.2600, 0.098, 0.22},
4777 X  {16, 2, 0.2540, 0.081, 0.19},
4778 X  {12, 4, 0.2340, 0.054, 0.15},
4779 X  {-1, -1, -1.0, -1.0, -1.0}
4780 };
4781 X
4782 struct alt_p nt13_p[] = {
4783 X  {0,  0,  1.374, 0.711, 1.31},
4784 X  {4,  1,  1.36,  0.67,  1.30},
4785 X  {3,  1,  1.34,  0.58,  1.19},
4786 X  {2,  1,  1.21,  0.34,  0.77},
4787 X  {-1, -1, -1.0, -1.0, -1.0}
4788 };
4789 X
4790 /* PAM-10 (1/10 Hartley ~ 1/3 bit scale) */
4791 X
4792 struct alt_p md10_p[] = {
4793 X  {0, 0, 0.2299, 0.309, 3.45},
4794 X  {20, 4, 0.222, 0.21, 3.1},
4795 X  {20, 2, 0.218, 0.18, 2.9},
4796 X  {18, 4, 0.220, 0.20, 2.9},
4797 X  {18, 2, 0.217, 0.18, 2.7},
4798 X  {16, 4, 0.217, 0.19, 2.8},
4799 X  {16, 2, 0.212, 0.17, 2.3},
4800 X  {14, 4, 0.212, 0.17, 2.5},
4801 X  {14, 2, 0.205, 0.15, 1.9},
4802 X  {12, 4, 0.206, 0.16, 2.1},
4803 X  {12, 2, 0.190, 0.11, 1.3},
4804 X  {-1, -1, -1.0, -1.0, -1.0}
4805 };
4806 X
4807 /* PAM-20 (1/10 Hartley ~ 1/3 bit scale) */
4808 struct alt_p md20_p[] = {
4809 X  {0, 0, 0.230, 0.287, 2.94},
4810 X  {20, 4, 0.221, 0.19, 2.6},
4811 X  {20, 2, 0.219, 0.18, 2.5},
4812 X  {18, 4, 0.220, 0.19, 2.5},
4813 X  {18, 2, 0.218, 0.18, 2.3},
4814 X  {16, 4, 0.218, 0.18, 2.4},
4815 X  {16, 2, 0.213, 0.17, 2.0},
4816 X  {14, 4, 0.213, 0.17, 2.1},
4817 X  {14, 2, 0.204, 0.14, 1.6},
4818 X  {12, 4, 0.207, 0.17, 1.8},
4819 X  {12, 2, 0.187, 0.10, 1.1},
4820 X  {-1, -1, -1.0, -1.0, -1.0}
4821 };
4822 X
4823 /* PAM-40 (1/10 Hartley ~ 1/3 bit scale) */
4824 struct alt_p md40_p[] = {
4825 X  {0,  0, 0.2293, 0.257, 2.22},
4826 X  {20, 4, 0.225, 0.22, 2.1},
4827 X  {20, 2, 0.222, 0.20, 1.9},
4828 X  {18, 4, 0.224, 0.22, 2.0},
4829 X  {18, 2, 0.220, 0.20, 1.8},
4830 X  {16, 4, 0.219, 0.19, 1.8},
4831 X  {16, 2, 0.212, 0.16, 1.5},
4832 X  {14, 4, 0.211, 0.15, 1.6},
4833 X  {14, 2, 0.199, 0.11, 1.2},
4834 X  {12, 4, 0.203, 0.14, 1.3},
4835 X  {12, 2, 0.177, 0.064, 0.7},
4836 X  {-1, -1, -1.0, -1.0, -1.0}
4837 };
4838 SHAR_EOF
4839 chmod 0644 alt_parms.h ||
4840 echo 'restore of alt_parms.h failed'
4841 Wc_c="`wc -c < 'alt_parms.h'`"
4842 test 10311 -eq "$Wc_c" ||
4843         echo 'alt_parms.h: original size 10311, current size' "$Wc_c"
4844 fi
4845 # ============= altlib.h ==============
4846 if test -f 'altlib.h' -a X"$1" != X"-c"; then
4847         echo 'x - skipping altlib.h (File already exists)'
4848 else
4849 echo 'x - extracting altlib.h (Text)'
4850 sed 's/^X//' << 'SHAR_EOF' > 'altlib.h' &&
4851 X
4852 /* $Name: fa_34_26_5 $ - $Id: altlib.h,v 1.9 2006/02/07 17:52:06 wrp Exp $ */
4853 X
4854 /* #ifdef UNIX */
4855 /* ncbi blast 1.3 format */
4856 /*
4857 #define NCBIBL13 11
4858 extern int ncbl_getliba();
4859 extern void ncbl_ranlib();
4860 void ncbl_closelib();
4861 */
4862 #define NCBIBL20 12
4863 /* #endif */
4864 X
4865 #ifdef MYSQL_DB
4866 #define MYSQL_LIB 16
4867 #define LASTLIB MYSQL_LIB+1
4868 #endif
4869 X
4870 #ifdef PGSQL_DB
4871 #define PGSQL_LIB 17
4872 #define LASTLIB PGSQL_LIB+1
4873 #endif
4874 X
4875 #if !defined (LASTLIB) && defined(NCBIBL20)
4876 #define LASTLIB NCBIBL20+1
4877 #endif
4878 #if !defined (LASTLIB)
4879 #define LASTLIB 10
4880 #endif
4881 X
4882 #define FASTA_F 0
4883 #define DEFAULT 0
4884 #define FULLGB 1
4885 #define UNIXPIR 2
4886 #define EMBLSWISS 3
4887 #define INTELLIG 4
4888 #define VMSPIR 5
4889 #define GCGBIN 6
4890 #define LASTTXT 6
4891 X
4892 int agetlib(); void aranlib();  /* pearson fasta format */
4893 int lgetlib(); void lranlib();  /* full uncompressed GB FULLGB*/
4894 int pgetlib(); void pranlib();  /* PIR UNIX protein UNIXPIR */
4895 int egetlib(); void eranlib();  /* EMBL/SWISS-PROT EMBLSWISS */
4896 int igetlib(); void iranlib();  /* Intelligenetics INTELLIG */
4897 int vgetlib(); void vranlib();  /* PIR VMS format */
4898 int gcg_getlib(); void gcg_ranlib();    /* GCG 2bit format */
4899 X
4900 #ifdef NCBIBL20
4901 extern int ncbl2_getliba(); /* ncbi blast 2.0 format */
4902 extern void ncbl2_ranlib();
4903 void ncbl2_closelib();
4904 #endif
4905 X
4906 #ifdef MYSQL_DB
4907 extern int mysql_getlib();
4908 extern void mysql_ranlib();
4909 int mysql_closelib();
4910 #endif
4911 X
4912 int (*getliba[LASTLIB])()={
4913 X  agetlib,lgetlib,pgetlib,egetlib,
4914 X  igetlib,vgetlib,gcg_getlib,agetlib,
4915 X  agetlib,agetlib
4916 #ifdef UNIX
4917 X  ,agetlib
4918 #ifdef NCBIBL13
4919 X  ,ncbl_getliba
4920 #else
4921 X  ,ncbl2_getliba
4922 #endif
4923 #ifdef NCBIBL20
4924 X  ,ncbl2_getliba
4925 #endif
4926 #ifdef MYSQL_DB
4927 X  ,agetlib
4928 X  ,agetlib
4929 X  ,agetlib
4930 X  ,mysql_getlib
4931 #endif
4932 #endif
4933 };
4934 X
4935 void (*ranliba[LASTLIB])()={
4936 X  aranlib,lranlib,pranlib,eranlib,
4937 X  iranlib,vranlib,gcg_ranlib,aranlib,
4938 X  aranlib,aranlib
4939 #ifdef UNIX
4940 X  ,aranlib
4941 #ifdef NCBIBL13
4942 X  ,ncbl_ranlib
4943 #else
4944 X  ,ncbl2_ranlib
4945 #endif
4946 #ifdef NCBIBL20
4947 X  ,ncbl2_ranlib
4948 #endif
4949 #ifdef MYSQL_DB
4950 X  ,aranlib
4951 X  ,aranlib
4952 X  ,aranlib
4953 X  ,mysql_ranlib
4954 #endif
4955 #endif
4956 };
4957 X
4958 X
4959 /* mmap()ed functions */
4960 #ifdef USE_MMAP
4961 int agetlibm(); void aranlibm();
4962 int lgetlibm(); void lranlibm();
4963 void vranlibm();
4964 int gcg_getlibm();
4965 X
4966 int (*getlibam[])()={
4967 X  agetlibm,lgetlibm, NULL, NULL,NULL,agetlibm,gcg_getlibm
4968 };
4969 X
4970 void (*ranlibam[])()={
4971 X  aranlibm,lranlibm,NULL,NULL,NULL,vranlibm,vranlibm
4972 };
4973 #endif
4974 SHAR_EOF
4975 chmod 0644 altlib.h ||
4976 echo 'restore of altlib.h failed'
4977 Wc_c="`wc -c < 'altlib.h'`"
4978 test 2319 -eq "$Wc_c" ||
4979         echo 'altlib.h: original size 2319, current size' "$Wc_c"
4980 fi
4981 # ============= apam.c ==============
4982 if test -f 'apam.c' -a X"$1" != X"-c"; then
4983         echo 'x - skipping apam.c (File already exists)'
4984 else
4985 echo 'x - extracting apam.c (Text)'
4986 sed 's/^X//' << 'SHAR_EOF' > 'apam.c' &&
4987 /*      pam.c   19-June-86
4988 X       copyright (c) 1987 William R. Pearson
4989 X       read in the alphabet and pam matrix data
4990 X       designed for universal matcher
4991 X
4992 X       This version reads BLAST format (square) PAM files
4993 */
4994 X
4995 /* $Name: fa_34_26_5 $ - $Id: apam.c,v 1.41 2007/03/31 18:47:20 wrp Exp $ */
4996 X
4997 #include <stdio.h>
4998 #include <stdlib.h>
4999 #include <string.h>
5000 #include <ctype.h>
5001 X
5002 #include "defs.h"
5003 #include "param.h"
5004 X
5005 #define XTERNAL
5006 #include "uascii.h"
5007 #include "upam.h"
5008 #undef XTERNAL
5009 X
5010 extern void alloc_pam (int d1, int d2, struct pstruct *ppst);
5011 X
5012 void
5013 pam_opts(char *smstr, struct pstruct *ppst) {
5014 X  char *bp;
5015 X
5016 X  ppst->pam_ms = 0;
5017 X  ppst->pamoff = 0;
5018 X
5019 X  if ((bp=strchr(smstr,'-'))!=NULL) {
5020 X    if (!strncmp(bp+1,"MS",2) || !strncmp(bp+1,"ms",2)) {
5021 X      ppst->pam_ms = 1;
5022 X    }
5023 X    else {
5024 X      ppst->pamoff=atoi(bp+1);
5025 X    }
5026 X    *bp = '\0';
5027 X   }
5028 X  else if ((bp=strchr(smstr,'+'))!=NULL) {
5029 X    ppst->pamoff= -atoi(bp+1);
5030 X    *bp = '\0';
5031 X  }
5032 }
5033 X
5034 /* modified 13-Oct-2005 to accomodate assymetrical matrices */
5035 X
5036 int
5037 initpam (char *mfname, struct pstruct *ppst)
5038 {
5039 X   char    line[512], *lp;
5040 X   int     i, j, iaa, pval;
5041 X   int *hsq, nsq;
5042 X   int *sascii;
5043 X   char *sq;
5044 X   int ess_tmp, max_val, min_val;
5045 X   int have_es = 0;
5046 X   FILE   *fmat;
5047 X
5048 X   pam_opts(mfname, ppst);
5049 X
5050 X   if ((fmat = fopen (mfname, "r")) == NULL)
5051 X   {
5052 X      printf ("***WARNING*** cannot open scoring matrix file %s\n", mfname);
5053 X      fprintf (stderr,"***WARNING*** cannot open scoring matrix file %s\n", mfname);
5054 X      return 0;
5055 X   }
5056 X
5057 /* 
5058 X   the size of the alphabet is determined in advance 
5059 */
5060 X   hsq = ppst->hsq;
5061 X   sq = ppst->sq;
5062 X
5063 X   ppst->nt_align = (ppst->dnaseq == SEQT_DNA || ppst->dnaseq == SEQT_RNA);
5064 X
5065 /* 
5066 X     look for alphabet line, skipping the comments
5067 X     alphabet ends up in line[]
5068 */
5069 X   while (fgets (line, sizeof(line), fmat) != NULL && line[0]=='#');
5070 X
5071 X   /* decide whether this is a protein or DNA matrix */
5072 X   if (ppst->nt_align) sascii = &nascii[0];
5073 X   else sascii = &aascii[0];
5074 X
5075 /*
5076 X  re-initialize sascii[] for matrix alphabet
5077 */
5078 X
5079 X   /* save ',' value used by FASTS/FASTM/FASTF */
5080 X   ess_tmp = sascii[','];
5081 X
5082 /*      clear out sascii        */
5083 X   for (i = 0; i <= AAMASK; i++) sascii[i] = NA;
5084 X
5085 /*      set end of line stop    */
5086 X   sascii[0] = sascii['\r'] = sascii['\n'] = EL;
5087 X
5088 X   sascii[','] = ess_tmp;
5089 X
5090 /* read the alphabet - determine alphabet nsq */
5091 X   sq[0] = '\0';
5092 X   for (i = 0, nsq = 1; line[i]; i++) {
5093 X     if (line[i] == '*') have_es = 1;
5094 X     if (line[i] > ' ') sq[nsq++] = toupper (line[i]);
5095 X   }
5096 X   sq[nsq]='\0';
5097 X   nsq--;
5098 X
5099 /* set end of sequence stop */
5100 X   fprintf(stderr,"sq[%d]: %s\n",nsq,sq+1);
5101 X
5102 /* initialize sascii */
5103 X   for (iaa = 1; iaa <= nsq; iaa++) {
5104 X     sascii[sq[iaa]] = iaa;
5105 X   }
5106 X   if (ppst->dnaseq==SEQT_DNA) {
5107 X     sascii['U'] = sascii['T'];
5108 X     sascii['u'] = sascii['t'];
5109 X   }
5110 X   else if (ppst->dnaseq==SEQT_RNA) {
5111 X     sascii['T'] = sascii['U'];
5112 X     sascii['t'] = sascii['u'];
5113 X   }
5114 X
5115 /* 
5116 X   finished with sascii[] 
5117 */
5118 X
5119 /*
5120 X  setup hnt (ambiguous nt hash) values
5121 */
5122 X   hsq[0] = 0;
5123 X   for (iaa = 1; iaa <= nsq; iaa++) {
5124 X     hsq[iaa]=iaa;
5125 X   }
5126 X   if (ppst->nt_align) {       /* DNA ambiguitities */
5127 X     hsq[sascii['R']]=hsq[sascii['M']]=hsq[sascii['W']]=hsq[sascii['A']];
5128 X     hsq[sascii['D']]=hsq[sascii['H']]=hsq[sascii['V']]=hsq[sascii['A']];
5129 X     hsq[sascii['N']]=hsq[sascii['X']]=hsq[sascii['A']];
5130 X     hsq[sascii['Y']]=hsq[sascii['S']]=hsq[sascii['B']]=hsq[sascii['C']];
5131 X     hsq[sascii['K']]=hsq[sascii['G']];
5132 X   }
5133 X   else        /* protein ambiguities */
5134 X     if (ppst->dnaseq == SEQT_UNK || ppst->dnaseq == SEQT_PROT ||
5135 X        (ppst->nsq >= 20 && ppst->nsq <= 24)) {
5136 X     hsq[sascii['B']] = hsq[sascii['N']];
5137 X     hsq[sascii['Z']] = hsq[sascii['E']];
5138 X     hsq[sascii['X']] = hsq[sascii['A']];
5139 X   }
5140 X   /* here if non-DNA, non-protein sequence */
5141 X   else ppst->dnaseq = SEQT_OTHER;
5142 X
5143 /*
5144 X  check for 2D pam  - if not found, allocate it
5145 */
5146 X
5147 X   if (!ppst->have_pam2) {
5148 X     alloc_pam (MAXSQ, MAXSQ, ppst);
5149 X     ppst->have_pam2 = 1;
5150 X   }
5151 X
5152 /*
5153 X  read the scoring matrix values
5154 */
5155 X
5156 X   max_val = -1;
5157 X   min_val =  1;
5158 X   for (j=0; j < nsq; j++) ppst->pam2[0][0][j] = -BIGNUM;
5159 X   for (iaa = 1; iaa <= nsq; iaa++) {  /* read pam value line */
5160 X     if (fgets(line,sizeof(line),fmat)==NULL) {
5161 X       fprintf (stderr," error reading pam line: %s\n",line);
5162 X       exit (1);
5163 X     }
5164 X     /*     fprintf(stderr,"%d/%d %s",iaa,nsq,line); */
5165 X     strtok(line," \t\n");             /* skip the letter (residue) */
5166 X     ppst->pam2[0][i][0] = -BIGNUM;
5167 X     for (j = 1; j <= nsq; j++) {      /* iaa limits to triangle */
5168 X       lp=strtok(NULL," \t\n");                /* get the number string */
5169 X       pval=ppst->pam2[0][iaa][j]=atoi(lp);    /* convert to integer */
5170 X       if (pval > max_val) max_val = pval;
5171 X       if (pval < min_val) min_val = pval;
5172 X     }
5173 X   }
5174 X
5175 X   if (have_es==0) {
5176 X     sascii['*']=nsq;
5177 X     nsq++;
5178 X     sq[nsq]='*';
5179 X     sq[nsq+1]='\0';
5180 X     for (j=1; j<=nsq; j++) ppst->pam2[0][nsq][j]= -1;
5181 X     ppst->pam2[0][nsq][nsq]= max_val/2;
5182 X   }
5183 X
5184 X   ppst->sqx[0]='\0';  /* initialize sqx[] */
5185 X   for (i=1; i<= nsq; i++) {
5186 X     ppst->sqx[i] = sq[i];
5187 X     ppst->sqx[i+nsq] = tolower(sq[i]);
5188 X     if (sascii[aa[i]] < NA && sq[i] >= 'A' && sq[i] <= 'Z')
5189 X       sascii[aa[i] - 'A' + 'a'] = sascii[aa[i]]+nsq;
5190 X   }
5191 X
5192 X   ppst->nsq = nsq;    /* save new nsq */
5193 X   ppst->nsqx = nsq*2; /* save new nsqx */
5194 X
5195 X   ppst->pam_h = max_val;
5196 X   ppst->pam_l = min_val;
5197 X
5198 X   strncpy (ppst->pamfile, mfname, MAX_FN);
5199 X   ppst->pamfile[MAX_FN-1]='\0';
5200 X
5201 X   if (ppst->pam_ms) {
5202 X     strncat(ppst->pamfile,"-MS",MAX_FN-strlen(ppst->pamfile)-1);
5203 X   }
5204 X   ppst->pamfile[MAX_FN-1]='\0';
5205 X   fclose (fmat);
5206 X   return 1;
5207 }
5208 X
5209 /* make a DNA scoring from +match/-mismatch values */
5210 X
5211 void mk_n_pam(int *arr,int siz, int mat, int mis)
5212 {
5213 X  int i, j, k;
5214 X  /* current default match/mismatch values */
5215 X  int max_mat = +5;
5216 X  int min_mis = -4;
5217 X  float f_val, f_scale;
5218 X  
5219 X  f_scale = (float)(mat - mis)/(float)(max_mat - min_mis);
5220 X  
5221 X  k = 0;
5222 X  for (i = 0; i<nnt-1; i++)
5223 X    for (j = 0; j <= i; j++ ) {
5224 X      if (arr[k] == max_mat) arr[k] = mat;
5225 X      else if (arr[k] == min_mis) arr[k] = mis;
5226 X      else if (arr[k] != -1) { 
5227 X       f_val = (arr[k] - min_mis)*f_scale + 0.5;
5228 X       arr[k] = f_val + mis;
5229 X      }
5230 X      k++;
5231 X    }
5232 }
5233 X
5234 struct std_pam_str {
5235 X  char abbrev[6];
5236 X  char name[10];
5237 X  int *pam;
5238 X  float scale;
5239 X  int gdel, ggap;
5240 };
5241 X
5242 static
5243 struct std_pam_str std_pams[] = {
5244 X  {"P120", "PAM120", apam120, 0.346574, -20, -3},
5245 X  {"P250", "PAM250", apam250, 0.231049, -12, -2},
5246 X  {"P10",  "MD10",  a_md10,  0.346574, -27, -4},
5247 X  {"M10",  "MD10",  a_md10,  0.346574, -27, -4},
5248 X  {"MD10", "MD10",  a_md10,  0.346574, -27, -4},
5249 X  {"P20",  "MD20",  a_md20,  0.346574, -26, -4},
5250 X  {"M20",  "MD20",  a_md20,  0.346574, -26, -4},
5251 X  {"MD20", "MD20",  a_md20,  0.346574, -26, -4},
5252 X  {"P40",  "MD40",  a_md40,  0.346574, -25, -4},
5253 X  {"M40",  "MD40",  a_md40,  0.346574, -25, -4},
5254 X  {"MD40", "MD40",  a_md40,  0.346574, -25, -4},
5255 X  {"BL50", "BL50",   abl50,  0.231049, -12, -2},
5256 X  {"BL62", "BL62",   abl62,  0.346574,  -8, -1},
5257 X  {"BP62", "BL62",   abl62,  0.346574, -12, -1},
5258 X  {"BL80", "BL80",   abl80,  0.346574, -12, -2},
5259 X  {"\0",   "\0",     NULL,   0.0,        0,  0}
5260 };
5261 X
5262 int
5263 standard_pam(char *smstr, struct pstruct *ppst, int del_set, int gap_set) {
5264 X
5265 X  struct std_pam_str *std_pam_p;
5266 X
5267 X  pam_opts(smstr, ppst);
5268 X
5269 X  for (std_pam_p = std_pams; std_pam_p->abbrev[0]; std_pam_p++ ) {
5270 X    if (strcmp(smstr,std_pam_p->abbrev)==0) {
5271 X      pam = std_pam_p->pam;
5272 X      strncpy(ppst->pamfile,std_pam_p->name,MAX_FN);
5273 X      ppst->pamfile[MAX_FN-1]='\0';
5274 X      if (ppst->pam_ms) {
5275 X       strncat(ppst->pamfile,"-MS",MAX_FN-strlen(ppst->pamfile)-1);
5276 X      }
5277 X      ppst->pamfile[MAX_FN-1]='\0';
5278 #ifdef OLD_FASTA_GAP
5279 X      if (!del_set) ppst->gdelval = std_pam_p->gdel;
5280 #else
5281 X      if (!del_set) ppst->gdelval = std_pam_p->gdel-std_pam_p->ggap;
5282 #endif
5283 X      if (!gap_set) ppst->ggapval = std_pam_p->ggap;
5284 X      ppst->pamscale = std_pam_p->scale;
5285 X      return 1;
5286 X    }
5287 X  }
5288 X  return 0;
5289 }
5290 X
5291 /* ESS must match uascii.h */
5292 #define ESS 49
5293 X
5294 void
5295 build_xascii(int *qascii, char *save_str) {
5296 X  int i, max_save;
5297 X  int comma_val, term_val;
5298 X  int save_arr[MAX_SSTR];
5299 X
5300 X  comma_val = qascii[','];
5301 X  term_val = qascii['*'];
5302 X
5303 X  /* preserve special characters */
5304 X  for (i=0; i < MAX_SSTR && save_str[i]; i++ ) {
5305 X    save_arr[i] = qascii[save_str[i]];
5306 X  }
5307 X  max_save = i;
5308 X
5309 X  for (i=1; i<128; i++) {
5310 X    qascii[i]=NA;
5311 X  }
5312 X  /* range of values in aax, ntx is from 1..naax,nntx - 
5313 X     do not zero-out qascii[0] - 9 Oct 2002 */
5314 X
5315 X  for (i=1; i<naax; i++) {
5316 X    qascii[aax[i]]=aax[i];
5317 X  }
5318 X
5319 X  for (i=1; i<nntx; i++) {
5320 X    qascii[ntx[i]]=ntx[i];
5321 X  }
5322 X
5323 X  qascii['\n']=qascii['\r']=qascii[0] = EL;
5324 X
5325 X  qascii[','] = comma_val;
5326 X  qascii['*'] = term_val;
5327 X
5328 X  for (i=0; i < max_save; i++) {
5329 X    qascii[save_str[i]]=save_arr[i];
5330 X  }
5331 }
5332 X
5333 /* 
5334 X   checks for lower case letters in *sq array;
5335 X   if not present, map lowercase to upper
5336 */
5337 void
5338 init_ascii(int is_ext, int *sascii, int is_dna) {
5339 X
5340 X  int isq, have_lc;
5341 X  char *sq, term_char;
5342 X  int nsq;
5343 X  
5344 X  if (is_dna==SEQT_UNK) return;
5345 X
5346 X  term_char = sascii['*'];
5347 X
5348 X  if (is_dna==SEQT_DNA || is_dna == SEQT_RNA) {
5349 X    if (is_ext) { 
5350 X      sq = &ntx[0];
5351 X      nsq = nntx;
5352 X    }
5353 X    else {sq = &nt[0]; nsq = nnt;}
5354 X  }
5355 X  else {
5356 X    if (is_ext) { sq = &aax[0]; nsq = naax; }
5357 X    else {sq = &aa[0]; nsq = naa;}
5358 X  }
5359 X
5360 X
5361 /* initialize sascii from sq[], checking for lower-case letters */
5362 X  have_lc = 0;
5363 X  for (isq = 1; isq <= nsq; isq++) {
5364 X     sascii[sq[isq]] = isq;
5365 X     if (sq[isq] >= 'a' && sq[isq] <= 'z') have_lc = 1;
5366 X  }
5367 X
5368 X  /* no lower case letters in alphabet, map lower case to upper */
5369 X  if (have_lc != 1) { 
5370 X    for (isq = 1; isq <= nsq; isq++) {
5371 X      if (sq[isq] >= 'A' && sq[isq] <= 'Z') sascii[sq[isq]-'A'+'a'] = isq;
5372 X    }
5373 X    if (is_dna==1) sascii['u'] = sascii['t'];
5374 X  }
5375 X
5376 X  sascii['*']=term_char;
5377 }
5378 X
5379 print_pam(struct pstruct *ppst) {
5380 X  int i, nsq, ip;
5381 X  char *sq;
5382 X
5383 X  fprintf(stderr," ext_sq_set: %d\n",ppst->ext_sq_set);
5384 X
5385 X  nsq = ppst->nsq;
5386 X  ip = 0;
5387 X  sq = ppst->sq;
5388 X
5389 X  fprintf(stderr," sq[%d]: %s\n",nsq, sq);
5390 X
5391 X  if (ppst->ext_sq_set) {
5392 X    nsq = ppst->nsqx;
5393 X    ip = 1;
5394 X    sq = ppst->sqx;
5395 X    fprintf(stderr," sq[%d]: %s\n",nsq, sq);
5396 X  }
5397 X
5398 X  for (i=1; i<=nsq; i++) {
5399 X    fprintf(stderr," %c:%c - %3d\n",sq[i], sq[i], ppst->pam2[ip][i][i]);
5400 X  }
5401 }
5402 SHAR_EOF
5403 chmod 0644 apam.c ||
5404 echo 'restore of apam.c failed'
5405 Wc_c="`wc -c < 'apam.c'`"
5406 test 10085 -eq "$Wc_c" ||
5407         echo 'apam.c: original size 10085, current size' "$Wc_c"
5408 fi
5409 # ============= blosum45.mat ==============
5410 if test -f 'blosum45.mat' -a X"$1" != X"-c"; then
5411         echo 'x - skipping blosum45.mat (File already exists)'
5412 else
5413 echo 'x - extracting blosum45.mat (Text)'
5414 sed 's/^X//' << 'SHAR_EOF' > 'blosum45.mat' &&
5415 #  Matrix made by matblas from blosum45.iij
5416 #  BLOSUM Clustered Scoring Matrix in 1/3 Bit Units
5417 #  Blocks Database = /data/blocks_5.0/blocks.dat
5418 #  Cluster Percentage: >= 45
5419 #  Entropy =   0.3795, Expected =  -0.2789
5420 X   A  R  N  D  C  Q  E  G  H  I  L  K  M  F  P  S  T  W  Y  V  B  Z  X
5421 A  5 -2 -1 -2 -1 -1 -1  0 -2 -1 -1 -1 -1 -2 -1  1  0 -2 -2  0 -1 -1  0
5422 R -2  7  0 -1 -3  1  0 -2  0 -3 -2  3 -1 -2 -2 -1 -1 -2 -1 -2 -1  0 -1
5423 N -1  0  6  2 -2  0  0  0  1 -2 -3  0 -2 -2 -2  1  0 -4 -2 -3  4  0 -1
5424 D -2 -1  2  7 -3  0  2 -1  0 -4 -3  0 -3 -4 -1  0 -1 -4 -2 -3  5  1 -1
5425 C -1 -3 -2 -3 12 -3 -3 -3 -3 -3 -2 -3 -2 -2 -4 -1 -1 -5 -3 -1 -2 -3 -2
5426 Q -1  1  0  0 -3  6  2 -2  1 -2 -2  1  0 -4 -1  0 -1 -2 -1 -3  0  4 -1
5427 E -1  0  0  2 -3  2  6 -2  0 -3 -2  1 -2 -3  0  0 -1 -3 -2 -3  1  4 -1
5428 G  0 -2  0 -1 -3 -2 -2  7 -2 -4 -3 -2 -2 -3 -2  0 -2 -2 -3 -3 -1 -2 -1
5429 H -2  0  1  0 -3  1  0 -2 10 -3 -2 -1  0 -2 -2 -1 -2 -3  2 -3  0  0 -1
5430 I -1 -3 -2 -4 -3 -2 -3 -4 -3  5  2 -3  2  0 -2 -2 -1 -2  0  3 -3 -3 -1
5431 L -1 -2 -3 -3 -2 -2 -2 -3 -2  2  5 -3  2  1 -3 -3 -1 -2  0  1 -3 -2 -1
5432 K -1  3  0  0 -3  1  1 -2 -1 -3 -3  5 -1 -3 -1 -1 -1 -2 -1 -2  0  1 -1
5433 M -1 -1 -2 -3 -2  0 -2 -2  0  2  2 -1  6  0 -2 -2 -1 -2  0  1 -2 -1 -1
5434 F -2 -2 -2 -4 -2 -4 -3 -3 -2  0  1 -3  0  8 -3 -2 -1  1  3  0 -3 -3 -1
5435 P -1 -2 -2 -1 -4 -1  0 -2 -2 -2 -3 -1 -2 -3  9 -1 -1 -3 -3 -3 -2 -1 -1
5436 S  1 -1  1  0 -1  0  0  0 -1 -2 -3 -1 -2 -2 -1  4  2 -4 -2 -1  0  0  0
5437 T  0 -1  0 -1 -1 -1 -1 -2 -2 -1 -1 -1 -1 -1 -1  2  5 -3 -1  0  0 -1  0
5438 W -2 -2 -4 -4 -5 -2 -3 -2 -3 -2 -2 -2 -2  1 -3 -4 -3 15  3 -3 -4 -2 -2
5439 Y -2 -1 -2 -2 -3 -1 -2 -3  2  0  0 -1  0  3 -3 -2 -1  3  8 -1 -2 -2 -1
5440 V  0 -2 -3 -3 -1 -3 -3 -3 -3  3  1 -2  1  0 -3 -1  0 -3 -1  5 -3 -3 -1
5441 B -1 -1  4  5 -2  0  1 -1  0 -3 -3  0 -2 -3 -2  0  0 -4 -2 -3  4  2 -1
5442 Z -1  0  0  1 -3  4  4 -2  0 -3 -2  1 -1 -3 -1  0 -1 -2 -2 -3  2  4 -1
5443 XX  0 -1 -1 -1 -2 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1  0  0 -2 -1 -1 -1 -1 -1
5444 X
5445 SHAR_EOF
5446 chmod 0644 blosum45.mat ||
5447 echo 'restore of blosum45.mat failed'
5448 Wc_c="`wc -c < 'blosum45.mat'`"
5449 test 1922 -eq "$Wc_c" ||
5450         echo 'blosum45.mat: original size 1922, current size' "$Wc_c"
5451 fi
5452 # ============= blosum50.mat ==============
5453 if test -f 'blosum50.mat' -a X"$1" != X"-c"; then
5454         echo 'x - skipping blosum50.mat (File already exists)'
5455 else
5456 echo 'x - extracting blosum50.mat (Text)'
5457 sed 's/^X//' << 'SHAR_EOF' > 'blosum50.mat' &&
5458 #  Matrix made by matblas from blosum50.iij
5459 #  BLOSUM Clustered Scoring Matrix in 1/3 Bit Units
5460 #  Blocks Database = /data/blocks_5.0/blocks.dat
5461 #  Cluster Percentage: >= 50
5462 #  Entropy =   0.4808, Expected =  -0.3573
5463 X   A  R  N  D  C  Q  E  G  H  I  L  K  M  F  P  S  T  W  Y  V  B  Z  X
5464 A  5 -2 -1 -2 -1 -1 -1  0 -2 -1 -2 -1 -1 -3 -1  1  0 -3 -2  0 -2 -1 -1
5465 R -2  7 -1 -2 -4  1  0 -3  0 -4 -3  3 -2 -3 -3 -1 -1 -3 -1 -3 -1  0 -1
5466 N -1 -1  7  2 -2  0  0  0  1 -3 -4  0 -2 -4 -2  1  0 -4 -2 -3  4  0 -1
5467 D -2 -2  2  8 -4  0  2 -1 -1 -4 -4 -1 -4 -5 -1  0 -1 -5 -3 -4  5  1 -1
5468 C -1 -4 -2 -4 13 -3 -3 -3 -3 -2 -2 -3 -2 -2 -4 -1 -1 -5 -3 -1 -3 -3 -2
5469 Q -1  1  0  0 -3  7  2 -2  1 -3 -2  2  0 -4 -1  0 -1 -1 -1 -3  0  4 -1
5470 E -1  0  0  2 -3  2  6 -3  0 -4 -3  1 -2 -3 -1 -1 -1 -3 -2 -3  1  5 -1
5471 G  0 -3  0 -1 -3 -2 -3  8 -2 -4 -4 -2 -3 -4 -2  0 -2 -3 -3 -4 -1 -2 -2
5472 H -2  0  1 -1 -3  1  0 -2 10 -4 -3  0 -1 -1 -2 -1 -2 -3  2 -4  0  0 -1
5473 I -1 -4 -3 -4 -2 -3 -4 -4 -4  5  2 -3  2  0 -3 -3 -1 -3 -1  4 -4 -3 -1
5474 L -2 -3 -4 -4 -2 -2 -3 -4 -3  2  5 -3  3  1 -4 -3 -1 -2 -1  1 -4 -3 -1
5475 K -1  3  0 -1 -3  2  1 -2  0 -3 -3  6 -2 -4 -1  0 -1 -3 -2 -3  0  1 -1
5476 M -1 -2 -2 -4 -2  0 -2 -3 -1  2  3 -2  7  0 -3 -2 -1 -1  0  1 -3 -1 -1
5477 F -3 -3 -4 -5 -2 -4 -3 -4 -1  0  1 -4  0  8 -4 -3 -2  1  4 -1 -4 -4 -2
5478 P -1 -3 -2 -1 -4 -1 -1 -2 -2 -3 -4 -1 -3 -4 10 -1 -1 -4 -3 -3 -2 -1 -2
5479 S  1 -1  1  0 -1  0 -1  0 -1 -3 -3  0 -2 -3 -1  5  2 -4 -2 -2  0  0 -1
5480 T  0 -1  0 -1 -1 -1 -1 -2 -2 -1 -1 -1 -1 -2 -1  2  5 -3 -2  0  0 -1  0
5481 W -3 -3 -4 -5 -5 -1 -3 -3 -3 -3 -2 -3 -1  1 -4 -4 -3 15  2 -3 -5 -2 -3
5482 Y -2 -1 -2 -3 -3 -1 -2 -3  2 -1 -1 -2  0  4 -3 -2 -2  2  8 -1 -3 -2 -1
5483 V  0 -3 -3 -4 -1 -3 -3 -4 -4  4  1 -3  1 -1 -3 -2  0 -3 -1  5 -4 -3 -1
5484 B -2 -1  4  5 -3  0  1 -1  0 -4 -4  0 -3 -4 -2  0  0 -5 -3 -4  5  2 -1
5485 Z -1  0  0  1 -3  4  5 -2  0 -3 -3  1 -1 -4 -1  0 -1 -2 -2 -3  2  5 -1
5486 XX -1 -1 -1 -1 -2 -1 -1 -2 -1 -1 -1 -1 -1 -2 -2 -1  0 -3 -1 -1 -1 -1 -1
5487 SHAR_EOF
5488 chmod 0644 blosum50.mat ||
5489 echo 'restore of blosum50.mat failed'
5490 Wc_c="`wc -c < 'blosum50.mat'`"
5491 test 1921 -eq "$Wc_c" ||
5492         echo 'blosum50.mat: original size 1921, current size' "$Wc_c"
5493 fi
5494 # ============= blosum62.mat ==============
5495 if test -f 'blosum62.mat' -a X"$1" != X"-c"; then
5496         echo 'x - skipping blosum62.mat (File already exists)'
5497 else
5498 echo 'x - extracting blosum62.mat (Text)'
5499 sed 's/^X//' << 'SHAR_EOF' > 'blosum62.mat' &&
5500 #  Matrix made by matblas from blosum62.iij
5501 #  BLOSUM Clustered Scoring Matrix in 1/2 Bit Units
5502 #  Blocks Database = /data/blocks_5.0/blocks.dat
5503 #  Cluster Percentage: >= 62
5504 #  Entropy =   0.6979, Expected =  -0.5209
5505 X   A  R  N  D  C  Q  E  G  H  I  L  K  M  F  P  S  T  W  Y  V  B  Z  X
5506 A  4 -1 -2 -2  0 -1 -1  0 -2 -1 -1 -1 -1 -2 -1  1  0 -3 -2  0 -2 -1  0
5507 R -1  5  0 -2 -3  1  0 -2  0 -3 -2  2 -1 -3 -2 -1 -1 -3 -2 -3 -1  0 -1
5508 N -2  0  6  1 -3  0  0  0  1 -3 -3  0 -2 -3 -2  1  0 -4 -2 -3  3  0 -1
5509 D -2 -2  1  6 -3  0  2 -1 -1 -3 -4 -1 -3 -3 -1  0 -1 -4 -3 -3  4  1 -1
5510 C  0 -3 -3 -3  9 -3 -4 -3 -3 -1 -1 -3 -1 -2 -3 -1 -1 -2 -2 -1 -3 -3 -2
5511 Q -1  1  0  0 -3  5  2 -2  0 -3 -2  1  0 -3 -1  0 -1 -2 -1 -2  0  3 -1
5512 E -1  0  0  2 -4  2  5 -2  0 -3 -3  1 -2 -3 -1  0 -1 -3 -2 -2  1  4 -1
5513 G  0 -2  0 -1 -3 -2 -2  6 -2 -4 -4 -2 -3 -3 -2  0 -2 -2 -3 -3 -1 -2 -1
5514 H -2  0  1 -1 -3  0  0 -2  8 -3 -3 -1 -2 -1 -2 -1 -2 -2  2 -3  0  0 -1
5515 I -1 -3 -3 -3 -1 -3 -3 -4 -3  4  2 -3  1  0 -3 -2 -1 -3 -1  3 -3 -3 -1
5516 L -1 -2 -3 -4 -1 -2 -3 -4 -3  2  4 -2  2  0 -3 -2 -1 -2 -1  1 -4 -3 -1
5517 K -1  2  0 -1 -3  1  1 -2 -1 -3 -2  5 -1 -3 -1  0 -1 -3 -2 -2  0  1 -1
5518 M -1 -1 -2 -3 -1  0 -2 -3 -2  1  2 -1  5  0 -2 -1 -1 -1 -1  1 -3 -1 -1
5519 F -2 -3 -3 -3 -2 -3 -3 -3 -1  0  0 -3  0  6 -4 -2 -2  1  3 -1 -3 -3 -1
5520 P -1 -2 -2 -1 -3 -1 -1 -2 -2 -3 -3 -1 -2 -4  7 -1 -1 -4 -3 -2 -2 -1 -2
5521 S  1 -1  1  0 -1  0  0  0 -1 -2 -2  0 -1 -2 -1  4  1 -3 -2 -2  0  0  0
5522 T  0 -1  0 -1 -1 -1 -1 -2 -2 -1 -1 -1 -1 -2 -1  1  5 -2 -2  0 -1 -1  0
5523 W -3 -3 -4 -4 -2 -2 -3 -2 -2 -3 -2 -3 -1  1 -4 -3 -2 11  2 -3 -4 -3 -2
5524 Y -2 -2 -2 -3 -2 -1 -2 -3  2 -1 -1 -2 -1  3 -3 -2 -2  2  7 -1 -3 -2 -1
5525 V  0 -3 -3 -3 -1 -2 -2 -3 -3  3  1 -2  1 -1 -2 -2  0 -3 -1  4 -3 -2 -1
5526 B -2 -1  3  4 -3  0  1 -1  0 -3 -4  0 -3 -3 -2  0 -1 -4 -3 -3  4  1 -1
5527 Z -1  0  0  1 -3  3  4 -2  0 -3 -3  1 -1 -3 -1  0 -1 -3 -2 -2  1  4 -1
5528 XX  0 -1 -1 -1 -2 -1 -1 -1 -1 -1 -1 -1 -1 -1 -2  0  0 -2 -1 -1 -1 -1 -1
5529 X
5530 SHAR_EOF
5531 chmod 0644 blosum62.mat ||
5532 echo 'restore of blosum62.mat failed'
5533 Wc_c="`wc -c < 'blosum62.mat'`"
5534 test 1922 -eq "$Wc_c" ||
5535         echo 'blosum62.mat: original size 1922, current size' "$Wc_c"
5536 fi
5537 # ============= blosum80.mat ==============
5538 if test -f 'blosum80.mat' -a X"$1" != X"-c"; then
5539         echo 'x - skipping blosum80.mat (File already exists)'
5540 else
5541 echo 'x - extracting blosum80.mat (Text)'
5542 sed 's/^X//' << 'SHAR_EOF' > 'blosum80.mat' &&
5543 #  Matrix made by matblas from blosum80_3.iij
5544 #  BLOSUM Clustered Scoring Matrix in 1/3 Bit Units
5545 #  Blocks Database = /data/blocks_5.0/blocks.dat
5546 #  Cluster Percentage: >= 80
5547 #  Entropy =   0.9868, Expected =  -0.7442
5548 X   A  R  N  D  C  Q  E  G  H  I  L  K  M  F  P  S  T  W  Y  V  B  Z  X
5549 A  7 -3 -3 -3 -1 -2 -2  0 -3 -3 -3 -1 -2 -4 -1  2  0 -5 -4 -1 -3 -2 -1
5550 R -3  9 -1 -3 -6  1 -1 -4  0 -5 -4  3 -3 -5 -3 -2 -2 -5 -4 -4 -2  0 -2
5551 N -3 -1  9  2 -5  0 -1 -1  1 -6 -6  0 -4 -6 -4  1  0 -7 -4 -5  5 -1 -2
5552 D -3 -3  2 10 -7 -1  2 -3 -2 -7 -7 -2 -6 -6 -3 -1 -2 -8 -6 -6  6  1 -3
5553 C -1 -6 -5 -7 13 -5 -7 -6 -7 -2 -3 -6 -3 -4 -6 -2 -2 -5 -5 -2 -6 -7 -4
5554 Q -2  1  0 -1 -5  9  3 -4  1 -5 -4  2 -1 -5 -3 -1 -1 -4 -3 -4 -1  5 -2
5555 E -2 -1 -1  2 -7  3  8 -4  0 -6 -6  1 -4 -6 -2 -1 -2 -6 -5 -4  1  6 -2
5556 G  0 -4 -1 -3 -6 -4 -4  9 -4 -7 -7 -3 -5 -6 -5 -1 -3 -6 -6 -6 -2 -4 -3
5557 H -3  0  1 -2 -7  1  0 -4 12 -6 -5 -1 -4 -2 -4 -2 -3 -4  3 -5 -1  0 -2
5558 I -3 -5 -6 -7 -2 -5 -6 -7 -6  7  2 -5  2 -1 -5 -4 -2 -5 -3  4 -6 -6 -2
5559 L -3 -4 -6 -7 -3 -4 -6 -7 -5  2  6 -4  3  0 -5 -4 -3 -4 -2  1 -7 -5 -2
5560 K -1  3  0 -2 -6  2  1 -3 -1 -5 -4  8 -3 -5 -2 -1 -1 -6 -4 -4 -1  1 -2
5561 M -2 -3 -4 -6 -3 -1 -4 -5 -4  2  3 -3  9  0 -4 -3 -1 -3 -3  1 -5 -3 -2
5562 F -4 -5 -6 -6 -4 -5 -6 -6 -2 -1  0 -5  0 10 -6 -4 -4  0  4 -2 -6 -6 -3
5563 P -1 -3 -4 -3 -6 -3 -2 -5 -4 -5 -5 -2 -4 -6 12 -2 -3 -7 -6 -4 -4 -2 -3
5564 S  2 -2  1 -1 -2 -1 -1 -1 -2 -4 -4 -1 -3 -4 -2  7  2 -6 -3 -3  0 -1 -1
5565 T  0 -2  0 -2 -2 -1 -2 -3 -3 -2 -3 -1 -1 -4 -3  2  8 -5 -3  0 -1 -2 -1
5566 W -5 -5 -7 -8 -5 -4 -6 -6 -4 -5 -4 -6 -3  0 -7 -6 -5 16  3 -5 -8 -5 -5
5567 Y -4 -4 -4 -6 -5 -3 -5 -6  3 -3 -2 -4 -3  4 -6 -3 -3  3 11 -3 -5 -4 -3
5568 V -1 -4 -5 -6 -2 -4 -4 -6 -5  4  1 -4  1 -2 -4 -3  0 -5 -3  7 -6 -4 -2
5569 B -3 -2  5  6 -6 -1  1 -2 -1 -6 -7 -1 -5 -6 -4  0 -1 -8 -5 -6  6  0 -3
5570 Z -2  0 -1  1 -7  5  6 -4  0 -6 -5  1 -3 -6 -2 -1 -2 -5 -4 -4  0  6 -1
5571 XX -1 -2 -2 -3 -4 -2 -2 -3 -2 -2 -2 -2 -2 -3 -3 -1 -1 -5 -3 -2 -3 -1 -2
5572 X
5573 SHAR_EOF
5574 chmod 0644 blosum80.mat ||
5575 echo 'restore of blosum80.mat failed'
5576 Wc_c="`wc -c < 'blosum80.mat'`"
5577 test 1924 -eq "$Wc_c" ||
5578         echo 'blosum80.mat: original size 1924, current size' "$Wc_c"
5579 fi
5580 # ============= bovgh.seq ==============
5581 if test -f 'bovgh.seq' -a X"$1" != X"-c"; then
5582         echo 'x - skipping bovgh.seq (File already exists)'
5583 else
5584 echo 'x - extracting bovgh.seq (Text)'
5585 sed 's/^X//' << 'SHAR_EOF' > 'bovgh.seq' &&
5586 >BOVGH bovine growth hormone (presomatotropin) gene and flanks.
5587 X AAAACCTATG GGGTGGGCTC TCAAGCTGAG ACCCTGTGTG CACAGCCCTC TGGCTGGTGG
5588 X CAGTGGAGAC GGGATNNNAT GACAAGCCTG GGGGACATGA CCCCAGAGAA GGAACGGGAA
5589 X CAGGATGAGT GAGAGGAGGT TCTAAATTAT CCATTAGCAC AGGCTGCCAG TGGTCCTTGC
5590 X ATAAATGTAT AGAGCACACA GGTGGGGGGA AAGGGAGAGA GAGAAGAAGC CAGGGTATAA
5591 X AAATGGCCCA GCAGGGACCA ATTCCAGGAT CCCAGGACCC AGTTCACCAG ACGACTCAGG
5592 X GTCCTGTGGA CAGCTCACCA GCTATGATGG CTGCAGGTAA GCTCGCTAAA ATCCCCTCCA
5593 X TTCGCGTGTC CTAAAGGGGT AATGCGGGGG GCCCTGCCGA TGGATGTGTT CAGAGCTTTG
5594 X GGCTTTAGGG CTTCCGAATG TGAACATAGG TATCTACACC CAGACATTTG GCCAAGTTTG
5595 X AAATGTTCTC AGTCCCTGGA GGGAAGGGTA GGTGGGGGCT GGCAGGAGAT CAGGCGTCTA
5596 X GCTCCCTGGG GCCCTCCGTC GCGGCCCTCC TGGTCTCTCC CTAGGCCCCC GGACCTCCCT
5597 X GCTCCTGGCT TTCGCCCTGC TCTGCCTGCC CTGGACTCAG GTGGTGGGCG CCTTCCCAGC
5598 X CATGTCCTTG TCCGGCCTGT TTGCCAACGC TGTGCTCCGG GCTCAGCACC TGCATCAGCT
5599 X GGCTGCTGAC ACCTTCAAAG AGTTTGTAAG CTCCCGAGGG ATGCGTCCTA GGGGTGGGGA
5600 X GGCAGGAAGG GGTGAATCCA CACCCCCTCC ACACAGTGGG AGGAAACTGA GGAGTTCAGC
5601 X CGTATTTTAT CCAAGTAGGG ATGTGGTTAG GGGAGCAGAA ACGGGGGTGT GTGGGGTGGG
5602 X GAGGGTTCCG AATAAGGCGG GGAGGGGAAC CGCGCACCAG CTTAGACCTG GGTGGGTGTG
5603 X TTCTTCCCCC AGGAGCGCAC CTACATCCCG GAGGGACAGA GATACTCCAT CCAGAACACC
5604 X CAGGTTGCCT TCTGCTTCTC TGAAACCATC CCGGCCCCCA CGGGCAAGAA TGAGGCCCAG
5605 X CAGAAATCAG TGAGTGGCAA CCTCGGACCG AGGAGCAGGG GACCTCCTTC ATCCTAAGTA
5606 X GGCTGCCCCA GCTCTCCGCA CCGGGCCTGG GGCGGCCTTC TCCCCGAGGT GGCGGAGGTT
5607 X GTTGGATGGC AGTGGAGGAT GATGGTGGGC GGTGGTGGCA GGAGGTCCTC GGGCAGAGGC
5608 X CGACCTTGCA GGGCTGCCCC AAGCCCGCGG CACCCACCGA CCACCCATCT GCCAGCAGGA
5609 X CTTGGAGCTG CTTCGCATCT CACTGCTCCT CATCCAGTCG TGGCTTGGGC CCCTGCAGTT
5610 X CCTCAGCAGA GTCTTCACCA ACAGCTTGGT GTTTGGCACC TCGGACCGTG TCTATGAGAA
5611 X GCTGAAGGAC CTGGAGGAAG GCATCCTGGC CCTGATGCGG GTGGGGATGG CGTTGTGGGT
5612 X CCCTTCCATG CTGGGGGCCA TGCCCGCCCT CTCCTGGCTT AGCCAGGAGA ATGCACGTGG
5613 X GCTTGGGGAG ACAGATCCCT GCTCTCTCCC TCTTTCTAGC AGTCCAGCCT TGACCCAGGG
5614 X GAAACCTTTT CCCCTTTTGA AACCTCCTTC CTCGCCCTTC TCCAAGCCTG TAGGGGAGGG
5615 X TGGAAAATGG AGCGGGCAGG AGGGAGCTGC TCCTGAGGGC CCTTCGGCCT CTCTGTCTCT
5616 X CCCTCCCTTG GCAGGAGCTG GAAGATGGCA CCCCCCGGGC TGGGCAGATC CTCAAGCAGA
5617 X CCTATGACAA ATTTGACACA AACATGCGCA GTGACGACGC GCTGCTCAAG AACTACGGTC
5618 X TGCTCTCCTG CTTCCGGAAG GACCTGCATA AGACGGAGAC GTACCTGAGG GTCATGAAGT
5619 X GCCGCCGCTT CGGGGAGGCC AGCTGTGCCT TCTAGTTGCC AGCCATCTGT TGTTTGCCCC
5620 X TCCCCCGTGC CTTCCTTGAC CCTGGAAGGT GCCACTCCCA CTGTCCTTTC CTAATAAAAT
5621 X GAGGAAATTG CATCGCATTG TCTGAGTAGG TGTCATTCTA TTCTGGGGGG TGGGGTGGGG
5622 X CAGGACAGCA AGGGGGAGGA TTGGGAAGAC AATAGCAGGC ATGCTGGGGA TGCGGTGGGC
5623 X TCTATGGGTA CCCAGGTGCT GAAGAATTGA CCCGGTTCCT CCTGGG
5624 SHAR_EOF
5625 chmod 0644 bovgh.seq ||
5626 echo 'restore of bovgh.seq failed'
5627 Wc_c="`wc -c < 'bovgh.seq'`"
5628 test 2528 -eq "$Wc_c" ||
5629         echo 'bovgh.seq: original size 2528, current size' "$Wc_c"
5630 fi
5631 # ============= bovprl.seq ==============
5632 if test -f 'bovprl.seq' -a X"$1" != X"-c"; then
5633         echo 'x - skipping bovprl.seq (File already exists)'
5634 else
5635 echo 'x - extracting bovprl.seq (Text)'
5636 sed 's/^X//' << 'SHAR_EOF' > 'bovprl.seq' &&
5637 >BOVPRL GenBank entry BOVPRL from omam file.  907 nucleotides.
5638 TGCTTGGCTGAGGAGCCATAGGACGAGAGCTTCCTGGTGAAGTGTGTTTCTTGAAATCAT
5639 CACCACCATGGACAGCAAAGGTTCGTCGCAGAAAGGGTCCCGCCTGCTCCTGCTGCTGGT
5640 GGTGTCAAATCTACTCTTGTGCCAGGGTGTGGTCTCCACCCCCGTCTGTCCCAATGGGCC
5641 TGGCAACTGCCAGGTATCCCTTCGAGACCTGTTTGACCGGGCAGTCATGGTGTCCCACTA
5642 CATCCATGACCTCTCCTCGGAAATGTTCAACGAATTTGATAAACGGTATGCCCAGGGCAA
5643 AGGGTTCATTACCATGGCCCTCAACAGCTGCCATACCTCCTCCCTTCCTACCCCGGAAGA
5644 TAAAGAACAAGCCCAACAGACCCATCATGAAGTCCTTATGAGCTTGATTCTTGGGTTGCT
5645 GCGCTCCTGGAATGACCCTCTGTATCACCTAGTCACCGAGGTACGGGGTATGAAAGGAGC
5646 CCCAGATGCTATCCTATCGAGGGCCATAGAGATTGAGGAAGAAAACAAACGACTTCTGGA
5647 AGGCATGGAGATGATATTTGGCCAGGTTATTCCTGGAGCCAAAGAGACTGAGCCCTACCC
5648 TGTGTGGTCAGGACTCCCGTCCCTGCAAACTAAGGATGAAGATGCACGTTATTCTGCTTT
5649 TTATAACCTGCTCCACTGCCTGCGCAGGGATTCAAGCAAGATTGACACTTACCTTAAGCT
5650 CCTGAATTGCAGAATCATCTACAACAACAACTGCTAAGCCCACATTCCATCCTATCCATT
5651 TCTGAGATGGTTCTTAATGATCCATTCCCTGGCAAACTTCTCTGAGCTTTATAGCTTTGT
5652 AATGCATGCTTGGCTCTAATGGGTTTCATCTTAAATAAAAACAGACTCTGTAGCGATGTC
5653 AAAATCT
5654 SHAR_EOF
5655 chmod 0644 bovprl.seq ||
5656 echo 'restore of bovprl.seq failed'
5657 Wc_c="`wc -c < 'bovprl.seq'`"
5658 test 986 -eq "$Wc_c" ||
5659         echo 'bovprl.seq: original size 986, current size' "$Wc_c"
5660 fi
5661 # ============= c_dispn.c ==============
5662 if test -f 'c_dispn.c' -a X"$1" != X"-c"; then
5663         echo 'x - skipping c_dispn.c (File already exists)'
5664 else
5665 echo 'x - extracting c_dispn.c (Text)'
5666 sed 's/^X//' << 'SHAR_EOF' > 'c_dispn.c' &&
5667 /*      dispn.c associated subroutines for matching sequences */
5668 X
5669 /* $Name: fa_34_26_5 $ - $Id: c_dispn.c,v 1.21 2005/10/25 20:22:52 wrp Exp $ */
5670 X
5671 #include <stdio.h>
5672 #include <stdlib.h>
5673 #include <string.h>
5674 #include <ctype.h>
5675 X
5676 #include "defs.h"
5677 #include "structs.h"
5678 #include "param.h"
5679 X
5680 #define XTERNAL
5681 X
5682 #define YES 1
5683 #define NO 0
5684 X
5685 #define MAXOUT 201
5686 X
5687 /* the seqca[] array has the following codes:
5688 X   0 - no alignment symbol
5689 X   1 - align; pam < 0
5690 X   2 - align; pam == 0
5691 X   3 - align; pam > 0
5692 X   4 - align; ident
5693 X   5 - align; del
5694 X
5695 X   the map_sym arrays determine the value to be displayed with each
5696 X   type of aligned residue
5697 */
5698 X
5699 static char *map_sym_0 ="  ..: ";
5700 static char *map_sym_1 =" Xxx  ";
5701 static char *map_sym_2 ="    . ";
5702 #ifdef M10_CONS_L
5703 static char *map_sym_10=" mzp=-";
5704 #else
5705 static char *map_sym_10="  ..:-";
5706 #endif
5707 X
5708 void
5709 discons(FILE *fd, struct mngmsg m_msg, struct pstruct pst,
5710 X       char *seqc0, char *seqc0a, char *seqc1, char *seqca, int nc,
5711 X       int n0, int n1, char *name0, char *name1, int nml,
5712 X       struct a_struct *aln, long loffset)
5713 {
5714 X  char line[3][MAXOUT], cline[2][MAXOUT+10], *clinep[2];
5715 X  int il, i, lend, loff, id;
5716 X  int del0, del1, ic, ll0, ll1, ll01, cl0, cl1, rl0, rl1;
5717 X  int ic_save;
5718 X  char *map_sym_p;
5719 X  int l_llen;
5720 X  int ioff0, ioff00, ioff1, ioff10;
5721 X  long qqoff, lloff, qoffset;
5722 X  int llsgn, llfact, qlsgn, qlfact, qfx0, qfxn, lfx0, lfxn;
5723 X  int have_res;
5724 X  char *name01, *sq;
5725 X  char blank[MAX_UID], afmt[32];
5726 X
5727 X  memset(blank,' ',sizeof(blank)-1);
5728 X  blank[sizeof(blank)-1]='\0';
5729 X
5730 X  if (nml > 6) {
5731 X    blank[nml-6]='\0';
5732 X    sprintf(afmt,"%%-%ds %%s\n",nml);
5733 X  }
5734 X  else {
5735 X    blank[0]='\0';
5736 X    strncpy(afmt,"%-6s %s\n",sizeof(afmt));
5737 X  }
5738 X  if (pst.ext_sq_set) sq = pst.sqx; else sq = pst.sq;
5739 X
5740 X  clinep[0]=cline[0]+1;
5741 X  clinep[1]=cline[1]+1;
5742 X
5743 X  if (aln->qlfact == 0) {qlfact = 1;}
5744 X  else qlfact = aln->qlfact;
5745 X  if (aln->qlrev == 1) {
5746 X    qoffset = n0;
5747 X    qlsgn = -1;
5748 X    qfx0 = 0;
5749 X    qfxn = 1;
5750 X  }
5751 X  else {
5752 X    qoffset = 0;
5753 X    qlsgn = 1;
5754 X    qfx0 = 1;
5755 X    qfxn = 0;
5756 X  }
5757 X
5758 X  if (aln->llfact == 0) {llfact = 1;}
5759 X  else llfact = aln->llfact;
5760 X
5761 X  if (aln->llrev == 1) {
5762 X    loffset += n1;
5763 X    llsgn = -1;
5764 X    lfx0 = 0;
5765 X    lfxn = 1;
5766 X  }
5767 X  else {
5768 X    llsgn = 1;
5769 X    lfx0 = 1;
5770 X    lfxn = 0;
5771 X  }
5772 X
5773 X  l_llen = aln->llen;
5774 X  if ((m_msg.markx & MX_M9SUMM) && m_msg.show_code != 1) { l_llen += 40; }
5775 X
5776 X  if ((m_msg.markx & MX_ATYPE)==2) name01=name1;
5777 X  else name01 = "\0";
5778 X
5779 X  ioff0=aln->smin0;
5780 X  ioff00 = ioff0;
5781 X  ioff1=aln->smin1;
5782 X  ioff10 = ioff1;
5783 X  
5784 X  if (m_msg.markx& MX_AMAP && (m_msg.markx & MX_ATYPE)==7) return;
5785 X
5786 X  /* set *map_sym_p to correct match symbol */
5787 X  if ((m_msg.markx&MX_ATYPE)==1) {map_sym_p = map_sym_1;}
5788 X  else if ((m_msg.markx&MX_ATYPE)==2) {map_sym_p = map_sym_2;}
5789 X  else if (m_msg.markx&MX_M10FORM) {map_sym_p = map_sym_10;}
5790 X  else {map_sym_p = map_sym_0;}
5791 X
5792 X  if (m_msg.markx & MX_ASEP) {
5793 X    fprintf(fd,">%s ..\n",name0);
5794 X    for (i=0; i<nc && seqc0[i]; i++) {
5795 X   /* if (seqc0[i]=='-') fputc('.',fd); else */
5796 X      fputc(seqc0[i],fd);
5797 X      if (i%50 == 49) fputc('\n',fd);
5798 X    }
5799 X    if ((i-1)%50 != 49) fputc('\n',fd);
5800 X    fprintf(fd,">%s ..\n",name1);
5801 X    for (i=0; i<nc && seqc1[i]; i++) {
5802 X    /* if (seqc1[i]=='-') fputc('.',fd); else */
5803 X      fputc(seqc1[i],fd);
5804 X      if (i%50 == 49) fputc('\n',fd);
5805 X    }
5806 X    if ((i-1)%50 != 49) fputc('\n',fd);
5807 X    return;
5808 X  }
5809 X
5810 X  if (m_msg.markx & MX_M10FORM) {
5811 X    fprintf(fd,">%s ..\n",name0);
5812 X    fprintf(fd,"; sq_len: %d\n",n0);
5813 X    fprintf(fd,"; sq_offset: %ld\n",m_msg.sq0off);
5814 X    fprintf(fd,"; sq_type: %c\n",m_msg.sqtype[0]);
5815 X    fprintf(fd,"; al_start: %ld\n",aln->d_start0);
5816 X    fprintf(fd,"; al_stop: %ld\n",aln->d_stop0);
5817 X    fprintf(fd,"; al_display_start: %ld\n",
5818 X           qoffset+qlsgn*ioff0*aln->llmult+qfx0);
5819 X
5820 X    have_res = 0;
5821 X    for (i=0; i<nc && seqc0[i]; i++) {
5822 X      if (!have_res && seqc0[i]==' ') fputc('-',fd);
5823 X      else if (seqc0[i]==' ') break;
5824 X      else {
5825 X       have_res = 1;
5826 X       fputc(seqc0[i],fd);
5827 X      }
5828 X      if (i%50 == 49) fputc('\n',fd);
5829 X    }
5830 X    if ((i-1)%50!=49 || seqc0[i-1]==' ') fputc('\n',fd);
5831 X    fprintf(fd,">%s ..\n",name1);
5832 X    fprintf(fd,"; sq_len: %d\n",n1);
5833 X    fprintf(fd,"; sq_type: %c\n",m_msg.sqtype[0]);
5834 X    fprintf(fd,"; al_start: %ld\n",aln->d_start1);
5835 X    fprintf(fd,"; al_stop: %ld\n",aln->d_stop1);
5836 X    fprintf(fd,"; al_display_start: %ld\n",loffset+llsgn*ioff1+lfx0);
5837 X
5838 X    have_res = 0;
5839 X    for (i=0; i<nc && seqc1[i]; i++) {
5840 X      if (!have_res && seqc1[i]==' ') fputc('-',fd);
5841 X      else if (seqc1[i]==' ') break;
5842 X      else {
5843 X       have_res = 1;
5844 X       fputc(seqc1[i],fd);
5845 X      }
5846 X      if (i%50 == 49) fputc('\n',fd);
5847 X    }
5848 X    if ((i-1)%50!=49 || seqc1[i-1]==' ') fputc('\n',fd);
5849 #ifdef M10_CONS
5850 X    fprintf(fd,"; al_cons:\n");
5851 X    for (i=0,del0=0,id=ioff0; id-del0<aln->amax0 && i < nc; i++,id++) {
5852 X      if (seqc0[i] == '\0' || seqc1[i] == '\0') break;
5853 X      if (seqc0[i]=='-' || seqc0[i]==' ' || seqc0[i]=='\\') del0++;
5854 X      else if (seqc0[i]=='/') del0++;
5855 X      if (id-del0<aln->amin0) fputc(' ',fd);
5856 X      else if (seqc0[i]=='-'||seqc1[i]=='-') fputc('-',fd);
5857 X      else fputc(map_sym_10[seqca[i]],fd);
5858 X
5859 X      if (i%50 == 49) fputc('\n',fd);
5860 X    }
5861 X    if ((i-1)%50!=49 || seqc1[i-1]==' ') fputc('\n',fd);
5862 #endif
5863 X    return;
5864 X  }
5865 X
5866 X  memset(line[0],' ',MAXOUT);
5867 X  memset(line[1],' ',MAXOUT);
5868 X  memset(line[2],' ',MAXOUT);
5869 X
5870 X  /* cl0 indicates whether a coordinate should be printed over the first
5871 X     sequence; cl1 indicates a coordinate for the second;
5872 X  */
5873 X
5874 X  ic = 0; del0=del1=0;
5875 X  for (il=0; il<(nc+l_llen-1)/l_llen; il++) {
5876 X    loff=il*l_llen;
5877 X    lend=min(l_llen,nc-loff);
5878 X
5879 X    ll0 = NO; ll1 = NO;
5880 X
5881 X    memset(cline[0],' ',MAXOUT+1);
5882 X    memset(cline[1],' ',MAXOUT+1);
5883 X
5884 X    ic_save = ic;
5885 X    for (i=0; i<lend; i++, ic++,ioff0++,ioff1++) {
5886 X      cl0 =  cl1 = rl0 = rl1 = YES;
5887 X      if ((line[0][i]=seqc0[ic])=='-' || seqc0[ic]=='\\') {
5888 X       del0++; cl0=rl0=NO;
5889 X      }
5890 X      else if (seqc0[ic]=='/') {
5891 X       del0++; cl0=rl0=NO;
5892 X      }
5893 X      if ((line[2][i]=seqc1[ic])=='-' || seqc1[ic]=='\\') {
5894 X       del1++; cl1=rl1=NO;
5895 X      }
5896 X      else if (seqc1[ic]=='/') {
5897 X       del1++; cl1=rl1=NO;
5898 X      }
5899 X
5900 X      if (seqc0[ic]==' ') {del0++; cl0=rl0=NO;}
5901 X      else ll0 = YES;
5902 X      if (seqc1[ic]==' ') {del1++; cl1=rl1=NO;}
5903 X      else ll1 = YES;
5904 X
5905 X      qqoff = m_msg.sq0off - 1 + qoffset + (long)qlsgn*ioff00 +
5906 X       (long)qlsgn*qlfact*(ioff0-del0-ioff00);
5907 X      if (cl0 && qqoff%10 == 9)  {
5908 X       sprintf(&clinep[0][i-qfxn],"%8ld",qqoff+1l);
5909 X       clinep[0][i+8-qfxn]=' ';
5910 X       rl0 = NO;
5911 X      }
5912 X      else if (cl0 && qqoff== -1) {
5913 X       sprintf(&clinep[0][i-qfxn],"%8ld",0l);
5914 X       clinep[0][i+8-qfxn]=' ';
5915 X       rl0 = NO;
5916 X      }
5917 X      else if (rl0 && (qqoff+1)%10 == 0) {
5918 X       sprintf(&clinep[0][i-qfxn],"%8ld",qqoff+1);
5919 X       clinep[0][i+8-qfxn]=' ';
5920 X      }
5921 X      
5922 X      /* the lloff coordinate of a residue is the sum of:
5923 X        m_msg.sq1off-1  - the user defined coordinate
5924 X        loffset        - the offset into the library sequence
5925 X        llsgn*ioff10   - the offset into the beginning of the alignment
5926 X                         (given in the "natural" coordinate system,
5927 X                          except for tfasta3 which provides context)
5928 X        llsgn*llfact*(ioff1-del1-ioff10)
5929 X                       - the position in the consensus aligment, -gaps
5930 X      */
5931 X
5932 X      lloff = m_msg.sq1off-1 + loffset + aln->frame +
5933 X       (long)llsgn*aln->llmult*ioff10 +
5934 X       (long)llsgn*llfact*(ioff1-del1-ioff10);
5935 X
5936 X      if (cl1 && lloff%10 == 9)  {
5937 X       sprintf(&clinep[1][i-lfxn],"%8ld",lloff+1l);
5938 X       clinep[1][i+8-lfxn]=' ';
5939 X       rl1 = NO;
5940 X      }
5941 X      else if (cl1 && lloff== -1) {
5942 X       sprintf(&clinep[1][i],"%8ld",0l);
5943 X       clinep[1][i+8-lfxn]=' ';
5944 X       rl1 = NO;
5945 X      }
5946 X      else if (rl1 && (lloff+1)%10 == 0) {
5947 X       sprintf(&clinep[1][i-lfxn],"%8ld",lloff+1);
5948 X       clinep[1][i+8-lfxn]=' ';
5949 X      }
5950 X
5951 X      line[1][i] = ' ';
5952 X      if (ioff0-del0 >= aln->amin0 && ioff0-del0 <= aln->amax0) {
5953 X       if (seqca[ic]==4) {line[1][i]=map_sym_p[4];}
5954 X       else if ((m_msg.markx&MX_ATYPE)==2) line[1][i]=line[2][i];
5955 X       else line[1][i] = map_sym_p[seqca[ic]];
5956 X      }
5957 X      else if ((m_msg.markx&MX_ATYPE)==2) line[1][i]=line[2][i];
5958 X    }
5959 X
5960 X    if (m_msg.ann_flg) {
5961 X      for (ic=ic_save,i=0; i<lend; ic++,i++) {
5962 X       if (seqc0a[ic]!= ' ') clinep[0][i+7-qfxn] = seqc0a[ic];
5963 X      }
5964 X    }
5965 X
5966 X    line[0][lend]=line[1][lend]=line[2][lend]=0;
5967 X    clinep[0][lend+7]=clinep[1][lend+7]=0;
5968 X    
5969 X    ll01 = ll0&&ll1;
5970 X    if ((m_msg.markx&MX_ATYPE)==2 && (!aln->showall || ll0)) ll1=0;
5971 X    fprintf(fd,"\n");
5972 X    if (ll0) fprintf(fd,"%s%s\n",blank,clinep[0]);
5973 X    if (ll0) fprintf(fd,afmt,name0,line[0]);
5974 X    if (ll01) fprintf(fd,afmt,name01,line[1]);
5975 X    if (ll1) fprintf(fd,afmt,name1,line[2]);
5976 X    if (ll1) fprintf(fd,"%s%s\n",blank,clinep[1]);
5977 X  }
5978 }
5979 X
5980 static float gscale= -1.0;
5981 X
5982 void
5983 disgraph(FILE *fd, int n0,int n1, float percent, int score,
5984 X        int min0, int min1, int max0, int max1, long sq0off,
5985 X        char *name0, char *name1, int nml,
5986 X        int mlen, int markx)
5987 {
5988 X  int i, gstart, gstop, gend;
5989 X  int llen;
5990 X  char line[MAXOUT+1];
5991 X  char afmt[16], afmtf[64];
5992 X
5993 X  if (nml > 6) {
5994 X    sprintf(afmt,"%%-%ds",nml);
5995 X  }
5996 X  else {
5997 X    strncpy(afmt,"%-6s",sizeof(afmt));
5998 X  }
5999 X  strncpy(afmtf,afmt,sizeof(afmtf));
6000 X  strncat(afmtf," %4ld-%4ld:     %5.1f%%:%s:\n",sizeof(afmtf));
6001 X
6002 X  llen = mlen - 10;
6003 X  memset(line,' ',llen);
6004 X
6005 X  line[llen-1]='\0';
6006 X  if (gscale < 0.0) {
6007 X    gscale = (float)llen/(float)n0;
6008 X    if ((markx&MX_ATYPE) == 7 ) 
6009 X      fprintf(fd,afmtf,name0,sq0off,sq0off+n0-1,100.0,line);
6010 X  }
6011 X
6012 X  gstart = (int)(gscale*(float)min0+0.5);
6013 X  gstop = (int)(gscale*(float)max0+0.5);
6014 X  gend = gstop+(int)(gscale*(float)(n1-max1));
6015 X
6016 X  if (gstop >= llen) gstop = llen-1;
6017 X  if (gend >= llen) gend = llen-1;
6018 X  for (i=0; i<gstart; i++) line[i]=' ';
6019 X  for (; i<gstop; i++) line[i]='-';
6020 X  for (; i<llen; i++) line[i]=' ';
6021 X
6022 X  line[gend]=':';
6023 X  line[llen]='\0';
6024 X
6025 X  if (markx & MX_AMAP) {
6026 X    if ((markx & MX_ATYPE)==7) {       /* markx==4 - no alignment */
6027 X      strncpy(afmtf,afmt,sizeof(afmtf));
6028 X      strncat(afmtf," %4ld-%4ld:%4d %5.1f%%:%s\n",sizeof(afmtf));
6029 X      fprintf(fd,afmtf,name1,min0+sq0off,max0+sq0off-1,score,percent,line);
6030 X    }
6031 X    else {
6032 X      afmtf[0]='>';
6033 X      strncpy(&afmtf[1],afmt,sizeof(afmtf)-1);
6034 X      strncat(afmtf," %4ld-%4ld:%s\n",sizeof(afmtf));
6035 X      fprintf(fd,afmtf, name1,min0+sq0off,max0+sq0off-1,line);
6036 X    }
6037 X  }
6038 }
6039 X
6040 void
6041 aancpy(char *to, char *from, int count, struct pstruct pst)
6042 {
6043 X  char *tp, *sq;
6044 X  int nsq;
6045 X
6046 X  if (pst.ext_sq_set) {
6047 X    nsq = pst.nsqx;
6048 X    sq = pst.sqx;
6049 X  }
6050 X  else {
6051 X    nsq = pst.nsq;
6052 X    sq = pst.sq;
6053 X  }
6054 X
6055 X  tp=to;
6056 X  while (count-- && *from) {
6057 X    if (*from <= nsq) *tp++ = sq[*(from++)];
6058 X    else *tp++ = *from++;
6059 X  }
6060 X  *tp='\0';
6061 }
6062 X
6063 void
6064 r_memcpy(dest,src,cnt)
6065 X     char *dest, *src;
6066 X     int cnt;
6067 {
6068 X  while (cnt--) *dest++ = *src++;
6069 }
6070 X
6071 void
6072 l_memcpy(dest,src,cnt)
6073 X     char *dest, *src;
6074 X     int cnt;
6075 {
6076 X  dest = dest+cnt;
6077 X  src = src+cnt;
6078 X  while (cnt--) *--dest = *--src;
6079 }
6080 X
6081 /* this routine now indexs from 1 (rather than 0) because sq starts
6082 X   with a 0 */
6083 X
6084 #define MAXSQ 50        /* must be same as upam.h */
6085 X
6086 void cal_coord(int n0, int n1, long sq0off, long loffset,
6087 X              struct a_struct *aln)
6088 {
6089 X  long qoffset;
6090 X  int llsgn, qlsgn, qfx0, qfxn, lfx0, lfxn;
6091 X
6092 X  if (aln->qlrev == 1) {
6093 X    qoffset = sq0off -1 + n0;
6094 X    qlsgn = -1;
6095 X    qfx0 = 0;
6096 X    qfxn = 1;
6097 X  }
6098 X  else {
6099 X    qoffset = sq0off - 1;
6100 X    qlsgn = 1;
6101 X    qfx0 = 1;
6102 X    qfxn = 0;
6103 X  }
6104 X
6105 X  if (aln->llrev == 1) {
6106 X    loffset += n1;
6107 X    llsgn = -1;
6108 X    lfx0 = 0;
6109 X    lfxn = 1;
6110 X  }
6111 X  else {
6112 X    llsgn = 1;
6113 X    lfx0 = 1;
6114 X    lfxn = 0;
6115 X  }
6116 X  aln->d_start0 = qoffset+qlsgn*aln->amin0+qfx0;
6117 X  aln->d_stop0 = qoffset+qlsgn*aln->amax0+qfxn;
6118 X  aln->d_start1 = loffset+llsgn*aln->amin1*aln->llmult+lfx0+aln->frame;
6119 X  aln->d_stop1 = loffset+llsgn*aln->amax1*aln->llmult+lfxn+aln->frame;
6120 }
6121 SHAR_EOF
6122 chmod 0644 c_dispn.c ||
6123 echo 'restore of c_dispn.c failed'
6124 Wc_c="`wc -c < 'c_dispn.c'`"
6125 test 11467 -eq "$Wc_c" ||
6126         echo 'c_dispn.c: original size 11467, current size' "$Wc_c"
6127 fi
6128 # ============= checkevent.c ==============
6129 if test -f 'checkevent.c' -a X"$1" != X"-c"; then
6130         echo 'x - skipping checkevent.c (File already exists)'
6131 else
6132 echo 'x - extracting checkevent.c (Text)'
6133 sed 's/^X//' << 'SHAR_EOF' > 'checkevent.c' &&
6134 X
6135 /* Copyright 1995 William R. Pearson */
6136 X
6137 /* used only in Mac versions to provide mac multitasking */
6138 X
6139 #include <stdlib.h>
6140 X
6141 #ifdef __MWERKS__
6142 #include <sioux.h>
6143 #endif
6144 X
6145 #define SLEEP                   2L
6146 #define NIL_MOUSE_REGION        0L
6147 X
6148 #define WNE_TRAP_NUM    0x60
6149 #define UNIMPL_TRAP_NUM 0x9F
6150 #define SUSPEND_RESUME_BIT      0x0001
6151 #define ACTIVATING              1
6152 #define RESUMING                1
6153 X
6154 Boolean         gDone, gWNEImplemented=0;
6155 EventRecord     gTheEvent;
6156 Rect            gDragRect, gSizeRect;
6157 X
6158 void
6159 InitEvent()
6160 {
6161 X       gWNEImplemented=(NGetTrapAddress(WNE_TRAP_NUM,ToolTrap)!=
6162 X               NGetTrapAddress(UNIMPL_TRAP_NUM,ToolTrap));
6163 X       }
6164 X
6165 X
6166 #define hiword(x)               (((short *) &(x))[0])
6167 #define loword(x)               (((short *) &(x))[1])
6168 static MenuHandle aMenu;
6169 X
6170 /*
6171 ChkEvent()
6172 {}
6173 */
6174 X
6175 #ifdef TPLOT
6176 extern WindowPtr gDrawWindow;
6177 extern PicHandle aPic;
6178 #endif
6179 X
6180 static long checkTime=0;
6181 X
6182 void
6183 ChkEvent()
6184 {
6185 X       EventRecord event;
6186 X       WindowPeek wp;
6187 X       Boolean gotEvent, SIOUXDidEvent;
6188 X       long choice;
6189 X       Str255 buf;
6190 X       
6191 X       if (TickCount() < checkTime) return;
6192 X       checkTime = TickCount()+60L;
6193 X
6194 X       if (gWNEImplemented)
6195 X               gotEvent=WaitNextEvent(everyEvent-diskMask,&event,SLEEP,NIL_MOUSE_REGION);
6196 X       else {
6197 X               SystemTask();
6198 X               gotEvent=GetNextEvent(everyEvent-diskMask,&event);
6199 X               }
6200 X
6201 X       if (gotEvent) SIOUXDidEvent=SIOUXHandleOneEvent(&event);
6202 X       if (SIOUXDidEvent) return;
6203 X
6204 X       if (event.what == nullEvent) {
6205 X               if (FrontWindow() == 0) InitCursor();
6206 X               return;
6207 X               }
6208 X       
6209 X       if (SystemEvent(&event)) return;
6210 X
6211 X       if (event.what == mouseDown) {
6212 X               switch (FindWindow(event.where, (WindowPtr *)&wp)) {
6213 X                       case inMenuBar:
6214 X                               InitCursor();
6215 X                               choice = MenuSelect(event.where);
6216 X                               goto doMenu;
6217 X                       case inDrag :
6218 X                               DragWindow((WindowPtr)wp, event.where, &gDragRect);
6219 X                               break;
6220 X                       case inSysWindow:
6221 X                               SystemClick(&event, (WindowPtr)wp);
6222 X                               break;
6223 X                       }
6224 X               }
6225 X       
6226 X       return;
6227 X
6228 doMenu: 
6229 X       switch (hiword(choice)) {
6230 X               case 1:
6231 X                       GetMenuItemText(aMenu, loword(choice), buf);
6232 X                       OpenDeskAcc(buf);
6233 X                       break;
6234 X               case 2:
6235 X                       exit(0);
6236 X               
6237 X               case 3: 
6238 X                       SystemEdit(loword(choice) - 1);
6239 X                       break;
6240 X       }
6241 X       HiliteMenu(0);
6242 }
6243 X
6244 #ifdef TPLOT
6245 X
6246 Waitkey(keyval)
6247 X       int keyval;
6248 {
6249 X       int key;
6250 X       EventRecord event;
6251 X       WindowPeek wp;
6252 X       long choice;
6253 X       Str255 buf;
6254 X       
6255 X       SystemTask();
6256 X       if (gWNEImplemented)
6257 X               WaitNextEvent(everyEvent-diskMask,&event,SLEEP,NIL_MOUSE_REGION);
6258 X       else {
6259 X               SystemTask();
6260 X               GetNextEvent(everyEvent-diskMask,&event);
6261 X               }
6262 X
6263 X                       
6264 X       InitCursor();
6265 X       if (event.what == nullEvent) {
6266 X               return 0;
6267 X               }
6268 X       
6269 X       if (SystemEvent(&event)) return 0;
6270 X
6271 X       if (event.what == updateEvt) {
6272 X               if ((WindowPtr)event.message == gDrawWindow) {
6273 X                       BeginUpdate((WindowPtr)event.message);
6274 X                       DrawPicture(aPic,&gDrawWindow->portRect);
6275 X                       EndUpdate((WindowPtr)event.message);
6276 X                       }
6277 X               else {
6278 X                       BeginUpdate((WindowPtr)event.message);
6279 X                       EndUpdate((WindowPtr)event.message);
6280 X                       }
6281 X               return 0;
6282 X               }
6283 X
6284 X       if (event.what == keyDown) return 1;
6285 X       if (event.what == mouseDown) {
6286 X               switch (FindWindow(event.where, (WindowPtr *)&wp)) {
6287 X                       case inMenuBar:
6288 X                               InitCursor();
6289 X                               choice = MenuSelect(event.where);
6290 X                               goto doMenu;
6291 X                       case inDrag :
6292 X                               DragWindow((WindowPtr)wp, event.where, &gDragRect);
6293 X                               break;
6294 X                       case inSysWindow:
6295 X                               SystemClick(&event, (WindowPtr)wp);
6296 X                               break;
6297 X                       case inGoAway :
6298 X                               return 1;
6299 X                       case inContent:
6300 X                               SelectWindow((WindowPtr)wp);
6301 X                               SetPort(gDrawWindow);
6302 X                               DrawPicture(aPic,&gDrawWindow->portRect);
6303 X                               break;
6304 X                       }
6305 X               }
6306 X       
6307 X       return 0;
6308 X
6309 doMenu: 
6310 X       switch (hiword(choice)) {
6311 X               case 1:
6312 X                       GetItem(aMenu, loword(choice), buf);
6313 X                       OpenDeskAcc(buf);
6314 X                       break;
6315 X               case 2:
6316 X                       return 1;
6317 X               
6318 X               case 3: 
6319 X                       SystemEdit(loword(choice) - 1);
6320 X                       break;
6321 X       }
6322 X       HiliteMenu(0);
6323 X       return 0;
6324 }
6325 #endif
6326 X
6327 X                       
6328 SHAR_EOF
6329 chmod 0644 checkevent.c ||
6330 echo 'restore of checkevent.c failed'
6331 Wc_c="`wc -c < 'checkevent.c'`"
6332 test 3492 -eq "$Wc_c" ||
6333         echo 'checkevent.c: original size 3492, current size' "$Wc_c"
6334 fi
6335 # ============= comp_lib.c ==============
6336 if test -f 'comp_lib.c' -a X"$1" != X"-c"; then
6337         echo 'x - skipping comp_lib.c (File already exists)'
6338 else
6339 echo 'x - extracting comp_lib.c (Text)'
6340 sed 's/^X//' << 'SHAR_EOF' > 'comp_lib.c' &&
6341 /* copyright (c) 1996, 1997, 1998, 1999, 2002  William R. Pearson and the
6342 X   U. of Virginia */
6343 X
6344 /* $Name: fa_34_26_5 $ - $Id: comp_lib.c,v 1.100 2007/04/26 18:36:36 wrp Exp $ */
6345 X
6346 /*
6347 X * Concurrent read version
6348 X *
6349 X *     Feb 20, 1998 modifications for prss3
6350 X *
6351 X *     December, 1998 - DNA searches are now down with forward and reverse
6352 X *                      strands
6353 X */
6354 X
6355 #include <stdio.h>
6356 #include <stdlib.h>
6357 #include <string.h>
6358 #include <ctype.h>
6359 #include <time.h>
6360 X
6361 #include <limits.h>
6362 #include <float.h>
6363 #include <math.h>
6364 X
6365 #ifdef UNIX
6366 #include <unistd.h>
6367 #include <sys/types.h>
6368 #include <signal.h>
6369 #endif
6370 X
6371 #include "defs.h"
6372 #include "mm_file.h"
6373 X
6374 #include "mw.h"                 /* defines beststr */
6375 #include "structs.h"            /* mngmsg, libstruct */
6376 #include "param.h"              /* pstruct, thr_str, buf_head, rstruct */
6377 X
6378 #define XTERNAL
6379 #include "uascii.h"
6380 X
6381 char *mp_verstr="34.26";
6382 X
6383 /********************************/
6384 /* global variable declarations */
6385 /********************************/
6386 char gstring2[MAX_STR];                  /* string for label */
6387 char gstring3[MAX_STR];
6388 char hstring1[MAX_STR];
6389 X
6390 extern int max_workers;
6391 X
6392 #ifdef SUPERFAMNUM
6393 int nsfnum;
6394 int sfnum[10];
6395 extern int sfn_cmp(int *q, int *s);
6396 int nsfnum_n;
6397 int sfnum_n[10];
6398 #endif
6399 X
6400 /********************************/
6401 /* extern variable declarations */
6402 /********************************/
6403 extern char *prog_func;         /* function label */
6404 extern char *verstr, *iprompt0, *iprompt1, *iprompt2, *refstr;
6405 X
6406 /********************************/
6407 /*extern function declarations  */
6408 /********************************/
6409 /* open sequence file (getseq.c) */
6410 extern int getseq(char *filen, int *sascii,
6411 X                 unsigned char *seq, int maxs,
6412 X                 char *libstr, int n_libstr,
6413 X                 long *sq0ff);
6414 X
6415 struct lmf_str *openlib(char *, int, int *, int, struct lmf_str *);
6416 X
6417 void set_shuffle(struct mngmsg m_msg);
6418 void closelib(struct lmf_str *m_fptr);
6419 X
6420 void irand(int);
6421 int nrand(int);
6422 X
6423 extern int ann_scan(unsigned char *, int, struct mngmsg *, int );
6424 extern int scanseq(unsigned char *seq, int n, char *str);
6425 extern void re_ascii(int *qascii, int *sascii);
6426 extern int recode(unsigned char *seq, int n, int *qascii, int nsq);
6427 extern void revcomp(unsigned char *seq, int n, int *c_nt);
6428 X
6429 extern void init_ascii(int is_ext, int *sascii, int is_dna);
6430 extern void qshuffle(unsigned char *aa0, int n0, int nm0);
6431 extern void free_pam2p(int **);
6432 X
6433 /* initialize environment (doinit.c) */
6434 extern void initenv (int argc, char **argv, struct mngmsg *m_msg,
6435 X                    struct pstruct *ppst, unsigned char **aa0);
6436 X
6437 /* print timing information */
6438 extern void ptime (FILE *, time_t);
6439 X
6440 #ifdef COMP_MLIB 
6441 #define QGETLIB (q_file_p->getlib)
6442 #endif
6443 X
6444 #define GETLIB (m_file_p->getlib)
6445 X
6446 /* calculation functions */
6447 extern void
6448 init_work(unsigned char *aa0, int n0,
6449 X         struct pstruct *ppst, void **f_arg );
6450 #ifndef COMP_THR
6451 extern void
6452 do_work(unsigned char *aa0, int n0, unsigned char *aa1, int n1, int frame, 
6453 X       struct pstruct *ppst, void *f_str, int qr_flg, struct rstruct *rst);
6454 #endif
6455 X
6456 extern void
6457 close_work(unsigned char *aa0, int n0, struct pstruct *ppst, void **f_arg);
6458 extern void
6459 get_param (struct pstruct *pstr, char *pstring1, char *pstring2);
6460 X
6461 #ifdef COMP_THR
6462 #ifndef PRSS
6463 void
6464 save_best(struct buf_head *cur_buf, struct mngmsg, struct pstruct pst, 
6465 X         FILE *fdata, int *, struct hist_str *, void **);
6466 #else
6467 void
6468 save_best(struct buf_head *cur_buf, struct mngmsg, struct pstruct pst, 
6469 X         FILE *fdata, int *, struct hist_str *, void **, int *, int *);
6470 #endif
6471 #endif
6472 X
6473 /* statistics functions */
6474 extern int
6475 process_hist(struct stat_str *sptr, int nstat, 
6476 X            struct mngmsg m_msg,
6477 X            struct pstruct pst,
6478 X            struct hist_str *hist, void **, int);
6479 extern void addhistz(double, struct hist_str *); /* scaleswn.c */
6480 void selectbestz(struct beststr **, int, int );
6481 extern double (*find_zp)(int score, double escore, int length, double comp,void *);
6482 X
6483 void last_stats(const unsigned char *, int, 
6484 X               struct stat_str *sptr, int nstats,
6485 X               struct beststr **bestp_arr, int nbest,
6486 X               struct mngmsg m_msg, struct pstruct pst, 
6487 X               struct hist_str *histp, void *);
6488 X
6489 int last_calc( unsigned char **a0, unsigned char *a1, int maxn,
6490 X              struct beststr **bestp_arr, int nbest,
6491 X              struct mngmsg m_msg, struct pstruct *ppst, 
6492 X              void **f_str, void *rs_str);
6493 X
6494 void scale_scores(struct beststr **bestp_arr, int nbest,
6495 X                 struct db_str,struct pstruct pst, void *);
6496 X
6497 #ifndef COMP_THR
6498 extern int shuffle(unsigned char *, unsigned char *, int);
6499 extern int wshuffle(unsigned char *, unsigned char *, int, int, int *);
6500 #endif
6501 X
6502 extern void set_db_size(int, struct db_str *, struct hist_str *);
6503 X
6504 /* display functions */
6505 extern void
6506 showbest (FILE *fp, unsigned char **aa0, unsigned char *aa1,
6507 X         int maxn, struct beststr **bestp_arr, int nbest,
6508 X         int qlib, struct mngmsg *m_msg,struct pstruct pst,
6509 X         struct db_str db, char *gstring2, void **f_str);
6510 X
6511 extern void
6512 showalign (FILE *fp, unsigned char **aa0, unsigned char *aa1,
6513 X          int maxn, struct beststr **bestp_arr, int nbest,
6514 X          int qlib, struct mngmsg m_msg,struct pstruct pst,
6515 X          char *gstring2, void **f_str);
6516 X
6517 /* misc functions */
6518 void h_init(struct pstruct *, struct mngmsg *, char *);         /* doinit.c */
6519 void last_init(struct mngmsg *, struct pstruct *); /* initfa/sw.c */
6520 void last_params(unsigned char *, int, struct mngmsg *, struct pstruct *);
6521 X
6522 void s_abort(char *, char *);           /* compacc.c */
6523 X
6524 /* initfa/sw.c */
6525 void resetp(struct mngmsg *, struct pstruct *); 
6526 X
6527 void gettitle(char *, char *, int);     /* nxgetaa.c */
6528 void libchoice(char *lname, int, struct mngmsg *); /* lib_sel.c */
6529 void libselect(char *lname, struct mngmsg *);   /* lib_sel.c */
6530 void query_parm(struct mngmsg *, struct pstruct *); /* initfa/sw.c */
6531 void selectbestz(struct beststr **, int, int);
6532 X
6533 /* compacc.c */
6534 void prhist(FILE *, struct mngmsg, struct pstruct, 
6535 X           struct hist_str hist, int nstats, struct db_str, char *);
6536 void printsum(FILE *, struct db_str db);
6537 int reset_maxn(struct mngmsg *, int);   /* set m_msg.maxt, maxn from maxl */
6538 X
6539 FILE *outfd;                    /* Output file */
6540 X
6541 /* this information is global for fsigint() */
6542 extern time_t s_time();                 /* fetches time */
6543 time_t tstart, tscan, tprev, tdone;     /* Timing */
6544 #ifdef COMP_MLIB
6545 time_t ttscan, ttdisp;
6546 #endif
6547 time_t tdstart, tddone;
6548 X
6549 static struct db_str qtt = {0l, 0l, 0};
6550 X
6551 #ifdef COMP_THR
6552 /***************************************/
6553 /* thread global variable declarations */
6554 /***************************************/
6555 X
6556 /* functions for getting/sending buffers to threads (thr_sub.c) */
6557 extern void init_thr(int , struct thr_str *, struct mngmsg, struct pstruct *,
6558 X                    unsigned char *, int);
6559 extern void start_thr(void);
6560 extern void get_rbuf(struct buf_head **cur_buf, int max_wor_buf);
6561 extern void put_rbuf(struct buf_head *cur_buf, int max_work_buf);
6562 extern void put_rbuf_done(int nthreads, struct buf_head *cur_buf, 
6563 X                         int max_work_buf);
6564 #undef XTERNAL
6565 #include "thr.h"
6566 struct buf_head buf_list[NUM_WORK_BUF];
6567 #endif
6568 X
6569 /* these variables must be global for comp_thr.c so that savebest()
6570 X   can use them */
6571 X
6572 static struct beststr 
6573 X    *best,             /* array of best scores */
6574 X    *bestp,
6575 X    **bestp_arr;       /* array of pointers */
6576 static int nbest;       /* number of best scores */
6577 X
6578 static struct stat_str *stats, *qstats; /* array of scores for statistics */
6579 X
6580 /* these variables are global so they can be set both by the main()
6581 X   program and savebest() in threaded mode.
6582 */
6583 static int nstats, nqstats, kstats;
6584 static double zbestcut;         /* cut off for best z-score */
6585 static int bestfull;            /* index for selectbest() */
6586 static int stats_done=0;        /* flag for z-value processing */
6587 void fsigint();
6588 X
6589 int
6590 main (int argc, char *argv[]) 
6591 {
6592 X  unsigned char *aa0[6], *aa0s, *aa1, *aa1ptr, *aa1s;
6593 X  int n1, n1s;  /* n1s needed for PRSS so that when getlib() returns -1 (because no more
6594 X                  library sequences, we have a valid n1 for shuffling */
6595 X
6596 X  int *n1tot_ptr=NULL, *n1tot_cur;
6597 X  int n1tot_cnt=0;
6598 X  int n1tot_v, aa1_loff;
6599 X
6600 X  long qoffset;                /* qoffset is the equivalent of loffset */
6601 X                       /* m_msg.sq0off is the l_off equivalent */
6602 X
6603 X  long loffset, l_off; /* loffset is the coordinate of first residue
6604 X                          when lcont > 0; l_off is not used in the
6605 X                          main loop, only in showbest and showalign */
6606 X  char lib_label[MAX_FN];
6607 X  char pgm_abbr[MAX_SSTR];
6608 X  char qlabel[MAX_FN];
6609 #ifdef COMP_MLIB
6610 X  char q_bline[MAX_STR];
6611 X  fseek_t qseek;
6612 X  int qlib;
6613 X  struct lmf_str *q_file_p;
6614 X  int sstart, sstop, is;
6615 #endif
6616 X  int id;
6617 X  struct lmf_str *m_file_p;
6618 X
6619 X  int t_best, t_rbest, t_qrbest;       /* best score of two/six frames */
6620 X  double t_escore, t_rescore, t_qrescore; /* best evalues of two/six frames */
6621 X  int i_score;
6622 #ifdef PRSS
6623 X  int s_score[3];
6624 X  int s_n1;
6625 #endif
6626 X
6627 X  struct pstruct pst;
6628 X  void *f_str[6], *qf_str;     /* different f_str[]'s for different
6629 X                                  translation frames, or forward,reverse */
6630 X  int have_f_str=0;
6631 X
6632 #ifdef COMP_THR
6633 X  long ntbuff;
6634 X  int max_buf_cnt, ave_seq_len, buf_siz;
6635 X  int max_work_buf;
6636 X  struct buf_head *cur_buf;
6637 X  struct buf_str *cur_buf_p;
6638 X  int nseq;
6639 X  struct thr_str *work_info;
6640 #endif
6641 X
6642 X  struct mngmsg m_msg;         /* Message from host to manager */
6643 X  int iln, itt;                        /* index into library names */
6644 X  char rline[MAX_FN];
6645 X  char argv_line[MAX_STR];
6646 X  int t_quiet;
6647 X
6648 X  struct rstruct  rst;         /* results structure */
6649 X  struct rstruct  rrst;                /* results structure for shuffle*/
6650 X  int i;
6651 X
6652 X  FILE *fdata=NULL;            /* file for full results */
6653 X  char libstr[MAX_UID];                /* string for labeling full results */
6654 X  char *libstr_p;              /* choose between libstr and ltitle */
6655 X  int n_libstr;                        /* length of libstr */
6656 X  int jstats;
6657 X  int leng;                    /* leng is length of the descriptive line */
6658 X  int maxn;                    /* size of the library sequence examined */
6659 X  int maxl;                    /* size of library buffer */
6660 X  fseek_t lmark;               /* seek into library of current sequence */
6661 X  int qlcont;                  /* continued query sequence */
6662 X  int lcont, ocont, maxt;      /* continued sequence */
6663 X  int igncnt=0;                        /* count for ignoring sequences warning */
6664 X  int ieven=0;                 /* tmp for wshuffle */
6665 X  double zscore;                       /* tmp value */
6666 X  char *bp;                    /* general purpose string ptr */
6667 X  
6668 X  /* Initialization */
6669 X
6670 #if defined(UNIX)
6671 X  m_msg.quiet= !isatty(1);
6672 #else
6673 X  m_msg.quiet = 0;
6674 #endif
6675 X
6676 #ifdef PGM_DOC
6677 X  argv_line[0]='#'; argv_line[1]='\0';
6678 X  for (i=0; i<argc; i++) {
6679 X    strncat(argv_line," ",sizeof(argv_line)-strlen(argv_line)-1);
6680 X    if (strchr(argv[i],' ')) {
6681 X      strncat(argv_line,"\"",sizeof(argv_line)-strlen(argv_line)-1);
6682 X      strncat(argv_line,argv[i],sizeof(argv_line)-strlen(argv_line)-1);
6683 X      strncat(argv_line,"\"",sizeof(argv_line)-strlen(argv_line)-1);
6684 X    }
6685 X    else {
6686 X      strncat(argv_line,argv[i],sizeof(argv_line)-strlen(argv_line)-1);
6687 X    }
6688 X  }
6689 X  argv_line[sizeof(argv_line)-1]='\0';
6690 #endif
6691 X
6692 X  /* first initialization routine - nothing is known */
6693 X  h_init(&pst, &m_msg, pgm_abbr);
6694 X  
6695 X  m_msg.db.length = qtt.length = 0l;
6696 X  m_msg.db.entries = m_msg.db.carry = qtt.entries = qtt.carry = 0;
6697 X  m_msg.pstat_void = NULL;
6698 X  m_msg.hist.entries = 0;
6699 X
6700 X  for (iln=0; iln<MAX_LF; iln++) m_msg.lb_mfd[iln]=NULL;
6701 X
6702 X  f_str[0] = f_str[1] = NULL;
6703 X
6704 X  aa0[0] = NULL;
6705 X  /* second initialiation - get commmand line arguments */
6706 X  initenv (argc, argv, &m_msg, &pst,&aa0[0]);
6707 X
6708 #ifdef COMP_THR
6709 X  /* now have max_workers - allocate work_info[] */
6710 X  if (max_workers >= MAX_WORKERS) max_workers = MAX_WORKERS;
6711 X  if ((work_info=
6712 X       (struct thr_str *)calloc(max_workers,sizeof(struct thr_str)))==NULL) {
6713 X    fprintf(stderr, " cannot allocate work_info[%d]\n",max_workers);
6714 X    exit(1);
6715 X  }
6716 #else
6717 X  max_workers = 1;
6718 #endif
6719 X
6720 #ifndef PRSS
6721 X  /* label library size limits */
6722 X  if (m_msg.n1_low > 0 && m_msg.n1_high < BIGNUM) 
6723 X    sprintf(lib_label,"library (range: %d-%d)",m_msg.n1_low,m_msg.n1_high);
6724 X  else if (m_msg.n1_low > 0) 
6725 X    sprintf(lib_label,"library (range: >%d)",m_msg.n1_low);
6726 X  else if (m_msg.n1_high < BIGNUM)
6727 X    sprintf(lib_label,"library (range: <%d)",m_msg.n1_high);
6728 X  else
6729 X    strncpy(lib_label,"library",sizeof(lib_label));
6730 #else
6731 X  sprintf(lib_label,"shuffled sequence");
6732 #endif
6733 X  lib_label[sizeof(lib_label)-1]='\0';
6734 X
6735 X  tstart = tscan = s_time();
6736 X  tdstart = time(NULL);
6737 X
6738 X  /* Allocate space for the query and library sequences */
6739 X  /* pad aa0[] with an extra 32 chars for ALTIVEC padding */
6740 X  if (aa0[0]==NULL) {
6741 X    if ((aa0[0] = (unsigned char *)malloc((m_msg.max_tot+1+32)*sizeof(unsigned char)))
6742 X       == NULL)
6743 X      s_abort ("Unable to allocate query sequence", "");
6744 X    *aa0[0]=0;
6745 X    aa0[0]++;
6746 X  }
6747 X  aa0[5]=aa0[4]=aa0[3]=aa0[2]=aa0[1]=aa0[0];
6748 X
6749 X  /* make room for random sequence -
6750 X     also used as storage for COMP_THR library overlaps 
6751 X  */
6752 X  if ((aa1s = (unsigned char *)malloc((m_msg.max_tot+1+32)*sizeof (char))) == NULL) {
6753 X    s_abort ("Unable to allocate shuffled library sequence", "");
6754 X  }
6755 X  *aa1s=0;
6756 X  aa1s++;
6757 X
6758 X  irand(0);
6759 X
6760 X  if (m_msg.markx & MX_HTML) {
6761 #ifdef HTML_HEAD    
6762 X    fprintf(stdout,"<html>\n<head>\n<title>%s Results</title>\n</head>\n<body>\n",prog_func);
6763 #endif
6764 X    fprintf(stdout,"<pre>\n");
6765 X  }
6766 X
6767 #ifdef PGM_DOC
6768 X    fputs(argv_line,stdout);
6769 X    fputc('\n',stdout);
6770 #endif  
6771 X
6772 X  fprintf(stdout,"%s\n",iprompt0);
6773 X  fprintf(stdout," %s%s\n",verstr,refstr);
6774 X  if (m_msg.markx & MX_HTML) fputs("</pre>\n",stdout);
6775 X
6776 X  /* Query library */
6777 X  if (m_msg.tname[0] == '\0') {
6778 X      if (m_msg.quiet == 1)
6779 X       s_abort("Query sequence undefined","");
6780 X    l1:        fputs (iprompt1, stdout);
6781 X      fflush  (stdout);
6782 X      if (fgets (m_msg.tname, MAX_FN, stdin) == NULL)
6783 X       s_abort ("Unable to read query library name","");
6784 X      m_msg.tname[MAX_FN-1]='\0';
6785 X      if ((bp=strchr(m_msg.tname,'\n'))!=NULL) *bp='\0';
6786 X      if (m_msg.tname[0] == '\0') goto l1;
6787 X  }
6788 X  
6789 X  /* Fetch first sequence */
6790 X  qoffset = 0l;
6791 X  qlcont = 0;
6792 #ifdef COMP_MLIB
6793 X  /* Open query library */
6794 X  if ((q_file_p= openlib(m_msg.tname, m_msg.qdnaseq,qascii,!m_msg.quiet,NULL))==NULL) {
6795 X    s_abort(" cannot open library ",m_msg.tname);
6796 X  }
6797 X  qlib = 0;
6798 X  m_msg.n0 = 
6799 X    QGETLIB (aa0[0], MAXTST, m_msg.qtitle, sizeof(m_msg.qtitle),
6800 X            &qseek, &qlcont,q_file_p,&m_msg.sq0off);
6801 X  if ((bp=strchr(m_msg.qtitle,' '))!=NULL) *bp='\0';
6802 X  strncpy(qlabel,m_msg.qtitle,sizeof(qlabel));
6803 X  if (bp != NULL) *bp = ' ';
6804 X  qlabel[sizeof(qlabel)-1]='\0';
6805 X
6806 X  /* if annotations are included in sequence, remove them */
6807 X  if (m_msg.ann_flg) {
6808 X    m_msg.n0 = ann_scan(aa0[0],m_msg.n0,&m_msg,m_msg.qdnaseq);
6809 X  }
6810 X
6811 X  if (m_msg.term_code && !(m_msg.qdnaseq==SEQT_DNA || m_msg.qdnaseq==SEQT_RNA) &&
6812 X      aa0[0][m_msg.n0-1]!='*') {
6813 X    aa0[0][m_msg.n0++]='*';
6814 X    aa0[0][m_msg.n0]=0;
6815 X  }
6816 X
6817 X  /* check for subset */
6818 X  if (q_file_p->opt_text[0]!='\0') {
6819 X    if (q_file_p->opt_text[0]=='-') {
6820 X      sstart=0; sscanf(&q_file_p->opt_text[1],"%d",&sstop);
6821 X    }
6822 X    else {
6823 X      sscanf(&q_file_p->opt_text[0],"%d-%d",&sstart,&sstop);
6824 X      sstart--;
6825 X      if (sstop <= 0 ) sstop = BIGNUM;
6826 X    }
6827 X    for (id=0,is=sstart; is<min(m_msg.n0,sstop); ) aa0[0][id++]=aa0[0][is++];
6828 X    aa0[0][id]=0;
6829 X    m_msg.n0 = min(m_msg.n0,sstop)-sstart;
6830 X    if (m_msg.sq0off==1) m_msg.sq0off = sstart+1;
6831 X  }
6832 X
6833 #if defined(SW_ALTIVEC) || defined(SW_SSE2)
6834 X  /* for ALTIVEC, must pad with 15 NULL's */
6835 X  for (id=0; id<SEQ_PAD; id++) {aa0[0][m_msg.n0+id]=0;}
6836 #endif
6837 X
6838 X  if (qlcont) {
6839 X    qoffset += m_msg.n0 - m_msg.sq0off;
6840 X  }
6841 X  else {
6842 X    qoffset = 0l;
6843 X  }
6844 X
6845 #else
6846 X  m_msg.n0 = getseq (m_msg.tname, qascii, aa0[0], m_msg.max_tot,
6847 X                    m_msg.qtitle, sizeof(m_msg.qtitle),
6848 X                    &m_msg.sq0off);
6849 X  strncpy(qlabel,m_msg.tname,sizeof(qlabel));
6850 X  qlabel[sizeof(qlabel)-1]='\0';
6851 X
6852 X  /* if annotations are included in sequence, remove them */
6853 X  if (m_msg.ann_flg) {
6854 X    m_msg.n0 = ann_scan(aa0[0],m_msg.n0,&m_msg,m_msg.qdnaseq);
6855 X  }
6856 #endif
6857 X
6858 X  if (m_msg.n0 > MAXTST) {
6859 X    fprintf(stderr," sequence truncated to %d\n %s\n",MAXTST,m_msg.sqnam);
6860 X    fprintf(stdout," sequence truncated to %d\n %s\n",MAXTST,m_msg.sqnam);
6861 X    aa0[0][MAXTST]='\0';
6862 X    m_msg.n0=MAXTST;
6863 X  }
6864 X
6865 X  if (m_msg.qdnaseq == SEQT_UNK) {
6866 X
6867 X  /* do automatic sequence recognition,but only for sequences > 20 residues */
6868 X    if (m_msg.n0 > 20 &&
6869 X       (float)scanseq(aa0[0],m_msg.n0,"ACGTUNacgtun")/(float)m_msg.n0 >0.85) {
6870 X      pascii = nascii;
6871 X      m_msg.qdnaseq = SEQT_DNA;
6872 X    }
6873 X    else {     /* its protein */
6874 X      pascii = aascii;
6875 X      m_msg.qdnaseq = SEQT_PROT;
6876 X    }
6877 X    /* modify qascii to use encoded version 
6878 X       cannot use memcpy() because it loses annotations 
6879 X    */
6880 X    re_ascii(qascii,pascii);
6881 X    init_ascii(pst.ext_sq_set,qascii,m_msg.qdnaseq);
6882 X    m_msg.n0 = recode(aa0[0],m_msg.n0,qascii, pst.nsqx);
6883 X  }
6884 X
6885 X  if (m_msg.n0 <= 0)
6886 X    s_abort ("Query sequence length <= 0: ", m_msg.tname);
6887 X
6888 #ifdef SUPERFAMNUM
6889 X  m_msg.nqsfnum = nsfnum;
6890 X  for (i=0; i <= nsfnum & i<10; i++) m_msg.qsfnum[i] = sfnum[i];
6891 X  m_msg.nqsfnum_n = nsfnum_n;
6892 X  for (i=0; i <= nsfnum_n & i<10; i++) m_msg.qsfnum_n[i] = sfnum_n[i];
6893 #endif
6894 X
6895 X  resetp (&m_msg, &pst);
6896 X
6897 #ifndef COMP_MLIB
6898 X  gettitle(m_msg.tname,m_msg.qtitle,sizeof(m_msg.qtitle));
6899 X  if (m_msg.tname[0]=='-' || m_msg.tname[0]=='@') {
6900 X    strncmp(m_msg.tname,m_msg.qtitle,sizeof(m_msg.tname));
6901 X    if ((bp=strchr(m_msg.tname,' '))!=NULL) *bp='\0';
6902 X  }
6903 #endif
6904 X
6905 X  /* get library file names */
6906 X
6907 #ifndef PRSS
6908 X  if (strlen (m_msg.lname) == 0) {
6909 X    if (m_msg.quiet == 1) s_abort("Library name undefined","");
6910 X    libchoice(m_msg.lname,sizeof(m_msg.lname),&m_msg);
6911 X  }
6912 X  
6913 X  libselect(m_msg.lname, &m_msg);
6914 #else
6915 X  if (strlen (m_msg.lname) == 0) {
6916 X    if (m_msg.quiet == 1) s_abort("Shuffle sequence undefined","");
6917 l2:    fputs(iprompt2,stdout);
6918 X    fflush(stdout);
6919 X    if (fgets (m_msg.lname, MAX_FN, stdin) == NULL)
6920 X      s_abort ("Unable to read shuffle file name","");
6921 X    m_msg.lname[MAX_FN-1]='\0';
6922 X    if ((bp=strchr(m_msg.lname,'\n'))!=NULL) *bp='\0';
6923 X    if (m_msg.lname[0] == '\0') goto l2;
6924 X  }
6925 X  m_msg.lbnames[0]= m_msg.lname;
6926 X  m_msg.nln = 1;
6927 X  m_msg.nshow = 0;
6928 #endif
6929 X
6930 X  /* Get additional parameters here */
6931 X  if (!m_msg.quiet) query_parm (&m_msg, &pst);
6932 X  
6933 X  last_init(&m_msg, &pst);
6934 X
6935 X  /* Allocate space for saved scores */
6936 X  if ((best = 
6937 X       (struct beststr *)calloc((MAXBEST+1),sizeof(struct beststr)))==NULL)
6938 X    s_abort ("Cannot allocate best struct","");
6939 X  if ((bestp_arr = 
6940 X       (struct beststr **)malloc((MAXBEST+1)*sizeof(struct beststr *)))==NULL)
6941 X    s_abort ("Cannot allocate bestp_arr","");
6942 X  
6943 X  /* Initialize bestp_arr */
6944 X  for (nbest = 0; nbest < MAXBEST+1; nbest++)
6945 X    bestp_arr[nbest] = &best[nbest];
6946 X  best++; bestp_arr++;
6947 X  best[-1].score[0]=best[-1].score[1]=best[-1].score[2]= INT_MAX;
6948 X  best[-1].zscore=FLT_MAX;     /* for Z-scores, bigger is best */
6949 X  best[-1].escore=FLT_MIN;     /* for E()-values, lower is best */
6950 X
6951 X  if ((stats =
6952 X       (struct stat_str *)calloc(MAXSTATS,sizeof(struct stat_str)))==NULL)
6953 X    s_abort ("Cannot allocate stats struct","");
6954 X
6955 #ifdef UNIX
6956 X  /* set up signals now that input is done */
6957 X  signal(SIGHUP,SIG_IGN);
6958 #endif
6959 X
6960 #ifdef COMP_THR
6961 X  /* Set up buffers for reading the library:
6962 X
6963 X     We will start by using a 2 Mbyte buffer for each worker.  For
6964 X     proteins, that means 5,000 sequences of length 400 (average).
6965 X     For DNA, that means 2,000 sequences of length 1000.  At the
6966 X     moment, those are good averages.
6967 X  */
6968 X
6969 X  if (m_msg.ldnaseq== SEQT_DNA) {
6970 X    max_buf_cnt = MAX_NT_BUF;
6971 X    ave_seq_len = AVE_NT_LEN;
6972 X  }
6973 X  else {
6974 X    max_buf_cnt = MAX_AA_BUF;
6975 X    ave_seq_len = AVE_AA_LEN;
6976 X  }
6977 X
6978 X  /* however - buffer sizes should be a function of the number of
6979 X     workers so that all the workers are kept busy.  Assuming a 10,000
6980 X     entry library is the smallest we want to schedule, then
6981 X  */
6982 X
6983 X  if (max_buf_cnt > 10000/max_workers) 
6984 X    max_buf_cnt = 10000/(2*max_workers);
6985 X
6986 X  max_buf_cnt /= m_msg.thr_fact;
6987 X
6988 X  /* finally, max_work_buf should be mod 6 for tfasta */
6989 X  max_buf_cnt -= (max_buf_cnt % 6);
6990 X
6991 X  max_work_buf = 2*max_workers;
6992 X
6993 X  /* allocate space for library buffers and results */
6994 X
6995 X  buf_siz=max_buf_cnt*ave_seq_len;
6996 X  if (buf_siz < m_msg.max_tot) buf_siz = m_msg.max_tot;
6997 X  for (i=0; i<max_work_buf; i++) {
6998 X    if ((buf_list[i].buf =(struct buf_str *)calloc((size_t)(max_buf_cnt+1),
6999 X                                                  sizeof(struct buf_str)))
7000 X        ==NULL) {
7001 X      fprintf(stderr," cannot allocate buffer struct %d %d\n",i,max_buf_cnt+1);
7002 X      exit(1);
7003 X    }
7004 X    buf_list[i].buf_cnt=0;
7005 X    buf_list[i].have_results=0;
7006 X    if ((buf_list[i].start =
7007 X         (unsigned char *)calloc((size_t)(buf_siz),sizeof(unsigned char)))
7008 X        ==NULL) {
7009 X      fprintf(stderr," cannot allocate buffer %d\n",i);
7010 X      exit(1);
7011 X    }
7012 X
7013 X    /* make certain there is a '\0' at the beginning */
7014 X    buf_list[i].start++;
7015 X
7016 X    reader_buf[i] = &buf_list[i];
7017 X  }
7018 X
7019 X  /* initialization of global variables for threads/buffers */
7020 X
7021 X  num_worker_bufs = 0;
7022 X  num_reader_bufs = max_work_buf;
7023 X  reader_done = 0;
7024 X  worker_buf_workp = 0;
7025 X  worker_buf_readp = 0;
7026 X  reader_buf_workp = 0;
7027 X  reader_buf_readp = 0;
7028 X
7029 X  start_thread = 1;    /* keeps threads from starting */
7030 #endif
7031 X
7032 X  /* Label the output */
7033 X  if ((bp = (char *) strchr (m_msg.lname, ' ')) != NULL) *bp = '\0';
7034 X  if (m_msg.ltitle[0] == '\0') {
7035 X    strncpy(m_msg.ltitle,m_msg.lname,sizeof(m_msg.ltitle));
7036 X    m_msg.ltitle[sizeof(m_msg.ltitle)-1]='\0';
7037 X  }
7038 X
7039 #ifdef COMP_MLIB
7040 X  printf("Query library %s vs %s library\n", m_msg.tname,m_msg.lname);
7041 X  if (m_msg.nln > 0) printf("searching %s library\n\n",m_msg.lbnames[0]);
7042 #endif
7043 X
7044 #ifdef COMP_MLIB
7045 X  while(1) {
7046 X    m_msg.db.length = 0l;
7047 X    m_msg.db.entries = m_msg.db.carry = 0;
7048 X    qlib++;
7049 X    stats_done = 0;
7050 #endif
7051 X
7052 X  maxl = m_msg.max_tot - m_msg.n0 -2;  /* maxn = max library sequence space */
7053 X
7054 X  maxn = reset_maxn(&m_msg,maxl);
7055 X  pst.maxlen = maxn;
7056 X
7057 X  outfd = stdout;  
7058 X  nbest = 0;
7059 X  zbestcut = -FLT_MAX;
7060 X  nstats = 0;
7061 X
7062 X  /* get the last parameters */
7063 X  last_params(aa0[0],m_msg.n0, &m_msg, &pst);
7064 X
7065 X  /*
7066 X     if our function returns approximate E()-scores, we do not need to
7067 X     work with raw scores and later calculate z-scores.  When
7068 X     approx. E()-scores are calculated, we still need various
7069 X     statistics structures, but we can get them immediately.  In this
7070 X     case, find_zp() must produce a z_score (large positive is good)
7071 X     from an e_score.
7072 X  */
7073 X
7074 X  if (m_msg.escore_flg) {
7075 X    pst.zsflag_f = process_hist(stats,nstats,m_msg,pst,
7076 X                               &m_msg.hist,&m_msg.pstat_void,0);
7077 X    stats_done=1;
7078 X  }
7079 X
7080 #ifndef COMP_THR
7081 X  if (m_msg.qshuffle) {
7082 X    if ((aa0s=(unsigned char *)calloc(m_msg.n0+2,sizeof(char)))==NULL) {
7083 X      fprintf(stderr,"cannot allocate aa0s[%d]\n",m_msg.n0+2);
7084 X      exit(1);
7085 X    }
7086 X    *aa0s='\0';
7087 X    aa0s++;
7088 X    memcpy(aa0s,aa0[0],m_msg.n0);
7089 X    qshuffle(aa0s,m_msg.n0,m_msg.nm0);
7090 X  }
7091 X
7092 X  /* previous versions of FASTA have stored the reverse complement in
7093 X     the same array as the forward query sequence.  This version
7094 X     changes that, by allocating separate space for the reverse complement,
7095 X     and thus reducing the demand for a large MAXLIB/MAXTRN for long queries
7096 X  */
7097 X  if (m_msg.qframe == 2) {
7098 X    if ((aa0[1]=(unsigned char *)calloc(m_msg.n0+2,sizeof(char)))==NULL) {
7099 X      fprintf(stderr,"cannot allocate aa0[1][%d]\n",m_msg.n0+2);
7100 X      exit(1);
7101 X    }
7102 X    *aa0[1] = '\0';
7103 X    aa0[1]++;
7104 X    memcpy(aa0[1],aa0[0],m_msg.n0+1);
7105 X    revcomp(aa0[1],m_msg.n0,&pst.c_nt[0]);
7106 X  }
7107 X  /* set aa1 for serial - threaded points aa1 to buffer */
7108 X
7109 X  aa1 = aa0[0] + m_msg.n0+1;   /* modified now that aa0[1] is done separately */
7110 X  *aa1++='\0';
7111 #else
7112 X  init_thr(max_workers, work_info, m_msg, &pst, aa0[0], max_work_buf);
7113 #endif
7114 X
7115 X  if (m_msg.qshuffle && qstats==NULL) {
7116 X    if ((qstats =
7117 X        (struct stat_str *)calloc(m_msg.shuff_max+1,sizeof(struct stat_str)))==NULL)
7118 X      s_abort ("Cannot allocate qstats struct","");
7119 X  }
7120 X  nqstats = 0;
7121 X
7122 X  if (m_msg.markx & MX_HTML) fputs("<pre>\n",stdout);
7123 #ifndef PRSS
7124 X  /* rline[] is a tmp string */
7125 X  if (m_msg.qdnaseq == SEQT_DNA || m_msg.qdnaseq == SEQT_RNA) {
7126 X    strncpy(rline,(m_msg.qframe==1)? " (forward-only)" : "\0",sizeof(rline));
7127 X    rline[sizeof(rline)-1]='\0';
7128 X  }
7129 X  else rline[0]='\0';
7130 X
7131 X  leng = (int)strlen(m_msg.qtitle);
7132 X  if (leng > 50) leng -= 10;
7133 X
7134 X  sprintf (&m_msg.qtitle[leng], " %d %s", m_msg.n0, m_msg.sqnam);
7135 X  m_msg.seqnm = 0;
7136 X
7137 X
7138 #ifdef COMP_MLIB
7139 X  printf("%3d>>>%s - %d %s%s\n vs  %.60s %s\n", qlib,
7140 X        m_msg.qtitle, m_msg.n0, m_msg.sqnam,
7141 X        (m_msg.revcomp ? " (reverse complement)" : rline),
7142 X        m_msg.ltitle,lib_label);
7143 #else
7144 X  printf("%.50s: %d %s%s\n %s\n vs  %.60s %s\n",
7145 X        qlabel, m_msg.n0, m_msg.sqnam,
7146 X        (m_msg.revcomp ? " (reverse complement)" : rline),
7147 X        m_msg.qtitle,m_msg.ltitle,lib_label);
7148 #endif
7149 X  libstr_p = &libstr[0];
7150 X  n_libstr=sizeof(libstr);
7151 #else           /* PRSS */
7152 X  libstr_p = &m_msg.ltitle[0];
7153 X  n_libstr= sizeof(m_msg.ltitle);
7154 X  set_shuffle(m_msg);  /* set count/width parameters in llgetaa.c */ 
7155 #endif
7156 X
7157 X  fflush (outfd);
7158 X
7159 X  tprev = s_time();
7160 X  
7161 X  if (m_msg.dfile[0] && (fdata=fopen(m_msg.dfile,"w"))!=NULL)
7162 X    fprintf(fdata,"%3d\t%-50s\n",m_msg.n0,m_msg.qtitle);
7163 X
7164 X  qtt.length += m_msg.n0;
7165 X  qtt.entries++;
7166 X
7167 #ifdef COMP_THR
7168 X  start_thr();
7169 X
7170 X  /* now open the library and start reading */
7171 X  /* get a buffer and fill it up */
7172 X  get_rbuf(&cur_buf,max_work_buf);
7173 X
7174 X  cur_buf->buf_cnt = 0;
7175 X  cur_buf->have_results = 0;
7176 X  cur_buf->buf[0].aa1b = cur_buf->start;
7177 X  ntbuff = 0;
7178 X  nseq = 0;
7179 #else /* ! COMP_THR */
7180 X  /* initialize the comparison function, returning f_str */
7181 X  init_work (aa0[0], m_msg.n0, &pst, &f_str[0]);
7182 X  have_f_str=1;
7183 X
7184 X  f_str[5] = f_str[4] = f_str[3] = f_str[2] = f_str[1] = f_str[0];
7185 X  if (m_msg.qframe == 2) {
7186 X    init_work ( aa0[1], m_msg.n0, &pst, &f_str[1]);
7187 X  }
7188 X  if (m_msg.qshuffle) {
7189 X    init_work ( aa0s, m_msg.n0, &pst, &qf_str);
7190 X  }
7191 #endif  /* COMP_THR */
7192 X
7193 X  /* open the library - start the search */
7194 X
7195 X  for (iln = 0; iln < m_msg.nln; iln++) {
7196 X    if ((m_msg.lb_mfd[iln] = m_file_p=
7197 X        openlib(m_msg.lbnames[iln], m_msg.ldnaseq, lascii, !m_msg.quiet, m_msg.lb_mfd[iln]))
7198 X       ==NULL) {
7199 X      fprintf(stderr," cannot open library %s\n",m_msg.lbnames[iln]);
7200 X      continue;
7201 X    }
7202 #if !defined(PRSS) && !defined(COMP_MLIB)
7203 X    else
7204 X      printf ("searching %s %s\n",m_msg.lbnames[iln],lib_label);
7205 #endif
7206 X
7207 X    loffset = 0l;
7208 X    lcont = 0;
7209 X    ocont = 0;
7210 X    n1tot_v = n1tot_cnt = 0;
7211 X    n1tot_cur = n1tot_ptr = NULL;
7212 X
7213 X    /* get next buffer to read into */
7214 X    maxt = maxn;
7215 X
7216 #ifndef COMP_THR
7217 X    aa1ptr = aa1;
7218 #else
7219 X    /* read sequence directly into buffer */
7220 X    aa1ptr = aa1 = cur_buf->buf[nseq].aa1b;
7221 #endif
7222 X
7223 X    while ((n1=GETLIB(aa1ptr,maxt,libstr_p,n_libstr,&lmark,&lcont,m_file_p,&l_off))>=0) {
7224 X
7225 X      if (n_libstr <= MAX_UID) {
7226 X       if ((bp=strchr(libstr_p,' '))!=NULL) *bp='\0';
7227 X      }
7228 X
7229 X      if (m_msg.term_code && !lcont &&
7230 X         m_msg.ldnaseq==SEQT_PROT && aa1ptr[n1-1]!=m_msg.term_code) {
7231 X       aa1ptr[n1++]=m_msg.term_code;
7232 X       aa1ptr[n1]=0;
7233 X      }
7234 X
7235 #if defined(SW_ALTIVEC) || defined(SW_SSE2)
7236 X      /* for ALTIVEC, must pad with 15 NULL's */
7237 X      for (id=0; id<SEQ_PAD; id++) {aa1ptr[n1+id]=0;}
7238 #endif
7239 X
7240 #ifdef DEBUG
7241 X      if (aa1[-1]!='\0' || aa1ptr[n1]!='\0') {
7242 X       fprintf(stderr,"%s: aa1[%d] missing NULL boundaries: %d %d\n",libstr_p,n1,aa1[-1],aa1ptr[n1]);
7243 X      }
7244 #endif
7245 X
7246 X      /* check for a continued sequence and provide a pointer to 
7247 X        the n1_tot array if lcont || ocont */
7248 X      n1tot_v += n1;
7249 X      if (lcont && !ocont) {   /* get a new pointer */
7250 X       if (n1tot_cnt <= 0) {
7251 X         if ((n1tot_ptr=calloc(1000,sizeof(int)))==NULL) {
7252 X           fprintf(stderr," cannot allocate n1tot_ptr\n");
7253 X           exit(1);
7254 X         }
7255 X         else {n1tot_cnt=1000;}
7256 X       }
7257 X       n1tot_cnt--;
7258 X       n1tot_cur = n1tot_ptr++;
7259 X      }
7260 X
7261 X      if (n1tot_v < m_msg.n1_low || n1tot_v > m_msg.n1_high) {
7262 X       goto loop2;
7263 X      }
7264 X
7265 X      m_msg.db.entries++;
7266 X      m_msg.db.length += n1;
7267 X      if (m_msg.db.length > LONG_MAX) {
7268 X       m_msg.db.length -= LONG_MAX; m_msg.db.carry++;
7269 X      }
7270 X
7271 #ifdef DEBUG
7272 X      /* This finds most reasons for core dumps */
7273 X      if (pst.debug_lib)
7274 X       for (i=0; i<n1; i++)
7275 X         if (aa1[i]>=pst.nsqx) 
7276 X             {fprintf(stderr,
7277 X                      "%s residue[%d/%d] %d range (%d) lcont/ocont: %d/%d\n%s\n",
7278 X                      libstr,i,n1,aa1[i],pst.nsqx,lcont,ocont,aa1ptr+i);
7279 X             aa1[i]=0;
7280 X             n1=i-1;
7281 X             break;
7282 X             }
7283 #endif
7284 X
7285 X      /* don't count long sequences more than once */
7286 X      if (aa1!=aa1ptr) {n1 += m_msg.loff; m_msg.db.entries--;}
7287 X
7288 #ifdef PROGRESS
7289 X      if (!m_msg.quiet) 
7290 X       if (m_msg.db.entries % 200 == 199) {
7291 X         fputc('.',stderr);
7292 X         if (m_msg.db.entries % 10000 == 9999) fputc('\n',stderr);
7293 X         else if (m_msg.db.entries % 1000 == 999) fputc(' ',stderr);
7294 X
7295 X       }
7296 #endif
7297 X
7298 X      if (n1<=1) {
7299 X       /*      if (igncnt++ <10)
7300 X               fprintf(stderr,"Ignoring: %s\n",libstr);
7301 X       */
7302 X       goto loop2;
7303 X      }
7304 X
7305 #ifdef PRSS
7306 X      if (lmark==0) {
7307 X       n1s = n1;
7308 X       memcpy(aa1s,aa1,n1s);
7309 X       m_msg.db.entries=0;
7310 X       m_msg.db.length=0;
7311 X      }
7312 #endif
7313 X
7314 X      /* if COMP_THR - fill and empty buffers */
7315 #ifdef COMP_THR
7316 X      ntbuff += n1+1;
7317 X
7318 X      for (itt=m_msg.revcomp; itt<=m_msg.nitt1; itt++) {
7319 X
7320 X       cur_buf->buf_cnt++;
7321 X       cur_buf_p = &(cur_buf->buf[nseq++]);
7322 X       cur_buf_p->n1  = n1;
7323 X       cur_buf_p->n1tot_p = n1tot_cur;
7324 X       cur_buf_p->lseek = lmark;
7325 X       cur_buf_p->cont = ocont+1;
7326 X       cur_buf_p->m_file_p = (void *)m_file_p;
7327 X       cur_buf_p->frame = itt;
7328 X       memcpy(cur_buf_p->libstr,libstr,MAX_UID);
7329 #ifdef SUPERFAMNUM
7330 X       cur_buf_p->nsfnum = nsfnum;
7331 X       if ((cur_buf_p->sfnum[0]=sfnum[0])>0 &&
7332 X           (cur_buf_p->sfnum[1]=sfnum[1])>0 &&
7333 X           (cur_buf_p->sfnum[2]=sfnum[2])>0 &&
7334 X           (cur_buf_p->sfnum[3]=sfnum[3])>0 &&
7335 X           (cur_buf_p->sfnum[4]=sfnum[4])>0 &&
7336 X           (cur_buf_p->sfnum[5]=sfnum[5])>0 &&
7337 X           (cur_buf_p->sfnum[6]=sfnum[6])>0 &&
7338 X           (cur_buf_p->sfnum[7]=sfnum[7])>0 &&
7339 X           (cur_buf_p->sfnum[8]=sfnum[8])>0 &&
7340 X           (cur_buf_p->sfnum[9]=sfnum[9])>0) ;
7341 #endif
7342 X
7343 X       /* this assumes that max_buf_cnt is guaranteed %6=0 so that
7344 X          additional pointers to the same buffer can be used 
7345 X          nseq now points to next buffer
7346 X       */
7347 X
7348 X       cur_buf->buf[nseq].aa1b = cur_buf->buf[nseq-1].aa1b;
7349 X      } /* for (itt .. */
7350 X
7351 X      /* make a copy of the overlap (threaded only) */
7352 X      if (lcont) {
7353 X       memcpy(aa1s,&aa1[n1-m_msg.loff],m_msg.loff);
7354 X      }
7355 X
7356 X      /* if the buffer is filled */
7357 X      if (nseq >= max_buf_cnt || ntbuff >= buf_siz - maxn) {
7358 X
7359 X       /* provide filled buffer to workers */
7360 X       put_rbuf(cur_buf,max_work_buf);
7361 X
7362 X       /* get an empty buffer to fill */
7363 X       get_rbuf(&cur_buf,max_work_buf);
7364 X
7365 X       /* "empty" buffers have results that must be processed */
7366 X       if (cur_buf->buf_cnt && cur_buf->have_results) {
7367 X         save_best(cur_buf,m_msg,pst,fdata,m_msg.qsfnum,&m_msg.hist,
7368 X                   &m_msg.pstat_void
7369 #ifdef PRSS
7370 X                   ,s_score,&s_n1
7371 #endif
7372 X                   );
7373 X
7374 X       }
7375 X
7376 X       /* now the buffer is truly empty, fill it up */
7377 X       cur_buf->buf_cnt = 0;
7378 X       cur_buf->have_results = 0;
7379 X       /* point the first aa1 ptr to the buffer start */
7380 X       aa1=cur_buf->buf[0].aa1b = cur_buf->start;
7381 X       ntbuff = 0;
7382 X       nseq=0;
7383 X      }
7384 X      else {   /* room left in current buffer, increment ptrs */
7385 X       aa1=cur_buf->buf[nseq].aa1b = cur_buf->buf[nseq-1].aa1b+n1+1;
7386 X      }
7387 #else /* if !COMP_THR - do a bunch of searches */
7388 X
7389 X      /* t_best and t_rbest are used to save the best score or shuffled
7390 X        score from all the frames */
7391 X
7392 X      t_best = t_rbest = t_qrbest = -1;
7393 X      t_escore = t_rescore = t_qrescore = FLT_MAX;
7394 X      for (itt=m_msg.revcomp; itt<=m_msg.nitt1; itt++) {
7395 X
7396 X       rst.score[0] = rst.score[1] = rst.score[2] = 0;
7397 X       do_work (aa0[itt], m_msg.n0,aa1,n1,itt,&pst,f_str[itt],0,&rst);
7398 X
7399 X       if (rst.score[pst.score_ix] > t_best) {
7400 X         t_best = rst.score[pst.score_ix];
7401 X       }
7402 X
7403 X       if (fdata) {
7404 X         fprintf(fdata,
7405 X                 "%-12s %5d %6d %d %.5f %.5f %4d %4d %4d %g %d %d %8lld\n",
7406 X                 libstr,
7407 #ifdef SUPERFAMNUM
7408 X                 sfn_cmp(m_msg.qsfnum,sfnum),
7409 #else
7410 X                 0,
7411 #endif
7412 X                 n1,itt,
7413 X                 rst.comp,rst.H,
7414 X                 rst.score[0],rst.score[1],rst.score[2],
7415 X                 rst.escore, rst.segnum, rst.seglen, lmark);
7416 X         fflush(fdata);
7417 X       }
7418 X
7419 #ifdef PRSS
7420 X       if (lmark==0) {
7421 X         s_score[0] = rst.score[0];
7422 X         s_score[1] = rst.score[1];
7423 X         s_score[2] = rst.score[2];
7424 X
7425 X         s_n1 = n1;
7426 X         aa1_loff = l_off;
7427 X       }
7428 X       t_best = t_rbest = rst.score[pst.score_ix];
7429 X       t_escore = t_rescore = rst.escore;
7430 #else
7431 X       if (m_msg.qshuffle) {
7432 X         do_work (aa0s, m_msg.n0,aa1,n1,itt,&pst,qf_str,1,&rrst);
7433 X
7434 X         if (rrst.score[pst.score_ix] > t_qrbest) 
7435 X           t_qrbest = rrst.score[pst.score_ix];
7436 X         if (rrst.escore < t_qrescore) 
7437 X           t_qrescore = rrst.escore;
7438 X
7439 X         if (itt==m_msg.nitt1 && nqstats < m_msg.shuff_max) {
7440 X           qstats[nqstats].n1 = n1;    /* save the best score */
7441 X           qstats[nqstats].comp =  rst.comp;
7442 X           qstats[nqstats].H = rst.H;
7443 X           qstats[nqstats].escore = t_qrescore;
7444 X           qstats[nqstats++].score = t_qrbest;
7445 X           t_qrbest = -1;      /* reset t_qrbest, t_qrescore */
7446 X           t_qrescore = FLT_MAX;
7447 X         }
7448 X       }
7449 X
7450 X       if (pst.zsflag >= 10) {
7451 X         if (pst.zs_win > 0) wshuffle(aa1,aa1s,n1,pst.zs_win,&ieven);
7452 X         else shuffle(aa1,aa1s,n1);
7453 X         do_work (aa0[itt], m_msg.n0, aa1s, n1,itt,&pst,f_str[itt],0,&rrst);
7454 X         if (rrst.score[pst.score_ix] > t_rbest) {
7455 X           t_rbest = rrst.score[pst.score_ix];
7456 X           t_rescore = rrst.escore;
7457 X         }
7458 X       }
7459 #endif
7460 X       i_score = rst.score[pst.score_ix];
7461 X
7462 /* this section saves scores for statistics calculations.  For
7463 X   comparisons that can be from one of 2 or 6 frames, it should only
7464 X   be run once, for the best of the 2 or 6 scores.  t_rbest,t_rescore
7465 X   have the best of the 2 or 6 scores from the frames.  For proteins,
7466 X   this is run for every score.
7467 X
7468 */   
7469 #ifdef PRSS     /* don't save the first score (unshuffled) with PRSS */
7470 X       if (lmark > 0) {
7471 #endif          
7472 X
7473 X       if (itt == m_msg.nitt1) {
7474 X         if (nstats < MAXSTATS) {
7475 X           stats[nstats].n1 = n1;      /* save the best score */
7476 X           stats[nstats].comp =  rst.comp;
7477 X           stats[nstats].H = rst.H;
7478 X           if (pst.zsflag >=10) {
7479 X             t_best = t_rbest;
7480 X             t_escore = t_rescore;
7481 X           }
7482 X           stats[nstats].escore = t_escore;
7483 X           stats[nstats++].score = t_best;
7484 X           t_best = t_rbest = -1;      /* reset t_rbest, t_best */
7485 X           t_escore = t_rescore = FLT_MAX;
7486 X         }
7487 X         else if (pst.zsflag >= 0) {
7488 X           if (!stats_done) {
7489 X             pst.zsflag_f = process_hist(stats,nstats,m_msg,pst,
7490 X                                         &m_msg.hist,&m_msg.pstat_void,0);
7491 X             stats_done = 1;
7492 X             kstats = nstats;
7493 X             for (i=0; i<MAXBEST; i++) {
7494 X               bestp_arr[i]->zscore = 
7495 X                 (*find_zp)(bestp_arr[i]->score[pst.score_ix],
7496 X                            bestp_arr[i]->escore, bestp_arr[i]->n1,
7497 X                            bestp_arr[i]->comp, m_msg.pstat_void);
7498 X             }
7499 X             zbestcut = bestp_arr[nbest-1]->zscore;
7500 X           }
7501 X
7502 #ifdef SAMP_STATS
7503 /* older versions saved the first MAXSTATS scores, and ignored the
7504 X   rest in the statistics.  With SAMP_STATS, scores after MAX_STATS
7505 X   are sampled at random, and included in the sample set and the
7506 X   statistics parameters are re-derived at the end of the run using
7507 X   the sampled scores.
7508 X
7509 X   It would be faster not to do the nrand(); if(jstats < MAXSTATS)
7510 X   less often.
7511 */
7512 X           if (!m_msg.escore_flg) {    /* only for zscores */
7513 X             jstats = nrand(++kstats); /* no mod % 0 */
7514 X             if (jstats < MAXSTATS) {
7515 X               stats[jstats].n1 = n1;  /* save the best score */
7516 X               stats[jstats].comp =  rst.comp;
7517 X               stats[jstats].H = rst.H;
7518 X               if (pst.zsflag >=10) t_best = t_rbest;
7519 X               stats[jstats].score = t_best;
7520 X             }
7521 X           }
7522 #endif
7523 X         }     /* ( nstats >= MAXSTATS) && zsflag >= 0 */
7524 X       }       /* itt1 == nitt1 */
7525 #ifdef PRSS
7526 X       }
7527 #endif
7528 X
7529 X       /* this section completes work on the current score */
7530 X       if (stats_done) { /* stats_done > 0 => nstats >= MAXSTATS */
7531 X         zscore=(*find_zp)(i_score, rst.escore, n1, rst.comp,
7532 X                           m_msg.pstat_void);
7533 X
7534 X         if (itt == m_msg.nitt1) {
7535 X           if (pst.zsflag >= 10) t_best = t_rbest;
7536 X           
7537 X           addhistz((*find_zp)(t_best, t_escore, n1, rst.comp, 
7538 X                               m_msg.pstat_void),
7539 X                    &m_msg.hist);
7540 X           t_best = t_rbest = -1;
7541 X         }
7542 X       }
7543 X       else zscore = (double) i_score;
7544 X
7545 #ifndef PRSS
7546 X       if (zscore > zbestcut ) {
7547 X         if (nbest >= MAXBEST) {
7548 X           bestfull = nbest-MAXBEST/4;
7549 X           selectbestz(bestp_arr,bestfull-1,nbest);
7550 X           zbestcut = bestp_arr[bestfull-1]->zscore;
7551 X           nbest = bestfull;
7552 X         }
7553 X
7554 X         bestp = bestp_arr[nbest++];
7555 X         bestp->score[0] = rst.score[0];
7556 X         bestp->score[1] = rst.score[1];
7557 X         bestp->score[2] = rst.score[2];
7558 X         bestp->comp =  rst.comp;
7559 X         bestp->H = rst.H;
7560 X         bestp->zscore = zscore;
7561 X         bestp->escore = rst.escore;
7562 X         bestp->segnum = rst.segnum;
7563 X         bestp->seglen = rst.seglen;
7564 X         bestp->lseek = lmark;
7565 X         bestp->cont = ocont+1;
7566 X         bestp->m_file_p = m_file_p;
7567 X         bestp->n1 = n1;
7568 X         bestp->n1tot_p=n1tot_cur;
7569 X         bestp->frame = itt;
7570 X         memcpy(bestp->libstr,libstr,MAX_UID);
7571 #ifdef SUPERFAMNUM
7572 X         bestp->nsfnum = nsfnum;
7573 X         if ((bestp->sfnum[0]=sfnum[0])>0 &&
7574 X             (bestp->sfnum[1]=sfnum[1])>0 &&
7575 X             (bestp->sfnum[2]=sfnum[2])>0 &&
7576 X             (bestp->sfnum[3]=sfnum[3])>0 &&
7577 X             (bestp->sfnum[4]=sfnum[4])>0 &&
7578 X             (bestp->sfnum[5]=sfnum[5])>0 &&
7579 X             (bestp->sfnum[6]=sfnum[6])>0 &&
7580 X             (bestp->sfnum[7]=sfnum[7])>0 &&
7581 X             (bestp->sfnum[8]=sfnum[8])>0 &&
7582 X             (bestp->sfnum[9]=sfnum[9])>0) ;
7583 #endif
7584 X       }
7585 #else   /* PRSS */
7586 X       if (lmark == 0) {
7587 X         bestp = bestp_arr[nbest++];
7588 X         bestp->score[0] = rst.score[0];
7589 X         bestp->score[1] = rst.score[1];
7590 X         bestp->score[2] = rst.score[2];
7591 X         bestp->comp =  rst.comp;
7592 X         bestp->H = rst.H;
7593 X         bestp->zscore = zscore;
7594 X         bestp->escore = rst.escore;
7595 X         bestp->segnum = rst.segnum;
7596 X         bestp->seglen = rst.seglen;
7597 X         bestp->lseek = lmark;
7598 X         bestp->cont = 0;
7599 X         bestp->m_file_p = m_file_p;
7600 X         bestp->n1 = n1;
7601 X         bestp->n1tot_p=n1tot_cur;
7602 X         bestp->frame = itt;
7603 X         memcpy(bestp->libstr,libstr,MAX_UID);
7604 X         bestp->nsfnum = 0;
7605 X       }
7606 #endif
7607 X      }
7608 #endif
7609 X
7610 X    loop2: 
7611 X      if (lcont) {
7612 X       maxt = m_msg.maxt3;
7613 #ifndef COMP_THR
7614 X       memcpy(aa1,&aa1[n1-m_msg.loff],m_msg.loff);
7615 #else
7616 X       memcpy(aa1,aa1s,m_msg.loff);
7617 #endif
7618 X       aa1ptr= &aa1[m_msg.loff];
7619 X       loffset += n1 - m_msg.loff;
7620 X       ocont = lcont;
7621 X      }
7622 X      else {
7623 X       maxt = maxn;
7624 X       aa1ptr=aa1;
7625 X       if (ocont) *n1tot_cur = n1tot_v;
7626 X       ocont = 0;
7627 X       loffset = 0l;
7628 X       n1tot_v = 0;
7629 X       n1tot_cur = NULL;
7630 X      }
7631 X    } /* end while((n1=getlib())) */
7632 X  } /* end iln=1..nln */
7633 X
7634 X  /* all done */
7635 X
7636 #ifdef COMP_THR
7637 X  /* check last buffers for any results */
7638 X  put_rbuf_done(max_workers,cur_buf,max_work_buf);
7639 X
7640 X  for (i=0; i < num_reader_bufs; i++) {
7641 X    reader_buf_readp = (reader_buf_readp+1)%(max_work_buf);
7642 X    if (reader_buf[reader_buf_readp]->buf_cnt > 0 && 
7643 X       reader_buf[reader_buf_readp]->have_results) {
7644 X         save_best(reader_buf[reader_buf_readp],m_msg,pst,fdata,m_msg.qsfnum,
7645 X                   &m_msg.hist, &m_msg.pstat_void
7646 #ifdef PRSS
7647 X                   ,s_score,&s_n1
7648 #endif
7649 X                   );
7650 X    }
7651 X  }
7652 #endif
7653 X
7654 #ifdef PROGRESS
7655 X  if (!m_msg.quiet)
7656 X    if (m_msg.db.entries >= 200) {fprintf(stderr," Done!\n");}
7657 #endif
7658 X
7659 X  m_msg.nbr_seq = m_msg.db.entries;
7660 X  get_param(&pst, gstring2,gstring3);
7661 X
7662 /* *************************** */
7663 /* analyze the last results    */
7664 /* *************************** */
7665 X    
7666 #ifndef PRSS
7667 #ifndef SAMP_STATS
7668 X  if (!stats_done && nstats > 0) {
7669 #endif
7670 X    pst.zsflag_f = process_hist(stats,nstats,m_msg,pst,&m_msg.hist,
7671 X                               &m_msg.pstat_void,stats_done);
7672 X    if (m_msg.pstat_void != NULL) {
7673 X      stats_done = 1;
7674 X      for (i = 0; i < nbest; i++) {
7675 X       bestp_arr[i]->zscore =
7676 X         (*find_zp)(bestp_arr[i]->score[pst.score_ix],
7677 X                    bestp_arr[i]->escore, bestp_arr[i]->n1, 
7678 X                    bestp_arr[i]->comp, m_msg.pstat_void);
7679 X      }
7680 #ifndef SAMP_STATS
7681 X    }
7682 X    else pst.zsflag = -1;
7683 #endif
7684 X  }
7685 #else   /* PRSS */
7686 X  if (pst.zsflag < 10) pst.zsflag += 10;
7687 X  pst.zsflag_f = process_hist(stats,nstats,m_msg,pst,
7688 X                             &m_msg.hist, &m_msg.pstat_void,0);
7689 X  stats_done = 1;
7690 X  for (i = 0; i < nbest; i++) {
7691 X    bestp_arr[i]->zscore = (*find_zp)(bestp_arr[i]->score[pst.score_ix],
7692 X                                     bestp_arr[i]->escore, bestp_arr[i]->n1,
7693 X                                     bestp_arr[i]->comp, m_msg.pstat_void);
7694 X  }
7695 #endif
7696 X
7697 X  if (pst.zdb_size <= 1) pst.zdb_size = m_msg.db.entries;
7698 X
7699 #ifdef COMP_THR
7700 X  /* before I call last_calc/showbest/showalign, I need init_work() to
7701 X     get an f_str. This duplicates some code above, which is used in
7702 X     the non-threaded version
7703 X  */
7704 X
7705 X  if (!have_f_str) {
7706 X    init_work(aa0[0],m_msg.n0,&pst,&f_str[0]);
7707 X    have_f_str = 1;
7708 X    f_str[5] = f_str[4] = f_str[3] = f_str[2] = f_str[1] =  f_str[0];
7709 X
7710 X    if (m_msg.qframe == 2) {
7711 X      if ((aa0[1]=(unsigned char *)calloc((size_t)m_msg.n0+2,
7712 X                                         sizeof(unsigned char)))==NULL) {
7713 X       fprintf(stderr," cannot allocate aa0[1][%d] for alignments\n",
7714 X               m_msg.n0+2);
7715 X      }
7716 X      *aa0[1]='\0';
7717 X      aa0[1]++;
7718 X      memcpy(aa0[1],aa0[0],m_msg.n0+1);
7719 X      revcomp(aa0[1],m_msg.n0,&pst.c_nt[0]);
7720 X      init_work(aa0[1],m_msg.n0,&pst,&f_str[1]);
7721 X    }
7722 X
7723 X    /* I also need a "real" aa1 */
7724 X    aa1 = buf_list[0].start;
7725 #ifdef PRSS
7726 X    /* for PRSS - I need the original second (non-shuffled) sequence */
7727 X    memcpy(aa1,aa1s,n1s+1);
7728 #endif
7729 X    }
7730 #endif
7731 X
7732 /* now we have one set of scaled scores for in bestp_arr  -
7733 X   for FASTS/F, we need to do some additional processing */
7734 X
7735 X  if (!m_msg.qshuffle) {
7736 X    last_stats(aa0[0], m_msg.n0, stats,nstats, bestp_arr,nbest,
7737 X              m_msg, pst, &m_msg.hist, &m_msg.pstat_void);
7738 X  }
7739 X  else {
7740 X    last_stats(aa0[0], m_msg.n0,
7741 X              qstats,nqstats, bestp_arr,nbest, m_msg, pst, 
7742 X              &m_msg.hist, &m_msg.pstat_void);
7743 X  }
7744 X
7745 X  /* here is a contradiction: if pst.zsflag < 0, then m_msg.pstat_void
7746 X     should be NULL; if it is not, then process_hist() has been called */
7747 X  if (pst.zsflag < 0 && m_msg.pstat_void != NULL) pst.zsflag = 1;
7748 X
7749 X  if (m_msg.last_calc_flg) {
7750 X    /* last_calc may need coefficients from last_stats() */
7751 X    nbest = last_calc(aa0, aa1, maxn, bestp_arr, nbest, m_msg, &pst,
7752 X                     f_str, m_msg.pstat_void);
7753 X  }
7754 X
7755 X  scale_scores(bestp_arr,nbest,m_msg.db,pst,m_msg.pstat_void);
7756 X
7757 X  get_param(&pst, gstring2,gstring3);
7758 X
7759 #ifdef PRSS
7760 X  /*   gettitle(m_msg.lname,m_msg.ltitle,sizeof(m_msg.ltitle)); */
7761 X  printf("%.50s - %s %d %s%s\n vs %.60s - %s shuffled sequence\n",
7762 X        m_msg.tname, m_msg.qtitle,m_msg.n0, m_msg.sqnam,
7763 X        (m_msg.revcomp ? " (reverse complement)" : "\0"),
7764 X        m_msg.lname,m_msg.ltitle);
7765 #endif
7766 X
7767 X  prhist (stdout, m_msg, pst, m_msg.hist, nstats, m_msg.db, gstring2);
7768 X
7769 X  tscan = s_time();
7770 X  printf (" Scan time: ");
7771 X  ptime(stdout,tscan-tprev);
7772 X  printf ("\n");
7773 #ifdef COMP_MLIB
7774 X  ttscan += tscan-tprev;
7775 #endif
7776 X
7777 X l3:
7778 X  if (!m_msg.quiet) {
7779 X    printf("Enter filename for results [%s]: ", m_msg.outfile);
7780 X    fflush(stdout);
7781 X  }
7782 X
7783 X  rline[0]='\0';
7784 X  if (!m_msg.quiet && fgets(rline,sizeof(rline),stdin)==NULL) goto end_l;
7785 X  if ((bp=strchr(rline,'\n'))!=NULL) *bp = '\0';
7786 X  if (rline[0]!='\0') strncpy(m_msg.outfile,rline,sizeof(m_msg.outfile));
7787 X  if (m_msg.outfile[0]!='\0') {
7788 X    if ((outfd=fopen(m_msg.outfile,"w"))==NULL) {
7789 X      fprintf(stderr," could not open %s\n",m_msg.outfile);
7790 X      if (!m_msg.quiet) goto l3;
7791 X      else goto l4;
7792 X    }
7793 X
7794 #ifdef PGM_DOC
7795 X    fputs(argv_line,outfd);
7796 X    fputc('\n',outfd);
7797 #endif  
7798 X    fputs(iprompt0,outfd);
7799 X    fprintf(outfd," %s%s\n",verstr,refstr);
7800 X
7801 X    fprintf(outfd," %s%s, %d %s\n vs %s %s\n",
7802 X           qlabel, (m_msg.revcomp ? "-" : "\0"), m_msg.n0,
7803 X           m_msg.sqnam, m_msg.ltitle, lib_label);
7804 X
7805 X    prhist(outfd,m_msg,pst,m_msg.hist, nstats, m_msg.db, gstring2);
7806 X  }
7807 X
7808 X l4:   
7809 X  if (m_msg.markx & MX_HTML) {
7810 X      fputs("</pre>\n<p>\n<hr>\n<p>\n",outfd);
7811 X  }
7812 X
7813 X  /* code from p2_complib.c to pre-calculate -m 9 alignment info -
7814 X     requires -q with -m 9 */
7815 X
7816 X  if (m_msg.quiet || m_msg.markx & MX_M9SUMM) {
7817 X
7818 X    /* to determine how many sequences to re-align (either for
7819 X       do_opt() or calc_id() we need to modify m_msg.mshow to get
7820 X       the correct number of alignments */
7821 X
7822 X    if (m_msg.mshow_flg != 1 && pst.zsflag >= 0) {
7823 X      for (i=0; i<nbest && bestp_arr[i]->escore< m_msg.e_cut; i++) {}
7824 X      m_msg.mshow = i;
7825 X    }
7826 X
7827 #ifndef PRSS
7828 X    if (m_msg.mshow <= 0) { /* no results to display */
7829 X      fprintf(outfd,"!! No sequences with E() < %f\n",m_msg.e_cut);
7830 X      m_msg.nshow = 0;
7831 X      goto end_l;
7832 X    }
7833 #endif
7834 X  }
7835 X
7836 #ifdef PRSS
7837 X  memcpy(aa1,aa1s,n1s);
7838 X  maxn = n1s;
7839 X  nbest = 1;
7840 #endif
7841 X
7842 X  showbest (stdout, aa0, aa1, maxn, bestp_arr, nbest, qtt.entries, &m_msg, pst,
7843 X           m_msg.db, gstring2, f_str);
7844 X
7845 X  if (outfd != stdout) {
7846 X    t_quiet = m_msg.quiet;
7847 X    m_msg.quiet = -1;  /* should guarantee 1..nbest shown */
7848 X    showbest (outfd, aa0, aa1, maxn, bestp_arr, nbest, qtt.entries, &m_msg, pst,
7849 X             m_msg.db, gstring2, f_str);
7850 X    m_msg.quiet = t_quiet;
7851 X  }
7852 X
7853 X  if (m_msg.nshow > 0) {
7854 X    rline[0]='N';
7855 X    if (!m_msg.quiet){
7856 X      printf(" Display alignments also? (y/n) [n] "); fflush(stdout);
7857 X      if (fgets(rline,sizeof(rline),stdin)==NULL) goto end_l;
7858 X    }
7859 X    else rline[0]='Y';
7860 X
7861 X    if (toupper((int)rline[0])=='Y') {
7862 X      if (!m_msg.quiet) {
7863 X       printf(" number of alignments [%d]? ",m_msg.nshow);
7864 X       fflush(stdout);
7865 X       if (fgets(rline,sizeof(rline),stdin)==NULL) goto end_l;
7866 X       if (rline[0]!=0) sscanf(rline,"%d",&m_msg.nshow);
7867 X       m_msg.ashow=m_msg.nshow;
7868 X      }
7869 X
7870 X      if (m_msg.markx & (MX_AMAP+ MX_HTML + MX_M9SUMM)) {
7871 X       fprintf(outfd,"\n>>>%s%s, %d %s vs %s library\n",
7872 X               qlabel,(m_msg.revcomp ? "_rev":"\0"), m_msg.n0,
7873 X               m_msg.sqnam,m_msg.lname);
7874 X      }
7875 X
7876 X      if (m_msg.markx & MX_M10FORM) {
7877 X       fprintf(outfd,"\n>>>%s%s, %d %s vs %s library\n",
7878 X               qlabel,(m_msg.revcomp ? "-":"\0"), m_msg.n0, m_msg.sqnam,
7879 X               m_msg.lname);
7880 X       fprintf(outfd,"; pg_name: %s\n",argv[0]);
7881 X       fprintf(outfd,"; pg_ver: %s\n",mp_verstr);
7882 X       fprintf(outfd,"; pg_argv:");
7883 X       for (i=0; i<argc; i++)
7884 X         fprintf(outfd," %s",argv[i]);
7885 X       fputc('\n',outfd);
7886 X       fputs(gstring3,outfd);
7887 X       fputs(hstring1,outfd);
7888 X      }
7889 X
7890 #ifndef PRSS
7891 X      showalign (outfd, aa0, aa1, maxn, bestp_arr, nbest, qtt.entries,
7892 X                m_msg, pst, gstring2, f_str);
7893 #else
7894 X      if (pst.sw_flag > 0 || (!m_msg.quiet && m_msg.nshow>0)) {
7895 X       showalign (outfd, aa0, aa1, maxn, bestp_arr, nbest, qtt.entries,
7896 X                m_msg, pst, gstring2, f_str);
7897 X      }
7898 #endif
7899 X
7900 X      fflush(outfd);
7901 X    }
7902 X  }
7903 X
7904 X  end_l:
7905 #if defined(COMP_THR) && defined(COMP_MLIB)
7906 X    for (i=0; i<max_work_buf; i++) {
7907 X      buf_list[i].buf_cnt=0;
7908 X      buf_list[i].have_results=0;
7909 X    }
7910 X
7911 X    num_worker_bufs = 0;
7912 X    num_reader_bufs = max_work_buf;
7913 X    reader_done = 0;
7914 X    worker_buf_workp = 0;
7915 X    worker_buf_readp = 0;
7916 X    reader_buf_workp = 0;
7917 X    reader_buf_readp = 0;
7918 X
7919 X    start_thread = 1;  /* stop thread from starting again */
7920 #endif
7921 X
7922 X    /* clean up alignment encodings */
7923 X    for (i=0; i < m_msg.nshow; i++) {
7924 X      if (bestp_arr[i]->have_ares) {
7925 X       free(bestp_arr[i]->a_res.res);
7926 X       bestp_arr[i]->a_res.res = NULL;
7927 X       bestp_arr[i]->have_ares = 0;
7928 X      }
7929 X    }
7930 X
7931 X    if (m_msg.qframe == 2) free(aa0[1]-1);
7932 X
7933 X    if (have_f_str) {
7934 X      if (f_str[1]!=f_str[0]) {
7935 X       close_work (aa0[1], m_msg.n0, &pst, &f_str[1]);
7936 X      }
7937 X      close_work (aa0[0], m_msg.n0, &pst, &f_str[0]);
7938 X      have_f_str = 0;
7939 #ifndef COMP_THR
7940 X      if (m_msg.qshuffle) close_work (aa0s, m_msg.n0, &pst, &qf_str);
7941 #endif
7942 X      if (pst.pam_pssm) {
7943 X       free_pam2p(pst.pam2p[0]);
7944 X       free_pam2p(pst.pam2p[1]);
7945 X      }
7946 X    }
7947 X
7948 X    for (iln=0; iln < m_msg.nln; iln++) {
7949 X      if (m_msg.lb_mfd[iln]!=NULL) closelib(m_msg.lb_mfd[iln]);
7950 X    }
7951 X
7952 X    tddone = time(NULL);
7953 X    tdone = s_time();
7954 X    fflush(outfd);
7955 X
7956 X    if (fdata) {
7957 X      fprintf(fdata,"/** %s **/\n",gstring2);
7958 X      fprintf(fdata,"%3ld%-50s\n",qtt.entries-1,m_msg.qtitle);
7959 X      fflush(fdata);
7960 X    }
7961 X    
7962 #ifdef COMP_MLIB
7963 X    ttdisp += tdone-tscan;
7964 X
7965 X    maxn = m_msg.max_tot;
7966 X    m_msg.n0 = 
7967 X      QGETLIB (aa0[0], MAXTST, m_msg.qtitle, sizeof(m_msg.qtitle),
7968 X              &qseek, &qlcont,q_file_p,&m_msg.sq0off);
7969 X    if (m_msg.n0 <= 0) break;
7970 X    if ((bp=strchr(m_msg.qtitle,' '))!=NULL) *bp='\0';
7971 X    strncpy(qlabel, m_msg.qtitle,sizeof(qlabel));
7972 X    if (bp != NULL) *bp=' ';
7973 X    qlabel[sizeof(qlabel)-1]='\0';
7974 X
7975 X    if (m_msg.ann_flg) {
7976 X      m_msg.n0 = ann_scan(aa0[0],m_msg.n0,&m_msg,m_msg.qdnaseq);
7977 X    }
7978 X
7979 X    if (m_msg.term_code && m_msg.qdnaseq==SEQT_PROT &&
7980 X       aa0[0][m_msg.n0-1]!=m_msg.term_code) {
7981 X      aa0[0][m_msg.n0++]=m_msg.term_code;
7982 X      aa0[0][m_msg.n0]=0;
7983 X    }
7984 X
7985 #if defined(SW_ALTIVEC) || defined(SW_SSE2)
7986 X    /* for ALTIVEC, must pad with 15 NULL's */
7987 X    for (id=0; id<SEQ_PAD; id++) {aa0[0][m_msg.n0+id]=0;}
7988 #endif
7989 X
7990 #ifdef SUPERFAMNUM
7991 X    m_msg.nqsfnum = nsfnum;
7992 X    for (i=0; i <= nsfnum & i<10; i++) m_msg.qsfnum[i] = sfnum[i];
7993 X    m_msg.nqsfnum_n = nsfnum_n;
7994 X    for (i=0; i <= nsfnum_n & i<10; i++) m_msg.qsfnum_n[i] = sfnum_n[i];
7995 #endif
7996 X  }
7997 #endif
7998 X  if (m_msg.markx & MX_M10FORM)
7999 X      fprintf(outfd,">>><<<\n");
8000 X
8001 X    tdone = s_time();
8002 X    if ( m_msg.markx & MX_HTML) fputs("<p><pre>\n",outfd); 
8003 X    printsum(outfd, m_msg.db);
8004 X    if ( m_msg.markx & MX_HTML) fputs("</pre>\n",outfd);
8005 #ifdef HTML_HEAD
8006 X    if (m_msg.markx & MX_HTML) fprintf(outfd,"</body>\n</html>\n");
8007 #endif
8008 X    if (outfd!=stdout) printsum(stdout,m_msg.db);
8009 X
8010 X    exit(0);
8011 }   /* End of main program */
8012 X
8013 void
8014 printsum(FILE *fd, struct db_str ntt)
8015 {
8016 X  double db_tt;
8017 X  char tstr1[26], tstr2[26];
8018 X
8019 X  strncpy(tstr1,ctime(&tdstart),sizeof(tstr1));
8020 X  strncpy(tstr2,ctime(&tddone),sizeof(tstr1));
8021 X  tstr1[24]=tstr2[24]='\0';
8022 X
8023 X  /* Print timing to output file as well */
8024 X  fprintf(fd, "\n\n%ld residues in %ld query   sequences\n", qtt.length, qtt.entries);
8025 X  if (ntt.carry == 0) 
8026 X    fprintf(fd, "%ld residues in %ld library sequences\n", ntt.length, ntt.entries);
8027 X  else {
8028 X    db_tt = (double)ntt.carry*(double)LONG_MAX + (double)ntt.length;
8029 X    fprintf(fd, "%.0f residues in %ld library sequences\n", db_tt, ntt.entries);
8030 X  }
8031 X
8032 #ifndef COMP_THR
8033 X  fprintf(fd," Scomplib [%s]\n start: %s done: %s\n",mp_verstr,tstr1,tstr2);
8034 #else
8035 X  fprintf(fd," Tcomplib [%s] (%d proc)\n start: %s done: %s\n", mp_verstr,
8036 X    max_workers,tstr1,tstr2);
8037 #endif
8038 #ifndef COMP_MLIB
8039 X  fprintf(fd," Scan time: ");
8040 X  ptime(fd, tscan - tprev);
8041 X  fprintf (fd," Display time: ");
8042 X  ptime (fd, tdone - tscan);
8043 #else
8044 X  fprintf(fd," Total Scan time: ");
8045 X  ptime(fd, ttscan);
8046 X  fprintf (fd," Total Display time: ");
8047 X  ptime (fd, ttdisp);
8048 #endif
8049 X  fprintf (fd,"\n");
8050 X  fprintf (fd, "\nFunction used was %s [%s]\n", prog_func,verstr);
8051 }
8052 X
8053 void fsigint()
8054 {
8055 X  struct db_str db;
8056 X
8057 X  db.entries = db.length = db.carry = 0;
8058 X  tdone = s_time();
8059 X  tddone = time(NULL);
8060 X
8061 X  printf(" /*** interrupted ***/\n");
8062 X  if (outfd!=stdout) fprintf(outfd,"/*** interrupted ***/\n");
8063 X  fprintf(stderr,"/*** interrupted ***/\n");
8064 X
8065 X  printsum(stdout,db);
8066 X  if (outfd!=stdout) printsum(outfd,db);
8067 X
8068 X  exit(1);
8069 }
8070 X
8071 #ifdef COMP_THR
8072 void save_best(struct buf_head *cur_buf, struct mngmsg m_msg, struct pstruct pst, 
8073 X              FILE *fdata, int *qsfnum, struct hist_str *histp,
8074 X              void **pstat_voidp
8075 #ifdef PRSS
8076 X              , int *s_score, int *s_n1
8077 X
8078 #endif
8079 X              )
8080 {
8081 X  double zscore;
8082 X  int i_score;
8083 X  struct buf_str *p_rbuf, *cur_buf_p;
8084 X  int i, t_best, t_rbest, t_qrbest, tm_best, t_n1, sc_ix;
8085 X  double e_score, tm_escore, t_rescore, t_qrescore;
8086 X  int jstats;
8087 X
8088 X  sc_ix = pst.score_ix;
8089 X
8090 X  cur_buf_p = cur_buf->buf;
8091 X  
8092 X  t_best = t_rbest = t_qrbest = -1;
8093 X  tm_escore = t_rescore = t_qrescore = FLT_MAX;
8094 X
8095 X  while (cur_buf->buf_cnt--) { /* count down the number of results */
8096 X    p_rbuf = cur_buf_p++;      /* step through the results buffer */
8097 X
8098 X    i_score = p_rbuf->rst.score[sc_ix];
8099 X    e_score = p_rbuf->rst.escore;
8100 X
8101 X    /* need to look for frame 0 if TFASTA, then save stats at frame 6 */
8102 X    if (fdata) {
8103 X      fprintf(fdata,
8104 X             "%-12s %5d %6d %d %.5f %.5f %4d %4d %4d %g %d %d %8ld\n",
8105 X             p_rbuf->libstr,
8106 #ifdef SUPERFAMNUM
8107 X             sfn_cmp(qsfnum,p_rbuf->sfnum),
8108 #else
8109 X             0,
8110 #endif
8111 X             p_rbuf->n1,p_rbuf->frame,p_rbuf->rst.comp,p_rbuf->rst.H,
8112 X             p_rbuf->rst.score[0],p_rbuf->rst.score[1],p_rbuf->rst.score[2],
8113 X             p_rbuf->rst.escore, p_rbuf->rst.segnum, p_rbuf->rst.seglen, p_rbuf->lseek);
8114 X    }
8115 X
8116 #ifdef PRSS
8117 X    if (p_rbuf->lseek==0) {
8118 X      s_score[0] = p_rbuf->rst.score[0];
8119 X      s_score[1] = p_rbuf->rst.score[1];
8120 X      s_score[2] = p_rbuf->rst.score[2];
8121 X      *s_n1 = p_rbuf->n1;
8122 X
8123 X      bestp = bestp_arr[nbest++];
8124 X      bestp->score[0] = s_score[0];
8125 X      bestp->score[1] = s_score[1];
8126 X      bestp->score[2] = s_score[2];
8127 X      bestp->n1 = *s_n1;
8128 X      bestp->escore = p_rbuf->rst.escore;
8129 X      bestp->segnum = p_rbuf->rst.segnum;
8130 X      bestp->seglen = p_rbuf->rst.seglen;
8131 X      bestp->zscore = zscore;
8132 X      bestp->lseek = p_rbuf->lseek;
8133 X      bestp->m_file_p = p_rbuf->m_file_p;
8134 X      memcpy(bestp->libstr,p_rbuf->libstr,MAX_UID);
8135 X      bestp->n1tot_p = p_rbuf->n1tot_p;
8136 X      bestp->frame = p_rbuf->frame;
8137 X
8138 X      continue;
8139 X    }
8140 #endif
8141 X
8142 X    t_n1 = p_rbuf->n1;
8143 X    if (i_score > t_best) tm_best = t_best = i_score;
8144 X    if (e_score < tm_escore) tm_escore = e_score;
8145 X
8146 X    if (m_msg.qshuffle) {
8147 X      if (p_rbuf->qr_score > t_qrbest)
8148 X       t_qrbest = p_rbuf->qr_score;
8149 X      if (p_rbuf->qr_escore < t_qrescore)
8150 X       t_qrescore = p_rbuf->qr_escore;
8151 X      
8152 X      if (p_rbuf->frame == m_msg.nitt1 && nqstats < m_msg.shuff_max) {
8153 X       qstats[nqstats].n1 = p_rbuf->n1;        /* save the best score */
8154 X       qstats[nqstats].comp =  p_rbuf->rst.comp;
8155 X       qstats[nqstats].H = p_rbuf->rst.H;
8156 X       qstats[nqstats].escore = t_qrescore;
8157 X       qstats[nqstats++].score = t_qrbest;
8158 X       t_qrbest = -1;  /* reset t_qrbest, t_qrescore */
8159 X       t_qrescore = FLT_MAX;
8160 X      }
8161 X    }
8162 X
8163 X    if (pst.zsflag >= 10 && p_rbuf->r_score > t_rbest) {
8164 X      t_rbest = p_rbuf->r_score;
8165 X      t_rescore = p_rbuf->r_escore;
8166 X    }
8167 X
8168 X    /* statistics done for best score of set */
8169 X
8170 X
8171 X    if (p_rbuf->frame == m_msg.nitt1) {
8172 X      if (nstats < MAXSTATS ) {
8173 X       stats[nstats].n1 = t_n1;
8174 X       stats[nstats].comp = p_rbuf->rst.comp;
8175 X       stats[nstats].H = p_rbuf->rst.H;
8176 X       if (pst.zsflag >= 10) {
8177 X         tm_best = t_rbest;
8178 X         tm_escore = t_rescore;
8179 X         t_rbest = -1;
8180 X         t_rescore = FLT_MAX;
8181 X       }
8182 X       stats[nstats].escore  = tm_escore;
8183 X       stats[nstats++].score = tm_best;
8184 X       t_best = -1;
8185 X       tm_escore = FLT_MAX;
8186 X      }
8187 X      else if (pst.zsflag > 0) {
8188 X       if (!stats_done) {
8189 X         pst.zsflag_f = process_hist(stats,nstats,m_msg,pst,
8190 X                                     histp, pstat_voidp,0);
8191 X         kstats = nstats;
8192 X         stats_done = 1;
8193 X         for (i=0; i<MAXBEST; i++) {
8194 X           bestp_arr[i]->zscore = 
8195 X             (*find_zp)(bestp_arr[i]->score[pst.score_ix],
8196 X                        bestp_arr[i]->escore, bestp_arr[i]->n1,
8197 X                        bestp_arr[i]->comp, *pstat_voidp);
8198 X         }
8199 X       }
8200 #ifdef SAMP_STATS
8201 X       else {
8202 X         if (!m_msg.escore_flg) {
8203 X           jstats = nrand(++kstats);
8204 X           if (jstats < MAXSTATS) {
8205 X             stats[jstats].n1 = t_n1;
8206 X             stats[jstats].comp = p_rbuf->rst.comp;
8207 X             stats[jstats].H = p_rbuf->rst.H;
8208 X             if (pst.zsflag >= 10) {
8209 X               tm_best = t_rbest;
8210 X             }
8211 X             stats[jstats].score = tm_best;
8212 X           }
8213 X         }
8214 X       }
8215 #endif
8216 X      }
8217 X    }
8218 X
8219 X    /* best saved for every score */
8220 X    if (stats_done) {
8221 X
8222 X      zscore=(*find_zp)(i_score, e_score, p_rbuf->n1,(double)p_rbuf->rst.comp,
8223 X                       *pstat_voidp);
8224 X
8225 X      if (p_rbuf->frame == m_msg.nitt1) {
8226 X       addhistz((*find_zp)(t_best, tm_escore, p_rbuf->n1, (double) p_rbuf->rst.comp,
8227 X                           *pstat_voidp), histp);
8228 X       t_best = t_rbest = -1;
8229 X       tm_escore = t_rescore = FLT_MAX;
8230 X      }
8231 X    }
8232 X    else zscore = (double) i_score;
8233 X
8234 #ifndef PRSS
8235 X    if (zscore > zbestcut) {
8236 X      if (nbest >= MAXBEST) {
8237 X       bestfull = nbest-MAXBEST/4;
8238 X       selectbestz(bestp_arr,bestfull-1,nbest);
8239 X       zbestcut = bestp_arr[bestfull-1]->zscore;
8240 X       nbest = bestfull;
8241 X      }
8242 X      bestp = bestp_arr[nbest++];
8243 X      bestp->score[0] = p_rbuf->rst.score[0];
8244 X      bestp->score[1] = p_rbuf->rst.score[1];
8245 X      bestp->score[2] = p_rbuf->rst.score[2];
8246 X      bestp->comp = (double) p_rbuf->rst.comp;
8247 X      bestp->H = (double) p_rbuf->rst.H;
8248 X      bestp->escore = p_rbuf->rst.escore;
8249 X      bestp->segnum = p_rbuf->rst.segnum;
8250 X      bestp->seglen = p_rbuf->rst.seglen;
8251 X      bestp->zscore = zscore;
8252 X      bestp->lseek = p_rbuf->lseek;
8253 X      memcpy(bestp->libstr,p_rbuf->libstr,MAX_UID);
8254 X      bestp->cont = p_rbuf->cont; /* not cont+1 because incremented already */
8255 X      bestp->m_file_p = p_rbuf->m_file_p;
8256 X      bestp->n1 = p_rbuf->n1;
8257 X      bestp->n1tot_p = p_rbuf->n1tot_p;
8258 X      bestp->frame = p_rbuf->frame;
8259 X      bestp->nsfnum = p_rbuf->nsfnum;
8260 #ifdef SUPERFAMNUM
8261 X      if ((bestp->sfnum[0] = p_rbuf->sfnum[0])>0 &&
8262 X         (bestp->sfnum[1] = p_rbuf->sfnum[1])>0 &&
8263 X         (bestp->sfnum[2] = p_rbuf->sfnum[2])>0 &&
8264 X         (bestp->sfnum[3] = p_rbuf->sfnum[3])>0 &&
8265 X         (bestp->sfnum[4] = p_rbuf->sfnum[4])>0 &&
8266 X         (bestp->sfnum[5] = p_rbuf->sfnum[5])>0 &&
8267 X         (bestp->sfnum[6] = p_rbuf->sfnum[6])>0 &&
8268 X         (bestp->sfnum[7] = p_rbuf->sfnum[7])>0 &&
8269 X         (bestp->sfnum[8] = p_rbuf->sfnum[8])>0 &&
8270 X         (bestp->sfnum[9] = p_rbuf->sfnum[9])>0) ;
8271 #endif
8272 X    }
8273 #endif
8274 X  }
8275 }
8276 #endif
8277 SHAR_EOF
8278 chmod 0644 comp_lib.c ||
8279 echo 'restore of comp_lib.c failed'
8280 Wc_c="`wc -c < 'comp_lib.c'`"
8281 test 55202 -eq "$Wc_c" ||
8282         echo 'comp_lib.c: original size 55202, current size' "$Wc_c"
8283 fi
8284 # ============= compacc.c ==============
8285 if test -f 'compacc.c' -a X"$1" != X"-c"; then
8286         echo 'x - skipping compacc.c (File already exists)'
8287 else
8288 echo 'x - extracting compacc.c (Text)'
8289 sed 's/^X//' << 'SHAR_EOF' > 'compacc.c' &&
8290 X
8291 /* copyright (c) 1996, 1997, 1998, 1999 William R. Pearson and the
8292 X   U. of Virginia */
8293 X
8294 /* $Name: fa_34_26_5 $ - $Id: compacc.c,v 1.61 2007/04/26 18:37:18 wrp Exp $ */
8295 X
8296 /* Concurrent read version */
8297 X
8298 #include <stdio.h>
8299 #include <stdlib.h>
8300 #if defined(UNIX) || defined(WIN32)
8301 #include <sys/types.h>
8302 #endif
8303 X
8304 #include <limits.h>
8305 #include <float.h>
8306 X
8307 #include <string.h>
8308 #include <time.h>
8309 #include <math.h>
8310 X
8311 #include "defs.h"
8312 #include "param.h"
8313 #include "structs.h"
8314 X
8315 #ifndef PCOMPLIB
8316 #include "mw.h"
8317 #else
8318 #include "p_mw.h"
8319 #endif
8320 X
8321 #define XTERNAL
8322 #include "uascii.h"
8323 #include "upam.h"
8324 #undef XTERNAL
8325 X
8326 #ifdef PCOMPLIB
8327 #include "msg.h"
8328 extern int nnodes;
8329 #ifdef PVM_SRC
8330 #include "pvm3.h"
8331 extern int pinums[],hosttid;
8332 #endif
8333 #ifdef MPI_SRC
8334 #include "mpi.h"
8335 #endif
8336 #endif
8337 X
8338 extern time_t tdone, tstart;            /* Timing */
8339 extern void abort ();
8340 extern void ptime ();
8341 X
8342 /* because it is used to pre-allocate space, maxn has various
8343 X   constraints.  For "simple" comparisons, it is simply the length of
8344 X   the longest library sequence.  But for translated comparisons, it
8345 X   must be 3 or 6X the length of the query sequence. 
8346 X
8347 X   In addition, however, it can be reduced to make certain that
8348 X   sequences are read in smaller chunks.  And, maxn affect how large
8349 X   overlaps must be when sequences are read in chunks.
8350 */
8351 X
8352 int
8353 reset_maxn(struct mngmsg *m_msg, int maxn) {
8354 X
8355 X  /* reduce maxn if requested */
8356 X  if (m_msg->maxn > 0 && m_msg->maxn < maxn) maxn = m_msg->maxn;
8357 X
8358 X  if (m_msg->qdnaseq==m_msg->ldnaseq || m_msg->qdnaseq==SEQT_DNA ||
8359 X      m_msg->qdnaseq == SEQT_RNA) {/* !TFAST - either FASTA or FASTX*/
8360 X
8361 X   if (m_msg->n0> m_msg->max_tot/3) {
8362 X      fprintf(stderr," query sequence is too long %d > %d %s\n",
8363 X             m_msg->n0,
8364 X             m_msg->max_tot/3,
8365 X             m_msg->sqnam);
8366 X      exit(1);
8367 X    }
8368 X    m_msg->loff = m_msg->n0;
8369 X    m_msg->maxt3 = maxn-m_msg->loff;
8370 X  }
8371 X  else {       /* is TFAST */
8372 X    if (m_msg->n0 > MAXTST) {
8373 X      fprintf(stderr," query sequence is too long %d %s\n",m_msg->n0,m_msg->sqnam);
8374 X      exit(1);
8375 X    }
8376 X
8377 X    if (m_msg->n0*3 > maxn ) { /* n0*3 for the three frames - this
8378 X                                  will only happen if maxn has been
8379 X                                  set low manually */
8380 X
8381 X      if (m_msg->n0*4+2 < m_msg->max_tot) { /* m_msg0*3 + m_msg0 */
8382 X       fprintf(stderr,
8383 X               " query sequence too long for library segment: %d - resetting to %d\n",
8384 X             maxn,m_msg->n0*3);
8385 X       maxn = m_msg->maxn = m_msg->n0*3;
8386 X      }
8387 X      else {
8388 X       fprintf(stderr," query sequence too long for translated search: %d * 4 > %d %s\n",
8389 X             m_msg->n0,maxn, m_msg->sqnam);
8390 X       exit(1);
8391 X      }
8392 X    }
8393 X
8394 X    /* set up some constants for overlaps */
8395 X    m_msg->loff = 3*m_msg->n0;
8396 X    m_msg->maxt3 = maxn-m_msg->loff-3;
8397 X    m_msg->maxt3 -= m_msg->maxt3%3;
8398 X    m_msg->maxt3++;
8399 X
8400 X    maxn = maxn - 3; maxn -= maxn%3; maxn++;
8401 X  }
8402 X  return maxn;
8403 }
8404 X
8405 X
8406 int
8407 scanseq(unsigned char *seq, int n, char *str) {
8408 X  int tot,i;
8409 X  char aaray[128];             /* this must be set > nsq */
8410 X       
8411 X  for (i=0; i<128; i++)  aaray[i]=0;
8412 X  for (i=0; (size_t)i < strlen(str); i++) aaray[qascii[str[i]]]=1;
8413 X  for (i=tot=0; i<n; i++) tot += aaray[seq[i]];
8414 X  return tot;
8415 }
8416 X
8417 /* subs_env takes a string, possibly with ${ENV}, and looks up all the
8418 X   potential environment variables and substitutes them into the
8419 X   string */
8420 X
8421 void subs_env(char *dest, char *src, int dest_size) {
8422 X  char *last_src, *bp, *bp1;
8423 X
8424 X  last_src = src;
8425 X
8426 X  if ((bp = strchr(src,'$'))==NULL) {
8427 X    strncpy(dest, src, dest_size);
8428 X    dest[dest_size-1] = '\0';
8429 X  }
8430 X  else {
8431 X    *dest = '\0';
8432 X    while (strlen(dest) < dest_size-1 && bp != NULL ) {
8433 X      /* copy stuff before ${*/
8434 X      *bp = '\0';
8435 X      strncpy(dest, last_src, dest_size);
8436 X      *bp = '$';
8437 X
8438 X      /* copy ENV */
8439 X      if (*(bp+1) != '{') {
8440 X       strncat(dest, "$", dest_size - strlen(dest) -1);
8441 X       dest[dest_size-1] = '\0';
8442 X       bp += 1;
8443 X      }
8444 X      else {   /* have  ${ENV} - put it in */
8445 X       if ((bp1 = strchr(bp+2,'}'))==NULL) {
8446 X         fprintf(stderr, "Unterminated ENV: %s\n",src);
8447 X         break;
8448 X       }
8449 X       else {
8450 X         *bp1 = '\0';
8451 X         if (getenv(bp+2)!=NULL) {
8452 X           strncat(dest, getenv(bp+2), dest_size - strlen(dest) - 1);
8453 X           dest[dest_size-1] = '\0';
8454 X           *bp1 = '}';
8455 X         }
8456 X         bp = bp1+1;   /* bump bp even if getenv == NULL */
8457 X       }
8458 X      }
8459 X      last_src = bp;
8460 X
8461 X      /* now get the next ${ENV} if present */
8462 X      bp = strchr(last_src,'$');
8463 X    }
8464 X    /* now copy the last stuff */
8465 X    strncat(dest, last_src, dest_size - strlen(dest) - 1);
8466 X    dest[dest_size-1]='\0';
8467 X  }
8468 }
8469 X
8470 X
8471 void selectbest(bptr,k,n)       /* k is rank in array */
8472 X     struct beststr **bptr;
8473 X     int k,n;
8474 {
8475 X  int v, i, j, l, r;
8476 X  struct beststr *tmptr;
8477 X
8478 X  l=0; r=n-1;
8479 X
8480 X  while ( r > l ) {
8481 X    v = bptr[r]->score[0];
8482 X    i = l-1;
8483 X    j = r;
8484 X    do {
8485 X      while (bptr[++i]->score[0] > v) ;
8486 X      while (bptr[--j]->score[0] < v) ;
8487 X      tmptr = bptr[i]; bptr[i]=bptr[j]; bptr[j]=tmptr;
8488 X    } while (j > i);
8489 X    bptr[j]=bptr[i]; bptr[i]=bptr[r]; bptr[r]=tmptr;
8490 X    if (i>=k) r = i-1;
8491 X    if (i<=k) l = i+1;
8492 X  }
8493 }
8494 X
8495 void selectbestz(bptr,k,n)      /* k is rank in array */
8496 X     struct beststr **bptr;
8497 X     int k,n;
8498 {
8499 X  int i, j, l, r;
8500 X  struct beststr *tmptr;
8501 X  double v;
8502 X
8503 X  l=0; r=n-1;
8504 X
8505 X  while ( r > l ) {
8506 X    v = bptr[r]->zscore;
8507 X    i = l-1;
8508 X    j = r;
8509 X    do {
8510 X      while (bptr[++i]->zscore > v) ;
8511 X      while (bptr[--j]->zscore < v) ;
8512 X      tmptr = bptr[i]; bptr[i]=bptr[j]; bptr[j]=tmptr;
8513 X    } while (j > i);
8514 X    bptr[j]=bptr[i]; bptr[i]=bptr[r]; bptr[r]=tmptr;
8515 X    if (i>=k) r = i-1;
8516 X    if (i<=k) l = i+1;
8517 X  }
8518 }
8519 X
8520 /* improved shellsort with high-performance increments */
8521 /*
8522 shellsort(itemType a[], int l, int r)
8523 { int i, j, k, h; itemType v;
8524 X int incs[16] = { 1391376, 463792, 198768, 86961, 33936,
8525 X                 13776, 4592, 1968, 861, 336, 
8526 X                 112, 48, 21, 7, 3, 1 };
8527 X for ( k = 0; k < 16; k++)
8528 X   for (h = incs[k], i = l+h; i <= r; i++)
8529 X     { 
8530 X       v = a[i]; j = i;
8531 X       while (j > h && a[j-h] > v)
8532 X        { a[j] = a[j-h]; j -= h; }
8533 X       a[j] = v; 
8534 X     } 
8535 }
8536 */
8537 X
8538 /* ?improved? version of sortbestz using optimal increments and fewer
8539 X   exchanges */
8540 void sortbestz(struct beststr **bptr, int nbest)
8541 {
8542 X  int gap, i, j, k;
8543 X  struct beststr *tmp;
8544 X  double v;
8545 X  int incs[16] = { 1391376, 463792, 198768, 86961, 33936,
8546 X                  13776, 4592, 1968, 861, 336, 
8547 X                  112, 48, 21, 7, 3, 1 };
8548 X
8549 X  for ( k = 0; k < 16; k++) {
8550 X    gap = incs[k];
8551 X    for (i=gap; i < nbest; i++) {
8552 X      tmp = bptr[i];
8553 X      j = i;
8554 X      v = bptr[i]->zscore;
8555 X      while ( j >= gap && bptr[j-gap]->zscore < v) {
8556 X       bptr[j] = bptr[j - gap];
8557 X       j -= gap;
8558 X      }
8559 X      bptr[j] = tmp;
8560 X    }
8561 X  }
8562 }
8563 X
8564 X
8565 void sortbeste(struct beststr **bptr, int nbest)
8566 {
8567 X  int gap, i, j, k;
8568 X  struct beststr *tmp;
8569 X  double v;
8570 X  int incs[16] = { 1391376, 463792, 198768, 86961, 33936,
8571 X                  13776, 4592, 1968, 861, 336, 
8572 X                  112, 48, 21, 7, 3, 1 };
8573 X
8574 X  for ( k = 0; k < 16; k++) {
8575 X    gap = incs[k]; 
8576 X    for (i=gap; i < nbest; i++) {
8577 X      j = i;
8578 X      tmp = bptr[i];
8579 X      v = tmp->escore;
8580 X      while ( j >= gap && bptr[j-gap]->escore > v) {
8581 X       bptr[j] = bptr[j - gap];
8582 X       j -= gap;
8583 X      }
8584 X      bptr[j] = tmp;
8585 X    }
8586 X  }
8587 X
8588 X  /* sometimes there are many high scores with E()==0.0, sort
8589 X     those by z() score */
8590 X
8591 X  j = 0;
8592 X  while (j < nbest && bptr[j]->escore <= 2.0*DBL_MIN ) {j++;}
8593 X  if (j > 1) sortbestz(bptr,j);
8594 }
8595 X
8596 extern double zs_to_Ec(double zs, long entries);
8597 X
8598 /*
8599 extern double ks_dev;
8600 extern int ks_df; */
8601 extern char hstring1[];
8602 X
8603 void
8604 prhist(FILE *fd, struct mngmsg m_msg,
8605 X       struct pstruct pst, 
8606 X       struct hist_str hist, 
8607 X       int nstats,
8608 X       struct db_str ntt,
8609 X       char *gstring2)
8610 {
8611 X  int i,j,hl,hll, el, ell, ev;
8612 X  char hline[80], pch, *bp;
8613 X  int mh1, mht;
8614 X  int maxval, maxvalt, dotsiz, ddotsiz,doinset;
8615 X  double cur_e, prev_e, f_int;
8616 X  double max_dev, x_tmp;
8617 X  double db_tt;
8618 X  int n_chi_sq, cum_hl=0, max_i;
8619 X
8620 X
8621 X  fprintf(fd,"\n");
8622 X  
8623 X  if (pst.zsflag_f < 0) {
8624 X    fprintf(fd, "%7ld residues in %5ld sequences\n", ntt.length,ntt.entries);
8625 X    fprintf(fd,"\n%s\n",gstring2);
8626 X    return;
8627 X  }
8628 X
8629 X  if (nstats > 20) { 
8630 X    max_dev = 0.0;
8631 X    mh1 = hist.maxh-1;
8632 X    mht = (3*hist.maxh-3)/4 - 1;
8633 X
8634 X    if (!m_msg.nohist && mh1 > 0) {
8635 X      for (i=0,maxval=0,maxvalt=0; i<hist.maxh; i++) {
8636 X       if (hist.hist_a[i] > maxval) maxval = hist.hist_a[i];
8637 X       if (i >= mht &&  hist.hist_a[i]>maxvalt) maxvalt = hist.hist_a[i];
8638 X      }
8639 X      n_chi_sq = 0;
8640 X      cum_hl = -hist.hist_a[0];
8641 X      dotsiz = (maxval-1)/60+1;
8642 X      ddotsiz = (maxvalt-1)/50+1;
8643 X      doinset = (ddotsiz < dotsiz && dotsiz > 2);
8644 X
8645 X      if (pst.zsflag_f>=0)
8646 X       fprintf(fd,"       opt      E()\n");
8647 X      else 
8648 X       fprintf(fd,"     opt\n");
8649 X
8650 X      prev_e =  zs_to_Ec((double)(hist.min_hist-hist.histint/2),hist.entries);
8651 X      for (i=0; i<=mh1; i++) {
8652 X       pch = (i==mh1) ? '>' : ' ';
8653 X       pch = (i==0) ? '<' : pch;
8654 X       hll = hl = hist.hist_a[i];
8655 X       if (pst.zsflag_f>=0) {
8656 X         cum_hl += hl;
8657 X         f_int = (double)(i*hist.histint+hist.min_hist)+(double)hist.histint/2.0;
8658 X         cur_e = zs_to_Ec(f_int,hist.entries);
8659 X         ev = el = ell = (int)(cur_e - prev_e + 0.5);
8660 X         if (hl > 0  && i > 5 && i < (90-hist.min_hist)/hist.histint) {
8661 X           x_tmp  = fabs(cum_hl - cur_e);
8662 X           if ( x_tmp > max_dev) {
8663 X             max_dev = x_tmp;
8664 X             max_i = i;
8665 X           }
8666 X           n_chi_sq++;
8667 X         }
8668 X         if ((el=(el+dotsiz-1)/dotsiz) > 60) el = 60;
8669 X         if ((ell=(ell+ddotsiz-1)/ddotsiz) > 40) ell = 40;
8670 X         fprintf(fd,"%c%3d %5d %5d:",
8671 X                 pch,(i<mh1)?(i)*hist.histint+hist.min_hist :
8672 X                 mh1*hist.histint+hist.min_hist,hl,ev);
8673 X       }
8674 X       else fprintf(fd,"%c%3d %5d :",
8675 X                    pch,(i<mh1)?(i)*hist.histint+hist.min_hist :
8676 X                    mh1*hist.histint+hist.min_hist,hl);
8677 X
8678 X       if ((hl=(hl+dotsiz-1)/dotsiz) > 60) hl = 60;
8679 X       if ((hll=(hll+ddotsiz-1)/ddotsiz) > 40) hll = 40;
8680 X       for (j=0; j<hl; j++) hline[j]='='; 
8681 X       if (pst.zsflag_f>=0) {
8682 X         if (el <= hl ) {
8683 X           if (el > 0) hline[el-1]='*';
8684 X           hline[hl]='\0';
8685 X         }
8686 X         else {
8687 X           for (j = hl; j < el; j++) hline[j]=' ';
8688 X           hline[el-1]='*';
8689 X           hline[hl=el]='\0';
8690 X         }
8691 X       }
8692 X       else hline[hl] = 0;
8693 X       if (i==1) {
8694 X         for (j=hl; j<10; j++) hline[j]=' ';
8695 X         sprintf(&hline[10]," one = represents %d library sequences",dotsiz);
8696 X       }
8697 X       if (doinset && i == mht-2) {
8698 X         for (j = hl; j < 10; j++) hline[j]=' ';
8699 X         sprintf(&hline[10]," inset = represents %d library sequences",ddotsiz);
8700 X       }
8701 X       if (i >= mht&& doinset ) {
8702 X         for (j = hl; j < 10; j++) hline[j]=' ';
8703 X         hline[10]=':';
8704 X         for (j = 11; j<11+hll; j++) hline[j]='=';
8705 X         hline[11+hll]='\0';
8706 X         if (pst.zsflag_f>=0) {
8707 X           if (ell <= hll) hline[10+ell]='*';
8708 X           else {
8709 X             for (j = 11+hll; j < 10+ell; j++) hline[j]=' ';
8710 X             hline[10+ell] = '*';
8711 X             hline[11+ell] = '\0';
8712 X           }
8713 X         }
8714 X       }
8715 X
8716 X       fprintf(fd,"%s\n",hline);
8717 X       prev_e = cur_e;
8718 X      }
8719 X    }
8720 X  }
8721 X
8722 X  if (ntt.carry==0) {
8723 X    fprintf(fd, "%7ld residues in %5ld sequences\n", ntt.length, ntt.entries);
8724 X  }
8725 X  else {
8726 X    db_tt = (double)ntt.carry*(double)LONG_MAX + (double)ntt.length;
8727 X    fprintf(fd, "%.0f residues in %5ld library sequences\n", db_tt, ntt.entries);
8728 X  }
8729 X
8730 X  if (pst.zsflag_f>=0) {
8731 X    if (MAXSTATS < hist.entries)
8732 #ifdef SAMP_STATS
8733 X      fprintf(fd," statistics sampled from %d to %ld sequences\n",
8734 X             MAXSTATS,hist.entries);
8735 #else
8736 X      fprintf(fd," statistics extrapolated from %d to %ld sequences\n",
8737 X             MAXSTATS,hist.entries);
8738 #endif
8739 X    /*    summ_stats(stat_info); */
8740 X    fprintf(fd," %s\n",hist.stat_info);
8741 X    if (!m_msg.nohist && cum_hl > 0)
8742 X      fprintf(fd," Kolmogorov-Smirnov  statistic: %6.4f (N=%d) at %3d\n",
8743 X             max_dev/(float)cum_hl, n_chi_sq,max_i*hist.histint+hist.min_hist);
8744 X    if (m_msg.markx & MX_M10FORM) {
8745 X      while ((bp=strchr(hist.stat_info,'\n'))!=NULL) *bp=' ';
8746 X      if (cum_hl <= 0) cum_hl = -1;
8747 X      sprintf(hstring1,"; mp_extrap: %d %ld\n; mp_stats: %s\n; mp_KS: %6.4f (N=%d) at %3d\n",
8748 X             MAXSTATS,hist.entries,hist.stat_info,max_dev/(float)cum_hl, n_chi_sq,max_i*hist.histint+hist.min_hist);
8749 X    }
8750 X  }
8751 X  fprintf(fd,"\n%s\n",gstring2);
8752 X  fflush(fd);
8753 }
8754 X
8755 extern char prog_name[], *verstr;
8756 X
8757 void s_abort (char *p,  char *p1)
8758 {
8759 X  int i;
8760 X
8761 X  fprintf (stderr, "\n***[%s] %s%s***\n", prog_name, p, p1);
8762 #ifdef PCOMPLIB
8763 #ifdef PVM_SRC
8764 X  for (i=FIRSTNODE; i< nnodes; i++) pvm_kill(pinums[i]);
8765 X  pvm_exit();
8766 #endif
8767 #ifdef MPI_SRC
8768 X  MPI_Abort(MPI_COMM_WORLD,1);
8769 X  MPI_Finalize();
8770 #endif
8771 #endif
8772 X  exit (1);
8773 }
8774 X
8775 #ifndef MPI_SRC
8776 void w_abort (char *p, char *p1)
8777 {
8778 X  fprintf (stderr, "\n***[%s] %s%s***\n\n", prog_name, p, p1);
8779 X  exit (1);
8780 }
8781 #endif
8782 X
8783 #ifndef PCOMPLIB
8784 /* copies from from to to shuffling */
8785 X
8786 extern int nrand(int);
8787 X
8788 void
8789 shuffle(unsigned char *from, unsigned char *to, int n)
8790 {
8791 X  int i,j; unsigned char tmp;
8792 X
8793 X  if (from != to) memcpy((void *)to,(void *)from,n);
8794 X
8795 X  for (i=n; i>0; i--) {
8796 X    j = nrand(i);
8797 X    tmp = to[j];
8798 X    to[j] = to[i-1];
8799 X    to[i-1] = tmp;
8800 X  }
8801 X  to[n] = 0;
8802 }
8803 X
8804 /* copies from from to from shuffling, ieven changed for threads */
8805 void
8806 wshuffle(unsigned char *from, unsigned char *to, int n, int wsiz, int *ieven)
8807 {
8808 X  int i,j, k, mm; 
8809 X  unsigned char tmp, *top;
8810 X
8811 X  memcpy((void *)to,(void *)from,n);
8812 X       
8813 X  mm = n%wsiz;
8814 X
8815 X  if (*ieven) {
8816 X    for (k=0; k<(n-wsiz); k += wsiz) {
8817 X      top = &to[k];
8818 X      for (i=wsiz; i>0; i--) {
8819 X       j = nrand(i);
8820 X       tmp = top[j];
8821 X       top[j] = top[i-1];
8822 X       top[i-1] = tmp;
8823 X      }
8824 X    }
8825 X    top = &to[n-mm];
8826 X    for (i=mm; i>0; i--) {
8827 X      j = nrand(i);
8828 X      tmp = top[j];
8829 X      top[j] = top[i-1];
8830 X      top[i-1] = tmp;
8831 X    }
8832 X    *ieven = 0;
8833 X  }
8834 X  else {
8835 X    for (k=n; k>=wsiz; k -= wsiz) {
8836 X      top = &to[k-wsiz];
8837 X      for (i=wsiz; i>0; i--) {
8838 X       j = nrand(i);
8839 X       tmp = top[j];
8840 X       top[j] = top[i-1];
8841 X       top[i-1] = tmp;
8842 X      }
8843 X    }
8844 X    top = &to[0];
8845 X    for (i=mm; i>0; i--) {
8846 X      j = nrand(i);
8847 X      tmp = top[j];
8848 X      top[j] = top[i-1];
8849 X      top[i-1] = tmp;
8850 X    }
8851 X    *ieven = 1;
8852 X  }
8853 X  to[n] = 0;
8854 }
8855 X
8856 #endif
8857 X
8858 int
8859 sfn_cmp(int *q, int *s)
8860 {
8861 X  if (*q == *s) return *q;
8862 X  while (*q && *s) {
8863 X    if (*q == *s) return *q;
8864 X    else if (*q < *s) q++;
8865 X    else if (*q > *s) s++;
8866 X  }
8867 X  return 0;
8868 }
8869 X
8870 #ifndef MPI_SRC
8871 X
8872 #define ESS 49
8873 X
8874 void
8875 revcomp(unsigned char *seq, int n, int *c_nt)
8876 {
8877 X  unsigned char tmp;
8878 X  int i, ni;
8879 X
8880 X  for (i=0, ni = n-1; i< n/2; i++,ni--) {
8881 X    tmp = c_nt[seq[i]];
8882 X    seq[i] = c_nt[seq[ni]];
8883 X    seq[ni] = tmp;
8884 X  }
8885 X  if ((n%2)==1) {
8886 X    i = n/2;
8887 X    seq[i] = c_nt[seq[i]];
8888 X  }
8889 X  seq[n]=0;
8890 }
8891 #endif
8892 X
8893 #ifdef PCOMPLIB
8894 X
8895 /* init_stage2 sets up the data structures necessary to send a subset
8896 X   of sequences to the nodes, and then collects the results
8897 */
8898 X
8899 /* wstage2[] FIRSTNODE .. nnodes has the next sequence to be do_opt()/do_walign()ed */
8900 /* wstage2p[] is a list of sequence numbers/frames, to be sent to workers */
8901 /* wstage2b[] is a list of bptr's that shares the index with wstage2p[] */
8902 X
8903 static int  wstage2[MAXWRKR +1];        /* count of second stage scores */
8904 static struct stage2_str  *wstage2p[MAXWRKR+1]; /* list of second stage sequences */
8905 static int  wstage2i[MAXWRKR+1];        /* index into second stage sequences */
8906 static struct beststr *bbptr,
8907 X     **wstage2b[MAXWRKR+1];    /* reverse pointers to bestr */
8908 X
8909 void
8910 do_stage2(struct beststr **bptr, int nbest, struct mngmsg m_msg0,
8911 X         int s_func, struct qmng_str *qm_msp) {
8912 X
8913 X  int i, is, ib, iw, nres;
8914 X  int node, snode, node_done;
8915 X  int bufid, numt, tid;
8916 X  char errstr[120];
8917 X  struct comstr2 bestr2[BFR2+1];       /* temporary structure array */
8918 X  char *seqc_buff, *seqc;
8919 X  int seqc_buff_len, aln_code_n;
8920 #ifdef MPI_SRC
8921 X  MPI_Status mpi_status;
8922 #endif
8923 X
8924 X  /* initialize the counter for each worker to 0 */
8925 X  for (iw = FIRSTNODE; iw < nnodes; iw++) wstage2[iw] = 0;
8926 X
8927 X  /* for each result, bump the counter for the worker that has
8928 X     the sequence */
8929 X  for (ib = 0; ib < nbest; ib++ ) { wstage2[bptr[ib]->wrkr]++;  }
8930 X
8931 X  /* now allocate enough space to send each worker a 
8932 X     list of its sequences stage2_str {seqnm, frame} */
8933 X  for (iw = FIRSTNODE; iw < nnodes; iw++) {
8934 X    if (wstage2[iw]>0) {
8935 X      if ((wstage2p[iw]=
8936 X          (struct stage2_str *)
8937 X          calloc(wstage2[iw],sizeof(struct stage2_str)))==NULL) {
8938 X       sprintf(errstr," cannot allocate sequence listp %d %d",
8939 X               iw,wstage2[iw]);
8940 X       s_abort(errstr,"");
8941 X      }
8942 X
8943 X      /* allocate space to remember the bptr's for each result */
8944 X      if ((wstage2b[iw]=(struct beststr **)
8945 X          calloc(wstage2[iw],sizeof(struct beststr *)))==NULL) {
8946 X       sprintf(errstr," cannot allocate sequence listb %d %d",
8947 X               iw,wstage2[iw]);
8948 X       s_abort(errstr,"");
8949 X      }
8950 X      wstage2i[iw]=0;
8951 X    }
8952 X    else {
8953 X      wstage2p[iw] = NULL;
8954 X      wstage2b[iw] = NULL;
8955 X    }
8956 X  }
8957 X
8958 X  /* for each result, set wstage2p[worker][result_index_in_worker] */
8959 X  for (is = 0; is < nbest; is++) {
8960 X    iw=bptr[is]->wrkr;
8961 X    wstage2p[iw][wstage2i[iw]].seqnm = bptr[is]->seqnm;
8962 X    wstage2p[iw][wstage2i[iw]].frame = bptr[is]->frame;
8963 X    wstage2b[iw][wstage2i[iw]] = bptr[is];
8964 X    wstage2i[iw]++;
8965 X  }
8966 X
8967 X
8968 X  /* at this point, wstage2i[iw] should equal wstage2[iw] */
8969 X  node_done = 0;
8970 X  for (node = FIRSTNODE; node < nnodes; node++) {
8971 X
8972 X    /*    fprintf(stderr,"node: %d stage2: %d\n",node,wstage2[node]); */
8973 X
8974 X    /* if a worker has no results, move on */
8975 X    if (wstage2[node]<=0) { node_done++; continue;}
8976 X
8977 X    qm_msp->slist = wstage2[node];     /* set number of results to return */
8978 X    qm_msp->s_func = s_func;           /* set s_funct for do_opt/do_walign */
8979 #ifdef PVM_SRC
8980 X    pvm_initsend(PvmDataRaw);
8981 X    pvm_pkbyte((char *)qm_msp,sizeof(struct qmng_str),1);
8982 X    pvm_send(pinums[node],MSEQTYPE);   /* send qm_msp */
8983 X    pvm_initsend(PvmDataRaw);  /* send the list of seqnm/frame */
8984 X    pvm_pkbyte((char *)wstage2p[node],wstage2[node]*sizeof(struct stage2_str),1);
8985 X    pvm_send(pinums[node],LISTTYPE);
8986 #endif
8987 #ifdef MPI_SRC
8988 X    MPI_Send(qm_msp,sizeof(struct qmng_str),MPI_BYTE,node,MSEQTYPE,
8989 X            MPI_COMM_WORLD);
8990 X    MPI_Send((char *)wstage2p[node],wstage2[node]*
8991 X            sizeof(struct stage2_str),MPI_BYTE,node,LISTTYPE,
8992 X            MPI_COMM_WORLD);
8993 #endif
8994 X  }
8995 X       
8996 X  /* all the workers have their list of sequences */
8997 X  /* reset the index of results to obtain */
8998 X  for (iw = 0; iw < nnodes; iw++) wstage2i[iw]=0;
8999 X       
9000 X  while (node_done < nnodes-FIRSTNODE) {
9001 #ifdef PVM_SRC
9002 X    bufid = pvm_recv(-1,LISTRTYPE);    /* wait for results */
9003 X    pvm_bufinfo(bufid,NULL,NULL,&tid);
9004 X    /* get a chunk of comstr2 results */
9005 X    pvm_upkbyte((char *)&bestr2[0],sizeof(struct comstr2)*(BFR2+1),1);
9006 X    snode = (iw=tidtonode(tid));
9007 X    pvm_freebuf(bufid);
9008 #endif
9009 #ifdef MPI_SRC
9010 X    MPI_Recv((char *)&bestr2[0],sizeof(struct comstr2)*(BFR2+1),
9011 X            MPI_BYTE,MPI_ANY_SOURCE,LISTRTYPE,MPI_COMM_WORLD,
9012 X            &mpi_status);
9013 X    snode = mpi_status.MPI_SOURCE;
9014 X    iw = snode;
9015 #endif
9016 X
9017 X    seqc_buff = NULL;
9018 X    if (s_func == DO_OPT_FLG && m_msg0.show_code==SHOW_CODE_ALIGN) {
9019 #ifdef PVM_SRC
9020 X      bufid = pvm_recv(tid,CODERTYPE);
9021 X      pvm_upkint(&seqc_buff_len,1,1);  /* get the code string length */
9022 #endif
9023 #ifdef MPI_SRC
9024 X      MPI_Recv((char *)&seqc_buff_len,1,MPI_INT, snode,
9025 X              CODERTYPE,MPI_COMM_WORLD, &mpi_status);
9026 #endif
9027 X
9028 X      seqc=seqc_buff = NULL;
9029 X      if (seqc_buff_len > 0) {         /* allocate space for it */
9030 X       if ((seqc=seqc_buff=calloc(seqc_buff_len,sizeof(char)))==NULL) {
9031 X         fprintf(stderr,"Cannot allocate seqc_buff: %d\n",seqc_buff_len);
9032 X         seqc_buff_len=0;
9033 X       }
9034 X       else {
9035 #ifdef PVM_SRC
9036 X         pvm_upkbyte(seqc_buff,seqc_buff_len*sizeof(char),1);
9037 #endif
9038 #ifdef MPI_SRC
9039 X         MPI_Recv((char *)seqc_buff,seqc_buff_len*sizeof(char),
9040 X                  MPI_BYTE,snode,CODERTYPE,MPI_COMM_WORLD, &mpi_status);
9041 #endif
9042 X       }
9043 X      }
9044 #ifdef PVM_SRC
9045 X      pvm_freebuf(bufid);
9046 #endif
9047 X    }
9048 X
9049 X    /* get number of results in this message */
9050 X    nres = bestr2[BFR2].seqnm & ~FINISHED;
9051 X    /* check to see if finished */
9052 X    if (bestr2[BFR2].seqnm&FINISHED) {node_done++;}
9053 X
9054 X    seqc = seqc_buff;
9055 X
9056 X    /* count through results from a specific worker */
9057 X    for (i=0,is=wstage2i[iw]; i < nres; i++,is++) {
9058 X
9059 X      /* get the (saved) bptr for this result */
9060 X      bbptr=wstage2b[iw][is];
9061 X      /* consistency check seqnm's must agree */
9062 X      if (wstage2p[iw][is].seqnm ==  bbptr->seqnm) {
9063 X       if (s_func == DO_CALC_FLG && m_msg0.last_calc_flg) {
9064 X         bbptr->score[0] = bestr2[i].score[0];
9065 X         bbptr->score[1] = bestr2[i].score[1];
9066 X         bbptr->score[2] = bestr2[i].score[2];
9067 X         bbptr->escore = bestr2[i].escore;
9068 X         bbptr->segnum = bestr2[i].segnum;
9069 X         bbptr->seglen = bestr2[i].seglen;
9070 X       }
9071 X       else if (m_msg0.stages > 1) {
9072 X         bbptr->score[0] = bestr2[i].score[0];
9073 X         bbptr->score[1] = bestr2[i].score[1];
9074 X         bbptr->score[2] = bestr2[i].score[2];
9075 X       }
9076 X
9077 X       if (s_func == DO_OPT_FLG && m_msg0.markx & MX_M9SUMM) {
9078 X         /* get score, alignment information, percents */
9079 X         bbptr->sw_score = bestr2[i].sw_score;
9080 X         memcpy(bbptr->aln_d,&bestr2[i].aln_d,sizeof(struct a_struct));
9081 X         bbptr->percent = bestr2[i].percent;
9082 X         bbptr->gpercent = bestr2[i].gpercent;
9083 X
9084 X         if (m_msg0.show_code == 2) {  /* if show code */
9085 X           /* length of encoding */
9086 X           aln_code_n = bbptr->aln_code_n = bestr2[i].aln_code_n;
9087 X           if (aln_code_n > 0) {
9088 X             if ((bbptr->aln_code = 
9089 X                  (char *)calloc(aln_code_n+1,sizeof(char)))==NULL) {
9090 X               fprintf(stderr,"cannot allocate seq_code[%d:%d]: %d\n",
9091 X                       bbptr->wrkr,bbptr->seqnm,aln_code_n);
9092 X               seqc += aln_code_n+1;
9093 X               bbptr->aln_code_n = 0;
9094 X             }
9095 X             else {
9096 X               strncpy(bbptr->aln_code,seqc,aln_code_n);
9097 X               bbptr->aln_code[aln_code_n]='\0';
9098 X               seqc += aln_code_n+1;
9099 X             }
9100 X           }
9101 X           else {
9102 X             fprintf(stderr," aln_code_n <=0: %d\n",aln_code_n);
9103 X           }
9104 X         }
9105 X       }
9106 X      }
9107 X      else fprintf(stderr,"phase error in phase II return %d %d", iw,i);
9108 X    }
9109 X    if (seqc_buff != NULL) {
9110 X      free(seqc_buff);
9111 X      seqc_buff = NULL;
9112 X    }
9113 X    wstage2i[iw] += nres;
9114 X  }
9115 X
9116 X  for (iw=FIRSTNODE; iw < nnodes; iw++) {
9117 X    if ((void *)wstage2p[iw]!=NULL) free((void *)wstage2p[iw]);
9118 X    if ((void *)wstage2b[iw]!=NULL) free((void *)wstage2b[iw]);
9119 X  }
9120 }
9121 X
9122 #endif
9123 SHAR_EOF
9124 chmod 0644 compacc.c ||
9125 echo 'restore of compacc.c failed'
9126 Wc_c="`wc -c < 'compacc.c'`"
9127 test 21270 -eq "$Wc_c" ||
9128         echo 'compacc.c: original size 21270, current size' "$Wc_c"
9129 fi
9130 # ============= create_seq_demo.sql ==============
9131 if test -f 'create_seq_demo.sql' -a X"$1" != X"-c"; then
9132         echo 'x - skipping create_seq_demo.sql (File already exists)'
9133 else
9134 echo 'x - extracting create_seq_demo.sql (Text)'
9135 sed 's/^X//' << 'SHAR_EOF' > 'create_seq_demo.sql' &&
9136 X
9137 DROP DATABASE seq_demo;
9138 CREATE DATABASE seq_demo;
9139 X
9140 USE seq_demo;
9141 X
9142 CREATE TABLE prot (
9143 id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
9144 seq TEXT NOT NULL,
9145 bin BLOB NOT NULL,
9146 len INT UNSIGNED NOT NULL
9147 );
9148 X
9149 CREATE TABLE annot (
9150 prot_id INT UNSIGNED NOT NULL,
9151 gi INT UNSIGNED NOT NULL PRIMARY KEY,
9152 db ENUM("gb","emb","dbj","prf","ref","pdb","pir","sp") NOT NULL,
9153 descr TEXT NOT NULL,
9154 X
9155 INDEX (prot_id),
9156 INDEX (db)
9157 );
9158 X
9159 CREATE TABLE sp (
9160 X    gi INT UNSIGNED NOT NULL,
9161 X    acc   VARCHAR(10),
9162 X    name  VARCHAR(10),
9163 X
9164 X    PRIMARY KEY (gi)
9165 );
9166 SHAR_EOF
9167 chmod 0644 create_seq_demo.sql ||
9168 echo 'restore of create_seq_demo.sql failed'
9169 Wc_c="`wc -c < 'create_seq_demo.sql'`"
9170 test 536 -eq "$Wc_c" ||
9171         echo 'create_seq_demo.sql: original size 536, current size' "$Wc_c"
9172 fi
9173 # ============= cvs_id ==============
9174 if test -f 'cvs_id' -a X"$1" != X"-c"; then
9175         echo 'x - skipping cvs_id (File already exists)'
9176 else
9177 echo 'x - extracting cvs_id (Text)'
9178 sed 's/^X//' << 'SHAR_EOF' > 'cvs_id' &&
9179 X
9180 /* $Name: fa_34_26_5 $ - $Id: cvs_id,v 1.1.1.1 1999/10/22 20:56:01 wrp Exp $ */
9181 SHAR_EOF
9182 chmod 0644 cvs_id ||
9183 echo 'restore of cvs_id failed'
9184 Wc_c="`wc -c < 'cvs_id'`"
9185 test 81 -eq "$Wc_c" ||
9186         echo 'cvs_id: original size 81, current size' "$Wc_c"
9187 fi
9188 # ============= dec_pthr_subs.c ==============
9189 if test -f 'dec_pthr_subs.c' -a X"$1" != X"-c"; then
9190         echo 'x - skipping dec_pthr_subs.c (File already exists)'
9191 else
9192 echo 'x - extracting dec_pthr_subs.c (Text)'
9193 sed 's/^X//' << 'SHAR_EOF' > 'dec_pthr_subs.c' &&
9194 X
9195 /* copyright (c) 1996, 1997, 1998, 1999 William R. Pearson and the
9196 X   U. of Virginia */
9197 X
9198 /* $Name: fa_34_26_5 $ - $Id: dec_pthr_subs.c,v 1.2 2006/04/12 18:00:02 wrp Exp $ */
9199 X
9200 /* this file isolates the pthreads calls from the main program */
9201 X
9202 #include <stdio.h>
9203 #include <stdlib.h>
9204 #include <string.h>
9205 #include <time.h>
9206 #include <sys/types.h>
9207 #include <signal.h>
9208 X
9209 #include "param.h"
9210 X
9211 #include <pthread.h>
9212 #define XTERNAL
9213 #include "thr.h"
9214 #undef XTERNAL
9215 #include "pthr_subs.h"
9216 X
9217 extern void work_thread (struct thr_str *work_info);
9218 X
9219 /* start the threads working */
9220 X
9221 void init_thr(int nthreads, struct thr_str *work_info)
9222 {
9223 X  int status, i;
9224 X  pthread_attr_t thread_attr;
9225 X
9226 X  if (nthreads > MAX_WORKERS) {
9227 X    fprintf ( stderr," cannot start %d threads, max: %d\n",
9228 X             nthreads, MAX_WORKERS);
9229 X    exit(1);
9230 X  }
9231 X
9232 X  /* mutex and condition variable initialisation */
9233 X
9234 X  status = pthread_mutex_init(&reader_mutex, pthread_mutexattr_default);
9235 X  check(status,"Reader_mutex init bad status\n");
9236 X   
9237 X  status = pthread_mutex_init(&worker_mutex, pthread_mutexattr_default);
9238 X  check(status,"Worker_mutex init bad status\n");
9239 X
9240 X  status = pthread_cond_init(&reader_cond_var, pthread_condattr_default);
9241 X  check(status,"Reader_cond_var init bad status\n");
9242 X
9243 X  status = pthread_cond_init(&worker_cond_var, pthread_condattr_default);
9244 X  check(status,"Worker_cond_var init bad status\n");
9245 X
9246 X  status = pthread_mutex_init(&start_mutex, pthread_mutexattr_default);
9247 X  check(status,"Start_mutex init bad status\n");
9248 X
9249 X  status = pthread_cond_init(&start_cond_var, pthread_condattr_default);
9250 X  check(status,"Start_cond_var init bad status\n");
9251 X
9252 X  /* change stacksize on threads */    /***************************/
9253 X
9254 X  status = pthread_attr_create( &thread_attr );
9255 X  check(status,"attribute create bad status\n");
9256 X
9257 X  status = pthread_attr_setstacksize( &thread_attr, 1000000);
9258 X  check(status,"stacksize change bad status\n");
9259 X
9260 X  /* start the worker threads */
9261 X
9262 X  for (work_info->worker=0; work_info->worker < nthreads;
9263 X       work_info->worker++) {
9264 X    /**********************/
9265 X    status=pthread_create(&threads[work_info->worker],thread_attr,
9266 X                         (pthread_startroutine_t)&work_thread,
9267 X                         (pthread_addr_t)work_info);
9268 X    check(status,"Pthread_create failed\n");
9269 X  }
9270 }
9271 X
9272 void start_thr()
9273 {
9274 X  int status;
9275 X
9276 X  /* tell threads to proceed */
9277 X
9278 X  status = pthread_mutex_lock(&start_mutex);
9279 X  check(status,"Start_mutex lock bad status in main\n");
9280 X
9281 X  start_thread = 0;  /* lower predicate */
9282 X
9283 X  status = pthread_cond_broadcast(&start_cond_var);
9284 X  status = pthread_mutex_unlock(&start_mutex);
9285 X  check(status,"Start_mutex unlock bad status in main\n");
9286 }
9287 X
9288 void get_rbuf(struct buf_head **cur_buf, int max_work_buf)
9289 {
9290 X  int status;
9291 X
9292 X  status = pthread_mutex_lock(&reader_mutex);  /* lock reader_buf structure */
9293 X
9294 X  check(status,"Reader_mutex lock in master bad status\n");
9295 X
9296 X  /* no reader bufs:  wait for signal to proceed */
9297 X  while (num_reader_bufs == 0) {
9298 X    pthread_cond_wait(&reader_cond_var,&reader_mutex);
9299 X  }
9300 X
9301 X  *cur_buf = reader_buf[reader_buf_readp];  /* get the buffer address */
9302 X  reader_buf_readp = (reader_buf_readp+1)%(max_work_buf);  /* increment index */
9303 X  num_reader_bufs--;
9304 X
9305 X  status = pthread_mutex_unlock(&reader_mutex);  /* unlock structure */
9306 X  check(status,"Reader_mutex unlock in master bad status\n");
9307 }
9308 X
9309 void put_rbuf(struct buf_head *cur_buf, int max_work_buf)
9310 {
9311 X  int status;
9312 X
9313 X  /* give the buffer to a thread, and wait for more */
9314 X  status = pthread_mutex_lock(&worker_mutex);  /* lock worker_buf_structure */
9315 X  check(status,"Worker_mutex lock in master bad status\n");
9316 X
9317 X  /*  Put buffer onto available for workers list */
9318 X  worker_buf[worker_buf_readp] = cur_buf;
9319 X  worker_buf_readp = (worker_buf_readp+1)%(max_work_buf);
9320 X  num_worker_bufs++;   /* increment number of buffers available to workers */
9321 X
9322 X  /*  Signal one worker to wake and start work */
9323 X  status = pthread_cond_signal(&worker_cond_var);
9324 X
9325 X  status = pthread_mutex_unlock(&worker_mutex);
9326 X  check(status,"Worker_mutex unlock in master bad status\n"); 
9327 }
9328 X
9329 void put_rbuf_done(int nthreads, struct buf_head *cur_buf, int max_work_buf)
9330 {
9331 X  int status, i;
9332 X  void *exit_value;
9333 X
9334 X  /* give the buffer to a thread, and wait for more */
9335 X  status = pthread_mutex_lock(&worker_mutex);  /* lock worker_buf_structure */
9336 X  check(status,"Worker_mutex lock in master bad status\n");
9337 X
9338 X  /*  Put buffer onto available for workers list */
9339 X  worker_buf[worker_buf_readp] = cur_buf;
9340 X  worker_buf_readp = (worker_buf_readp+1)%(max_work_buf);
9341 X  num_worker_bufs++;   /* increment number of buffers available to workers */
9342 X
9343 X  /*  Signal one worker to wake and start work */
9344 X
9345 X  reader_done = 1;
9346 X  status = pthread_cond_broadcast(&worker_cond_var);
9347 X
9348 X  status = pthread_mutex_unlock(&worker_mutex);
9349 X  check(status,"Worker_mutex unlock in master bad status\n"); 
9350 X
9351 X  /* wait for all buffers available (means all do_workers are done) */
9352
9353 X  for (i=0; i < nthreads; i++) {
9354 X    status = pthread_join( threads[i], &exit_value);
9355 X    check(status,"Pthread_join bad status\n");
9356 X
9357 X    status = pthread_detach( &threads[i]);
9358 X    check(status,"Pthread_detach bad status\n");
9359 X  } 
9360 }
9361 X
9362 void wait_thr()
9363 {
9364 X  int status;
9365 X
9366 X  /* Wait on master to give start signal */
9367 X  status = pthread_mutex_lock(&start_mutex);
9368 X  check(status,"Start_mutex lock bad status in worker\n");
9369 X
9370 X  while (start_thread) {
9371 X         status = pthread_cond_wait(&start_cond_var, &start_mutex);
9372 X         check(status,"Start_cond_wait bad status in worker\n");
9373 X  }
9374 X
9375 X  status = pthread_mutex_unlock(&start_mutex);
9376 X  check(status,"Start_mutex unlock bad status in worker\n");
9377 }
9378 X
9379 int get_wbuf(struct buf_head **cur_buf, int max_work_buf)
9380 {
9381 X  int status;
9382 X
9383 X  /* get a buffer to work on */
9384 X  status = pthread_mutex_lock(&worker_mutex);
9385 X  check(status,"First worker_mutex lock in worker bad status\n");
9386 X
9387 X  /*  No worker_bufs available:  wait for reader to produce some */
9388 X  while (num_worker_bufs == 0) {
9389 X    /*  Exit if reader has finished */
9390 X    if (reader_done) {
9391 X      pthread_mutex_unlock(&worker_mutex);
9392 X      return 0;
9393 X    }
9394 X    pthread_cond_wait(&worker_cond_var,&worker_mutex);
9395 X  } /* end while */
9396 X
9397 X  /*  Get the buffer from list */
9398 X  *cur_buf = worker_buf[worker_buf_workp];
9399 X  worker_buf_workp = (worker_buf_workp+1)%(max_work_buf);
9400 X  num_worker_bufs--;
9401 X
9402 X  status = pthread_mutex_unlock(&worker_mutex);
9403 X  check(status,"First worker_mutex unlock in worker bad status\n");
9404 X  return 1;
9405 }
9406 X
9407 void put_wbuf(struct buf_head *cur_buf, int max_work_buf)
9408 {
9409 X  int status;
9410 X
9411 X  /* put buffer back on list for reader */
9412 X  status = pthread_mutex_lock(&reader_mutex);
9413 X  check(status,"Reader_mutex lock in worker bad status\n");
9414 X    
9415 X  reader_buf[reader_buf_workp] = cur_buf;
9416 X  reader_buf_workp = (reader_buf_workp+1)%(max_work_buf);
9417 X  num_reader_bufs++;
9418 X
9419 X     /* No reader_bufs available:  wake reader */
9420 X  if (num_reader_bufs == 1) {
9421 X    pthread_cond_signal(&reader_cond_var);
9422 X  }
9423 X
9424 X  status = pthread_mutex_unlock(&reader_mutex);
9425 X  check(status,"Reader_mutex unlock in worker bad status\n");
9426 }
9427 SHAR_EOF
9428 chmod 0644 dec_pthr_subs.c ||
9429 echo 'restore of dec_pthr_subs.c failed'
9430 Wc_c="`wc -c < 'dec_pthr_subs.c'`"
9431 test 6955 -eq "$Wc_c" ||
9432         echo 'dec_pthr_subs.c: original size 6955, current size' "$Wc_c"
9433 fi
9434 # ============= dec_pthr_subs.h ==============
9435 if test -f 'dec_pthr_subs.h' -a X"$1" != X"-c"; then
9436         echo 'x - skipping dec_pthr_subs.h (File already exists)'
9437 else
9438 echo 'x - extracting dec_pthr_subs.h (Text)'
9439 sed 's/^X//' << 'SHAR_EOF' > 'dec_pthr_subs.h' &&
9440 X
9441 /* $Name: fa_34_26_5 $ - $Id: dec_pthr_subs.h,v 1.1.1.1 1999/10/22 20:55:59 wrp Exp $ */
9442 X
9443 #include <pthread.h>
9444 X
9445 #define check(status,string) \
9446 X     if (status == -1) perror(string)   /* error macro for thread calls */
9447 X
9448 #ifndef XTERNAL
9449 pthread_t threads[MAX_WORKERS];
9450 X
9451 /* mutex stuff */
9452 X
9453 pthread_mutex_t reader_mutex;      /* empty buffer pointer structure lock */
9454 pthread_mutex_t worker_mutex;      /* full buffer pointer structure lock */
9455 X
9456 /* condition variable stuff */
9457 X
9458 pthread_cond_t reader_cond_var;    /* condition variable for reader */
9459 pthread_cond_t worker_cond_var;    /* condition variable for workers */
9460 X
9461 pthread_mutex_t start_mutex;       /* start-up synchronisation lock */
9462 pthread_cond_t start_cond_var;     /* start-up synchronisation condition variable */
9463 X
9464 extern pthread_t threads[];
9465 X
9466 /* mutex stuff */
9467 X
9468 extern pthread_mutex_t reader_mutex;
9469 extern pthread_mutex_t worker_mutex;
9470 X
9471 /* condition variable stuff */
9472 X
9473 extern pthread_cond_t reader_cond_var;
9474 extern pthread_cond_t worker_cond_var;
9475 X
9476 extern pthread_mutex_t start_mutex;
9477 extern pthread_cond_t start_cond_var;
9478 extern int start_thread;
9479 X
9480 #endif
9481 SHAR_EOF
9482 chmod 0644 dec_pthr_subs.h ||
9483 echo 'restore of dec_pthr_subs.h failed'
9484 Wc_c="`wc -c < 'dec_pthr_subs.h'`"
9485 test 1116 -eq "$Wc_c" ||
9486         echo 'dec_pthr_subs.h: original size 1116, current size' "$Wc_c"
9487 fi
9488 # ============= defs.h ==============
9489 if test -f 'defs.h' -a X"$1" != X"-c"; then
9490         echo 'x - skipping defs.h (File already exists)'
9491 else
9492 echo 'x - extracting defs.h (Text)'
9493 sed 's/^X//' << 'SHAR_EOF' > 'defs.h' &&
9494 /* Concurrent read version */
9495 X
9496 /* $Name: fa_34_26_5 $ - $Id: defs.h,v 1.26 2006/06/22 02:35:05 wrp Exp $ */
9497 X
9498 #ifdef SUNOS
9499 #include <sys/stdtypes.h>
9500 #endif
9501 X
9502 #ifndef IS_BIG_ENDIAN
9503 #if defined(__BIG_ENDIAN__) || defined(_BIG_ENDIAN)
9504 #define IS_BIG_ENDIAN
9505 #else
9506 #undef IS_BIG_ENDIAN
9507 #endif
9508 #endif
9509 X
9510 #if !defined(MAX_WORKERS) && !defined(PCOMPLIB)
9511 #define MAX_WORKERS 1
9512 #endif
9513 X
9514 /* 3-Oct-2003 - we can now have 2 nucleotide query types, DNA
9515 X   and RNA.  pst.dnaseq can also be SEQT_RNA.
9516 X   ldnaseq can only be DNA */
9517 X
9518 #define SEQT_DNA 1
9519 #define SEQT_RNA 3      /* DNA and RNA seqtypes must be odd */
9520 X
9521 #define SEQT_PROT 0
9522 #define SEQT_UNK -1
9523 #define SEQT_OTHER 2
9524 X
9525 #ifndef DEF_NMLEN
9526 #define DEF_NMLEN 6
9527 #endif
9528 X
9529 /* unfortunately, there is an important relationship between MAXTRN and
9530 X   MAXTST+MAXLIB embedded here.  MAXTRN must be >= (MAXTST+MAXLIB)/3
9531 X   or it will be possible for a translated DNA sequence to be longer
9532 X   than the translation space available */
9533 X
9534 #define MAX_STR 512 /* standard label/message buffer */
9535 #define MAX_SSTR 32 /* short string */
9536 #define MAX_FN  120 /* maximum size of a file name */
9537 #define MAX_CH  40 /* maximum number of library choices */
9538 #ifndef SMALLMEM
9539 #define MAX_LF  500 /* maximum numer of library files */
9540 #else
9541 #define MAX_LF  80 /* maximum numer of library files */
9542 #endif
9543 X
9544 /* padding at the end of sequences for ALTIVEC, other vector
9545 X   processors */
9546 #define SEQ_PAD 16
9547 X
9548 #define MAX_UID 20 /* length of libstr, used for character keys with SQL */
9549 X
9550 #define AVE_AA_LEN 400
9551 #define AVE_NT_LEN 5000
9552 #define MAX_AA_BUF 5000         /* 5000 later */
9553 #define MAX_NT_BUF 1000         /* 2000 later */
9554 X
9555 #ifndef SMALLMEM
9556 #define MAXTST  40000           /* longest query */
9557 #define MAXLIB  120000          /* longest library */
9558 #define MAXPLIB 600000          /* longest library with p_comp* */
9559 #define MIN_RES 2000            /* minimum amount allocated for alignment */
9560 #ifndef TFAST
9561 #define MAXTRN  80000           /* buffer for fastx translation */
9562 #else
9563 #define MAXTRN 180000           /* buffer for tfastx translation */
9564 #endif
9565 #define SEQDUP  1200            /* future - overlap */
9566 #ifndef PCOMPLIB
9567 #ifndef MAXBEST
9568 #define MAXBEST 60000   /* max number of best scores */
9569 #endif
9570 #define MAXSTATS 60000
9571 #else
9572 #ifndef MAXBEST
9573 #define MAXBEST 60000   /* max number of best scores */
9574 #endif
9575 #define MAXSTATS 60000
9576 #endif
9577 #define BIGNUM  1000000000
9578 #ifndef MAXINT
9579 #define MAXINT 2147483647
9580 #endif
9581 #define MAXLN   120     /* size of a library name */
9582 #else
9583 #define MAXTST  1500
9584 #define MAXLIB  10000
9585 #define MAXPLIB 100000          /* longest library with p_comp* */
9586 #define MIN_RES 1000
9587 #ifndef TFAST
9588 #define MAXTRN  6000
9589 #else
9590 #define MAXTRN 11500
9591 #endif
9592 #define SEQDUP  300
9593 #define MAXBEST 2000
9594 #define MAXSTATS 20000
9595 #define BIGNUM  32767
9596 #define MAXINT  32767
9597 #define MAXLN   40      /* size of a library name */
9598 #endif
9599 #if !defined(TFAST)
9600 #define MAXTOT (MAXTST+MAXLIB)
9601 #define MAXDIAG (MAXTST+MAXLIB)
9602 #else
9603 #define MAXTOT (MAXTST+MAXTRN)
9604 #define MAXDIAG (MAXTST+MAXTRN)
9605 #endif
9606 X
9607 #define MAXPAM  600     /* maximum allowable size of the pam matrix */
9608 #define PROF_MAX 500
9609 #define ALF_MAX 30
9610 X
9611 #ifdef SUPERFAMNUM
9612 #define NSFCHAR '!'
9613 #endif
9614 X
9615 #define max(a,b) (((a) > (b)) ? (a) : (b))
9616 #define min(a,b) (((a) < (b)) ? (a) : (b))
9617 X
9618 #define MX_ATYPE 7      /* markx==0,1,2 7=> no alignment */
9619 #define MX_ASEP  8      /* markx==3  - separate lines */
9620 #define MX_AMAP  16     /* markx==4,5 - graphic map */
9621 #define MX_HTML  32     /* markx==6  - HTML */
9622 #define MX_M9SUMM 64    /* markx==9(c) */
9623 #define MX_M10FORM 128  /* markx==10 */
9624 X
9625 /* codes for -m 9 */
9626 #define SHOW_CODE_ID    1       /* identity only */
9627 #define SHOW_CODE_ALIGN 2       /* encoded alignment */
9628 SHAR_EOF
9629 chmod 0644 defs.h ||
9630 echo 'restore of defs.h failed'
9631 Wc_c="`wc -c < 'defs.h'`"
9632 test 3530 -eq "$Wc_c" ||
9633         echo 'defs.h: original size 3530, current size' "$Wc_c"
9634 fi
9635 # ============= dna.mat ==============
9636 if test -f 'dna.mat' -a X"$1" != X"-c"; then
9637         echo 'x - skipping dna.mat (File already exists)'
9638 else
9639 echo 'x - extracting dna.mat (Text)'
9640 sed 's/^X//' << 'SHAR_EOF' > 'dna.mat' &&
9641 #  Sample dna matrix
9642 X   A  C  G  T  U  R  Y  M  W  S  K  D  H  V  B  N  X 
9643 A  5 -4 -4 -4 -4  2 -1  2  2 -1 -1  1  1  1 -2 -1 -1
9644 C -4  5 -4 -4 -4 -1  2  2 -1  2 -1 -2  1  1  1 -1 -1
9645 G -4 -4  5 -4 -4  2 -1 -1 -1  2  2  1 -2  1  1 -1 -1
9646 T -4 -4 -4  5  5 -1  2 -1  2 -1  2  1  1 -2  1 -1 -1
9647 U -4 -4 -4  5  5 -1  2 -1  2 -1  2  1  1 -2  1 -1 -1
9648 R  2 -1  2 -1 -1  2 -2 -1  1  1  1  1 -1  1 -1 -1 -1
9649 Y -1  2 -1  2  2 -2  2 -1  1  1  1 -1  1 -1  1 -1 -1
9650 M  2  2 -1 -1 -1 -1 -1  2  1  1 -1 -1  1  1 -1 -1 -1
9651 W  2 -1 -1  2  2  1  1  1  2 -1  1  1  1 -1 -1 -1 -1
9652 S -1  2  2 -1 -1  1  1  1 -1  2  1 -1 -1  1  1 -1 -1
9653 K -1 -1  2  2  2  1  1 -1  1  1  2  1 -1 -1  1 -1 -1
9654 D  1 -2  1  1  1  1 -1 -1  1 -1  1  1 -1 -1 -1 -1 -1
9655 H  1  1 -2  1  1 -1  1  1  1 -1 -1 -1  1 -1 -1 -1 -1
9656 V  1  1  1 -2 -2  1 -1  1 -1  1 -1 -1 -1  1 -1 -1 -1
9657 B -2  1  1  1  1 -1  1 -1 -1  1  1 -1 -1 -1  1 -1 -1
9658 N -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
9659 XX -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
9660 SHAR_EOF
9661 chmod 0644 dna.mat ||
9662 echo 'restore of dna.mat failed'
9663 Wc_c="`wc -c < 'dna.mat'`"
9664 test 976 -eq "$Wc_c" ||
9665         echo 'dna.mat: original size 976, current size' "$Wc_c"
9666 fi
9667 # ============= doinit.c ==============
9668 if test -f 'doinit.c' -a X"$1" != X"-c"; then
9669         echo 'x - skipping doinit.c (File already exists)'
9670 else
9671 echo 'x - extracting doinit.c (Text)'
9672 sed 's/^X//' << 'SHAR_EOF' > 'doinit.c' &&
9673 /*      doinit.c        general and function-specific initializations */
9674 X
9675 /* copyright (c) 1996, 1997, 1998  William R. Pearson and the U. of Virginia */
9676 X
9677 /* $Name: fa_34_26_5 $ - $Id: doinit.c,v 1.62 2007/01/08 15:38:46 wrp Exp $ */
9678 X
9679 /* this file performs general initializations of search parameters
9680 X
9681 X   In addition, it calls several functions in init??.c that provide
9682 X   program-specific initializations:
9683 X
9684 X   f_initenv() - called from initenv()
9685 X   f_getopt()  - called from initenv() during a getopt() scan
9686 X   f_getarg()  - called from initenv() after the getopt() scan
9687 X
9688 */
9689 X
9690 #include <stdio.h>
9691 #include <stdlib.h>
9692 #include <string.h>
9693 X
9694 #include "defs.h"
9695 #include "param.h"
9696 #include "upam.h"       /* required for 'U' option change of nascii */
9697 X
9698 #include "structs.h"
9699 X
9700 #define XTERNAL
9701 #include "uascii.h"
9702 #undef XTERNAL
9703 X
9704 extern char *s_optstr;
9705 extern int optind;              /* used by getopt() */
9706 X
9707 #ifdef PCOMPLIB
9708 #define PARALLEL
9709 #include "p_mw.h"
9710 extern char pgmdir[];
9711 extern char managepgm[];
9712 extern char workerpgm[];
9713 extern int max_buf_cnt;
9714 #define MAX_WORKERS MAXWRKR
9715 #endif
9716 X
9717 char prog_name[MAX_FN];
9718 X
9719 extern void f_initenv(struct mngmsg *, struct pstruct *, unsigned char **);
9720 extern void f_lastenv(struct mngmsg *, struct pstruct *);
9721 extern void f_getopt(char, char *, struct mngmsg *, struct pstruct *);
9722 extern void f_getarg(int, char **, int, struct mngmsg *, struct pstruct *);
9723 void ann_ascii(int *qascii, char *ann_arr);
9724 int set_markx(int markx, int val);
9725 X
9726 int optcnt;
9727 int max_workers=MAX_WORKERS;
9728 #ifdef PCOMPLIB
9729 int worker_1=0;
9730 int worker_n=0;
9731 #endif
9732 extern char *optarg;
9733 X
9734 /* initenv ()  initializes the environment */
9735 void initenv (int argc, char **argv, struct mngmsg *m_msg, 
9736 X                struct pstruct *ppst, unsigned char **aa0)
9737 {
9738 X   char   *cptr, ctmp;
9739 X   int     copt, itmp;
9740 X
9741 X   /* options for all search functions */
9742 X   char   *g_optstr = "ab:BC:d:DE:F:HiIJ:K:l:Lm:M:N:O:QqR:T:v:V:w:W:X:z:Z:";
9743 X   char    optstring[MAX_STR];
9744 X
9745 /*  these initializations will be used by all functions */
9746 X
9747 X   /* prog_name[] is only used for error messages */
9748 X   strncpy(prog_name,argv[0],sizeof(prog_name));
9749 X   prog_name[sizeof(prog_name)-1]='\0';
9750 X
9751 #ifdef PARALLEL
9752 X   if ((cptr = getenv ("MANAGEPGM")) != NULL) strncpy (managepgm, cptr, 120);
9753 X   if ((cptr = getenv ("WORKERPGM")) != NULL) strncpy (workerpgm, cptr, 120);
9754 X   if ((cptr = getenv ("PGMDIR")) != NULL) strncpy (pgmdir, cptr, 120);
9755 #endif
9756 X
9757 X   m_msg->ltitle[0] = '\0';
9758 X
9759 X   if ((cptr=getenv("FASTLIBS"))!=NULL) {
9760 X     strncpy(m_msg->flstr,cptr,MAX_FN);
9761 X     m_msg->flstr[MAX_FN-1] = '\0';
9762 X   }
9763 X   else m_msg->flstr[0]='\0';
9764 X
9765 X   m_msg->hist.hist_a = NULL;
9766 X   m_msg->outfile[0] = '\0';
9767 X   m_msg->ldnaseq = SEQT_PROT; /* library is protein */
9768 X   m_msg->n1_low = 0;
9769 X   m_msg->n1_high = BIGNUM;
9770 X   m_msg->ql_start = 1;        /* start with first query sequence */
9771 X   m_msg->ql_stop = BIGNUM;    /* end with the last query sequence */
9772 X
9773 X   m_msg->pamd1 = MAXSQ;
9774 X   m_msg->pamd2 = MAXSQ;
9775 X
9776 X   m_msg->term_code = 0;
9777 X   ppst->tr_type = 0;
9778 X   ppst->debug_lib = 0;
9779 X   m_msg->nshow = 20;
9780 #if defined(PCOMPLIB)
9781 X   m_msg->nohist = 1;
9782 X   m_msg->mshow = 20;
9783 #else
9784 X   m_msg->nohist = 0;
9785 X   m_msg->mshow = 50;
9786 #endif
9787 X   m_msg->ashow = -1;
9788 X   m_msg->nmlen = DEF_NMLEN;
9789 X   m_msg->z_bits = 1;
9790 X   m_msg->mshow_flg = 0;
9791 X   m_msg->aln.llen = 0;
9792 X   m_msg->aln.llcntx = 30;
9793 X   m_msg->aln.llcntx_flg = 0;
9794 X   m_msg->e_cut = 10.0;
9795 X   m_msg->e_low = 0.0;
9796 X   m_msg->e_cut_set = 0;
9797 X   m_msg->revcomp = 0;
9798 X   m_msg->self = 0;
9799 X   m_msg->long_info = 0;
9800 X   m_msg->maxn = 0;
9801 X   m_msg->dupn = SEQDUP;
9802 X   m_msg->dfile[0] = '\0';
9803 X   m_msg->tname[0] = '\0';
9804 X   m_msg->lname[0] = '\0';
9805 X   m_msg->show_code = 0;
9806 X   m_msg->aln.showall = 0;
9807 X   m_msg->markx = 0;
9808 X   m_msg->sq0off = m_msg->sq1off = 1;
9809 X   strncpy(m_msg->sqnam,"aa",4);
9810 X   strncpy(m_msg->sqtype,"protein",10);
9811 X   m_msg->ann_flg = 0;
9812 X   m_msg->ann_arr[0] = '\0';
9813 X   m_msg->aa0a = NULL;
9814 X   
9815 X   ppst->zsflag = ppst->zsflag_f = 1;
9816 X   ppst->zs_win = 0;
9817 X
9818 X   ppst->zdb_size = -1;
9819 X   ppst->dnaseq = SEQT_PROT;   /* default is protein */
9820 X   ppst->nt_align = 0;
9821 X
9822 X   f_initenv (m_msg, ppst, aa0);
9823 X
9824 X   strncpy (optstring, g_optstr, sizeof (optstring));
9825 X   strncat (optstring, s_optstr, sizeof (optstring));
9826 X
9827 X   while ((copt = getopt (argc, argv, optstring)) != EOF)
9828 X   {
9829 X      if (strchr (g_optstr, copt) != NULL)
9830 X      {
9831 X       switch (copt) {  /* switches for all options */
9832 X       case 'a': m_msg->aln.showall = 1; break;
9833 X       case 'b':
9834 X         if (optarg[0] == '$') {
9835 X           m_msg->mshow = -1;
9836 X           m_msg->e_cut = 10000000.0;
9837 X           break;
9838 X         }
9839 X         else sscanf (optarg, "%d", &m_msg->mshow);
9840 X         m_msg->e_cut = 10000000.0;
9841 X         m_msg->e_cut_set = 1;
9842 X         m_msg->mshow_flg = 1;
9843 X         break;
9844 X       case 'B': m_msg->z_bits = 0; break;
9845 X       case 'C': sscanf(optarg,"%d",&m_msg->nmlen);
9846 X         if (m_msg->nmlen > MAX_UID-1) m_msg->nmlen = MAX_UID-1;
9847 X         break;
9848 X       case 'd': sscanf(optarg,"%d",&m_msg->ashow);
9849 X         if (m_msg->ashow > m_msg->mshow) m_msg->mshow=m_msg->ashow;
9850 X         /* m_msg->ashow_flg = 1; (ashow_flg not in structs.h, not used)*/
9851 X         break;
9852 X       case 'D': ppst->debug_lib = 1;
9853 X         break;
9854 X       case 'E':
9855 X         sscanf(optarg,"%lf",&m_msg->e_cut);
9856 X         m_msg->e_cut_set = 1;
9857 X         break;
9858 X       case 'F':
9859 X         sscanf(optarg,"%lg",&m_msg->e_low);
9860 X         m_msg->e_cut_set = 1;
9861 X         break;
9862 X       case 'H':
9863 #if defined(PCOMPLIB)
9864 X         m_msg->nohist = 0; break;
9865 #else
9866 X         m_msg->nohist = 1; break;
9867 #endif
9868 X       case 'i':
9869 X         m_msg->revcomp = 1; break;
9870 #ifdef PARALLEL
9871 X       case 'I':
9872 X         m_msg->self = 1; break;
9873 X       case 'J':
9874 X         if (optarg[0]==':') {
9875 X           m_msg->ql_start = 0;
9876 X           sscanf(optarg,":%d",&m_msg->ql_stop);
9877 X           m_msg->ql_stop++;
9878 X         }
9879 X         else if (!strchr(optarg,':')) {
9880 X           m_msg->ql_stop = BIGNUM;
9881 X           sscanf(optarg,"%d",&m_msg->ql_start);
9882 X         }
9883 X         else {
9884 X           sscanf(optarg,"%d:%d",&m_msg->ql_start,&m_msg->ql_stop);
9885 X           m_msg->ql_stop++;
9886 X         }
9887 X         break;
9888 X       case 'K':
9889 X         sscanf(optarg,"%d",&max_buf_cnt);
9890 X         break;
9891 #endif
9892 X       case 'l':
9893 X         strncpy(m_msg->flstr,optarg,MAX_FN);
9894 X         m_msg->flstr[MAX_FN-1]='\0';
9895 X         break;
9896 X       case 'L':
9897 X         m_msg->long_info = 1; break;
9898 X       case 'm':
9899 X         sscanf(optarg,"%d%c",&itmp,&ctmp);
9900 X         if (itmp==9 && ctmp=='c') {
9901 X           m_msg->show_code = SHOW_CODE_ALIGN;
9902 X         }
9903 X         else if (itmp==9 && ctmp=='i') {
9904 X           m_msg->show_code = SHOW_CODE_ID;
9905 X         }
9906 X         if (itmp > 6 && itmp != 10 && itmp != 9) itmp = 0;
9907 X         m_msg->markx = set_markx(m_msg->markx,itmp);
9908 X         break;
9909 X       case 'M':
9910 X         sscanf(optarg,"%d-%d",&m_msg->n1_low,&m_msg->n1_high);
9911 X         if (m_msg->n1_low < 0) {
9912 X           m_msg->n1_high = -m_msg->n1_low;
9913 X           m_msg->n1_low = 0;
9914 X         }
9915 X         if (m_msg->n1_high == 0) m_msg->n1_high = BIGNUM;
9916 X         if (m_msg->n1_low > m_msg->n1_high) {
9917 X           fprintf(stderr," low cutoff %d greater than high %d\n",
9918 X                   m_msg->n1_low, m_msg->n1_high);
9919 X           m_msg->n1_low = 0;
9920 X           m_msg->n1_high = BIGNUM;
9921 X         }
9922 X         break;
9923 X       case 'N':
9924 X         sscanf(optarg,"%d",&m_msg->maxn);
9925 X         break;
9926 X       case 'p':
9927 X         m_msg->qdnaseq = SEQT_PROT;
9928 X         ppst->dnaseq = SEQT_PROT;
9929 X         strncpy(m_msg->sqnam,"aa",4);
9930 X         break;
9931 X       case 'O':
9932 X         strncpy(m_msg->outfile,optarg,MAX_FN);
9933 X         m_msg->outfile[MAX_FN-1]='\0';
9934 X         break;
9935 X       case 'q':
9936 X       case 'Q':
9937 X         m_msg->quiet = 1;
9938 X         break;
9939 X       case 'R':
9940 X         strncpy (m_msg->dfile, optarg, MAX_FN);
9941 X         m_msg->dfile[MAX_FN-1]='\0';
9942 X         break;
9943 X       case 'T':
9944 #ifdef PCOMPLIB
9945 X         if (strchr(optarg,'-') != NULL) {
9946 X           sscanf(optarg,"%d-%d",&worker_1,&worker_n);
9947 X           if (worker_1 > worker_n) {
9948 X             worker_1 = worker_n = 0;
9949 X           }
9950 X         }
9951 X         else 
9952 #endif
9953 X           sscanf (optarg, "%d", &max_workers);
9954 X         if (max_workers < 0) max_workers=1;
9955 X         break;
9956 X       case 'v':
9957 X         sscanf (optarg,"%d",&ppst->zs_win);
9958 X         break;
9959 X       case 'V':
9960 X         strncpy(m_msg->ann_arr+1,optarg,MAX_FN-2);
9961 X         m_msg->ann_arr[0]='\0';
9962 X         m_msg->ann_arr[MAX_FN-2]='\0';
9963 X         m_msg->ann_flg = 1;
9964 X         ann_ascii(qascii, m_msg->ann_arr);
9965 X         break;
9966 /*
9967 X       case 'V':
9968 X         fprintf(stderr," -V option not currently supported in parallel\n");
9969 X         break;
9970 */
9971 X       case 'w':
9972 X         sscanf (optarg,"%d",&m_msg->aln.llen);
9973 X         if (m_msg->aln.llen < 10) m_msg->aln.llen = 10;
9974 X         if (m_msg->aln.llen > 200) m_msg->aln.llen = 200;
9975 X         if (!m_msg->aln.llcntx_flg) m_msg->aln.llcntx = m_msg->aln.llen/2;
9976 X         break;
9977 X       case 'W':
9978 X         sscanf (optarg,"%d",&m_msg->aln.llcntx);
9979 X         m_msg->aln.llcntx_flg = 1;
9980 X         break;
9981 X       case 'X':
9982 X         sscanf (optarg,"%ld %ld",&m_msg->sq0off,&m_msg->sq1off); break;
9983 X       case 'z':
9984 X         sscanf(optarg,"%d",&ppst->zsflag);
9985 X         break;
9986 X       case 'Z':
9987 X         sscanf(optarg,"%ld",&ppst->zdb_size);
9988 X         break;
9989 X       }
9990 X      }
9991 X      else if (strchr (s_optstr, copt))
9992 X        f_getopt (copt, optarg, m_msg, ppst);
9993 X   }
9994 X   optind--;
9995 X
9996 X   f_lastenv (m_msg, ppst);
9997 X
9998 X   if (argc - optind < 3) return;
9999 X   m_msg->tnamesize = sizeof (m_msg->tname);
10000 X   if (argc - optind > 1) strncpy (m_msg->tname, argv[optind + 1],MAX_FN);
10001 X   if (argc - optind > 2) { strncpy(m_msg->lname, argv[optind + 2],MAX_FN); }
10002 X   f_getarg (argc, argv, optind, m_msg, ppst);
10003 }
10004 X
10005 int
10006 ann_scan(unsigned char *aa0, int n0, struct mngmsg *m_msg, int seqtype)
10007 {
10008 X  unsigned char *aa0p, *aa0d, *aa0ad;
10009 X  int n_n0;
10010 X
10011 X  /* count how many "real" residues */
10012 X
10013 X  if (seqtype==SEQT_UNK) {
10014 X    for (n_n0=0, aa0p = aa0; aa0p < aa0+n0; aa0p++) {
10015 X      if (*aa0p > '@' || *aa0p == ESS ) n_n0++;
10016 X    }
10017 X  }
10018 X  else {
10019 X    for (n_n0=0, aa0p = aa0; aa0p < aa0+n0; aa0p++) {
10020 X      if (*aa0p < NANN ) n_n0++;
10021 X    }
10022 X  }
10023 X
10024 X  aa0d = aa0;
10025 X  /* n_n0 has the real sequence length */
10026 X  if ((m_msg->aa0a = calloc(n_n0+2, sizeof(char)))==NULL) {
10027 X    fprintf(stderr," cannot allocate annotation sequence: %d\n",n_n0);
10028 X    m_msg->ann_flg = 0;
10029 X    if (seqtype==SEQT_UNK) {
10030 X      for (aa0p = aa0; aa0p < aa0+n0; aa0p++) {
10031 X       if (*aa0p > '@' || *aa0p == ESS) {*aa0d++ = *aa0p;}
10032 X      }
10033 X    }
10034 X    else {
10035 X      for (aa0p = aa0; aa0p < aa0+n0; aa0p++) {
10036 X       if (*aa0p < NANN) {*aa0d++ = *aa0p;}
10037 X      }
10038 X    }
10039 X      *aa0d = '\0';
10040 X    return n_n0;
10041 X  }
10042 X
10043 X  aa0ad = m_msg->aa0a;
10044 X  if (seqtype==SEQT_UNK) {
10045 X    for (aa0p = aa0; aa0p<aa0+n0; aa0p++) {
10046 X      if (*aa0p > '@' || *aa0p == ESS) {*aa0d++ = *aa0p; *aa0ad++='\0';}
10047 X      else if (aa0ad > m_msg->aa0a) { aa0ad[-1] = *aa0p - NANN;}
10048 X    }
10049 X  }
10050 X  else {
10051 X    for (aa0p = aa0; aa0p<aa0+n0; aa0p++) {
10052 X      if (*aa0p < NANN) {*aa0d++ = *aa0p; *aa0ad++='\0';}
10053 X      else if (aa0ad > m_msg->aa0a) { aa0ad[-1] = *aa0p - NANN;}
10054 X    }
10055 X  }
10056 X  *aa0ad = *aa0d = '\0';
10057 X  return n_n0;
10058 }
10059 X
10060 void
10061 ann_ascii(int *qascii, char *ann_arr)
10062 {
10063 X  char *ann_p;
10064 X  int ann_ix = NANN+1;
10065 X
10066 X  ann_arr[0] = ' ';
10067 X  if (strchr(ann_arr+1,'*')) {qascii['*'] = NA;}
10068 X
10069 X  for (ann_p = ann_arr+1; *ann_p; ann_p++) {
10070 X    if (qascii[*ann_p] == NA) { qascii[*ann_p] = ann_ix++;}
10071 X  }
10072 }
10073 X
10074 int 
10075 set_markx(int markx, int val) {
10076 X
10077 X  if (val < 3) {
10078 X    return markx | (MX_ATYPE & val);
10079 X  }
10080 X  else if (val == 3) {
10081 X    markx |= (MX_ATYPE + MX_ASEP);
10082 X  }
10083 X  else if (val == 4) {
10084 X    markx |= (MX_ATYPE + MX_AMAP);
10085 X  }
10086 X  else if (val == 5) {
10087 X    markx |= MX_AMAP;
10088 X  }
10089 X  else if (val == 6) {
10090 X    markx |= (MX_HTML) ;
10091 X  }
10092 X  else if (val == 9) {
10093 X    markx |= MX_M9SUMM;
10094 X  }
10095 X  else if (val == 10) {
10096 X    markx |= MX_M10FORM;
10097 X  }
10098 X
10099 X  return markx;
10100 }
10101 SHAR_EOF
10102 chmod 0644 doinit.c ||
10103 echo 'restore of doinit.c failed'
10104 Wc_c="`wc -c < 'doinit.c'`"
10105 test 10740 -eq "$Wc_c" ||
10106         echo 'doinit.c: original size 10740, current size' "$Wc_c"
10107 fi
10108 # ============= drop_func.h ==============
10109 if test -f 'drop_func.h' -a X"$1" != X"-c"; then
10110         echo 'x - skipping drop_func.h (File already exists)'
10111 else
10112 echo 'x - extracting drop_func.h (Text)'
10113 sed 's/^X//' << 'SHAR_EOF' > 'drop_func.h' &&
10114 /* drop_func.h */
10115 X
10116 /* $Name: fa_34_26_5 $ - $Id: drop_func.h,v 1.7 2006/05/31 15:31:45 wrp Exp $ */
10117 X
10118 /* functions provided by each of the drop files */
10119 X
10120 /* Copyright (c) 2005 William R. Pearson and the University of Virginia */
10121 X
10122 X
10123 void    /* initializes f_struct **f_arg */
10124 init_work (unsigned char *aa0, int n0,
10125 X          struct pstruct *ppst,
10126 #ifndef DROP_INTERN
10127 X          void **f_arg
10128 #else
10129 X          struct f_struct **f_arg
10130 #endif
10131 );
10132 X
10133 X
10134 void    /* frees memory allocated in f_struct */
10135 close_work (const unsigned char *aa0, int n0,
10136 X           struct pstruct *ppst,
10137 #ifndef DROP_INTERN
10138 X          void **f_arg
10139 #else
10140 X          struct f_struct **f_arg
10141 #endif
10142 );
10143 X
10144 void    /* documents search function, parameters */
10145 get_param (struct pstruct *pstr, char *pstring1, char *pstring2);
10146 X
10147 void    /* calculates alignment score(s), returns them in rst */
10148 do_work (const unsigned char *aa0, int n0,
10149 X        const unsigned char *aa1, int n1,
10150 X        int frame,
10151 X        struct pstruct *ppst,
10152 #ifndef DROP_INTERN
10153 X        void *f_arg,
10154 #else
10155 X        struct f_struct *f_arg,
10156 #endif
10157 X        int qr_flg, struct rstruct *rst);
10158 X
10159 void    /* calculates optimal alignment score */
10160 do_opt (const unsigned char *aa0, int n0,
10161 X       const unsigned char *aa1, int n1,
10162 X       int frame,
10163 X       struct pstruct *ppst,
10164 #ifndef DROP_INTERN
10165 X       void *f_arg,
10166 #else
10167 X       struct f_struct *f_arg,
10168 #endif
10169 X       struct rstruct *rst
10170 X       );
10171 X
10172 int     /* produces encoding of alignment */
10173 do_walign (const unsigned char *aa0, int n0,
10174 X          const unsigned char *aa1, int n1,
10175 X          int frame,
10176 X          struct pstruct *ppst, 
10177 #ifndef DROP_INTERN
10178 X          void *f_arg,
10179 #else
10180 X          struct f_struct *f_arg,
10181 #endif
10182 X          struct a_res_str *a_res,
10183 X          int *have_ares);
10184 X
10185 void
10186 pre_cons(const unsigned char *aa, int n, int frame, 
10187 #ifndef DROP_INTERN
10188 X          void *f_arg
10189 #else
10190 X          struct f_struct *f_arg
10191 #endif
10192 X       );
10193 X
10194 void 
10195 aln_func_vals(int frame, struct a_struct *aln);
10196 X
10197 int     /* takes aa0, aa1, a_res, and produces seqc0, seqc1 */
10198 calcons(const unsigned char *aa0, int n0,
10199 X       const unsigned char *aa1, int n1,
10200 X       int *nc,
10201 X       struct a_struct *aln,           /* seqc0/seqc1 coordinates */
10202 X       struct a_res_str a_res,         /* aa0,aa1, coord, inc. res, nres */
10203 X       struct pstruct pst,
10204 X       char *seqc0, char *seqc1, char *seqca,
10205 #ifndef DROP_INTERN
10206 X       void *f_arg
10207 #else
10208 X       struct f_struct *f_arg
10209 #endif
10210 X       );
10211 X
10212 /* calcons_a - takes aa0, aa1, a_res, and produces seqc0, seqc1, 
10213 X *             and seqc0a, seqc1a - the annotated sequences 
10214 X */
10215 int
10216 calcons_a(const unsigned char *aa0, unsigned char *aa0a, int n0,
10217 X         const unsigned char *aa1, int n1,
10218 X         int *nc,
10219 X         struct a_struct *aln,
10220 X         struct a_res_str a_res,
10221 X         struct pstruct pst,
10222 X         char *seqc0, char *seqc0a, char *seqc1, char *seqca,
10223 X         char *ann_arr,
10224 #ifndef DROP_INTERN
10225 X         void *f_arg
10226 #else
10227 X         struct f_struct *f_arg
10228 #endif
10229 X         );
10230 X
10231 int     /* returns lenc - length of aligment */
10232 calc_code(const unsigned char *aa0, int n0,
10233 X         const unsigned char *aa1, int n1,
10234 X         struct a_struct *aln,
10235 X         struct a_res_str a_res,
10236 X         struct pstruct pst,
10237 X         char *al_str, int al_str_n,
10238 #ifndef DROP_INTERN
10239 X         void *f_arg
10240 #else
10241 X         struct f_struct *f_arg
10242 #endif
10243 X         );
10244 X
10245 int     /* returns lenc - length of alignment */
10246 calc_id(const unsigned char *aa0, int n0,
10247 X       const unsigned char *aa1, int n1,
10248 X       struct a_struct *aln, 
10249 X       struct a_res_str a_res,
10250 X       struct pstruct pst,
10251 #ifndef DROP_INTERN
10252 X       void *f_arg
10253 #else
10254 X       struct f_struct *f_arg
10255 #endif
10256 X       );
10257 SHAR_EOF
10258 chmod 0644 drop_func.h ||
10259 echo 'restore of drop_func.h failed'
10260 Wc_c="`wc -c < 'drop_func.h'`"
10261 test 3226 -eq "$Wc_c" ||
10262         echo 'drop_func.h: original size 3226, current size' "$Wc_c"
10263 fi
10264 # ============= dropff2.c ==============
10265 if test -f 'dropff2.c' -a X"$1" != X"-c"; then
10266         echo 'x - skipping dropff2.c (File already exists)'
10267 else
10268 echo 'x - extracting dropff2.c (Text)'
10269 sed 's/^X//' << 'SHAR_EOF' > 'dropff2.c' &&
10270 X
10271 /* copyright (c) 1998, 1999 William R. Pearson and the U. of Virginia */
10272 X
10273 /*  - dropffa.c,v 1.1.1.1 1999/10/22 20:55:59 wrp Exp */
10274 X
10275 /* this code implements the "fastf" algorithm, which is designed to
10276 X   deconvolve mixtures of protein sequences derived from mixed-peptide
10277 X   Edman sequencing.  The expected input is:
10278 X
10279 X   >test | 40001 90043 | mgstm1
10280 X   MGCEN,
10281 X   MIDYP,
10282 X   MLLAY,
10283 X   MLLGY
10284 X
10285 X   Where the ','s indicate the length/end of the sequencing cycle
10286 X   data.  Thus, in this example, the sequence is from a mixture of 4
10287 X   peptides, M was found in the first position, G,I, and L(2) at the second,
10288 X   C,D, L(2) at the third, etc.
10289 X
10290 X   Because the sequences are derived from mixtures, there need not be
10291 X   any partial sequence "MGCEN", the actual deconvolved sequence might be
10292 X   "MLDGN".
10293 */
10294 X
10295 #include <stdio.h>
10296 #include <stdlib.h>
10297 #include <string.h>
10298 #include <stdlib.h>
10299 #include <math.h>
10300 #include <ctype.h>
10301 X
10302 #include "defs.h"
10303 #include "param.h"
10304 #include "structs.h"
10305 #include "tatstats.h"
10306 X
10307 #define EOSEQ 0 
10308 #define ESS 49
10309 #define MAXHASH 32
10310 #define NMAP MAXHASH+1
10311 #define NMAP_X 23       /* re-code NMAP for 'X' */
10312 #define NMAP_Z 24       /* re-code NMAP for '*' */
10313 X
10314 #ifndef MAXSAV
10315 #define MAXSAV 10
10316 #endif
10317 X
10318 #define DROP_INTERN
10319 #include "drop_func.h"
10320 X
10321 static char *verstr="4.21 May 2006 (ajm/wrp)";
10322 X
10323 int shscore(unsigned char *aa0, const int n0, int **pam2, int nsq);
10324 void update_code(char *al_str, int al_str_max, int op, int op_cnt, int fnum);
10325 extern void aancpy(char *to, char *from, int count, struct pstruct pst);
10326 X
10327 #ifdef TFAST
10328 extern int aatran(const unsigned char *ntseq, unsigned char *aaseq, 
10329 X                 const int maxs, const int frame);
10330 #endif
10331 X
10332 struct hlstr { int next, pos;};
10333 X
10334 void savemax(struct dstruct *, struct f_struct *);
10335 X
10336 static int m0_spam(unsigned char *, const unsigned char *, int, struct savestr *,
10337 X           int **, struct f_struct *);
10338 static int m1_spam(unsigned char *, int,
10339 X                  const unsigned char *, int,
10340 X                  struct savestr *, int **, int, struct f_struct *);
10341 X
10342 int sconn(struct savestr **v, int nsave, int cgap,
10343 X         struct f_struct *, struct rstruct *, struct pstruct *,
10344 X         const unsigned char *aa0, int n0,
10345 X         const unsigned char *aa1, int n1,
10346 X         int opt_prob);
10347 X
10348 void kpsort(struct savestr **, int);
10349 void kssort(struct savestr **, int);
10350 void kpsort(struct savestr **, int);
10351 X
10352 int
10353 sconn_a(unsigned char *, int, int, struct f_struct *,
10354 X       struct a_res_str *);
10355 X
10356 /* initialize for fasta */
10357 X
10358 void
10359 init_work (unsigned char *aa0, int n0, 
10360 X          struct pstruct *ppst,
10361 X          struct f_struct **f_arg)
10362 {
10363 X   int mhv, phv;
10364 X   int hmax;
10365 X   int i0, ii0, hv;
10366 X   struct f_struct *f_str;
10367 X
10368 X   int maxn0;
10369 X   int i, j, q;
10370 X   struct savestr *vmptr;
10371 X   int *res;
10372 X
10373 X   f_str = (struct f_struct *) calloc(1, sizeof(struct f_struct));
10374 X   if(f_str == NULL) {
10375 X     fprintf(stderr, "Couldn't calloc f_str\n");
10376 X     exit(1);
10377 X   }
10378 X
10379 X   ppst->sw_flag = 0;
10380 X
10381 X   /* fastf3 cannot work with lowercase symbols as low complexity;
10382 X      thus, NMAP must be disabled; this depends on aascii['X']  */
10383 X   if (ppst->hsq[NMAP_X] == NMAP ) {ppst->hsq[NMAP_X]=1;}
10384 X   if (ppst->hsq[NMAP_Z] == NMAP ) {ppst->hsq[NMAP_Z]=1;}
10385 X
10386 X   /*   this does not work for share ppst structs, as in threads */
10387 X   /*else {fprintf(stderr," cannot find 'X'==NMAP\n");} */
10388 X
10389 X   for (i0 = 1, mhv = -1; i0 <= ppst->nsq; i0++)
10390 X      if (ppst->hsq[i0] < NMAP && ppst->hsq[i0] > mhv) mhv = ppst->hsq[i0];
10391 X
10392 X   if (mhv <= 0) {
10393 X      fprintf (stderr, " maximum hsq <=0 %d\n", mhv);
10394 X      exit (1);
10395 X   }
10396 X
10397 X   for (f_str->kshft = 0; mhv > 0; mhv /= 2)
10398 X      f_str->kshft++;
10399 X
10400 /*      kshft = 2;      */
10401 X   hmax = hv = (1 << f_str->kshft);
10402 X   f_str->hmask = (hmax >> f_str->kshft) - 1;
10403 X
10404 X   if ((f_str->aa0 = (unsigned char *) calloc(n0+1, sizeof(char))) == NULL) {
10405 X     fprintf (stderr, " cannot allocate f_str->aa0 array; %d\n",n0+1);
10406 X     exit (1);
10407 X   }
10408 X   for (i=0; i<n0; i++) f_str->aa0[i] = aa0[i];
10409 X   aa0 = f_str->aa0;
10410 X
10411 X   if ((f_str->aa0t = (unsigned char *) calloc(n0+1, sizeof(char))) == NULL) {
10412 X     fprintf (stderr, " cannot allocate f_str0->aa0t array; %d\n",n0+1);
10413 X     exit (1);
10414 X   }
10415 X   f_str->aa0ix = 0;
10416 X
10417 X   if ((f_str->harr = (struct hlstr *) calloc (hmax, sizeof (struct hlstr))) == NULL) {
10418 X     fprintf (stderr, " cannot allocate hash array; hmax: %d hmask: %d\n",
10419 X             hmax,f_str->hmask);
10420 X     exit (1);
10421 X   }
10422 X   if ((f_str->pamh1 = (int *) calloc (ppst->nsq+1, sizeof (int))) == NULL) {
10423 X     fprintf (stderr, " cannot allocate pamh1 array\n");
10424 X     exit (1);
10425 X   }
10426 X   if ((f_str->pamh2 = (int *) calloc (hmax, sizeof (int))) == NULL) {
10427 X     fprintf (stderr, " cannot allocate pamh2 array\n");
10428 X     exit (1);
10429 X   }
10430 X   if ((f_str->link = (struct hlstr *) calloc (n0, sizeof (struct hlstr))) == NULL) {
10431 X     fprintf (stderr, " cannot allocate hash link array");
10432 X     exit (1);
10433 X   }
10434 X
10435 X   for (i0 = 0; i0 < hmax; i0++) {
10436 X      f_str->harr[i0].next = -1;
10437 X      f_str->harr[i0].pos = -1;
10438 X   }
10439 X
10440 X   for (i0 = 0; i0 < n0; i0++) {
10441 X      f_str->link[i0].next = -1;
10442 X      f_str->link[i0].pos = -1;
10443 X   }
10444 X
10445 X   /* encode the aa0 array */
10446 X   /*
10447 X     this code has been modified to allow for mixed peptide sequences
10448 X      aa0[] = 5 8 9 3 4 NULL 5 12 3 7 2 NULL
10449 X      the 'NULL' character resets the hash position counter, to indicate that
10450 X      any of several residues can be in the same position.
10451 X      We also need to keep track of the number of times this has happened, so that
10452 X      we can redivide the sequence later
10453 X
10454 X      i0 counts through the sequence
10455 X      ii0 counts through the hashed sequence
10456 X
10457 X      */
10458 X
10459 X   f_str->nm0 = 1;
10460 X   f_str->nmoff = -1;
10461 X   phv = hv = 0;
10462 X   for (i0= ii0 = 0; i0 < n0; i0++, ii0++) {
10463 X     /* reset the counter and start hashing again */
10464 X     if (aa0[i0] == ESS || aa0[i0] == 0) {
10465 X       aa0[i0] = 0;    /* set ESS to 0 */
10466 X       /*       fprintf(stderr," converted ',' to 0\n");*/
10467 X       i0++;   /* skip over the blank */
10468 X       f_str->nm0++;
10469 X       if (f_str->nmoff < 0) f_str->nmoff = i0;
10470 X       phv = hv = 0;
10471 X       ii0 = 0;
10472 X     }
10473 X     hv = ppst->hsq[aa0[i0]];
10474 X     f_str->link[i0].next = f_str->harr[hv].next;
10475 X     f_str->link[i0].pos = f_str->harr[hv].pos;
10476 X     f_str->harr[hv].next = i0;
10477 X     f_str->harr[hv].pos = ii0;
10478 X     f_str->pamh2[hv] = ppst->pam2[0][aa0[i0]][aa0[i0]];
10479 X   }
10480 X   if (f_str-> nmoff < 0) f_str->nmoff = n0;
10481 X
10482 X
10483 #ifdef DEBUG
10484 X   /*
10485 X   fprintf(stderr," nmoff: %d/%d nm0: %d\n", f_str->nmoff, n0,f_str->nm0);
10486 X   */
10487 #endif
10488 X
10489 /*
10490 #ifdef DEBUG
10491 X   fprintf(stderr," hmax: %d\n",hmax);
10492 X   for ( hv=0; hv<hmax; hv++)
10493 X       fprintf(stderr,"%2d %c %3d %3d\n",hv,
10494 X              (hv > 0 && hv < ppst->nsq ) ? ppst->sq[ppst->hsq[hv]] : ' ',
10495 X              f_str->harr[hv].pos,f_str->harr[hv].next);
10496 X   fprintf(stderr,"----\n");
10497 X   for ( hv=0; hv<n0; hv++)
10498 X       fprintf(stderr,"%2d: %3d %3d\n",hv,
10499 X              f_str->link[hv].pos,f_str->link[hv].next);
10500 #endif
10501 */
10502 X
10503 X   f_str->maxsav = MAXSAV;
10504 X   if ((f_str->vmax = (struct savestr *)
10505 X       calloc(MAXSAV,sizeof(struct savestr)))==NULL) {
10506 X     fprintf(stderr, "Couldn't allocate vmax[%d].\n",f_str->maxsav);
10507 X     exit(1);
10508 X   }
10509 X
10510 X   if ((f_str->vptr = (struct savestr **)
10511 X       calloc(MAXSAV,sizeof(struct savestr *)))==NULL) {
10512 X     fprintf(stderr, "Couldn't allocate vptr[%d].\n",f_str->maxsav);
10513 X     exit(1);
10514 X   }
10515 X
10516 X   for (vmptr = f_str->vmax; vmptr < &f_str->vmax[MAXSAV]; vmptr++) {
10517 X     vmptr->used = (int *) calloc(n0, sizeof(int));
10518 X     if(vmptr->used == NULL) {
10519 X       fprintf(stderr, "Couldn't alloc vmptr->used\n");
10520 X       exit(1);
10521 X     }
10522 X   }
10523 X
10524 /* this has been modified from 0..<ppst->nsq to 1..<=ppst->nsq because the
10525 X   pam2[0][0] is now undefined for consistency with blast
10526 */
10527 X
10528 X   for (i0 = 1; i0 <= ppst->nsq; i0++)
10529 X     f_str->pamh1[i0] = ppst->pam2[0][i0][i0];
10530 X
10531 X   ppst->param_u.fa.cgap = shscore(aa0,f_str->nmoff-1,ppst->pam2[0],ppst->nsq)/3;
10532 X   if (ppst->param_u.fa.cgap > ppst->param_u.fa.bestmax/4)
10533 X     ppst->param_u.fa.cgap = ppst->param_u.fa.bestmax/4;
10534 X
10535 X   f_str->ndo = 0;
10536 X   f_str->noff = n0-1;
10537 X   if (f_str->diag==NULL) 
10538 X     f_str->diag = (struct dstruct *) calloc ((size_t)MAXDIAG,
10539 X                                             sizeof (struct dstruct));
10540 X
10541 X   if (f_str->diag == NULL)
10542 X   {
10543 X      fprintf (stderr, " cannot allocate diagonal arrays: %ld\n",
10544 X             (long) MAXDIAG * (long) (sizeof (struct dstruct)));
10545 X      exit (1);
10546 X   }
10547 X
10548 #ifdef TFAST
10549 X   if ((f_str->aa1x =(unsigned char *)calloc((size_t)ppst->maxlen+2,
10550 X                                            sizeof(unsigned char)))
10551 X       == NULL) {
10552 X     fprintf (stderr, "cannot allocate aa1x array %d\n", ppst->maxlen+2);
10553 X     exit (1);
10554 X   }
10555 X   f_str->aa1x++;
10556 #endif
10557 X
10558 X   /* allocate space for the scoring arrays */
10559 X   maxn0 = n0 + 4;
10560 X
10561 X   maxn0 = max(3*n0/2,MIN_RES);
10562 X   if ((res = (int *)calloc((size_t)maxn0,sizeof(int)))==NULL) {
10563 X     fprintf(stderr,"cannot allocate alignment results array %d\n",maxn0);
10564 X     exit(1);
10565 X   }
10566 X   f_str->res = res;
10567 X   f_str->max_res = maxn0;
10568 X
10569 X   /* Tatusov Statistics Setup */
10570 X
10571 X   /* initialize priors array. */
10572 X   if((f_str->priors = (double *)calloc(ppst->nsq+1, sizeof(double))) == NULL) {
10573 X     fprintf(stderr, "Couldn't allocate priors array.\n");
10574 X     exit(1);
10575 X   }
10576 X   calc_priors(f_str->priors, ppst, f_str, NULL, 0, ppst->pseudocts);
10577 X
10578 X   f_str->dotat = 0;
10579 X   f_str->shuff_cnt = ppst->shuff_node;
10580 X
10581 X   /* End of Tatusov Statistics Setup */
10582 X
10583 X   *f_arg = f_str;
10584 }
10585 X
10586 X
10587 /* pstring1 is a message to the manager, currently 512 */
10588 /* pstring2 is the same information, but in a markx==10 format */
10589 void
10590 get_param (struct pstruct *pstr, char *pstring1, char *pstring2)
10591 {
10592 #ifndef TFAST
10593 X  char *pg_str="FASTF";
10594 #else
10595 X  char *pg_str="TFASTF";
10596 #endif
10597 X
10598 X  sprintf (pstring1, "%s (%s) function [%s matrix (%d:%d)] join: %d",pg_str,verstr,
10599 X          pstr->pamfile, pstr->pam_h,pstr->pam_l,pstr->param_u.fa.cgap);
10600 X
10601 X  if (pstr->param_u.fa.iniflag) strcat(pstring1," init1");
10602 X  /*
10603 X  if (pstr->zsflag==0) strcat(pstring1," not-scaled");
10604 X  else if (pstr->zsflag==1) strcat(pstring1," reg.-scaled");
10605 X  */
10606 X
10607 X  if (pstring2 != NULL) {
10608 X    sprintf (pstring2, "; pg_name: %s\n; pg_ver: %s\n; pg_matrix: %s (%d:%d)\n\
10609 ; pg_join: %d\n",
10610 X            pg_str,verstr, pstr->pamfile, pstr->pam_h,pstr->pam_l,
10611 X            pstr->param_u.fa.cgap);
10612 X   }
10613 }
10614 X
10615 void
10616 close_work (const unsigned char *aa0, const int n0,
10617 X           struct pstruct *ppst,
10618 X           struct f_struct **f_arg)
10619 {
10620 X  struct f_struct *f_str;
10621 X  struct savestr *vmptr;
10622 X
10623 X  f_str = *f_arg;
10624 X
10625 X  if (f_str != NULL) {
10626 X
10627 X    for (vmptr = f_str->vmax; vmptr < &f_str->vmax[MAXSAV]; vmptr++)
10628 X      free(vmptr->used);
10629 X
10630 X    free(f_str->res);
10631 #ifdef TFAST
10632 X    free(f_str->aa1x - 1); /* allocated, then aa1x++'ed */
10633 #endif
10634 X    free(f_str->diag);
10635 X    free(f_str->link);
10636 X    free(f_str->pamh2); 
10637 X    free(f_str->pamh1);
10638 X    free(f_str->harr);
10639 X    free(f_str->aa0t);
10640 X    free(f_str->aa0);
10641 X    free(f_str->priors);
10642 X    free(f_str);
10643 X    *f_arg = NULL;
10644 X  }
10645 }
10646 X
10647 int do_fastf (unsigned char *aa0, int n0,
10648 X             const unsigned char *aa1, int n1,
10649 X             struct pstruct *ppst, struct f_struct *f_str,
10650 X             struct rstruct *rst, int *hoff, int opt_prob)
10651 {
10652 X   int     nd;         /* diagonal array size */
10653 X   int     lhval;
10654 X   int     kfact;
10655 X   register struct dstruct *dptr;
10656 X   register int tscor;
10657 X   register struct dstruct *diagp;
10658 X   struct dstruct *dpmax;
10659 X   register int lpos;
10660 X   int     tpos, npos;
10661 X   struct savestr *vmptr;
10662 X   int     scor, tmp;
10663 X   int     im, ib, nsave;
10664 X   int     cmps ();            /* comparison routine for ksort */
10665 X   int *hsq;
10666 X
10667 X   hsq = ppst->hsq;
10668 X
10669 X   if (n1 < 1) {
10670 X     rst->score[0] = rst->score[1] = rst->score[2] = 0;
10671 X     rst->escore = 1.0;
10672 X     rst->segnum = 0;
10673 X     rst->seglen = 0;
10674 X     return 1;
10675 X   }
10676 X
10677 X   if (n0+n1+1 >= MAXDIAG) {
10678 X     fprintf(stderr,"n0,n1 too large: %d, %d\n",n0,n1);
10679 X     rst->score[0] = rst->score[1] = rst->score[2] = -1;
10680 X     rst->escore = 2.0;
10681 X     rst->segnum = 0;
10682 X     rst->seglen = 0;
10683 X     return -1;
10684 X   }
10685 X
10686 X   nd = n0 + n1;
10687 X
10688 X   dpmax = &f_str->diag[nd];
10689 X   for (dptr = &f_str->diag[f_str->ndo]; dptr < dpmax;) {
10690 X      dptr->stop = -1;
10691 X      dptr->dmax = NULL;
10692 X      dptr++->score = 0;
10693 X   }
10694 X
10695 X   /* initialize the saved segment structures */
10696 X   for (vmptr = f_str->vmax; vmptr < &f_str->vmax[MAXSAV]; vmptr++) {
10697 X      vmptr->score = 0;
10698 X      memset(vmptr->used, 0, n0 * sizeof(int));
10699 X   }
10700 X
10701 X   f_str->lowmax = f_str->vmax;
10702 X   f_str->lowscor = 0;
10703 X
10704 X   /* start hashing */
10705 X
10706 X   diagp = &f_str->diag[f_str->noff];
10707 X   for (lhval = lpos = 0; lpos < n1; lpos++, diagp++) {
10708 X     if (hsq[aa1[lpos]]>=NMAP) {
10709 X       lpos++ ; diagp++;
10710 X       while (lpos < n1 && hsq[aa1[lpos]]>=NMAP) {lpos++; diagp++;}
10711 X       if (lpos >= n1) break;
10712 X       lhval = 0;
10713 X     }
10714 X     lhval = hsq[aa1[lpos]];
10715 X     for (tpos = f_str->harr[lhval].pos, npos = f_str->harr[lhval].next;
10716 X         tpos >= 0; tpos = f_str->link[npos].pos, npos = f_str->link[npos].next) {
10717 X       /* tscor gets position of end of current lpos diag run */
10718 X       if ((tscor = (dptr = &diagp[-tpos])->stop) >= 0) {
10719 X        tscor++;                /* move forward one */
10720 X        if ((tscor -= lpos) <= 0) { /* check for size of gap to this hit - */
10721 X                                    /* includes implicit -1 mismatch penalty */
10722 X          scor = dptr->score;       /* current score of this run */
10723 X          if ((tscor += (kfact = f_str->pamh2[lhval])) < 0 &&
10724 X              f_str->lowscor < scor)   /* if updating tscor makes run worse, */
10725 X            savemax (dptr, f_str);     /* save it */
10726 X
10727 X          if ((tscor += scor) >= kfact) {  /* add to current run if continuing */
10728 X                                           /* is better than restart (kfact) */
10729 X              dptr->score = tscor;
10730 X              dptr->stop = lpos;
10731 X            }
10732 X            else {
10733 X              dptr->score = kfact;     /* starting over is better */
10734 X              dptr->start = (dptr->stop = lpos);
10735 X            }
10736 X        }
10737 X        else {                         /* continue current run */
10738 X          dptr->score += f_str->pamh1[aa0[tpos]]; 
10739 X          dptr->stop = lpos;
10740 X        }
10741 X       }
10742 X       else {                          /* no diagonal run yet */
10743 X        dptr->score = f_str->pamh2[lhval];
10744 X        dptr->start = (dptr->stop = lpos);
10745 X       }
10746 X     }                         /* end tpos */
10747 X   }                           /* end lpos */
10748 X
10749 X   for (dptr = f_str->diag; dptr < dpmax;) {
10750 X     if (dptr->score > f_str->lowscor) savemax (dptr, f_str);
10751 X     dptr->stop = -1;
10752 X     dptr->dmax = NULL;
10753 X     dptr++->score = 0;
10754 X   }
10755 X   f_str->ndo = nd;
10756 X
10757 /*
10758 X        at this point all of the elements of aa1[lpos]
10759 X        have been searched for elements of aa0[tpos]
10760 X        with the results in diag[dpos]
10761 */
10762 X
10763 X   /* set up pointers for sorting */
10764 X
10765 X   for (nsave = 0, vmptr = f_str->vmax; vmptr < &f_str->vmax[MAXSAV]; vmptr++) {
10766 X     if (vmptr->score > 0) {
10767 X       vmptr->score = m0_spam (aa0, aa1, n1, vmptr, ppst->pam2[0], f_str);
10768 X       f_str->vptr[nsave++] = vmptr;
10769 X     }
10770 X   }
10771 X
10772 X   /* sort them */
10773 X   kssort (f_str->vptr, nsave);
10774 X
10775 X   
10776 #ifdef DEBUG
10777 X   /*
10778 X   for (ib=0; ib<nsave; ib++) {
10779 X     fprintf(stderr,"0: %4d-%4d  1: %4d-%4d  dp: %d score: %d\n",
10780 X            f_str->noff+f_str->vptr[ib]->start-f_str->vptr[ib]->dp,
10781 X            f_str->noff+f_str->vptr[ib]->stop-f_str->vptr[ib]->dp,
10782 X            f_str->vptr[ib]->start,f_str->vptr[ib]->stop,
10783 X            f_str->vptr[ib]->dp,f_str->vptr[ib]->score);
10784 X       for (im=f_str->vptr[ib]->start; im<=f_str->vptr[ib]->stop; im++)
10785 X         fprintf(stderr," %c:%c",ppst->sq[aa0[f_str->noff+im-f_str->vptr[ib]->dp]],
10786 X                ppst->sq[aa1[im]]);
10787 X       fputc('\n',stderr);
10788 X   }
10789 X   fprintf(stderr,"---\n");
10790 X   */
10791 X   /* now use m_spam to re-evaluate */
10792 X   /*
10793 X   for (tpos = 0; tpos < n0; tpos++) {
10794 X     fprintf(stderr,"%c:%2d ",ppst->sq[aa0[tpos]],aa0[tpos]);
10795 X     if (tpos %10 == 9) fputc('\n',stderr);
10796 X   }
10797 X   fputc('\n',stderr);
10798 X   */
10799 #endif   
10800 X   
10801 X   f_str->aa0ix = 0;
10802 X   for (ib=0; ib < nsave; ib++) {
10803 X     if ((vmptr=f_str->vptr[ib])->score > 0) {
10804 X       vmptr->score = m1_spam (aa0, n0, aa1, n1, vmptr,
10805 X                              ppst->pam2[0], ppst->pam_l, f_str);
10806 X     }
10807 X   }
10808 X   /* reset aa0 - modified by m1_spam */
10809 X   for (tpos = 0; tpos < n0; tpos++) {
10810 X     if (aa0[tpos] >= 32) aa0[tpos] -= 32;
10811 X   }
10812 X
10813 X   kssort(f_str->vptr,nsave);
10814 X
10815 X   for ( ; nsave > 0; nsave--) 
10816 X     if (f_str->vptr[nsave-1]->score >0) break;
10817 X
10818 X   if (nsave <= 0) {
10819 X     f_str->nsave = 0;
10820 X     rst->score[0] = rst->score[1] = rst->score[2] = 0;
10821 X     rst->escore = 1.0;
10822 X
10823 X     return 1;
10824 X   }
10825 X   else f_str->nsave = nsave;
10826 X
10827 X   
10828 #ifdef DEBUG
10829 X   /*
10830 X   fprintf(stderr,"n0: %d; n1: %d; noff: %d\n",n0,n1,f_str->noff);
10831 X   for (ib=0; ib<nsave; ib++) {
10832 X     fprintf(stderr,"0: %4d-%4d  1: %4d-%4d  dp: %d score: %d\n",
10833 X            f_str->noff+f_str->vptr[ib]->start-f_str->vptr[ib]->dp,
10834 X            f_str->noff+f_str->vptr[ib]->stop-f_str->vptr[ib]->dp,
10835 X            f_str->vptr[ib]->start,f_str->vptr[ib]->stop,
10836 X            f_str->vptr[ib]->dp,f_str->vptr[ib]->score);
10837 X     for (im=f_str->vptr[ib]->start; im<=f_str->vptr[ib]->stop; im++)
10838 X       fprintf(stderr," %c:%c",ppst->sq[aa0[f_str->noff+im-f_str->vptr[ib]->dp]],
10839 X              ppst->sq[aa1[im]]);
10840 X     fputc('\n',stderr);
10841 X   }
10842 X
10843 X   fprintf(stderr,"---\n");
10844 X   */
10845 #endif   
10846 X
10847 X   scor = sconn (f_str->vptr, nsave, ppst->param_u.fa.cgap, f_str,
10848 X                rst, ppst, aa0, n0, aa1, n1, opt_prob);
10849 X
10850 X   for (vmptr=f_str->vptr[0],ib=1; ib<nsave; ib++)
10851 X     if (f_str->vptr[ib]->score > vmptr->score) vmptr=f_str->vptr[ib];
10852 X
10853 X   rst->score[1] = vmptr->score;
10854 X   rst->score[0] = rst->score[2] = max (scor, vmptr->score);
10855 X
10856 X   return 1;
10857 }
10858 X
10859 void do_work (const unsigned char *aa0, int n0,
10860 X             const unsigned char *aa1, int n1,
10861 X             int frame,
10862 X             struct pstruct *ppst, struct f_struct *f_str,
10863 X             int qr_flg, struct rstruct *rst)
10864 {
10865 X  int opt_prob;
10866 X  int hoff, n10, i;
10867 X
10868 X  if (qr_flg==1 && f_str->shuff_cnt <= 0) {
10869 X    rst->escore = 2.0;
10870 X    rst->score[0]=rst->score[1]=rst->score[2]= -1;
10871 X    return;
10872 X  }
10873 X
10874 X  if (f_str->dotat || ppst->zsflag == 4 || ppst->zsflag == 14 ) opt_prob=1;
10875 X  else opt_prob = 0;
10876 X  if (ppst->zsflag == 2 || ppst->zsflag == 12) opt_prob = 0;
10877 X  if (qr_flg) {
10878 X    opt_prob=1;
10879 X    /*    if (frame==1) */
10880 X      f_str->shuff_cnt--;
10881 X  }
10882 X
10883 X  if (n1 < 1) {
10884 X    rst->score[0] = rst->score[1] = rst->score[2] = -1;
10885 X    rst->escore = 2.0;
10886 X    return;
10887 X  }
10888 X
10889 #ifdef TFAST 
10890 X  n10=aatran(aa1,f_str->aa1x,n1,frame);
10891 X  if (ppst->debug_lib)
10892 X    for (i=0; i<n10; i++)
10893 X      if (f_str->aa1x[i]>ppst->nsq) {
10894 X       fprintf(stderr,
10895 X               "residue[%d/%d] %d range (%d)\n",i,n1,
10896 X               f_str->aa1x[i],ppst->nsq);
10897 X       f_str->aa1x[i]=0;
10898 X       n10=i-1;
10899 X      }
10900 X
10901 X  do_fastf (f_str->aa0, n0, f_str->aa1x, n10, ppst, f_str, rst, &hoff, opt_prob);
10902 #else   /* FASTF */
10903 X  do_fastf (f_str->aa0, n0, aa1, n1, ppst, f_str, rst, &hoff, opt_prob);
10904 #endif
10905 X
10906 X  rst->comp = rst->H = -1.0;
10907 X
10908 }
10909 X
10910 void do_opt (const unsigned char *aa0, int n0,
10911 X            const unsigned char *aa1, int n1,
10912 X            int frame,
10913 X            struct pstruct *ppst,
10914 X            struct f_struct *f_str,
10915 X            struct rstruct *rst)
10916 {
10917 X  int optflag, tscore, hoff, n10;
10918 X
10919 X  optflag = ppst->param_u.fa.optflag;
10920 X  ppst->param_u.fa.optflag = 1;
10921 X
10922 #ifdef TFAST  
10923 X  n10=aatran(aa1,f_str->aa1x,n1,frame);
10924 X  do_fastf (f_str->aa0, n0, f_str->aa1x, n10, ppst, f_str, rst, &hoff, 1);
10925 #else   /* FASTA */
10926 X  do_fastf(f_str->aa0, n0, aa1, n1, ppst, f_str, rst, &hoff, 1);
10927 #endif
10928 X  ppst->param_u.fa.optflag = optflag;
10929 }
10930 X
10931 void
10932 savemax (dptr, f_str)
10933 X  register struct dstruct *dptr;
10934 X  struct f_struct *f_str;
10935 {
10936 X   register int dpos;
10937 X   register struct savestr *vmptr;
10938 X   register int i;
10939 X
10940 X   dpos = (int) (dptr - f_str->diag);
10941 X
10942 /* check to see if this is the continuation of a run that is already saved */
10943 X
10944 X   if ((vmptr = dptr->dmax) != NULL && vmptr->dp == dpos &&
10945 X        vmptr->start == dptr->start)
10946 X   {
10947 X      vmptr->stop = dptr->stop;
10948 X      if ((i = dptr->score) <= vmptr->score)
10949 X        return;
10950 X      vmptr->score = i;
10951 X      if (vmptr != f_str->lowmax)
10952 X        return;
10953 X   }
10954 X   else
10955 X   {
10956 X      i = f_str->lowmax->score = dptr->score;
10957 X      f_str->lowmax->dp = dpos;
10958 X      f_str->lowmax->start = dptr->start;
10959 X      f_str->lowmax->stop = dptr->stop;
10960 X      dptr->dmax = f_str->lowmax;
10961 X   }
10962 X
10963 X   for (vmptr = f_str->vmax; vmptr < &f_str->vmax[MAXSAV]; vmptr++)
10964 X      if (vmptr->score < i)
10965 X      {
10966 X        i = vmptr->score;
10967 X        f_str->lowmax = vmptr;
10968 X      }
10969 X   f_str->lowscor = i;
10970 }
10971 X
10972 /* this version of spam() is designed to work with a collection of
10973 X   subfragments, selecting the best amino acid at each position so
10974 X   that, from each subfragment, each position is only used once.
10975 X
10976 X   As a result, m_spam needs to know the number of fragments.
10977 X
10978 X   In addition, it now requires a global alignment to the fragment
10979 X   and resets the start and stop positions
10980 X
10981 X   */
10982 X
10983 static int
10984 m1_spam (unsigned char *aa0, int n0,
10985 X        const unsigned char *aa1, int n1,
10986 X        struct savestr *dmax, int **pam2, int pam_l,
10987 X        struct f_struct *f_str)
10988 {
10989 X  int     tpos, lpos, im, ii, nm, ci;
10990 X  int     tot, ctot, pv;
10991 X
10992 X  struct {
10993 X    int     start, stop, score;
10994 X  } curv, maxv;
10995 X  unsigned char *aa0p;
10996 X  const unsigned char *aa1p;
10997 X
10998 X  lpos = dmax->start;                   /* position in library sequence */
10999 X   tpos = lpos - dmax->dp + f_str->noff; /* position in query sequence */
11000 X   /* force global alignment, reset start*/
11001 X   if (tpos < lpos) {
11002 X     lpos = dmax->start -= tpos;
11003 X     tpos = 0;
11004 X   }
11005 X   else {
11006 X     tpos -= lpos;
11007 X     lpos = dmax->start = 0;
11008 X   }
11009 X
11010 X   dmax->stop = dmax->start + (f_str->nmoff -2 - tpos);
11011 X   if (dmax->stop > n1) dmax->stop = n1;
11012 X
11013 X   /*
11014 X   if (dmax->start < 0) {
11015 X     tpos = -dmax->start;
11016 X     lpos = dmax->start=0;
11017 X   }
11018 X   else tpos = 0;
11019 X   */
11020 X
11021 X   aa1p = &aa1[lpos];
11022 X   aa0p = &aa0[tpos];
11023 X
11024 X   nm = f_str->nm0;
11025 X
11026 X   tot = curv.score = maxv.score = 0;
11027 X   for (; lpos <= dmax->stop; lpos++,aa0p++,aa1p++) {
11028 X     ctot = pam_l;
11029 X     ci = -1;
11030 X     for (im = 0, ii=0; im < nm; im++,ii+=f_str->nmoff) {
11031 X       if (aa0p[ii] < 32 && (pv = pam2[aa0p[ii]][*aa1p]) > ctot) {
11032 X        ctot = pv;
11033 X        ci = ii;
11034 /*       fprintf(stderr, "lpos: %d im: %d ii: %d ci: %d ctot: %d pi: %d pv: %d\n", lpos, im, ii, ci, ctot, aa0p[ii], pam2[aa0p[ii]][*aa1p]); */
11035 X       }
11036 X     }
11037 X     tot += ctot;
11038 X     if (ci >= 0 && aa0p[ci] < 32) {
11039 #ifdef DEBUG
11040 /*         fprintf(stderr, "used: lpos: %d ci: %d : %c\n", lpos, ci, sq[aa0p[ci]]); */
11041 #endif
11042 X       aa0p[ci] +=  32;
11043 X       dmax->used[&aa0p[ci] - aa0] = 1;
11044 X     }
11045 X   }
11046 X   return tot;
11047 }
11048 X
11049 int ma_spam (unsigned char *aa0, int n0, const unsigned char *aa1,
11050 X            struct savestr *dmax, struct pstruct *ppst,
11051 X            struct f_struct *f_str)
11052 {
11053 X  int **pam2;
11054 X  int     tpos, lpos, im, ii, nm, ci, lp0;
11055 X  int     tot, ctot, pv;
11056 X  struct {
11057 X    int     start, stop, score;
11058 X  } curv, maxv;
11059 X   const unsigned char *aa1p;
11060 X   unsigned char *aa0p, *aa0pt;
11061 X   int aa0t_flg;
11062 X
11063 X   pam2 = ppst->pam2[0];
11064 X   aa0t_flg = 0;
11065 X
11066 X   lpos = dmax->start;                 /* position in library sequence */
11067 X   tpos = lpos - dmax->dp + f_str->noff; /* position in query sequence */
11068 X   lp0 = lpos = dmax->start;
11069 X   aa1p = &aa1[lpos];
11070 X   aa0p = &aa0[tpos];                  /* real aa0 sequence */
11071 X
11072 X                       /* the destination aa0 sequence (without nulls) */
11073 X   aa0pt = &f_str->aa0t[f_str->aa0ix];
11074 X
11075 X   curv.start = lpos;
11076 X   nm = f_str->nm0;
11077 X
11078 X   /* sometimes, tpos may be > 0, with lpos = 0 - fill with 'X' */
11079 X   if (lpos == 0 && tpos > 0)
11080 X     for (ii = 0; ii < tpos; ii++) *aa0pt++ = 31;  /* filler character */
11081 X
11082 X   tot = curv.score = maxv.score = 0;
11083 X   for (; lpos <= dmax->stop; lpos++) {
11084 X     ctot = ppst->pam_l;
11085 X     ci = -1;
11086 X     for (im = 0, ii=0; im < nm; im++,ii+=f_str->nmoff) {
11087 X       if (aa0p[ii] < 32 && (pv = pam2[aa0p[ii]][*aa1p]) > ctot) {
11088 X        ctot = pv;
11089 X        ci = ii;
11090 X       }
11091 X     }
11092 X     tot += ctot;
11093 X     if (ci >= 0) {
11094 X       if (ci >= n0) {fprintf(stderr," warning - ci off end %d/%d\n",ci,n0);}
11095 X       else {
11096 X        *aa0pt++ = aa0p[ci];
11097 X        aa0p[ci] +=  32;
11098 X        aa0t_flg=1;
11099 X       }
11100 X     }
11101 X     aa0p++; aa1p++;
11102 X   }
11103 X
11104 X   if (aa0t_flg) {
11105 X     dmax->dp -= f_str->aa0ix;         /* shift ->dp for aa0t */
11106 X     if ((ci=(int)(aa0pt-f_str->aa0t)) > n0) {
11107 X       fprintf(stderr," warning - aapt off %d/%d end\n",ci,n0);
11108 X     }
11109 X     else 
11110 X       *aa0pt++ = 0;                   /* skip over NULL */
11111 X
11112 X     aa0pt = &f_str->aa0t[f_str->aa0ix];
11113 X     aa1p = &aa1[lp0];
11114 X
11115 X     /*
11116 X     for (im = 0; im < f_str->nmoff; im++)
11117 X       fprintf(stderr,"%c:%c,",ppst->sq[aa0pt[im]],ppst->sq[aa1p[im]]);
11118 X     fprintf(stderr,"- %3d (%3d:%3d)\n",dmax->score,f_str->aa0ix,lp0);
11119 X     */
11120 X
11121 X     f_str->aa0ix += f_str->nmoff;     /* update offset into aa0t */
11122 X   }
11123 X   /*
11124 X      fprintf(stderr," ma_spam returning: %d\n",tot);
11125 X   */
11126 X   return tot;
11127 }
11128 X
11129 static int
11130 m0_spam (unsigned char *aa0, const unsigned char *aa1, int n1,
11131 X        struct savestr *dmax, int **pam2,
11132 X        struct f_struct *f_str)
11133 {
11134 X   int tpos, lpos, lend, im, ii, nm;
11135 X   int     tot, ctot, pv;
11136 X   struct {
11137 X     int     start, stop, score;
11138 X   } curv, maxv;
11139 X   const unsigned char *aa0p, *aa1p;
11140 X
11141 X   lpos = dmax->start;                 /* position in library sequence */
11142 X   tpos = lpos - dmax->dp + f_str->noff; /* position in query sequence */
11143 X   if (tpos > 0) {
11144 X     if (lpos-tpos >= 0) {
11145 X       lpos = dmax->start -= tpos;    /* force global alignment, reset start*/
11146 X       tpos = 0;
11147 X     }
11148 X     else {
11149 X       tpos -= lpos;
11150 X       lpos = dmax->start = 0;
11151 X     }
11152 X   }
11153 X
11154 X   nm = f_str->nm0;
11155 X   lend = dmax->stop;
11156 X   if (n1 - (lpos + f_str->nmoff-2) < 0 ) {
11157 X     lend = dmax->stop = (lpos - tpos) + f_str->nmoff-2;
11158 X     if (lend >= n1) lend = n1-1;
11159 X   }
11160 X
11161 X   aa1p = &aa1[lpos];
11162 X   aa0p = &aa0[tpos];
11163 X
11164 X   curv.start = lpos;
11165 X
11166 X   tot = curv.score = maxv.score = 0;
11167 X   for (; lpos <= lend; lpos++) {
11168 X     ctot = -10000;
11169 X     for (im = 0, ii=0; im < nm; im++,ii+=f_str->nmoff) {
11170 X       if ((pv = pam2[aa0p[ii]][*aa1p]) > ctot) {
11171 X        ctot = pv;
11172 X       }
11173 X     }
11174 X     tot += ctot;
11175 X     aa0p++; aa1p++;
11176 X   }
11177 X
11178 X   /* reset dmax if necessary */
11179 X
11180 X   return tot;
11181 }
11182 X
11183 /* sconn links up non-overlapping alignments and calculates the score */
11184 X
11185 int sconn (struct savestr **v, int n, int cgap, struct f_struct *f_str,
11186 X          struct rstruct *rst, struct pstruct *ppst,
11187 X          const unsigned char *aa0, int n0,
11188 X          const unsigned char *aa1, int n1,
11189 X          int opt_prob)
11190 {
11191 X   int     i, si, cmpp ();
11192 X   struct slink *start, *sl, *sj, *so, sarr[MAXSAV];
11193 X   int     lstart, plstop;
11194 X   double tatprob;
11195 X
11196 X   /* sarr[] saves each alignment score/position, and provides a link
11197 X      back to the previous alignment that maximizes the score */
11198 X
11199 X   /*  sort the score left to right in lib pos */
11200 X   kpsort (v, n);
11201 X
11202 X   start = NULL;
11203 X
11204 X   /* for the remaining runs, see if they fit */
11205 X   for (i = 0, si = 0; i < n; i++) {
11206 X
11207 X     /* if the score is less than the gap penalty, it never helps */
11208 X     if (!opt_prob && (v[i]->score < cgap) ){ continue; }
11209 X
11210 X     lstart = v[i]->start;
11211 X
11212 X     /* put the run in the group */
11213 X     sarr[si].vp = v[i];
11214 X     sarr[si].score = v[i]->score;
11215 X     sarr[si].next = NULL;
11216 X     sarr[si].prev = NULL;
11217 X     sarr[si].tat = NULL;
11218 X     
11219 X     if(opt_prob) {
11220 X       sarr[si].tatprob = 
11221 X        calc_tatusov(NULL, &sarr[si], aa0, n0, aa1, n1,
11222 X                     ppst->pam2[0],ppst->nsq, f_str,
11223 X                     ppst->pseudocts, opt_prob,ppst->zsflag);
11224 X       sarr[si].tat = sarr[si].newtat;
11225 X     }
11226 X
11227 X     /* if it fits, then increase the score */
11228 X     for (sl = start; sl != NULL; sl = sl->next) {
11229 X       plstop = sl->vp->stop;
11230 X       /* if end < start or start > end, add score */
11231 X       if (plstop < lstart ) {
11232 X        if(!opt_prob) {
11233 X          sarr[si].score = sl->score + v[i]->score;
11234 X          sarr[si].prev = sl;
11235 X          /*
11236 X            fprintf(stderr,"sconn %d added %d/%d getting %d; si: %d, tat: %g\n",
11237 X            i,v[i]->start, v[i]->score,sarr[si].score,si, 2.0);
11238 X          */
11239 X          break;
11240 X        } else {
11241 X          tatprob = 
11242 X            calc_tatusov(sl, &sarr[si], aa0, n0, aa1, n1,
11243 X                         ppst->pam2[0], ppst->nsq, f_str,
11244 X                         ppst->pseudocts, opt_prob, ppst->zsflag);
11245 X          /* if our tatprob gets worse when we add this, forget it */
11246 X          if(tatprob > sarr[si].tatprob) {
11247 X            free(sarr[si].newtat->probs); /* get rid of new tat struct */
11248 X            free(sarr[si].newtat);
11249 X            continue;
11250 X          } else {
11251 X            sarr[si].tatprob = tatprob;
11252 X            free(sarr[si].tat->probs); /* get rid of old tat struct */
11253 X            free(sarr[si].tat);
11254 X            sarr[si].tat = sarr[si].newtat;
11255 X            sarr[si].prev = sl;
11256 X            sarr[si].score = sl->score + v[i]->score;
11257 X            /*
11258 X              fprintf(stderr,"sconn TAT %d added %d/%d getting %d; si: %d, tat: %g\n",
11259 X              i,v[i]->start, v[i]->score,sarr[si].score,si, tatprob);
11260 X            */
11261 X            break;
11262 X          }
11263 X        }
11264 X       }
11265 X     }
11266 X
11267 X     /*        now recalculate where the score fits - resort the scores */
11268 X     if (start == NULL) {
11269 X       start = &sarr[si];
11270 X     } else {
11271 X       if(!opt_prob) { /* sort by scores */
11272 X        for (sj = start, so = NULL; sj != NULL; sj = sj->next) {
11273 X          if (sarr[si].score > sj->score) { /* if new score > best score */
11274 X            sarr[si].next = sj;             /* previous best linked to best */
11275 X            if (so != NULL)            
11276 X              so->next = &sarr[si];         /* old best points to new best */
11277 X            else
11278 X              start = &sarr[si];
11279 X            break;
11280 X          }
11281 X          so = sj;                          /* old-best saved in so */
11282 X        }
11283 X       } else { /* sort by tatprobs */
11284 X        for (sj = start, so = NULL; sj != NULL; sj = sj->next) {
11285 X          if ( sarr[si].tatprob < sj->tatprob ||
11286 X               ((sarr[si].tatprob == sj->tatprob) && sarr[si].score > sj->score) ) {
11287 X            sarr[si].next = sj;
11288 X            if (so != NULL)
11289 X              so->next = &sarr[si];
11290 X            else
11291 X              start = &sarr[si];
11292 X            break;
11293 X          }
11294 X          so = sj;
11295 X        }
11296 X       }
11297 X     }
11298 X     si++;
11299 X   }
11300 X   
11301 X   if(opt_prob) {
11302 X     for (i = 0 ; i < si ; i++) {
11303 X       free(sarr[i].tat->probs);
11304 X       free(sarr[i].tat);
11305 X     }
11306 X   }
11307 X
11308 X   if (start != NULL) {
11309 X
11310 X     if(opt_prob)
11311 X       rst->escore = start->tatprob;
11312 X     else
11313 X       rst->escore = 2.0;
11314 X
11315 X     rst->segnum = rst->seglen = 0;
11316 X     for(sj = start ; sj != NULL; sj = sj->prev) {
11317 X       rst->segnum++;
11318 X       rst->seglen += sj->vp->stop - sj->vp->start + 1;
11319 X     }
11320 X     return (start->score);
11321 X   } else {
11322 X
11323 X     if(opt_prob)
11324 X       rst->escore = 1.0;
11325 X     else
11326 X       rst->escore = 2.0;
11327 X
11328 X     rst->segnum = rst->seglen = 0;
11329 X     return (0);
11330 X   }
11331 }
11332 X
11333 void
11334 kssort (struct savestr **v, int n)
11335 {
11336 X   int     gap, i, j;
11337 X   struct savestr *tmp;
11338 X
11339 X   for (gap = n / 2; gap > 0; gap /= 2)
11340 X      for (i = gap; i < n; i++)
11341 X        for (j = i - gap; j >= 0; j -= gap)
11342 X        {
11343 X           if (v[j]->score >= v[j + gap]->score)
11344 X              break;
11345 X           tmp = v[j];
11346 X           v[j] = v[j + gap];
11347 X           v[j + gap] = tmp;
11348 X        }
11349 }
11350 void
11351 kpsort (v, n)
11352 struct savestr *v[];
11353 int     n;
11354 {
11355 X   int     gap, i, j;
11356 X   struct savestr *tmp;
11357 X
11358 X   for (gap = n / 2; gap > 0; gap /= 2)
11359 X      for (i = gap; i < n; i++)
11360 X        for (j = i - gap; j >= 0; j -= gap)
11361 X        {
11362 X           if (v[j]->start <= v[j + gap]->start)
11363 X              break;
11364 X           tmp = v[j];
11365 X           v[j] = v[j + gap];
11366 X           v[j + gap] = tmp;
11367 X        }
11368 }
11369 X
11370 /* sorts alignments from right to left (back to front) based on stop */
11371 X
11372 void
11373 krsort (v, n)
11374 struct savestr *v[];
11375 int     n;
11376 {
11377 X   int     gap, i, j;
11378 X   struct savestr *tmp;
11379 X
11380 X   for (gap = n / 2; gap > 0; gap /= 2)
11381 X      for (i = gap; i < n; i++)
11382 X        for (j = i - gap; j >= 0; j -= gap)
11383 X        {
11384 X           if (v[j]->stop > v[j + gap]->stop)
11385 X              break;
11386 X           tmp = v[j];
11387 X           v[j] = v[j + gap];
11388 X           v[j + gap] = tmp;
11389 X        }
11390 }
11391 X
11392 int  do_walign (const unsigned char *aa0, int n0,
11393 X               const unsigned char *aa1, int n1,
11394 X               int frame,
11395 X               struct pstruct *ppst, 
11396 X               struct f_struct *f_str, 
11397 X               struct a_res_str *a_res,
11398 X               int *have_ares)
11399 {
11400 X  int hoff, n10;
11401 X  struct rstruct rst;
11402 X  int ib;
11403 X  unsigned char *aa0t;
11404 X  const unsigned char *aa1p;
11405 X
11406 #ifdef TFAST
11407 X  f_str->n10 = n10 = aatran(aa1,f_str->aa1x,n1,frame);
11408 X  aa1p = f_str->aa1x;
11409 #else
11410 X  n10 = n1;
11411 X  aa1p = aa1;
11412 #endif
11413 X
11414 X  do_fastf(f_str->aa0, n0, aa1p, n10, ppst, f_str, &rst, &hoff, 1);
11415 X
11416 X  /* the alignment portion takes advantage of the information left
11417 X     over in f_str after do_fastf is done.  in particular, it is
11418 X     easy to run a modified sconn() to produce the alignments.
11419 X
11420 X     unfortunately, the alignment display routine wants to have
11421 X     things encoded as with bd_align and sw_align, so we need to do that.
11422 X     */
11423 X
11424 X  if ((aa0t = (unsigned char *)calloc(n0+1,sizeof(unsigned char)))==NULL) {
11425 X    fprintf(stderr," cannot allocate aa0t %d\n",n0+1);
11426 X    exit(1);
11427 X  }
11428 X
11429 X   kssort (f_str->vptr, f_str->nsave);
11430 X   f_str->aa0ix = 0;
11431 X   if (f_str->nsave > f_str->nm0) f_str->nsave = f_str->nm0;
11432 X   for (ib=0; ib < f_str->nm0; ib++) {
11433 X     if (f_str->vptr[ib]->score > 0) {
11434 X       f_str->vptr[ib]->score = 
11435 X        ma_spam (f_str->aa0, n0, aa1p, f_str->vptr[ib], ppst, f_str);
11436 X     }
11437 X   }
11438 X
11439 X   /* after ma_spam is over, we need to reset aa0 */
11440 X   for (ib = 0; ib < n0; ib++) {
11441 X     if (f_str->aa0[ib] >= 32) f_str->aa0[ib] -= 32;
11442 X   }
11443 X
11444 X   kssort(f_str->vptr,f_str->nsave);
11445 X
11446 X   for ( ; f_str->nsave > 0; f_str->nsave--) 
11447 X     if (f_str->vptr[f_str->nsave-1]->score >0) break;
11448 X
11449 X  a_res->nres = sconn_a (aa0t,n0, ppst->param_u.fa.cgap, f_str,a_res);
11450 X  free(aa0t);
11451 X
11452 X  a_res->res = f_str->res;
11453 X  *have_ares = 0;
11454 X  return rst.score[0];
11455 }
11456 X
11457 /* this version of sconn is modified to provide alignment information */
11458 X
11459 int sconn_a (unsigned char *aa0, int n0, int cgap, 
11460 X            struct f_struct *f_str,
11461 X            struct a_res_str *a_res)
11462 {
11463 X   int     i, si, cmpp (), n;
11464 X   unsigned char *aa0p;
11465 X   int sx, dx, doff;
11466 X
11467 X   struct savestr **v;
11468 X   struct slink {
11469 X     int     score;
11470 X     struct savestr *vp;
11471 X     struct slink *snext;
11472 X     struct slink *aprev;
11473 X   } *start, *sl, *sj, *so, sarr[MAXSAV];
11474 X   int     lstop, plstart;
11475 X   int *res, nres, tres;
11476 X
11477 /*      sort the score left to right in lib pos */
11478 X
11479 X   v = f_str->vptr;
11480 X   n = f_str->nsave;
11481 X
11482 X   krsort (v, n);      /* sort from left to right in library */
11483 X
11484 X   start = NULL;
11485 X
11486 /*      for each alignment, see if it fits */
11487 X
11488 X   for (i = 0, si = 0; i < n; i++) {
11489 X
11490 /*      if the score is less than the join threshold, skip it */
11491 X     if (v[i]->score < cgap) continue;
11492 X
11493 X     lstop = v[i]->stop;               /* have right-most lstart */
11494 X
11495 /*      put the alignment in the group */
11496 X
11497 X     sarr[si].vp = v[i];
11498 X     sarr[si].score = v[i]->score;
11499 X     sarr[si].snext = NULL;
11500 X     sarr[si].aprev = NULL;
11501 X
11502 /*      if it fits, then increase the score */
11503 /* start points to a sorted (by total score) list of candidate
11504 X   overlaps */
11505 X
11506 X     for (sl = start; sl != NULL; sl = sl->snext) { 
11507 X       plstart = sl->vp->start;
11508 X       if (plstart > lstop ) {
11509 X        sarr[si].score = sl->score + v[i]->score;
11510 X        sarr[si].aprev = sl;
11511 X        break;         /* quit as soon as the alignment has been added */
11512 X       }
11513 X     }
11514 X
11515 /* now recalculate the list of best scores */
11516 X     if (start == NULL)
11517 X       start = &sarr[si];      /* put the first one in the list */
11518 X     else
11519 X       for (sj = start, so = NULL; sj != NULL; sj = sj->snext) {
11520 X        if (sarr[si].score > sj->score) { /* new score better than old */
11521 X          sarr[si].snext = sj;         /* snext best after new score */
11522 X          if (so != NULL)
11523 X            so->snext = &sarr[si];     /* prev_best->snext points to best */
11524 X          else  start = &sarr[si];     /* start points to best */
11525 X          break;                       /* stop looking */
11526 X        }
11527 X        so = sj;               /* previous candidate best */
11528 X       }
11529 X     si++;                             /* increment to snext alignment */
11530 X   }
11531 X
11532 X   /* we have the best set of alignments, write them to *res */
11533 X   if (start != NULL) {
11534 X     res = f_str->res; /* set a destination for the alignment ops */
11535 X     tres = nres = 0;  /* alignment op length = 0 */
11536 X     aa0p = aa0;       /* point into query (needed for calcons later) */
11537 X     a_res->min1 = start->vp->start;   /* start in library */
11538 X     a_res->min0 = 0;                  /* start in query */
11539 X     for (sj = start; sj != NULL; sj = sj->aprev ) {
11540 X       doff = (int)(aa0p-aa0) - (sj->vp->start-sj->vp->dp+f_str->noff);
11541 X       /*
11542 X       fprintf(stderr,"doff: %3d\n",doff);
11543 X       */
11544 X       for (dx=sj->vp->start,sx=sj->vp->start-sj->vp->dp+f_str->noff;
11545 X           dx <= sj->vp->stop; dx++) {
11546 X        *aa0p++ = f_str->aa0t[sx++];   /* copy residue into aa0 */
11547 X        tres++;                        /* bump alignment counter */
11548 X        res[nres++] = 0;               /* put 0-op in res */
11549 X       }
11550 X       sj->vp->dp -= doff;
11551 X       if (sj->aprev != NULL) {
11552 X        if (sj->aprev->vp->start - sj->vp->stop - 1 > 0 )
11553 X        /* put an insert op into res to get to next aligned block */
11554 X          tres += res[nres++] = (sj->aprev->vp->start - sj->vp->stop - 1);
11555 X       }
11556 X       /*
11557 X       fprintf(stderr,"t0: %3d, tx: %3d, l0: %3d, lx: %3d, dp: %3d noff: %3d, score: %3d\n",
11558 X              sj->vp->start - sj->vp->dp + f_str->noff,
11559 X              sj->vp->stop - sj->vp->dp + f_str->noff,
11560 X              sj->vp->start,sj->vp->stop,sj->vp->dp,
11561 X              f_str->noff,sj->vp->score);
11562 X       fprintf(stderr,"%3d - %3d: %3d\n",
11563 X              sj->vp->start,sj->vp->stop,sj->vp->score);
11564 X       */
11565 X       a_res->max1 = sj->vp->stop;
11566 X       a_res->max0 = a_res->max1 - sj->vp->dp + f_str->noff;
11567 X     }
11568 X
11569 X     /*
11570 X     fprintf(stderr,"(%3d - %3d):(%3d - %3d)\n",
11571 X     a_res->min0,a_res->max0,a_res->min1,a_res->max1);
11572 X     */
11573 X
11574 X     /* now replace f_str->aa0t with aa0 */
11575 X     for (i=0; i<n0; i++) f_str->aa0t[i] = aa0[i];
11576 X
11577 X     return tres;
11578 X   }
11579 X   else return (0);
11580 }
11581 X
11582 /* calculate the 100% identical score */
11583 int
11584 shscore(unsigned char *aa0, int n0, int **pam2, int nsq)
11585 {
11586 X  int i, sum;
11587 X  for (i=0,sum=0; i<n0; i++)
11588 X    if (aa0[i]!=0 && aa0[i]<=nsq) sum += pam2[aa0[i]][aa0[i]];
11589 X  return sum;
11590 }
11591 X
11592 void
11593 pre_cons(const unsigned char *aa1, int n1, int frame, struct f_struct *f_str) {
11594 X
11595 #ifdef TFAST
11596 X  f_str->n10=aatran(aa1,f_str->aa1x,n1,frame);
11597 #endif
11598 }
11599 X
11600 /* aln_func_vals - set up aln.qlfact, qlrev, llfact, llmult, frame, llrev */
11601 /* call from calcons, calc_id, calc_code */
11602 void 
11603 aln_func_vals(int frame, struct a_struct *aln) {
11604 X
11605 #ifdef TFAST
11606 X  aln->qlrev = 0;
11607 X  aln->qlfact = 1;
11608 X  aln->llfact = aln->llmult = 3;
11609 X  aln->frame = 0;
11610 X  if (frame > 3) aln->llrev = 1;
11611 #else   /* FASTF */
11612 X  aln->llfact = aln->qlfact = aln->llmult = 1;
11613 X  aln->llrev = aln->qlrev = 0;
11614 X  aln->frame = 0;
11615 #endif
11616 }
11617 X
11618 #include "a_mark.h"
11619 X
11620 int calcons(const unsigned char *aa0, int n0,
11621 X           const unsigned char *aa1, int n1,
11622 X           int *nc,
11623 X           struct a_struct *aln, 
11624 X           struct a_res_str a_res,
11625 X           struct pstruct pst,
11626 X           char *seqc0, char *seqc1, char *seqca,
11627 X           struct f_struct *f_str)
11628 {
11629 X  int i0, i1, nn1, n0t;
11630 X  int op, lenc, len_gap, nd, ns, itmp;
11631 X  const unsigned char *aa1p;
11632 X  char *sp0, *sp1, *sq, *spa;
11633 X  int *rp;
11634 X  int mins, smins;
11635 X
11636 X  /* do not allow low complexity */
11637 X  sq = pst.sq;
11638 X  
11639 #ifndef TFAST
11640 X  aa1p = aa1;
11641 X  nn1 = n1;
11642 #else
11643 X  aa1p = f_str->aa1x;
11644 X  nn1 = f_str->n10;
11645 #endif
11646 X
11647 X  /* first fill in the ends */
11648 X  /*   a_res.min0--; a_res.min1--; */
11649 X  n0 -= (f_str->nm0-1);
11650 X
11651 X  aln->amin0 = a_res.min0;
11652 X  aln->amin1 = a_res.min1;
11653 X  aln->amax0 = a_res.max0;
11654 X  aln->amax1 = a_res.max1;
11655 X
11656 X  if (min(a_res.min0,a_res.min1)<aln->llen || aln->showall==1) {
11657 X    /* will we show all the start ?*/ 
11658 X    smins=0;
11659 X    mins = min(a_res.min1,aln->llen/2);
11660 X    aancpy(seqc1,(char *)(aa1p+a_res.min1-mins),mins,pst);
11661 X    aln->smin1 = a_res.min1-mins;
11662 X    if ((mins-a_res.min0)>0) {
11663 X      memset(seqc0,' ',mins-a_res.min0);
11664 X      aancpy(seqc0+mins-a_res.min0,(char *)f_str->aa0t,a_res.min0,pst);
11665 X      aln->smin0 = 0;
11666 X    }
11667 X    else {
11668 X      aancpy(seqc0,(char *)f_str->aa0t+a_res.min0-mins,mins,pst);
11669 X      aln->smin0 = a_res.min0-mins;
11670 X    }
11671 X  }
11672 X  else {
11673 X    mins= min(aln->llen/2,min(a_res.min0,a_res.min1));
11674 X    smins=mins;
11675 X    aln->smin0=a_res.min0;
11676 X    aln->smin1=a_res.min1;
11677 X    aancpy(seqc0,(char *)f_str->aa0t+a_res.min0-mins,mins,pst);
11678 X    aancpy(seqc1,(char *)aa1p+a_res.min1-mins,mins,pst);
11679 X  }
11680 X
11681 X  memset(seqca,M_BLANK,mins);
11682 X
11683 /* now get the middle */
11684 X
11685 X  spa = seqca+mins;
11686 X  sp0 = seqc0+mins;
11687 X  sp1 = seqc1+mins;
11688 X  rp = a_res.res;
11689 X  n0t = lenc = len_gap = aln->nident = aln->nsim = aln->ngap_q = aln->ngap_l = op = 0;
11690 X  i0 = a_res.min0;
11691 X  i1 = a_res.min1;
11692 X  
11693 X  while (i0 < a_res.max0 || i1 < a_res.max1) {
11694 X    if (op == 0 && *rp == 0) {
11695 X      op = *rp++;
11696 X
11697 X      if ((itmp=pst.pam2[0][f_str->aa0t[i0]][aa1p[i1]])<0) { *spa = M_NEG; }
11698 X      else if (itmp == 0) { *spa = M_ZERO;}
11699 X      else {*spa = M_POS;}
11700 X      if (*spa == M_ZERO || *spa == M_POS) { aln->nsim++;}
11701 X
11702 X      *sp0 = sq[f_str->aa0t[i0++]];
11703 X      *sp1 = sq[aa1p[i1++]];
11704 X      n0t++;
11705 X      lenc++;
11706 X      if (toupper(*sp0) == toupper(*sp1)) {aln->nident++; *spa = M_IDENT;}
11707 X      sp0++; sp1++; spa++;
11708 X    }
11709 X    else {
11710 X      if (op==0) { op = *rp++;}
11711 X      if (op>0) {
11712 X       *sp0++ = '-';
11713 X       *sp1++ = sq[aa1p[i1++]];
11714 X       *spa++ = M_DEL;
11715 X       op--;
11716 X       len_gap++;
11717 X       lenc++;
11718 X      }
11719 X      else {
11720 X       *sp0++ = sq[f_str->aa0t[i0++]];
11721 X       *sp1++ = '-';
11722 X       *spa++ = M_DEL;
11723 X       op++;
11724 X       n0t++;
11725 X       len_gap++;
11726 X       lenc++;
11727 X      }
11728 X    }
11729 X  }
11730 X
11731 X  *spa = '\0';
11732 X  *nc = lenc-len_gap;
11733 X
11734 X  /* now we have the middle, get the right end */
11735 X  /* ns is amount to be shown */
11736 X  /* nd is amount remaining to be shown */
11737 X  ns = mins + lenc + aln->llen;
11738 X  ns -= (itmp = ns %aln->llen);
11739 X  if (itmp>aln->llen/2) ns += aln->llen;
11740 X  nd = ns - (mins+lenc);
11741 X  if (nd > max(n0t-a_res.max0,nn1-a_res.max1)) nd = max(n0t-a_res.max0,nn1-a_res.max1);
11742 X  
11743 X  if (aln->showall==1) {
11744 X    nd = max(n0t-a_res.max0,nn1-a_res.max1);   /* reset for showall=1 */
11745 X    /* get right end */
11746 X    /* there isn't any aa0 to get */
11747 X    memset(seqc0+mins+lenc,' ',n0t-a_res.max0);
11748 X    aancpy(seqc1+mins+lenc,(char *)aa1p+a_res.max1,nn1-a_res.max1,pst);
11749 X    /* fill with blanks - this is required to use one 'nc' */
11750 X    memset(seqc0+mins+lenc+n0t-a_res.max0,' ',nd-(n0t-a_res.max0));
11751 X    memset(seqc1+mins+lenc+nn1-a_res.max1,' ',nd-(nn1-a_res.max1));
11752 X  }
11753 X  else {
11754 X    memset(seqc0+mins+lenc,' ',nd);
11755 X    if ((nd-(nn1-a_res.max1))>0) {
11756 X      aancpy(seqc1+mins+lenc,(char *)aa1p+a_res.max1,nn1-a_res.max1,pst);
11757 X      memset(seqc1+mins+lenc+nn1-a_res.max1,' ',nd-(nn1-a_res.max1));
11758 X    }
11759 X    else aancpy(seqc1+mins+lenc,(char *)aa1p+a_res.max1,nd,pst);
11760 X  }
11761 X  
11762 X  return mins+lenc+nd;
11763 }
11764 X
11765 int calcons_a(const unsigned char *aa0, unsigned char *aa0a, int n0,
11766 X             const unsigned char *aa1, int n1,
11767 X             int *nc,
11768 X             struct a_struct *aln,
11769 X             struct a_res_str a_res,
11770 X             struct pstruct pst,
11771 X             char *seqc0, char *seqc0a, char *seqc1, char *seqca,
11772 X             char *ann_arr, struct f_struct *f_str)
11773 {
11774 X  int i0, i1, nn1, n0t;
11775 X  int op, lenc, len_gap, nd, ns, itmp;
11776 X  const unsigned char *aa1p;
11777 X  char *sp0, *sp0a, *sp1, *sq, *spa;
11778 X  int *rp;
11779 X  int mins, smins;
11780 X
11781 X  /* do not allow low complexity */
11782 X  sq = pst.sq;
11783 X  
11784 #ifndef TFAST
11785 X  aa1p = aa1;
11786 X  nn1 = n1;
11787 #else
11788 X  aa1p = f_str->aa1x;
11789 X  nn1 = f_str->n10;
11790 #endif
11791 X
11792 X  aln->amin0 = a_res.min0;
11793 X  aln->amin1 = a_res.min1;
11794 X  aln->amax0 = a_res.max0;
11795 X  aln->amax1 = a_res.max1;
11796 X
11797 X  /* first fill in the ends */
11798 X  n0 -= (f_str->nm0-1);
11799 X
11800 X  if (min(a_res.min0,a_res.min1)<aln->llen || aln->showall==1) {
11801 X    /* will we show all the start ?*/ 
11802 X    smins=0;
11803 X    mins = min(a_res.min1,aln->llen/2);
11804 X    aancpy(seqc1,(char *)(aa1p+a_res.min1-mins),mins,pst);
11805 X    aln->smin1 = a_res.min1-mins;
11806 X    if ((mins-a_res.min0)>0) {
11807 X      memset(seqc0,' ',mins-a_res.min0);
11808 X      aancpy(seqc0+mins-a_res.min0,(char *)f_str->aa0t,a_res.min0,pst);
11809 X      aln->smin0 = 0;
11810 X    }
11811 X    else {
11812 X      aancpy(seqc0,(char *)f_str->aa0t+a_res.min0-mins,mins,pst);
11813 X      aln->smin0 = a_res.min0-mins;
11814 X    }
11815 X  }
11816 X  else {
11817 X    mins= min(aln->llen/2,min(a_res.min0,a_res.min1));
11818 X    smins=mins;
11819 X    aln->smin0=a_res.min0;
11820 X    aln->smin1=a_res.min1;
11821 X    aancpy(seqc0,(char *)f_str->aa0t+a_res.min0-mins,mins,pst);
11822 X    aancpy(seqc1,(char *)aa1p+a_res.min1-mins,mins,pst);
11823 X  }
11824 X
11825 X  memset(seqca,M_BLANK,mins);
11826 X  memset(seqc0a,' ',mins);
11827 X
11828 /* now get the middle */
11829 X
11830 X  spa = seqca+mins;
11831 X  sp0 = seqc0+mins;
11832 X  sp0a = seqc0a+mins;
11833 X  sp1 = seqc1+mins;
11834 X  rp = a_res.res;
11835 X  n0t = lenc = len_gap = aln->nident = aln->nsim = aln->ngap_q = aln->ngap_l = op = 0;
11836 X  i0 = a_res.min0;
11837 X  i1 = a_res.min1;
11838 X  
11839 X  while (i0 < a_res.max0 || i1 < a_res.max1) {
11840 X    if (op == 0 && *rp == 0) {
11841 X      op = *rp++;
11842 X
11843 X      if ((itmp=pst.pam2[0][f_str->aa0t[i0]][aa1p[i1]])<0) { *spa = M_NEG; }
11844 X      else if (itmp == 0) { *spa = M_ZERO;}
11845 X      else {*spa = M_POS;}
11846 X      if (*spa == M_ZERO || *spa == M_POS) { aln->nsim++;}
11847 X
11848 X      *sp0a++ = ' ';
11849 X      *sp0 = sq[f_str->aa0t[i0++]];
11850 X      *sp1 = sq[aa1p[i1++]];
11851 X      n0t++;
11852 X      lenc++;
11853 X      if (toupper(*sp0) == toupper(*sp1)) {aln->nident++; *spa = M_IDENT;}
11854 X      sp0++; sp1++; spa++;
11855 X    }
11856 X    else {
11857 X      if (op==0) { op = *rp++;}
11858 X      if (op>0) {
11859 X       *sp0++ = '-';
11860 X       *sp0a++ = ' ';
11861 X       *sp1++ = sq[aa1p[i1++]];
11862 X       *spa++ = M_DEL;
11863 X       op--;
11864 X       len_gap++;
11865 X       lenc++;
11866 X      }
11867 X      else {
11868 X       *sp0++ = sq[f_str->aa0t[i0++]];
11869 X       *sp0a++ = ' ';
11870 X       *sp1++ = '-';
11871 X       *spa++ = M_DEL;
11872 X       op++;
11873 X       n0t++;
11874 X       len_gap++;
11875 X       lenc++;
11876 X      }
11877 X    }
11878 X  }
11879 X
11880 X  *sp0a = *spa = '\0';
11881 X  *nc = lenc-len_gap;
11882 X
11883 X  /* now we have the middle, get the right end */
11884 X  /* ns is amount to be shown */
11885 X  /* nd is amount remaining to be shown */
11886 X  ns = mins + lenc + aln->llen;
11887 X  ns -= (itmp = ns %aln->llen);
11888 X  if (itmp>aln->llen/2) ns += aln->llen;
11889 X  nd = ns - (mins+lenc);
11890 X  if (nd > max(n0t-a_res.max0,nn1-a_res.max1)) nd = max(n0t-a_res.max0,nn1-a_res.max1);
11891 X  
11892 X  if (aln->showall==1) {
11893 X    nd = max(n0t-a_res.max0,nn1-a_res.max1);   /* reset for showall=1 */
11894 X    /* get right end */
11895 X    /* there isn't any aa0 to get */
11896 X    memset(seqc0+mins+lenc,' ',n0t-a_res.max0);
11897 X    aancpy(seqc1+mins+lenc,(char *)aa1p+a_res.max1,nn1-a_res.max1,pst);
11898 X    /* fill with blanks - this is required to use one 'nc' */
11899 X    memset(seqc0+mins+lenc+n0t-a_res.max0,' ',nd-(n0t-a_res.max0));
11900 X    memset(seqc1+mins+lenc+nn1-a_res.max1,' ',nd-(nn1-a_res.max1));
11901 X  }
11902 X  else {
11903 X    memset(seqc0+mins+lenc,' ',nd);
11904 X    if ((nd-(nn1-a_res.max1))>0) {
11905 X      aancpy(seqc1+mins+lenc,(char *)aa1p+a_res.max1,nn1-a_res.max1,pst);
11906 X      memset(seqc1+mins+lenc+nn1-a_res.max1,' ',nd-(nn1-a_res.max1));
11907 X    }
11908 X    else aancpy(seqc1+mins+lenc,(char *)aa1p+a_res.max1,nd,pst);
11909 X  }
11910 X  
11911 X  return mins+lenc+nd;
11912 }
11913 X
11914 void aa0shuffle(unsigned char *aa0, int n0, struct f_struct *f_str) {
11915 X
11916 X  int i, j, k;
11917 X  unsigned char tmp;
11918 X
11919 X  for (i = f_str->nmoff-1 ; --i ; ) {
11920 X
11921 X    /* j = nrand(i); if (i == j) continue;*/       /* shuffle columns */ 
11922 X    j = (f_str->nmoff - 2) - i; if (i <= j) break; /* reverse columns */
11923 X
11924 X    /* swap all i'th column residues for all j'th column residues */
11925 X    for(k = 0 ; k < f_str->nm0 ; k++) {
11926 X      tmp = aa0[(k * (f_str->nmoff)) + i];
11927 X      aa0[(k * (f_str->nmoff)) + i] = aa0[(k * (f_str->nmoff)) + j];
11928 X      aa0[(k * (f_str->nmoff)) + j] = tmp;
11929 X    }
11930 X  }
11931 }
11932 X
11933 /* build an array of match/ins/del - length strings */
11934 int calc_code(const unsigned char *aa0, const int n0,
11935 X             const unsigned char *aa1, const int n1,
11936 X             struct a_struct *aln,
11937 X             struct a_res_str a_res,
11938 X             struct pstruct pst,
11939 X             char *al_str, int al_str_n, struct f_struct *f_str)
11940 {
11941 X  int i0, i1, nn1;
11942 X  int op, lenc, len_gap;
11943 X  int p_op, op_cnt;
11944 X  const unsigned char *aa1p;
11945 X  char tmp_cnt[20];
11946 X  char sp0, sp1, *sq;
11947 X  int *rp;
11948 X  int mins, smins;
11949 X  int fnum = 0;
11950 X
11951 X  if (pst.ext_sq_set) {
11952 X    sq = pst.sqx;
11953 X  }
11954 X  else {
11955 X    sq = pst.sq;
11956 X  }
11957 X
11958 #ifndef TFAST
11959 X  aa1p = aa1;
11960 X  nn1 = n1;
11961 #else
11962 X  aa1p = f_str->aa1x;
11963 X  nn1 = f_str->n10;
11964 #endif
11965 X
11966 X  rp = a_res.res;
11967 X  lenc = len_gap = aln->nident = aln->nsim = aln->ngap_q = aln->ngap_l = aln->nfs = op = p_op = 0;
11968 X  op_cnt = 0;
11969 X
11970 X  i0 = a_res.min0;
11971 X  i1 = a_res.min1;
11972 X  tmp_cnt[0]='\0';
11973 X  
11974 X  fnum = f_str->aa0ti[i0] + 1;
11975 X  while (i0 < a_res.max0 || i1 < a_res.max1) {
11976 X    if (op == 0 && *rp == 0) {
11977 X      if (p_op == 0) {         op_cnt++;}
11978 X      else {
11979 X       update_code(al_str,al_str_n-strlen(al_str),p_op,op_cnt,fnum);
11980 X       op_cnt = 1; p_op = 0;
11981 X       fnum = f_str->aa0ti[i0] + 1;
11982 X      }
11983 X      op = *rp++;
11984 X      lenc++;
11985 X      if (pst.pam2[0][f_str->aa0t[i0]][aa1p[i1]]>=0) {aln->nsim++;}
11986 X      sp0 = pst.sq[f_str->aa0t[i0++]];
11987 X      sp1 = pst.sq[aa1p[i1++]];
11988 X      if (toupper(sp0) == toupper(sp1)) aln->nident++;
11989 X    }
11990 X    else {
11991 X      if (op==0) op = *rp++;
11992 X      if (op>0) {
11993 X       if (p_op == 1) { op_cnt++;}
11994 X       else {
11995 X         update_code(al_str,al_str_n - strlen(al_str),p_op,op_cnt,fnum);
11996 X         op_cnt = 1; p_op = 1; fnum = f_str->aa0ti[i0] + 1;
11997 X       }
11998 X       op--; lenc++; i1++; len_gap++;
11999 X      }
12000 X      else {
12001 X       if (p_op == 2) { op_cnt++;}
12002 X       else {
12003 X         update_code(al_str,al_str_n - strlen(al_str),p_op,op_cnt,fnum);
12004 X         op_cnt = 1; p_op = 2; fnum = f_str->aa0ti[i0] + 1;
12005 X       }
12006 X       op++; lenc++; i0++; len_gap++;
12007 X      }
12008 X    }
12009 X  }
12010 X  update_code(al_str,al_str_n - strlen(al_str),p_op,op_cnt,fnum);
12011 X
12012 X  return lenc - len_gap;
12013 }
12014 X
12015 void
12016 update_code(char *al_str, int al_str_max, int op, int op_cnt, int fnum) {
12017 X
12018 X  char op_char[4]={"=-+"};
12019 X  char tmp_cnt[20];
12020 X
12021 X  if (op == 0)
12022 X    sprintf(tmp_cnt,"%c%d[%d]",op_char[op],op_cnt,fnum);
12023 X  else
12024 X    sprintf(tmp_cnt,"%c%d",op_char[op],op_cnt);
12025 X
12026 X  strncat(al_str,tmp_cnt,al_str_max);
12027 }
12028 X
12029 int calc_id(const unsigned char *aa0, int n0,
12030 X           const unsigned char *aa1, int n1,
12031 X           struct a_struct *aln,
12032 X           struct a_res_str a_res,
12033 X           struct pstruct pst,
12034 X           struct f_struct *f_str)
12035 {
12036 X  int i0, i1, nn1, n0t;
12037 X  int op, lenc, len_gap;
12038 X  const unsigned char *aa1p;
12039 X  int sp0, sp1;
12040 X  int *rp;
12041 X  int mins, smins;
12042 X  char *sq;
12043 X
12044 X  if (pst.ext_sq_set) {
12045 X    sq = pst.sqx;
12046 X  }
12047 X  else {
12048 X    sq = pst.sq;
12049 X  }
12050 X  
12051 #ifndef TFAST
12052 X  aa1p = aa1;
12053 X  nn1 = n1;
12054 #else
12055 X  aa1p = f_str->aa1x;
12056 X  nn1 = f_str->n10;
12057 #endif
12058 X
12059 X  /* first fill in the ends */
12060 X  /* a_res.min0--; a_res.min1--; */
12061 X  n0 -= (f_str->nm0-1);
12062 X
12063 X  /* now get the middle */
12064 X  rp = a_res.res;
12065 X  n0t = lenc = len_gap = aln->nident = aln->nsim = aln->ngap_q = aln->ngap_l = op = 0;
12066 X  i0 = a_res.min0;
12067 X  i1 = a_res.min1;
12068 X  
12069 X  while (i0 < a_res.max0 || i1 < a_res.max1) {
12070 X    if (op == 0 && *rp == 0) {
12071 X      op = *rp++;
12072 X      if (pst.pam2[0][f_str->aa0t[i0]][aa1p[i1]]>=0) {aln->nsim++;}
12073 X      sp0 = sq[f_str->aa0t[i0++]];
12074 X      sp1 = sq[aa1p[i1++]];
12075 X      n0t++;
12076 X      lenc++;
12077 X      if (toupper(sp0) == toupper(sp1)) aln->nident++;
12078 X    }
12079 X    else {
12080 X      if (op==0) { op = *rp++;}
12081 X      if (op>0) {
12082 X        i1++;
12083 X        op--;
12084 X        len_gap++;
12085 X        lenc++;
12086 X      }
12087 X      else {
12088 X        i0++;
12089 X        op++;
12090 X        n0t++;
12091 X        len_gap++;
12092 X        lenc++;
12093 X      }
12094 X    }
12095 X  }
12096 X  return lenc-len_gap;
12097 }
12098 X
12099 #ifdef PCOMPLIB
12100 X
12101 #include "structs.h"
12102 #include "p_mw.h"
12103 X
12104 void
12105 update_params(struct qmng_str *qm_msg,
12106 X             struct mngmsg *m_msg, struct pstruct *ppst)
12107 {
12108 X  m_msg->n0 = ppst->n0 = qm_msg->n0;
12109 X  m_msg->nm0 = qm_msg->nm0;
12110 X  m_msg->escore_flg = qm_msg->escore_flg;
12111 X  m_msg->qshuffle = qm_msg->qshuffle;
12112 }
12113 #endif
12114 SHAR_EOF
12115 chmod 0644 dropff2.c ||
12116 echo 'restore of dropff2.c failed'
12117 Wc_c="`wc -c < 'dropff2.c'`"
12118 test 48853 -eq "$Wc_c" ||
12119         echo 'dropff2.c: original size 48853, current size' "$Wc_c"
12120 fi
12121 # ============= dropfs2.c ==============
12122 if test -f 'dropfs2.c' -a X"$1" != X"-c"; then
12123         echo 'x - skipping dropfs2.c (File already exists)'
12124 else
12125 echo 'x - extracting dropfs2.c (Text)'
12126 sed 's/^X//' << 'SHAR_EOF' > 'dropfs2.c' &&
12127 /* copyright (c) 1998, 1999 William R. Pearson and the U. of Virginia */
12128 X
12129 /*  $Name: fa_34_26_5 $ - $Id: dropfs2.c,v 1.40 2007/02/26 21:56:59 wrp Exp $ */
12130 X
12131 /* changed to return 2.0, rather than -1.0, for failure */
12132 X
12133 /* Feb 4, 2005 - modifications to allow searches with ktup=2 for very
12134 X   long queries.  This is a temporary solution to savemax(), spam()
12135 X   which do not preserve exact matches
12136 X
12137 X   do_fasts() has been modified to allow higher maxsav for do_walign
12138 X   than for do_work (2*nsegs, 6*nsegs)
12139 X */
12140 X
12141 /* this code implements the "fasts" algorithm, which compares a set of
12142 X   protein fragments to a protein sequence.  Comma's are used to separate
12143 X   the sequence fragments, which need not be the same length.
12144 X
12145 X   The expected input is:
12146 X
12147 X   >mgstm1
12148 X   MGDAPDFD,
12149 X   MILGYW,
12150 X   MLLEYTDS
12151 X
12152 X   The fragments do not need to be in the correct order (which is
12153 X   presumably unknown from the peptide sequencing.
12154 */
12155 X
12156 #include <stdio.h>
12157 #include <stdlib.h>
12158 #include <string.h>
12159 #include <ctype.h>
12160 #include <math.h>
12161 X
12162 #include "defs.h"
12163 #include "param.h"
12164 #include "tatstats.h"
12165 X
12166 #define EOSEQ 0
12167 #define ESS 49
12168 #define NMAP_X 23 /* for 'X' */
12169 #define NMAP_Z 24 /* for '*' */
12170 #define MAXHASH 32
12171 #define NMAP MAXHASH+1
12172 X
12173 static char *verstr="4.32 Feb 2007";
12174 X
12175 #define DROP_INTERN
12176 #include "drop_func.h"
12177 X
12178 int shscore(const unsigned char *aa0, const int n0, int **pam2, int nsq);
12179 static void update_code(char *al_str, int al_str_max, int op, int op_cnt, int fnum);
12180 extern void aancpy(char *to, char *from, int count, struct pstruct pst);
12181 X
12182 #ifdef TFAST
12183 extern int aatran(const unsigned char *ntseq, unsigned char *aaseq, const int maxs, const int frame);
12184 #endif
12185 X
12186 void savemax(struct dstruct *, struct f_struct *, int maxsav, int exact,int t_end);
12187 X
12188 int spam(const unsigned char *, const unsigned char *, int, struct savestr *, int **, struct f_struct *);
12189 int sconn(struct savestr **v,
12190 X         int nsave,
12191 X         struct f_struct *,
12192 X         struct rstruct *,
12193 X         struct pstruct *,
12194 X         const unsigned char *aa0, int n0,
12195 X         const unsigned char *aa1, int n1,
12196 X         int opt_prob);
12197 X
12198 void kpsort(struct savestr **, int);
12199 void kssort(struct savestr **, int);    /* sort by score */
12200 int sconn_a(unsigned char *, int, 
12201 X           const unsigned char *, int,
12202 X           struct f_struct *, 
12203 X           struct a_res_str *,
12204 X           struct pstruct *);
12205 void kpsort(struct savestr **, int);
12206 X
12207 /* initialize for fasta */
12208 X
12209 void
12210 init_work (unsigned char *aa0, const int n0, 
12211 X          struct pstruct *ppst,
12212 X          struct f_struct **f_arg
12213 X          )
12214 {
12215 X   int mhv, phv;
12216 X   int hmax, nsegs;
12217 X   int i0, ib, hv, old_hv;
12218 X   int pamfact;
12219 X   struct f_struct *f_str;
12220 X   /* these used to be globals, but do not need to be */
12221 X   int ktup, fact, kt1;
12222 X
12223 X   int maxn0;
12224 X   int stmp;   /* temporary score */
12225 X   int i, j, q;
12226 X   int tat_size;
12227 X   int *res;
12228 X
12229 X   unsigned char *query;
12230 X   int k, l, m, n, N, length, index;
12231 X
12232 X   double *tatprobptr;
12233 X
12234 X   f_str = (struct f_struct *)calloc(1,sizeof(struct f_struct));
12235 X
12236 X   ppst->param_u.fa.pgap = ppst->gdelval + ppst->ggapval;
12237 X   ktup = ppst->param_u.fa.ktup;
12238 X   if ( ktup  > 2 ) {
12239 X     ktup = ppst->param_u.fa.ktup = 2;
12240 X   }
12241 X   fact = ppst->param_u.fa.scfact;
12242 X
12243 X   /* fasts3 cannot work with lowercase symbols as low complexity;
12244 X      thus, NMAP must be disabled; this depends on aascii['X']  */
12245 X   if (ppst->hsq[NMAP_X] == NMAP ) {ppst->hsq[NMAP_X]=1;}
12246 X   if (ppst->hsq[NMAP_Z] == NMAP ) {ppst->hsq[NMAP_Z]=1;}
12247 X   /* this does not work in a threaded environment */
12248 X   /*    else {fprintf(stderr," cannot find 'X'==NMAP\n");} */
12249 X
12250 X   for (i0 = 1, mhv = -1; i0 <= ppst->nsq; i0++)
12251 X      if (ppst->hsq[i0] < NMAP && ppst->hsq[i0] > mhv)  mhv = ppst->hsq[i0];
12252 X
12253 X   if (mhv <= 0) {
12254 X      fprintf (stderr, " maximum hsq <=0 %d\n", mhv);
12255 X      exit (1);
12256 X   }
12257 X
12258 X   for (f_str->kshft = 0; mhv > 0; mhv /= 2) f_str->kshft++;
12259 X
12260 /*      kshft = 2;      */
12261 X   kt1 = ktup-1;
12262 X   hv = 1;
12263 X   for (i0 = 0; i0 < ktup; i0++) hv = hv << f_str->kshft;
12264 X   hmax = hv;
12265 X   f_str->hmask = (hmax >> f_str->kshft) - 1;
12266 X
12267 X   if ((f_str->aa0t = (unsigned char *) calloc(n0+1, sizeof(char))) == NULL) {
12268 X     fprintf (stderr, " cannot allocate f_str0->aa0t array; %d\n",n0+1);
12269 X     exit (1);
12270 X   }
12271 X
12272 X   if ((f_str->aa0ti = (int *) calloc(n0+1, sizeof(int))) == NULL) {
12273 X     fprintf (stderr, " cannot allocate f_str0->aa0ti array; %d\n",n0+1);
12274 X     exit (1);
12275 X   }
12276 X
12277 X   if ((f_str->aa0b = (int *) calloc(n0+1, sizeof(int))) == NULL) {
12278 X     fprintf (stderr, " cannot allocate f_str0->aa0b array; %d\n",n0+1);
12279 X     exit (1);
12280 X   }
12281 X
12282 X   if ((f_str->aa0e = (int *) calloc(n0+1, sizeof(int))) == NULL) {
12283 X     fprintf (stderr, " cannot allocate f_str0->aa0e array; %d\n",n0+1);
12284 X     exit (1);
12285 X   }
12286 X
12287 X   if ((f_str->aa0i = (int *) calloc(n0+1, sizeof(int))) == NULL) {
12288 X     fprintf (stderr, " cannot allocate f_str0->aa0i array; %d\n",n0+1);
12289 X     exit (1);
12290 X   }
12291 X
12292 X   if ((f_str->aa0s = (int *) calloc(n0+1, sizeof(int))) == NULL) {
12293 X     fprintf (stderr, " cannot allocate f_str0->aa0s array; %d\n",n0+1);
12294 X     exit (1);
12295 X   }
12296 X
12297 X   if ((f_str->aa0l = (int *) calloc(n0+1, sizeof(int))) == NULL) {
12298 X     fprintf (stderr, " cannot allocate f_str0->aa0l array; %d\n",n0+1);
12299 X     exit (1);
12300 X   }
12301 X
12302 X   if ((f_str->harr = (int *) calloc (hmax, sizeof (int))) == NULL) {
12303 X     fprintf (stderr, " cannot allocate hash array: hmax: %d hmask: %d\n",
12304 X             hmax, f_str->hmask);
12305 X     exit (1);
12306 X   }
12307 X   if ((f_str->pamh1 = (int *) calloc (ppst->nsq+1, sizeof (int))) == NULL) {
12308 X     fprintf (stderr, " cannot allocate pamh1 array\n");
12309 X     exit (1);
12310 X   }
12311 X   if ((f_str->pamh2 = (int *) calloc (hmax, sizeof (int))) == NULL) {
12312 X     fprintf (stderr, " cannot allocate pamh2 array\n");
12313 X     exit (1);
12314 X   }
12315 X
12316 X   if ((f_str->link = (int *) calloc (n0, sizeof (int))) == NULL) {
12317 X     fprintf (stderr, " cannot allocate hash link array");
12318 X     exit (1);
12319 X   }
12320 X
12321 X   /* for FASTS/FASTM, we want to know when we get to the end of a peptide,
12322 X      so we can ensure that we set the end and restart */
12323 X
12324 X   if ((f_str->l_end = (int *) calloc (n0, sizeof (int))) == NULL) {
12325 X     fprintf (stderr, " cannot allocate link end array");
12326 X     exit (1);
12327 X   }
12328 X
12329 X   for (i0 = 0; i0 < hmax; i0++) f_str->harr[i0] = -1;
12330 X   for (i0 = 0; i0 < n0; i0++) f_str->link[i0] = -1;
12331 X   for (i0 = 0; i0 < n0; i0++) f_str->l_end[i0] = 0;
12332 X
12333 X   /* count the number of peptides */
12334 X   nsegs = 1;
12335 X   for (i0 = 0; i0 < n0; i0++) {
12336 X     if (aa0[i0] == ESS || aa0[i0] == 0) nsegs++;
12337 X   }
12338 X
12339 X   /* allocate space for peptides offsets, nm_u */
12340 X   if ((f_str->nmoff = (int *)calloc(nsegs+1, sizeof(int)))==NULL) {
12341 X     fprintf(stderr, " cannot allocat nmoff array: %d\n", nsegs);
12342 X     exit(1);
12343 X   }
12344 X
12345 X   if ((f_str->nm_u = (int *)calloc(nsegs+1, sizeof(int)))==NULL) {
12346 X     fprintf(stderr, " cannot allocat nm_u array: %d\n", nsegs);
12347 X     exit(1);
12348 X   }
12349 X
12350 X   phv = hv = 0;
12351 X   f_str->nmoff[0] = 0;
12352 X   f_str->nm0 = 1;
12353 X
12354 X   /* encode the aa0 array */
12355 X   if (kt1 > 0) {
12356 X     hv = ppst->hsq[aa0[0]];
12357 X     phv = ppst->pam2[0][aa0[0]][aa0[0]];
12358 X   }
12359 X
12360 X   for (i0=kt1 ; i0 < n0; i0++) {
12361 X     if (aa0[i0] == ESS || aa0[i0] == 0) {
12362 X       /*       fprintf(stderr," converted %d to 0\n",aa0[i0]); */
12363 X       aa0[i0] = EOSEQ;        /* set ESS to 0 */
12364 X       f_str->nmoff[f_str->nm0++] = i0+1; 
12365 X       f_str->l_end[i0-1] = 1;
12366 X       phv = hv = 0;
12367 X       if (kt1 > 0) {
12368 X        i0++;
12369 X        hv = ppst->hsq[aa0[i0]];
12370 X        phv = ppst->pam2[0][aa0[i0]][aa0[i0]];
12371 X       }
12372 X       continue;
12373 X     }
12374 X
12375 X     hv = ((hv & f_str->hmask) << f_str->kshft) + ppst->hsq[aa0[i0]];
12376 X     f_str->link[i0] = f_str->harr[hv];
12377 X     f_str->harr[hv] = i0;
12378 X     f_str->pamh2[hv] = (phv += ppst->pam2[0][aa0[i0]][aa0[i0]]);
12379 X     phv -= ppst->pam2[0][aa0[i0 - kt1]][aa0[i0 - kt1]];
12380 X   }
12381 X   f_str->l_end[n0-1] = 1;
12382 X
12383 X   f_str->nmoff[f_str->nm0] = n0+1;
12384 X
12385 X   /*
12386 #ifdef DEBUG
12387 X   fprintf(stderr, ">>%s\n",qtitle);
12388 X   for (j=0; j<f_str->nm0; j++) {
12389 X     for (i=f_str->nmoff[j]; i < f_str->nmoff[j+1]-1; i++) {
12390 X       fprintf(stderr,"%c",ppst->sq[aa0[i]]);
12391 X     }
12392 X     fprintf(stderr," %d\n",aa0[i]);
12393 X   }
12394 X
12395 X   for (j=1; j<=ppst->nsq; j++) {
12396 X     fprintf(stderr, "%c %d\n", ppst->sq[j], f_str->harr[j]);
12397 X   }
12398 X
12399 X   for (j=0; j<=n0; j++) {
12400 X     fprintf(stderr, "%c %d\n", ppst->sq[aa0[j]], f_str->link[j]);
12401 X   }
12402 X
12403 #endif
12404 X   */
12405 X
12406 X   /* build an integer array of the max score that can be achieved
12407 X      from that position - use in savemax to mark some segments as
12408 X      fixed */
12409 X
12410 X   /* setup aa0b[], aa0e[], which specify the begining and end of each
12411 X      segment */
12412 X
12413 X   stmp = 0;
12414 X   q = -1;
12415 X   for (ib = i0 = 0; i0 < n0; i0++) {
12416 X     f_str->aa0l[i0] = i0 - q;
12417 X     if (aa0[i0]==EOSEQ) {
12418 X       f_str->aa0b[i0] = -1;
12419 X       f_str->aa0e[i0] = -1;
12420 X       f_str->aa0i[i0] = -1;
12421 X       f_str->aa0l[i0] = -1;
12422 X       q = i0;
12423 X       if (i0 > 0)f_str->aa0s[i0-1] = stmp;
12424 X       stmp = 0;
12425 X       ib++;
12426 X     }
12427 X     else {
12428 X       stmp += ppst->pam2[0][aa0[i0]][aa0[i0]];
12429 X     }
12430 X
12431 X     f_str->aa0b[i0] =  f_str->nmoff[ib];
12432 X     f_str->aa0e[i0] =  f_str->nmoff[ib+1]-2;
12433 X     f_str->aa0i[i0] =  ib;
12434 X
12435 X     /*
12436 X     fprintf(stderr,"%2d %c: %2d %2d %2d\n",i0,ppst->sq[aa0[i0]],
12437 X            f_str->aa0b[i0],f_str->aa0e[i0],f_str->aa0i[i0]);
12438 X     */
12439 X   }
12440 X   f_str->aa0s[n0-1]=stmp;     /* save last best possible score */
12441 X
12442 X   /* maxsav - maximum number of peptide alignments saved in search */
12443 X   /* maxsav_w - maximum number of peptide alignments saved in
12444 X      alignment */
12445 X
12446 X   f_str->maxsav = max(MAXSAV,2*f_str->nm0);
12447 X   f_str->maxsav_w = max(MAXSAV,6*f_str->nm0);
12448 X
12449 X   if ((f_str->vmax = (struct savestr *)
12450 X       calloc(f_str->maxsav_w,sizeof(struct savestr)))==NULL) {
12451 X     fprintf(stderr, "Couldn't allocate vmax[%d].\n",f_str->maxsav_w);
12452 X     exit(1);
12453 X   }
12454 X
12455 X   if ((f_str->vptr = (struct savestr **)
12456 X       calloc(f_str->maxsav_w,sizeof(struct savestr *)))==NULL) {
12457 X     fprintf(stderr, "Couldn't allocate vptr[%d].\n",f_str->maxsav_w);
12458 X     exit(1);
12459 X   }
12460 X
12461 X   if ((f_str->sarr = (struct slink *)
12462 X       calloc(f_str->maxsav_w,sizeof(struct slink)))==NULL) {
12463 X     fprintf(stderr, "Couldn't allocate sarr[%d].\n",f_str->maxsav_w);
12464 X     exit(1);
12465 X   }
12466 X
12467 X   /* Tatusov Statistics Setup */
12468 X
12469 X   /* initialize priors array. */
12470 X   if((f_str->priors = (double *)calloc(ppst->nsq+1, sizeof(double))) == NULL) {
12471 X     fprintf(stderr, "Couldn't allocate priors array.\n");
12472 X     exit(1);
12473 X   }
12474 X
12475 X   calc_priors(f_str->priors, ppst, f_str, NULL, 0, ppst->pseudocts);
12476 X
12477 X   /* pre-calculate the Tatusov probability array for each full segment */
12478 X
12479 X   if(ppst->zsflag >= 1 && ppst->zsflag <= 3 && f_str->nm0 <= 10) {
12480 X
12481 X     tat_size = (1<<f_str->nm0) -1;
12482 X     f_str->dotat = 1;
12483 X     f_str->tatprobs = (struct tat_str **) malloc((size_t)tat_size*sizeof(struct tat_str *));
12484 X     if (f_str->tatprobs == NULL) {
12485 X       fprintf (stderr, " cannot allocate tatprobs array: %ld\n",
12486 X               tat_size * sizeof(struct tat_str *));
12487 X       exit (1);
12488 X     }
12489 X
12490 X     f_str->intprobs = (double **) malloc((size_t)tat_size * sizeof(double *));
12491 X     if(f_str->intprobs == NULL) {
12492 X       fprintf(stderr, "Couldn't allocate intprobs array.\n");
12493 X       exit(1);
12494 X     }
12495 X
12496 X     for(k = 0, l = f_str->nm0 ; k < l ; k++) {
12497 X       query = &(aa0[f_str->nmoff[k]]);
12498 X       length = f_str->nmoff[k+1] - f_str->nmoff[k] - 1;
12499 X
12500 X       /* this segment alone */
12501 X       index = (1 << k) - 1;
12502 X       generate_tatprobs(query, 0, length - 1, f_str->priors, ppst->pam2[0], ppst->nsq, &(f_str->tatprobs[index]), NULL);
12503 X
12504 X       /* integrate the probabilities */
12505 X       N = f_str->tatprobs[index]->highscore - f_str->tatprobs[index]->lowscore;
12506 X       tatprobptr = (double *) calloc(N+1, sizeof(double));
12507 X       if(tatprobptr == NULL) {
12508 X        fprintf(stderr, "Couldn't calloc tatprobptr.\n");
12509 X        exit(1);
12510 X       }
12511 X       f_str->intprobs[index] = tatprobptr;
12512 X
12513 X       for (i = 0; i <= N ; i++ ) {
12514 X        tatprobptr[i] = f_str->tatprobs[index]->probs[i];
12515 X        for (j = i + 1 ; j <= N ; j++ ) {
12516 X          tatprobptr[i] += f_str->tatprobs[index]->probs[j];
12517 X        }
12518 X       }
12519 X
12520 X       /* this segment built on top of all other subcombinations */
12521 X       for(i = 0, j = (1 << k) - 1 ; i < j ; i++) {
12522 X        index = (1 << k) + i;
12523 X        generate_tatprobs(query, 0, length - 1, f_str->priors, ppst->pam2[0], ppst->nsq, &(f_str->tatprobs[index]), f_str->tatprobs[i]);
12524 X
12525 X        /* integrate the probabilities */
12526 X        N = f_str->tatprobs[index]->highscore - f_str->tatprobs[index]->lowscore;
12527 X        tatprobptr = (double *) calloc(N+1, sizeof(double));
12528 X        if(tatprobptr == NULL) {
12529 X          fprintf(stderr, "Couldn't calloc tatprobptr.\n");
12530 X          exit(1);
12531 X        }
12532 X        f_str->intprobs[index] = tatprobptr;
12533 X       
12534 X        for (m = 0; m <= N ; m++ ) {
12535 X          tatprobptr[m] = f_str->tatprobs[index]->probs[m];
12536 X          for (n = m + 1 ; n <= N ; n++ ) {
12537 X            tatprobptr[m] += f_str->tatprobs[index]->probs[n];
12538 X          }
12539 X        }
12540 X       }
12541 X     }
12542 X   } else {
12543 X     f_str->dotat = 0;
12544 X     f_str->shuff_cnt = ppst->shuff_node;
12545 X   }
12546 X
12547 X   /* End of Tatusov Statistics Setup */
12548 X
12549 X   /*
12550 X   for (i0=1; i0<=ppst->nsq; i0++) {
12551 X     fprintf(stderr," %c: %2d ",ppst->sq[i0],f_str->harr[i0]);
12552 X     hv = f_str->harr[i0];
12553 X     while (hv >= 0) {
12554 X       fprintf(stderr," %2d",f_str->link[hv]);
12555 X       hv = f_str->link[hv];
12556 X     }
12557 X     fprintf(stderr,"\n");
12558 X   }
12559 X   */
12560 X
12561 /* this has been modified from 0..<ppst->nsq to 1..<=ppst->nsq because the
12562 X   pam2[0][0] is now undefined for consistency with blast
12563 */
12564 X   for (i0 = 1; i0 <= ppst->nsq; i0++)
12565 X     f_str->pamh1[i0] = ppst->pam2[0][i0][i0];
12566 X
12567 X   f_str->ndo = 0;
12568 X   f_str->noff = n0-1;
12569 X   if (f_str->diag==NULL) 
12570 X     f_str->diag = (struct dstruct *) calloc ((size_t)MAXDIAG,
12571 X                                             sizeof (struct dstruct));
12572 X   if (f_str->diag == NULL) {
12573 X      fprintf (stderr, " cannot allocate diagonal arrays: %ld\n",
12574 X             (long) MAXDIAG * (long) (sizeof (struct dstruct)));
12575 X      exit (1);
12576 X   }
12577 X
12578 #ifdef TFAST
12579 X   if ((f_str->aa1x =(unsigned char *)calloc((size_t)ppst->maxlen+2,
12580 X                                            sizeof(unsigned char)))
12581 X       == NULL) {
12582 X     fprintf (stderr, "cannot allocate aa1x array %d\n", ppst->maxlen+2);
12583 X     exit (1);
12584 X   }
12585 X   f_str->aa1x++;
12586 #endif
12587 X
12588 X   maxn0 = max(3*n0/2,MIN_RES);
12589 X   if ((res = (int *)calloc((size_t)maxn0,sizeof(int)))==NULL) {
12590 X     fprintf(stderr,"cannot allocate alignment results array %d\n",maxn0);
12591 X     exit(1);
12592 X   }
12593 X   f_str->res = res;
12594 X   f_str->max_res = maxn0;
12595 X
12596 X   *f_arg = f_str;
12597 }
12598 X
12599 X
12600 /* pstring1 is a message to the manager, currently 512 */
12601 /* pstring2 is the same information, but in a markx==10 format */
12602 void
12603 get_param (struct pstruct *pstr, char *pstring1, char *pstring2)
12604 {
12605 #ifdef FASTS
12606 #ifndef TFAST
12607 X  char *pg_str="FASTS";
12608 #else
12609 X  char *pg_str="TFASTS";
12610 #endif
12611 #endif
12612 X
12613 #ifdef FASTM
12614 #ifndef TFAST
12615 X  char *pg_str="FASTM";
12616 #else
12617 X  char *pg_str="TFASTM";
12618 #endif
12619 #endif
12620 X
12621 X  sprintf (pstring1, "%s (%s) function [%s matrix (%d:%d)] ktup=%d",pg_str,verstr,
12622 X              pstr->pamfile, pstr->pam_h,pstr->pam_l, pstr->param_u.fa.ktup);
12623 X  if (pstr->param_u.fa.iniflag) strcat(pstring1," init1");
12624 X  /*
12625 X  if (pstr->zsflag==0) strcat(pstring1," not-scaled");
12626 X  else if (pstr->zsflag==1) strcat(pstring1," reg.-scaled");
12627 X  */
12628 X  if (pstring2 != NULL) {
12629 X    sprintf (pstring2, "; pg_name: %s\n; pg_ver: %s\n; pg_matrix: %s (%d:%d)\n\
12630 ; pg_gap-pen: %d %d\n; pg_ktup: %d\n",
12631 X            pg_str,verstr,pstr->pamfile, pstr->pam_h,pstr->pam_l, pstr->gdelval,
12632 X            pstr->ggapval,pstr->param_u.fa.ktup);
12633 X   }
12634 }
12635 X
12636 void
12637 close_work (const unsigned char *aa0, const int n0,
12638 X           struct pstruct *ppst,
12639 X           struct f_struct **f_arg)
12640 {
12641 X  struct f_struct *f_str;
12642 X  int i, j;
12643 X
12644 X  f_str = *f_arg;
12645 X
12646 X  if (f_str != NULL) {
12647 X
12648 X    free(f_str->res);
12649 #ifdef TFAST
12650 X    free(f_str->aa1x - 1); /* because f_str->aa1x got ++'ed when allocated! */
12651 #endif
12652 X    free(f_str->diag);
12653 X    free(f_str->l_end);
12654 X    free(f_str->link);
12655 X    free(f_str->pamh2); 
12656 X    free(f_str->pamh1);
12657 X    free(f_str->harr);
12658 X    free(f_str->vmax);
12659 X    free(f_str->vptr);
12660 X    free(f_str->sarr);
12661 X    free(f_str->aa0i);
12662 X    free(f_str->aa0e);
12663 X    free(f_str->aa0b);
12664 X    free(f_str->aa0ti);
12665 X    free(f_str->aa0t);
12666 X    free(f_str->nmoff);
12667 X    free(f_str->nm_u);
12668 X
12669 X    if(f_str->dotat) {
12670 X      for(i = 0, j = (1 << f_str->nm0) - 1 ; i < j ; i++) {
12671 X       free(f_str->tatprobs[i]->probs);
12672 X       free(f_str->tatprobs[i]);
12673 X       free(f_str->intprobs[i]);
12674 X      }
12675 X      free(f_str->tatprobs);
12676 X      free(f_str->intprobs);
12677 X    }
12678 X
12679 X    free(f_str->priors);
12680 X    free(f_str);
12681 X    *f_arg = NULL;
12682 X  }
12683 }
12684 X
12685 void do_fasts (const unsigned char *aa0, const int n0,
12686 X              const unsigned char *aa1, const int n1,
12687 X              struct pstruct *ppst, struct f_struct *f_str,
12688 X              struct rstruct *rst, int *hoff, int opt_prob,
12689 X              int maxsav)
12690 {
12691 X   int     nd;         /* diagonal array size */
12692 X   int     lhval;
12693 X   int     kfact;
12694 X   register struct dstruct *dptr;
12695 X   register int tscor;
12696 X   register struct dstruct *diagp;
12697 X   struct dstruct *dpmax;
12698 X   register int lpos;
12699 X   int     tpos;
12700 X   struct savestr *vmptr, *vmaxmax;
12701 X   int     scor, tmp;
12702 X   int     im, ib, nsave;
12703 X   int     cmps ();            /* comparison routine for ksort */
12704 X   int ktup;
12705 X   int doffset;
12706 X
12707 X
12708 X   vmaxmax = &f_str->vmax[maxsav];
12709 X
12710 X   ktup = ppst->param_u.fa.ktup;
12711 X
12712 X   if (n1 < ktup) {
12713 X     rst->score[0] = rst->score[1] = rst->score[2] = 0;
12714 X     rst->escore = 1.0;
12715 X     rst->segnum = 0;
12716 X     rst->seglen = 0;
12717 X     return;
12718 X   }
12719 X
12720 X   if (n0+n1+1 >= MAXDIAG) {
12721 X     fprintf(stderr,"n0,n1 too large: %d, %d\n",n0,n1);
12722 X     rst->score[0] = rst->score[1] = rst->score[2] = -1;
12723 X     rst->escore = 2.0;
12724 X     rst->segnum = 0;
12725 X     rst->seglen = 0;
12726 X     return;
12727 X   }
12728 X
12729 X   nd = n0 + n1;
12730 X
12731 X   dpmax = &f_str->diag[nd];
12732 X   for (dptr = &f_str->diag[f_str->ndo]; dptr < dpmax;)
12733 X   {
12734 X      dptr->stop = -1;
12735 X      dptr->dmax = NULL;
12736 X      dptr++->score = 0;
12737 X   }
12738 X
12739 X   for (vmptr = f_str->vmax; vmptr < vmaxmax; vmptr++) {
12740 X      vmptr->score = 0;
12741 X      vmptr->exact = 0;
12742 X   }
12743 X   f_str->lowmax = f_str->vmax;
12744 X   f_str->lowscor = 0;
12745 X
12746 X   /* start hashing */
12747 X   diagp = &f_str->diag[f_str->noff];
12748 X   for (lhval=lpos=0; lpos < n1; lpos++, diagp++) {
12749 X     if (ppst->hsq[aa1[lpos]]>=NMAP) { /* skip residue */
12750 X       lpos++ ; diagp++;
12751 X       while (lpos < n1 && ppst->hsq[aa1[lpos]]>=NMAP) {lpos++; diagp++;}
12752 X       if (lpos >= n1) break;
12753 X       lhval = 0;
12754 X     }
12755 X
12756 X     lhval = ((lhval & f_str->hmask) << f_str->kshft) + ppst->hsq[aa1[lpos]];
12757 X
12758 X     for (tpos = f_str->harr[lhval]; tpos >= 0; tpos = f_str->link[tpos]) {
12759 X
12760 X       dptr = &diagp[-tpos];
12761 X
12762 X       if (f_str->l_end[tpos]) {
12763 X        if (dptr->score + f_str->pamh1[aa0[tpos]] == f_str->aa0s[tpos]) {
12764 X          dptr->stop = lpos;
12765 X          dptr->score = f_str->aa0s[tpos];
12766 X          savemax(dptr, f_str, maxsav, 1, tpos);
12767 X          dptr->dmax = NULL;
12768 X        }
12769 X
12770 X        else if (dptr->score + f_str->pamh1[aa0[tpos]] > f_str->aa0s[tpos]) {
12771 X          /*
12772 X          fprintf(stderr,"exact match score too high: %d:%d %d < %d + %d - %d:%d - %d > %d\n",
12773 X                  tpos, lpos, f_str->aa0s[tpos],dptr->score, f_str->pamh1[aa0[tpos]],
12774 X                  dptr->start, dptr->stop,
12775 X                  dptr->stop - dptr->start, f_str->aa0l[tpos]);
12776 X          */
12777 X          dptr->stop = lpos;
12778 X          dptr->start = lpos - f_str->aa0l[tpos];
12779 X          dptr->score = f_str->aa0s[tpos];
12780 X          savemax(dptr, f_str, maxsav, 1, tpos);
12781 X          dptr->dmax = NULL;
12782 X        }
12783 X       }
12784 X       else if ((tscor = dptr->stop) >= 0) {
12785 X        tscor++;       /* tscor is stop of current, increment it */
12786 X        if ((tscor -= lpos) <= 0) {  /* tscor, the end of the current
12787 X                                        match, is before lpos, so there
12788 X                                        is a mismatch - this is also the
12789 X                                        mismatch cost */
12790 X          tscor *= 2;
12791 X          scor = dptr->score;  /* save the run score on the diag */
12792 X          if ((tscor += (kfact = f_str->pamh2[lhval])) < 0 
12793 X              && f_str->lowscor < scor) {
12794 X            /* if what we will get (tscor + kfact) is < 0 and the
12795 X               score is better than the worst savemax() score, save
12796 X               it */
12797 X            savemax (dptr, f_str, maxsav,0,-1);
12798 X          }
12799 X
12800 X          /* if extending is better than starting over, extend */
12801 X          if ((tscor += scor) >= kfact) {
12802 X            dptr->score = tscor;
12803 X            dptr->stop = lpos;
12804 X            if (f_str->l_end[tpos]) {
12805 X              if (dptr->score == f_str->aa0s[tpos]) {
12806 X                savemax(dptr, f_str, maxsav,1,tpos);
12807 X                dptr->dmax = NULL;
12808 X              }
12809 X              else if (dptr->score > f_str->lowscor)
12810 X                savemax(dptr, f_str, maxsav,0,tpos);
12811 X            }
12812 X          }
12813 X          else {     /* otherwise, start new */
12814 X            dptr->score = kfact;
12815 X            dptr->start = dptr->stop = lpos;
12816 X          }
12817 X        } 
12818 X        else { /* tscor is after lpos, so extend one residue */
12819 X          dptr->score += f_str->pamh1[aa0[tpos]];
12820 X          dptr->stop = lpos;
12821 X          if (f_str->l_end[tpos]) {
12822 X            if (dptr->score == f_str->aa0s[tpos]) {
12823 X              savemax(dptr, f_str, maxsav,1,tpos);
12824 X              dptr->dmax = NULL;
12825 X            }
12826 X            else if (dptr->score > f_str->lowscor)
12827 X              savemax(dptr, f_str, maxsav,0,tpos);
12828 X          }
12829 X        }
12830 X       }
12831 X       else {  /* start new */
12832 X        dptr->score = f_str->pamh2[lhval];
12833 X        dptr->start = dptr->stop = lpos;
12834 X       }
12835 X     }                         /* end tpos */
12836 X   }                           /* end lpos */
12837 X
12838 X   for (dptr = f_str->diag; dptr < dpmax;) {
12839 X     if (dptr->score > f_str->lowscor) savemax (dptr, f_str, maxsav,0,-1);
12840 X     dptr->stop = -1;
12841 X     dptr->dmax = NULL;
12842 X     dptr++->score = 0;
12843 X   }
12844 X   f_str->ndo = nd;
12845 X
12846 /*
12847 X        at this point all of the elements of aa1[lpos]
12848 X        have been searched for elements of aa0[tpos]
12849 X        with the results in diag[dpos]
12850 */
12851 X
12852 X   for (nsave=0, vmptr=f_str->vmax; vmptr< vmaxmax; vmptr++) {
12853 X      if (vmptr->score > 0) {
12854 X       /*
12855 X
12856 X       fprintf(stderr,"%c 0: %4d-%4d  1: %4d-%4d  dp: %d score: %d",
12857 X               (vmptr->exact ? 'x' : ' '),
12858 X               f_str->noff+vmptr->start-vmptr->dp,
12859 X               f_str->noff+vmptr->stop-vmptr->dp,
12860 X               vmptr->start,vmptr->stop,
12861 X               vmptr->dp,vmptr->score);
12862 X       */
12863 X       vmptr->score = spam (aa0, aa1, n1, vmptr, ppst->pam2[0], f_str);
12864 X       /*
12865 X       fprintf(stderr,"  sscore: %d %d-%d\n",vmptr->score,vmptr->start,vmptr->stop);
12866 X       */
12867 X       if (vmptr->score > 0) f_str->vptr[nsave++] = vmptr;
12868 X      }
12869 X   }
12870 X
12871 X   if (nsave <= 0) {
12872 X     rst->score[0] = rst->score[1] = rst->score[2] = 0;
12873 X     rst->escore = 1.0;
12874 X     rst->segnum = 0;
12875 X     rst->seglen = 0;
12876 X     f_str->nsave = 0;
12877 X     return;
12878 X   }
12879 X
12880 X   /*
12881 X   fprintf(stderr,"n0: %d; n1: %d; noff: %d\n",n0,n1,f_str->noff);
12882 X   for (ib=0; ib<nsave; ib++) {
12883 X     fprintf(stderr,"%c 0: %4d-%4d  1: %4d-%4d  dp: %d score: %d\n",
12884 X            f_str->vptr[ib]->exact ? 'x' : ' ',
12885 X            f_str->noff+f_str->vptr[ib]->start-f_str->vptr[ib]->dp,
12886 X            f_str->noff+f_str->vptr[ib]->stop-f_str->vptr[ib]->dp,
12887 X            f_str->vptr[ib]->start,f_str->vptr[ib]->stop,
12888 X            f_str->vptr[ib]->dp,f_str->vptr[ib]->score);
12889 X   }
12890 X
12891 X   fprintf(stderr,"---\n");
12892 X   */
12893 X   kssort(f_str->vptr,nsave);
12894 X
12895 X   /* make certain each seg is used only once */
12896 X
12897 X   for (ib=0; ib<f_str->nm0; ib++) f_str->nm_u[ib]=0;
12898 X   for (ib=0; ib < nsave; ib++) {
12899 X     doffset = f_str->vptr[ib]->dp - f_str->noff;
12900 X     tpos=f_str->aa0i[f_str->vptr[ib]->start - doffset];
12901 X     if (f_str->nm_u[tpos] == 0) {
12902 X       f_str->nm_u[tpos]=1;
12903 X     } else {
12904 X       f_str->vptr[ib]->score = -1;
12905 X     }
12906 X   }
12907 X
12908 X   kssort(f_str->vptr,nsave);
12909 X   for (ib = nsave-1; ib >= 0; ib--)
12910 X     if (f_str->vptr[ib]->score > -1) break;
12911 X   nsave = ib+1;
12912 X
12913 X   scor = sconn (f_str->vptr, nsave, 
12914 X                f_str, rst, ppst, aa0, n0, aa1, n1,
12915 X                opt_prob);
12916 X
12917 X   if (rst->escore < 0.0) rst->escore = 2.0;
12918 X   kssort(f_str->vptr,nsave);
12919 X
12920 X   /* here we should use an nsave that is consistent with sconn and nm0 */
12921 X
12922 X   f_str->nsave = nsave;
12923 X   if (nsave > f_str->nm0) f_str->nsave = f_str->nm0;
12924 X
12925 X   rst->score[1] = f_str->vptr[0]->score;
12926 X   rst->score[0] = rst->score[2] = max(scor, f_str->vptr[0]->score);
12927 X
12928 }
12929 X
12930 void do_work (const unsigned char *aa0, const int n0,
12931 X             const unsigned char *aa1, const int n1,
12932 X             int frame,
12933 X             struct pstruct *ppst, struct f_struct *f_str,
12934 X             int qr_flg, struct rstruct *rst)
12935 {
12936 X  int opt_prob;
12937 X  int hoff, n10, i;
12938 X
12939 X  if (qr_flg==1 && f_str->shuff_cnt <= 0) {
12940 X    rst->escore = 2.0;
12941 X    rst->score[0]=rst->score[1]=rst->score[2]= -1;
12942 X    return;
12943 X  }
12944 X
12945 X  if (f_str->dotat || ppst->zsflag == 4 || ppst->zsflag == 14 ) opt_prob=1;
12946 X  else opt_prob = 0;
12947 X  if (ppst->zsflag == 2 || ppst->zsflag == 12) opt_prob = 0;
12948 X  if (qr_flg) {
12949 X    opt_prob=1;
12950 X    /*    if (frame==1) */
12951 X      f_str->shuff_cnt--;
12952 X  }
12953 X
12954 X  if (n1 < ppst->param_u.fa.ktup) {
12955 X    rst->score[0] = rst->score[1] = rst->score[2] = -1;
12956 X    rst->escore = 2.0;
12957 X    return;
12958 X  }
12959 #ifdef TFAST
12960 X  n10=aatran(aa1,f_str->aa1x,n1,frame);
12961 X  if (ppst->debug_lib)
12962 X    for (i=0; i<n10; i++)
12963 X      if (f_str->aa1x[i]>ppst->nsq) {
12964 X       fprintf(stderr,
12965 X               "residue[%d/%d] %d range (%d)\n",i,n1,
12966 X               f_str->aa1x[i],ppst->nsq);
12967 X       f_str->aa1x[i]=0;
12968 X       n10=i-1;
12969 X      }
12970 X
12971 X  do_fasts (aa0, n0, f_str->aa1x, n10, ppst, f_str, rst, &hoff, opt_prob, f_str->maxsav);
12972 #else   /* FASTA */
12973 X  do_fasts (aa0, n0, aa1, n1, ppst, f_str, rst, &hoff, opt_prob, f_str->maxsav);
12974 #endif
12975 X
12976 X  rst->comp = rst->H = -1.0;
12977 }
12978 X
12979 void do_opt (const unsigned char *aa0, const int n0,
12980 X            const unsigned char *aa1, const int n1,
12981 X            int frame,
12982 X            struct pstruct *ppst, struct f_struct *f_str,
12983 X            struct rstruct *rst)
12984 {
12985 X  int lag, tscore, hoff, n10;
12986 X
12987 #ifdef TFAST
12988 X  n10=aatran(aa1,f_str->aa1x,n1,frame);
12989 X  do_fasts (aa0, n0, f_str->aa1x, n10, ppst, f_str, rst, &hoff, 1, f_str->maxsav);
12990 #else   /* FASTA */
12991 X  do_fasts(aa0,n0,aa1,n1,ppst,f_str,rst, &hoff, 1, f_str->maxsav);
12992 #endif
12993 }
12994 X
12995 X
12996 /* modify savemax() so that full length 100% matches are marked
12997 X   so that they cannot be removed - if we have a 100% match, mark "exact"
12998 X
12999 X   modify savemax() to split alignments that include a comma
13000 */
13001 X
13002 /* savemax(dptr, f_str, maxsav) takes a current diagonal run (saved in dptr),
13003 X   and places it in the set of runs to be saved (in  f_str->vmax[])
13004 */
13005 X
13006 void 
13007 savemax (struct dstruct *dptr, struct f_struct *f_str, int maxsav,
13008 X        int exact, int tpos)
13009 {
13010 X  register int dpos;   /* position along the diagonal, -n0 .. n1 */
13011 X  int i, j, lowj;
13012 X  register struct savestr *vmptr;
13013 X  struct savestr *vmaxmax;
13014 X
13015 X  vmaxmax = &f_str->vmax[maxsav];
13016 X
13017 X  dpos = (int) (dptr - f_str->diag);   /* current diagonal */
13018 X
13019 /* check to see if this is the continuation of a run that is already saved */
13020 /* if we are at the end of the query, save it regardless */
13021 X
13022 /*  if (t_end > 0 && t_end < dptr->stop - dptr->start) {return;} */
13023 X
13024 X  if ((vmptr = dptr->dmax) != NULL     /* have an active run */
13025 X      && vmptr->dp == dpos &&          /* on the correct diagonal */
13026 X      vmptr->start == dptr->start) {   /* and it starts at the same place */
13027 X    vmptr->stop = dptr->stop;  /* update the end of the match in vmax[] */
13028 X
13029 X    if (exact == 1) {
13030 X    /*
13031 X      fprintf(stderr,"have cont exact match: %d - %d:%d %d:%d = %d\n",
13032 X             dptr->score, dptr->start, dptr->stop,
13033 X             vmptr->start, vmptr->stop, dptr->stop - dptr->start+1);
13034 X    */
13035 X      exact = 1;
13036 X    }
13037 X
13038 X
13039 /* if the score is worse, don't update, return - if the score gets bad
13040 X   enough, it will restart in the diagonal scan */
13041 X    if ((i = dptr->score) <= vmptr->score) { return;} 
13042 X
13043 /* score is better, update */
13044 X    vmptr->score = i;
13045 X
13046 X    vmptr->exact = exact;
13047 /* if the score is not the worst, return */
13048 X    if (vmptr != f_str->lowmax) { return;}
13049 X  }
13050 X  else {       /* not a continuation */
13051 X    /* save in the lowest place */
13052 X    /*
13053 X    fprintf(stderr," Replacing: %d - %d:%d => %d - %d:%d",
13054 X           f_str->lowmax->score, f_str->lowmax->start, f_str->lowmax->stop,
13055 X           dptr->score, dptr->start, dptr->stop);
13056 X    */
13057 X
13058 X    vmptr = f_str->lowmax;
13059 X
13060 X    /*
13061 X    if (exact == 1) {
13062 X      fprintf(stderr,"have new exact match: %d - %d:%d = %d\n",
13063 X             dptr->score, dptr->start, dptr->stop, dptr->stop - dptr->start+1);
13064 X    }
13065 X    */
13066 X    vmptr->exact = exact;
13067 X
13068 X    i = vmptr->score = dptr->score;   /* 'i' is used as a bound */
13069 X    vmptr->dp = dpos;
13070 X    vmptr->start = dptr->start;
13071 X    vmptr->stop = dptr->stop;
13072 X    dptr->dmax = vmptr;
13073 X  }
13074 X
13075 X  /* rescan the list for the worst score */
13076 X  for (vmptr = f_str->vmax;  vmptr < &f_str->vmax[maxsav] ; vmptr++) {
13077 X    if (vmptr->score < i && !vmptr->exact) {
13078 X      i = vmptr->score;
13079 X      f_str->lowmax = vmptr;
13080 X    }
13081 X  }
13082 X
13083 X  f_str->lowscor = i;
13084 }
13085 X
13086 /* this version of spam scans the diagonal to find the best local score,
13087 X   then resets the boundaries for a global alignment and re-scans */
13088 X
13089 /* NOOVERHANG allows one to score any overhanging alignment as zero.
13090 X   Useful for SAGE alignments.  Normally, one allows overhangs because
13091 X   of the possibility of partial sequences.
13092 */
13093 X
13094 #undef NOOVERHANG
13095 X
13096 /* 
13097 X   May, 2005 - spam() has an intesting bug that occurs when two
13098 X   peptides match in order, separated by one position (the comma).  In
13099 X   this case, spam() splits the match, and only returns the better of
13100 X   the two matches.  So, if spam splits an alignment at a comma, it
13101 X   needs the ability to insert the missing match.
13102 X
13103 */
13104 X
13105 int spam (const unsigned char *aa0, const unsigned char *aa1,int n1,
13106 X         struct savestr *dmax, int **pam2,
13107 X         struct f_struct *f_str)
13108 {
13109 X   int     lpos, doffset;
13110 X   int     tot, mtot;
13111 X   struct {
13112 X     int  start, stop, score;
13113 X   } curv, maxv;
13114 X   register const unsigned char *aa0p, *aa1p;
13115 X
13116 X   doffset = dmax->dp - f_str->noff;
13117 X   curv.start = dmax->start;
13118 X   aa1p = &aa1[dmax->start];
13119 X   aa0p = &aa0[dmax->start - doffset];
13120 X
13121 X   tot = curv.score = maxv.score = 0;
13122 X   for (lpos = dmax->start; lpos <= dmax->stop; lpos++) {
13123 X     tot += pam2[*aa0p++][*aa1p++];
13124 X     if (tot > curv.score) {
13125 X       curv.stop = lpos;       /* here, curv.stop is actually curv.max */
13126 X       curv.score = tot;
13127 X      }
13128 X      else if (tot < 0) {
13129 X       if (curv.score > maxv.score) {
13130 X         maxv.start = curv.start;
13131 X         maxv.stop = curv.stop;
13132 X         maxv.score = curv.score;
13133 X       }
13134 X       tot = curv.score = 0;
13135 X       curv.start = lpos+1;
13136 X      }
13137 X   }
13138 X
13139 X   if (curv.score > maxv.score) {
13140 X     maxv.start = curv.start;
13141 X     maxv.stop = curv.stop;
13142 X     maxv.score = curv.score;
13143 X   }
13144 X
13145 X   if (maxv.score <= 0) return 0;
13146 X
13147 X   /* now, reset the boundaries of the alignment using aa0b[]
13148 X      and aa0e[], which specify the residues that start and end
13149 X      the segment */
13150 X      
13151 X   maxv.start = f_str->aa0b[maxv.stop-doffset] + doffset;
13152 X   if (maxv.start < 0) {
13153 X     maxv.start = 0;
13154 #ifdef NOOVERHANG
13155 X     return 0;
13156 #endif
13157 X   }
13158 X
13159 X   maxv.stop = f_str->aa0e[maxv.stop-doffset] + doffset;
13160 X   if (maxv.stop > n1) {
13161 X     maxv.stop = n1-1;
13162 #ifdef NOOVERHANG
13163 X     return 0;
13164 #endif
13165 X   }
13166 X   aa1p = &aa1[lpos = maxv.start];
13167 X   aa0p = &aa0[lpos - doffset];
13168 X
13169 X   for (tot=0; lpos <= maxv.stop; lpos++) {
13170 X     tot += pam2[*aa0p++][*aa1p++];
13171 X   }
13172 X
13173 X   maxv.score = tot;
13174 X
13175 /*      if (maxv.start != dmax->start || maxv.stop != dmax->stop)
13176 X               printf(" new region: %3d %3d %3d %3d\n",maxv.start,
13177 X                       dmax->start,maxv.stop,dmax->stop);
13178 */
13179 X   dmax->start = maxv.start;
13180 X   dmax->stop = maxv.stop;
13181 X
13182 X   return maxv.score;
13183 }
13184 X
13185 int sconn (struct savestr **v, int n, 
13186 X          struct f_struct *f_str,
13187 X          struct rstruct *rst, struct pstruct *ppst,
13188 X          const unsigned char *aa0, int n0,
13189 X          const unsigned char *aa1, int n1, int opt_prob)
13190 {
13191 X   int     i, si, cmpp ();
13192 X   struct slink *start, *sl, *sj, *so, *sarr;
13193 X   int     lstart, ltmp, tstart, plstop, ptstop, ptstart, tstop;
13194 X   double  tatprob;
13195 X   int     dotat;
13196 X
13197 X   sarr = f_str->sarr;
13198 X
13199 X   /*  sort the score left to right in lib pos */
13200 X   kpsort (v, n);
13201 X
13202 X   start = NULL;
13203 X   rst->score[0] = 0;
13204 X   rst->escore = 2.0;
13205 X
13206 /*  for the remaining runs, see if they fit */
13207 /*  lstart/lstop -> start/stop in library sequence
13208 X    tstart/tstop -> start/stop in query sequence
13209 X    plstart/plstop ->
13210 */
13211 X
13212 X   for (i = 0, si = 0; i < n; i++) {
13213 X
13214 X     /* the segment is worth adding; find out where? */
13215 X     lstart = v[i]->start;
13216 X     ltmp = v[i]->stop;
13217 X     tstart = lstart - v[i]->dp + f_str->noff;
13218 X     tstop = ltmp - v[i]->dp + f_str->noff;
13219 X
13220 X     /*        put the run in the group */
13221 X     sarr[si].vp = v[i];
13222 X     sarr[si].score = v[i]->score;
13223 X     sarr[si].next = NULL;
13224 X     sarr[si].prev = NULL;
13225 X     sarr[si].tat = NULL;
13226 X
13227 /*
13228 X  opt_prob for FASTS only has to do with using aa1 for priors,
13229 X  i.e. we always calculate tatprobs for segments in FASTS (unlike
13230 X  FASTF)
13231 */
13232 X     if(opt_prob) {
13233 X       sarr[si].tatprob = 
13234 X        calc_tatusov(NULL, &sarr[si], aa0, n0, aa1, n1, 
13235 X                     ppst->pam2[0], ppst->nsq, f_str, 
13236 X                     ppst->pseudocts, opt_prob, ppst->zsflag);
13237 X       if (sarr[si].tatprob < 0.0) {
13238 X        fprintf(stderr," negative tatprob: %lg\n",sarr[si].tatprob);
13239 X        sarr[si].tatprob = 1.0;
13240 X       }
13241 X       sarr[si].tat = sarr[si].newtat;
13242 X     }
13243 X
13244 /*  if it fits, then increase the score
13245 X
13246 X    start points to the highest scoring run
13247 X    -> next is the second highest, etc.
13248 X    put the segment into the highest scoring run that it fits into
13249 */
13250 X     for (sl = start; sl != NULL; sl = sl->next) {
13251 X       ltmp = sl->vp->start;
13252 X /* plstop -> previous lstop */
13253 X       plstop = sl->vp->stop;
13254 X /* ptstart -> previous t(query) start */
13255 X       ptstart = ltmp - sl->vp->dp + f_str->noff;
13256 X /* ptstop -> previous t(query) stop */
13257 X       ptstop = plstop - sl->vp->dp + f_str->noff;
13258 #ifndef FASTM
13259 X /* if the previous library stop is before the current library start */
13260 X       if (plstop < lstart && ( ptstop < tstart || ptstart > tstop))
13261 #else
13262 X /* if the previous library stop is before the current library start */
13263 X       if (plstop < lstart && ptstop < tstart)
13264 #endif
13265 X       {
13266 X        if(!opt_prob) {
13267 X           sarr[si].score = sl->score + v[i]->score;
13268 X           sarr[si].prev = sl;
13269 X           break;
13270 X         } else {
13271 X           tatprob = calc_tatusov(sl, &sarr[si], aa0, n0, aa1, n1, 
13272 X                                  ppst->pam2[0], ppst->nsq, f_str, 
13273 X                                  ppst->pseudocts, opt_prob, ppst->zsflag);
13274 X           /* if our tatprob gets worse when we add this, forget it */
13275 X           if(tatprob > sarr[si].tatprob) {
13276 X             free(sarr[si].newtat->probs); /* get rid of new tat struct */
13277 X             free(sarr[si].newtat);
13278 X             continue; /* reuse this sarr[si] */
13279 X           } else {
13280 X             sarr[si].tatprob = tatprob;
13281 X             free(sarr[si].tat->probs); /* get rid of old tat struct */
13282 X             free(sarr[si].tat);
13283 X             sarr[si].tat = sarr[si].newtat;
13284 X             sarr[si].prev = sl;
13285 X             sarr[si].score = sl->score + v[i]->score;
13286 X             /*
13287 X               fprintf(stderr,"sconn %d added %d/%d getting %d; si: %d, tat: %g\n",
13288 X               i,v[i]->start, v[i]->score,sarr[si].score,si, tatprob);
13289 X             */
13290 X             break;
13291 X           }
13292 X         }
13293 X       }
13294 X      }
13295 X      
13296 X      /* now recalculate where the score fits */
13297 X      if (start == NULL) start = &sarr[si];
13298 X      else {
13299 X       if(!opt_prob) {
13300 X         for (sj = start, so = NULL; sj != NULL; sj = sj->next) {
13301 X           if (sarr[si].score > sj->score) {
13302 X             sarr[si].next = sj;
13303 X             if (so != NULL)
13304 X               so->next = &sarr[si];
13305 X             else
13306 X               start = &sarr[si];
13307 X             break;
13308 X           }
13309 X           so = sj;
13310 X         }
13311 X       } else {
13312 X         for (sj = start, so = NULL; sj != NULL; sj = sj->next) {
13313 X           if ( sarr[si].tatprob < sj->tatprob ||
13314 X                ((sarr[si].tatprob == sj->tatprob) && sarr[si].score > sj->score) ) {
13315 X             sarr[si].next = sj;
13316 X             if (so != NULL)
13317 X               so->next = &sarr[si];
13318 X             else
13319 X               start = &sarr[si];
13320 X             break;
13321 X           }
13322 X           so = sj;
13323 X         }
13324 X       }
13325 X      }
13326 X
13327 X      si++;
13328 X   }
13329 X      
13330 X   if(opt_prob) {
13331 X     for (i = 0 ; i < si ; i++) {
13332 X       free(sarr[i].tat->probs);
13333 X       free(sarr[i].tat);
13334 X     }
13335 X   }
13336 X
13337 X   if (start != NULL) {
13338 X     if(opt_prob) {
13339 X       rst->escore = start->tatprob;
13340 X     } else {
13341 X       rst->escore = 2.0;
13342 X     }
13343 X
13344 X     rst->segnum = rst->seglen = 0;
13345 X     for(sj = start ; sj != NULL; sj = sj->prev) {
13346 X       rst->segnum++;
13347 X       rst->seglen += sj->vp->stop - sj->vp->start + 1;
13348 X     }
13349 X     return (start->score);
13350 X   } else {
13351 X     rst->escore = 1.0;
13352 X   }
13353 X
13354 X   rst->segnum = rst->seglen = 0;
13355 X   return (0);
13356 }
13357 X
13358 void
13359 kssort (v, n)
13360 struct savestr *v[];
13361 int     n;
13362 {
13363 X   int     gap, i, j;
13364 X   struct savestr *tmp;
13365 X
13366 X   for (gap = n / 2; gap > 0; gap /= 2)
13367 X      for (i = gap; i < n; i++)
13368 X        for (j = i - gap; j >= 0; j -= gap)
13369 X        {
13370 X           if (v[j]->score >= v[j + gap]->score)
13371 X              break;
13372 X           tmp = v[j];
13373 X           v[j] = v[j + gap];
13374 X           v[j + gap] = tmp;
13375 X        }
13376 }
13377 X
13378 void
13379 kpsort (v, n)
13380 struct savestr *v[];
13381 int     n;
13382 {
13383 X   int     gap, i, j;
13384 X   struct savestr *tmp;
13385 X
13386 X   for (gap = n / 2; gap > 0; gap /= 2)
13387 X      for (i = gap; i < n; i++)
13388 X        for (j = i - gap; j >= 0; j -= gap)
13389 X        {
13390 X           if (v[j]->start <= v[j + gap]->start)
13391 X              break;
13392 X           tmp = v[j];
13393 X           v[j] = v[j + gap];
13394 X           v[j + gap] = tmp;
13395 X        }
13396 }
13397 X
13398 /* calculate the 100% identical score */
13399 int
13400 shscore(const unsigned char *aa0, const int n0, int **pam2, int nsq)
13401 {
13402 X  int i, sum;
13403 X  for (i=0,sum=0; i<n0; i++)
13404 X    if (aa0[i] != EOSEQ && aa0[i]<=nsq) sum += pam2[aa0[i]][aa0[i]];
13405 X  return sum;
13406 }
13407 X
13408 /* sorts alignments from right to left (back to front) based on stop */
13409 X
13410 void
13411 krsort (v, n)
13412 struct savestr *v[];
13413 int     n;
13414 {
13415 X   int     gap, i, j;
13416 X   struct savestr *tmp;
13417 X
13418 X   for (gap = n / 2; gap > 0; gap /= 2)
13419 X      for (i = gap; i < n; i++)
13420 X        for (j = i - gap; j >= 0; j -= gap)
13421 X        {
13422 X           if (v[j]->stop > v[j + gap]->stop)
13423 X              break;
13424 X           tmp = v[j];
13425 X           v[j] = v[j + gap];
13426 X           v[j + gap] = tmp;
13427 X        }
13428 }
13429 X
13430 int  do_walign (const unsigned char *aa0, int n0,
13431 X               const unsigned char *aa1, int n1,
13432 X               int frame,
13433 X               struct pstruct *ppst, 
13434 X               struct f_struct *f_str, 
13435 X               struct a_res_str *a_res,
13436 X               int *have_ares)
13437 {
13438 X  int hoff, n10;
13439 X  struct rstruct rst;
13440 X  int ib, i;
13441 X  unsigned char *aa0t;
13442 X  const unsigned char *aa1p;
13443 X  struct savestr *vmptr;
13444 X
13445 #ifdef TFAST
13446 X  f_str->n10 = n10 = aatran(aa1,f_str->aa1x,n1,frame);
13447 X  aa1p = f_str->aa1x;
13448 #else
13449 X  n10 = n1;
13450 X  aa1p = aa1;
13451 #endif
13452 X
13453 X  do_fasts(aa0, n0, aa1p, n10, ppst, f_str, &rst, &hoff, 1, f_str->maxsav_w);
13454 X
13455 X  /* the alignment portion takes advantage of the information left
13456 X     over in f_str after do_fasts is done.  in particular, it is
13457 X     easy to run a modified sconn() to produce the alignments.
13458 X
13459 X     unfortunately, the alignment display routine wants to have
13460 X     things encoded as with bd_align and sw_align, so we need to do that.
13461 X     */
13462 X
13463 X  /* unnecessary; do_fasts just did this */
13464 X  /*  kssort(f_str->vptr,f_str->nsave);  */
13465 X
13466 X   /* at some point, we want one best score for each of the segments */
13467 X
13468 X   for ( ; f_str->nsave > 0; f_str->nsave--) 
13469 X     if (f_str->vptr[f_str->nsave-1]->score >0) break;
13470 X
13471 X   if ((aa0t = (unsigned char *)calloc(n0+1,sizeof(unsigned char)))==NULL) {
13472 X     fprintf(stderr," cannot allocate aa0t %d\n",n0+1);
13473 X     exit(1);
13474 X   }
13475 X
13476 X   /* copy aa0[] into f_str->aa0t[] */
13477 X   for (i=0; i<n0; i++) f_str->aa0t[i] = aa0t[i] = aa0[i];
13478 X   f_str->aa0t[i] = aa0t[i] = '\0';
13479 X
13480 X   a_res->nres = sconn_a (aa0t,n0,aa1p,n10,f_str, a_res, ppst);
13481 X
13482 X   free(aa0t);
13483 X
13484 X   a_res->res = f_str->res;
13485 X   *have_ares = 0;
13486 X   return rst.score[0];
13487 }
13488 X
13489 /* this version of sconn is modified to provide alignment information */
13490 /* in addition, it needs to know whether a segment has been used before */
13491 X
13492 /* sconn_a fills in the res[nres] array, but this is passed implicitly
13493 X   through f_str->res[f_str->nres] */
13494 X
13495 int sconn_a (unsigned char *aa0, int n0,
13496 X            const unsigned char *aa1, int n1,
13497 X            struct f_struct *f_str,
13498 X            struct a_res_str *a_res,
13499 X            struct pstruct *ppst)
13500 {
13501 X   int     i, si, cmpp (), n;
13502 X   unsigned char *aa0p;
13503 X   int sx, dx, doff, *aa0tip;
13504 X
13505 X   struct savestr **v;
13506 X   struct slink *start, *sl, *sj, *so, *sarr;
13507 X   int     lstart, lstop, ltmp, plstart, tstart, plstop, ptstop, ptstart, tstop;
13508 X
13509 X   int *res, nres, tres;
13510 X
13511 X   double tatprob;
13512 X
13513 /*      sort the score left to right in lib pos */
13514 X
13515 X   v = f_str->vptr;
13516 X   n = f_str->nsave;
13517 X   sarr = f_str->sarr;
13518 X
13519 X   /* set things up in case nothing fits */
13520 X   if (n <=0 || v[0]->score <= 0) return 0;
13521 X
13522 X   if (v[0]->score < 0) {
13523 X     sarr[0].vp = v[0];
13524 X     sarr[0].score = v[0]->score;
13525 X     sarr[0].next = NULL;
13526 X     sarr[0].prev = NULL;
13527 X     start = &sarr[0];
13528 X   }
13529 X   else {
13530 X
13531 X     krsort (v, n);    /* sort from left to right in library */
13532 X
13533 X     start = NULL;
13534 X
13535 X     /*        for each alignment, see if it fits */
13536 X
13537 X
13538 X     for (i = 0, si = 0; i < n; i++) {
13539 X       /*      if the score is less than the join threshold, skip it */
13540 X
13541 X       if (v[i]->score < 0) continue;
13542 X
13543 X       lstart = v[i]->start;
13544 X       lstop = v[i]->stop;
13545 X       tstart = lstart - v[i]->dp + f_str->noff;
13546 X       tstop = lstop - v[i]->dp + f_str->noff;
13547 X
13548 X       /*      put the alignment in the group */
13549 X
13550 X       sarr[si].vp = v[i];
13551 X       sarr[si].score = v[i]->score;
13552 X       sarr[si].next = NULL;
13553 X       sarr[si].prev = NULL;
13554 X       sarr[si].tat = NULL;
13555 X
13556 X       sarr[si].tatprob = 
13557 X        calc_tatusov(NULL, &sarr[si], aa0, n0, aa1, n1, 
13558 X                     ppst->pam2[0], ppst->nsq, f_str, 
13559 X                     ppst->pseudocts, 1, ppst->zsflag);
13560 X       sarr[si].tat = sarr[si].newtat;
13561 X
13562 X
13563 X       /*      if it fits, then increase the score */
13564 X       /* start points to a sorted (by total score) list of candidate
13565 X         overlaps */
13566 X
13567 X       for (sl = start; sl != NULL; sl = sl->next) { 
13568 X        plstart = sl->vp->start;
13569 X        plstop = sl->vp->stop;
13570 X        ptstart = plstart - sl->vp->dp + f_str->noff;
13571 X        ptstop = plstop - sl->vp->dp + f_str->noff;
13572 #ifndef FASTM
13573 X        if (plstart > lstop && (ptstop < tstart || ptstart > tstop)) {
13574 #else
13575 X         if (plstop > lstart && ptstart > tstop) {
13576 #endif
13577 X          /* alignment always uses probabilistic scoring ... */
13578 X          /*   sarr[si].score = sl->score + v[i]->score;
13579 X               sarr[si].prev = sl;
13580 X               break; */               /* quit as soon as the alignment has been added */
13581 X
13582 X          tatprob = calc_tatusov(sl, &sarr[si], aa0, n0, aa1, n1, 
13583 X                                 ppst->pam2[0], ppst->nsq, f_str, 
13584 X                                 ppst->pseudocts, 1, ppst->zsflag);
13585 X          /* if our tatprob gets worse when we add this, forget it */
13586 X          if(tatprob > sarr[si].tatprob) {
13587 X            free(sarr[si].newtat->probs); /* get rid of new tat struct */
13588 X            free(sarr[si].newtat);
13589 X            continue; /* reuse this sarr[si] */
13590 X          } else {
13591 X            sarr[si].tatprob = tatprob;
13592 X            free(sarr[si].tat->probs); /* get rid of old tat struct */
13593 X            free(sarr[si].tat);
13594 X            sarr[si].tat = sarr[si].newtat;
13595 X            sarr[si].prev = sl;
13596 X            sarr[si].score = sl->score + v[i]->score;
13597 X            /*
13598 X              fprintf(stderr,"sconn %d added %d/%d getting %d; si: %d, tat: %g\n",
13599 X              i,v[i]->start, v[i]->score,sarr[si].score,si, tatprob);
13600 X            */
13601 X            break;
13602 X          }
13603 X        }
13604 X       }
13605 X
13606 X       /* now recalculate the list of best scores */
13607 X       if (start == NULL)
13608 X        start = &sarr[si];     /* put the first one in the list */
13609 X       else
13610 X        for (sj = start, so = NULL; sj != NULL; sj = sj->next) {
13611 X          /* if (sarr[si].score > sj->score) { */ /* new score better than old */
13612 X          if ( sarr[si].tatprob < sj->tatprob ||
13613 X               ((sarr[si].tatprob == sj->tatprob) && sarr[si].score > sj->score) ) {
13614 X            sarr[si].next = sj;                /* next best after new score */
13615 X            if (so != NULL)
13616 X              so->next = &sarr[si];    /* prev_best->next points to best */
13617 X            else  start = &sarr[si];   /* start points to best */
13618 X            break;                     /* stop looking */
13619 X          }
13620 X          so = sj;             /* previous candidate best */
13621 X        }
13622 X       si++;                           /* increment to next alignment */
13623 X     }
13624 X   }
13625 X
13626 X   for (i = 0 ; i < si ; i++) {
13627 X     free(sarr[i].tat->probs);
13628 X     free(sarr[i].tat);
13629 X   }
13630 X
13631 X   res = f_str->res;
13632 X   tres = nres = 0;
13633 X   aa0p = aa0;
13634 X   aa0tip = f_str->aa0ti;      /* point to temporary index */
13635 X   a_res->min1 = start->vp->start;
13636 X   a_res->min0 = 0;
13637 X
13638 X   for (sj = start; sj != NULL; sj = sj->prev ) {
13639 X     doff = (int)(aa0p-aa0) - (sj->vp->start-sj->vp->dp+f_str->noff);
13640 X     
13641 X     /* fprintf(stderr,"doff: %3d\n",doff); */
13642 X     
13643 X     for (dx=sj->vp->start,sx=sj->vp->start-sj->vp->dp+f_str->noff;
13644 X         dx <= sj->vp->stop; dx++) {
13645 X       *aa0tip++ = f_str->aa0i[sx];    /* save index */
13646 X       *aa0p++ = f_str->aa0t[sx++];    /* save sequence at index */
13647 X       tres++;
13648 X       res[nres++] = 0;
13649 X     }
13650 X     sj->vp->dp -= doff;
13651 X     if (sj->prev != NULL) {
13652 X       if (sj->prev->vp->start - sj->vp->stop - 1 > 0 )
13653 X        tres += res[nres++] = (sj->prev->vp->start - sj->vp->stop - 1);
13654 X     }
13655 X
13656 X     /*
13657 X     fprintf(stderr,"t0: %3d, tx: %3d, l0: %3d, lx: %3d, dp: %3d noff: %3d, score: %3d\n",
13658 X       sj->vp->start - sj->vp->dp + f_str->noff,
13659 X       sj->vp->stop - sj->vp->dp + f_str->noff,
13660 X       sj->vp->start,sj->vp->stop,sj->vp->dp,
13661 X       f_str->noff,sj->vp->score);
13662 X
13663 X       fprintf(stderr,"%3d - %3d: %3d\n",
13664 X       sj->vp->start,sj->vp->stop,sj->vp->score);
13665 X     */
13666 X     a_res->max1 = sj->vp->stop+1;
13667 X     a_res->max0 = a_res->max1 - sj->vp->dp + f_str->noff;
13668 X   }
13669 X
13670 X   /*
13671 X   fprintf(stderr,"(%3d - %3d):(%3d - %3d)\n",
13672 X          a_res->min0,a_res->max0,a_res->min1,a_res->max1);
13673 X   */
13674 X   
13675 X   /* now replace f_str->aa0t with aa0
13676 X      (f_str->aa0t is permanent, aa0 is not)*/
13677 X   for (i=0; i<n0; i++) f_str->aa0t[i] = aa0[i];
13678 X
13679 X   return tres;
13680 }
13681 X
13682 /* for fasts (and fastf), pre_cons needs to set up f_str as well as do
13683 X   necessary translations - for right now, simply do do_walign */
13684 X
13685 void
13686 pre_cons(const unsigned char *aa1, int n1, int frame, struct f_struct *f_str) {
13687 X
13688 #ifdef TFAST
13689 X  f_str->n10=aatran(aa1,f_str->aa1x,n1,frame);
13690 #endif
13691 X
13692 }
13693 X
13694 /* aln_func_vals - set up aln.qlfact, qlrev, llfact, llmult, frame, llrev */
13695 /* call from calcons, calc_id, calc_code */
13696 void 
13697 aln_func_vals(int frame, struct a_struct *aln) {
13698 X
13699 #ifdef TFAST
13700 X  aln->qlrev = 0;
13701 X  aln->qlfact= 1;
13702 X  aln->llfact = aln->llmult = 3;
13703 X  if (frame > 3) aln->llrev = 1;
13704 X  else aln->llrev = 0;
13705 X  aln->frame = 0;
13706 #else   /* FASTS */
13707 X  aln->llfact = aln->llmult = aln->qlfact = 1;
13708 X  aln->llrev = aln->qlrev = 0;
13709 X  aln->frame = 0;
13710 #endif
13711 }
13712 X
13713 #include "a_mark.h"
13714 X
13715 int calcons(const unsigned char *aa0, int n0,
13716 X           const unsigned char *aa1, int n1,
13717 X           int *nc,
13718 X           struct a_struct *aln,
13719 X           struct a_res_str a_res,
13720 X           struct pstruct pst,
13721 X           char *seqc0, char *seqc1, char *seqca,
13722 X           struct f_struct *f_str)
13723 {
13724 X  int i0, i1, nn1, n0t;
13725 X  int op, lenc, len_gap, nd, ns, itmp;
13726 X  const unsigned char *aa1p;
13727 X  char *sp0, *sp1, *spa;
13728 X  int *rp;
13729 X  int mins, smins;
13730 X  
13731 #ifndef TFAST
13732 X  aa1p = aa1;
13733 X  nn1 = n1;
13734 #else
13735 X  aa1p = f_str->aa1x;
13736 X  nn1 = f_str->n10;
13737 #endif
13738 X
13739 X  aln->amin0 = a_res.min0;
13740 X  aln->amin1 = a_res.min1;
13741 X  aln->amax0 = a_res.max0;
13742 X  aln->amax1 = a_res.max1;
13743 X
13744 X  /* first fill in the ends */
13745 X  n0 -= (f_str->nm0-1);
13746 X
13747 X  if (min(a_res.min0,a_res.min1)<aln->llen || aln->showall==1)
13748 X                       /* will we show all the start ?*/
13749 X    if (a_res.min0>=a_res.min1) {                        /* aa0 extends more to left */
13750 X      smins=0;
13751 X      if (aln->showall==1) mins=a_res.min0;
13752 X      else mins = min(a_res.min0,aln->llen/2);
13753 X      aancpy(seqc0,(char *)f_str->aa0t+a_res.min0-mins,mins,pst);
13754 X      aln->smin0 = a_res.min0-mins;
13755 X      if ((mins-a_res.min1)>0) {
13756 X       memset(seqc1,' ',mins-a_res.min1);
13757 X       aancpy(seqc1+mins-a_res.min1,(char *)aa1p,a_res.min1,pst);
13758 X       aln->smin1 = 0;
13759 X      }
13760 X      else {
13761 X       aancpy(seqc1,(char *)aa1p+a_res.min1-mins,mins,pst);
13762 X       aln->smin1 = a_res.min1-mins;
13763 X      }
13764 X    }
13765 X    else {
13766 X      smins=0;
13767 X      if (aln->showall == 1) mins=a_res.min1;
13768 X      else mins = min(a_res.min1,aln->llen/2);
13769 X      aancpy(seqc1,(char *)(aa1p+a_res.min1-mins),mins,pst);
13770 X      aln->smin1 = a_res.min1-mins;
13771 X      if ((mins-a_res.min0)>0) {
13772 X       memset(seqc0,' ',mins-a_res.min0);
13773 X       aancpy(seqc0+mins-a_res.min0,(char *)f_str->aa0t,a_res.min0,pst);
13774 X       aln->smin0 = 0;
13775 X      }
13776 X      else {
13777 X       aancpy(seqc0,(char *)f_str->aa0t+a_res.min0-mins,mins,pst);
13778 X       aln->smin0 = a_res.min0-mins;
13779 X      }
13780 X    }
13781 X  else {
13782 X    mins= min(aln->llen/2,min(a_res.min0,a_res.min1));
13783 X    smins=mins;
13784 X    aln->smin0=a_res.min0;
13785 X    aln->smin1=a_res.min1;
13786 X    aancpy(seqc0,(char *)f_str->aa0t+a_res.min0-mins,mins,pst);
13787 X    aancpy(seqc1,(char *)aa1p+a_res.min1-mins,mins,pst);
13788 X  }
13789 X
13790 X  memset(seqca,M_BLANK,mins);
13791 X
13792 /* now get the middle */
13793 X
13794 X  spa = seqca+mins;
13795 X  sp0 = seqc0+mins;
13796 X  sp1 = seqc1+mins;
13797 X  rp = a_res.res;
13798 X  n0t = lenc = len_gap = aln->nident = aln->nsim = aln->ngap_q = aln->ngap_l = op = 0;
13799 X  i0 = a_res.min0;
13800 X  i1 = a_res.min1;
13801 X  
13802 X  /* op is the previous "match/insert" operator; *rp is the current
13803 X     operator or repeat count */
13804 X
13805 X  while (i0 < a_res.max0 || i1 < a_res.max1) {
13806 X    if (op == 0 && *rp == 0) { /* previous was match (or start), current is match */
13807 X      op = *rp++;              /* get the next match/insert operator */
13808 X
13809 X      /* get the alignment symbol */
13810 X      if ((itmp=pst.pam2[0][f_str->aa0t[i0]][aa1p[i1]])<0) { *spa = M_NEG; }
13811 X      else if (itmp == 0) { *spa = M_ZERO;}
13812 X      else {*spa = M_POS;}
13813 X      if (*spa == M_ZERO || *spa == M_POS) { aln->nsim++;}
13814 X
13815 X      *sp0 = pst.sq[f_str->aa0t[i0++]];        /* get the residues for the consensus */
13816 X      *sp1 = pst.sq[aa1p[i1++]];
13817 X      n0t++;
13818 X      lenc++;
13819 X      if (toupper(*sp0) == toupper(*sp1)) {aln->nident++; *spa = M_IDENT;}
13820 X      sp0++; sp1++; spa++;
13821 X    }
13822 X    else {     /* either op != 0 (previous was insert) or *rp != 0
13823 X                  (current is insert) */
13824 X      if (op==0) { op = *rp++;}        /* previous was match, start insert */
13825 X                               /* previous was insert - count through gap */
13826 X      *sp0++ = '-';
13827 X      *sp1++ = pst.sq[aa1p[i1++]];
13828 X      *spa++ = M_DEL;
13829 X      op--;
13830 X      len_gap++;
13831 X      lenc++;
13832 X    }
13833 X  }
13834 X
13835 X  *spa = '\0';
13836 X  *nc = lenc-len_gap;
13837 /*      now we have the middle, get the right end */
13838 X
13839 X  ns = mins + lenc + aln->llen;
13840 X  ns -= (itmp = ns %aln->llen);
13841 X  if (itmp>aln->llen/2) ns += aln->llen;
13842 X  nd = ns - (mins+lenc);
13843 X  if (nd > max(n0t-a_res.max0,nn1-a_res.max1)) nd = max(n0t-a_res.max0,nn1-a_res.max1);
13844 X  
13845 X  if (aln->showall==1) {
13846 X    nd = max(n0t-a_res.max0,nn1-a_res.max1);   /* reset for showall=1 */
13847 X    /* get right end */
13848 X    aancpy(seqc0+mins+lenc,(char *)f_str->aa0t+a_res.max0,n0t-a_res.max0,pst);
13849 X    aancpy(seqc1+mins+lenc,(char *)aa1p+a_res.max1,nn1-a_res.max1,pst);
13850 X    /* fill with blanks - this is required to use one 'nc' */
13851 X    memset(seqc0+mins+lenc+n0t-a_res.max0,' ',nd-(n0t-a_res.max0));
13852 X    memset(seqc1+mins+lenc+nn1-a_res.max1,' ',nd-(nn1-a_res.max1));
13853 X  }
13854 X  else {
13855 X    if ((nd-(n0t-a_res.max0))>0) {
13856 X      aancpy(seqc0+mins+lenc,(char *)f_str->aa0t+a_res.max0,
13857 X            n0t-a_res.max0,pst);
13858 X      memset(seqc0+mins+lenc+n0t-a_res.max0,' ',nd-(n0t-a_res.max0));
13859 X    }
13860 X    else aancpy(seqc0+mins+lenc,(char *)f_str->aa0t+a_res.max0,nd,pst);
13861 X    if ((nd-(nn1-a_res.max1))>0) {
13862 X      aancpy(seqc1+mins+lenc,(char *)aa1p+a_res.max1,nn1-a_res.max1,pst);
13863 X      memset(seqc1+mins+lenc+nn1-a_res.max1,' ',nd-(nn1-a_res.max1));
13864 X    }
13865 X    else aancpy(seqc1+mins+lenc,(char *)aa1p+a_res.max1,nd,pst);
13866 X  }
13867 X  
13868 X  return mins+lenc+nd;
13869 }
13870 X
13871 int
13872 calcons_a(const unsigned char *aa0, unsigned char *aa0a, int n0,
13873 X         const unsigned char *aa1, int n1,
13874 X         int *nc,
13875 X         struct a_struct *aln,
13876 X         struct a_res_str a_res,
13877 X         struct pstruct pst,
13878 X         char *seqc0, char *seqc0a, char *seqc1, char *seqca,
13879 X         char *ann_arr, struct f_struct *f_str)
13880 {
13881 X  int i0, i1, nn1, n0t;
13882 X  int op, lenc, len_gap, nd, ns, itmp, p_ac, fnum, o_fnum;
13883 X  const unsigned char *aa1p;
13884 X  unsigned char *aa0ap;
13885 X  char *sp0, *sp0a, *sp1, *spa;
13886 X  int *rp;
13887 X  int mins, smins;
13888 X  
13889 #ifndef TFAST
13890 X  aa1p = aa1;
13891 X  nn1 = n1;
13892 #else
13893 X  aa1p = f_str->aa1x;
13894 X  nn1 = f_str->n10;
13895 #endif
13896 X
13897 X  aln->amin0 = a_res.min0;
13898 X  aln->amin1 = a_res.min1;
13899 X  aln->amax0 = a_res.max0;
13900 X  aln->amax1 = a_res.max1;
13901 X
13902 X  /* first fill in the ends */
13903 X  n0 -= (f_str->nm0-1);
13904 X
13905 X  if (min(a_res.min0,a_res.min1)<aln->llen || aln->showall==1)
13906 X                       /* will we show all the start ?*/
13907 X    if (a_res.min0>=a_res.min1) {                        /* aa0 extends more to left */
13908 X      smins=0;
13909 X      if (aln->showall==1) mins=a_res.min0;
13910 X      else mins = min(a_res.min0,aln->llen/2);
13911 X      aancpy(seqc0,(char *)f_str->aa0t+a_res.min0-mins,mins,pst);
13912 X      aln->smin0 = a_res.min0-mins;
13913 X      if ((mins-a_res.min1)>0) {
13914 X       memset(seqc1,' ',mins-a_res.min1);
13915 X       aancpy(seqc1+mins-a_res.min1,(char *)aa1p,a_res.min1,pst);
13916 X       aln->smin1 = 0;
13917 X      }
13918 X      else {
13919 X       aancpy(seqc1,(char *)aa1p+a_res.min1-mins,mins,pst);
13920 X       aln->smin1 = a_res.min1-mins;
13921 X      }
13922 X    }
13923 X    else {
13924 X      smins=0;
13925 X      if (aln->showall == 1) mins=a_res.min1;
13926 X      else mins = min(a_res.min1,aln->llen/2);
13927 X      aancpy(seqc1,(char *)(aa1p+a_res.min1-mins),mins,pst);
13928 X      aln->smin1 = a_res.min1-mins;
13929 X      if ((mins-a_res.min0)>0) {
13930 X       memset(seqc0,' ',mins-a_res.min0);
13931 X       aancpy(seqc0+mins-a_res.min0,(char *)f_str->aa0t,a_res.min0,pst);
13932 X       aln->smin0 = 0;
13933 X      }
13934 X      else {
13935 X       aancpy(seqc0,(char *)f_str->aa0t+a_res.min0-mins,mins,pst);
13936 X       aln->smin0 = a_res.min0-mins;
13937 X      }
13938 X    }
13939 X  else {
13940 X    mins= min(aln->llen/2,min(a_res.min0,a_res.min1));
13941 X    smins=mins;
13942 X    aln->smin0=a_res.min0;
13943 X    aln->smin1=a_res.min1;
13944 X    aancpy(seqc0,(char *)f_str->aa0t+a_res.min0-mins,mins,pst);
13945 X    aancpy(seqc1,(char *)aa1p+a_res.min1-mins,mins,pst);
13946 X  }
13947 X
13948 X  memset(seqca,M_BLANK,mins);
13949 X  memset(seqc0a,' ', mins);
13950 X
13951 /* now get the middle */
13952 X
13953 X  spa = seqca+mins;
13954 X  sp0 = seqc0+mins;
13955 X  sp0a = seqc0a+mins;
13956 X  sp1 = seqc1+mins;
13957 X  rp = a_res.res;
13958 X  n0t=lenc=len_gap=aln->nident=aln->nsim=aln->ngap_q=aln->ngap_l=op=p_ac= 0;
13959 X  i0 = a_res.min0;
13960 X  i1 = a_res.min1;
13961 X  
13962 X  /* op is the previous "match/insert" operator; *rp is the current
13963 X     operator or repeat count */
13964 X
13965 X  o_fnum = f_str->aa0ti[i0];
13966 X  aa0ap = &aa0a[f_str->nmoff[o_fnum]+i0];
13967 X
13968 X  while (i0 < a_res.max0 || i1 < a_res.max1) {
13969 X    fnum = f_str->aa0ti[i0];
13970 X    if (op == 0 && *rp == 0) { /* previous was match (or start), current is match */
13971 X      if (p_ac == 0) { /* previous code was a match */
13972 X       if (fnum != o_fnum) { /* continuing a match, but with a different fragment */
13973 X         aa0ap = &aa0a[f_str->nmoff[fnum]];
13974 X         o_fnum = fnum;
13975 X       }
13976 X      }
13977 X      else {
13978 X       p_ac = 0; o_fnum = fnum = f_str->aa0ti[i0];
13979 X       aa0ap = &aa0a[f_str->nmoff[fnum]];
13980 X      }
13981 X      op = *rp++;              /* get the next match/insert operator */
13982 X
13983 X      /* get the alignment symbol */
13984 X      if ((itmp=pst.pam2[0][f_str->aa0t[i0]][aa1p[i1]])<0) { *spa = M_NEG; }
13985 X      else if (itmp == 0) { *spa = M_ZERO;}
13986 X      else {*spa = M_POS;}
13987 X      if (*spa == M_ZERO || *spa == M_POS) { aln->nsim++;}
13988 X
13989 X      *sp0 = pst.sq[f_str->aa0t[i0++]];        /* get the residues for the consensus */
13990 X      *sp0a++ = ann_arr[*aa0ap++];
13991 X      *sp1 = pst.sq[aa1p[i1++]];
13992 X      n0t++;
13993 X      lenc++;
13994 X      if (toupper(*sp0) == toupper(*sp1)) {aln->nident++; *spa = M_IDENT;}
13995 X      sp0++; sp1++; spa++;
13996 X    }
13997 X    else {     /* either op != 0 (previous was insert) or *rp != 0
13998 X                  (current is insert) */
13999 X      if (op==0) { op = *rp++;}        /* previous was match, start insert */
14000 X                               /* previous was insert - count through gap */
14001 X      if (p_ac != 1) {
14002 X       p_ac = 1; fnum = f_str->aa0ti[i0];
14003 X      }
14004 X
14005 X      *sp0++ = '-';
14006 X      *sp1++ = pst.sq[aa1p[i1++]];
14007 X      *spa++ = M_DEL;
14008 X      *sp0a++ = ' ';
14009 X      op--;
14010 X      len_gap++;
14011 X      lenc++;
14012 X    }
14013 X  }
14014 X
14015 X  *sp0a = *spa = '\0';
14016 X  *nc = lenc-len_gap;
14017 /*      now we have the middle, get the right end */
14018 X
14019 X  ns = mins + lenc + aln->llen;
14020 X  ns -= (itmp = ns %aln->llen);
14021 X  if (itmp>aln->llen/2) ns += aln->llen;
14022 X  nd = ns - (mins+lenc);
14023 X  if (nd > max(n0t-a_res.max0,nn1-a_res.max1)) nd = max(n0t-a_res.max0,nn1-a_res.max1);
14024 X  
14025 X  if (aln->showall==1) {
14026 X    nd = max(n0t-a_res.max0,nn1-a_res.max1);   /* reset for showall=1 */
14027 X    /* get right end */
14028 X    aancpy(seqc0+mins+lenc,(char *)f_str->aa0t+a_res.max0,n0t-a_res.max0,pst);
14029 X    aancpy(seqc1+mins+lenc,(char *)aa1p+a_res.max1,nn1-a_res.max1,pst);
14030 X    /* fill with blanks - this is required to use one 'nc' */
14031 X    memset(seqc0+mins+lenc+n0t-a_res.max0,' ',nd-(n0t-a_res.max0));
14032 X    memset(seqc1+mins+lenc+nn1-a_res.max1,' ',nd-(nn1-a_res.max1));
14033 X  }
14034 X  else {
14035 X    if ((nd-(n0t-a_res.max0))>0) {
14036 X      aancpy(seqc0+mins+lenc,(char *)f_str->aa0t+a_res.max0,
14037 X            n0t-a_res.max0,pst);
14038 X      memset(seqc0+mins+lenc+n0t-a_res.max0,' ',nd-(n0t-a_res.max0));
14039 X    }
14040 X    else aancpy(seqc0+mins+lenc,(char *)f_str->aa0t+a_res.max0,nd,pst);
14041 X    if ((nd-(nn1-a_res.max1))>0) {
14042 X      aancpy(seqc1+mins+lenc,(char *)aa1p+a_res.max1,nn1-a_res.max1,pst);
14043 X      memset(seqc1+mins+lenc+nn1-a_res.max1,' ',nd-(nn1-a_res.max1));
14044 X    }
14045 X    else aancpy(seqc1+mins+lenc,(char *)aa1p+a_res.max1,nd,pst);
14046 X  }
14047 X  return mins+lenc+nd;
14048 }
14049 X
14050 void aaptrshuffle(unsigned char *res, int n) {
14051 X
14052 X  int i, j;
14053 X  unsigned char tmp;
14054 X
14055 X  for( i = n; --i; ) {
14056 X
14057 X    /* j = nrand(i); if (i == j) continue; */ /* shuffle */
14058 X    j = (n - 1) - i; if (i <= j ) break; /* reverse */
14059 X
14060 X    tmp = res[i];
14061 X    res[i] = res[j];
14062 X    res[j] = tmp;
14063 X  }
14064 }
14065 X
14066 void aa0shuffle(unsigned char *aa0, int n0, struct f_struct *f_str) {
14067 X
14068 X  int i;
14069 X  int j;
14070 X
14071 X  for(i = 0 ; i < f_str->nm0 ; i++) { /* for each fragment */
14072 X
14073 X    aaptrshuffle(&(aa0[f_str->nmoff[i]]), 
14074 X                f_str->nmoff[i+1] - f_str->nmoff[i] - 1 );
14075 X
14076 X  }
14077 X
14078 }
14079 X
14080 /* build an array of match/ins/del - length strings */
14081 int
14082 calc_code(const unsigned char *aa0, const int n0,
14083 X         const unsigned char *aa1, const int n1,
14084 X         struct a_struct *aln,
14085 X         struct a_res_str a_res,
14086 X         struct pstruct pst,
14087 X         char *al_str, int al_str_n, struct f_struct *f_str)
14088 {
14089 X  int i0, i1, nn1;
14090 X  int op, lenc, len_gap;
14091 X  int p_ac, op_cnt;
14092 X  const unsigned char *aa1p;
14093 X  char tmp_cnt[20];
14094 X  char sp0, sp1, *sq;
14095 X  int *rp;
14096 X  int mins, smins;
14097 X  int o_fnum,fnum = 0;
14098 X
14099 X  if (pst.ext_sq_set) {sq = pst.sqx;}
14100 X  else {sq = pst.sq;}
14101 X
14102 #ifndef TFAST
14103 X  aa1p = aa1;
14104 X  nn1 = n1;
14105 #else
14106 X  aa1p = f_str->aa1x;
14107 X  nn1 = f_str->n10;
14108 #endif
14109 X
14110 X  aln->amin0 = a_res.min0;
14111 X  aln->amin1 = a_res.min1;
14112 X  aln->amax0 = a_res.max0;
14113 X  aln->amax1 = a_res.max1;
14114 X
14115 X  rp = a_res.res;
14116 X  lenc = len_gap =aln->nident=aln->nsim=aln->ngap_q=aln->ngap_l=aln->nfs=op=p_ac = 0;
14117 X  op_cnt = 0;
14118 X
14119 X  i0 = a_res.min0;     /* start in aa0 (f_str->aa0t) */
14120 X  i1 = a_res.min1;     /* start in aa1 */
14121 X  tmp_cnt[0]='\0';
14122 X  
14123 X  o_fnum = f_str->aa0ti[i0] + 1;       /* fragment number */
14124 X  while (i0 < a_res.max0 || i1 < a_res.max1) {
14125 X    fnum = f_str->aa0ti[i0]+1;
14126 X    if (op == 0 && *rp == 0) { /* previous was match, this is match */
14127 X      if (p_ac == 0) { /* previous code was a match */
14128 X       if (fnum == o_fnum) { op_cnt++;}
14129 X       else {          /* continuing a match, but with a different fragment */
14130 X         update_code(al_str,al_str_n-strlen(al_str), p_ac, op_cnt, o_fnum);
14131 X         o_fnum = fnum;
14132 X         op_cnt=1;
14133 X       }
14134 X      }
14135 X      else {
14136 X       update_code(al_str,al_str_n-strlen(al_str),p_ac,op_cnt,o_fnum);
14137 X       op_cnt = 1; p_ac = 0; o_fnum = fnum = f_str->aa0ti[i0] + 1;
14138 X      }
14139 X      op = *rp++;
14140 X      lenc++;
14141 X      if (pst.pam2[0][f_str->aa0t[i0]][aa1p[i1]]>=0) {aln->nsim++;}
14142 X      sp0 = pst.sq[f_str->aa0t[i0++]];
14143 X      sp1 = pst.sq[aa1p[i1++]];
14144 X      if (toupper(sp0) == toupper(sp1)) aln->nident++;
14145 X    }
14146 X    else {
14147 X      if (op==0) op = *rp++;
14148 X      if (p_ac == 1) { op_cnt++;}
14149 X      else {
14150 X       update_code(al_str,al_str_n - strlen(al_str),p_ac,op_cnt,o_fnum);
14151 X       op_cnt = 1; p_ac = 1; fnum = f_str->aa0ti[i0] + 1;
14152 X      }
14153 X      op--; lenc++; i1++; len_gap++;
14154 X    }
14155 X  }
14156 X  update_code(al_str,al_str_n - strlen(al_str),p_ac,op_cnt,o_fnum);
14157 X
14158 X  return lenc - len_gap;
14159 }
14160 X
14161 /* update_code(): if "op" == 0, this is the end of a match of length
14162 X   "op_cnt" involving fragment "fnum"
14163 X   otherwise, this is an insertion (op==1) or deletion (op==2)
14164 */
14165 X
14166 void
14167 update_code(char *al_str, int al_str_max, int op, int op_cnt, int fnum) {
14168 X
14169 X  char op_char[4]={"=-+"};
14170 X  char tmp_cnt[20];
14171 X
14172 X  if (op == 0)
14173 X    sprintf(tmp_cnt,"%c%d[%d]",op_char[op],op_cnt,fnum);
14174 X  else
14175 X    sprintf(tmp_cnt,"%c%d",op_char[op],op_cnt);
14176 X
14177 X  strncat(al_str,tmp_cnt,al_str_max);
14178 }
14179 X
14180 int
14181 calc_id(const unsigned char *aa0, int n0,
14182 X       const unsigned char *aa1, int n1,
14183 X       struct a_struct *aln,
14184 X       struct a_res_str a_res,
14185 X       struct pstruct pst,
14186 X       struct f_struct *f_str)
14187 {
14188 X  int i0, i1, nn1;
14189 X  int op, lenc, len_gap;
14190 X  const unsigned char *aa1p;
14191 X  int sp0, sp1;
14192 X  int *rp;
14193 X  int mins, smins;
14194 X  
14195 #ifndef TFAST
14196 X  aa1p = aa1;
14197 X  nn1 = n1;
14198 #else
14199 X  aa1p = f_str->aa1x;
14200 X  nn1 = f_str->n10;
14201 #endif
14202 X
14203 X  aln->amin0 = a_res.min0;
14204 X  aln->amin1 = a_res.min1;
14205 X  aln->amax0 = a_res.max0;
14206 X  aln->amax1 = a_res.max1;
14207 X
14208 X  /* first fill in the ends */
14209 X  n0 -= (f_str->nm0-1);
14210 X
14211 X  /* now get the middle */
14212 X  rp = a_res.res;
14213 X  lenc=len_gap=aln->nident=aln->nsim=aln->ngap_q = aln->ngap_l = aln->nfs = op = 0;
14214 X  i0 = a_res.min0;
14215 X  i1 = a_res.min1;
14216 X  
14217 X  while (i0 < a_res.max0 || i1 < a_res.max1) {
14218 X    if (op == 0 && *rp == 0) {
14219 X      op = *rp++;
14220 X
14221 X      if (pst.pam2[0][f_str->aa0t[i0]][aa1p[i1]]>=0) {aln->nsim++;}
14222 X
14223 X      sp0 = pst.sq[f_str->aa0t[i0++]];
14224 X      sp1 = pst.sq[aa1p[i1++]];
14225 X      lenc++;
14226 X      if (toupper(sp0) == toupper(sp1)) aln->nident++;
14227 X    }
14228 X    else {
14229 X      if (op==0) { op = *rp++;}
14230 X      i1++;
14231 X      op--;
14232 X      len_gap++;
14233 X      lenc++;
14234 X    }
14235 X  }
14236 X  return lenc-len_gap;
14237 }
14238 X
14239 #ifdef PCOMPLIB
14240 X
14241 #include "structs.h"
14242 #include "p_mw.h"
14243 X
14244 void
14245 update_params(struct qmng_str *qm_msg,
14246 X             struct mngmsg *m_msg, struct pstruct *ppst)
14247 {
14248 X  m_msg->n0 = ppst->n0 = qm_msg->n0;
14249 X  m_msg->nm0 = qm_msg->nm0;
14250 X  m_msg->escore_flg = qm_msg->escore_flg;
14251 X  m_msg->qshuffle = qm_msg->qshuffle;
14252 }
14253 #endif
14254 SHAR_EOF
14255 chmod 0644 dropfs2.c ||
14256 echo 'restore of dropfs2.c failed'
14257 Wc_c="`wc -c < 'dropfs2.c'`"
14258 test 59078 -eq "$Wc_c" ||
14259         echo 'dropfs2.c: original size 59078, current size' "$Wc_c"
14260 fi
14261 # ============= dropfx.c ==============
14262 if test -f 'dropfx.c' -a X"$1" != X"-c"; then
14263         echo 'x - skipping dropfx.c (File already exists)'
14264 else
14265 echo 'x - extracting dropfx.c (Text)'
14266 sed 's/^X//' << 'SHAR_EOF' > 'dropfx.c' &&
14267 X
14268 /* copyright (c) 1998, 1999 William R. Pearson and the U. of Virginia */
14269 X
14270 /* $Name: fa_34_26_5 $ - $Id: dropfx.c,v 1.68 2007/04/26 18:37:18 wrp Exp $ */
14271 X
14272 /* implements the fastx algorithm, see:
14273 X
14274 X   W. R. Pearson, T. Wood, Z. Zhang, A W. Miller (1997) "Comparison of
14275 X   DNA sequences with protein sequences" Genomics 46:24-36
14276 X
14277 X   see dropnfa.c for better variable descriptions and comments
14278 */
14279 X   
14280 /* 18-Sept-2006 - remove global variables used for alignment */
14281 X
14282 /* 22-June-2006 - correct incorrect alignment coordinates generated
14283 X   after pro_dna() on projected DNA region.  
14284 */
14285 X
14286 /* 9-May-2003 -> 3.46 changed lx_band to use projected protein
14287 X   boundary end.  this fixes some addressing issues on MacOSX, and
14288 X   speeds up alignment on very long proteins
14289 */
14290 X
14291 #include <stdio.h>
14292 #include <stdlib.h>
14293 #include <string.h>
14294 #include <ctype.h>
14295 #include <math.h>
14296 X
14297 #include "defs.h"
14298 #include "param.h"
14299 #define XTERNAL
14300 #include "upam.h"
14301 X
14302 /* this must be consistent with upam.h */
14303 #define MAXHASH 32
14304 #define NMAP MAXHASH+1
14305 X
14306 /* globals for fasta */
14307 #define MAXWINDOW 64
14308 X
14309 #ifndef MAXSAV
14310 #define MAXSAV 10
14311 #endif
14312 X
14313 #ifndef ALLOCN0
14314 static char *verstr="3.5 Sept 2006";
14315 #else
14316 static char *verstr="3.5an0 May 2006";
14317 #endif
14318 X
14319 struct dstruct          /* diagonal structure for saving current run */
14320 {                       
14321 X   int     score;      /* hash score of current match */
14322 X   int     start;      /* start of current match */
14323 X   int     stop;       /* end of current match */
14324 X   struct savestr *dmax;   /* location in vmax[] where best score data saved */
14325 };
14326 X
14327 struct savestr
14328 {
14329 X   int     score;              /* pam score with segment optimization */
14330 X   int     score0;             /* pam score of best single segment */
14331 X   int     gscore;             /* score from global match */
14332 X   int     dp;                 /* diagonal of match */
14333 X   int     start;              /* start of match in lib seq */
14334 X   int     stop;               /* end of match in lib seq */
14335 };
14336 X
14337 struct swstr { int H, E;};
14338 X
14339 struct bdstr { int CC, DD, CP, DP;};
14340 X
14341 void savemax();
14342 void kpsort();
14343 X
14344 struct sx_s {int C1, C2, C3, I1, I2, I3, flag; };
14345 X
14346 struct f_struct {
14347 X  struct dstruct *diag;
14348 X  struct savestr vmax[MAXSAV]; /* best matches saved for one sequence */
14349 X  struct savestr *vptr[MAXSAV];
14350 X  struct savestr *lowmax;
14351 X  int ndo;
14352 X  int noff;
14353 X  int hmask;                   /* hash constants */
14354 X  int *pamh1;                  /* pam based array */
14355 X  int *pamh2;                  /* pam based kfact array */
14356 X  int *link, *harr;            /* hash arrays */
14357 X  int kshft;                   /* shift width */
14358 X  int nsav, lowscor;           /* number of saved runs, worst saved run */
14359 #ifndef TFAST
14360 X  unsigned char *aa0x;         /* contains translated codons 111222333*/
14361 X  unsigned char *aa0y;         /* contains translated codons 123123123*/
14362 #else
14363 X  unsigned char *aa1x;         /* contains translated codons 111222333 */
14364 X  unsigned char *aa1y;         /* contains translated codons 123123123 */
14365 #endif
14366 X  struct sx_s *cur;
14367 X  int *waa0;
14368 X  int *waa1;
14369 X  int *res;
14370 X  int max_res;
14371 };
14372 X
14373 #define DROP_INTERN
14374 #include "drop_func.h"
14375 X
14376 static int dmatchx(const unsigned char *aa0, int n0,
14377 X                  const unsigned char *aa1, int n1,
14378 X                  int hoff, int window, 
14379 X                  int **pam2, int gdelval, int ggapval, int gshift,
14380 X                  struct f_struct *f_str);
14381 X
14382 int shscore(unsigned char *aa0, int n0, int **pam2);
14383 int saatran(const unsigned char *ntseq, unsigned char *aaseq, int maxs, int frame);
14384 int spam (const unsigned char *aa0, const unsigned char *aa1, 
14385 X         struct savestr *dmax, int **pam2,
14386 X         struct f_struct *f_str);
14387 int sconn (struct savestr **v, int n,int cgap, int pgap, struct f_struct *f_str);
14388 int lx_band(const unsigned char *prot_seq, int len_prot,
14389 X           const unsigned char *dna_prot_seq, int len_dna_prot,
14390 X           int **pam_matrix, int gopen, int gext,
14391 X           int gshift, int start_diag, int width, struct f_struct *f_str);
14392 X
14393 static void
14394 update_code(char *al_str, int al_str_max, int op, int op_cnt, char *op_char);
14395 X
14396 extern void w_abort (char *p, char *p1);
14397 X
14398 /* initialize for fasta */
14399 X
14400 void
14401 init_work (unsigned char *aa0, int n0, 
14402 X          struct pstruct *ppst,
14403 X          struct f_struct **f_arg)
14404 {
14405 X   int mhv, phv;
14406 X   int hmax;
14407 X   int i0, hv;
14408 X   int pamfact;
14409 X   int btemp;
14410 X   struct f_struct *f_str;
14411 X   int ktup;           /* word size examined */
14412 X   int fact;           /* factor used to scale ktup match value */
14413 X   int kt1;            /* ktup-1 */
14414 X   int lkt;            /* last ktup - initiall kt1, but can be increased
14415 X                          for hsq >= NMAP */
14416 X
14417 X   int maxn0;
14418 X   int *pwaa;
14419 X   int i, j, q;
14420 X   struct swstr *ss, *r_ss;
14421 X   int *waa;
14422 X   int *res;
14423 X   int nsq, ip, *hsq;
14424 #ifndef TFAST
14425 X   int last_n0, itemp;
14426 X   unsigned char *fd, *fs, *aa0x, *aa0y, *aa0s;
14427 X   int n0x, n0x3;
14428 #endif
14429 X
14430 X  if (ppst->ext_sq_set) {
14431 X    nsq = ppst->nsqx; ip = 1;
14432 X    hsq = ppst->hsqx;
14433 X  }
14434 X  else {
14435 X    nsq = ppst->nsq; ip = 0;
14436 X    hsq = ppst->hsq;
14437 X  }
14438 X
14439 X   f_str = (struct f_struct *)calloc(1,sizeof(struct f_struct));
14440 X
14441 X   btemp = 2 * ppst->param_u.fa.bestoff / 3 +
14442 X      n0 / ppst->param_u.fa.bestscale +
14443 X      ppst->param_u.fa.bkfact *
14444 X      (ppst->param_u.fa.bktup - ppst->param_u.fa.ktup);
14445 X   btemp = min (btemp, ppst->param_u.fa.bestmax);
14446 X   if (btemp > 3 * n0) btemp = 3 * shscore(aa0,n0,ppst->pam2[0]) / 5;
14447 X
14448 X   ppst->param_u.fa.cgap = btemp + ppst->param_u.fa.bestoff / 3;
14449 X   if (ppst->param_u.fa.optcut_set != 1)
14450 #ifndef TFAST
14451 X      ppst->param_u.fa.optcut = (btemp*5)/4;
14452 #else
14453 X      ppst->param_u.fa.optcut = (btemp*4)/3;
14454 #endif
14455 X
14456 #ifdef OLD_FASTA_GAP
14457 X   ppst->param_u.fa.pgap = ppst->gdelval + ppst->ggapval;
14458 #else
14459 X   ppst->param_u.fa.pgap = ppst->gdelval + 2*ppst->ggapval;
14460 #endif
14461 X   pamfact = ppst->param_u.fa.pamfact;
14462 X   ktup = ppst->param_u.fa.ktup;
14463 X   fact = ppst->param_u.fa.scfact * ktup;
14464 X
14465 X   if (pamfact == -1)
14466 X      pamfact = 0;
14467 X   else if (pamfact == -2)
14468 X      pamfact = 1;
14469 X
14470 X   for (i0 = 1, mhv = -1; i0 <=nsq; i0++)
14471 X      if (hsq[i0] < NMAP && hsq[i0] > mhv) mhv = hsq[i0];
14472 X
14473 X   if (mhv <= 0) {
14474 X      fprintf (stderr, " maximum hsq <=0 %d\n", mhv);
14475 X      exit (1);
14476 X   }
14477 X
14478 X   for (f_str->kshft = 0; mhv > 0; mhv /= 2)
14479 X      f_str->kshft++;
14480 X
14481 /*      kshft = 2;      */
14482 X   kt1 = ktup - 1;
14483 X   hv = 1;
14484 X   for (i0 = 0; i0 < ktup; i0++) {
14485 X     hv = hv << f_str->kshft;
14486 X   }
14487 X   hmax = hv;
14488 X   f_str->hmask = (hmax >> f_str->kshft) - 1;
14489 X
14490 X
14491 X   if ((f_str->harr = (int *) calloc (hmax, sizeof (int))) == NULL) {
14492 X     fprintf (stderr, " cannot allocate hash array\n");
14493 X     exit (1);
14494 X   }
14495 X   if ((f_str->pamh1 = (int *) calloc (nsq+1, sizeof (int))) == NULL) {
14496 X     fprintf (stderr, " cannot allocate pamh1 array\n");
14497 X     exit (1);
14498 X   }
14499 X   if ((f_str->pamh2 = (int *) calloc (hmax, sizeof (int))) == NULL) {
14500 X     fprintf (stderr, " cannot allocate pamh2 array\n");
14501 X     exit (1);
14502 X   }
14503 X   if ((f_str->link = (int *) calloc (n0, sizeof (int))) == NULL) {
14504 X     fprintf (stderr, " cannot allocate hash link array");
14505 X     exit (1);
14506 X   }
14507 X
14508 #ifdef TFAST
14509 X   if ((f_str->aa1x =(unsigned char *)calloc((size_t)ppst->maxlen+2,
14510 X                                            sizeof(unsigned char)))
14511 X       == NULL) {
14512 X     fprintf (stderr, "cannot allocate aa1x array %d\n", ppst->maxlen+2);
14513 X     exit (1);
14514 X   }
14515 X   f_str->aa1x++;
14516 X
14517 X   if ((f_str->aa1y =(unsigned char *)calloc((size_t)ppst->maxlen+2,
14518 X                                            sizeof(unsigned char)))
14519 X       == NULL) {
14520 X     fprintf (stderr, "cannot allocate aa1y array %d\n", ppst->maxlen+2);
14521 X     exit (1);
14522 X   }
14523 X   f_str->aa1y++;
14524 #else   /* FASTX */
14525 X   maxn0 = n0 + 2;
14526 X   if ((aa0x =(unsigned char *)calloc((size_t)maxn0,sizeof(unsigned char)))
14527 X       == NULL) {
14528 X     fprintf (stderr, "cannot allocate aa0x array %d\n", maxn0);
14529 X     exit (1);
14530 X   }
14531 X   aa0x++;
14532 X   f_str->aa0x = aa0x;
14533 X
14534 X   if ((aa0y =(unsigned char *)calloc((size_t)maxn0,sizeof(unsigned char)))
14535 X       == NULL) {
14536 X     fprintf (stderr, "cannot allocate aa0y array %d\n", maxn0);
14537 X     exit (1);
14538 X   }
14539 X   aa0y++;
14540 X   f_str->aa0y = aa0y;
14541 X
14542 X   last_n0 = 0;
14543 X   for (itemp=0; itemp<3; itemp++) {
14544 X     n0x = saatran(aa0,&aa0x[last_n0],n0,itemp);
14545 X     /*
14546 X       for (i=0; i<n0x; i++) {
14547 X       fprintf(stderr,"%c",aa[aa0x[last_n0+i]]);
14548 X       if ((i%60)==59) fprintf(stderr,"\n");
14549 X       }
14550 X       fprintf(stderr,"\n");
14551 X     */
14552 X     last_n0 += n0x+1;
14553 X   }
14554 X
14555 X   /*     fprintf(stderr,"\n"); */
14556 X
14557 X   for (itemp=0, fs=aa0x; itemp <3; itemp++,fs++) {
14558 X     for (fd = &aa0y[itemp]; *fs!=EOSEQ; fd += 3, fs++) *fd = *fs;
14559 X     *fd=EOSEQ;
14560 X   }
14561 X
14562 X   /* now switch aa0 and aa0x for hashing functions */
14563 X   /* this seems dangerous in threaded code, but only the pointer is changed,
14564 X      not the data itself */
14565 X
14566 X   fs = aa0;
14567 X   aa0 = aa0x;
14568 X   aa0x = fs;
14569 X                                        
14570 #endif
14571 X
14572 X   for (i0 = 0; i0 < hmax; i0++)
14573 X      f_str->harr[i0] = -1;
14574 X   for (i0 = 0; i0 < n0; i0++)
14575 X      f_str->link[i0] = -1;
14576 X
14577 X   /* encode the aa0 array */
14578 X
14579 X   phv = hv = 0;
14580 X   lkt = kt1;
14581 X   for (i0 = 0; i0 < min(lkt,n0); i0++) {
14582 X     if (hsq[aa0[i0]] >= NMAP) {hv=phv=0; lkt=i0+ktup; continue;}
14583 X     hv = (hv << f_str->kshft) + hsq[aa0[i0]];
14584 X     phv += ppst->pam2[ip][aa0[i0]][aa0[i0]] * ktup;
14585 X   }
14586 X
14587 X   for (; i0 < n0; i0++) {
14588 X     if (hsq[aa0[i0]] >= NMAP) {
14589 X       hv=phv=0; 
14590 X       lkt = i0+ktup;
14591 X       /* restart hv, phv calculation */
14592 X       for (; (i0 < lkt || hsq[aa0[i0]]>=NMAP) && i0<n0; i0++) {
14593 X        if (hsq[aa0[i0]] >= NMAP) {hv=phv=0; lkt = i0+ktup; continue;}
14594 X        hv = (hv << f_str->kshft) + hsq[aa0[i0]];
14595 X        phv += ppst->pam2[ip][aa0[i0]][aa0[i0]] * ktup;
14596 X       }
14597 X     }
14598 X     if (i0 >= n0) break;
14599 X     hv = ((hv & f_str->hmask) << f_str->kshft) + hsq[aa0[i0]];
14600 X     f_str->link[i0] = f_str->harr[hv];
14601 X     f_str->harr[hv] = i0;
14602 X     if (pamfact) {
14603 X       f_str->pamh2[hv] = (phv += ppst->pam2[ip][aa0[i0]][aa0[i0]] * ktup);
14604 X       /* this check should always be true, but just in case */
14605 X       if (hsq[aa0[i0-kt1]]<NMAP)
14606 X        phv -= ppst->pam2[ip][aa0[i0 - kt1]][aa0[i0 - kt1]] * ktup;
14607 X     }
14608 X     else f_str->pamh2[hv] = fact * ktup;
14609 X   }
14610 X
14611 #ifndef TFAST
14612 X   /* done hashing, now switch aa0, aa0x back */
14613 X   fs = aa0;
14614 X   aa0 = aa0x;
14615 X   aa0x = fs;
14616 #endif
14617 X
14618 /* this has been modified from 0..<nsq to 1..<=nsq because the
14619 X   pam2[0][0] is now undefined for consistency with blast
14620 */
14621 X
14622 X   if (pamfact)
14623 X      for (i0 = 1; i0 <= nsq; i0++)
14624 X        f_str->pamh1[i0] = ppst->pam2[ip][i0][i0] * ktup;
14625 X   else
14626 X      for (i0 = 1; i0 <= nsq; i0++)
14627 X        f_str->pamh1[i0] = fact;
14628 X
14629 X   f_str->ndo = 0;     /* used to save time on diagonals with long queries */
14630 X
14631 #ifndef ALLOCN0
14632 X   if ((f_str->diag = (struct dstruct *) calloc ((size_t)MAXDIAG,
14633 X                                                sizeof (struct dstruct)))==NULL) {
14634 X      fprintf (stderr," cannot allocate diagonal arrays: %ld\n",
14635 X             (long) MAXDIAG *sizeof (struct dstruct));
14636 X      exit (1);
14637 X     };
14638 #else
14639 X   if ((f_str->diag = (struct dstruct *) calloc ((size_t)n0,
14640 X                                             sizeof (struct dstruct)))==NULL) {
14641 X      fprintf (stderr," cannot allocate diagonal arrays: %ld\n",
14642 X             (long)n0*sizeof (struct dstruct));
14643 X      exit (1);
14644 X     };
14645 #endif
14646 X
14647 X
14648 X   if ((waa= (int *)malloc (sizeof(int)*(nsq+1)*n0)) == NULL) {
14649 X     fprintf(stderr,"cannot allocate waa struct %3d\n",nsq*n0);
14650 X     exit(1);
14651 X   }
14652 X
14653 X   pwaa = waa;
14654 X   for (i=0; i<=nsq; i++) {
14655 X     for (j=0;j<n0; j++) {
14656 X       *pwaa = ppst->pam2[ip][i][aa0[j]];
14657 X       pwaa++;
14658 X     }
14659 X   }
14660 X   f_str->waa0 = waa;
14661 X
14662 X   if ((waa= (int *)malloc (sizeof(int)*(nsq+1)*n0)) == NULL) {
14663 X     fprintf(stderr,"cannot allocate waa struct %3d\n",nsq*n0);
14664 X     exit(1);
14665 X   }
14666 X
14667 X   pwaa = waa;
14668 X   for (i=0; i<=nsq; i++) {
14669 X     for (j=0;j<n0; j++) {
14670 X       *pwaa = ppst->pam2[0][i][aa0[j]];
14671 X       pwaa++;
14672 X     }
14673 X   }
14674 X   f_str->waa1 = waa;
14675 X
14676 #ifndef TFAST
14677 X   maxn0 = max(2*n0,MIN_RES);
14678 #else
14679 X   /* maxn0 needs to be large enough to accomodate introns
14680 X      for TFASTX.  For all other functions, it will be
14681 X      more reasonable. */
14682 X   maxn0 = max(4*n0,MIN_RES);
14683 #endif
14684 X   if ((res = (int *)calloc((size_t)maxn0,sizeof(int)))==NULL) {
14685 X     fprintf(stderr,"cannot allocate alignment results array %d\n",maxn0);
14686 X     exit(1);
14687 X   }
14688 X   f_str->res = res;
14689 X   f_str->max_res = maxn0;
14690 X
14691 X   *f_arg = f_str;
14692 }
14693 X
14694 X
14695 /* pstring1 is a message to the manager, currently 512 */
14696 /* pstring2 is the same information, but in a markx==10 format */
14697 void
14698 get_param (struct pstruct *pstr, char *pstring1, char *pstring2)
14699 {
14700 #ifndef TFAST
14701 X  char *pg_str="FASTX";
14702 #else
14703 X  char *pg_str="TFASTX";
14704 #endif
14705 X
14706 X   if (!pstr->param_u.fa.optflag)
14707 #ifdef OLD_FASTA_GAP
14708 X      sprintf (pstring1, "%s (%s) function [%s matrix (%d:%d:%d)%s] ktup: %d\n join: %d, gap-pen: %d/%d, shift: %d width: %3d",pg_str,verstr,
14709 #else
14710 X      sprintf (pstring1, "%s (%s) function [%s matrix (o=%d:%d:%d:%d)%s] ktup: %d\n join: %d, open/ext: %d/%d, shift: %d width: %3d",pg_str,verstr,
14711 #endif
14712 X              pstr->pamfile, pstr->pam_h,pstr->pam_l,pstr->pam_xx,pstr->pam_xm,
14713 X              (pstr->ext_sq_set) ? "xS":"\0",
14714 X              pstr->param_u.fa.ktup, pstr->param_u.fa.cgap,
14715 X              pstr->gdelval, pstr->ggapval, pstr->gshift,
14716 X              pstr->param_u.fa.optwid);
14717 X   else
14718 #ifdef OLD_FASTA_GAP
14719 X      sprintf (pstring1, "%s (%s) function [optimized, %s matrix (%d:%d:%d)%s] ktup: %d\n join: %d, opt: %d, gap-pen: %d/%d shift: %3d, width: %3d",pg_str,verstr,
14720 #else
14721 X      sprintf (pstring1, "%s (%s) function [optimized, %s matrix (o=%d:%d:%d:%d)%s] ktup: %d\n join: %d, opt: %d, open/ext: %d/%d shift: %3d, width: %3d",pg_str,verstr,
14722 #endif
14723 X              pstr->pamfile, pstr->pam_h,pstr->pam_l,pstr->pam_xx, pstr->pam_xm,
14724 X              (pstr->ext_sq_set) ? "xS":"\0",
14725 X              pstr->param_u.fa.ktup, pstr->param_u.fa.cgap,
14726 X              pstr->param_u.fa.optcut, pstr->gdelval, pstr->ggapval,
14727 X              pstr->gshift,pstr->param_u.fa.optwid);
14728 X
14729 X   if (pstr->param_u.fa.iniflag) strcat(pstring1," init1");
14730 X   /*
14731 X   if (pstr->zsflag==0) strcat(pstring1," not-scaled");
14732 X   else if (pstr->zsflag==1) strcat(pstring1," reg.-scaled");
14733 X   */
14734 X
14735 X   if (pstring2 != NULL) {
14736 #ifdef OLD_FASTA_GAP
14737 X     sprintf (pstring2, "; pg_name: %s\n; pg_ver: %s\n; pg_matrix: %s (%d:%d)%s\n\
14738 ; pg_gap-pen: %d %d\n; pg_ktup: %d\n; pg_optcut: %d\n; pg_cgap: %d\n",
14739 #else
14740 X     sprintf (pstring2, "; pg_name: %s\n; pg_ver: %s\n; pg_matrix: %s (%d:%d)%s\n\
14741 ; pg_open_ext: %d %d\n; pg_ktup: %d\n; pg_optcut: %d\n; pg_cgap: %d\n",
14742 #endif
14743 X             pg_str,verstr,pstr->pamfile, pstr->pam_h,pstr->pam_l, 
14744 X             (pstr->ext_sq_set) ? "xS":"\0", pstr->gdelval,
14745 X              pstr->ggapval,pstr->param_u.fa.ktup,pstr->param_u.fa.optcut,
14746 X             pstr->param_u.fa.cgap);
14747 X   }
14748 }
14749 X
14750 void
14751 close_work (const unsigned char *aa0, int n0,
14752 X           struct pstruct *ppst,
14753 X           struct f_struct **f_arg)
14754 {
14755 X  struct f_struct *f_str;
14756 X
14757 X  f_str = *f_arg;
14758 X
14759 X  if (f_str != NULL) {
14760 X    free(f_str->cur);
14761 #ifndef TFAST
14762 X    f_str->aa0y--;
14763 X    free(f_str->aa0y);
14764 X    f_str->aa0x--;
14765 X    free(f_str->aa0x);
14766 #else
14767 X    f_str->aa1y--;
14768 X    free(f_str->aa1y);
14769 X    f_str->aa1x--;
14770 X    free(f_str->aa1x);
14771 #endif
14772 X    free(f_str->res);
14773 X    free(f_str->waa1);
14774 X    free(f_str->waa0);
14775 X    free(f_str->diag);
14776 X    free(f_str->link);
14777 X    free(f_str->pamh2); 
14778 X    free(f_str->pamh1);
14779 X    free(f_str->harr);
14780 X    free(f_str);
14781 X    *f_arg = NULL;
14782 X  }
14783 }
14784 X
14785 void do_fastx (const unsigned char *aa0, int n0,
14786 X              const unsigned char *aa1, int n1,
14787 X              struct pstruct *ppst, struct f_struct *f_str,
14788 X              struct rstruct *rst, int *hoff)
14789 {
14790 X   int     nd;         /* diagonal array size */
14791 X   int     lhval;
14792 X   int     kfact;
14793 X   int i;
14794 X   int my_hoff;
14795 X   register struct dstruct *dptr;
14796 X   register int tscor;
14797 X
14798 #ifndef ALLOCN0
14799 X   register struct dstruct *diagp;
14800 #else
14801 X   register int dpos;
14802 X   int     lposn0;
14803 #endif
14804 X   struct dstruct *dpmax;
14805 X   register int lpos;
14806 X   int     tpos;
14807 X   struct savestr *vmptr;
14808 X   int     scor, tmp;
14809 X   int     im, ib, nsave;
14810 X   int ktup, kt1, *hsq, ip, lkt;
14811 #ifndef TFAST
14812 X   int n0x31, n0x32;
14813 X   n0x31 = (n0-2)/3;
14814 X   n0x32 = n0x31+1+(n0-n0x31-1)/2;
14815 #else
14816 X   const unsigned char *fs;
14817 X   unsigned char *fd;
14818 X   int n1x31, n1x32, last_n1, itemp;
14819 X   n1x31 = (n1-2)/3;
14820 X   n1x32 = n1x31+1+(n1-n1x31-1)/2;
14821 #endif
14822 X
14823 X  if (ppst->ext_sq_set) {
14824 X    ip = 1;
14825 X    hsq = ppst->hsqx;
14826 X  }
14827 X  else {
14828 X    ip = 0;
14829 X    hsq = ppst->hsq;
14830 X  }
14831 X
14832 X   ktup = ppst->param_u.fa.ktup;
14833 X   kt1 = ktup-1;
14834 X
14835 X   if (n1 < ktup) {
14836 X     rst->score[0] = rst->score[1] = rst->score[2] = 0;
14837 X     return;
14838 X   }
14839 X
14840 X   if (n0+n1+1 >= MAXDIAG) {
14841 X     fprintf(stderr,"n0,n1 too large: %d, %d\n",n0,n1);
14842 X     rst->score[0] = rst->score[1] = rst->score[2] = -1;
14843 X     return;
14844 X   }
14845 X
14846 X   f_str->noff = n0 - 1;
14847 X
14848 #ifdef ALLOCN0
14849 X   nd = n0;
14850 #endif
14851 X
14852 #ifndef ALLOCN0
14853 X   nd = n0 + n1;
14854 #endif
14855 X
14856 X   dpmax = &f_str->diag[nd];
14857 X   for (dptr = &f_str->diag[f_str->ndo]; dptr < dpmax;)
14858 X   {
14859 X      dptr->stop = -1;
14860 X      dptr->dmax = NULL;
14861 X      dptr++->score = 0;
14862 X   }
14863 X
14864 X   for (vmptr = f_str->vmax; vmptr < &f_str->vmax[MAXSAV]; vmptr++)
14865 X      vmptr->score = 0;
14866 X   f_str->lowmax = f_str->vmax;
14867 X   f_str->lowscor = 0;
14868 X
14869 X   /* start hashing */
14870 X   lhval = 0;
14871 X   lkt = kt1;
14872 X   for (lpos = 0; (lpos < lkt || hsq[aa1[lpos]]>=NMAP) && lpos<n1; lpos++) {
14873 X     if (hsq[aa1[lpos]]>=NMAP) {
14874 X       lhval = 0; lkt=lpos+ktup; continue;
14875 #ifdef ALLOCN0          /* reinitialize dptr */
14876 X       dptr = &f_str->diag[lpos % nd];
14877 X       dptr->stop = -1;
14878 X       dptr->dmax = NULL;
14879 X       dptr->score = 0;
14880 #endif
14881 X     }
14882 X     lhval = ((lhval & f_str->hmask) << f_str->kshft) + hsq[aa1[lpos]];
14883 X   }
14884 X
14885 #ifndef ALLOCN0
14886 X   diagp = &f_str->diag[f_str->noff + lkt];
14887 X   for (; lpos < n1; lpos++, diagp++) {
14888 X     /*     if (hsq[aa1[lpos]]>=NMAP) {lhval = 0; continue;} */
14889 X     if (hsq[aa1[lpos]]>=NMAP) {
14890 X       lpos++ ; diagp++;
14891 X       while (lpos < n1 && hsq[aa1[lpos]]>=NMAP) {lpos++; diagp++;}
14892 X       if (lpos >= n1) break;
14893 X       lhval = 0;
14894 X     }
14895 X     lhval = ((lhval & f_str->hmask) << f_str->kshft) + hsq[aa1[lpos]];
14896 X     for (tpos = f_str->harr[lhval]; tpos >= 0; tpos = f_str->link[tpos]) {
14897 X       if ((tscor = (dptr = &diagp[-tpos])->stop) >= 0) {
14898 #else
14899 X   lposn0 = f_str->noff + lpos;
14900 X   for (; lpos < n1; lpos++, lposn0++) {
14901 X     if (hsq[aa1[lpos]]>=NMAP) {lhval = 0; goto loopl;}
14902 X     lhval = ((lhval & f_str->hmask) << f_str->kshft) + hsq[aa1[lpos]];
14903 X     for (tpos = f_str->harr[lhval]; tpos >= 0; tpos = f_str->link[tpos]) {
14904 X       dpos = lposn0 - tpos;
14905 X       if ((tscor = (dptr = &f_str->diag[dpos % nd])->stop) >= 0) {
14906 #endif
14907 X        tscor += ktup;
14908 X        if ((tscor -= lpos) <= 0) {    /* better to start over */
14909 X          scor = dptr->score;
14910 X          if ((tscor += (kfact = f_str->pamh2[lhval])) < 0 && f_str->lowscor < scor)
14911 #ifdef ALLOCN0
14912 X            savemax (dptr, dpos, f_str);
14913 #else
14914 X            savemax (dptr, f_str);
14915 #endif
14916 X            if ((tscor += scor) >= kfact) {
14917 X              dptr->score = tscor;
14918 X              dptr->stop = lpos;
14919 X            }
14920 X            else {
14921 X              dptr->score = kfact;
14922 X              dptr->start = (dptr->stop = lpos) - kt1;
14923 X            }
14924 X        }                              /* continue current run in diagonal */
14925 X        else {
14926 X          dptr->score += f_str->pamh1[aa0[tpos]];
14927 X          dptr->stop = lpos;
14928 X        }
14929 X       }
14930 X       else {
14931 X        dptr->score = f_str->pamh2[lhval];
14932 X        dptr->start = (dptr->stop = lpos) - kt1;
14933 X       }
14934 X     }                         /* end tpos */
14935 X
14936 #ifdef ALLOCN0
14937 X      /* reinitialize diag structure */
14938 X   loopl:
14939 X     if ((dptr = &f_str->diag[lpos % nd])->score > f_str->lowscor) {
14940 X          savemax (dptr, lpos, f_str);
14941 X     }
14942 X     dptr->stop = -1;
14943 X     dptr->dmax = NULL;
14944 X     dptr->score = 0;
14945 #endif
14946 X   }                           /* end lpos */
14947 X
14948 #ifdef ALLOCN0
14949 X   for (tpos = 0, dpos = f_str->noff + n1 - 1; tpos < n0; tpos++, dpos--) {
14950 X     if ((dptr = &f_str->diag[dpos % nd])->score > f_str->lowscor)
14951 X       savemax (dptr, dpos, f_str);
14952 X   }
14953 #else
14954 X   for (dptr = f_str->diag; dptr < dpmax;) {
14955 X     if (dptr->score > f_str->lowscor) savemax (dptr, f_str);
14956 X     dptr->stop = -1;
14957 X     dptr->dmax = NULL;
14958 X     dptr++->score = 0;
14959 X   }
14960 X   f_str->ndo = nd;
14961 #endif
14962 X
14963 /*
14964 X        at this point all of the elements of aa1[lpos]
14965 X        have been searched for elements of aa0[tpos]
14966 X        with the results in diag[dpos]
14967 */
14968 X
14969 X   for (nsave = 0, vmptr = f_str->vmax; vmptr < &f_str->vmax[MAXSAV]; vmptr++)
14970 X   {
14971 X     /*
14972 X       fprintf(stderr,"0: %4d-%4d  1: %4d-%4d  dp: %d score: %d\n",
14973 X              f_str->noff+vmptr->start-vmptr->dp,
14974 X              f_str->noff+vmptr->stop-vmptr->dp,
14975 X              vmptr->start,vmptr->stop,
14976 X              vmptr->dp,vmptr->score);
14977 X     */
14978 X      if (vmptr->score > 0) {
14979 X        vmptr->score = spam (aa0, aa1, vmptr, ppst->pam2[ip], f_str);
14980 X        f_str->vptr[nsave++] = vmptr;
14981 X      }
14982 X   }
14983 X
14984 X   if (nsave <= 0) {
14985 X     rst->score[0] = rst->score[1] = rst->score[2] = 0;
14986 X     return;
14987 X   }
14988 X       
14989 #ifndef TFAST
14990 X   /* FASTX code here to modify the start, stop points for 
14991 X      the three phases of the translated protein sequence
14992 X      */
14993 X   /*
14994 X     fprintf(stderr,"n0x: %d; n0x31:%d; n0x32: %d\n",n0,n0x31,n0x32);
14995 X     for (ib=0; ib<nsave; ib++) {
14996 X       fprintf(stderr,"0: %4d-%4d  1: %4d-%4d  dp: %d score: %d\n",
14997 X              f_str->noff+f_str->vptr[ib]->start-f_str->vptr[ib]->dp,
14998 X              f_str->noff+f_str->vptr[ib]->stop-f_str->vptr[ib]->dp,
14999 X              f_str->vptr[ib]->start,f_str->vptr[ib]->stop,
15000 X              f_str->vptr[ib]->dp,f_str->vptr[ib]->score);
15001 X     }
15002 X
15003 X     fprintf(stderr,"---\n");
15004 X   */
15005 X   for (ib=0; ib<nsave; ib++) {
15006 X     if (f_str->noff-f_str->vptr[ib]->dp+f_str->vptr[ib]->start >= n0x32)
15007 X       f_str->vptr[ib]->dp += n0x32;
15008 X     if (f_str->noff-f_str->vptr[ib]->dp +f_str->vptr[ib]->start >= n0x31)
15009 X       f_str->vptr[ib]->dp += n0x31;
15010 X   }
15011 X           
15012 X   /*
15013 X     for (ib=0; ib<nsave; ib++) {
15014 X       fprintf(stderr,"0: %4d-%4d  1: %4d-%4d  dp: %d score: %d\n",
15015 X              f_str->noff+f_str->vptr[ib]->start-f_str->vptr[ib]->dp,
15016 X              f_str->noff+f_str->vptr[ib]->stop-f_str->vptr[ib]->dp,
15017 X              f_str->vptr[ib]->start,f_str->vptr[ib]->stop,
15018 X              f_str->vptr[ib]->dp,f_str->vptr[ib]->score);
15019 X     }
15020 X     */
15021 #else
15022 X
15023 X   /* TFASTX code here to modify the start, stop points for 
15024 X            the three phases of the translated protein sequence
15025 X            TFASTX modifies library start points, rather than 
15026 X            query start points
15027 X            */
15028 X
15029 X     /*
15030 X   fprintf(stderr,"n0: %d; noff: %d; n1: %d; n1x31: %d n1x32 %d\n",n0, f_str->noff,n1,n1x31,n1x32);
15031 X   for (ib=0; ib<nsave; ib++) {
15032 X     fprintf(stderr,"0: %4d-%4d  1: %4d-%4d  dp: %d score: %d\n",
15033 X            f_str->noff+f_str->vptr[ib]->start-f_str->vptr[ib]->dp,
15034 X            f_str->noff+f_str->vptr[ib]->stop-f_str->vptr[ib]->dp,
15035 X            f_str->vptr[ib]->start,f_str->vptr[ib]->stop,
15036 X            f_str->vptr[ib]->dp,f_str->vptr[ib]->score);
15037 X   }
15038 X
15039 X   fprintf(stderr,"---\n");
15040 X   */
15041 X
15042 X   for (ib=0; ib<nsave; ib++) {
15043 X     if (f_str->vptr[ib]->start >= n1x32) {
15044 X       f_str->vptr[ib]->start -= n1x32;
15045 X       f_str->vptr[ib]->stop -= n1x32;
15046 X       f_str->vptr[ib]->dp -= n1x32;
15047 X     }
15048 X     if (f_str->vptr[ib]->start >= n1x31) {
15049 X       f_str->vptr[ib]->start -= n1x31;
15050 X       f_str->vptr[ib]->stop -= n1x31;
15051 X       f_str->vptr[ib]->dp -= n1x31;
15052 X     }
15053 X   }
15054 X           
15055 X   /*
15056 X   for (ib=0; ib<nsave; ib++) {
15057 X     fprintf(stderr,"0: %4d-%4d  1: %4d-%4d  dp: %d score: %d\n",
15058 X            f_str->noff+f_str->vptr[ib]->start-f_str->vptr[ib]->dp,
15059 X            f_str->noff+f_str->vptr[ib]->stop-f_str->vptr[ib]->dp,
15060 X            f_str->vptr[ib]->start,f_str->vptr[ib]->stop,
15061 X            f_str->vptr[ib]->dp,f_str->vptr[ib]->score);
15062 X   }
15063 X   */
15064 X
15065 #endif /* TFASTX */
15066 X
15067 X   scor = sconn (f_str->vptr, nsave, ppst->param_u.fa.cgap, 
15068 X                ppst->param_u.fa.pgap, f_str);
15069 X
15070 X   for (vmptr=f_str->vptr[0],ib=1; ib<nsave; ib++)
15071 X     if (f_str->vptr[ib]->score > vmptr->score) vmptr=f_str->vptr[ib];
15072 X
15073 /*  kssort (f_str->vptr, nsave); */
15074 X
15075 X   rst->score[1] = vmptr->score;       /* best single score - init1*/
15076 X   rst->score[0] = max (scor, vmptr->score);  /* initn */
15077 X   rst->score[2] = rst->score[0];              /* initn */
15078 X
15079 X   my_hoff=f_str->noff - vmptr->dp;
15080 X
15081 X   /*
15082 X   if (n1 > 5000) {
15083 X     fprintf(stderr," Long n1: %d\n",n1);
15084 X   }
15085 X   */
15086 X
15087 X   if (ppst->param_u.fa.optflag) {
15088 X     if (rst->score[0] > ppst->param_u.fa.optcut) {
15089 #ifndef TFAST
15090 X       rst->score[2] = dmatchx(aa0, n0,aa1,n1,my_hoff,
15091 X                            ppst->param_u.fa.optwid, ppst->pam2[ip],
15092 X                            ppst->gdelval,ppst->ggapval,ppst->gshift,f_str);
15093 #else /* TFASTX */
15094 X     /* generate f_str->aa1y */
15095 /*
15096 X     for (i=0; i<n1; i++) {
15097 X       fputc(ppst->sq[aa1[i]],stderr);
15098 X       if (i%60==59) fputc('\n',stderr);
15099 X     }
15100 X     fprintf(stderr,"\n-----\n");
15101 */
15102 X     for (fs=aa1,itemp=0; itemp <3; itemp++,fs++) {
15103 X       for (fd= &f_str->aa1y[itemp]; *fs!=EOSEQ; fd += 3, fs++) *fd = *fs;
15104 X       *fd=EOSEQ;
15105 X     }
15106 X
15107 /*
15108 X     for (i=0; i<n1; i++) {
15109 X       fputc(ppst->sq[f_str->aa1y[i]],stderr);
15110 X       if (i%60==59) fputc('\n',stderr);
15111 X     }
15112 */
15113 X     rst->score[2] = dmatchx(aa0, n0, aa1, n1, my_hoff=vmptr->dp-f_str->noff,
15114 X                            ppst->param_u.fa.optwid, ppst->pam2[ip],
15115 X                            ppst->gdelval,ppst->ggapval,ppst->gshift,f_str);
15116 #endif /* TFASTX */
15117 X     }
15118 X   }
15119 X   *hoff = my_hoff;
15120 }
15121 X
15122 /* returns rst.score[0] - initn
15123 X          rst.score[1] - init1
15124 X          rst.score[2] - opt
15125 */
15126 X
15127 void do_work (const unsigned char *aa0, int n0,
15128 X             const unsigned char *aa1, int n1,
15129 X             int frame,
15130 X             struct pstruct *ppst, struct f_struct *f_str,
15131 X             int qr_flg, struct rstruct *rst)
15132 {
15133 X  int hoff;
15134 X  int last_n1, itx, itt, n10, i;
15135 X
15136 #ifdef TFAST
15137 X  unsigned char *aa1x;
15138 X  /* aa0 has a protein sequence */
15139 X  /* aa1 has a raw DNA sequence */
15140 X
15141 X  itt = frame;
15142 X  last_n1 = 0;
15143 X  aa1x = f_str->aa1x;
15144 X  for (itx= itt*3; itx< itt*3+3; itx++) {
15145 X    n10  = saatran(aa1,&aa1x[last_n1],n1,itx);
15146 X    /*
15147 X    fprintf(stderr," itt %d itx: %d\n",itt,itx);
15148 X    for (i=0; i<n10; i++) {
15149 X      fprintf(stderr,"%c",aa[f_str->aa1x[last_n1+i]]);
15150 X      if ((i%60)==59) fprintf(stderr,"\n");
15151 X    }
15152 X    fprintf(stderr,"\n");
15153 X    */
15154 X    last_n1 += n10+1;
15155 X  }
15156 X  n10 = last_n1-1;
15157 #endif
15158 X
15159 X  rst->score[0] = rst->score[1] = rst->score[2] = 0;
15160 X  rst->escore = 1.0;
15161 X  rst->segnum = rst->seglen = 1;
15162 X
15163 #ifndef TFAST
15164 X  do_fastx (f_str->aa0x, n0, aa1, n1, ppst, f_str, rst, &hoff);
15165 #else /* tfastx */
15166 X  do_fastx (aa0, n0, f_str->aa1x, n10, ppst, f_str, rst, &hoff);
15167 #endif
15168 }
15169 X
15170 void do_opt (const unsigned char *aa0, int n0,
15171 X            const unsigned char *aa1, int n1,
15172 X            int frame,
15173 X            struct pstruct *ppst,
15174 X            struct f_struct *f_str,
15175 X            struct rstruct *rst)
15176 {
15177 X  int optflag, tscore, hoff;
15178 X
15179 X  optflag = ppst->param_u.fa.optflag;
15180 X  ppst->param_u.fa.optflag = 1;
15181 X
15182 #ifndef TFAST
15183 X  do_fastx (f_str->aa0x, n0, aa1, n1, ppst, f_str, rst, &hoff);
15184 #else
15185 X  do_fastx (aa0, n0, aa1, n1, ppst, f_str, rst, &hoff);
15186 #endif
15187 X
15188 X  ppst->param_u.fa.optflag = optflag;
15189 }
15190 X
15191 #ifdef ALLOCN0
15192 void
15193 savemax (dptr, dpos, f_str)
15194 X  register struct dstruct *dptr;
15195 X  int  dpos;
15196 X  struct f_struct *f_str;
15197 {
15198 X   register struct savestr *vmptr;
15199 X   register int i;
15200 X
15201 #else
15202 void
15203 savemax (dptr, f_str)
15204 X  register struct dstruct *dptr;
15205 X  struct f_struct *f_str;
15206 {
15207 X   register int dpos;
15208 X   register struct savestr *vmptr;
15209 X   register int i;
15210 X
15211 X   dpos = (int) (dptr - f_str->diag);
15212 X
15213 #endif
15214 X
15215 /* check to see if this is the continuation of a run that is already saved */
15216 X
15217 X   if ((vmptr = dptr->dmax) != NULL && vmptr->dp == dpos &&
15218 X        vmptr->start == dptr->start)
15219 X   {
15220 X      vmptr->stop = dptr->stop;
15221 X      if ((i = dptr->score) <= vmptr->score)
15222 X        return;
15223 X      vmptr->score = i;
15224 X      if (vmptr != f_str->lowmax)
15225 X        return;
15226 X   }
15227 X   else
15228 X   {
15229 X      i = f_str->lowmax->score = dptr->score;
15230 X      f_str->lowmax->dp = dpos;
15231 X      f_str->lowmax->start = dptr->start;
15232 X      f_str->lowmax->stop = dptr->stop;
15233 X      dptr->dmax = f_str->lowmax;
15234 X   }
15235 X
15236 X   for (vmptr = f_str->vmax; vmptr < &f_str->vmax[MAXSAV]; vmptr++)
15237 X      if (vmptr->score < i)
15238 X      {
15239 X        i = vmptr->score;
15240 X        f_str->lowmax = vmptr;
15241 X      }
15242 X   f_str->lowscor = i;
15243 }
15244 X
15245 int spam (const unsigned char *aa0, const unsigned char *aa1,
15246 X         struct savestr *dmax, int **pam2,
15247 X         struct f_struct *f_str)
15248 {
15249 X   int     lpos;
15250 X   int     tot, mtot;
15251 X   struct {
15252 X     int     start, stop, score;
15253 X   } curv, maxv;
15254 X   const unsigned char *aa0p, *aa1p;
15255 X
15256 X   aa1p = &aa1[lpos = dmax->start];
15257 X   aa0p = &aa0[lpos - dmax->dp + f_str->noff];
15258 X   curv.start = lpos;
15259 X
15260 X   tot = curv.score = maxv.score = 0;
15261 X   for (; lpos <= dmax->stop; lpos++) {
15262 X     tot += pam2[*aa0p++][*aa1p++];
15263 X     if (tot > curv.score) {
15264 X       curv.stop = lpos;
15265 X       curv.score = tot;
15266 X      }
15267 X      else if (tot < 0) {
15268 X       if (curv.score > maxv.score) {
15269 X         maxv.start = curv.start;
15270 X         maxv.stop = curv.stop;
15271 X         maxv.score = curv.score;
15272 X       }
15273 X       tot = curv.score = 0;
15274 X       curv.start = lpos+1;
15275 X      }
15276 X   }
15277 X
15278 X   if (curv.score > maxv.score) {
15279 X     maxv.start = curv.start;
15280 X     maxv.stop = curv.stop;
15281 X     maxv.score = curv.score;
15282 X   }
15283 X
15284 /*      if (maxv.start != dmax->start || maxv.stop != dmax->stop)
15285 X               printf(" new region: %3d %3d %3d %3d\n",maxv.start,
15286 X                       dmax->start,maxv.stop,dmax->stop);
15287 */
15288 X   dmax->start = maxv.start;
15289 X   dmax->stop = maxv.stop;
15290 X
15291 X   return maxv.score;
15292 }
15293 X
15294 #define XFACT 10
15295 X
15296 int sconn (struct savestr **v, int n, 
15297 X       int cgap, int pgap, struct f_struct *f_str)
15298 {
15299 X  int     i, si;
15300 X  struct slink {
15301 X    int     score;
15302 X    struct savestr *vp;
15303 X    struct slink *next;
15304 X  }      *start, *sl, *sj, *so, sarr[MAXSAV];
15305 X  int     lstart, tstart, plstop, ptstop;
15306 X
15307 /*      sort the score left to right in lib pos */
15308 X
15309 X  kpsort (v, n);
15310 X
15311 X  start = NULL;
15312 X
15313 /*      for the remaining runs, see if they fit */
15314 X
15315 X   for (i = 0, si = 0; i < n; i++)
15316 X   {
15317 X
15318 /*      if the score is less than the gap penalty, it never helps */
15319 X      if (v[i]->score < cgap)
15320 X        continue;
15321 X      lstart = v[i]->start;
15322 X      tstart = lstart - v[i]->dp + f_str->noff;
15323 X
15324 /*      put the run in the group */
15325 X      sarr[si].vp = v[i];
15326 X      sarr[si].score = v[i]->score;
15327 X      sarr[si].next = NULL;
15328 X
15329 /*      if it fits, then increase the score */
15330 X      for (sl = start; sl != NULL; sl = sl->next)
15331 X      {
15332 X        plstop = sl->vp->stop;
15333 X        ptstop = plstop - sl->vp->dp + f_str->noff;
15334 X        if (plstop < lstart+XFACT && ptstop < tstart+XFACT) {
15335 X          sarr[si].score = sl->score + v[i]->score + pgap;
15336 X          break;
15337 X        }
15338 X      }
15339 X
15340 /*      now recalculate where the score fits */
15341 X      if (start == NULL)
15342 X        start = &sarr[si];
15343 X      else
15344 X        for (sj = start, so = NULL; sj != NULL; sj = sj->next)
15345 X        {
15346 X           if (sarr[si].score > sj->score)
15347 X           {
15348 X              sarr[si].next = sj;
15349 X              if (so != NULL)
15350 X                 so->next = &sarr[si];
15351 X              else
15352 X                 start = &sarr[si];
15353 X              break;
15354 X           }
15355 X           so = sj;
15356 X        }
15357 X      si++;
15358 X   }
15359 X
15360 X   if (start != NULL)
15361 X      return (start->score);
15362 X   else
15363 X      return (0);
15364 }
15365 X
15366 void
15367 kssort (v, n)
15368 struct savestr *v[];
15369 int     n;
15370 {
15371 X   int     gap, i, j;
15372 X   struct savestr *tmp;
15373 X
15374 X   for (gap = n / 2; gap > 0; gap /= 2)
15375 X      for (i = gap; i < n; i++)
15376 X        for (j = i - gap; j >= 0; j -= gap)
15377 X        {
15378 X           if (v[j]->score >= v[j + gap]->score)
15379 X              break;
15380 X           tmp = v[j];
15381 X           v[j] = v[j + gap];
15382 X           v[j + gap] = tmp;
15383 X        }
15384 }
15385 X
15386 void
15387 kpsort (v, n)
15388 struct savestr *v[];
15389 int     n;
15390 {
15391 X   int     gap, i, j;
15392 X   struct savestr *tmp;
15393 X
15394 X   for (gap = n / 2; gap > 0; gap /= 2)
15395 X      for (i = gap; i < n; i++)
15396 X        for (j = i - gap; j >= 0; j -= gap)
15397 X        {
15398 X           if (v[j]->start <= v[j + gap]->start)
15399 X              break;
15400 X           tmp = v[j];
15401 X           v[j] = v[j + gap];
15402 X           v[j + gap] = tmp;
15403 X        }
15404 }
15405 X
15406 static int
15407 dmatchx(const unsigned char *aa0, int n0,
15408 X       const unsigned char *aa1, int n1,
15409 X       int hoff, int window, 
15410 X       int **pam2, int gdelval, int ggapval, int gshift,
15411 X       struct f_struct *f_str)
15412 {
15413 X
15414 X   hoff -= window/2;
15415 X
15416 #ifndef TFAST
15417 X   return lx_band(aa1,n1,f_str->aa0y,n0, 
15418 X                 pam2,
15419 #ifdef OLD_FASTA_GAP
15420 X                 -(gdelval-ggapval),
15421 #else
15422 X                 -gdelval,
15423 #endif
15424 X                 -ggapval,-gshift,
15425 X                 hoff,window,f_str);
15426 #else
15427 X   return lx_band(aa0,n0,f_str->aa1y,n1, 
15428 X                 pam2,
15429 #ifdef OLD_FASTA_GAP
15430 X                 -(gdelval-ggapval),
15431 #else
15432 X                 -gdelval,
15433 #endif
15434 X                 -ggapval,-gshift,
15435 X                 hoff,window,f_str);
15436 #endif
15437 }
15438 X
15439 static void
15440 init_row(struct sx_s *row, int sp) {
15441 X  int i;
15442 X  for (i = 0; i < sp; i++) {
15443 X      row[i].C1 = row[i].I1 = 0;
15444 X      row[i].C2 = row[i].I2 = 0;
15445 X      row[i].C3 = row[i].I3 = 0;
15446 X      row[i].flag = 0;
15447 X  }
15448 }
15449 X
15450 int
15451 lx_band(const unsigned char *prot_seq,  /* array with protein sequence numbers*/
15452 X       int len_prot,    /* length of prot. seq */
15453 X       const unsigned char *dna_prot_seq, /* translated DNA sequence numbers*/
15454 X       int len_dna_prot,   /* length trans. seq. */
15455 X       int **pam_matrix,   /* scoring matrix */
15456 X       int gopen, int gext, /* gap open, gap extend penalties */
15457 X       int gshift,         /* frame-shift penalty */
15458 X       int start_diag,     /* start diagonal of band */
15459 X       int width,         /* width for band alignment */
15460 X       struct f_struct *f_str)
15461 {
15462 X  void *ckalloc();
15463 X  int i, j, bd, bd1, x1, sp, p1=0, p2=0, end_prot;
15464 X  int sc, del, best = 0, cd,ci, e1, e2, e3, cd1, cd2, cd3, f, gg;
15465 X  register int *wt;
15466 X  const unsigned char *dp;
15467 X  register struct sx_s *ap, *aq;
15468 X
15469 X  sp = width+7;        
15470 X  gg = gopen+gext;
15471 X  /*  sp = sp/3; */
15472 X  if (f_str->cur == NULL) 
15473 X    f_str->cur = (struct sx_s *) ckalloc(sizeof(struct sx_s)*sp);
15474 X
15475 X  init_row(f_str->cur, sp);
15476 X
15477 X  /*
15478 X  if (start_diag %3 !=0) start_diag = start_diag/3-1;
15479 X  else start_diag = start_diag/3;
15480 X  */
15481 X
15482 X  /*
15483 X  if (width % 3 != 0) width = width/3+1;
15484 X  else width = width /3;
15485 X  */
15486 X
15487 X  /* currently, this code assumes that the DNA sequence is longer than the
15488 X     protein sequence. This is not always true.  len_prot in the loop below
15489 X     should be decreased to the projection of the DNA on the protein */
15490 X
15491 X  x1 = start_diag;             /* x1 = lower bound of DNA */
15492 X
15493 X  
15494 X  end_prot = max(0,-width-start_diag) + (len_dna_prot+5)/3 + width;
15495 X  end_prot = min(end_prot,len_prot);
15496 X
15497 X  /* i counts through protein sequence, x1 through DNAp */
15498 X
15499 X  for (i = max(0, -width-start_diag), x1+=i; i < end_prot; i++, x1++) {
15500 X      bd = min(x1+width, len_dna_prot/3);      /* upper bound of band */
15501 X      bd1 = max(0,x1);                 /* lower bound of band */
15502 X      wt = pam_matrix[prot_seq[i]];
15503 X      del = 1-x1;   /*adjustment*/
15504 X      bd += del; 
15505 X      bd1 +=del;
15506 X
15507 X      ap = &f_str->cur[bd1];
15508 X      aq = ap+1;
15509 X      e1 = f_str->cur[bd1-1].C3;
15510 X      e2 = ap->C1;
15511 X      cd1 = cd2= cd3= 0;
15512 X
15513 X      for (dp = &dna_prot_seq[(bd1-del)*3]; ap < &f_str->cur[bd]; ap++) {
15514 X         sc = max(max(e1, (e3=ap->C2))-gshift, e2)+wt[*dp++];
15515 X         if (cd1 > sc) sc = cd1;
15516 X         cd1 -= gext;
15517 X         if ((ci = aq->I1) > 0) {
15518 X             if (sc < ci) { ap->C1 = ci; ap->I1 = ci-gext;}
15519 X             else {
15520 X                 ap->C1 = sc;
15521 X                 sc -= gg;
15522 X                 if (sc > 0) {
15523 X                     if (sc > best) best =sc;
15524 X                     if (cd1 < sc) cd1 = sc;
15525 X                     ap->I1 = max(ci-gext, sc);
15526 X                 } else ap->I1 = ci-gext;
15527 X             }
15528 X         } else {
15529 X             if (sc <= 0) {
15530 X                 ap->I1 = ap->C1 = 0;
15531 X             } else {
15532 X                 ap->C1 = sc; sc-=gg;
15533 X                 if (sc >0) {
15534 X                     if (sc > best) best =sc;
15535 X                     if (cd1 < sc) cd1 = sc;
15536 X                     ap->I1 = sc;
15537 X                 } else ap->I1 = 0;
15538 X             }
15539 X         }
15540 X         sc = max(max(e2, (e1=ap->C3))-gshift, e3)+wt[*dp++];
15541 X         if (cd2 > sc) sc = cd2;
15542 X         cd2 -= gext;
15543 X         if ((ci = aq->I2) > 0) {
15544 X             if (sc < ci) { ap->C2 = ci; ap->I2 = ci-gext;}
15545 X             else {
15546 X                 ap->C2 = sc;
15547 X                 sc -= gg;
15548 X                 if (sc > 0) {
15549 X                     if (sc > best) best =sc;
15550 X                     if (cd2 < sc) cd2 = sc;
15551 X                     ap->I2 = max(ci-gext, sc);
15552 X                 }
15553 X             }
15554 X         } else {
15555 X             if (sc <= 0) {
15556 X                 ap->I2 = ap->C2 = 0;
15557 X             } else {
15558 X                 ap->C2 = sc; sc-=gg;
15559 X                 if (sc >0) {
15560 X                     if (sc > best) best =sc;
15561 X                     if (cd2 < sc) cd2 = sc;
15562 X                     ap->I2 = sc;
15563 X                 } else ap->I2 = 0;
15564 X             }
15565 X         }
15566 X         sc = max(max(e3, (e2=aq->C1))-gshift, e1)+wt[*dp++];
15567 X         if (cd3 > sc) sc = cd3;
15568 X         cd3 -= gext;
15569 X         if ((ci = aq++->I3) > 0) {
15570 X             if (sc < ci) { ap->C3 = ci; ap->I3 = ci-gext;}
15571 X             else {
15572 X                 ap->C3 = sc;
15573 X                 sc -= gg;
15574 X                 if (sc > 0) {
15575 X                     if (sc > best) best =sc;
15576 X                     if (cd3 < sc) cd3 = sc;
15577 X                     ap->I3 = max(ci-gext, sc);
15578 X                 }
15579 X             }
15580 X         } else {
15581 X             if (sc <= 0) {
15582 X                 ap->I3 = ap->C3 = 0;
15583 X             } else {
15584 X                 ap->C3 = sc; sc-=gg;
15585 X                 if (sc >0) {
15586 X                     if (sc > best) best =sc;
15587 X                     if (cd3 < sc) cd3 = sc;
15588 X                     ap->I3 = sc;
15589 X                 } else ap->I3 = 0;
15590 X             }
15591 X         }
15592 X      }
15593 X  }
15594 X  /*  printf("The best score is %d\n", best); */
15595 X  return best+gopen+gext;
15596 }
15597 X
15598 /* ckalloc - allocate space; check for success */
15599 void *ckalloc(size_t amount)
15600 {
15601 X  void *p;
15602 X
15603 X  if ((p = (void *)malloc( (size_t)amount)) == NULL)
15604 X    w_abort("Ran out of memory.","");
15605 X  return(p);
15606 }
15607 X
15608 /* calculate the 100% identical score */
15609 int
15610 shscore(unsigned char *aa0, int n0, int **pam2)
15611 {
15612 X  int i, sum;
15613 X  for (i=0,sum=0; i<n0; i++)
15614 X    sum += pam2[aa0[i]][aa0[i]];
15615 X  return sum;
15616 }
15617 X
15618 #define SGW1 100
15619 #define SGW2 300
15620 #define WIDTH 60
15621 X
15622 /* code above is to convert sequence into numbers */
15623 X
15624 typedef struct mat *match_ptr;
15625 X
15626 typedef struct mat {
15627 X       int i, j, l;
15628 X       match_ptr next;
15629 } match_node;
15630 X
15631 typedef struct {
15632 X       int i,j;
15633 } state;
15634 X
15635 typedef state *state_ptr;
15636 X
15637 typedef struct st_s { int C, I, D;} *st_ptr;
15638 X
15639 /* static st_ptr up=NULL, down, tp; */
15640 /* static int *st_up; */
15641 /* static int gop, gext, shift; */
15642 X
15643 void *ckalloc(size_t);
15644 static match_ptr small_global(), global();
15645 static int local_align(), find_best();
15646 static void init_row2(),  init_ROW();
15647 X
15648 int
15649 pro_dna(const unsigned char *prot_seq,  /* array with prot. seq. numbers*/
15650 X       int len_prot,                   /* length of prot. seq */
15651 X       const unsigned char *dna_prot_seq, /* trans. DNA seq. numbers*/
15652 X       int len_dna_prot,               /* length trans. seq. */
15653 X       int **pam_matrix,               /* scoring matrix */
15654 X       int gopen, int gex,             /* gap open, gap extend penalties */
15655 X       int gshift,                     /* frame-shift penalty */
15656 X       int max_res,
15657 X       struct a_res_str *a_res)        /* alignment info */
15658 {
15659 X  match_ptr align, ap, aq;
15660 X  int x, y, ex, ey, i, score;
15661 X  int *alignment;
15662 X  st_ptr up, down, tp;
15663 X
15664 X  /* these globals removed */
15665 X  /*   gext = gex; gop = gopen; shift = gshift; */
15666 X
15667 X  /* for fastx (but not tfastx), these could be moved into init_work(),
15668 X     and done only once */
15669 X
15670 X  up = (st_ptr) ckalloc(sizeof(struct st_s)*(len_dna_prot+10));
15671 X  down = (st_ptr) ckalloc(sizeof(struct st_s)*(len_dna_prot+10));
15672 X  tp = (st_ptr) ckalloc(sizeof(struct st_s)*(len_dna_prot+10));
15673 X
15674 X  /*local alignment find the best local alignment x (prot) and y (DNA)
15675 X    is the starting position of the best local alignment
15676 X    and ex (prot) ey (DNA) is the ending position */
15677 X  score= local_align(&x, &y, &ex, &ey, pam_matrix,
15678 X                    gopen, gex, gshift,
15679 X                    dna_prot_seq, len_dna_prot,
15680 X                    prot_seq, len_prot, up, down);
15681 X
15682 X  /* this is very strange, since local_align initialized up, down */
15683 X  up += 3; down += 3; tp += 3;
15684 X
15685 X  /* x, y - start in prot, dna_prot */
15686 X  a_res->min0 = x;     /* prot */
15687 X  a_res->max0 = ex;    /* prot */
15688 X
15689 X  a_res->min1 = y;     /* DNA-prot */
15690 X  a_res->max1 = ey;    /* DNA-prot */
15691 X
15692 X  align = global(x, y, ex, ey, pam_matrix, gopen, gex, gshift, 
15693 X                dna_prot_seq, prot_seq, 0, 0, &up, &down, &tp);
15694 X
15695 X  alignment = a_res->res;
15696 X
15697 X  /* from earlier version */
15698 X  /* alignment[0] = x; */ /* start of alignment in prot */
15699 X  /* alignment[1] = y; */ /* start of alignment in DNA */
15700 X
15701 X  for (ap = align, i= 0; ap; i++) {
15702 X    if (i < max_res) {alignment[i] = ap->l;}
15703 X    aq = ap->next; free(ap); ap = aq;
15704 X  }
15705 X
15706 X  if (i >= max_res) {
15707 X    fprintf(stderr," alignment truncated: %d/%d\n", max_res,i);
15708 X  }
15709 X
15710 X  up = &up[-3]; down = &down[-3]; tp = &tp[-3];
15711 X  free(up); free(tp); free(down);
15712 X  /* free(st_up); */ /*  moved into local align */
15713 X
15714 X  a_res->nres = i;     /* i has the length of the alignment */
15715 X  return score;
15716 }
15717 X
15718 static void
15719 swap(void **a, void **b) {
15720 X  void *t;
15721 X
15722 X  t = *a;
15723 X  *a = *b;
15724 X  *b = t;
15725 }
15726 X
15727 /*
15728 X   local alignment find the best local alignment x and y
15729 X   is the starting position of the best local alignment
15730 X   and ex ey is the ending position 
15731 */
15732 static int
15733 local_align(int *x, int *y, int *ex, int *ey,
15734 X           int **wgts, int gop, int gext, int shift,
15735 X           unsigned char *dnap, int ld,
15736 X           unsigned char *pro,  int lp,
15737 X           st_ptr up, st_ptr down) {
15738 X
15739 X  int i, j,  score, x1,x2,x3,x4, e1, e2 = 0, e3,
15740 X    sc, del,  e, best = 0, *wt, cd, ci;
15741 X  state_ptr cur_st, last_st, cur_i_st;
15742 X  st_ptr cur, last;
15743 X  unsigned char *dp;
15744 X  int *st_up, *cur_d_st;
15745 X
15746 /*      
15747 X   Array rowiC store the best scores of alignment ending at a position
15748 X   Arrays rowiD, and rowiI store the best scores of alignment ending
15749 X                 at a position with a deletion or insrtion
15750 X   Arrays sti stores the starting position of the best alignment whose
15751 X              score stored in the corresponding row array.
15752 X   The program stores two rows to complete the computation, same is
15753 X        for the global alignment routine.
15754 */
15755 X
15756 X  /* for fastx (but not tfastx), this could be moved into init_work(),
15757 X     and done only once */
15758 X  st_up = (int *) ckalloc(sizeof(int)*(ld+10));
15759 X  init_row2(st_up, ld+5);
15760 X
15761 X  ld += 2;
15762 X  init_ROW(up, ld+1);  /* set to zero */
15763 X  init_ROW(down, ld+1);        /* set to zero */
15764 X
15765 X
15766 X  cur = up+1;
15767 X  last = down+1; 
15768 X
15769 X  /* for fastx (but not tfastx), these could be moved into init_work(),
15770 X     and done only once */
15771 X  cur_st = (state_ptr) ckalloc(sizeof(state)*(ld+1));
15772 X  last_st = (state_ptr) ckalloc(sizeof(state)*(ld+1));
15773 X  cur_i_st = (state_ptr) ckalloc(sizeof(state)*(ld+1));
15774 X
15775 X  cur_d_st = st_up; 
15776 X
15777 X  dp = dnap-2;
15778 X  for (i = 0; i < lp; i++) {
15779 X    wt = &wgts[pro[i]][0];
15780 X    for (j = 0; j < 2; j++) {
15781 X      cur_st[j].i = i+1;
15782 X      cur_st[j].j = j+1;
15783 X    }
15784 X    for (j = 2; j < ld; j++) {
15785 X      score = wt[dp[j]];
15786 X      del = -1;
15787 X      if (j >= 3) {
15788 X       sc = -score;
15789 X       e3 = e2-shift; e2 = last[j-3].C;
15790 X       e1 = last[j-2].C-shift; 
15791 X       if (e1 > sc) {sc = e1; del = 2;}
15792 X       if (e2 > sc) {sc = e2; del = 3;}
15793 X       if (e3 > sc) {sc = e3; del = 4;} 
15794 X      } else {
15795 X       sc = e2  = 0;
15796 X       if (sc < -score) sc=-score;
15797 X       else del = 3;
15798 X      }
15799 X      sc += score;
15800 X      if (sc < (ci=last[j].I)) {
15801 X       sc = ci; del = 0;
15802 X      }
15803 X      if (sc < (cd=cur[j].D)) {
15804 X       sc = cd; del = 5;
15805 X      }
15806 X      cur[j].C = sc;
15807 X      e = sc  - gop;
15808 X      if (e > cd) {
15809 X       cur[j+3].D = e-gext;
15810 X       cur_d_st[j+3] = 3;
15811 X      } else {
15812 X       cur[j+3].D = cd-gext;
15813 X       cur_d_st[j+3] = cur_d_st[j]+3;
15814 X      }
15815 X      switch(del) {
15816 X      case 5:
15817 X       e1 = cur_d_st[j];
15818 X       cur_st[j].i = cur_st[j-e1].i;
15819 X       cur_st[j].j = cur_st[j-e1].j;
15820 X       break;
15821 X      case 0:
15822 X       cur_st[j].i = cur_i_st[j].i;
15823 X       cur_st[j].j = cur_i_st[j].j;
15824 X       break;
15825 X      case 2:
15826 X      case 3:
15827 X      case 4:
15828 X       if (i) {
15829 X         if (j-del >= 0) {
15830 X           cur_st[j].i = last_st[j-del].i;
15831 X           cur_st[j].j = last_st[j-del].j;
15832 X         } else {
15833 X           cur_st[j].i = i;
15834 X           cur_st[j].j = 0;
15835 X         }
15836 X       } else {
15837 X         cur_st[j].i = 0;
15838 X         cur_st[j].j = max(0, j-del+1);
15839 X       }
15840 X       break;
15841 X      case -1:
15842 X       cur_st[j].i = i+1;
15843 X       cur_st[j].j = j+1;
15844 X       break;
15845 X      }
15846 X      if (e > ci) {
15847 X       cur[j].I  = e -gext;
15848 X       cur_i_st[j].i = cur_st[j].i;
15849 X       cur_i_st[j].j = cur_st[j].j;
15850 X      } else {
15851 X       cur[j].I  = ci- gext;
15852 X      }
15853 X      if (sc > best) {
15854 X       x1 = cur_st[j].i;
15855 X       x2 = cur_st[j].j;
15856 X       best =sc;
15857 X       x3 = i;
15858 X       x4 = j;
15859 X      }
15860 X    }
15861 X    swap((void **)&last, (void **)&cur);
15862 X    swap((void **)&cur_st, (void **)&last_st);
15863 X  }
15864 X  /*   printf("The best score is %d\n", best); */
15865 X  *x = x1; *y = x2; *ex = x3; *ey = x4;
15866 X  free(cur_st); free(last_st); free(cur_i_st); 
15867 X  free(st_up);
15868 X  return best;
15869 }
15870 X
15871 /* 
15872 X   Both global_up and global_down do linear space score only global 
15873 X   alignments on subsequence pro[x]...pro[ex], and dna[y]...dna[ey].
15874 X   global_up do the algorithm upwards, from row x towards row y.
15875 X   global_down do the algorithm downwards, from row y towards x.
15876 */
15877 X
15878 static void
15879 global_up(st_ptr *row1, st_ptr *row2,
15880 X         int x, int y, int ex, int ey, 
15881 X         int **wgts, int gop, int gext, int shift,
15882 X         unsigned char *dnap,
15883 X         unsigned char *pro,
15884 X         int N) {
15885 X  int i, j, k, sc, e, e1, e2, e3, t, ci, cd, score, *wt;
15886 X  st_ptr cur, last;
15887 X
15888 X  cur = *row1; last = *row2;
15889 X  sc = -gop-gext;
15890 X  for (j = 1; j <= ey-y+1; j++) {
15891 X    if (j % 3 == 0) {last[j].C = sc; sc -= gext; last[j].I = sc-gop;}
15892 X    else { last[j].I = last[j].C = -10000;}
15893 X    cur[j].I = -10000;
15894 X  }  
15895 X  last[0].C = 0; cur[0].D = cur[1].D = cur[2].D = -10000;
15896 X  last[0].D = last[1].D = last[2].D = -10000;
15897 X  if (N) last[0].I = -gext; else last[0].I = -gop-gext;
15898 X  for (i = 1; i <= ex-x+1; i++) {
15899 X    wt = &wgts[pro[i+x-1]][0]; e2 = last[0].C; e1 = -10000;
15900 X    for (j = 0; j <= ey-y+1; j++) {
15901 X      t = j+y;
15902 X      sc = -10000; 
15903 X      if (t < 3) score = -10000;
15904 X      else score = wt[dnap[t-3]]; 
15905 X      if (j < 4) {
15906 X       if (j == 3) sc = e2;
15907 X       else if (j == 2) sc = e2-shift;
15908 X      } else {
15909 X       e3 = e2; e2 = e1;
15910 X       e1 = last[j-2].C;
15911 X       sc = max(max(e1, e3)-shift, e2);
15912 X      }
15913 X      sc += score;
15914 X      sc = max(sc, max(ci=last[j].I, cd = cur[j].D));
15915 X      cur[j].C = sc;
15916 X      cur[j+3].D = max(cd, sc-gop)-gext;
15917 X      cur[j].I = max(ci, sc-gop)-gext;
15918 X    }
15919 X    swap((void **)&last, (void **)&cur);
15920 X  }
15921 X  for (i = 0; i <= ey-y+1; i++) last[i].I = cur[i].I;
15922 X  if (*row1 != last) swap((void **)row1, (void **)row2);
15923 }
15924 X
15925 static void
15926 global_down(st_ptr *row1, st_ptr *row2,
15927 X           int x, int y, int ex, int ey,
15928 X           int **wgts, int gop, int gext, int shift,
15929 X           unsigned char *dnap, unsigned char *pro,
15930 X           int N) {
15931 X  int i, j, k, sc, del, *tmp, e,  t, e1,e2,e3, ci,cd, s1, s2, s3, *wt;
15932 X  st_ptr cur, last;
15933 X
15934 X  cur = (*row1); last = *row2;
15935 X  sc = -gop-gext;
15936 X  for (j = ey-y; j >= 0; j--) {
15937 X    if ((ey-y+1-j) % 3) {last[j].C = sc; sc-=gext; last[j].I = sc-gop;}
15938 X    else  last[j].I =  last[j].C = -10000;
15939 X  } 
15940 X  last[ey-y+1].C = 0;
15941 X  cur[ey-y+1].D = cur[ey-y].D = cur[ey-y-1].D = -10000;
15942 X  last[ey-y+1].D = last[ey-y].D = last[ey-y-1].D = -10000;
15943 X  if (N) last[ey-y+1].I = -gext; else last[ey-y+1].I = -gop-gext;
15944 X  for (i = ex-x; i >= 0; i--) {
15945 X    wt = &wgts[pro[i+x]][0]; e2 = last[ey-y+1].C; 
15946 X    e1 = s2 = s3 = -10000; 
15947 X    for (j = ey-y+1; j >= 0; j--) {
15948 X      t = j+y;
15949 X      s1 = wt[dnap[t-1]];
15950 X      sc = -10000;
15951 X      if (t+3 > ey) {
15952 X       if (t+2==ey) sc = e2+s2;
15953 X       else if (t+1==ey) sc = e2-shift+s1;
15954 X      } else {
15955 X       e3 = e2; e2 = e1;
15956 X       e1 = last[j+2].C;
15957 X       sc = max(max(e1+s1, e3+s3)-shift, e2+s2);
15958 X      }
15959 X      if (sc < (cd= cur[j].D)) {
15960 X       sc = cd; 
15961 X       cur[j-3].D = cd-gext;
15962 X      } else cur[j-3].D =max(cd, sc-gop)-gext;
15963 X      if (sc < (ci= last[j].I)) {
15964 X       sc = ci; del = 0;
15965 X       cur[j].I = ci - gext;
15966 X      } else cur[j].I = max(sc-gop,ci)-gext;
15967 X      cur[j].C = sc;
15968 X      s3 = s2; s2 = s1;
15969 X    }
15970 X    swap((void **)&last, (void **)&cur);
15971 X  }
15972 X  for (i = 0; i <= ey-y+1; i++) last[i].I = cur[i].I;
15973 X  if (*row1 != last) swap((void **)row1, (void **)row2);
15974 }
15975 X
15976 static void
15977 init_row2(int *row, int ld) {
15978 X  int i;
15979 X  for (i = 0; i < ld; i++) row[i] = 0;
15980 }
15981 X
15982 static void
15983 init_ROW(st_ptr row, int ld) {
15984 X  int i;
15985 X  for (i = 0; i < ld; i++) row[i].I = row[i].D = row[i].C = 0;
15986 }
15987 X
15988 static match_ptr
15989 combine(match_ptr x1, match_ptr x2, int st) {
15990 X  match_ptr x;
15991 X
15992 X  if (x1 == NULL) return x2;
15993 X  for (x = x1; x->next; x = x->next);
15994 X  x->next = x2;
15995 X  if (st) {
15996 X    for (x = x2; x; x = x->next) {
15997 X      x->j++;
15998 X      if (x->l == 3 || x->l == 4) break;
15999 X    }
16000 X    x->l--;
16001 X  }
16002 X  return x1;
16003 }
16004 X
16005 /*
16006 X   global use the two upwards and downwards score only linear
16007 X   space global alignment subroutine to recursively build the
16008 X   alignment.
16009 */
16010 X
16011 match_ptr
16012 global(int x, int y, int ex, int ey, 
16013 X       int **wgts, int gop, int gext, int shift,
16014 X       unsigned char *dnap, 
16015 X       unsigned char *pro,
16016 X       int N1, int N2,
16017 X       st_ptr *up_stp, st_ptr *dn_stp, st_ptr *tp_stp
16018 X       )
16019 {
16020 X  int m;
16021 X  int m1, m2;
16022 X  match_ptr x1, x2, mm1, mm2;
16023 X  /*printf("%d %d %d %d\n", x,y, ex, ey);*/
16024 X  /*
16025 X    if the space required is limited, we can do a quadratic space
16026 X    algorithm to find the alignment.
16027 X  */
16028 X  if (ex <= x) {
16029 X    mm1  = NULL; mm2= NULL;
16030 X    for (m = y+3; m <= ey; m+=3) {
16031 X      x1 = (match_ptr) ckalloc(sizeof(match_node));
16032 X      x1->l = 5; x1->next = mm1; 
16033 X      if (mm1== NULL) mm2 = x1;
16034 X      mm1 = x1;
16035 X    }
16036 X    if (ex == x) {
16037 X      if ((ey-y) % 3 != 0) {
16038 X       x1 = (match_ptr) ckalloc(sizeof(match_node));
16039 X       x1->l = ((ey-y) % 3) +1; x1->next = NULL;
16040 X       if (mm2) mm2->next = x1;
16041 X       else mm1 = x1;
16042 X      } else {
16043 X       if (mm2) mm2->l = 4;
16044 X      }
16045 X    }
16046 X    return mm1;
16047 X  }
16048 X  if (ey <= y) {
16049 X    mm1  = NULL;
16050 X    for (m = x; m <= ex; m++) {
16051 X      x1 = (match_ptr) ckalloc(sizeof(match_node));
16052 X      x1->l = 0; x1->next = mm1; mm1 = x1;
16053 X    }
16054 X    return mm1;
16055 X  }
16056 X  if (ex -x < SGW1-1 && ey-y < SGW2-1) 
16057 X    return small_global(x,y,ex,ey,
16058 X                       wgts, gop, gext, shift,
16059 X                       dnap, pro, N1, N2);
16060 X  m = (x+ex)/2;
16061 X  /*     
16062 X        Do the score only global alignment from row x to row m, m is
16063 X        the middle row of x and ex. Store the information of row m in
16064 X        upC, upD, and upI.
16065 X  */
16066 X  global_up(up_stp, tp_stp, x, y, m, ey, 
16067 X           wgts, gop, gext, shift,
16068 X           dnap, pro, N1);
16069 X
16070 X  /* 
16071 X     Do the score only global alignment downwards from row ex
16072 X     to row m+1, store information of row m+1 in downC downI and downD
16073 X  */
16074 X  global_down(dn_stp, tp_stp,  m+1, y, ex, ey, 
16075 X             wgts, gop, gext, shift,
16076 X             dnap, pro, N2);
16077 X
16078 X  /*
16079 X    Use these information of row m and m+1, to find the crossing
16080 X    point of the best alignment with the middle row. The crossing
16081 X    point is given by m1 and m2. Then we recursively call global
16082 X    itself to compute alignments in two smaller regions found by
16083 X    the crossing point and combine the two alignments to form a
16084 X    whole alignment. Return that alignment.
16085 X  */
16086 X  if (find_best(*up_stp, *dn_stp, &m1, &m2, ey-y+1, y, gop)) {
16087 X    x1 = global(x, y, m, m1, wgts, gop, gext, shift, dnap, pro, N1, 0,
16088 X               up_stp, dn_stp, tp_stp);
16089 X    x2 = global(m+1, m2, ex, ey, wgts, gop, gext, shift, dnap, pro, 0, N2,
16090 X               up_stp, dn_stp, tp_stp);
16091 X    if (m1 == m2) x1 = combine(x1,x2,1);
16092 X    else x1 = combine(x1, x2,0);
16093 X  } else {
16094 X    x1 = global(x, y, m-1, m1, wgts, gop, gext, shift,  dnap, pro, N1, 1,
16095 X               up_stp, dn_stp, tp_stp);
16096 X    x2 = global(m+2, m2, ex, ey, wgts, gop, gext, shift, dnap, pro, 1, N2,
16097 X               up_stp, dn_stp, tp_stp);
16098 X    mm1 = (match_ptr) ckalloc(sizeof(match_node));
16099 X    mm1->i = m; mm1->l = 0; mm1->j = m1;
16100 X    mm2 = (match_ptr) ckalloc(sizeof(match_node));
16101 X    mm2->i = m+1; mm2->l = 0; mm2->j = m1;
16102 X    mm1->next = mm2; mm2->next = x2;
16103 X    x1 = combine(x1, mm1, 0);
16104 X  }
16105 X  return x1;
16106 }
16107 X
16108 static int
16109 find_best(st_ptr up, st_ptr down,
16110 X         int *m1, int *m2,
16111 X         int ld, int y, int gop) {
16112 X  int i, best = -100000, j = 0, s1, s2, s3, s4, st;
16113 X  up++;
16114 X  for (i = 1; i < ld; i++) {
16115 X    s2 = up[i-1].C + down[i].C;
16116 X    s4 = up[i-1].I + down[i].I + gop;
16117 X    if (best < s2) {
16118 X      best = s2; j = i; st = 1;
16119 X    }
16120 X    if (best < s4) {
16121 X      best = s4; j = i; st = 0;
16122 X    }
16123 X  }
16124 X  *m1 = j-1+y;
16125 X  *m2 = j+y;
16126 X  /*printf("find best score =%d\n", best);*/
16127 X  return st;
16128
16129 X
16130 /*
16131 X   An alignment is represented as a linked list whose element
16132 X   is of type match_node. Each element represent an edge in the
16133 X   path of the alignment graph. The fields of match_node are
16134 X   l ---  gives the type of the edge.
16135 X   i, j --- give the end position.
16136 */
16137 X
16138 static match_ptr
16139 small_global(int x, int y, int ex, int ey,
16140 X            int **wgts, int gop, int gext, int shift,
16141 X            unsigned char *dnap, unsigned char *pro,
16142 X            int N1, int N2) {
16143 X  static int C[SGW1+1][SGW2+1], st[SGW1+1][SGW2+1], D[SGW2+7], I[SGW2+1];
16144 X  int i, j, e, sc, score, del, k, t, *wt, ci, cd;
16145 X  int *cI, *cD, *cC, *lC, *cst, e2, e3, e4;
16146 X  match_ptr mp, first;
16147 X
16148 X  /*printf("small_global %d %d %d %d\n", x, y, ex, ey);*/
16149 X  sc = -gop-gext; C[0][0] = 0;
16150 X  if (N1) I[0] = -gext; else I[0] = sc;
16151 X  for (j = 1; j <= ey-y+1; j++) {
16152 X    if (j % 3== 0) {
16153 X      C[0][j] = sc; sc -= gext; I[j] = sc-gop;
16154 X    } else I[j] = C[0][j] = -10000;
16155 X    st[0][j] = 5;
16156 X  }
16157 X  lC = &C[0][0]; cD = D; D[0] = D[1] = D[2] = -10000;
16158 X  cI = I;
16159 X  for (i = 1; i <= ex-x+1; i++) {
16160 X    cC = &C[i][0];     
16161 X    wt = &wgts[pro[i+x-1]][0]; cst = &st[i][0];
16162 X    for (j = 0; j <=ey-y+1; j++) {
16163 X      sc = -10000; del = 0;
16164 X      ci = cI[j];
16165 X      cd= cD[j];
16166 X      t = j+y;
16167 X      if (t < 3) score = -10000;
16168 X      else score = wt[dnap[t-3]];
16169 X      if (j >= 4) {
16170 X       e2 = lC[j-2]-shift; sc = lC[j-3]; e4 = lC[j-4]-shift;
16171 X       del = 3;
16172 X       if (e2 > sc) { sc = e2; del = 2;}
16173 X       if (e4 >= sc) { sc = e4; del = 4;}
16174 X      } else {
16175 X       if (j ==3) {sc= lC[0]; del = 3;}
16176 X       else if (j == 2) {sc = lC[0]-shift; del = 2;}
16177 X      }
16178 X      sc = sc+score;
16179 X      if (sc < ci) {
16180 X       sc = ci; del = 0; 
16181 X      }
16182 X      if (sc <= cd) {
16183 X       sc = cd;
16184 X       del = 5;
16185 X      }
16186 X      cC[j] = sc;
16187 X      sc -= gop;
16188 X      if (sc < cd) {
16189 X       del += 10;
16190 X       cD[j+3] = cd - gext;
16191 X      } else cD[j+3] = sc -gext;
16192 X      if (sc < ci) {
16193 X       del += 20;
16194 X       cI[j] = ci-gext;
16195 X      } else cI[j] = sc-gext;
16196 X      *(cst++) = del;
16197 X    }
16198 X    lC = cC;
16199 X  }
16200 X  if (N2 && ci +gop > cC[ey-y+1]) {
16201 X    st[ex-x+1][ey-y+1] = 0;
16202 X    /*printf("small score = %d\n", ci+gop);*/
16203 X  } /*else printf("small score =%d\n", cC[ey-y+1]);*/
16204 X  first = NULL; e = 1;
16205 X  for (i = ex+1, j = ey+1; i > x || j > y; i--) {
16206 X    mp = (match_ptr) ckalloc(sizeof(match_node));
16207 X    mp->i = i-1;
16208 X    k  = (t=st[i-x][j-y])%10;
16209 X    mp->j = j-1;
16210 X    if (e == 5 && (t/10)%2 == 1) k = 5;
16211 X    if (e == 0 && (t/20)== 1) k = 0;
16212 X    if (k == 5) { j -= 3; i++; e=5;}
16213 X    else {j -= k;if (k==0) e= 0; else e = 1;}
16214 X    mp->l = k;
16215 X    mp->next = first;
16216 X    first = mp;
16217 X  }
16218 X
16219 X  /*   for (i = 0; i <= ex-x; i++) {
16220 X       for (j = 0; j <= ey-y; j++) 
16221 X       printf("%d ", C[i][j]);
16222 X       printf("\n");
16223 X       }
16224 X  */
16225 X  return first;        
16226 }
16227 X
16228 X
16229 #define XTERNAL
16230 #include "upam.h"
16231 X
16232 extern void display_alig(a, dna, pro,length, ld)
16233 int *a;
16234 unsigned char *dna, *pro;
16235 int length, ld;
16236 {
16237 X       int len = 0, i, j, x, y, lines, k;
16238 X       static char line1[100], line2[100], line3[100],
16239 X                tmp[10] = "         ";
16240 X       unsigned char *dna1, c1, c2, c3, *st;
16241 X
16242 X       dna1 = ckalloc((size_t)ld);
16243 X       for (st = dna, i = 0; i < ld; i++, st++) dna1[i] = aa[*st];
16244 X       line1[0] = line2[0] = line3[0] = '\0'; x= a[0]; y = a[1]-1;
16245
16246 X       for (len = 0, j = 2, lines = 0; j < length; j++) {
16247 X               i = a[j];
16248 X               /*printf("%d %d %d\n", i, len, b->j);*/
16249 X               if (i > 0 && i < 5) tmp[i-2] = aa[pro[x++]];
16250 X               if (i == 5) {
16251 X                   i = 3; tmp[0] = tmp[1] = tmp[2] = '-';
16252 X                   if (a[j+1] == 2) tmp[2] = ' ';
16253 X               }
16254 X               if (i > 0) {
16255 X                   strncpy(&line1[len], (const char *)&dna1[y], i); y+=i;
16256 X               } else {line1[len] = '-'; i = 1; tmp[0] = aa[pro[x++]];}
16257 X               strncpy(&line2[len], tmp, i);
16258 X               for (k = 0; k < i; k++) {
16259 X                       if (tmp[k] != ' ' && tmp[k] != '-') {
16260 X                               if (k == 2) tmp[k] = '\\';
16261 X                               else if (k == 1) tmp[k] = '|';
16262 X                               else tmp[k] = '/';
16263 X                       } else tmp[k] = ' ';
16264 X               }
16265 X               if (i == 1) tmp[0] = ' ';
16266 X               strncpy(&line3[len], tmp, i); 
16267 X               tmp[0] = tmp[1] =  tmp[2] = ' ';
16268 X               len += i;
16269 X               line1[len] = line2[len] =line3[len]  = '\0'; 
16270 X               if (len >= WIDTH) {
16271 X                   printf("\n%5d", WIDTH*lines++);
16272 X                   for (k = 10; k <= WIDTH; k+=10) 
16273 X                       printf("    .    :");
16274 X                   if (k-5 < WIDTH) printf("    .");
16275 X                   c1 = line1[WIDTH]; c2 = line2[WIDTH]; c3 = line3[WIDTH];
16276 X                   line1[WIDTH] = line2[WIDTH] = line3[WIDTH] = '\0';
16277 X                   printf("\n     %s\n     %s\n     %s\n", line1, line3, line2);
16278 X                   line1[WIDTH] = c1; line2[WIDTH] = c2; line3[WIDTH] = c3;
16279 X                   strncpy(line1, &line1[WIDTH], sizeof(line1)-1);
16280 X                   strncpy(line2, &line2[WIDTH], sizeof(line2)-1);
16281 X                   strncpy(line3, &line3[WIDTH], sizeof(line3)-1);
16282 X                   len = len - WIDTH;
16283 X               }
16284 X        }
16285 X       printf("\n%5d", WIDTH*lines);
16286 X       for (k = 10; k < len; k+=10) 
16287 X           printf("    .    :");
16288 X       if (k-5 < len) printf("    .");
16289 X       printf("\n     %s\n     %s\n     %s\n", line1, line3, line2);
16290 }
16291 X
16292 X
16293 /* alignment store the operation that align the protein and dna sequence.
16294 X   The code of the number in the array is as follows:
16295 X   0:     delete of an amino acid.
16296 X   2:     frame shift, 2 nucleotides match with an amino acid
16297 X   3:     match an  amino acid with a codon
16298 X   4:     the other type of frame shift
16299 X   5:     delete of a codon
16300 X   
16301 X
16302 X   Also the first two element of the array stores the starting point 
16303 X   in the protein and dna sequences in the local alignment.
16304 X
16305 X   Display looks like where WIDTH is assumed to be divisible by 10.
16306 X
16307 X    0    .    :    .    :    .    :    .    :    .    :    .    :
16308 X     CCTATGATACTGGGATACTGGAACGTCCGCGGACTGACACACCCGATCCGCATGCTCCTG
16309 X      P  M  I  L  G  Y  W  N  V  R  G  L  T  H  P  I  R  M  L  L 
16310 X
16311 X   60    .    :    .    :    .    :    .    :    .    :    .    :
16312 X     GAATACACAGACTCAAGCTATGATGAGAAGAGATACACCATGGGTGACGCTCCCGACTTT
16313 X      E  Y  T  D  S  S  Y  D  E  K  R  Y  T  M  G  D  A  P  D  F 
16314 */
16315 X
16316 X
16317 /* fatal - print message and die */
16318 void fatal(msg)
16319 char *msg;
16320 {
16321 X       fprintf(stderr, "%s\n", msg);
16322 X       exit(1);
16323 }
16324 X
16325 int do_walign (const unsigned char *aa0, int n0,
16326 X              const unsigned char *aa1, int n1,
16327 X              int frame,
16328 X              struct pstruct *ppst, 
16329 X              struct f_struct *f_str, 
16330 X              struct a_res_str *a_res,
16331 X              int *have_ares)
16332 {
16333 X  int score;
16334 X  int i, last_n1, itemp, n10;
16335 X  int n_aa, n_nt, hoff, nt_min, nt_max, w_fact;
16336 X  unsigned char *fs, *fd;
16337 X  struct rstruct rst;
16338 X  int itx;
16339 X  
16340 #ifndef TFAST   /* FASTX */
16341 X  n_aa = n1;
16342 X  n_nt = n0;
16343 X
16344 X  /*  check for large differences in sequence length */
16345 X  nt_min = 0; nt_max = n_nt;
16346 X  if (n_nt > 6 * n_aa) {
16347 X    /* find out where the diagonal is - get hoff
16348 X       hoff < 0 => seq0 is in the middle of seq1 
16349 X    */
16350 X    do_fastx(f_str->aa0x, n0, aa1, n1, ppst, f_str, &rst, &hoff);
16351 X    if (rst.score[0] > 2 * rst.score[2]) {w_fact = 4;} 
16352 X    else w_fact = 2;
16353 X
16354 X    if (hoff > n_aa) { /* hoff > 0 => seq1 is in the middle of seq0 */
16355 X      nt_min = max(0,(hoff-w_fact*n_aa)*3);
16356 X      nt_max = min((hoff+w_fact*n_aa)*3,n_nt);
16357 X    }
16358 X    else {
16359 X      nt_max = min(3*w_fact*n_aa,n_nt);
16360 X    }
16361 X  }
16362 X
16363 X  a_res->res = f_str->res;
16364 X
16365 X  score = pro_dna(aa1, n1, f_str->aa0y+nt_min, nt_max-nt_min, ppst->pam2[0],
16366 #ifdef OLD_FASTA_GAP
16367 X                 -(ppst->gdelval - ppst->ggapval),
16368 #else
16369 X                 -ppst->gdelval,
16370 #endif
16371 X                 -ppst->ggapval,
16372 X                 -ppst->gshift,
16373 X                 f_str->max_res, a_res);
16374 X
16375 X  /* correct for nt_min missing residues in alignment */
16376 X
16377 #else   /* TFASTX */
16378 X
16379 X  /*
16380 X  for (i=0; i<n1; i++) {
16381 X    fputc(ppst->sq[f_str->aa1x[i]],stderr);
16382 X    if (i%60==59) fputc('\n',stderr);
16383 X  }
16384 X  fprintf(stderr,"\n-----\n");
16385 X  */
16386 X
16387 X  last_n1 = 0;
16388 X  for (itx=3*frame; itx<3+3*frame; itx++) {
16389 X    n10 = saatran(aa1,&f_str->aa1x[last_n1],n1,itx);
16390 /*
16391 X  for (i=0; i<n10; i++) {
16392 X  fprintf(stderr,"%c",pst.sq[aa10[last_n1+i]]);
16393 X  if ((i%60)==59) fprintf(stderr,"\n");
16394 X  }
16395 X  fprintf(stderr,"\n");
16396 */
16397 X    last_n1 += n10+1;
16398 X  }
16399 X  n10 = last_n1-1;
16400 X
16401 X  /* create aa1y from aa1x */
16402 X  for (fs=f_str->aa1x,itemp=0; itemp <3; itemp++,fs++) {
16403 X    for (fd= &f_str->aa1y[itemp]; *fs!=EOSEQ; fd += 3, fs++) *fd = *fs;
16404 X    *fd=EOSEQ;
16405 X  }
16406 X  /*
16407 X  for (i=0; i<n1; i++) {
16408 X    fputc(ppst->sq[f_str->aa1y[i]],stderr);
16409 X    if (i%60==59) fputc('\n',stderr);
16410 X  }
16411 X  fprintf(stderr,"\n-----\n");
16412 X  */
16413 X
16414 X  n_aa = n0;
16415 X  n_nt = n1;
16416 X
16417 X  /*  check for large differences in sequence length */
16418 X  nt_min = 0; nt_max = n_nt;
16419 X  if (n_nt > 6 * n_aa) {
16420 X    /* find out where the diagonal is - get hoff
16421 X       hoff < 0 => seq0 is in the middle of seq1 
16422 X    */
16423 X    do_fastx(aa0, n0, f_str->aa1x, n10, ppst, f_str, &rst, &hoff);
16424 X    if (rst.score[0] > 2 * rst.score[2]) {w_fact = 4;} 
16425 X    else w_fact = 2;
16426 X
16427 X    if ( hoff > n_aa) { /* hoff > 0 => seq1 is in the middle of seq0 */
16428 X      nt_min = max(0,(hoff-w_fact*n_aa)*3);
16429 X      nt_max = min((hoff+w_fact*n_aa)*3,n_nt);
16430 X    }
16431 X    else {
16432 X      nt_max = min(3*w_fact*n_aa,n_nt);
16433 X    }
16434 X  }
16435 X
16436 X  a_res->res = f_str->res;
16437 X
16438 X  score = pro_dna(aa0, n0, f_str->aa1y+nt_min, nt_max-nt_min, ppst->pam2[0],
16439 #ifdef OLD_FASTA_GAP
16440 X                 -(ppst->gdelval - ppst->ggapval),
16441 #else
16442 X                 -ppst->gdelval,
16443 #endif
16444 X                 -ppst->ggapval,
16445 X                 -ppst->gshift,
16446 X                 f_str->max_res, a_res);
16447 X
16448 #endif  /* TFASTX */
16449 X
16450 X  /* pro_dna always compares protein to DNA, and returns protein
16451 X     coordinates in a_res->min0,max0 */
16452 X
16453 X  a_res->min1 += nt_min;
16454 X  a_res->max1 += nt_min;
16455 X
16456 X  /* display_alig(f_str->res,f_str->aa0y,aa1,*nres,n0); */
16457 X
16458 X  *have_ares = 1;
16459 X  return score;
16460 }
16461 X
16462 /* aln_func_vals - set up aln.qlfact, qlrev, llfact, llmult, frame, llrev */
16463 /* call from calcons, calc_id, calc_code */
16464 void 
16465 aln_func_vals(int frame, struct a_struct *aln) {
16466 X
16467 #ifndef TFAST
16468 X  aln->llrev = 0;
16469 X  aln->llfact = 1;
16470 X  aln->llmult = 1;
16471 X  aln->qlfact = 3;
16472 X  aln->frame = 0;
16473 X  if (frame > 0) aln->qlrev = 1;
16474 X  else aln->qlrev = 0;
16475 #else   /* TFASTX */
16476 X  aln->qlfact = 1;
16477 X  aln->qlrev = 0;
16478 X  aln->llfact = 3;
16479 X  aln->llmult = 1;
16480 X  aln->frame = 0;
16481 X  if (frame > 0) aln->llrev = 1;
16482 X  else aln->llrev = 0;
16483 #endif  /* TFASTX */
16484 }
16485 X
16486 /* this function is required for programs like tfastx/y/s that do
16487 X   translations on DNA sequences and save them in f_str->aa1??
16488 */
16489 X
16490 void
16491 pre_cons(const unsigned char *aa1, int n1, int frame, struct f_struct *f_str) {
16492 #ifdef TFAST
16493 X  int i, last_n1, itemp, n10;
16494 X  unsigned char *fs, *fd;
16495 X  int itx;
16496 X
16497 X  last_n1 = 0;
16498 X  for (itx=3*frame; itx<3+3*frame; itx++) {
16499 X    n10 = saatran(aa1,&f_str->aa1x[last_n1],n1,itx);
16500 /*
16501 X  for (i=0; i<n10; i++) {
16502 X  fprintf(stderr,"%c",pst.sq[aa10[last_n1+i]]);
16503 X  if ((i%60)==59) fprintf(stderr,"\n");
16504 X  }
16505 X  fprintf(stderr,"\n");
16506 */
16507 X    last_n1 += n10+1;
16508 X  }
16509 X  n10 = last_n1-1;
16510 X
16511 X  /* create aa1y from aa1x */
16512 X  for (fs=f_str->aa1x,itemp=0; itemp <3; itemp++,fs++) {
16513 X    for (fd= &f_str->aa1y[itemp]; *fs!=EOSEQ; fd += 3, fs++) *fd = *fs;
16514 X    *fd=EOSEQ;
16515 X  }
16516 #endif
16517 }
16518 X
16519 X
16520 /*
16521 X   Alignment: store the operation that align the protein and dna sequence.
16522 X   The code of the number in the array is as follows:
16523 X   0:     delete of an amino acid.
16524 X   2:     frame shift, 2 nucleotides match with an amino acid
16525 X   3:     match an  amino acid with a codon
16526 X   4:     the other type of frame shift
16527 X   5:     delete of a codon
16528 X
16529 X   The first two elements of the array stores the starting point 
16530 X   in the protein and dna sequences in the local alignment.
16531 */
16532 X
16533 #include "a_mark.h"
16534 X
16535 int calcons(const unsigned char *aa0, int n0,
16536 X           const unsigned char *aa1, int n1,
16537 X           int *nc,
16538 X           struct a_struct *aln, 
16539 X           struct a_res_str a_res, 
16540 X           struct pstruct pst,
16541 X           char *seqc0, char *seqc1, char *seqca,
16542 X           struct f_struct *f_str)
16543 {
16544 X  int i0, i1, i, j;
16545 X  int lenc, not_c, itmp, ngap_p, ngap_d, nfs;
16546 X  char *sp0, *sp1, *spa, *sq;
16547 X  const unsigned char *ap0, *ap1;
16548 X  int *rp, *rpmax;
16549 X  
16550 X  if (pst.ext_sq_set) {sq = pst.sqx;}
16551 X  else {sq = pst.sq;}
16552 X
16553 X
16554 X
16555 #ifndef TFAST   /* FASTX */
16556 X  aln->amin1 = aln->smin1 = a_res.min0;        /* prot */
16557 X  aln->amin0 = aln->smin0 = a_res.min1;        /* DNA */
16558 X
16559 X  ap0 = f_str->aa0y;   /* translated DNA */
16560 X  ap1 = aa1;           /* protein */
16561 X
16562 X  sp0 = seqc0;
16563 X  sp1 = seqc1;
16564 #else           /* TFASTX */
16565 X  aln->amin0 = aln->smin0 = a_res.min0;        /* DNA */
16566 X  aln->amin1 = aln->smin1 = a_res.min1;        /* prot */
16567 X
16568 X  ap1 = aa0;   /* protein */
16569 X  ap0 = f_str->aa1y;   /* translated DNA */
16570 X
16571 X  sp1 = seqc0;
16572 X  sp0 = seqc1;
16573 #endif
16574 X
16575 X  rp = a_res.res;
16576 X  rpmax = rp+a_res.nres;
16577 X
16578 X  spa = seqca;
16579 X
16580 X  lenc = not_c = aln->nident = aln->nsim = ngap_p = ngap_d = nfs= 0;
16581 X  i0 = a_res.min1;
16582 X  i1 = a_res.min0;
16583 X
16584 X  while (rp < rpmax) {
16585 X    /*    fprintf(stderr,"%d %d %d (%c) %d (%c)\n"
16586 X         ,(int)(rp-res),*rp,i0,sq[ap0[i0]],i1,sq[ap1[i1]]);
16587 X    */
16588 X    switch (*rp++) {
16589 X    case 0:    /* aa insertion */
16590 X      *sp0++ = '-';
16591 X      *sp1++ = sq[ap1[i1++]];
16592 X      *spa++ = M_DEL;
16593 X      lenc++;
16594 X      ngap_d++;
16595 X      break;
16596 X    case 2:    /* -1 frameshift */
16597 X      nfs++;
16598 X      *sp0++ = '/';
16599 X      i0 -= 1;
16600 X      *sp1++ = '-';
16601 X      *spa++ = M_DEL;
16602 X      not_c++;
16603 X
16604 X      if ((itmp=pst.pam2[0][ap0[i0]][ap1[i1]])<0) { *spa = M_NEG; }
16605 X      else if (itmp == 0) { *spa = M_ZERO;}
16606 X      else {*spa = M_POS;}
16607 X      if (*spa == M_POS || *spa == M_ZERO) { aln->nsim++;}
16608 X
16609 X      *sp0 = sq[ap0[i0]];
16610 X      i0 += 3;
16611 X      *sp1 = sq[ap1[i1++]];
16612 X      if (toupper(*sp0) == toupper(*sp1)) {aln->nident++; *spa = M_IDENT;}
16613 X      sp0++; sp1++; spa++;
16614 X      lenc++;
16615 X      break;
16616 X    case 3:    /* codon/aa match */
16617 X      if ((itmp=pst.pam2[0][ap0[i0]][ap1[i1]])<0) { *spa = M_NEG; }
16618 X      else if (itmp == 0) { *spa = M_ZERO;}
16619 X      else {*spa = M_POS;}
16620 X      if (*spa == M_POS || *spa == M_ZERO) { aln->nsim++;}
16621 X
16622 X      *sp0 = sq[ap0[i0]];
16623 X      i0 += 3;
16624 X      *sp1 = sq[ap1[i1++]];
16625 X      if (toupper(*sp0) == toupper(*sp1)) {aln->nident++; *spa = M_IDENT;}
16626 X      sp0++; sp1++; spa++;
16627 X      lenc++;
16628 X      break;
16629 X    case 4:    /* +1 frameshift */
16630 X      nfs++;
16631 X      *sp0++ = '\\';
16632 X      i0 += 1;
16633 X      *sp1++ = '-';
16634 X      *spa++ = M_DEL;
16635 X      not_c++;
16636 X
16637 X      if ((itmp=pst.pam2[0][ap0[i0]][ap1[i1]])<0) { *spa = M_NEG; }
16638 X      else if (itmp == 0) { *spa = M_ZERO;}
16639 X      else {*spa = M_POS;}
16640 X      if (*spa == M_POS || *spa == M_ZERO) { aln->nsim++;}
16641 X
16642 X      *sp0 = sq[ap0[i0]];
16643 X      i0 += 3;
16644 X      *sp1 = sq[ap1[i1++]];
16645 X      if (toupper(*sp0) == toupper(*sp1)) {aln->nident++; *spa = M_IDENT;}
16646 X      sp0++; sp1++; spa++;
16647 X      lenc++;
16648 X      break;
16649 X    case 5:    /* codon insertion */
16650 X      *sp0++ = sq[ap0[i0]];
16651 X      i0 += 3;
16652 X      *sp1++ = '-';
16653 X      *spa++ = M_DEL;
16654 X      lenc++;
16655 X      ngap_p++;
16656 X      break;
16657 X    }
16658 X  }
16659 X  *spa = '\0';
16660 X
16661 #ifndef TFAST   /* FASTX */
16662 X  aln->amax0 = i0;
16663 X  aln->amax1 = i1;
16664 X  aln->ngap_q = ngap_d;
16665 X  aln->ngap_l = ngap_p;
16666 #else
16667 X  aln->amax1 = i0;
16668 X  aln->amax0 = i1;
16669 X  aln->amin1 = aln->smin1;
16670 X  aln->amin0 = aln->smin0;
16671 X  aln->ngap_q = ngap_p;
16672 X  aln->ngap_l = ngap_d;
16673 #endif
16674 X  aln->nfs = nfs;
16675 X
16676 X  if (lenc < 0) lenc = 1;
16677 X  *nc = lenc;
16678 /*      now we have the middle, get the right end */
16679 X  return lenc+not_c;
16680 }
16681 X
16682 int calcons_a(const unsigned char *aa0, unsigned char *aa0a, int n0,
16683 X             const unsigned char *aa1, int n1,
16684 X             int *nc,
16685 X             struct a_struct *aln,
16686 X             struct a_res_str a_res, 
16687 X             struct pstruct pst,
16688 X             char *seqc0, char *seqc0a, char *seqc1, char *seqca,
16689 X             char *ann_arr, struct f_struct *f_str)
16690 {
16691 X  int i0, i1, i, j;
16692 X  int lenc, not_c, itmp, ngap_p, ngap_d, nfs;
16693 X  char *sp0, *sp0a, *sp1, *spa, *sq;
16694 X  const unsigned char *ap0, *ap1;
16695 X  int *rp, *rpmax;
16696 X  
16697 X  if (pst.ext_sq_set) {sq = pst.sqx;}
16698 X  else {sq = pst.sq;}
16699 X
16700 #ifndef TFAST   /* FASTX */
16701 X  aln->amin1 = aln->smin1 = a_res.min0;        /* prot */
16702 X  aln->amin0 = aln->smin0 = a_res.min1;        /* DNA */
16703 X
16704 X  ap0 = f_str->aa0y;   /* translated DNA */
16705 X  ap1 = aa1;           /* protein */
16706 #else           /* TFASTX */
16707 X  aln->amin0 = aln->smin0 = a_res.min0;        /* DNA */
16708 X  aln->amin1 = aln->smin1 = a_res.min1;        /* prot */
16709 X
16710 X  ap1 = aa0;
16711 X  ap0 = f_str->aa1y;
16712 #endif
16713 X
16714 X  rp = a_res.res;
16715 X  rpmax = &a_res.res[a_res.nres];
16716 X
16717 #ifndef TFAST
16718 X  sp0 = seqc0;
16719 X  sp1 = seqc1;
16720 #else
16721 X  sp1 = seqc0;
16722 X  sp0 = seqc1;
16723 #endif
16724 X  spa = seqca;
16725 X  sp0a = seqc0a;
16726 X
16727 X  lenc = not_c = aln->nident = aln->nsim = ngap_p = ngap_d = nfs= 0;
16728 X  i0 = a_res.min1;
16729 X  i1 = a_res.min0;
16730 X
16731 X  while (rp < rpmax) {
16732 X    /*    fprintf(stderr,"%d %d %d (%c) %d (%c)\n"
16733 X         ,(int)(rp-res),*rp,i0,sq[ap0[i0]],i1,sq[ap1[i1]]);
16734 X    */
16735 X    switch (*rp++) {
16736 X    case 0:    /* aa insertion */
16737 X      *sp0++ = '-';
16738 X      *sp1++ = sq[ap1[i1++]];
16739 X      *spa++ = M_DEL;
16740 X      *sp0a++ = ' ';
16741 X      lenc++;
16742 X      ngap_d++;
16743 X      break;
16744 X    case 2:    /* -1 frameshift */
16745 X      nfs++;
16746 X      *sp0++ = '/';
16747 X      i0 -= 1;
16748 X      *sp1++ = '-';
16749 X      *spa++ = M_DEL;
16750 X      *sp0a++ = ' ';
16751 X      not_c++;
16752 X
16753 X      if ((itmp=pst.pam2[0][ap0[i0]][ap1[i1]])<0) { *spa = M_NEG; }
16754 X      else if (itmp == 0) { *spa = M_ZERO;}
16755 X      else {*spa = M_POS;}
16756 X      if (*spa == M_POS || *spa == M_ZERO) { aln->nsim++;}
16757 X
16758 #ifndef TFAST
16759 X      *sp0a++ = ' ';
16760 #else
16761 X      *sp0a++ = ann_arr[aa0a[i1]];
16762 #endif
16763 X      *sp0 = sq[ap0[i0]];
16764 X      i0 += 3;
16765 X      *sp1 = sq[ap1[i1++]];
16766 X      if (toupper(*sp0) == toupper(*sp1)) {aln->nident++; *spa = M_IDENT;}
16767 X      sp0++; sp1++; spa++;
16768 X      lenc++;
16769 X      break;
16770 X    case 3:    /* codon/aa match */
16771 X      if ((itmp=pst.pam2[0][ap0[i0]][ap1[i1]])<0) { *spa = M_NEG; }
16772 X      else if (itmp == 0) { *spa = M_ZERO;}
16773 X      else {*spa = M_POS;}
16774 X      if (*spa == M_POS || *spa == M_ZERO) { aln->nsim++;}
16775 X
16776 #ifndef TFAST
16777 X      *sp0a++ = ' ';
16778 #else
16779 X      *sp0a++ = ann_arr[aa0a[i1]];
16780 #endif
16781 X      *sp0 = sq[ap0[i0]];
16782 X      i0 += 3;
16783 X      *sp1 = sq[ap1[i1++]];
16784 X      if (toupper(*sp0) == toupper(*sp1)) {aln->nident++; *spa = M_IDENT;}
16785 X      sp0++; sp1++; spa++;
16786 X      lenc++;
16787 X      break;
16788 X    case 4:    /* +1 frameshift */
16789 X      nfs++;
16790 X      *sp0a++ = ' ';
16791 X      *sp0++ = '\\';
16792 X      i0 += 1;
16793 X      *sp1++ = '-';
16794 X      *spa++ = M_DEL;
16795 X      not_c++;
16796 X
16797 X      if ((itmp=pst.pam2[0][ap0[i0]][ap1[i1]])<0) { *spa = M_NEG; }
16798 X      else if (itmp == 0) { *spa = M_ZERO;}
16799 X      else {*spa = M_POS;}
16800 X      if (*spa == M_POS || *spa == M_ZERO) { aln->nsim++;}
16801 X
16802 X      *sp0 = sq[ap0[i0]];
16803 X      i0 += 3;
16804 X      *sp1 = sq[ap1[i1++]];
16805 X      if (toupper(*sp0) == toupper(*sp1)) {aln->nident++; *spa = M_IDENT;}
16806 X      sp0++; sp1++; spa++;
16807 X      lenc++;
16808 X      break;
16809 X    case 5:    /* codon insertion */
16810 X      *sp0a++ = ' ';
16811 X      *sp0++ = sq[ap0[i0]];
16812 X      i0 += 3;
16813 X      *sp1++ = '-';
16814 X      *spa++ = M_DEL;
16815 X      lenc++;
16816 X      ngap_p++;
16817 X      break;
16818 X    }
16819 X  }
16820 X  *sp0a = *spa = '\0';
16821 X
16822 #ifndef TFAST
16823 X  aln->amax0 = i0;
16824 X  aln->amax1 = i1;
16825 X  aln->ngap_q = ngap_d;
16826 X  aln->ngap_l = ngap_p;
16827 #else
16828 X  aln->amax1 = i0;
16829 X  aln->amax0 = i1;
16830 X  aln->ngap_q = ngap_p;
16831 X  aln->ngap_l = ngap_d;
16832 #endif
16833 X  aln->nfs = nfs;
16834 X
16835 X  if (lenc < 0) lenc = 1;
16836 X  *nc = lenc;
16837 /*      now we have the middle, get the right end */
16838 X  return lenc+not_c;
16839 }
16840 X
16841 /* build an array of match/ins/del - length strings */
16842 int calc_code(const unsigned char *aa0, int n0,
16843 X             const unsigned char *aa1, int n1,
16844 X             struct a_struct *aln,
16845 X             struct a_res_str a_res, 
16846 X             struct pstruct pst,
16847 X             char *al_str, int al_str_n, struct f_struct *f_str)
16848 {
16849 X  int i0, i1, i, j;
16850 X  int lenc, not_c, itmp, ngap_p, ngap_d, nfs;
16851 X  char op_char[10];
16852 X  int op, op_cnt;
16853 X  char sp0, sp1, *sq;
16854 X  const unsigned char *ap0, *ap1;
16855 X  int *rp, *rpmax;
16856 X  
16857 X  if (pst.ext_sq_set) {sq = pst.sqx;}
16858 X  else {sq = pst.sq;}
16859 X
16860 X
16861 #ifndef TFAST   /* FASTX */
16862 X  strncpy(op_char,"- /=\\+*",sizeof(op_char));
16863 X  aln->amin1 = aln->smin1 = a_res.min0;        /* prot */
16864 X  aln->amin0 = aln->smin0 = a_res.min1;        /* DNA */
16865 X
16866 X  ap0 = f_str->aa0y;
16867 X  ap1 = aa1;
16868 #else           /* TFASTX */
16869 X  strncpy(op_char,"+ /=\\-*",sizeof(op_char));
16870 X  aln->amin0 = aln->smin0 = a_res.min0;        /* DNA */
16871 X  aln->amin1 = aln->smin1 = a_res.min1;        /* prot */
16872 X
16873 X  ap1 = aa0;
16874 X  ap0 = f_str->aa1y;
16875 #endif
16876 X
16877 X  rp = a_res.res;
16878 X  rpmax = &a_res.res[a_res.nres];
16879 X
16880 X  op_cnt = lenc = not_c = aln->nident = aln->nsim = ngap_p = ngap_d = nfs = 0;
16881 X  op = 3; /* code for a match - all alignments start with a match */
16882 X
16883 X  i0 = a_res.min1;
16884 X  i1 = a_res.min0;
16885 X
16886 X  while (rp < rpmax) {
16887 X    switch (*rp++) {
16888 X    case 0:    /* aa insertion */
16889 X      if (op == 0) op_cnt++;
16890 X      else {
16891 X       update_code(al_str, al_str_n-strlen(al_str),op, op_cnt,op_char);
16892 X       op = 0; op_cnt = 1;
16893 X      }
16894 X      i1++;
16895 X      lenc++;
16896 X      ngap_d++;
16897 X      break;
16898 X    case 2:    /* -1 frameshift */
16899 X      if (pst.pam2[0][ap0[i0]][ap1[i1]]>=0) { aln->nsim++;}
16900 X
16901 X      update_code(al_str, al_str_n-strlen(al_str),op, op_cnt,op_char);
16902 X      op = 2; op_cnt = 1;
16903 X      update_code(al_str, al_str_n-strlen(al_str),op, op_cnt,op_char);
16904 X      op = 3; op_cnt = 1;
16905 X      nfs++;
16906 X      i0 -= 1;
16907 X      not_c++;
16908 X      sp0 = sq[ap0[i0]];
16909 X      i0 += 3;
16910 X      sp1 = sq[ap1[i1++]];
16911 X      if (toupper(sp0) == toupper(sp1)) aln->nident++;
16912 X      lenc++;
16913 X      break;
16914 X    case 3:    /* codon/aa match */
16915 X      if (pst.pam2[0][ap0[i0]][ap1[i1]]>=0) { aln->nsim++;}
16916 X      sp0 = sq[ap0[i0]];
16917 X      i0 += 3;
16918 X      sp1 = sq[ap1[i1++]];
16919 X      if (toupper(sp0) == toupper(sp1)) aln->nident++;
16920 X
16921 X      if (op == 3 || op == 6) {
16922 X       if (sp0 != '*' && sp1 != '*') {
16923 X         if (op == 6 ) {
16924 X           update_code(al_str, al_str_n-strlen(al_str),op, op_cnt,op_char);
16925 X           op_cnt = 1; op = 3;
16926 X         }
16927 X         else {op_cnt++;}
16928 X       }
16929 X       else {
16930 X         update_code(al_str, al_str_n-strlen(al_str),op, op_cnt,op_char);
16931 X         op_cnt = 1; op = 6;
16932 X       }
16933 X      }
16934 X      else {
16935 X       update_code(al_str, al_str_n-strlen(al_str),op, op_cnt,op_char);
16936 X       if (op == 2 || op == 4) op_cnt = 2;
16937 X       else op_cnt = 1;
16938 X       op = 3;
16939 X      }
16940 X      lenc++;
16941 X      break;
16942 X    case 4:    /* +1 frameshift */
16943 X      update_code(al_str, al_str_n-strlen(al_str),op, op_cnt,op_char);
16944 X      op = 4; op_cnt = 1;
16945 X      update_code(al_str, al_str_n-strlen(al_str),op, op_cnt,op_char);
16946 X      op = 3; op_cnt = 1;
16947 X
16948 X      nfs++;
16949 X      i0 += 1;
16950 X      not_c++;
16951 X      if (pst.pam2[0][ap0[i0]][ap1[i1]]>=0) { aln->nsim++;}
16952 X      sp0 = sq[ap0[i0]];
16953 X      i0 += 3;
16954 X      sp1 = sq[ap1[i1++]];
16955 X      if (toupper(sp0) == toupper(sp1)) aln->nident++;
16956 X      lenc++;
16957 X      break;
16958 X    case 5:    /* codon insertion */
16959 X      if (op == 5) op_cnt++;
16960 X      else {
16961 X       update_code(al_str, al_str_n-strlen(al_str),op, op_cnt,op_char);
16962 X       op = 5; op_cnt = 1;
16963 X      }
16964 X      i0 += 3;
16965 X      lenc++;
16966 X      ngap_p++;
16967 X      break;
16968 X    }
16969 X  }
16970 X  update_code(al_str, al_str_n-strlen(al_str),op, op_cnt,op_char);
16971 X
16972 #ifndef TFAST
16973 X  aln->amax0 = i0;
16974 X  aln->amax1 = i1;
16975 X  aln->ngap_q = ngap_d;
16976 X  aln->ngap_l = ngap_p;
16977 #else
16978 X  aln->amax1 = i0;
16979 X  aln->amax0 = i1;
16980 X  aln->ngap_q = ngap_p;
16981 X  aln->ngap_l = ngap_d;
16982 #endif
16983 X  aln->nfs = nfs;
16984 X
16985 X  if (lenc < 0) lenc = 1;
16986 X
16987 X  return lenc;
16988 }
16989 X
16990 static void
16991 update_code(char *al_str, int al_str_max, int op, int op_cnt, char *op_char) {
16992 X
16993 X  char tmp_cnt[20];
16994 X
16995 X  sprintf(tmp_cnt,"%c%d",op_char[op],op_cnt);
16996 X  strncat(al_str,tmp_cnt,al_str_max-1);
16997 X  al_str[al_str_max-1]='\0';
16998 }
16999 X
17000 int calc_id(const unsigned char *aa0, int n0,
17001 X           const unsigned char *aa1, int n1,
17002 X           struct a_struct *aln,
17003 X           struct a_res_str a_res, 
17004 X           struct pstruct pst,
17005 X           struct f_struct *f_str)
17006 {
17007 X  int i0, i1, i, j;
17008 X  int lenc, not_c, itmp, ngap_p, ngap_d, nfs;
17009 X  char sp0, sp1, *sq;
17010 X  const unsigned char *ap0, *ap1;
17011 X  int *rp, *rpmax;
17012 X  
17013 X  if (pst.ext_sq_set) {sq = pst.sqx;}
17014 X  else {sq = pst.sq;}
17015 X
17016 X
17017 #ifndef TFAST   /* FASTX */
17018 X  aln->amin1 = aln->smin1 = a_res.min0;        /* prot */
17019 X  aln->amin0 = aln->smin0 = a_res.min1;        /* DNA */
17020 X
17021 X  ap0 = f_str->aa0y;
17022 X  ap1 = aa1;
17023 #else   /* TFASTX */
17024 X  aln->amin0 = aln->smin0 = a_res.min0;        /* DNA */
17025 X  aln->amin1 = aln->smin1 = a_res.min1;        /* prot */
17026 X
17027 X  ap1 = aa0;
17028 X  ap0 = f_str->aa1y;
17029 #endif
17030 X
17031 X  rp = a_res.res;
17032 X  rpmax = &a_res.res[a_res.nres];
17033 X
17034 X  lenc = not_c = aln->nident = aln->nsim = ngap_p = ngap_d = nfs = 0;
17035 X  i0 = a_res.min1;
17036 X  i1 = a_res.min0;
17037 X
17038 X  while (rp < rpmax) {
17039 X    /*    fprintf(stderr,"%d %d %d (%c) %d (%c)\n"
17040 X         ,(int)(rp-res),*rp,i0,sq[ap0[i0]],i1,sq[ap1[i1]]);
17041 X    */
17042 X    switch (*rp++) {
17043 X    case 0:    /* aa insertion */
17044 X      i1++;
17045 X      lenc++;
17046 X      ngap_d++;
17047 X      break;
17048 X    case 2:    /* -1 frameshift */
17049 X      nfs++;
17050 X      i0 -= 1;
17051 X      not_c++;
17052 X      if (pst.pam2[0][ap0[i0]][ap1[i1]]>=0) { aln->nsim++;}
17053 X      sp0 = sq[ap0[i0]];
17054 X      i0 += 3;
17055 X      sp1 = sq[ap1[i1++]];
17056 X      if (toupper(sp0) == toupper(sp1)) aln->nident++;
17057 X      lenc++;
17058 X      break;
17059 X    case 3:    /* codon/aa match */
17060 X      if (pst.pam2[0][ap0[i0]][ap1[i1]]>=0) { aln->nsim++;}
17061 X      sp0 = sq[ap0[i0]];
17062 X      i0 += 3;
17063 X      sp1 = sq[ap1[i1++]];
17064 X      if (toupper(sp0) == toupper(sp1)) aln->nident++;
17065 X      lenc++;
17066 X      break;
17067 X    case 4:    /* +1 frameshift */
17068 X      nfs++;
17069 X      i0 += 1;
17070 X      not_c++;
17071 X      if (pst.pam2[0][ap0[i0]][ap1[i1]]>=0) { aln->nsim++;}
17072 X      sp0 = sq[ap0[i0]];
17073 X      i0 += 3;
17074 X      sp1 = sq[ap1[i1++]];
17075 X      if (toupper(sp0) == toupper(sp1)) aln->nident++;
17076 X      lenc++;
17077 X      break;
17078 X    case 5:    /* codon insertion */
17079 X      i0 += 3;
17080 X      lenc++;
17081 X      ngap_p++;
17082 X      break;
17083 X    }
17084 X  }
17085 X
17086 #ifndef TFAST
17087 X  aln->amax0 = i0;
17088 X  aln->amax1 = i1;
17089 X  aln->ngap_q = ngap_d;
17090 X  aln->ngap_l = ngap_p;
17091 #else
17092 X  aln->amax1 = i0;
17093 X  aln->amax0 = i1;
17094 X  aln->ngap_q = ngap_p;
17095 X  aln->ngap_l = ngap_d;
17096 #endif
17097 X  aln->nfs = nfs;
17098 X
17099 X  if (lenc < 0) lenc = 1;
17100 /*      now we have the middle, get the right end */
17101 X  return lenc;
17102 }
17103 X
17104 #ifdef PCOMPLIB
17105 #include "p_mw.h"
17106 void
17107 update_params(struct qmng_str *qm_msg, struct pstruct *ppst)
17108 {
17109 X  ppst->n0 = qm_msg->n0;
17110 }
17111 #endif
17112 SHAR_EOF
17113 chmod 0644 dropfx.c ||
17114 echo 'restore of dropfx.c failed'
17115 Wc_c="`wc -c < 'dropfx.c'`"
17116 test 73324 -eq "$Wc_c" ||
17117         echo 'dropfx.c: original size 73324, current size' "$Wc_c"
17118 fi
17119 # ============= dropfz2.c ==============
17120 if test -f 'dropfz2.c' -a X"$1" != X"-c"; then
17121         echo 'x - skipping dropfz2.c (File already exists)'
17122 else
17123 echo 'x - extracting dropfz2.c (Text)'
17124 sed 's/^X//' << 'SHAR_EOF' > 'dropfz2.c' &&
17125 X
17126 /* copyright (c) 1998, 1999 William R. Pearson and the U. of Virginia */
17127 X
17128 /* $Name: fa_34_26_5 $ - $Id: dropfz2.c,v 1.57 2007/04/26 18:37:19 wrp Exp $ */
17129 X
17130 /* 18-Sept-2006 - removed static global variables for alignment */
17131 X
17132 /* 2002/06/23 finally correctly implement fix to translate 'N' to 'X' */
17133 X
17134 /* 1999/11/29 modification by Z. Zhang to translate DNA 'N' as 'X' */
17135 X
17136 /* implements an improved version of the fasty algorithm, see:
17137 X
17138 X   W. R. Pearson, T. Wood, Z. Zhang, A W. Miller (1997) "Comparison of
17139 X   DNA sequences with protein sequences" Genomics 46:24-36
17140 X
17141 */
17142 #include <stdio.h>
17143 #include <stdlib.h>
17144 #include <string.h>
17145 #include <math.h>
17146 #include <ctype.h>
17147 X
17148 #include "defs.h"
17149 #include "param.h"
17150 #define XTERNAL
17151 #include "upam.h"
17152 #include "uascii.h"
17153 X
17154 #define NT_N 16
17155 X
17156 /* globals for fasta */
17157 #define MAXWINDOW 64
17158 X
17159 #ifndef MAXSAV
17160 #define MAXSAV 10
17161 #endif
17162 X
17163 #ifndef ALLOCN0
17164 static char *verstr="3.5 Sept 2006";
17165 #else
17166 static char *verstr="3.5an0 Sept 2006";
17167 #endif
17168 X
17169 struct dstruct          /* diagonal structure for saving current run */
17170 {                       
17171 X   int     score;      /* hash score of current match */
17172 X   int     start;      /* start of current match */
17173 X   int     stop;       /* end of current match */
17174 X   struct savestr *dmax;   /* location in vmax[] where best score data saved */
17175 };
17176 X
17177 struct savestr
17178 {
17179 X   int     score;              /* pam score with segment optimization */
17180 X   int     score0;             /* pam score of best single segment */
17181 X   int     gscore;             /* score from global match */
17182 X   int     dp;                 /* diagonal of match */
17183 X   int     start;              /* start of match in lib seq */
17184 X   int     stop;               /* end of match in lib seq */
17185 };
17186 X
17187 void savemax();
17188 void kpsort();
17189 X
17190 struct sx_s {int C1, C2, C3, I1, I2, I3, flag; };
17191 X
17192 struct wgt { int  iii, ii, iv;};
17193 struct wgtc {char c2, c3, c4, c5;};
17194 X
17195 typedef struct st_s { int C, I, D;} *st_ptr;
17196 X
17197 struct f_struct {
17198 X  struct dstruct *diag;
17199 X  struct savestr vmax[MAXSAV]; /* best matches saved for one sequence */
17200 X  struct savestr *vptr[MAXSAV];
17201 X  struct savestr *lowmax;
17202 X  int ndo;
17203 X  int noff;
17204 X  int hmask;                   /* hash constants */
17205 X  int *pamh1;                  /* pam based array */
17206 X  int *pamh2;                  /* pam based kfact array */
17207 X  int *link, *harr;            /* hash arrays */
17208 X  int kshft;                   /* shift width */
17209 X  int nsav, lowscor;           /* number of saved runs, worst saved run */
17210 #ifndef TFAST
17211 X  unsigned char *aa0x, *aa0v;  /* aa0x - 111122223333 */
17212 #else
17213 X  unsigned char *aa1x, *aa1v;  /* aa1x - 111122223333 */
17214 #endif                          /* aa1v - computed codons */
17215 X  struct sx_s *cur;
17216 X  struct wgt **weight0;
17217 X  struct wgt **weight1;
17218 X  struct wgtc **weight_c;
17219 X  int *waa;
17220 X  int *res;
17221 X  int max_res;
17222 X  st_ptr up, down, tp;
17223 };
17224 X
17225 #define DROP_INTERN
17226 #include "drop_func.h"
17227 X
17228 static int dmatchx(const unsigned char *aa0, int n0,
17229 X                  const unsigned char *aa1, int n1,
17230 X                  int hoff, int window, 
17231 X                  int **pam2, int gdelval, int ggapval, int gshift,
17232 X                  struct f_struct *f_str);
17233 X
17234 int shscore(unsigned char *aa0, int n0, int **pam2);
17235 int saatran(const unsigned char *ntseq, unsigned char *aaseq, int maxs, int frame);
17236 int spam (const unsigned char *aa0, const unsigned char *aa1, 
17237 X         struct savestr *dmax, int **pam2,
17238 X         struct f_struct *f_str);
17239 int sconn (struct savestr **v, int n,int cgap, int pgap, struct f_struct *f_str);
17240 int lx_band(const unsigned char *prot_seq, int len_prot,
17241 X           const unsigned char *dna_prot_seq, int len_dna_prot,
17242 X           int **pam_matrix, int gopen, int gext,
17243 X           int gshift, int start_diag, int width, struct f_struct *f_str);
17244 static void update_code(char *al_str, int al_str_max, int op, int op_cnt, char *op_char);
17245 extern void w_abort (char *p, char *p1);
17246 extern void aagetmap(char *to, int n);
17247 X
17248 /* initialize for fasta */
17249 /* modified 30-August-1999 by Zheng Zhang to work with an extended alphabet */
17250 /* Assume naa=47, and wgts[47][23] matches both upper and lower case
17251 amoino acids with another amino acid.  And also assume the DNA letter
17252 does not have upper/lower case difference.  If you also allow DNA
17253 sequence to be upper/lower case letters, more needs be changed. Not
17254 only here, but also in the alignment code, the way that pack a codon
17255 into a number between 0-63 need be changed. */
17256 X
17257 /* modified so that if **weightci==NULL, do not fiddle with characters */
17258 X
17259 void
17260 init_weights(struct wgt ***weighti, struct wgtc ***weightci,
17261 X            int **wgts, int gshift, int gsubs, int naa)
17262 {
17263 X  int i, j, do_wgtc=0;
17264 X  int aa, b, a, x, y, z;
17265 X  int *wwt, e;
17266 X  struct wgt **weight;
17267 X  struct wgtc **weightc;
17268 X  char aacmap[64];
17269 X  int temp[49][64]; /*change*/
17270 X  char le[49][64];
17271 X
17272 X
17273 X  if ((*weighti=(struct wgt **)calloc((size_t)(naa+1),sizeof(struct wgt *)))
17274 X      ==NULL) {
17275 X    fprintf(stderr," cannot allocate weights array: %d\n",naa);
17276 X    exit(1);
17277 X  }
17278 X
17279 X  weight = *weighti;
17280 X  for (aa=0; aa <= naa; aa++) {
17281 X    if ((weight[aa]=(struct wgt *)calloc((size_t)256,sizeof(struct wgt)))
17282 X       ==NULL) {
17283 X      fprintf(stderr," cannot allocate weight[]: %d/%d\n",aa,naa);
17284 X      exit(1);
17285 X    }
17286 X  }
17287 X
17288 X  if (weightci !=NULL) {
17289 X    if ((*weightci=(struct wgtc **)calloc((size_t)(naa+1),
17290 X                                         sizeof(struct wgtc *)))==NULL) {
17291 X      fprintf(stderr," cannot allocate weight_c array: %d\n",naa);
17292 X      exit(1);
17293 X    }
17294 X    weightc = *weightci;
17295 X
17296 X    for (aa=0; aa <= naa; aa++) {
17297 X      if ((weightc[aa]=(struct wgtc *)calloc((size_t)256,sizeof(struct wgtc)))
17298 X         ==NULL) {
17299 X       fprintf(stderr," cannot allocate weightc[]: %d/%d\n",aa,naa);
17300 X       exit(1);
17301 X      }
17302 X    }
17303 X    do_wgtc = 1;
17304 X  }
17305 X  else do_wgtc = 0;
17306 X
17307 X  aagetmap(aacmap,64);
17308 X
17309 X  for (aa = 0; aa <= naa; aa++) {      /* change*/
17310 X      wwt = wgts[aa];
17311 X      for (i = 0; i < 64; i++) {       /* j iterates through the codons */
17312 X         x = -1000;
17313 X         y = i;
17314 X         for (j = 0; j < 64; j++) {    /* j iterates through the codons */
17315 X             z = ((~i & j) | (i & ~j));
17316 X             b = 0;            /* score = 0 */
17317 X             if (z % 4) b-= gsubs;
17318 X             if (z /16) b-= gsubs;
17319 X             if ((z /4) % 4) b -= gsubs;   
17320 X             b += wwt[aascii[aacmap[j]]];  /* add the match score for char j*/
17321 X             if (b > x) {
17322 X               x = b;          /* x has the score */
17323 X               y = j;          /* y has the character */
17324 X             }
17325 X         }
17326 X         /*      if (y < 0 || y > 63) printf("%d %d %d %d ",aa, i, x, y); */
17327 X         temp[aa][i] = x;
17328 X         le[aa][i] = y;
17329 X      }
17330 X      /*            printf("\n"); */
17331 X  }
17332 X
17333 X  for (aa= 0; aa <= naa; aa++) { 
17334 X      wwt = temp[aa];
17335 X      for (i = 0; i < 256; i++) {
17336 X          for (x=-100,b = 0; b < 4; b++) {
17337 X              z = (i/ (1 << ((b+1)*2)))*(1<<(b*2))+(i%(1<<(b*2)));
17338 X             if (x < (e=wwt[z])) {
17339 X                 x = e;
17340 X                 if (do_wgtc) weightc[aa][i].c4 = aacmap[le[aa][z]];
17341 X             }
17342 X          }
17343 X          weight[aa][i].iv=x-gshift;
17344 X          weight[aa][i].iii = wwt[i%64];
17345 X
17346 X         if (do_wgtc) {
17347 X           weightc[aa][i].c5 = aacmap[le[aa][i%64]];
17348 X           weightc[aa][i].c3 = aacmap[i%64];
17349 X         }
17350 X          x = i %16;
17351 X          for (y = -100, b = 0; b < 3; b++) {
17352 X              z = ((x >> (b*2)) << (b*2+2)) + (x % (1 << (b*2))); 
17353 X              for (a = 0; a < 4; a++) {
17354 X                 if ((e =wwt[z+(a<<(b*2))]) > y) {
17355 X                     y = e;
17356 X                     if (do_wgtc) 
17357 X                       weightc[aa][i].c2 = aacmap[le[aa][z+(a<<(b*2))]];
17358 X                 }
17359 X              }
17360 X          }
17361 X          weight[aa][i].ii = y-gshift;
17362 X      }
17363 X  }
17364 X  /*106=CGGG*/
17365 X  for (aa = 0; aa <= naa; aa++) {
17366 X    weight[aa][106].iii = wgts[aa][23]; /* is 23 the code for 'X'?*/
17367 X    weight[aa][106].iv = weight[aa][106].ii = weight[aa][106].iii-gshift;
17368 X    if (do_wgtc) {
17369 X      weightc[aa][106].c5 = weightc[aa][106].c4 = weightc[aa][106].c3
17370 X       = weightc[aa][106].c2 = 'X';
17371 X    }
17372 X  }
17373 }
17374 X
17375 void
17376 free_weights(struct wgt ***weighti0, struct wgt ***weighti1, 
17377 X            struct wgtc ***weightci, int naa)
17378 {
17379 X  int aa;
17380 X  struct wgt **weight0;
17381 X  struct wgt **weight1;
17382 X  struct wgtc **weightc;
17383 X
17384 X  weight0 = *weighti0;
17385 X  weight1 = *weighti1;
17386 X  weightc = *weightci;
17387 X
17388 X  for (aa=0; aa <= naa; aa++) {free(weight0[aa]);}
17389 X  for (aa=0; aa <= naa; aa++) {free(weight1[aa]);}
17390 X  for (aa=0; aa <= naa; aa++) {free(weightc[aa]);}
17391 X
17392 X  free(weight0);
17393 X  free(weight1);
17394 X  free(weightc);
17395 }
17396 X
17397 static void
17398 pre_com(const unsigned char *aa0, int n0, unsigned char *aa0v)
17399 {
17400 X  int dnav, i;
17401 X   dnav = (hnt[aa0[0]]<<2) + hnt[aa0[1]];
17402 X   for (i=2; i<n0; i++) {
17403 X     dnav = ((dnav<<2)+hnt[aa0[i]])&255;
17404 X     if (aa0[i] == NT_N  || aa0[i-1]==NT_N || aa0[i-2] == NT_N) 
17405 X       aa0v[i-2] = 106;
17406 X     else {
17407 X       if (dnav == 106/*CGGG*/) dnav = 42/*AGGG*/;
17408 X       aa0v[i-2]=dnav;
17409 X     }
17410 X   }
17411 }
17412 X
17413 static void
17414 pre_com_r(const unsigned char *aa0, int n0, unsigned char *aa0v)
17415 {
17416 X    int dnav, i, ir;
17417 X    dnav = (3-hnt[aa0[n0-1]]<<2) + 3-hnt[aa0[n0-2]];
17418 X    for (i=2, ir=n0-3; i<n0; i++,ir--) {
17419 X      dnav = ((dnav<<2)+3-hnt[aa0[ir]])&255; 
17420 X      if (aa0[ir] == NT_N || aa0[ir+1]==NT_N || aa0[ir+2] == NT_N) 
17421 X       aa0v[i-2] = 106;
17422 X      else {
17423 X       if (dnav == 106) dnav = 42;
17424 X       aa0v[i-2]=dnav;
17425 X      }
17426 X    }
17427 }
17428 X
17429 void
17430 init_work (unsigned char *aa0, int n0, 
17431 X          struct pstruct *ppst,
17432 X          struct f_struct **f_arg)
17433 {
17434 X   int mhv, phv;
17435 X   int hmax;
17436 X   int i0, hv;
17437 X   int pamfact;
17438 X   int btemp;
17439 X   struct f_struct *f_str;
17440 X   struct bdstr *bss;
17441 X   /* these used to be globals, but do not need to be */
17442 X   int ktup, fact, kt1, lkt;
17443 X
17444 X   int maxn0;
17445 X   int *pwaa;
17446 X   int i, j, q;
17447 X   struct swstr *ss, *r_ss;
17448 X   int *waa;
17449 X   int *res;
17450 X   int nsq, ip, *hsq, naat;
17451 #ifndef TFAST
17452 X   int last_n0, itemp, dnav;
17453 X   unsigned char *fd, *fs, *aa0x, *aa0v;
17454 X   int n0x, n0x3;
17455 #endif
17456 X
17457 X   if (nt[NT_N] != 'N') {
17458 X     fprintf(stderr," nt[NT_N] (%d) != 'X' (%c) - recompile\n",NT_N,nt[NT_N]);
17459 X     exit(1);
17460 X   }     
17461 X
17462 X  if (ppst->ext_sq_set) {
17463 X    nsq = ppst->nsqx; ip = 1;
17464 X    hsq = ppst->hsqx;
17465 X  }
17466 X  else {
17467 X    nsq = ppst->nsq; ip = 0;
17468 X    hsq = ppst->hsq;
17469 X  }
17470 X
17471 X   f_str = (struct f_struct *)calloc(1,sizeof(struct f_struct));
17472 X
17473 X   btemp = 2 * ppst->param_u.fa.bestoff / 3 +
17474 X      n0 / ppst->param_u.fa.bestscale +
17475 X      ppst->param_u.fa.bkfact *
17476 X      (ppst->param_u.fa.bktup - ppst->param_u.fa.ktup);
17477 X   btemp = min (btemp, ppst->param_u.fa.bestmax);
17478 X   if (btemp > 3 * n0) btemp = 3 * shscore(aa0,n0,ppst->pam2[0]) / 5;
17479 X
17480 X   ppst->param_u.fa.cgap = btemp + ppst->param_u.fa.bestoff / 3;
17481 X   if (ppst->param_u.fa.optcut_set != 1)
17482 #ifndef TFAST
17483 X      ppst->param_u.fa.optcut = (btemp*5)/4;
17484 #else
17485 X      ppst->param_u.fa.optcut = (btemp*4)/3;
17486 #endif
17487 X
17488 #ifdef OLD_FASTA_GAP
17489 X   ppst->param_u.fa.pgap = ppst->gdelval + ppst->ggapval;
17490 #else
17491 X   ppst->param_u.fa.pgap = ppst->gdelval + 2*ppst->ggapval;
17492 #endif
17493 X   pamfact = ppst->param_u.fa.pamfact;
17494 X   ktup = ppst->param_u.fa.ktup;
17495 X   fact = ppst->param_u.fa.scfact * ktup;
17496 X
17497 #ifndef TFAST
17498 X   /* before hashing, we must set up some space and translate the sequence */
17499 X
17500 X   maxn0 = n0 + 2;
17501 X   if ((aa0x =(unsigned char *)calloc((size_t)maxn0,
17502 X                                            sizeof(unsigned char)))
17503 X       == NULL) {
17504 X     fprintf (stderr, "cannot allocate aa0x array %d\n", maxn0);
17505 X     exit (1);
17506 X   }
17507 X   aa0x++;
17508 X   f_str->aa0x = aa0x;
17509 X
17510 X
17511 X   if ((aa0v =(unsigned char *)calloc((size_t)maxn0,
17512 X                                            sizeof(unsigned char)))
17513 X       == NULL) {
17514 X     fprintf (stderr, "cannot allocate aa0v array %d\n", maxn0);
17515 X     exit (1);
17516 X   }
17517 X   aa0v++;
17518 X   f_str->aa0v = aa0v;
17519 X
17520 X   /* make a precomputed codon number series */
17521 X   pre_com(aa0, n0, aa0v);
17522 X
17523 X   last_n0 = 0;
17524 X   for (itemp=0; itemp<3; itemp++) {
17525 X     n0x=saatran(aa0,&aa0x[last_n0],n0,itemp);
17526 X     /*         for (i=0; i<n0x; i++) {
17527 X          fprintf(stderr,"%c",aa[aa0x[last_n0+i]]);
17528 X          if ((i%60)==59) fprintf(stderr,"\n");
17529 X          }
17530 X          fprintf(stderr,"\n");
17531 X          */
17532 X     last_n0 += n0x+1;
17533 X   }
17534 X
17535 X   /*     fprintf(stderr,"\n"); */
17536 X   n0x = n0;
17537 X   n0x3 = n0x/3;
17538 X
17539 X   /* now switch aa0 and aa0x for hashing functions */
17540 X   fs = aa0;
17541 X   aa0 = aa0x;
17542 X   aa0x = fs;
17543 #endif
17544 X
17545 X   if (ppst->ext_sq_set) naat = MAXLC;
17546 X   else naat = MAXUC;
17547 X
17548 X   init_weights(&f_str->weight0, NULL,
17549 X               ppst->pam2[ip],-ppst->gshift,-ppst->gsubs,naat);
17550 X   init_weights(&f_str->weight1, &f_str->weight_c,
17551 X               ppst->pam2[0],-ppst->gshift,-ppst->gsubs,naat);
17552 X
17553 X   if (pamfact == -1)
17554 X      pamfact = 0;
17555 X   else if (pamfact == -2)
17556 X      pamfact = 1;
17557 X
17558 X   for (i0 = 1, mhv = -1; i0 <= ppst->nsq; i0++)
17559 X      if (hsq[i0] < NMAP && hsq[i0] > mhv)
17560 X        mhv = ppst->hsq[i0];
17561 X
17562 X   if (mhv <= 0)
17563 X   {
17564 X      fprintf (stderr, " maximum hsq <=0 %d\n", mhv);
17565 X      exit (1);
17566 X   }
17567 X
17568 X   for (f_str->kshft = 0; mhv > 0; mhv /= 2) f_str->kshft++;
17569 X
17570 /*      kshft = 2;      */
17571 X   kt1 = ktup - 1;
17572 X   hv = 1;
17573 X   for (i0 = 0; i0 < ktup; i0++)
17574 X      hv = hv << f_str->kshft;
17575 X   hmax = hv;
17576 X   f_str->hmask = (hmax >> f_str->kshft) - 1;
17577 X
17578 X   if ((f_str->harr = (int *) calloc (hmax, sizeof (int))) == NULL) {
17579 X     fprintf (stderr, " cannot allocate hash array\n");
17580 X     exit (1);
17581 X   }
17582 X   if ((f_str->pamh1 = (int *) calloc (ppst->nsq+1, sizeof (int))) == NULL) {
17583 X     fprintf (stderr, " cannot allocate pamh1 array\n");
17584 X     exit (1);
17585 X   }
17586 X   if ((f_str->pamh2 = (int *) calloc (hmax, sizeof (int))) == NULL) {
17587 X     fprintf (stderr, " cannot allocate pamh2 array\n");
17588 X     exit (1);
17589 X   }
17590 X   if ((f_str->link = (int *) calloc (n0, sizeof (int))) == NULL) {
17591 X     fprintf (stderr, " cannot allocate hash link array");
17592 X     exit (1);
17593 X   }
17594 X
17595 X   for (i0 = 0; i0 < hmax; i0++)
17596 X      f_str->harr[i0] = -1;
17597 X   for (i0 = 0; i0 < n0; i0++)
17598 X      f_str->link[i0] = -1;
17599 X
17600 X   /* encode the aa0 array */
17601 X   phv = hv = 0;
17602 X   lkt = kt1;
17603 X   for (i0 = 0; i0 < min(n0,lkt); i0++) {
17604 X     if (hsq[aa0[i0]] >= NMAP) {
17605 X       hv=phv=0; lkt = i0+ktup; continue;
17606 X     }
17607 X     hv = (hv << f_str->kshft) + ppst->hsq[aa0[i0]];
17608 X     phv += ppst->pam2[ip][aa0[i0]][aa0[i0]] * ktup;
17609 X   }
17610 X
17611 X   for (; i0 < n0; i0++) {
17612 X     if (hsq[aa0[i0]] >= NMAP) {
17613 X       hv=phv=0;
17614 X       /* restart hv, phv calculation */
17615 X       for (lkt = i0+kt1; (i0 < lkt || hsq[aa0[i0]]>=NMAP) && i0<n0; i0++) {
17616 X        if (hsq[aa0[i0]] >= NMAP) {
17617 X          hv=phv=0;
17618 X          lkt = i0+ktup;
17619 X          continue;
17620 X        }
17621 X        hv = (hv << f_str->kshft) + hsq[aa0[i0]];
17622 X        phv += ppst->pam2[ip][aa0[i0]][aa0[i0]]*ktup;
17623 X       }
17624 X     }
17625 X     if (i0 >= n0) break;
17626 X     hv = ((hv & f_str->hmask) << f_str->kshft) + ppst->hsq[aa0[i0]];
17627 X     f_str->link[i0] = f_str->harr[hv];
17628 X     f_str->harr[hv] = i0;
17629 X     if (pamfact) {
17630 X       f_str->pamh2[hv] = (phv += ppst->pam2[ip][aa0[i0]][aa0[i0]] * ktup);
17631 X       if (hsq[aa0[i0-kt1]] < NMAP) 
17632 X        phv -= ppst->pam2[ip][aa0[i0 - kt1]][aa0[i0 - kt1]] * ktup;
17633 X     }
17634 X     else f_str->pamh2[hv] = fact * ktup;
17635 X   }
17636 X
17637 /* this has been modified from 0..<ppst->nsq to 1..<=ppst->nsq because the
17638 X   pam2[0][0] is now undefined for consistency with blast
17639 */
17640 X
17641 X   if (pamfact)
17642 X      for (i0 = 1; i0 <= ppst->nsq; i0++)
17643 X        f_str->pamh1[i0] = ppst->pam2[ip][i0][i0] * ktup;
17644 X   else
17645 X      for (i0 = 1; i0 <= ppst->nsq; i0++)
17646 X        f_str->pamh1[i0] = fact;
17647 X
17648 X   f_str->ndo = 0;     /* used to save time on diagonals with long queries */
17649 X
17650 X
17651 #ifndef ALLOCN0
17652 X   if ((f_str->diag = (struct dstruct *) calloc ((size_t)MAXDIAG,
17653 X                                                sizeof (struct dstruct)))==NULL) {
17654 X      fprintf (stderr," cannot allocate diagonal arrays: %lu\n",
17655 X              MAXDIAG *sizeof (struct dstruct));
17656 X      exit (1);
17657 X     };
17658 #else
17659 X   if ((f_str->diag = (struct dstruct *) calloc ((size_t)n0,
17660 X                                             sizeof (struct dstruct)))==NULL) {
17661 X      fprintf (stderr," cannot allocate diagonal arrays: %ld\n",
17662 X             (long)n0*sizeof (struct dstruct));
17663 X      exit (1);
17664 X     };
17665 #endif
17666 X
17667 #ifndef TFAST
17668 X   /* done hashing, now switch aa0, aa0x back */
17669 X   fs = aa0;
17670 X   aa0 = aa0x;
17671 X   aa0x = fs;
17672 #else
17673 X   if ((f_str->aa1x =(unsigned char *)calloc((size_t)ppst->maxlen+4,
17674 X                                            sizeof(unsigned char)))
17675 X       == NULL) {
17676 X     fprintf (stderr, "cannot allocate aa1x array %d\n", ppst->maxlen+4);
17677 X     exit (1);
17678 X   }
17679 X   f_str->aa1x++;
17680 X
17681 X   if ((f_str->aa1v =(unsigned char *)calloc((size_t)ppst->maxlen+4,
17682 X                                            sizeof(unsigned char))) == NULL) {
17683 X     fprintf (stderr, "cannot allocate aa1v array %d\n", ppst->maxlen+4);
17684 X     exit (1);
17685 X   }
17686 X   f_str->aa1v++;
17687 X
17688 #endif
17689 X
17690 X   if ((waa= (int *)malloc (sizeof(int)*(ppst->nsq+1)*n0)) == NULL) {
17691 X     fprintf(stderr,"cannot allocate waa struct %3d\n",ppst->nsq*n0);
17692 X     exit(1);
17693 X   }
17694 X
17695 X   pwaa = waa;
17696 X   for (i=0; i<=ppst->nsq; i++) {
17697 X     for (j=0;j<n0; j++) {
17698 X       *pwaa = ppst->pam2[ip][i][aa0[j]];
17699 X       pwaa++;
17700 X     }
17701 X   }
17702 X   f_str->waa = waa;
17703 X
17704 #ifndef TFAST
17705 X   maxn0 = max(2*n0,MIN_RES);
17706 #else
17707 X   maxn0 = max(4*n0,MIN_RES);
17708 #endif
17709 X   if ((res = (int *)calloc((size_t)maxn0,sizeof(int)))==NULL) {
17710 X     fprintf(stderr,"cannot allocate alignment results array %d\n",maxn0);
17711 X     exit(1);
17712 X   }
17713 X   f_str->res = res;
17714 X   f_str->max_res = maxn0;
17715 X
17716 X   *f_arg = f_str;
17717 }
17718 X
17719 /* pstring1 is a message to the manager, currently 512 */
17720 /* pstring2 is the same information, but in a markx==10 format */
17721 void
17722 get_param (struct pstruct *pstr, char *pstring1, char *pstring2)
17723 {
17724 #ifndef TFAST
17725 X  char *pg_str="FASTY";
17726 #else
17727 X  char *pg_str="TFASTY";
17728 #endif
17729 X
17730 X   if (!pstr->param_u.fa.optflag)
17731 #ifdef OLD_FASTA_GAP
17732 X      sprintf (pstring1, "%s (%s) function [%s matrix (%d:%d)%s] ktup: %d\n join: %d, gap-pen: %d/%d, shift: %d subs: %d width: %3d",pg_str,verstr,
17733 #else
17734 X      sprintf (pstring1, "%s (%s) function [%s matrix (%d:%d)%s] ktup: %d\n join: %d, open/ext: %d/%d, shift: %d subs: %d width: %3d",pg_str,verstr,
17735 #endif
17736 X              pstr->pamfile, pstr->pam_h,pstr->pam_l, 
17737 X              (pstr->ext_sq_set) ? "xS":"\0",
17738 X              pstr->param_u.fa.ktup, pstr->param_u.fa.cgap,
17739 X              pstr->gdelval, pstr->ggapval, pstr->gshift, pstr->gsubs,
17740 X              pstr->param_u.fa.optwid);
17741 X   else
17742 #ifdef OLD_FASTA_GAP
17743 X      sprintf (pstring1, "%s (%s) function [optimized, %s matrix (%d:%d)%s] ktup: %d\n join: %d, opt: %d, gap-pen: %3d/%3d shift: %3d, subs: %3d width: %3d",pg_str,verstr,
17744 #else
17745 X      sprintf (pstring1, "%s (%s) function [optimized, %s matrix (%d:%d)%s] ktup: %d\n join: %d, opt: %d, open/ext: %3d/%3d shift: %3d, subs: %3d width: %3d",pg_str,verstr,
17746 #endif
17747 X              pstr->pamfile, pstr->pam_h,pstr->pam_l,
17748 X              (pstr->ext_sq_set) ? "xS":"\0",
17749 X              pstr->param_u.fa.ktup, pstr->param_u.fa.cgap,
17750 X              pstr->param_u.fa.optcut, pstr->gdelval, pstr->ggapval,
17751 X              pstr->gshift,pstr->gsubs,pstr->param_u.fa.optwid);
17752 X
17753 X   if (pstr->param_u.fa.iniflag) strcat(pstring1," init1");
17754 X   /*
17755 X   if (pstr->zsflag==0) strcat(pstring1," not-scaled");
17756 X   else if (pstr->zsflag==1) strcat(pstring1," reg.-scaled");
17757 X   */
17758 X
17759 X   if (pstring2 != NULL) {
17760 #ifdef OLD_FASTA_GAP
17761 X     sprintf (pstring2, "; pg_name: %s\n; pg_ver: %s\n; pg_matrix: %s (%d:%d)%s\n\
17762 ; pg_gap-pen: %d %d\n; pg_ktup: %d\n; pg_optcut: %d\n; pg_cgap: %d\n",
17763 #else
17764 X     sprintf (pstring2, "; pg_name: %s\n; pg_ver: %s\n; pg_matrix: %s (%d:%d)%s\n\
17765 ; pg_open-ext: %d %d\n; pg_ktup: %d\n; pg_optcut: %d\n; pg_cgap: %d\n",
17766 #endif
17767 X             pg_str,verstr,pstr->pamfile, pstr->pam_h,pstr->pam_l,
17768 X             (pstr->ext_sq_set) ? "xS":"\0",  pstr->gdelval,
17769 X              pstr->ggapval,pstr->param_u.fa.ktup,pstr->param_u.fa.optcut,
17770 X             pstr->param_u.fa.cgap);
17771 X   }
17772 }
17773 X
17774 void
17775 close_work (const unsigned char *aa0, int n0,
17776 X           struct pstruct *ppst,
17777 X           struct f_struct **f_arg)
17778 {
17779 X  struct f_struct *f_str;
17780 X  int naat;
17781 X
17782 X  f_str = *f_arg;
17783 X
17784 X  if (f_str != NULL) {
17785 X   if (ppst->ext_sq_set) naat = MAXLC;
17786 X   else naat = MAXUC;
17787 X    free_weights(&f_str->weight0,&f_str->weight1,&f_str->weight_c,naat);
17788 X    free(f_str->cur);
17789 #ifndef TFAST
17790 X    f_str->aa0v--;
17791 X    free(f_str->aa0v);
17792 X    f_str->aa0x--;
17793 X    free(f_str->aa0x);
17794 #else   /* TFAST */
17795 X    f_str->aa1x--;
17796 X    free(f_str->aa1x);
17797 X    f_str->aa1v--;
17798 X    free(f_str->aa1v);
17799 #endif
17800 X    free(f_str->res);
17801 X    free(f_str->waa);
17802 X    free(f_str->diag);
17803 X    free(f_str->link);
17804 X    free(f_str->pamh2); 
17805 X    free(f_str->pamh1);
17806 X    free(f_str->harr);
17807 X    free(f_str);
17808 X    *f_arg = NULL;
17809 X  }
17810 }
17811 X
17812 void do_fasta (const unsigned char *aa0, int n0,
17813 X              const unsigned char *aa1, int n1,
17814 X              struct pstruct *ppst, struct f_struct *f_str,
17815 X              struct rstruct *rst, int *hoff)
17816 {
17817 X   int     nd;         /* diagonal array size */
17818 X   int     lhval;
17819 X   int     kfact;
17820 X   int i;
17821 X   register struct dstruct *dptr;
17822 X   register int tscor;
17823 X   int xdebug = 0;
17824 X
17825 #ifndef ALLOCN0
17826 X   register struct dstruct *diagp;
17827 #else
17828 X   register int dpos;
17829 X   int     lposn0;
17830 #endif
17831 X   struct dstruct *dpmax;
17832 X   register int lpos;
17833 X   int     tpos;
17834 X   struct savestr *vmptr;
17835 X   int     scor, tmp;
17836 X   int     im, ib, nsave;
17837 X   int ktup, kt1, *hsq, ip, lkt;
17838 #ifndef TFAST
17839 X   int n0x31, n0x32;
17840 X   n0x31 = (n0-2)/3;
17841 X   n0x32 = n0x31+1+(n0-n0x31-1)/2;
17842 #else
17843 X   unsigned char *fs, *fd;
17844 X   int n1x31, n1x32, last_n1, itemp;
17845 X   n1x31 = (n1-2)/3;
17846 X   n1x32 = n1x31+1+(n1-n1x31-1)/2;
17847 #endif
17848 X
17849 X  if (ppst->ext_sq_set) {
17850 X    ip = 1;
17851 X    hsq = ppst->hsqx;
17852 X  }
17853 X  else {
17854 X    ip = 0;
17855 X    hsq = ppst->hsq;
17856 X  }
17857 X
17858 X   ktup = ppst->param_u.fa.ktup;
17859 X   kt1 = ktup-1;
17860 X
17861 X   if (n1 < ktup) {
17862 X     rst->score[0] = rst->score[1] = rst->score[2] = 0;
17863 X     return;
17864 X   }
17865 X
17866 X   if (n0+n1+1 >= MAXDIAG) {
17867 X     fprintf(stderr,"n0,n1 too large: %d, %d\n",n0,n1);
17868 X     rst->score[0] = rst->score[1] = rst->score[2] = -1;
17869 X     return;
17870 X   }
17871 X
17872 X   f_str->noff = n0 - 1;
17873 X
17874 #ifdef ALLOCN0
17875 X   nd = n0;
17876 #endif
17877 X
17878 #ifndef ALLOCN0
17879 X   nd = n0 + n1;
17880 #endif
17881 X
17882 X   dpmax = &f_str->diag[nd];
17883 X   for (dptr = &f_str->diag[f_str->ndo]; dptr < dpmax;)
17884 X   {
17885 X      dptr->stop = -1;
17886 X      dptr->dmax = NULL;
17887 X      dptr++->score = 0;
17888 X   }
17889 X
17890 X   for (vmptr = f_str->vmax; vmptr < &f_str->vmax[MAXSAV]; vmptr++)
17891 X      vmptr->score = 0;
17892 X   f_str->lowmax = f_str->vmax;
17893 X   f_str->lowscor = 0;
17894 X
17895 X  if (n1 > 1000 && aa1[0]==23 && aa1[100]==23 &&
17896 X      aa1[1400]==23 && aa1[1401]!=23) {
17897 X    xdebug = 1;
17898 X  }
17899 X  else xdebug = 0;
17900 X
17901 X   /* start hashing */
17902 X   lhval = 0;
17903 X   lkt = kt1;
17904 X   for (lpos = 0; (lpos < lkt || hsq[aa1[lpos]]>=NMAP) && lpos<n1; lpos++) {
17905 X     /* restart lhval calculation */
17906 X     if (hsq[aa1[lpos]]>=NMAP) {
17907 X       lhval = 0; lkt=lpos+ktup;
17908 X       continue;
17909 X     }
17910 X     lhval = ((lhval & f_str->hmask) << f_str->kshft) + ppst->hsq[aa1[lpos]];
17911 X   }
17912 X
17913 #ifndef ALLOCN0
17914 X   diagp = &f_str->diag[f_str->noff + lkt];
17915 X   for (; lpos < n1; lpos++, diagp++) {
17916 X     if (hsq[aa1[lpos]]>=NMAP) {
17917 X       lpos++ ; diagp++;
17918 X       while (lpos < n1 && hsq[aa1[lpos]]>=NMAP) {lpos++; diagp++;}
17919 X       if (lpos >= n1) break;
17920 X       lhval = 0;
17921 X     }
17922 X     lhval = ((lhval & f_str->hmask) << f_str->kshft) + ppst->hsq[aa1[lpos]];
17923 X     for (tpos = f_str->harr[lhval]; tpos >= 0; tpos = f_str->link[tpos]) {
17924 X       if ((tscor = (dptr = &diagp[-tpos])->stop) >= 0) {
17925 #else
17926 X   lposn0 = f_str->noff + lpos;
17927 X   for (; lpos < n1; lpos++, lposn0++) {
17928 X     if (hsq[aa1[lpos]]>=NMAP) {lhval = 0; goto loopl;}
17929 X     lhval = ((lhval & f_str->hmask) << f_str->kshft) + ppst->hsq[aa1[lpos]];
17930 X     for (tpos = f_str->harr[lhval]; tpos >= 0; tpos = f_str->link[tpos]) {
17931 X       dpos = lposn0 - tpos;
17932 X       if ((tscor = (dptr = &f_str->diag[dpos % nd])->stop) >= 0) {
17933 #endif
17934 X        tscor += ktup;
17935 X        if ((tscor -= lpos) <= 0) {
17936 X          scor = dptr->score;
17937 X          if ((tscor += (kfact = f_str->pamh2[lhval])) < 0 && f_str->lowscor < scor)
17938 #ifdef ALLOCN0
17939 X            savemax (dptr, dpos, f_str);
17940 #else
17941 X            savemax (dptr, f_str);
17942 #endif
17943 X            if ((tscor += scor) >= kfact) {
17944 X              dptr->score = tscor;
17945 X              dptr->stop = lpos;
17946 X            }
17947 X            else {
17948 X              dptr->score = kfact;
17949 X              dptr->start = (dptr->stop = lpos) - kt1;
17950 X            }
17951 X        }
17952 X        else {
17953 X          dptr->score += f_str->pamh1[aa0[tpos]];
17954 X          dptr->stop = lpos;
17955 X        }
17956 X       }
17957 X       else {
17958 X        dptr->score = f_str->pamh2[lhval];
17959 X        dptr->start = (dptr->stop = lpos) - kt1;
17960 X       }
17961 X     }                         /* end tpos */
17962 X
17963 #ifdef ALLOCN0
17964 X      /* reinitialize diag structure */
17965 X   loopl:
17966 X     if ((dptr = &f_str->diag[lpos % nd])->score > f_str->lowscor)
17967 X       savemax (dptr, lpos, f_str);
17968 X     dptr->stop = -1;
17969 X     dptr->dmax = NULL;
17970 X     dptr->score = 0;
17971 #endif
17972 X   }   /* end lpos */
17973 X
17974 #ifdef ALLOCN0
17975 X   for (tpos = 0, dpos = f_str->noff + n1 - 1; tpos < n0; tpos++, dpos--) {
17976 X     if ((dptr = &f_str->diag[dpos % nd])->score > f_str->lowscor)
17977 X       savemax (dptr, dpos, f_str);
17978 X   }
17979 #else
17980 X   for (dptr = f_str->diag; dptr < dpmax;) {
17981 X     if (dptr->score > f_str->lowscor) savemax (dptr, f_str);
17982 X     dptr->stop = -1;
17983 X     dptr->dmax = NULL;
17984 X     dptr++->score = 0;
17985 X   }
17986 X   f_str->ndo = nd;
17987 #endif
17988 X
17989 /*
17990 X        at this point all of the elements of aa1[lpos]
17991 X        have been searched for elements of aa0[tpos]
17992 X        with the results in diag[dpos]
17993 */
17994 X   /*
17995 X   if (xdebug) 
17996 X     fprintf(stderr,"n0: %d; noff: %d; n1: %d; n1x31: %d n1x32 %d\n",
17997 X            n0, f_str->noff,n1,n1x31,n1x32);
17998 X   */
17999 X
18000 X   for (nsave = 0, vmptr = f_str->vmax; vmptr < &f_str->vmax[MAXSAV]; vmptr++)
18001 X   {
18002 X     /*
18003 X     if (xdebug) 
18004 X       fprintf(stderr,"0: %4d-%4d  1: %4d-%4d  dp: %d score: %d\n",
18005 X            f_str->noff+vmptr->start-vmptr->dp,
18006 X            f_str->noff+vmptr->stop-vmptr->dp,
18007 X            vmptr->start,vmptr->stop,
18008 X            vmptr->dp,vmptr->score);
18009 X     */
18010 X     if (vmptr->score > 0) {
18011 X       vmptr->score = spam (aa0, aa1, vmptr, ppst->pam2[0], f_str);
18012 X       f_str->vptr[nsave++] = vmptr;
18013 X     }
18014 X   }
18015 X
18016 X   if (nsave <= 0) {
18017 X     rst->score[0] = rst->score[1] = rst->score[2] = 0;
18018 X     return;
18019 X   }
18020 X       
18021 #ifndef TFAST
18022 X   /* FASTX code here to modify the start, stop points for 
18023 X      the three phases of the translated protein sequence
18024 X      */
18025 X
18026 X   /*
18027 X     fprintf(stderr,"n0x: %d; n0x31:%d; n0x32: %d\n",n0,n0x31,n0x32);
18028 X     for (ib=0; ib<nsave; ib++) {
18029 X       fprintf(stderr,"0: %4d-%4d  1: %4d-%4d  dp: %d score: %d\n",
18030 X              f_str->noff+f_str->vptr[ib]->start-f_str->vptr[ib]->dp,
18031 X              f_str->noff+f_str->vptr[ib]->stop-f_str->vptr[ib]->dp,
18032 X              f_str->vptr[ib]->start,f_str->vptr[ib]->stop,
18033 X              f_str->vptr[ib]->dp,f_str->vptr[ib]->score);
18034 X     }
18035 X
18036 X     fprintf(stderr,"---\n");
18037 X     */
18038 X
18039 X   for (ib=0; ib<nsave; ib++) {
18040 X     if (f_str->noff-f_str->vptr[ib]->dp+f_str->vptr[ib]->start >= n0x32)
18041 X       f_str->vptr[ib]->dp += n0x32;
18042 X     if (f_str->noff-f_str->vptr[ib]->dp +f_str->vptr[ib]->start >= n0x31)
18043 X       f_str->vptr[ib]->dp += n0x31;
18044 X   }
18045 X           
18046 X   /*
18047 X     for (ib=0; ib<nsave; ib++) {
18048 X       fprintf(stderr,"0: %4d-%4d  1: %4d-%4d  dp: %d score: %d\n",
18049 X              f_str->noff+f_str->vptr[ib]->start-f_str->vptr[ib]->dp,
18050 X              f_str->noff+f_str->vptr[ib]->stop-f_str->vptr[ib]->dp,
18051 X              f_str->vptr[ib]->start,f_str->vptr[ib]->stop,
18052 X              f_str->vptr[ib]->dp,f_str->vptr[ib]->score);
18053 X     }
18054 X     */
18055 #else
18056 X   /* TFAST code here to modify the start, stop points for 
18057 X            the three phases of the translated protein sequence
18058 X            TFAST modifies library start points, rather than 
18059 X            query start points
18060 X            */
18061 X
18062 X     /*
18063 X   fprintf(stderr,"n0: %d; noff: %d; n1: %d; n1x31: %d n1x32 %d\n",n0, f_str->noff,n1,n1x31,n1x32);
18064 X   for (ib=0; ib<nsave; ib++) {
18065 X     fprintf(stderr,"0: %4d-%4d  1: %4d-%4d  dp: %d score: %d\n",
18066 X            f_str->noff+f_str->vptr[ib]->start-f_str->vptr[ib]->dp,
18067 X            f_str->noff+f_str->vptr[ib]->stop-f_str->vptr[ib]->dp,
18068 X            f_str->vptr[ib]->start,f_str->vptr[ib]->stop,
18069 X            f_str->vptr[ib]->dp,f_str->vptr[ib]->score);
18070 X   }
18071 X
18072 X   fprintf(stderr,"---\n");
18073 X   */
18074 X
18075 X   for (ib=0; ib<nsave; ib++) {
18076 X     if (f_str->vptr[ib]->start >= n1x32) {
18077 X       f_str->vptr[ib]->start -= n1x32;
18078 X       f_str->vptr[ib]->stop -= n1x32;
18079 X       f_str->vptr[ib]->dp -= n1x32;
18080 X     }
18081 X     if (f_str->vptr[ib]->start >= n1x31) {
18082 X       f_str->vptr[ib]->start -= n1x31;
18083 X       f_str->vptr[ib]->stop -= n1x31;
18084 X       f_str->vptr[ib]->dp -= n1x31;
18085 X     }
18086 X   }
18087 X           
18088 X   /*
18089 X   for (ib=0; ib<nsave; ib++) {
18090 X     fprintf(stderr,"0: %4d-%4d  1: %4d-%4d  dp: %d score: %d\n",
18091 X            f_str->noff+f_str->vptr[ib]->start-f_str->vptr[ib]->dp,
18092 X            f_str->noff+f_str->vptr[ib]->stop-f_str->vptr[ib]->dp,
18093 X            f_str->vptr[ib]->start,f_str->vptr[ib]->stop,
18094 X            f_str->vptr[ib]->dp,f_str->vptr[ib]->score);
18095 X   }
18096 X   */
18097 X
18098 #endif /* TFAST */
18099 X
18100 X   scor = sconn (f_str->vptr, nsave, ppst->param_u.fa.cgap, 
18101 X                ppst->param_u.fa.pgap, f_str);
18102 X
18103 X   for (vmptr=f_str->vptr[0],ib=1; ib<nsave; ib++)
18104 X     if (f_str->vptr[ib]->score > vmptr->score) vmptr=f_str->vptr[ib];
18105 X
18106 /*  kssort (f_str->vptr, nsave); */
18107 X
18108 X   rst->score[1] = vmptr->score;
18109 X   rst->score[0] = max (scor, vmptr->score);
18110 X   rst->score[2] = rst->score[0];              /* initn */
18111 X
18112 X   if (ppst->param_u.fa.optflag) {
18113 X     if (rst->score[0] > ppst->param_u.fa.optcut) {
18114 #ifndef TFAST
18115 X       rst->score[2] = dmatchx(aa0, n0,aa1,n1,*hoff=f_str->noff - vmptr->dp,
18116 X                            ppst->param_u.fa.optwid, ppst->pam2[0],
18117 X                            ppst->gdelval,ppst->ggapval,ppst->gshift,f_str);
18118 #else /* TFAST */
18119 X     /* generate f_str->aa1x */
18120 /*
18121 X     for (i=0; i<n1; i++) {
18122 X       fputc(ppst->sq[aa1[i]],stderr);
18123 X       if (i%60==59) fputc('\n',stderr);
18124 X     }
18125 X     fprintf(stderr,"\n-----\n");
18126 */
18127 /*
18128 X     fprintf(stderr,"n1: %d, aa1x[n1]: %d; EOSEQ: %d\n",
18129 X            n1,f_str->aa1x[n1],EOSEQ);
18130 X     for (fs=aa1,itemp=0; itemp <3; itemp++,fs++) {
18131 X       for (fd= &f_str->aa1x[itemp]; *fs!=EOSEQ; fd += 3, fs++) *fd = *fs;
18132 X       fprintf(stderr,"fs stopped at: %d\n",(int)(fs-f_str->aa1x));
18133 X       *fd=EOSEQ;
18134 X     }
18135 */
18136 /*
18137 X     for (i=0; i<n1; i++) {
18138 X       fputc(ppst->sq[f_str->aa1x[i]],stderr);
18139 X       if (i%60==59) fputc('\n',stderr);
18140 X     }
18141 */
18142 X     rst->score[2] = dmatchx(aa0, n0, aa1, n1, *hoff=vmptr->dp-f_str->noff,
18143 X                            ppst->param_u.fa.optwid, ppst->pam2[0],
18144 X                            ppst->gdelval,ppst->ggapval,ppst->gshift,f_str);
18145 #endif /* TFAST */
18146 X     }
18147 X   }
18148 }
18149 X
18150 void do_work (const unsigned char *aa0, int n0,
18151 X             const unsigned char *aa1, int n1,
18152 X             int frame,
18153 X             struct pstruct *ppst,
18154 X             struct f_struct *f_str,
18155 X             int qr_flg, struct rstruct *rst)
18156 {
18157 X  int hoff;
18158 X  int last_n1, itx, dnav, n10, i, ir;
18159 X  unsigned char *aa1x;
18160 X
18161 X  rst->escore = 1.0;
18162 X  rst->segnum = rst->seglen = 1;
18163 X
18164 X  if (n1 < ppst->param_u.fa.ktup) {
18165 X    rst->score[0] = rst->score[1] = rst->score[2] = 0;
18166 X    return;
18167 X  }
18168 X
18169 #ifndef TFAST
18170 X  do_fasta (f_str->aa0x, n0, aa1, n1, ppst, f_str, rst, &hoff);
18171 #else
18172 X   /* make a precomputed codon number series */
18173 X
18174 X  if (frame == 0) {
18175 X    pre_com(aa1, n1, f_str->aa1v);
18176 X  }
18177 X  else {
18178 X    pre_com_r(aa1, n1, f_str->aa1v);
18179 X  }
18180 X
18181 X  /* make translated sequence */
18182 X  last_n1 = 0;
18183 X  aa1x = f_str->aa1x;
18184 X  for (itx= frame*3; itx< frame*3+3; itx++) {
18185 X    n10  = saatran(aa1,&aa1x[last_n1],n1,itx);
18186 X    /*
18187 X    fprintf(stderr," itt %d frame: %d\n",itx,frame);
18188 X    for (i=0; i<n10; i++) {
18189 X      fprintf(stderr,"%c",aa[f_str->aa1x[last_n1+i]]);
18190 X      if ((i%60)==59) fprintf(stderr,"\n");
18191 X    }
18192 X    fprintf(stderr,"\n");
18193 X
18194 X    fprintf(stderr,"n10: %d aa1x[] %d last_n1: %d\n",n10,aa1x[last_n1+n10],
18195 X           last_n1);
18196 X    */
18197 X    last_n1 += n10+1;
18198 X  }
18199 X  n10 = last_n1-1;
18200 X
18201 X  do_fasta (aa0, n0, f_str->aa1x, n10, ppst, f_str, rst, &hoff);
18202 #endif
18203 }
18204 X
18205 void do_opt (const unsigned char *aa0, int n0,
18206 X            const unsigned char *aa1, int n1,
18207 X            int frame,
18208 X            struct pstruct *ppst,
18209 X            struct f_struct *f_str,
18210 X            struct rstruct *rst)
18211 {
18212 X  int optflag, tscore, hoff;
18213 X
18214 X  optflag = ppst->param_u.fa.optflag;
18215 X  ppst->param_u.fa.optflag = 1;
18216 X
18217 #ifndef TFAST
18218 X  do_fasta (f_str->aa0x, n0, aa1, n1, ppst, f_str, rst, &hoff);
18219 #else
18220 X  do_fasta (aa0, n0, aa1, n1, ppst, f_str, rst, &hoff);
18221 #endif
18222 X
18223 X  ppst->param_u.fa.optflag = optflag;
18224 }
18225 X
18226 #ifdef ALLOCN0
18227 void
18228 savemax (dptr, dpos, f_str)
18229 X  register struct dstruct *dptr;
18230 X  int  dpos;
18231 X  struct f_struct *f_str;
18232 {
18233 X   register struct savestr *vmptr;
18234 X   register int i;
18235 X
18236 #else
18237 void
18238 savemax (dptr, f_str)
18239 X  register struct dstruct *dptr;
18240 X  struct f_struct *f_str;
18241 {
18242 X   register int dpos;
18243 X   register struct savestr *vmptr;
18244 X   register int i;
18245 X
18246 X   dpos = (int) (dptr - f_str->diag);
18247 X
18248 #endif
18249 X
18250 /* check to see if this is the continuation of a run that is already saved */
18251 X
18252 X   if ((vmptr = dptr->dmax) != NULL && vmptr->dp == dpos &&
18253 X        vmptr->start == dptr->start)
18254 X   {
18255 X      vmptr->stop = dptr->stop;
18256 X      if ((i = dptr->score) <= vmptr->score)
18257 X        return;
18258 X      vmptr->score = i;
18259 X      if (vmptr != f_str->lowmax)
18260 X        return;
18261 X   }
18262 X   else
18263 X   {
18264 X      i = f_str->lowmax->score = dptr->score;
18265 X      f_str->lowmax->dp = dpos;
18266 X      f_str->lowmax->start = dptr->start;
18267 X      f_str->lowmax->stop = dptr->stop;
18268 X      dptr->dmax = f_str->lowmax;
18269 X   }
18270 X
18271 X   for (vmptr = f_str->vmax; vmptr < &f_str->vmax[MAXSAV]; vmptr++)
18272 X      if (vmptr->score < i)
18273 X      {
18274 X        i = vmptr->score;
18275 X        f_str->lowmax = vmptr;
18276 X      }
18277 X   f_str->lowscor = i;
18278 }
18279 X
18280 int spam (const unsigned char *aa0,
18281 X         const unsigned char *aa1,
18282 X         struct savestr *dmax, int **pam2,
18283 X         struct f_struct *f_str)
18284 {
18285 X   int     lpos;
18286 X   int     tot, mtot;
18287 X   struct {
18288 X     int     start, stop, score;
18289 X   } curv, maxv;
18290 X   const unsigned char *aa0p, *aa1p;
18291 X
18292 X   aa1p = &aa1[lpos = dmax->start];
18293 X   aa0p = &aa0[lpos - dmax->dp + f_str->noff];
18294 X   curv.start = lpos;
18295 X
18296 X   tot = curv.score = maxv.score = 0;
18297 X   for (; lpos <= dmax->stop; lpos++) {
18298 X     tot += pam2[*aa0p++][*aa1p++];
18299 X     if (tot > curv.score) {
18300 X       curv.stop = lpos;
18301 X       curv.score = tot;
18302 X      }
18303 X      else if (tot < 0) {
18304 X       if (curv.score > maxv.score) {
18305 X         maxv.start = curv.start;
18306 X         maxv.stop = curv.stop;
18307 X         maxv.score = curv.score;
18308 X       }
18309 X       tot = curv.score = 0;
18310 X       curv.start = lpos+1;
18311 X      }
18312 X   }
18313 X
18314 X   if (curv.score > maxv.score) {
18315 X     maxv.start = curv.start;
18316 X     maxv.stop = curv.stop;
18317 X     maxv.score = curv.score;
18318 X   }
18319 X
18320 /*      if (maxv.start != dmax->start || maxv.stop != dmax->stop)
18321 X               printf(" new region: %3d %3d %3d %3d\n",maxv.start,
18322 X                       dmax->start,maxv.stop,dmax->stop);
18323 */
18324 X   dmax->start = maxv.start;
18325 X   dmax->stop = maxv.stop;
18326 X
18327 X   return maxv.score;
18328 }
18329 X
18330 #define XFACT 10
18331 X
18332 int sconn (struct savestr **v, int n, 
18333 X       int cgap, int pgap, struct f_struct *f_str)
18334 {
18335 X  int     i, si;
18336 X  struct slink {
18337 X    int     score;
18338 X    struct savestr *vp;
18339 X    struct slink *next;
18340 X  }      *start, *sl, *sj, *so, sarr[MAXSAV];
18341 X  int     lstart, tstart, plstop, ptstop;
18342 X
18343 /*      sort the score left to right in lib pos */
18344 X
18345 X   kpsort (v, n);
18346 X
18347 X   start = NULL;
18348 X
18349 /*      for the remaining runs, see if they fit */
18350 X
18351 X   for (i = 0, si = 0; i < n; i++)
18352 X   {
18353 X
18354 /*      if the score is less than the gap penalty, it never helps */
18355 X      if (v[i]->score < cgap)
18356 X        continue;
18357 X      lstart = v[i]->start;
18358 X      tstart = lstart - v[i]->dp + f_str->noff;
18359 X
18360 /*      put the run in the group */
18361 X      sarr[si].vp = v[i];
18362 X      sarr[si].score = v[i]->score;
18363 X      sarr[si].next = NULL;
18364 X
18365 /*      if it fits, then increase the score */
18366 X      for (sl = start; sl != NULL; sl = sl->next)
18367 X      {
18368 X        plstop = sl->vp->stop;
18369 X        ptstop = plstop - sl->vp->dp + f_str->noff;
18370 X        if (plstop < lstart+XFACT && ptstop < tstart+XFACT) {
18371 X          sarr[si].score = sl->score + v[i]->score + pgap;
18372 X          break;
18373 X        }
18374 X      }
18375 X
18376 /*      now recalculate where the score fits */
18377 X      if (start == NULL)
18378 X        start = &sarr[si];
18379 X      else
18380 X        for (sj = start, so = NULL; sj != NULL; sj = sj->next)
18381 X        {
18382 X           if (sarr[si].score > sj->score)
18383 X           {
18384 X              sarr[si].next = sj;
18385 X              if (so != NULL)
18386 X                 so->next = &sarr[si];
18387 X              else
18388 X                 start = &sarr[si];
18389 X              break;
18390 X           }
18391 X           so = sj;
18392 X        }
18393 X      si++;
18394 X   }
18395 X
18396 X   if (start != NULL)
18397 X      return (start->score);
18398 X   else
18399 X      return (0);
18400 }
18401 X
18402 void
18403 kssort (v, n)
18404 struct savestr *v[];
18405 int     n;
18406 {
18407 X   int     gap, i, j;
18408 X   struct savestr *tmp;
18409 X
18410 X   for (gap = n / 2; gap > 0; gap /= 2)
18411 X      for (i = gap; i < n; i++)
18412 X        for (j = i - gap; j >= 0; j -= gap)
18413 X        {
18414 X           if (v[j]->score >= v[j + gap]->score)
18415 X              break;
18416 X           tmp = v[j];
18417 X           v[j] = v[j + gap];
18418 X           v[j + gap] = tmp;
18419 X        }
18420 }
18421 X
18422 void
18423 kpsort (v, n)
18424 struct savestr *v[];
18425 int     n;
18426 {
18427 X   int     gap, i, j;
18428 X   struct savestr *tmp;
18429 X
18430 X   for (gap = n / 2; gap > 0; gap /= 2)
18431 X      for (i = gap; i < n; i++)
18432 X        for (j = i - gap; j >= 0; j -= gap)
18433 X        {
18434 X           if (v[j]->start <= v[j + gap]->start)
18435 X              break;
18436 X           tmp = v[j];
18437 X           v[j] = v[j + gap];
18438 X           v[j + gap] = tmp;
18439 X        }
18440 }
18441 X
18442 static int
18443 dmatchx(const unsigned char *aa0, int n0,
18444 X       const unsigned char *aa1, int n1,
18445 X       int hoff, int window, 
18446 X       int **pam2, int gdelval, int ggapval, int gshift,
18447 X       struct f_struct *f_str)
18448 {
18449 X
18450 X   hoff -= window/2;
18451 X
18452 #ifndef TFAST
18453 X   return lx_band(aa1,n1,f_str->aa0v,n0-2, 
18454 X                 pam2,
18455 #ifdef OLD_FASTA_GAP
18456 X                 -(gdelval - ggapval),
18457 #else
18458 X                 -gdelval,
18459 #endif
18460 X                 -ggapval,-gshift,
18461 X                 hoff,window,f_str);
18462 #else
18463 X   return lx_band(aa0,n0,f_str->aa1v,n1-2, 
18464 X                 pam2,
18465 #ifdef OLD_FASTA_GAP
18466 X                 -(gdelval - ggapval),
18467 #else
18468 X                 -gdelval,
18469 #endif
18470 X                 -ggapval,-gshift,
18471 X                 hoff,window,f_str);
18472 #endif
18473 }
18474 X
18475 static void
18476 init_row(struct sx_s *row, int sp) {
18477 X  int i;
18478 X  for (i = 0; i < sp; i++) {
18479 X      row[i].C1 = row[i].I1 = 0;
18480 X      row[i].C2 = row[i].I2 = 0;
18481 X      row[i].C3 = row[i].I3 = 0;
18482 X      row[i].flag = 0;
18483 X  }
18484 }
18485 X
18486 int lx_band(const unsigned char *prot_seq,  /* array with protein sequence numbers*/
18487 X           int len_prot,    /* length of prot. seq */
18488 X           const unsigned char *dna_prot_seq, /* translated DNA sequence numbers*/
18489 X           int len_dna_prot,   /* length trans. seq. */
18490 X           int **pam_matrix,   /* scoring matrix */
18491 X           int gopen, int gext, /* gap open, gap extend penalties */
18492 X           int gshift,         /* frame-shift penalty */
18493 X           int start_diag,     /* start diagonal of band */
18494 X           int width,         /* width for band alignment */
18495 X           struct f_struct *f_str)
18496 {
18497 X  void *ckalloc();
18498 X  int i, j, bd, bd1, x1, x2, sp, p1=0, p2=0, end_prot;
18499 X  struct sx_s *last, *tmp;
18500 X  int sc, del, best = 0, cd,ci, e1, e2, e3, cd1, cd2, cd3, f, gg;
18501 X  const unsigned char *dp;
18502 X  register struct sx_s *ap, *aq;
18503 X  struct wgt *wt, *ww;
18504 X  int aa, b, a,x,y,z;
18505 X
18506 X  sp = width+7;
18507 X  gg = gopen+gext;
18508 X  /* sp = sp/3+1; */
18509 X
18510 X  if (f_str->cur == NULL) {
18511 X    f_str->cur = (struct sx_s *) ckalloc(sizeof(struct sx_s)*sp);
18512 X  }
18513 X
18514 X  init_row(f_str->cur, sp);
18515 X
18516 X  /*
18517 X  if (start_diag %3 !=0) start_diag = start_diag/3-1;
18518 X  else start_diag = start_diag/3;
18519 X  if (width % 3 != 0) width = width/3+1;
18520 X  else width = width /3;
18521 X  */
18522 X
18523 X  x1 = start_diag;             /* x1 = lower bound of DNA */
18524 X  x2 = 1;               /* the amount of position shift from last row*/
18525 X
18526 X  end_prot = max(0,-width-start_diag) + (len_dna_prot+5)/3 + width;
18527 X  end_prot = min(end_prot,len_prot);
18528 X
18529 X  /* i counts through protein sequence, x1 through DNAp */
18530 X
18531 X  for (i = max(0, -width-start_diag), x1+=i; i < len_prot; i++, x1++) {
18532 X      bd = min(x1+width, (len_dna_prot+2)/3);  /* upper bound of band */
18533 X      bd1 = max(0,x1);                 /* lower bound of band */
18534 X      wt = f_str->weight0[prot_seq[i]];
18535 X      del = 1-x1;   /*adjustment*/
18536 X      bd += del; 
18537 X      bd1 +=del;
18538 X
18539 X      ap = &f_str->cur[bd1]; aq = ap+1;
18540 X      e1 = f_str->cur[bd1-1].C3; e2 = ap->C1; cd1 = cd2= cd3= 0;
18541 X      for (dp = &dna_prot_seq[(bd1-del)*3]; ap < &f_str->cur[bd]; ap++) {
18542 X         ww = &wt[(unsigned char) *dp++];
18543 X         sc = max(max(e1+ww->iv, (e3=ap->C2)+ww->ii), e2+ww->iii);
18544 X         if (cd1 > sc) sc = cd1;
18545 X         cd1 -= gext;
18546 X         if ((ci = aq->I1) > 0) {
18547 X             if (sc < ci) { ap->C1 = ci; ap->I1 = ci-gext;}
18548 X             else {
18549 X                 ap->C1 = sc;
18550 X                 sc -= gg;
18551 X                 if (sc > 0) {
18552 X                     if (sc > best) best =sc;
18553 X                     if (cd1 < sc) cd1 = sc;
18554 X                     ap->I1 = max(ci-gext, sc);
18555 X                 } else ap->I1 = ci-gext;
18556 X             }
18557 X         } else {
18558 X             if (sc <= 0) {
18559 X                 ap->I1 = ap->C1 = 0;
18560 X             } else {
18561 X                 ap->C1 = sc; sc-=gg;
18562 X                 if (sc >0) {
18563 X                     if (sc > best) best =sc;
18564 X                     if (cd1 < sc) cd1 = sc;
18565 X                     ap->I1 = sc;
18566 X                 } else ap->I1 = 0;
18567 X             }
18568 X         }
18569 X         ww = &wt[(unsigned char) *dp++];
18570 X         sc = max(max(e2+ww->iv, (e1=ap->C3)+ww->ii), e3+ww->iii);
18571 X         if (cd2 > sc) sc = cd2;
18572 X         cd2 -= gext;
18573 X         if ((ci = aq->I2) > 0) {
18574 X             if (sc < ci) { ap->C2 = ci; ap->I2 = ci-gext;}
18575 X             else {
18576 X                 ap->C2 = sc;
18577 X                 sc -= gg;
18578 X                 if (sc > 0) {
18579 X                     if (sc > best) best =sc;
18580 X                     if (cd2 < sc) cd2 = sc;
18581 X                     ap->I2 = max(ci-gext, sc);
18582 X                 }
18583 X             }
18584 X         } else {
18585 X             if (sc <= 0) {
18586 X                 ap->I2 = ap->C2 = 0;
18587 X             } else {
18588 X                 ap->C2 = sc; sc-=gg;
18589 X                 if (sc >0) {
18590 X                     if (sc > best) best =sc;
18591 X                     if (cd2 < sc) cd2 = sc;
18592 X                     ap->I2 = sc;
18593 X                 } else ap->I2 = 0;
18594 X             }
18595 X         }
18596 X         ww = &wt[(unsigned char)*dp++];
18597 X         sc = max(max(e3+ww->iv, (e2=aq->C1)+ww->ii), e1+ww->iii);
18598 X         if (cd3 > sc) sc = cd3;
18599 X         cd3 -= gext;
18600 X         if ((ci = aq++->I3) > 0) {
18601 X             if (sc < ci) { ap->C3 = ci; ap->I3 = ci-gext;}
18602 X             else {
18603 X                 ap->C3 = sc;
18604 X                 sc -= gg;
18605 X                 if (sc > 0) {
18606 X                     if (sc > best) best =sc;
18607 X                     if (cd3 < sc) cd3 = sc;
18608 X                     ap->I3 = max(ci-gext, sc);
18609 X                 }
18610 X             }
18611 X         } else {
18612 X             if (sc <= 0) {
18613 X                 ap->I3 = ap->C3 = 0;
18614 X             } else {
18615 X                 ap->C3 = sc; sc-=gg;
18616 X                 if (sc >0) {
18617 X                     if (sc > best) best =sc;
18618 X                     if (cd3 < sc) cd3 = sc;
18619 X                     ap->I3 = sc;
18620 X                 } else ap->I3 = 0;
18621 X             }
18622 X         }
18623 X      }
18624 X  }
18625 X  /*  printf("The best score is %d\n", best); */
18626 X  return best+gg;
18627 }
18628 X
18629 /* ckalloc - allocate space; check for success */
18630 void *ckalloc(size_t amount)
18631 {
18632 X       void *p;
18633 X
18634 X       if ((p = (void *)malloc( (size_t)amount)) == NULL)
18635 X               w_abort("Ran out of memory.","");
18636 X       return(p);
18637 }
18638 X
18639 /* calculate the 100% identical score */
18640 int
18641 shscore(unsigned char *aa0, int n0, int **pam2)
18642 {
18643 X  int i, sum;
18644 X  for (i=0,sum=0; i<n0; i++)
18645 X    sum += pam2[aa0[i]][aa0[i]];
18646 X  return sum;
18647 }
18648 X
18649 #define SGW1 100
18650 #define SGW2 300
18651 #define WIDTH 60
18652 X
18653 typedef struct mat *match_ptr;
18654 X
18655 typedef struct mat {
18656 X       int i, j, l;
18657 X       match_ptr next;
18658 } match_node;
18659 X
18660 typedef struct { int i,j;} state;
18661 typedef state *state_ptr;
18662 X
18663 X
18664 void *ckalloc();
18665 static match_ptr small_global(), global();
18666 static int local_align(), find_best();
18667 static void init_row2(), init_ROW();
18668 X
18669 int
18670 pro_dna(const unsigned char *prot_seq,  /* array with prot. seq. numbers*/
18671 X       int len_prot,    /* length of prot. seq */
18672 X       const unsigned char *dna_prot_seq, /* trans. DNA seq. numbers*/
18673 X       int len_dna_prot,   /* length trans. seq. */
18674 X       int **pam_matrix,   /* scoring matrix */
18675 X       int gopen, int gext, /* gap open, gap extend penalties */
18676 X       int gshift,         /* frame-shift penalty */
18677 X       struct f_struct *f_str,
18678 X       int max_res,
18679 X       struct a_res_str *a_res) /* alignment info */
18680 {
18681 X  match_ptr align, ap, aq;
18682 X  int x, y, ex, ey, i, score;
18683 X  int *alignment;
18684 X
18685 X  f_str->up = (st_ptr) ckalloc(sizeof(struct st_s)*(len_dna_prot+10));
18686 X  f_str->down = (st_ptr) ckalloc(sizeof(struct st_s)*(len_dna_prot+10));
18687 X  f_str->tp = (st_ptr) ckalloc(sizeof(struct st_s)*(len_dna_prot+10));
18688 X
18689 X  /*local alignment find the best local alignment x and y
18690 X    is the starting position of the best local alignment
18691 X    and ex ey is the ending position */
18692 X
18693 X  score= local_align(&x, &y, &ex, &ey, 
18694 X                    pam_matrix, gopen, gext,
18695 X                    dna_prot_seq, len_dna_prot,
18696 X                    prot_seq, len_prot, f_str);
18697 X
18698 X  f_str->up += 3; f_str->down += 3; f_str->tp += 3;
18699 X
18700 X  /* x, y - start in prot, dna_prot */
18701 X  a_res->min0 = x;     /* prot */
18702 X  a_res->min1 = y;     /* DNA */
18703 X  a_res->max0 = ex;    /* prot */
18704 X  a_res->max1 = ey;    /* DNA */
18705 X
18706 X  align = global(x, y, ex, ey, 
18707 X                pam_matrix, gopen, gext,
18708 X                dna_prot_seq, prot_seq,
18709 X                0, 0, f_str);
18710 X
18711 X  alignment = a_res->res;
18712 X
18713 X  for (ap = align, i= 0; ap; i++) {
18714 X    if (i < max_res) alignment[i] = ap->l;
18715 X    aq = ap->next; free(ap); ap = aq;
18716 X  }
18717 X  if (i >= max_res)
18718 X    fprintf(stderr,"***alignment truncated: %d/%d***\n", max_res,i);
18719 X
18720 X  /*   up = &up[-3]; down = &down[-3]; tp = &tp[-3]; */
18721 X  free(&f_str->up[-3]); free(&f_str->tp[-3]); free(&f_str->down[-3]);
18722 X
18723 X  a_res->nres = i;
18724 X  return score;
18725 }
18726 X
18727 static void
18728 swap(void **a, void **b)
18729 {
18730 X    void *t = *a;
18731 X    *a = *b;   *b = t;
18732 }
18733 X
18734 /*
18735 X   local alignment find the best local alignment x and y
18736 X   is the starting position of the best local alignment
18737 X   and ex ey is the ending position 
18738 */
18739 static int
18740 local_align(int *x, int *y, int *ex, int *ey, 
18741 X           int **wgts, int gop, int gext,
18742 X           const unsigned char *dnap, int ld,
18743 X           const unsigned char *pro, int lp,
18744 X           struct f_struct *f_str)
18745 {
18746 X  int i, j,  score, x1,x2,x3,x4, e1 = 0, e2 = 0, e3,
18747 X    sc, del,  e, best = 0,  cd, ci, c;
18748 X  struct wgt *wt, *ww;
18749 X  state_ptr cur_st, last_st, cur_i_st;
18750 X  st_ptr cur, last;
18751 X  const unsigned char *dp;
18752 X  int *cur_d_st, *st_up;
18753 X
18754 X  /*      
18755 X         Array rowiC stores the best scores of alignment ending at a position
18756 X         Arrays rowiD and rowiI store the best scores of alignment ending
18757 X         at a position with a deletion or insrtion
18758 X         Arrays sti stores the starting position of the best alignment whose
18759 X         score stored in the corresponding row array.
18760 X         The program stores two rows to complete the computation, same is
18761 X         for the global alignment routine.
18762 X  */
18763 X
18764 X
18765 X  st_up = (int *) ckalloc(sizeof(int)*(ld+10));
18766 X  init_row2(st_up, ld+5);
18767 X
18768 X  ld += 2;
18769 X
18770 X  init_ROW(f_str->up, ld+1);
18771 X  init_ROW(f_str->down, ld+1);
18772 X  cur = f_str->up+1;
18773 X  last = f_str->down+1; 
18774 X
18775 X  cur_st = (state_ptr) ckalloc(sizeof(state)*(ld+1));
18776 X  last_st = (state_ptr) ckalloc(sizeof(state)*(ld+1));
18777 X  cur_i_st = (state_ptr) ckalloc(sizeof(state)*(ld+1));
18778 X  cur_d_st = st_up; 
18779 X  dp = dnap-2;
18780 X  for (i = 0; i < lp; i++) {
18781 X    wt = f_str->weight1[pro[i]];  e2 =0; e1 = last[0].C;
18782 X    for (j = 0; j < 2; j++) {
18783 X      cur_st[j].i = i+1;
18784 X      cur_st[j].j = j+1;
18785 X    }
18786 X    for (j = 2; j < ld; j++) {
18787 X      ww = &wt[(unsigned char) dp[j]];
18788 X      del = -1;
18789 X      if (j >= 3) {
18790 X       sc = 0;
18791 X       e3 = e2; e2 = e1;
18792 X       e1 = last[j-2].C; 
18793 X       if ((e=e2+ww->iii) > sc) {sc = e; del = 3;}
18794 X       if ((e=e1+ww->ii) > sc) {sc = e; del = 2;}
18795 X       if ((e = e3+ww->iv) > sc) {sc = e; del = 4;} 
18796 X      } else {
18797 X       sc = e2  = 0;
18798 X       if (ww->iii > 0) {sc = ww->iii; del = 3;}
18799 X      }
18800 X      if (sc < (ci=last[j].I)) {
18801 X       sc = ci; del = 0;
18802 X      }
18803 X      if (sc < (cd=cur[j].D)) {
18804 X       sc = cd; del = 5;
18805 X      }
18806 X      cur[j].C = sc;
18807 X      e = sc  - gop;
18808 X      if (e > cd) {
18809 X       cur[j+3].D = e-gext;
18810 X       cur_d_st[j+3] = 3;
18811 X      } else {
18812 X       cur[j+3].D = cd-gext;
18813 X       cur_d_st[j+3] = cur_d_st[j]+3;
18814 X      }
18815 X      switch(del) {
18816 X      case 5:
18817 X       c = cur_d_st[j];
18818 X       cur_st[j].i = cur_st[j-c].i;
18819 X       cur_st[j].j = cur_st[j-c].j;
18820 X       break;
18821 X      case 0:
18822 X       cur_st[j].i = cur_i_st[j].i;
18823 X       cur_st[j].j = cur_i_st[j].j;
18824 X       break;
18825 X      case 2:
18826 X      case 3:
18827 X      case 4:
18828 X       if (i) {
18829 X         if (j-del >= 0) {
18830 X           cur_st[j].i = last_st[j-del].i;
18831 X           cur_st[j].j = last_st[j-del].j;
18832 X         } else {
18833 X           cur_st[j].i = i;
18834 X           cur_st[j].j = 0;
18835 X         }
18836 X       } else {
18837 X         cur_st[j].i = 0;
18838 X         cur_st[j].j = max(0, j-del+1);
18839 X       }
18840 X       break;
18841 X      case -1:
18842 X       cur_st[j].i = i+1;
18843 X       cur_st[j].j = j+1;
18844 X       break;
18845 X      }
18846 X      if (e > ci) {
18847 X       cur[j].I  = e -gext;
18848 X       cur_i_st[j].i = cur_st[j].i;
18849 X       cur_i_st[j].j = cur_st[j].j;
18850 X      } else {
18851 X       cur[j].I  = ci- gext;
18852 X      }
18853 X      if (sc > best) {
18854 X       x1 = cur_st[j].i;
18855 X       x2 = cur_st[j].j;
18856 X       best =sc;
18857 X       x3 = i;
18858 X       x4 = j;
18859 X      }
18860 X    }
18861 X    swap((void *)&last, (void *)&cur);
18862 X    swap((void *)&cur_st, (void *)&last_st);
18863 X  }
18864 X  /*   printf("The best score is %d\n", best);*/
18865 X  *x = x1; *y = x2; *ex = x3; *ey = x4;
18866 X  free(cur_st); free(last_st); free(cur_i_st); 
18867 X  free(st_up);
18868 X  return best;
18869 }
18870 X
18871 /* 
18872 X   Both global_up and global_down do linear space score only global 
18873 X   alignments on subsequence pro[x]...pro[ex], and dna[y]...dna[ey].
18874 X   global_up do the algorithm upwards, from row x towards row y.
18875 X   global_down do the algorithm downwards, from row y towards x.
18876 */
18877 X
18878 static void
18879 global_up(st_ptr *row1, st_ptr *row2, 
18880 X         int x, int y, int ex, int ey, 
18881 X         int **wgts, int gop, int gext,
18882 X         unsigned char *dnap, unsigned char *pro, 
18883 X         int N, struct f_struct *f_str)
18884 {
18885 X  int i, j, k, sc, e, e1, e2, e3, t, ci, cd, score;
18886 X  struct wgt *wt, *ww;
18887 X  st_ptr cur, last;
18888 X
18889 X  cur = *row1; last = *row2;
18890 X  sc = -gop;
18891 X  for (j = 0; j <= ey-y+1; j++) {
18892 X    if (j % 3 == 0) {last[j].C = sc; sc -= gext; last[j].I = sc-gop;}
18893 X    else { last[j].I = last[j].C = -10000;}
18894 X  }  
18895 X  last[0].C = 0; cur[0].D = cur[1].D = cur[2].D = -10000;
18896 X  last[0].D = last[1].D = last[2].D = -10000;
18897 X  if (N) last[0].I = -gext;
18898 X  for (i = 1; i <= ex-x+1; i++) {
18899 X    wt = f_str->weight1[pro[i+x-1]]; e1 = -10000; e2 = last[0].C;
18900 X    for (j = 0; j <= ey-y+1; j++) {
18901 X      t = j+y;
18902 X      sc = -10000; 
18903 X      ww = &wt[(unsigned char) dnap[t-3]]; 
18904 X      if (j < 4) {
18905 X       if (j == 3) {
18906 X         sc = e2+ww->iii;
18907 X       } else if (j == 2) {
18908 X         sc = e2 + ww->ii;
18909 X       }
18910 X      } else {
18911 X       e3 = e2; e2 = e1;
18912 X       e1 = last[j-2].C;
18913 X       sc = max(e2+ww->iii, max(e1+ww->ii, e3+ww->iv));
18914 X      }
18915 X      sc = max(sc, max(ci=last[j].I, cd = cur[j].D));
18916 X      cur[j].C = sc;
18917 X      cur[j+3].D = max(cd, sc-gop)-gext;
18918 X      cur[j].I = max(ci, sc-gop)-gext;
18919 X    }
18920 X    swap((void *)&last, (void *)&cur);
18921 X  }
18922 X  /*printf("global up score =%d\n", last[ey-y+1].C);*/
18923 X  for (i = 0; i <= ey-y+1; i++) last[i].I = cur[i].I;  
18924 X  if (*row1 != last) swap((void *)row1, (void *)row2);
18925 }
18926 X
18927 static void
18928 global_down(st_ptr *row1, st_ptr *row2,
18929 X           int x, int y, int ex, int ey, 
18930 X           int **wgts, int gop, int gext,
18931 X           unsigned char *dnap, unsigned char *pro,
18932 X           int N, struct f_struct *f_str)
18933 {
18934 X  int i, j, k, sc, del, *tmp, e,  t, e1,e2,e3, ci,cd, score;
18935 X  struct wgt *wt, *w1, *w2, *w3;
18936 X  st_ptr cur, last;
18937 X
18938 X  cur = (*row1); last = *row2;
18939 X  sc = -gop;
18940 X  for (j = ey-y+1; j >= 0; j--) {
18941 X    if ((ey-y+1-j) % 3) {last[j].C = sc; sc-=gext; last[j].I = sc-gop;}
18942 X    else  last[j].I =  last[j].C = -10000;
18943 X    cur[j].I = -10000;
18944 X  } 
18945 X  last[ey-y+1].C = 0;
18946 X  if (N) last[ey-y+1].I = -gext;
18947 X  cur[ey-y+1].D = cur[ey-y].D = cur[ey-y-1].D = -10000;
18948 X  last[ey-y+1].D = last[ey-y].D = last[ey-y-1].D = -10000;
18949 X  for (i = ex-x; i >= 0; i--) {
18950 X    wt = f_str->weight1[pro[i+x]]; e2 = last[ey-y+1].C; 
18951 X    e1 = -10000;
18952 X    w3 = &wt[(unsigned char) dnap[ey]]; 
18953 X    w2 = &wt[(unsigned char) dnap[ey-1]];
18954 X    for (j = ey-y+1; j >= 0; j--) {
18955 X      t = j+y;
18956 X      w1 = &wt[(unsigned char) dnap[t-1]];
18957 X      sc = -10000;
18958 X      if (t+3 > ey) {
18959 X       if (t+2 == ey) {
18960 X         sc = e2+w2->iii; 
18961 X       } else if (t+1 == ey) {
18962 X         sc = e2+w1->ii;
18963 X       }
18964 X      } else {
18965 X       e3 = e2; e2 = e1;
18966 X       e1 = last[j+2].C;
18967 X       sc = max(e2+w2->iii, max(e1+w1->ii,e3+w3->iv)) ;
18968 X      }
18969 X      if (sc < (cd= cur[j].D)) {
18970 X       sc = cd; 
18971 X       cur[j-3].D = cd-gext;
18972 X      } else cur[j-3].D =max(cd, sc-gop)-gext;
18973 X      if (sc < (ci= last[j].I)) {
18974 X       sc = ci;
18975 X       cur[j].I = ci - gext;
18976 X      } else cur[j].I = max(sc-gop,ci)-gext;
18977 X      cur[j].C = sc;
18978 X      w3 = w2; w2 = w1;
18979 X    }
18980 X    swap((void *)&last, (void *)&cur);
18981 X  }
18982 X  for (i = 0; i <= ey-y+1; i++) last[i].I = cur[i].I;
18983 X  if (*row1 != last) swap((void *)row1, (void *)row2);
18984 }
18985 X
18986 static void
18987 init_row2(int *row, int ld) {
18988 X  int i;
18989 X  for (i = 0; i < ld; i++) row[i] = 0;
18990 }
18991 X
18992 static void init_ROW(st_ptr row, int ld) {
18993 X  int i;
18994 X  for (i = 0; i < ld; i++) row[i].I = row[i].D = row[i].C = 0;
18995 }
18996 X
18997 static match_ptr
18998 combine(match_ptr x1, match_ptr x2, int st) {
18999 X  match_ptr x;
19000 X
19001 X  if (x1 == NULL) return x2;
19002 X  for (x = x1; x->next; x = x->next);
19003 X  x->next = x2;
19004 X  if (st) {
19005 X    for (x = x2; x; x = x->next) {
19006 X      x->j++;
19007 X      if (x->l == 3 || x->l == 4) break;
19008 X    }
19009 X    x->l--;
19010 X  }
19011 X  return x1;
19012 }
19013 X
19014 /*
19015 X   global use the two upwards and downwards score only linear
19016 X   space global alignment subroutine to recursively build the
19017 X   alignment.
19018 */
19019 X
19020 match_ptr
19021 global(int x, int y, int ex, int ey,
19022 X       int **wgts, int gop, int gext,
19023 X       unsigned char *dnap, unsigned char *pro, int N1, int N2,
19024 X       struct f_struct *f_str)
19025 {
19026 X  int m;
19027 X  int m1, m2;
19028 X  match_ptr x1, x2, mm1, mm2;
19029 X
19030 X  /*printf("%d %d %d %d %d %d\n", x,y, ex, ey, N1, N2);*/
19031 X  /*
19032 X    if the space required is limited, we can do a quadratic space
19033 X    algorithm to find the alignment.
19034 X  */
19035 X
19036 X  if (ex <= x) {
19037 X    mm1  = NULL;
19038 X    for (m = y+3; m <= ey; m+=3) {
19039 X      x1 = (match_ptr) ckalloc(sizeof(match_node));
19040 X      x1->l = 5; x1->next = mm1; 
19041 X      if (mm1== NULL) mm2 = x1;
19042 X      mm1 = x1;
19043 X    }
19044 X    if (ex == x) {
19045 X      if ((ey-y) % 3 != 0) {
19046 X       x1  = (match_ptr) ckalloc(sizeof(match_node));
19047 X       x1->l = ((ey-y) % 3) +1; x1->next = NULL;
19048 X       if (mm1) mm2->next = x1; else mm1 = x1;
19049 X      } else mm2->l = 4;
19050 X    }
19051 X    return mm1;
19052 X  }
19053 X  if (ey <= y) {
19054 X    mm1  = NULL;
19055 X    for (m = x; m <= ex; m++) {
19056 X      x1 = (match_ptr) ckalloc(sizeof(match_node));
19057 X      x1->l = 0; x1->next = mm1; mm1 = x1;
19058 X    }
19059 X    return mm1;
19060 X  }
19061 X  if (ex -x < SGW1 && ey-y < SGW2) 
19062 X    return small_global(x,y,ex,ey,wgts, gop, gext,  dnap, pro, N1, N2,f_str);
19063 X  m = (x+ex)/2;
19064 X  /*     
19065 X        Do the score only global alignment from row x to row m, m is
19066 X        the middle row of x and ex. Store the information of row m in
19067 X        upC, upD, and upI.
19068 X  */
19069 X  global_up(&f_str->up, &f_str->tp,  x, y, m, ey,
19070 X           wgts, gop, gext,
19071 X           dnap, pro, N1, f_str);
19072 X  /* 
19073 X     Do the score only global alignment downwards from row ex
19074 X     to row m+1, store information of row m+1 in downC downI and downD
19075 X  */
19076 X  global_down(&f_str->down, &f_str->tp, m+1, y, ex, ey,
19077 X             wgts, gop, gext,
19078 X             dnap, pro, N2, f_str);
19079 X
19080 X  /*
19081 X    Use this information for row m and m+1 to find the crossing
19082 X    point of the best alignment with the middle row. The crossing
19083 X    point is given by m1 and m2. Then we recursively call global
19084 X    itself to compute alignments in two smaller regions found by
19085 X    the crossing point and combine the two alignments to form a
19086 X    whole alignment. Return that alignment.
19087 X  */
19088 X  if (find_best(f_str->up, f_str->down, &m1, &m2, ey-y+1, y, gop)) {
19089 X    x1 = global(x, y, m, m1, wgts, gop, gext, dnap, pro, N1, 0, f_str);
19090 X    x2 = global(m+1, m2, ex, ey, wgts, gop, gext, dnap, pro, 0, N2, f_str);
19091 X    if (m1 == m2) x1 = combine(x1,x2,1);
19092 X    else x1 = combine(x1, x2,0);
19093 X  } else {
19094 X    x1 = global(x, y, m-1, m1, wgts, gop, gext, dnap, pro, N1, 1, f_str);
19095 X    x2 = global(m+2, m2, ex, ey, wgts, gop, gext, dnap, pro, 1, N2, f_str);
19096 X    mm1 = (match_ptr) ckalloc(sizeof(match_node));
19097 X    mm1->i = m; mm1->l = 0; mm1->j = m1;
19098 X    mm2 = (match_ptr) ckalloc(sizeof(match_node));
19099 X    mm2->i = m+1; mm2->l = 0; mm2->j = m1;
19100 X    mm1->next = mm2; mm2->next = x2;
19101 X    x1 = combine(x1, mm1, 0);
19102 X  }
19103 X  return x1;
19104 }
19105 X
19106 static int
19107 find_best(st_ptr up, st_ptr down, int *m1, int *m2, int ld, int y, int gop) {
19108 X
19109 X  int i, best = -1000, j = 0, s1, s2, s3, s4, st;
19110 X
19111 X  for (i = 1; i < ld; i++) {
19112 X    s2 = up[i].C + down[i].C;
19113 X    s4 = up[i].I + down[i].I + gop;
19114 X    if (best < s2) {
19115 X      best = s2; j = i; st = 1;
19116 X    }
19117 X    if (best < s4) {
19118 X      best = s4; j = i; st = 0;
19119 X    }
19120 X  }
19121 X  *m1 = j-1+y;
19122 X  *m2 = j+y;
19123 X  /*printf("score=%d\n", best);*/
19124 X  return st;
19125
19126 X
19127 /*
19128 X   An alignment is represented as a linked list whose element
19129 X   is of type match_node. Each element represent an edge in the
19130 X   path of the alignment graph. The fields of match_node are
19131 X   l ---  gives the type of the edge.
19132 X   i, j --- give the end position.
19133 */
19134 X
19135 static match_ptr
19136 small_global(int x, int y, int ex, int ey, 
19137 X            int **wgts, int gop, int gext,
19138 X            unsigned char *dnap, unsigned char *pro,
19139 X            int N1, int N2, struct f_struct *f_str) {
19140 X
19141 X  static int C[SGW1+1][SGW2+1], st[SGW1+1][SGW2+1], D[SGW2+7], I[SGW2+1];
19142 X  int i, j, e, sc, score, del, k, t,  ci, cd;
19143 X  int *cI, *cD, *cC, *lC, *cst, e2, e3, e4;
19144 X  match_ptr mp, first;
19145 X  struct wgt *wt, *ww;
19146 X
19147 X  /*printf("small_global %d %d %d %d\n", x, y, ex, ey);*/
19148 X  sc = -gop-gext; C[0][0] = 0; 
19149 X  if (N1) I[0] = -gext; else I[0] = sc;
19150 X
19151 X  for (j = 1; j <= ey-y+1; j++) {
19152 X    if (j % 3== 0) {
19153 X      C[0][j] = sc; sc -= gext; I[j] = sc-gop;
19154 X    } else I[j] = C[0][j] = -10000;
19155 X    st[0][j] = 5;
19156 X  }
19157 X  lC = &C[0][0]; cD = D; D[0] = D[1] = D[2] = -10000;
19158 X  cI = I;
19159 X  for (i = 1; i <= ex-x+1; i++) {
19160 X    cC = &C[i][0];     
19161 X    wt = f_str->weight1[pro[i+x-1]]; cst = &st[i][0];
19162 X    for (j = 0; j <=ey-y+1; j++) {
19163 X      ci = cI[j];
19164 X      cd= cD[j];
19165 X      t = j+y;
19166 X      ww = &wt[(unsigned char) dnap[t-3]];
19167 X      if (j >= 4) {
19168 X       sc = lC[j-3]+ww->iii; e2 = lC[j-2]+ww->ii;  
19169 X       e4 = lC[j-4]+ww->iv; del = 3;
19170 X       if (e2 > sc) { sc = e2; del = 2;}
19171 X       if (e4 >= sc) { sc = e4; del = 4;}
19172 X      } else {
19173 X       if (j == 3) {
19174 X         sc = lC[0]+ww->iii; del =3;
19175 X       } else if (j == 2) {
19176 X         sc = lC[0]+ww->ii; del = 2;
19177 X       } else {sc = -10000; del = 0;}
19178 X      }
19179 X      if (sc < ci) {
19180 X       sc = ci; del = 0; 
19181 X      }
19182 X      if (sc <= cd) {
19183 X       sc = cd;
19184 X       del = 5;
19185 X      }
19186 X      cC[j] = sc;
19187 X      sc -= gop;
19188 X      if (sc <= cd) {
19189 X       del += 10;
19190 X       cD[j+3] = cd - gext;
19191 X      } else cD[j+3] = sc -gext;
19192 X      if (sc < ci) {
19193 X       del += 20;
19194 X       cI[j] = ci-gext;
19195 X      } else cI[j] = sc-gext;
19196 X      *(cst++) = del;
19197 X    }
19198 X    lC = cC;
19199 X  }
19200 X  /*printf("small global score =%d\n", C[ex-x+1][ey-y+1]);*/
19201 X  if (N2 && cC[ey-y+1] <  ci+gop) st[ex-x+1][ey-y+1] =0;
19202 X  first = NULL; e = 1;
19203 X  for (i = ex+1, j = ey+1; i > x || j > y; i--) {
19204 X    mp = (match_ptr) ckalloc(sizeof(match_node));
19205 X    mp->i = i-1;
19206 X    k  = (t=st[i-x][j-y])%10;
19207 X    mp->j = j-1;
19208 X    if (e == 5 && (t/10)%2 == 1) k = 5;
19209 X    if (e == 0 && (t/20)== 1) k = 0;
19210 X    if (k == 5) { j -= 3; i++; e=5;}
19211 X    else {j -= k;if (k==0) e= 0; else e = 1;}
19212 X    mp->l = k;
19213 X    mp->next = first;
19214 X    first = mp;
19215 X  }
19216 X
19217 X  /*   for (i = 0; i <= ex-x; i++) {
19218 X       for (j = 0; j <= ey-y; j++) 
19219 X       printf("%d ", C[i][j]);
19220 X       printf("\n");
19221 X       }
19222 X  */
19223 X  return first;        
19224 }
19225 X
19226 #define XTERNAL
19227 #include "upam.h"
19228 X
19229 void
19230 display_alig(int *a, unsigned char *dna, unsigned char *pro,
19231 X            int length, int ld, struct f_struct *f_str)
19232 {
19233 X  int len = 0, i, j, x, y, lines, k, iaa;
19234 X  static char line1[100], line2[100], line3[100],
19235 X    tmp[10] = "         ", *st;
19236 X  char *dna1, c1, c2, c3;
19237 X
19238 X  line1[0] = line2[0] = line3[0] = '\0'; x= a[0]; y = a[1]-3;
19239 X
19240 X  printf("\n%5d\n%5d", y+3, x);
19241 X  for (len = 0, j = 2, lines = 0; j < length; j++) {
19242 X    i = a[j];
19243 X    line3[len] = ' ';
19244 X    switch (i) {
19245 X    case 3: 
19246 X      y += 3;
19247 X      line2[len] = aa[iaa=pro[x++]];
19248 X      line1[len] = f_str->weight_c[iaa][(unsigned char) dna[y]].c5;
19249 X      if (line1[len] != f_str->weight_c[iaa][(unsigned char) dna[y]].c3)
19250 X       line3[len] = f_str->weight_c[iaa][(unsigned char) dna[y]].c3;
19251 X      break;
19252 X    case 2:
19253 X      y += 2;
19254 X      line1[len] = '\\';
19255 X      line2[len++] = ' ';
19256 X      line2[len] = aa[iaa=pro[x++]];
19257 X      line1[len] = f_str->weight_c[iaa][(unsigned char) dna[y]].c2;
19258 X      line3[len] = f_str->weight_c[iaa][(unsigned char) dna[y]].c3;
19259 X      break;
19260 X    case 4:
19261 X      y += 4;
19262 X      line1[len] = '/';
19263 X      line2[len++] = ' ';
19264 X      line2[len] = aa[iaa=pro[x++]];
19265 X      line1[len] = f_str->weight_c[iaa][(unsigned char) dna[y]].c4;
19266 X      line3[len] = f_str->weight_c[iaa][(unsigned char) dna[y]].c3;
19267 X      break;
19268 X    case 5:
19269 X      y += 3;
19270 X      line1[len] = f_str->weight_c[0][(unsigned char) dna[y]].c3;
19271 X      line2[len] = '-';
19272 X      break;
19273 X    case 0:
19274 X      line1[len] = '-';
19275 X      line2[len] = aa[pro[x++]];
19276 X      break;
19277 X    }
19278 X    len++;
19279 X    line1[len] = line2[len]  = line3[len]  = '\0'; 
19280 X    if (len >= WIDTH) {
19281 X      for (k = 10; k <= WIDTH; k+=10) 
19282 X       printf("    .    :");
19283 X      if (k-5 < WIDTH) printf("    .");
19284 X      c1 = line1[WIDTH]; c2 = line2[WIDTH]; c3 = line3[WIDTH];
19285 X      line1[WIDTH] = line2[WIDTH] = line3[WIDTH] = '\0';
19286 X      printf("\n     %s\n     %s\n     %s\n", line1, line3, line2);
19287 X      line1[WIDTH] = c1; line2[WIDTH] = c2;
19288 X      strncpy(line1, &line1[WIDTH], sizeof(line1)-1);
19289 X      strncpy(line2, &line2[WIDTH], sizeof(line2)-1);
19290 X      strncpy(line3, &line3[WIDTH], sizeof(line3)-1);
19291 X      len = len - WIDTH;
19292 X      printf("\n%5d\n%5d", y+3, x);
19293 X    }
19294 X  }
19295 X  for (k = 10; k < len; k+=10) 
19296 X    printf("    .    :");
19297 X  if (k-5 < len) printf("    .");
19298 X  printf("\n     %s\n     %s\n     %s\n", line1, line3, line2);
19299 }
19300 X
19301 X
19302 /* alignment store the operation that align the protein and dna sequence.
19303 X   The code of the number in the array is as follows:
19304 X   0:     delete of an amino acid.
19305 X   2:     frame shift, 2 nucleotides match with an amino acid
19306 X   3:     match an  amino acid with a codon
19307 X   4:     the other type of frame shift
19308 X   5:     delete of a codon
19309 X   
19310 X
19311 X   Also the first two element of the array stores the starting point 
19312 X   in the protein and dna sequences in the local alignment.
19313 X
19314 X   Display looks like where WIDTH is assumed to be divisible by 10.
19315 X
19316 X    0    .    :    .    :    .    :    .    :    .    :    .    :
19317 X     AACE/N\PLK\G\HK\Y/LWA\S\C\E/P\PRIRZ/G\HK\Y/LWA\S\C\E/P\PRIRZ
19318 X          I S   G S  V F   N R Q L A     G S  V F   N R Q L A    
19319 X     AACE P P-- G HK Y TWA A C E P P---- G HK Y TWA A C E P P----
19320 X
19321 X   60    .    :    .    :    .    :    .    :    .    :    .    :
19322 X     /G\HK\Y/LWA\S\C\E/P\PRIRZ/G\HK\Y/LWA\S\C\E/P\PRIRZ/G\HK\Y/LW
19323 X      G S  V F   N R Q L A     G S  V F   N R Q L A     G S  V F 
19324 X      G HK Y TWA A C E P P---- G HK Y TWA A C E P P---- G HK Y TW
19325 X
19326 For frame shift, the middle row show the letter in the original sequence,
19327 and the letter in the top row is the amino acid that is chose by the 
19328 alignment (translated codon chosen from 4 nucleotides, or 2+1).
19329 */
19330 X
19331 /* fatal - print message and die */
19332 void
19333 fatal(msg)
19334 X     char *msg;
19335 {
19336 X  fprintf(stderr, "%s\n", msg);
19337 X  exit(1);
19338 }
19339 X
19340 int do_walign (const unsigned char *aa0, int n0,
19341 X              const unsigned char *aa1, int n1,
19342 X              int frame,
19343 X              struct pstruct *ppst, 
19344 X              struct f_struct *f_str, 
19345 X              struct a_res_str *a_res,
19346 X              int *have_ares)
19347 {
19348 X  int score;
19349 X  int i, ir, last_n1, itemp, n10, itx, dnav;
19350 X  unsigned char *aa1x;
19351 X  
19352 X  a_res->res = f_str->res;
19353 X
19354 #ifndef TFAST
19355 X  score = pro_dna(aa1, n1, f_str->aa0v, n0-2, ppst->pam2[0],
19356 #ifdef OLD_FASTA_GAP
19357 X                 -(ppst->gdelval - ppst->ggapval),
19358 #else
19359 X                 -ppst->gdelval,
19360 #endif
19361 X                 -ppst->ggapval,
19362 X                 -ppst->gshift,
19363 X                 f_str, f_str->max_res, a_res);
19364 X  /* display_alig(f_str->res,f_str->aa0v+2,aa1,*nres,n0-2,f_str); */
19365 X
19366 #else
19367 X  /* make a precomputed codon number series */
19368 X  if (frame==0) {
19369 X    pre_com(aa1, n1, f_str->aa1v);
19370 X  }
19371 X  else { /* must do things backwards */
19372 X    pre_com_r(aa1, n1, f_str->aa1v);
19373 X  }
19374 X
19375 X  /* make translated sequence */
19376 X  last_n1 = 0;
19377 X  aa1x = f_str->aa1x;
19378 X  for (itx= frame*3; itx< frame*3+3; itx++) {
19379 X    n10  = saatran(aa1,&aa1x[last_n1],n1,itx);
19380 X    /*
19381 X      fprintf(stderr," itt %d itx: %d\n",itt,itx);
19382 X      for (i=0; i<n10; i++) {
19383 X      fprintf(stderr,"%c",aa[f_str->aa1x[last_n1+i]]);
19384 X      if ((i%60)==59) fprintf(stderr,"\n");
19385 X      }
19386 X      fprintf(stderr,"\n");
19387 X    */
19388 X    last_n1 += n10+1;
19389 X  }
19390 X  n10 = last_n1-1;
19391 X
19392 X  score = pro_dna(aa0, n0, f_str->aa1v, n1-2, ppst->pam2[0],
19393 #ifdef OLD_FASTA_GAP
19394 X                 -(ppst->gdelval - ppst->ggapval),
19395 #else
19396 X                 -ppst->gdelval,
19397 #endif
19398 X                 -ppst->ggapval,
19399 X                 -ppst->gshift,
19400 X                 f_str, f_str->max_res, a_res);
19401 X  /* display_alig(f_str->res,f_str->aa0y,aa1,*nres,n0,f_str); */
19402 #endif
19403 X  a_res->res = f_str->res;
19404 X  *have_ares = 1;
19405 X
19406 X  return score;
19407 }
19408 X
19409 void
19410 pre_cons(const unsigned char *aa1, int n1, int frame, struct f_struct *f_str) {
19411 X
19412 #ifdef TFAST
19413 X  int i, last_n1, itemp, n10;
19414 X  unsigned char *fs, *fd;
19415 X  int itx;
19416 X
19417 X  /* make a precomputed codon number series */
19418 X  if (frame==0) {
19419 X    pre_com(aa1, n1, f_str->aa1v);
19420 X  }
19421 X  else { /* must do things backwards */
19422 X    pre_com_r(aa1, n1, f_str->aa1v);
19423 X  }
19424 #endif
19425 }
19426 X
19427 /* aln_func_vals - set up aln.qlfact, qlrev, llfact, llmult, frame, llrev */
19428 /* call from calcons, calc_id, calc_code */
19429 void 
19430 aln_func_vals(int frame, struct a_struct *aln) {
19431 X
19432 #ifndef TFAST
19433 X  aln->llrev = 0;
19434 X  aln->llfact = 1;
19435 X  aln->llmult = 1;
19436 X  aln->qlfact = 3;
19437 X  aln->frame = 0;
19438 X  if (frame > 0) aln->qlrev = 1;
19439 X  else aln->qlrev = 0;
19440 #else   /* TFASTX */
19441 X  aln->qlfact = 1;
19442 X  aln->qlrev = 0;
19443 X  aln->llfact = 3;
19444 X  aln->llmult = 1;
19445 X  aln->frame = 0;
19446 X  if (frame > 0) aln->llrev = 1;
19447 X  else aln->llrev = 0;
19448 #endif  /* TFASTX */
19449 }
19450 X
19451 #include "structs.h"
19452 #include "a_mark.h"
19453 X
19454 int calcons(const unsigned char *aa0, int n0,
19455 X           const unsigned char *aa1, int n1,
19456 X           int *nc,
19457 X           struct a_struct *aln, 
19458 X           struct a_res_str a_res,
19459 X           struct pstruct pst,
19460 X           char *seqc0, char *seqc1, char *seqca,
19461 X           struct f_struct *f_str)
19462 {
19463 X  int i0, i1;
19464 X  int lenc, not_c, itmp, ngap_p, ngap_d, nfs;
19465 X  char *sp0, *sp1, *spa, *sq;
19466 X  unsigned char aap;
19467 X  const unsigned char *ap0, *ap1;
19468 X  int *rp, *rpmax;
19469 X  int *res;
19470 X
19471 X  /* don't fill in the ends */
19472 X
19473 X  
19474 X  res = a_res.res;
19475 X  rpmax = &res[a_res.nres];            /* end of alignment info */
19476 X
19477 X  if (pst.ext_sq_set) {sq = pst.sqx;}
19478 X  else {sq = pst.sq;}
19479 X
19480 X  /* res[0] has start of protein sequence */
19481 X  /* res[1] has start of translated DNA sequence */
19482 X
19483 #ifndef TFAST           /* FASTX */
19484 X  ap0 = f_str->aa0v;           /* computed codons -> ap0*/
19485 X  ap1 = aa1;                   /* protein sequence -> ap1 */
19486 X  aln->smin1 = a_res.min0;     /* start in protein sequence */
19487 X  aln->smin0= a_res.min1;      /* start in DNA/codon sequence */
19488 #else   /* TFASTYZ */
19489 X  ap0 = f_str->aa1v;           /* computed codons -> ap0*/
19490 X  ap1 = aa0;                   /* protein sequence */
19491 X  aln->smin0 = a_res.min0;     /* start in protein sequence */
19492 X  aln->smin1 = a_res.min1;     /* start in codon sequence */
19493 #endif
19494 X
19495 X  rp = a_res.res;                      /* start of alignment info */
19496 X
19497 /* now get the middle */
19498 X  spa = seqca;
19499 #ifndef TFAST
19500 X  sp0 = seqc0;         /* sp0/seqc0 is codon sequence */
19501 X  sp1 = seqc1;         /* sp1/seqc1 is protein sequence */
19502 #else
19503 X  sp1 = seqc0;         /* sp1/seqc0 is protein sequence */
19504 X  sp0 = seqc1;         /* sp0/seqc1 is codon sequence */
19505 #endif
19506 X
19507 X  lenc = not_c = aln->nident = aln->nsim = ngap_d = ngap_p = nfs = 0;
19508 X  i0 = a_res.min1-3;   /* start of codon sequence */
19509 X  i1 = a_res.min0;     /* start of protein sequence */
19510 X
19511 X  while (rp < rpmax ) {
19512 X    switch (*rp++) {
19513 X    case 3:            /* match */
19514 X      i0 += 3;
19515 X      *sp1 = sq[aap=ap1[i1++]];
19516 X      *sp0 = f_str->weight_c[aap][ap0[i0]].c5;
19517 X
19518 X      if ((itmp=pst.pam2[0][aap][pascii[*sp0]])<0) { *spa = M_NEG; }
19519 X      else if (itmp == 0) { *spa = M_ZERO;}
19520 X      else {*spa = M_POS;}
19521 X      if (*spa == M_ZERO || *spa == M_POS) { aln->nsim++;}
19522 X
19523 X      if (toupper(*sp0) == toupper(*sp1)) {aln->nident++; *spa = M_IDENT;}
19524 X      sp0++; sp1++; spa++;
19525 X      lenc++;
19526 X      break;
19527 X    case 2:            /* frame shift +2, then match */
19528 X      nfs++;
19529 X      i0 += 2;
19530 X      *sp0++ = '/';
19531 X      *sp1++ = '-';
19532 X      *spa++ = M_DEL;
19533 X      not_c++;
19534 X      *sp1 = sq[aap=ap1[i1++]];
19535 X      *sp0 = f_str->weight_c[aap][ap0[i0]].c2;
19536 X      if ((itmp=pst.pam2[0][aap][pascii[*sp0]])<0) { *spa = M_NEG; }
19537 X      else if (itmp == 0) { *spa = M_ZERO;}
19538 X      else {*spa = M_POS;}
19539 X
19540 X      if (toupper(*sp0) == toupper(*sp1)) {aln->nident++; *spa = M_IDENT;}
19541 X      sp0++; sp1++; spa++;
19542 X      lenc++;
19543 X      break;
19544 X    case 4:            /* frame shift, -1, then match */
19545 X      nfs++;
19546 X      i0 += 4;
19547 X      *sp0++ = '\\';
19548 X      *sp1++ = '-';
19549 X      *spa++ = M_DEL;
19550 X      not_c++;
19551 X      *sp1 = sq[aap=ap1[i1++]];
19552 X      *sp0 = f_str->weight_c[aap][ap0[i0]].c4;
19553 X      if ((itmp=pst.pam2[0][aap][pascii[*sp0]])<0) { *spa = M_NEG; }
19554 X      else if (itmp == 0) { *spa = M_ZERO;}
19555 X      else {*spa = M_POS;}
19556 X
19557 X      if (toupper(*sp0) == toupper(*sp1)) {aln->nident++; *spa = M_IDENT;}
19558 X      sp0++; sp1++; spa++;
19559 X      lenc++;
19560 X      break;
19561 X    case 5:            /* insertion in 1 */
19562 X      i0 += 3;
19563 X      *sp0++ = f_str->weight_c[0][ap0[i0]].c3;
19564 X      *sp1++ = '-';
19565 X      *spa++ = M_DEL;
19566 X      lenc++;
19567 X      ngap_p++;
19568 X      break;
19569 X    case 0:            /* insertion in 0 */
19570 X      *sp0++ = '-';
19571 X      *sp1++ = sq[ap1[i1++]];
19572 X      *spa++ = M_DEL;
19573 X      lenc++;
19574 X      ngap_d++;
19575 X      break;
19576 X    }
19577 X  }
19578 X
19579 X  *spa = '\0';
19580 X
19581 #ifndef TFAST
19582 X  aln->amax0 = i0+3;   /* end of codon sequence */
19583 X  aln->amax1 = i1;     /* end of protein sequence */
19584 X  aln->ngap_q = ngap_d;
19585 X  aln->ngap_l = ngap_p;
19586 #else
19587 X  aln->amax1 = i0+3;   /* end of codon sequence */
19588 X  aln->amax0 = i1;     /* end of protein sequence */
19589 X  aln->ngap_q = ngap_p;
19590 X  aln->ngap_l = ngap_d;
19591 #endif
19592 X  aln->nfs = nfs;
19593 X  aln->amin0 = aln->smin0;
19594 X  aln->amin1 = aln->smin1;
19595 X
19596 X  if (lenc < 0) lenc = 1;
19597 X
19598 X  *nc = lenc;
19599 /*      now we have the middle, get the right end */
19600 X
19601 X  return lenc+not_c;
19602 }
19603 X
19604 int calcons_a(const unsigned char *aa0, unsigned char *aa0a, int n0,
19605 X             const unsigned char *aa1, int n1,
19606 X             int *nc,
19607 X             struct a_struct *aln,
19608 X             struct a_res_str a_res,
19609 X             struct pstruct pst,
19610 X             char *seqc0, char *seqc0a, char *seqc1, char *seqca,
19611 X             char *ann_arr, struct f_struct *f_str)
19612 {
19613 X  int i0, i1;
19614 X  int lenc, not_c, itmp, ngap_p, ngap_d, nfs;
19615 X  char *sp0, *sp0a, *sp1, *spa, *sq;
19616 X  unsigned char aap;
19617 X  const unsigned char *ap0, *ap1;
19618 X  int *rp, *rpmax;
19619 X  
19620 X  /* don't fill in the ends */
19621 X
19622 X  rpmax = &a_res.res[a_res.nres];              /* end of alignment info */
19623 X
19624 X  if (pst.ext_sq_set) {sq = pst.sqx;}
19625 X  else {sq = pst.sq;}
19626 X
19627 X  /* res[0] has start of protein sequence */
19628 X  /* res[1] has start of translated DNA sequence */
19629 X
19630 #ifndef TFAST
19631 X  ap0 = f_str->aa0v;           /* computed codons -> ap0*/
19632 X  ap1 = aa1;                   /* protein sequence -> ap1 */
19633 X  aln->smin1 = a_res.min0;     /* start in protein sequence */
19634 X  aln->smin0= a_res.min1;              /* start in DNA/codon sequence */
19635 #else   /* TFASTYZ */
19636 X  ap0 = f_str->aa1v;           /* computed codons -> ap0*/
19637 X  ap1 = aa0;                   /* protein sequence */
19638 X  aln->smin0 = a_res.min0;     /* start in protein sequence */
19639 X  aln->smin1 = a_res.min1;             /* start in codon sequence */
19640 #endif
19641 X
19642 X  rp = a_res.res;                      /* start of alignment info */
19643 X
19644 X
19645 /* now get the middle */
19646 X  spa = seqca;
19647 X  sp0a = seqc0a;
19648 #ifndef TFAST
19649 X  sp0 = seqc0;         /* sp0/seqc0 is codon sequence */
19650 X  sp1 = seqc1;         /* sp1/seqc1 is protein sequence */
19651 #else
19652 X  sp1 = seqc0;         /* sp1/seqc0 is protein sequence */
19653 X  sp0 = seqc1;         /* sp0/seqc1 is codon sequence */
19654 #endif
19655 X
19656 X  lenc = not_c = aln->nident = aln->nsim = ngap_d = ngap_p = nfs = 0;
19657 X  i0 = a_res.min1-3;   /* start of codon sequence */
19658 X  i1 = a_res.min0;     /* start of protein sequence */
19659 X
19660 X  while (rp < rpmax ) {
19661 X    switch (*rp++) {
19662 X    case 3:            /* match */
19663 X      i0 += 3;
19664 X      *sp0a++ = ' ';
19665 X      *sp1 = sq[aap=ap1[i1++]];
19666 X      *sp0 = f_str->weight_c[aap][ap0[i0]].c5;
19667 X
19668 X      if ((itmp=pst.pam2[0][aap][pascii[*sp0]])<0) { *spa = M_NEG; }
19669 X      else if (itmp == 0) { *spa = M_ZERO;}
19670 X      else {*spa = M_POS;}
19671 X      if (*spa == M_ZERO || *spa == M_POS) { aln->nsim++;}
19672 X
19673 X      if (toupper(*sp0) == toupper(*sp1)) {aln->nident++; *spa = M_IDENT;}
19674 X      sp0++; sp1++; spa++;
19675 X      lenc++;
19676 X      break;
19677 X    case 2:            /* frame shift +2, then match */
19678 X      nfs++;
19679 X      i0 += 2;
19680 X      *sp0a++ = ' ';
19681 X      *sp0++ = '/';
19682 X      *sp1++ = '-';
19683 X      *spa++ = M_DEL;
19684 X      not_c++;
19685 X
19686 #ifndef TFAST
19687 X      *sp0a++ = ' ';
19688 #else
19689 X      *sp0a++ = ann_arr[aa0a[i1]];
19690 #endif
19691 X      *sp1 = sq[aap=ap1[i1++]];
19692 X      *sp0 = f_str->weight_c[aap][ap0[i0]].c2;
19693 X      if ((itmp=pst.pam2[0][aap][pascii[*sp0]])<0) { *spa = M_NEG; }
19694 X      else if (itmp == 0) { *spa = M_ZERO;}
19695 X      else {*spa = M_POS;}
19696 X      if (*spa == M_ZERO || *spa == M_POS) { aln->nsim++;}
19697 X
19698 X      if (toupper(*sp0) == toupper(*sp1)) {aln->nident++; *spa = M_IDENT;}
19699 X      sp0++; sp1++; spa++;
19700 X      lenc++;
19701 X      break;
19702 X    case 4:            /* frame shift, -1, then match */
19703 X      nfs++;
19704 X      i0 += 4;
19705 #ifndef TFAST
19706 X      *sp0a++ = ' ';
19707 #else
19708 X      *sp0a++ = ann_arr[aa0a[i1]];
19709 #endif
19710 X      *sp0++ = '\\';
19711 X      *sp1++ = '-';
19712 X      *spa++ = M_DEL;
19713 X      not_c++;
19714 X      *sp1 = sq[aap=ap1[i1++]];
19715 X      *sp0 = f_str->weight_c[aap][ap0[i0]].c4;
19716 X      if ((itmp=pst.pam2[0][aap][pascii[*sp0]])<0) { *spa = M_NEG; }
19717 X      else if (itmp == 0) { *spa = M_ZERO;}
19718 X      else {*spa = M_POS;}
19719 X      if (*spa == M_ZERO || *spa == M_POS) { aln->nsim++;}
19720 X
19721 X      if (toupper(*sp0) == toupper(*sp1)) {aln->nident++; *spa = M_IDENT;}
19722 X      sp0++; sp1++; spa++;
19723 X      lenc++;
19724 X      break;
19725 X    case 5:            /* insertion in 1 */
19726 X      i0 += 3;
19727 X      *sp0++ = f_str->weight_c[0][ap0[i0]].c3;
19728 X      *sp1++ = '-';
19729 X      *spa++ = M_DEL;
19730 X      *sp0a++ = ' ';
19731 X      lenc++;
19732 X      ngap_p++;
19733 X      break;
19734 X    case 0:            /* insertion in 0 */
19735 X      *sp0++ = '-';
19736 #ifndef TFAST
19737 X      *sp0a++ = ' ';
19738 #else
19739 X      *sp0a++ = ann_arr[aa0a[i1]];
19740 #endif
19741 X      *sp1++ = sq[ap1[i1++]];
19742 X      *spa++ = M_DEL;
19743 X      lenc++;
19744 X      ngap_d++;
19745 X      break;
19746 X    }
19747 X  }
19748 X
19749 X  *sp0a = *spa = '\0';
19750 X
19751 #ifndef TFAST
19752 X  aln->amax0 = i0+3;   /* end of codon sequence */
19753 X  aln->amax1 = i1;     /* end of protein sequence */
19754 X  aln->ngap_q = ngap_d;
19755 X  aln->ngap_l = ngap_p;
19756 #else
19757 X  aln->amax1 = i0+3;   /* end of codon sequence */
19758 X  aln->amax0 = i1;     /* end of protein sequence */
19759 X  aln->ngap_q = ngap_p;
19760 X  aln->ngap_l = ngap_d;
19761 #endif
19762 X  aln->nfs = nfs;
19763 X  aln->amin0 = aln->smin0;
19764 X  aln->amin1 = aln->smin1;
19765 X
19766 X  if (lenc < 0) lenc = 1;
19767 X
19768 X  *nc = lenc;
19769 /*      now we have the middle, get the right end */
19770 X
19771 X  return lenc+not_c;
19772 }
19773 X
19774 void
19775 update_code(char *al_str, int al_str_max, int op, int op_cnt, char *op_char) {
19776 X
19777 X  char tmp_cnt[20];
19778 X
19779 X  sprintf(tmp_cnt,"%c%d",op_char[op],op_cnt);
19780 X  strncat(al_str,tmp_cnt,al_str_max);
19781 }
19782 X
19783 /* build an array of match/ins/del - length strings */
19784 int calc_code(const unsigned char *aa0, int n0,
19785 X             const unsigned char *aa1, int n1,
19786 X             struct a_struct *aln,
19787 X             struct a_res_str a_res,
19788 X             struct pstruct pst,
19789 X             char *al_str, int al_str_n, struct f_struct *f_str)
19790 {
19791 X  int i0, i1;
19792 X  int lenc, not_c, itmp, ngap_d, ngap_p, nfs;
19793 X  int op, op_cnt;
19794 X  char sp0, sp1, op_char[10];
19795 X  unsigned char aap;
19796 X  const unsigned char *ap0, *ap1;
19797 X  int *rp, *rpmax;
19798 X  
19799 X  /* don't fill in the ends */
19800 X
19801 #ifndef TFAST
19802 X  strncpy(op_char,"- /=\\+*",sizeof(op_char));
19803 X  ap0 = f_str->aa0v;           /* computed codons -> ap0*/
19804 X  ap1 = aa1;                   /* protein sequence -> ap1 */
19805 X  aln->smin1 = a_res.min0;     /* start in protein sequence */
19806 X  aln->smin0= a_res.min1;              /* start in DNA/codon sequence */
19807 #else   /* TFASTYZ */
19808 X  strncpy(op_char,"+ /=\\-*",sizeof(op_char));
19809 X  ap0 = f_str->aa1v;           /* computed codons -> ap0*/
19810 X  ap1 = aa0;                   /* protein sequence */
19811 X  aln->smin0 = a_res.min0;     /* start in protein sequence */
19812 X  aln->smin1 = a_res.min1;             /* start in codon sequence */
19813 #endif
19814 X
19815 X  rp = a_res.res;                      /* start of alignment info */
19816 X  rpmax = &a_res.res[a_res.nres];              /* end of alignment info */
19817 X
19818 /* now get the middle */
19819 X
19820 X  lenc = not_c = aln->nident = aln->nsim = ngap_d = ngap_p = nfs = 0;
19821 X  op_cnt = 0;
19822 X  op = 3;
19823 X
19824 X  i0 = a_res.min1-3;   /* start of codon sequence */
19825 X  i1 = a_res.min0;     /* start of protein sequence */
19826 X
19827 X  while (rp < rpmax ) {
19828 X    switch (*rp++) {
19829 X    case 3:                    /* match */
19830 X      sp1 = pst.sq[aap=ap1[i1++]];
19831 X      i0 += 3;
19832 X      sp0 = f_str->weight_c[aap][ap0[i0]].c5;
19833 X      if (pst.pam2[0][aap][pascii[sp0]]>=0) { aln->nsim++; }
19834 X
19835 X      if (op == 3 || op == 6) {
19836 X       if (sp0 != '*' && sp1 != '*') {
19837 X         if (op == 6 ) {
19838 X           update_code(al_str, al_str_n-strlen(al_str),op, op_cnt,op_char);
19839 X           op_cnt = 1; op = 3;
19840 X         }
19841 X         else {op_cnt++;}
19842 X       }
19843 X       else {
19844 X         update_code(al_str, al_str_n-strlen(al_str),op, op_cnt,op_char);
19845 X         op_cnt = 1; op = 6;
19846 X       }
19847 X      }
19848 X      else {
19849 X       update_code(al_str, al_str_n-strlen(al_str),op, op_cnt, op_char);
19850 X       op_cnt = 1; op = 3;
19851 X      }
19852 X      if (sp0 == sp1) aln->nident++;
19853 X      lenc++;
19854 X      break;
19855 X    case 2:                    /* -1 frame shift */
19856 X      update_code(al_str, al_str_n-strlen(al_str),op, op_cnt, op_char);
19857 X      op = 2; op_cnt = 1;
19858 X      update_code(al_str, al_str_n-strlen(al_str),op, op_cnt, op_char);
19859 X      op = 3; op_cnt = 1;
19860 X
19861 X      nfs++;
19862 X      i0 += 2;
19863 X      not_c++;
19864 X      sp1 = pst.sq[aap=ap1[i1++]];
19865 X      sp0 = f_str->weight_c[aap][ap0[i0]].c2;
19866 X      if (pst.pam2[0][aap][pascii[sp0]]>=0) { aln->nsim++; }
19867 X      if (sp0 == sp1) aln->nident++;
19868 X      lenc++;
19869 X      break;
19870 X    case 4:            /* +1 frame shift */
19871 X      update_code(al_str, al_str_n-strlen(al_str),op, op_cnt, op_char);
19872 X      op = 4; op_cnt = 1;
19873 X      update_code(al_str, al_str_n-strlen(al_str),op, op_cnt, op_char);
19874 X      op = 3; op_cnt = 1;
19875 X
19876 X      nfs++;
19877 X      i0 += 4;
19878 X      not_c++;
19879 X      sp1 = pst.sq[aap=ap1[i1++]];
19880 X      sp0 = f_str->weight_c[aap][ap0[i0]].c4;
19881 X      if (pst.pam2[0][aap][pascii[sp0]]>=0) { aln->nsim++; }
19882 X      if (sp0 == sp1) aln->nident++;
19883 X      lenc++;
19884 X      break;
19885 X    case 5:            /* insert in 1 */
19886 X      if (op == 5) op_cnt++;
19887 X      else {
19888 X       update_code(al_str, al_str_n-strlen(al_str),op, op_cnt, op_char);
19889 X       op = 5; op_cnt = 1;
19890 X      }
19891 X
19892 X      i0 += 3;
19893 X      lenc++;
19894 X      ngap_p++;
19895 X      break;
19896 X    case 0:            /* insert in 0 */
19897 X      if (op == 0) op_cnt++;
19898 X      else {
19899 X       update_code(al_str, al_str_n-strlen(al_str),op, op_cnt, op_char);
19900 X       op = 0; op_cnt = 1;
19901 X      }
19902 X
19903 X      i1++;
19904 X      lenc++;
19905 X      ngap_d++;
19906 X      break;
19907 X    }
19908 X  }
19909 X
19910 X  update_code(al_str, al_str_n-strlen(al_str),op, op_cnt, op_char);
19911 X
19912 #ifndef TFAST
19913 X  aln->amax0 = i0+3;   /* end of codon sequence */
19914 X  aln->amax1 = i1;     /* end of protein sequence */
19915 X  aln->ngap_q = ngap_d;
19916 X  aln->ngap_l = ngap_p;
19917 #else
19918 X  aln->amax1 = i0+3;   /* end of codon sequence */
19919 X  aln->amax0 = i1;     /* end of protein sequence */
19920 X  aln->ngap_q = ngap_p;
19921 X  aln->ngap_l = ngap_d;
19922 #endif
19923 X  aln->nfs = nfs;
19924 X  aln->amin0 = aln->smin0;
19925 X  aln->amin1 = aln->smin1;
19926 X
19927 X  if (lenc < 0) lenc = 1;
19928 X
19929 /*      now we have the middle, get the right end */
19930 X
19931 X  return lenc;
19932 }
19933 X
19934 int calc_id(const unsigned char *aa0, int n0,
19935 X           const unsigned char *aa1, int n1,
19936 X           struct a_struct *aln, 
19937 X           struct a_res_str a_res, 
19938 X           struct pstruct pst,
19939 X           struct f_struct *f_str)
19940 {
19941 X  int i0, i1;
19942 X  int lenc, not_c, itmp, ngap_d, ngap_p, nfs;
19943 X  char sp0, sp1;
19944 X  unsigned char aap;
19945 X  const unsigned char *ap0, *ap1;
19946 X  int *rp, *rpmax;
19947 X  
19948 X  /* don't fill in the ends */
19949 X
19950 #ifndef TFAST   /* FASTYZ */
19951 X  ap0 = f_str->aa0v;           /* computed codons -> ap0*/
19952 X  ap1 = aa1;                   /* protein sequence -> ap1 */
19953 X  aln->smin1 = a_res.min0;     /* start in protein sequence */
19954 X  aln->smin0 = a_res.min1;             /* start in DNA/codon sequence */
19955 #else   /* TFASTYZ */
19956 X  ap0 = f_str->aa1v;           /* computed codons -> ap0*/
19957 X  ap1 = aa0;                   /* protein sequence */
19958 X  aln->smin0 = a_res.min0;     /* start in protein sequence */
19959 X  aln->smin1 = a_res.min1;             /* start in codon sequence */
19960 #endif
19961 X
19962 X  rp = a_res.res;                      /* start of alignment info */
19963 X  rpmax = &a_res.res[a_res.nres];              /* end of alignment info */
19964 X
19965 /* now get the middle */
19966 X
19967 X  lenc = not_c = aln->nident = aln->nsim = ngap_d = ngap_p = nfs = 0;
19968 X  i0 = a_res.min1-3;   /* start of codon sequence */
19969 X  i1 = a_res.min0;     /* start of protein sequence */
19970 X
19971 X  while (rp < rpmax ) {
19972 X    switch (*rp++) {
19973 X    case 3:
19974 X      i0 += 3;
19975 X      sp1 = pst.sq[aap=ap1[i1++]];
19976 X      sp0 = f_str->weight_c[aap][ap0[i0]].c5;
19977 X      if (pst.pam2[0][aap][pascii[sp0]]>=0) { aln->nsim++; }
19978 X      if (sp0 == sp1) aln->nident++;
19979 X      lenc++;
19980 X      break;
19981 X    case 2:
19982 X      nfs++;
19983 X      i0 += 2;
19984 X      not_c++;
19985 X      sp1 = pst.sq[aap=ap1[i1++]];
19986 X      sp0 = f_str->weight_c[aap][ap0[i0]].c2;
19987 X      if (pst.pam2[0][aap][pascii[sp0]]>=0) { aln->nsim++; }
19988 X      if (sp0 == sp1) aln->nident++;
19989 X      lenc++;
19990 X      break;
19991 X    case 4:
19992 X      nfs++;
19993 X      i0 += 4;
19994 X      not_c++;
19995 X      sp1 = pst.sq[aap=ap1[i1++]];
19996 X      sp0 = f_str->weight_c[aap][ap0[i0]].c4;
19997 X      if (pst.pam2[0][aap][pascii[sp0]]>=0) { aln->nsim++; }
19998 X      if (sp0 == sp1) aln->nident++;
19999 X      lenc++;
20000 X      break;
20001 X    case 5:
20002 X      i0 += 3;
20003 X      lenc++;
20004 X      ngap_p++;
20005 X      break;
20006 X    case 0:
20007 X      i1++;
20008 X      lenc++;
20009 X      ngap_d++;
20010 X      break;
20011 X    }
20012 X  }
20013 X
20014 #ifndef TFAST
20015 X  aln->amax0 = i0+3;   /* end of codon sequence */
20016 X  aln->amax1 = i1;     /* end of protein sequence */
20017 X  aln->ngap_q = ngap_d;
20018 X  aln->ngap_l = ngap_p;
20019 #else
20020 X  aln->amax1 = i0+3;   /* end of codon sequence */
20021 X  aln->amax0 = i1;     /* end of protein sequence */
20022 X  aln->ngap_q = ngap_p;
20023 X  aln->ngap_l = ngap_d;
20024 #endif
20025 X  aln->nfs = nfs;
20026 X  aln->amin0 = aln->smin0;
20027 X  aln->amin1 = aln->smin1;
20028 X
20029 X  if (lenc < 0) lenc = 1;
20030 X
20031 /*      now we have the middle, get the right end */
20032 X
20033 X  return lenc;
20034 }
20035 X
20036 #ifdef PCOMPLIB
20037 #include "p_mw.h"
20038 void
20039 update_params(struct qmng_str *qm_msg, struct pstruct *ppst)
20040 {
20041 X  ppst->n0 = qm_msg->n0;
20042 }
20043 #endif
20044 SHAR_EOF
20045 chmod 0644 dropfz2.c ||
20046 echo 'restore of dropfz2.c failed'
20047 Wc_c="`wc -c < 'dropfz2.c'`"
20048 test 77360 -eq "$Wc_c" ||
20049         echo 'dropfz2.c: original size 77360, current size' "$Wc_c"
20050 fi
20051 # ============= dropgsw.c ==============
20052 if test -f 'dropgsw.c' -a X"$1" != X"-c"; then
20053         echo 'x - skipping dropgsw.c (File already exists)'
20054 else
20055 echo 'x - extracting dropgsw.c (Text)'
20056 sed 's/^X//' << 'SHAR_EOF' > 'dropgsw.c' &&
20057 /* copyright (c) 1996 William R. Pearson */
20058 X
20059 /* $Name: fa_34_26_5 $ - $Id: dropgsw.c,v 1.80 2006/10/19 15:12:11 wrp Exp $ */
20060 X
20061 /* 17-Aug-2006 - removed globals *sapp/last - alignment should be thread safe */
20062 X
20063 /* 12-Oct-2005 - converted to use a_res and aln for alignment coordinates */
20064 X
20065 /* 4-Nov-2004 - Diagonal Altivec Smith-Waterman included */
20066 X
20067 /* 14-May-2003 - modified to return alignment start at 0, rather than
20068 X   1, for begin:end alignments
20069 X
20070 X   25-Feb-2003 - modified to support Altivec parallel Smith-Waterman
20071 X
20072 X   22-Sep-2003 - removed Altivec support at request of Sencel lawyers
20073 */
20074 X
20075 /* the do_walign() code in this file is not thread_safe */
20076 /* init_work(), do_work(), are thread safe */
20077 X
20078 /* this code uses an implementation of the Smith-Waterman algorithm
20079 X   designed by Phil Green, U. of Washington, that is 1.5 - 2X faster
20080 X   than my Miller and Myers implementation. */
20081 X
20082 /* the shortcuts used in this program prevent it from calculating scores
20083 X   that are less than the gap penalty for the first residue in a gap. As
20084 X   a result this code cannot be used with very large gap penalties, or
20085 X   with very short sequences, and probably should not be used with prss3.
20086 */
20087 X
20088 /* version 3.2 fixes a subtle bug that was encountered while running
20089 X   do_walign() interspersed with do_work().  This happens only with -m
20090 X   9 and pvcomplib.  The fix was to more explicitly zero-out ss[] at
20091 X   the beginning of do_work.
20092 */
20093 X
20094 #include <stdio.h>
20095 #include <stdlib.h>
20096 #include <string.h>
20097 #include <ctype.h>
20098 #include <math.h>
20099 X
20100 #include "defs.h"
20101 #include "param.h"
20102 X
20103 static char *verstr="5.5 Sept 2006";
20104 X
20105 #include "dropgsw.h"
20106 X
20107 #define DROP_INTERN
20108 #include "drop_func.h"
20109 X
20110 #ifdef SW_ALTIVEC
20111 #include "smith_waterman_altivec.h"
20112 #endif
20113 #ifdef SW_SSE2
20114 #include "smith_waterman_sse2.h"
20115 #endif
20116 X
20117 struct swstr {int H, E;};
20118 X
20119 extern void init_karlin(const unsigned char *aa0, int n0, struct pstruct *ppst,
20120 X                       double *aa0_f, double **kp);
20121 extern int do_karlin(const unsigned char *aa1, int n1,
20122 X                    int **pam2, struct pstruct *ppst,
20123 X                    double *aa0_f, double *kar_p, double *lambda, double *H);
20124 X
20125 static int
20126 ALIGN(const unsigned char *A, const unsigned char *B,
20127 X      int M, int N,
20128 X      int **W, int IW, int G, int H, int *res, int *nres,
20129 X      struct f_struct *f_str);
20130 X
20131 static int
20132 FLOCAL_ALIGN(const unsigned char *aa0, const unsigned char *aa1,
20133 X            int n0, int n1, int low, int up,
20134 X            int **W, int GG,int HH, int MW,
20135 X            struct f_struct *f_str);
20136 X
20137 static 
20138 void DISPLAY(const unsigned char *A, const unsigned char *B, 
20139 X            int M, int N,
20140 X            int *S, int AP, int BP, char *sq);
20141 X
20142 extern void aancpy(char *to, char *from, int count, struct pstruct pst);
20143 X
20144 /* initialize for Smith-Waterman optimal score */
20145 X
20146 void
20147 init_work (unsigned char *aa0, int n0,
20148 X          struct pstruct *ppst,
20149 X          struct f_struct **f_arg)
20150 {
20151 X  int maxn0, ip;
20152 X  int *pwaa_s, *pwaa_a;
20153 X  int e, f, i, j, l;
20154 X  int *res;
20155 X  struct f_struct *f_str;
20156 X  int **pam2p;
20157 X  struct swstr *ss;
20158 X  int nsq;
20159 X
20160 #if defined(SW_ALTIVEC) || defined(SW_SSE2)
20161 X  int data,bias;
20162 X  unsigned char *  pc;
20163 X  unsigned short * ps;
20164 X  int  overflow;
20165 X
20166 X  int n_count;
20167 X  int col_len;
20168 #endif
20169 X  
20170 X  if (ppst->ext_sq_set) {
20171 X    nsq = ppst->nsqx; ip = 1;
20172 X  }
20173 X  else {
20174 X    nsq = ppst->nsq; ip = 0;
20175 X  }
20176 X
20177 X  /* allocate space for function globals */
20178 X
20179 X   f_str = (struct f_struct *)calloc(1,sizeof(struct f_struct));
20180 X
20181 X   if(ppst->zsflag == 6 || ppst->zsflag == 16) {
20182 X     f_str->kar_p = NULL;
20183 X     init_karlin(aa0, n0, ppst, &f_str->aa0_f[0], &f_str->kar_p);
20184 X   }
20185 X  
20186 X   /* allocate space for the scoring arrays */
20187 X   if ((ss = (struct swstr *) calloc (n0+2, sizeof (struct swstr)))
20188 X       == NULL) {
20189 X     fprintf (stderr, "cannot allocate ss array %3d\n", n0);
20190 X     exit (1);
20191 X   }
20192 X   ss++;
20193 X
20194 X   ss[n0].H = -1;      /* this is used as a sentinel - normally H >= 0 */
20195 X   ss[n0].E = 1;
20196 X   f_str->ss = ss;
20197 X
20198 X   /* initialize variable (-S) pam matrix */
20199 X   if ((f_str->waa_s= (int *)calloc((nsq+1)*(n0+1),sizeof(int))) == NULL) {
20200 X     fprintf(stderr,"cannot allocate waa_s array %3d\n",nsq*n0);
20201 X     exit(1);
20202 X   }
20203 X
20204 X   /* initialize pam2p[1] pointers */
20205 X   if ((f_str->pam2p[1]= (int **)calloc((n0+1),sizeof(int *))) == NULL) {
20206 X     fprintf(stderr,"cannot allocate pam2p[1] array %3d\n",n0);
20207 X     exit(1);
20208 X   }
20209 X
20210 X   pam2p = f_str->pam2p[1];
20211 X   if ((pam2p[0]=(int *)calloc((nsq+1)*(n0+1),sizeof(int))) == NULL) {
20212 X     fprintf(stderr,"cannot allocate pam2p[1][] array %3d\n",nsq*n0);
20213 X     exit(1);
20214 X   }
20215 X
20216 X   for (i=1; i<n0; i++) {
20217 X     pam2p[i]= pam2p[0] + (i*(nsq+1));
20218 X   }
20219 X
20220 X   /* initialize universal (alignment) matrix */
20221 X   if ((f_str->waa_a= (int *)calloc((nsq+1)*(n0+1),sizeof(int))) == NULL) {
20222 X     fprintf(stderr,"cannot allocate waa_a struct %3d\n",nsq*n0);
20223 X     exit(1);
20224 X   }
20225 X   
20226 X   /* initialize pam2p[0] pointers */
20227 X   if ((f_str->pam2p[0]= (int **)calloc((n0+1),sizeof(int *))) == NULL) {
20228 X     fprintf(stderr,"cannot allocate pam2p[1] array %3d\n",n0);
20229 X     exit(1);
20230 X   }
20231 X
20232 X   pam2p = f_str->pam2p[0];
20233 X   if ((pam2p[0]=(int *)calloc((nsq+1)*(n0+1),sizeof(int))) == NULL) {
20234 X     fprintf(stderr,"cannot allocate pam2p[1][] array %3d\n",nsq*n0);
20235 X     exit(1);
20236 X   }
20237 X
20238 X   for (i=1; i<n0; i++) {
20239 X     pam2p[i]= pam2p[0] + (i*(nsq+1));
20240 X   }
20241 X
20242 X   /* 
20243 X      pwaa effectively has a sequence profile --
20244 X       pwaa[0..n0-1] has pam score for residue 0 (-BIGNUM)
20245 X       pwaa[n0..2n0-1] has pam scores for residue 1 (A)
20246 X       pwaa[2n0..3n-1] has pam scores for residue 2 (R), ...
20247 X
20248 X       thus: pwaa = f_str->waa_s + (*aa1p++)*n0; sets up pwaa so that
20249 X       *pwaa++ rapidly moves though the scores of the aa1p[] position
20250 X       without further indexing
20251 X
20252 X       For a real sequence profile, pwaa[0..n0-1] vs ['A'] could have
20253 X       a different score in each position.
20254 X   */
20255 X
20256 X   if (ppst->pam_pssm) {
20257 X     pwaa_s = f_str->waa_s;
20258 X     pwaa_a = f_str->waa_a;
20259 X     for (e = 0; e <=nsq; e++) {       /* for each residue in the alphabet */
20260 X       for (f = 0; f < n0; f++) {      /* for each position in aa0 */
20261 X        *pwaa_s++ = f_str->pam2p[ip][f][e] = ppst->pam2p[ip][f][e];
20262 X        *pwaa_a++ = f_str->pam2p[0][f][e]  = ppst->pam2p[0][f][e];
20263 X       }
20264 X     }
20265 X   }
20266 X   else {      /* initialize scanning matrix */
20267 X     pwaa_s = f_str->waa_s;
20268 X     pwaa_a = f_str->waa_a;
20269 X     for (e = 0; e <=nsq; e++) /* for each residue in the alphabet */
20270 X       for (f = 0; f < n0; f++)        {       /* for each position in aa0 */
20271 X        *pwaa_s++ = f_str->pam2p[ip][f][e]= ppst->pam2[ip][aa0[f]][e];
20272 X        *pwaa_a++ = f_str->pam2p[0][f][e] = ppst->pam2[0][aa0[f]][e];
20273 X       }
20274 X   }
20275 X
20276 #if defined(SW_ALTIVEC)
20277 X
20278 X   /* First we allocate memory for the workspace - i.e. the single row
20279 X    * of storage for H/F. Since this might be run on Linux or AIX too,
20280 X    * we don't assume anything about the memory allocation but align
20281 X    * it ourselves.  We need two vectors (16 bytes each) per element,
20282 X    * and some padding space to make it cache-line aligned.
20283 X
20284 X    * MAXTST+MAXLIB is longest allowed database sequence length...
20285 X    * this should be m_msg.max_tot, but m_msg is not available, but
20286 X    * ppst->maxlen has maxn, which is appropriate.
20287 X    */
20288 X
20289 X     f_str->workspace_memory  = (void *)malloc(2*16*(ppst->maxlen+SEQ_PAD)+256);
20290 X     f_str->workspace  = (void *) ((((size_t) f_str->workspace_memory) + 255) & (~0xff));
20291 X
20292 X   
20293 X
20294 X   /* We always use a scoring profile in altivec, but the layout is a bit strange 
20295 X    * in order to optimize memory access order and thus cache efficiency.
20296 X    * Normally we first try 8-bit scoring in altivec, and if this leads to overflow
20297 X    * we recompute the score with 16-bit accuracy. Because of this we need to construct
20298 X    * two score profiles.
20299 X    * Since altivec always loads 16 bytes from aligned memory, corresponding to 8 or 16 
20300 X    * elements (for 16 and 8 bit scoring, respectively), we organize the scoring 
20301 X    * profile like this for 8-bit accuracy:
20302 X    *
20303 X    * 1. The profile starts on 256-byte aligned memory (cache line on G5 is 128 bytes).
20304 X    * 2. First we have the score for the full alphabet for the first 16 residues of
20305 X    *    the query, i.e. positions 0-15 are the scores for the first 16 query letters
20306 X    *    vs. the first in the alphabet, positions 16-31 the scores for the same 16
20307 X    *    query positions against alphabet letter two, etc.
20308 X    * 3. After alphabet_size*16bytes we start with the scores for residues 16-31 in
20309 X    *    the query, organized in the same way.
20310 X    * 4. At the end of the query sequence, we pad the scoring to the next 16-tuple
20311 X    *    with neutral scores.
20312 X    * 5. The total size of the profile is thus alphabet_size*N, where N is the 
20313 X    *    size of the query rounded up to the next 16-tuple.
20314 X    *
20315 X    * The word (16-bit) profile is identical, but scores are stored as 8-tuples.
20316 X    */
20317 X
20318 X   f_str->word_score_memory = (void *)malloc(10*2*(nsq+2)*(n0+1+16)+256);
20319 X   f_str->byte_score_memory = (void *)malloc(10*(nsq+2)*(n0+1+16)+256);
20320 X
20321 X   f_str->word_score = (unsigned short *) ((((size_t) f_str->word_score_memory) + 255) & (~0xff));
20322 X   f_str->byte_score = (unsigned char *) ((((size_t) f_str->byte_score_memory) + 255) & (~0xff));
20323 X
20324 X   overflow = 0;
20325 X
20326 X   if (ppst->pam_pssm) {
20327 X     /* Use a position-specific scoring profile. 
20328 X      * This is essentially what we are going to construct anyway, but we'll
20329 X      * reorder it to suit altivec.
20330 X      */       
20331 X     bias = 127;
20332 X     for(i = 1; i <= nsq ; i++) {
20333 X        for(j = 0; j < n0 ; j++) {
20334 X            data = ppst->pam2p[ip][j][i];
20335 X            if(data<bias) bias = data;
20336 X           }
20337 X       }
20338 X
20339 X     /* Fill our specially organized byte- and word-size scoring arrays. */
20340 X     ps = f_str->word_score;
20341 X     for(f = 0; f<n0 ; f+=8) {
20342 X       /* e=0 */
20343 X       for(i=0 ; i<8 ; i++) {
20344 X        *ps++ = (unsigned short) 0;
20345 X       }
20346 X       /* for each chunk of 8 residues in our query */
20347 X       for(e = 1; e<=nsq; e++) {
20348 X        for(i=0 ; i<8 ; i++) {
20349 X          l = f + i;
20350 X          if(l<n0) {
20351 X            data = ppst->pam2p[ip][l][e] - bias;
20352 X          }
20353 X          else {
20354 X            data = 0;
20355 X          }
20356 X          *ps++ = (unsigned short)data;
20357 X        }
20358 X       }
20359 X     }
20360 X     pc = f_str->byte_score;
20361 X     for(f = 0; f<n0 ; f+=16) {
20362 X       /* e=0 */
20363 X       for(i=0 ; i<16 ; i++) {
20364 X        *pc++ = (unsigned char)0;
20365 X       }       
20366 X           
20367 X       for(e = 1; e<=nsq; e++) {
20368 X        for(i=0 ; i<16 ; i++) {
20369 X          l = f + i;
20370 X          if(l<n0) {
20371 X            data = ppst->pam2p[ip][l][e] - bias;
20372 X          }
20373 X          else {
20374 X            data = 0;
20375 X          }
20376 X          if(data>255) {
20377 X            /*
20378 X            printf("Fatal error. data: %d bias: %d, position: %d/%d, Score out of range for 8-bit Altivec/VMX datatype.\n",data,bias,l,e);
20379 X            exit(1);
20380 X            */
20381 X            overflow = 1;
20382 X          }
20383 X          *pc++ = (unsigned char)data;
20384 X        }
20385 X       }
20386 X     }
20387 X   }
20388 X   else {
20389 X     /* Classical simple substitution matrix */
20390 X     /* Find the bias to use in the substitution matrix */
20391 X     bias = 127;
20392 X     for(i = 1; i <= nsq ; i++) {
20393 X       for(j = 1; j <= nsq ; j++) {
20394 X        data = ppst->pam2[ip][i][j];
20395 X        if(data<bias) bias = data;
20396 X       }
20397 X     }
20398 X     /* Fill our specially organized byte- and word-size scoring arrays. */
20399 X     ps = f_str->word_score;
20400 X     for(f = 0; f<n0 ; f+=8) {
20401 X       /* e=0 */
20402 X       for(i=0 ; i<8 ; i++) {
20403 X        *ps++ = (unsigned short) 0;
20404 X       }       
20405 X       /* for each chunk of 8 residues in our query */
20406 X       for(e = 1; e<=nsq; e++) {
20407 X        for(i=0 ; i<8 ; i++) {
20408 X          l = f + i;
20409 X          if(l<n0) {
20410 X            data = ppst->pam2[ip][aa0[l]][e] - bias;
20411 X          }
20412 X          else {
20413 X            data = 0;
20414 X          }
20415 X          *ps++ = (unsigned short)data;
20416 X        }
20417 X       }
20418 X     }
20419 X     pc = f_str->byte_score;
20420 X     for(f = 0; f<n0 ; f+=16) {
20421 X       /* e=0 */
20422 X       for(i=0 ; i<16 ; i++) {
20423 X        *pc++ = (unsigned char)0;
20424 X       }
20425 X           
20426 X       for(e = 1; e<=nsq; e++) {
20427 X        for(i=0 ; i<16 ; i++) {
20428 X          l = f + i;
20429 X          if (l<n0) {
20430 X            data = ppst->pam2[ip][aa0[l]][e] - bias;
20431 X          }
20432 X          else {
20433 X            data = 0;
20434 X          }
20435 X          if(data>255) {
20436 X            /*
20437 X            printf("Fatal error. Score out of range for 8-bit Altivec/VMX datatype.\n");
20438 X            exit(1);
20439 X            */
20440 X            overflow = 1;
20441 X          }
20442 X          *pc++ = (unsigned char)data;
20443 X        }
20444 X       }
20445 X     }
20446 X   }
20447 X       
20448 X   f_str->bias = (unsigned char) (-bias);
20449 X   f_str->alphabet_size = nsq+1;
20450 X
20451 X   /* Some variable to keep track of how many 8-bit runs we need to rerun
20452 X    * in 16-bit accuracy. If there are too many reruns it can be faster
20453 X    * to use 16-bit alignments directly. 
20454 X    */
20455 X   
20456 X   /* We can only do 8-bit alignments if the scores were small enough. */
20457 X   if(overflow==0) f_str->try_8bit   = 1;
20458 X   else f_str->try_8bit   = 0;
20459 X
20460 X   f_str->done_8bit  = 0;
20461 X   f_str->done_16bit = 0;
20462 X       
20463 #endif /* SW_ALTIVEC */
20464 X
20465 #if defined(SW_SSE2)
20466 X   /* First we allocate memory for the workspace - i.e. two rows for H and
20467 X    * one row for F.  We also need enough space to hold a temporary
20468 X    * scoring profile which will be query_length * 16 (sse2 word length).
20469 X    * Since this might be run on Linux or AIX too, we don't assume 
20470 X    * anything about the memory allocation but align it ourselves.
20471 X    */
20472 X    f_str->workspace_memory  = (void *)malloc(3*16*(MAXTST+MAXLIB+32)+256);
20473 X    f_str->workspace  = (void *) ((((size_t) f_str->workspace_memory) + 255) & (~0xff));
20474 X
20475 X   /* We always use a scoring profile for the SSE2 implementation, but the layout
20476 X    * is a bit strange.  The scoring profile is parallel to the query, but is
20477 X    * accessed in a stripped pattern.  The query is divided into equal length
20478 X    * segments.  The number of segments is equal to the number of elements
20479 X    * processed in the SSE2 register.  For 8-bit calculations, the query will
20480 X    * be divided into 16 equal length parts.  If the query is not long enough
20481 X    * to fill the last segment, it will be filled with neutral weights.  The
20482 X    * first element in the SSE register will hold a value from the first segment,
20483 X    * the second element of the SSE register will hold a value from the
20484 X    * second segment and so on.  So if the query length is 288, then each
20485 X    * segment will have a length of 18.  So the first 16 bytes will  have
20486 X    * the following weights: Q1, Q19, Q37, ... Q271; the next 16 bytes will
20487 X    * have the following weights: Q2, Q20, Q38, ... Q272; and so on until
20488 X    * all parts of all segments have been written.  The last seqment will
20489 X    * have the following weights: Q18, Q36, Q54, ... Q288.  This will be
20490 X    * done for the entire alphabet.
20491 X    */
20492 X
20493 X    f_str->word_score_memory = (void *)malloc((n0 + 32) * sizeof (short) * (nsq + 1) + 256);
20494 X    f_str->byte_score_memory = (void *)malloc((n0 + 32) * sizeof (char) * (nsq + 1) + 256);
20495 X
20496 X    f_str->word_score = (unsigned short *) ((((size_t) f_str->word_score_memory) + 255) & (~0xff));
20497 X    f_str->byte_score = (unsigned char *) ((((size_t) f_str->byte_score_memory) + 255) & (~0xff));
20498 X
20499 X    overflow = 0;
20500 X
20501 X    if (ppst->pam_pssm) {
20502 X        /* Use a position-specific scoring profile. 
20503 X        * This is essentially what we are going to construct anyway, but we'll
20504 X        * reorder it to suit sse2.
20505 X        */       
20506 X        bias = 127;
20507 X        for (i = 1; i <= nsq ; i++) {
20508 X            for (j = 0; j < n0 ; j++) {
20509 X                data = ppst->pam2p[ip][j][i];
20510 X                if (data < bias) {
20511 X                    bias = data;
20512 X                }
20513 X            }
20514 X        }
20515 X
20516 X        /* Fill our specially organized byte- and word-size scoring arrays. */
20517 X        ps = f_str->word_score;
20518 X        col_len = (n0 + 7) / 8;
20519 X        n_count = (n0 + 7) & 0xfffffff8;
20520 X        for (f = 0; f < n_count; ++f) {
20521 X            *ps++ = 0;
20522 X        }
20523 X        for (f = 1; f <= nsq ; f++) {
20524 X            for (e = 0; e < col_len; e++) {
20525 X                for (i = e; i < n_count; i += col_len) {
20526 X                 if ( i < n0) { data = ppst->pam2p[ip][i][f];}
20527 X                 else {data = 0;}
20528 X                 *ps++ = (unsigned short)data;
20529 X                }
20530 X            }
20531 X        }
20532 X        pc = f_str->byte_score;
20533 X        col_len = (n0 + 15) / 16;
20534 X        n_count = (n0 + 15) & 0xfffffff0;
20535 X        for (f = 0; f < n_count; ++f) {
20536 X            *pc++ = 0;
20537 X        }
20538 X        for (f = 1; f <= nsq ; f++) {
20539 X            for (e = 0; e < col_len; e++) {
20540 X                for (i = e; i < n_count; i += col_len) {
20541 X                 if ( i < n0 ) { data = ppst->pam2p[ip][i][f] - bias;}
20542 X                 else {data = 0 - bias;}
20543 X                 if (data > 255) {
20544 X                   printf("Fatal error. data: %d bias: %d, position: %d/%d, "
20545 X                          "Score out of range for 8-bit SSE2 datatype.\n",
20546 X                          data, bias, f, e);
20547 X                   exit(1);
20548 X                 }
20549 X                 *pc++ = (unsigned char)data;
20550 X               }
20551 X           }
20552 X        }
20553 X    }
20554 X    else 
20555 X    {
20556 X        /* Classical simple substitution matrix */
20557 X        /* Find the bias to use in the substitution matrix */
20558 X        bias = 127;
20559 X        for (i = 1; i <= nsq ; i++) {
20560 X            for (j = 1; j <= nsq ; j++) {
20561 X                data = ppst->pam2[ip][i][j];
20562 X                if (data < bias) {
20563 X                    bias = data;
20564 X                }
20565 X            }
20566 X        }
20567 X
20568 X        /* Fill our specially organized byte- and word-size scoring arrays. */
20569 X        ps = f_str->word_score;
20570 X        col_len = (n0 + 7) / 8;
20571 X        n_count = (n0 + 7) & 0xfffffff8;
20572 X        for (f = 0; f < n_count; ++f) {
20573 X            *ps++ = 0;
20574 X        }
20575 X        for (f = 1; f <= nsq ; f++) {
20576 X            for (e = 0; e < col_len; e++) {
20577 X                for (i = e; i < n_count; i += col_len) {
20578 X                    if (i >= n0) {
20579 X                        data = 0;
20580 X                    } else {
20581 X                        data = ppst->pam2[ip][aa0[i]][f];
20582 X                    }
20583 X                    *ps++ = (unsigned short)data;
20584 X                }
20585 X            }
20586 X        }
20587 X
20588 X        pc = f_str->byte_score;
20589 X        col_len = (n0 + 15) / 16;
20590 X        n_count = (n0 + 15) & 0xfffffff0;
20591 X        for (f = 0; f < n_count; ++f) {
20592 X            *pc++ = 0;
20593 X        }
20594 X        for (f = 1; f <= nsq ; f++) {
20595 X            for (e = 0; e < col_len; e++) {
20596 X                for (i = e; i < n_count; i += col_len) {
20597 X                    if (i >= n0) {
20598 X                        data = -bias;
20599 X                    } else {
20600 X                        data = ppst->pam2[ip][aa0[i]][f] - bias;
20601 X                    }
20602 X                    if (data > 255) {
20603 X                        printf("Fatal error. data: %d bias: %d, position: %d/%d, "
20604 X                               "Score out of range for 8-bit SSE2 datatype.\n",
20605 X                               data, bias, f, e);
20606 X                        exit(1);
20607 X                    }
20608 X                    *pc++ = (unsigned char)data;
20609 X                }
20610 X            }
20611 X        }
20612 X    }
20613 X       
20614 X    f_str->bias = (unsigned char) (-bias);
20615 X    f_str->alphabet_size = nsq+1;
20616 X
20617 X    /* Some variable to keep track of how many 8-bit runs we need to rerun
20618 X     * in 16-bit accuracy. If there are too many reruns it can be faster
20619 X     * to use 16-bit alignments directly. 
20620 X     */
20621 X   
20622 X    /* We can only do 8-bit alignments if the scores were small enough. */
20623 X    f_str->try_8bit = (overflow == 0) ? 1 : 0;
20624 X
20625 X    f_str->done_8bit  = 0;
20626 X    f_str->done_16bit = 0;
20627 #endif /* SW_SSE2 */
20628 X
20629 X   /* these structures are used for producing alignments */
20630 X
20631 X   maxn0 = max(3*n0/2,MIN_RES);                /* minimum allocation for alignment */
20632 X   if ((res = (int *)calloc((size_t)maxn0,sizeof(int)))==NULL) {
20633 X     fprintf(stderr,"cannot allocate alignment results array %d\n",maxn0);
20634 X     exit(1);
20635 X   }
20636 X   f_str->res = res;
20637 X
20638 X
20639 X   *f_arg = f_str;
20640 }
20641 X
20642 void close_work (const unsigned char *aa0, int n0,
20643 X                struct pstruct *ppst,
20644 X                struct f_struct **f_arg)
20645 {
20646 X  struct f_struct *f_str;
20647 X
20648 X  f_str = *f_arg;
20649 X
20650 X  if (f_str != NULL) {
20651 X    if (f_str->kar_p !=NULL) free(f_str->kar_p);
20652 X    f_str->ss--;
20653 X    free(f_str->ss);
20654 X    free(f_str->res);
20655 X    free(f_str->waa_a);
20656 X    free(f_str->pam2p[0][0]);
20657 X    free(f_str->pam2p[0]);
20658 X    free(f_str->waa_s);
20659 X    free(f_str->pam2p[1][0]);
20660 X    free(f_str->pam2p[1]);
20661 X
20662 #if defined(SW_ALTIVEC) || defined(SW_SSE2)
20663 X    free(f_str->workspace_memory);
20664 X    free(f_str->word_score_memory);
20665 X    free(f_str->byte_score_memory);
20666 #endif
20667 X    free(f_str);
20668 X    *f_arg = NULL;
20669 X  }
20670 }
20671 X
20672 X
20673 /* pstring1 is a message to the manager, currently 512 */
20674 /*void get_param(struct pstruct *pstr,char *pstring1)*/
20675 void    get_param (struct pstruct *pstr, char *pstring1, char *pstring2)
20676 {
20677 X  char pg_str[120];
20678 X  char psi_str[120];
20679 X
20680 #if defined(SW_ALTIVEC)
20681 X  strncpy(pg_str,"Smith-Waterman (Altivec/VMX, Erik Lindahl 2004)",sizeof(pg_str));
20682 #endif
20683 #if defined(SW_SSE2)
20684 X  strncpy(pg_str,"Smith-Waterman (SSE2, Michael Farrar 2006)",sizeof(pg_str));
20685 #endif
20686 #if !defined(SW_ALTIVEC) && !defined(SW_SSE2)
20687 X  strncpy(pg_str,"Smith-Waterman (PGopt)",sizeof(pg_str));
20688 #endif
20689 X
20690 X  if (pstr->pam_pssm) { strncpy(psi_str,"-PSI",sizeof(psi_str));}
20691 X  else { psi_str[0]='\0';}
20692 X
20693 #ifdef OLD_FASTA_GAP
20694 X   sprintf (pstring1, " %s (%s) function [%s matrix%s (%d:%d)%s], gap-penalty: %d/%d",
20695 #else
20696 X   sprintf (pstring1, " %s (%s) function [%s matrix%s (%d:%d)%s], open/ext: %d/%d",
20697 #endif
20698 X           pg_str, verstr, pstr->pamfile, psi_str, pstr->pam_h,pstr->pam_l, 
20699 X           (pstr->ext_sq_set)?"xS":"\0", pstr->gdelval, pstr->ggapval);
20700 X   /*
20701 X   if (pstr->zsflag==0) strcat(pstring1," not-scaled\n");
20702 X   else if (pstr->zsflag==1) strcat(pstring1," reg.-scaled");
20703 X   */
20704 X   if (pstring2 != NULL) {
20705 #ifdef OLD_FASTA_GAP
20706 X     sprintf(pstring2,"; pg_name: %s\n; pg_ver: %s\n; pg_matrix: %s (%d:%d)%s\n; pg_gap-pen: %d %d\n",
20707 #else
20708 X     sprintf(pstring2,"; pg_name: %s\n; pg_ver: %s\n; pg_matrix: %s (%d:%d)%s\n; pg_open-ext: %d %d\n",
20709 #endif
20710 X            pg_str,verstr,psi_str,pstr->pam_h,pstr->pam_l, 
20711 X            (pstr->ext_sq_set)?"xS":"\0",pstr->gdelval,pstr->ggapval);
20712 X   }
20713 }
20714 X
20715 void do_work (const unsigned char *aa0, int n0,
20716 X             const unsigned char *aa1, int n1,
20717 X             int frame,
20718 X             struct pstruct *ppst, struct f_struct *f_str,
20719 X             int qr_flg, struct rstruct *rst)
20720 {
20721 X  int     score;
20722 X  double lambda, H;
20723 X  int i;
20724 X  
20725 #ifdef SW_ALTIVEC
20726 X  if(f_str->try_8bit)
20727 X  {
20728 X      score = smith_waterman_altivec_byte(aa0,
20729 X                                          f_str->byte_score,
20730 X                                          n0,
20731 X                                          aa1,
20732 X                                          n1,
20733 X                                          f_str->bias,
20734 #ifndef OLD_FASTA_GAP
20735 X                                          -(ppst->gdelval + ppst->ggapval),
20736 #else
20737 X                                          -ppst->gdelval,
20738 #endif
20739 X                                          -ppst->ggapval,
20740 X                                          f_str);
20741 X      
20742 X      f_str->done_8bit++;
20743 X      
20744 X      if(score>=255)
20745 X      {
20746 X          /* Overflow, so we have to redo it in 16 bits. */
20747 X          score = smith_waterman_altivec_word(aa0,
20748 X                                              f_str->word_score,
20749 X                                              n0,
20750 X                                              aa1,
20751 X                                              n1,
20752 X                                              f_str->bias,
20753 #ifndef OLD_FASTA_GAP
20754 X                                              -(ppst->gdelval + ppst->ggapval),
20755 #else
20756 X                                              -ppst->gdelval,
20757 #endif
20758 X                                              -ppst->ggapval,
20759 X                                              f_str);
20760 X          
20761 X          /* The 8 bit version is roughly 50% faster than the 16 bit version,
20762 X           * so we are fine if less than about 1/3 of the runs have to
20763 X           * be rerun with 16 bits. If it is more, and we have tried at least
20764 X           * 500 sequences, we switch off the 8-bit mode.
20765 X           */
20766 X          f_str->done_16bit++;
20767 X          if(f_str->done_8bit>500 && (3*f_str->done_16bit)>(f_str->done_8bit))
20768 X              f_str->try_8bit = 0;
20769 X      }
20770 X  }
20771 X  else
20772 X  { 
20773 X      /* Just use the 16-bit altivec version directly */
20774 X      score = smith_waterman_altivec_word(aa0,
20775 X                                          f_str->word_score,
20776 X                                          n0,
20777 X                                          aa1,
20778 X                                          n1,
20779 X                                          f_str->bias,
20780 #ifndef OLD_FASTA_GAP
20781 X                                          -(ppst->gdelval + ppst->ggapval),
20782 #else
20783 X                                          -ppst->gdelval,
20784 #endif
20785 X                                          -ppst->ggapval,
20786 X                                          f_str);
20787 X  }      
20788 X
20789 #endif /* not Altivec */
20790 X
20791 #if defined(SW_SSE2)
20792 X
20793 X  if(f_str->try_8bit)
20794 X  {
20795 X      score = smith_waterman_sse2_byte(aa0,
20796 X                                       f_str->byte_score,
20797 X                                       n0,
20798 X                                       aa1,
20799 X                                       n1,
20800 X                                       f_str->bias,
20801 #ifndef OLD_FASTA_GAP
20802 X                                       -(ppst->gdelval + ppst->ggapval),
20803 #else
20804 X                                       -ppst->gdelval,
20805 #endif
20806 X                                       -ppst->ggapval,
20807 X                                       f_str);
20808 X      
20809 X      f_str->done_8bit++;
20810 X      
20811 X      if(score>=255)
20812 X      {
20813 X          /* Overflow, so we have to redo it in 16 bits. */
20814 X          score = smith_waterman_sse2_word(aa0,
20815 X                                           f_str->word_score,
20816 X                                           n0,
20817 X                                           aa1,
20818 X                                           n1,
20819 #ifndef OLD_FASTA_GAP
20820 X                                           -(ppst->gdelval + ppst->ggapval),
20821 #else
20822 X                                           -ppst->gdelval,
20823 #endif
20824 X                                           -ppst->ggapval,
20825 X                                           f_str);
20826 X          
20827 X          /* The 8 bit version is roughly 50% faster than the 16 bit version,
20828 X           * so we are fine if less than about 1/3 of the runs have to
20829 X           * be rerun with 16 bits. If it is more, and we have tried at least
20830 X           * 500 sequences, we switch off the 8-bit mode.
20831 X           */
20832 X          f_str->done_16bit++;
20833 X          if(f_str->done_8bit>500 && (3*f_str->done_16bit)>(f_str->done_8bit))
20834 X              f_str->try_8bit = 0;
20835 X      }
20836 X  }
20837 X  else
20838 X  { 
20839 X      /* Just use the 16-bit altivec version directly */
20840 X      score = smith_waterman_sse2_word(aa0,
20841 X                                       f_str->word_score,
20842 X                                       n0,
20843 X                                       aa1,
20844 X                                       n1,
20845 #ifndef OLD_FASTA_GAP
20846 X                                       -(ppst->gdelval + ppst->ggapval),
20847 #else
20848 X                                       -ppst->gdelval,
20849 #endif
20850 X                                       -ppst->ggapval,
20851 X                                       f_str);
20852 X  }      
20853 #endif
20854 X
20855 #if !defined(SW_ALTIVEC) && !defined(SW_SSE2)
20856 X
20857 X  score = FLOCAL_ALIGN(aa0,aa1,n0,n1,0,0,
20858 X                       NULL,
20859 #ifndef OLD_FASTA_GAP
20860 X                       -(ppst->gdelval + ppst->ggapval),
20861 #else
20862 X                       -ppst->gdelval,
20863 #endif
20864 X                       ppst->ggapval,0,f_str);
20865 #endif
20866 X
20867 X  rst->score[0] = score;
20868 X
20869 X  if(( ppst->zsflag == 6 || ppst->zsflag == 16) &&
20870 X     (do_karlin(aa1, n1, ppst->pam2[0], ppst,f_str->aa0_f, 
20871 X               f_str->kar_p, &lambda, &H)>0)) {
20872 X    rst->comp = 1.0/lambda;
20873 X    rst->H = H;
20874 X  }
20875 X  else {rst->comp = rst->H = -1.0;}
20876 X
20877 }
20878 X
20879 static int
20880 FLOCAL_ALIGN(const unsigned char *aa0, const unsigned char *aa1,
20881 X            int n0, int n1, int low, int up,
20882 X            int **W, int GG,int HH, int MW,
20883 X            struct f_struct *f_str) {
20884 X
20885 X  register int *pwaa;
20886 X  register struct swstr *ssj;
20887 X  struct swstr *ss;
20888 X  register int h, e, f, p;
20889 X  int temp, score;
20890 X  int gap_ext, n_gap_init;
20891 X
20892 X  const unsigned char *aa1p;
20893 X  ss = f_str->ss;
20894 X  ss[n0].H = -1;
20895 X  ss[n0].E = 1;
20896 X
20897 X  n_gap_init = GG;
20898 X  gap_ext = HH;
20899 X
20900 X  score = 0;
20901 X  for (h=0; h<n0; h++) {         /* initialize 0th row */
20902 X    ss[h].H = ss[h].E = 0;
20903 X  }
20904 X  
20905 X  aa1p=aa1;
20906 X  while (*aa1p) {              /* relies on aa1[n1]==0 for EOS flag */
20907 X    /* waa_s has the offsets for each residue in aa0 into pam2 */
20908 X    /* waa_s has complexity (-S) dependent scores */
20909 X    pwaa = f_str->waa_s + (*aa1p++)*n0;
20910 X    ssj = ss;
20911 X
20912 X    e = f = h = p = 0;
20913 X  zero_f:      /* in this section left-gap f==0, and is never examined */
20914 X
20915 X    while (1) {        /* build until h > n_gap_init (f < 0 until h > n_gap_init) */
20916 X               /* bump through the pam[][]'s for each of the aa1[] matches to
20917 X                  aa0[], because of the way *pwaa is set up */
20918 X
20919 X      h = p + *pwaa++;         /* increment diag value */
20920 X      p = ssj->H;              /* get next diag value */
20921 X      if ((e = ssj->E) > 0 ) { /* >0 from up-gap */
20922 X       if (p == -1) goto next_row;     /* done, -1=ss[n0].H sentinel */
20923 X       if (h < e) h = e;       /* up-gap better than diag */
20924 X       else 
20925 X         if (h > n_gap_init) { /* we won't starting a new up-gap */
20926 X           e += gap_ext;       /* but we might be extending one */
20927 X           goto transition;    /* good h > n_gap_diag; scan f */
20928 X         }
20929 X       e += gap_ext;           /* up-gap decreased */
20930 X       ssj->E =  (e > 0) ?  e : 0;     /* set to 0 if < 0 */
20931 X       ssj++->H = h;           /* diag match updated */
20932 X      }
20933 X      else {                   /* up-gap (->E) is 0 */
20934 X       if ( h > 0) {           /* diag > 0 */
20935 X         if (h > n_gap_init) { /* we won't be starting a new up-gap */
20936 X           e = 0;              /* and we won't be extending one */
20937 X           goto transition;    /* good h > n_gap_diag; scan f */
20938 X         }
20939 X         ssj++->H = h;         /* update diag */
20940 X       }
20941 X       else ssj++->H = 0;      /* update diag to 0 */
20942 X      }
20943 X    }
20944 X
20945 X    /* here h > n_gap_init and h > e, => the next f will be > 0 */
20946 X  transition:
20947 #ifdef DEBUG
20948 X    if ( h > 10000) 
20949 X      fprintf(stderr,"h: %d ssj: %d\n",h, (int)(ssj-ss));
20950 #endif
20951 X    if ( score < h ) score = h;        /* save best score, only when h > n_gap_init */
20952 X
20953 X    temp = h - n_gap_init;     /* best score for starting a new gap */
20954 X    if ( f < temp ) f = temp;  /* start a left-gap? */
20955 X    if ( e < temp ) e = temp;  /* start an up-gap? */
20956 X    ssj->E = ( e > 0 ) ? e : 0;        /* update up-gap */
20957 X    ssj++->H = h;              /* update diag */
20958 X    e = 0;
20959 X
20960 X    do {                       /* stay here until f <= 0 */
20961 X      h = p + *pwaa++;         /* diag + match/mismatch */
20962 X      p = ssj->H;              /* save next (right) diag */
20963 X
20964 X      if ( h < f ) h = f;      /* update diag using left gap */
20965 X      f += gap_ext;            /* update next left-gap */
20966 X
20967 X      if ((e = ssj->E) > 0) {  /* good up gap */
20968 X       if (p == -1) goto next_row;     /* at the end of the row */
20969 X       if ( h < e ) h = e;     /* update diag using up-gap */
20970 X       else
20971 X         if ( h > n_gap_init ) {
20972 X           e += gap_ext;       /* update up gap */
20973 X           goto transition;    /* good diag > n_gap_init, restart */
20974 X         }
20975 X       e += gap_ext;           /* update up-gap */
20976 X       ssj->E = (e > 0) ? e : 0;       /* e must be >= 0 */
20977 X       ssj++->H = h;           /* update diag */
20978 X      }
20979 X      else {                   /* up-gap <= 0 */
20980 X       if ( h > n_gap_init ) {
20981 X         e = 0;
20982 X         goto transition;      /* good diag > n_gap_init; restart */
20983 X       }
20984 X       ssj++->H = h;           /* update diag */
20985 X      }
20986 X    } while ( f > 0 );         /* while left gap f > 0  */
20987 X    goto zero_f;               /* otherwise, go to f==0 section */
20988 X  next_row:
20989 X    ;
20990 X  }            /* end while(*aap1) {} */
20991 X
20992 X  return score;
20993 X
20994 }               /* here we should be all done */
20995 X
20996 void do_opt (const unsigned char *aa0, int n0,
20997 X            const unsigned char *aa1, int n1,
20998 X            int frame,
20999 X            struct pstruct *ppst, struct f_struct *f_str,
21000 X            struct rstruct *rst)
21001 {
21002 }
21003 X
21004 int do_walign (const unsigned char *aa0, int n0,
21005 X              const unsigned char *aa1, int n1,
21006 X              int frame,
21007 X              struct pstruct *ppst, 
21008 X              struct f_struct *f_str, 
21009 X              struct a_res_str *a_res,
21010 X              int *have_ares)
21011 {
21012 X   const unsigned char *aa0p, *aa1p;
21013 X   register int *pwaa;
21014 X   register int i, j;
21015 X   register struct swstr *ssj;
21016 X   struct swstr *ss;
21017 X   int *res, *waa;
21018 X   int e, f, h, p;
21019 X   int     q, r, m;
21020 X   int     score;
21021 X   int cost, I, J, K, L;
21022 X
21023 X   ss = f_str->ss;
21024 X
21025 X   res = f_str->res;
21026 X   waa = f_str->waa_a; /* this time use universal pam2[0] */
21027 X
21028 X   
21029 #ifdef OLD_FASTA_GAP
21030 X   q = -(ppst->gdelval - ppst->ggapval);
21031 #else
21032 X   q = -ppst->gdelval;
21033 #endif
21034 X
21035 X   r = -ppst->ggapval;
21036 X   m = q + r;
21037 X
21038 X   /* initialize 0th row */
21039 X   for (ssj=ss; ssj<ss+n0; ssj++) {
21040 X     ssj->H = 0;
21041 X     ssj->E = -q;
21042 X   }
21043 X
21044 X   score = 0;
21045 X   aa1p = aa1;
21046 X   i = 0;
21047 X   while (*aa1p) {
21048 X     h = p = 0;
21049 X     f = -q;
21050 X     pwaa = waa + (*aa1p++ * n0);
21051 X     for (ssj = ss, aa0p = aa0; ssj < ss+n0; ssj++) {
21052 X       if ((h =   h     - m) > /* gap open from left best */
21053 X          /* gap extend from left gapped */
21054 X          (f =   f     - r)) f = h;    /* if better, use new gap opened */
21055 X       if ((h = ssj->H - m) >  /* gap open from up best */
21056 X          /* gap extend from up gap */
21057 X          (e = ssj->E - r)) e = h;     /* if better, use new gap opened */
21058 X       h = p + *pwaa++;                /* diagonal match */
21059 X       if (h < 0 ) h = 0;      /* ?  < 0, reset to 0 */
21060 X       if (h < f ) h = f;      /* left gap better, reset */
21061 X       if (h < e ) h = e;      /* up gap better, reset */
21062 X       p = ssj->H;             /* save previous best score */
21063 X       ssj->H = h;             /* save (new) up diag-matched */
21064 X       ssj->E = e;             /* save upper gap opened */
21065 X       if (h > score) {                /* ? new best score */
21066 X        score = h;             /* save best */
21067 X        I = i;                 /* row */
21068 X        J = (int)(ssj-ss);     /* column */
21069 X       }
21070 X     }
21071 X     i++;
21072 X   }                           /* done with forward pass */
21073 X   if (score <= 0) return 0;
21074 X
21075 X  /* to get the start point, go backwards */
21076 X  
21077 X   /* 18-June-2003 fix bug in backtracking code to identify start of
21078 X      alignment.  Code used pam2[0][aa0[j]][aa1[i]] instead of
21079 X      pam2p[0][j][aa1[i]].  Ideally, it would use waa_a.
21080 X   */
21081 X
21082 X  cost = K = L = 0;
21083 X  for (ssj=ss+J; ssj>=ss; ssj--) ssj->H= ssj->E= -1;
21084 X  
21085 X  for (i=I; i>=0; i--) {
21086 X    h = f = -1;
21087 X    p = (i == I) ? 0 : -1;
21088 X    for (ssj=ss+J, j= J; ssj>=ss; ssj--,j--) {
21089 X      f = max (f,h-q)-r;
21090 X      ssj->E=max(ssj->E,ssj->H-q)-r;
21091 X      h = max(max(ssj->E,f),p+f_str->pam2p[0][j][aa1[i]]);
21092 X      p = ssj->H;
21093 X      ssj->H=h;
21094 X      if (h > cost) {
21095 X       cost = h;
21096 X       K = i;
21097 X       L = (int)(ssj-ss);
21098 X       if (cost >= score) goto found;
21099 X      }
21100 X    }
21101 X  }
21102 X  
21103 found:  
21104 X
21105 /*  printf(" %d: L: %3d-%3d/%3d; K: %3d-%3d/%3d\n",score,L,J,n0,K,I,n1); */
21106 X
21107 /* in the f_str version, the *res array is already allocated at 4*n0/3 */
21108 X
21109 X  a_res->res = f_str->res;
21110 X  *have_ares = 1;
21111 X  a_res->max0 = J+1; a_res->min0 = L; a_res->max1 = I+1; a_res->min1 = K;
21112 X  
21113 /*  ALIGN(&aa1[K-1],&aa0[L-1],I-K+1,J-L+1,ppst->pam2[0],q,r,res,nres,f_str); */
21114 X
21115 X
21116 /* this code no longer refers to aa0[], it uses pam2p[0][L] instead */
21117 X  ALIGN(&aa0[L-1],&aa1[K-1],J-L+1,I-K+1,f_str->pam2p[0],L,q,r,
21118 X       a_res->res,&a_res->nres,f_str);
21119 X
21120 /*  DISPLAY(&aa0[L-1],&aa1[K-1],J-L+1,I-K+1,res,L,K,ppst->sq); */
21121 X
21122 /* return *res and nres */
21123 X
21124 X  return score;
21125 }
21126 X
21127 static int CHECK_SCORE(const unsigned char *A, const unsigned char *B,
21128 X                      int M, int N,
21129 X                      int *S, int **W, int IW, int G, int H, int *nres);
21130 X
21131 #define gap(k)  ((k) <= 0 ? 0 : g+h*(k))        /* k-symbol indel cost */
21132 X
21133 /* Append "Delete k" op */
21134 #define DEL(k)                          \
21135 { if (*last < 0)                        \
21136 X    *last = (*sapp)[-1] -= (k);                \
21137 X  else {                               \
21138 X    *last = (*sapp)[0] = -(k);         \
21139 X    (*sapp)++;                         \
21140 X  }                                    \
21141 }
21142 X
21143 /* Append "Insert k" op */
21144 #define INS(k)                          \
21145 { if (*last > 0)                        \
21146 X    *last = (*sapp)[-1] += (k);                \
21147 X  else {                               \
21148 X    *last = (*sapp)[0] = (k);          \
21149 X    (*sapp)++;                         \
21150 X  }                                    \
21151 }
21152 X
21153 /*
21154 #define XTERNAL
21155 #include "upam.h"
21156 X
21157 void
21158 print_seq_prof(unsigned char *A, int M,
21159 X              unsigned char *B, int N,
21160 X              int **w, int iw, int dir) {
21161 X  char c_max;
21162 X  int i_max, j_max, i,j;
21163 X
21164 X  char *c_dir="LRlr";
21165 X
21166 X  for (i=1; i<=min(60,M); i++) {
21167 X    fprintf(stderr,"%c",aa[A[i]]);
21168 X  }
21169 X  fprintf(stderr, - %d\n,M);
21170 X
21171 X  for (i=0; i<min(60,M); i++) {
21172 X    i_max = -1;
21173 X    for (j=1; j<21; j++) {
21174 X      if (w[iw+i][j]> i_max) {
21175 X       i_max = w[iw+i][j]; 
21176 X       j_max = j;
21177 X      }
21178 X    }
21179 X    fprintf(stderr,"%c",aa[j_max]);
21180 X  }
21181 X  fputc(':',stderr);
21182 X
21183 X  for (i=1; i<=min(60,N); i++) {
21184 X    fprintf(stderr,"%c",aa[B[i]]);
21185 X  }
21186 X
21187 X  fprintf(stderr," -%c: %d,%d\n",c_dir[dir],M,N);
21188 }
21189 */
21190 X
21191 /* align(A,B,M,N,tb,te,last) returns the cost of an optimum conversion between
21192 X   A[1..M] and B[1..N] that begins(ends) with a delete if tb(te) is zero
21193 X   and appends such a conversion to the current script.                   */
21194 X
21195 static int 
21196 align(const unsigned char *A, const unsigned char *B,
21197 X      int M, int N,
21198 X      int tb, int te, int **w, int iw, int g, int h, 
21199 X      struct f_struct *f_str, int dir,
21200 X      int **sapp, int *last)
21201 {
21202 X
21203 X  int midi, midj, type;        /* Midpoint, type, and cost */
21204 X  int midc;
21205 X  int c1, c2;
21206 X
21207 X  register int   i, j;
21208 X  register int c, e, d, s;
21209 X  int m, t, *wa;
21210 X  struct swstr *f_ss, *r_ss;
21211 X
21212 /*   print_seq_prof(A,M,B,N,w,iw,dir); */
21213 X
21214 X  m = g + h;
21215 X
21216 X  f_ss = f_str->f_ss;
21217 X  r_ss = f_str->r_ss;
21218 X
21219 /* Boundary cases: M <= 1 or N == 0 */
21220 X
21221 X  if (N <= 0) {
21222 X    if (M > 0) {DEL(M)}
21223 X    return -gap(M);
21224 X  }
21225 X
21226 X  if (M <= 1) {
21227 X    if (M <= 0) { 
21228 X      INS(N)
21229 X      return -gap(N);
21230 X    }
21231 X
21232 X    if (tb < te) tb = te;
21233 X    midc = (tb-h) - gap(N);
21234 X    midj = 0;
21235 /*  wa = w[A[1]]; */
21236 X    wa = w[iw];
21237 X    for (j = 1; j <= N; j++) {
21238 X      c = -gap(j-1) + wa[B[j]] - gap(N-j);
21239 X      if (c > midc) { midc = c; midj = j;}
21240 X    }
21241 X    if (midj == 0) { DEL(1) INS(N) }
21242 X    else  {
21243 X      if (midj > 1) { INS(midj-1)}
21244 X      *last = (*sapp)[0] = 0;
21245 X      (*sapp)++;
21246 X      if (midj < N) { INS(N-midj)}
21247 X    }
21248 X    return midc;
21249 X  }
21250 X
21251 /* Divide: Find optimum midpoint (midi,midj) of cost midc */
21252 X
21253 X  midi = M/2;          /* Forward phase:                          */
21254 X  f_ss[0].H = 0;       /*   Compute H(M/2,k) & E(M/2,k) for all k */
21255 X  t = -g;
21256 X  for (j = 1; j <= N; j++) {
21257 X    f_ss[j].H = t = t-h;
21258 X    f_ss[j].E = t-g;
21259 X  }
21260 X  t = tb;
21261 X  for (i = 1; i <= midi; i++) {
21262 X    s = f_ss[0].H;
21263 X    f_ss[0].H = c = t = t-h;
21264 X    e = t-g;
21265 /*    wa = w[A[i]]; */
21266 X    wa = w[iw+i-1];
21267 X    for (j = 1; j <= N; j++) {
21268 X      if ((c =   c   - m) > (e =   e   - h)) e = c;
21269 X      if ((c = f_ss[j].H - m) > (d = f_ss[j].E - h)) d = c;
21270 X      c = s + wa[B[j]];
21271 X      if (e > c) c = e;
21272 X      if (d > c) c = d;
21273 X      s = f_ss[j].H;
21274 X      f_ss[j].H = c;
21275 X      f_ss[j].E = d;
21276 X    }
21277 X  }
21278 X  f_ss[0].E = f_ss[0].H;
21279 X
21280 X  r_ss[N].H = 0;               /* Reverse phase:                  */
21281 X  t = -g;                      /*   Compute R(M/2,k) & S(M/2,k) for all k */
21282 X
21283 X  for (j = N-1; j >= 0; j--) {
21284 X    r_ss[j].H = t = t-h;
21285 X    r_ss[j].E = t-g;
21286 X  }
21287 X
21288 X  t = te;
21289 X  for (i = M-1; i >= midi; i--) {
21290 X    s = r_ss[N].H;
21291 X    r_ss[N].H = c = t = t-h;
21292 X    e = t-g;
21293 /*    wa = w[A[i+1]]; */
21294 X    wa = w[iw+i];
21295 X    for (j = N-1; j >= 0; j--) {
21296 X      if ((c =   c   - m) > (e =   e   - h)) { e = c; }
21297 X      if ((c = r_ss[j].H - m) > (d = r_ss[j].E - h)) { d = c; }
21298 X      c = s + wa[B[j+1]];
21299 X      if (e > c) c = e;
21300 X      if (d > c) c = d;
21301 X      s = r_ss[j].H;
21302 X      r_ss[j].H = c;
21303 X      r_ss[j].E = d;
21304 X    }
21305 X  }
21306 X  r_ss[N].E = r_ss[N].H;
21307 X
21308 X  midc = f_ss[0].H+r_ss[0].H;          /* Find optimal midpoint */
21309 X  midj = 0;
21310 X  type = 1;
21311 X
21312 X  for (j = 0; j <= N; j++) {
21313 X    if ((c = f_ss[j].H + r_ss[j].H) >= midc) {
21314 X      if (c > midc || (f_ss[j].H != f_ss[j].E && r_ss[j].H == r_ss[j].E)) {
21315 X       midc = c;
21316 X       midj = j;
21317 X      }
21318 X    }
21319 X  }
21320 X
21321 X  for (j = N; j >= 0; j--) {
21322 X    if ((c = f_ss[j].E + r_ss[j].E + g) > midc) {
21323 X      midc = c;
21324 X      midj = j;
21325 X      type = 2;
21326 X    }
21327 X  }
21328 X
21329 /* Conquer: recursively around midpoint */
21330 X
21331 X  if (type == 1)
21332 X    { c1 = align(A,B,midi,midj,tb,-g,w,iw,g,h,f_str,0,sapp,last);
21333 X      c2 = align(A+midi,B+midj,M-midi,N-midj,-g,te,w,iw+midi,g,h,f_str,1,sapp,last);
21334 X    }
21335 X  else
21336 X    { align(A,B,midi-1,midj,tb,0,w,iw,g,h,f_str,2,sapp,last);
21337 X      DEL(2);
21338 X      align(A+midi+1,B+midj,M-midi-1,N-midj,0,te,w,iw+midi+1,g,h,f_str,3,sapp,last);
21339 X    }
21340 X  return midc;
21341 }
21342 X
21343 /* Interface and top level of comparator */
21344 X
21345 static int 
21346 ALIGN(const unsigned char *A, const unsigned char *B,
21347 X      int M, int N,
21348 X      int **W, int IW, int G, int H, int *S, int *NC,
21349 X      struct f_struct *f_str)
21350
21351 X  struct swstr *f_ss, *r_ss;
21352 X  int *sapp, last;
21353 X  int c, ck;
21354 X
21355 X  sapp = S;
21356 X  last = 0;
21357 X
21358 X   if ((f_ss = (struct swstr *) calloc (N+2, sizeof (struct swstr)))
21359 X       == NULL) {
21360 X     fprintf (stderr, "cannot allocate f_ss array %3d\n", N+2);
21361 X     exit (1);
21362 X   }
21363 X   f_ss++;
21364 X   f_str->f_ss = f_ss;
21365 X
21366 X   if ((r_ss = (struct swstr *) calloc (N+2, sizeof (struct swstr)))
21367 X       == NULL) {
21368 X     fprintf (stderr, "cannot allocate r_ss array %3d\n", N+2);
21369 X     exit (1);
21370 X   }
21371 X   r_ss++;
21372 X   f_str->r_ss = r_ss;
21373 X
21374 X  /*   print_seq_prof(A,M,W,IW); */
21375 X  c = align(A,B,M,N,-G,-G,W,IW,G,H,f_str,0,&sapp,&last);       /* OK, do it */
21376 X
21377 X  ck = CHECK_SCORE(A,B,M,N,S,W,IW,G,H,NC);
21378 X  if (c != ck) {
21379 X    fprintf(stdout,"*** Check_score error. %d != %d ***\n",c,ck);
21380 X    fprintf(stderr,"*** Check_score error. %d != %d ***\n",c,ck);
21381 X  }
21382 X
21383 X  f_ss--; r_ss--;
21384 X  free(r_ss); free(f_ss);
21385 X
21386 X  return c;
21387 }
21388 X
21389 /* Alignment display routine */
21390 X
21391 static void
21392 DISPLAY(const unsigned char *A, const unsigned char *B, 
21393 X       int M, int N,
21394 X       int *S, int AP, int BP, char *sq)
21395 { register char *a, *b, *c;
21396 X  register int   i,  j, op;
21397 X           int   lines, ap, bp;
21398 X
21399 X  char ALINE[51], BLINE[51], CLINE[51];
21400 X
21401 X  i = j = op = lines = 0;
21402 X  ap = AP;
21403 X  bp = BP;
21404 X  a = ALINE;
21405 X  b = BLINE;
21406 X  c = CLINE;
21407 X  while (i < M || j < N)
21408 X    { if (op == 0 && *S == 0)
21409 X        { op = *S++;
21410 X          *a = sq[A[++i]];
21411 X          *b = sq[B[++j]];
21412 X          *c++ = (*a++ == *b++) ? '|' : ' ';
21413 X        }
21414 X      else
21415 X        { if (op == 0)
21416 X            op = *S++;
21417 X          if (op > 0)
21418 X            { *a++ = ' ';
21419 X              *b++ = sq[B[++j]];
21420 X              op--;
21421 X            }
21422 X          else
21423 X            { *a++ = sq[A[++i]];
21424 X              *b++ = ' ';
21425 X              op++;
21426 X            }
21427 X          *c++ = '-';
21428 X        }
21429 X      if (a >= ALINE+50 || (i >= M && j >= N))
21430 X        { *a = *b = *c = '\0';
21431 X          printf("\n%5d ",50*lines++);
21432 X          for (b = ALINE+10; b <= a; b += 10)
21433 X            printf("    .    :");
21434 X          if (b <= a+5)
21435 X            printf("    .");
21436 X          printf("\n%5d %s\n      %s\n%5d %s\n",ap,ALINE,CLINE,bp,BLINE);
21437 X         ap = AP + i;
21438 X         bp = BP + j;
21439 X          a = ALINE;
21440 X          b = BLINE;
21441 X          c = CLINE;
21442 X        }
21443 X    }
21444 }
21445 X
21446 /* CHECK_SCORE - return the score of the alignment stored in S */
21447 X
21448 static int CHECK_SCORE(const unsigned char *A, const unsigned char *B,
21449 X                      int M, int N,
21450 X                      int *S, int **w, int iw, 
21451 X                      int g, int h, int *NC)
21452
21453 X  register int   i,  j, op, nc;
21454 X  int score;
21455 X
21456 X  /*  print_seq_prof(A,M,w,iw); */
21457 X
21458 X  score = i = j = op = nc = 0;
21459 X  while (i < M || j < N) {
21460 X    op = *S++;
21461 X    if (op == 0) {
21462 X      score = w[iw+i][B[++j]] + score;
21463 X      i++;
21464 X      nc++;
21465 X    }
21466 X    else if (op > 0) {
21467 X      score = score - (g+op*h);
21468 X      j += op;
21469 X      nc += op;
21470 X    } else {
21471 X      score = score - (g-op*h);
21472 X      i -= op;
21473 X      nc -= op;
21474 X    }
21475 X  }
21476 X  *NC = nc;
21477 X  return score;
21478 }
21479 X
21480 void
21481 pre_cons(const unsigned char *aa1, int n1, int frame, struct f_struct *f_str) {
21482 X
21483 #ifdef TFAST
21484 X  f_str->n10 = aatran(aa1,f_str->aa1x,n1,frame);
21485 #endif
21486 X
21487 }
21488 X
21489 /* aln_func_vals - set up aln.qlfact, qlrev, llfact, llmult, frame, llrev */
21490 /* call from calcons, calc_id, calc_code */
21491 void 
21492 aln_func_vals(int frame, struct a_struct *aln) {
21493 X
21494 X  aln->llfact = aln->llmult = aln->qlfact = 1;
21495 X  aln->qlrev = aln->llrev = 0;
21496 X  aln->frame = 0;
21497 }
21498 X
21499 /* 29-June-2003 this version has been modified to use pst.pam2p
21500 X   instead of pam2 to indicate similarity */
21501 X
21502 #include "a_mark.h"
21503 X
21504 int calcons(const unsigned char *aa0, int n0,
21505 X           const unsigned char *aa1, int n1,
21506 X           int *nc, struct a_struct *aln,
21507 X           struct a_res_str a_res, 
21508 X           struct pstruct pst,
21509 X           char *seqc0, char *seqc1, char *seqca,
21510 X           struct f_struct *f_str)
21511 {
21512 X  int i0, i1;
21513 X  int op, lenc, nd, ns, itmp;
21514 X  char *sp0, *sp1, *spa, *sq;
21515 X  int mins, smins;
21516 X  int *rp;
21517 X  
21518 X  if (pst.ext_sq_set) { sq = pst.sqx; }
21519 X  else { sq = pst.sq; }
21520 X
21521 X  aln->amin0 = a_res.min0;
21522 X  aln->amax0 = a_res.max0;
21523 X  aln->amin1 = a_res.min1;
21524 X  aln->amax1 = a_res.max1;
21525 X
21526 X  /* first fill in the ends */
21527 X
21528 X  if (min(a_res.min0,a_res.min1)<aln->llen || aln->showall==1) /* will we show all the start ?*/
21529 X    if (a_res.min0>=a_res.min1) {                                      /* aa0 extends more to left */
21530 X      smins=0;
21531 X      if (aln->showall==1) mins=a_res.min0;
21532 X      else mins = min(a_res.min0,aln->llcntx);
21533 X      aancpy(seqc0,(char *)aa0+a_res.min0-mins,mins,pst);
21534 X      aln->smin0 = a_res.min0-mins;
21535 X      if ((mins-a_res.min1)>0) {
21536 X       memset(seqc1,' ',mins-a_res.min1);
21537 X       aancpy(seqc1+mins-a_res.min1,(char *)aa1,a_res.min1,pst);
21538 X       aln->smin1 = 0;
21539 X      }
21540 X      else {
21541 X       aancpy(seqc1,(char *)aa1+a_res.min1-mins,mins,pst);
21542 X       aln->smin1 = a_res.min1-mins;
21543 X      }
21544 X    }
21545 X    else {
21546 X      smins=0;
21547 X      if (aln->showall == 1) mins=a_res.min1;
21548 X      else mins = min(a_res.min1,aln->llcntx);
21549 X      aancpy(seqc1,(char *)(aa1+a_res.min1-mins),mins,pst);
21550 X      aln->smin1 = a_res.min1-mins;
21551 X      if ((mins-a_res.min0)>0) {
21552 X       memset(seqc0,' ',mins-a_res.min0);
21553 X       aancpy(seqc0+mins-a_res.min0,(char *)aa0,a_res.min0,pst);
21554 X       aln->smin0 = 0;
21555 X      }
21556 X      else {
21557 X       aancpy(seqc0,(char *)aa0+a_res.min0-mins,mins,pst);
21558 X       aln->smin0 = a_res.min0-mins;
21559 X      }
21560 X    }
21561 X  else {       /* we are not showing the start */
21562 X    /* mins has the amount of unaligned context to be shown */
21563 X    mins= min(aln->llcntx,min(a_res.min0,a_res.min1));
21564 X    smins=mins;
21565 X
21566 X    aln->smin0=a_res.min0 - mins;
21567 X    aln->smin1=a_res.min1 - mins;
21568 X
21569 X    aancpy(seqc0,(char *)aa0+a_res.min0-mins,mins,pst);
21570 X    aancpy(seqc1,(char *)aa1+a_res.min1-mins,mins,pst);
21571 X  }
21572 X
21573 /* now get the middle */
21574 X
21575 X  memset(seqca,M_BLANK,mins);
21576 X
21577 X  spa = seqca+mins;
21578 X  sp0 = seqc0+mins;
21579 X  sp1 = seqc1+mins;
21580 X  rp = a_res.res;
21581 X  lenc = aln->nident = aln->nsim = aln->ngap_q = aln->ngap_l = aln->nfs =op = 0;
21582 X  i0 = a_res.min0;
21583 X  i1 = a_res.min1;
21584 X  
21585 X  while (i0 < a_res.max0 || i1 < a_res.max1) {
21586 X    if (op == 0 && *rp == 0) {
21587 X      op = *rp++;
21588 X      lenc++;
21589 X      if ((itmp=f_str->pam2p[0][i0][aa1[i1]])<0) { *spa = M_NEG; }
21590 X      else if (itmp == 0) { *spa = M_ZERO;}
21591 X      else {*spa = M_POS;}
21592 X      if (*spa == M_POS || *spa==M_ZERO) aln->nsim++;
21593 X
21594 X      *sp0 = sq[aa0[i0++]];
21595 X      *sp1 = sq[aa1[i1++]];
21596 X
21597 X      if (toupper(*sp0) == toupper(*sp1)) {aln->nident++; *spa = M_IDENT;}
21598 X      else if (pst.nt_align && ((*sp0 == 'T' && *sp1 == 'U') ||
21599 X                  (*sp0=='U' && *sp1=='T'))) {
21600 X       aln->nident++; *spa=M_IDENT;
21601 X      }
21602 X
21603 X      sp0++; sp1++; spa++;
21604 X    }
21605 X    else {
21606 X      if (op==0) op = *rp++;
21607 X      if (op>0) {
21608 X       *sp0++ = '-';
21609 X       *sp1++ = sq[aa1[i1++]];
21610 X       *spa++ = M_DEL;
21611 X       op--;
21612 X       lenc++;
21613 X       aln->ngap_q++;
21614 X      }
21615 X      else {
21616 X       *sp0++ = sq[aa0[i0++]];
21617 X       *sp1++ = '-';
21618 X       *spa++ = M_DEL;
21619 X       op++;
21620 X       lenc++;
21621 X       aln->ngap_l++;
21622 X      }
21623 X    }
21624 X  }
21625 X
21626 X  *nc = lenc;
21627 X  *spa = '\0';
21628 /*      now we have the middle, get the right end */
21629 X
21630 #ifndef LFASTA
21631 X  /* how much extra to show at end ? */
21632 X  if (!aln->llcntx_flg) {
21633 X    ns = mins + lenc + aln->llen;      /* show an extra line? */
21634 X    ns -= (itmp = ns %aln->llen);      /* itmp = left over on last line */
21635 X    if (itmp>aln->llen/2) ns += aln->llen;  /* more than 1/2 , use another*/
21636 X    nd = ns - (mins+lenc);             /* this much extra */
21637 X  }
21638 X  else nd = aln->llcntx;
21639 X
21640 X  if (nd > max(n0-a_res.max0,n1-a_res.max1))
21641 X    nd = max(n0-a_res.max0,n1-a_res.max1);
21642 X  
21643 X  if (aln->showall==1) {
21644 X    nd = max(n0-a_res.max0,n1-a_res.max1);     /* reset for showall=1 */
21645 X    /* get right end */
21646 X    aancpy(seqc0+mins+lenc,(char *)aa0+a_res.max0,n0-a_res.max0,pst);
21647 X    aancpy(seqc1+mins+lenc,(char *)aa1+a_res.max1,n1-a_res.max1,pst);
21648 X    /* fill with blanks - this is required to use one 'nc' */
21649 X    memset(seqc0+mins+lenc+n0-a_res.max0,' ',nd-(n0-a_res.max0));
21650 X    memset(seqc1+mins+lenc+n1-a_res.max1,' ',nd-(n1-a_res.max1));
21651 X  }
21652 X  else {
21653 X     if ((nd-(n0-a_res.max0))>0) {
21654 X       aancpy(seqc0+mins+lenc,(char *)aa0+a_res.max0,n0-a_res.max0,pst);
21655 X       memset(seqc0+mins+lenc+n0-a_res.max0,' ',nd-(n0-a_res.max0));
21656 X     }
21657 X     else aancpy(seqc0+mins+lenc,(char *)aa0+a_res.max0,nd,pst);
21658 X
21659 X     if ((nd-(n1-a_res.max1))>0) {
21660 X       aancpy(seqc1+mins+lenc,(char *)aa1+a_res.max1,n1-a_res.max1,pst);
21661 X       memset(seqc1+mins+lenc+n1-a_res.max1,' ',nd-(n1-a_res.max1));
21662 X     }
21663 X     else aancpy(seqc1+mins+lenc,(char *)aa1+a_res.max1,nd,pst);
21664 X }
21665 X  
21666 #else   /* LFASTA */
21667 X  nd = 0;
21668 #endif
21669 X  /* #undef LFASTA */
21670 X  return mins+lenc+nd;
21671 }
21672 X
21673 int calcons_a(const unsigned char *aa0, unsigned char *aa0a, int n0,
21674 X             const unsigned char *aa1, int n1,
21675 X             int *nc,
21676 X             struct a_struct *aln,
21677 X             struct a_res_str a_res,
21678 X             struct pstruct pst,
21679 X             char *seqc0, char *seqc0a, char *seqc1, char *seqca,
21680 X             char *ann_arr, struct f_struct *f_str)
21681 {
21682 X  int i0, i1;
21683 X  int op, lenc, nd, ns, itmp;
21684 X  char *sp0, *sp0a, *sp1, *spa, *sq;
21685 X  int *rp;
21686 X  int mins, smins;
21687 X  
21688 X  if (pst.ext_sq_set) {
21689 X    sq = pst.sqx;
21690 X  }
21691 X  else {
21692 X    sq = pst.sq;
21693 X  }
21694 X
21695 X  aln->amin0 = a_res.min0;
21696 X  aln->amax0 = a_res.max0;
21697 X  aln->amin1 = a_res.min1;
21698 X  aln->amax1 = a_res.max1;
21699 X
21700 X  /* first fill in the ends */
21701 X
21702 X  if (min(a_res.min0,a_res.min1)<aln->llen || aln->showall==1)     /* will we show all the start ?*/
21703 X    if (a_res.min0>=a_res.min1) {              /* aa0 extends more to left */
21704 X      smins=0;
21705 X      if (aln->showall==1) mins=a_res.min0;
21706 X      else mins = min(a_res.min0,aln->llcntx);
21707 X      aancpy(seqc0,(char *)aa0+a_res.min0-mins,mins,pst);
21708 X      aln->smin0 = a_res.min0-mins;
21709 X      if ((mins-a_res.min1)>0) {
21710 X       memset(seqc1,' ',mins-a_res.min1);
21711 X       aancpy(seqc1+mins-a_res.min1,(char *)aa1,a_res.min1,pst);
21712 X       aln->smin1 = 0;
21713 X      }
21714 X      else {
21715 X       aancpy(seqc1,(char *)aa1+a_res.min1-mins,mins,pst);
21716 X       aln->smin1 = a_res.min1-mins;
21717 X      }
21718 X    }
21719 X    else {
21720 X      smins=0;
21721 X      if (aln->showall == 1) mins=a_res.min1;
21722 X      else mins = min(a_res.min1,aln->llcntx);
21723 X      aancpy(seqc1,(char *)(aa1+a_res.min1-mins),mins,pst);
21724 X      aln->smin1 = a_res.min1-mins;
21725 X      if ((mins-a_res.min0)>0) {
21726 X       memset(seqc0,' ',mins-a_res.min0);
21727 X       aancpy(seqc0+mins-a_res.min0,(char *)aa0,a_res.min0,pst);
21728 X       aln->smin0 = 0;
21729 X      }
21730 X      else {
21731 X       aancpy(seqc0,(char *)aa0+a_res.min0-mins,mins,pst);
21732 X       aln->smin0 = a_res.min0-mins;
21733 X      }
21734 X    }
21735 X  else {
21736 X    mins= min(aln->llcntx,min(a_res.min0,a_res.min1));
21737 X    smins=mins;
21738 X    aln->smin0=a_res.min0 - smins;
21739 X    aln->smin1=a_res.min1 - smins;
21740 X    aancpy(seqc0,(char *)aa0+a_res.min0-mins,mins,pst);
21741 X    aancpy(seqc1,(char *)aa1+a_res.min1-mins,mins,pst);
21742 X  }
21743 X
21744 /* now get the middle */
21745 X
21746 X  memset(seqca,M_BLANK,mins);
21747 X  memset(seqc0a,' ',mins);
21748 X
21749 X  spa = seqca+mins;
21750 X  sp0 = seqc0+mins;
21751 X  sp0a = seqc0a+mins;
21752 X  sp1 = seqc1+mins;
21753 X  rp = a_res.res;
21754 X  lenc = aln->nident = aln->nsim = aln->ngap_q = aln->ngap_l = aln->nfs =op = 0;
21755 X  i0 = a_res.min0;
21756 X  i1 = a_res.min1;
21757 X  
21758 X  while (i0 < a_res.max0 || i1 < a_res.max1) {
21759 X    if (op == 0 && *rp == 0) {
21760 X      op = *rp++;
21761 X      lenc++;
21762 X      if ((itmp=f_str->pam2p[0][i0][aa1[i1]])<0) { *spa = M_NEG; }
21763 X      else if (itmp == 0) { *spa = M_ZERO;}
21764 X      else {*spa = M_POS;}
21765 X      if (*spa == M_POS || *spa==M_ZERO) aln->nsim++;
21766 X
21767 X      *sp0a++ = ann_arr[aa0a[i0]];
21768 X      *sp0 = sq[aa0[i0++]];
21769 X      *sp1 = sq[aa1[i1++]];
21770 X
21771 X      if (toupper(*sp0) == toupper(*sp1)) {aln->nident++; *spa = M_IDENT;}
21772 X      else if (pst.nt_align && ((*sp0 == 'T' && *sp1 == 'U') ||
21773 X                               (*sp0=='U' && *sp1=='T'))) {
21774 X       aln->nident++; *spa=M_IDENT;
21775 X      }
21776 X
21777 X      sp0++; sp1++; spa++;
21778 X    }
21779 X    else {
21780 X      if (op==0) op = *rp++;
21781 X      if (op>0) {
21782 X       *sp0++ = '-';
21783 X       *sp1++ = sq[aa1[i1++]];
21784 X       *spa++ = M_DEL;
21785 X       *sp0a++ = ' ';
21786 X       op--;
21787 X       lenc++;
21788 X       aln->ngap_q++;
21789 X      }
21790 X      else {
21791 X       *sp0a++ = ann_arr[aa0a[i0]];
21792 X       *sp0++ = sq[aa0[i0++]];
21793 X       *sp1++ = '-';
21794 X       *spa++ = M_DEL;
21795 X       op++;
21796 X       lenc++;
21797 X       aln->ngap_l++;
21798 X      }
21799 X    }
21800 X  }
21801 X
21802 X  *nc = lenc;
21803 X  *sp0a = *spa = '\0';
21804 /*      now we have the middle, get the right end */
21805 X
21806 X  /* how much extra to show at end ? */
21807 X  if (!aln->llcntx_flg) {
21808 X    ns = mins + lenc + aln->llen;      /* show an extra line? */
21809 X    ns -= (itmp = ns %aln->llen);      /* itmp = left over on last line */
21810 X    if (itmp>aln->llen/2) ns += aln->llen;  /* more than 1/2 , use another*/
21811 X    nd = ns - (mins+lenc);             /* this much extra */
21812 X  }
21813 X  else nd = aln->llcntx;
21814 X
21815 X  if (nd > max(n0-a_res.max0,n1-a_res.max1))
21816 X    nd = max(n0-a_res.max0,n1-a_res.max1);
21817 X  
21818 X  if (aln->showall==1) {
21819 X    nd = max(n0-a_res.max0,n1-a_res.max1);     /* reset for showall=1 */
21820 X    /* get right end */
21821 X    aancpy(seqc0+mins+lenc,(char *)aa0+a_res.max0,n0-a_res.max0,pst);
21822 X    aancpy(seqc1+mins+lenc,(char *)aa1+a_res.max1,n1-a_res.max1,pst);
21823 X    /* fill with blanks - this is required to use one 'nc' */
21824 X    memset(seqc0+mins+lenc+n0-a_res.max0,' ',nd-(n0-a_res.max0));
21825 X    memset(seqc1+mins+lenc+n1-a_res.max1,' ',nd-(n1-a_res.max1));
21826 X  }
21827 X  else {
21828 X     if ((nd-(n0-a_res.max0))>0) {
21829 X       aancpy(seqc0+mins+lenc,(char *)aa0+a_res.max0,n0-a_res.max0,pst);
21830 X       memset(seqc0+mins+lenc+n0-a_res.max0,' ',nd-(n0-a_res.max0));
21831 X     }
21832 X     else aancpy(seqc0+mins+lenc,(char *)aa0+a_res.max0,nd,pst);
21833 X
21834 X     if ((nd-(n1-a_res.max1))>0) {
21835 X       aancpy(seqc1+mins+lenc,(char *)aa1+a_res.max1,n1-a_res.max1,pst);
21836 X       memset(seqc1+mins+lenc+n1-a_res.max1,' ',nd-(n1-a_res.max1));
21837 X     }
21838 X     else aancpy(seqc1+mins+lenc,(char *)aa1+a_res.max1,nd,pst);
21839 X }
21840 X  
21841 X  return mins+lenc+nd;
21842 }
21843 X
21844 static void
21845 update_code(char *al_str, int al_str_max, int op, int op_cnt);
21846 X
21847 /* build an array of match/ins/del - length strings */
21848 int calc_code(const unsigned char *aa0, int n0,
21849 X             const unsigned char *aa1, int n1,
21850 X             struct a_struct *aln,
21851 X             struct a_res_str a_res,
21852 X             struct pstruct pst,
21853 X             char *al_str, int al_str_n, struct f_struct *f_str)
21854 {
21855 X  int i0, i1, nn1;
21856 X  int op, lenc;
21857 X  int p_op, op_cnt;
21858 X  const unsigned char *aa1p;
21859 X  char tmp_cnt[20];
21860 X  char sp0, sp1, *sq;
21861 X  int *rp;
21862 X
21863 X  if (pst.ext_sq_set) {
21864 X    sq = pst.sqx;
21865 X  }
21866 X  else {
21867 X    sq = pst.sq;
21868 X  }
21869 X
21870 #ifndef TFAST
21871 X  aa1p = aa1;
21872 X  nn1 = n1;
21873 #else
21874 X  aa1p = f_str->aa1x;
21875 X  nn1 = f_str->n10;
21876 #endif
21877 X
21878 X  aln->amin0 = a_res.min0;
21879 X  aln->amax0 = a_res.max0;
21880 X  aln->amin1 = a_res.min1;
21881 X  aln->amax1 = a_res.max1;
21882 X
21883 X  rp = a_res.res;
21884 X  lenc = aln->nident = aln->nsim = aln->ngap_q = aln->ngap_l = aln->nfs = op = p_op = 0;
21885 X  op_cnt = 0;
21886 X
21887 X  i0 = a_res.min0;
21888 X  i1 = a_res.min1;
21889 X  tmp_cnt[0]='\0';
21890 X  
21891 X  while (i0 < a_res.max0 || i1 < a_res.max1) {
21892 X    if (op == 0 && *rp == 0) {
21893 X
21894 X      if (pst.pam2[0][aa0[i0]][aa1p[i1]]>=0) { aln->nsim++;}
21895 X
21896 X      sp0 = sq[aa0[i0++]];
21897 X      sp1 = sq[aa1p[i1++]];
21898 X
21899 X      if (p_op == 0 || p_op==3) {
21900 X       if (sp0 != '*' && sp1 != '*') {
21901 X         if (p_op == 3) {
21902 X           update_code(al_str,al_str_n-strlen(al_str),p_op,op_cnt);
21903 X           op_cnt = 1; p_op = 0;
21904 X         }
21905 X         else {op_cnt++;}
21906 X       }
21907 X       else {
21908 X         update_code(al_str,al_str_n-strlen(al_str),p_op,op_cnt);
21909 X         op_cnt = 1; p_op = 3;
21910 X       }
21911 X      }
21912 X      else {
21913 X       update_code(al_str,al_str_n-strlen(al_str),p_op,op_cnt);
21914 X       op_cnt = 1; p_op = 0;
21915 X      }
21916 X
21917 X      op = *rp++;
21918 X      lenc++;
21919 X
21920 X      if (toupper(sp0) == toupper(sp1)) aln->nident++;
21921 X      else if (pst.nt_align) {
21922 X       if ((toupper(sp0) == 'T' && toupper(sp1) == 'U') ||
21923 X           (toupper(sp0)=='U' && toupper(sp1)=='T')) aln->nident++;
21924 X       else if (toupper(sp0) == 'N') aln->ngap_q++;
21925 X       else if (toupper(sp1) == 'N') aln->ngap_l++;
21926 X      }
21927 X    }
21928 X    else {
21929 X      if (op==0) op = *rp++;
21930 X      if (op>0) {
21931 X       if (p_op == 1) { op_cnt++;}
21932 X       else {
21933 X         update_code(al_str,al_str_n - strlen(al_str),p_op,op_cnt);
21934 X         op_cnt = 1; p_op = 1;
21935 X       }
21936 X       op--; lenc++; i1++; aln->ngap_q++;
21937 X      }
21938 X      else {
21939 X       if (p_op == 2) { op_cnt++;}
21940 X       else {
21941 X         update_code(al_str,al_str_n - strlen(al_str),p_op,op_cnt);
21942 X         op_cnt = 1; p_op = 2;
21943 X       }
21944 X       op++; lenc++; i0++; aln->ngap_l++;
21945 X      }
21946 X    }
21947 X  }
21948 X  update_code(al_str,al_str_n - strlen(al_str),p_op,op_cnt);
21949 X
21950 X  return lenc;
21951 }
21952 X
21953 static void
21954 update_code(char *al_str, int al_str_max, int op, int op_cnt) {
21955 X
21956 X  char op_char[5]={"=-+*"};
21957 X  char tmp_cnt[20];
21958 X
21959 X  sprintf(tmp_cnt,"%c%d",op_char[op],op_cnt);
21960 X  strncat(al_str,tmp_cnt,al_str_max);
21961 }
21962 X
21963 int calc_id(const unsigned char *aa0, int n0,
21964 X           const unsigned char *aa1, int n1,
21965 X           struct a_struct *aln, 
21966 X           struct a_res_str a_res,
21967 X           struct pstruct pst,
21968 X           struct f_struct *f_str)
21969 {
21970 X  int i0, i1, nn1, n_id;
21971 X  int op, lenc;
21972 X  int sp0, sp1;
21973 X  const unsigned char *aa1p;
21974 X  int *rp;
21975 X  char *sq;
21976 X  
21977 X  if (pst.ext_sq_set) {
21978 X    sq = pst.sqx;
21979 X  }
21980 X  else {
21981 X    sq = pst.sq;
21982 X  }
21983 X
21984 #ifndef TFAST
21985 X  aa1p = aa1;
21986 X  nn1 = n1;
21987 #else
21988 X  aa1p = f_str->aa1x;
21989 X  nn1 = f_str->n10;
21990 #endif
21991 X
21992 X  aln->amin0 = a_res.min0;
21993 X  aln->amax0 = a_res.max0;
21994 X  aln->amin1 = a_res.min1;
21995 X  aln->amax1 = a_res.max1;
21996 X
21997 X  rp = a_res.res;
21998 X  lenc = n_id = aln->nsim = aln->ngap_q = aln->ngap_l = aln->nfs = op = 0;
21999 X  i0 = a_res.min0;
22000 X  i1 = a_res.min1;
22001 X
22002 X  while (i0 < a_res.max0 || i1 < a_res.max1) {
22003 X    if (op == 0 && *rp == 0) {
22004 X      op = *rp++;
22005 X      lenc++;
22006 X      if (pst.pam2[0][aa0[i0]][aa1p[i1]]>=0) { aln->nsim++;}
22007 X
22008 X      sp0 = sq[aa0[i0++]];
22009 X      sp1 = sq[aa1p[i1++]];
22010 X      if (toupper(sp0) == toupper(sp1)) n_id++;
22011 X      else if (pst.nt_align &&
22012 X              ((sp0=='T' && sp1== 'U')||(sp0=='U' && sp1=='T'))) n_id++;
22013 X    }
22014 X    else {
22015 X      if (op==0) op = *rp++;
22016 X      if (op>0) {op--; lenc++; i1++; aln->ngap_q++; }
22017 X      else {op++; lenc++; i0++;        aln->ngap_l++; }
22018 X    }
22019 X  }
22020 X  aln->nident = n_id;
22021 X  return lenc;
22022 }
22023 X
22024 #ifdef PCOMPLIB
22025 #include "p_mw.h"
22026 void
22027 update_params(struct qmng_str *qm_msg, struct pstruct *ppst)
22028 {
22029 X  ppst->n0 = qm_msg->n0;
22030 }
22031 #endif
22032 SHAR_EOF
22033 chmod 0644 dropgsw.c ||
22034 echo 'restore of dropgsw.c failed'
22035 Wc_c="`wc -c < 'dropgsw.c'`"
22036 test 55870 -eq "$Wc_c" ||
22037         echo 'dropgsw.c: original size 55870, current size' "$Wc_c"
22038 fi
22039 # ============= dropgsw.h ==============
22040 if test -f 'dropgsw.h' -a X"$1" != X"-c"; then
22041         echo 'x - skipping dropgsw.h (File already exists)'
22042 else
22043 echo 'x - extracting dropgsw.h (Text)'
22044 sed 's/^X//' << 'SHAR_EOF' > 'dropgsw.h' &&
22045 X
22046 /* global definitions shared by dropgsw.c and altivec.c */
22047 X
22048 /* definitions for SW */
22049 X
22050 struct f_struct {
22051 X  struct swstr *ss;
22052 X  struct swstr *f_ss, *r_ss;
22053 X  int *waa_s, *waa_a;
22054 X  int **pam2p[2];
22055 X  int *res;
22056 X  double aa0_f[MAXSQ];
22057 X  double *kar_p;
22058 #if defined(SW_ALTIVEC) || defined(SW_SSE2)
22059 X  unsigned char      bias;
22060 X  unsigned short *   word_score;
22061 X  unsigned char *    byte_score;
22062 X  void *             workspace;
22063 X  int                alphabet_size;
22064 X  void *             word_score_memory;
22065 X  void *             byte_score_memory;
22066 X  void *             workspace_memory;
22067 X  int                try_8bit;
22068 X  int                done_8bit;
22069 X  int                done_16bit;
22070 #endif
22071 };
22072 X
22073 SHAR_EOF
22074 chmod 0644 dropgsw.h ||
22075 echo 'restore of dropgsw.h failed'
22076 Wc_c="`wc -c < 'dropgsw.h'`"
22077 test 677 -eq "$Wc_c" ||
22078         echo 'dropgsw.h: original size 677, current size' "$Wc_c"
22079 fi
22080 # ============= dropnfa.c ==============
22081 if test -f 'dropnfa.c' -a X"$1" != X"-c"; then
22082         echo 'x - skipping dropnfa.c (File already exists)'
22083 else
22084 echo 'x - extracting dropnfa.c (Text)'
22085 sed 's/^X//' << 'SHAR_EOF' > 'dropnfa.c' &&
22086 X
22087 /* copyright (c) 1998, 1999 William R. Pearson and the U. of Virginia */
22088 X
22089 /* $Name: fa_34_26_5 $ - $Id: dropnfa.c,v 1.81 2007/04/26 18:37:19 wrp Exp $ */
22090 X
22091 /* 18-Sep-2006 - removed global variables for alignment from nw_align
22092 X   and bg_align */
22093 X
22094 /* 18-Oct-2005 - converted to use a_res and aln for alignment coordinates */
22095 X
22096 /* 14-May-2003 - modified to return alignment start at 0, rather than
22097 X   1, for begin:end alignments
22098 */
22099 X
22100 /*
22101 X  implements the fasta algorithm, see:
22102 X
22103 X  W. R. Pearson, D. J. Lipman (1988) "Improved tools for biological
22104 X  sequence comparison" Proc. Natl. Acad. Sci. USA 85:2444-2448
22105 X
22106 X  This version uses Smith-Waterman for final protein alignments
22107 X
22108 X  W. R. Pearson (1996) "Effective protein sequence comparison"
22109 X  Methods Enzymol. 266:227-258
22110 X
22111 X
22112 X  26-April-2001 - -DGAP_OPEN redefines -f, as gap open penalty
22113 X
22114 X  4-Nov-2001 - modify spam() while(1).
22115 */
22116 X
22117 #include <stdio.h>
22118 #include <stdlib.h>
22119 #include <string.h>
22120 #include <ctype.h>
22121 #include <math.h>
22122 X
22123 #include "defs.h"
22124 #include "param.h"
22125 X
22126 /* this must be consistent with upam.h */
22127 #define MAXHASH 32
22128 #define NMAP MAXHASH+1
22129 X
22130 /* globals for fasta */
22131 #define MAXWINDOW 64
22132 X
22133 #ifndef MAXSAV
22134 #define MAXSAV 10
22135 #endif
22136 X
22137 #ifndef ALLOCN0
22138 static char *verstr="3.5 Sept 2006";
22139 #else
22140 static char *verstr="3.5an0 Sept 2006";
22141 #endif
22142 X
22143 extern void w_abort(char *, char *);
22144 int shscore(const unsigned char *aa0, int n0, int **pam2);
22145 extern void init_karlin(const unsigned char *aa0, int n0, struct pstruct *ppst,
22146 X                       double *aa0_f, double **kp);
22147 extern void init_karlin_a(struct pstruct *, double *, double **);
22148 extern int do_karlin(const unsigned char *, int n1, int **,
22149 X                    struct pstruct *, double *, double *,
22150 X                    double *, double *);
22151 extern void aancpy(char *to, char *from, int count, struct pstruct pst);
22152 char *ckalloc(size_t);
22153 X
22154 #ifdef TFASTA
22155 extern int aatran(const unsigned char *ntseq, unsigned char *aaseq, int maxs, int frame);
22156 #endif
22157 X
22158 #include "dropnfa.h"
22159 X
22160 #define DROP_INTERN
22161 #include "drop_func.h"
22162 X
22163 struct swstr { int H, E;};
22164 X
22165 static int
22166 dmatch (const unsigned char *aa0, int n0,
22167 X       const unsigned char *aa1, int n1,
22168 X       int hoff, int window, 
22169 X       int **pam2, int gdelval, int ggapval,
22170 X       struct f_struct *f_str);
22171 X
22172 /* initialize for fasta */
22173 X
22174 void
22175 init_work (unsigned char *aa0, int n0, 
22176 X          struct pstruct *ppst,
22177 X          struct f_struct **f_arg)
22178 {
22179 X   int mhv, phv;
22180 X   int hmax;
22181 X   int i0, hv;
22182 X   int pamfact;
22183 X   int btemp;
22184 X   struct f_struct *f_str;
22185 X   /* these used to be globals, but do not need to be */
22186 X   int ktup;           /* word size examined */
22187 X   int fact;           /* factor used to scale ktup match value */
22188 X   int kt1;            /* ktup-1 */
22189 X   int lkt;            /* last ktup - initiall kt1, but can be increased
22190 X                          for hsq >= NMAP */
22191 X
22192 X   int maxn0;          /* used in band alignment */
22193 X   int *pwaa;          /* pam[aa0[]] profile */
22194 X   int i, j;
22195 X   struct swstr *ss;
22196 X   int *waa;
22197 X   int nsq, ip, *hsq;
22198 X
22199 X   if (ppst->ext_sq_set) {
22200 X     nsq = ppst->nsqx; ip = 1;
22201 X     hsq = ppst->hsqx;
22202 X   }
22203 X   else {
22204 X     nsq = ppst->nsq; ip = 0;
22205 X     hsq = ppst->hsq;
22206 X   }
22207 X
22208 X  f_str = (struct f_struct *)calloc(1,sizeof(struct f_struct));
22209 X
22210 #ifndef TFASTA
22211 X  if((ppst->zsflag%10) == 6) {
22212 X    f_str->kar_p = NULL;
22213 X    init_karlin(aa0, n0, ppst, &f_str->aa0_f[0], &f_str->kar_p);
22214 X  }
22215 #endif
22216 X
22217 X  btemp = 2 * ppst->param_u.fa.bestoff / 3 +
22218 X    n0 / ppst->param_u.fa.bestscale +
22219 X    ppst->param_u.fa.bkfact *
22220 X    (ppst->param_u.fa.bktup - ppst->param_u.fa.ktup);
22221 X
22222 X  if (ppst->nt_align)
22223 X     btemp = (btemp*ppst->pam_h)/5;  /* normalize to standard +5/-4 */
22224 X
22225 X   btemp = min (btemp, ppst->param_u.fa.bestmax);
22226 X   if (btemp > 3 * n0) btemp = 3 * shscore(aa0,n0,ppst->pam2[0]) / 5;
22227 X
22228 X   ppst->param_u.fa.cgap = btemp + ppst->param_u.fa.bestoff / 3;
22229 X
22230 X   if (ppst->param_u.fa.optcut_set != 1)
22231 #ifndef TFASTA
22232 X      ppst->param_u.fa.optcut = btemp;
22233 #else
22234 X      ppst->param_u.fa.optcut = (btemp*3)/2;
22235 #endif
22236 X
22237 #ifndef OLD_FASTA_GAP
22238 X   ppst->param_u.fa.pgap = ppst->gdelval + 2*ppst->ggapval;
22239 #else
22240 X   ppst->param_u.fa.pgap = ppst->gdelval + ppst->ggapval;
22241 #endif
22242 X   pamfact = ppst->param_u.fa.pamfact;
22243 X   ktup = ppst->param_u.fa.ktup;
22244 X   fact = ppst->param_u.fa.scfact * ktup;
22245 X
22246 X   if (pamfact == -1) pamfact = 0;
22247 X   else if (pamfact == -2) pamfact = 1;
22248 X
22249 X   for (i0 = 1, mhv = -1; i0 <= ppst->nsq; i0++)
22250 X      if (hsq[i0] < NMAP && hsq[i0] > mhv) mhv = hsq[i0];
22251 X
22252 X   if (mhv <= 0) {
22253 X      fprintf (stderr, " maximum hsq <=0 %d\n", mhv);
22254 X      exit (1);
22255 X   }
22256 X
22257 X   for (f_str->kshft = 0; mhv > 0; mhv /= 2) f_str->kshft++;
22258 X
22259 /*      kshft = 2;      */
22260 X   kt1 = ktup - 1;
22261 X   hv = 1;
22262 X   for (i0 = 0; i0 < ktup; i0++) hv = hv << f_str->kshft;
22263 X   hmax = hv;
22264 X   f_str->hmask = (hmax >> f_str->kshft) - 1;
22265 X
22266 X   if ((f_str->harr = (int *) calloc (hmax, sizeof (int))) == NULL) {
22267 X     fprintf (stderr, " cannot allocate hash array: hmax: %d hmask: %d\n",
22268 X             hmax, f_str->hmask);
22269 X     exit (1);
22270 X   }
22271 X
22272 X   if ((f_str->pamh1 = (int *) calloc (nsq+1, sizeof (int))) == NULL) {
22273 X     fprintf (stderr, " cannot allocate pamh1 array nsq=%d\n",nsq);
22274 X     exit (1);
22275 X   }
22276 X
22277 X   if ((f_str->pamh2 = (int *) calloc (hmax, sizeof (int))) == NULL) {
22278 X     fprintf (stderr, " cannot allocate pamh2 array hmax=%d\n",hmax);
22279 X     exit (1);
22280 X   }
22281 X
22282 X   if ((f_str->link = (int *) calloc (n0, sizeof (int))) == NULL) {
22283 X     fprintf (stderr, " cannot allocate hash link array n0=%d",n0);
22284 X     exit (1);
22285 X   }
22286 X
22287 X   for (i0 = 0; i0 < hmax; i0++) f_str->harr[i0] = -1;
22288 X   for (i0 = 0; i0 < n0; i0++) f_str->link[i0] = -1;
22289 X
22290 X   /* encode the aa0 array */
22291 X   phv = hv = 0;
22292 X   lkt = kt1;
22293 X   /* restart hv, phv calculation */
22294 X   for (i0 = 0; i0 < min(lkt,n0); i0++) {
22295 X     if (hsq[aa0[i0]] >= NMAP) {hv=phv=0; lkt = i0+ ktup; continue;}
22296 X     hv = (hv << f_str->kshft) + hsq[aa0[i0]];
22297 X     phv += ppst->pam2[ip][aa0[i0]][aa0[i0]]*ktup;
22298 X   }
22299 X
22300 X   for (; i0 < n0; i0++) {
22301 X     if (hsq[aa0[i0]] >= NMAP) {
22302 X       hv=phv=0;
22303 X       /* restart hv, phv calculation */
22304 X       for (lkt = i0+kt1; (i0 < lkt || hsq[aa0[i0]]>=NMAP) && i0<n0; i0++) {
22305 X        if (hsq[aa0[i0]] >= NMAP) {
22306 X          hv=phv=0; 
22307 X          lkt = i0+ktup;
22308 X          continue;
22309 X        }
22310 X        hv = (hv << f_str->kshft) + hsq[aa0[i0]];
22311 X        phv += ppst->pam2[ip][aa0[i0]][aa0[i0]]*ktup;
22312 X       }
22313 X     }
22314 X     if (i0 >= n0) break;
22315 X     hv = ((hv & f_str->hmask) << f_str->kshft) + hsq[aa0[i0]];
22316 X     f_str->link[i0] = f_str->harr[hv];
22317 X     f_str->harr[hv] = i0;
22318 X     if (pamfact) {
22319 X       f_str->pamh2[hv] = (phv += ppst->pam2[ip][aa0[i0]][aa0[i0]] * ktup);
22320 X       /* this check should always be true, but just in case */
22321 X       if (hsq[aa0[i0-kt1]]<NMAP)
22322 X        phv -= ppst->pam2[ip][aa0[i0 - kt1]][aa0[i0 - kt1]] * ktup;
22323 X     }
22324 X     else f_str->pamh2[hv] = fact * ktup;
22325 X   }
22326 X
22327 /* this has been modified from 0..<ppst->nsq to 1..<=ppst->nsq because the
22328 X   pam2[0][0] is now undefined for consistency with blast
22329 */
22330 X
22331 X   if (pamfact)
22332 X      for (i0 = 1; i0 <= nsq; i0++)
22333 X        f_str->pamh1[i0] = ppst->pam2[ip][i0][i0] * ktup;
22334 X   else
22335 X      for (i0 = 1; i0 <= nsq; i0++)
22336 X        f_str->pamh1[i0] = fact;
22337 X
22338 X   f_str->ndo = 0;
22339 X   f_str->noff = n0-1;
22340 #ifndef ALLOCN0
22341 X   if ((f_str->diag = (struct dstruct *) calloc ((size_t)MAXDIAG,
22342 X                                                sizeof (struct dstruct)))==NULL) {
22343 X      fprintf (stderr," cannot allocate diagonal arrays: %lu\n",
22344 X             MAXDIAG *sizeof (struct dstruct));
22345 X      exit (1);
22346 X     };
22347 #else
22348 X   if ((f_str->diag = (struct dstruct *) calloc ((size_t)n0,
22349 X                                             sizeof (struct dstruct)))==NULL) {
22350 X      fprintf (stderr," cannot allocate diagonal arrays: %ld\n",
22351 X             (long)n0*sizeof (struct dstruct));
22352 X      exit (1);
22353 X     };
22354 #endif
22355 X
22356 X
22357 #ifdef TFASTA
22358 X   if ((f_str->aa1x =(unsigned char *)calloc((size_t)ppst->maxlen+2,
22359 X                                            sizeof(unsigned char)))
22360 X       == NULL) {
22361 X     fprintf (stderr, "cannot allocate aa1x array %d\n", ppst->maxlen+2);
22362 X     exit (1);
22363 X   }
22364 X   f_str->aa1x++;
22365 #endif
22366 X
22367 X   f_str->bss = (struct bdstr *) calloc((size_t)ppst->param_u.fa.optwid*2+4,
22368 X                                       sizeof(struct bdstr));
22369 X   f_str->bss++;
22370 X  
22371 X   /* allocate space for the scoring arrays */
22372 X   maxn0 = n0 + 4;
22373 X   if ((ss = (struct swstr *) calloc (maxn0, sizeof (struct swstr)))
22374 X        == NULL) {
22375 X     fprintf (stderr, "cannot allocate ss array %3d\n", n0);
22376 X     exit (1);
22377 X   }
22378 X   ss++;
22379 X   f_str->ss = ss;
22380 X
22381 X   /* initialize the "variable" pam array */
22382 X
22383 X   if ((waa= (int *)calloc ((size_t)(nsq+1)*n0,sizeof(int))) == NULL) {
22384 X     fprintf(stderr,"cannot allocate waa struct %3d\n",nsq*n0);
22385 X     exit(1);
22386 X   }
22387 X
22388 X   pwaa = waa;
22389 X   for (i=0; i<=nsq; i++) {
22390 X     for (j=0;j<n0; j++) {
22391 X       *pwaa = ppst->pam2[ip][aa0[j]][i];
22392 X       pwaa++;
22393 X     }
22394 X   }
22395 X   f_str->waa0 = waa;
22396 X
22397 X   /* initialize the "conventional" pam array used for alignments */
22398 X
22399 X   if ((waa= (int *)calloc ((size_t)(nsq+1)*n0,sizeof(int))) == NULL) {
22400 X     fprintf(stderr,"cannot allocate waa struct %3d\n",nsq*n0);
22401 X     exit(1);
22402 X   }
22403 X
22404 X   pwaa = waa;
22405 X   for (i=0; i<=nsq; i++) {
22406 X     for (j=0;j<n0; j++) {
22407 X       *pwaa = ppst->pam2[0][aa0[j]][i];
22408 X       pwaa++;
22409 X     }
22410 X   }
22411 X   f_str->waa1 = waa;
22412 X
22413 X   f_str->max_res = max(3*n0/2,MIN_RES);
22414 X
22415 X   /* now we need alignment storage - get it */
22416 X   if ((f_str->res = (int *)calloc((size_t)f_str->max_res,sizeof(int)))==NULL) {
22417 X     fprintf(stderr,"cannot allocate alignment results array %d\n",f_str->max_res);
22418 X     exit(1);
22419 X   }
22420 X
22421 X   *f_arg = f_str;
22422 }
22423 X
22424 X
22425 /* pstring1 is a message to the manager, currently 512 */
22426 /* pstring2 is the same information, but in a markx==10 format */
22427 void
22428 get_param (struct pstruct *pstr, char *pstring1, char *pstring2)
22429 {
22430 #ifndef TFASTA
22431 X  char *pg_str="FASTA";
22432 #else
22433 X  char *pg_str="TFASTA";
22434 #endif
22435 X
22436 X   if (!pstr->param_u.fa.optflag)
22437 #ifdef OLD_FASTA_GAP
22438 X     sprintf (pstring1, "%s (%s) function [%s matrix, (%d:%d)%s] ktup: %d\n join: %d, gap-pen: %d/%d, width: %3d",
22439 #else
22440 X     sprintf (pstring1, "%s (%s) function [%s matrix, (%d:%d)%s] ktup: %d\n join: %d, open/ext: %d/%d, width: %3d",
22441 #endif
22442 X             pg_str,verstr,pstr->pamfile, pstr->pam_h,pstr->pam_l,
22443 X             (pstr->ext_sq_set) ? "xS":"\0",
22444 X             pstr->param_u.fa.ktup, pstr->param_u.fa.cgap,
22445 X              pstr->gdelval, pstr->ggapval, pstr->param_u.fa.optwid);
22446 X   else
22447 #ifdef OLD_FASTA_GAP
22448 X      sprintf (pstring1, "%s (%s) function [optimized, %s matrix (%d:%d)%s] ktup: %d\n join: %d, opt: %d, gap-pen: %d/%d, width: %3d",
22449 #else
22450 X      sprintf (pstring1, "%s (%s) function [optimized, %s matrix (%d:%d)%s] ktup: %d\n join: %d, opt: %d, open/ext: %d/%d, width: %3d",
22451 #endif
22452 X              pg_str,verstr,pstr->pamfile, pstr->pam_h,pstr->pam_l,
22453 X              (pstr->ext_sq_set) ? "xS":"\0",
22454 X              pstr->param_u.fa.ktup, pstr->param_u.fa.cgap,
22455 X              pstr->param_u.fa.optcut, pstr->gdelval, pstr->ggapval,
22456 X              pstr->param_u.fa.optwid);
22457 X   if (pstr->param_u.fa.iniflag) strcat(pstring1," init1");
22458 X   /*
22459 X   if (pstr->zsflag==0) strcat(pstring1," not-scaled");
22460 X   else if (pstr->zsflag==1) strcat(pstring1," reg.-scaled");
22461 X   */
22462 X
22463 X   if (pstring2 != NULL) {
22464 #ifdef OLD_FASTA_GAP
22465 X     sprintf (pstring2, "; pg_name: %s\n; pg_ver: %s\n; pg_matrix: %s (%d:%d)\n\
22466 ; pg_gap-pen: %d %d\n; pg_ktup: %d\n; pg_optcut: %d\n; pg_cgap: %d\n",
22467 #else
22468 X     sprintf (pstring2, "; pg_name: %s\n; pg_ver: %s\n; pg_matrix: %s (%d:%d)\n\
22469 ; pg_open-ext: %d %d\n; pg_ktup: %d\n; pg_optcut: %d\n; pg_cgap: %d\n",
22470 #endif
22471 X             pg_str,verstr,pstr->pamfile, pstr->pam_h,pstr->pam_l, pstr->gdelval,
22472 X              pstr->ggapval,pstr->param_u.fa.ktup,pstr->param_u.fa.optcut,
22473 X             pstr->param_u.fa.cgap);
22474 X   }
22475 }
22476 X
22477 void
22478 close_work (const unsigned char *aa0, int n0,
22479 X           struct pstruct *ppst,
22480 X           struct f_struct **f_arg)
22481 {
22482 X  struct f_struct *f_str;
22483 X
22484 X
22485 X  f_str = *f_arg;
22486 X
22487 X
22488 X  if (f_str != NULL) {
22489 X    if (f_str->kar_p!=NULL) free(f_str->kar_p);
22490 X    f_str->ss--;
22491 X    f_str->bss--;
22492 X
22493 X    free(f_str->res);
22494 X    free(f_str->waa1);
22495 X    free(f_str->waa0);
22496 X    free(f_str->ss);
22497 X    free(f_str->bss);
22498 X    free(f_str->diag);
22499 X    free(f_str->link);
22500 X    free(f_str->pamh2); 
22501 X    free(f_str->pamh1);
22502 X    free(f_str->harr);
22503 X
22504 X    free(f_str);
22505 X    *f_arg = NULL;
22506 X  }
22507 }
22508 X
22509 #ifdef ALLOCN0
22510 void savemax (struct dstruct *, int, struct f_struct *);
22511 #else
22512 void savemax (struct dstruct *, struct f_struct *);
22513 #endif
22514 X
22515 int spam (const unsigned char *, const unsigned char *, struct savestr *,
22516 X        int **, int, int, int);
22517 int sconn(struct savestr **, int nsave, int cgap, int pgap, int noff);
22518 void kpsort(struct savestr **, int);
22519 X
22520 static int
22521 ALIGN(const unsigned char *, const unsigned char *, int, int, 
22522 X      int **, int, int, int *, int *, struct f_struct *);
22523 X
22524 static int
22525 LOCAL_ALIGN(const unsigned char *, const unsigned char *,
22526 X           int, int, int, int,
22527 X           int **, int, int, int *, int *, int *, int *, int,
22528 X           struct f_struct *);
22529 X
22530 static int
22531 B_ALIGN(const unsigned char *A, const unsigned char *B, int M,
22532 X       int N, int low, int up, int **W, int G, int H, int *S,
22533 X       int *nS, int MW, int MX, struct bdstr *bss);
22534 X
22535 static void
22536 do_fasta (const unsigned char *aa0, int n0,
22537 X         const unsigned char *aa1, int n1,
22538 X         struct pstruct *ppst, struct f_struct *f_str,
22539 X         struct rstruct *rst, int *hoff)
22540 {
22541 X   int     nd;         /* diagonal array size */
22542 X   int     lhval;
22543 X   int     kfact;
22544 X   register struct dstruct *dptr;
22545 X   register int tscor;
22546 X
22547 #ifndef ALLOCN0
22548 X   register struct dstruct *diagp;
22549 #else
22550 X   register int dpos;
22551 X   int     lposn0;
22552 #endif
22553 X   int noff;
22554 X   struct dstruct *dpmax;
22555 X   register int lpos;
22556 X   int     tpos;
22557 X   struct savestr *vmptr;
22558 X   int     scor, ib, nsave;
22559 X   int xdrop, do_extend;
22560 X   int ktup, kt1, lkt, *hsq, ip;
22561 X
22562 X  if (ppst->ext_sq_set) {
22563 X    ip = 1;
22564 X    hsq = ppst->hsqx;
22565 X  }
22566 X  else {
22567 X    ip = 0;
22568 X    hsq = ppst->hsq;
22569 X  }
22570 X
22571 X  xdrop = -ppst->pam_l;
22572 X  /* do extended alignment in spam iff protein or short sequences */
22573 X  do_extend = !ppst->nt_align || (n0 < 50) || (n1 < 50);
22574 X
22575 X  ktup = ppst->param_u.fa.ktup;
22576 X  kt1 = ktup-1;
22577 X
22578 X  if (n1 < ktup) {
22579 X     rst->score[0] = rst->score[1] = rst->score[2] = 0;
22580 X     return;
22581 X   }
22582 X
22583 X   if (n0+n1+1 >= MAXDIAG) {
22584 X     fprintf(stderr,"n0,n1 too large: %d, %d\n",n0,n1);
22585 X     rst->score[0] = rst->score[1] = rst->score[2] = -1;
22586 X     return;
22587 X   }
22588 X
22589 #ifdef ALLOCN0
22590 X   nd = n0;
22591 #else
22592 X   nd = n0 + n1;
22593 #endif
22594 X
22595 X   dpmax = &f_str->diag[nd];
22596 X   for (dptr = &f_str->diag[f_str->ndo]; dptr < dpmax;)
22597 X   {
22598 X      dptr->stop = -1;
22599 X      dptr->dmax = NULL;
22600 X      dptr++->score = 0;
22601 X   }
22602 X
22603 X   for (vmptr = f_str->vmax; vmptr < &f_str->vmax[MAXSAV]; vmptr++)
22604 X      vmptr->score = 0;
22605 X   f_str->lowmax = f_str->vmax;
22606 X   f_str->lowscor = 0;
22607 X
22608 X   /* start hashing */
22609 X   lhval = 0;
22610 X   lkt = kt1;
22611 X   for (lpos = 0; (lpos < lkt || hsq[aa1[lpos]]>=NMAP) && lpos <n1; lpos++) {
22612 X     /* restart lhval calculation */
22613 X     if (hsq[aa1[lpos]]>=NMAP) {
22614 X       lhval = 0; lkt = lpos + ktup;
22615 X       continue;
22616 X     }
22617 X     lhval = ((lhval & f_str->hmask) << f_str->kshft) + hsq[aa1[lpos]];
22618 X   }
22619 X
22620 X   noff = f_str->noff;
22621 #ifndef ALLOCN0
22622 X   diagp = &f_str->diag[noff + lkt];
22623 X   for (; lpos < n1; lpos++, diagp++) {
22624 X     if (hsq[aa1[lpos]]>=NMAP) {
22625 X       lpos++ ; diagp++;
22626 X       while (lpos < n1 && hsq[aa1[lpos]]>=NMAP) {lpos++; diagp++;}
22627 X       if (lpos >= n1) break;
22628 X       lhval = 0;
22629 X     }
22630 X     lhval = ((lhval & f_str->hmask) << f_str->kshft) + hsq[aa1[lpos]];
22631 X     for (tpos = f_str->harr[lhval]; tpos >= 0; tpos = f_str->link[tpos]) {
22632 X       if ((tscor = (dptr = &diagp[-tpos])->stop) >= 0) {
22633 #else
22634 X   lposn0 = noff + lpos;
22635 X   for (; lpos < n1; lpos++, lposn0++) {
22636 X     if (hsq[aa1[lpos]]>=NMAP) {lhval = 0; goto loopl;}
22637 X     /*
22638 X     if (hsq[aa1[lpos]]>=NMAP) {
22639 X       lpos++; lposn0++;
22640 X       while (lpos < n1 && hsq[aa1[lpos]]>=NMAP) {lpos++; lposn0++;}
22641 X     }
22642 X     */
22643 X     lhval = ((lhval & f_str->hmask) << f_str->kshft) + hsq[aa1[lpos]];
22644 X     for (tpos = f_str->harr[lhval]; tpos >= 0; tpos = f_str->link[tpos]) {
22645 X       dpos = lposn0 - tpos;
22646 X       if ((tscor = (dptr = &f_str->diag[dpos % nd])->stop) >= 0) {
22647 #endif
22648 X        tscor += ktup;
22649 X        if ((tscor -= lpos) <= 0) {
22650 X          scor = dptr->score;
22651 X          if ((tscor += (kfact = f_str->pamh2[lhval])) < 0 && f_str->lowscor < scor)
22652 #ifdef ALLOCN0
22653 X            savemax (dptr, dpos, f_str);
22654 #else
22655 X            savemax (dptr, f_str);
22656 #endif
22657 X            if ((tscor += scor) >= kfact) {
22658 X              dptr->score = tscor;
22659 X              dptr->stop = lpos;
22660 X            }
22661 X            else {
22662 X              dptr->score = kfact;
22663 X              dptr->start = (dptr->stop = lpos) - kt1;
22664 X            }
22665 X        }
22666 X        else {
22667 X          dptr->score += f_str->pamh1[aa0[tpos]];
22668 X          dptr->stop = lpos;
22669 X        }
22670 X       }
22671 X       else {
22672 X        dptr->score = f_str->pamh2[lhval];
22673 X        dptr->start = (dptr->stop = lpos) - kt1;
22674 X       }
22675 X     }                         /* end tpos */
22676 X
22677 #ifdef ALLOCN0
22678 X      /* reinitialize diag structure */
22679 X   loopl:
22680 X     if ((dptr = &f_str->diag[lpos % nd])->score > f_str->lowscor)
22681 X       savemax (dptr, lpos, f_str);
22682 X     dptr->stop = -1;
22683 X     dptr->dmax = NULL;
22684 X     dptr->score = 0;
22685 #endif
22686 X   }                           /* end lpos */
22687 X
22688 #ifdef ALLOCN0
22689 X   for (tpos = 0, dpos = noff + n1 - 1; tpos < n0; tpos++, dpos--) {
22690 X     if ((dptr = &f_str->diag[dpos % nd])->score > f_str->lowscor)
22691 X       savemax (dptr, dpos, f_str);
22692 X   }
22693 #else
22694 X   for (dptr = f_str->diag; dptr < dpmax;) {
22695 X     if (dptr->score > f_str->lowscor) savemax (dptr, f_str);
22696 X     dptr->stop = -1;
22697 X     dptr->dmax = NULL;
22698 X     dptr++->score = 0;
22699 X   }
22700 X   f_str->ndo = nd;
22701 #endif
22702 X
22703 /*
22704 X        at this point all of the elements of aa1[lpos]
22705 X        have been searched for elements of aa0[tpos]
22706 X        with the results in diag[dpos]
22707 */
22708 X   for (nsave = 0, vmptr = f_str->vmax; vmptr < &f_str->vmax[MAXSAV]; vmptr++)    {
22709 X     /*
22710 X     fprintf(stderr,"0: %4d-%4d  1: %4d-%4d  dp: %d score: %d\n",
22711 X            noff+vmptr->start-vmptr->dp,
22712 X            noff+vmptr->stop-vmptr->dp,
22713 X            vmptr->start,vmptr->stop,
22714 X            vmptr->dp,vmptr->score);
22715 X
22716 X     */
22717 X      if (vmptr->score > 0) {
22718 X       vmptr->score = spam (aa0, aa1, vmptr, ppst->pam2[ip], xdrop,
22719 X                            noff,do_extend);
22720 X       f_str->vptr[nsave++] = vmptr;
22721 X      }
22722 X   }
22723 X
22724 X   if (nsave <= 0) {
22725 X     rst->score[0] = rst->score[1] = rst->score[2] = 0;
22726 X     return;
22727 X   }
22728 X       
22729 X   /*
22730 X   fprintf(stderr,"n0: %d; n1: %d; noff: %d\n",n0,n1,noff);
22731 X   for (ib=0; ib<nsave; ib++) {
22732 X     fprintf(stderr,"0: %4d-%4d  1: %4d-%4d  dp: %d score: %d\n",
22733 X            noff+f_str->vptr[ib]->start-f_str->vptr[ib]->dp,
22734 X            noff+f_str->vptr[ib]->stop-f_str->vptr[ib]->dp,
22735 X            f_str->vptr[ib]->start,f_str->vptr[ib]->stop,
22736 X            f_str->vptr[ib]->dp,f_str->vptr[ib]->score);
22737 X   }
22738 X   fprintf(stderr,"---\n");
22739 X   */
22740 X
22741 X   scor = sconn (f_str->vptr, nsave, ppst->param_u.fa.cgap, 
22742 X                ppst->param_u.fa.pgap, noff);
22743 X
22744 X   for (vmptr=f_str->vptr[0],ib=1; ib<nsave; ib++)
22745 X     if (f_str->vptr[ib]->score > vmptr->score) vmptr=f_str->vptr[ib];
22746 X
22747 /*  kssort (f_str->vptr, nsave); */
22748 X
22749 X   rst->score[1] = vmptr->score;
22750 X   rst->score[0] = max (scor, vmptr->score);
22751 X   rst->score[2] = rst->score[0];              /* initn */
22752 X
22753 X   if (ppst->param_u.fa.optflag) {
22754 X     if (rst->score[0] > ppst->param_u.fa.optcut)
22755 X       rst->score[2] = dmatch (aa0, n0, aa1, n1, *hoff=noff - vmptr->dp,
22756 X                            ppst->param_u.fa.optwid, ppst->pam2[ip],
22757 X                            ppst->gdelval,ppst->ggapval,f_str);
22758 X   }
22759 }
22760 X
22761 void do_work (const unsigned char *aa0, int n0,
22762 X             const unsigned char *aa1, int n1,
22763 X             int frame,
22764 X             struct pstruct *ppst, struct f_struct *f_str,
22765 X             int qr_flg, struct rstruct *rst)
22766 {
22767 X  int hoff, n10;
22768 X
22769 X  double lambda, H;
22770 X  
22771 X  rst->score[0] = rst->score[1] = rst->score[2] = 0;
22772 X  rst->escore = 1.0;
22773 X  rst->segnum = rst->seglen = 1;
22774 X
22775 X  if (n1 < ppst->param_u.fa.ktup) return;
22776 X
22777 #ifdef TFASTA  
22778 X  n10=aatran(aa1,f_str->aa1x,n1,frame);
22779 X  do_fasta (aa0, n0, f_str->aa1x, n10, ppst, f_str, rst, &hoff);
22780 #else   /* FASTA */
22781 X  do_fasta (aa0, n0, aa1, n1, ppst, f_str, rst, &hoff);
22782 #endif
22783 X
22784 #ifndef TFASTA
22785 X  if((ppst->zsflag%10) == 6 && 
22786 X     (do_karlin(aa1, n1, ppst->pam2[0], ppst,f_str->aa0_f, 
22787 X               f_str->kar_p, &lambda, &H)>0)) {
22788 X    rst->comp = 1.0/lambda;
22789 X    rst->H = H;
22790 X  }
22791 X  else {rst->comp = rst->H = -1.0;}
22792 #else
22793 X  rst->comp = rst->H = -1.0;
22794 #endif
22795 }
22796 X
22797 void do_opt (const unsigned char *aa0, int n0,
22798 X            const unsigned char *aa1, int n1,
22799 X            int frame,
22800 X            struct pstruct *ppst,
22801 X            struct f_struct *f_str,
22802 X            struct rstruct *rst)
22803 {
22804 X  int optflag, tscore, hoff, n10;
22805 X
22806 X  optflag = ppst->param_u.fa.optflag;
22807 X  ppst->param_u.fa.optflag = 1;
22808 X
22809 #ifdef TFASTA  
22810 X  n10=aatran(aa1,f_str->aa1x,n1,frame);
22811 X  do_fasta (aa0, n0, f_str->aa1x, n10, ppst, f_str, rst, &hoff);
22812 #else   /* FASTA */
22813 X  do_fasta(aa0,n0,aa1,n1,ppst,f_str,rst, &hoff);
22814 #endif
22815 X  ppst->param_u.fa.optflag = optflag;
22816 }
22817 X
22818 #ifdef ALLOCN0
22819 void
22820 savemax (dptr, dpos, f_str)
22821 X  register struct dstruct *dptr;
22822 X  int  dpos;
22823 X  struct f_struct *f_str;
22824 {
22825 X   register struct savestr *vmptr;
22826 X   register int i;
22827 X
22828 #else
22829 void 
22830 savemax (dptr, f_str)
22831 X  register struct dstruct *dptr;
22832 X  struct f_struct *f_str;
22833 {
22834 X   register int dpos;
22835 X   register struct savestr *vmptr;
22836 X   register int i;
22837 X
22838 X   dpos = (int) (dptr - f_str->diag);
22839 X
22840 #endif
22841 X
22842 /* check to see if this is the continuation of a run that is already saved */
22843 X
22844 X   if ((vmptr = dptr->dmax) != NULL && vmptr->dp == dpos &&
22845 X        vmptr->start == dptr->start)
22846 X   {
22847 X      vmptr->stop = dptr->stop;
22848 X      if ((i = dptr->score) <= vmptr->score)
22849 X        return;
22850 X      vmptr->score = i;
22851 X      if (vmptr != f_str->lowmax)
22852 X        return;
22853 X   }
22854 X   else
22855 X   {
22856 X      i = f_str->lowmax->score = dptr->score;
22857 X      f_str->lowmax->dp = dpos;
22858 X      f_str->lowmax->start = dptr->start;
22859 X      f_str->lowmax->stop = dptr->stop;
22860 X      dptr->dmax = f_str->lowmax;
22861 X   }
22862 X
22863 X   for (vmptr = f_str->vmax; vmptr < &f_str->vmax[MAXSAV]; vmptr++)
22864 X      if (vmptr->score < i)
22865 X      {
22866 X        i = vmptr->score;
22867 X        f_str->lowmax = vmptr;
22868 X      }
22869 X   f_str->lowscor = i;
22870 }
22871 X
22872 int spam (const unsigned char *aa0, const unsigned char *aa1,
22873 X         struct savestr *dmax, int **pam2, int xdrop,
22874 X         int noff, int do_extend)
22875 {
22876 X   register int lpos, tot;
22877 X   register const unsigned char *aa0p, *aa1p;
22878 X
22879 X   int drop_thresh;
22880 X
22881 X   struct {
22882 X     int     start, stop, score;
22883 X   } curv, maxv;
22884 X
22885 X   aa1p = &aa1[lpos= dmax->start];     /* get the start of lib seq */
22886 X   aa0p = &aa0[lpos - dmax->dp + noff];        /* start of query */
22887 #ifdef DEBUG
22888 X   /* also add check in calling routine */
22889 X   if (aa0p < aa0) { return -99; }
22890 #endif
22891 X   curv.start = lpos;                  /* start index in lib seq */
22892 X
22893 X   tot = curv.score = maxv.score = 0;
22894 X
22895 X   for (; lpos <= dmax->stop; lpos++) {
22896 X     tot += pam2[*aa0p++][*aa1p++];
22897 X     if (tot > curv.score) {           /* update current score */
22898 X       curv.stop = lpos;
22899 X       curv.score = tot;
22900 X      }
22901 X      else if (tot < 0) {
22902 X       if (curv.score > maxv.score) {  /* save score, start, stop */
22903 X         maxv.start = curv.start;
22904 X         maxv.stop = curv.stop;
22905 X         maxv.score = curv.score;
22906 X       }
22907 X       tot = curv.score = 0;           /* reset running score */
22908 X       curv.start = lpos+1;            /* reset start */
22909 X       if(lpos >= dmax->stop) break;   /* if the zero is beyond stop, quit */
22910 X      }
22911 X   }
22912 X
22913 X   if (curv.score > maxv.score) {
22914 X     maxv.start = curv.start;
22915 X     maxv.stop = curv.stop;
22916 X     maxv.score = curv.score;
22917 X   }
22918 X
22919 #ifndef NOSPAM_EXT
22920 X
22921 X   /* now check to see if the score gets better by extending */
22922 X   if (do_extend && maxv.score > xdrop) {
22923 X
22924 X     if (maxv.stop == dmax->stop) {
22925 X       tot = maxv.score;
22926 X       drop_thresh = maxv.score - xdrop;
22927 X       aa1p = &aa1[lpos= dmax->stop];
22928 X       aa0p = &aa0[lpos - dmax->dp + noff];
22929 X       while (tot > drop_thresh ) {
22930 X        ++lpos;
22931 X        tot += pam2[*(++aa0p)][*(++aa1p)];
22932 X        if (tot > maxv.score) {
22933 X          maxv.start = lpos;
22934 X          maxv.score = tot;
22935 X          drop_thresh = tot - xdrop;
22936 X        }
22937 X       }
22938 X     }
22939 X
22940 X     /* scan backwards now */
22941 X
22942 X     if (maxv.start == dmax->start) {
22943 X       tot = maxv.score;
22944 X       drop_thresh = maxv.score - xdrop;
22945 X       aa1p = &aa1[lpos= dmax->start];
22946 X       aa0p = &aa0[lpos - dmax->dp + noff];
22947 X       while (tot > drop_thresh) {
22948 X        --lpos;
22949 X        tot += pam2[*(--aa0p)][*(--aa1p)];
22950 X        if (tot > maxv.score) {
22951 X          maxv.start = lpos;
22952 X          maxv.score = tot;
22953 X          drop_thresh = tot - xdrop;
22954 X        }
22955 X       }
22956 X     }
22957 X   }
22958 #endif
22959 X
22960 /*      if (maxv.start != dmax->start || maxv.stop != dmax->stop)
22961 X               printf(" new region: %3d %3d %3d %3d\n",maxv.start,
22962 X                       dmax->start,maxv.stop,dmax->stop);
22963 */
22964 X   dmax->start = maxv.start;
22965 X   dmax->stop = maxv.stop;
22966 X
22967 X   return maxv.score;
22968 }
22969 X
22970 int sconn (struct savestr **v, int n, int cgap, int pgap, int noff)
22971 {
22972 X   int     i, si;
22973 X   struct slink
22974 X   {
22975 X      int     score;
22976 X      struct savestr *vp;
22977 X      struct slink *next;
22978 X   }      *start, *sl, *sj, *so, sarr[MAXSAV];
22979 X   int     lstart, tstart, plstop, ptstop;
22980 X
22981 /*      sort the score left to right in lib pos */
22982 X
22983 X   kpsort (v, n);
22984 X
22985 X   start = NULL;
22986 X
22987 /*      for the remaining runs, see if they fit */
22988 X
22989 X   for (i = 0, si = 0; i < n; i++)
22990 X   {
22991 X
22992 /*      if the score is less than the gap penalty, it never helps */
22993 X      if (v[i]->score < cgap)
22994 X        continue;
22995 X      lstart = v[i]->start;
22996 X      tstart = lstart - v[i]->dp + noff;
22997 X
22998 /*      put the run in the group */
22999 X      sarr[si].vp = v[i];
23000 X      sarr[si].score = v[i]->score;
23001 X      sarr[si].next = NULL;
23002 X
23003 /*      if it fits, then increase the score */
23004 X      for (sl = start; sl != NULL; sl = sl->next)
23005 X      {
23006 X        plstop = sl->vp->stop;
23007 X        ptstop = plstop - sl->vp->dp + noff;
23008 X        if (plstop < lstart && ptstop < tstart)
23009 X        {
23010 X           sarr[si].score = sl->score + v[i]->score + pgap;
23011 X           break;
23012 X        }
23013 X      }
23014 X
23015 /*      now recalculate where the score fits */
23016 X      if (start == NULL)
23017 X        start = &sarr[si];
23018 X      else
23019 X        for (sj = start, so = NULL; sj != NULL; sj = sj->next) {
23020 X           if (sarr[si].score > sj->score) {
23021 X              sarr[si].next = sj;
23022 X              if (so != NULL) so->next = &sarr[si];
23023 X              else  start = &sarr[si];
23024 X              break;
23025 X           }
23026 X           so = sj;
23027 X        }
23028 X      si++;
23029 X   }
23030 X
23031 X   if (start != NULL)
23032 X      return (start->score);
23033 X   else
23034 X      return (0);
23035 }
23036 X
23037 void
23038 kssort (v, n)
23039 struct savestr *v[];
23040 int     n;
23041 {
23042 X   int     gap, i, j;
23043 X   struct savestr *tmp;
23044 X
23045 X   for (gap = n / 2; gap > 0; gap /= 2)
23046 X      for (i = gap; i < n; i++)
23047 X        for (j = i - gap; j >= 0; j -= gap)
23048 X        {
23049 X           if (v[j]->score >= v[j + gap]->score)
23050 X              break;
23051 X           tmp = v[j];
23052 X           v[j] = v[j + gap];
23053 X           v[j + gap] = tmp;
23054 X        }
23055 }
23056 X
23057 void
23058 kpsort (v, n)
23059 struct savestr *v[];
23060 int     n;
23061 {
23062 X   int     gap, i, j;
23063 X   struct savestr *tmp;
23064 X
23065 X   for (gap = n / 2; gap > 0; gap /= 2)
23066 X      for (i = gap; i < n; i++)
23067 X        for (j = i - gap; j >= 0; j -= gap)
23068 X        {
23069 X           if (v[j]->start <= v[j + gap]->start)
23070 X              break;
23071 X           tmp = v[j];
23072 X           v[j] = v[j + gap];
23073 X           v[j + gap] = tmp;
23074 X        }
23075 }
23076 X
23077 static int dmatch (const unsigned char *aa0, int n0,
23078 X                  const unsigned char *aa1, int n1,
23079 X                  int hoff, int window, 
23080 X                  int **pam2, int gdelval, int ggapval,
23081 X                  struct f_struct *f_str)
23082 {
23083 X   int low, up;
23084 X
23085 X   window = min (n1, window);
23086 X   /* hoff is the offset found from aa1 to seq 2 by hmatch */
23087 X
23088 X   low = -window/2-hoff;
23089 X   up = low+window;
23090 X
23091 X   return FLOCAL_ALIGN(aa0-1,aa1-1,n0,n1, low, up,
23092 X                     pam2,
23093 #ifdef OLD_FASTA_GAP
23094 X                      -(gdelval-ggapval),
23095 #else
23096 X                      -gdelval,
23097 #endif
23098 X                      -ggapval,window,f_str);
23099 X }
23100 X
23101 X
23102 /* A PACKAGE FOR LOCALLY ALIGNING TWO SEQUENCES WITHIN A BAND:
23103 X
23104 X   To invoke, call LOCAL_ALIGN(A,B,M,N,L,U,W,G,H,MW).
23105 X   The parameters are explained as follows:
23106 X       A, B : two sequences to be aligned
23107 X       M : the length of sequence A
23108 X       N : the length of sequence B
23109 X       L : lower bound of the band
23110 X       U : upper bound of the band
23111 X       W : scoring table for matches and mismatches
23112 X       G : gap-opening penalty
23113 X       H : gap-extension penalty
23114 X       MW  : maximum window size
23115 */
23116 X
23117 #include <stdio.h>
23118 X
23119 #define MININT -9999999
23120 X
23121 static int
23122 FLOCAL_ALIGN(const unsigned char *A, const unsigned char *B,
23123 X            int M, int N, int low, int up,
23124 X            int **W, int G,int H, int MW,
23125 X            struct f_struct *f_str)
23126 {
23127 X  int band;
23128 X  register struct bdstr *bssp;
23129 X  int i, j, si, ei;
23130 X  int c, d, e, m;
23131 X  int leftd, rightd;
23132 X  int best_score;
23133 X  int *wa, curd;
23134 X  int ib;
23135 X  
23136 X  bssp = f_str->bss;
23137 X
23138 X  m = G+H;
23139 X  low = max(-M, low);
23140 X  up = min(N, up);
23141 X  
23142 X  if (N <= 0) return 0;
23143 X
23144 X  if (M <= 0) return 0;
23145 X
23146 X  band = up-low+1;
23147 X  if (band < 1) {
23148 X    fprintf(stderr,"low > up is unacceptable!: M: %d N: %d l/u: %d/%d\n",
23149 X           M, N, low, up);
23150 X    return 0;
23151 X  }
23152 X
23153 X  if (low > 0) leftd = 1;
23154 X  else if (up < 0) leftd = band;
23155 X  else leftd = 1-low;
23156 X  rightd = band;
23157 X  si = max(0,-up);     /* start index -1 */
23158 X  ei = min(M,N-low);   /* end index */
23159 X  bssp[leftd].CC = 0;
23160 X  for (j = leftd+1; j <= rightd; j++) {
23161 X    bssp[j].CC = 0;
23162 X    bssp[j].DD = -G;
23163 X  }
23164 X
23165 X  bssp[rightd+1].CC = MININT;
23166 X  bssp[rightd+1].DD = MININT;
23167 X
23168 X  best_score = 0;
23169 X  bssp[leftd-1].CC = MININT;
23170 X  bssp[leftd].DD = -G;
23171 X
23172 X  for (i = si+1; i <= ei; i++) {
23173 X    if (i > N-up) rightd--;
23174 X    if (leftd > 1) leftd--;
23175 X    wa = W[A[i]];
23176 X    if ((c = bssp[leftd+1].CC-m) > (d = bssp[leftd+1].DD-H)) d = c;
23177 X    if ((ib = leftd+low-1+i ) > 0) c = bssp[leftd].CC+wa[B[ib]];
23178 X
23179 X    if (d > c) c = d;
23180 X    if (c < 0) c = 0;
23181 X    e = c-G;
23182 X    bssp[leftd].DD = d;
23183 X    bssp[leftd].CC = c;
23184 X    if (c > best_score) best_score = c;
23185 X
23186 X    for (curd=leftd+1; curd <= rightd; curd++) {
23187 X      if ((c = c-m) > (e = e-H)) e = c;
23188 X      if ((c = bssp[curd+1].CC-m) > (d = bssp[curd+1].DD-H)) d = c;
23189 X      c = bssp[curd].CC + wa[B[curd+low-1+i]];
23190 X      if (e > c) c = e;
23191 X      if (d > c) c = d;
23192 X      if (c < 0) c = 0;
23193 X      bssp[curd].CC = c;
23194 X      bssp[curd].DD = d;
23195 X      if (c > best_score) best_score = c;
23196 X    }
23197 X  }
23198 X
23199 X  return best_score;
23200 }
23201 X
23202 /* ckalloc - allocate space; check for success */
23203 char *ckalloc(size_t amount)
23204 {
23205 X  char *p;
23206 X
23207 X  if ((p = malloc( (unsigned) amount)) == NULL)
23208 X    w_abort("Ran out of memory.","");
23209 X  return(p);
23210 }
23211 X
23212 /* calculate the 100% identical score */
23213 int
23214 shscore(const unsigned char *aa0, int n0, int **pam2)
23215 {
23216 X  int i, sum;
23217 X  for (i=0,sum=0; i<n0; i++)
23218 X    sum += pam2[aa0[i]][aa0[i]];
23219 X  return sum;
23220 }
23221 X
23222 int  sw_walign (const unsigned char *aa0, int n0,
23223 X               const unsigned char *aa1, int n1,
23224 X               struct pstruct *ppst, 
23225 X               struct f_struct *f_str,
23226 X               struct a_res_str *a_res
23227 X               )
23228 {
23229 X   register const unsigned char *aa0p, *aa1p;
23230 X   register int *pwaa;
23231 X   register int i, j;
23232 X   register struct swstr *ssj;
23233 X   struct swstr *ss;
23234 X   int *waa;
23235 X   int e, f, h, p;
23236 X   int     q, r, m;
23237 X   int     score;
23238 X   int cost, I, J, K, L;
23239 X
23240 X   ss = f_str->ss;
23241 X   waa = f_str->waa1;
23242 X
23243 #ifdef OLD_FASTA_GAP
23244 X   q = -(ppst->gdelval - ppst->ggapval);
23245 #else
23246 X   q = -ppst->gdelval;
23247 #endif
23248 X   r = -ppst->ggapval;
23249 X   m = q + r;
23250 X
23251 X   /* initialize 0th row */
23252 X   for (ssj=ss; ssj<ss+n0; ssj++) {
23253 X     ssj->H = 0;
23254 X     ssj->E = -q;
23255 X   }
23256 X
23257 X   score = I = J = 0;
23258 X   aa1p = aa1;
23259 X   i = 0;
23260 X   while (*aa1p) {
23261 X     h = p = 0;
23262 X     f = -q;
23263 X     pwaa = waa + (*aa1p++ * n0);
23264 X     for (ssj = ss, aa0p = aa0; ssj < ss+n0; ssj++) {
23265 X       if ((h =   h     - m) > (f =   f     - r)) f = h;
23266 X       if ((h = ssj->H - m) > (e = ssj->E - r)) e = h;
23267 X       h = p + *pwaa++;
23268 X       if (h < 0 ) h = 0;
23269 X       if (h < f ) h = f;
23270 X       if (h < e ) h = e;
23271 X       p = ssj->H;
23272 X       ssj->H = h;
23273 X       ssj->E = e;
23274 X       if (h > score) {
23275 X        score = h;
23276 X        I = i;
23277 X        J = (int)(ssj-ss);
23278 X       }
23279 X     }
23280 X     i++;
23281 X   }                           /* done with forward pass */
23282 X   if (score <= 0) return 0;  
23283 X
23284 X  /* to get the start point, go backwards */
23285 X  
23286 X  cost = K = L = 0;
23287 X  for (ssj=ss+J; ssj>=ss; ssj--) ssj->H= ssj->E= -1;
23288 X  
23289 X  for (i=I; i>=0; i--) {
23290 X    h = f = -1;
23291 X    p = (i == I) ? 0 : -1;
23292 X    ssj = ss+J;  /* bug in compiler */
23293 X    for (aa0p = &aa0[J]; ssj>=ss; ssj--,aa0p--) {
23294 X      f = max (f,h-q)-r;
23295 X      ssj->E=max(ssj->E,ssj->H-q)-r;
23296 X      h = max(max(ssj->E,f),p+ppst->pam2[0][*aa0p][aa1[i]]);
23297 X      p = ssj->H;
23298 X      ssj->H=h;
23299 X      if (h > cost) {
23300 X       cost = h;
23301 X       K = i;
23302 X       L = (int)(ssj-ss);
23303 X       if (cost >= score) goto found;
23304 X      }
23305 X    }
23306 X  }
23307 X  
23308 found:  
23309 X
23310 X  /*  printf(" %d: L: %3d-%3d/%3d; K: %3d-%3d/%3d\n",score,L,J,n0,K,I,n1); */
23311 X
23312 /* in the f_str version, the *res array is already allocated at 4*n0/3 */
23313 X
23314 X  a_res->max0 = J+1; a_res->min0 = L; a_res->max1 = I+1; a_res->min1 = K;
23315 X  
23316 X  /* the seq array arguments in this call have been reversed to allow
23317 X     assymetric scoring matrices - this affects the score decoding, 
23318 X     and allocation of the score row matrix */
23319 X  ALIGN(&aa0[L-1],&aa1[K-1],J-L+1,I-K+1,ppst->pam2[0],q,r,a_res->res,&a_res->nres,f_str);
23320 X
23321 X  /*  DISPLAY(&aa1[K-1],&aa0[L-1],I-K+1,J-L+1,res,L,K,ppst->sq); */
23322 X
23323 X   return score;
23324 }
23325 X
23326 static int CHECK_SCORE(const unsigned char *A, const unsigned char *B, 
23327 X                      int M, int N,
23328 X                      int *S, int **W, int G, int H, int *nres);
23329 X
23330 #define gap(k)  ((k) <= 0 ? 0 : g+h*(k))        /* k-symbol indel cost */
23331 X
23332 /* static int *sapp; */                         /* Current script append ptr */
23333 /* static int  last; */                         /* Last script op appended */
23334 X
23335 X                                               /* Append "Delete k" op */
23336 #define DEL(k)                          \
23337 { if (*last < 0)                                \
23338 X    *last = (*sapp)[-1] -= (k);                \
23339 X  else {                               \
23340 X    *last = (*sapp)[0] = -(k);         \
23341 X    (*sapp)++;                         \
23342 X  }                                    \
23343 }
23344 X                                               /* Append "Insert k" op */
23345 #define INS(k)                          \
23346 { if (*last > 0)                        \
23347 X     *last = (*sapp)[-1] += (k);       \
23348 X  else {                               \
23349 X    *last = (*sapp)[0] = (k);          \
23350 X    (*sapp)++;                         \
23351 X  }                                    \
23352 }
23353 X
23354 #define REP { *last = (*sapp)[0] = 0; (*sapp)++;} /* Append "Replace" op */
23355 X
23356 /* align(A,B,M,N,tb,te) returns the cost of an optimum conversion between
23357 X   A[1..M] and B[1..N] that begins(ends) with a delete if tb(te) is zero
23358 X   and appends such a conversion to the current script.                   */
23359 X
23360 static int
23361 nw_align(const unsigned char *A, const unsigned char *B,
23362 X        int M, int N,
23363 X        int tb, int te, int **w, int g, int h, 
23364 X        struct f_struct *f_str,
23365 X        int **sapp, int *last)
23366 {
23367 X  int   midi, midj, type;      /* Midpoint, type, and cost */
23368 X  int midc;
23369 X
23370 X  register int   i, j;
23371 X  register int c, e, d, s;
23372 X  int m, t, *wa;
23373 X  struct swstr *f_ss, *r_ss;
23374 X
23375 X  m = g + h;
23376 X
23377 X  f_ss = f_str->f_ss;
23378 X  r_ss = f_str->r_ss;
23379 X
23380 /* Boundary cases: M <= 1 or N == 0 */
23381 X
23382 X  if (N <= 0) {
23383 X    if (M > 0) {DEL(M)}
23384 X     return -gap(M);
23385 X  }
23386 X
23387 X  if (M <= 1) {
23388 X    if (M <= 0) {
23389 X      INS(N);
23390 X      return -gap(N);
23391 X    }
23392 X    if (tb < te) tb = te;
23393 X    midc = (tb-h) - gap(N);
23394 X    midj = 0;
23395 X    wa = w[A[1]];      /* in the original version of this code, A[]
23396 X                          is the second sequence */
23397 X    for (j = 1; j <= N; j++) {
23398 X      c = -gap(j-1) + wa[B[j]] - gap(N-j);
23399 X      if (c > midc) {
23400 X       midc = c;
23401 X       midj = j;
23402 X      }
23403 X    }
23404 X    if (midj == 0) { DEL(1) INS(N) }
23405 X    else {
23406 X      if (midj > 1) { INS(midj-1) }
23407 X      REP
23408 X      if (midj < N) { INS(N-midj) }
23409 X    }
23410 X    return midc;
23411 X  }
23412 X
23413 /* Divide: Find optimum midpoint (midi,midj) of cost midc */
23414 X
23415 X  midi = M/2;          /* Forward phase:                          */
23416 X  f_ss[0].H = 0;               /*   Compute H(M/2,k) & E(M/2,k) for all k */
23417 X  t = -g;
23418 X  for (j = 1; j <= N; j++) {
23419 X    f_ss[j].H = t = t-h;
23420 X    f_ss[j].E = t-g;
23421 X  }
23422 X  t = tb;
23423 X  for (i = 1; i <= midi; i++) {
23424 X    s = f_ss[0].H;
23425 X    f_ss[0].H = c = t = t-h;
23426 X    e = t-g;
23427 X    wa = w[A[i]];
23428 X    for (j = 1; j <= N; j++) {
23429 X      if ((c =   c   - m) > (e =   e   - h)) e = c;
23430 X      if ((c = f_ss[j].H - m) > (d = f_ss[j].E - h)) d = c;
23431 X      c = s + wa[B[j]];
23432 X      if (e > c) c = e;
23433 X      if (d > c) c = d;
23434 X      s = f_ss[j].H;
23435 X      f_ss[j].H = c;
23436 X      f_ss[j].E = d;
23437 X    }
23438 X  }
23439 X  f_ss[0].E = f_ss[0].H;
23440 X
23441 X  r_ss[N].H = 0;               /* Reverse phase:                          */
23442 X  t = -g;                      /*   Compute R(M/2,k) & S(M/2,k) for all k */
23443 X  for (j = N-1; j >= 0; j--)
23444 X    { r_ss[j].H = t = t-h;
23445 X      r_ss[j].E = t-g;
23446 X    }
23447 X  t = te;
23448 X  for (i = M-1; i >= midi; i--)
23449 X    { s = r_ss[N].H;
23450 X      r_ss[N].H = c = t = t-h;
23451 X      e = t-g;
23452 X      wa = w[A[i+1]];
23453 X      for (j = N-1; j >= 0; j--)
23454 X        { if ((c =   c   - m) > (e =   e   - h)) e = c;
23455 X          if ((c = r_ss[j].H - m) > (d = r_ss[j].E - h)) d = c;
23456 X          c = s + wa[B[j+1]];
23457 X          if (e > c) c = e;
23458 X          if (d > c) c = d;
23459 X          s = r_ss[j].H;
23460 X          r_ss[j].H = c;
23461 X          r_ss[j].E = d;
23462 X        }
23463 X    }
23464 X  r_ss[N].E = r_ss[N].H;
23465 X
23466 X  midc = f_ss[0].H+r_ss[0].H;          /* Find optimal midpoint */
23467 X  midj = 0;
23468 X  type = 1;
23469 X  for (j = 0; j <= N; j++)
23470 X    if ((c = f_ss[j].H + r_ss[j].H) >= midc)
23471 X      if (c > midc || (f_ss[j].H != f_ss[j].E && r_ss[j].H == r_ss[j].E))
23472 X        { midc = c;
23473 X          midj = j;
23474 X        }
23475 X  for (j = N; j >= 0; j--)
23476 X    if ((c = f_ss[j].E + r_ss[j].E + g) > midc)
23477 X      { midc = c;
23478 X        midj = j;
23479 X        type = 2;
23480 X      }
23481 X
23482 X
23483 /* Conquer: recursively around midpoint */
23484 X
23485 X  if (type == 1) {
23486 X    nw_align(A,B,midi,midj,tb,-g,w,g,h,f_str, sapp, last);
23487 X    nw_align(A+midi,B+midj,M-midi,N-midj,-g,te,w,g,h,f_str,sapp, last);
23488 X  }
23489 X  else {
23490 X    nw_align(A,B,midi-1,midj,tb,0,w,g,h,f_str, sapp, last);
23491 X    DEL(2);
23492 X    nw_align(A+midi+1,B+midj,M-midi-1,N-midj,0,te,w,g,h,f_str, sapp, last);
23493 X  }
23494 X  return midc;
23495 }
23496 X
23497 /* Interface and top level of comparator */
23498 X
23499 static int
23500 ALIGN(const unsigned char *A, const unsigned char *B,
23501 X      int M, int N,
23502 X      int **W, int G, int H, int *S, int *nS,
23503 X      struct f_struct *f_str)
23504
23505 X  int c, ck;
23506 X  struct swstr *f_ss, *r_ss;
23507 X  int *sapp, last;
23508 X
23509 X  sapp = S;
23510 X  last = 0;
23511 X
23512 X   if ((f_ss = (struct swstr *) calloc (N+2, sizeof (struct swstr)))
23513 X       == NULL) {
23514 X     fprintf (stderr, "cannot allocate f_ss array %3d\n", N+2);
23515 X     exit (1);
23516 X   }
23517 X   f_ss++;
23518 X   f_str->f_ss = f_ss;
23519 X
23520 X   if ((r_ss = (struct swstr *) calloc (N+2, sizeof (struct swstr)))
23521 X       == NULL) {
23522 X     fprintf (stderr, "cannot allocate r_ss array %3d\n", N+2);
23523 X     exit (1);
23524 X   }
23525 X   r_ss++;
23526 X   f_str->r_ss = r_ss;
23527 X
23528 X  c = nw_align(A,B,M,N,-G,-G,W,G,H,f_str,&sapp, &last);        /* OK, do it */
23529 X
23530 X  ck = CHECK_SCORE(A,B,M,N,S,W,G,H,nS);
23531 X  if (c != ck) fprintf(stderr,"Check_score error %d != %d\n",c,ck);
23532 X
23533 X  f_ss--; r_ss--;
23534 X  free(r_ss); free(f_ss);
23535 X
23536 X  return c;
23537 }
23538 X
23539 /* Alignment display routine */
23540 X
23541 static char ALINE[51], BLINE[51], CLINE[51];
23542 X
23543 void DISPLAY(unsigned char *A, unsigned char *B, int M, int N,
23544 X           int *S, int AP, int BP, char *sq)
23545 { register char *a, *b, *c;
23546 X  register int   i,  j, op;
23547 X           int   lines, ap, bp;
23548 X
23549 X  i = j = op = lines = 0;
23550 X  ap = AP;
23551 X  bp = BP;
23552 X  a = ALINE;
23553 X  b = BLINE;
23554 X  c = CLINE;
23555 X  while (i < M || j < N)
23556 X    { if (op == 0 && *S == 0)
23557 X        { op = *S++;
23558 X          *a = sq[A[++i]];
23559 X          *b = sq[B[++j]];
23560 X          *c++ = (*a++ == *b++) ? '|' : ' ';
23561 X        }
23562 X      else
23563 X        { if (op == 0)
23564 X            op = *S++;
23565 X          if (op > 0)
23566 X            { *a++ = ' ';
23567 X              *b++ = sq[B[++j]];
23568 X              op--;
23569 X            }
23570 X          else
23571 X            { *a++ = sq[A[++i]];
23572 X              *b++ = ' ';
23573 X              op++;
23574 X            }
23575 X          *c++ = '-';
23576 X        }
23577 X      if (a >= ALINE+50 || (i >= M && j >= N))
23578 X        { *a = *b = *c = '\0';
23579 X          printf("\n%5d ",50*lines++);
23580 X          for (b = ALINE+10; b <= a; b += 10)
23581 X            printf("    .    :");
23582 X          if (b <= a+5)
23583 X            printf("    .");
23584 X          printf("\n%5d %s\n      %s\n%5d %s\n",ap,ALINE,CLINE,bp,BLINE);
23585 X         ap = AP + i;
23586 X         bp = BP + j;
23587 X          a = ALINE;
23588 X          b = BLINE;
23589 X          c = CLINE;
23590 X        }
23591 X    }
23592 }
23593 X
23594 /* CHECK_SCORE - return the score of the alignment stored in S */
23595 X
23596 static int CHECK_SCORE(const unsigned char *A, const unsigned char *B,
23597 X                      int M, int N, int *S, int **w, int g, int h,
23598 X                      int *nres)
23599
23600 X  register int   i,  j, op, nc;
23601 X  int score;
23602 X
23603 X  score = i = j = op = nc = 0;
23604 X  while (i < M || j < N) {
23605 X       op = *S++;
23606 X       if (op == 0) {
23607 X         score = w[A[++i]][B[++j]] + score;
23608 X         nc++;
23609 X  /*     fprintf(stderr,"=%4d %4d %4d %4d\n",i,j,w[A[i]][B[i]],score); */
23610 X       }
23611 X       else if (op > 0) {
23612 X         score = score - (g+op*h);
23613 X  /*     fprintf(stderr,">%4d %4d %4d %4d\n",i,j,-(g+op*h),score); */
23614 X         j += op;
23615 X         nc += op;
23616 X       } else {
23617 X         score = score - (g-op*h);
23618 X  /*     fprintf(stderr,"<%4d %4d %4d %4d\n",i,j,-(g-op*h),score); */
23619 X         i -= op;
23620 X         nc -= op;
23621 X       }
23622 X  }
23623 X  *nres = nc;
23624 X  return score;
23625 }
23626 X
23627 X
23628 static int
23629 BCHECK_SCORE(const unsigned char *A, const unsigned char *B,
23630 X                      int M, int N, int *S, int **w, int g, int h,
23631 X                      int *nres)
23632
23633 X  register int   i,  j, op, nc;
23634 X  int *Ssave;
23635 X  int score;
23636 X
23637 X  score = i = j = op = nc = 0;
23638 X  Ssave = S;
23639 X  while (i < M || j < N) {
23640 X       op = *S++;
23641 X       if (op == 0) {
23642 X         score = w[A[++i]][B[++j]] + score;
23643 X         nc++;
23644 /*        fprintf(stderr,"op0 %4d %4d %4d %4d\n",i,j,w[A[i]][B[i]],score); */
23645 X       }
23646 X       else if (op > 0) {
23647 X         score = score - (g+op*h);
23648 /*        fprintf(stderr,"op> %4d %4d %4d %4d %4d\n",i,j,op,-(g+op*h),score); */
23649 X         j += op;
23650 X         nc += op;
23651 X       } else {
23652 X         score = score - (g-op*h);
23653 /*        fprintf(stderr,"op< %4d %4d %4d %4d %4d\n",i,j,op,-(g-op*h),score); */
23654 X         i -= op;
23655 X         nc -= op;
23656 X       }
23657 X  }
23658 X  *nres = nc;
23659 X  return score;
23660 }
23661 X
23662 X
23663 /* A PACKAGE FOR LOCALLY ALIGNING TWO SEQUENCES WITHIN A BAND:
23664 X
23665 X   To invoke, call LOCAL_ALIGN(A,B,M,N,L,U,W,G,H,S,dflag,&SI,&SJ,&EI,&EJ,MW).
23666 X   The parameters are explained as follows:
23667 X       A, B : two sequences to be aligned
23668 X       M : the length of sequence A
23669 X       N : the length of sequence B
23670 X       L : lower bound of the band
23671 X       U : upper bound of the band
23672 X       W : scoring table for matches and mismatches
23673 X       G : gap-opening penalty
23674 X       H : gap-extension penalty
23675 X       dflag : 0 - no display or backward pass
23676 X       *SI : starting position of sequence A in the optimal local alignment
23677 X       *SJ : starting position of sequence B in the optimal local alignment
23678 X       *EI : ending position of sequence A in the optimal local alignment
23679 X       *EJ : ending position of sequence B in the optimal local alignment
23680 X       MW  : maximum window size
23681 */
23682 X
23683 int bd_walign (const unsigned char *aa0, int n0,
23684 X                const unsigned char *aa1, int n1,
23685 X                struct pstruct *ppst, 
23686 X                struct f_struct *f_str, int hoff,
23687 X                struct a_res_str *a_res)
23688 {
23689 X   int low, up, score;
23690 X   int min0, min1, max0, max1;
23691 X   int window;
23692 X
23693 X   window = min (n1, ppst->param_u.fa.optwid);
23694 X   /* hoff is the offset found from aa1 to seq 2 by hmatch */
23695 X
23696 X   low = -window/2-hoff;
23697 X   up = low+window;
23698 X
23699 X   score=LOCAL_ALIGN(aa0-1,aa1-1,n0,n1, low, up,
23700 X                   ppst->pam2[0],
23701 #ifdef OLD_FASTA_GAP
23702 X                    -(ppst->gdelval-ppst->ggapval),
23703 #else
23704 X                    -ppst->gdelval,
23705 #endif
23706 X                    -ppst->ggapval,
23707 X                   &min0,&min1,&max0,&max1,ppst->param_u.fa.optwid,f_str);
23708 X  
23709 X   if (score <=0) {
23710 X     fprintf(stderr,"n0/n1: %d/%d hoff: %d window: %d\n",
23711 X            n0, n1, hoff, window);
23712 X     return 0;
23713 X   }
23714 X  
23715 /*
23716 X  fprintf(stderr," ALIGN: start0: %d start1: %d stop0: %d stop1: %d, bot: %d top: %d, win: %d MX %d\n",
23717 X  min0-1,min1-1,max0-min0+1,max1-min1+1,low-(min1-min0),up-(min1-min0),
23718 X  ppst->param_u.fa.optwid,n0);
23719 */
23720 X
23721 X   a_res->min0 = min0-1; a_res->min1 = min1-1;
23722 X   a_res->max0 = max0; a_res->max1 = max1; 
23723 X
23724 X   B_ALIGN(aa0-1+min0-1,aa1-1+min1-1,max0-min0+1,max1-min1+1,
23725 X          low-(min1-min0),up-(min1-min0),
23726 X          ppst->pam2[0],
23727 #ifdef OLD_FASTA_GAP
23728 X          -(ppst->gdelval-ppst->ggapval),
23729 #else
23730 X          -ppst->gdelval,
23731 #endif
23732 X          -ppst->ggapval,
23733 X          a_res->res,&a_res->nres,ppst->param_u.fa.optwid,n0,f_str->bss);
23734 X
23735 X   return score;
23736 }
23737 X
23738 static int
23739 LOCAL_ALIGN(const unsigned char *A, const unsigned char *B,
23740 X           int M, int N,
23741 X           int low, int up, int **W, int G,int H,
23742 X           int *psi, int *psj, int *pei, int *pej, int MW,
23743 X           struct f_struct *f_str)
23744
23745 X  int band;
23746 X  register struct bdstr *bssp;
23747 X  int i, j, si, ei;
23748 X  int c, d, e, t, m;
23749 X  int leftd, rightd;
23750 X  int best_score, starti, startj, endi, endj;
23751 X  int *wa, curd;
23752 X  int ib;
23753 X  char flag;
23754 X  
23755 X  bssp = f_str->bss;
23756 X
23757 X  m = G+H;
23758 X  low = max(-M, low);
23759 X  up = min(N, up);
23760 X  
23761 X  if (N <= 0) { 
23762 X    *psi = *psj = *pei = *pej;
23763 X    return 0;
23764 X  }
23765 X  if (M <= 0) {
23766 X    *psi = *psj = *pei = *pej;
23767 X    return 0;
23768 X  }
23769 X  band = up-low+1;
23770 X  if (band < 1) {
23771 X    fprintf(stderr,"low > up is unacceptable!: M: %d N: %d l/u: %d/%d\n",
23772 X           M, N, low, up);
23773 X    return -1;
23774 X  }
23775 X
23776 X  j = (MW + 2 + 2) * sizeof(struct bdstr);
23777 X
23778 X  /* already done by init_work(); 
23779 X  if (f_str->bss==NULL) f_str->bss = (struct bdstr *) ckalloc(j);
23780 X  */
23781 X
23782 X  if (low > 0) leftd = 1;
23783 X  else if (up < 0) leftd = band;
23784 X  else leftd = 1-low;
23785 X  rightd = band;
23786 X  si = max(0,-up);
23787 X  ei = min(M,N-low);
23788 X  bssp[leftd].CC = 0;
23789 X  for (j = leftd+1; j <= rightd; j++) {
23790 X    bssp[j].CC = 0;
23791 X    bssp[j].DD = -G;
23792 X  }
23793 X  bssp[rightd+1].CC = MININT;
23794 X  bssp[rightd+1].DD = MININT;
23795 X  best_score = 0;
23796 X  endi = si;
23797 X  endj = si+low;
23798 X  bssp[leftd-1].CC = MININT;
23799 X  bssp[leftd].DD = -G;
23800 X  for (i = si+1; i <= ei; i++) {
23801 X    if (i > N-up) rightd--;
23802 X    if (leftd > 1) leftd--;
23803 X    wa = W[A[i]];
23804 X    if ((c = bssp[leftd+1].CC-m) > (d = bssp[leftd+1].DD-H)) d = c;
23805 X    if ((ib = leftd+low-1+i ) > 0) c = bssp[leftd].CC+wa[B[ib]];
23806 /*
23807 X    if (ib > N) fprintf(stderr,"B[%d] out of range %d\n",ib,N);
23808 */
23809 X    if (d > c) c = d;
23810 X    if (c < 0) c = 0;
23811 X    e = c-G;
23812 X    bssp[leftd].DD = d;
23813 X    bssp[leftd].CC = c;
23814 X    if (c > best_score) {
23815 X      best_score = c;
23816 X      endi = i;
23817 X      endj = ib;
23818 X    }
23819 X    for (curd=leftd+1; curd <= rightd; curd++) {
23820 X      if ((c = c-m) > (e = e-H)) e = c;
23821 X      if ((c = bssp[curd+1].CC-m) > (d = bssp[curd+1].DD-H)) d = c;
23822 /*
23823 X      if ((ib=curd+low-1+i) <= 0 || ib > N)
23824 X       fprintf(stderr,"B[%d]:%d\n",ib,B[ib]);
23825 */
23826 X      c = bssp[curd].CC + wa[B[curd+low-1+i]];
23827 X      if (e > c) c = e;
23828 X      if (d > c) c = d;
23829 X      if (c < 0) c = 0;
23830 X      bssp[curd].CC = c;
23831 X      bssp[curd].DD = d;
23832 X      if (c > best_score) {
23833 X       best_score = c;
23834 X       endi = i;
23835 X       endj = curd+low-1+i;
23836 X      }
23837 X    }
23838 X  }
23839 X  
23840 X  leftd = max(1,-endi-low+1);
23841 X  rightd = band-(up-(endj-endi));
23842 X  bssp[rightd].CC = 0;
23843 X  t = -G;
23844 X  for (j = rightd-1; j >= leftd; j--) {
23845 X    bssp[j].CC = t = t-H;
23846 X    bssp[j].DD = t-G;
23847 X  }
23848 X  for (j = rightd+1; j <= band; ++j) bssp[j].CC = MININT;
23849 X  bssp[leftd-1].CC = bssp[leftd-1].DD = MININT;
23850 X  bssp[rightd].DD = -G;
23851 X  flag = 0;
23852 X  for (i = endi; i >= 1; i--) {
23853 X    if (i+low <= 0) leftd++;
23854 X    if (rightd < band) rightd++;
23855 X    wa = W[A[i]];
23856 X    if ((c = bssp[rightd-1].CC-m) > (d = bssp[rightd-1].DD-H)) d = c;
23857 X    if ((ib = rightd+low-1+i) <= N) c = bssp[rightd].CC+wa[B[ib]];
23858 X
23859 /*
23860 X    if (ib <= 0) fprintf(stderr,"rB[%d] <1\n",ib);
23861 */
23862 X    if (d > c) c = d;
23863 X    e = c-G;
23864 X    bssp[rightd].DD = d;
23865 X    bssp[rightd].CC = c;
23866 X    if (c == best_score) {
23867 X      starti = i;
23868 X      startj = ib;
23869 X      flag = 1;
23870 X      break;
23871 X    }
23872 X    for (curd=rightd-1; curd >= leftd; curd--) {
23873 X      if ((c = c-m) > (e = e-H)) e = c;
23874 X      if ((c = bssp[curd-1].CC-m) > (d = bssp[curd-1].DD-H)) d = c;
23875 X
23876 /*
23877 X      if ((ib=curd+low-1+i) <= 0 || ib > N)
23878 X       fprintf(stderr,"i: %d, B[%d]:%d\n",i,ib,B[ib]);
23879 */
23880 X      c = bssp[curd].CC + wa[B[curd+low-1+i]];
23881 X      if (e > c) c = e;
23882 X      if (d > c) c = d;
23883 X      bssp[curd].CC = c;
23884 X      bssp[curd].DD = d;
23885 X      if (c == best_score) {
23886 X       starti = i;
23887 X       startj = curd+low-1+i;
23888 X       flag = 1;
23889 X       break;
23890 X      }
23891 X    }
23892 X    if (flag == 1) break;
23893 X  }
23894 X  
23895 X  if (starti < 0 || starti > M || startj < 0 || startj > N) {
23896 X    printf("starti=%d, startj=%d\n",starti,startj);
23897 X    *psi = *psj = *pei = *pej;
23898 X    exit(1);
23899 X  }
23900 X  *psi = starti;
23901 X  *psj = startj;
23902 X  *pei = endi;
23903 X  *pej = endj;
23904 X  return best_score;
23905 }
23906 X
23907 /* A PACKAGE FOR GLOBALLY ALIGNING TWO SEQUENCES WITHIN A BAND:
23908 X
23909 X   To invoke, call B_ALIGN(A,B,M,N,L,U,W,G,H,S,MW,MX).
23910 X   The parameters are explained as follows:
23911 X       A, B : two sequences to be aligned
23912 X       M : the length of sequence A
23913 X       N : the length of sequence B
23914 X       L : lower bound of the band
23915 X       U : upper bound of the band
23916 X       W : scoring table for matches and mismatches
23917 X       G : gap-opening penalty
23918 X       H : gap-extension penalty
23919 X       S : script for DISPLAY routine
23920 X       MW : maximum window size
23921 X       MX : maximum length sequence M to be aligned
23922 */
23923 X
23924 static int IP;
23925 static int *MP[3];              /* save crossing points */
23926 static int *FP;                 /* forward dividing points */
23927 static char *MT[3];             /* 0: rep, 1: del, 2: ins */
23928 static char *FT;
23929 X
23930 /* bg_align(A,B,M,N,up,low,tb,te) returns the cost of an optimum conversion between
23931 X  A[1..M] and B[1..N] and appends such a conversion to the current script.
23932 X  tb(te)= 1  no gap-open penalty if the conversion begins(ends) with a delete.
23933 X  tb(te)= 2  no gap-open penalty if the conversion begins(ends) with an insert.
23934 */
23935 static int
23936 bg_align(const unsigned char *A, const unsigned char *B, 
23937 X        int M, int N,
23938 X        int low, int up, int tb, int te,
23939 X        int **w, int g, int h,
23940 X        struct bdstr *bss, int **sapp, int *last)
23941 {
23942 X  int rmid, k, l, r, v, kt;
23943 X  int t1, t2, t3;
23944 X
23945 X  {
23946 X  int band, midd;
23947 X  int leftd, rightd;   /* for CC, DD, CP and DP */
23948 X  register int curd;   /* current index for CC, DD CP and DP */
23949 X  register int i, j;
23950 X  register int c, d, e;
23951 X  int t, fr, *wa, ib, m;
23952 X
23953 X  /* Boundary cases: M <= 0 , N <= 0, or up-low <= 0 */
23954 X  if (N <= 0) { 
23955 X    if (M > 0) { DEL(M) }
23956 X    return 0;
23957 X  }
23958 X  if (M <= 0) {
23959 X    INS(N)
23960 X    return 0;
23961 X  }
23962 X  if ((band = up-low+1) <= 1) {
23963 X    for (i = 1; i <= M; i++) { REP }
23964 X    return 0;
23965 X  }
23966 X
23967 X  /* Divide: Find all crossing points */
23968 X
23969 X  /* Initialization */
23970 X  m = g + h;
23971 X
23972 X  midd = band/2 + 1;
23973 X  rmid = low + midd - 1;
23974 X  leftd = 1-low;
23975 X  rightd = up-low+1;
23976 X  if (leftd < midd) {
23977 X    fr = -1;
23978 X    for (j = 0; j < midd; j++) 
23979 X      bss[j].CP = bss[j].DP = -1;
23980 X    for (j = midd; j <= rightd; j++) {
23981 X      bss[j].CP = bss[j].DP = 0;
23982 X    }
23983 X    MP[0][0] = -1;
23984 X    MP[1][0] = -1;
23985 X    MP[2][0] = -1;
23986 X    MT[0][0] = MT[1][0] = MT[2][0] = 0;
23987 X  } else if (leftd > midd) {
23988 X    fr = leftd-midd;
23989 X    for (j = 0; j <= midd; j++) {
23990 X      bss[j].CP = bss[j].DP = fr;
23991 X    }
23992 X    for (j = midd+1; j <= rightd; j++) 
23993 X      bss[j].CP = bss[j].DP = -1;
23994 X    MP[0][fr] = -1;
23995 X    MP[1][fr] = -1;
23996 X    MP[2][fr] = -1;
23997 X    MT[0][fr] = MT[1][fr] = MT[2][fr] = 0;
23998 X  } else {
23999 X    fr = 0;
24000 X    for (j = 0; j < midd; j++) {
24001 X      bss[j].CP = bss[j].DP = 0;
24002 X    }
24003 X    for (j = midd; j <= rightd; j++) {
24004 X      bss[j].CP = bss[j].DP = 0;
24005 X    }
24006 X    MP[0][0] = -1;
24007 X    MP[1][0] = -1;
24008 X    MP[2][0] = -1;
24009 X    MT[0][0] = MT[1][0] = MT[2][0] = 0;
24010 X  }
24011 X
24012 X  bss[leftd].CC = 0;
24013 X  if (tb == 2) t = 0;
24014 X  else t = -g;
24015 X  for (j = leftd+1; j <= rightd; j++) {
24016 X    bss[j].CC = t = t-h;
24017 X    bss[j].DD = t-g;
24018 X  }
24019 X  bss[rightd+1].CC = MININT;
24020 X  bss[rightd+1].DD = MININT;
24021 X  if (tb == 1) bss[leftd].DD = 0;
24022 X  else bss[leftd].DD = -g;
24023 X  bss[leftd-1].CC = MININT;
24024 X  for (i = 1; i <= M; i++) {
24025 X    if (i > N-up) rightd--;
24026 X    if (leftd > 1) leftd--;
24027 X    wa = w[A[i]];
24028 X    if ((c = bss[leftd+1].CC-m) > (d = bss[leftd+1].DD-h)) {
24029 X      d = c;
24030 X      bss[leftd].DP = bss[leftd+1].CP;
24031 X    } else bss[leftd].DP = bss[leftd+1].DP;
24032 X    if ((ib = leftd+low-1+i) > 0) c = bss[leftd].CC+wa[B[ib]];
24033 X    if (d > c || ib <= 0) {
24034 X      c = d;
24035 X      bss[leftd].CP = bss[leftd].DP;
24036 X    }
24037 X    e = c-g;
24038 X    bss[leftd].DD = d;
24039 X    bss[leftd].CC = c;
24040 X    IP = bss[leftd].CP;
24041 X    if (leftd == midd) bss[leftd].CP = bss[leftd].DP = IP = i;
24042 X    for (curd=leftd+1; curd <= rightd; curd++) {
24043 X      if (curd != midd) {
24044 X       if ((c = c-m) > (e = e-h)) {
24045 X         e = c;
24046 X         IP = bss[curd-1].CP;
24047 X       }  /* otherwise, IP is unchanged */
24048 X       if ((c = bss[curd+1].CC-m) > (d = bss[curd+1].DD-h)) {
24049 X         d = c;
24050 X         bss[curd].DP = bss[curd+1].CP;
24051 X       } else {
24052 X         bss[curd].DP = bss[curd+1].DP;
24053 X       }
24054 X       c = bss[curd].CC + wa[B[curd+low-1+i]];
24055 X       if (c < d || c < e) {
24056 X         if (e > d) {
24057 X           c = e;
24058 X           bss[curd].CP = IP;
24059 X         } else {
24060 X           c = d;
24061 X           bss[curd].CP = bss[curd].DP;
24062 X         }
24063 X       } /* otherwise, CP is unchanged */
24064 X       bss[curd].CC = c;
24065 X       bss[curd].DD = d;
24066 X      } else {
24067 X       if ((c = c-m) > (e = e-h)) {
24068 X         e = c;
24069 X         MP[1][i] = bss[curd-1].CP;
24070 X         MT[1][i] = 2;
24071 X       } else {
24072 X         MP[1][i] = IP;
24073 X         MT[1][i] = 2;
24074 X       }
24075 X       if ((c = bss[curd+1].CC-m) > (d = bss[curd+1].DD-h)) {
24076 X         d = c;
24077 X         MP[2][i] = bss[curd+1].CP;
24078 X         MT[2][i] = 1;
24079 X       } else {
24080 X         MP[2][i] = bss[curd+1].DP;
24081 X         MT[2][i] = 1;
24082 X       }
24083 X       c = bss[curd].CC + wa[B[curd+low-1+i]];
24084 X       if (c < d || c < e) {
24085 X         if (e > d) {
24086 X           c = e;
24087 X           MP[0][i] = MP[1][i];
24088 X           MT[0][i] = 2;
24089 X         } else {
24090 X           c = d;
24091 X           MP[0][i] = MP[2][i];
24092 X           MT[0][i] = 1;
24093 X         }
24094 X       } else {
24095 X         MP[0][i] = i-1;
24096 X         MT[0][i] = 0;
24097 X       }
24098 X       if (c-g > e) {
24099 X         MP[1][i] = MP[0][i];
24100 X         MT[1][i] = MT[0][i];
24101 X       }
24102 X       if (c-g > d) {
24103 X         MP[2][i] = MP[0][i];
24104 X         MT[2][i] = MT[0][i];
24105 X       }
24106 X       bss[curd].CP = bss[curd].DP = IP = i;
24107 X       bss[curd].CC = c;
24108 X       bss[curd].DD = d;
24109 X      }
24110 X    }
24111 X  }
24112 X
24113 X  /* decide which path to be traced back */
24114 X  if (te == 1 && d+g > c) {
24115 X    k = bss[rightd].DP;
24116 X    l = 2;
24117 X  } else if (te == 2 && e+g > c) {
24118 X    k = IP;
24119 X    l = 1;
24120 X  } else {
24121 X    k = bss[rightd].CP;
24122 X    l = 0;
24123 X  }
24124 X  if (rmid > N-M) l = 2;
24125 X  else if (rmid < N-M) l = 1;
24126 X  v = c;
24127 X  }
24128 X  /* Conquer: Solve subproblems recursively */
24129 X
24130 X  /* trace back */
24131 X  r = -1;      
24132 X  for (; k > -1; r=k, k=MP[l][r], l=MT[l][r]){
24133 X    FP[k] = r;
24134 X    FT[k] = l; /* l=0,1,2 */
24135 X  }
24136 X  /* forward dividing */
24137 X  if (r == -1) { /* optimal alignment did not cross the middle diagonal */
24138 X    if (rmid < 0) {
24139 X      bg_align(A,B,M,N,rmid+1,up,tb,te,w,g,h,bss, sapp, last);
24140 X    }
24141 X    else {
24142 X      bg_align(A,B,M,N,low,rmid-1,tb,te,w,g,h,bss, sapp, last);
24143 X    }
24144 X  } else {
24145 X    k = r;
24146 X    l = FP[k];
24147 X    kt = FT[k];
24148 X
24149 X    /* first block */
24150 X    if (rmid < 0) {
24151 X      bg_align(A,B,r-1,r+rmid,rmid+1,min(up,r+rmid),tb,1,w,g,h,bss,sapp,last);
24152 X      DEL(1)
24153 X    } else if (rmid > 0) {
24154 X      bg_align(A,B,r,r+rmid-1,max(-r,low),rmid-1,tb,2,w,g,h,bss,sapp,last);
24155 X      INS(1)
24156 X    }
24157 X
24158 X    /* intermediate blocks */
24159 X    t2 = up-rmid-1;
24160 X    t3 = low-rmid+1;
24161 X    for (; l > -1; k = l, l = FP[k], kt = FT[k]) {
24162 X      if (kt == 0) { REP }
24163 X      else if (kt == 1) { /* right-hand side triangle */
24164 X       INS(1)
24165 X       t1 = l-k-1;
24166 X       bg_align(A+k,B+k+rmid+1,t1,t1,0,min(t1,t2),2,1,w,g,h,bss,sapp,last);
24167 X       DEL(1)
24168 X      }
24169 X      else { /* kt == 2, left-hand side triangle */
24170 X       DEL(1)
24171 X       t1 = l-k-1;
24172 X       bg_align(A+k+1,B+k+rmid,t1,t1,max(-t1,t3),0,1,2,w,g,h,bss,sapp,last);
24173 X       INS(1)
24174 X      }
24175 X    }
24176 X
24177 X    /* last block */
24178 X    if (N-M > rmid) {
24179 X      INS(1)
24180 X      t1 = k+rmid+1;
24181 X      bg_align(A+k,B+t1,M-k,N-t1,0,min(N-t1,t2),2,te,w,g,h,bss,sapp,last);
24182 X    } else if (N-M < rmid) {
24183 X      DEL(1)
24184 X      t1 = M-(k+1);
24185 X      bg_align(A+k+1,B+k+rmid,t1,N-(k+rmid),max(-t1,t3),0,1,te,w,g,h,
24186 X              bss,sapp,last);
24187 X    }
24188 X  }
24189 X  return(v);
24190 }
24191 X
24192 int B_ALIGN(const unsigned char *A, const unsigned char *B,
24193 X           int M, int N,
24194 X           int low, int up, int **W, int G, int H, int *S, int *nS,
24195 X           int MW, int MX, struct bdstr *bss)
24196
24197 X  int c, i, j;
24198 X  int g, h;
24199 X  size_t mj;
24200 X  int check_score;
24201 X  int **sapp, *sapp_v, *last, last_v;
24202 X
24203 X  g = G;
24204 X  h = H;
24205 X  sapp_v = S;
24206 X  sapp = &sapp_v;
24207 X
24208 X  last_v = 0;
24209 X  last = &last_v;
24210 X
24211 X  low = min(max(-M, low),min(N-M,0));
24212 X  up = max(min(N, up),max(N-M,0));
24213 X
24214 X  if (N <= 0) { 
24215 X    if (M > 0) { DEL(M); }
24216 X    return -gap(M);
24217 X  }
24218 X  if (M <= 0) {
24219 X    INS(N);
24220 X    return -gap(N);
24221 X  }
24222 X  if (up-low+1 <= 1) {
24223 X    c = 0;
24224 X    for (i = 1; i <= M; i++) {
24225 X      REP;
24226 X      c += W[A[i]][B[i]];
24227 X    }
24228 X    return c;
24229 X  }
24230 X
24231 X  if (MT[0]==NULL) {
24232 X    mj = MX+1;
24233 X    MT[0] = (char *) ckalloc(mj);
24234 X    MT[1] = (char *) ckalloc(mj);
24235 X    MT[2] = (char *) ckalloc(mj);
24236 X    FT = (char *) ckalloc(mj);
24237 X
24238 X    mj *= sizeof(int);
24239 X    MP[0] = (int *) ckalloc(mj);
24240 X    MP[1] = (int *) ckalloc(mj);
24241 X    MP[2] = (int *) ckalloc(mj);
24242 X    FP = (int *) ckalloc(mj);
24243 X  }
24244 X
24245 X  c = bg_align(A,B,M,N,low,up,0,0,W,G,H,bss, sapp, last);
24246 X
24247 X  check_score = BCHECK_SCORE(A,B,M,N,S,W,G,H,nS);
24248 X
24249 X  free(FP); free(MP[2]); free(MP[1]); free(MP[0]);
24250 X  free(FT); free(MT[2]); free(MT[1]); free(MT[0]);
24251 X  MT[0]=NULL;
24252 X
24253 X  if (check_score != c)
24254 X    printf("\nBCheck_score=%d != %d\n", check_score,c);
24255 X  return c;
24256 }
24257 X
24258 int  do_walign (const unsigned char *aa0, int n0,
24259 X               const unsigned char *aa1, int n1,
24260 X               int frame,
24261 X               struct pstruct *ppst, 
24262 X               struct f_struct *f_str, 
24263 X               struct a_res_str *a_res,
24264 X               int *have_ares)
24265 {
24266 X  int hoff, optflag_s, optcut_s, optwid_s, n10, score;
24267 X  const unsigned char *aa1p;
24268 X  struct rstruct rst;
24269 X
24270 #ifdef TFASTA  
24271 X  f_str->n10 = n10=aatran(aa1,f_str->aa1x,n1,frame);
24272 X  do_fasta (aa0, n0, f_str->aa1x, n10, ppst, f_str, &rst, &hoff);
24273 X  aa1p = f_str->aa1x;
24274 X
24275 #else
24276 X  n10 = n1;
24277 X  aa1p = aa1;
24278 #endif
24279 X
24280 X  a_res->res = f_str->res;
24281 X  *have_ares = 1;
24282 X
24283 X  if (ppst->sw_flag)
24284 X    return sw_walign(aa0, n0, aa1p, n10, ppst, f_str, a_res);
24285 X  else {
24286 X    optflag_s = ppst->param_u.fa.optflag;
24287 X    optcut_s = ppst->param_u.fa.optcut;
24288 X    optwid_s = ppst->param_u.fa.optwid;
24289 X    ppst->param_u.fa.optflag = 1;
24290 X    ppst->param_u.fa.optcut = 0;
24291 X    ppst->param_u.fa.optwid *= 2;
24292 X
24293 X    do_fasta(aa0, n0, aa1p, n10, ppst, f_str, &rst, &hoff);
24294 X
24295 X    if (rst.score[0]>0) {
24296 X      score=bd_walign(aa0, n0, aa1p, n10, ppst, f_str, hoff, a_res);
24297 X    }
24298 X    else {
24299 X      a_res->nres = 0;
24300 X      score=0;
24301 X    }
24302 X
24303 X    ppst->param_u.fa.optflag = optflag_s;
24304 X    ppst->param_u.fa.optcut = optcut_s;
24305 X    ppst->param_u.fa.optwid = optwid_s;
24306 X    return score;
24307 X  }
24308 }
24309 X
24310 void
24311 pre_cons(const unsigned char *aa1, int n1, int frame, struct f_struct *f_str) {
24312 X
24313 #ifdef TFASTA
24314 X  f_str->n10 = aatran(aa1,f_str->aa1x,n1,frame);
24315 #endif
24316 }
24317 X
24318 /* aln_func_vals - set up aln.qlfact, qlrev, llfact, llmult, frame, llrev */
24319 /* call from calcons, calc_id, calc_code */
24320 void 
24321 aln_func_vals(int frame, struct a_struct *aln) {
24322 X
24323 #ifdef TFASTA
24324 X  aln->qlfact = 1;
24325 X  aln->llfact = 3;
24326 X  aln->llmult = 3;
24327 X  aln->qlrev = 0;
24328 X  aln->frame = frame;
24329 X  if (frame > 2) {
24330 X    aln->llrev = 1;
24331 X    aln->frame = 3 - frame;
24332 X  }
24333 X  else aln->llrev = 0;
24334 #else   /* FASTA */
24335 X  aln->llfact = aln->qlfact = aln->llmult = 1;
24336 X  aln->llrev = 0;
24337 X  if (frame > 0) aln->qlrev = 1;
24338 X  else aln->qlrev = 0;
24339 X  aln->frame = 0;
24340 #endif
24341 }
24342 X
24343 #include "a_mark.h"
24344 X
24345 int calcons(const unsigned char *aa0, int n0,
24346 X           const unsigned char *aa1, int n1,
24347 X           int *nc,
24348 X           struct a_struct *aln, struct a_res_str a_res,
24349 X           struct pstruct pst,
24350 X           char *seqc0, char *seqc1, char *seqca,
24351 X           struct f_struct *f_str)
24352 {
24353 X  int i0, i1, nn1;
24354 X  int op, lenc, nd, ns, itmp;
24355 X  const unsigned char *aa1p;
24356 X  char *sp0, *sp1, *spa, *sq;
24357 X  int *rp;
24358 X  int smins, mins;
24359 X
24360 X  if (pst.ext_sq_set) { sq = pst.sqx; }
24361 X  else { sq = pst.sq; }
24362 X
24363 #ifndef TFASTA
24364 X  aa1p = aa1;
24365 X  nn1 = n1;
24366 #else
24367 X  aa1p = f_str->aa1x;
24368 X  nn1 = f_str->n10;
24369 #endif
24370 X
24371 X  aln->amin0 = a_res.min0;
24372 X  aln->amax0 = a_res.max0;
24373 X  aln->amin1 = a_res.min1;
24374 X  aln->amax1 = a_res.max1;
24375 X                                       /* will we show all the start ?*/
24376 X  if (min(a_res.min0,a_res.min1) < aln->llen || aln->showall==1)
24377 X    if (a_res.min0 >= a_res.min1) {    /* aa0 extends more to left */
24378 X      smins=0;
24379 X      if (aln->showall==1) mins = a_res.min0;
24380 X      else mins = min(a_res.min0,aln->llcntx);
24381 X      aancpy(seqc0,(char *)aa0+a_res.min0-mins,mins,pst);
24382 X      aln->smin0 = a_res.min0-mins;
24383 X      if ((mins-a_res.min1)>0) {
24384 X       memset(seqc1,' ',mins-a_res.min1);
24385 X       aancpy(seqc1+mins-a_res.min1,(char *)aa1p,a_res.min1,pst);
24386 X       aln->smin1 = 0;
24387 X      }
24388 X      else {
24389 X       aancpy(seqc1,(char *)aa1p+a_res.min1-mins,mins,pst);
24390 X       aln->smin1 = a_res.min1-mins;
24391 X      }
24392 X    }
24393 X    else {
24394 X      smins=0;
24395 X      if (aln->showall == 1) mins=a_res.min1;
24396 X      else mins = min(a_res.min1,aln->llcntx);
24397 X      aancpy(seqc1,(char *)(aa1p+a_res.min1-mins),mins,pst);
24398 X      aln->smin1 = a_res.min1-mins;
24399 X      if ((mins-a_res.min0)>0) {
24400 X       memset(seqc0,' ',mins-a_res.min0);
24401 X       aancpy(seqc0+mins-a_res.min0,(char *)aa0,a_res.min0,pst);
24402 X       aln->smin0 = 0;
24403 X      }
24404 X      else {
24405 X       aancpy(seqc0,(char *)aa0+a_res.min0-mins,mins,pst);
24406 X       aln->smin0 = a_res.min0-mins;
24407 X      }
24408 X    }
24409 X  else {
24410 X    mins= min(aln->llcntx,min(a_res.min0,a_res.min1));
24411 X    smins=mins;
24412 X    aln->smin0=a_res.min0 - mins;
24413 X    aln->smin1=a_res.min1 - mins;
24414 X    aancpy(seqc0,(char *)aa0+a_res.min0-mins,mins,pst);
24415 X    aancpy(seqc1,(char *)aa1p+a_res.min1-mins,mins,pst);
24416 X  }
24417 X  /* set the alignment code to zero for context */
24418 X  memset(seqca,0,mins);
24419 X
24420 X  /* TFASTA
24421 X  smins = mins = 0;
24422 X  aln->smin0=a_res.min0;
24423 X  aln->smin1=a_res.min1;
24424 X  */
24425 X
24426 /* now get the middle */
24427 X
24428 X  spa = seqca+mins;
24429 X  sp0 = seqc0+mins;
24430 X  sp1 = seqc1+mins;
24431 X  rp = a_res.res;
24432 X  lenc = aln->nident = aln->nsim = aln->ngap_q = aln->ngap_l = aln->nfs = op = 0;
24433 X  i0 = a_res.min0;
24434 X  i1 = a_res.min1;
24435 X  
24436 X  while (i0 < a_res.max0 || i1 < a_res.max1) {
24437 X    if (op == 0 && *rp == 0) {
24438 X      op = *rp++;
24439 X      lenc++;
24440 X      if ((itmp=pst.pam2[0][aa0[i0]][aa1p[i1]])<0) { *spa = M_NEG; }
24441 X      else if (itmp == 0) { *spa = M_ZERO;}
24442 X      else {*spa = M_POS;}
24443 X      if (*spa == M_POS || *spa==M_ZERO) aln->nsim++;
24444 X
24445 X
24446 X      *sp0 = sq[aa0[i0++]];
24447 X      *sp1 = sq[aa1p[i1++]];
24448 X      if (toupper(*sp0) == toupper(*sp1)) {
24449 X       aln->nident++;
24450 X       *spa = M_IDENT;
24451 X      }
24452 X      else if (pst.nt_align) {
24453 X       if ((toupper(*sp0) == 'T' && toupper(*sp1) == 'U') ||
24454 X           (toupper(*sp0)=='U' && toupper(*sp1)=='T')) {
24455 X         aln->nident++;
24456 X         *spa = M_IDENT;
24457 X       }
24458 X       else if (toupper(*sp0) == 'N') aln->ngap_q++;
24459 X       else if (toupper(*sp1) == 'N') aln->ngap_l++;
24460 X      }
24461 X      sp0++; sp1++; spa++;
24462 X    }
24463 X    else {
24464 X      if (op==0) op = *rp++;
24465 X      if (op > 0) {
24466 X       *sp0++ = '-';
24467 X       *sp1++ = sq[aa1p[i1++]];
24468 X       *spa++ = M_DEL;
24469 X       op--;
24470 X       lenc++;
24471 X       aln->ngap_q++;
24472 X      }
24473 X      else {
24474 X       *sp0++ = sq[aa0[i0++]];
24475 X       *sp1++ = '-';
24476 X       *spa++ = M_DEL;
24477 X       op++;
24478 X       lenc++;
24479 X       aln->ngap_l++;
24480 X      }
24481 X    }
24482 X  }
24483 X
24484 X  *nc = lenc;
24485 X  *spa = '\0';
24486 X
24487 /*      now we have the middle, get the right end */
24488 X  if (!aln->llcntx_flg) {
24489 X    ns = mins + lenc + aln->llen;      /* show an extra line? */
24490 X    ns -= (itmp = ns %aln->llen);      /* itmp = left over on last line */
24491 X    if (itmp>aln->llen/2) ns += aln->llen;  /* more than 1/2 , use another*/
24492 X    nd = ns - (mins+lenc);             /* this much extra */
24493 X  }
24494 X  else nd = aln->llcntx;
24495 X
24496 X  if (nd > max(n0-a_res.max0,nn1-a_res.max1)) 
24497 X    nd = max(n0-a_res.max0,nn1-a_res.max1);
24498 X  
24499 X  if (aln->showall==1) {
24500 X    nd = max(n0-a_res.max0,nn1-a_res.max1);    /* reset for showall=1 */
24501 X    /* get right end */
24502 X    aancpy(seqc0+mins+lenc,(char *)aa0+a_res.max0,n0-a_res.max0,pst);
24503 X    aancpy(seqc1+mins+lenc,(char *)aa1p+a_res.max1,nn1-a_res.max1,pst);
24504 X    /* fill with blanks - this is required to use one 'nc' */
24505 X    memset(seqc0+mins+lenc+n0-a_res.max0,' ',nd-(n0-a_res.max0));
24506 X    memset(seqc1+mins+lenc+nn1-a_res.max1,' ',nd-(nn1-a_res.max1));
24507 X  }
24508 X  else {
24509 X    if ((nd-(n0-a_res.max0))>0) {
24510 X      aancpy(seqc0+mins+lenc,(char *)aa0+a_res.max0,(n0-a_res.max0),pst);
24511 X      memset(seqc0+mins+lenc+n0-a_res.max0,' ',nd-(n0-a_res.max0));
24512 X    }
24513 X    else aancpy(seqc0+mins+lenc,(char *)aa0+a_res.max0,nd,pst);
24514 X
24515 X    if ((nd-(nn1-a_res.max1))>0) {
24516 X      aancpy(seqc1+mins+lenc,(char *)aa1p+a_res.max1,nn1-a_res.max1,pst);
24517 X      memset(seqc1+mins+lenc+nn1-a_res.max1,' ',nd-(nn1-a_res.max1));
24518 X    }
24519 X    else aancpy(seqc1+mins+lenc,(char *)aa1p+a_res.max1,nd,pst);
24520 X  }
24521 X
24522 X  /*  fprintf(stderr,"%d\n",mins+lenc+nd); */
24523 X
24524 X  return mins+lenc+nd;
24525 }
24526 X
24527 int calcons_a(const unsigned char *aa0, unsigned char *aa0a, int n0,
24528 X             const unsigned char *aa1, int n1,
24529 X             int *nc,
24530 X             struct a_struct *aln,
24531 X             struct a_res_str a_res,
24532 X             struct pstruct pst,
24533 X             char *seqc0, char *seqc0a, char *seqc1, char *seqca,
24534 X             char *ann_arr, struct f_struct *f_str)
24535 {
24536 X  int i0, i1, nn1;
24537 X  int op, lenc, nd, ns, itmp;
24538 X  const unsigned char *aa1p;
24539 X  char *sp0, *sp0a, *sp1, *spa, *sq;
24540 X  int *rp;
24541 X  int smins, mins;
24542 X
24543 X  if (pst.ext_sq_set) {
24544 X    sq = pst.sqx;
24545 X  }
24546 X  else {
24547 X    sq = pst.sq;
24548 X  }
24549 X
24550 #ifndef TFASTA
24551 X  aa1p = aa1;
24552 X  nn1 = n1;
24553 #else
24554 X  aa1p = f_str->aa1x;
24555 X  nn1 = f_str->n10;
24556 #endif
24557 X
24558 X  aln->amin0 = a_res.min0;
24559 X  aln->amax0 = a_res.max0;
24560 X  aln->amin1 = a_res.min1;
24561 X  aln->amax1 = a_res.max1;
24562 X                                       /* will we show all the start ?*/
24563 X  /* will we show all the start ?*/
24564 X  if (min(a_res.min0,a_res.min1)<aln->llen || aln->showall==1)
24565 X    if (a_res.min0>=a_res.min1) {              /* aa0 extends more to left */
24566 X      smins=0;
24567 X      if (aln->showall==1) mins = a_res.min0;
24568 X      else mins = min(a_res.min0,aln->llcntx);
24569 X      aancpy(seqc0,(char *)aa0+a_res.min0-mins,mins,pst);
24570 X      aln->smin0 = a_res.min0-mins;
24571 X      if ((mins-a_res.min1)>0) {
24572 X       memset(seqc1,' ',mins-a_res.min1);
24573 X       aancpy(seqc1+mins-a_res.min1,(char *)aa1p,a_res.min1,pst);
24574 X       aln->smin1 = 0;
24575 X      }
24576 X      else {
24577 X       aancpy(seqc1,(char *)aa1p+a_res.min1-mins,mins,pst);
24578 X       aln->smin1 = a_res.min1-mins;
24579 X      }
24580 X    }
24581 X    else {
24582 X      smins=0;
24583 X      if (aln->showall == 1) mins=a_res.min1;
24584 X      else mins = min(a_res.min1,aln->llcntx);
24585 X      aancpy(seqc1,(char *)(aa1p+a_res.min1-mins),mins,pst);
24586 X      aln->smin1 = a_res.min1-mins;
24587 X      if ((mins-a_res.min0)>0) {
24588 X       memset(seqc0,' ',mins-a_res.min0);
24589 X       aancpy(seqc0+mins-a_res.min0,(char *)aa0,a_res.min0,pst);
24590 X       aln->smin0 = 0;
24591 X      }
24592 X      else {
24593 X       aancpy(seqc0,(char *)aa0+a_res.min0-mins,mins,pst);
24594 X       aln->smin0 = a_res.min0-mins;
24595 X      }
24596 X    }
24597 X  else {
24598 X    mins= min(aln->llcntx,min(a_res.min0,a_res.min1));
24599 X    smins=mins;
24600 X    aln->smin0=a_res.min0 - smins;
24601 X    aln->smin1=a_res.min1 - smins;
24602 X    aancpy(seqc0,(char *)aa0+a_res.min0-mins,mins,pst);
24603 X    aancpy(seqc1,(char *)aa1p+a_res.min1-mins,mins,pst);
24604 X  }
24605 X  /* set the alignment code to zero for context */
24606 X  memset(seqca,0,mins);
24607 X  memset(seqc0a,' ',mins);
24608 X
24609 X  /* TFASTA
24610 X  smins = mins = 0;
24611 X  aln->smin0=a_res.min0;
24612 X  aln->smin1=a_res.min1;
24613 X  */
24614 X
24615 /* now get the middle */
24616 X
24617 X  spa = seqca+mins;
24618 X  sp0 = seqc0+mins;
24619 X  sp0a = seqc0a+mins;
24620 X  sp1 = seqc1+mins;
24621 X  rp = a_res.res;
24622 X  lenc = aln->nident = aln->nsim = aln->ngap_q = aln->ngap_l = aln->nfs = op = 0;
24623 X  i0 = a_res.min0;
24624 X  i1 = a_res.min1;
24625 X  
24626 X  while (i0 < a_res.max0 || i1 < a_res.max1) {
24627 X    if (op == 0 && *rp == 0) {
24628 X      op = *rp++;
24629 X      lenc++;
24630 X      if ((itmp=pst.pam2[0][aa0[i0]][aa1p[i1]])<0) { *spa = M_NEG; }
24631 X      else if (itmp == 0) { *spa = M_ZERO;}
24632 X      else {*spa = M_POS;}
24633 X      if (*spa == M_POS || *spa==M_ZERO) aln->nsim++;
24634 X
24635 X      *sp0a++ = ann_arr[aa0a[i0]];
24636 X
24637 X      *sp0 = sq[aa0[i0++]];
24638 X      *sp1 = sq[aa1p[i1++]];
24639 X
24640 X      if (toupper(*sp0) == toupper(*sp1)) {
24641 X       aln->nident++;
24642 X       *spa = M_IDENT;
24643 X      }
24644 X      else if (pst.nt_align) {
24645 X       if ((toupper(*sp0) == 'T' && toupper(*sp1) == 'U') ||
24646 X           (toupper(*sp0)=='U' && toupper(*sp1)=='T')) {
24647 X         aln->nident++;
24648 X         *spa = M_IDENT;
24649 X       }
24650 X       else if (toupper(*sp0) == 'N') aln->ngap_q++;
24651 X       else if (toupper(*sp1) == 'N') aln->ngap_l++;
24652 X      }
24653 X      sp0++; sp1++; spa++;
24654 X    }
24655 X    else {
24656 X      if (op==0) op = *rp++;
24657 X      if (op>0) {
24658 X       *sp0++ = '-';
24659 X       *sp1++ = sq[aa1p[i1++]];
24660 X       *spa++ = M_DEL;
24661 X       *sp0a++ = ' ';
24662 X       op--;
24663 X       lenc++;
24664 X       aln->ngap_q++;
24665 X      }
24666 X      else {
24667 X       *sp0a++ = ann_arr[aa0a[i0]];
24668 X       *sp0++ = sq[aa0[i0++]];
24669 X       *sp1++ = '-';
24670 X       *spa++ = M_DEL;
24671 X       op++;
24672 X       lenc++;
24673 X       aln->ngap_l++;
24674 X      }
24675 X    }
24676 X  }
24677 X
24678 X  *nc = lenc;
24679 X  *sp0a = *spa = '\0';
24680 X
24681 /*      now we have the middle, get the right end */
24682 X  if (!aln->llcntx_flg) {
24683 X    ns = mins + lenc + aln->llen;      /* show an extra line? */
24684 X    ns -= (itmp = ns %aln->llen);      /* itmp = left over on last line */
24685 X    if (itmp>aln->llen/2) ns += aln->llen;  /* more than 1/2 , use another*/
24686 X    nd = ns - (mins+lenc);             /* this much extra */
24687 X  }
24688 X  else nd = aln->llcntx;
24689 X
24690 X  if (nd > max(n0-a_res.max0,nn1-a_res.max1)) 
24691 X    nd = max(n0-a_res.max0,nn1-a_res.max1);
24692 X  
24693 X  if (aln->showall==1) {
24694 X    nd = max(n0-a_res.max0,nn1-a_res.max1);    /* reset for showall=1 */
24695 X    /* get right end */
24696 X    aancpy(seqc0+mins+lenc,(char *)aa0+a_res.max0,n0-a_res.max0,pst);
24697 X    aancpy(seqc1+mins+lenc,(char *)aa1p+a_res.max1,nn1-a_res.max1,pst);
24698 X    /* fill with blanks - this is required to use one 'nc' */
24699 X    memset(seqc0+mins+lenc+n0-a_res.max0,' ',nd-(n0-a_res.max0));
24700 X    memset(seqc1+mins+lenc+nn1-a_res.max1,' ',nd-(nn1-a_res.max1));
24701 X  }
24702 X  else {
24703 X    if ((nd-(n0-a_res.max0))>0) {
24704 X      aancpy(seqc0+mins+lenc,(char *)aa0+a_res.max0,(n0-a_res.max0),pst);
24705 X      memset(seqc0+mins+lenc+n0-a_res.max0,' ',nd-(n0-a_res.max0));
24706 X    }
24707 X    else aancpy(seqc0+mins+lenc,(char *)aa0+a_res.max0,nd,pst);
24708 X
24709 X    if ((nd-(nn1-a_res.max1))>0) {
24710 X      aancpy(seqc1+mins+lenc,(char *)aa1p+a_res.max1,nn1-a_res.max1,pst);
24711 X      memset(seqc1+mins+lenc+nn1-a_res.max1,' ',nd-(nn1-a_res.max1));
24712 X    }
24713 X    else aancpy(seqc1+mins+lenc,(char *)aa1p+a_res.max1,nd,pst);
24714 X  }
24715 X
24716 X  /*  fprintf(stderr,"%d\n",mins+lenc+nd); */
24717 X
24718 X  return mins+lenc+nd;
24719 }
24720 X
24721 static void
24722 update_code(char *al_str, int al_str_max, int op, int op_cnt) {
24723 X
24724 X  char op_char[5]={"=-+*"};
24725 X  char tmp_cnt[20];
24726 X
24727 X  sprintf(tmp_cnt,"%c%d",op_char[op],op_cnt);
24728 X  strncat(al_str,tmp_cnt,al_str_max);
24729 }
24730 X
24731 X
24732 /* build an array of match/ins/del - length strings */
24733 int calc_code(const unsigned char *aa0, int n0,
24734 X             const unsigned char *aa1, int n1,
24735 X             struct a_struct *aln, struct a_res_str a_res,
24736 X             struct pstruct pst,
24737 X             char *al_str, int al_str_n, struct f_struct *f_str)
24738 {
24739 X  int i0, i1, nn1;
24740 X  int op, lenc;
24741 X  int p_op, op_cnt;
24742 X  const unsigned char *aa1p;
24743 X  char sp0, sp1, *sq;
24744 X  int *rp;
24745 X
24746 X  if (pst.ext_sq_set) {
24747 X    sq = pst.sqx;
24748 X  }
24749 X  else {
24750 X    sq = pst.sq;
24751 X  }
24752 X
24753 #ifndef TFASTA
24754 X  aa1p = aa1;
24755 X  nn1 = n1;
24756 #else
24757 X  aa1p = f_str->aa1x;
24758 X  nn1 = f_str->n10;
24759 #endif
24760 X
24761 X  aln->amin0 = a_res.min0;
24762 X  aln->amax0 = a_res.max0;
24763 X  aln->amin1 = a_res.min1;
24764 X  aln->amax1 = a_res.max1;
24765 X
24766 X  rp = a_res.res;
24767 X  lenc = aln->nident = aln->nsim = aln->ngap_q = aln->ngap_l = aln->nfs = op = p_op = 0;
24768 X  op_cnt = 0;
24769 X
24770 X  i0 = a_res.min0;
24771 X  i1 = a_res.min1;
24772 X  
24773 X  while (i0 < a_res.max0 || i1 < a_res.max1) {
24774 X    if (op == 0 && *rp == 0) {
24775 X
24776 X      if (pst.pam2[0][aa0[i0]][aa1p[i1]]>=0) { aln->nsim++;}
24777 X
24778 X      sp0 = sq[aa0[i0++]];
24779 X      sp1 = sq[aa1p[i1++]];
24780 X
24781 X      if (p_op == 0 || p_op==3) {
24782 X       if (sp0 != '*' && sp1 != '*') {
24783 X         if (p_op == 3) {
24784 X           update_code(al_str,al_str_n-strlen(al_str),p_op,op_cnt);
24785 X           op_cnt = 1; p_op = 0;
24786 X         }
24787 X         else {op_cnt++;}
24788 X       }
24789 X       else {
24790 X         update_code(al_str,al_str_n-strlen(al_str),p_op,op_cnt);
24791 X         op_cnt = 1; p_op = 3;
24792 X       }
24793 X      }
24794 X      else {
24795 X       update_code(al_str,al_str_n-strlen(al_str),p_op,op_cnt);
24796 X       op_cnt = 1; p_op = 0;
24797 X      }
24798 X
24799 X      op = *rp++;
24800 X      lenc++;
24801 X
24802 X      if (toupper(sp0) == toupper(sp1)) aln->nident++;
24803 X      else if (pst.nt_align) {
24804 X       if ((toupper(sp0) == 'T' && toupper(sp1) == 'U') ||
24805 X           (toupper(sp0)=='U' && toupper(sp1)=='T')) aln->nident++;
24806 X       else if (toupper(sp0) == 'N') aln->ngap_q++;
24807 X       else if (toupper(sp1) == 'N') aln->ngap_l++;
24808 X      }
24809 X    }
24810 X    else {
24811 X      if (op==0) op = *rp++;
24812 X      if (op>0) {
24813 X       if (p_op == 1) { op_cnt++;}
24814 X       else {
24815 X         update_code(al_str,al_str_n - strlen(al_str),p_op,op_cnt);
24816 X         op_cnt = 1; p_op = 1;
24817 X       }
24818 X       op--; lenc++; i1++; aln->ngap_q++;
24819 X      }
24820 X      else {
24821 X       if (p_op == 2) { op_cnt++;}
24822 X       else {
24823 X         update_code(al_str,al_str_n - strlen(al_str),p_op,op_cnt);
24824 X         op_cnt = 1; p_op = 2;
24825 X       }
24826 X       op++; lenc++; i0++; aln->ngap_l++;
24827 X      }
24828 X    }
24829 X  }
24830 X  update_code(al_str,al_str_n - strlen(al_str),p_op,op_cnt);
24831 X
24832 X  return lenc;
24833 }
24834 X
24835 int calc_id(const unsigned char *aa0, int n0,
24836 X           const unsigned char *aa1, int n1,
24837 X           struct a_struct *aln, 
24838 X           struct a_res_str a_res,
24839 X           struct pstruct pst,
24840 X           struct f_struct *f_str)
24841 {
24842 X  int i0, i1, nn1;
24843 X  int op, lenc;
24844 X  int sp0, sp1;
24845 X  const unsigned char *aa1p;
24846 X  int *rp;
24847 X  char *sq;
24848 X  
24849 X  if (pst.ext_sq_set) { sq = pst.sqx; }
24850 X  else { sq = pst.sq; }
24851 X
24852 #ifndef TFASTA
24853 X  aa1p = aa1;
24854 X  nn1 = n1;
24855 #else
24856 X  aa1p = f_str->aa1x;
24857 X  nn1 = f_str->n10;
24858 #endif
24859 X
24860 X  aln->amin0 = a_res.min0;
24861 X  aln->amax0 = a_res.max0;
24862 X  aln->amin1 = a_res.min1;
24863 X  aln->amax1 = a_res.max1;
24864 X
24865 X  rp = a_res.res;
24866 X  lenc = aln->nident = aln->nsim = aln->ngap_q = aln->ngap_l = aln->nfs = op = 0;
24867 X  i0 = a_res.min0;
24868 X  i1 = a_res.min1;
24869 X
24870 X  while (i0 < a_res.max0 || i1 < a_res.max1) {
24871 X    if (op == 0 && *rp == 0) {
24872 X      op = *rp++;
24873 X      lenc++;
24874 X
24875 X      if (pst.pam2[0][aa0[i0]][aa1p[i1]]>=0) { aln->nsim++;}
24876 X
24877 X      sp0 = sq[aa0[i0++]];
24878 X      sp1 = sq[aa1p[i1++]];
24879 X      if (toupper(sp0) == toupper(sp1)) {aln->nident++;}
24880 X      else if (pst.nt_align) {
24881 X       if ((toupper(sp0)=='T' && toupper(sp1)== 'U')||
24882 X         (toupper(sp0)=='U' && toupper(sp1)=='T')) {aln->nident++;}
24883 X       else if (toupper(sp0) == 'N') aln->ngap_q++;
24884 X       else if (toupper(sp1) == 'N') aln->ngap_l++;
24885 X      }
24886 X    }
24887 X    else {
24888 X      if (op==0) op = *rp++;
24889 X      if (op>0) {op--; lenc++; i1++; aln->ngap_q++;}
24890 X      else {op++; lenc++; i0++; aln->ngap_l++; }
24891 X    }
24892 X  }
24893 X  return lenc;
24894 }
24895 X
24896 #ifdef PCOMPLIB
24897 X
24898 #include "w_mw.h"
24899 X
24900 void
24901 update_params(struct qmng_str *qm_msg, struct pstruct *ppst)
24902 {
24903 X  ppst->n0 = qm_msg->n0;
24904 }
24905 #endif
24906 SHAR_EOF
24907 chmod 0644 dropnfa.c ||
24908 echo 'restore of dropnfa.c failed'
24909 Wc_c="`wc -c < 'dropnfa.c'`"
24910 test 70110 -eq "$Wc_c" ||
24911         echo 'dropnfa.c: original size 70110, current size' "$Wc_c"
24912 fi
24913 # ============= dropnfa.h ==============
24914 if test -f 'dropnfa.h' -a X"$1" != X"-c"; then
24915         echo 'x - skipping dropnfa.h (File already exists)'
24916 else
24917 echo 'x - extracting dropnfa.h (Text)'
24918 sed 's/^X//' << 'SHAR_EOF' > 'dropnfa.h' &&
24919 X
24920 /* global definitions shared by dropnfa.c and altivec.c */
24921 X
24922 #ifndef MAXSAV
24923 #define MAXSAV 10
24924 #endif
24925 X
24926 X
24927 X
24928 struct dstruct          /* diagonal structure for saving current run */
24929 {                       
24930 X   int     score;      /* hash score of current match */
24931 X   int     start;      /* start of current match */
24932 X   int     stop;       /* end of current match */
24933 X   struct savestr *dmax;   /* location in vmax[] where best score data saved */
24934 };
24935 X
24936 struct savestr
24937 {
24938 X   int     score;              /* pam score with segment optimization */
24939 X   int     score0;             /* pam score of best single segment */
24940 X   int     gscore;             /* score from global match */
24941 X   int     dp;                 /* diagonal of match */
24942 X   int     start;              /* start of match in lib seq */
24943 X   int     stop;               /* end of match in lib seq */
24944 };
24945 X
24946 struct bdstr { int CC, DD, CP, DP;};
24947 X
24948 struct f_struct {
24949 X  struct dstruct *diag;
24950 X  struct savestr vmax[MAXSAV]; /* best matches saved for one sequence */
24951 X  struct savestr *vptr[MAXSAV];
24952 X  struct savestr *lowmax;
24953 X  int ndo;
24954 X  int noff;
24955 X  int hmask;                   /* hash constants */
24956 X  int *pamh1;                  /* pam based array */
24957 X  int *pamh2;                  /* pam based kfact array */
24958 X  int *link, *harr;            /* hash arrays */
24959 X  int kshft;                   /* shift width */
24960 X  int nsav, lowscor;           /* number of saved runs, worst saved run */
24961 #ifdef TFASTA
24962 X  unsigned char *aa1x;
24963 X  int n10;
24964 #endif
24965 X  struct bdstr *bss;
24966 X  struct swstr *ss;
24967 X  struct swstr *f_ss, *r_ss;
24968 X  int *waa0;
24969 X  int *waa1;
24970 X  int *res;
24971 X  int max_res;
24972 X  double aa0_f[MAXSQ];
24973 X  double *kar_p;
24974
24975 #ifdef FA_ALTIVEC
24976 X  int vec_len;
24977 X  vecInt **vec_matrix;
24978 X  vector signed ALTIVEC_SIZE *vec_HH;
24979 X  vector signed ALTIVEC_SIZE *vec_EE;
24980 X
24981 X  int vec_len2;
24982 X  vecInt2 **vec_matrix2;
24983 X  vector signed ALTIVEC_SIZE2 *vec_HH2;
24984 X  vector signed ALTIVEC_SIZE2 *vec_EE2;
24985 #endif
24986 };
24987 X
24988 static int
24989 FLOCAL_ALIGN(const unsigned char *A, const unsigned char *B,
24990 X            int M, int N, int low, int up,
24991 X            int **W, int G,int H, int MW,
24992 X            struct f_struct *f_str);
24993 SHAR_EOF
24994 chmod 0644 dropnfa.h ||
24995 echo 'restore of dropnfa.h failed'
24996 Wc_c="`wc -c < 'dropnfa.h'`"
24997 test 1882 -eq "$Wc_c" ||
24998         echo 'dropnfa.h: original size 1882, current size' "$Wc_c"
24999 fi
25000 # ============= dropnsw.c ==============
25001 if test -f 'dropnsw.c' -a X"$1" != X"-c"; then
25002         echo 'x - skipping dropnsw.c (File already exists)'
25003 else
25004 echo 'x - extracting dropnsw.c (Text)'
25005 sed 's/^X//' << 'SHAR_EOF' > 'dropnsw.c' &&
25006 /* copyright (c) 1994, 1995, 1996 William R. Pearson */
25007 X
25008 /* $Name: fa_34_26_5 $ - $Id: dropnsw.c,v 1.35 2006/10/19 14:49:14 wrp Exp $ */
25009 X
25010 /*
25011 X  this is a slower version of dropgsw.c that implements the Smith-Waterman
25012 X  algorithm.  It lacks the shortcuts in dropgsw.c that prevent scores less
25013 X  than the penalty for the first residue in a gap from being generated.
25014 X
25015 X  Thus, dropnsw.c should be used for tests with very large gap penalties,
25016 X  and is more appropriate for programs like prss3, which are interested
25017 X  in accurate low scores.
25018 */
25019 X
25020 /* the do_walign() code in this file is not thread_safe */
25021 /* init_work(), do_work(), are thread safe */
25022 X
25023 #include <stdio.h>
25024 #include <stdlib.h>
25025 #include <string.h>
25026 #include <ctype.h>
25027 #include <math.h>
25028 X
25029 #include "defs.h"
25030 #include "param.h"
25031 X
25032 static char *verstr="3.5 Sept 2006";
25033 X
25034 struct swstr { int H, E;};
25035 X
25036 struct f_struct {
25037 X  struct swstr *ss;
25038 X  struct swstr *f_ss;
25039 X  struct swstr *r_ss;
25040 X  int *waa_s, *waa_a;
25041 X  int **pam2p[2];
25042 X  int *res;
25043 X  double aa0_f[MAXSQ];
25044 X  double *kar_p;
25045 };
25046 X
25047 #define DROP_INTERN
25048 #include "drop_func.h"
25049 X
25050 extern int do_karlin(const unsigned char *aa1, int n1,
25051 X                    int **pam2, struct pstruct *ppst,
25052 X                    double *aa0_f, double *kar_p, double *lambda, double *H);
25053 extern void aancpy(char *to, char *from, int count, struct pstruct pst);
25054 int ALIGN(const unsigned char *A, const unsigned char *B, int M, int N,
25055 X         int **W, int IW, int G, int H, int *S, int *NC,
25056 X         struct f_struct *f_str);
25057 X
25058 /* initialize for Smith-Waterman optimal score */
25059 X
25060 void init_work (unsigned char *aa0, int n0,
25061 X               struct pstruct *ppst,
25062 X               struct f_struct **f_arg)
25063 {
25064 X   int maxn0;
25065 X   int *pwaa_s, *pwaa_a;
25066 X   int e, f, i, j, q;
25067 X   int *res;
25068 X   struct f_struct *f_str;
25069 X   int **pam2p;
25070 X   struct swstr *ss, *f_ss, *r_ss;
25071 X   int nsq, ip;
25072 X
25073 X   if (ppst->ext_sq_set) {
25074 X     nsq = ppst->nsqx; ip = 1;
25075 X   }
25076 X   else {
25077 X     nsq = ppst->nsq; ip = 0;
25078 X   }
25079 X
25080 X   f_str = (struct f_struct *)calloc(1,sizeof(struct f_struct));
25081 X
25082 X   /* allocate space for the scoring arrays */
25083 X   maxn0 = n0 + 2;
25084 X   if ((ss = (struct swstr *) calloc (maxn0, sizeof (struct swstr)))
25085 X        == NULL) {
25086 X     fprintf (stderr, "cannot allocate ss array %3d\n", n0);
25087 X     exit (1);
25088 X   }
25089 X   ss++;
25090 X   f_str->ss = ss;
25091 X
25092 X   if ((f_ss = (struct swstr *) calloc (maxn0, sizeof (struct swstr)))
25093 X       == NULL) {
25094 X     fprintf (stderr, "cannot allocate f_ss array %3d\n", n0);
25095 X     exit (1);
25096 X   }
25097 X   f_ss++;
25098 X   f_str->f_ss = f_ss;
25099 X
25100 X   if ((r_ss = (struct swstr *) calloc (n0+2, sizeof (struct swstr)))
25101 X       == NULL) {
25102 X     fprintf (stderr, "cannot allocate r_ss array %3d\n", n0);
25103 X     exit (1);
25104 X   }
25105 X   r_ss++;
25106 X   f_str->r_ss = r_ss;
25107 X
25108 X   /* initialize variable (-S) pam matrix */
25109 X   if ((f_str->waa_s= (int *)calloc((nsq+1)*(n0+1),sizeof(int))) == NULL) {
25110 X     fprintf(stderr,"cannot allocate waa_s array %3d\n",nsq*n0);
25111 X     exit(1);
25112 X   }
25113 X
25114 X   if ((f_str->pam2p[1]= (int **)calloc((n0+1),sizeof(int *))) == NULL) {
25115 X     fprintf(stderr,"cannot allocate pam2p[1] array %3d\n",n0);
25116 X     exit(1);
25117 X   }
25118 X
25119 X   pam2p = f_str->pam2p[1];
25120 X   if ((pam2p[0]=(int *)calloc((nsq+1)*(n0+1),sizeof(int))) == NULL) {
25121 X     fprintf(stderr,"cannot allocate pam2p[1][] array %3d\n",nsq*n0);
25122 X     exit(1);
25123 X   }
25124 X
25125 X   for (i=1; i<n0; i++) {
25126 X     pam2p[i]= pam2p[0] + (i*(nsq+1));
25127 X   }
25128 X
25129 X   /* initialize universal (alignment) matrix */
25130 X   if ((f_str->waa_a= (int *)calloc((nsq+1)*(n0+1),sizeof(int))) == NULL) {
25131 X     fprintf(stderr,"cannot allocate waa_a struct %3d\n",nsq*n0);
25132 X     exit(1);
25133 X   }
25134 X
25135 X   if ((f_str->pam2p[0]= (int **)calloc((n0+1),sizeof(int *))) == NULL) {
25136 X     fprintf(stderr,"cannot allocate pam2p[1] array %3d\n",n0);
25137 X     exit(1);
25138 X   }
25139 X
25140 X   pam2p = f_str->pam2p[0];
25141 X   if ((pam2p[0]=(int *)calloc((nsq+1)*(n0+1),sizeof(int))) == NULL) {
25142 X     fprintf(stderr,"cannot allocate pam2p[1][] array %3d\n",nsq*n0);
25143 X     exit(1);
25144 X   }
25145 X
25146 X   for (i=1; i<n0; i++) {
25147 X     pam2p[i]= pam2p[0] + (i*(nsq+1));
25148 X   }
25149 X
25150 X   /* 
25151 X      pwaa effectively has a sequence profile --
25152 X       pwaa[0..n0-1] has pam score for residue 0 (-BIGNUM)
25153 X       pwaa[n0..2n0-1] has pam scores for residue 1 (A)
25154 X       pwaa[2n0..3n-1] has pam scores for residue 2 (R), ...
25155 X
25156 X       thus: pwaa = f_str->waa_s + (*aa1p++)*n0; sets up pwaa so that
25157 X       *pwaa++ rapidly moves though the scores of the aa1p[] position
25158 X       without further indexing
25159 X
25160 X       For a real sequence profile, pwaa[0..n0-1] vs ['A'] could have
25161 X       a different score in each position.
25162 X   */
25163 X
25164 X   if (ppst->pam_pssm) {
25165 X     pwaa_s = f_str->waa_s;
25166 X     pwaa_a = f_str->waa_a;
25167 X     for (e = 0; e <=nsq; e++) {       /* for each residue in the alphabet */
25168 X       for (f = 0; f < n0; f++) {      /* for each position in aa0 */
25169 X        *pwaa_s++ = f_str->pam2p[ip][f][e] = ppst->pam2p[ip][f][e];
25170 X        *pwaa_a++ = f_str->pam2p[0][f][e]  = ppst->pam2p[0][f][e];
25171 X       }
25172 X     }
25173 X   }
25174 X   else {      /* initialize scanning matrix */
25175 X     pwaa_s = f_str->waa_s;
25176 X     pwaa_a = f_str->waa_a;
25177 X     for (e = 0; e <=nsq; e++) /* for each residue in the alphabet */
25178 X       for (f = 0; f < n0; f++)        {       /* for each position in aa0 */
25179 X        *pwaa_s++ = f_str->pam2p[ip][f][e]= ppst->pam2[ip][e][aa0[f]];
25180 X        *pwaa_a++ = f_str->pam2p[0][f][e] = ppst->pam2[0][e][aa0[f]];
25181 X       }
25182 X   }
25183 X
25184 X   maxn0 = max(3*n0/2,MIN_RES);
25185 X   if ((res = (int *)calloc((size_t)maxn0,sizeof(int)))==NULL) {
25186 X     fprintf(stderr,"cannot allocate alignment results array %d\n",maxn0);
25187 X     exit(1);
25188 X   }
25189 X   f_str->res = res;
25190 X
25191 X   *f_arg = f_str;
25192 }
25193 X
25194 void close_work (const unsigned char *aa0, int n0,
25195 X                struct pstruct *ppst, struct f_struct **f_arg)
25196 {
25197 X  struct f_struct *f_str;
25198 X
25199 X  f_str = *f_arg;
25200 X
25201 X  if (f_str != NULL) {
25202 X    if (f_str->kar_p !=NULL) free(f_str->kar_p);
25203 X    f_str->ss--;
25204 X    free(f_str->ss);
25205 X    free(f_str->res);
25206 X    free(f_str->waa_a);
25207 X    free(f_str->pam2p[0][0]);
25208 X    free(f_str->pam2p[0]);
25209 X    free(f_str->waa_s);
25210 X    free(f_str->pam2p[1][0]);
25211 X    free(f_str->pam2p[1]);
25212 X
25213 X    free(f_str);
25214 X    *f_arg = NULL;
25215 X  }
25216 }
25217 X
25218 X
25219 /* pstring1 is a message to the manager, currently 512 */
25220 /*void get_param(struct pstruct *pstr,char *pstring1)*/
25221 void    get_param (struct pstruct *pstr, char *pstring1, char *pstring2)
25222 {
25223 X  char psi_str[120];
25224 X
25225 X  char *pg_str="Smith-Waterman";
25226 X
25227 X  if (pstr->pam_pssm) { strncpy(psi_str,"-PSI",sizeof(psi_str));}
25228 X  else { psi_str[0]='\0';}
25229 X
25230 #ifdef OLD_FASTA_GAP
25231 X   sprintf (pstring1, " %s (%s) function [%s matrix%s (%d:%d)%s], gap-penalty: %d/%d",
25232 #else
25233 X   sprintf (pstring1, " %s (%s) function [%s matrix%s (%d:%d)%s], open/ext: %d/%d",
25234 #endif
25235 X           pg_str, verstr, pstr->pamfile, psi_str, pstr->pam_h,pstr->pam_l, 
25236 X           (pstr->ext_sq_set)?"xS":"\0", pstr->gdelval, pstr->ggapval);
25237 X
25238 X   if (pstring2 != NULL) {
25239 #ifdef OLD_FASTA_GAP
25240 X     sprintf(pstring2,"; pg_name: %s\n; pg_ver: %s\n; pg_matrix: %s (%d:%d)%s\n; pg_gap-pen: %d %d\n",
25241 #else
25242 X     sprintf(pstring2,"; pg_name: %s\n; pg_ver: %s\n; pg_matrix: %s (%d:%d)%s\n; pg_open-ext: %d %d\n",
25243 #endif
25244 X            pg_str,verstr,psi_str,pstr->pam_h,pstr->pam_l, 
25245 X            (pstr->ext_sq_set)?"xS":"\0",pstr->gdelval,pstr->ggapval);
25246 X   }
25247 }
25248 X
25249 X
25250 void do_work (const unsigned char *aa0, int n0,
25251 X             const unsigned char *aa1, int n1,
25252 X             int frame,
25253 X             struct pstruct *ppst, struct f_struct *f_str,
25254 X             int qr_flg,
25255 X             struct rstruct *rst)
25256 {
25257 X   const unsigned char *aa0p, *aa1p;
25258 X   register struct swstr *ssj;
25259 X   struct swstr *ss, *f_ss, *r_ss;
25260 X   register int *pwaa;
25261 X   int *waa;
25262 X   register int i, j;
25263 X   int     e, f, h, p;
25264 X   int     q, r, m;
25265 X   int     score;
25266 X
25267 X   double lambda, H, K;
25268 X
25269 X   rst->escore = 1.0;
25270 X   rst->segnum = rst->seglen = 1;
25271 X
25272 X   waa = f_str->waa_s;
25273 X   ss = f_str->ss;
25274 X   f_ss = f_str->f_ss;
25275 X   r_ss = f_str->r_ss;
25276 X
25277 #ifdef OLD_FASTA_GAP
25278 X   q = -(ppst->gdelval - ppst->ggapval);
25279 #else
25280 X   q = -ppst->gdelval;
25281 #endif
25282 X   r = -ppst->ggapval;
25283 X   m = q + r;
25284 X
25285 X   /* initialize 0th row */
25286 X   for (ssj=ss; ssj<&ss[n0]; ssj++) {
25287 X     ssj->H = 0;
25288 X     ssj->E = -q;
25289 X   }
25290 X
25291 X   score = 0;
25292 X   aa1p = aa1;
25293 X   while (*aa1p) {
25294 X     h = p = 0;
25295 X     f = -q;
25296 X     pwaa = waa + (*aa1p++ * n0);
25297 X     for (ssj = ss, aa0p = aa0; ssj < ss+n0; ssj++) {
25298 X       if ((h =   h     - m) > (f =   f     - r)) f = h;
25299 X       if ((h = ssj->H - m) > (e = ssj->E - r)) e = h;
25300 X       h = p + *pwaa++;
25301 X       if (h < 0 ) h = 0;
25302 X       if (h < f ) h = f;
25303 X       if (h < e ) h = e;
25304 X       p = ssj->H;
25305 X       ssj->H = h;
25306 X       ssj->E = e;
25307 X       if (h > score) score = h;
25308 X     }
25309 X   }                           /* done with forward pass */
25310 X
25311 X   rst->score[0] = score;
25312 X
25313 X   if(ppst->zsflag == 6 || ppst->zsflag == 16 && 
25314 X     (do_karlin(aa1, n1, ppst->pam2[0], ppst,f_str->aa0_f, 
25315 X               f_str->kar_p, &lambda, &H)>0)) {
25316 X     rst->comp = 1.0/lambda;
25317 X     rst->H = H;
25318 X   }
25319 X  else {rst->comp = rst->H = -1.0;}
25320 }                               /* here we should be all done */
25321 X
25322 void    do_opt (const unsigned char *aa0, int n0,
25323 X               const unsigned char *aa1, int n1,
25324 X               int frame,
25325 X               struct pstruct *pst, struct f_struct *f_str,
25326 X               struct rstruct *rstr)
25327 {
25328 }
25329 X
25330 int do_walign (const unsigned char *aa0, const int n0,
25331 X              const unsigned char *aa1, const int n1,
25332 X              int frame,
25333 X              struct pstruct *ppst, 
25334 X              struct f_struct *f_str, 
25335 X              struct a_res_str *a_res,
25336 X              int *have_ares )
25337 {
25338 X   const unsigned char *aa0p, *aa1p;
25339 X   register int *pwaa;
25340 X   register int i, j;
25341 X   register struct swstr *ssj;
25342 X   struct swstr *f_ss, *r_ss, *ss;
25343 X   int *res, *waa;
25344 X   int e, f, h, p;
25345 X   int     q, r, m;
25346 X   int     score;
25347 X   int cost, I, J, K, L;
25348 X
25349 X   ss = f_str->ss;
25350 X
25351 X   res = f_str->res;
25352 X   waa = f_str->waa_a; /* this time use universal pam2[0] */
25353 X
25354 #ifdef OLD_FASTA_GAP
25355 X   q = -(ppst->gdelval - ppst->ggapval);
25356 #else
25357 X   q = -ppst->gdelval;
25358 #endif
25359 X
25360 X   r = -ppst->ggapval;
25361 X   m = q + r;
25362 X
25363 X   /* initialize 0th row */
25364 X   for (ssj=ss; ssj<ss+n0; ssj++) {
25365 X     ssj->H = 0;
25366 X     ssj->E = -q;
25367 X   }
25368 X
25369 X   score = 0;
25370 X   aa1p = aa1;
25371 X   i = 0;
25372 X   while (*aa1p) {
25373 X     h = p = 0;
25374 X     f = -q;
25375 X     pwaa = waa + (*aa1p++ * n0);
25376 X     for (ssj = ss, aa0p = aa0; ssj < ss+n0; ssj++) {
25377 X       if ((h =   h     - m) > /* gap open from left best */
25378 X          /* gap extend from left gapped */
25379 X          (f =   f     - r)) f = h;    /* if better, use new gap opened */
25380 X       if ((h = ssj->H - m) >  /* gap open from up best */
25381 X          /* gap extend from up gap */
25382 X          (e = ssj->E - r)) e = h;     /* if better, use new gap opened */
25383 X       h = p + *pwaa++;                /* diagonal match */
25384 X       if (h < 0 ) h = 0;      /* ?  < 0, reset to 0 */
25385 X       if (h < f ) h = f;      /* left gap better, reset */
25386 X       if (h < e ) h = e;      /* up gap better, reset */
25387 X       p = ssj->H;             /* save previous best score */
25388 X       ssj->H = h;             /* save (new) up diag-matched */
25389 X       ssj->E = e;             /* save upper gap opened */
25390 X       if (h > score) {                /* ? new best score */
25391 X        score = h;             /* save best */
25392 X        I = i;                 /* row */
25393 X        J = (int)(ssj-ss);     /* column */
25394 X       }
25395 X     }
25396 X     i++;
25397 X   }                           /* done with forward pass */
25398 X   if (score <= 0) return 0;
25399 X
25400 X  /* to get the start point, go backwards */
25401 X  
25402 X   /* 18-June-2003 fix bug in backtracking code to identify start of
25403 X      alignment.  Code used pam2[0][aa0[j]][aa1[i]] instead of
25404 X      pam2p[0][j][aa1[i]].  Ideally, it would use waa_a.
25405 X   */
25406 X
25407 X  cost = K = L = 0;
25408 X  for (ssj=ss+J; ssj>=ss; ssj--) ssj->H= ssj->E= -1;
25409 X  
25410 X  for (i=I; i>=0; i--) {
25411 X    h = f = -1;
25412 X    p = (i == I) ? 0 : -1;
25413 X    for (ssj=ss+J, j= J; ssj>=ss; ssj--,j--) {
25414 X      f = max (f,h-q)-r;
25415 X      ssj->E=max(ssj->E,ssj->H-q)-r;
25416 X      h = max(max(ssj->E,f),p+f_str->pam2p[0][j][aa1[i]]);
25417 X      p = ssj->H;
25418 X      ssj->H=h;
25419 X      if (h > cost) {
25420 X       cost = h;
25421 X       K = i;
25422 X       L = (int)(ssj-ss);
25423 X       if (cost >= score) goto found;
25424 X      }
25425 X    }
25426 X  }
25427 X  
25428 found:  
25429 X
25430 X  /*  printf(" %d: L: %3d-%3d/%3d; K: %3d-%3d/%3d\n",score,L,J,n0,K,I,n1); */
25431 X
25432 /* in the f_str version, the *res array is already allocated at 4*n0/3 */
25433 X
25434 X  a_res->res = f_str->res;
25435 X  *have_ares = 1;
25436 X  a_res->max0 = J+1; a_res->min0 = L; a_res->max1 = I+1; a_res->min1 = K;
25437 X  
25438 /*  ALIGN(&aa1[K-1],&aa0[L-1],I-K+1,J-L+1,ppst->pam2[0],q,r,res,nres,f_str); */
25439 X
25440 /* this code no longer refers to aa0[], it used pam2p[0][L] instead */
25441 X  ALIGN(&aa0[L-1],&aa1[K-1],J-L+1,I-K+1,f_str->pam2p[0],L,q,r,
25442 X       a_res->res,&a_res->nres,f_str);
25443 X
25444 /*   DISPLAY(&aa0[L-1],&aa1[K-1],J-L+1,I-K+1,res,L,K,ppst->sq); */
25445 X
25446 X  return score;
25447 }
25448 X
25449 static int CHECK_SCORE(const unsigned char *A, const unsigned char *B, int M, int N,
25450 X                      int *S, int **W, int IW, int G, int H, int *nres);
25451 X
25452 #define gap(k)  ((k) <= 0 ? 0 : g+h*(k))        /* k-symbol indel cost */
25453 X
25454 /* Append "Delete k" op */
25455 #define DEL(k)                          \
25456 { if (*last < 0)                        \
25457 X    *last = (*sapp)[-1] -= (k);                \
25458 X  else {                               \
25459 X    *last = (*sapp)[0] = -(k);         \
25460 X    (*sapp)++;                         \
25461 X  }                                    \
25462 }
25463 X
25464 /* Append "Insert k" op */
25465 #define INS(k)                          \
25466 { if (*last > 0)                        \
25467 X    *last = (*sapp)[-1] += (k);                \
25468 X  else {                               \
25469 X    *last = (*sapp)[0] = (k);          \
25470 X    (*sapp)++;                         \
25471 X  }                                    \
25472 }
25473 X
25474 #define REP { *last = (*sapp)[0] = 0; (*sapp)++; } /* Append "Replace" op */
25475 X
25476 /*
25477 #define XTERNAL
25478 #include "upam.h"
25479 X
25480 void
25481 print_seq_prof(unsigned char *A, int M,
25482 X              unsigned char *B, int N,
25483 X              int **w, int iw, int dir) {
25484 X  char c_max;
25485 X  int i_max, j_max, i,j;
25486 X
25487 X  char *c_dir="LRlr";
25488 X
25489 X  for (i=1; i<=min(60,M); i++) {
25490 X    fprintf(stderr,"%c",aa[A[i]]);
25491 X  }
25492 X  fprintf(stderr, - %d\n,M);
25493 X
25494 X  for (i=0; i<min(60,M); i++) {
25495 X    i_max = -1;
25496 X    for (j=1; j<21; j++) {
25497 X      if (w[iw+i][j]> i_max) {
25498 X       i_max = w[iw+i][j]; 
25499 X       j_max = j;
25500 X      }
25501 X    }
25502 X    fprintf(stderr,"%c",aa[j_max]);
25503 X  }
25504 X  fputc(':',stderr);
25505 X  for (i=1; i<=min(60,N); i++) {
25506 X    fprintf(stderr,"%c",aa[B[i]]);
25507 X  }
25508 X  fprintf(stderr," -%c: %d,%d\n",c_dir[dir],M,N);
25509 }
25510 */
25511 X
25512 /* align(A,B,M,N,tb,te) returns the cost of an optimum conversion between
25513 X   A[1..M] and B[1..N] that begins(ends) with a delete if tb(te) is zero
25514 X   and appends such a conversion to the current script.                   */
25515 X
25516 static int
25517 align(const unsigned char *A, const unsigned char *B, int M, int N,
25518 X      int tb, int te, int **w, int iw, int g, int h, 
25519 X      struct f_struct *f_str, int dir,
25520 X      int **sapp, int *last)
25521 {
25522 X  int   midi, midj, type;      /* Midpoint, type, and cost */
25523 X  int midc;
25524 X  int c1, c2;
25525 X
25526 { register int   i, j;
25527 X  register int c, e, d, s;
25528 X  int m, t, *wa;
25529 X  struct swstr *f_ss, *r_ss;
25530 X
25531 /*   print_seq_prof(A,M,B,N,w,iw,dir); */
25532 X
25533 X  m = g + h;
25534 X
25535 X  f_ss = f_str->f_ss;
25536 X  r_ss = f_str->r_ss;
25537 X
25538 /* Boundary cases: M <= 1 or N == 0 */
25539 X
25540 X  if (N <= 0) {
25541 X    if (M > 0) {
25542 X      DEL(M)
25543 X    }
25544 X    return -gap(M);
25545 X  }
25546 X
25547 X  if (M <= 1) {
25548 X    if (M <= 0){ 
25549 X      INS(N)
25550 X      return -gap(N); }
25551 X    if (tb < te) tb = te;
25552 X    midc = (tb-h) - gap(N);
25553 X    midj = 0;
25554 /*  wa = w[A[1]]; */
25555 X    wa = w[iw];
25556 X    for (j = 1; j <= N; j++) {
25557 X      c = -gap(j-1) + wa[B[j]] - gap(N-j);
25558 X      if (c > midc) { midc = c; midj = j;}
25559 X    }
25560 X    if (midj == 0) { 
25561 X      DEL(1)
25562 X      INS(N)
25563 X    }
25564 X    else  {
25565 X      if (midj > 1) { INS(midj-1)}
25566 X      REP
25567 X      if (midj < N) { INS(N-midj)}
25568 X    }
25569 X    return midc;
25570 X  }
25571 X
25572 /* Divide: Find optimum midpoint (midi,midj) of cost midc */
25573 X
25574 X  midi = M/2;          /* Forward phase:                          */
25575 X  f_ss[0].H = 0;       /*   Compute H(M/2,k) & E(M/2,k) for all k */
25576 X  t = -g;
25577 X  for (j = 1; j <= N; j++)
25578 X    { f_ss[j].H = t = t-h;
25579 X      f_ss[j].E = t-g;
25580 X    }
25581 X  t = tb;
25582 X  for (i = 1; i <= midi; i++)
25583 X    { s = f_ss[0].H;
25584 X      f_ss[0].H = c = t = t-h;
25585 X      e = t-g;
25586 /*    wa = w[A[i]]; */
25587 X      wa = w[iw+i-1];
25588 X      for (j = 1; j <= N; j++)
25589 X        { if ((c =   c   - m) > (e =   e   - h)) e = c;
25590 X          if ((c = f_ss[j].H - m) > (d = f_ss[j].E - h)) d = c;
25591 X          c = s + wa[B[j]];
25592 X          if (e > c) c = e;
25593 X          if (d > c) c = d;
25594 X          s = f_ss[j].H;
25595 X          f_ss[j].H = c;
25596 X          f_ss[j].E = d;
25597 X        }
25598 X    }
25599 X  f_ss[0].E = f_ss[0].H;
25600 X
25601 X  r_ss[N].H = 0;               /* Reverse phase:                  */
25602 X  t = -g;                      /*   Compute R(M/2,k) & S(M/2,k) for all k */
25603 X  for (j = N-1; j >= 0; j--)
25604 X    { r_ss[j].H = t = t-h;
25605 X      r_ss[j].E = t-g;
25606 X    }
25607 X  t = te;
25608 X  for (i = M-1; i >= midi; i--)
25609 X    { s = r_ss[N].H;
25610 X      r_ss[N].H = c = t = t-h;
25611 X      e = t-g;
25612 /*    wa = w[A[i+1]]; */
25613 X      wa = w[iw+i];
25614 X      for (j = N-1; j >= 0; j--)
25615 X        { if ((c =   c   - m) > (e =   e   - h)) e = c;
25616 X          if ((c = r_ss[j].H - m) > (d = r_ss[j].E - h)) d = c;
25617 X          c = s + wa[B[j+1]];
25618 X          if (e > c) c = e;
25619 X          if (d > c) c = d;
25620 X          s = r_ss[j].H;
25621 X          r_ss[j].H = c;
25622 X          r_ss[j].E = d;
25623 X        }
25624 X    }
25625 X  r_ss[N].E = r_ss[N].H;
25626 X
25627 X  midc = f_ss[0].H+r_ss[0].H;          /* Find optimal midpoint */
25628 X  midj = 0;
25629 X  type = 1;
25630 X  for (j = 0; j <= N; j++)
25631 X    if ((c = f_ss[j].H + r_ss[j].H) >= midc)
25632 X      if (c > midc || f_ss[j].H != f_ss[j].E && r_ss[j].H == r_ss[j].E)
25633 X        { midc = c;
25634 X          midj = j;
25635 X        }
25636 X  for (j = N; j >= 0; j--)
25637 X    if ((c = f_ss[j].E + r_ss[j].E + g) > midc)
25638 X      { midc = c;
25639 X        midj = j;
25640 X        type = 2;
25641 X      }
25642 X  }
25643 X
25644 /* Conquer: recursively around midpoint */
25645 X
25646 X  if (type == 1)
25647 X    { c1 = align(A,B,midi,midj,tb,-g,w,iw,g,h,f_str,0, sapp, last);
25648 X      c2 = align(A+midi,B+midj,M-midi,N-midj,-g,te,w,iw+midi,g,h,f_str,1,sapp,last);
25649 X    }
25650 X  else
25651 X    { align(A,B,midi-1,midj,tb,0,w,iw,g,h,f_str,2,sapp, last);
25652 X      DEL(2);
25653 X      align(A+midi+1,B+midj,M-midi-1,N-midj,0,te,w,iw+midi+1,g,h,f_str,3,sapp,last);
25654 X    }
25655 X  return midc;
25656 }
25657 X
25658 /* Interface and top level of comparator */
25659 X
25660 int ALIGN(const unsigned char *A, const unsigned char *B, int M, int N,
25661 X         int **W, int IW, int G, int H, int *S, int *NC,
25662 X         struct f_struct *f_str)
25663
25664 X  struct swstr *f_ss, *r_ss;
25665 X  int *sapp, last;
25666 X  int c, ck;
25667 X
25668 X  sapp = S;
25669 X  last = 0;
25670 X
25671 X   if ((f_ss = (struct swstr *) calloc (N+2, sizeof (struct swstr)))
25672 X       == NULL) {
25673 X     fprintf (stderr, "cannot allocate f_ss array %3d\n", N+2);
25674 X     exit (1);
25675 X   }
25676 X   f_ss++;
25677 X   f_str->f_ss = f_ss;
25678 X
25679 X   if ((r_ss = (struct swstr *) calloc (N+2, sizeof (struct swstr)))
25680 X       == NULL) {
25681 X     fprintf (stderr, "cannot allocate r_ss array %3d\n", N+2);
25682 X     exit (1);
25683 X   }
25684 X   r_ss++;
25685 X   f_str->r_ss = r_ss;
25686 X
25687 X  /*   print_seq_prof(A,M,W,IW); */
25688 X  c = align(A,B,M,N,-G,-G,W,IW,G,H,f_str,0,&sapp, &last);      /* OK, do it */
25689 X
25690 X  ck = CHECK_SCORE(A,B,M,N,S,W,IW,G,H,NC);
25691 X  if (c != ck) printf("Check_score error. %d != %d\n",c,ck);
25692 X
25693 X  f_ss--; r_ss--;
25694 X  free(r_ss); free(f_ss);
25695 X
25696 X  return c;
25697 }
25698 X
25699 /* Alignment display routine */
25700 X
25701 static char ALINE[51], BLINE[51], CLINE[51];
25702 X
25703 void DISPLAY(unsigned char *A, unsigned char *B, int M, int N,
25704 X           int *S, int AP, int BP, char *sq)
25705 { register char *a, *b, *c;
25706 X  register int   i,  j, op;
25707 X           int   lines, ap, bp;
25708 X
25709 X  i = j = op = lines = 0;
25710 X  ap = AP;
25711 X  bp = BP;
25712 X  a = ALINE;
25713 X  b = BLINE;
25714 X  c = CLINE;
25715 X  while (i < M || j < N)
25716 X    { if (op == 0 && *S == 0)
25717 X        { op = *S++;
25718 X          *a = sq[A[++i]];
25719 X          *b = sq[B[++j]];
25720 X          *c++ = (*a++ == *b++) ? '|' : ' ';
25721 X        }
25722 X      else
25723 X        { if (op == 0)
25724 X            op = *S++;
25725 X          if (op > 0)
25726 X            { *a++ = ' ';
25727 X              *b++ = sq[B[++j]];
25728 X              op--;
25729 X            }
25730 X          else
25731 X            { *a++ = sq[A[++i]];
25732 X              *b++ = ' ';
25733 X              op++;
25734 X            }
25735 X          *c++ = '-';
25736 X        }
25737 X      if (a >= ALINE+50 || i >= M && j >= N)
25738 X        { *a = *b = *c = '\0';
25739 X          printf("\n%5d ",50*lines++);
25740 X          for (b = ALINE+10; b <= a; b += 10)
25741 X            printf("    .    :");
25742 X          if (b <= a+5)
25743 X            printf("    .");
25744 X          printf("\n%5d %s\n      %s\n%5d %s\n",ap,ALINE,CLINE,bp,BLINE);
25745 X         ap = AP + i;
25746 X         bp = BP + j;
25747 X          a = ALINE;
25748 X          b = BLINE;
25749 X          c = CLINE;
25750 X        }
25751 X    }
25752 }
25753 X
25754 /* CHECK_SCORE - return the score of the alignment stored in S */
25755 X
25756 static int CHECK_SCORE(const unsigned char *A, const unsigned char *B,
25757 X                      int M, int N, int *S, int **w, int iw, 
25758 X                      int g, int h, int *NC)
25759
25760 X  register int   i,  j, op, nc;
25761 X  int score;
25762 X
25763 X  /*  print_seq_prof(A,M,w,iw); */
25764 X
25765 X  score = i = j = op = nc = 0;
25766 X  while (i < M || j < N) {
25767 X    op = *S++;
25768 X    if (op == 0) {
25769 X      score = w[iw+i][B[++j]] + score;
25770 X      i++;
25771 X      nc++;
25772 X    }
25773 X    else if (op > 0) {
25774 X      score = score - (g+op*h);
25775 X      j += op;
25776 X      nc += op;
25777 X    } else {
25778 X      score = score - (g-op*h);
25779 X      i -= op;
25780 X      nc -= op;
25781 X    }
25782 X  }
25783 X  *NC = nc;
25784 X  return score;
25785 }
25786 X
25787 void
25788 pre_cons(const unsigned char *aa1, int n1, int frame, struct f_struct *f_str) {}
25789 X
25790 /* aln_func_vals - set up aln.qlfact, qlrev, llfact, llmult, frame, llrev */
25791 /* call from calcons, calc_id, calc_code */
25792 void 
25793 aln_func_vals(int frame, struct a_struct *aln) {
25794 X
25795 X  aln->llfact = aln->llmult = aln->qlfact = 1;
25796 X  aln->qlrev = aln->llrev = 0;
25797 X  aln->frame = 0;
25798 }
25799 X
25800 /* 29-June-2003 this version has been modified to use pst.pam2p
25801 X   instead of pam2 to indicate similarity */
25802 X
25803 #include "a_mark.h"
25804 X
25805 int calcons(const unsigned char *aa0, int n0,
25806 X           const unsigned char *aa1, int n1,
25807 X           int *nc,
25808 X           struct a_struct *aln, 
25809 X           struct a_res_str a_res,
25810 X           struct pstruct pst,
25811 X           char *seqc0, char *seqc1, char *seqca,
25812 X           struct f_struct *f_str)
25813 {
25814 X  int i0, i1;
25815 X  int op, lenc, nd, ns, itmp;
25816 X  char *sp0, *sp1, *spa, *sq;
25817 X  int *rp;
25818 X  int mins, smins;
25819 X  
25820 X  if (pst.ext_sq_set) { sq = pst.sqx;}
25821 X  else {sq = pst.sq;}
25822 X
25823 X  aln->amin0 = a_res.min0;
25824 X  aln->amax0 = a_res.max0;
25825 X  aln->amin1 = a_res.min1;
25826 X  aln->amax1 = a_res.max1;
25827 X
25828 X  /* #define LFASTA */
25829 #ifndef LFASTA
25830 X  if (min(a_res.min0,a_res.min1)<aln->llen || aln->showall==1)     /* will we show all the start ?*/
25831 X    if (a_res.min0>=a_res.min1) {              /* aa0 extends more to left */
25832 X      smins=0;
25833 X      if (aln->showall==1) mins=a_res.min0;
25834 X      else mins = min(a_res.min0,aln->llcntx);
25835 X      aancpy(seqc0,(char *)aa0+a_res.min0-mins,mins,pst);
25836 X      aln->smin0 = a_res.min0-mins;
25837 X      if ((mins-a_res.min1)>0) {
25838 X       memset(seqc1,' ',mins-a_res.min1);
25839 X       aancpy(seqc1+mins-a_res.min1,(char *)aa1,a_res.min1,pst);
25840 X       aln->smin1 = 0;
25841 X      }
25842 X      else {
25843 X       aancpy(seqc1,(char *)aa1+a_res.min1-mins,mins,pst);
25844 X       aln->smin1 = a_res.min1-mins;
25845 X      }
25846 X    }
25847 X    else {
25848 X      smins=0;
25849 X      if (aln->showall == 1) mins=a_res.min1;
25850 X      else mins = min(a_res.min1,aln->llcntx);
25851 X      aancpy(seqc1,(char *)(aa1+a_res.min1-mins),mins,pst);
25852 X      aln->smin1 = a_res.min1-mins;
25853 X      if ((mins-a_res.min0)>0) {
25854 X       memset(seqc0,' ',mins-a_res.min0);
25855 X       aancpy(seqc0+mins-a_res.min0,(char *)aa0,a_res.min0,pst);
25856 X       aln->smin0 = 0;
25857 X      }
25858 X      else {
25859 X       aancpy(seqc0,(char *)aa0+a_res.min0-mins,mins,pst);
25860 X       aln->smin0 = a_res.min0-mins;
25861 X      }
25862 X    }
25863 X  else {
25864 X    mins= min(aln->llcntx,min(a_res.min0,a_res.min1));
25865 X    smins=mins;
25866 X    aln->smin0=a_res.min0;
25867 X    aln->smin1=a_res.min1;
25868 X    aancpy(seqc0,(char *)aa0+a_res.min0-mins,mins,pst);
25869 X    aancpy(seqc1,(char *)aa1+a_res.min1-mins,mins,pst);
25870 X  }
25871 #else
25872 X  aln->smin0 = a_res.min0;
25873 X  aln->smin1 = a_res.min1;
25874 X  smins = mins = 0;
25875 #endif
25876 X
25877 /* now get the middle */
25878 X
25879 X  memset(seqca,M_BLANK,mins);
25880 X
25881 X  spa = seqca+mins;
25882 X  sp0 = seqc0+mins;
25883 X  sp1 = seqc1+mins;
25884 X  rp = a_res.res;
25885 X  lenc = aln->nident = aln->nsim = aln->ngap_q = aln->ngap_l = aln->nfs =op = 0;
25886 X  i0 = a_res.min0;
25887 X  i1 = a_res.min1;
25888 X  
25889 X  while (i0 < a_res.max0 || i1 < a_res.max1) {
25890 X    if (op == 0 && *rp == 0) {
25891 X      op = *rp++;
25892 X      lenc++;
25893 X      if ((itmp=f_str->pam2p[0][i0][aa1[i1]])<0) { *spa = M_NEG; }
25894 X      else if (itmp == 0) { *spa = M_ZERO;}
25895 X      else {*spa = M_POS;}
25896 X      if (*spa == M_POS || *spa==M_ZERO) aln->nsim++;
25897 X
25898 X      *sp0 = sq[aa0[i0++]];
25899 X      *sp1 = sq[aa1[i1++]];
25900 X
25901 X      if (toupper(*sp0) == toupper(*sp1)) {aln->nident++; *spa = M_IDENT;}
25902 X      else if (pst.dnaseq==1 && ((*sp0 == 'T' && *sp1 == 'U') ||
25903 X                                (*sp0=='U' && *sp1=='T'))) {
25904 X       aln->nident++; *spa=M_IDENT;
25905 X      }
25906 X
25907 X      sp0++; sp1++; spa++;
25908 X    }
25909 X    else {
25910 X      if (op==0) op = *rp++;
25911 X      if (op>0) {
25912 X       *sp0++ = '-';
25913 X       *sp1++ = sq[aa1[i1++]];
25914 X       *spa++ = M_DEL;
25915 X       op--;
25916 X       lenc++;
25917 X       aln->ngap_q++;
25918 X      }
25919 X      else {
25920 X       *sp0++ = sq[aa0[i0++]];
25921 X       *sp1++ = '-';
25922 X       *spa++ = M_DEL;
25923 X       op++;
25924 X       lenc++;
25925 X       aln->ngap_l++;
25926 X      }
25927 X    }
25928 X  }
25929 X
25930 X  *nc = lenc;
25931 X  *spa = '\0';
25932 /*      now we have the middle, get the right end */
25933 X
25934 #ifndef LFASTA
25935 X  /* how much extra to show at end ? */
25936 X  if (!aln->llcntx_flg) {
25937 X    ns = mins + lenc + aln->llen;      /* show an extra line? */
25938 X    ns -= (itmp = ns %aln->llen);      /* itmp = left over on last line */
25939 X    if (itmp>aln->llen/2) ns += aln->llen;  /* more than 1/2 , use another*/
25940 X    nd = ns - (mins+lenc);             /* this much extra */
25941 X  }
25942 X  else nd = aln->llcntx;
25943 X
25944 X  if (nd > max(n0-a_res.max0,n1-a_res.max1))
25945 X    nd = max(n0-a_res.max0,n1-a_res.max1);
25946 X  
25947 X  if (aln->showall==1) {
25948 X    nd = max(n0-a_res.max0,n1-a_res.max1);     /* reset for showall=1 */
25949 X    /* get right end */
25950 X    aancpy(seqc0+mins+lenc,(char *)aa0+a_res.max0,n0-a_res.max0,pst);
25951 X    aancpy(seqc1+mins+lenc,(char *)aa1+a_res.max1,n1-a_res.max1,pst);
25952 X    /* fill with blanks - this is required to use one 'nc' */
25953 X    memset(seqc0+mins+lenc+n0-a_res.max0,' ',nd-(n0-a_res.max0));
25954 X    memset(seqc1+mins+lenc+n1-a_res.max1,' ',nd-(n1-a_res.max1));
25955 X  }
25956 X  else {
25957 X     if ((nd-(n0-a_res.max0))>0) {
25958 X       aancpy(seqc0+mins+lenc,(char *)aa0+a_res.max0,n0-a_res.max0,pst);
25959 X       memset(seqc0+mins+lenc+n0-a_res.max0,' ',nd-(n0-a_res.max0));
25960 X     }
25961 X     else aancpy(seqc0+mins+lenc,(char *)aa0+a_res.max0,nd,pst);
25962 X
25963 X     if ((nd-(n1-a_res.max1))>0) {
25964 X       aancpy(seqc1+mins+lenc,(char *)aa1+a_res.max1,n1-a_res.max1,pst);
25965 X       memset(seqc1+mins+lenc+n1-a_res.max1,' ',nd-(n1-a_res.max1));
25966 X     }
25967 X     else aancpy(seqc1+mins+lenc,(char *)aa1+a_res.max1,nd,pst);
25968 X }
25969 X  
25970 #else   /* LFASTA */
25971 X  nd = 0;
25972 #endif
25973 X  /* #undef LFASTA */
25974 X  return mins+lenc+nd;
25975 }
25976 X
25977 int calcons_a(const unsigned char *aa0, unsigned char *aa0a, int n0,
25978 X             const unsigned char *aa1, int n1,
25979 X             int *nc,
25980 X             struct a_struct *aln,
25981 X             struct a_res_str a_res,
25982 X             struct pstruct pst,
25983 X             char *seqc0, char *seqc0a, char *seqc1, char *seqca,
25984 X             char *ann_arr, struct f_struct *f_str)
25985 {
25986 X  int i0, i1;
25987 X  int op, lenc, nd, ns, itmp;
25988 X  char *sp0, *sp0a, *sp1, *spa, *sq;
25989 X  int *rp;
25990 X  int mins, smins;
25991 X  
25992 X  if (pst.ext_sq_set) {sq = pst.sqx;}
25993 X  else {sq = pst.sq;}
25994 X
25995 X  aln->amin0 = a_res.min0;
25996 X  aln->amax0 = a_res.max0;
25997 X  aln->amin1 = a_res.min1;
25998 X  aln->amax1 = a_res.max1;
25999 X
26000 X  /* first fill in the ends */
26001 X
26002 X  /* #define LFASTA */
26003 #ifndef LFASTA
26004 X  if (min(a_res.min0,a_res.min1)<aln->llen || aln->showall==1)     /* will we show all the start ?*/
26005 X    if (a_res.min0>=a_res.min1) {              /* aa0 extends more to left */
26006 X      smins=0;
26007 X      if (aln->showall==1) mins=a_res.min0;
26008 X      else mins = min(a_res.min0,aln->llcntx);
26009 X      aancpy(seqc0,(char *)aa0+a_res.min0-mins,mins,pst);
26010 X      aln->smin0 = a_res.min0-mins;
26011 X      if ((mins-a_res.min1)>0) {
26012 X       memset(seqc1,' ',mins-a_res.min1);
26013 X       aancpy(seqc1+mins-a_res.min1,(char *)aa1,a_res.min1,pst);
26014 X       aln->smin1 = 0;
26015 X      }
26016 X      else {
26017 X       aancpy(seqc1,(char *)aa1+a_res.min1-mins,mins,pst);
26018 X       aln->smin1 = a_res.min1-mins;
26019 X      }
26020 X    }
26021 X    else {
26022 X      smins=0;
26023 X      if (aln->showall == 1) mins=a_res.min1;
26024 X      else mins = min(a_res.min1,aln->llcntx);
26025 X      aancpy(seqc1,(char *)(aa1+a_res.min1-mins),mins,pst);
26026 X      aln->smin1 = a_res.min1-mins;
26027 X      if ((mins-a_res.min0)>0) {
26028 X       memset(seqc0,' ',mins-a_res.min0);
26029 X       aancpy(seqc0+mins-a_res.min0,(char *)aa0,a_res.min0,pst);
26030 X       aln->smin0 = 0;
26031 X      }
26032 X      else {
26033 X       aancpy(seqc0,(char *)aa0+a_res.min0-mins,mins,pst);
26034 X       aln->smin0 = a_res.min0-mins;
26035 X      }
26036 X    }
26037 X  else {
26038 X    mins= min(aln->llcntx,min(a_res.min0,a_res.min1));
26039 X    smins=mins;
26040 X    aln->smin0=a_res.min0;
26041 X    aln->smin1=a_res.min1;
26042 X    aancpy(seqc0,(char *)aa0+a_res.min0-mins,mins,pst);
26043 X    aancpy(seqc1,(char *)aa1+a_res.min1-mins,mins,pst);
26044 X  }
26045 #else
26046 X  aln->smin0 = a_res.min0;
26047 X  aln->smin1 = a_res.min1;
26048 X  smins = mins = 0;
26049 #endif
26050 X
26051 /* now get the middle */
26052 X
26053 X  memset(seqca,M_BLANK,mins);
26054 X  memset(seqc0a,' ',mins);
26055 X
26056 X  spa = seqca+mins;
26057 X  sp0 = seqc0+mins;
26058 X  sp0a = seqc0a+mins;
26059 X  sp1 = seqc1+mins;
26060 X  rp = a_res.res;
26061 X  lenc = aln->nident = aln->nsim = aln->ngap_q = aln->ngap_l = aln->nfs =op = 0;
26062 X  i0 = a_res.min0;
26063 X  i1 = a_res.min1;
26064 X  
26065 X  while (i0 < a_res.max0 || i1 < a_res.max1) {
26066 X    if (op == 0 && *rp == 0) {
26067 X      op = *rp++;
26068 X      lenc++;
26069 X      if ((itmp=f_str->pam2p[0][i0][aa1[i1]])<0) { *spa = M_NEG; }
26070 X      else if (itmp == 0) { *spa = M_ZERO;}
26071 X      else {*spa = M_POS;}
26072 X      if (*spa == M_POS || *spa==M_ZERO) aln->nsim++;
26073 X
26074 X      *sp0a++ = ann_arr[aa0a[i0]];
26075 X      *sp0 = sq[aa0[i0++]];
26076 X      *sp1 = sq[aa1[i1++]];
26077 X
26078 X      if (toupper(*sp0) == toupper(*sp1)) {aln->nident++; *spa = M_IDENT;}
26079 X      else if (pst.dnaseq==1 && ((*sp0 == 'T' && *sp1 == 'U') ||
26080 X                                (*sp0=='U' && *sp1=='T'))) {
26081 X       aln->nident++; *spa=M_IDENT;
26082 X      }
26083 X
26084 X      sp0++; sp1++; spa++;
26085 X    }
26086 X    else {
26087 X      if (op==0) op = *rp++;
26088 X      if (op>0) {
26089 X       *sp0++ = '-';
26090 X       *sp0a++ = ' ';
26091 X       *sp1++ = sq[aa1[i1++]];
26092 X       *spa++ = M_DEL;
26093 X       op--;
26094 X       lenc++;
26095 X       aln->ngap_q++;
26096 X      }
26097 X      else {
26098 X       *sp0a++ = ann_arr[aa0a[i0]];
26099 X       *sp0++ = sq[aa0[i0++]];
26100 X       *sp1++ = '-';
26101 X       *spa++ = M_DEL;
26102 X       op++;
26103 X       lenc++;
26104 X       aln->ngap_l++;
26105 X      }
26106 X    }
26107 X  }
26108 X
26109 X  *nc = lenc;
26110 X  *spa = '\0';
26111 /*      now we have the middle, get the right end */
26112 X
26113 #ifndef LFASTA
26114 X  /* how much extra to show at end ? */
26115 X  if (!aln->llcntx_flg) {
26116 X    ns = mins + lenc + aln->llen;      /* show an extra line? */
26117 X    ns -= (itmp = ns %aln->llen);      /* itmp = left over on last line */
26118 X    if (itmp>aln->llen/2) ns += aln->llen;  /* more than 1/2 , use another*/
26119 X    nd = ns - (mins+lenc);             /* this much extra */
26120 X  }
26121 X  else nd = aln->llcntx;
26122 X
26123 X  if (nd > max(n0-a_res.max0,n1-a_res.max1))
26124 X    nd = max(n0-a_res.max0,n1-a_res.max1);
26125 X  
26126 X  if (aln->showall==1) {
26127 X    nd = max(n0-a_res.max0,n1-a_res.max1);     /* reset for showall=1 */
26128 X    /* get right end */
26129 X    aancpy(seqc0+mins+lenc,(char *)aa0+a_res.max0,n0-a_res.max0,pst);
26130 X    aancpy(seqc1+mins+lenc,(char *)aa1+a_res.max1,n1-a_res.max1,pst);
26131 X    /* fill with blanks - this is required to use one 'nc' */
26132 X    memset(seqc0+mins+lenc+n0-a_res.max0,' ',nd-(n0-a_res.max0));
26133 X    memset(seqc1+mins+lenc+n1-a_res.max1,' ',nd-(n1-a_res.max1));
26134 X  }
26135 X  else {
26136 X     if ((nd-(n0-a_res.max0))>0) {
26137 X       aancpy(seqc0+mins+lenc,(char *)aa0+a_res.max0,n0-a_res.max0,pst);
26138 X       memset(seqc0+mins+lenc+n0-a_res.max0,' ',nd-(n0-a_res.max0));
26139 X     }
26140 X     else aancpy(seqc0+mins+lenc,(char *)aa0+a_res.max0,nd,pst);
26141 X
26142 X     if ((nd-(n1-a_res.max1))>0) {
26143 X       aancpy(seqc1+mins+lenc,(char *)aa1+a_res.max1,n1-a_res.max1,pst);
26144 X       memset(seqc1+mins+lenc+n1-a_res.max1,' ',nd-(n1-a_res.max1));
26145 X     }
26146 X     else aancpy(seqc1+mins+lenc,(char *)aa1+a_res.max1,nd,pst);
26147 X }
26148 X  
26149 #else   /* LFASTA */
26150 X  nd = 0;
26151 #endif
26152 X  /* #undef LFASTA */
26153 X  return mins+lenc+nd;
26154 }
26155 X
26156 static void
26157 update_code(char *al_str, int al_str_max, int op, int op_cnt);
26158 X
26159 /* build an array of match/ins/del - length strings */
26160 int calc_code(const unsigned char *aa0, const int n0,
26161 X             const unsigned char *aa1, const int n1,
26162 X             struct a_struct *aln,
26163 X             struct a_res_str a_res,
26164 X             struct pstruct pst,
26165 X             char *al_str, int al_str_n, struct f_struct *f_str)
26166 {
26167 X  int i0, i1, nn1;
26168 X  int op, lenc, nd, ns, itmp;
26169 X  int p_op, op_cnt;
26170 X  const unsigned char *aa1p;
26171 X  char tmp_cnt[20];
26172 X  char sp0, sp1, *sq;
26173 X  int *rp;
26174 X  int mins, smins;
26175 X
26176 X  if (pst.ext_sq_set) {
26177 X    sq = pst.sqx;
26178 X  }
26179 X  else {
26180 X    sq = pst.sq;
26181 X  }
26182 X
26183 #ifndef TFASTA
26184 X  aa1p = aa1;
26185 X  nn1 = n1;
26186 #else
26187 X  aa1p = f_str->aa1x;
26188 X  nn1 = f_str->n10;
26189 #endif
26190 X
26191 X  aln->amin0 = a_res.min0;
26192 X  aln->amax0 = a_res.max0;
26193 X  aln->amin1 = a_res.min1;
26194 X  aln->amax1 = a_res.max1;
26195 X
26196 X  rp = a_res.res;
26197 X  lenc = aln->nident = aln->nsim = aln->ngap_q = aln->ngap_l = aln->nfs = op = p_op = 0;
26198 X  op_cnt = 0;
26199 X
26200 X  i0 = a_res.min0;
26201 X  i1 = a_res.min1;
26202 X  tmp_cnt[0]='\0';
26203 X  
26204 X  while (i0 < a_res.max0 || i1 < a_res.max1) {
26205 X    if (op == 0 && *rp == 0) {
26206 X
26207 X      if (pst.pam2[0][aa0[i0]][aa1p[i1]]>=0) { aln->nsim++;}
26208 X
26209 X      sp0 = sq[aa0[i0++]];
26210 X      sp1 = sq[aa1p[i1++]];
26211 X
26212 X      if (p_op == 0 || p_op==3) {
26213 X       if (sp0 != '*' && sp1 != '*') {
26214 X         if (p_op == 3) {
26215 X           update_code(al_str,al_str_n-strlen(al_str),p_op,op_cnt);
26216 X           op_cnt = 1; p_op = 0;
26217 X         }
26218 X         else {op_cnt++;}
26219 X       }
26220 X       else {
26221 X         update_code(al_str,al_str_n-strlen(al_str),p_op,op_cnt);
26222 X         op_cnt = 1; p_op = 3;
26223 X       }
26224 X      }
26225 X      else {
26226 X       update_code(al_str,al_str_n-strlen(al_str),p_op,op_cnt);
26227 X       op_cnt = 1; p_op = 0;
26228 X      }
26229 X
26230 X      op = *rp++;
26231 X      lenc++;
26232 X
26233 X      if (toupper(sp0) == toupper(sp1)) aln->nident++;
26234 X      else if (pst.dnaseq==1) {
26235 X       if ((toupper(sp0) == 'T' && toupper(sp1) == 'U') ||
26236 X           (toupper(sp0)=='U' && toupper(sp1)=='T')) aln->nident++;
26237 X       else if (toupper(sp0) == 'N') aln->ngap_q++;
26238 X       else if (toupper(sp1) == 'N') aln->ngap_l++;
26239 X      }
26240 X    }
26241 X    else {
26242 X      if (op==0) op = *rp++;
26243 X      if (op>0) {
26244 X       if (p_op == 1) { op_cnt++;}
26245 X       else {
26246 X         update_code(al_str,al_str_n - strlen(al_str),p_op,op_cnt);
26247 X         op_cnt = 1; p_op = 1;
26248 X       }
26249 X       op--; lenc++; i1++; aln->ngap_q++;
26250 X      }
26251 X      else {
26252 X       if (p_op == 2) { op_cnt++;}
26253 X       else {
26254 X         update_code(al_str,al_str_n - strlen(al_str),p_op,op_cnt);
26255 X         op_cnt = 1; p_op = 2;
26256 X       }
26257 X       op++; lenc++; i0++; aln->ngap_l++;
26258 X      }
26259 X    }
26260 X  }
26261 X  update_code(al_str,al_str_n - strlen(al_str),p_op,op_cnt);
26262 X
26263 X  return lenc;
26264 }
26265 X
26266 static void
26267 update_code(char *al_str, int al_str_max, int op, int op_cnt) {
26268 X
26269 X  char op_char[5]={"=-+*"};
26270 X  char tmp_cnt[20];
26271 X
26272 X  sprintf(tmp_cnt,"%c%d",op_char[op],op_cnt);
26273 X  strncat(al_str,tmp_cnt,al_str_max);
26274 }
26275 X
26276 int calc_id(const unsigned char *aa0, const int n0,
26277 X           const unsigned char *aa1, const int n1,
26278 X           struct a_struct *aln,
26279 X           struct a_res_str a_res,
26280 X           struct pstruct pst,
26281 X           struct f_struct *f_str)
26282 {
26283 X  int i0, i1, nn1, n_id;
26284 X  int op, lenc, nd, ns, itmp;
26285 X  int sp0, sp1;
26286 X  const unsigned char *aa1p;
26287 X  int *rp;
26288 X  char *sq;
26289 X  
26290 X  if (pst.ext_sq_set) {
26291 X    sq = pst.sqx;
26292 X  }
26293 X  else {
26294 X    sq = pst.sq;
26295 X  }
26296 X
26297 #ifndef TFASTA
26298 X  aa1p = aa1;
26299 X  nn1 = n1;
26300 #else
26301 X  aa1p = f_str->aa1x;
26302 X  nn1 = f_str->n10;
26303 #endif
26304 X
26305 X  rp = a_res.res;
26306 X  lenc = n_id = aln->nsim = aln->ngap_q = aln->ngap_l = aln->nfs = op = 0;
26307 X  i0 = a_res.min0;
26308 X  i1 = a_res.min1;
26309 X
26310 X  while (i0 < a_res.max0 || i1 < a_res.max1) {
26311 X    if (op == 0 && *rp == 0) {
26312 X      op = *rp++;
26313 X      lenc++;
26314 X      if (pst.pam2[0][aa0[i0]][aa1p[i1]]>=0) { aln->nsim++;}
26315 X
26316 X      sp0 = sq[aa0[i0++]];
26317 X      sp1 = sq[aa1p[i1++]];
26318 X      if (toupper(sp0) == toupper(sp1)) n_id++;
26319 X      else if (pst.dnaseq==1 &&
26320 X              ((sp0=='T' && sp1== 'U')||(sp0=='U' && sp1=='T'))) n_id++;
26321 X    }
26322 X    else {
26323 X      if (op==0) op = *rp++;
26324 X      if (op>0) {op--; lenc++; i1++; aln->ngap_q++; }
26325 X      else {op++; lenc++; i0++;        aln->ngap_l++; }
26326 X    }
26327 X  }
26328 X  aln->nident = n_id;
26329 X  return lenc;
26330 }
26331 X
26332 #ifdef PCOMPLIB
26333 #include "p_mw.h"
26334 void
26335 update_params(struct qmng_str *qm_msg, struct pstruct *ppst)
26336 {
26337 X  ppst->n0 = qm_msg->n0;
26338 }
26339 #endif
26340 SHAR_EOF
26341 chmod 0644 dropnsw.c ||
26342 echo 'restore of dropnsw.c failed'
26343 Wc_c="`wc -c < 'dropnsw.c'`"
26344 test 34172 -eq "$Wc_c" ||
26345         echo 'dropnsw.c: original size 34172, current size' "$Wc_c"
26346 fi
26347 # ============= egmsmg.aa ==============
26348 if test -f 'egmsmg.aa' -a X"$1" != X"-c"; then
26349         echo 'x - skipping egmsmg.aa (File already exists)'
26350 else
26351 echo 'x - extracting egmsmg.aa (Text)'
26352 sed 's/^X//' << 'SHAR_EOF' > 'egmsmg.aa' &&
26353 >EGMSMG Epidermal growth factor precursor - Mouse
26354 MPWGRRPTWLLLAFLLVFLKISILSVTAWQTGNCQPGPLERSERSGTCAGPAPFLVFSQGKSISRIDPDG
26355 TNHQQLVVDAGISADMDIHYKKERLYWVDVERQVLLRVFLNGTGLEKVCNVERKVSGLAIDWIDDEVLWV
26356 DQQNGVITVTDMTGKNSRVLLSSLKHPSNIAVDPIERLMFWSSEVTGSLHRAHLKGVDVKTLLETGGISV
26357 LTLDVLDKRLFWVQDSGEGSHAYIHSCDYEGGSVRLIRHQARHSLSSMAFFGDRIFYSVLKSKAIWIANK
26358 HTGKDTVRINLHPSFVTPGKLMVVHPRAQPRTEDAAKDPDPELLKQRGRPCRFGLCERDPKSHSSACAEG
26359 YTLSRDRKYCEDVNECATQNHGCTLGCENTPGSYHCTCPTGFVLLPDGKQCHELVS
26360 CPGNVSKCSHGCVLTSDGPRCICPAGSVLGRDGKTCTGCSSPDNGGCSQICLPLRPGSWECDCFPGYDLQ
26361 SDRKSCAASGPQPLLLFANSQDIRHMHFDGTDYKVLLSRQMGMVFALDYDPVESKIYFAQTALKWIERAN
26362 MDGSQRERLITEGVDTLEGLALDWIGRRIYWTDSGKSVVGGSDLSGKHHRIIIQERISRPRGIAVHPRAR
26363 RLFWTDVGMSPRIESASLQGSDRVLIASSNLLEPSGITIDYLTDTLYWCDTKRSVIEMANLDGSKRRRLI
26364 QNDVGHPFSLAVFEDHLWVSDWAIPSVIRVNKRTGQNRVRLQGSMLKPSSLVVVHPLAKPGADPCLYRNG
26365 GCEHICQESLGTARCLCREGFVKAWDGKMCLPQDYPILSGENADLSKEVTSLSNST
26366 QAEVPDDDGTESSTLVAEIMVSGMNYEDDCGPGGCGSHARCVSDGETAECQCLKGFARDGNLCSDIDECV
26367 LARSDCPSTSSRCINTEGGYVCRCSEGYEGDGISCFDIDECQRGAHNCAENAACTNTEGGYNCTCAGRPS
26368 SPGRSCPDSTAPSLLGEDGHHLDRNSYPGCPSSYDGYCLNGGVCMHIESLDSYTCNCVIGYSGDRCQTRD
26369 LRWWELRHAGYGQKHDIMVVAVCMVALVLLLLLGMWGTYYYRTRKQLSNPPKNPCDEPSGSVSSSGPDSS
26370 SGAAVASCPQPWFVVLEKHQDPKNGSLPADGTNGAVVDAGLSPSLQLGSVHLTSWRQKPHIDGMGTGQSC
26371 WIPPSSDRGPQEIEGNSHLPSYRPVGPEKLHSLQSANGSCHERAPDLPRQTEPVK 
26372 SHAR_EOF
26373 chmod 0644 egmsmg.aa ||
26374 echo 'restore of egmsmg.aa failed'
26375 Wc_c="`wc -c < 'egmsmg.aa'`"
26376 test 1286 -eq "$Wc_c" ||
26377         echo 'egmsmg.aa: original size 1286, current size' "$Wc_c"
26378 fi
26379 # ============= faatran.c ==============
26380 if test -f 'faatran.c' -a X"$1" != X"-c"; then
26381         echo 'x - skipping faatran.c (File already exists)'
26382 else
26383 echo 'x - extracting faatran.c (Text)'
26384 sed 's/^X//' << 'SHAR_EOF' > 'faatran.c' &&
26385 X
26386 /* copyright (c) 1996, 1997, 1998, 1999 William R. Pearson and the
26387 X   U. of Virginia */
26388 X
26389 /* $Name: fa_34_26_5 $ - $Id: faatran.c,v 1.6 2007/04/02 18:08:11 wrp Exp $ */
26390 X
26391 /*      aatran.c        translates from nt to aa, 1 char codes */
26392 /*      modified July 2, 1987 for all 6 frames */
26393 /*      23 Jan 1991     fixed bug for short sequences */
26394 X
26395 /*      this mapping is not alphabet independent */
26396 X
26397 #define XTERNAL
26398 #include <stdio.h>
26399 #include <stdlib.h>
26400 X
26401 #include "upam.h"
26402 #include "uascii.h"
26403 X
26404 /*
26405 1. The Standard Code (transl_table=1)
26406 X
26407 By default all transl_table in GenBank flatfiles are equal to id 1, and this
26408 is not shown. When transl_table is not equal to id 1, it is shown as a
26409 qualifier on the CDS feature.
26410 X
26411 */
26412 static
26413 char *AA1="FFLLSSSSYY**CC*WLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG";
26414 /*
26415 X  Starts = ---M---------------M---------------M----------------------------
26416 X  Base1  = TTTTTTTTTTTTTTTTCCCCCCCCCCCCCCCCAAAAAAAAAAAAAAAAGGGGGGGGGGGGGGGG
26417 X  Base2  = TTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGG
26418 X  Base3  = TCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAG
26419 X
26420 2. The Vertebrate Mitochondrial Code (transl_table=2)
26421 */
26422 static
26423 char *AA2 ="FFLLSSSSYY**CCWWLLLLPPPPHHQQRRRRIIMMTTTTNNKKSS**VVVVAAAADDEEGGGG";
26424 /*
26425 X  Starts = --------------------------------MMMM---------------M------------
26426 X  Base1  = TTTTTTTTTTTTTTTTCCCCCCCCCCCCCCCCAAAAAAAAAAAAAAAAGGGGGGGGGGGGGGGG
26427 X  Base2  = TTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGG
26428 X  Base3  = TCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAG
26429 X
26430 3. The Yeast Mitochondrial Code (transl_table=3)
26431 */
26432 static
26433 char *AA3 ="FFLLSSSSYY**CCWWTTTTPPPPHHQQRRRRIIMMTTTTNNKKSSRRVVVVAAAADDEEGGGG";
26434 /*
26435 X  Starts = -----------------------------------M----------------------------
26436 X  Base1  = TTTTTTTTTTTTTTTTCCCCCCCCCCCCCCCCAAAAAAAAAAAAAAAAGGGGGGGGGGGGGGGG
26437 X  Base2  = TTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGG
26438 X  Base3  = TCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAG
26439 X
26440 4. The Mold, Protozoan, and Coelenterate Mitochondrial Code and the
26441 Mycoplasma/Spiroplasma Code (transl_table=4)
26442 */
26443 static
26444 char *AA4 ="FFLLSSSSYY**CCWWLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG";
26445 /*
26446 X  Starts = --MM---------------M------------MMMM---------------M------------
26447 X  Base1  = TTTTTTTTTTTTTTTTCCCCCCCCCCCCCCCCAAAAAAAAAAAAAAAAGGGGGGGGGGGGGGGG
26448 X  Base2  = TTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGG
26449 X  Base3  = TCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAG
26450 X
26451 5. The Invertebrate Mitochondrial Code (transl_table=5)
26452 */
26453 static
26454 char *AA5 ="FFLLSSSSYY**CCWWLLLLPPPPHHQQRRRRIIMMTTTTNNKKSSSSVVVVAAAADDEEGGGG";
26455 /*
26456 X  Starts = ---M----------------------------MMMM---------------M------------
26457 X  Base1  = TTTTTTTTTTTTTTTTCCCCCCCCCCCCCCCCAAAAAAAAAAAAAAAAGGGGGGGGGGGGGGGG
26458 X  Base2  = TTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGG
26459 X  Base3  = TCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAG
26460 X
26461 6. The Ciliate, Dasycladacean and Hexamita Nuclear Code (transl_table=6)
26462 */
26463 static
26464 char *AA6 ="FFLLSSSSYYQQCC*WLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG";
26465 /*
26466 X  Starts = -----------------------------------M----------------------------
26467 X  Base1  = TTTTTTTTTTTTTTTTCCCCCCCCCCCCCCCCAAAAAAAAAAAAAAAAGGGGGGGGGGGGGGGG
26468 X  Base2  = TTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGG
26469 X  Base3  = TCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAG
26470 X
26471 9. The Echinoderm Mitochondrial Code (transl_table=9)
26472 */
26473 static
26474 char *AA7 ="FFLLSSSSYY**CCWWLLLLPPPPHHQQRRRRIIIMTTTTNNNKSSSSVVVVAAAADDEEGGGG";
26475 /*
26476 X  Starts = -----------------------------------M----------------------------
26477 X  Base1  = TTTTTTTTTTTTTTTTCCCCCCCCCCCCCCCCAAAAAAAAAAAAAAAAGGGGGGGGGGGGGGGG
26478 X  Base2  = TTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGG
26479 X  Base3  = TCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAG
26480 X
26481 10. The Euplotid Nuclear Code (transl_table=10)
26482 */
26483 static
26484 char *AA10="FFLLSSSSYY**CCCWLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG";
26485 /*
26486 X  Starts = -----------------------------------M----------------------------
26487 X  Base1  = TTTTTTTTTTTTTTTTCCCCCCCCCCCCCCCCAAAAAAAAAAAAAAAAGGGGGGGGGGGGGGGG
26488 X  Base2  = TTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGG
26489 X  Base3  = TCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAG
26490 X
26491 11. The Bacterial "Code" (transl_table=11)
26492 */
26493 static
26494 char *AA11="FFLLSSSSYY**CC*WLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG";
26495 /*
26496 X  Starts = ---M---------------M------------MMMM---------------M------------
26497 X  Base1  = TTTTTTTTTTTTTTTTCCCCCCCCCCCCCCCCAAAAAAAAAAAAAAAAGGGGGGGGGGGGGGGG
26498 X  Base2  = TTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGG
26499 X  Base3  = TCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAG
26500 X
26501 12. The Alternative Yeast Nuclear Code (transl_table=12)
26502 */
26503 static
26504 char *AA12 ="FFLLSSSSYY**CC*WLLLSPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG";
26505 /*
26506 X  Starts = -------------------M---------------M----------------------------
26507 X  Base1  = TTTTTTTTTTTTTTTTCCCCCCCCCCCCCCCCAAAAAAAAAAAAAAAAGGGGGGGGGGGGGGGG
26508 X  Base2  = TTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGG
26509 X  Base3  = TCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAG
26510 X
26511 13. The Ascidian Mitochondrial Code (transl_table=13)
26512 */
26513 static
26514 char *AA13="FFLLSSSSYY**CCWWLLLLPPPPHHQQRRRRIIMMTTTTNNKKSSGGVVVVAAAADDEEGGGG";
26515 /*
26516 X  Starts = -----------------------------------M----------------------------
26517 X  Base1  = TTTTTTTTTTTTTTTTCCCCCCCCCCCCCCCCAAAAAAAAAAAAAAAAGGGGGGGGGGGGGGGG
26518 X  Base2  = TTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGG
26519 X  Base3  = TCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAG
26520 X
26521 14. The Flatworm Mitochondrial Code (transl_table=14)
26522 */
26523 static
26524 char *AA14 ="FFLLSSSSYYY*CCWWLLLLPPPPHHQQRRRRIIIMTTTTNNNKSSSSVVVVAAAADDEEGGGG";
26525 /*
26526 X  Starts = -----------------------------------M----------------------------
26527 X  Base1  = TTTTTTTTTTTTTTTTCCCCCCCCCCCCCCCCAAAAAAAAAAAAAAAAGGGGGGGGGGGGGGGG
26528 X  Base2  = TTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGG
26529 X  Base3  = TCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAG
26530 X
26531 15. Blepharisma Nuclear Code (transl_table=15)
26532 */
26533 static
26534 char *AA15="FFLLSSSSYY*QCC*WLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG";
26535 /*
26536 X  Starts = -----------------------------------M----------------------------
26537 X  Base1  = TTTTTTTTTTTTTTTTCCCCCCCCCCCCCCCCAAAAAAAAAAAAAAAAGGGGGGGGGGGGGGGG
26538 X  Base2  = TTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGG
26539 X  Base3  = TCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAG
26540 */
26541 X
26542 static
26543 char *AA16 ="FFLLSSSSYY*LCC*WLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG";
26544 /* 
26545 X  id 16 ,
26546 X  name "Chlorophycean Mitochondrial" ,
26547 X  sncbieaa "-----------------------------------M----------------------------"
26548 X  -- Base1  TTTTTTTTTTTTTTTTCCCCCCCCCCCCCCCCAAAAAAAAAAAAAAAAGGGGGGGGGGGGGGGG
26549 X  -- Base2  TTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGG
26550 X  -- Base3  TCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAG
26551 */
26552 X
26553 static
26554 char *AA21 ="FFLLSSSSYY**CCWWLLLLPPPPHHQQRRRRIIMMTTTTNNNKSSSSVVVVAAAADDEEGGGG";
26555 /*
26556 X  name "Trematode Mitochondrial" ,
26557 X  id 21 ,
26558 X  sncbieaa "-----------------------------------M---------------M------------"
26559 X  -- Base1  TTTTTTTTTTTTTTTTCCCCCCCCCCCCCCCCAAAAAAAAAAAAAAAAGGGGGGGGGGGGGGGG
26560 X  -- Base2  TTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGG
26561 X  -- Base3  TCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAG
26562 */
26563 X
26564 static
26565 char *AA22 ="FFLLSS*SYY*LCC*WLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG";
26566 /*
26567 X  name "Scenedesmus obliquus Mitochondrial" ,
26568 X  id 22 ,
26569 X  sncbieaa "-----------------------------------M----------------------------"
26570 X  -- Base1  TTTTTTTTTTTTTTTTCCCCCCCCCCCCCCCCAAAAAAAAAAAAAAAAGGGGGGGGGGGGGGGG
26571 X  -- Base2  TTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGG
26572 X  -- Base3  TCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAG
26573 */
26574 X
26575 static
26576 char *AA23 ="FF*LSSSSYY**CC*WLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG";
26577 /*
26578 X  name "Thraustochytrium Mitochondrial" ,
26579 X  id 23 ,
26580 X  sncbieaa "--------------------------------M--M---------------M------------"
26581 X  -- Base1  TTTTTTTTTTTTTTTTCCCCCCCCCCCCCCCCAAAAAAAAAAAAAAAAGGGGGGGGGGGGGGGG
26582 X  -- Base2  TTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGG
26583 X  -- Base3  TCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAG
26584 */
26585 X
26586 X
26587 static char aacmap[64]={
26588 X  'K','N','K','N','T','T','T','T','R','S','R','S','I','I','M','I',
26589 X  'Q','H','Q','H','P','P','P','P','R','R','R','R','L','L','L','L',
26590 X  'E','D','E','D','A','A','A','A','G','G','G','G','V','V','V','V',
26591 X  '*','Y','*','Y','S','S','S','S','*','C','W','C','L','F','L','F'
26592 };
26593 X
26594 static int aamap[64];   /* integer aa values */
26595 static int aamapr[64]; /* reverse sequence map */
26596 X
26597 /* tnt is used only by aatran.c. It must be consistent with lascii and
26598 the nt alphabet. It uses 3,3 because T and U are considered separately
26599 */
26600 static int tnt[]={0,0,1,2,3,3,0,1,0,0,1,2,0,0,0,1,0,0,
26601 X                   0,1,2,3,3,0,1,0,0,1,2,0,0,0,1,0,0};
26602 X
26603 static int debug_set;
26604 X
26605 int
26606 aatran(const unsigned char *ntseq, unsigned char *aaseq, int maxs, int frame)
26607 {
26608 X  int iaa, im, nna, i;
26609 X  register int *nnp;
26610 X  const unsigned char *nts0;
26611 X  register int *aamp;
26612 X  register unsigned char *aap;
26613 X
26614 X  iaa=nna=(maxs-(frame<3?frame:frame-3))/3;
26615 X  if (nna <= 3 ) {
26616 X    aaseq[0]=EOSEQ;
26617 X    return 0;
26618 X  }
26619 X
26620 X  nnp = tnt;
26621 X
26622 X  if (frame < 3) {
26623 X    aamp = aamap;
26624 X    nts0 = &ntseq[frame];
26625 X    aap = aaseq;
26626 X    while (nna--) {
26627 X      im = nnp[*nts0++]<<4;
26628 X      im += nnp[*nts0++]<<2;
26629 X      im += nnp[*nts0++];
26630 X      *aap++ = aamp[im];
26631 X
26632 X      /* this check is included because of a bug in tfasty 
26633 X         which occurs only during the alignment process */
26634 X
26635 #ifdef DEBUG
26636 X      if (debug_set && aamp[im] > MAXUC) {
26637 X       fprintf(stderr,"faatran: %d %d %d %d %d?%d\n",
26638 X               *(nts0-3),*(nts0-2),*(nts0-1), im, aamp[im],aamap[im]);
26639 X
26640 X       /* this allows recovery, but should not be done frequently */
26641 X       for (i=0; i<64; i++) {
26642 X         aamap[i]=aascii[aacmap[i]];
26643 X         aamapr[i]=aascii[aacmap[(~i)&63]];
26644 X       }
26645 X       *(aap-1) = aamp[im];
26646 X      }
26647 #endif
26648 X    }
26649 X  }
26650 X  else {
26651 X    aamp = aamapr;
26652 X    nts0 = &ntseq[maxs-(frame-3)];
26653 X    aap = aaseq;
26654 X    while (nna--) {
26655 X      im = nnp[*--nts0]<<4;
26656 X      im += nnp[*--nts0]<<2;
26657 X      im += nnp[*--nts0];
26658 X      *aap++ = aamp[im];
26659 X      /* this check is included because of a bug in tfasty 
26660 X         which occurs only during the alignment process */
26661 X
26662 #ifdef DEBUG
26663 X      if (debug_set && aamp[im] > MAXUC) {
26664 X       fprintf(stderr,"faatran: %d %d %d %d %d?%d\n",
26665 X               *(nts0-3),*(nts0-2),*(nts0-1), im, aamp[im],aamap[im]);
26666 X
26667 X       /* this allows recovery, but should not be done frequently */
26668 X       for (i=0; i<64; i++) {
26669 X         aamap[i]=aascii[aacmap[i]];
26670 X         aamapr[i]=aascii[aacmap[(~i)&63]];
26671 X       }
26672 X       *(aap-1) = aamp[im];
26673 X      }
26674 #endif
26675 X    }
26676 X  }
26677 X  aaseq[iaa]=EOSEQ;
26678 X  return iaa;
26679 }
26680 X
26681 /* slower version that masks out NNN,XXX */
26682 X
26683 /*                - A C G T U R Y M W S K D H V B N X */
26684 static int snt[]={0,0,1,2,3,3,0,1,0,0,4,4,4,4,4,4,4,4};
26685 X
26686 int
26687 saatran(const unsigned char *ntseq,
26688 X       unsigned char *aaseq, int maxs, int frame)
26689 {
26690 X  int iaa, im, it, nna, xflag;
26691 X  register int *nnp;
26692 X  const unsigned char *nts0;
26693 X  register int *aamp;
26694 X  register unsigned char *aap;
26695 X
26696 X  iaa=nna=(maxs-(frame<3?frame:frame-3))/3;
26697 X  if (nna <= 3 ) {
26698 X    aaseq[0]=EOSEQ;
26699 X    return 0;
26700 X  }
26701 X
26702 X  nnp = snt;
26703 X  if (frame < 3) {
26704 X    aamp = aamap;
26705 X    nts0 = &ntseq[frame];
26706 X    aap = aaseq;
26707 X    while (nna--) {
26708 X      xflag = 0;
26709 X      if ((it=nnp[*nts0++])<4) {im = it<<4;}
26710 X      else {xflag = 1; im=0;}
26711 X      if ((it=nnp[*nts0++])<4) {im += it<<2;}
26712 X      else xflag = 1;
26713 X      if ((it=nnp[*nts0++])<4) {im += it;}
26714 X      else xflag = 1;
26715 X      if (xflag) *aap++ = aascii['X'];
26716 X      else *aap++ = aamp[im];
26717 X    }
26718 X  }
26719 X  else {
26720 X    aamp = aamapr;
26721 X    nts0 = &ntseq[maxs-(frame-3)];
26722 X    aap = aaseq;
26723 X    while (nna--) {
26724 X      xflag = 0;
26725 X      if ((it=nnp[*--nts0]) < 4) im = it<<4;
26726 X      else {xflag = 1; im=0;}
26727 X      if ((it=nnp[*--nts0]) < 4) im += it<<2;
26728 X      else xflag = 1;
26729 X      if ((it=nnp[*--nts0]) < 4) im += it;
26730 X      else xflag = 1;
26731 X      if (xflag) *aap++ = aascii['X'];
26732 X      else *aap++ = aamp[im];
26733 X    }
26734 X  }
26735 X  aaseq[iaa]=EOSEQ;
26736 X  return iaa;
26737 }
26738 X
26739 void
26740 aainit(int tr_type, int debug)
26741 {
26742 X  int i,j;
26743 X  char *aasmap;
26744 X  int imap[4]={3,1,0,2}, i0, i1, i2, ii;
26745 X
26746 X  debug_set = debug;
26747 X
26748 X  aasmap = AA1;
26749 X  if (tr_type > 0) {
26750 X    /* need to put in a new translation table */
26751 X    switch (tr_type) {
26752 X    case 1: aasmap = AA1; break;
26753 X    case 2: aasmap = AA2; break;
26754 X    case 3: aasmap = AA3; break;
26755 X    case 4: aasmap = AA4; break;
26756 X    case 5: aasmap = AA5; break;
26757 X    case 6: aasmap = AA6; break;
26758 X    case 7: aasmap = AA7; break;
26759 X    case 10: aasmap = AA10; break;
26760 X    case 11: aasmap = AA11; break;
26761 X    case 12: aasmap = AA12; break;
26762 X    case 13: aasmap = AA13; break;
26763 X    case 14: aasmap = AA14; break;
26764 X    case 15: aasmap = AA15; break;
26765 X    case 16: aasmap = AA16; break;
26766 X    case 21: aasmap = AA21; break;
26767 X    case 22: aasmap = AA22; break;
26768 X    case 23: aasmap = AA23; break;
26769 X
26770 X    default: aasmap = AA1; break;
26771 X    }
26772 X
26773 X    if (debug) fprintf(stderr," codon table: %d\n     new old\n",tr_type);
26774 X    for (i0 = 0; i0 < 4; i0++)
26775 X      for (i1 = 0; i1 < 4; i1++)
26776 X       for (i2 = 0; i2 < 4; i2++) {
26777 X         ii = (imap[i0]<<4) + (imap[i1]<<2) + imap[i2];
26778 X         if (debug &&  aacmap[ii] != *aasmap)
26779 X           fprintf(stderr," %c%c%c: %c - %c\n",
26780 X                   nt[imap[i0]+1],nt[imap[i1]+1],nt[imap[i2]+1],
26781 X                   *aasmap,aacmap[ii]);
26782 X         aacmap[ii]= *aasmap++;
26783 X       }
26784 X
26785 X    /*
26786 X    for (i=0; i<64; i++) {
26787 X      fprintf(stderr,"'%c',",aacmap[i]);
26788 X      if ((i%16)==15) fputc('\n',stderr);
26789 X    }
26790 X    fputc('\n',stderr);
26791 X    */
26792 X  }
26793 X  for (i=0; i<64; i++) {
26794 X    aamap[i]=aascii[aacmap[i]];
26795 X    aamapr[i]=aascii[aacmap[(~i)&63]];
26796 X  }
26797 }
26798 X
26799 void
26800 aagetmap(char *to, int n) 
26801 {
26802 X  int i;
26803 X  for (i=0; i<n; i++) to[i] = aacmap[i];
26804 }
26805 SHAR_EOF
26806 chmod 0644 faatran.c ||
26807 echo 'restore of faatran.c failed'
26808 Wc_c="`wc -c < 'faatran.c'`"
26809 test 13742 -eq "$Wc_c" ||
26810         echo 'faatran.c: original size 13742, current size' "$Wc_c"
26811 fi
26812 # ============= fast_new ==============
26813 if test -f 'fast_new' -a X"$1" != X"-c"; then
26814         echo 'x - skipping fast_new (File already exists)'
26815 else
26816 echo 'x - extracting fast_new (Text)'
26817 sed 's/^X//' << 'SHAR_EOF' > 'fast_new' &&
26818 NBRF PIR1 Annotated Protein Database (rel 56)$0+pir1+/slib2/blast/pir1.lseg
26819 NBRF Protein database (complete)$0+nbrf+@/seqlib/lib/NBRF.nam
26820 NRL_3d structure database$0D/seqlib/lib/nrl_3d.seq 5
26821 NCBI/Blast non-redundant proteins$0+nr+/slib2/blast/nr.lseg
26822 NCBI/Blast Swissprot$0+sp+/slib2/blast/swissprot.lseg
26823 GENPEPT Translated Protein Database (rel 106.0)$0G/slib2/blast/genpept.fsa
26824 Swiss-Prot Release 34$0S/slib0/lib/swiss.seq 5
26825 Yeast proteins$0Y/slib0/genomes/yeast_nr.pep
26826 C. elegans blast server$0W/slib2/blast/C.elegans_blast.fa
26827 E. coli proteome$0E/slib0/genomes/ecoli.npep
26828 H. influenzae proteome$0I/slib0/genomes/hinf.npep
26829 H. pylori proteome$0L/slib0/genomes/hpyl.npep
26830 NCBI Entrez Human proteins$0H/slib2/blast/human.aa
26831 M. pneumococcus proteome$0M/slib0/genomes/mpneu.npep
26832 M. jannaschii proteome$0J/slib0/genomes/mjan.npep
26833 Synechosystis proteome$0C/slib0/genomes/synecho.npep
26834 GB108.0 Invertebrates$1I/seqlib2/gcggenbank/gb_in.seq 6
26835 GB108.0 Bacteria$1T@/slib0/lib/gb_ba.nam 6
26836 GB108.0 Primate$1P@/slib0/lib/gb_pri.nam
26837 GB108.0 Rodent$1R/seqlib2/gcggenbank/gb_ro.seq 6
26838 GB108.0 other Mammal$1M/seqlib2/gcggenbank/gb_om.seq 6
26839 GB108.0 verteBrates$1B/seqlib2/gcggenbank/gb_ov.seq 6
26840 GB108.0 Expressed Seq. Tags$1E@/slib0/lib/gb_est.nam
26841 GB108.0 High throughput genmomic$1h/seqlib2/gcggenbank/gb_htg.seq 6
26842 GB108.0 pLants$1L@/slib0/lib/gb_pl.nam 6
26843 GB108.0 genome Survey sequences$1S@/slib0/lib/gb_gss.nam 6
26844 GB108.0 Viral$1V/seqlib2/gcggenbank/gb_vi.seq 6
26845 GB108.0 Phage$1G/seqlib2/gcggenbank/gb_ph.seq 6
26846 GB108.0 Unannotated$1D/seqlib2/gcggenbank/gb_un.seq 6
26847 GB108.0 New$1u/seqlib2/gcggenbank/gb_new.seq 6
26848 GB108.0 All sequences (long)$1A@/slib0/lib/genbank.nam
26849 Yeast genome$1Y@/seqlib/yeast/yeast_chr.nam
26850 E. coli genome$1D/slib0/genomes/ecoli.gbk 1
26851 Blast Human ESTs$1F/slib2/blast/est_human
26852 TIGR Human Gene Index$1K/slib2/blast/HGI.nr.031898
26853 Blast Mouse ESTs$1C/slib2/blast/est_mouse
26854 TIGR Mouse Gene Index$1J/slib2/blast/MGI.nr.022498
26855 NCBI/BLAST NR DNA$1n/slib2/blast/nt
26856 SHAR_EOF
26857 chmod 0644 fast_new ||
26858 echo 'restore of fast_new failed'
26859 Wc_c="`wc -c < 'fast_new'`"
26860 test 1959 -eq "$Wc_c" ||
26861         echo 'fast_new: original size 1959, current size' "$Wc_c"
26862 fi
26863 # ============= fasta.defaults ==============
26864 if test -f 'fasta.defaults' -a X"$1" != X"-c"; then
26865         echo 'x - skipping fasta.defaults (File already exists)'
26866 else
26867 echo 'x - extracting fasta.defaults (Text)'
26868 sed 's/^X//' << 'SHAR_EOF' > 'fasta.defaults' &&
26869 #pgm    mol     matrix  g_open  g_ext   fr_shft e_cut   ktup
26870 #       -n/-p   -s      -e      -f      -h/-j   -E      argv[3]
26871 fasta   prot    bl50    -10     -2      -       10.0    2
26872 fasta   dna     +5/-4   -14     -4      -       2.0     6
26873 ssearch prot    bl50    -10     -2      -       10.0    -
26874 ssearch dna     +5/-4   -14     -4      -       2.0     -
26875 fastx   prot    BL50    -12     -2      -20     5.0     2
26876 fasty   prot    BL50    -12     -2      -20/-24 5.0     2
26877 tfastx  dna     BL50    -14     -2      -20     5.0     2
26878 tfasty  dna     BL50    -14     -2      -20/-24 5.0     2
26879 fasts   prot    MD20-MS -       -       -       5.0     -
26880 tfasts  prot    MD10-MS -       -       -       2.0     -
26881 fastf   prot    MD20    -       -       -       5.0     -
26882 tfastf  prot    MD10    -       -       -       2.0     -
26883 fastm   prot    MD20    -       -       -       5.0     -
26884 tfastm  prot    MD10    -       -       -       2.0     -
26885 SHAR_EOF
26886 chmod 0644 fasta.defaults ||
26887 echo 'restore of fasta.defaults failed'
26888 Wc_c="`wc -c < 'fasta.defaults'`"
26889 test 529 -eq "$Wc_c" ||
26890         echo 'fasta.defaults: original size 529, current size' "$Wc_c"
26891 fi
26892 # ============= fasta.options ==============
26893 if test -f 'fasta.options' -a X"$1" != X"-c"; then
26894         echo 'x - skipping fasta.options (File already exists)'
26895 else
26896 echo 'x - extracting fasta.options (Text)'
26897 sed 's/^X//' << 'SHAR_EOF' > 'fasta.options' &&
26898 doinit.c
26899 X  case 'a': m_msg->aln.showall = 1;
26900 X  case 'B': m_msg->z_bits = 0;
26901 X  case 'b': m_msg->mshow
26902 X  case 'C': m_msg->nmlen
26903 X  case 'd': m_msg->ashow);
26904 X  case 'D': ppst->debug_lib = 1;
26905 X  case 'E': m_msg->e_cut
26906 X  case 'F': m_msg->e_low
26907 X  case 'f': ppst->gdelval
26908 X  case 'g': ppst->ggapval
26909 X  case 'H':  m_msg->nohist = 1; break;
26910 X  case 'i':  m_msg->revcomp = 1; break;
26911 X  case 'I':  m_msg->self = 1; break;
26912 X  case 'J':  m_msg->ql_start, ql_stop
26913 X  case 'K':  max_buf_cnt (PCOMPLIB)
26914 X  case 'l':  m_msg->flstr
26915 X  case 'L':  m_msg->long_info = 1
26916 X  case 'M':  m_msg->n1_low,&m_msg->n1_high
26917 X  case 'm':  m_msg->markx
26918 X  case 'n':  m_msg->qdnaseq = 1
26919 X  case 'N':  m_msg->maxn
26920 X  case 'p':  m_msg->qdnaseq = 0;
26921 X  case 'O':  m_msg->outfile
26922 X  case 'q':
26923 X  case 'Q':  m_msg->quiet = 1;
26924 X  case 'r':  ppst->p_d_mat,&ppst->p_d_mis
26925 X  case 'R':  m_msg->dfile
26926 X  case 's':  standard_pam(smstr); ppst->pamoff=atoi(bp+1);
26927 X  case 'S':  ppst->ext_sq_set = 1;
26928 X  case 't':  ppst->tr_type
26929 X  case 'T':  PCOMPLIB: worker_1,worker_n
26930 X            _t: max_workers
26931 X  case 'v':  ppst->zs_win
26932 X  case 'w':  m_msg->aln.llen
26933 X  case 'W':  m_msg->aln.llcntx);
26934 X  case 'X':  m_msg->sq0off,&m_msg->sq1off
26935 X  case 'x':  ppst->pam_x
26936 X  case 'z':  ppst->zsflag
26937 X  case 'Z':  ppst->zdb_size
26938 X
26939 initfa.c
26940 X  case '1': ppst->param_u.fa.iniflag=1;
26941 X  case '3': m_msg->nframe = 3; /* TFASTA */
26942 X           m_msg->nframe = 1;  /* for TFASTXY */
26943 X           m_msg->qframe = 1;  /* for FASTA, FASTX */
26944 X  case 'A': ppst->sw_flag= 1;
26945 X  case 'c': ppst->param_u.fa.optcut
26946 X  case 'h': ppst->gshift
26947 X  case 'j': ppst->gsubs
26948 X  case 'o': ppst->param_u.fa.optflag = 0;
26949 X  case 'y': ppst->param_u.fa.optwid
26950 X
26951 initsw.c
26952 X  case '3': m_msg->qframe = m_msg->nframe = 1; 
26953 SHAR_EOF
26954 chmod 0644 fasta.options ||
26955 echo 'restore of fasta.options failed'
26956 Wc_c="`wc -c < 'fasta.options'`"
26957 test 1670 -eq "$Wc_c" ||
26958         echo 'fasta.options: original size 1670, current size' "$Wc_c"
26959 fi
26960 # ============= fasta20.doc ==============
26961 if test -f 'fasta20.doc' -a X"$1" != X"-c"; then
26962         echo 'x - skipping fasta20.doc (File already exists)'
26963 else
26964 echo 'x - extracting fasta20.doc (Text)'
26965 sed 's/^X//' << 'SHAR_EOF' > 'fasta20.doc' &&
26966 X
26967 X                        COPYRIGHT NOTICE
26968 X
26969 Copyright 1988, 1991, 1992, 1994, 1995, 1996 by William R.
26970 Pearson and the University of Virginia.  All rights reserved. The
26971 FASTA program and documentation may not be sold or incorporated
26972 into a commercial product, in whole or in part, without written
26973 consent of William R. Pearson and the University of Virginia.
26974 For further information regarding permission for use or
26975 reproduction, please contact: David Hudson, Assistant Provost for
26976 Research, University of Virginia, P.O. Box 9025, Charlottesville,
26977 VA 22906-9025, (434) 924-6853
26978 X
26979 X
26980 The FASTA program package
26981 X
26982 Introduction
26983 X
26984 X     This documentation describes the version 2.0x of the FASTA
26985 program package (see W. R. Pearson and D. J. Lipman (1988),
26986 "Improved Tools for Biological Sequence Analysis", PNAS 85:2444-
26987 2448, and W. R.  Pearson (1990) "Rapid and Sensitive Sequence
26988 Comparison with FASTP and FASTA" Methods in Enzymology 183:63-
26989 98). Version 2.0 modifies version 1.8 to include explicit
26990 statistical estimates for similarity scores based on the extreme
26991 value distribution.  In addition, FASTA protein alignments now
26992 use the Smith-Waterman algorithm with no limitation on gap size.
26993 FASTA and SSEARCH now use the BLOSUM50 matrix by default, with
26994 options to change gap penalties on the command line. Version 1.7
26995 replaces rdf2 and rss with prdf and prss, which use the extreme-
26996 value distribution to calculate accurate probability estimates.
26997 X
26998 X
26999 Although there are a large number of programs in this package,
27000 they belong to four groups:
27001 X
27002 X
27003 X    Library search programs: FASTA, FASTX, TFASTA, TFASTX, SSEARCH
27004 X
27005 X    Local homology programs: LFASTA, PLFASTA, LALIGN, PLALIGN, FLALIGN
27006 X
27007 X    Statistical significance: PRDF, RELATE, PRSS, RANDSEQ
27008 X
27009 X    Global alignment: ALIGN
27010 X
27011 X
27012 X
27013 In addition, I have included several programs for protein
27014 sequence analysis, including a Kyte-Doolittle hydropathicity
27015 plotting program (GREASE, TGREASE), and a secondary structure
27016 prediction package (GARNIER).
27017 X
27018 X     The FASTA sequence comparison programs on this disk are
27019 improved versions of the FASTP program, originally described in
27020 Science (Lipman and Pearson, (1985) Science 227:1435-1441).  We
27021 have made several improvements.  First, the library search
27022 programs use a more sensitive method for the initial comparison
27023 of two sequences which allows the scores of several similar
27024 regions to be combined.  As a result, the results of a library
27025 search are now given with three scores, initn (the new initial
27026 score which may include several similar regions), init1 (the old
27027 fastp initial score from the best initial region), and opt (the
27028 old fastp optimized score allowing gaps in a 32 residue wide
27029 band).
27030 X
27031 X     These programs have also been modified to become "universal"
27032 (hence FAST-A, for FASTA-All, as opposed to FAST-P (protein) or
27033 FAST-N (nucleotides)); by changing the environment variable
27034 SMATRIX, the programs can be used to search protein sequences,
27035 DNA sequences, or whatever you like.  By default, FASTA, LFASTA,
27036 and the PRDF programs automatically recognize protein and DNA
27037 sequences.  Sequences are first read as amino acids, and then
27038 converted to nucleotides if the sequence is greater than 85%
27039 A,C,G,T (the '-n' option can be used to indicate DNA sequences).
27040 TFASTA compares protein sequences to a translated DNA sequence.
27041 Alternative scoring matrices can also be used.  In addition to
27042 the BLOSUM50 matrix for proteins, the PAM250 matrix or matrices
27043 based on simple identities or the genetic code can also be used
27044 for sequence comparisons or evaluation of significance.  Several
27045 different protein sequence matrices have been included;
27046 instructions for constructing your own scoring matrix are
27047 included in the file FORMAT.DOC.
27048 X
27049 X
27050 The remainder of this document is divided into three sections:
27051 (1) a brief history of the changes to the FASTA package; (2) A
27052 guide to installing the programs and databases; (3) A guide to
27053 using the FASTA programs. The programs are very easy to use, so
27054 if you are using them on a machine that is administered by
27055 someone else, you may want to skip to section (3) to learn how to
27056 use the programs, and then read section (1) to look at some of
27057 the more recent changes.  If you are installing the programs on
27058 your own machine, you will need to read section (2) carefully.
27059 X
27060 X
27061 1.  Revision History
27062 X
27063 1.1.  Changes with version 2.0u
27064 X
27065 X     Version 2.0u provides several major improvements over
27066 previous versions of FASTA (and SSEARCH).  The most important is
27067 the incorporation of explicit statistical estimates and
27068 appropriate normalization of similarity scores. This improvement
27069 is discussed in more detail below in the section entitled
27070 Statistical Significance.  In addition, all of the protein
27071 comparison programs now use the BLOSUM50 matrix, with gap
27072 penalties of -12, -2, by default.  BLOSUM50 performs
27073 significantly better than the older PAM250 matrix.  PAM250 can
27074 still be used with the command line option: -s 250.  (DNA
27075 sequence comparisons use a more stringent gap penalty of -16, -4,
27076 which produces excellent statistical estimates when optimized
27077 scores are used. TFASTA uses -16, -4 as well.)
27078 X
27079 X     The quality of the fit of the extreme value distribution to
27080 the actual distribution of similarity scores is summarized with
27081 the Kolmogorov-Smirnov statistic.  The acceptance limits for this
27082 statistic can be found in many statistics books.  In general,
27083 values <0.10 (N=30) indicate excellent agreement between the
27084 actual and theoretical distributions.  If this statistic is >
27085 0.2, consider using a higher (more stringent) gap penalty, e.g.
27086 -16, -4 rather than -12, -2.  The default scoring matrix for DNA
27087 has been changed to score +5 for an identity and -4 for a
27088 mismatch.  These are the same scores used by BLASTN.
27089 X
27090 X     With explicit expectation calculations, the program now
27091 shows all scores and alignments with expectations less than 10.0
27092 (with optimized scores, 2.0 without optimization) when the "-Q"
27093 (quiet) mode is used.  The expectation threshold can be changed
27094 with the "-E" option.
27095 X
27096 X     Finally, the algorithm used to produce the final alignments
27097 of protein sequences is now a full Smith-Waterman, with unlimited
27098 gaps.  (The older band-limited alignments are used for DNA
27099 sequences and TFASTA by default, because Smith-Waterman
27100 alignments are very slow for long sequences.)  Both the optimized
27101 and Smith-Waterman scores are reported; if the Smith-Waterman
27102 score is higher, then additional gaps allowed a better alignment
27103 and similarity score to be calculated.
27104 X
27105 X     FASTA searches now optimize similarity scores by default
27106 (this slows searches about 2-fold (worst case) for ktup=2). Thus,
27107 the meaning of the "-o" option has been reversed; "-o" now turns
27108 off optimization and reports results sorted by "initn" scores.
27109 Optimization significantly improves the sensitivity of FASTA, so
27110 that it almost matches Smith-Waterman.  With version 2.0, the
27111 default band width used for optimized calculations can be varied
27112 with the "-y" option.  For proteins with ktup=2, a width of 16
27113 (-y 16) is used; 16 is also used for DNA sequences.  For proteins
27114 and ktup=1, a width of 32 is used. Searches that disable
27115 optimization with the "-o" option will work fine for sequences
27116 that share 25% or more identity in general, but to detect
27117 evolutionary relationships with 20% - 25% identity, the more
27118 sensitive default optimization is often required.  Optimization
27119 is required for accurate statistical estimates with either
27120 protein or DNA sequences.
27121 X
27122 X     The FASTA package now includes FASTX, a program that
27123 compares a DNA sequence to a protein sequence database by
27124 translating the DNA sequence in three frames (the reverse frames
27125 are selected with the -i option) and aligning the three-frame
27126 translation with the sequences in the protein database.
27127 Alignment scores allow frameshifts so that a cDNA or EST sequence
27128 with insertion/deletion errors can be aligned with its homologues
27129 from beginning to end.
27130 X
27131 X     With release 20u6, there is also a TFASTX program, which is
27132 a replacement for TFASTA.  TFASTA treats each of the six reading
27133 frames of a DNA library sequence as a different sequence; TFASTX
27134 compares a protein sequence against only two sequences from each
27135 DNA sequence - the forward and reverse orientation.  For a given
27136 orientation, TFASTX calculates a similarity score for alignments
27137 that allow frameshifts, thus considering all possible reading
27138 frames.
27139 X
27140 X     Another new program is included - randseq - which will
27141 produce a randomly shuffled (uniform or local shuffle) from an
27142 input sequence.  This randomly shuffled sequence can be used to
27143 evaluate the statistical estimates produced by FASTA, SSEARCH, or
27144 BLAST.
27145 X
27146 1.2.  Changes with version 1.7
27147 Version 1.7 has been released to provide the PRDF and PRSS
27148 programs for shuffling sequences and estimating accurately the
27149 probabilities of the unshuffled-sequence scores.
27150 X
27151 PRDF      a version of RDF2 that uses calculates the probability
27152 X          of a similarity score more accurately by using a fit to
27153 X          an extreme value distribution.  Code to fit the extreme
27154 X          value distribution parameters and the impetus to update
27155 X          RDF2 was provided by Phil Green, U. of Washington.
27156 X
27157 PRSS      a version of PRDF that uses a rigorous Smith-Waterman
27158 X          calculation to score similarities
27159 X
27160 1.3.  Changes with version 1.6
27161 X
27162 X     FASTA version 1.6 uses a new method for calculating optimal
27163 scores in a band (the optimization or last step in the FASTA
27164 algorithm). In addition, it uses a linear-space method for
27165 calculating the actual alignments.  FASTA v1.6 package includes
27166 several new programs:
27167 X
27168 SSEARCH   a program to search a sequence database using the
27169 X          rigorous Smith-Waterman algorithm (this program is
27170 X          about 100-fold slower than FASTA with ktup=2 (for
27171 X          proteins).
27172 X
27173 LALIGN    A rigorous local sequence alignment program that will
27174 X          display the N-best local alignments (N=10 by default).
27175 X
27176 PLALIGN   a version of lalign that plots the local alignments to
27177 X          a tektronix display.
27178 X
27179 FLALIGN   a version of lalign that plots the local alignments to
27180 X          a GCG Figure file.
27181 X
27182 X     The LALIGN/PLALIGN/FLALIGN programs incorporate the "sim"
27183 algorithm described by Huang and Miller (1991) Adv. Appl. Math.
27184 12:337-357.  The SSEARCH and PRSS programs incorporate algorithms
27185 described by Huang, Hardison, and Miller (1990) CABIOS 6:373-381.
27186 X
27187 X     LFASTA and PLFASTA now calculate a different number of local
27188 similarities; they now behave more like LALIGN/PLALIGN.  Since
27189 local alignments of identical sequences produce "mirror-image"
27190 alignments, lalign and lfasta consider only one-half of the
27191 potential alignments between sequences from identical file names.
27192 Thus
27193 X
27194 X    lfasta mchu.aa mchu.aa
27195 X
27196 Displays only two alignments, with earlier versions of the
27197 program, it would have displayed five, including the identity
27198 alignment.  PLFASTA does display five alignments; when two
27199 identical filenames are given, it draws the identity alignment,
27200 calculates the two unique local alignments, draws them, and draws
27201 their mirror images. LFASTA/PLFASTA and LALIGN/PLALIGN use the
27202 filenames, rather than the actual sequences, to determine whether
27203 sequences are identical; you can "trick" the programs into
27204 behaving the old way by putting the same sequence in two
27205 different files.
27206 X
27207 1.4.  Changes with version 1.5
27208 X
27209 X     FASTA version 1.5 includes a number of substantial revisions
27210 to improve the performance and sensitivity of the program.  It is
27211 now possible to tell the program to optimize all of the initn
27212 scores greater than a threshold.  The threshold is set at the
27213 same value as the old FASTA cutoff score.  Alternatively, you can
27214 tell FASTA to sort the results by the init1, rather than the
27215 initn, score by using the -1 option.  FASTA -1 ... will report
27216 the results the way the older FASTP program did.
27217 X
27218 X     A new method has been provided for selecting libraries. In
27219 the past, one could enter the name of a sequence file to be
27220 searched or a single letter that would specify a library from the
27221 list included in the $FASTLIBS file. Now, you can specify a set
27222 of library files with a string of letters preceded by a '%'.
27223 Thus, if the FASTLIBS file has the lines:
27224 X
27225 X    Genbank 70 primates$1P/seqlib/gbpri.seq 1
27226 X    Genbank 70 rodents$1R/seqlib/gbrod.seq 1
27227 X    Genbank 70 other mammals$1M/seqlib/gbmam.seq 1
27228 X    Genbank 70 vertebrates $1B/seqlib/gbvrt.seq 1
27229 X
27230 Then the string: "%PRMB" would tell FASTA to search the four
27231 libraries listed above.  The %PRMB string can be entered either
27232 on the command line or when the program asks for a filename or
27233 library letter.
27234 X
27235 X     FASTA1.5 also provides additional flexibility for specifying
27236 the number of results and alignments to be displayed with the -Q
27237 (quiet) option.  The -b number option allows you to specify the
27238 number of sequence scores to show when the search is finished.
27239 Thus
27240 X
27241 X
27242 X    FASTA -b 100 ...
27243 X
27244 X
27245 tells the program to display the top 100 sequence scores. In the
27246 past, if you displayed 100 scores (in -Q mode), you would also
27247 have store 100 alignments. The -d option allows you to limit the
27248 number of alignments shown.  FASTA -b 100 -d 20 would show 100
27249 scores and 20 alignments.
27250 X
27251 X     Finally, FASTA can provide a complete list of all of the
27252 sequences and scores calculated to a file with the -r (results)
27253 option.  FASTA -r results.out ... creates a file with a list of
27254 scores for every sequence in the library.  The list is not
27255 sorted, and only includes those scores calculated during the
27256 initial scan of the library.
27257 X
27258 2.  Installing the FASTA package
27259 X
27260 2.1.  Installing the programs
27261 X
27262 2.1.1.  Unix version
27263 X
27264 X     The FASTA distribution comes with several makefile's that
27265 can be used to compile the FASTA programs.  Over the years, as
27266 ATT Unix System 5 and BSD unix have converged, these files have
27267 become very similar. To begin with, I recommend using the
27268 standard Makefile.  There are two values in the makefile that
27269 should be checked against the values used on your system: the HZ
27270 value, which is the frequency in ticks per second used by the
27271 times() system call, this value can usually be found by running:
27272 X
27273 X    grep HZ /usr/include/sys/*
27274 X
27275 and the functions available to return random numbers.  If you
27276 have a rand48() function that returns a 32-bit random number, use
27277 it and use the lines:
27278 X
27279 X    NRAND=nrand48
27280 X    RANFLG= -DRAND32
27281 X
27282 If not, you will need to use the rand() function call and
27283 determine whether it returns a 16-bit or a 32-bit value.  These
27284 functions are used by PRDF and PRSS.  If you have problems
27285 compiling the programs, you may want to examine the makefile.unx
27286 and makefile.sun files, to look for differences.  I have tried to
27287 use very standard unix functions in these programs, and they have
27288 been successfully compiled, with very small changes to the
27289 Makefile, on Sun's (Sun OS 4.1), IBM RS/6000's (AIX), and MIPS
27290 machines (under the BSD environment).
27291 X
27292 2.1.2.  IBM-PC/DOS version
27293 X
27294 X     For the IBM-PC/DOS version, the FASTA source code disk
27295 contains the complete source code to all of the programs on the
27296 other disks.  The programs were compiled with Borland's Turbo
27297 'C++', using Borland's MAKE utility.  The graphics programs
27298 (PLFASTA, TGREASE) use the graphics device drivers supplied with
27299 the Turbo 'C' V2.0 package.  Also included are the documentation
27300 files PROGRAMS.DOC and FORMAT.DOC.  You do not need any of the
27301 files the source code disk to run the programs.  The files on
27302 this disk are identical to the UNIX and VMS versions that run on
27303 larger machines.  Also included is the code to compile
27304 ALIGN0.EXE.  ALIGN0 is the same as ALIGN, but does not penalize
27305 for end-gaps.
27306 X
27307 X     If you have the DOS or Macintosh version of the FASTA
27308 package, to install the programs you should:
27309 X
27310 X (1)   Make a new directory (folder) for the FASTA programs.
27311 X       This need not be the same as the directory for your
27312 X       sequence databases.
27313 X
27314 X (2)   Copy the files from the FASTA source disk to the new
27315 X       directory.
27316 X
27317 X (3)   (DOS only) Edit your AUTOEXEC.BAT file to (a) modify your
27318 X       PATH command to include the FASTA directory and (b) add
27319 X       the line:
27320 X
27321 X           set FASTLIBS=c:\yourfastadirectory\fastgbs
27322 X
27323 X       On the Macintosh, you may need to edit the "environment"
27324 X       file and change the line that reads:
27325 X
27326 X           FASTLIBS=fastgbs
27327 X
27328 X       to indicate the full directory path for the fastgbs file,
27329 X       for example:
27330 X
27331 X           FASTLIBS=Q105:FASTA:fastgbs
27332 X
27333 X
27334 X (4)   Finally, you will need to edit the fastgbs file.  This is
27335 X       usually the most confusing part of the installation.  An
27336 X       example of this file is shown below; to customize this
27337 X       file for your machine, you will need to change the file
27338 X       names from those provided in the fastgbs file to ones that
27339 X       reflect the directory names and file names you use on your
27340 X       machine. This is explained in more detail below.  In
27341 X       addition, some entries in the fastgbs file refer to other
27342 X       files of file names.  These files of file names (as
27343 X       opposed to actual database files) may also need to be
27344 X       edited.
27345 X
27346 2.2.  Installing the libraries
27347 X
27348 2.2.1.  The NBRF protein sequence library
27349 X
27350 X     The FASTA program package does not include any protein or
27351 DNA sequence libraries.  You can obtain the PIR protein sequence
27352 database from:
27353 X
27354 X    National  Biomedical Research Foundation
27355 X    Georgetown  University  Medical  Center
27356 X    3900 Reservoir Rd, N.W.
27357 X    Washington, D.C. 20007
27358 X
27359 In addition, this database is available via anonymous ftp from
27360 the host "ftp.bchs.uh.edu". It is available in two formats, VMS
27361 and CODATA format.  The "VMS" format (library type 5 below) can
27362 be searched much faster, can be easily reformatted for use by the
27363 "BLAST" rapid searching program, and is compatible with the
27364 Genetics Computer Group package of programs.  The CODATA format
27365 is used by the EUGENE/MBIR computing package from Baylor (library
27366 type 2).
27367 X
27368 2.2.2.  The GENBANK DNA sequence library
27369 X
27370 X     FASTA, and TFASTA search sequences from the GENBANK
27371 "flatfile" (not ASN.1) DNA sequence library in the flat-file
27372 format distributed by the National Center for Biotechnology
27373 Information and the PIR format used by EBI/EMBL.  CD-ROMs can be
27374 obtained from:
27375 X
27376 X    Genbank
27377 X    National Center for Biotechnology Information
27378 X    National Library of Medicine
27379 X    National Institutes of Health
27380 X    8600 Rockville Pike
27381 X    Bethesda, MD  20894
27382 X
27383 X
27384 X     The GenBank DNA sequence library is also available via
27385 anonymous FTP from ncbi.nlm.nih.gov.
27386 X
27387 2.2.3.  The EBI/EMBL CD-ROM libraries
27388 X
27389 X     The European Bioinformatics Institute (EBI) is now
27390 distributing the EMBL CD-ROM that contains both the complete EMBL
27391 DNA sequence database (which should be essentially identical to
27392 the GenBank DNA sequence database) and the SWISS-PROT protein
27393 sequence database. SWISS-PROT is derived from the NBRF Protein
27394 sequence database with additions from the EBI/EMBL DNA sequence
27395 database.  This CD-ROM is a "best-buy," since it provides both
27396 DNA and protein sequence libraries.  It is available from:
27397 X
27398 X
27399 X    European Bioinformatics Institute
27400 X    Hinxton Genome Campus, Hinxton Hall
27401 X    Hinxton, Cambridge CB10 1RQ,
27402 X    United Kingdom
27403 X    Tel: +44 1223 4944
27404 X    Fax: +44 1223 494468
27405 X    Email: DATALIB@ebi.ac.uk
27406 X
27407 X
27408 X
27409 X     In addition, the SWISS-PROT protein sequence database is
27410 available via anonymous FTP from ncbi.nlm.nih.gov.
27411 X
27412 2.3.  Finding the libraries: FASTLIBS
27413 X
27414 X     FASTA and TFASTA use the environment variable FASTLIBS to
27415 find the protein and DNA sequence libraries.  The FASTLIBS
27416 variable contains the name of a file that has the actual
27417 filenames of the libraries.  The FASTGBS file on is an example of
27418 a file that can be referred to by FASTLIBS. To use the FASTGBS
27419 file, type:
27420 X
27421 X    setenv FASTLIBS /usr/lib/fasta/fastgbs (BSD UNIX/csh)
27422 X    or
27423 X    export FASTLIBS=/usr/lib/fasta/fastgbs (SysV UNIX/ksh)
27424 X
27425 Then edit the FASTGBS file to indicate where the protein and DNA
27426 sequence libraries can be found.  If you have a hard disk and
27427 your protein sequence library is kept in the file
27428 /usr/lib/aabank.lib and your Genbank DNA sequence library is kept
27429 in the directory: /usr/lib/genbank, then fastgbs might contain:
27430 X
27431 X    NBRF Protein$0P/usr/lib/seq/aabank.lib 0
27432 X    SWISS PROT 10$0S/usr/lib/vmspir/swiss.seq 5
27433 X    GB Primate$1P@/usr/lib/genbank/gpri.nam
27434 X    GB Rodent$1R@/usr/lib/genbank/grod.nam
27435 X    GB Mammal$1M@/usr/lib/genbank/gmammal.nam
27436 X    ^   1    ^^^^       4                   ^     ^
27437 X              23                             (5)
27438 X
27439 The first line of this file says that there is a copy of the NBRF
27440 protein sequence database (which is a protein database) that can
27441 be selected by typing "P" on the command line or when the
27442 database menu is presented in the file /usr/lib/seq/aabank.lib.
27443 X
27444 X     Note that there are 4 or 5 fields in the lines in fastgbs.
27445 The first field is the description of the library which will be
27446 displayed by FASTA; it ends with a '$'.  The second field (1
27447 character), is a 0 if the library is a protein library and 1 if
27448 it is a DNA library.  The third field (1 character) is the
27449 character to be typed to select the library.
27450 X
27451 X     The fourth field is the name of the library file.  In the
27452 example above, the /usr/lib/seq/aabank.lib file contains the
27453 entire protein sequence library.  However the DNA library file
27454 names are preceded by a '@', because these files (gpri.nam,
27455 grod.nam, gmammal.nam) do not contain the sequences; instead they
27456 contain the names of the files which contain the sequences.  This
27457 is done because the GENBANK DNA database is broken down in to a
27458 large number of smaller files.  In order to search the entire
27459 primate database, you must search more than a dozen files.
27460 X
27461 X     In addition, an optional fifth field can be used to specify
27462 the format of the library file.  Alternatively, you can specify
27463 the library format in a file of file names (a file preceded by an
27464 '@').  This field must be separated from the file name by a space
27465 character (' ') from the filename.  In the example above, the
27466 aabank.lib file is in Pearson/FASTA format, while the swiss.seq
27467 file is in PIR/VMS format (from the EMBL CD-ROM). Currently,
27468 FASTA can read the following formats:
27469 X
27470 X    0 Pearson/FASTA (>SEQID - comment/sequence)
27471 X    1 Uncompressed Genbank (LOCUS/DEFINITION/ORIGIN)
27472 X    2 NBRF CODATA (ENTRY/SEQUENCE)
27473 X    3 EMBL/SWISS-PROT (ID/DE/SQ)
27474 X    4 Intelligenetics (;comment/SEQID/sequence)
27475 X    5 NBRF/PIR VMS (>P1;SEQID/comment/sequence)
27476 X    6 GCG (version 8.0) Unix Protein and DNA (compressed)
27477 X    11 NCBI Blast1.3.2 format  (unix only)
27478 X
27479 In particular, this version will work with the EMBL and PIR VMS
27480 formats that are distributed on the EMBL CD-ROM. The latter
27481 format (PIR VMS) is much faster to search than EMBL format.  This
27482 release also works with the protein and DNA database formats
27483 created for the BLASTP and BLASTN programs by SETDB and PRESSDB
27484 and with the new NCBI search format.  If a library format is not
27485 specified, for example, because you are just comparing two
27486 sequences, Pearson/FASTA (format 0) is used by default.  To
27487 change this default, you may set the LIBTYPE environment variable
27488 to a number.  For example,
27489 X
27490 X    setenv LIBTYPE 1
27491 X
27492 would cause the program to use the GenBank LOCUS format by
27493 default for libraries (or the second sequence file), but the
27494 Pearson/FASTA format would still be used for the query sequence.
27495 X
27496 X     You can specify a group of library files by putting a '@'
27497 symbol before a file that contains a list of file names to be
27498 searched.  For example, if @gmam.nam is in the fastgbs file, the
27499 file "gmam.nam" might contain the lines:
27500 X
27501 X    </usr/lib/genbank
27502 X    gbpri.seq 1
27503 X    gbrod.seq 1
27504 X    gbmam.seq 1
27505 X
27506 In this case, the line beginning with a '<' indicates the
27507 directory the files will be found in.  The remaining lines name
27508 the actual sequence files.  So the first sequence file to be
27509 searched would be:
27510 X
27511 X    /usr/lib/genbank/gbpri.seq
27512 X
27513 The notation "<PIRNAQ:" might be used under the VAX/VMS operating
27514 system. Under UNIX, the trailing '/' is left off, so the library
27515 directory might be written as "</usr/seqlib".
27516 X
27517 X     With version 1.4 of the FASTA package, the FASTA and TFASTA
27518 programs can search a library composed of different files in
27519 different sequence formats.  For example, you may wish to search
27520 the Genbank files (in GenBank flat file format) and the EMBL DNA
27521 sequence database on CD-ROM.  To do this, you simply list the
27522 names and filetypes of the files to be searched in a file of
27523 filenames.  For example, to search the mammalian portion of
27524 Genbank, the unannotated portion of Genbank, and the unannotated
27525 portion of the EMBL library, you could use the file:
27526 X
27527 X    </usr/lib/DNA
27528 X    gbpri.seq 1
27529 X    #  (this '#' causes the program to display the size of the library)
27530 X    gbrod.seq 1
27531 X    gbmam.seq 1
27532 X    gbuna.seq 1
27533 X    unanno.seq 5
27534 X    #
27535 X
27536 X    You do not need to include library format numbers if  you
27537 X    only use the Pearson/FASTA version of the PIR protein se-
27538 X    quence library.  If no library  type  is  specified,  the
27539 X    program  assumes  that  type  0 is being used (unless you
27540 X    have set LIBTYPE).
27541 X
27542 Support for the old compressed GenBank files, which have not been
27543 distributed for more than four years, has been removed from
27544 programs in the FASTA package.
27545 X
27546 X
27547 X     Test the setup by running FASTA.  Enter the sequence file
27548 'MUSPLFM.AA' when the program requests it (this file is included
27549 with the programs).  The program should then ask you to select a
27550 protein sequence library.  Alternatively, if you run the TFASTA
27551 program and use the MUSPLFM.AA query sequence, the program should
27552 show you a selection of DNA sequence libraries.  Once the fastgbs
27553 file has been set up correctly, you can set FASTLIBS=fastgbs in
27554 your AUTOEXEC.BAT file, and you will not need to remember where
27555 the libraries are kept or how they are named.
27556 X
27557 X     FASTA and TFASTA must open a large number of files when
27558 searching and reporting the results of a GENBANK floppy disk
27559 format library search.  You may have problems with the large
27560 number of files under DOS on IBM-PC's (Unix and VMS users will
27561 not have these problems).  If you are going to search the GENBANK
27562 floppy disk format DNA sequence library under DOS, you should add
27563 the line:
27564 X
27565 X    FILES=16
27566 X
27567 to your CONFIG.SYS file.  (Typically this is already done for
27568 programs like Windows or WordPerfect.)
27569 X
27570 3.  Using the FASTA Package
27571 X
27572 3.1.  Overview
27573 X
27574 X     The FASTA sequence comparison programs all require similar
27575 information, the name of a query sequence file, a library file,
27576 and the ktup parameter.  All of the programs can accept arguments
27577 on the command line, or they will prompt for the file names and
27578 ktup value.
27579 X
27580 To use FASTA, simply type:
27581 X
27582 X    FASTA
27583 X    and you will be prompted for :
27584 X         the name of the test sequence file
27585 X         the name of the library file
27586 X         and whether you want ktup = 1 or 2. (or 1 to 6 for DNA sequences)
27587 X
27588 X             ktup of 2 is about 5 times faster than ktup = 1.
27589 X             For  a  200  aa sequence against a 10,000,000 aa
27590 X             library, the program takes  about  30  min  with
27591 X             ktup = 2, 150 min with ktup = 1, on a 12 Mhz 286
27592 X             IBM-PC.
27593 X
27594 X
27595 The program can also be run by typing
27596 X
27597 X    FASTA test.aa /lib/bigfile.lib ktup (1 or 2)
27598 X
27599 X
27600 Included with the package are the test files, MUSPLFM.AA,
27601 LCBO.AA, MCHU.AA and BOVPRL.SEQ.  To check to make certain that
27602 everything is working, you can try:
27603 X
27604 X    fasta musplfm.aa lcbo.aa
27605 X    and
27606 X    tfasta musplfm.aa bovprl.seq
27607 X
27608 To test the local similarity programs LFASTA and PLFASTA, try:
27609 X
27610 X    lfasta mchu.aa mchu.aa
27611 X    and
27612 X    plfasta mchu.aa mchu.aa (use this only on an IBM-PC with graphics
27613 X    or on a Tektronix terminal under UNIX or VMS)
27614 X
27615 MCHU (calmodulin) has four duplicated calcium binding sites that
27616 are clearly detected by LFASTA.  For a more complicated example,
27617 try MWRTC1.aa, myosin heavy chain.
27618 X
27619 3.2.  Sequence files
27620 X
27621 X     The FASTA programs know about three kinds of sequence files
27622 (four under VMS): (1) plain sequence files that can only be used
27623 as query sequences or for LFASTA, PRDF, and ALIGN. (2) Standard
27624 library files.  These are the same as plain sequence files, each
27625 sequence is preceded by a comment line with a '>' in the first
27626 column. (3) distributed sequence libraries (this is a broad class
27627 that includes the NBRF/PIR VMS and blocked ascii formats, Genbank
27628 flat-file format, EMBL flat-file format, and Intelligenetics
27629 format.  All of the files that you create should be of type (1)
27630 or (2).  Type (2) files (ones with a be used as query or library
27631 sequence files by all of the programs.
27632 X
27633 X     I have included several sample test files, *.AA.  The first
27634 line may begin with a '>'  or ';' followed by a comment.  The
27635 text after ';' in other lines will  be  ignored.   Spaces  and
27636 tabs  (and anything else that  is  not  an amino-acid code) are
27637 ignored.
27638 X
27639 X     Library files should have the form:
27640 X
27641 X    >Sequence name and identifier
27642 X    A F A S Y T .... actual sequence.
27643 X    F S S       .... second line of sequence.
27644 X    >Next sequence name and identifier
27645 X
27646 This is often referred to as "FASTA" or "Pearson" format.  You
27647 can build your own library by concatenating several sequence
27648 files.  Just be sure that each sequence is preceded by a line
27649 beginning with a '>' with a sequence name.
27650 X
27651 X     The test file should not have lines longer than 120
27652 characters, and sequences entered with word processors should use
27653 a document mode, with normal carriage returns at the end of
27654 lines.
27655 X
27656 Program Summary
27657 X
27658 3.3.  Sequence search programs
27659 X
27660 FASTA     universal sequence comparison. Defaults to comparing
27661 X          protein sequences; if the sequences are > 85% A+C+G+T
27662 X          or the -n option is used, a DNA sequence is assumed.
27663 X
27664 FASTX     Search a protein sequence library using amino acid
27665 X          sequence comparison to the forward three frames of a
27666 X          translated DNA query sequence. (The reverse frames are
27667 X          specified with the -i option.) Alignment scores allow
27668 X          frameshifts; the final alignment uses a Smith-Waterman
27669 X          type alignment routine (no limit on gaps) that allows
27670 X          frameshifts.
27671 X
27672 TFASTA    Search DNA library for a protein sequence by
27673 X          translating the DNA sequence to protein in all six
27674 X          frames (three forward frames with the -3 command line
27675 X          option). TFASTA with ktup=2 is about as fast as a DNA
27676 X          FASTA with ktup=4, and is substantially more sensitive.
27677 X          (also reads the GENBANK library)
27678 X
27679 TFASTX    Search DNA library for a protein sequence by
27680 X          translating the DNA sequence to protein in all six
27681 X          frames (three forward frames with the -3 command line
27682 X          option) calculating similarity scores that allow
27683 X          frameshifts. TFASTX produces an optimal Smith-Waterman
27684 X          alignment of the query and translated-library sequence.
27685 X
27686 SSEARCH   Universal sequence comparison using the Smith-Waterman
27687 X          algorithm ( T. F. Smith and M. S. Waterman (1981) J.
27688 X          Mol. Biol. 147:195-197).  This program uses code
27689 X          developed by Huang and Miller (X. Huang, R. C.
27690 X          Hardison, W. Miller (1990) CABIOS 6:373-381) for
27691 X          calculating the local similarity score and code from
27692 X          the ALIGN program (see below) for calculating the local
27693 X          alignment.  SSEARCH is about 50-times slower than FASTA
27694 X          with ktup=2 (for proteins).
27695 X
27696 ALIGN     optimal global alignment of two sequences with no
27697 X          short-cuts.  This program is a slightly modified
27698 X          version of one taken from E.  Myers and W. Miller. The
27699 X          algorithm is described in E. Myers and W.  Miller,
27700 X          "Optimal Alignments in Linear Space" (CABIOS (1988)
27701 X          4:11-17).
27702 X
27703 3.4.  Local similarity programs
27704 X
27705 LFASTA    local similarity searches showing local alignments.
27706 X          The algorithm used to calculate the local alignment in
27707 X          a band has been improved (Chao, Pearson, and Miller,
27708 X          submitted).
27709 X
27710 PLFASTA   local similarity searches with plot output (on the IBM,
27711 X          this program requires that the environment variable
27712 X          BGIDIR be set).
27713 X
27714 PCLFASTA  (unix only) local similarity searches with plot output
27715 X          using pic commands.
27716 X
27717 LALIGN    Calculates the N-best local alignments using a rigorous
27718 X          algorithm.  (N=10 by default.) The algorithm was
27719 X          developed by Huang and Miller (X.  Huang and W.  Miller
27720 X          (1991) Adv. Appl. Math. 12:337-357), which is a
27721 X          linear-space version of an algorithm described by M. S.
27722 X          Waterman and M. Eggert (J.  Mol. Biol. 197:723-728).
27723 X          Like SSEARCH, LALIGN is rigorous, but also very slow.
27724 X
27725 PLALIGN   A version of LALIGN that plots its output to a screen
27726 X          or to a Tektronix terminal emulator.
27727 X
27728 3.5.  Statistical Significance
27729 X
27730 X     With version 2.0 of the FASTA program distribution, FASTA,
27731 TFASTA, and SSEARCH now provide estimates of statistical
27732 significance for library searches.  Work by Altschul, Arratia,
27733 Karlin, Mott, Waterman, and others (see Altschul et al. (1994)
27734 Nature Genetics 6:119 for an excellent review) suggests that
27735 local sequence similarity scores follow the extreme value
27736 distribution, so that P(s > x) = 1 - exp(-exp(-lambda(x-u)) where
27737 u = ln(Kmn)/lambda and m,m are the lengths of the query and
27738 library sequence. This formula can be rewritten as: 1 - exp(-Kmn
27739 exp(-lambda x), which shows that the average score for an
27740 unrelated library sequence increases with the logarithm of the
27741 length of the library sequence.  FASTA and SSEARCH use simple
27742 linear regression against the the log of the library sequence
27743 length to calculate a normalized "z-score" with mean 50,
27744 regardless of library sequence length, and variance 10.  These
27745 z-scores can then be used with the extreme value distribution and
27746 the poisson distribution (to account for the fact that each
27747 library sequence comparison is an independent test) to calculate
27748 the number of library sequences to obtain a score greater than or
27749 equal to the score obtained in the search. The original idea and
27750 routines to do the linear regression on library sequence length
27751 were provided Phil Green, U. Washington.  This version of FASTA
27752 and SSEARCH uses a slightly different strategy for fitting the
27753 data than those originally provided by Dr. Green.
27754 X
27755 X     The expected number of sequences is plotted in the histogram
27756 using an "*". Since the parameters for the extreme value
27757 distribution are not calculated directly from the distribution of
27758 similarity scores, the pattern of "*'s" in the histogram gives a
27759 qualitative view of how well the statistical theory fits the
27760 similarity scores calculated by FASTA and SSEARCH.  For FASTA, if
27761 optimized scores are calculated for each sequence in the database
27762 (the default), the agreement between the actual distribution of
27763 "z-scores" and the expected distribution based on the length
27764 dependence of the score and the extreme value distribution is
27765 usually very good.  Likewise, the distribution of SSEARCH Smith-
27766 Waterman scores typically agrees closely with the actual
27767 distribution of "z-scores."  The agreement with unoptimized
27768 scores, ktup=2, is often not very good, with too many high
27769 scoring sequences and too few low scoring sequences compared with
27770 the predicted relationship between sequence length and similarity
27771 score.  In those cases, the expectation values may be
27772 overestimates.
27773 X
27774 X     The statistical routines assume that the library contains a
27775 large sample of unrelated sequences.  If this is not the case,
27776 then the expectation values are meaningless.  Likewise, if there
27777 are fewer than 20 sequences in the library, the statistical
27778 calculations are not done.
27779 X
27780 X     For protein searches, library sequences with E() values <
27781 0.01 for searches of a 10,000 entry protein database are almost
27782 always homologous. Frequently sequences with E()-values from 1 -
27783 10 are related as well. Remember, however, that these E() values
27784 also reflect differences between the amino acid composition of
27785 the query sequence and that of the "average" library sequence.
27786 Thus, when searches are done with query sequences with "biased"
27787 amino-acid composition, unrelated sequences may have
27788 "significant" scores because of sequence bias.  The programs
27789 below, PRDF and PRSS, can address this problem by calculating
27790 similarity scores for random sequences with the same length and
27791 amino acid composition.
27792 X
27793 X     If optimization is not used ("-o"), E-values for DNA
27794 sequences overestimate the significance of the scores that are
27795 obtained and unrelated sequences frequently have E()-values <
27796 0.0005. With optimization, the agreement between E()-value
27797 compares favorably with protein sequence comparison.  This is in
27798 part due to the use of more stringent gap penalties for DNA
27799 sequence comparison, -16, -4 rather than -12, -2.  With the
27800 latter penalties, many unrelated sequences appear to have
27801 significant similarity. Nevertheless, since protein sequence
27802 comparison is much more sensitive, DNA sequence comparison should
27803 not be used to identify sequences that encode protein.  Even with
27804 ktup=6, optimization rarely increases run-times more than 50%
27805 with mRNA-size query sequences.  Optimization should be used
27806 whenever possible.
27807 X
27808 X     Similar comments apply to TFASTA, where  higher gap
27809 penalties (-16,-4) are required for accurate statistical
27810 estimates.  Because TFASTA produces so many artificial "coding"
27811 sequences with atypical amino acid compositions, the statistical
27812 estimates with TFASTA are often over estimates.  With optimized
27813 scores, ktup=1, and gap penalties of -16, -4, unrelated sequences
27814 will sometimes have E() values of 0.1.  If initn scores are used,
27815 unrelated sequences may have have E() values < 0.01.
27816 X
27817 PRDF      improved version of RDF program that includes accurate
27818 X          probability estimates for all three scoring methods
27819 X          (includes local or window shuffle routine)
27820 X
27821 PRSS      A version of PRDF that uses the rigorous Smith-Waterman
27822 X          calculation used by SSEARCH.
27823 X
27824 RANDSEQ   produces a randomly shuffled sequence from a query
27825 X          sequence.
27826 X
27827 RELATE    significance program described by Dayhoff (Atlas of
27828 X          Protein Sequence and Structure, Vol. 5, Supplement 3).
27829 X          Each chunk of 25 residues in one sequence is compared
27830 X          to every 25 residue fragment of the second sequence.
27831 X          Sequences which are genuinely related will have a large
27832 X          number of scores greater than 3 standard deviations
27833 X          above the mean score of all of the comparisons.
27834 X
27835 3.6.  Other analysis programs
27836 X
27837 AACOMP    calculate the amino acid composition and molecular
27838 X          weight of a sequence.
27839 X
27840 BESTSCOR  calculate the best self-comparison score.
27841 X
27842 GREASE    Kyte-Doolittle hydropathicity profile
27843 X
27844 TGREASE   graphic plot of Kyte-Doolittle profile
27845 X
27846 FROMGB    convert from GenBank LOCUS format (also used by the
27847 X          IBI-Pustell programs) to Pearson/FASTA format.
27848 X
27849 GARNIER   A secondary structure prediction program using the
27850 X          method of Garnier, Osgusthorpe, and Robson, J. Mol.
27851 X          Biol., (1978) 120:97-120.
27852 X
27853 3.7.  Options
27854 X
27855 X     These programs have a number of output options, which are
27856 invoked by the environment variables LINLEN, SHOWALL, and MARKX.
27857 Alternatively, these values can be controlled by command line
27858 options.  The number of sequence residues per output line is now
27859 adjustable by setting the environment variable LINLEN, or the
27860 command line option -w.  LINLEN is normally 60, to change it set
27861 LINLEN=80 before running the program or add -w 80 to the command
27862 line.  LINLEN can be set up to 200.  SHOWALL (-a) determines
27863 whether all, or just a portion, of the aligned sequences are
27864 displayed.  Previously, FASTP would show the entire length of
27865 both sequences in an alignment while FASTN would only show the
27866 portions of the two sequences that overlapped. Now the default is
27867 to show only the overlap between the two sequences, to show
27868 complete sequences, set SHOWALL=1, or use the -a option on the
27869 command line.
27870 X
27871 X     The differences between the two aligned sequences can be
27872 highlighted in three different ways by changing the environment
27873 variable MARKX or the -m option.  Normally (MARKX=0) the program
27874 uses ':' do denote identities and '.' to denote conservative
27875 replacements.  If MARKX=1, the program will not mark identities;
27876 instead conservative replacements are denoted by a 'x' and non-
27877 conservative substitutions by a 'X'.  If MARKX=2, the residues in
27878 the second sequence are only shown if they are different from the
27879 first. MARKX=3 displays the aligned library sequences without the
27880 query sequence; these can be used to build a primitive multiple
27881 alignment.  MARKX=4 provides a graphical display of the
27882 boundaries of the alignments. Thus the five options are:
27883 X
27884 X
27885 X     MARKX=0      MARKX=1       MARKX=2       MARKX=3      MARKX=4
27886 X
27887 X    MWRTCGPPYT   MWRTCGPPYT    MWRTCGPPYT                 MWRTCGPPYT
27888 X    ::..:: :::     xx  X       ..KS..Y...    MWKSCGYPYT   ----------
27889 X    MWKSCGYPYT   MWKSCGYPYT
27890 X
27891 X
27892 (fasta20u4, Feb. 1996) In addition MARKX=10 is a new, parseable
27893 format for use with other programs.  See the file"readme.v20u4"
27894 for a more complete description.
27895 X
27896 3.8.  Command line options
27897 X
27898 X     It is now possible to specify  several options on the
27899 command line, instead of using environment variables.  The
27900 command line options are preceded by a dash; the following
27901 options are available:
27902 X
27903 -a        same as showall=1
27904 X
27905 -A        force Smith-Waterman alignments for DNA sequences and
27906 X          TFASA.  By default, only FASTA protein sequence
27907 X          comparisons use Smith-Waterman alignments.
27908 X
27909 -b #      Number of sequence scores to be shown on output.  In
27910 X          the absence of this option, fasta (and tfasta and
27911 X          ssearch) display all library sequences obtaining
27912 X          similarity scores with expectations less than 10.0 if
27913 X          optimized score are used, or 2.0 if they are not. The
27914 X          -b option can limit the display further, but it will
27915 X          not cause additional sequences to be displayed.
27916 X
27917 -c #      Threshold score for optimization (OPTCUT).  Set "-c 1"
27918 X          to optimize every sequence in a database.  (This slows
27919 X          the program down about 5-fold).
27920 X
27921 -E #      Limit the number of scores and alignments shown based
27922 X          on the expected number of scores.  Used to override the
27923 X          expectation value of 10.0 used by default.  When used
27924 X          with -Q, -E 2.0 will show all library sequences with
27925 X          scores with an expectation value <= 2.0.
27926 X
27927 -d #      Number of alignments to be reported by default. (Used
27928 X          in conjunction with -Q).  No longer necessary, see "-b"
27929 X          above.
27930 X
27931 -f        Penalty for the first residue in a gap (-12 by default
27932 X          for proteins, -16 for DNA or for TFASTA).
27933 X
27934 -g        Penalty for additional residues in a gap (-2 by default
27935 X          for proteins, -4 for DNA and TFASTA ).
27936 X
27937 -h        Penalty for frameshift (FASTX, TFASTX only).
27938 X
27939 -H        Omit histogram.
27940 X
27941 -i        Invert (reverse complement) the query sequence if it is
27942 X          DNA.  For TFASTX, search the reverse complement of the
27943 X          library sequence only.
27944 X
27945 -k #      Threshold for joining init1 segments to build an initn
27946 X          score (GAPCUT).
27947 X
27948 -l file   Location of library menu file (FASTLIBS).
27949 X
27950 -L        Display more information about the library sequence in
27951 X          the alignment.
27952 X
27953 -m #      MARKX = # (0, 1, 2, 3, 4, 10)
27954 X
27955 -n        Force the query sequence to be treated as a DNA
27956 X          sequence.  This is particularly useful for query
27957 X          sequences that contain a large number of ambiguous
27958 X          residues, e.g. transcription factor binding sites.
27959 X
27960 -O        Send copy of results to "filename."  Helpful for
27961 X          environments without STDOUT.
27962 X
27963 -o        Turn off default optimization of all scores greater
27964 X          than OPTCUT. Sort results by "initn" scores.
27965 X
27966 -Q,-q     Quiet - does not prompt for any input.  Writes scores
27967 X          and alignments to the terminal or standard output file.
27968 X
27969 -r file   Save a results summary line for every sequence in the
27970 X          sequence library.  The summary line includes the
27971 X          sequence identifier, superfamily number (if available)
27972 X          position in the library, and the similarity scores
27973 X          calculated.  This option can be used to evaluate the
27974 X          sensitivity and selectivity of different search
27975 X          strategies (see W. R. Pearson (1991) Genomics 11:635-
27976 X          650.)
27977 X
27978 -s file   SMATRIX is read from file.  Several SMATRIX files are
27979 X          provided with the standard distribution.  For protein
27980 X          sequences: codaa.mat - based on minimum mutation
27981 X          matrix; idnaa.mat - identity matrix; pam250.mat - the
27982 X          PAM250 matrix developed by Dayhoff et al (Atlas of
27983 X          Protein Sequence and Structure, vol. 5, suppl. 3,
27984 X          1978); pam120.mat - a PAM120 matrix.  The default
27985 X          scoring matrix is BLOSUM50, PAM250 is available with
27986 X          "-s 250", BLOSUM62 ("-s BL62") is also available.
27987 X
27988 -v        (LINEVAL) values used for line styles in plfasta
27989 X
27990 -w #      Line length (width) = number (<200)
27991 X
27992 -x        Specifies offsets for the beginning of the query and
27993 X          library sequence.  For example, if you are comparing
27994 X          upstream regions for two genes, and the first sequence
27995 X          contains 500 nt of upstream sequence while the second
27996 X          contains 300 nt of upstream sequence, you might try:
27997 X
27998 X              fasta -x "-500 -300" seq1.nt seq2.nt
27999 X
28000 X          If the -x option is not used, FASTA assumes numbering
28001 X          starts with 1.  This option will not work properly with
28002 X          the translated library sequence with tfasta.  (You
28003 X          should double check to be certain the negative
28004 X          numbering works properly.)
28005 X
28006 -y        Set the width of the band used for calculating
28007 X          "optimized" scores.  For proteins and ktup=2, the width
28008 X          is 16.  For proteins with ktup=1, the width is 32 by
28009 X          default.  For DNA the width is 16.
28010 X
28011 -z        Turn off statistical calculations.
28012 X
28013 -1        sort output by init1 score (as FASTP used to do).
28014 X
28015 -3        (TFASTA, TFASTX only) translate only three forward
28016 X          frames
28017 X
28018 X
28019 For example:
28020 X
28021 X    fasta -w 80 -a seq1.aa seq.aa
28022 X
28023 would compare the sequence in seq1.aa to that in seq2.aa and
28024 display the results with 80 residues on an output line, showing
28025 all of the residues in both sequences.  Be sure to enter the
28026 options before entering the file names, or just enter the options
28027 on the command line, and the program will prompt for the file
28028 names.
28029 X
28030 X     Not all of these options are appropriate for all of the
28031 programs.  The options above are used by FASTA and TFASTA. RELATE
28032 uses the -s option, ALIGN uses the -w, -m, and -s options, and
28033 the PRDF program uses -c, -f, -k, and -s.
28034 X
28035 4.  Environment variable summary
28036 X
28037 X     Environment variables allow you to set search parameters
28038 that will be used frequently when you run a program; for example,
28039 if you prefer to use the PAM250 scoring matrix, you might "set
28040 SMATRIX=250."  Command line parameters, if used, always override
28041 environment variable settings. The following environment
28042 variables are used by this program:
28043 X
28044 AABANK    the file name  of the default sequence library.
28045 X
28046 FASTLIBS  the location of the file which contains the list of
28047 X          library files to be searched.
28048 X
28049 GAPCUT    threshold used for joining init1 regions in the second
28050 X          step of FASTA.  Normally set based on sequence length
28051 X          and ktup.
28052 X
28053 LIBTYPE   used to specify the format of the library sequence for
28054 X          FASTA and TFASTA.
28055 X
28056 LINLEN    output line length - can go up to 200
28057 X
28058 LINEVAL   used by plfasta to determine the relationship between
28059 X          line style and similarity score (-v).  This should be a
28060 X          string of three numbers, e.g.  "200 100 50"
28061 X
28062 MARKX     symbol for denoting matches, mismatches. Note that this
28063 X          symbol is only used across the optimized local region;
28064 X          sequences that are outside this region are not marked.
28065 X
28066 OPTCUT    Set the threshold to be used for optimization in a band
28067 X          around the best initial region.  Normally the OPTCUT
28068 X          value is calculated from the length of the sequence and
28069 X          the ktup value (for a 200 residue sequence, it is about
28070 X          28).  If OPTCUT=1, every sequence in the database will
28071 X          be optimized.  This is the most sensitive option.
28072 X
28073 PAMFACT   This version of fasta uses a more sensitive method for
28074 X          identifying initial regions. Instead of using a
28075 X          constant factor (fact) for each match in a ktup, it
28076 X          uses the scoring matrix (PAM) scores.  While this works
28077 X          well for protein sequences, it has not been as
28078 X          carefully tested for DNA sequences, so by default, this
28079 X          modification is used for proteins but not for DNA.
28080 X          Setting the PAMFACT environment variable to 1 forces
28081 X          the option on; PAMFACT=0 turns it off.
28082 X
28083 SHOWALL   on output, show the complete sequence instead of just
28084 X          the overlap of the two aligned sequences.
28085 X
28086 SMATRIX   alternative scoring matrix file.
28087 X
28088 TEKPLOT   (IBM-PC only, Unix and VMS versions generate Tektronix
28089 X          graphics by default) Generate Tektronix output.
28090 X          Normally, PLFASTA and TGREASE plot graphs using the
28091 X          Turbo C graphics library.  Unfortunately, often these
28092 X          plots cannot be printed out without special programs.
28093 X          However, if you set TEKPLOT=1, tektronix graphics
28094 X          commands will be used.  Tektronix commands can be used
28095 X          together with the PLOTDEV program, available from
28096 X          Microplot Systems.  They no lonter sell this program,
28097 X          but it can be downloaded from
28098 X          http://iquest.com/~microplt/index1.html.  PLOTDEV also
28099 X          allows you to print out graphics on the screen.
28100 X
28101 As always, please inform me of bugs as soon as possible.
28102 X
28103 William R. Pearson
28104 Department of Biochemistry
28105 Box 440, Jordan Hall
28106 U. of Virginia
28107 Charlottesville, VA
28108 X
28109 wrp@virginia.EDU
28110 SHAR_EOF
28111 chmod 0644 fasta20.doc ||
28112 echo 'restore of fasta20.doc failed'
28113 Wc_c="`wc -c < 'fasta20.doc'`"
28114 test 49762 -eq "$Wc_c" ||
28115         echo 'fasta20.doc: original size 49762, current size' "$Wc_c"
28116 fi
28117 # ============= fasta3.1 ==============
28118 if test -f 'fasta3.1' -a X"$1" != X"-c"; then
28119         echo 'x - skipping fasta3.1 (File already exists)'
28120 else
28121 echo 'x - extracting fasta3.1 (Text)'
28122 sed 's/^X//' << 'SHAR_EOF' > 'fasta3.1' &&
28123 .TH FASTA/TFASTA/FASTX/TFASTXv3 1 local
28124 .SH NAME
28125 fasta3, fasta3_t \- scan a protein or DNA sequence library for similar
28126 sequences
28127 X
28128 tfasta3, tfasta3_t \- compare a protein sequence to a DNA sequence
28129 library, translating the DNA sequence library `on-the-fly'.
28130 X
28131 fastx3, fastx3_t \ - compare a DNA sequence to a protein sequence
28132 database, comparing the translated DNA sequence in forward and
28133 reverse frames.
28134 X
28135 tfastx3, tfastx3_t \ - compare a protein sequence to a DNA sequence
28136 database, calculating similarities with frameshifts to the forward and
28137 reverse orientations.
28138 X
28139 fasty3, fasty3_t \ - compare a DNA sequence to a protein sequence
28140 database, comparing the translated DNA sequence in forward and reverse
28141 frames.
28142 X
28143 tfasty3, tfasty3_t \ - compare a protein sequence to a DNA sequence
28144 database, calculating similarities with frameshifts to the forward and
28145 reverse orientations.
28146 X
28147 fasts3, fasts3_t \- compare unordered peptides to a protein sequence database
28148 X
28149 tfasts3, tfasts3_t \- compare unordered peptides to a translated DNA
28150 sequence database
28151 X
28152 fastf3, fastf3_t \- compare mixed peptides to a protein sequence database
28153 X
28154 tfastf3, tfastf3_t \- compare mixed peptides to a translated DNA
28155 sequence database
28156 X
28157 ssearch3, ssearch3_t \- compare a protein or DNA sequence to a
28158 sequence database using the Smith-Waterman algorithm.
28159 X
28160 prss3, prfx3 \- estimate statistical significance of an alignment by
28161 comparing the score to the distribution of similarity scores generated
28162 by shuffling the second sequence.  prss3 uses Smith-Waterman.  prfx3
28163 uses the fastx algorithm.
28164 X
28165 .SH DESCRIPTION
28166 X
28167 Release 3.x of the FASTA package provides a modular set of sequence
28168 comparison programs that can run on conventional single processor
28169 computers or in parallel on multiprocessor computers. Seven different
28170 programs \- fasta3, fastx3, fasty3, tfastx3, tfasty3, tfasta3, and
28171 ssearch3 \- are currently available.
28172 X
28173 All of the comparison programs share a set of basic command line
28174 options; additional options are available for individual comparison
28175 functions.
28176 X
28177 The fasta3_t, fastx3_t, fasty3_t, tfasta3_t, tfastx3_t, tfasty3_t and
28178 ssearch3_t programs are threaded versions that will run in parallel on
28179 Digital Equipment, Sun, and SGI multiprocessor computers.
28180 X
28181 .SH Options for comparison functions
28182 .LP
28183 These versions of the fasta programs have been modified to accept a
28184 query sequence from the unix "stdin" data stream.  This makes it much
28185 easier to use fasta3 and its relatives as part of a WWW page. To
28186 indicate that stdin is to be used, use "@" as the query
28187 sequence file name.  "@" can also be used to specify a
28188 subset of the query sequence to be used, e.g:
28189 .sp
28190 .ti 0.5i
28191 cat query.aa | fasta3 -q @:50-150 s
28192 .sp
28193 would search the 's' database with residues 50-150 of query.aa.  FASTA
28194 cannot automatically detect the sequence type (protein vs DNA) when
28195 "stdin" is used, so the '-n' option is required for DNA.
28196 .TP
28197 \-1
28198 Sort by "init1" score.
28199 .TP
28200 \-3
28201 (TFASTA3, TFASTX/Y3 only) use only forward frame translations
28202 .TP
28203 \-a #
28204 "SHOWALL" option attempts to align all of both sequences in FASTA and SSEARCH.
28205 .TP
28206 \-A
28207 force Smith-Waterman alignment for output.  Smith-Waterman is the
28208 default for protein sequences and FASTX3, but not for TFASTA3 or DNA
28209 comparisons with FASTA3.
28210 .TP
28211 \-b #
28212 number of best scores to show (must be < -E cutoff if -E is given)
28213 .TP
28214 \-B
28215 show z-scores rather than bit scores
28216 .TP
28217 \-c #
28218 threshold for band optimization (FASTA, FASTX)
28219 .TP
28220 \-C #
28221 (fasta34t11d4) length of name abbreviation in alignments, default = 6.
28222 .TP
28223 \-d #
28224 number of best alignments to show ( must be < -e cutoff)
28225 .TP
28226 \-D
28227 turn on debugging mode.  Enables checks on sequence alphabet that
28228 cause problems with tfastx3, tfasty3, tfasta3.
28229 .TP
28230 \-E #
28231 expectation value upper limit for score and alignment display.
28232 Defaults are 10.0 for FASTA3 and SSEARCH3 protein searches, 5.0 for
28233 translated DNA/protein comparisons, and 2.0 for DNA/DNA searches.
28234 .TP
28235 \-f #
28236 penalty for opening a gap (or first residue for older versions)
28237 .TP
28238 \-F #
28239 expectation value lower limit for score and alignment display.
28240 -F 1e-6 prevents library sequences with E()-values lower than 1e-6
28241 from being displayed. This allows the use to focus on more distant
28242 relationships.
28243 .TP
28244 \-g #
28245 penalty for additional residues in a gap
28246 .TP
28247 \-h #
28248 (FASTX3, TFASTX3, FASTY3, TFASTY3 only) penalty for a frameshift between
28249 two codons.
28250 .TP
28251 \-j #
28252 (FASTY3, TFASTY3 only) penalty for a frameshift within a codon.
28253 .TP
28254 \-H
28255 turn off histogram display
28256 .TP
28257 \-i
28258 (DNA only) reverse complement the query sequence. (TFASTX) compare against
28259 only the reverse complement of the library sequence.
28260 .TP
28261 \-l str
28262 specify FASTLIBS file
28263 .TP
28264 \-L
28265 report long sequence description in alignments
28266 .TP
28267 \-m 0,1,2,3,4,5,6,9,10 alignment display options.  \fC-m 0, 1, 2, 3\fP
28268 display different types of alignments.  \fC-m 4\fP provides an
28269 alignment "map" on the query. \fC-m 5\fP combines the alignment map
28270 and a \fC-m 0\fP alignment.  \fC-m 6\fP provides an HTML output.
28271 \fC-m 9\fP does not change the alignment output, but provides
28272 alignment coordinate and percent identity information with the best
28273 scores report.  \fC-m 9c\fP adds encoded alignment information to the
28274 \fC-m 9\fP; \fC-m 9i\fP provides only percent identity and alignment
28275 length information with the best scores.  With current versions of the
28276 FASTA programs, independent \fC-m\fP options can be combined;
28277 e.g. \fC-m 1 -m 9c -m 6\fP.
28278 .TP
28279 \-M #-#
28280 molecular weight (residue) cutoffs.  -M "101-200" examines only sequences that are 101-200 residues long.
28281 .TP
28282 \-n
28283 force query to nucleotide sequence
28284 .TP
28285 \-N #
28286 break long library sequences into blocks of # residues.  Useful for
28287 bacterial genomes, which have only one sequence entry.  -N 2000 works
28288 well for well for bacterial genomes.
28289 .TP
28290 \-o
28291 (FASTA) turn fasta band optimization off during initial phase.  This was
28292 the behavior of fasta1.x versions.
28293 .TP
28294 \-O file
28295 send output to file
28296 .TP
28297 \-q/-Q
28298 quiet option; do not prompt for input
28299 .TP
28300 \-r "+n/-m" 
28301 values for match/mismatch for DNA comparisons. \fC+n\fP is
28302 used for the maximum positive value and \fC-m\fP is used for the
28303 maximum negative value. Values between max and min, are rescaled, but
28304 residue pairs having the value -1 continue to be -1.
28305 .TP 
28306 \-R file
28307 save all scores to statistics file (previously -r file)
28308 .TP
28309 \-s name
28310 specify substitution matrix.  BLOSUM50 is used by default;
28311 PAM250, PAM120, and BLOSUM62 can be specified by setting -s P120,
28312 P250, or BL62.  With this version, many more scoring matrices are
28313 available, including BLOSUM80 (BL80), and MDM10, MDM20, MDM40 (Jones,
28314 Taylor, and Thornton, 1992 CABIOS 8:275-282; specified as -s M10, -s
28315 M20, -s M40). Alternatively, BLASTP1.4 format scoring matrix files can
28316 be specified.  BL80, BL62, and P120 are scaled in 1/2 bit units; all
28317 the other matrices use 1/3 bit units.  DNA scoring matrices can also
28318 be specified with the "-r" option.
28319 .TP
28320 \-S
28321 treat lower case letters in the query or database as low complexity
28322 regions that are equivalent to 'X' during the initial database scan,
28323 but are treated as normal residues for the final alignment display.
28324 Statistical estimates are based on the 'X'ed out sequence used during
28325 the initial search. Protein databases (and query sequences) can be
28326 generated in the appropriate format using John Wooton's "pseg"
28327 program, available from ftp://ncbi.nlm.nih.gov/pub/seg/pseg.  Once you
28328 have compiled the "pseg" program, use the command:
28329 .IP
28330 \fCpseg database.fasta -z 1 -q  > database.lc_seg\fP
28331 .TP
28332 \-t #
28333 Translation table - tfasta3, fastx3, tfastx3, fasty3, and
28334 tfasty3 now support the BLAST tranlation tables.  See
28335 \fChttp://www.ncbi.nlm.nih.gov/Taxonomy/Utils/wprintgc.cgi\fP.
28336 .IP
28337 In addition, "\-t t" or "\-t t#" turns on the addition of an implicit termination
28338 codon to a protein:translated DNA match.  That is, each protein
28339 sequence implicitly ends with "*", which matches the termination codes
28340 for the appropriate genetic code.  "\-t t#" sets implicit termination
28341 and a different genetic code.
28342 .TP
28343 \-T #
28344 (threaded, parallel only) number of threads or workers to use (set by
28345 default to 4 at compile time).
28346 .TP
28347 \-U
28348 Do RNA sequence comparisons: treat 'T' as 'U', allow G:U base pairs (by 
28349 scoring "G-A" and "T-C" as "G-G" -1).  Search only one strand.
28350 .TP
28351 \-V "?$%*"
28352 Allow special annotation characters in query sequence.  These characters
28353 will be displayed in the alignments on the coordinate number line.
28354 .TP
28355 \-w # line width for similarity score, sequence alignment, output.
28356 .TP
28357 \-W # context length (default is 1/2 of line width -w) for alignment,
28358 like fasta and ssearch, that provide additional sequence context.
28359 .TP
28360 \-x #match,#mismatch
28361 scores used for matches to 'X:X','N:N', '*:*' matches, and the corresponding
28362 'X:not-X', etc, mismatches, overriding the values
28363 specified in the scoring matrix.  If only one value is given, it is
28364 used for both values.
28365 .TP
28366 \-X "#,#"
28367 offsets query, library sequence for numbering alignments
28368 .TP
28369 \-y #
28370 Width for band optimization; by default 16 for DNA and protein ktup=2;
28371 32 for protein ktup=1;
28372 .TP
28373 \-z #
28374 Specify statistical calculation. Default is -z 1, which uses
28375 regression against the length of the library sequence. -z 0 disables
28376 statistics.  -z 2 provides maximum likelihood estimates for lambda and K,
28377 censoring the 250 lowest and 250 highest scores. -z 3 uses Altschul
28378 and Gish's statistical estimates for specific protein BLOSUM scoring
28379 matrices and gap penalties. -z 4,5: an alternate regression method.
28380 \-z 6 uses a composition based maximum likelihood estimate based
28381 on the method of Mott (1992) Bull. Math. Biol. 54:59-75.
28382 -z 11,12,14,15,16: compute the regression against scores of randomly
28383 shuffled copies of the library sequences.  Twice as many comparisons
28384 are performed, but accurate estimates can be generated from databases
28385 of related sequences. -z 11 uses the -z 1 regression strategy, etc.
28386 .TP
28387 \-Z db_size
28388 Set the apparent database size used for expectation value calculations
28389 (used for protein/protein FASTA and SSEARCH, and for FASTX, FASTY, TFASTX,
28390 and TFASTY).
28391 .SH Environment variables:
28392 .TP
28393 FASTLIBS
28394 location of library choice file (-l FASTLIBS)
28395 .TP
28396 SMATRIX
28397 default scoring matrix (-s SMATRIX)
28398 .TP
28399 SRCH_URL
28400 the format string used to define the option to re-search the
28401 database.
28402 .TP
28403 REF_URL
28404 the format string used to define the option to lookup the library
28405 sequence in entrez, or some other database.
28406 X
28407 .SH AUTHOR
28408 Bill Pearson
28409 .br
28410 wrp@virginia.EDU
28411 SHAR_EOF
28412 chmod 0644 fasta3.1 ||
28413 echo 'restore of fasta3.1 failed'
28414 Wc_c="`wc -c < 'fasta3.1'`"
28415 test 10345 -eq "$Wc_c" ||
28416         echo 'fasta3.1: original size 10345, current size' "$Wc_c"
28417 fi
28418 # ============= fasta3.rsp ==============
28419 if test -f 'fasta3.rsp' -a X"$1" != X"-c"; then
28420         echo 'x - skipping fasta3.rsp (File already exists)'
28421 else
28422 echo 'x - extracting fasta3.rsp (Text)'
28423 sed 's/^X//' << 'SHAR_EOF' > 'fasta3.rsp' &&
28424 compacc.obj doinit.obj showbest.obj htime.obj apam.obj karlin.obj scaleswn.obj c_dispn.obj lib_sel.obj url_subs.obj nrand.obj getopt.obj regetlib.obj lgetlib.obj ncbl2_mlib.obj
28425 SHAR_EOF
28426 chmod 0644 fasta3.rsp ||
28427 echo 'restore of fasta3.rsp failed'
28428 Wc_c="`wc -c < 'fasta3.rsp'`"
28429 test 177 -eq "$Wc_c" ||
28430         echo 'fasta3.rsp: original size 177, current size' "$Wc_c"
28431 fi
28432 # ============= fasta3x.doc ==============
28433 if test -f 'fasta3x.doc' -a X"$1" != X"-c"; then
28434         echo 'x - skipping fasta3x.doc (File already exists)'
28435 else
28436 echo 'x - extracting fasta3x.doc (Text)'
28437 sed 's/^X//' << 'SHAR_EOF' > 'fasta3x.doc' &&
28438 (Updated December, 2003)
28439 X
28440 X
28441 X                        COPYRIGHT NOTICE
28442 X
28443 Copyright 1988, 1991, 1992, 1994, 1995, 1996, 1999 by William R.
28444 Pearson and the University of Virginia.  All rights reserved. The
28445 FASTA program and documentation may not be sold or incorporated
28446 into a commercial product, in whole or in part, without written
28447 consent of William R. Pearson and the University of Virginia.
28448 For further information regarding permission for use or
28449 reproduction, please contact: David Hudson, Assistant Provost for
28450 Research, University of Virginia, P.O. Box 9025, Charlottesville,
28451 VA 22906-9025, (434) 924-6853
28452 X
28453 The FASTA program package
28454 X
28455 Introduction
28456 X
28457 X     This documentation describes the version 3 of the FASTA
28458 program package (see W. R. Pearson and D. J. Lipman (1988),
28459 "Improved Tools for Biological Sequence Analysis", PNAS
28460 85:2444-2448 (Pearson and Lipman, 1988); W. R.  Pearson (1996)
28461 "Effective protein sequence comparison" Meth. Enzymol.
28462 266:227-258 (Pearson, 1996); Pearson et. al. (1997) Genomics
28463 46:24-36 (Zhang et al., 1997);  Pearson, (1999) Meth. in
28464 Molecular Biology 132:185-219 (Pearson, 2000).  Version 3 of the
28465 FASTA packages contains many programs for searching DNA and
28466 protein databases and one program (prss3) for evaluating
28467 statistical significance from randomly shuffled sequences.
28468 Several additional analysis programs, including programs that
28469 produce local alignments, are available as part of version 2 of
28470 the FASTA package, which is still available.
28471 X
28472 X     This document is divided into three sections: (1) A summary
28473 overview of the programs in the FASTA3 package; (2) A guide to
28474 installing the programs and databases; (3) A guide to using the
28475 FASTA programs. The revision history of the programs can be found
28476 in the readme.v30..v34, files. The programs are easy to use, so
28477 if you are using them on a machine that is administered by
28478 someone else, you can skip section (2) and focus on (1) and (3)
28479 to learn how to use the programsIf you are installing the
28480 programs on your own machine, you will need to read section (2)
28481 carefully.
28482 X
28483 1.  An overview of the FASTA programs
28484 X
28485 X     Although there are a large number of programs in this
28486 package, they belong to three groups: (1) "Conventional" Library
28487 search programs: FASTA3, FASTX3, FASTY3, TFASTA3, TFASTX3,
28488 TFASTY3, SSEARCH3; (2) Programs for searching with short
28489 fragments: FASTS3, FASTF3, TFASTS3, TFASTF3; (3) Statistical
28490 significance: PRSS3.  Programs that start with fast search
28491 protein databases, while tfast programs search translated DNA
28492 databases.  Table I gives a brief description of the programs.
28493 X
28494 X
28495 X            Table I. Comparison programs in the FASTA3 package
28496 X
28497 ---------------------------------------------------------------------------
28498 fasta3             Compare  a  protein  sequence  to  a  protein  sequence
28499 X                   database  or  a DNA sequence to a DNA sequence database
28500 X                   using the FASTA algorithm  (Pearson  and  Lipman, 1988,
28501 X                   Pearson, 1996).   Search speed and selectivity are con-
28502 X                   trolled with the ktup(wordsize) parameter.  For protein
28503 X                   comparisons,  ktup = 2 by default; ktup =1 is more sen-
28504 X                   sitive but slower.  For DNA comparisons, ktup=6 by  de-
28505 X                   fault;  ktup=3  or  ktup=4 provides higher sensitivity;
28506 X                   ktup=1 should be used for oligonucleotides  (DNA  query
28507 X                   lengths < 20).
28508 X
28509 ssearch3           Compare  a  protein  sequence  to  a  protein  sequence
28510 X                   database or a DNA sequence to a DNA  sequence  database
28511 X                   using  the  Smith-Waterman  algorithm (Smith and Water-
28512 X                   man, 1981).  ssearch3 is  about  10-times  slower  than
28513 X                   FASTA3,  but  is more sensitive for full-length protein
28514 X                   sequence comparison.
28515 X
28516 fastx3/ fasty3     Compare a DNA sequence to a protein sequence  database,
28517 X                   by  comparing  the  translated  DNA  sequence  in three
28518 X                   frames and allowing gaps and frameshifts.  fastx3  uses
28519 X                   a  simpler, faster algorithm for alignments that allows
28520 X                   frameshifts only between codons; fasty3 is  slower  but
28521 X                   produces  better alignments with poor quality sequences
28522 X                   because frameshifts are allowed within codons.
28523 X
28524 tfastx3/ tfasty3   Compare a protein sequence to a DNA sequence  database,
28525 X                   calculating  similarities  with frameshifts to the for-
28526 X                   ward and reverse orientations.
28527 X
28528 tfasta3            Compare a protein sequence to a DNA sequence  database,
28529 X                   calculating similarities (without frameshifts) to the 3
28530 X                   forward and three reverse reading frames.  tfastx3  and
28531 X                   tfasty3 are preferred because they calculate similarity
28532 X                   over frameshifts.
28533 X
28534 fastf3/tfastf3     Compares an ordered peptide mixture, as  would  be  ob-
28535 X                   tained  by  Edman  degredation  of a CNBr cleavage of a
28536 X                   protein, against a  protein  (fastf)  or  DNA  (tfastf)
28537 X                   database.
28538 X
28539 fasts3/tfasts3     Compares  set  of  short peptide fragments, as would be
28540 X                   obtained from mass-spec. analysis of a protein, against
28541 X                   a protein (fasts) or DNA (tfasts) database.
28542 ---------------------------------------------------------------------------
28543 X
28544 2.  Installing FASTA and the sequence databases
28545 X
28546 2.1.  Obtaining the libraries
28547 X
28548 X     The FASTA program package does not include any protein or
28549 DNA sequence libraries.  Protein databases are available on CD-
28550 ROM from the PIR and EMBL (see below), or via anonymouse FTP from
28551 many different sources.  As this document is updated in the fall
28552 of 1999, no DNA databases are available on CD-ROM from the major
28553 sequence databases: Genbank at the National for Biotechnology
28554 Information (www.ncbi.nlm.nih.gov and ftp://ncbi.nlm.nih.gov) and
28555 EMBL at the European Bioinformatics Institute (www.ebi.ac.uk).
28556 However, the databases are available via anonymous FTP from both
28557 sites.
28558 X
28559 2.1.1.  The GENBANK DNA sequence library
28560 X
28561 X     Because of the large size of DNA databases, you will
28562 probably want to keep DNA databases in only one, or possibly two,
28563 formats.  The FASTA3 programs that search DNA databases - fasta3,
28564 tfastx/y3, and tfasta3 can read DNA databases in Genbank flatfile
28565 (not ASN.1), FASTA, GCG/compressed-binary, BLAST1.4 (pressdb),
28566 and BLAST2.0 (formatdb) formats, as well as EMBL format.  If you
28567 are also running the GCG suite of sequence analysis programs, you
28568 should use GCG/compressed-binary format or BLAST2.0 format for
28569 your fasta3 searches.  If not, BLAST2.0 is a good choice.  These
28570 files are considerably more compact than Genbank flat files, and
28571 are preferred.  The NCBI does not provide software for converting
28572 from Genbank flat files to Blast2.0 DNA databases, but you can
28573 use the Blast formatdb program to convert ASN.1 formated Genbank
28574 files, which are available from the NCBI ftp site.
28575 X
28576 X     The NCBI also provides the nr, swissprot, and several EST
28577 databases that are used by BLAST in FASTA format from:
28578 ftp://ncbi.nlm.nih.gov/blast/db.  These databases are updated
28579 nightly.
28580 X
28581 2.1.2.  The NBRF protein sequence library
28582 X
28583 X     You can obtain the PIR protein sequence database (Barker et
28584 al., 1998) from:
28585 X
28586 X    National  Biomedical Research Foundation
28587 X    Georgetown  University  Medical  Center
28588 X    3900 Reservoir Rd, N.W.
28589 X    Washington, D.C. 20007
28590 X
28591 or via ftp from nbrf.georgetown.edu or from the NCBI
28592 (ncbi.nlm.nih.gov/repository/PIR). The data in the ascii
28593 directory is in PIR Codata format, which is not widely used.  I
28594 recommend the PIR/VMS format data (libtype=5) in the vms
28595 directory.
28596 X
28597 2.1.3.  The EBI/EMBL CD-ROM libraries
28598 X
28599 X     The European Bioinformatics Institute (EBI) distributes both
28600 the EMBL DNA database and the SwissProt database on CD-ROM
28601 (Bairoch and Apweiler, 1996), and they are available from:
28602 X
28603 X    EMBL-Outstation  European Bioinformatics Institute
28604 X    Wellcome Trust Genome Campus,
28605 X    Hinxton Hall
28606 X    Hinxton,
28607 X    Cambridge CB10 1SD
28608 X    United Kingdom
28609 X    Tel: +44 (0)1223 494444
28610 X    Fax: +44 (0)1223 494468
28611 X    Email: DATALIB@ebi.ac.uk
28612 X
28613 In addition, the SWISS-PROT protein sequence database is
28614 available via anonymous FTP from
28615 ftp://ftp.expasy.ch/databases/swiss-prot/ (also see
28616 www.expasy.ch).
28617 X
28618 2.2.  Finding the libraries: FASTLIBS
28619 X
28620 X     The major problem that most new users of the FASTA package
28621 have is in setting up the program to find the databases and their
28622 library type.  In general, if you cannot get fasta3 to read a
28623 sequence database, it is likely that something is wrong with the
28624 FASTLIBS file.  A common problem is that the database file is
28625 found, but either no sequences are read, or an incorrect number
28626 of entries is read.  This is almost always because the library
28627 format (libtype) is incorrect.  Note that a type 5 file (PIR/VMS
28628 format) can be read as a type 0 (default FASTA) format file, and
28629 the number of entries will be correct, but the sequence lengths
28630 will not.
28631 X
28632 X     All the search programs in the FASTA3 package use the
28633 environment variable FASTLIBS to find the protein and DNA
28634 sequence libraries.  The FASTLIBS variable contains the name of a
28635 file that has the actual filenames of the libraries.  The
28636 fastlibs file included with the distribution on is an example of
28637 a file that can be referred to by FASTLIBS. To use the fastlibs
28638 file, type:
28639 X
28640 X    setenv FASTLIBS /usr/lib/fasta/fastgbs (BSD UNIX/csh)
28641 X    or
28642 X    export FASTLIBS=/usr/lib/fasta/fastgbs (SysV UNIX/ksh)
28643 X
28644 Then edit the fastlibs file to indicate where the protein and DNA
28645 sequence libraries can be found.  If you have a hard disk and
28646 your protein sequence library is kept in the file
28647 /usr/lib/aabank.lib and your Genbank DNA sequence library is kept
28648 in the directory: /usr/lib/genbank, then fastgbs might contain:
28649 X
28650 X    NBRF Protein$0P/usr/lib/seq/aabank.lib 0
28651 X    SWISS PROT 10$0S/usr/lib/vmspir/swiss.seq 5
28652 X    GB Primate$1P@/usr/lib/genbank/gpri.nam
28653 X    GB Rodent$1R@/usr/lib/genbank/grod.nam
28654 X    GB Mammal$1M@/usr/lib/genbank/gmammal.nam
28655 X    ^   1    ^^^^       4                   ^     ^
28656 X              23                             (5)
28657 X
28658 The first line of this file says that there is a copy of the NBRF
28659 protein sequence database (which is a protein database) that can
28660 be selected by typing "P" on the command line or when the
28661 database menu is presented in the file /usr/lib/seq/aabank.lib.
28662 X
28663 X     Note that there are 4 or 5 fields in the lines in fastgbs.
28664 The first field is the description of the library which will be
28665 displayed by FASTA; it ends with a '$'.  The second field (1
28666 character), is a 0 if the library is a protein library and 1 if
28667 it is a DNA library.  The third field (1 character) is the
28668 character to be typed to select the library.
28669 X
28670 X     The fourth field is the name of the library file.  In the
28671 example above, the /usr/lib/seq/aabank.lib file contains the
28672 entire protein sequence library.  However the DNA library file
28673 names are preceded by a '@', because these files (gpri.nam,
28674 grod.nam, gmammal.nam) do not contain the sequences; instead they
28675 contain the names of the files which contain the sequences.  This
28676 is done because the GENBANK DNA database is broken down in to a
28677 large number of smaller files.  In order to search the entire
28678 primate database, you must search more than a dozen files.
28679 X
28680 X     In addition, an optional fifth field can be used to specify
28681 the format of the library file.  Alternatively, you can specify
28682 the library format in a file of file names (a file preceded by an
28683 '@').  This field must be separated from the file name by a space
28684 character (' ') from the filename.  In the example above, the
28685 aabank.lib file is in Pearson/FASTA format, while the swiss.seq
28686 file is in PIR/VMS format (from the EMBL CD-ROM). Currently,
28687 FASTA can read the following formats:
28688 X
28689 X    0 Pearson/FASTA (>SEQID - comment/sequence)
28690 X    1 Uncompressed Genbank (LOCUS/DEFINITION/ORIGIN)
28691 X    2 NBRF CODATA (ENTRY/SEQUENCE)
28692 X    3 EMBL/SWISS-PROT (ID/DE/SQ)
28693 X    4 Intelligenetics (;comment/SEQID/sequence)
28694 X    5 NBRF/PIR VMS (>P1;SEQID/comment/sequence)
28695 X    6 GCG (version 8.0) Unix Protein and DNA (compressed)
28696 X    11 NCBI Blast1.3.2 format  (unix only)
28697 X    12 NCBI Blast2.0 format  (unix only, fasta32t08 or later)
28698 X
28699 In particular, this version will work with the EMBL and PIR VMS
28700 formats that are distributed on the EMBL CD-ROM. The latter
28701 format (PIR VMS) is much faster to search than EMBL format.  This
28702 release also works with the protein and DNA database formats
28703 created for the BLASTP and BLASTN programs by SETDB and PRESSDB
28704 and with the new NCBI search format.  If a library format is not
28705 specified, for example, because you are just comparing two
28706 sequences, Pearson/FASTA (format 0) is used by default. To
28707 specify a library type on the command line, add it to the library
28708 filename and surround the filename and library type in quotes:
28709 X
28710 X    fasta3 query.file "/seqdb/genbank/gbpri1.seq 1"
28711 X
28712 X     You can specify a group of library files by putting a '@'
28713 symbol before a file that contains a list of file names to be
28714 searched.  For example, if @gmam.nam is in the fastgbs file, the
28715 file "gmam.nam" might contain the lines:
28716 X
28717 X    </seqdb/genbank
28718 X    gbpri1.seq 1
28719 X    gbpri2.seq 1
28720 X    gbpri3.seq 1
28721 X    gbpri4.seq 1
28722 X    gbrod.seq 1
28723 X    gbmam.seq 1
28724 X
28725 In this case, the line beginning with a '<' indicates the
28726 directory the files will be found in.  The remaining lines name
28727 the actual sequence files.  So the first sequence file to be
28728 searched would be:
28729 X
28730 X    /usr/lib/genbank/gbpri.seq
28731 X
28732 The notation "<PIRNAQ:" might be used under the VAX/VMS operating
28733 system. Under UNIX, the trailing '/' is left off, so the library
28734 directory might be written as "</usr/seqlib".
28735 X
28736 X     The FASTA programs can search a database composed of
28737 different files in different sequence formats.  For example, you
28738 may wish to search the Genbank files (in GenBank flat file
28739 format) and the EMBL DNA sequence database on CD-ROM.  To do
28740 this, you simply list the names and filetypes of the files to be
28741 searched in a file of filenames.  For example, to search the
28742 mammalian portion of Genbank, the unannotated portion of Genbank,
28743 and the unannotated portion of the EMBL library, you could use
28744 the file:
28745 X
28746 X    </usr/lib/DNA
28747 X    gbpri.seq 1
28748 X    #  (this '#' causes the program to display the size of the library)
28749 X    gbrod.seq 1
28750 X    ...
28751 X    gbmam.seq 1
28752 X    ...
28753 X    gbuna.seq 1
28754 X    ...
28755 X    unanno.seq 5
28756 X    #
28757 X
28758 X    You do not need to include library format numbers if  you
28759 X    only use the Pearson/FASTA version of the PIR protein se-
28760 X    quence library.  If no library  type  is  specified,  the
28761 X    program assumes that type 0 is being used.
28762 X
28763 X     Test the setup by running FASTA.  Enter the sequence file
28764 'mgstm1.aa' when the program requests it (this file is included
28765 with the programs).  The program should then ask you to select a
28766 protein sequence library.  Alternatively, if you run the TFASTA
28767 program and use the mgstm1.aa query sequence, the program should
28768 show you a selection of DNA sequence libraries.  Once the fastgbs
28769 file has been set up correctly, you can set FASTLIBS=fastgbs in
28770 your AUTOEXEC.BAT file, and you will not need to remember where
28771 the libraries are kept or how they are named.
28772 X
28773 3.  Using the FASTA Package
28774 X
28775 3.1.  Overview
28776 X
28777 X     The FASTA sequence comparison programs all require similar
28778 information, the name of a query sequence file, a library file,
28779 and the ktup parameter.  All of the programs can accept arguments
28780 on the command line, or they will prompt for the file names and
28781 ktup value.
28782 X
28783 To use FASTA, simply type:
28784 X
28785 X    FASTA
28786 X    and you will be prompted for :
28787 X         the name of the test sequence file
28788 X         the name of the library file
28789 X         and whether you want ktup = 1 or 2. (or 1 to 6 for DNA sequences)
28790 X         (ktup of 2 is about 5 times faster than ktup = 1)
28791 X
28792 The program can also be run by typing
28793 X
28794 X    FASTA test.aa /lib/bigfile.lib ktup (1 or 2)
28795 X
28796 Included with the package are several test files.  To check to
28797 make certain that everything is working, you can try:
28798 X
28799 X    fasta musplfm.aa prot_test.lib
28800 X    and
28801 X    tfastx mgstm1.aa gst.nlib
28802 X
28803 3.2.  Sequence files
28804 X
28805 X     The fasta3 programs know about three kinds of sequence
28806 files: (1) plain sequence files - files that contain nothing but
28807 sequence residues - can only be used as query sequences. (2)
28808 FASTA format files.  These are the same as plain sequence files,
28809 each sequence is preceded by a comment line with a '>' in the
28810 first column. (3) distributed sequence libraries (this is a broad
28811 class that includes the NBRF/PIR VMS and blocked ascii formats,
28812 Genbank flat-file format, EMBL flat-file format, and
28813 Intelligenetics format.  All of the files that you create should
28814 be of type (1) or (2).  FASTA format files (ones with a '>' and
28815 comment before the sequence) are preferred, because they can be
28816 used as query or library sequence files by all of the programs.
28817 X
28818 X     I have included several sample test files, *.aa and *.seq as
28819 well as two small sequence libraries, prot_test.lib and gst.nlib.
28820 The first line may begin with a '>' by a comment.  Spaces and
28821 tabs (and anything else that is not an amino-acid code) are
28822 ignored.
28823 X
28824 X     Library files should have the form:
28825 X
28826 X    >Sequence name and identifier
28827 X    A F A S Y T .... actual sequence.
28828 X    F S S       .... second line of sequence.
28829 X    >Next sequence name and identifier
28830 X
28831 This is often referred to as "FASTA" or format.  You can build
28832 your own library by concatenating several sequence files.  Just
28833 be sure that each sequence is preceded by a line beginning with a
28834 '>' with a sequence name.
28835 X
28836 X     The test file should not have lines longer than 120
28837 characters, and sequences entered with word processors should use
28838 a document mode, with normal carriage returns at the end of
28839 lines.
28840 X
28841 X     A different format is required to specify the ordered
28842 peptide mixture for fastf3/tfastf3. For example:
28843 X
28844 X    >mgstm1
28845 X    MGCEN,
28846 X    MIDYP,
28847 X    MLLAY,
28848 X    MLLGY
28849 X
28850 indicates m in the first position of all three peptides (as from
28851 CNBr), G, I, L (twice) in the second position (first cycle),
28852 C,D,L (twice) in the third position, etc.  The commas (,) are
28853 required to indicate the number of fragments in the mixture, but
28854 there should be no comma after the last residue.
28855 X
28856 X     For the fasts3/tfasts3 program, the format is the same,
28857 except that there is no requirement for the peptides to be the
28858 same length.
28859 X
28860 4.  Statistical Significance
28861 X
28862 X     All the programs in the FASTA3 package attempt to calculate
28863 accurate estimates of the statistical significance of a match.
28864 For fasta3, ssearch3, and fastx3/y3, these estimates are very
28865 accurate (Pearson, 1998, Zhang et al., 1997)..  Altschul et al.
28866 (Altschul et al., 1994) provides an excellent review of the
28867 statistics of local similarity scores.  Local sequence similarity
28868 scores follow the extreme value distribution, so that P(s > x) =
28869 1 - exp(-exp(-lambda(x-u)) where u = ln(Kmn)/lambda and m,m are
28870 the lengths of the query and library sequence. This formula can
28871 be rewritten as: 1 - exp(-Kmn exp(-lambda x), which shows that
28872 the average score for an unrelated library sequence increases
28873 with the logarithm of the length of the library sequence.  The
28874 fasta3 programs use simple linear regression against the the log
28875 of the library sequence length to calculate a normalized "z-
28876 score" with mean 50, regardless of library sequence length, and
28877 variance 10. (Several other estimation methods are available with
28878 the -z option.) These z-scores can then be used with the extreme
28879 value distribution and the poisson distribution (to account for
28880 the fact that each library sequence comparison is an independent
28881 test) to calculate the number of library sequences to obtain a
28882 score greater than or equal to the score obtained in the search.
28883 The original idea and routines to do the linear regression on
28884 library sequence length were provided Phil Green, U. Washington.
28885 This version uses a slightly different strategy for fitting the
28886 data than those originally provided by Dr. Green.
28887 X
28888 X     The expected number of sequences is plotted in the histogram
28889 using an "*". Since the parameters for the extreme value
28890 distribution are not calculated directly from the distribution of
28891 similarity scores, the pattern of "*'s" in the histogram gives a
28892 qualitative view of how well the statistical theory fits the
28893 similarity scores calculated by the programs.  For fasta3, if
28894 optimized scores are calculated for each sequence in the database
28895 (the default), the agreement between the actual distribution of
28896 "z-scores" and the expected distribution based on the length
28897 dependence of the score and the extreme value distribution is
28898 usually very good.  Likewise, the distribution of ssearch3 Smith-
28899 Waterman scores typically agrees closely with the <actual
28900 distribution of "z-scores."  The agreement with unoptimized
28901 scores, ktup=2, is often not very good, with too many high
28902 scoring sequences and too few low scoring sequences compared with
28903 the predicted relationship between sequence length and similarity
28904 score.  In those cases, the expectation values may be
28905 overestimates.
28906 X
28907 X     With version 33t01, all the FASTA programs also report a
28908 "bit" score, which is equivalent to the bit score reported by
28909 BLAST2.  The FASTA33/BLAST2 bit score is calculated as: (lambda*S
28910 - ln K)/ln 2, where S is the raw similarity score, lambda and K
28911 are statistical parameters estimated from the distribution of
28912 unrelated sequence similarity scores.  The statistical
28913 signficance of a given bit score depends on the lengths of the
28914 query and library sequences and the size of the library, but a 1
28915 bit increase in score corresponds to a 2-fold reduction in
28916 expectation; a 10-bit increase implies 1000-fold lower
28917 expectation, etc.
28918 X
28919 X     The statistical routines assume that the library contains a
28920 large sample of unrelated sequences.  If this is not true, then
28921 statistical parameters can be estimated by using the -z 11-15,
28922 options.  -z options greater than 10 calculate a shuffled
28923 similarity score for each library sequence, in addition to the
28924 unshuffled score, and estimate the statistical parameters from
28925 the scores of the shuffled sequences.  If there are fewer than 20
28926 sequences in the library, the statistical calculations are not
28927 done.
28928 X
28929 X     For protein searches, library sequences with E() values <
28930 0.01 for searches of a 10,000 entry protein database are almost
28931 always homologous. Frequently sequences with E()-values from 1 -
28932 10 are related as well, but unrelated sequences ( 1 - 10 per
28933 search) will have scores in this renage as well. Remember,
28934 however, that these E() values also reflect differences between
28935 the amino acid composition of the query sequence and that of the
28936 "average" library sequence.  Thus, when searches are done with
28937 query sequences with "biased" amino-acid composition, unrelated
28938 sequences may have "significant" scores because of sequence bias.
28939 PRSS3 can address this problem by calculating similarity scores
28940 for random sequences with the same length and amino acid
28941 composition.
28942 X
28943 5.  Options
28944 X
28945 X     Command line options are available to change the scoring
28946 parameters and output display. Command line options must preceed
28947 other program arguments, such as the query and library file
28948 names.
28949 X
28950 5.1.  Command line options
28951 X
28952 -a   (fasta3, ssearch3 only) show both sequences in their
28953 X     entirety.
28954 X
28955 -A   force Smith-Waterman alignments for fasta3 DNA sequences.
28956 X     By default, only fasta3 protein sequence comparisons use
28957 X     Smith-Waterman alignments.
28958 X
28959 -B   Show normalized score as a z-score, rather than a bit-score
28960 X     in the list of best scores.
28961 X
28962 -b # Number of sequence scores to be shown on output.  In the
28963 X     absence of this option, fasta (and tfasta and ssearch)
28964 X     display all library sequences obtaining similarity scores
28965 X     with expectations less than 10.0 if optimized score are
28966 X     used, or 2.0 if they are not. The -b option can limit the
28967 X     display further, but it will not cause additional sequences
28968 X     to be displayed.
28969 X
28970 -c # Threshold score for optimization (OPTCUT).  Set "-c 1" to
28971 X     optimize every sequence in a database.
28972 X
28973 -E # Limit the number of scores and alignments shown based on the
28974 X     expected number of scores.  Used to override the expectation
28975 X     value of 10.0 used by default.  When used with -Q, -E 2.0
28976 X     will show all library sequences with scores with an
28977 X     expectation value <= 2.0.
28978 X
28979 -d # Maximum number of alignments to be displayed.  Ignored if
28980 X     "-Q" is not used.
28981 X
28982 -f   Penalty for the first residue in a gap (-12 by default for
28983 X     proteins, -16 for DNA, -15 for FAST[XY]/TFAST[XY]).
28984 X
28985 -F # Limit the number of scores and alignments shown based on the
28986 X     expected number of scores. "-E #" sets the highest E()-value
28987 X     shown; "-F #" sets the lowest E()-value. Thus, "-F 0.0001"
28988 X     will not show any matches or alignments with E() < 0.0001.
28989 X     This allows one to skip over close relationships in searches
28990 X     for more distant relationships.
28991 X
28992 -g   Penalty for additional residues in a gap (-2 by default for
28993 X     proteins, -4 for DNA, -3 for FAST[XY]/TFAST[XY]).
28994 X
28995 -h   Penalty for frameshift (fastx3/y3, tfastx3/y3 only).
28996 X
28997 -H   Omit histogram.
28998 X
28999 -i   Invert (reverse complement) the query sequence if it is DNA.
29000 X     For tfasta3/x3/y3, search the reverse complement of the
29001 X     library sequence only.
29002 X
29003 -j # Penalty for frameshift within a codon (fasty3/tfasty3 only).
29004 X
29005 -l file
29006 X     Location of library menu file (FASTLIBS).
29007 X
29008 -L   Display more information about the library sequence in the
29009 X     alignment.
29010 X
29011 -M low-high
29012 X     Range of amino acid sequence lengths to be included in the
29013 X     search.
29014 X
29015 -m # Specify alignment type: 0, 1, 2, 3, 4, 5, 6, 9, 10
29016 X
29017 X             -m 0        -m 1          -m 2          -m 3        -m 4
29018 X         MWRTCGPPYT   MWRTCGPPYT    MWRTCGPPYT                 MWRTCGPPYT
29019 X         ::..:: :::     xx  X       ..KS..Y...    MWKSCGYPYT   ----------
29020 X         MWKSCGYPYT   MWKSCGYPYT
29021 X
29022 X     -m 5 provides a combination of -m 4 and -m 0. -m 6 provides
29023 X     -m 5 plus HTML formatting.
29024 X
29025 -m 9 provides coordinates and scores with the best score
29026 X     information.  A simple " -m 9 extends the normal best score
29027 X     information:
29028 X
29029 X         The best scores are:                                      opt bits E(14548)
29030 X         XURTG4 glutathione transferase (EC 2.5.1.18) 4 -   ( 219) 1248 291.7 1.1e-79
29031 X
29032 X     to include the additional information (on the same line,
29033 X     separated by a <tab>):
29034 X
29035 X         %_id  %_gid   sw  alen  an0  ax0  pn0  px0  an1  ax1 pn1 px1 gapq gapl  fs
29036 X         0.771 0.771 1248  218    1  218    1  218    1  218    1  219   0   0   0
29037 X
29038 X      -m 9c provides additional information: an encoded alignment
29039 X     string.  Thus:
29040 X
29041 X                10        20        30        40        50          60         70
29042 X         GT8.7  NVRGLTHPIRMLLEYTDSSYDEKRYTMGDAPDFDRSQWLNEKFKL--GLDFPNLPYL-IDGSHKITQ
29043 X                :.::  . :: ::  .   .:::         : .:    ::.:   .: : ..:.. :::  :..:
29044 X         XURTG  NARGRMECIRWLLAAAGVEFDEK---------FIQSPEDLEKLKKDGNLMFDQVPMVEIDG-MKLAQ
29045 X                        20        30                 40        50        60
29046 X
29047 X     would be encoded:
29048 X
29049 X         =23+9=13-2=10-1=3+1=5
29050 X
29051 X     The alignment encoding is with repect to the alignment, not
29052 X     the sequences.  The coordinate of the alignment is given
29053 X     earlier in the " -m 9c" line.
29054 X
29055 -m 10
29056 X     -m 10 is a new, parseable format for use with other
29057 X     programs.  See the file "readme.v20u4" for a more complete
29058 X     description.
29059 X
29060 X     As of version "fa34t23b2", it has become possible to combine
29061 X     independent "-m" options.  Thus, one can use "-m 1 -m 6 -m
29062 X     9".
29063 X
29064 -M low-high
29065 X     Include library sequences (proteins only) with lengths
29066 X     between low and high.
29067 X
29068 -n   Force the query sequence to be treated as a DNA sequence.
29069 X     This is particularly useful for query sequences that contain
29070 X     a large number of ambiguous residues, e.g. transcription
29071 X     factor binding sites.
29072 X
29073 -O   Send copy of results to "filename."  Helpful for
29074 X     environments without STDOUT (mostly for the Macintosh).
29075 X
29076 -o   Turn off default optimization of all scores greater than
29077 X     OPTCUT. Sort results by "initn" scores (reduces the accuracy
29078 X     of statistical estimates).
29079 X
29080 -p   Force query to be treated as protein sequence.
29081 X
29082 -Q,-q
29083 X     Quiet - does not prompt for any input.  Writes scores and
29084 X     alignments to the terminal or standard output file.
29085 X
29086 -r   Specify match/mismatch scores for DNA comparisons.  The
29087 X     default is "+5/-4". "+3/-2" can perform better in some
29088 X     cases.
29089 X
29090 -R file
29091 X     Save a results summary line for every sequence in the
29092 X     sequence library.  The summary line includes the sequence
29093 X     identifier, superfamily number (if available) position in
29094 X     the library, and the similarity scores calculated.  This
29095 X     option can be used to evaluate the sensitivity and
29096 X     selectivity of different search strategies (Pearson, 1995,
29097 X     Pearson, 1998).
29098 X
29099 -s file
29100 X     Specify the scoring matrix file.  fasta3 uses the same
29101 X     scoring matrices as Blast1.4/2.0.  Several scoring matrix
29102 X     files are included in the standard distribution.  For
29103 X     protein sequences: codaa.mat - based on minimum mutation
29104 X     matrix; idnaa.mat - identity matrix; pam250.mat - the PAM250
29105 X     matrix developed by Dayhoff et al. (Dayhoff et al., 1978);
29106 X     pam120.mat - a PAM120 matrix.  The default scoring matrix is
29107 X     BLOSUM50 ("-s BL50"). Other matrices available from within
29108 X     the program are: PAM250/"-s P250", PAM120/"-s P120",
29109 X     PAM40/"-s P40", PAM20/"-s P20", MDM10 - MDM40/"-s M10 - M40"
29110 X     (MDM are modern PAM matrices from Jones et al. (Jones et
29111 X     al., 1992),), BLOSUM50, 62, and 80/"-s BL50", "-s BL62", "-s
29112 X     BL80".
29113 X
29114 -S   Treat lower-case characters in the query or library
29115 X     sequences as "low-complexity" ("seg"-ed) residues.
29116 X     Traditionally, the "seg" program (Wootton and
29117 X     Federhen, 1993) is used to remove low complexity regions in
29118 X     DNA sequences by replacing the residues with an "X".  When
29119 X     the "-S" option is used, the FASTA33 programs provide a
29120 X     potentially more informative approach.  With "-S", lower
29121 X     case characters in the query or database sequences are
29122 X     treated as "X"'s during the initial scan, but are treated as
29123 X     normal residues during the final alignment display.  Since
29124 X     statistical significance is calculated from the similarity
29125 X     score calculated during the library search, when the lower
29126 X     case residues are "X"'s, low complexity regions will not
29127 X     produce statistically significant matches.  However, if a
29128 X     significant alignment contains low complexity regions, their
29129 X     alignmen is shown.  With "-S", lower case characters may be
29130 X     included in the alignment to indicate low complexity
29131 X     regions, and the final alignment score may be higher than
29132 X     the score obtained during the search.
29133 X
29134 X     The pseg program can be used to produce databases (or query
29135 X     sequences) with lower case residues indicating low
29136 X     complexity regions using the command:
29137 X
29138 X         pseg database.fasta -z 1 -q  > database.lc_seg
29139 X
29140 X     (seg can also be used with some post processing, see
29141 X     readme.v33tx.)
29142 X
29143 -U   Treat the query sequence an RNA sequence.  In addition to
29144 X     selecting a DNA/RNA alphabet, this option causes changes to
29145 X     the scoring matrix so that 'G:A' , 'T:C' or 'U:C' are scored
29146 X     as 'G:G'.
29147 X
29148 -V str
29149 X     It is now possible to specify some annotation characters
29150 X     that can be included (and will be ignored), in the query
29151 X     sequence file.  Thus, One might have a file with:
29152 X     "ACVS*ITRLFT?", where "*" and "?"  are used to indicate
29153 X     phosphorylation.  By giving the option -V '*?', those
29154 X     characters in the query will be moved to an "annotation
29155 X     string", and alignments that include the annotated residues
29156 X     will be highlighted with the appropriate character above the
29157 X     sequence (on the number line).
29158 X
29159 -w # Line length (width) = number (<200)
29160 X
29161 -W #  context length (default is 1/2 of line width -w) for
29162 X     alignment, like fasta and ssearch, that provide additional
29163 X     sequence context.
29164 X
29165 -x # Specify the penalty for a match to an 'X', independently of
29166 X     the PAM matrix.  Particularly useful for fastx3/fasty3,
29167 X     where termination codons are encoded as 'X'.
29168 X
29169 -X   Specifies offsets for the beginning of the query and library
29170 X     sequence.  For example, if you are comparing upstream
29171 X     regions for two genes, and the first sequence contains 500
29172 X     nt of upstream sequence while the second contains 300 nt of
29173 X     upstream sequence, you might try:
29174 X
29175 X         fasta -X "-500 -300" seq1.nt seq2.nt
29176 X
29177 X     If the -X option is not used, FASTA assumes numbering starts
29178 X     with 1.  (You should double check to be certain the negative
29179 X     numbering works properly.)
29180 X
29181 -y   Set the width of the band used for calculating "optimized"
29182 X     scores.  For proteins and ktup=2, the width is 16.  For
29183 X     proteins with ktup=1, the width is 32 by default.  For DNA
29184 X     the width is 16.
29185 X
29186 -z -1,0,1,2,3,4,5
29187 X     -z -1 turns off statistical calculations. z 0 estimates the
29188 X     significance of the match from the mean and standard
29189 X     deviation of the library scores, without correcting for
29190 X     library sequence length.  -z 1 (the default) uses a weighted
29191 X     regression of average score vs library sequence length; -z 2
29192 X     uses maximum likelihood estimates of Lambda and K; -z 3 uses
29193 X     Altschul-Gish parameters (Altschul and Gish, 1996); -z 4 - 5
29194 X     uses two variations on the -z 1 strategy. -z 1 and -z 2 are
29195 X     the best methods, in general.
29196 X
29197 -z 11,12,14,15
29198 X     estimate the statistical parameters from shuffled copies of
29199 X     each library sequence.  This doubles the time required for a
29200 X     search, but allows accurate statistics to be estimated for
29201 X     libraries comprised of a single protein family.
29202 X
29203 -Z db_size
29204 X     set the apparent size of the database to be used when
29205 X     calculating expectation E() values.  If you searched a
29206 X     database with 1,000 sequences, but would like to have the
29207 X     E()-values calculated in the context of a 100,000 sequence
29208 X     database, use '-Z 100000'.
29209 X
29210 -1   sort output by init1 score (for compatibility with FASTP -
29211 X     do not use).
29212 X
29213 -3   translate only three forward frames
29214 X
29215 For example:
29216 X
29217 X    fasta -w 80 -a seq1.aa seq.aa
29218 X
29219 would compare the sequence in seq1.aa to that in seq2.aa and
29220 display the results with 80 residues on an output line, showing
29221 all of the residues in both sequences.  Be sure to enter the
29222 options before entering the file names, or just enter the options
29223 on the command line, and the program will prompt for the file
29224 names.
29225 X
29226 X     (November, 1997) In addition, it is now possible to provide
29227 the fasta programs with the query sequence (fasta, fasty,
29228 ssearch, tfastx), or two sequences (prss, lalign, plalign) from
29229 the unix "stdin" stream.  This makes it much easier to set up
29230 FASTA or PRSS WWW pages.  To specify that stdin be used, rather
29231 than a file, the file name should be specified as '-' or '@' (the
29232 latter file name makes it possible to specify a subset of the
29233 sequence).  Thus:
29234 X
29235 X    cat query.aa | fasta -q @:25-75 s
29236 X
29237 would take residues 25-75 from query.aa and search the 's'
29238 library (see the discussion of FASTLIBS).
29239 X
29240 5.2.  Environment variables
29241 X
29242 X     Because the current version of the program allows the user
29243 to set virtually every option on the command line (except the
29244 ktup, which must be set as the third command line argument), only
29245 the FASTLIBS environment variable is routinely used.
29246 X
29247 FASTLIBS
29248 X     specifies the location of the file which contains the list
29249 X     of library descriptions, locations, and library types (see
29250 X     section on finding library files).
29251 X
29252 6.  Frequently Asked Questions
29253 X
29254 X (1)   Which program should I use? See Table I.
29255 X
29256 X (2)   How do I search with both DNA strands with fasta3 and
29257 X       fastx3? With version 32 of the FASTA program package, all
29258 X       searches that use DNA queries (e.g. fasta3, fastx3/y3)
29259 X       examine both strands. To revert to earlier FASTA behavior
29260 X       - only looking at the forward or reverse strand - use -3
29261 X       to search only the forward strand and -i -3 to search only
29262 X       the reverse strand.
29263 X
29264 X (3)   When I search Genbank - the program reports: 0 residues in
29265 X       0 sequences.  This typically happens because the program
29266 X       does not know that you are searching a Genbank flatfile
29267 X       database and is looking for a FASTA format database.  Be
29268 X       certain to specify the library type ("1" for Genbank
29269 X       flatfile) with the database name.
29270 X
29271 X (4)   What is the difference between fastx3 and fasty3 (or
29272 X       tfastx3 and tfasty3).  [t]fastx3 uses a simpler codon
29273 X       based model for alignments that does not allow frameshifts
29274 X       in some codon positions (see ref. (Zhang et al., 1997)).
29275 X       tfastx3 is about 30% faster, but tfasty3 can produce
29276 X       higher quality alignments in some cases.
29277 X
29278 X (5)   When I run fasta3 -q, I don't see any (or very little)
29279 X       output, but I get lots of scores when I run interactively.
29280 X       With the -Q option, the number of high scores displayed is
29281 X       limited by the -E # cutoff, which is 10.0 for protein
29282 X       comparisons, 2.0 for DNA comparisons, and 5.0 for
29283 X       translated DNA:protein comparisons.  In interactive mode
29284 X       (without -Q), by default you see 20 high scores,
29285 X       regardless of E() value.
29286 X
29287 X (6)   What is ktup - All of the programs with fast in their name
29288 X       use a computer science method called a lookup table to
29289 X       speed the search.  For proteins with ktup=2, this means
29290 X       that the program does not look at any sequence alignment
29291 X       that does not involve matching two identical residues in
29292 X       both sequences.  Likewise with DNA and ktup = 6, the
29293 X       initial alignment of the sequences looks for 6 identical
29294 X       adjacent nucleotides in both sequences.  Because it is
29295 X       less likely that two identical amino-acids will line up by
29296 X       chance in two unrelated proteins, this speeds up the
29297 X       comparison.  But very distantly related sequences may
29298 X       never have two identical residues in a row but will have
29299 X       single aligned identities.  In this case, ktup = 1 may
29300 X       find alignments that ktup=2 misses.
29301 X
29302 X (7)   Sometimes, in the list of best scores, the same sequence
29303 X       is shown twice with exactly the same score.  Sometimes,
29304 X       the sequence is there twice, but the scores are slightly
29305 X       different. When any of the fasta3 programs searches a long
29306 X       sequence, it breaks the sequence up into overlapping
29307 X       pieces.  The length of the piece depends on the length of
29308 X       the query and the particular program being used (it can
29309 X       also be controlled with the -N #### option).  Since the
29310 X       pieces overlap by the length of the query sequence (or
29311 X       3*query_length for fastx/y3 and tfasta/x/y3), if the
29312 X       highest scoring alignment is at the end of one piece, it
29313 X       will be scored again at the beginning of the next piece.
29314 X       If the alignment is not be completely included in the
29315 X       overlap region, one of the pieces will give a higher score
29316 X       than the other.  These duplications can be detected by
29317 X       looking at the coordinates of the alignment.  If either
29318 X       the beginning or end coordinate is identical in two
29319 X       alignments, the alignments are at least partially
29320 X       duplicates.
29321 X
29322 As always, please inform me of bugs as soon as possible.
29323 X
29324 William R. Pearson
29325 Department of Biochemistry
29326 Jordan Hall Box 800733
29327 U. of Virginia
29328 Charlottesville, VA
29329 X
29330 wrp@virginia.EDU
29331 X
29332 7.  References
29333 X
29334 Altschul, S. F., Boguski, M. S., Gish, W., and Wootton, J. C.
29335 (1994). Issues in searching molecular sequence databases. Nature
29336 Genet. 6,119-129.
29337 X
29338 Altschul, S. F. and Gish, W. (1996). Local alignment statistics.
29339 Methods Enzymol. 266,460-480.
29340 X
29341 Bairoch, A. and Apweiler, R. (1996). The Swiss-Prot protein
29342 sequence data bank and its new supplement TrEMBL. Nucleic Acids.
29343 Res. 24,21-25.
29344 X
29345 Barker, W. C., Garavelli, J. S., Haft, D. H., Hunt, L. T.,
29346 Marzec, C. R., Orcutt, B. C., Srinivasarao, G. Y., Yeh, L. S. L.,
29347 Ledley, R. S., Mewes, H. W., Pfeiffer, F., and Tsugita, A.
29348 (1998). The PIR-International Protein Sequence Database. Nucleic
29349 Acids Res 26,27-32.
29350 X
29351 Dayhoff, M., Schwartz, R. M., and Orcutt, B. C. (1978). A model
29352 of evolutionary change in proteins. In Atlas of Protein Sequence
29353 and Structure, vol. 5, supplement 3. M. Dayhoff, ed. (Silver
29354 Spring, MD: National Biomedical Research Foundation), pp.
29355 345-352.
29356 X
29357 Jones, D. T., Taylor, W. R., and Thornton, J. M. (1992). The
29358 rapid generation of mutation data matrices from protein
29359 sequences. Comp. Appl. Biosci. 8,275-282.
29360 X
29361 Pearson, W. R. (2000). Flexible similarity searching with the
29362 FASTA3 program package. In Bioinformatics Methods and Protocols,
29363 S. Misener and S. A. Krawetz, ed. (Totowa, NJ: Humana Press), pp.
29364 185-219.
29365 X
29366 Pearson, W. R. and Lipman, D. J. (1988). Improved tools for
29367 biological sequence comparison. Proc. Natl. Acad. Sci. USA
29368 85,2444-2448.
29369 X
29370 Pearson, W. R. (1995). Comparison of methods for searching
29371 protein sequence databases. Prot. Sci. 4,1145-1160.
29372 X
29373 Pearson, W. R. (1996). Effective protein sequence comparison.
29374 Methods Enzymol. 266,227-258.
29375 X
29376 Pearson, W. R. (1998). Empirical statistical estimates for
29377 sequence similarity searches. J. Mol. Biol. 276,71-84.
29378 X
29379 Smith, T. F. and Waterman, M. S. (1981). Identification of common
29380 molecular subsequences. J. Mol. Biol. 147,195-197.
29381 X
29382 Wootton, J. C. and Federhen, S. (1993). Statistics of local
29383 complexity in amino acid sequences and sequence databases.
29384 Comput. Chem. 17,149-163.
29385 X
29386 Zhang, Z., Pearson, W. R., and Miller, W. (1997). Aligning a DNA
29387 sequence with a protein sequence. J. Computational Biology
29388 4,339-349.
29389 X
29390 SHAR_EOF
29391 chmod 0644 fasta3x.doc ||
29392 echo 'restore of fasta3x.doc failed'
29393 Wc_c="`wc -c < 'fasta3x.doc'`"
29394 test 41617 -eq "$Wc_c" ||
29395         echo 'fasta3x.doc: original size 41617, current size' "$Wc_c"
29396 fi
29397 # ============= fasta3x.me ==============
29398 if test -f 'fasta3x.me' -a X"$1" != X"-c"; then
29399         echo 'x - skipping fasta3x.me (File already exists)'
29400 else
29401 echo 'x - extracting fasta3x.me (Text)'
29402 sed 's/^X//' << 'SHAR_EOF' > 'fasta3x.me' &&
29403 .nr pp 11
29404 .nr sp 11
29405 .nr tp 11
29406 .nr fp 10
29407 .nr fi 0n
29408 .sz 11
29409 .if t \{
29410 .po 1i
29411 .he 'FASTA3.DOC''Release 3.4, Fall, 2003'
29412 .fo ''- % -''
29413 \}
29414 .if n \{
29415 .po 0
29416 .na
29417 .nh
29418 \}
29419 .ll 6.5i
29420 .ce
29421 \fBCOPYRIGHT NOTICE\fP
29422 .lp
29423 Copyright 1988, 1991, 1992, 1994, 1995, 1996, 1999 by William
29424 R. Pearson and the University of Virginia.  All rights reserved. The
29425 FASTA program and documentation may not be sold or incorporated into a
29426 commercial product, in whole or in part, without written consent of
29427 William R. Pearson and the University of Virginia.  For further
29428 information regarding permission for use or reproduction, please
29429 contact: David Hudson, Assistant Provost for Research, University of
29430 Virginia, P.O. Box 9025, Charlottesville, VA 22906-9025, (434)
29431 924-6853
29432 .uh "\s+2The FASTA program package\s0"
29433 .uh "Introduction"
29434 .pp
29435 This documentation describes the version 3 of the FASTA program
29436 package (see W. R. Pearson and D. J. Lipman (1988), "Improved Tools
29437 for Biological Sequence Analysis", PNAS 85:2444-2448 [.wrp881.]; W. R.
29438 Pearson (1996) "Effective protein sequence comparison"
29439 Meth. Enzymol. 266:227-258;[.wrp960.] Pearson et. al. (1997) Genomics
29440 46:24-36;[.wrp971.]  Pearson, (1999) Meth. in Molecular Biology
29441 132:185-219.[.wrp000.]  Version 3 of the FASTA packages contains many
29442 programs for searching DNA and protein databases and one program
29443 (prss3) for evaluating statistical significance from randomly shuffled
29444 sequences.  Several additional analysis programs, including programs
29445 that produce local alignments, are available as part of version 2 of
29446 the FASTA package, which is still available.
29447 .pp
29448 This document is divided into three sections: (1) A summary overview of
29449 the programs in the FASTA3 package; (2) A guide to installing the
29450 programs and databases; (3) A guide to using the FASTA programs. The
29451 revision history of the programs can be found in the
29452 \fCreadme.v30..v34\fP, files. The programs are easy to use, so if
29453 you are using them on a machine that is administered by someone else,
29454 you can skip section (2) and focus on (1) and (3) to learn how to use
29455 the programsIf you are installing the programs on your own
29456 machine, you will need to read section (2) carefully.
29457 .sh 1 "An overview of the \f(CBFASTA\fP programs"
29458 .pp
29459 Although there are a large number of programs in this package, they
29460 belong to three groups: (1) 
29461 "Conventional" Library search programs:
29462 FASTA3, FASTX3, FASTY3, TFASTA3, TFASTX3, TFASTY3, SSEARCH3;
29463 (2)
29464 Programs for searching with short fragments:
29465 FASTS3, FASTF3, TFASTS3, TFASTF3;
29466 (3)
29467 Statistical significance: PRSS3.
29468 Programs that start with \f(CBfast\fP search protein
29469 databases, while \f(CBtfast\fP programs search translated DNA databases.
29470 Table I gives a brief description of the programs.
29471 .lp
29472 .(z
29473 .TS
29474 center;
29475 c s
29476 c s
29477 = =
29478 l lw(5.5i).
29479 \d\fBTable I. Comparison programs in the FASTA3 package\fP\u
29480 X
29481 \fCfasta3\fP    T{
29482 Compare a protein sequence to a protein sequence 
29483 database or a DNA sequence to a DNA sequence database using the FASTA 
29484 algorithm.[.wrp881,wrp960.]  Search speed and selectivity are 
29485 controlled with the \fIktup\fP(wordsize) parameter.  For protein 
29486 comparisons, \fIktup\fP = 2 by default; \fIktup\fP =1 is more sensitive 
29487 but slower.  For DNA comparisons, \fIktup\fP=6 by default; \fIktup\fP=3 or 
29488 \fIktup\fP=4 provides higher sensitivity; \fIktup\fP=1 should be used for 
29489 oligonucleotides (DNA query lengths < 20).
29490 T}
29491 X
29492 \fCssearch3\fP  T{
29493 Compare a protein sequence to a protein sequence 
29494 database or a DNA sequence to a DNA sequence database using the 
29495 Smith-Waterman algorithm.[.wat815.]  \fCssearch3\fP is about 10-times 
29496 slower than FASTA3, but is more sensitive for full-length protein 
29497 sequence comparison.
29498 T}
29499 X
29500 \fCfastx3\fP/ \fCfasty3\fP      T{
29501 Compare a DNA sequence to a protein
29502 sequence database, by comparing the translated DNA sequence in three
29503 frames and allowing gaps and frameshifts.  \fCfastx3\fP uses a
29504 simpler, faster algorithm for alignments that allows frameshifts only
29505 between codons; \fCfasty3\fP is slower but produces better alignments
29506 with poor quality sequences because frameshifts are allowed within
29507 codons.
29508 T}
29509 X
29510 \fCtfastx3\fP/ \fCtfasty3\fP    T{
29511 Compare a protein sequence to a DNA sequence
29512 database, calculating similarities with frameshifts to the forward and
29513 reverse orientations.
29514 T}
29515 X
29516 \fCtfasta3\fP   T{
29517 Compare a protein sequence to a DNA sequence database, calculating 
29518 similarities (without frameshifts) to the 3 forward and three reverse 
29519 reading frames.  \fCtfastx3\fP and \fCtfasty3\fP are preferred because 
29520 they calculate similarity over frameshifts.
29521 T}
29522 X
29523 \fCfastf3/tfastf3\fP    T{
29524 Compares an ordered peptide mixture, as would be obtained by
29525 Edman degredation of a CNBr cleavage of a protein, against a protein
29526 (\fCfastf\fP) or DNA (\fCtfastf\fP) database.
29527 T}
29528 X
29529 \fCfasts3/tfasts3\fP    T{
29530 Compares set of short peptide fragments, as would be obtained
29531 from mass-spec. analysis of a protein, against a
29532 protein (\fCfasts\fP) or DNA (\fCtfasts\fP) database.
29533 T}
29534 =       =
29535 .TE
29536 .)z
29537 .sh 1 "Installing FASTA and the sequence databases"
29538 .sh 2 "Obtaining the libraries"
29539 .pp
29540 The FASTA program package does not include any protein or DNA sequence
29541 libraries.  Protein databases are available on CD-ROM from the PIR and
29542 EMBL (see below), or via anonymouse FTP from many different sources.
29543 As this document is updated in the fall of 1999, no DNA databases are
29544 available on CD-ROM from the major sequence databases: Genbank at the
29545 National for Biotechnology Information (\fCwww.ncbi.nlm.nih.gov\fP and
29546 \fCftp://ncbi.nlm.nih.gov\fP) and EMBL at the European Bioinformatics
29547 Institute (\fCwww.ebi.ac.uk\fP). However, the databases are available
29548 via anonymous FTP from both sites.
29549 .sh 3 "The GENBANK DNA sequence library"
29550 .pp
29551 Because of the large size of DNA databases, you will probably want to
29552 keep DNA databases in only one, or possibly two, formats.  The FASTA3
29553 programs that search DNA databases - \fCfasta3\fP, \fCtfastx/y3\fP,
29554 and \fCtfasta3\fP can read DNA databases in Genbank flatfile (not
29555 ASN.1), FASTA, GCG/compressed-binary, BLAST1.4 (\fCpressdb\fP), and
29556 BLAST2.0 (\fCformatdb\fP) formats, as well as EMBL format.  If you are
29557 also running the GCG suite of sequence analysis programs, you should
29558 use GCG/compressed-binary format or BLAST2.0 format for your
29559 \fCfasta3\fP searches.  If not, BLAST2.0 is a good choice.  These
29560 files are considerably more compact than Genbank flat files, and are
29561 preferred.  The NCBI does not provide software for converting from
29562 Genbank flat files to Blast2.0 DNA databases, but you can use the
29563 Blast \fCformatdb\fP program to convert ASN.1 formated Genbank files,
29564 which are available from the NCBI \fCftp\fP site.
29565 .pp
29566 The NCBI also provides the \fCnr\fP, \fCswissprot\fP, and several EST
29567 databases that are used by BLAST in FASTA format from:
29568 \fCftp://ncbi.nlm.nih.gov/blast/db\fP.  These databases are updated
29569 nightly.
29570 .sh 3 "The NBRF protein sequence library"
29571 .pp
29572 You can obtain the PIR protein sequence database
29573 [.pir980.] from:
29574 .(l
29575 National  Biomedical Research Foundation
29576 Georgetown  University  Medical  Center
29577 3900 Reservoir Rd, N.W.
29578 Washington, D.C. 20007
29579 .)l
29580 or via ftp from \fCnbrf.georgetown.edu\fP or from the NCBI
29581 (\fCncbi.nlm.nih.gov/repository/PIR\fP). The data in the \fCascii\fP
29582 directory is in PIR Codata format, which is not widely used.  I
29583 recommend the PIR/VMS format data (libtype=5) in the \fCvms\fP
29584 directory.
29585 .sh 3 "The EBI/EMBL CD-ROM libraries"
29586 .pp
29587 The European Bioinformatics Institute (EBI) distributes both the EMBL
29588 DNA database and the SwissProt database on CD-ROM,[.apw961.] and they
29589 are available from:
29590 .(l
29591 EMBL-Outstation  European Bioinformatics Institute
29592 Wellcome Trust Genome Campus,
29593 Hinxton Hall
29594 Hinxton,
29595 Cambridge CB10 1SD
29596 United Kingdom
29597 Tel: +44 (0)1223 494444
29598 Fax: +44 (0)1223 494468
29599 Email: DATALIB@ebi.ac.uk
29600 .)l
29601 In addition, the SWISS-PROT protein sequence database is available via
29602 anonymous FTP from \fCftp://ftp.expasy.ch/databases/swiss-prot/\fP
29603 (also see \fCwww.expasy.ch\fP).
29604 .sh 2 "Finding the libraries: FASTLIBS"
29605 .pp
29606 The major problem that most new users of the FASTA package have is in
29607 setting up the program to find the databases and their library type.
29608 In general, if you cannot get \fCfasta3\fP to read a sequence
29609 database, it is likely that something is wrong with the \fCFASTLIBS\fP
29610 file.  A common problem is that the database file is found, but either
29611 no sequences are read, or an incorrect number of entries is read.
29612 This is almost always because the library format (\fClibtype\fP) is
29613 incorrect.  Note that a type 5 file (PIR/VMS format) can be read
29614 as a type 0 (default FASTA) format file, and the number of entries
29615 will be correct, but the sequence lengths will not.
29616 .pp
29617 All the search programs in the FASTA3 package use the environment
29618 variable \fCFASTLIBS\fP to find the protein and DNA sequence libraries.  The
29619 \fCFASTLIBS\fP variable contains the name of a file that has the actual
29620 filenames of the libraries.  The \fCfastlibs\fP file included with the
29621 distribution on is an example of a file that can be referred to by
29622 FASTLIBS. To use the \fCfastlibs\fP file, type:
29623 .(l
29624 \fCsetenv FASTLIBS /usr/lib/fasta/fastgbs\fP (BSD UNIX/csh)
29625 or
29626 \fCexport FASTLIBS=/usr/lib/fasta/fastgbs\fP (SysV UNIX/ksh)
29627 .)l
29628 Then edit the \fCfastlibs\fP file to indicate where the protein and DNA
29629 sequence libraries can be found.  If you have a hard disk and your
29630 protein sequence library is kept in the file \fC/usr/lib/aabank.lib\fP and
29631 your Genbank DNA sequence library is kept in the directory:
29632 \fC/usr/lib/genbank\fP, then \fCfastgbs\fP might contain:
29633 .ne 8
29634 .(l
29635 .ft C
29636 NBRF Protein$0P/usr/lib/seq/aabank.lib 0
29637 SWISS PROT 10$0S/usr/lib/vmspir/swiss.seq 5
29638 GB Primate$1P@/usr/lib/genbank/gpri.nam
29639 GB Rodent$1R@/usr/lib/genbank/grod.nam 
29640 GB Mammal$1M@/usr/lib/genbank/gmammal.nam
29641 ^   1    ^^^^       4                   ^     ^
29642 X          23                             (5)
29643 .ft R
29644 .)l
29645 The first line of this file says that there is a copy of the NBRF
29646 protein sequence database (which is a protein database) that can be
29647 selected by typing "P" on the command line or when the database menu
29648 is presented in the file \fC/usr/lib/seq/aabank.lib\fP.
29649 .pp
29650 Note that there are 4 or 5 fields in the lines in \fCfastgbs\fP.  The first
29651 field is the description of the library which will be displayed by
29652 FASTA; it ends with a '$'.  The second field (1 character), is a 0 if
29653 the library is a protein library and 1 if it is a DNA library.  The
29654 third field (1 character) is the character to be typed to select the
29655 library.
29656 .pp
29657 The fourth field is the name of the library file.  In the example
29658 above, the \fC/usr/lib/seq/aabank.lib\fP file contains the entire
29659 protein sequence library.  However the DNA library file names are
29660 preceded by a '@', because these files (\fCgpri.nam, grod.nam,
29661 gmammal.nam\fP) do not contain the sequences; instead they contain the names
29662 of the files which contain the sequences.  This is done because the
29663 GENBANK DNA database is broken down in to a large number of smaller
29664 files.  In order to search the entire primate database, you must
29665 search more than a dozen files.
29666 .pp
29667 In addition, an optional fifth field can be used to specify the format
29668 of the library file.  Alternatively, you can specify the library
29669 format in a file of file names (a file preceded by an '@').  This
29670 field must be separated from the file name by a space character ('\ ')
29671 from the filename.  In the example above, the \fCaabank.lib\fP file is
29672 in Pearson/FASTA format, while the \fCswiss.seq\fP file is in PIR/VMS format
29673 (from the EMBL CD-ROM). Currently, FASTA can read the following formats:
29674 .(l I
29675 .ft C
29676 0 Pearson/FASTA (>SEQID - comment/sequence)
29677 1 Uncompressed Genbank (LOCUS/DEFINITION/ORIGIN)
29678 2 NBRF CODATA (ENTRY/SEQUENCE)
29679 3 EMBL/SWISS-PROT (ID/DE/SQ)
29680 4 Intelligenetics (;comment/SEQID/sequence)
29681 5 NBRF/PIR VMS (>P1;SEQID/comment/sequence)
29682 6 GCG (version 8.0) Unix Protein and DNA (compressed)
29683 11 NCBI Blast1.3.2 format  (unix only)
29684 12 NCBI Blast2.0 format  (unix only, fasta32t08 or later)
29685 .ft R
29686 .)l
29687 In particular, this version will work with the EMBL and PIR VMS
29688 formats that are distributed on the EMBL CD-ROM. The latter format
29689 (PIR VMS) is much faster to search than EMBL format.  This release
29690 also works with the protein and DNA database formats created for the
29691 BLASTP and BLASTN programs by SETDB and PRESSDB and with the new NCBI
29692 search format.  If a library format is not specified, for example,
29693 because you are just comparing two sequences, Pearson/FASTA (format 0)
29694 is used by default. To specify a library type on the command line,
29695 add it to the library filename and surround the filename and library
29696 type in quotes:
29697 .(l
29698 .ft C
29699 fasta3 query.file "/seqdb/genbank/gbpri1.seq 1"
29700 .ft P
29701 .)l
29702 .pp
29703 You can specify a group of library files by putting a '@' symbol
29704 before a file that contains a list of file names to be searched.  For
29705 example, if @gmam.nam is in the fastgbs file, the file "gmam.nam"
29706 might contain the lines:
29707 .(l
29708 .ft C
29709 </seqdb/genbank
29710 gbpri1.seq 1
29711 gbpri2.seq 1
29712 gbpri3.seq 1
29713 gbpri4.seq 1
29714 gbrod.seq 1
29715 gbmam.seq 1
29716 .ft R
29717 .)l
29718 In this case, the line beginning with a '<' indicates the directory
29719 the files will be found in.  The remaining lines name the actual
29720 sequence files.  So the first sequence file to be searched would be:
29721 .(l
29722 .ft C
29723 /usr/lib/genbank/gbpri.seq
29724 .ft R
29725 .)l
29726 The notation "\fC<PIRNAQ:\fP" might be used under the VAX/VMS operating
29727 system. Under UNIX, the trailing '/' is left off, so the library
29728 directory might be written as "\fC</usr/seqlib\fP".
29729 .pp
29730 The FASTA programs can search a database composed of different files
29731 in different sequence formats.  For example, you may wish to search
29732 the Genbank files (in GenBank flat file format) and the EMBL DNA
29733 sequence database on CD-ROM.  To do this, you simply list the names
29734 and filetypes of the files to be searched in a file of filenames.  For
29735 example, to search the mammalian portion of Genbank, the unannotated
29736 portion of Genbank, and the unannotated portion of the EMBL library,
29737 you could use the file:
29738 .(l I
29739 .ft C
29740 </usr/lib/DNA
29741 gbpri.seq 1
29742 \&#  (this '#' causes the program to display the size of the library)
29743 gbrod.seq 1
29744 \&...
29745 gbmam.seq 1
29746 \&...
29747 gbuna.seq 1
29748 \&...
29749 unanno.seq 5
29750 \&#
29751 .ft R
29752 .)l
29753 .(l I F
29754 You do not need to include library format numbers if you only use the
29755 Pearson/FASTA version of the PIR protein sequence library.  If no
29756 library type is specified, the program assumes that type 0 is being
29757 used.
29758 .)l 
29759 .pp
29760 Test the setup by running FASTA.  Enter the sequence
29761 file '\fCmgstm1.aa\fP' when the program requests it (this file is
29762 included with the programs).  The program should then ask you to
29763 select a protein sequence library.  Alternatively, if you run the
29764 TFASTA program and use the mgstm1.aa query sequence, the program
29765 should show you a selection of DNA sequence libraries.
29766 Once the fastgbs file has been set up correctly, you can
29767 set FASTLIBS=fastgbs in your AUTOEXEC.BAT file, and you will not need to
29768 remember where the libraries are kept or how they are named.
29769 .ne 8
29770 .sh 1 "Using the FASTA Package"
29771 .sh 2 "Overview"
29772 .pp
29773 The FASTA sequence comparison programs all require similar
29774 information, the name of a query sequence file, a library file, and
29775 the \fIktup\fP parameter.  All of the programs can accept arguments
29776 on the command line, or they will prompt for the file names and
29777 \fIktup\fP value.
29778 .lp
29779 To use FASTA, simply type:
29780 .(l
29781 .ft C
29782 \f(CBFASTA\fP
29783 and you will be prompted for :
29784 .in +0.5i
29785 the name of the test sequence file
29786 the name of the library file
29787 and whether you want ktup = 1 or 2. (or 1 to 6 for DNA sequences)
29788 (ktup of 2 is about 5 times faster than ktup = 1)
29789 .ft R
29790 .)l
29791 The program can also be run by typing
29792 .(l
29793 .ft C
29794 FASTA test.aa /lib/bigfile.lib \fIktup\fP (1 or 2)
29795 .ft R
29796 .)l
29797 .lp
29798 Included with the package are several test files.
29799 To check to make certain that everything is working, you can try:
29800 .(l
29801 .ft C
29802 fasta musplfm.aa prot_test.lib
29803 and
29804 tfastx mgstm1.aa gst.nlib
29805 .ft R
29806 .)l
29807 .sh 2 "Sequence files"
29808 .pp
29809 The \fCfasta3\fP programs know about three kinds of sequence files:
29810 (1) plain sequence files - files that contain nothing but
29811 sequence residues - can only be used as query sequences. (2) FASTA
29812 format files.  These are the same as plain sequence files, each
29813 sequence is preceded by a comment line with a '>' in the first
29814 column. (3) distributed sequence libraries (this is a broad class that
29815 includes the NBRF/PIR VMS and blocked ascii formats, Genbank flat-file
29816 format, EMBL flat-file format, and Intelligenetics format.  All of the
29817 files that you create should be of type (1) or (2).  FASTA format
29818 files (ones with a '>' and comment before the sequence) are preferred,
29819 because they can be used as query or library sequence files by all of
29820 the programs.
29821 .pp
29822 I have included several sample test files, \fC*.aa\fP and \fC*.seq\fP
29823 as well as two small sequence libraries, \fCprot_test.lib\fP and
29824 \fCgst.nlib\fP.  The first line may begin with a '>' by a comment.
29825 Spaces and tabs (and anything else that is not an amino-acid code) are
29826 ignored.
29827 .pp
29828 Library files should have the form:
29829 .(l
29830 .ft C
29831 >Sequence name and identifier
29832 A F A S Y T .... actual sequence.
29833 F S S       .... second line of sequence.
29834 >Next sequence name and identifier
29835 .ft R
29836 .)l
29837 This is often referred to as "FASTA" or format.  You can
29838 build your own library by concatenating several sequence files.  Just
29839 be sure that each sequence is preceded by a line beginning with a '>'
29840 with a sequence name.
29841 .pp
29842 The test file should not have lines longer than 120 characters, and
29843 sequences entered with word processors should use a document
29844 mode, with normal carriage returns at the end of lines.
29845 .pp
29846 A different format is required to specify the ordered peptide mixture for \fCfastf3/tfastf3\fP. For example:
29847 .(l I
29848 .ft C
29849 >mgstm1
29850 MGCEN,
29851 MIDYP,
29852 MLLAY,
29853 MLLGY
29854 .ft P
29855 .)l
29856 indicates \fCm\fP in the first position of all three peptides (as
29857 from CNBr), \fCG, I, L\fP (twice) in the second position (first cycle),
29858 \fCC,D,L\fP (twice) in the third position, etc.  The commas (\fC,\fP)
29859 are required to indicate the number of fragments in the mixture, but
29860 there should be no comma after the last residue.
29861 .pp
29862 For the \fCfasts3/tfasts3\fP program, the format is the same, except that there
29863 is no requirement for the peptides to be the same length.
29864 .sh 1 "Statistical Significance"
29865 .pp
29866 All the programs in the FASTA3 package attempt to calculate accurate
29867 estimates of the statistical significance of a match. For
29868 \fCfasta3\fP, \fCssearch3\fP, and \fCfastx3/y3\fP, these estimates are
29869 very accurate.[.wrp971,wrp981.].  Altschul et al. [.alt940.] provides
29870 an excellent review of the statistics of local similarity scores.
29871 Local sequence similarity scores follow the extreme value
29872 distribution, so that P(s > x) = 1 - exp(-exp(-lambda(x-u)) where u =
29873 ln(Kmn)/lambda and m,m are the lengths of the query and library
29874 sequence. This formula can be rewritten as: 1 - exp(-Kmn exp(-lambda
29875 x), which shows that the average score for an unrelated library
29876 sequence increases with the logarithm of the length of the library
29877 sequence.  The \fCfasta3\fP programs use simple linear regression
29878 against the the log of the library sequence length to calculate a
29879 normalized "z-score" with mean 50, regardless of library sequence
29880 length, and variance 10. (Several other estimation methods are
29881 available with the \fC\-z\fP option.) These z-scores can then be used
29882 with the extreme value distribution and the poisson distribution (to
29883 account for the fact that each library sequence comparison is an
29884 independent test) to calculate the number of library sequences to
29885 obtain a score greater than or equal to the score obtained in the
29886 search. The original idea and routines to do the linear regression on
29887 library sequence length were provided Phil Green, U. Washington.  This
29888 version uses a slightly different strategy for fitting the data than
29889 those originally provided by Dr. Green.
29890 .pp
29891 The expected number of sequences is plotted in the histogram using an
29892 "*". Since the parameters for the extreme value distribution are not
29893 calculated directly from the distribution of similarity scores, the
29894 pattern of "*'s" in the histogram gives a qualitative view of how well
29895 the statistical theory fits the similarity scores calculated by the
29896 programs.  For \fCfasta3\fP, if optimized scores are calculated for
29897 each sequence in the database (the default), the agreement between the
29898 actual distribution of "z-scores" and the expected distribution based
29899 on the length dependence of the score and the extreme value
29900 distribution is usually very good.  Likewise, the distribution of
29901 \fCssearch3\fP Smith-Waterman scores typically agrees closely with the
29902 <actual distribution of "z-scores."  The agreement with unoptimized
29903 scores, \fIktup=2\fP, is often not very good, with too many high
29904 scoring sequences and too few low scoring sequences compared with the
29905 predicted relationship between sequence length and similarity score.
29906 In those cases, the expectation values may be overestimates.
29907 .pp
29908 With version 33t01, all the FASTA programs also report a "bit" score,
29909 which is equivalent to the bit score reported by BLAST2.  The
29910 FASTA33/BLAST2 bit score is calculated as: (lambda*S - ln K)/ln 2,
29911 where S is the raw similarity score, lambda and K are statistical
29912 parameters estimated from the distribution of unrelated sequence
29913 similarity scores.  The statistical signficance of a given bit score
29914 depends on the lengths of the query and library sequences and the size
29915 of the library, but a 1 bit increase in score corresponds to a 2-fold
29916 reduction in expectation; a 10-bit increase implies 1000-fold lower
29917 expectation, etc.
29918 .pp
29919 The statistical routines assume that the library contains a large
29920 sample of unrelated sequences.  If this is not true, then statistical
29921 parameters can be estimated by using the \fC\-z 11\-15\fP, options.
29922 \fC\-z\fP options greater than 10 calculate a shuffled similarity score
29923 for each library sequence, in addition to the unshuffled score, and
29924 estimate the statistical parameters from the scores of the shuffled
29925 sequences.  If there are fewer than 20 sequences in the library, the
29926 statistical calculations are not done.
29927 .pp
29928 For protein searches, library sequences with E() values < 0.01 for
29929 searches of a 10,000 entry protein database are almost always
29930 homologous. Frequently sequences with E()-values from 1 - 10 are
29931 related as well, but unrelated sequences ( 1 \- 10 per search) will
29932 have scores in this renage as well. Remember, however, that these E()
29933 values also reflect differences between the amino acid composition of
29934 the query sequence and that of the "average" library sequence.  Thus,
29935 when searches are done with query sequences with "biased" amino-acid
29936 composition, unrelated sequences may have "significant" scores because
29937 of sequence bias.  \fCPRSS3\fP can address this problem by calculating
29938 similarity scores for random sequences with the same length and amino
29939 acid composition. 
29940 .sh 1 "Options"
29941 .pp
29942 Command line options are available to change the scoring parameters
29943 and output display. \fBCommand line options must preceed other program
29944 arguments, such as the query and library file names.\fP
29945 .sh 2 "Command line options"
29946 .ip "-a"
29947 (fasta3, ssearch3 only) show both sequences in their entirety.
29948 .ip "-A"
29949 force Smith-Waterman alignments for fasta3 DNA sequences.  By default,
29950 only fasta3 protein sequence comparisons use Smith-Waterman alignments.
29951 .ip "-B"
29952 Show normalized score as a z-score, rather than a bit-score in the list
29953 of best scores.
29954 .ip "-b #"
29955 Number of sequence scores to be shown on output.  In the absence of
29956 this option, fasta (and tfasta and ssearch) display all library
29957 sequences obtaining similarity scores with expectations less than
29958 10.0 if optimized score are used, or 2.0 if they are not. The -b
29959 option can limit the display further, but it will not cause additional
29960 sequences to be displayed.
29961 .ip "-c #"
29962 Threshold score for optimization (OPTCUT).  Set "-c 1" to
29963 optimize every sequence in a database.
29964 .ip "-E #"
29965 Limit the number of scores and alignments shown based on the
29966 expected number of scores.  Used to override the expectation value of 10.0
29967 used by default.  When used with -Q, -E 2.0 will show all library sequences
29968 with scores with an expectation value <= 2.0.
29969 .ip "-d #"
29970 Maximum number of alignments to be displayed.  Ignored if "-Q" is not
29971 used.
29972 .ip "-f"
29973 Penalty for the first residue in a gap (-12 by default for proteins,
29974 -16 for DNA, -15 for FAST[XY]/TFAST[XY]).
29975 .ip "-F #"
29976 Limit the number of scores and alignments shown based on the expected
29977 number of scores. "-E #" sets the highest E()-value shown; "-F #" sets
29978 the lowest E()-value. Thus, "-F 0.0001" will not show any matches or
29979 alignments with E() < 0.0001.  This allows one to skip over close
29980 relationships in searches for more distant relationships.
29981 .ip "-g"
29982 Penalty for additional residues in a gap (-2 by default for proteins,
29983 -4 for DNA, -3 for FAST[XY]/TFAST[XY]).
29984 .ip "-h"
29985 Penalty for frameshift (fastx3/y3, tfastx3/y3 only).
29986 .ip "-H"
29987 Omit histogram.
29988 .ip "-i"
29989 Invert (reverse complement) the query sequence if it is DNA.  For
29990 tfasta3/x3/y3, search the reverse complement of the library sequence
29991 only.
29992 .ip "-j #"
29993 Penalty for frameshift within a codon (fasty3/tfasty3 only).
29994 .ip "-l file"
29995 Location of library menu file (FASTLIBS).
29996 .ip "-L"
29997 Display more information about the library sequence in the alignment.
29998 .ip "-M low-high"
29999 Range of amino acid sequence lengths to be included in the search.
30000 .ip "-m #"
30001 Specify alignment type: 0, 1, 2, 3, 4, 5, 6, 9, 10
30002 .(l I
30003 .ft C
30004 X    \-m 0        \-m 1          \-m 2          \-m 3        \-m 4
30005 .ft C
30006 MWRTCGPPYT   MWRTCGPPYT    MWRTCGPPYT                 MWRTCGPPYT
30007 ::..:: :::     xx  X       ..KS..Y...    MWKSCGYPYT   ----------
30008 MWKSCGYPYT   MWKSCGYPYT
30009 .ft P
30010 .)l
30011 .ip 
30012 \fC\-m 5\fP provides a combination of \fC\-m 4\fP and
30013 \fC\-m 0. \fC\-m 6 provides \fC\-m 5\fP plus HTML formatting.
30014 .ip "-m 9"
30015 provides coordinates and scores with the best score information.
30016 A simple "\fC -m 9\fP extends the normal best score information:
30017 .(l
30018 .ft C
30019 The best scores are:                                      opt bits E(14548)
30020 XXURTG4 glutathione transferase (EC 2.5.1.18) 4 -   ( 219) 1248 291.7 1.1e-79
30021 .ft P
30022 .)l
30023 to include the additional information (on the same line, separated by
30024 a <tab>):
30025 .(l
30026 .ft C
30027 %_id  %_gid   sw  alen  an0  ax0  pn0  px0  an1  ax1 pn1 px1 gapq gapl  fs
30028 0.771 0.771 1248  218    1  218    1  218    1  218    1  219   0   0   0
30029 .ft P
30030 .)l
30031 \fC -m 9c\fP provides additional information: an encoded alignment string.  Thus:
30032 .(l I
30033 .ft C
30034 X       10        20        30        40        50          60         70  
30035 GT8.7  NVRGLTHPIRMLLEYTDSSYDEKRYTMGDAPDFDRSQWLNEKFKL--GLDFPNLPYL-IDGSHKITQ
30036 X       :.::  . :: ::  .   .:::         : .:    ::.:   .: : ..:.. :::  :..:
30037 XXURTG  NARGRMECIRWLLAAAGVEFDEK---------FIQSPEDLEKLKKDGNLMFDQVPMVEIDG-MKLAQ
30038 X               20        30                 40        50        60        
30039 .ft P
30040 .)l
30041 would be encoded:
30042 .(l
30043 .ft C
30044 =23+9=13-2=10-1=3+1=5
30045 .ft P
30046 .)l
30047 The alignment encoding is with repect to the alignment, not the
30048 sequences.  The coordinate of the alignment is given earlier in the
30049 "\fC -m 9c\fP" line.
30050 .ip "-m 10"
30051 \fC\-m 10\fP is a new, parseable format for use
30052 with other programs.  See the file "readme.v20u4" for a more complete
30053 description. 
30054 .ip
30055 As of version "fa34t23b2", it has become possible to combine independent
30056 "\fC\-m\fP" options.  Thus, one can use "\fC\-m 1 -m 6 -m 9\fP".
30057 .ip "-M low\-high"
30058 Include library sequences (proteins only) with lengths between low and
30059 high.
30060 .ip "-n"
30061 Force the query sequence to be treated as a DNA sequence.  This is
30062 particularly useful for query sequences that contain a large number of
30063 ambiguous residues, e.g. transcription factor binding sites.
30064 .ip "-O"
30065 Send copy of results to "filename."  Helpful for environments without
30066 STDOUT (mostly for the Macintosh).
30067 .ip "-o "
30068 Turn off default optimization of all scores greater than OPTCUT. Sort
30069 results by "initn" scores (reduces the accuracy of statistical
30070 estimates).
30071 .ip "-p"
30072 Force query to be treated as protein sequence.
30073 .ip "-Q,-q"
30074 Quiet - does not prompt for any input.  Writes scores and alignments
30075 to the terminal or standard output file.
30076 .ip "-r"
30077 Specify match/mismatch scores for DNA comparisons.  The default is
30078 "+5/-4". "+3/-2" can perform better in some cases.
30079 .ip "-R file"
30080 Save a results summary line for every sequence in the sequence
30081 library.  The summary line includes the sequence identifier,
30082 superfamily number (if available) position 
30083 in the library, and the similarity scores calculated.  This option can
30084 be used to evaluate the sensitivity and selectivity of different
30085 search strategies.[.wrp951,wrp981.]
30086 .ip "-s file"
30087 Specify the scoring matrix file.  \fCfasta3\fP uses the same scoring
30088 matrices as Blast1.4/2.0.  Several scoring matrix files are included
30089 in the standard distribution.  For protein sequences: \fCcodaa.mat\fP
30090 - based on minimum mutation matrix; \fCidnaa.mat\fP - identity matrix;
30091 \fCpam250.mat\fP - the PAM250 matrix developed by Dayhoff et
30092 al.;[.day787.]  \fCpam120.mat\fP - a PAM120 matrix.  The default
30093 scoring matrix is BLOSUM50 ("-s BL50"). Other matrices available from
30094 within the program are: PAM250/"-s P250", PAM120/"-s P120", PAM40/"-s
30095 P40", PAM20/"-s P20", MDM10 - MDM40/"-s M10 \- M40" (MDM are modern
30096 PAM matrices from Jones et al.,[.tay925.]), BLOSUM50, 62, and 80/"-s
30097 BL50", "-s BL62", "-s BL80".
30098 .ip "-S"
30099 Treat lower-case characters in the query or library sequences as
30100 "low-complexity" ("seg"-ed) residues.  Traditionally, the "seg"
30101 program [.woo935.] is used to remove low complexity regions in DNA
30102 sequences by replacing the residues with an "X".  When the "-S" option
30103 is used, the FASTA33 (and later) programs provide a potentially more
30104 informative approach.  With "-S", lower case characters in the query
30105 or database sequences are treated as "X"'s during the initial scan,
30106 but are treated as normal residues during the final alignment display.
30107 Since statistical significance is calculated from the similarity score
30108 calculated during the library search, when the lower case residues are
30109 "X"'s, low complexity regions will not produce statistically
30110 significant matches.  However, if a significant alignment contains low
30111 complexity regions, their alignmen is shown.  With "-S", lower case
30112 characters may be included in the alignment to indicate low complexity
30113 regions, and the final alignment score may be higher than the score
30114 obtained during the search.
30115 .ip
30116 The \fCpseg\fP program can be used to produce databases (or query
30117 sequences) with lower case residues indicating low complexity regions
30118 using the command:
30119 .(l I
30120 \fCpseg database.fasta -z 1 -q  > database.lc_seg\fP
30121 .)l
30122 (\fCseg\fP can also be used with some post processing, see readme.v33tx.)
30123 .ip
30124 The \fC-S\fP option should always be used with \fCFASTX/Y\fCP and
30125 \fCTFASTX/Y\fP because out of frame translations often generate
30126 low-complexity protein sequences.  However, only lower case characters
30127 in the protein sequence (or protein database) are masked; lower case
30128 DNA sequences are translated into upper case protein sequences, and
30129 not treated as low complexity by the translated alignment programs.
30130 .ip "-t #"
30131 Translation table - tfasta3, fastx3, tfastx3, fasty3, and
30132 tfasty3 now support the BLAST tranlation tables.  See
30133 \fChttp://www.ncbi.nlm.nih.gov/Taxonomy/Utils/wprintgc.cgi\fP.
30134 .ip
30135 In addition, "\-t t" or "\-t t#" turns on the addition of an implicit termination
30136 codon to a protein:translated DNA match.  That is, each protein
30137 sequence implicitly ends with "*", which matches the termination codes
30138 for the appropriate genetic code.  "\-t t#" sets implicit termination
30139 and a different genetic code.
30140 .ip "-U"
30141 Treat the query sequence an RNA sequence.  In addition to selecting a
30142 DNA/RNA alphabet, this option causes changes to the scoring matrix so
30143 that 'G:A' , 'T:C' or 'U:C' are scored as 'G:G'.
30144 .ip "-V str"
30145 It is now possible to specify some annotation characters that can be
30146 included (and will be ignored), in the query sequence file.  Thus, One
30147 might have a file with: \fC"ACVS*ITRLFT?"\fP, where "*" and "?"  are
30148 used to indicate phosphorylation.  By giving the option \fC\-V '*?'\fP,
30149 those characters in the query will be moved to an "annotation string",
30150 and alignments that include the annotated residues will be highlighted
30151 with the appropriate character above the sequence (on the number line).
30152 .ip "-w #"
30153 Line length (width) = number (<200)
30154 .ip "-W #"
30155 X context length (default is 1/2 of line width -w) for alignment,
30156 like fasta and ssearch, that provide additional sequence context.
30157 .ip "-x #match,#mismatch"
30158 Specify the penalty for a match to an 'X', and mismatch to 'X',
30159 independently of the PAM matrix.  Particularly useful for
30160 \fCfastx3/fasty3\fP, where termination codons are encoded as 'X'.
30161 .ip "-X \"off1 off2\""
30162 Specifies offsets for the beginning of the query and library sequence.
30163 For example, if you are comparing upstream regions for two genes, and
30164 the first sequence contains 500 nt of upstream sequence while the
30165 second contains 300 nt of upstream sequence, you might try:
30166 .(l I
30167 \fCfasta -X "-500 -300" seq1.nt seq2.nt\fP
30168 .)l
30169 If the -X option is not used, FASTA assumes numbering starts with 1.
30170 (You should double check to be certain the negative numbering works
30171 properly.)
30172 .ip "-y"
30173 Set the width of the band used for calculating "optimized" scores.
30174 For proteins and ktup=2, the width is 16.  For proteins with ktup=1,
30175 the width is 32 by default.  For DNA the width is 16.
30176 .ip "-z -1,0,1,2,3,4,5"
30177 \fC\-z -1\fP turns off statistical calculations. \fCz 0\fP estimates
30178 the significance of the match from the mean and standard deviation of
30179 the library scores, without correcting for library sequence length.
30180 \fC\-z 1\fP (the default) uses a weighted regression of average score
30181 vs library sequence length; \fC\-z 2\fP uses maximum likelihood
30182 estimates of
30183 .if t \(*l
30184 .if n Lambda
30185 and \fIK\fP; \fC\-z 3\fP uses Altschul-Gish
30186 parameters;[.alt960.] \fC\-z 4 \- 5\fP uses two variations on the
30187 \fC\-z 1\fP strategy. \fC\-z 1\fP and \fC\-z 2\fP are the best methods,
30188 in general.
30189 .ip "-z 11,12,14,15" 
30190 estimate the statistical parameters from shuffled copies of each
30191 library sequence.  This doubles the time required for a search, but
30192 allows accurate statistics to be estimated for libraries comprised of
30193 a single protein family.
30194 .ip "-Z db_size"
30195 set the apparent size of the database to be used when calculating
30196 expectation E() values.  If you searched a database with 1,000
30197 sequences, but would like to have the E()-values calculated in the
30198 context of a 100,000 sequence database, use '-Z 100000'.
30199 .ip "-1"
30200 sort output by init1 score (for compatibility with FASTP - do not
30201 use).
30202 .ip "-3"
30203 translate only three forward frames
30204 .sp
30205 .lp
30206 For example:
30207 .(l
30208 \fCfasta -w 80 -a seq1.aa seq.aa\fP
30209 .)l
30210 would compare the sequence in seq1.aa to that in seq2.aa and display the
30211 results with 80 residues on an output line, showing all of the residues
30212 in both sequences.  Be sure to enter the options before entering the file
30213 names, or just enter the options on the command line, and the program will
30214 prompt for the file names.
30215 .sp
30216 .pp
30217 (November, 1997) In addition, it is now possible to provide the fasta
30218 programs with the query sequence (fasta, fasty, ssearch, tfastx), or
30219 two sequences (prss, lalign, plalign) from the unix "stdin" stream.  This
30220 makes it much easier to set up FASTA or PRSS WWW pages.  To specify
30221 that stdin be used, rather than a file, the file name should be
30222 specified as '-' or '@' (the latter file name makes it possible to
30223 specify a subset of the sequence).
30224 Thus:
30225 .(l
30226 cat query.aa | fasta -q @:25-75 s
30227 .)l
30228 would take residues 25-75 from query.aa and search the 's' library
30229 (see the discussion of FASTLIBS).
30230 .sh 2 "Environment variables"
30231 .pp
30232 Because the current version of the program allows the user to set
30233 virtually every option on the command line (except the \fIktup\fP,
30234 which must be set as the third command line argument), only the
30235 \fCFASTLIBS\fP environment variable is routinely used.
30236 .ip "FASTLIBS"
30237 specifies the location of the file which contains the list of library
30238 descriptions, locations, and library types (see section on finding
30239 library files).
30240 .sh 1 "Frequently Asked Questions (FAQs)"
30241 .np
30242 \fIWhich program should I use?\fP See Table I.
30243 .np
30244 \fIHow do I search with both DNA strands with\fP \fCfasta3\fP \fIand\fP
30245 \fCfastx3\fP? With version 32 of the FASTA program package, all
30246 searches that use DNA queries (e.g. \fCfasta3\fP, \fCfastx3/y3\fP)
30247 examine both strands. To revert to earlier FASTA behavior - only
30248 looking at the forward or reverse strand - use \fC\-3\fP to search only
30249 the forward strand and \fC\-i -3\fP to search only the reverse strand.
30250 .np
30251 \fIWhen I search Genbank - the program reports:\fP \fC0 residues in 0
30252 sequences\fP.  This typically happens because the program does not
30253 know that you are searching a Genbank flatfile database and is looking
30254 for a FASTA format database.  Be certain to specify the library type
30255 ("1" for Genbank flatfile) with the database name.
30256 .np
30257 What is the difference between \fCfastx3\fP and \fCfasty3\fP (or
30258 \fCtfastx3\fP and \fCtfasty3\fP).  \fC[t]fastx3\fP uses a simpler
30259 codon based model for alignments that does not allow frameshifts in
30260 some codon positions (see ref. [.wrp971.]).  \fCtfastx3\fP is about
30261 30% faster, but \fCtfasty3\fP can produce higher quality alignments in
30262 some cases.
30263 .np
30264 \fIWhen I run\fP \fCfasta3 -q\fP, I don't see any (or very little)
30265 output, but I get lots of scores when I run interactively. With the
30266 \fC\-Q\fP option, the number of high scores displayed is limited by the
30267 \fC\-E #\fP cutoff, which is 10.0 for protein comparisons, 2.0 for DNA
30268 comparisons, and 5.0 for translated DNA:protein comparisons.  In
30269 interactive mode (without \fC\-Q\fP), by default you see 20 high
30270 scores, regardless of \fCE()\fP value.
30271 .np
30272 \fIWhat is ktup\fP \- All of the programs with \fCfast\fP in their
30273 name use a computer science method called a lookup table to speed the
30274 search.  For proteins with \fIktup\fP=2, this means that the program
30275 does not look at any sequence alignment that does not involve matching
30276 two identical residues in both sequences.  Likewise with DNA and
30277 \fIktup\fP = 6, the initial alignment of the sequences looks for 6
30278 identical adjacent nucleotides in both sequences.  Because it is less
30279 likely that two identical amino-acids will line up by chance in two
30280 unrelated proteins, this speeds up the comparison.  But very distantly
30281 related sequences may never have two identical residues in a row but
30282 will have single aligned identities.  In this case, \fIktup\fP = 1 may
30283 find alignments that \fIktup\fP=2 misses.
30284 .np
30285 \fISometimes, in the list of best scores, the same sequence is shown
30286 twice with exactly the same score.  Sometimes, the sequence is there
30287 twice, but the scores are slightly different.\fP When any of the
30288 \fCfasta3\fP programs searches a long sequence, it breaks the sequence
30289 up into \fIoverlapping\fP pieces.  The length of the piece depends on
30290 the length of the query and the particular program being used (it can
30291 also be controlled with the -N #### option).  Since the pieces overlap
30292 by the length of the query sequence (or 3*query_length for fastx/y3
30293 and tfasta/x/y3), if the highest scoring alignment is at the end of
30294 one piece, it will be scored again at the beginning of the next piece.
30295 If the alignment is not be completely included in the overlap region,
30296 one of the pieces will give a higher score than the other.  These
30297 duplications can be detected by looking at the coordinates of the
30298 alignment.  If either the beginning or end coordinate is identical in
30299 two alignments, the alignments are at least partially duplicates.
30300 .lp
30301 As always, please inform me of bugs as soon as possible.
30302 .sp
30303 .nf
30304 William R. Pearson
30305 Department of Biochemistry
30306 Jordan Hall Box 800733
30307 U. of Virginia
30308 Charlottesville, VA
30309 X
30310 wrp@virginia.EDU
30311 X
30312 .sh 1 "References"
30313 .[]
30314 SHAR_EOF
30315 chmod 0644 fasta3x.me ||
30316 echo 'restore of fasta3x.me failed'
30317 Wc_c="`wc -c < 'fasta3x.me'`"
30318 test 39642 -eq "$Wc_c" ||
30319         echo 'fasta3x.me: original size 39642, current size' "$Wc_c"
30320 fi
30321 # ============= fasta_func.doc ==============
30322 if test -f 'fasta_func.doc' -a X"$1" != X"-c"; then
30323         echo 'x - skipping fasta_func.doc (File already exists)'
30324 else
30325 echo 'x - extracting fasta_func.doc (Text)'
30326 sed 's/^X//' << 'SHAR_EOF' > 'fasta_func.doc' &&
30327 Over all structure of the fasta3 program.  (Some functions
30328 are different for translated comparisons FASTX, FASTY, TFASTX, TFASTY.)
30329 X
30330 main() {        /* complib.c structure */
30331 X
30332 X  /* get command line arguments, set up initial parameter values */
30333 X  initenv (argc, argv, &m_msg, &pst,&aa0[0],outtty);
30334 X
30335 X  /* allocate space for sequence arrays */
30336 X  /* get the query file name if not on command line */
30337 X  /* get query */
30338 X  m_msg.n0 = getseq (m_msg.tname,aa0[0], MAXTOT, m_msg.libstr,&pst.dnaseq,
30339 X                    &m_msg.sq0off);
30340 X
30341 X  /* reset some parameters if DNA */                
30342 X  resetp (aa0[0], m_msg.n0, &m_msg, &pst);
30343 X
30344 X  /* get a library name if not on command line */
30345 X  libchoice(m_msg.lname,sizeof(m_msg.lname),&m_msg);
30346 X  /* use library name to build list of library files */
30347 X  libselect(m_msg.lname, &m_msg);
30348 X
30349 X  /* get additional options (ktup, prss-window) if not specified */
30350 X  query_parm (&m_msg, &pst);
30351 X
30352 X  /* do final parameter initializations */
30353 X  last_init(&m_msg, &pst);
30354 X
30355 X  /* set up structures for saved scores[20000], statistics[50000] */
30356 X  nbest = 0;
30357 X  
30358 X  /* initialize the comparison function */
30359 X  init_work (aa0[0], m_msg.n0, &pst, &f_str[0]);
30360 X
30361 X  /* open the library */
30362 X  for (iln = 0; iln < m_msg.nln; iln++) {
30363 X    if (openlib(m_msg.lbnames[iln],m_msg)!=1) {continue;}
30364 X  }
30365 X
30366 X  /* get the library sequence and do the comparison */
30367 X  while ((n1=GETLIB(aa1ptr,maxt,libstr,&lmark,&lcont))>0) {
30368 X    do_work (aa0[itt], m_msg.n0, aa1, n1, itt, &pst, f_str[itt], &rst);
30369 X
30370 X  /* save the scores */
30371 X  /* save the scores for statistics */
30372 X  }
30373 X
30374 X  /* all done with all libraries */
30375 X  process_hist(stats,nstats,pst);
30376 X
30377 X  /* sort the scores by z-value */
30378 X  sortbestz (bptr, nbest);
30379 X
30380 X  /* sort the scores by E-value */
30381 X  sortbeste (bptr, nbest);
30382 X
30383 X  /* print the histogram */
30384 X  prhist (stdout,m_msg,pst,gstring2);
30385 X
30386 X  /* show the high scoring sequences */
30387 X  showbest (stdout, aa0, aa1, maxn, bptr, nbest, qlib, &m_msg, pst,
30388 X            f_str, gstring2);
30389 X
30390 X  /* show the high-scoring alignments */
30391 X  showalign(outfd, aa0, aa1, maxn, bptr, nbest, qlib, m_msg, pst,
30392 X           f_str, gstring2);
30393 X
30394 X  /* thats all folks !!! */
30395 }
30396 X\f
30397 ================
30398 complib.c       /* version set as mp_verstr */
30399 X
30400 main()
30401 printsum()      /* prints summary of run (residues, entries, time) */
30402 void fsigint()  /* sets up interrupt handler for HUP not used */
30403 X
30404 ================
30405 compacc.c
30406 X
30407 void selectbest() /* select best 15000/20000 based on raw score */
30408 void selectbestz() /* select best 15000/20000 based on z-score */
30409 void sortbest()  /* sort based on raw score */
30410 void sortbestz() /* sort based on z-score */
30411 void sortbeste() /* sort based on E() score - different from z-score for DNA */
30412 X
30413 prhist()        /* print histogram */
30414 X
30415 shuffle()       /* shuffle sequence (prss) */
30416 wshuffle()      /* window shuffle */
30417 X
30418 ================
30419 showbest.c
30420 X
30421 void showbest() /* present list of high scoring sequences */
30422 X
30423 ================
30424 showalign.c
30425 X
30426 void showalign() /* show list of high-scoring alignments */
30427 void do_show()  /* show an individual alignment */
30428 void initseq()  /* setup seqc0/seqc1 which contain alignment characters */
30429 void freeseq()  /* free them up */
30430 X
30431 ================
30432 htime.c
30433 X
30434 time_t s_time() /* get the time in usecs */
30435 void ptime()    /* print elapsed time */
30436 X
30437 ================
30438 apam.c
30439 X
30440 initpam ()      /* read in PAM matrix or change default array */
30441 void mk_n_pam() /* make DNA pam from +5/-3 values */
30442 ================
30443 doinit.c
30444 X
30445 void initenv()  /* read environment variables, general options */
30446 ================
30447 initfa.c        /* version set as "verstr" */
30448 X
30449 alloc_pam()     /* allocate 2D pam array */
30450 initpam2()      /* fill it up from 1D pam triangle */
30451 f_initenv()     /* function-specific environment variables */
30452 f_getopt()      /* function-specific options */
30453 f_getarg()      /* function specific argument - ktup */
30454 resetp()        /* reset scoring matrix, optional parameters for DNA-DNA */
30455 reseta()        /* reset scoring matrix, optional parameters for prot-DNA */
30456 query_parm()    /* ask for additional program arguments (ktup) */
30457 last_init()     /* last chance to set up parameters based on query,lib,parms */
30458 f_initpam()     /* not used - could set parameters from pam matrix */
30459 X
30460 ================
30461 scaleswn.c
30462 X
30463 process_hist()  /* do statistics calculations */
30464 X
30465 X  proc_hist_r()        /* regression fit z=1, also used by z=5 */
30466 X    float find_z() /* gives z-score for score, length, mu, rho, var */
30467 X    float find_zr() /* gives z-score for score, length, mu, rho, var */
30468 X    fit_llen() /* first estimate of mu, rho, var */
30469 X    fit_llens()        /* second estimate of mu, rho, var, mu2, rho2 */
30470 X
30471 X  proc_hist_r2()  /* regression_i fit z=4 */
30472 X    float find_zr2() /* gives z-score for score, length, mu, rho, mu2, rho2 */
30473 X    fit_llen2()        /* iterative estimate of mu, rho, var */
30474 X
30475 X  proc_hist_ln()  /* ln()-scaled z=2 */ /* no longer used */
30476 X    float find_zl() /* gives z-score from ln()-scaled scores */
30477 X
30478 X  proc_hist_ml() /* estimate lambda, K using Maximum Likelihood */
30479 X    float find_ze() /* z-score from lambda, K */
30480 X
30481 X  proc_hist_n()   /* no length-scaling z=0 */
30482 X    float find_zn() /* gives z-score from mu, var (no scaling) */
30483 X
30484 X  proc_hist_a()   /* Altschul-Gish params z= 3 */
30485 X    ag_parm()  /* match pst.pamfile name, look_p() */
30486 X    look_p()   /* lookup Lambda, K, H given param struct */
30487 X    float find_za()
30488 X
30489 eq_s()  /* returns (double)score (available for length correction) */
30490 ln_s()  /* returns (double)score * ln(200)/ln(length) */
30491 X
30492 proc_hist_r()   /* regression fit z=1, also used by z=5 */
30493 alloc_hist()    /* set up arrays for score vs length  */
30494 free_hist()     /* free them */
30495 inithist()      /* calls alloc_hist(), sets some other globals */
30496 addhist()       /* update score vs length hist */ 
30497 inithistz()     /* initialize displayed (z-score) histogram hist[]*/
30498 addhistz()      /* add to hist[], increment num_db_entries */
30499 addhistzp()     /* add to hist[], don't change num_db_entries */
30500 prune_hist()    /* remove scores from score vs length */
30501 update_db_size() /* num_db_entries = nlib - ntrimmed */
30502 set_db_size()   /* -Z db_size; set nlib */
30503 X
30504 double z_to_E() /* z-value to E() (extreme value distribution */
30505 double zs_to_E() /* z-score (mu=50, sigma=10) to E() */
30506 double zs_to_bit() /* z-score to BLAST2 bit score */
30507 X
30508 float E_to_zs() /* E() to z-score */
30509 double zs_to_Ec() /* z-score to num_db_entries*(1 - P(zs))
30510 X
30511 summ_stats()    /* put stat summary in string */
30512 vsort()         /* not used, does shell sort */
30513 calc_ks()       /* does Kolmogorov-Smirnoff calculation for histogram */
30514 ================
30515 dropnfa.c       /* contains worker comparison functions */
30516 X
30517 init_work()     /* set up struct f_struct fstr - hash query */
30518 get_param()     /* actually prints parameters to string */
30519 close_work()    /* clean up fstr */
30520 do_work()       /* do a comparison */
30521 X  do_fasta()   /* use the fasta() function */
30522 X    savemax()  /* save the best region during scan */
30523 X    spam()     /* rescan the best regions */
30524 X    sconn()    /* try to connect the best regions for initn */
30525 X    kssort()   /* sort by score */
30526 X    kpsort()   /* sort by left end pos */
30527 X    shscore()  /* best self-score */
30528 X    dmatch()   /* do band alignment for opt score */
30529 X      FLOCAL_ALIGN()   /* fast band score-only */
30530 X
30531 do_opt()        /* do an "optimized comparison */
30532 X
30533 do_walign()     /* put an alignment into res[] for calcons() */
30534 X  sw_walign()  /* SW alignment driver - find boundaries */
30535 X    ALIGN()    /* actual alignment driver */
30536 X      nw_align()       /* recursive global alignment */
30537 X    CHECK_SCORE()      /* double check */
30538 X    DISPLAY()  /* Miller's display routine */
30539 X
30540 X  bd_walign()  /* band alignment driver for DNA */
30541 X    LOCAL_ALIGN()      /* find boundaries in band */
30542 X    B_ALIGN()          /* produce band alignment  */
30543 X      bg_align()       /* recursively produce band alignment */
30544 X    BCHECK_SCORE()     /* double check */
30545 X
30546 calcons()       /* calculate ascii alignment  seqc0,seqc1 from res[]*/
30547 calc_id()       /* calculate % identity with no alignment */
30548 ================
30549 nxgetaa.c
30550 X
30551 getseq()        /* get a query (prot or DNA) */
30552 getntseq()      /* get a nt query (for fastx, fasty) */
30553 gettitle()      /* get a description */
30554 X
30555 int openlib()   /* open a library */
30556 closelib()      /* close it */
30557 GETLIB()        /* get a fasta-format next library entry */
30558 RANLIB()        /* jump back in, get description, position for getlib() */
30559 X
30560 lgetlib()       /* get a Genbank flat-file format next library entry */
30561 lranlib()       /* jump back in, get description, position for lgetlib() */
30562 X
30563 pgetlib()       /* get CODATA format next library entry */
30564 pranlib()       /* jump back in, get description, position for lgetlib() */
30565 X
30566 egetlib()       /* get EMBL format next library entry */
30567 eranlib()       /* jump back in, get description, position for egetlib() */
30568 X
30569 igetlib()       /* get Intelligenetics format next library entry */
30570 iranlib()       /* jump back in, get description, position for igetlib() */
30571 X
30572 vgetlib()       /* get PIR/VMS/GCG format next library entry */
30573 vranlib()       /* jump back in, get description, position for vgetlib() */
30574 X
30575 gcg_getlib()    /* get GCG binary format next library entry */
30576 gcg_ranlib()    /* jump back in, get description, position for gcg_getlib() */
30577 X
30578 int scanseq()   /* find %ACGT */
30579 X
30580 revcomp()       /* do reverse complement */
30581 sf_sort()       /* sort superfamily numbers */
30582 ================
30583 c_dispn.c
30584 X
30585 discons()       /* display alignment from seqc0, seqc1 */
30586 disgraph()      /* display graphical representation, -m 4,5 */
30587 aancpy()        /* copy a binary sequence to ascii */
30588 r_memcpy()
30589 l_memcpy()
30590 iidex()         /* lookup ascii-encoding of residue */
30591 cal_coord()     /* calculate coordinates of alignment ends */
30592 X
30593 ================
30594 ncbl_lib.c
30595 X
30596 ncbl_openlib()
30597 ncbl_closelib()
30598 ncbl_getliba()
30599 ncbl_getlibn()
30600 ncbl_ranlib()
30601 src_ulong_read()
30602 src_long_read()
30603 src_char_read()
30604 src_fstr_read()
30605 newname()
30606 X
30607 ================
30608 lib_sel.c
30609 X
30610 getlnames()
30611 libchoice()
30612 libselect()
30613 addfile()
30614 ulindex()
30615 X
30616 ================
30617 nrand48.c
30618 X
30619 irand(time)     /* initialize random number generator */
30620 nrand(n)        /* get a number 0 - n */
30621 X
30622 ================
30623 url_subs.c
30624 X
30625 void do_url1()  /* setup search links */
30626 X
30627 SHAR_EOF
30628 chmod 0644 fasta_func.doc ||
30629 echo 'restore of fasta_func.doc failed'
30630 Wc_c="`wc -c < 'fasta_func.doc'`"
30631 test 9645 -eq "$Wc_c" ||
30632         echo 'fasta_func.doc: original size 9645, current size' "$Wc_c"
30633 fi
30634 # ============= fastf3.1 ==============
30635 if test -f 'fastf3.1' -a X"$1" != X"-c"; then
30636         echo 'x - skipping fastf3.1 (File already exists)'
30637 else
30638 echo 'x - extracting fastf3.1 (Text)'
30639 sed 's/^X//' << 'SHAR_EOF' > 'fastf3.1' &&
30640 .TH FASTF/TFASTFv3 1 local
30641 .SH NAME
30642 fastf3, fastf3_t \- compare a mixed peptide sequence against a protein
30643 database using a modified fasta algorithm.
30644 X
30645 tfastf3, tfastf3_t \- compare a mixed pepide sequence against a
30646 translated DNA database.
30647 X
30648 .SH DESCRIPTION
30649 X
30650 .B fastf3
30651 and
30652 .B tfastf3
30653 are designed to compare a sequence of mixed peptides to a protein
30654 (fastf3) or translated DNA (tfastf3) database.  Unlike the traditional
30655 .B fasta3
30656 search, which uses a protein or DNA sequence,
30657 .B fastf3
30658 and
30659 .B tfastf3
30660 work with a query sequence of the form:
30661 .in +5
30662 .nf
30663 >testf from mgstm1
30664 MGCEN,
30665 MIDYP,
30666 MLLAY,
30667 MLLGY
30668 .fi
30669 .in 0
30670 This sequence indicates that a mixture of four peptides has been
30671 found, with 'M' in the first position of each one (as from a CNBr
30672 cleavage), in the second position 'G', 'I', or 'L' (twice), at the
30673 third position 'C', 'D', or 'L' (twice), at the fourth position 'E',
30674 'Y', 'A', or 'G', etc.  When this sequence is compared against mgstm1.aa 
30675 (included with the distribution), the mixture is deconvolved to form:
30676 .nf
30677 .ft C
30678 .in +5
30679 testf    MILGY-----------MLLEY-----------MGDAP-----------
30680 X         :::::           :::::           :::::           
30681 GT8.7  MPMILGYWNVRGLTHPIRMLLEYTDSSYDEKRYTMGDAPDFDRSQWLNEK
30682 X               10        20        30        40        50
30683 X
30684 testf  --------------------------------------------------
30685 X                                                         
30686 GT8.7  FKLGLDFPNLPYLIDGSHKITQSNAILRYLARKHHLDGETEEERIRADIV
30687 X               60        70        80        90       100
30688 X
30689 X                      20                                 
30690 testf  ------------MLCYN                                 
30691 X                   :::::                                 
30692 GT8.7  ENQVMDTRMQLIMLCYNPDFEKQKPEFLKTIPEKMKLYSEFLGKRPWFAG
30693 X              110       120       130       140       150
30694 .in 0
30695 .ft P
30696 .fi
30697 .SH Options
30698 .LP
30699 .B fastf3
30700 and
30701 .B tfastf3
30702 can accept a query sequence from the unix "stdin" data stream.  This makes it much
30703 easier to use fasta3 and its relatives as part of a WWW page. To
30704 indicate that stdin is to be used, use "-" or "@" as the query
30705 sequence file name.
30706 .TP
30707 \-b #
30708 number of best scores to show (must be < -E cutoff)
30709 .TP
30710 \-d #
30711 number of best alignments to show ( must be < -E cutoff)
30712 .TP
30713 \-D
30714 turn on debugging mode.  Enables checks on sequence alphabet that
30715 cause problems with tfastx3, tfasty3, tfasta3.
30716 .TP
30717 \-E #
30718 Expectation value limit for displaying scores and
30719 alignments.  Expectation values for
30720 .B fastf3
30721 and
30722 .B tfastf3
30723 are not as accurate as those for the other 
30724 .B fasta3
30725 programs.
30726 .TP
30727 \-H
30728 turn off histogram display
30729 .TP
30730 \-i
30731 compare against only the reverse complement of the library sequence.
30732 .TP
30733 \-L
30734 report long sequence description in alignments
30735 .TP
30736 \-m 0,1,2,3,4,5,6,10
30737 alignment display options
30738 .TP
30739 \-n
30740 force query to nucleotide sequence
30741 .TP
30742 \-N #
30743 break long library sequences into blocks of # residues.  Useful for
30744 bacterial genomes, which have only one sequence entry.  -N 2000 works
30745 well for well for bacterial genomes.
30746 .TP
30747 \-O file
30748 send output to file
30749 .TP
30750 \-q/-Q
30751 quiet option; do not prompt for input
30752 .TP 
30753 \-R file
30754 save all scores to statistics file
30755 .TP
30756 \-S #
30757 offset substitution matrix values by  a constant #
30758 .TP
30759 \-s name
30760 specify substitution matrix.  BLOSUM50 is used by default;
30761 PAM250, PAM120, and BLOSUM62 can be specified by setting -s P120,
30762 P250, or BL62.  With this version, many more scoring matrices are
30763 available, including BLOSUM80 (BL80), and MDM_10, MDM_20, MDM_40 (M10,
30764 M20, M40). Alternatively, BLASTP1.4 format scoring matrix files can be
30765 specified.
30766 .TP
30767 \-T #
30768 (threaded, parallel only) number of threads or workers to use (set by
30769 default to 4 at compile time).
30770 .TP
30771 \-t #
30772 Translation table - tfastf3 can use the BLAST tranlation tables.  See
30773 \fChttp://www.ncbi.nlm.nih.gov/htbin-post/Taxonomy/wprintgc?mode=c/\fP.
30774 .TP
30775 \-w #
30776 line width for similarity score, sequence alignment, output.
30777 .TP
30778 \-x "#,#"
30779 offsets query, library sequence for numbering alignments
30780 .TP
30781 \-z #
30782 Specify statistical calculation. Default is -z 1, which uses
30783 regression against the length of the library sequence. -z 0 disables
30784 statistics.  -z 2 uses the ln() length correction. -z 3 uses Altschul
30785 and Gish's statistical estimates for specific protein BLOSUM scoring
30786 matrices and gap penalties. -z 4: an alternate regression method.
30787 .TP
30788 \-Z db_size
30789 Set the apparent database size used for expectation value calculations.
30790 .TP
30791 \-1
30792 Sort by "init1" score.
30793 .TP
30794 \-3
30795 (TFASTF3 only) use only forward frame translations
30796 .SH Environment variables:
30797 .TP
30798 FASTLIBS
30799 location of library choice file (-l FASTLIBS)
30800 .TP
30801 SMATRIX
30802 default scoring matrix (-s SMATRIX)
30803 .TP
30804 SRCH_URL
30805 the format string used to define the option to re-search the
30806 database.
30807 .TP
30808 REF_URL
30809 the format string used to define the option to lookup the library
30810 sequence in entrez, or some other database.
30811 X
30812 .SH AUTHOR
30813 Bill Pearson
30814 .br
30815 wrp@virginia.EDU
30816 SHAR_EOF
30817 chmod 0644 fastf3.1 ||
30818 echo 'restore of fastf3.1 failed'
30819 Wc_c="`wc -c < 'fastf3.1'`"
30820 test 4824 -eq "$Wc_c" ||
30821         echo 'fastf3.1: original size 4824, current size' "$Wc_c"
30822 fi
30823 # ============= fastlibs ==============
30824 if test -f 'fastlibs' -a X"$1" != X"-c"; then
30825         echo 'x - skipping fastlibs (File already exists)'
30826 else
30827 echo 'x - extracting fastlibs (Text)'
30828 sed 's/^X//' << 'SHAR_EOF' > 'fastlibs' &&
30829 NBRF PIR1 Annotated Protein Database (rel 56)$0A/seqlib/lib/pir1.seq 5
30830 NBRF PIR1 Annotated (seg) (rel 56)$0B/slib2/blast/pir1.seg
30831 NBRF Protein database (complete)$0P@/seqlib/lib/NBRF.nam
30832 NRL_3d structure database$0D/seqlib/lib/nrl_3d.seq 5
30833 NCBI/Blast non-redundant proteins$0N/slib2/blast/nr
30834 NCBI/Blast non-redundant proteins (seg)$0K/slib2/blast/nr.seg
30835 NCBI/Blast Swissprot$0Q/slib2/blast/swissprot
30836 NCBI/Blast Swissprot (seg)$0R/slib2/blast/swissprot.seg
30837 OWL 30.1 non-redundant protein database$0O/slib2/OWL/owl.seq 5
30838 GENPEPT Translated Protein Database (rel 106.0)$0G/slib2/blast/genpept.fsa
30839 Swiss-Prot Release 34$0S/slib0/lib/swiss.seq 5
30840 Yeast proteins$0Y/slib0/genomes/yeast_nr.pep
30841 C. elegans blast server$0W/slib2/blast/C.elegans_blast.fa
30842 E. coli proteome$0E/slib0/genomes/ecoli.npep
30843 H. influenzae proteome$0I/slib0/genomes/hinf.npep
30844 H. pylori proteome$0L/slib0/genomes/hpyl.npep
30845 NCBI Entrez Human proteins$0H/slib2/blast/human.aa
30846 M. pneumococcus proteome$0M/slib0/genomes/mpneu.npep
30847 M. jannaschii proteome$0J/slib0/genomes/mjan.npep
30848 Synechosystis proteome$0C/slib0/genomes/synecho.npep
30849 GB108.0 Invertebrates$1I/seqlib2/gcggenbank/gb_in.seq 6
30850 GB108.0 Bacteria$1T@/slib0/lib/gb_ba.nam 6
30851 GB108.0 Primate$1P@/slib0/lib/gb_pri.nam
30852 GB108.0 Rodent$1R/seqlib2/gcggenbank/gb_ro.seq 6
30853 GB108.0 other Mammal$1M/seqlib2/gcggenbank/gb_om.seq 6
30854 GB108.0 verteBrates$1B/seqlib2/gcggenbank/gb_ov.seq 6
30855 GB108.0 Expressed Seq. Tags$1E@/slib0/lib/gb_est.nam
30856 GB108.0 High throughput genmomic$1h/seqlib2/gcggenbank/gb_htg.seq 6
30857 GB108.0 pLants$1L@/slib0/lib/gb_pl.nam 6
30858 GB108.0 genome Survey sequences$1S@/slib0/lib/gb_gss.nam 6
30859 GB108.0 Viral$1V/seqlib2/gcggenbank/gb_vi.seq 6
30860 GB108.0 Phage$1G/seqlib2/gcggenbank/gb_ph.seq 6
30861 GB108.0 Unannotated$1D/seqlib2/gcggenbank/gb_un.seq 6
30862 GB108.0 New$1u/seqlib2/gcggenbank/gb_new.seq 6
30863 GB108.0 All sequences (long)$1A@/slib0/lib/genbank.nam
30864 Yeast genome$1Y@/seqlib/yeast/yeast_chr.nam
30865 E. coli genome$1D/slib0/genomes/ecoli.gbk 1
30866 Blast Human ESTs$1F/slib2/blast/est_human
30867 TIGR Human Gene Index$1K/slib2/blast/HGI.nr.031898
30868 Blast Mouse ESTs$1C/slib2/blast/est_mouse
30869 TIGR Mouse Gene Index$1J/slib2/blast/MGI.nr.022498
30870 NCBI/BLAST NR DNA$1n/slib2/blast/nt
30871 SHAR_EOF
30872 chmod 0644 fastlibs ||
30873 echo 'restore of fastlibs failed'
30874 Wc_c="`wc -c < 'fastlibs'`"
30875 test 2173 -eq "$Wc_c" ||
30876         echo 'fastlibs: original size 2173, current size' "$Wc_c"
30877 fi
30878 # ============= fasts3.1 ==============
30879 if test -f 'fasts3.1' -a X"$1" != X"-c"; then
30880         echo 'x - skipping fasts3.1 (File already exists)'
30881 else
30882 echo 'x - extracting fasts3.1 (Text)'
30883 sed 's/^X//' << 'SHAR_EOF' > 'fasts3.1' &&
30884 .TH FASTS/TFASTSv3 1 local
30885 .SH NAME
30886 fasts3, fasts3_t \- compare several short peptide sequences against a protein
30887 database using a modified fasta algorithm.
30888 X
30889 tfasts3, tfasts3_t \- compare short pepides against a
30890 translated DNA database.
30891 X
30892 .SH DESCRIPTION
30893 X
30894 .B fasts3
30895 and
30896 .B tfasts3
30897 are designed to compare set of (presumably non-contiguous) peptides to
30898 a protein (fasts3) or translated DNA (tfasts3) database.
30899 fasts3/tfasts3 are designed particularly for short peptide data from
30900 mass-spec analysis of protein digests.  Unlike the traditional
30901 .B fasta3
30902 search, which uses a protein or DNA sequence,
30903 .B fasts3
30904 and
30905 .B tfasts3
30906 work with a query sequence of the form:
30907 .in +5
30908 .nf
30909 >tests from mgstm1
30910 MLLE,
30911 MILGYW,
30912 MGADP,
30913 MLCYNP
30914 .fi
30915 .in 0
30916 This sequence indicates that four peptides are to be used.  When this
30917 sequence is compared against mgstm1.aa (included with the
30918 distribution), the result is:
30919 .nf
30920 .ft C
30921 .in +5
30922 testf    MILGYW----------MLLE------------MGDAP-----------
30923 X         ::::::          ::::            :::::           
30924 GT8.7  MPMILGYWNVRGLTHPIRMLLEYTDSSYDEKRYTMGDAPDFDRSQWLNEK
30925 X               10        20        30        40        50
30926 X
30927 testf  --------------------------------------------------
30928 X                                                         
30929 GT8.7  FKLGLDFPNLPYLIDGSHKITQSNAILRYLARKHHLDGETEEERIRADIV
30930 X               60        70        80        90       100
30931 X
30932 X                      20                                 
30933 testf  ------------MLCYNP
30934 X                   ::::::
30935 GT8.7  ENQVMDTRMQLIMLCYNPDFEKQKPEFLKTIPEKMKLYSEFLGKRPWFAG
30936 X              110       120       130       140       150
30937 .in 0
30938 .ft P
30939 .fi
30940 .SH Options
30941 .LP
30942 .B fasts3
30943 and
30944 .B tfasts3
30945 can accept a query sequence from the unix "stdin" data stream.  This makes it much
30946 easier to use fasta3 and its relatives as part of a WWW page. To
30947 indicate that stdin is to be used, use "-" or "@" as the query
30948 sequence file name.
30949 .TP
30950 \-b #
30951 number of best scores to show (must be < -E cutoff)
30952 .TP
30953 \-d #
30954 number of best alignments to show ( must be < -E cutoff)
30955 .TP
30956 \-D
30957 turn on debugging mode.  Enables checks on sequence alphabet that
30958 cause problems with tfastx3, tfasty3, tfasta3.
30959 .TP
30960 \-E #
30961 Expectation value limit for displaying scores and
30962 alignments.  Expectation values for
30963 .B fasts3
30964 and
30965 .B tfasts3
30966 are not as accurate as those for the other 
30967 .B fasta3
30968 programs.
30969 .TP
30970 \-H
30971 turn off histogram display
30972 .TP
30973 \-i
30974 compare against only the reverse complement of the library sequence.
30975 .TP
30976 \-L
30977 report long sequence description in alignments
30978 .TP
30979 \-m 0,1,2,3,4,5,6,9,10
30980 alignment display options
30981 .TP
30982 \-N #
30983 break long library sequences into blocks of # residues.  Useful for
30984 bacterial genomes, which have only one sequence entry.  -N 2000 works
30985 well for well for bacterial genomes.
30986 .TP
30987 \-O file
30988 send output to file
30989 .TP
30990 \-q/-Q
30991 quiet option; do not prompt for input
30992 .TP 
30993 \-R file
30994 save all scores to statistics file
30995 .TP
30996 \-S #
30997 offset substitution matrix values by  a constant #
30998 .TP
30999 \-s name
31000 specify substitution matrix.  BLOSUM50 is used by default;
31001 PAM250, PAM120, and BLOSUM62 can be specified by setting -s P120,
31002 P250, or BL62.  With this version, many more scoring matrices are
31003 available, including BLOSUM80 (BL80), and MDM_10, MDM_20, MDM_40 (M10,
31004 M20, M40). Alternatively, BLASTP1.4 format scoring matrix files can be
31005 specified.
31006 .TP
31007 \-T #
31008 (threaded, parallel only) number of threads or workers to use (set by
31009 default to 4 at compile time).
31010 .TP
31011 \-t #
31012 Translation table - tfasts3 can use the BLAST tranlation tables.  See
31013 \fChttp://www.ncbi.nlm.nih.gov/htbin-post/Taxonomy/wprintgc?mode=c/\fP.
31014 .TP
31015 \-w #
31016 line width for similarity score, sequence alignment, output.
31017 .TP
31018 \-x "#,#"
31019 offsets query, library sequence for numbering alignments
31020 .TP
31021 \-z #
31022 Specify statistical calculation. Default is -z 1, which uses
31023 regression against the length of the library sequence. -z 0 disables
31024 statistics.  -z 2 uses the ln() length correction. -z 3 uses Altschul
31025 and Gish's statistical estimates for specific protein BLOSUM scoring
31026 matrices and gap penalties. -z 4: an alternate regression method.
31027 .TP
31028 \-Z db_size
31029 Set the apparent database size used for expectation value calculations.
31030 .TP
31031 \-3
31032 (TFASTS3 only) use only forward frame translations
31033 .SH Environment variables:
31034 .TP
31035 FASTLIBS
31036 location of library choice file (-l FASTLIBS)
31037 .TP
31038 SMATRIX
31039 default scoring matrix (-s SMATRIX)
31040 .TP
31041 SRCH_URL
31042 the format string used to define the option to re-search the
31043 database.
31044 .TP
31045 REF_URL
31046 the format string used to define the option to lookup the library
31047 sequence in entrez, or some other database.
31048 X
31049 .SH AUTHOR
31050 Bill Pearson
31051 .br
31052 wrp@virginia.EDU
31053 SHAR_EOF
31054 chmod 0644 fasts3.1 ||
31055 echo 'restore of fasts3.1 failed'
31056 Wc_c="`wc -c < 'fasts3.1'`"
31057 test 4556 -eq "$Wc_c" ||
31058         echo 'fasts3.1: original size 4556, current size' "$Wc_c"
31059 fi
31060 # ============= fasts3.rsp ==============
31061 if test -f 'fasts3.rsp' -a X"$1" != X"-c"; then
31062         echo 'x - skipping fasts3.rsp (File already exists)'
31063 else
31064 echo 'x - extracting fasts3.rsp (Text)'
31065 sed 's/^X//' << 'SHAR_EOF' > 'fasts3.rsp' &&
31066 compacc.obj doinit.obj showbest.obj htime.obj apam.obj scaleswt.obj karlin.obj last_tat.obj tatsta_s.obj c_dispn.obj lib_sel.obj url_subs.obj nrand.obj getopt.obj regetlib.obj lgetlib.obj ncbl2_mlib.obj
31067 SHAR_EOF
31068 chmod 0644 fasts3.rsp ||
31069 echo 'restore of fasts3.rsp failed'
31070 Wc_c="`wc -c < 'fasts3.rsp'`"
31071 test 203 -eq "$Wc_c" ||
31072         echo 'fasts3.rsp: original size 203, current size' "$Wc_c"
31073 fi
31074 # ============= getenv.c ==============
31075 if test -f 'getenv.c' -a X"$1" != X"-c"; then
31076         echo 'x - skipping getenv.c (File already exists)'
31077 else
31078 echo 'x - extracting getenv.c (Text)'
31079 sed 's/^X//' << 'SHAR_EOF' > 'getenv.c' &&
31080 #include <stdio.h>
31081 #include <string.h>
31082 #include <stdlib.h>
31083 X
31084 #define MAXENV 1024
31085 char *envstr;
31086 X
31087 char *mgetenv(str)
31088 char *str;
31089 {
31090 X       static int EnvInit=0;
31091 X
31092 X       char *eptr, *esptr, *bp;
31093 X       int i,esize;
31094 X       FILE *fenv;
31095 X       
31096 X       if (EnvInit==0) {
31097 X               EnvInit=1;
31098 X               if ((fenv=fopen("environment","r"))!=NULL) {
31099 X                       if ((envstr=malloc((size_t)(esize=MAXENV)))==NULL) {
31100 X                               fclose(fenv); goto noenv;}
31101 X                       esptr=envstr; esize -= 10;
31102 X                       while (fgets(esptr,esize,fenv)!=NULL) {
31103 X                               if ((bp=strchr(esptr,'\n'))!=NULL) *bp='\0';
31104 X                               esize -= (i=strlen(esptr)+1);
31105 X                               esptr += i;
31106 X                               }
31107 X                       fclose(fenv);
31108 X                       esptr='\0';
31109 X                       }
31110 X               else envstr=NULL;
31111 X       }
31112 X       
31113 X       if (envstr==NULL) return NULL;
31114 X       else {          
31115 X               for (eptr=envstr; *eptr; eptr += strlen(eptr)+1) {
31116 X                       if (strncmp(str,eptr,(long)strlen(str))==0) {
31117 X                               return strchr(eptr,'=')+1;
31118 X                               }
31119 X                       }
31120 X               return NULL;
31121 X               }
31122 noenv:  envstr=NULL; return NULL;
31123 X       }
31124 X
31125 strnpcpy(to,from,max)
31126 X       char *to; Str255 from; size_t max;
31127 {
31128 X       size_t i, n;
31129 X       
31130 X       n = (*from<max) ? *from : max;
31131 X       from++;
31132 X
31133 X       for (i=0; i<n; i++) *to++ = *from++;
31134 X       if (n<max) *to='\0';
31135 X       }
31136 SHAR_EOF
31137 chmod 0644 getenv.c ||
31138 echo 'restore of getenv.c failed'
31139 Wc_c="`wc -c < 'getenv.c'`"
31140 test 1036 -eq "$Wc_c" ||
31141         echo 'getenv.c: original size 1036, current size' "$Wc_c"
31142 fi
31143 # ============= getopt.c ==============
31144 if test -f 'getopt.c' -a X"$1" != X"-c"; then
31145         echo 'x - skipping getopt.c (File already exists)'
31146 else
31147 echo 'x - extracting getopt.c (Text)'
31148 sed 's/^X//' << 'SHAR_EOF' > 'getopt.c' &&
31149 /*LINTLIBRARY*/
31150 X
31151 #include <stdio.h>
31152 #include <stdlib.h>
31153 #include <string.h>
31154 X
31155 #define ERR(s, c)       if(opterr){\
31156 X       char errbuf[3];\
31157 X       errbuf[0] = c; errbuf[1] = '\n'; errbuf[2]='\0';\
31158 X       (void) fputs(argv[0],stderr);\
31159 X       (void) fputs(s,stderr);\
31160 X       (void) fputs(errbuf,stderr);}
31161 X
31162 X
31163 int     opterr = 1;
31164 int     optind = 1;
31165 int     optopt;
31166 char    *optarg;
31167 X
31168 int
31169 getopt(argc, argv, opts)
31170 int     argc;
31171 char    **argv, *opts;
31172 {
31173 X       static int sp = 1;
31174 X       register int c;
31175 X       register char *cp;
31176 X
31177 X       if(sp == 1)
31178 X               if(optind >= argc ||
31179 X                  argv[optind][0] != '-' || argv[optind][1] == '\0')
31180 X                       return(EOF);
31181 X               else if(strcmp(argv[optind], "--") == 0) {
31182 X                       optind++;
31183 X                       return(EOF);
31184 X               }
31185 X       optopt = c = argv[optind][sp];
31186 X       if(c == ':' || (cp=strchr(opts, c)) == NULL) {
31187 X               ERR(": illegal option -- ", c);
31188 X               if(argv[optind][++sp] == '\0') {
31189 X                       optind++;
31190 X                       sp = 1;
31191 X               }
31192 X               return('?');
31193 X       }
31194 X       if(*++cp == ':') {
31195 X               if(argv[optind][sp+1] != '\0')
31196 X                       optarg = &argv[optind++][sp+1];
31197 X               else if(++optind >= argc) {
31198 X                       ERR(": option requires an argument -- ", c);
31199 X                       sp = 1;
31200 X                       return('?');
31201 X               } else
31202 X                       optarg = argv[optind++];
31203 X               sp = 1;
31204 X       } else {
31205 X               if(argv[optind][++sp] == '\0') {
31206 X                       sp = 1;
31207 X                       optind++;
31208 X               }
31209 X               optarg = NULL;
31210 X       }
31211 X       return(c);
31212 }
31213 SHAR_EOF
31214 chmod 0644 getopt.c ||
31215 echo 'restore of getopt.c failed'
31216 Wc_c="`wc -c < 'getopt.c'`"
31217 test 1174 -eq "$Wc_c" ||
31218         echo 'getopt.c: original size 1174, current size' "$Wc_c"
31219 fi
31220 # ============= getseq.c ==============
31221 if test -f 'getseq.c' -a X"$1" != X"-c"; then
31222         echo 'x - skipping getseq.c (File already exists)'
31223 else
31224 echo 'x - extracting getseq.c (Text)'
31225 sed 's/^X//' << 'SHAR_EOF' > 'getseq.c' &&
31226 /*      May, June 1987  - modified for rapid read of database
31227 X
31228 X       copyright (c) 1987,1988,1989,1992,1995,2000 William R. Pearson
31229 X
31230 X       This is one of three alternative files that can be used to
31231 X       read a database.  The three files are nxgetaa.c, nmgetaa.c, and
31232 X       mmgetaa.c.
31233 X
31234 X       nxgetaa.c contains the original code for reading databases, and
31235 X       is still used for Mac and PC versions of fasta33 (which do not
31236 X       use mmap).
31237 X
31238 X       nmgetaa.c and mmgetaa.c are used together.  nmgetaa.c provides
31239 X       the same functions as nxgetaa.c if memory mapping is not used,
31240 X       mmgetaa.c provides the database reading functions if memory
31241 X       mapping is used. The decision to use memory mapping is made on
31242 X       a file-by-file basis.
31243 X
31244 X       June 2, 1987 - added TFASTA
31245 X       March 30, 1988 - combined ffgetaa, fgetgb;
31246 X       April 8, 1988 - added PIRLIB format for unix
31247 X       Feb 4, 1989 - added universal subroutines for libraries
31248 X       December, 1995 - added range option file.name:1-1000
31249 X       Feb 22, 2002 - fix to allow "plain" text file queries
31250 X
31251 X       getnt.c associated subroutines for matching sequences */
31252 X
31253 /* $Name: fa_34_26_5 $ - $Id: getseq.c,v 1.13 2006/10/05 18:22:07 wrp Exp $ */
31254 X
31255 /*
31256 X       8-April-88
31257 X       The compile time #define PIRLIB allows this routine to be used
31258 X       to read protein and DNA sequence libraries in the NBRF/PIR
31259 X       VAX/VMS library format.  That is:
31260 X
31261 X       >P1;LCBO
31262 X       This is a line of description
31263 X       GTYH ... the sequence starts on this line
31264 X
31265 X       This may ease conversion from UWGCG format libraries. It
31266 X       has not been extensively tested.
31267 X
31268 X       In addition, sequence libraries with a '>' in the 4th position
31269 X       are recognized as NBRF format libraries for consistency with
31270 X       UWGCG
31271 */
31272 X
31273 /*      Nov 12, 1987    - this version checks to see if the sequence
31274 X       is DNA or protein by asking whether > 85% is A, C, G, T
31275 X
31276 X       May 5, 1988 - modify the DNA/PROTEIN checker by re-reading
31277 X       DNA sequences in order to check for 'U'.
31278 */
31279 X
31280 #include <stdio.h>
31281 #include <stdlib.h>
31282 #include <string.h>
31283 X
31284 #include "defs.h"
31285 #include "structs.h"
31286 X
31287 #ifndef SFCHAR
31288 #define SFCHAR ':'
31289 #endif
31290 X
31291 #ifdef VMS
31292 #define PIRLIB
31293 #endif
31294 X
31295 #define XTERNAL
31296 #include "uascii.h"
31297 #include "upam.h"
31298 #undef XTERNAL
31299 X
31300 #define YES 1
31301 #define NO 0
31302 #define MAXLINE 512
31303 X
31304 #ifndef min
31305 #define min(x,y) ((x) > (y) ? (y) : (x))
31306 #endif
31307 X
31308 #ifdef SUPERFAMNUM
31309 extern int nsfnum;      /* number of superfamily numbers */
31310 extern int sfnum[];     /* superfamily number from types 0 and 5 */
31311 extern int nsfnum_n;
31312 extern int sfnum_n[];
31313 #endif
31314 X
31315 #define NO_FORMAT 0
31316 #define FASTA_FORMAT 1
31317 #define GCG_FORMAT 2
31318 X
31319 static int seq_format=NO_FORMAT;
31320 static char seq_title[200];
31321 X
31322 int scanseq(unsigned char *, int, char *);
31323 void sf_sort(int *, int);
31324 extern void init_ascii(int is_ext, int *sascii, int is_dna);
31325 X
31326 /* getseq       - get a query sequence, possibly re-reading to set type
31327 X   returns     - length of query sequence or error = 0
31328 X
31329 X   char *filen - name of file to be opened
31330 X   char *seq   - destination for query sequence
31331 X   int maxs    - maximum length of query
31332 X   char libstr[20] - short description (locus or acc)
31333 X   int *dnaseq  - -1 => use scanseq to determine sequence type
31334 X                  0 => must be protein
31335 X                  1 => must be DNA
31336 X   long *sq0off        - offset into query specified by query_file:1001-2000
31337 */   
31338 X
31339 int
31340 getseq(char *filen, int *qascii, unsigned char *seq, int maxs, char *libstr, long *sq0off)
31341 {
31342 X  FILE *fptr;
31343 X  char line[512],*bp, *bp1, *bpn, *tp;
31344 X  int i, rn, n;
31345 X  int ic;
31346 X  int sstart, sstop, sset=0;
31347 X  int llen, l_offset;
31348 #ifdef SUPERFAMNUM
31349 X  static char tline[MAXLINE];
31350 #endif
31351 X
31352 X  seq_title[0]='\0';
31353 X  libstr[0]='\0';
31354 X
31355 X  sstart = sstop = -1;
31356 #ifndef DOS
31357 X  if ((bp=strchr(filen,':'))!=NULL && *(bp+1)!='\0') {
31358 #else
31359 X  if ((bp=strchr(filen+3,':'))!=NULL && *(bp+1)!='\0') {
31360 #endif
31361 X    *bp='\0';
31362 X    if (*(bp+1)=='-') {
31363 X      sstart = 0;
31364 X      sscanf(bp+2,"%d",&sstop);
31365 X    }
31366 X    else {
31367 X      sscanf(bp+1,"%d-%d",&sstart,&sstop);
31368 X      sstart--;
31369 X      if (sstop <= 0 ) sstop = BIGNUM;
31370 X    }
31371 X    sset=1;
31372 X  }
31373 X  else {
31374 X    sstart = 0;
31375 X    sstop = BIGNUM;
31376 X  }
31377 X
31378 X  /* check for input from stdin */
31379 X  if (strcmp(filen,"-") && strcmp(filen,"@")) {
31380 X    if ((fptr=fopen(filen,"r"))==NULL) {
31381 X      fprintf(stderr," could not open %s\n",filen);
31382 X      return 0;
31383 X    }
31384 X  }
31385 X  else {
31386 X    fptr = stdin;
31387 X  }
31388 X  rn = n=0;
31389 X
31390 X  while(fgets(line,sizeof(line),fptr)!=NULL) {
31391 #ifdef PIRLIB
31392 X    if (line[0]=='>'&& (line[3]==';'||line[3]=='>'))
31393 X      fgets(line,sizeof(line),fptr);
31394 X    else
31395 #endif
31396 X    l_offset = 0;
31397 X    if (line[0]=='>') {
31398 X      seq_format = FASTA_FORMAT;
31399 #ifdef SUPERFAMNUM
31400 X      sfnum[nsfnum=0]= sfnum_n[nsfnum_n=0]=0;
31401 X      strncpy(tline,line+1,sizeof(tline));
31402 X      tline[sizeof(tline)-1]='\0';
31403 X
31404 X      if ((bp=strchr(tline,' ')) && (bp=strchr(bp+1,SFCHAR))) {
31405 X       if ((bp1=strchr(bp+1,SFCHAR))==NULL) {
31406 X         fprintf(stderr," second %c missing: %s\n",SFCHAR,tline);
31407 X       }
31408 X       else {
31409 X         if ((bpn=strchr(bp+1,NSFCHAR))!=NULL) *bpn = '\0';
31410 X         *bp1 = '\0';
31411 X         i = 0;
31412 X         if ((tp = strtok(bp+1," \t"))!=NULL)  {
31413 X           sfnum[i++] = atoi(tp);
31414 X           while ((tp = strtok((char *)NULL," \t")) != (char *)NULL) {
31415 X             if (isdigit(*tp)) sfnum[i++] = atoi(tp);
31416 X             if (i>=9) break;
31417 X           }
31418 X         }
31419 X         sfnum[nsfnum=i]= 0;
31420 X         if (nsfnum>1) sf_sort(sfnum,nsfnum);
31421 X         else {
31422 X           if (nsfnum < 1) fprintf(stderr," found | but no sfnum: %s\n",libstr);
31423 X         }
31424 X         if (bpn != NULL) {
31425 X           tp = strtok(bpn+1," \t");
31426 X           sfnum_n[0]=atoi(tp);
31427 X           i = 1;
31428 X           while ((tp=strtok(NULL," \t"))!=NULL) {
31429 X             sfnum_n[i++] = atoi(tp);
31430 X             if (i >= 10) {
31431 X               fprintf(stderr,
31432 X                       " error - too many negative superfamilies: %d\n %s\n",
31433 X                       i,tline);
31434 X               break;
31435 X             }
31436 X           }
31437 X           sfnum_n[nsfnum_n=i]=0;
31438 X           sf_sort(sfnum_n,nsfnum_n);
31439 X         }
31440 X       }
31441 X      }
31442 X      else {
31443 X       sfnum[nsfnum = 0] = 0;
31444 X       sfnum_n[nsfnum_n = 0] = 0;
31445 X      }
31446 #endif
31447 X      if ((bp=(char *)strchr(line,'\n'))!=NULL) *bp='\0';
31448 X      strncpy(seq_title,line+1,sizeof(seq_title));
31449 X      seq_title[sizeof(seq_title)-1]='\0';
31450 X      if ((bp=(char *)strchr(line,' '))!=NULL) *bp='\0';
31451 X      strncpy(libstr,line+1,12);
31452 X      libstr[12]='\0';
31453 X    }
31454 X    else if (seq_format==NO_FORMAT && strcmp(line,"..")==0) {
31455 X      seq_format = GCG_FORMAT;
31456 /*
31457 X      if (*dnaseq != 1) qascii['*'] = qascii['X'];
31458 */
31459 X      l_offset = 10;
31460 X      llen = strlen(line);
31461 X      while (strncmp(&line[llen-3],"..\n",(size_t)3) != 0) {
31462 X       if (fgets(line,sizeof(line),fptr)==NULL) return 0;
31463 X       llen = strlen(line);
31464 X      }
31465 X      bp = strtok(line," \t");
31466 /*
31467 X      if ((bp=(char *)strchr(line,' '))!=NULL) *bp='\0';
31468 X      else if ((bp=(char *)strchr(line,'\n'))!=NULL) *bp='\0';
31469 */
31470 X      if (bp!=NULL) strncpy(libstr,bp,12);
31471 X      else strncpy(libstr,filen,12);
31472 X      libstr[12]='\0';
31473 X      if (fgets(line,sizeof(line),fptr)==NULL) return 0;
31474 X    }
31475 X    else {
31476 X      if (libstr[0]=='\0') strncpy(libstr,filen,12);
31477 X      libstr[12]='\0';
31478 X    }
31479 X
31480 X    if (seq_format==GCG_FORMAT && strlen(line)<l_offset) continue;
31481 X
31482 X    if (line[0]!='>'&& line[0]!=';') {
31483 X      for (i=l_offset; (n<maxs && rn < sstop)&&
31484 X            ((ic=qascii[line[i]&AAMASK])<EL); i++)
31485 X       if (ic<NA && ++rn > sstart) seq[n++]= ic;
31486 X      if (ic == ES || rn > sstop) break;
31487 X    }
31488 X  }
31489 X
31490 X  if (n==maxs) {
31491 X    fprintf(stderr," sequence may be truncated %d %d\n",n,maxs);
31492 X    fflush(stderr);
31493 X  }
31494 X  if ((bp=strchr(libstr,'\n'))!=NULL) *bp = '\0';
31495 X  if ((bp=strchr(libstr,'\r'))!=NULL) *bp = '\0';
31496 X  seq[n]= EOSEQ;
31497 X
31498 X
31499 X  if (seq_format !=GCG_FORMAT) 
31500 X    while(fgets(line,sizeof(line),fptr)!=NULL) {
31501 #ifdef PIRLIB
31502 X      if (line[0]=='>'&& (line[3]==';'||line[3]=='>'))
31503 X       fgets(line,sizeof(line),fptr);
31504 X      else
31505 #endif
31506 X       if (line[0]!='>'&& line[0]!=';') {
31507 X         for (i=0; (n<maxs && rn < sstop)&&
31508 X                ((ic=qascii[line[i]&AAMASK])<EL); i++)
31509 X           if (ic<NA && ++rn > sstart ) seq[n++]= ic;
31510 X         if (ic == ES || rn > sstop) break;
31511 X       }
31512 X    }
31513 X  else {
31514 X    llen = strlen(line);
31515 X    while (strncmp(&line[llen-3],"..\n",(size_t)3) != 0) {
31516 X      if (fgets(line,sizeof(line),fptr)==NULL) return 0;
31517 X      llen = strlen(line);
31518 X    }
31519 X    while (fgets(line,sizeof(line),fptr)!=NULL) {
31520 X      if (strlen(line)<l_offset) continue;
31521 X      for (i=l_offset; (n<maxs && rn < sstop) &&
31522 X            ((ic=qascii[line[i]&AAMASK])<EL); i++)
31523 X       if (ic<NA && ++rn > sstart ) seq[n++]= ic;
31524 X      if (ic == ES || rn > sstop ) break;
31525 X    }
31526 X  }
31527 X
31528 X  if (n==maxs) {
31529 X    fprintf(stderr," sequence may be truncated %d %d\n",n,maxs);
31530 X    fflush(stderr);
31531 X  }
31532 X  seq[n]= EOSEQ;
31533 X
31534 X  if (fptr!=stdin) fclose(fptr);
31535 X
31536 X  if (sset==1) {
31537 X    sstart++;
31538 X    filen[strlen(filen)]=':';
31539 X    if (*sq0off==1 || sstart>=1) *sq0off = sstart;
31540 X  }
31541 X
31542 X  return n;
31543 }
31544 X
31545 int
31546 gettitle(char *filen, char *title, int len) {
31547 X  FILE *fptr;
31548 X  char line[512];
31549 X  char *bp;
31550 X  int sset;
31551 #ifdef WIN32
31552 X  char *strpbrk();
31553 #endif
31554 X
31555 X  sset = 0;
31556 X
31557 X  if (strncmp(filen,"-",1)==0 || strncmp(filen,"@",1)==0) {
31558 X    strncpy(title,seq_title,len);
31559 X    title[len-1]='\0';
31560 X    return (int)strlen(title);
31561 X  }
31562 X
31563 X  if ((bp=strchr(filen,':'))!=NULL) { *bp='\0'; sset=1;}
31564 X         
31565 X
31566 X  if ((fptr=fopen(filen,"r"))==NULL) {
31567 X    fprintf(stderr," file %s was not found\n",filen);
31568 X    fflush(stderr);
31569 X    return 0;
31570 X  }
31571 X
31572 X  if (sset==1) filen[strlen(filen)]=':';
31573 X
31574 X  while(fgets(line,sizeof(line),fptr)!=NULL) {
31575 X    if (line[0]=='>'|| line[0]==';') goto found;
31576 X  }
31577 X  fclose(fptr);
31578 X  title[0]='\0';
31579 X  return 0;
31580 X
31581 X found:
31582 X
31583 #ifdef PIRLIB
31584 X  if (line[0]=='>'&&(line[3]==';'||line[3]=='>')) {
31585 X    if ((bp = strchr(line,'\n'))!=NULL) *bp='\0';
31586 X    ll=strlen(line); line[ll++]=' '; line[ll]='\0';
31587 X    fgets(&line[ll],sizeof(line)-ll,fptr);
31588 X  }
31589 #endif
31590 X
31591 #ifdef WIN32
31592 X  bp = strpbrk(line,"\n\r");
31593 #else
31594 X  bp = strchr(line,'\n');
31595 #endif
31596 X  if (bp!=NULL) *bp = 0;
31597 X  strncpy(title,line,len);
31598 X  title[len-1]='\0';
31599 X  fclose(fptr);
31600 X  return strlen(title);
31601 }
31602 X
31603 SHAR_EOF
31604 chmod 0644 getseq.c ||
31605 echo 'restore of getseq.c failed'
31606 Wc_c="`wc -c < 'getseq.c'`"
31607 test 9431 -eq "$Wc_c" ||
31608         echo 'getseq.c: original size 9431, current size' "$Wc_c"
31609 fi
31610 # ============= grou_drome.pseg ==============
31611 if test -f 'grou_drome.pseg' -a X"$1" != X"-c"; then
31612         echo 'x - skipping grou_drome.pseg (File already exists)'
31613 else
31614 echo 'x - extracting grou_drome.pseg (Text)'
31615 sed 's/^X//' << 'SHAR_EOF' > 'grou_drome.pseg' &&
31616 >gi|121620|sp|P16371|GROU_DROME GROUCHO PROTEIN (ENHANCER OF SPLIT M9/10)
31617 MYPSPVRHpaaggpppqgpIKFTIADTLERIKEEFNFLQAHYHSIKLECEKLSNEKTEMQ
31618 RHYVMYYEMSYGLNVEMHKQTEIAKRLNTLINQLLPFLQADHQQQVLQAVERAKQVTMQE
31619 LNLIIGQQIHAqqvpggppqpmgALNPFGALGATMGLPHGPQGLLNKPPEHHRPDIKPTG
31620 LEGPAAAEERLRNSVSPADREKYRTRSPLDIENDSKRRKDEKLQEDEGEKSDQDLVVDVA
31621 NEMESHSPRPNGEHVSMEVRDRESLNGERLEKPSSSGIKQErppsrsgssssrstpsLKT
31622 KDMEKPGTPGakartptpnaaapapgvnpkqmmpqgpppagypgapyqrpaDPYQRPPSD
31623 PAYGRPPPMPYDPHAHVRTNGIPHPSALTGGKPAYSFHMNGEGSLQPVPFPPDALVGVGI
31624 PRHARQINTLSHGEVVCAVTISNPTKYVYTGGKGCVKVWDISQPGNKNPVSQLDCLQRDN
31625 YIRSVKLLPDGRTLIVGGEASNLSIWDLASPTPRIKAELTSAAPACYALAISPDSKVCFS
31626 CCSDGNIAVWDLHNEILVRQFQGHTDGASCIDISPDGSRLWTGGLDNTVRSWDLREGRQL
31627 QQHDFSSQIFSLGYCPTGDWLAVGMENSHVEVLHASKPDKYQLHLHESCVLSLRFAACGK
31628 WFVSTGKDNLLNAWRTPYGASIFQSKETSSVLSCDISTDDKYIVTGSGDKKATVYEVIY
31629 X
31630 SHAR_EOF
31631 chmod 0644 grou_drome.pseg ||
31632 echo 'restore of grou_drome.pseg failed'
31633 Wc_c="`wc -c < 'grou_drome.pseg'`"
31634 test 806 -eq "$Wc_c" ||
31635         echo 'grou_drome.pseg: original size 806, current size' "$Wc_c"
31636 fi
31637 # ============= gst.nlib ==============
31638 if test -f 'gst.nlib' -a X"$1" != X"-c"; then
31639         echo 'x - skipping gst.nlib (File already exists)'
31640 else
31641 echo 'x - extracting gst.nlib (Text)'
31642 sed 's/^X//' << 'SHAR_EOF' > 'gst.nlib' &&
31643 >pGT875 | 266
31644 GCTGAAGCCAGTTTGAGAAGACCACAGCACCAGCACCATGCCTATGATACTGGGATACTG
31645 GAACGTCCGCGGACTGACACACCCGATCCGCATGCTCCTGGAATACACAGACTCAAGCTA
31646 TGATGAGAAGAGATACACCATGGGTGACGCTCCCGACTTTGACAGAAGCCAGTGGCTGAA
31647 TGAGAAGTTCAAGCTGGGCCTGGACTTTCCCAATCTGCCTTACTTGATCGATGGATCACA
31648 CAAGATCACCCAGAGCAATGCCATCCTGCGCTACCTTGCCCGAAAGCACCACCTGGATGG
31649 AGAGACAGAGGAGGAGAGGATCCGTGCAGACATTGTGGAGAACCAGGTCATGGACACCCG
31650 catgcagctcatcatgctctgttacaaccctgactttgagaagcagaagccagagttctt
31651 gaagaccatccctgagaaaatgaagctctactctgagttcctgggcaagaggccatggtt
31652 tgcaggggacaaggtcacctatgtggatttccttgcttatgacattcttgaccagtaccg
31653 tatgtttgagcccaagtgcctggacgccttcccaaacctgagggacttcctggcccgctt
31654 cgagggcctcaagaagatctctgcctacatgaagagtagccgctacatcgcaacacctat
31655 ATTTTCAAAGATGGCCCACTGGAGTAACAAGTAGGCCCTTGCTACACGGGCACTCACTAG
31656 GAGGACCTGTCCACACTGGGGATCCTGCAGGCCCTGGGTGGGGACAGCACCCTGGCCTTC
31657 TGCACTGTGGCTCCTGGTTCTCTCTCCTTCCCGCTCCCTTCTGCAGCTTGGTCAGCCCCA
31658 TCTCCTCACCCTCTTCCCAGTCAAGTCCACACAGCCTTCATTCTCCCCAGTTTCTTTCAC
31659 ATGGCCCCTTCTTCATTGGCTCCCTGACCCAACCTCACAGCCCGTTTCTGCGAACTGAGG
31660 TCTGTCCTGAACTCACGCTTCCTAGAATTACCCCGATGGTCAACACTATCTTAGTGCTAG
31661 CCCTCCCTAGAGTTACCCCGAAGTCAATACTTGAGTGCCAGCCTGTTCCTGGTGGAGTAG
31662 CCTCCCCAGGTCTGTCTCGTCTACAATAAAGTCTGAAACACACTT
31663 >RABGLTR Oryctolagus cuniculus glutathione S-transferase mRNA, complete cds.
31664 X CGGCAGCTCC TGTGGACTCA GAGGAGCTGC ACCATGCCCA TGACGCTGGG TTACTGGGAC
31665 X GTCCGTGGGC TGGCTCTGCC AATCCGCATG CTCCTGGAAT ACACGGACAC CAGCTATGAG
31666 X GAAAAGAAAT ACACCATGGG GGATGCTCCC AACTATGACC AAAGCAAGTG GCTGAGTGAG
31667 X AAGTTCACCC TGGGCCTGGA CTTTCCCAAT CTGCCCTACC TAATTGATGG GACTCACAAG
31668 X CTCACGCAGA GCAACGCCAT CCTGCGCTAC CTGGCCCGCA AGCACGGCCT GTGTGGGGAG
31669 X ACGGAAGAGG AGAGGATTCG CGTGGACATT CTGGAGAATC AGCTGATGGA CAACCGCTTC
31670 X CAACTTGTAA ACGTCTGCTA CAGTCCCGAC TTTGAGAAGC TCAAGCCCGA GTACCTGAAG
31671 X GGGCTCCCTG AGAAGCTGCA GCTGTACTCG CAGTTCCTGG GAAGCCTCCC CTGGTTCGCA
31672 X GGGGACAAGA TCACCTTCGC CGATTTCCTT GTCTACGACG TTCTTGACCA GAACCGGATA
31673 X TTTGTGCCTG GGTGCCTGGA CGCGTTCCCA AACCTGAAGG ACTTTCATGT CCGCTTTGAG
31674 X GGCCTGCCGA AGATCTCTGC CTACATGAAG TCCAGCCGCT TTATCCGAGT CCCTGTGTTT
31675 X TTAAAGAAGG CCACGTGGAC GGGAATATAG GGCCCTGGAA GGAGGTGGGC CATCCCCTGG
31676 X GAGCTCAGGT CTCCCAGCCT CTTGCTCATC TTCCTCAACC TTCCCAAAAA CAAAAGCCTA
31677 X CTGCCTGCTT GTGTTCTGAG CCAGCCCCTC CCATGCAGGC TCTGGCCAGC TCAGAAACCC
31678 X ACCCTTCTAG CCATGGGCTC TCTAAGGCTG CTCTTCCCGG ACTAAGCAGA CCCCACGGGC
31679 X CACATCTCTC TTCGTGGGCT CCGTTTGATC TCCCCGACTG CCAGAATCAT GGTTGTACCT
31680 X GCTGCGGCCC TATTCCCAGG CGGGACTCCC CAGTGCTGTT TGGTCCCCAG GAGGGCCTGA
31681 X CCTCAGCCAG GGCCCTTCTT ACCCCTCCCT GTGTTGCACT GGAGTGGGCG CTGACTGTGC
31682 X AGACCTTGGG GGGGTTTCTT TGTTCTGCTG CCCACAGCAT GGCTGGGTGG GGCAGGATTA
31683 X GTGTGGGGGG AGTTGGGTGC TCAGGCAGGG CTATGAGGGA TCTTGTTCAT TTCCGGGCCC
31684 X TATCCATGTG CTCTGCTCCT CGCCCTGGGT TTTCTCCTCT GCCCGGGTTC CTCGTTCCTT
31685 X CACCCTGGAG GGAGGCCAGG GCCACGTGCA GCCGTGCCGG GTTCTGAGAG CGCTGGGCTG
31686 X ATGGGGACGG GGCTGAGCAG GCTTGAGCAG ACCCCTCTGT CACCATCTCC CGGAAGCTTT
31687 X CAGCTGATAC AGATGCTCCT CGTCTATAGT TTCAGGATGT TTCTCAATAA AACATCCCAC
31688 X TGT
31689 >BTGST Bovine GST mRNA for gluthathione S-transferase, class-pi.
31690 X CGGCTCAGGC CGCCGCCGAG CGCGCTGGAA CTTTGCTGCC GCCGCCACCT TTACCGACTT
31691 X CCCCGACTCC AGGATGCCTC CCTACACCAT CGTCTACTTC CCGGTTCAAG GGCGCTGCGA
31692 X GGCCATGCGC ATGCTGCTGG CCGACCAGGG CCAGAGCTGG AAGGAGGAGG TCGTAGCCAT
31693 X GCAGAGCTGG CTGCAGGGCC CACTCAAGGC CTCCTGCCTG TACGGGCAGC TCCCCAAGTT
31694 X CCAGGACGGA GACCTCACGC TGTACCAGTC CAATGCCATC CTGCGGCACC TGGGCCGCAC
31695 X CCTCGGGCTG TATGGGAAGG ACCAGCAGGA GGCGGCCCTG GTGGACATGG TGAATGACGG
31696 X TGTAGAGGAC CTTCGCTGCA AATACGTCTC CCTCATTTAC ACCAACTACG AGGCGGGCAA
31697 X GGAGGACTAT GTGAAGGCGC TGCCCCAGCA CCTGAAGCCT TTCGAGACCC TGCTGTCCCA
31698 X GAACAAGGGT GGCCAGGCCT TCATCGTGGG CGACCAGATC TCCTTTGCGG ACTACAACCT
31699 X GCTGGACCTG CTTCGGATTC ACCAGGTCCT GGCCCCCAGC TGTCTGGACT CCTTCCCCCT
31700 X GCTCTCAGCC TACGTGGCCC GTCTCAACTC CCGGCCCAAG CTCAAGGCCT TCCTGGCCTC
31701 X CCCCGAGCAC ATGAACCGGC CCATCAACGG CAATGGGAAA CAGTGAGGGC TTGCAGCACT
31702 X CTCTGCTCGA GGCAGGGGGC TGCCTGCTCT TCCCTTTCCC CAGGACCAAT AAAACTTCCA
31703 X AGAGAGAAAA AAAAAAAAAA AAAAAAAAA
31704 >OCDHPR Rabbit mRNA for dihydropyridine (DHP) receptor (from skeletal
31705 X TTCCACCTAC ATGTTGGCCT GGACAGCAGG GAGCCGAGGG GAGGCTAATT TTACTGCTGG
31706 X GAGCAGCTAG CATAATCCTC CCGCCCCCAC CCCGCTGGCT CAGCAGGGCA GGCTTCGCCC
31707 X GGCAAGCTCA GCGGCCCAGT CCCCAAGGCG GGGAACACTG GGGACGCAGG GAAGAGAGGG
31708 X CCGCGGGGTG GGGGAGCAGC AGGAAGCGCC GTGGCCAGGG AAGCCATGGA GCCATCCTCA
31709 X CCCCAGGATG AGGGCCTGAG GAAGAAACAG CCCAAGAAGC CCCTGCCCGA GGTCCTGCCC
31710 X AGGCCGCCGC GGGCTCTGTT CTGCCTGACC CTGCAGAACC CGCTGAGGAA GGCGTGCATC
31711 X AGCATCGTGG AATGGAAACC CTTCGAGACC ATCATCCTGC TCACCATCTT TGCCAACTGT
31712 X GTGGCCCTGG CCGTGTACCT GCCCATGCCC GAGGATGACA ACAACTCCCT GAACCTGGGC
31713 X CTGGAGAAGC TGGAGTACTT CTTCCTCACC GTCTTCTCCA TCGAAGCCGC CATGAAGATC
31714 X ATCGCCTACG GCTTCCTGTT CCACCAGGAC GCCTACCTGC GCAGCGGCTG GAACGTGCTG
31715 X GACTTCATCA TCGTCTTCCT GGGGGTCTTC ACGGCGATTC TGGAACAGGT CAACGTCATC
31716 X CAGAGCAACA CGGCCCCGAT GAGCAGCAAA GGAGCCGGCC TGGACGTCAA GGCCCTGAGG
31717 X GCCTTCCGTG TGCTCAGACC CCTCCGGCTG GTGTCGGGGG TGCCTAGTTT GCAGGTGGTC
31718 X CTCAACTCCA TCTTCAAGGC CATGCTCCCC CTGTTCCACA TCGCCCTGCT CGTCCTCTTC
31719 X ATGGTCATCA TCTACGCCAT CATCGGGCTG GAGCTCTTCA AGGGCAAGAT GCACAAGACC
31720 X TGCTACTACA TCGGGACAGA CATCGTGGCC ACAGTGGAGA ATGAGAAGCC CTCGCCCTGC
31721 X GCTAGGACGG GCTCGGGGCG CCCCTGCACC ATCAACGGCA GCGAGTGCCG GGGCGGCTGG
31722 X CCGGGGCCCA ACCACGGCAT CACGCACTTC GACAACTTCG GCTTCTCCAT GCTCACCGTG
31723 X TACCAGTGCA TCACCATGGA GGGCTGGACA GATGTCCTCT ACTGGGTCAA CGATGCCATC
31724 X GGGAACGAGT GGCCCTGGAT CTACTTTGTC ACTCTCATCC TGCTGGGGTC CTTCTTCATC
31725 X CTCAACCTGG TGCTGGGCGT CCTGAGTGGG GAATTCACCA AGGAGCGGGA GAAGGCCAAG
31726 X TCCAGGGGAA CCTTCCAGAA GCTGCGGGAG AAGCAGCAGC TGGAGGAGGA CCTTCGGGGC
31727 X TACATGAGCT GGATCACGCA GGGCGAGGTC ATGGACGTGG AGGACCTGAG AGAAGGAAAG
31728 X CTGTCCTTGG AAGAGGGAGG CTCCGACACG GAAAGCCTGT ACGAAATCGA GGGCTTGAAC
31729 X AAAATCATCC AGTTCATCCG ACACTGGAGG CAGTGGAACC GTGTCTTTCG CTGGAAGTGC
31730 X CATGACCTGG TGAAGTCGAG AGTCTTCTAC TGGCTGGTCA TCCTGATCGT GGCCCTCAAC
31731 X ACCCTGTCCA TCGCCTCGGA GCACCACAAC CAGCCGCTCT GGCTGACCCA CTTGCAAGAC
31732 X ATCGCCAATC GAGTGCTGCT GTCACTCTTC ACCATCGAGA TGCTGCTGAA GATGTACGGG
31733 X CTGGGCCTGC GCCAGTACTT CATGTCCATC TTCAACCGCT TCGACTGCTT CGTGGTGTGC
31734 X AGCGGCATCC TGGAGCTGCT GCTGGTGGAG TCGGGCGCCA TGACGCCGCT GGGCATCTCC
31735 X GTGTTGCGCT GCATCCGCCT CCTGAGGCTC TTCAAGATCA CCAAGTACTG GACGTCGCTC
31736 X AGCAACCTGG TGGCCTCCCT GCTCAACTCC ATCCGCTCCA TCGCCTCGCT GCTGCTGCTG
31737 X CTCTTCCTCT TCATCATCAT CTTCGCCCTG CTGGGCATGC AGCTCTTCGG GGGGCGGTAC
31738 X GACTTCGAGG ACACGGAAGT GCGACGCAGC AACTTCGACA ACTTCCCCCA GGCCCTCATC
31739 X AGCGTCTTCC AGGTGCTGAC GGGTGAGGAC TGGAACTCCG TGATGTACAA CGGGATCATG
31740 X GCCTACGGAG GCCCGTCCTA CCCGGGCGTT CTCGTGTGCA TCTATTTCAT CATCCTTTTT
31741 X GTCTGCGGCA ACTATATCCT GCTGAATGTC TTCCTGGCCA TCGCCGTGGA CAACCTGGCC
31742 X GAGGCGGAGA GCCTGACTTC CGCGCAAAAG GCCAAGGCCG AGGAGAGGAA ACGCAGGAAG
31743 X ATGTCCAGGG GTCTCCCTGA CAAGACAGAG GAGGAGAAGT CTGTGATGGC CAAGAAGCTG
31744 X GAGCAGAAGC CCAAGGGGGA GGGCATCCCC ACCACTGCCA AGCTCAAGGT CGATGAGTTC
31745 X GAATCTAACG TCAACGAGGT GAAGGACCCC TACCCTTCAG CTGACTTCCC AGGGGATGAT
31746 X GAGGAGGACG AGCCTGAGAT CCCAGTGAGC CCCCGACCGC GCCCGCTGGC CGAGCTGCAG
31747 X CTCAAAGAGA AGGCAGTGCC CATCCCGGAA GCCAGCTCCT TCTTCATCTT CAGTCCCACC
31748 X AATAAGGTCC GTGTCCTGTG TCACCGCATC GTCAACGCCA CCTGGTTCAC CAACTTCATC
31749 X CTGCTCTTCA TCCTGCTCAG CAGTGCTGCG CTGGCCGCCG AGGACCCCAT CCGGGCGGAG
31750 X TCCGTGAGGA ATCAGATCCT TGGATATTTT GATATTGCCT TCACCTCTGT CTTCACTGTG
31751 X GAGATTGTCC TCAAGATGAC GACCTACGGC GCCTTCCTGC ACAAGGGCTC CTTCTGCCGC
31752 X AACTACTTCA ACATCCTGGA CCTGCTGGTG GTGGCTGTGT CTCTCATCTC CATGGGTCTC
31753 X GAGTCCAGCA CCATCTCCGT GGTAAAGATC CTGAGAGTGC TAAGGGTGCT CCGGCCCCTG
31754 X CGAGCCATCA ACAGAGCCAA AGGGTTGAAG CACGTGGTCC AGTGCGTGTT CGTGGCCATC
31755 X CGCACCATCG GGAACATCGT CCTGGTCACC ACGCTCCTGC AGTTCATGTT CGCCTGCATT
31756 X GGTGTCCAGC TCTTCAAGGG CAAGTTCTTC AGCTGCAACG ACCTATCCAA GATGACAGAA
31757 X GAGGAGTGCA GGGGCTACTA CTATGTGTAC AAGGACGGGG ACCCCACGCA GATGGAGCTG
31758 X CGCCCCCGCC AGTGGATACA CAATGACTTC CACTTTGACA ACGTGCTGTC GGCCATGATG
31759 X TCGCTCTTCA CGGTGTCCAC CTTCGAGGGA TGGCCCCAGC TGCTGTACAG GGCCATAGAC
31760 X TCCAACGAGG AGGACATGGG CCCCGTTTAC AACAACCGAG TGGAGATGGC CATCTTCTTC
31761 X ATCATCTACA TCATCCTCAT TGCCTTCTTC ATGATGAACA TCTTTGTGGG CTTTGTCATC
31762 X GTCACCTTCC AGGAGCAGGG GGAGACAGAG TACAAGAACT GCGAGCTGGA CAAGAACCAG
31763 X CGCCAGTGTG TGCAGTATGC CCTGAAGGCC CGCCCACTTC GGTGCTACAT CCCCAAGAAC
31764 X CCATACCAGT ACCAGGTGTG GTACGTCGTC ACCTCCTCCT ACTTTGAATA CCTGATGTTC
31765 X GCCCTCATCA TGCTCAACAC CATCTGCCTG GGCATGCAGC ACTACCACCA GTCGGAGGAG
31766 X ATGAACCACA TCTCGGACAT CCTCAACGTG GCCTTCACCA TCATCTTCAC ACTGGAGATG
31767 X ATCCTCAAGC TCTTGGCGTT CAAGGCCAGG GGCTATTTCG GAGACCCCTG GAATGTGTTC
31768 X GACTTCCTGA TCGTCATCGG CAGCATCATT GACGTCATCC TCAGCGAGAT CGACACTTTC
31769 X CTGGCCTCCA GCGGGGGACT GTATTGCCTG GGTGGCGGCT GCGGGAACGT TGACCCAGAC
31770 X GAGAGCGCCC GCATCTCCAG TGCCTTCTTC CGCCTGTTCC GGGTCATGAG GCTGATCAAG
31771 X CTGCTGAGTC GGGCCGAGGG CGTGCGCACG CTGCTGTGGA CGTTCATCAA GTCCTTCCAG
31772 X GCCCTGCCCT ACGTGGCCCT GCTCATCGTC ATGCTGTTCT TCATCTACGC CGTCATCGGC
31773 X ATGCAGATGT TTGGAAAGAT CGCCCTGGTG GACGGGACCC AGATCAACCG CAACAACAAC
31774 X TTCCAGACCT TCCCGCAGGC CGTGCTGCTG CTCTTCAGGT GTGCGACAGG GGAGGCGTGG
31775 X CAAGAGATCC TGCTGGCCTG CAGCTACGGG AAGTTGTGCG ACCCAGAGTC AGACTACGCC
31776 X CCGGGCGAGG AGTACACGTG TGGCACCAAC TTCGCCTACT ACTACTTCAT CAGCTTCTAC
31777 X ATGCTCTGCG CCTTCCTGAT CATCAACCTC TTCGTGGCTG TCATCATGGA CAACTTTGAC
31778 X TACCTGACAC GCGACTGGTC CATCCTGGGC CCTCACCACC TGGACGAGTT CAAGGCTATC
31779 X TGGGCAGAGT ATGACCCAGA GGCCAAGGGG CGAATCAAGC ACCTGGACGT GGTGACCCTG
31780 X CTGAGAAGGA TCCAGCCCCC TCTGGGCTTC GGGAAGTTCT GTCCACACCG GGTGGCCTGT
31781 X AAGCGCCTGG TGGGCATGAA CATGCCCCTG AACAGTGACG GCACGGTCAC CTTCAATGCC
31782 X ACGCTCTTTG CCCTGGTGCG CACGGCCCTC AAGATCAAGA CAGAAGGTAA CTTTGAGCAG
31783 X GCCAACGAGG AGCTGAGGGC CATCATCAAG AAGATCTGGA AGAGAACCAG CATGAAGCTG
31784 X CTGGACCAGG TCATCCCTCC CATAGGAGAT GACGAGGTGA CCGTGGGGAA GTTCTACGCC
31785 X ACATTCCTCA TCCAGGAGCA CTTCCGGAAG TTCATGAAGC GCCAGGAGGA ATATTATGGG
31786 X TATCGGCCCA AGAAGGACAC CGTGCAGATC CAGGCTGGGC TGCGGACCAT AGAGGAGGAG
31787 X GCGGCCCCTG AGATCCGCCG CACCATCTCA GGAGACCTGA CCGCCGAGGA GGAGCTGGAG
31788 X AGAGCCATGG TGGAGGCTGC GATGGAGGAG AGGATCTTCC GGAGGACGGG AGGCCTGTTT
31789 X GGCCAGGTGG ACACCTTCCT GGAAAGGACC AACTCCCTGC CCCCGGTGAT GGCCAACCAA
31790 X AGACCGCTCC AGTTTGCTGA GATAGAAATG GAAGAGCTTG AGTCGCCTGT CTTCTTGGAG
31791 X GACTTCCCTC AAGATGCAAG AACCAACCCT CTCGCTCGTG CCAATACCAA CAACGCCAAT
31792 X GCCAATGTTG CCTATGGCAA CAGCAACCAT AGCAACAACC AGATGTTTTC CAGCGTCCAC
31793 X TGTGAAAGGG AGTTCCCGGG AGAGGCGGAG ACACCGGCTG CCGGACGAGG AGCCCTCAGC
31794 X CACTCCCACA GGGCCCTGGG ACCTCACAGC AAGCCCTGTG CTGGAAAACT GAATGGGCAG
31795 X CTGGTCCAGC CGGGGATGCC CATCAACCAG GCACCTCCTG CCCCCTGCCA GCAGCCTAGC
31796 X ACGGATCCCC CAGAGCGCGG GCAGAGGAGG ACCTCCCTGA CAGGGTCTCT GCAAGACGAA
31797 X GCACCCCAGA GGAGGAGCTC CGAGGGGAGC ACCCCCAGGC GCCCGGCTCC TGCTACAGCT
31798 X CTGCTGATCC AAGAGGCTCT GGTTCGAGGG GGCCTGGACA CCTTGGCAGC TGATGCTGGC
31799 X TTCGTCACGG CAACAAGCCA GGCCCTGGCA GACGCCTGTC AGATGGAACC GGAGGAAGTA
31800 X GAGGTCGCAG CCACAGAGCT ACTGAAAGCG CGAGAGTCTG TCCAGGGCAT GGCCAGTGTC
31801 X CCGGGAAGCC TGAGCCGCAG GTCCTCCCTG GGCAGCCTTG ACCAGGTCCA GGGCTCCCAG
31802 X GAAACCCTTA TTCCTCCCAG GCCGTGATGG CTGTGGTGTC CACATGACCA AGGCGAGAGG
31803 X GACAGTGCGT GCAGAAGCTC AGCCCTGCAT GGCAGCCTCC CTCTGTCTCA GCCCTCCTGC
31804 X TGAGCTGGGG CGGTCTGGAA CCGCACCAGG AAGCCAGGAG CCTCCCCTGG CCAGCAAGAG
31805 X GCATGATTCT AAAGCCATCC AGAAAGGCCT GGTCAGTGCC ACTCCCCAGC AGGACATTAA
31806 X AGTCTCTAGG TCTGTGGCAC TGG
31807 >RABALP1A Rabbit dihydropyridine-sensitive calcium channel alpha-1 subunit
31808 X TTCCACCTAC ATGTTGGCCT GGACAGCAGG GAGCCGAGGG GAGGCTAATT TTACTGCTGG
31809 X GAGCAGCTAG CATAATCCTC CCGCCCCCAC CCCGCTGGCT CAGCAGGGCA GGCTTCGCCC
31810 X GGCAAGCTCA GCGGCCCAGT CCCCAAGGCG GGGAACACTG GGGACGCAGG GAAGAGAGGG
31811 X CCGCGGGGTG GGGGAGCAGC AGGAAGCGCC GTGGCCAGGG AAGCCATGGA GCCATCCTCA
31812 X CCCCAGGATG AGGGCCTGAG GAAGAAACAG CCCAAGAAGC CCCTGCCCGA GGTCCTGCCC
31813 X AGGCCGCCGC GGGCTCTGTT CTGCCTGACC CTGCAGAACC CGCTGAGGAA GGCGTGCATC
31814 X AGCATCGTGG AATGGAAACC CTTCGAGACC ATCATCCTGC TCACCATCTT TGCCAACTGT
31815 X GTGGCCCTGG CCGTGTACCT GCCCATGCCC GAGGATGACA ACAACTCCCT GAACCTGGGC
31816 X CTGGAGAAGC TGGAGTACTT CTTCCTCACC GTCTTCTCCA TCGAAGCCGC CATGAAGATC
31817 X ATCGCCTACG GCTTCCTGTT CCACCAGGAC GCCTACCTGC GCAGCGGCTG GAACGTGCTG
31818 X GACTTCATCA TCGTCTTCCT GGGGGTCTTC ACGGCGATTC TGGAACAGGT CAACGTCATC
31819 X CAGAGCAACA CGGCCCCGAT GAGCAGCAAA GGAGCCGGCC TGGACGTCAA GGCCCTGAGG
31820 X GCCTTCCGTG TGCTCAGACC CCTCCGGCTG GTGTCGGGGG TGCCTAGTTT GCAGGTGGTC
31821 X CTCAACTCCA TCTTCAAGGC CATGCTCCCC CTGTTCCACA TCGCCCTGCT CGTCCTCTTC
31822 X ATGGTCATCA TCTACGCCAT CATCGGGCTG GAGCTCTTCA AGGGCAAGAT GCACAAGACC
31823 X TGCTACTACA TCGGGACAGA CATCGTGGCC ACAGTGGAGA ATGAGAAGCC CTCGCCCTGC
31824 X GCTAGGACGG GCTCGGGGCG CCCCTGCACC ATCAACGGCA GCGAGTGCCG GGGCGGCTGG
31825 X CCGGGGCCCA ACCACGGCAT CACGCACTTC GACAACTTCG GCTTCTCCAT GCTCACCGTG
31826 X TACCAGTGCA TCACCATGGA GGGCTGGACA GATGTCCTCT ACTGGGTCAA CGATGCCATC
31827 X GGGAACGAGT GGCCCTGGAT CTACTTTGTC ACTCTCATCC TGCTGGGGTC CTTCTTCATC
31828 X CTCAACCTGG TGCTGGGCGT CCTGAGTGGG GAATTCACCA AGGAGCGGGA GAAGGCCAAG
31829 X TCCAGGGGAA CCTTCCAGAA GCTGCGGGAG AAGCAGCAGC TGGAGGAGGA CCTTCGGGGC
31830 X TACATGAGCT GGATCACGCA GGGCGAGGTC ATGGACGTGG AGGACCTGAG AGAAGGAAAG
31831 X CTGTCCTTGG AAGAGGGAGG CTCCGACACG GAAAGCCTGT ACGAAATCGA GGGCTTGAAC
31832 X AAAATCATCC AGTTCATCCG ACACTGGAGG CAGTGGAACC GTGTCTTTCG CTGGAAGTGC
31833 X CATGACCTGG TGAAGTCGAG AGTCTTCTAC TGGCTGGTCA TCCTGATCGT GGCCCTCAAC
31834 X ACCCTGTCCA TCGCCTCGGA GCACCACAAC CAGCCGCTCT GGCTGACCCA CTTGCAAGAC
31835 X ATCGCCAATC GAGTGCTGCT GTCACTCTTC ACCATCGAGA TGCTGCTGAA GATGTACGGG
31836 X CTGGGCCTGC GCCAGTACTT CATGTCCATC TTCAACCGCT TCGACTGCTT CGTGGTGTGC
31837 X AGCGGCATCC TGGAGCTGCT GCTGGTGGAG TCGGGCGCCA TGACGCCGCT GGGCATCTCC
31838 X GTGTTGCGCT GCATCCGCCT CCTGAGGCTC TTCAAGATCA CCAAGTACTG GACGTCGCTC
31839 X AGCAACCTGG TGGCCTCCCT GCTCAACTCC ATCCGCTCCA TCGCCTCGCT GCTGCTGCTG
31840 X CTCTTCCTCT TCATCATCAT CTTCGCCCTG CTGGGCATGC AGCTCTTCGG GGGGCGGTAC
31841 X GACTTCGAGG ACACGGAAGT GCGACGCAGC AACTTCGACA ACTTCCCCCA GGCCCTCATC
31842 X AGCGTCTTCC AGGTGCTGAC GGGTGAGGAC TGGAACTCCG TGATGTACAA CGGGATCATG
31843 X GCCTACGGAG GCCCGTCCTA CCCGGGCGTT CTCGTGTGCA TCTATTTCAT CATCCTTTTT
31844 X GTCTGCGGCA ACTATATCCT GCTGAATGTC TTCCTGGCCA TCGCCGTGGA CAACCTGGCC
31845 X GAGGCCGAGA GCCTGACTTC CGCGCAAAAG GCCAAGGCCG AGGAGAGGAA ACGTAGGAAG
31846 X ATGTCCAGGG GTCTCCCTGA CAAGAGAGAG GAGGAGAAGT CTGTGATGGC CAAGAAGCTG
31847 X GAGCAGAAGC CCAAGGGGGA GGGCATCCCC ACCACTGCCA AGCTCAAGGT CGATGAGTTC
31848 X GAATCTAACG TCAACGAGGT GAAGGACCCC TACCCTTCAG CTGACTTCCC AGGGGATGAT
31849 X GAGGAGGACG AGCCTGAGAT CCCAGTGAGC CCCCGACCGC GCCCGCTGGC CGAGCTGCAG
31850 X CTCAAAGAGA AGGCAGTGCC CATCCCGGAA GCCAGCTCCT TCTTCATCTT CAGTCCCACC
31851 X AATAAGGTCC GTGTCCTGTG TCACCGCATC GTCAACGCCA CCTGGTTCAC CAACTTCATC
31852 X CTGCTCTTCA TCCTGCTCAG CAGTGCTGCG CTGGCCGCCG AGGACCCCAT CCGGGCGGAG
31853 X TCCGTGAGGA ATCAGATCCT TGGATATTTT GATATTGCCT TCACCTCTGT CTTCACTGTG
31854 X GAGATTGTCC TCAAGATGAC AACCTACGGC GCCTTCCTGC ACAAGGGCTC CTTCTGCCGC
31855 X AACTACTTCA ACATCCTGGA CCTGCTGGTG GTGGCCGTGT CTCTCATCTC CATGGGTCTC
31856 X GAGTCCAGCA CCATCTCCGT GGTAAAGATC CTGAGAGTGC TAAGGGTGCT CCGGCCCCTG
31857 X CGAGCCATCA ACAGAGCCAA AGGGTTGAAG CACGTGGTCC AGTGCGTGTT CGTGGCCATC
31858 X CGCACCATCG GGAACATCGT CCTGGTCACC ACGCTCCTGC AGTTCATGTT CGCCTGCATC
31859 X GGTGTCCAGC TCTTCAAGGG CAAGTTCTTC AGCTGCAATG ACCTATCCAA GATGACAGAA
31860 X GAGGAGTGCA GGGGCTACTA CTATGTGTAC AAGGACGGGG ACCCCACGCA GATGGAGCTG
31861 X CGCCCCCGCC AGTGGATACA CAATGACTTC CACTTTGACA ACGTGCTGTC GGCCATGATG
31862 X TCGCTCTTCA CGGTGTCCAC CTTCGAGGGA TGGCCCCAGC TGCTGTACAG GGCCATAGAC
31863 X TCCAACGAGG AGGACATGGG CCCCGTTTAC AACAACCGAG TGGAGATGGC CATCTTCTTC
31864 X ATCATCTACA TCATCCTCAT TGCCTTCTTC ATGATGAACA TCTTTGTGGG CTTTGTCATC
31865 X GTCACCTTCC AGGAGCAGGG GGAGACAGAG TACAAGAACT GCGAGCTGGA CAAGAACCAG
31866 X CGCCAGTGTG TGCAGTATGC CCTGAAGGCC CGCCCACTTC GGTGCTACAT CCCCAAGAAC
31867 X CCATACCAGT ACCAGGTGTG GTACGTCGTC ACCTCCTCCT ACTTTGAATA CCTGATGTTC
31868 X GCCCTCATCA TGCTCAACAC CATCTGCCTG GGCATGCAGC ACTACCACCA GTCGGAGGAG
31869 X ATGAACCACA TCTCAGACAT CCTCAATGTG GCCTTCACCA TCATCTTCAC GCTGGAGATG
31870 X ATTCTCAAGC TCTTGGCGTT CAAGGCCAGG GGCTATTTCG GAGACCCCTG GAATGTGTTC
31871 X GACTTCCTGA TCGTCATCGG CAGCATCATT GACGTCATCC TCAGCGAGAT CGACACTTTC
31872 X CTGGCCTCCA GCGGGGGACT GTATTGCCTG GGTGGCGGCT GCGGGAACGT TGACCCAGAC
31873 X GAGAGCGCCC GCATCTCCAG TGCCTTCTTC CGCCTGTTCC GGGTTATGAG GCTGATCAAG
31874 X CTGCTGAGTC GGGCCGAGGG CGTGCGCACG CTGCTGTGGA CGTTCATCAA GTCCTTCCAG
31875 X GCCCTGCCCT ACGTGGCCCT GCTCATCGTC ATGCTGTTCT TCATCTACGC CGTCATCGGC
31876 X ATGCAGATGT TTGGAAAGAT CGCCCTGGTG GACGGGACCC AGATCAACCG CAACAACAAC
31877 X TTCCAGACCT TCCCGCAGGC CGTGCTGCTG CTCTTCAGGT GTGCGACAGG GGAGGCGTGG
31878 X CAAGAGATCC TGCTGGCCTG CAGCTACGGG AAGTTGTGCG ACCCAGAGTC AGACTACGCC
31879 X CCGGGCGAGG AGTACACGTG TGGCACCAAC TTCGCCTACT ACTACTTCAT CAGCTTCTAC
31880 X ATGCTCTGCG CCTTCCTGAT CATCAACCTC TTCGTGGCTG TCATCATGGA CAACTTTGAC
31881 X TACCTGACAC GCGACTGGTC CATCCTGGGC CCTCACCACC TGGACGAGTT CAAGGCCATC
31882 X TGGGCAGAGT ATGACCCAGA GGCCAAGGGG CGAATCAAGC ACCTGGACGT GGTGACCCTG
31883 X CTGAGAAGGA TCCAGCCCCC TCTGGGCTTC GGGAAGTTCT GTCCACACCG GGTGGCCTGT
31884 X AAGCGCCTGG TGGGCATGAA CATGCCCCTG AACAGTGACG GCACGGTCAC CTTCAATGCC
31885 X ACGCTCTTTG CCCTGGTGCG CACGGCCCTC AAGATCAAGA CAGAAGGTAA CTTCGAGCAG
31886 X GCCAACGAGG AGCTGAGGGC CATCATCAAG AAGATCTGGA AGAGAACCAG CATGAAGCTA
31887 X CTGGACCAGG TCATCCCTCC CATAGGAGAT GACGAGGTGA CCGTGGGGAA GTTCTACGCC
31888 X ACATTCCTCA TCCAGGAGCA CTTCCGGAAG TTCATGAAGC GCCAGGAGGA ATATTATGGG
31889 X TATCGGCCCA AGAAGGACAC CGTGCAGATC CAGGCTGGGC TGCGGACCAT AGAGGAGGAG
31890 X GCGGCCCCTG AGATCCGCCG CACCATCTCA GGAGACCTGA CCGCCGAGGA GGAGCTGGAG
31891 X AGAGCCATGG TGGAGGCTGC GATGGAGGAG AGGATCTTCC GGAGGACCGG AGGCCTGTTT
31892 X GGCCAGGTGG ACACCTTCCT GGAAAGGACC AACTCCCTAC CCCCGGTGAT GGCCAACCAA
31893 X AGACCGCTCC AGTTTGCTGA GATAGAAATG GAAGAGCTTG AGTCGCCTGT CTTCTTGGAG
31894 X GACTTCCCTC AAGACGCAAG AACCAACCCT CTCGCTCGTG CCAATACCAA CAACGCCAAT
31895 X GCCAATGTTG CCTATGGCAA CAGCAACCAT AGCAACAACC AGATGTTTTC CAGCGTCCAC
31896 X TGTGAAAGGG AGTTCCCGGG AGAGGCGGAG ACACCGGCTG CCGGACGAGG AGCCCTCAGC
31897 X CACTCCCACA GGGCCCTGGG ACCTCACAGC AAGCCCTGTG CTGGAAAACT GAATGGGCAG
31898 X CTGGTCCAGC CGGGAATGCC CATCAACCAG GCACCTCCTG CCCCCTGCCA GCAGCCTAGC
31899 X ACAGATCCCC CAGAGCGCGG GCAGAGGAGG ACCTCCCTGA CAGGGTCTCT GCAAGACGAA
31900 X GCACCCCAGA GGAGGAGCTC CGAGGGGAGC ACCCCCAGGC GCCCGGCTCC TGCTACAGCT
31901 X CTGCTGATCC AAGAGGCTCT GGTTCGAGGG GGCCTGGACA CCTTGGCAGC TGATGCTGGC
31902 X TTCGTCATGG CAACAAGCCA GGCCCTGGTA GACGCCTGTC AGATGGAACC GGAGGAAGTA
31903 X GAGGTCGCAG CCACAGAGCT ACTGAAAGAG CGAGAGTCCG TCCAGGGCAT GGCCAGTGTC
31904 X CCGGGAAGCC TGAGCCGCAG GTCCTCCCTG GGCAGCCTTG ACCAGGTCCA GGGCTCCCAG
31905 X GAAACCCTTA TTCCTCCCAG GCCGTGATGG CTGTGCAGTG TCCACATGAC CAAGGCGAGA
31906 X GGGACAGTGC GTGCAGAAGC TCAGCCCTGC ATGGCAGCCT CCCTCTGTCT CAGCCCTCCT
31907 X GCTGAGCTGG GGCGGTCTGG AACCGACCAG GAAGCCAGGA GCCTCCCCTG GCCAGCAAGA
31908 X GGCATGATTC TAAAGCCATC CAGAAAGGCC TGGTCAGTGC CACTCCCCAG CAGGACATTA
31909 X AAGTCTCTAG GTCTGTGGCA 
31910 >RABGSTB Oryctolagus cuniculus glutathione S-transferase mRNA, complete cds.
31911 X CAGAAACCAC CACTATGGCA GGGAAGCCCA AGCTTCACTA CTTCAATGCA CGGGGCAGAA
31912 X TGGAGTCTAT CCGGTGGCTC CTGACTGCAG CTGGGGTAGA GTTTGAAGAG AAATGTATGA
31913 X AAACTCGAGA AGACCTGGAA AAGTTAAGAA AAGATGGGGT ATTGATGTTC CAGCAAGTGC
31914 X CCATGGTTGA GATTGATGGG ATGAAGCTGG TGCAGACCAG AGCCATTTTC AACTACATTG
31915 X CAGACAAGCA CAACCTGTAT GGGAAAGACA TAAAGGAGAG AGCCCTGATT GATATGTATA
31916 X CAGAAGGCAT AGTAGATTTG AATGAATTGA TTCTTACTCG TCCATTCCTT CCACCGGAGG
31917 X AACAAGAGGC AAAACTTGCT CAGATCAAAG ATAAAGCAAA AAACCGTTAT TTTCCTGCCT
31918 X TTGAAAAGGT GTTGAAGAGC CACGGACAAG ACTACCTTGT TGGCAACAAG CTGAGCAAGG
31919 X CTGACATTCT CCTGGTTGAA CTTCTCTACA ACGTGGAAGA GCTCAACCCC GGCGCGACTG
31920 X CCAGCTTCCC TCTGCTGCAG GCCCTGAAAA CCAGGATCAG CAATCTCCCC ACCGTGAAGA
31921 X AGTTTCTGCA GCCTGGCAGC CAGAGGAATC CGCCTGATGA TGAGAAATGC AGAGAAGAAG
31922 X CAAAAATCAT TTTCCATTAA GAAGGCAAAG ATACCAAGCA CAGGCAAGAC CAGCCTCTGA
31923 X CCCCCTGCAG CGATGAAGTA CTTTAAATAA ATAGTGATCC TGATTGTCAT AAGGCATATT
31924 X ACGTTTTCTA AGTATTGTGT AAATTTAATT AAAAACCACC CATGTAGATT TAGTTGCAAT
31925 X ACATGGTACT TGGTTTTGAT CAAATACAAA ATTATGAGCA CCTCCTAGGA TGTCCCTTTG
31926 X AA
31927 SHAR_EOF
31928 chmod 0644 gst.nlib ||
31929 echo 'restore of gst.nlib failed'
31930 Wc_c="`wc -c < 'gst.nlib'`"
31931 test 18633 -eq "$Wc_c" ||
31932         echo 'gst.nlib: original size 18633, current size' "$Wc_c"
31933 fi
31934 # ============= gst.seq ==============
31935 if test -f 'gst.seq' -a X"$1" != X"-c"; then
31936         echo 'x - skipping gst.seq (File already exists)'
31937 else
31938 echo 'x - extracting gst.seq (Text)'
31939 sed 's/^X//' << 'SHAR_EOF' > 'gst.seq' &&
31940 >gi|193547|gb|J04632|MUSGLUTA Mouse glutathione S-transferase class mu (GST1-1) mRNA, complete cds
31941 CCTGCCTTCCGCTTTAGGGTCTGCTGCTCTGGTTACAGACCTAGGAAGGGGAGTGCCTAATTGGGATTGG
31942 TGCAGGGTTGGGAGGGACCCGCTGTTTTGTCCTGCCCACGTTTCTCTAGTAGTCTGTATAAAGTCACAAC
31943 TCCAAACACACAGGTCAGTCCTGCTGAAGCCAGTTTGAGAAGACCACAGCACCAGCACCATGCCTATGAT
31944 ACTGGGATACTGGAACGTCCGCGGACTGACACACCCGATCCGCATGCTCCTGGAATACACAGACTCAAGC
31945 TATGATGAGAAGAGATACACCATGGGTGACGCTCCCGACTTTGACAGAAGCCAGTGGCTGAATGAGAAGT
31946 TCAAGCTGGGCCTGGACTTTCCCAATCTGCCTTACTTGATCGATGGATCACACAAGATCACCCAGAGCAA
31947 TGCCATCCTGCGCTACCTTGCCCGAAAGCACCACCTGGATGGAGAGACAGAGGAGGAGAGGATCCGTGCA
31948 GACATTGTGGAGAACCAGGTCATGGACACCCGCATGCAGCTCATCATGCTCTGTTACAACCCTGACTTTG
31949 AGAAGCAGAAGCCAGAGTTCTTGAAGACCATCCCTGAGAAAATGAAGCTCTACTCTGAGTTCCTGGGCAA
31950 GAGGCCATGGTTTGCAGGGGACAAGGTCACCTATGTGGATTTCCTTGCTTATGACATTCTTGACCAGTAC
31951 CGTATGTTTGAGCCCAAGTGCCTGGACGCCTTCCCAAACCTGAGGGACTTCCTGGCCCGCTTCGAGGGCC
31952 TCAAGAAGATCTCTGCCTACATGAAGAGTAGCCGCTACATCGCAACACCTATATTTTCAAAGATGGCCCA
31953 CTGGAGTAACAAGTAGGCCCTTGCTACACGGGCACTCACTAGGAGGACCTGTCCACACTGGGGATCCTGC
31954 AGGCCCTGGGTGGGGACAGCACCCTGGCCTTCTGCACTGTGGCTCCTGGTTCTCTCTCCTTCCCGCTCCC
31955 TTCTGCAGCTTGGTCAGCCCCATCTCCTCACCCTCTTCCCAGTCAAGTCCACACAGCCTTCATTCTCCCC
31956 AGTTTCTTTCACATGGCCCCTTCTTCATTGGCTCCCTGACCCAACCTCACAGCCCGTTTCTGCGAACTGA
31957 GGTCTGTCCTGAACTCACGCTTCCTAGAATTACCCCGATGGTCAACACTATCTTAGTGCTAGCCCTCCCT
31958 AGAGTTACCCCGAAGTCAATACTTGAGTGCCAGCCTGTTCCTGGTGGAGTAGCCTCCCCAGGTCTGTCTC
31959 GTCTACAATAAAGTCTGAAACACACTT
31960 SHAR_EOF
31961 chmod 0644 gst.seq ||
31962 echo 'restore of gst.seq failed'
31963 Wc_c="`wc -c < 'gst.seq'`"
31964 test 1405 -eq "$Wc_c" ||
31965         echo 'gst.seq: original size 1405, current size' "$Wc_c"
31966 fi
31967 # ============= gtm1_human.aa ==============
31968 if test -f 'gtm1_human.aa' -a X"$1" != X"-c"; then
31969         echo 'x - skipping gtm1_human.aa (File already exists)'
31970 else
31971 echo 'x - extracting gtm1_human.aa (Text)'
31972 sed 's/^X//' << 'SHAR_EOF' > 'gtm1_human.aa' &&
31973 >gtm1_human GLUTATHIONE S-TRANSFERASE MU 1 (EC 2.5.1.18) (GSTM1-1) (HB SUBUNI
31974 MPMILGYWDIRGLAHAIRLLLEYTDSSYEEKKYTMGDAPDYDRSQWLNEKFKLGLDFPNLPYLIDGAHKITQSNAILCY
31975 IARKHNLCGETEEEKIRVDILENQTMDNHMQLGMICYNPEFEKLKPKYLEELPEKLKLYSEFLGKRPWFAGNKITFVD
31976 FLVYDVLDLHRIFEPKCLDAFPNLKDFISRFEGLEKISAYMKSSRFLPRPVFSKMAVWGNK 
31977 SHAR_EOF
31978 chmod 0644 gtm1_human.aa ||
31979 echo 'restore of gtm1_human.aa failed'
31980 Wc_c="`wc -c < 'gtm1_human.aa'`"
31981 test 300 -eq "$Wc_c" ||
31982         echo 'gtm1_human.aa: original size 300, current size' "$Wc_c"
31983 fi
31984 # ============= gtt1_drome.aa ==============
31985 if test -f 'gtt1_drome.aa' -a X"$1" != X"-c"; then
31986         echo 'x - skipping gtt1_drome.aa (File already exists)'
31987 else
31988 echo 'x - extracting gtt1_drome.aa (Text)'
31989 sed 's/^X//' << 'SHAR_EOF' > 'gtt1_drome.aa' &&
31990 >GTT1_DROME GLUTATHIONE S-TRANSFERASE 1-1 (EC 2.5.1.18) (CLASS-THETA). - DROS
31991 MVDFYYLPGSSPCRSVIMTAKAVGVELNKKLLNLQAGEHLKPEFLKINPQHTIPTLVDNGFALWESRAIQVYLVEKYG
31992 KTDSLYPKCPKKRAVINQRLYFDMGTLYQSFANYYYPQVFAKAPADPEAFKKIEAAFEFLNTFLEGQDYAAGDSLTVA
31993 DIALVATVSTFEVAKFEISKYANVNRWYENAKKVTPGWEENWAGCLEFKKYFE 
31994 SHAR_EOF
31995 chmod 0644 gtt1_drome.aa ||
31996 echo 'restore of gtt1_drome.aa failed'
31997 Wc_c="`wc -c < 'gtt1_drome.aa'`"
31998 test 291 -eq "$Wc_c" ||
31999         echo 'gtt1_drome.aa: original size 291, current size' "$Wc_c"
32000 fi
32001 # ============= h10_human.aa ==============
32002 if test -f 'h10_human.aa' -a X"$1" != X"-c"; then
32003         echo 'x - skipping h10_human.aa (File already exists)'
32004 else
32005 echo 'x - extracting h10_human.aa (Text)'
32006 sed 's/^X//' << 'SHAR_EOF' > 'h10_human.aa' &&
32007 >H10_HUMAN | 90538   | HISTONE H1' (H1.0) (H1(0)).
32008 TENSTSAPAAKPKRAKASKKSTDHPKYSDMIVAAIQAEKNRAGSSRQSIQKYIKSHYKVGENADSQIKLSIKRLV
32009 TTGVLKQTKGVGASGSFRLAKSDEPKKSVAFKKTKKEIKKVATPKKASKPKKAASKAPTKKPKATPVKKAKKKLA
32010 ATPKKAKKPKTVKAKPVKASKPKKAKPVKPKAKSSAKRAGKKK
32011 SHAR_EOF
32012 chmod 0644 h10_human.aa ||
32013 echo 'restore of h10_human.aa failed'
32014 Wc_c="`wc -c < 'h10_human.aa'`"
32015 test 247 -eq "$Wc_c" ||
32016         echo 'h10_human.aa: original size 247, current size' "$Wc_c"
32017 fi
32018 # ============= h_altlib.h ==============
32019 if test -f 'h_altlib.h' -a X"$1" != X"-c"; then
32020         echo 'x - skipping h_altlib.h (File already exists)'
32021 else
32022 echo 'x - extracting h_altlib.h (Text)'
32023 sed 's/^X//' << 'SHAR_EOF' > 'h_altlib.h' &&
32024 X
32025 /* $Name: fa_34_26_5 $ - $Id: h_altlib.h,v 1.2 1999/12/30 01:26:57 wrp Exp $ */
32026 X
32027 X
32028 #define LASTENTRY 10
32029 #define LASTLIB 10
32030 #define BINARYGB 9
32031 #define DEFAULT 0
32032 #define FULLGB 1
32033 #define UNIXPIR 2
32034 #define EMBLSWISS 3
32035 #define INTELLIG 4
32036 #define VMSPIR 5
32037 X
32038 int agetlib_h();        /* pearson fasta format */
32039 int agetntlib_h();      /* pearson fasta format nucleotides */
32040 int vgetlib_h();        /* PIR VMS format */
32041 X
32042 int (*h_getliba[LASTLIB])()={
32043 X       agetlib_h,agetlib_h,agetlib_h,agetlib_h,
32044 X       agetlib_h,vgetlib_h,agetlib_h,agetlib_h,
32045 X       agetlib_h,agetlib_h};
32046 X
32047 int (*h_getntliba[LASTLIB])()={
32048 X       agetntlib_h,agetntlib_h,agetntlib_h,agetntlib_h,
32049 X       agetntlib_h,agetntlib_h,agetntlib_h,agetntlib_h,
32050 X       agetntlib_h,agetntlib_h};
32051 X
32052 SHAR_EOF
32053 chmod 0644 h_altlib.h ||
32054 echo 'restore of h_altlib.h failed'
32055 Wc_c="`wc -c < 'h_altlib.h'`"
32056 test 691 -eq "$Wc_c" ||
32057         echo 'h_altlib.h: original size 691, current size' "$Wc_c"
32058 fi
32059 # ============= hahu.aa ==============
32060 if test -f 'hahu.aa' -a X"$1" != X"-c"; then
32061         echo 'x - skipping hahu.aa (File already exists)'
32062 else
32063 echo 'x - extracting hahu.aa (Text)'
32064 sed 's/^X//' << 'SHAR_EOF' > 'hahu.aa' &&
32065 >HAHU | 1114 | Hemoglobin alpha chain - Human, chimpanzee, and pygmy chimpanzee
32066 VLSPADKTNVKAAWGKVGAHAGEYGAEALERMFLSFPTTKTYFPHFDLSHGSAQVKGHGKKVADALTNAV
32067 AHVDDMPNALSALSDLHAHKLRVDPVNFKLLSHCLLVTLAAHLPAEFTPAVHASLDKFLASVSTVLTSKY
32068
32069 SHAR_EOF
32070 chmod 0644 hahu.aa ||
32071 echo 'restore of hahu.aa failed'
32072 Wc_c="`wc -c < 'hahu.aa'`"
32073 test 225 -eq "$Wc_c" ||
32074         echo 'hahu.aa: original size 225, current size' "$Wc_c"
32075 fi
32076 # ============= hostacc.c ==============
32077 if test -f 'hostacc.c' -a X"$1" != X"-c"; then
32078         echo 'x - skipping hostacc.c (File already exists)'
32079 else
32080 echo 'x - extracting hostacc.c (Text)'
32081 sed 's/^X//' << 'SHAR_EOF' > 'hostacc.c' &&
32082 X
32083 /* copyright (c) 1996, 1997, 1998, 1999 William R. Pearson and the
32084 X   U. of Virginia */
32085 X
32086 /* $Name: fa_34_26_5 $ - $Id: hostacc.c,v 1.7 2006/04/12 18:00:02 wrp Exp $ */
32087 X
32088 /* Concurrent read version */
32089 X
32090 #include <stdio.h>
32091 #include <stdlib.h>
32092 #include <sys/time.h>
32093 X
32094 #ifdef PVM_SRC
32095 #include "pvm3.h"
32096 #endif
32097 #ifdef MPI_SRC
32098 #include "mpi.h"
32099 #endif
32100 X
32101 #include "msg.h"
32102 X
32103 #define XTERNAL
32104 #include "uascii.h"
32105 #include "upam.h"
32106 #undef XTERNAL
32107 X
32108 extern char prog_name[];
32109 X
32110 extern int nnodes;
32111 #ifdef PVM_SRC
32112 extern int pinums[];
32113 #endif
32114 X
32115 X
32116 #ifdef PVM_SRC
32117 int tidtonode(tid)
32118 X     int tid;
32119 {
32120 X  int i;
32121 X  for (i=FIRSTNODE; i< nnodes; i++) if (tid==pinums[i]) return i;
32122 X  return -1;
32123 }
32124 #endif
32125 X
32126 /* rand_nodes selects nnodes at random from max_nodes */
32127 X
32128 void
32129 rand_nodes(int *node_map, int nnodes, int max_nodes)
32130 {
32131 X  int node_used[MAXNOD];
32132 X  int i, j;
32133 X  struct timeval tv;
32134 X
32135 X  gettimeofday(&tv,NULL);
32136 X  SRAND(tv.tv_usec);
32137 X
32138 X  for (i=0; i<max_nodes; i++) node_used[i]=0;
32139 X
32140 X  if (nnodes < (max_nodes+1)/2) {
32141 X    for (i=0; i<nnodes; ) {
32142 X      j = RAND()%max_nodes;
32143 X      if (node_used[j]) continue;
32144 X      else {
32145 X       node_map[i++]=j;
32146 X       node_used[j]=1;
32147 X      }
32148 X    }
32149 X  }
32150 X  else {
32151 X    for (i=0; i<(max_nodes-nnodes); ) {
32152 X      j = RAND()%max_nodes;
32153 X      if (node_used[j]) continue;
32154 X      else {
32155 X       node_used[j]=1;
32156 X       i++;
32157 X      }
32158 X    }
32159 X    for (i=j=0; i<nnodes; j++)
32160 X      if (node_used[j]) continue;
32161 X      else node_map[i++]=j;
32162 X  }
32163 /*  for (i=0; i<nnodes; i++) fprintf(stderr,"%2d %2d\n",i,node_map[i]); */
32164 }
32165 SHAR_EOF
32166 chmod 0644 hostacc.c ||
32167 echo 'restore of hostacc.c failed'
32168 Wc_c="`wc -c < 'hostacc.c'`"
32169 test 1466 -eq "$Wc_c" ||
32170         echo 'hostacc.c: original size 1466, current size' "$Wc_c"
32171 fi
32172 # ============= hsgstm1b.gcg ==============
32173 if test -f 'hsgstm1b.gcg' -a X"$1" != X"-c"; then
32174         echo 'x - skipping hsgstm1b.gcg (File already exists)'
32175 else
32176 echo 'x - extracting hsgstm1b.gcg (Text)'
32177 sed 's/^X//' << 'SHAR_EOF' > 'hsgstm1b.gcg' &&
32178 X FROMSTADEN of: hsgstm1b.g  check: 1769  from: 1  to: 5183
32179
32180 X <---No Contig Comments--->
32181
32182 hsgstm1b.gcg  Length: 5183  October 12, 1994 10:58  Type: N  Check: 1769  ..
32183 X
32184 X       1  GCACCAACCA GCACCATGCC CATGATACTG GGGTACTGGG ACATCCGTGG 
32185 X
32186 X      51  GGTAAGCGAG GGTCCTCTGG TGGGTGGGAC AGGGGGCGGA GGCGGGGATG 
32187 X
32188 X     101  TGTGGAGTAG CTGCAGGACT GGCTCTAGGG ACCGTTCCTC TTCAGGGCTG 
32189 X
32190 X     151  CCCGCCTCAG AAGGGCCTGT GCATGACGCT GTGTGTGTGT TTGGGGGTGG 
32191 X
32192 X     201  GGGCGGGTAG AGGAGGCGAC GGGTACGTGC AGTATAGACT AGGGCTGGCC 
32193 X
32194 X     251  TGGTGCAGAG AAAGTCACCA AGTCAGGGAC CCTCCATCTC TGACCCGAGC 
32195 X
32196 X     301  CGCGGCCATC TCTCCCAGCT GGCCCACGCC ATCCGCCTGC TCCTGGAATA 
32197 X
32198 X     351  CACAGACTCA AGCTACGAGG AAAAGAAGTA TACGATGGGG GACGGTAATG 
32199 X
32200 X     401  ACACCCTTGT GTCCGGGCTC TGCACTCACG CTGAGTTGGC ACCAAGCAAC 
32201 X
32202 X     451  CCATGGTGGC CACCTGTCGT ACCTCTGCAG GCCTCCCCTG CTGGAGCTGC 
32203 X
32204 X     501  AGGCTGTCCC TTCCCTGAGC CCCGGTGAGG AGTCCTGTGG CCTTGCAAGG 
32205 X
32206 X     551  CAGAATGCTG GGGCGGGATA GTGGGTCCCT GTTTAATTGG GTTGGGTGTC 
32207 X
32208 X     601  CTCAGAGCTT CCCAAACCCT GGAAGCCTTA GCCGTGTGGG GTCCAGAGCC 
32209 X
32210 X     651  TCAGCGGGAT TATTTGTCCC TGAACCCTGG GATGTGGGAC TGAGTGGTCA 
32211 X
32212 X     701  GATTCTAGAT CCACCTGTCT CAGGGATCTT GCCACTGGTT CCTTGGGAGG 
32213 X
32214 X     751  GTCCCCGGAA GGAGGGCTGG GCTCTGGGGA GGTTTGTTTT CACTTCTTCT 
32215 X
32216 X     801  TCCCCACGGC AGCTCCTGAC TATGACAGAA CGCAGTGGCT GAATGAAAAA 
32217 X
32218 X     851  TTCAAGCTGG GCCTGGACTT TCCCAATGTA GGTGCAGGGG GAAGGGGCGG 
32219 X
32220 X     901  TTTTGGGGGA AAGTGCGACG TGTCTCTGAC TGCATCTCCT CTCCCCAGAT 
32221 X
32222 X     951  TAGAGGTGTT CGGATCAGGA GTCTTCTGCC CAATTCCTGG TTGTCTACAC 
32223 X
32224 X    1001  AGCCCCTGCA TGATGTTCTG TGTCCCAGCT CATTTGTTCA TGTGACAGTA 
32225 X
32226 X    1051  TTTCTATGTC AGGCCTGCAT GAGCGGGCAC AGTGAGTCTG GTCTCCCCTT 
32227 X
32228 X    1101  GCATATAGGA AGGGGATGCT GGGGAGCCTG CTGGCCCCAA CTGAGCTTCC 
32229 X
32230 X    1151  CCGGTTTCCC ATCTATCCAG CTGCCCTACT TGATTGATGG GGCTCACAAG 
32231 X
32232 X    1201  ATCACCCAGA GCAACGCCAT CTTGTGCTAC ATTGCCCGCA AGCACAACCT 
32233 X
32234 X    1251  GTGTGAGTGT GGGTGGCTGC AATGTGTGGG GGGAAGGTGG CCTCCTCCTT 
32235 X
32236 X    1301  GGCTGGGCTG TGATGCTGAG ATTGAGTCTG TGTTTTGTGG GTGGCAGGTG 
32237 X
32238 X    1351  GGGAGACAGA AGAGGAGAAG ATTCGTGTGG ACATTTTGGA GAACCAGACC 
32239 X
32240 X    1401  ATGGACAACC ATATGCAGCT GGGCATGATC TGCTACAATC CAGAATTTGT 
32241 X
32242 X    1451  GAGTGTCCCC AGTGAGCTGC ATCTGACAGA GTTTGGATTT GGGGCCAGGA 
32243 X
32244 X    1501  CTCTTGCATC CTGCACACAT TGGTCTTAAG TCCCTGGTAC CATTCATCCT 
32245 X
32246 X    1551  CCAAGTGCTT TCCCATCATC TAGCAGTATC TCTACGACTC CAATGTCATG 
32247 X
32248 X    1601  TCAACAAAAG CAGAGGCAAT TCCCAACCAA CCTTAGGACA CGATTCCAGG 
32249 X
32250 X    1651  CATTCCCAGG GTAGAAATTT CAGTTCCTGT ATGGTAAAGT TTGTGTTCAG 
32251 X
32252 X    1701  AATCTCCTTC ATCAGCTCTG GCCTCTGACT TCTGTCCTGG GTCATTTCTG 
32253 X
32254 X    1751  TCAGCCAGTT CACATCACCT GCCTGCTCCT AGAATATGCA GACTCAAGTA 
32255 X
32256 X    1801  GAAGACTCAG GAATGTAATG GCACCCTCGA ATTGCATCTT CTCCTCAACA 
32257 X
32258 X    1851  GTTTTCTGAG TGCTGTCATT GACATGCACA GGGATCTGCG CATCTTCATA 
32259 X
32260 X    1901  ACAGACAGCT CAGAGGCAGT CAGAGGGCCT TTATTCCTCT CCCTCCTTCC 
32261 X
32262 X    1951  TTTCAACTTG AACTTCTCAT CTCCCTGGAA ACTAGTCAAC GTTCATTGTT 
32263 X
32264 X    2001  TTCTTCTGCC ACCCCATTAG AAGGAACTTT CTACTTTCCC TGAGCTCCCT 
32265 X
32266 X    2051  TAGTTCTTTG CATCCTTGAT TCTGCTGGTC TGGATCCAGA GGCTGCCAGG 
32267 X
32268 X    2101  TGCTTGGGCG CTCCTGGGGC TGACCCAGAG GCTATTGGGA GGTCAGTGAG 
32269 X
32270 X    2151  GACAGATTCA GGGACAGCAT CTCATTCCTC TCTGCCTTCT GATCAGTTTA 
32271 X
32272 X    2201  GATAGGGTCT GACACTCAGT CAGAGTCTAA AATGCTGAGT ATCCAATTGA 
32273 X
32274 X    2251  AGCCTGCACT GCCCCAGTTC CAGACTTGGG GAAGATGGCT GCTTGCCCGT 
32275 X
32276 X    2301  GCCAGCCTGG CCGTCCACAG CCCCGGGGAG GCCACGTCTG TGCAGGGAGC 
32277 X
32278 X    2351  TTTTGTCCGA GGGTGGTGAC AGCTGTTTTC TGCCTCAGGA GAAACTGAAG 
32279 X
32280 X    2401  CCAAAGTACT TGGAGGAACT CCCTGAAAAG CTAAAGCTCT ACTCAGAGTT 
32281 X
32282 X    2451  TCTGGGGAAG CGGCCATGGT TTGCAGGAAA CAAGGTAAAG GAGGAGTGAT 
32283 X
32284 X    2501  ATGGGGAATG AGATCTGTTT TGCTTCACGT GTTATGGAGG TTCCAGCCCA 
32285 X
32286 X    2551  CACATTCTTG GCCTTCTGCA GATCACTTTT GTAGATTTTC TCGTCTATGA 
32287 X
32288 X    2601  TGTCCTTGAC CTCCACCGTA TATTTGAGCC CAACTGCTTG GACGCCTTCC 
32289 X
32290 X    2651  CAAATCTGAA GGACTTCATC TCCCGCTTTG AGGTGATGCC CCCAATCCTC 
32291 X
32292 X    2701  CCTTCTCTTT GATGCCCCTT GTTCCGTTAC CTCCTTTCAG ATGCTTTCCC 
32293 X
32294 X    2751  ATGCCTGGAG CTACACACAG AATAACTCGC ATGTATTGAG TACTGGTTTC 
32295 X
32296 X    2801  ATGCCACGAA CCGTACCCCA GCACATTATA CCTATTGTGT GAAATTTGAA 
32297 X
32298 X    2851  TTTTATAACA TTCCAGTAAG GTAACAGAAT TATCTCGCCC ATTTTAGAGA 
32299 X
32300 X    2901  TAAGGAAACT AAGAATGAGA GGGTCGGTCC TCTGCTCAGG GTCCCAGAGC 
32301 X
32302 X    2951  TAGTGGAGGC AGTGCTGGGC CCCTGTGAGC CTCTGGATCT ATGGGTGGCA 
32303 X
32304 X    3001  GTCAGGCTCT CCCATTCGAC AGAGAAAAAG CCTTAGCGTT CACCTAGCCT 
32305 X
32306 X    3051  GGGTTTCACA GCCCAGGACA CTTTGGAAGA GGCAGAGAAC TTCATGACCA 
32307 X
32308 X    3101  TAGATGGAGC TGGCAATAGT AGGACTGACA CAACGGTGAC ATTGATGTCT 
32309 X
32310 X    3151  AGTACTGAAC CCACAGGCAA TCTCATAGCT ACCTCCAGAA GCTTTGCATG 
32311 X
32312 X    3201  ATTGGACCCC AGTGTGGGAA TCCTGAGAGC CAGGGCTGTG GCTGTAGCTG 
32313 X
32314 X    3251  GATTAAGGTA CATATGTGGG TGTCCCTGTT GAAGGAGTAT ATGTTGAAAT 
32315 X
32316 X    3301  GCCCGGTGCT GGGGCACTTA CTTACTCCAC CACTATCTTT TTTTTTTTTT 
32317 X
32318 X    3351  TTTTTTTTTT TTTGTGCTGG AGTCTTGCTC TGTTGCCCAG GCTGGAGTTC 
32319 X
32320 X    3401  AATGGAGTGA TCTTGGCTCA CTGCAACCTC CGCCTCCTGG GTTCAAGCGA 
32321 X
32322 X    3451  TTCTACTGCC TCAGCTGCAC GATTAGTTGG GATTACAGGT GTGCACCACC 
32323 X
32324 X    3501  ACGTCTGGCT AATTTTTGTA TTTTTAGTAG AGATGGGGTT TTGCCATGTT 
32325 X
32326 X    3551  GGTCAGGCTG GTCTTCGAAC TCCTGACCTC AGGTGATCTA CCCACATCAG 
32327 X
32328 X    3601  CCTCCCTCAG ATCGTGTCTT GCTGTTGCCC AGGCTGGAGC AGCAGTTGCG 
32329 X
32330 X    3651  TGACCTCGGA CTTACTGCAA CCTCTGCTCC CGGGTTCAAA CAATTCTCTG 
32331 X
32332 X    3701  CCTCAGCCTC CCGAGTAGCT GGGAATTACA AGTGTCTATC ACCACGCCCA 
32333 X
32334 X    3751  GCTAATTTTT CTATTTTTAG TAGAGATGGG CTTTTCACCA TGTTGGCCAG 
32335 X
32336 X    3801  GTGGTCTTGA ACTCCTGACC TCGGTGATCC ACCCACCTCG GCTTCCCACA 
32337 X
32338 X    3851  TCTGAGTGTC ATGTAGCCTG ATCTGCAGCA GGGCTGTAGA TGCCATGGGT 
32339 X
32340 X    3901  TAGGGCACAG TGAGATTTTG CTCAGGTATT AGATGGAGAA CTTTGGACTT 
32341 X
32342 X    3951  TCTGCTTTAA GGGGAATGTT TAGAGCCTAG TCTCgTTTGA TTTTCTTGTG 
32343 X
32344 X    4001  CACTGCCACC CCCCATTCCA CTTTCATCCA GGTTTACTGA GACATTGGGG 
32345 X
32346 X    4051  TGAGTGTGTT CAGAGCCCCT TTGTTCTGCT GCAGGTCCCT TCTGTGTCTC 
32347 X
32348 X    4101  TATACCCAGA CAAGCCAAGA GCCTCCCTGT GGAAAAGGAG ACTGTTTGTG 
32349 X
32350 X    4151  CAGTCAAGGA GTGACAGGGC CTGGTGTGAG GGGTGGTGGG GCAGAAGAAG 
32351 X
32352 X    4201  AAGAGAATTT GTCAGGAAGA GGCCAGAACT GGAGAGAGAC AGAACCAGGC 
32353 X
32354 X    4251  TACACYGCAA GTTCTATTCC CCTTACAAGG TATCTAAACG TAAGGAAGTT 
32355 X
32356 X    4301  GCTGAACTTC TGTTCCACAT GAGAATGGTG ATAATAGATT CAGCCTTGCA 
32357 X
32358 X    4351  GAGCAGTCGA GTGGTTTTCT AAGCTTACGT TGTAATTTGT GTTGGTACAG 
32359 X
32360 X    4401  AGCACCCAGC ACCGTGTAGA ATCTTCGTAA GTGTTAGCTG TTACTGTGGT 
32361 X
32362 X    4451  ACAACATTAC CTAAAGGAAG TTGGAAGAGT TAACTCAGCA AATCTGGGGA 
32363 X
32364 X    4501  CCCTAAGAAG CTGTGTGATG CCTCAGCACT TGAGCCCACA TGGAAAGGCT 
32365 X
32366 X    4551  GTGCCAGGGC CCTGACCTGC TGTGTCTGCA GTGGGGTTGT CCCACCGCTC 
32367 X
32368 X    4601  ATGGGCAGCT GACCTTGAGT TCTGGCCTTA TTTTCCCCCC TCTCAGGGCT 
32369 X
32370 X    4651  TGGAGAAGAT CTCTGCCTAC ATGAAGTCCA GCCGCTTCCT CCCAAGACCT 
32371 X
32372 X    4701  GTGTTCTCAA AGATGGCTGT CTGGGGCAAC AAGTAGGGCC TTGAAGGCAG 
32373 X
32374 X    4751  GAGGTGGGAG TGAGGAGCCC ATACTCAGCC TGCTGCCCAG GCTGTGCAGC 
32375 X
32376 X    4801  GCAGCTGGAC TCTGCATCCC AGCACCTGCC TCCTCGTTCC TTTCTCCTGT 
32377 X
32378 X    4851  TTATTCCCAT CTTTACTCCC AAGACTTCAT TGTCCCTCTT CACTCCCCCT 
32379 X
32380 X    4901  AAACCCCTGT CCCATGCAGG CCCTTTGAAG CCTCAGCTAC CCACTATCCT 
32381 X
32382 X    4951  TCGTGAACAT CCCCTCCCAT CATTACCCTT CCCTGCACTA AAGCCAGCCT 
32383 X
32384 X    5001  GACCTTCCTT CCTGTTAGTG GTTGTGTCTG CTTTAAAGCC TGCCTGGCCC 
32385 X
32386 X    5051  CTCGCCTGTG GAGCTCAGCC CCGAGCTGTC CCCGTGTTGC ATGAAGGAGC 
32387 X
32388 X    5101  AGCATTGACT GGTTTACAGG CCCTGCTCCT GCAGCATGGT CCCTGCCTAG 
32389 X
32390 X    5151  GCCTACCTGA TGGAAGTAAA GCCTCAACCA CAc
32391 X
32392 SHAR_EOF
32393 chmod 0644 hsgstm1b.gcg ||
32394 echo 'restore of hsgstm1b.gcg failed'
32395 Wc_c="`wc -c < 'hsgstm1b.gcg'`"
32396 test 7118 -eq "$Wc_c" ||
32397         echo 'hsgstm1b.gcg: original size 7118, current size' "$Wc_c"
32398 fi
32399 # ============= hsgstm1b.seq ==============
32400 if test -f 'hsgstm1b.seq' -a X"$1" != X"-c"; then
32401         echo 'x - skipping hsgstm1b.seq (File already exists)'
32402 else
32403 echo 'x - extracting hsgstm1b.seq (Text)'
32404 sed 's/^X//' << 'SHAR_EOF' > 'hsgstm1b.seq' &&
32405 >gi|31932|emb|X68676|HSGSTM1B H.sapiens GSTM1b gene for glutathione S-transferase
32406 ATGCCCATGATACTGGGGTACTGGGACATCCGTGGGGTAAGCGAGGGTCCTCTGGTGGGTGGGACAGGGG
32407 GCGGAGGCGGGGATGTGTGGAGTAGCTGCAGGACTGGCTCTAGGGACCGTTCCTCTTCAGGGCTGCCCGC
32408 CTCAGAAGGGCCTGTGCATGACGCTGTGTGTGTGTTTGGGGGTGGGGGCGGGTAGAGGAGGCGACGGGTA
32409 CGTGCAGTATAGACTAGGGCTGGCCTGGTGCAGAGAAAGTCACCAAGTCAGGGACCCTCCATCTCTGACC
32410 CGAGCCGCGGCCATCTCTCCCAGCTGGCCCACGCCATCCGCCTGCTCCTGGAATACACAGACTCAAGCTA
32411 CGAGGAAAAGAAGTATACGATGGGGGACGGTAATGACACCCTTGTGTCCGGGCTCTGCACTCACGCTGAG
32412 TTGGCACCAAGCAACCCATGGTGGCCACCTGTCGTACCTCTGCAGGCCTCCCCTGCTGGAGCTGCAGGCT
32413 GTCCCTTCCCTGAGCCCCGGTGAGGAGTCCTGTGGCCTTGCAAGGCAGAATGCTGGGGCGGGATAGTGGG
32414 TCCCTGTTTAATTGGGTTGGGTGTCCTCAGAGCTTCCCAAACCCTGGAAGCCTTAGCCGTGTGGGGTCCA
32415 GAGCCTCAGCGGGATTATTTGTCCCTGAACCCTGGGATGTGGGACTGAGTGGTCAGATTCTAGATCCACC
32416 TGTCTCAGGGATCTTGCCACTGGTTCCTTGGGAGGGTCCCCGGAAGGAGGGCTGGGCTCTGGGGAGGTTT
32417 GTTTTCACTTCTTCTTCCCCACGGCAGCTCCTGACTATGACAGAACGCAGTGGCTGAATGAAAAATTCAA
32418 GCTGGGCCTGGACTTTCCCAATGTAGGTGCAGGGGGAAGGGGCGGTTTTGGGGGAAAGTGCGACGTGTCT
32419 CTGACTGCATCTCCTCTCCCCAGATTAGAGGTGTTCGGATCAGGAGTCTTCTGCCCAATTCCTGGTTGTC
32420 TACACAGCCCCTGCATGATGTTCTGTGTCCCAGCTCATTTGTTCATGTGACAGTATTTCTATGTCAGGCC
32421 TGCATGAGCGGGCACAGTGAGTCTGGTCTCCCCTTGCATATAGGAAGGGGATGCTGGGGAGCCTGCTGGC
32422 CCCAACTGAGCTTCCCCGGTTTCCCATCTATCCAGCTGCCCTACTTGATTGATGGGGCTCACAAGATCAC
32423 CCAGAGCAACGCCATCTTGTGCTACATTGCCCGCAAGCACAACCTGTGTGAGTGTGGGTGGCTGCAATGT
32424 GTGGGGGGAAGGTGGCCTCCTCCTTGGCTGGGCTGTGATGCTGAGATTGAGTCTGTGTTTTGTGGGTGGC
32425 AGGTGGGGAGACAGAAGAGGAGAAGATTCGTGTGGACATTTTGGAGAACCAGACCATGGACAACCATATG
32426 CAGCTGGGCATGATCTGCTACAATCCAGAATTTGTGAGTGTCCCCAGTGAGCTGCATCTGACAGAGTTTG
32427 GATTTGGGGCCAGGACTCTTGCATCCTGCACACATTGGTCTTAAGTCCCTGGTACCATTCATCCTCCAAG
32428 TGCTTTCCCATCATCTAGCAGTATCTCTACGACTCCAATGTCATGTCAACAAAAGCAGAGGCAATTCCCA
32429 ACCAACCTTAGGACACGATTCCAGGCATTCCCAGGGTAGAAATTTCAGTTCCTGTATGGTAAAGTTTGTG
32430 TTCAGAATCTCCTTCATCAGCTCTGGCCTCTGACTTCTGTCCTGGGTCATTTCTGTCAGCCAGTTCACAT
32431 CACCTGCCTGCTCCTAGAATATGCAGACTCAAGTAGAAGACTCAGGAATGTAATGGCACCCTCGAATTGC
32432 ATCTTCTCCTCAACAGTTTTCTGAGTGCTGTCATTGACATGCACAGGGATCTGCGCATCTTCATAACAGA
32433 CAGCTCAGAGGCAGTCAGAGGGCCTTTATTCCTCTCCCTCCTTCCTTTCAACTTGAACTTCTCATCTCCC
32434 TGGAAACTAGTCAACGTTCATTGTTTTCTTCTGCCACCCCATTAGAAGGAACTTTCTACTTTCCCTGAGC
32435 TCCCTTAGTTCTTTGCATCCTTGATTCTGCTGGTCTGGATCCAGAGGCTGCCAGGTGCTTGGGCGCTCCT
32436 GGGGCTGACCCAGAGGCTATTGGGAGGTCAGTGAGGACAGATTCAGGGACAGCATCTCATTCCTCTCTGC
32437 CTTCTGATCAGTTTAGATAGGGTCTGACACTCAGTCAGAGTCTAAAATGCTGAGTATCCAATTGAAGCCT
32438 GCACTGCCCCAGTTCCAGACTTGGGGAAGATGGCTGCTTGCCCGTGCCAGCCTGGCCGTCCACAGCCCCG
32439 GGGAGGCCACGTCTGTGCAGGGAGCTTTTGTCCGAGGGTGGTGACAGCTGTTTTCTGCCTCAGGAGAAAC
32440 TGAAGCCAAAGTACTTGGAGGAACTCCCTGAAAAGCTAAAGCTCTACTCAGAGTTTCTGGGGAAGCGGCC
32441 ATGGTTTGCAGGAAACAAGGTAAAGGAGGAGTGATATGGGGAATGAGATCTGTTTTGCTTCACGTGTTAT
32442 GGAGGTTCCAGCCCACACATTCTTGGCCTTCTGCAGATCACTTTTGTAGATTTTCTCGTCTATGATGTCC
32443 TTGACCTCCACCGTATATTTGAGCCCAACTGCTTGGACGCCTTCCCAAATCTGAAGGACTTCATCTCCCG
32444 CTTTGAG
32445 SHAR_EOF
32446 chmod 0644 hsgstm1b.seq ||
32447 echo 'restore of hsgstm1b.seq failed'
32448 Wc_c="`wc -c < 'hsgstm1b.seq'`"
32449 test 2788 -eq "$Wc_c" ||
32450         echo 'hsgstm1b.seq: original size 2788, current size' "$Wc_c"
32451 fi
32452 # ============= htime.c ==============
32453 if test -f 'htime.c' -a X"$1" != X"-c"; then
32454         echo 'x - skipping htime.c (File already exists)'
32455 else
32456 echo 'x - extracting htime.c (Text)'
32457 sed 's/^X//' << 'SHAR_EOF' > 'htime.c' &&
32458 /* Concurrent read version */
32459 X
32460 /* $Name: fa_34_26_5 $ - $Id: htime.c,v 1.3 2006/04/12 18:00:02 wrp Exp $ */
32461 X
32462 #include <stdio.h>
32463 #include <time.h>
32464 X
32465 #ifdef UNIX
32466 #include <sys/types.h>
32467 #include <sys/time.h>
32468 #ifdef TIMES
32469 #include <sys/times.h>
32470 #else
32471 #undef TIMES
32472 #endif
32473 #endif
32474 X
32475 #ifndef HZ
32476 #define HZ 100
32477 #endif
32478 X
32479 time_t s_time ()                        /* returns time in milliseconds */
32480 {
32481 #ifndef TIMES
32482 X       time_t time(), tt;
32483 X       return time(&tt)*1000;
32484 #else
32485 X  struct tms tt;
32486 X  times(&tt);
32487 #ifdef CLK_TCK
32488 X  return tt.tms_utime*1000/CLK_TCK;
32489 #else
32490 X  return tt.tms_utime*1000/HZ;
32491 #endif
32492 #endif
32493 }
32494 X
32495 void ptime (FILE *fp, time_t time)              /* prints the time */
32496 {
32497 X  fprintf (fp, "%6.3f",(double)(time)/1000.0);
32498 }
32499 X
32500 SHAR_EOF
32501 chmod 0644 htime.c ||
32502 echo 'restore of htime.c failed'
32503 Wc_c="`wc -c < 'htime.c'`"
32504 test 674 -eq "$Wc_c" ||
32505         echo 'htime.c: original size 674, current size' "$Wc_c"
32506 fi
32507 # ============= humgstd.seq ==============
32508 if test -f 'humgstd.seq' -a X"$1" != X"-c"; then
32509         echo 'x - skipping humgstd.seq (File already exists)'
32510 else
32511 echo 'x - extracting humgstd.seq (Text)'
32512 sed 's/^X//' << 'SHAR_EOF' > 'humgstd.seq' &&
32513 >HUMGSTD Human glutathione transferase class mu (GST1) mRNA, complete cds.
32514 X GCACCAACCA GCACCATGCC CATGATACTG GGGTACTGGG ACATCCGCGG GCTGGCCCAC
32515 X GCCATCCGCC TGCTCCTGGA ATACACAGAC TCAAGCTATG AGGAAAAGAA GTACACGATG
32516 X GGGGACGCTC CTGATTATGA CAGAAGCCAG TGGCTGAATG AAAAATTCAA GCTGGGCCTG
32517 X GACTTTCCCA ATCTGCCCTA CTTGATTGAT GGGGCTCACA AGATCACCCA GAGCAACGCC
32518 X ATCTTGTGCT ACATTGCCCG CAAGCACAAC CTGTGTGGGG AGACAGAAGA GGAGAAGATT
32519 X CGTGTGGACA TTTTGGAGAA CCAGACCATG GACAACCATA TGCAGCTGGG CATGATCTGC
32520 X TACAATCCAG AATTTGAGAA ACTGAAGCCA AAGTACTTGG AGGAACTCCC TGAAAAGCTA
32521 X AAGCTCTACT CAGAGTTTCT GGGGAAGCGG CCATGGTTTG CAGGAAACAA GATCACTTTT
32522 X GTAGATTTTC TCGTCTATGA TGTCCTTGAC CTCCACCGTA TATTTGAGCC CAACTGCTTG
32523 X GACGCCTTCC CAAATCTGAA GGACTTCATC TCCCGCTTTG AGGGCTTGGA GAAGATCTCT
32524 X GCCTACATGA AGTCCAGCCG CTTCCTCCCA AGACCTGTGT TCTCAAAGAT GGCTGTCTGG
32525 X GGCAACAAGT AGGGCCTTGA AGGCAGGAGG TGGGAGTGAG GAGCCCATAC TCAGCCTGCT
32526 X GCCCAGGCTG TGCAGCGCAG CTGGACTCTG CATCCCAGCA CCTGCCTCCT CGTTCCTTTC
32527 X TCCTGTTTAT TCCCATCTTT ACTCCCAAGA CTTCATTGTC CCTCTTCACT CCCCCTAAAC
32528 X CCCTGTCCCA TGCAGGCCCT TTGAAGCCTC AGCTACCCAC TATCCTTCGT GAACATCCCC
32529 X TCCCATCATT ACCCTTCCCT GCACTAAAGC CAGCCTGACC TTCCTTCCTG TTAGTGGTTG
32530 X TGTCTGCTTT AAAGCCTGCC TGGCCCCTCG CCTGTGGAGC TCAGCCCCGA GCTGTCCCCG
32531 X TGTTGCATGA AGGAGCAGCA TTGACTGGTT TACAGGCCCT GCTCCTGCAG CATGGTCCCT
32532 X GCCTAGGCCT ACCTGATGGA AGTAAAGCCT CAACCAC
32533 SHAR_EOF
32534 chmod 0644 humgstd.seq ||
32535 echo 'restore of humgstd.seq failed'
32536 Wc_c="`wc -c < 'humgstd.seq'`"
32537 test 1323 -eq "$Wc_c" ||
32538         echo 'humgstd.seq: original size 1323, current size' "$Wc_c"
32539 fi
32540 # ============= idn_aa.mat ==============
32541 if test -f 'idn_aa.mat' -a X"$1" != X"-c"; then
32542         echo 'x - skipping idn_aa.mat (File already exists)'
32543 else
32544 echo 'x - extracting idn_aa.mat (Text)'
32545 sed 's/^X//' << 'SHAR_EOF' > 'idn_aa.mat' &&
32546 X   A  R  N  B  D  C  Q  Z  E  G  H  I  L  K  M  F  P  S  T  W  Y  V  X
32547 A  4 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10
32548 R -10  4 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10
32549 N -10 -10  4 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10
32550 B -10 -10 -10  4 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10
32551 D -10 -10 -10 -10  4 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10
32552 C -10 -10 -10 -10 -10  4 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10
32553 Q -10 -10 -10 -10 -10 -10  4 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10
32554 Z -10 -10 -10 -10 -10 -10 -10  4 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10
32555 E -10 -10 -10 -10 -10 -10 -10 -10  4 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10
32556 G -10 -10 -10 -10 -10 -10 -10 -10 -10  4 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10
32557 H -10 -10 -10 -10 -10 -10 -10 -10 -10 -10  4 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10
32558 I -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10  4 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10
32559 L -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10  4 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10
32560 K -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10  4 -10 -10 -10 -10 -10 -10 -10 -10 -10
32561 M -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10  4 -10 -10 -10 -10 -10 -10 -10 -10
32562 F -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10  4 -10 -10 -10 -10 -10 -10 -10
32563 P -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10  4 -10 -10 -10 -10 -10 -10
32564 S -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10  4 -10 -10 -10 -10 -10
32565 T -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10  4 -10 -10 -10 -10
32566 W -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10  4 -10 -10 -10
32567 Y -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10  4 -10 -10
32568 V -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10  4 -10
32569 XX -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10  0
32570 SHAR_EOF
32571 chmod 0644 idn_aa.mat ||
32572 echo 'restore of idn_aa.mat failed'
32573 Wc_c="`wc -c < 'idn_aa.mat'`"
32574 test 2210 -eq "$Wc_c" ||
32575         echo 'idn_aa.mat: original size 2210, current size' "$Wc_c"
32576 fi
32577 # ============= initfa.c ==============
32578 if test -f 'initfa.c' -a X"$1" != X"-c"; then
32579         echo 'x - skipping initfa.c (File already exists)'
32580 else
32581 echo 'x - extracting initfa.c (Text)'
32582 sed 's/^X//' << 'SHAR_EOF' > 'initfa.c' &&
32583 /*      initfa.c        */
32584 X
32585 /* $Name: fa_34_26_5 $ - $Id: initfa.c,v 1.148 2007/04/26 18:40:58 wrp Exp $ */
32586 X
32587 /* copyright (c) 1996, 1997, 1998  William R. Pearson and the U. of Virginia */
32588 X
32589 /* init??.c files provide function specific initializations */
32590 X
32591 /* h_init()     - called from comp_lib.c, comp_thr.c to initialize pstruct ppst
32592 X                 which includes the alphabet, and pam matrix
32593 X
32594 X   alloc_pam() - allocate pam matrix space
32595 X   init_pam2() - convert from 1D to 2D pam
32596 X
32597 X   init_pamx() - convert from 1D to 2D pam
32598 X
32599 X   f_initenv() - set up mngmsg and pstruct defaults
32600 X   f_getopt()  - read fasta specific command line options
32601 X   f_getarg()  - read ktup
32602 X
32603 X   resetp()    - reset the parameters, scoring matrix for DNA-DNA/DNA-prot
32604 X
32605 X   query_parm()        - ask for ktup
32606 X   last_init() - some things must be done last
32607 X
32608 X   f_initpam() - set some parameters based on the pam matrix
32609 */
32610 X
32611 #include <stdio.h>
32612 #include <stdlib.h>
32613 #include <ctype.h>
32614 #include <string.h>
32615 #include <math.h>
32616 X
32617 #ifdef UNIX
32618 #include <sys/types.h>
32619 #include <sys/stat.h>
32620 #endif
32621 X
32622 #include "defs.h"
32623 #include "structs.h"
32624 #include "param.h"
32625 X
32626 #ifndef PCOMPLIB
32627 #include "mw.h"
32628 #else
32629 #include "p_mw.h"
32630 #endif
32631 X
32632 #define XTERNAL
32633 #include "upam.h"
32634 #include "uascii.h"
32635 #undef XTERNAL
32636 X
32637 #define MAXWINDOW 32
32638 X
32639 int initpam(char *, struct pstruct *);
32640 void init_pam2 (struct pstruct *ppst);
32641 void extend_pssm(unsigned char *aa0, int n0, struct pstruct *ppst);
32642 void build_xascii(int *qascii, char *save_str);
32643 void ann_ascii(int *qascii, char *ann_arr);
32644 void re_ascii(int *qascii, int *pascii);
32645 extern int nrand(int);
32646 X
32647 /*  at some point, all the defaults should be driven from this table */
32648 /*
32649 #pgm    q_seq   l_seq   p_seq   matrix  g_open  g_ext   fr_shft e_cut   ktup
32650 #       -n/-p           -s      -e      -f      -h/-j   -E      argv[3]
32651 fasta   prot(0) prot(0) prot(0) bl50    -10     -2      -       10.0    2
32652 fasta   dna(1)  dna(1)  dna(1)  +5/-4   -14     -4      -       2.0     6
32653 ssearch prot(0) prot(0) prot(0) bl50    -10     -2      -       10.0    -
32654 ssearch dna(1)  dna(1)  dna(1)  +5/-4   -14     -4      -       2.0     -
32655 fastx   dna(1)  prot(0) prot(0) BL50    -12     -2      -20     5.0     2
32656 fasty   dna(1)  prot(0) prot(0) BL50    -12     -2      -20/-24 5.0     2
32657 tfastx  dna(1)  prot(0) prot(0) BL50    -14     -2      -20     5.0     2
32658 tfasty  dna(1)  prot(0) prot(0) BL50    -14     -2      -20/-24 5.0     2
32659 fasts   prot(0) prot(0) prot(0) MD20-MS -       -       -       5.0     -
32660 fasts   dna(1)  dna(1)  dna(1)  +2/-4   -       -       -       5.0     1
32661 tfasts  prot(0) dna(1)  prot(0) MD10-MS -       -       -       2.0     1
32662 fastf   prot(0) prot(0) prot(0) MD20    -       -       -       2.0     1
32663 tfastf  prot(0) dna(1)  prot(0) MD10    -       -       -       1.0     1
32664 fastm   prot(0) prot(0) prot(0) MD20    -       -       -       5.0     1
32665 fastm   dna(1)  dna(1)  dna(1)  +2/-4   -       -       -       2.0     1
32666 tfastm  prot(0) dna(1)  prot(0) MD10    -       -       -       2.0     1
32667 */
32668 X
32669 struct pgm_def_str {
32670 X  int pgm_id;
32671 X  char *prog_func;
32672 X  char *pgm_abbr;
32673 X  char *iprompt0;
32674 X  char *ref_str;
32675 X  int PgmDID;
32676 X  char *smstr;
32677 X  int g_open_mod;
32678 X  int gshift;
32679 X  int hshift;
32680 X  int e_cut;
32681 X  int ktup;
32682 };
32683 X
32684 char *ref_str_a[]={
32685 X  "\nPlease cite:\n W.R. Pearson & D.J. Lipman PNAS (1988) 85:2444-2448\n",
32686 X  "\nPlease cite:\n T. F. Smith and M. S. Waterman, (1981) J. Mol. Biol. 147:195-197; \n W.R. Pearson (1991) Genomics 11:635-650\n",
32687 X "\nPlease cite:\n Pearson et al, Genomics (1997) 46:24-36\n",
32688 X "\nPlease cite:\n Mackey et al. Mol. Cell. Proteomics  (2002) 1:139-147\n",
32689 X  "\nPlease cite:\n W.R. Pearson (1996) Meth. Enzymol. 266:227-258\n"
32690 };
32691 X
32692 #define FA_PID  1
32693 #define SS_PID  2
32694 #define FX_PID  3
32695 #define FY_PID  4
32696 #define FS_PID  5
32697 #define FF_PID  6
32698 #define FM_PID  7
32699 #define RSS_PID 8
32700 #define RFX_PID 9
32701 #define SSS_PID 10      /* old (slow) non-PG Smith-Waterman */
32702 #define TFA_PID FA_PID+10
32703 #define TFX_PID FX_PID+10
32704 #define TFY_PID FY_PID+10
32705 #define TFS_PID FS_PID+10
32706 #define TFF_PID FF_PID+10
32707 #define TFM_PID FM_PID+10
32708 X
32709 struct pgm_def_str
32710 pgm_def_arr[20] = {
32711 X  {0, "", "", "", NULL, 400, "", 0, 0, 0, 1.0, 0 },  /* 0 */
32712 X  {FA_PID, "FASTA", "fa",
32713 X   "FASTA searches a protein or DNA sequence data bank",
32714 X   NULL, 401, "BL50", 0, 0, 0, 10.0, 2}, /* 1 - FASTA */
32715 X  {SS_PID, "SSEARCH","gsw","SSEARCH searches a sequence data bank",
32716 X   NULL, 404, "BL50", 0, 0, 0, 10.0, 0}, /* 2 - SSEARCH */
32717 X  {FX_PID, "FASTX","fx",
32718 X   "FASTX compares a DNA sequence to a protein sequence data bank",
32719 X   NULL, 405, "BL50", -2, -20, 0, 5.0, 2}, /* 3 - FASTX */
32720 X  {FY_PID, "FASTY", "fy",
32721 X   "FASTY compares a DNA sequence to a protein sequence data bank",
32722 X   NULL, 405, "BL50", -2, -20, -24, 5.0, 2}, /* 4 - FASTY */
32723 X  {FS_PID, "FASTS", "fs",
32724 X   "FASTS compares linked peptides to a protein data bank",
32725 X   NULL, 400, "MD20-MS", 0, 0, 0, 5.0, 1}, /* 5 - FASTS */
32726 X  {FF_PID, "FASTF", "ff",
32727 X   "FASTF compares mixed peptides to a protein databank",
32728 X   NULL, 400, "MD20", 0, 0, 0, 2.0, 1 }, /* 6 - FASTF */
32729 X  {FM_PID, "FASTM", "fm",
32730 X   "FASTM compares ordered peptides to a protein data bank",
32731 X     NULL, 400, "MD20", 0, 0, 0, 5.0, 1 }, /* 7 - FASTM */
32732 X  {RSS_PID, "PRSS", "rss",
32733 X   "PRSS evaluates statistical signficance using Smith-Waterman",
32734 X   NULL, 401, "BL50", 0, 0, 0, 1000.0, 0 }, /* 8 - PRSS */
32735 X  {RFX_PID,"PRFX", "rfx",
32736 X   "PRFX evaluates statistical signficance using FASTX",
32737 X   NULL, 401, "BL50", -2, -20, -24, 1000.0, 2 }, /* 9 - PRFX */
32738 X  {SSS_PID, "OSEARCH","ssw","OSEARCH searches a sequence data bank",
32739 X   NULL, 404, "BL50", 0, 0, 0, 10.0, 0}, /* 2 - OSEARCH */
32740 X  {TFA_PID, "TFASTA", "tfa",
32741 X   "TFASTA compares a protein  to a translated DNA data bank",
32742 X   NULL, 402, "BL50", -2, 0, 0, 5.0, 2 },
32743 X  {0, "", "", "", NULL, 400, "", 0, 0, 0, 1.0, 0 },  /* 0 */
32744 X  {TFX_PID, "TFASTX", "tfx",
32745 X   "TFASTX compares a protein to a translated DNA data bank",
32746 X   NULL, 406, "BL50", -2, -20, 0, 2.0, 2},
32747 X  {TFY_PID, "TFASTY", "tfy",
32748 X   "TFASTY compares a protein to a translated DNA data bank",
32749 X   NULL, 406, "BL50", -2, -20, -24, 2.0, 2},
32750 X  {TFS_PID, "TFASTS", "tfs",
32751 X   "TFASTS compares linked peptides to a translated DNA data bank",
32752 X   NULL, 400, "MD10-MS", 0, 0, 0, 2.0, 2 },
32753 X  {TFF_PID, "TFASTF", "tff",
32754 X   "TFASTF compares mixed peptides to a protein databank",
32755 X   NULL, 400, "MD10", 0, 0, 0, 1.0, 1 },
32756 X  {TFM_PID, "TFASTM", "tfm",
32757 X   "TFASTM compares ordered peptides to a translated DNA databank",
32758 X   NULL, 400, "MD10", 0, 0, 0, 1.0, 1 }
32759 };
32760 X
32761 struct msg_def_str {
32762 X  int pgm_id;
32763 X  int q_seqt;
32764 X  int l_seqt;
32765 X  int p_seqt;
32766 X  int sw_flag;
32767 X  int stages;
32768 X  int qframe;
32769 X  int nframe;
32770 X  int nrelv, srelv, arelv;
32771 X  char *f_id0, *f_id1, *label;
32772 };
32773 X
32774 /* pgm_id    q_seqt     l_seqt   p_seqt sw_f st qf nf nrv srv arv s_ix */
32775 struct msg_def_str msg_def_arr[20] = {
32776 X  {0, 0, 0,  0, 0, 0, 0, 0, 0, 0, 0, "", "", ""},      /* ID=0 */
32777 X  {FA_PID, SEQT_UNK, SEQT_PROT, SEQT_PROT, 1, 1, 1, -1, 3, 1, 3,
32778 X   "fa","sw", "opt"},
32779 X  {SS_PID, SEQT_UNK, SEQT_PROT, SEQT_PROT, 1, 1, 1, -1, 1, 1, 1,
32780 X   "sw","sw", "s-w"},
32781 X  {FX_PID, SEQT_DNA, SEQT_PROT, SEQT_PROT, 1, 1, 2, -1, 3, 1, 3,
32782 X   "fx","sx", "opt"},
32783 X  {FY_PID, SEQT_DNA, SEQT_PROT, SEQT_PROT, 1, 1, 2, -1, 3, 1, 3,
32784 X   "fy","sy", "opt"},
32785 X  {FS_PID, SEQT_UNK, SEQT_PROT, SEQT_PROT, 1, 1, 1, -1, 3, 2, 3,
32786 X   "fs","fs", "initn init1"},
32787 X  {FF_PID, SEQT_PROT,SEQT_PROT, SEQT_PROT, 1, 1, 1, -1, 3, 2, 3,
32788 X   "ff","ff", "initn init1"},
32789 X  {FM_PID, SEQT_PROT,SEQT_PROT, SEQT_PROT, 1, 1, 1, -1, 3, 2, 3,
32790 X   "fm","fm","initn init1"},
32791 X  {RSS_PID, SEQT_UNK,SEQT_PROT, SEQT_PROT, 0, 1, 1, -1, 1, 1, 1,
32792 X   "rss","sw","s-w"},
32793 X  {RFX_PID, SEQT_DNA,SEQT_PROT, SEQT_PROT, 0, 1, 2, -1, 3, 1, 3,
32794 X   "rfx","sx","opt"},
32795 X  {SSS_PID, SEQT_UNK,SEQT_PROT, SEQT_PROT, 1, 1, 1, -1, 1, 1, 1,
32796 X   "sw","sw", "s-w"},
32797 X  {TFA_PID, SEQT_PROT,SEQT_DNA, SEQT_PROT, 0, 1, 1, 6, 3, 1, 3,
32798 X   "tfa","fa","initn init1"},
32799 X  {0, 0, 0,  0, 0, 0, 0, 0, 0, 0, 0, "", "", ""},      /* ID=12 */
32800 X  {TFX_PID, SEQT_PROT,SEQT_DNA, SEQT_PROT, 1, 1, 1, 2, 3, 2, 3,
32801 X   "tfx","sx","initn opt"},
32802 X  {TFY_PID, SEQT_PROT,SEQT_DNA, SEQT_PROT, 1, 1, 1, 2, 3, 2, 3,
32803 X   "tfy","sy","initn opt"},
32804 X  {TFS_PID, SEQT_PROT,SEQT_DNA, SEQT_PROT, 1, 1, 1, 6, 3, 2, 3,
32805 X   "tfs","fs","initn init1"},
32806 X  {TFF_PID, SEQT_PROT,SEQT_DNA, SEQT_PROT, 1, 1, 1, 6, 3, 2, 3,
32807 X   "tff","ff","initn init1"},
32808 X  {TFM_PID, SEQT_PROT,SEQT_DNA, SEQT_PROT, 1, 1, 1, 6, 3, 2, 3,
32809 X   "tfm","fm","initn init1"}
32810 };
32811 X
32812 int
32813 get_pgm_id() {
32814 X
32815 X  int rval=0;
32816 X
32817 #ifdef FASTA
32818 #ifndef TFAST
32819 X  pgm_def_arr[FA_PID].ref_str = ref_str_a[0];
32820 X  rval=FA_PID;
32821 #else
32822 X  pgm_def_arr[TFA_PID].ref_str = ref_str_a[0];
32823 X  rval=TFA_PID;
32824 #endif
32825 #endif
32826 X
32827 #ifdef FASTX
32828 #ifndef TFAST
32829 #ifndef PRSS
32830 X  pgm_def_arr[FX_PID].ref_str = ref_str_a[2];
32831 X  rval=FX_PID;
32832 #else
32833 X  pgm_def_arr[RFX_PID].ref_str = ref_str_a[2];
32834 X  rval=RFX_PID;
32835 #endif
32836 #else
32837 X  pgm_def_arr[TFX_PID].ref_str = ref_str_a[2];
32838 X  rval=TFX_PID;
32839 #endif
32840 #endif
32841 X
32842 #ifdef FASTY
32843 #ifndef TFAST
32844 X  pgm_def_arr[FY_PID].ref_str = ref_str_a[2];
32845 X  rval=FY_PID;
32846 #else
32847 X  pgm_def_arr[TFY_PID].ref_str = ref_str_a[2];
32848 X  rval=TFY_PID;
32849 #endif
32850 #endif
32851 X
32852 #ifdef FASTS
32853 #ifndef TFAST
32854 X  pgm_def_arr[FS_PID].ref_str = ref_str_a[3];
32855 X  rval=FS_PID;
32856 #else
32857 X  pgm_def_arr[TFS_PID].ref_str = ref_str_a[3];
32858 X  rval=TFS_PID;
32859 #endif
32860 #endif
32861 X
32862 #ifdef FASTF
32863 #ifndef TFAST
32864 X  pgm_def_arr[FF_PID].ref_str = ref_str_a[3];
32865 X  rval=FF_PID;
32866 #else
32867 X  pgm_def_arr[TFF_PID].ref_str = ref_str_a[3];
32868 X  rval=TFF_PID;
32869 #endif
32870 #endif
32871 X
32872 #ifdef FASTM
32873 #ifndef TFAST
32874 X  pgm_def_arr[FM_PID].ref_str = ref_str_a[3];
32875 X  rval=FM_PID;
32876 #else
32877 X  pgm_def_arr[TFM_PID].ref_str = ref_str_a[3];
32878 X  rval=TFM_PID;
32879 #endif
32880 #endif
32881 X
32882 #ifdef SSEARCH
32883 X  pgm_def_arr[SS_PID].ref_str = ref_str_a[1];
32884 X  rval=SS_PID;
32885 #endif
32886 X
32887 #ifdef OSEARCH
32888 X  pgm_def_arr[SSS_PID].ref_str = ref_str_a[1];
32889 X  rval=SSS_PID;
32890 #endif
32891 X
32892 #ifdef PRSS
32893 #ifndef FASTX
32894 X  pgm_def_arr[RSS_PID].ref_str = ref_str_a[4];
32895 X  rval=RSS_PID;
32896 #endif
32897 #endif
32898 X
32899 X  return rval;
32900 }
32901 X
32902 char *iprompt1=" test sequence file name: ";
32903 char *iprompt2=" database file name: ";
32904 X
32905 char *verstr="version 34.26.5 April 26, 2007";
32906 X
32907 char   *s_optstr = "13Ac:f:g:h:j:k:nopP:r:s:St:Ux:y:";
32908 X
32909 static int mktup=2;
32910 static int ktup_set = 0;
32911 static int gap_set=0;
32912 static int del_set=0;
32913 static int mshuff_set = 0;
32914 static int prot2dna = 0;
32915 X
32916 extern int max_workers;
32917 X
32918 extern void s_abort(char *, char *);
32919 extern void init_ascii(int ext_sq, int *sascii, int dnaseq);
32920 extern int standard_pam(char *smstr, struct pstruct *ppst,
32921 X                       int del_set, int gap_set);
32922 extern void mk_n_pam(int *arr,int siz, int mat, int mis);
32923 extern int karlin(int , int, double *, double *, double *);
32924 extern void init_karlin_a(struct pstruct *, double *, double **);
32925 extern int do_karlin_a(int **, struct pstruct *, double *,
32926 X                      double *, double *, double *, double *);
32927 X
32928 #if defined(TFAST) || defined(FASTX) || defined(FASTY)
32929 extern void aainit(int tr_type, int debug);
32930 #endif
32931 X
32932 char *iprompt0, *prog_func, *refstr;
32933 X
32934 X
32935 /* Sets defaults assuming a protein sequence */
32936 void h_init (struct pstruct *ppst, struct mngmsg *m_msp, char *pgm_abbr)
32937 {
32938 X  struct pgm_def_str pgm_def;
32939 X  int i, pgm_id;
32940 X
32941 X  ppst->pgm_id  = pgm_id =  get_pgm_id();
32942 X  pgm_def = pgm_def_arr[pgm_id];
32943 X
32944 X  /* check that pgm_def_arr[] is valid */
32945 X  if (pgm_def.pgm_id != pgm_id) {
32946 X    fprintf(stderr,
32947 X           "**pgm_def integrity failure: def.pgm_id %d != pgm_id %d**\n",
32948 X           pgm_def.pgm_id, pgm_id);
32949 X    exit(1);
32950 X  }
32951 X
32952 X  /* check that msg_def_arr[] is valid */
32953 X  if (msg_def_arr[pgm_id].pgm_id != pgm_id) {
32954 X    fprintf(stderr,
32955 X           "**msg_def integrity failure: def.pgm_id %d != pgm_id %d**\n",
32956 X           msg_def_arr[pgm_id].pgm_id, pgm_id);
32957 X    exit(1);
32958 X  }
32959 X
32960 X  strncpy(pgm_abbr,pgm_def.pgm_abbr,MAX_SSTR);
32961 X  iprompt0 = pgm_def.iprompt0;
32962 X  refstr = pgm_def.ref_str;
32963 X  prog_func = pgm_def.prog_func;
32964 X
32965 X  /* MAXTOT = MAXTST + MAXLIB for everything except TFAST,
32966 X     where it is MAXTST + MAXTRN */
32967 X  m_msp->max_tot = MAXTOT;
32968 X
32969 X  /* set up DNA query sequence if required*/
32970 X  if (msg_def_arr[pgm_id].q_seqt == SEQT_DNA) {
32971 X    memcpy(qascii,nascii,sizeof(qascii));
32972 X    m_msp->qdnaseq = SEQT_DNA;
32973 X  }
32974 X  else {       /* when SEQT_UNK, start with protein */
32975 X    memcpy(qascii,aascii,sizeof(qascii));
32976 X    m_msp->qdnaseq = msg_def_arr[pgm_id].q_seqt;
32977 X  }
32978 X
32979 #if defined(FASTF) || defined(FASTS) || defined(FASTM)
32980 X  qascii[','] = ESS;
32981 X  /* also initialize aascii, nascii for databases */
32982 X  qascii['*'] = NA;
32983 #endif
32984 X
32985 X  /* initialize a pam matrix */
32986 X  strncpy(ppst->pamfile,pgm_def.smstr,MAX_FN);
32987 X  standard_pam(ppst->pamfile,ppst,del_set,gap_set);
32988 X  ppst->have_pam2 = 0;
32989 X
32990 X  /* this is always protein by default */
32991 X  ppst->nsq = naa;
32992 X  ppst->nsqx = naax;
32993 X  for (i=0; i<=ppst->nsqx; i++) {
32994 X    ppst->sq[i] = aa[i];
32995 X    ppst->hsq[i] = haa[i];
32996 X    ppst->sqx[i]=aax[i];       /* sq = aa */
32997 X    ppst->hsqx[i]=haax[i];     /* hsq = haa */
32998 X  }
32999 X  ppst->sq[ppst->nsqx+1] = ppst->sqx[ppst->nsqx+1] = '\0';
33000 X
33001 X  /* set up the c_nt[] mapping */
33002 X
33003 #if defined(FASTS) || defined(FASTF) || defined(FASTM)
33004 X  ppst->c_nt[ESS] = ESS;
33005 #endif
33006 X  ppst->c_nt[0]=0;
33007 X  for (i=1; i<=nnt; i++) {
33008 X    ppst->c_nt[i]=gc_nt[i];
33009 X    ppst->c_nt[i+nnt]=gc_nt[i]+nnt;
33010 X  }
33011 }
33012 X
33013 /*
33014 X * alloc_pam(): allocates memory for the 2D pam matrix as well
33015 X * as for the integer array used to transmit the pam matrix
33016 X */
33017 void
33018 alloc_pam (int d1, int d2, struct pstruct *ppst)
33019 {
33020 X  int     i, *d2p;
33021 X  char err_str[128];
33022 X
33023 X  if ((ppst->pam2[0] = (int **) malloc (d1 * sizeof (int *))) == NULL) {
33024 X     sprintf(err_str,"Cannot allocate 2D pam matrix: %d",d1);
33025 X     s_abort (err_str,"");
33026 X  }
33027 X
33028 X  if ((ppst->pam2[1] = (int **) malloc (d1 * sizeof (int *))) == NULL) {
33029 X     sprintf(err_str,"Cannot allocate 2D pam matrix: %d",d1);
33030 X     s_abort (err_str,"");
33031 X  }
33032 X
33033 X  if ((d2p = pam12 = (int *) calloc (d1 * d2, sizeof (int))) == NULL) {
33034 X     sprintf(err_str,"Cannot allocate 2D pam matrix: %d",d1);
33035 X     s_abort (err_str,"");
33036 X   }
33037 X
33038 X   for (i = 0; i < d1; i++, d2p += d2)
33039 X      ppst->pam2[0][i] = d2p;
33040 X
33041 X   if ((d2p=pam12x= (int *) malloc (d1 * d2 * sizeof (int))) == NULL) {
33042 X     sprintf(err_str,"Cannot allocate 2d pam matrix: %d",d2);
33043 X     s_abort (err_str,"");
33044 X   }
33045 X
33046 X   for (i = 0;  i < d1; i++, d2p += d2)
33047 X      ppst->pam2[1][i] = d2p;
33048 X
33049 X   ppst->have_pam2 = 1;
33050 }
33051 X
33052 /*
33053 X *  init_pam2(struct pstruct pst): Converts 1-D pam matrix to 2-D
33054 X */
33055 void
33056 init_pam2 (struct pstruct *ppst) {
33057 X  int     i, j, k, nsq;
33058 X
33059 X  nsq = ppst->nsq;
33060 X
33061 X  ppst->pam2[0][0][0] = -BIGNUM;
33062 X  ppst->pam_h = -1; ppst->pam_l = 1;
33063 X
33064 X  k = 0;
33065 X  for (i = 1; i <= nsq; i++) {
33066 X    ppst->pam2[0][0][i] = ppst->pam2[0][i][0] = -BIGNUM;
33067 X    for (j = 1; j <= i; j++) {
33068 X      ppst->pam2[0][j][i] = ppst->pam2[0][i][j] = pam[k++] - ppst->pamoff;
33069 X      if (ppst->pam_l > ppst->pam2[0][i][j]) ppst->pam_l =ppst->pam2[0][i][j];
33070 X      if (ppst->pam_h < ppst->pam2[0][i][j]) ppst->pam_h =ppst->pam2[0][i][j];
33071 X    }
33072 X  }
33073 }
33074 X
33075 void
33076 init_pamx (struct pstruct *ppst) {
33077 X  int     i, j, k, nsq, pam_xx, pam_xm;
33078 X  int sa_x, sa_t, tmp;
33079 X
33080 X  nsq = ppst->nsq;
33081 X
33082 X  ppst->nt_align = (ppst->dnaseq== SEQT_DNA || ppst->dnaseq == SEQT_RNA);
33083 X
33084 X  if (ppst->nt_align) {
33085 X    sa_x = pascii['N'];
33086 X    sa_t = sa_x;
33087 X  }
33088 X  else {
33089 X    sa_x = pascii['X'];
33090 X    sa_t = pascii['*'];
33091 X  }
33092 X
33093 X  if (ppst->dnaseq == SEQT_RNA) {
33094 X    tmp = ppst->pam2[0][nascii['G']][nascii['G']] - 1;
33095 X    ppst->pam2[0][nascii['A']][nascii['G']] = 
33096 X      ppst->pam2[0][nascii['C']][nascii['T']] = 
33097 X      ppst->pam2[0][nascii['C']][nascii['U']] = tmp;
33098 X  }
33099 X
33100 X  if (ppst->pam_x_set) {
33101 X    for (i=1; i<=nsq; i++) {
33102 X      ppst->pam2[0][sa_x][i] = ppst->pam2[0][i][sa_x]=ppst->pam_xm;
33103 X      ppst->pam2[0][sa_t][i] = ppst->pam2[0][i][sa_t]=ppst->pam_xm;
33104 X    }
33105 X    ppst->pam2[0][sa_x][sa_x]=ppst->pam_xx;
33106 X    ppst->pam2[0][sa_t][sa_t]=ppst->pam_xx;
33107 X  }
33108 X  else {
33109 X    ppst->pam_xx = ppst->pam2[0][sa_x][sa_x];
33110 X    ppst->pam_xm = ppst->pam2[0][1][sa_x];
33111 X  }
33112 X
33113 X  pam_xx = ppst->pam_xx;
33114 X  pam_xm = ppst->pam_xm;
33115 X
33116 X  if (ppst->ext_sq_set) {      /* using extended alphabet */
33117 X    /* fill in pam2[1] matrix */
33118 X    ppst->pam2[1][0][0] = -BIGNUM;
33119 X    /* fill in additional parts of the matrix */
33120 X    for (i = 1; i <= nsq; i++) {
33121 X
33122 X      /* -BIGNUM to all matches vs 0 */
33123 X      ppst->pam2[0][0][i+nsq] = ppst->pam2[0][i+nsq][0] = 
33124 X       ppst->pam2[1][0][i+nsq] = ppst->pam2[1][i+nsq][0] = 
33125 X       ppst->pam2[1][0][i] = ppst->pam2[1][i][0] = -BIGNUM;
33126 X
33127 X      for (j = 1; j <= nsq; j++) {
33128 X
33129 X       /* replicate pam2[0] to i+nsq, j+nsq */
33130 X       ppst->pam2[0][i+nsq][j] = ppst->pam2[0][i][j+nsq] =
33131 X         ppst->pam2[0][i+nsq][j+nsq] = ppst->pam2[1][i][j] =
33132 X         ppst->pam2[0][i][j];
33133 X
33134 X       /* set the high portion of pam2[1] to the corresponding value
33135 X          of pam2[1][sa_x][j] */
33136 X
33137 X       ppst->pam2[1][i+nsq][j] = ppst->pam2[1][i][j+nsq]=
33138 X         ppst->pam2[1][i+nsq][j+nsq]=ppst->pam2[0][sa_x][j];
33139 X      }
33140 X    }
33141 X  }
33142 }
33143 X
33144 /*  function specific initializations */
33145 void
33146 f_initenv (struct mngmsg *m_msp, struct pstruct *ppst, unsigned char **aa0) {
33147 X  struct msg_def_str m_msg_def;
33148 X  int pgm_id;
33149 X
33150 X  pgm_id = ppst->pgm_id;
33151 X  m_msg_def = msg_def_arr[pgm_id];
33152 X
33153 X  m_msp->last_calc_flg=0;
33154 X
33155 X  strncpy(m_msp->f_id0,m_msg_def.f_id0,sizeof(m_msp->f_id0));
33156 X  strncpy(m_msp->f_id1,m_msg_def.f_id1,sizeof(m_msp->f_id1));
33157 X  strncpy (m_msp->label, m_msg_def.label, sizeof(m_msp->label));
33158 X
33159 #ifndef SSEARCH
33160 X  strncpy (m_msp->alab[0],"initn",20);
33161 X  strncpy (m_msp->alab[1],"init1",20);
33162 X  strncpy (m_msp->alab[2],"opt",20);
33163 #else
33164 X  strncpy (m_msp->alab[0],"s-w opt",20);
33165 #endif
33166 X
33167 X  ppst->gdelval += pgm_def_arr[pgm_id].g_open_mod;
33168 X  ppst->sw_flag = m_msg_def.sw_flag;
33169 X  m_msp->e_cut=pgm_def_arr[pgm_id].e_cut;
33170 X
33171 X  ppst->score_ix = 0;
33172 X  ppst->histint = 2;
33173 X  m_msp->qframe = m_msg_def.qframe;
33174 X  ppst->sw_flag = m_msg_def.sw_flag;
33175 X  m_msp->nframe = m_msg_def.nframe;
33176 X  m_msp->nrelv = m_msg_def.nrelv;
33177 X  m_msp->srelv = m_msg_def.srelv;
33178 X  m_msp->arelv = m_msg_def.arelv;
33179 X  m_msp->stages = m_msg_def.stages;
33180 #if defined(PRSS)
33181 X  m_msp->shuff_wid = 0;
33182 X  m_msp->shuff_max = 200;
33183 #endif
33184 X
33185 X  /* see param.h for the definition of all these */
33186 X
33187 X  m_msp->qshuffle = 0;
33188 X  m_msp->nm0 = 1;
33189 X  m_msp->escore_flg = 0;
33190 X
33191 X  /* pam information */
33192 X  ppst->pam_pssm = 0;
33193 #if defined(FASTS) || defined(FASTF) || defined(FASTM)
33194 X   ppst->pam_xx = ppst->pam_xm = 0;
33195 #else
33196 X  ppst->pam_xx = 1;  /* set >0 to use pam['X']['X'] value */
33197 X  ppst->pam_xm = -1;  /* set >0 to use pam['X']['A-Z'] value */
33198 #endif
33199 X  ppst->pam_x_set = 0;
33200 X  ppst->pam_set = 0;
33201 X  ppst->pam_pssm = 0;
33202 X  ppst->p_d_set = 0;
33203 X  ppst->pamoff = 0;
33204 X  ppst->ext_sq_set = 0;
33205 X
33206 X  if (pgm_def_arr[ppst->pgm_id].ktup > 0) {
33207 X    mktup = 2;
33208 X    ppst->param_u.fa.bestscale = 300;
33209 X    ppst->param_u.fa.bestoff = 36;
33210 X    ppst->param_u.fa.bkfact = 6;
33211 X    ppst->param_u.fa.scfact = 3;
33212 X    ppst->param_u.fa.bktup = 2;
33213 X    ppst->param_u.fa.ktup = 0;
33214 X    ppst->param_u.fa.bestmax = 50;
33215 X    ppst->param_u.fa.pamfact = 1;
33216 X    ppst->param_u.fa.altflag = 0;
33217 X    ppst->param_u.fa.optflag = 1;
33218 X    ppst->param_u.fa.iniflag = 0;
33219 X    ppst->param_u.fa.optcut = 0;
33220 X    ppst->param_u.fa.optcut_set = 0;
33221 X    ppst->param_u.fa.cgap = 0;
33222 X    ppst->param_u.fa.optwid = MAXWINDOW;
33223 X  }
33224 X
33225 }
33226 X
33227 /*  switches for fasta only */
33228 X
33229 static int shift_set=0;
33230 static int subs_set=0;
33231 static int sw_flag_set=0;
33232 static int nframe_set=0;
33233 static int wid_set=0;
33234 X
33235 void
33236 f_getopt (char copt, char *optarg,
33237 X         struct mngmsg *m_msg, struct pstruct *ppst)
33238 {
33239 X  int pgm_id;
33240 X  char *bp;
33241 X
33242 X  pgm_id = ppst->pgm_id;
33243 X
33244 X  switch (copt) {
33245 X  case '1': 
33246 X    if (pgm_def_arr[pgm_id].ktup > 0) {
33247 X      ppst->param_u.fa.iniflag=1;
33248 X    }
33249 X     break;
33250 X  case '3':
33251 X    nframe_set = 1;
33252 X    if (pgm_id == TFA_PID) {
33253 X      m_msg->nframe = 3; break;
33254 X    }
33255 X    else {
33256 X      m_msg->nframe = 1;       /* for TFASTXY */
33257 X      m_msg->qframe = 1;  /* for FASTA, FASTX */
33258 X    }
33259 X    break;
33260 X  case 'A':
33261 X    ppst->sw_flag= 1;
33262 X    sw_flag_set = 1;
33263 X    break;
33264 X  case 'c':
33265 X    if (pgm_def_arr[pgm_id].ktup > 0) {
33266 X      sscanf (optarg, "%d", &ppst->param_u.fa.optcut);
33267 X      ppst->param_u.fa.optcut_set = 1;
33268 X    }
33269 X    break;
33270 X  case 'f':
33271 X    sscanf (optarg, "%d", &ppst->gdelval);
33272 X    if (ppst->gdelval > 0) ppst->gdelval = -ppst->gdelval;
33273 X    del_set = 1;
33274 X    break;
33275 X  case 'g':
33276 X    sscanf (optarg, "%d", &ppst->ggapval);
33277 X    if (ppst->ggapval > 0) ppst->ggapval = -ppst->ggapval;
33278 X    gap_set = 1;
33279 X    break;
33280 X  case 'h':
33281 X    sscanf (optarg, "%d", &ppst->gshift);
33282 X    if (ppst->gshift > 0) ppst->gshift = -ppst->gshift;
33283 X    shift_set = 1;
33284 X    break;
33285 X  case 'j':
33286 X    sscanf (optarg, "%d", &ppst->gsubs);
33287 X    subs_set = 1;
33288 X    break;
33289 X  case 'k':
33290 X    sscanf (optarg, "%d", &m_msg->shuff_max);
33291 X    mshuff_set = 1;
33292 X    break;
33293 X  case 'n':
33294 X    m_msg->qdnaseq = SEQT_DNA;
33295 X    re_ascii(qascii,nascii);
33296 X    strncpy(m_msg->sqnam,"nt",4);
33297 X    prot2dna = 1;
33298 X    break;
33299 X  case 'o':
33300 X    if (pgm_def_arr[pgm_id].ktup > 0) {
33301 X      ppst->param_u.fa.optflag = 0;
33302 X      msg_def_arr[pgm_id].nrelv = m_msg->nrelv = 2;
33303 X    }
33304 X    break;
33305 X  case 'p':
33306 X    m_msg->qdnaseq = SEQT_PROT;
33307 X    ppst->dnaseq = SEQT_PROT;
33308 X    strncpy(m_msg->sqnam,"aa",4);
33309 X    break;
33310 X  case 'P':
33311 X    strncpy(ppst->pgpfile,optarg,MAX_FN);
33312 X    if ((bp=strchr(ppst->pgpfile,' '))!=NULL) {
33313 X      *bp='\0';
33314 X      ppst->pgpfile_type = atoi(bp+1);
33315 X    }
33316 X    else ppst->pgpfile_type = 0;
33317 X    ppst->pgpfile[MAX_FN-1]='\0';
33318 X    ppst->pam_pssm = 1;
33319 X    break;
33320 X  case 'r':
33321 X    sscanf(optarg,"%d/%d",&ppst->p_d_mat,&ppst->p_d_mis);
33322 X    if (ppst->p_d_mat > 0 && ppst->p_d_mis < 0) {
33323 X      ppst->p_d_set = 1;
33324 X      strncpy(ppst->pamfile,optarg,40);
33325 X    }
33326 X    break;
33327 X  case 's':
33328 X    strncpy (ppst->pamfile, optarg, 120);
33329 X    ppst->pamfile[120-1]='\0';
33330 X    if (!standard_pam(ppst->pamfile,ppst,del_set, gap_set)) {
33331 X      initpam (ppst->pamfile, ppst);
33332 X    }
33333 X    ppst->pam_set=1;
33334 X    break;
33335 X  case 'S':    /* turn on extended alphabet for seg */
33336 X    ppst->ext_sq_set = 1;
33337 X    break;
33338 X  case 't':
33339 X    if (tolower(optarg[0])=='t') {
33340 X      m_msg->term_code = aascii['*']; optarg++;
33341 X    }
33342 X    if (*optarg) {sscanf (optarg, "%d", &ppst->tr_type);}
33343 X    break;
33344 X  case 'U':
33345 X    m_msg->qdnaseq = SEQT_RNA;
33346 X    memcpy(qascii,nascii,sizeof(qascii));
33347 X    strncpy(m_msg->sqnam,"nt",4);
33348 X    nt[nascii['T']]='U';
33349 X    prot2dna=1;
33350 X    break;
33351 X  case 'x':
33352 X    if (strchr(optarg,',')!=NULL) {
33353 X      sscanf (optarg,"%d,%d",&ppst->pam_xx, &ppst->pam_xm);
33354 X    }
33355 X    else {
33356 X      sscanf (optarg,"%d",&ppst->pam_xx);
33357 X      ppst->pam_xm = ppst->pam_xx;
33358 X    }
33359 X    ppst->pam_x_set=1;
33360 X    break;
33361 X  case 'y':
33362 X    if (pgm_def_arr[pgm_id].ktup > 0) {
33363 X      sscanf (optarg, "%d", &ppst->param_u.fa.optwid);
33364 X      wid_set = 1;
33365 X    }
33366 X    break;
33367 X  }
33368 }
33369 X
33370 void
33371 f_lastenv (struct mngmsg *m_msg, struct pstruct *ppst)
33372 {
33373 X  char save_str[MAX_SSTR];
33374 X
33375 #if !defined(FASTM) && !defined(FASTS) && !defined(FASTF)
33376 X  strncpy(save_str,"*",sizeof(save_str));
33377 #else
33378 X  strncpy(save_str,",",sizeof(save_str));
33379 #endif
33380 X
33381 X  if (m_msg->qdnaseq == SEQT_UNK) {
33382 X    build_xascii(qascii,save_str);
33383 X    if (m_msg->ann_flg) ann_ascii(qascii,m_msg->ann_arr);
33384 X  }  
33385 X
33386 /* this check allows lc DNA sequence queries with FASTX */
33387 #if defined(FASTA) && !defined(FASTS) && !defined(FASTM) && !defined(FASTF)
33388 X  else
33389 X   init_ascii(ppst->ext_sq_set,qascii,m_msg->qdnaseq);
33390 #endif
33391 }
33392 X
33393 void
33394 f_getarg (int argc, char **argv, int optind,
33395 X         struct mngmsg *m_msg, struct pstruct *ppst)
33396 {
33397 X
33398 X  if (pgm_def_arr[ppst->pgm_id].ktup > 0) {
33399 X    if (argc - optind >= 4) {
33400 X      sscanf (argv[optind + 3], "%d", &ppst->param_u.fa.ktup);
33401 X      ktup_set = 1;
33402 X    }
33403 X    else
33404 X      ppst->param_u.fa.ktup = -ppst->param_u.fa.bktup;
33405 X  }
33406 X  
33407 X  if (ppst->pgm_id == RSS_PID && argc - optind > 3) {
33408 X    sscanf (argv[optind + 3], "%d", &m_msg->shuff_max);
33409 X  }
33410 X
33411 X  if (ppst->pgm_id == RFX_PID && argc - optind > 4) {
33412 X    sscanf (argv[optind + 4], "%d", &m_msg->shuff_max);
33413 X  }
33414 }
33415 X
33416 /* fills in the query ascii mapping from the parameter
33417 X   ascii mapping.
33418 */
33419 X
33420 void
33421 re_ascii(int *qascii, int *pascii) {
33422 X  int i;
33423 X
33424 X  for (i=0; i < 128; i++) {
33425 X    if (qascii[i] > '@' || qascii[i] < ESS) {
33426 X      qascii[i] = pascii[i];
33427 X    }
33428 X  }
33429 }
33430 X
33431 X
33432 /* recode has become function specific to accommodate FASTS/M */
33433 /* modified 28-Dec-2004 to ensure that all mapped characters
33434 X   are valid */
33435 int
33436 recode(unsigned char *seq, int n, int *qascii, int nsqx) {
33437 X  int i,j;
33438 X  char save_c;
33439 X
33440 #if defined(FASTS) || defined(FASTM)
33441 X  qascii[',']=ESS;
33442 #endif
33443 X
33444 X  for (i=0; i < n; i++) {
33445 X    save_c = seq[i];
33446 X    if (seq[i] > '@') seq[i] = qascii[seq[i]];
33447 X    if (seq[i] > nsqx && seq[i]!=ESS) {
33448 X      fprintf(stderr, "*** Warning - unrecognized residue at %d:%c - %2d\n",
33449 X             i,save_c,save_c);
33450 X      seq[i] = qascii['X'];
33451 X    }
33452 X  }
33453 X  seq[i]=EOSEQ;
33454 X  return i;
33455 }
33456 X
33457 /* here we have the query sequence, all the command line options,
33458 X   but we need to set various parameter options based on the type
33459 X   of the query sequence (m_msg->qdnaseq = 0:protein/1:DNA) and
33460 X   the function (FASTA/FASTX/TFASTA)
33461 */
33462 X
33463 /* this resetp is for conventional a FASTA/TFASTXYZ search */
33464 void
33465 resetp (struct mngmsg *m_msg, struct pstruct *ppst) {
33466 X  int i, pgm_id;
33467 X
33468 X  pgm_id = ppst->pgm_id;
33469 X
33470 #if defined(TFAST)
33471 X  if (m_msg->qdnaseq == SEQT_DNA || m_msg->qdnaseq == SEQT_RNA) {
33472 X    fprintf(stderr," %s compares a protein to a translated\n\
33473 DNA sequence library.  Do not use a DNA query/scoring matrix.\n",prog_func);
33474 X    exit(1);
33475 X  }
33476 #else
33477 #if (defined(FASTX) || defined(FASTY))
33478 X  if (!(m_msg->qdnaseq == SEQT_DNA || m_msg->qdnaseq == SEQT_RNA)) {
33479 X    fprintf(stderr," FASTX/Y compares a DNA sequence to a protein database\n");
33480 X    fprintf(stderr," Use a DNA query\n");
33481 X    exit(1);
33482 X  }
33483 #endif
33484 #endif
33485 X
33486 /* this code changes parameters for programs (FA_PID, SS_PID, FS_PID,
33487 X   RSS_PID) that can examine either protein (initial state) or DNA 
33488 X   Modified May, 2006 to reset e_cut for DNA comparisons.
33489 */
33490 X
33491 X  if (msg_def_arr[pgm_id].q_seqt == SEQT_UNK) {
33492 X    if (m_msg->qdnaseq == SEQT_DNA || m_msg->qdnaseq == SEQT_RNA) {
33493 X      msg_def_arr[pgm_id].q_seqt = m_msg->qdnaseq;
33494 X      msg_def_arr[pgm_id].p_seqt = SEQT_DNA;
33495 X      msg_def_arr[pgm_id].l_seqt = SEQT_DNA;
33496 X      if (m_msg->qdnaseq == SEQT_DNA) msg_def_arr[pgm_id].qframe = 2;
33497 X      pgm_def_arr[pgm_id].e_cut /= 5.0;
33498 X    }
33499 X    else {
33500 X      msg_def_arr[pgm_id].q_seqt = SEQT_PROT;
33501 X    }
33502 X  }
33503 X
33504 X  ppst->dnaseq = msg_def_arr[pgm_id].p_seqt;
33505 X  if (!sw_flag_set) ppst->sw_flag = msg_def_arr[pgm_id].sw_flag;
33506 X  if (!m_msg->e_cut_set) m_msg->e_cut=pgm_def_arr[pgm_id].e_cut;
33507 X
33508 X  if (ppst->dnaseq == SEQT_DNA && m_msg->qdnaseq==SEQT_RNA) {
33509 X    ppst->dnaseq = SEQT_RNA;
33510 X    ppst->nt_align = 1;
33511 X  }
33512 X  if (ppst->dnaseq==SEQT_DNA) pascii = &nascii[0];
33513 X  else if (ppst->dnaseq==SEQT_RNA) {
33514 X    pascii = &nascii[0];
33515 X    ppst->sq[nascii['T']] = 'U';
33516 X  }
33517 X  else pascii = &aascii[0];
33518 X  m_msg->ldnaseq = msg_def_arr[pgm_id].l_seqt;
33519 X  if (m_msg->ldnaseq & SEQT_DNA) {
33520 X    memcpy(lascii,nascii,sizeof(lascii));
33521 #ifndef TFAST
33522 #ifdef DNALIB_LC
33523 X   init_ascii(ppst->ext_sq_set,lascii,m_msg->ldnaseq);
33524 #endif
33525 #else
33526 X  /* no init_ascii() because we translate lower case library sequences */
33527 #endif
33528 X  }
33529 X  else {
33530 X    memcpy(lascii,aascii,sizeof(lascii));      /* initialize lib mapping */
33531 X
33532 #if defined(FASTF) || defined(FASTS) || defined(FASTM)
33533 X    lascii['*'] = NA;
33534 #endif
33535 X    init_ascii(ppst->ext_sq_set,lascii,m_msg->ldnaseq);
33536 X  }
33537 X
33538 X  if (!nframe_set) {
33539 X    m_msg->qframe = msg_def_arr[pgm_id].qframe;
33540 X    m_msg->nframe = msg_def_arr[pgm_id].nframe;
33541 X  }
33542 X
33543 X  /* the possibilities:
33544 X            -i  -3     qframe  revcomp
33545 X   FA_D/FX   -    -        2       0   
33546 X   FA_D/FX   +    -        2       1   
33547 X   FA_D/FX   -    +        1       0   
33548 X   FA_D/FX   +    +        2       1   
33549 X  */
33550 X
33551 X  if (m_msg->qdnaseq == SEQT_DNA) {
33552 X    m_msg->nframe = 1;
33553 X    if (m_msg->qframe == 1 && m_msg->revcomp==1) {
33554 X      m_msg->qframe = m_msg->revcomp+1;
33555 X    }
33556 X  }
33557 X  else if (m_msg->qdnaseq == SEQT_RNA) {
33558 X    m_msg->qframe = m_msg->revcomp+1;
33559 X    m_msg->nframe = 1;
33560 X  }
33561 X
33562 X  /* change settings for DNA search */
33563 X  if (ppst->dnaseq == SEQT_DNA || ppst->dnaseq == SEQT_RNA) {
33564 X    ppst->histint = 4;
33565 X
33566 X    if (!del_set) {
33567 #ifdef OLD_FASTA_GAP
33568 X      ppst->gdelval = -16;     /* def. del penalty */
33569 #else
33570 X      ppst->gdelval = -12;     /* def. open penalty */
33571 #endif
33572 X    }
33573 X    if (!gap_set) ppst->ggapval = -4;  /* def. gap penalty */
33574 X
33575 X    if (pgm_def_arr[pgm_id].ktup > 0) {
33576 X      /* these parameters are used to scale optcut, they should be replaced
33577 X        by statistically based parameters */
33578 X      if (!wid_set) ppst->param_u.fa.optwid = 16;
33579 X      ppst->param_u.fa.bestscale = 80;
33580 X      ppst->param_u.fa.bkfact = 5;
33581 X      ppst->param_u.fa.scfact = 1;
33582 X      ppst->param_u.fa.bktup = 6;
33583 X      ppst->param_u.fa.bestmax = 80;
33584 X      ppst->param_u.fa.bestoff = 45;
33585 X
33586 X      if (!sw_flag_set) {
33587 X       ppst->sw_flag = 0;
33588 X       strncpy(m_msg->f_id1,"bs",sizeof(m_msg->f_id1));
33589 X      }
33590 X
33591 X      /* largest ktup */
33592 X      mktup = 6;
33593 X      
33594 X      if (ppst->param_u.fa.pamfact >= 0) ppst->param_u.fa.pamfact = 0;
33595 X      if (ppst->param_u.fa.ktup < 0)
33596 X       ppst->param_u.fa.ktup = -ppst->param_u.fa.bktup;
33597 X    }
33598 X
33599 X    ppst->nsq = nnt;
33600 X    ppst->nsqx = nntx;
33601 X    for (i=0; i<=ppst->nsqx; i++) {
33602 X      ppst->hsq[i] = hnt[i];
33603 X      ppst->sq[i] = nt[i];
33604 X      ppst->hsqx[i] = hntx[i];
33605 X      ppst->sqx[i] = ntx[i];
33606 X    }
33607 X    ppst->sq[ppst->nsqx+1] = ppst->sqx[ppst->nsqx+1] = '\0';
33608 X
33609 X    if (!ppst->pam_set) {
33610 X      if (ppst->p_d_set)
33611 X       mk_n_pam(npam,nnt,ppst->p_d_mat,ppst->p_d_mis);
33612 #if !defined(FASTS) && !defined(FASTM)
33613 X      else if (ppst->pamfile[0]=='\0' || strncmp(ppst->pamfile,"BL50",4)==0) {
33614 X       strncpy (ppst->pamfile, "+5/-4", sizeof(ppst->pamfile));
33615 X      }
33616 #else
33617 X      else if (strncmp(ppst->pamfile,"MD20",4)==0) {
33618 X       strncpy (ppst->pamfile, "+2/-2", sizeof(ppst->pamfile));
33619 X       ppst->p_d_mat = +2;
33620 X       ppst->p_d_mis = -2;
33621 X       mk_n_pam(npam,nnt,ppst->p_d_mat,ppst->p_d_mis);
33622 X      }
33623 #endif
33624 X      pam = npam;
33625 X    }
33626 X
33627 X    strncpy (m_msg->sqnam, "nt",sizeof(m_msg->sqnam));
33628 X    strncpy (m_msg->sqtype, "DNA",sizeof(m_msg->sqtype));
33629 X  }    /* end DNA reset */
33630 X
33631 X  else {  /* other parameters for protein comparison */
33632 X    if (pgm_def_arr[pgm_id].ktup > 0) {
33633 X      if (!wid_set) {
33634 X       if (ppst->param_u.fa.ktup==1) ppst->param_u.fa.optwid = 32;
33635 X       else ppst->param_u.fa.optwid = 16;
33636 X      }
33637 X    }
33638 X    if (!del_set) {ppst->gdelval += pgm_def_arr[pgm_id].g_open_mod;}
33639 X    if (!shift_set) {ppst->gshift = pgm_def_arr[pgm_id].gshift;}
33640 X    if (!subs_set) {ppst->gsubs = pgm_def_arr[pgm_id].hshift;}
33641 X  }
33642 X
33643 }
33644 X
33645 /* query_parm() this function asks for any additional parameters
33646 X       that have not been provided.  Could be null. */
33647 void
33648 query_parm (struct mngmsg *m_msp, struct pstruct *ppst)
33649 {
33650 X   char    qline[40];
33651 X
33652 X   if (pgm_def_arr[ppst->pgm_id].ktup > 0) {
33653 X     if (ppst->param_u.fa.ktup < 0)
33654 X       ppst->param_u.fa.ktup = -ppst->param_u.fa.ktup;
33655 X
33656 X     if (ppst->param_u.fa.ktup == 0) {
33657 X       printf (" ktup? (1 to %d) [%d] ", mktup, ppst->param_u.fa.bktup);
33658 X       if (fgets (qline, sizeof(qline), stdin) == NULL) exit (0);
33659 X       else sscanf(qline,"%d",&ppst->param_u.fa.ktup);
33660 X     }
33661 X     if (ppst->param_u.fa.ktup == 0)
33662 X       ppst->param_u.fa.ktup = ppst->param_u.fa.bktup;
33663 X     else ktup_set = 1;
33664 X   }
33665 X
33666 #if defined(PRSS)
33667 X   if (m_msp->shuff_max < 10) m_msp->shuff_max = 200;
33668 X
33669 X   if (!mshuff_set) {
33670 X     printf(" number of shuffles [%d]? ",m_msp->shuff_max);
33671 X     fflush(stdout);
33672 X     if (fgets (qline, sizeof(qline), stdin) == NULL) exit (0);
33673 X     else sscanf(qline,"%d",&m_msp->shuff_max);
33674 X   }
33675 X
33676 X   if (ppst->zs_win == 0) {
33677 X     printf (" local (window) (w) or uniform (u) shuffle [u]? ");
33678 X     if (fgets (qline, sizeof(qline), stdin) == NULL) exit (0);
33679 X     else if (qline[0]=='w' || qline[0]=='W') {
33680 X       m_msp->shuff_wid = 20;
33681 X       printf(" local shuffle window size [%d]? ",m_msp->shuff_wid);
33682 X       if (fgets (qline, sizeof(qline), stdin) == NULL) exit (0);
33683 X       else sscanf(qline,"%d",&m_msp->shuff_wid);
33684 X     }
33685 X   }
33686 #endif
33687 }
33688 X
33689 /* last_init() cannot look at aa0, n0, because it is only run once,
33690 X   it is not run before each new aa0 search */
33691 void
33692 last_init (struct mngmsg *m_msg, struct pstruct *ppst
33693 #ifdef PCOMPLIB
33694 X          ,int nnodes
33695 #endif
33696 X          )
33697 {
33698 X  int ix_l, ix_i, i, pgm_id;
33699 X  double *kar_p;
33700 X  double aa0_f[MAXSQ];
33701 X
33702 X  pgm_id = ppst->pgm_id;
33703 X
33704 #if defined(FASTF) || defined(FASTS) || defined(FASTM)
33705 X  m_msg->nohist = 1;
33706 X  m_msg->shuff_max = 2000;
33707 #ifndef PCOMPLIB
33708 X  ppst->shuff_node = m_msg->shuff_max/max_workers;
33709 #else
33710 X  ppst->shuff_node = m_msg->shuff_max/nnodes;
33711 #endif
33712 #endif
33713 X
33714 X  if (m_msg->aln.llen < 1) {
33715 X    m_msg->aln.llen = 60;
33716 X  }
33717 X
33718 #ifndef PCOMPLIB
33719 #if defined(FASTX) || defined(FASTY) || defined(TFAST)
33720 X  /* set up translation tables: faatran.c */
33721 X  aainit(ppst->tr_type,ppst->debug_lib);
33722 #endif
33723 #endif
33724 X
33725 /* a sanity check */
33726 #if !defined(TFAST)
33727 X   if (m_msg->revcomp && m_msg->qdnaseq!=SEQT_DNA && m_msg->qdnaseq!=SEQT_RNA) {
33728 X     fprintf(stderr," cannot reverse complement protein\n");
33729 X     m_msg->revcomp = 0;
33730 X   }
33731 #endif
33732 X
33733 X   if (pgm_def_arr[pgm_id].ktup > 0) {
33734 X
33735 X     if (ppst->param_u.fa.ktup < 0)
33736 X       ppst->param_u.fa.ktup = -ppst->param_u.fa.ktup;
33737 X
33738 X     if (ppst->param_u.fa.ktup < 1 || ppst->param_u.fa.ktup > mktup) {
33739 X       fprintf(stderr," warning ktup = %d out of range [1..%d], reset to %d\n",
33740 X              ppst->param_u.fa.ktup, mktup, ppst->param_u.fa.bktup);
33741 X       ppst->param_u.fa.ktup = ppst->param_u.fa.bktup;
33742 X     }
33743 X   }
33744 X
33745 X   if (pgm_id == TFA_PID) {
33746 X     m_msg->revcomp *= 3;
33747 X     if (m_msg->nframe == 3) m_msg->nframe += m_msg->revcomp;
33748 X   }
33749 X   else if (pgm_id == TFX_PID || pgm_id == TFY_PID) {
33750 X     if (m_msg->nframe == 1) m_msg->nframe += m_msg->revcomp;
33751 X   }
33752 X
33753 #if !defined(TFAST)
33754 X  /* for fasta/fastx searches, itt iterates the the query strand */
33755 X  m_msg->nitt1 = m_msg->qframe-1;
33756 #else
33757 X  /* for tfasta/tfastxy searches, itt iterates the library frames */
33758 X  m_msg->nitt1 = m_msg->nframe-1;
33759 #endif
33760 X
33761 X  if (pgm_def_arr[pgm_id].ktup > 0) {
33762 X    if (ppst->param_u.fa.ktup>=2 && !wid_set) {
33763 X      ppst->param_u.fa.optwid=16;
33764 X      switch (pgm_id) {
33765 X      case FA_PID:
33766 X       m_msg->thr_fact = 32;
33767 X       break;
33768 X      case FX_PID:
33769 X      case FY_PID:
33770 X       m_msg->thr_fact = 16;
33771 X       break;
33772 X      case TFA_PID:
33773 X      case TFX_PID:
33774 X      case TFY_PID:
33775 X       m_msg->thr_fact = 8;
33776 X       break;
33777 X      default:
33778 X       m_msg->thr_fact = 4;
33779 X      }
33780 X    }
33781 X    else { m_msg->thr_fact = 4;}
33782 X  }
33783 X  else m_msg->thr_fact = 4;
33784 X
33785 #if defined(PRSS)
33786 X   if (m_msg->shuff_max < 10) m_msg->shuff_max = 200;
33787 X   if (ppst->zsflag < 10) ppst->zsflag += 10;
33788 X   if (ppst->zs_win > 0) {
33789 X     m_msg->shuff_wid = ppst->zs_win;
33790 X   }
33791 #endif
33792 X
33793 X   if (pgm_def_arr[ppst->pgm_id].ktup > 0) {
33794 X     if (ppst->param_u.fa.iniflag) {
33795 X       ppst->score_ix = 1;
33796 X       strncpy (m_msg->label, "initn init1", sizeof(m_msg->label));
33797 X     }
33798 X     else if (ppst->param_u.fa.optflag) {
33799 X       ppst->score_ix = 2;
33800 X       m_msg->stages = 1;
33801 X     }
33802 X   }
33803 X
33804 X   if (!ppst->have_pam2) {
33805 X     alloc_pam (MAXSQ, MAXSQ, ppst);
33806 X     init_pam2(ppst);
33807 X   }
33808 X   init_pamx(ppst);
33809 X
33810 X   if (ppst->pam_ms) {
33811 X     if (m_msg->qdnaseq == SEQT_PROT) {
33812 X       /* code to make 'L'/'I' identical scores */
33813 X       ix_l = pascii['L'];
33814 X       ix_i = pascii['I'];
33815 X       ppst->pam2[0][ix_l][ix_i] = ppst->pam2[0][ix_i][ix_l] =
33816 X        ppst->pam2[0][ix_l][ix_l] = ppst->pam2[0][ix_i][ix_i] =
33817 X        (ppst->pam2[0][ix_l][ix_l]+ppst->pam2[0][ix_i][ix_i]+1)/2;
33818 X       for (i=1; i<=ppst->nsq; i++) {
33819 X        ppst->pam2[0][i][ix_i] = ppst->pam2[0][i][ix_l] =
33820 X          (ppst->pam2[0][i][ix_l]+ppst->pam2[0][i][ix_i]+1)/2;
33821 X        ppst->pam2[0][ix_i][i] = ppst->pam2[0][ix_l][i] =
33822 X          (ppst->pam2[0][ix_i][i]+ppst->pam2[0][ix_l][i]+1)/2;
33823 X       }
33824 X
33825 X       /* code to make 'Q'/'K' identical scores */
33826 X       if (!shift_set) {
33827 X        ix_l = pascii['Q'];
33828 X        ix_i = pascii['K'];
33829 X        ppst->pam2[0][ix_l][ix_i] = ppst->pam2[0][ix_i][ix_l] =
33830 X          ppst->pam2[0][ix_l][ix_l] = ppst->pam2[0][ix_i][ix_i] =
33831 X          (ppst->pam2[0][ix_l][ix_l]+ppst->pam2[0][ix_i][ix_i]+1)/2;
33832 X        for (i=1; i<=ppst->nsq; i++) {
33833 X          ppst->pam2[0][i][ix_i] = ppst->pam2[0][i][ix_l] =
33834 X            (ppst->pam2[0][i][ix_l]+ppst->pam2[0][i][ix_i]+1)/2;
33835 X          ppst->pam2[0][ix_i][i] = ppst->pam2[0][ix_l][i] =
33836 X            (ppst->pam2[0][ix_i][i]+ppst->pam2[0][ix_l][i]+1)/2;
33837 X        }
33838 X       }
33839 X     }
33840 X   }
33841 X
33842 X   /*
33843 X   print_pam(ppst);
33844 X   */
33845 X
33846 X   /* once we have a complete pam matrix, we can calculate Lambda and K 
33847 X      for "average" sequences */
33848 X   kar_p = NULL;
33849 X   init_karlin_a(ppst, aa0_f, &kar_p);
33850 X   do_karlin_a(ppst->pam2[0], ppst, aa0_f,
33851 X              kar_p, &m_msg->Lambda, &m_msg->K, &m_msg->H);
33852 X   free(kar_p);
33853 X
33854 #if defined(FASTF) || defined(FASTS) || defined(FASTM)
33855 X   if (ppst->ext_sq_set) {
33856 X     fprintf(stderr," -S not available on [t]fast[fs]\n");
33857 X     ppst->ext_sq_set = 0;
33858 X
33859 X     /* reset sascii to ignore -S, map lc */
33860 X     init_ascii(0,lascii,0);
33861 X   }
33862 #endif
33863 }
33864 X
33865 /* this function is left over from the older FASTA format scoring
33866 X   matrices that allowed additional parameters (bktup, bkfact) to be
33867 X   set in the scoring matrix.  It is no longer used.  A modern version
33868 X   would set parameters based on lambda and K.
33869 */
33870 /*
33871 void
33872 f_initpam (line, ppst)
33873 char   *line;
33874 struct pstruct *ppst;
33875 {
33876 X   if (sscanf (line, " %d %d %d %d %d %d %d", &ppst->param_u.fa.scfact,
33877 X              &ppst->param_u.fa.bestoff, &ppst->param_u.fa.bestscale,
33878 X              &ppst->param_u.fa.bkfact, &ppst->param_u.fa.bktup,
33879 X              &ppst->param_u.fa.bestmax, &ppst->histint) != 7)
33880 X   {
33881 X      printf ("  bestcut parameters - bad format\n");
33882 X      exit (1);
33883 X   }
33884 }
33885 */
33886 X
33887 /* alloc_pam2 creates a profile structure */
33888 int **
33889 alloc_pam2p(int len, int nsq) {
33890 X  int i;
33891 X  int **pam2p;
33892 X
33893 X  if ((pam2p = (int **)calloc(len,sizeof(int *)))==NULL) {
33894 X    fprintf(stderr," Cannot allocate pam2p: %d\n",len);
33895 X    return NULL;
33896 X  }
33897 X
33898 X  if((pam2p[0] = (int *)calloc((nsq+1)*len,sizeof(int)))==NULL) {
33899 X    fprintf(stderr, "Cannot allocate pam2p[0]: %d\n", (nsq+1)*len);
33900 X    free(pam2p);
33901 X    return NULL;
33902 X  }
33903 X
33904 X  for (i=1; i<len; i++) {
33905 X    pam2p[i] = pam2p[0] + (i*(nsq+1));
33906 X  }
33907 X
33908 X  return pam2p;
33909 }
33910 X
33911 void free_pam2p(int **pam2p) {
33912 X  if (pam2p) {
33913 X    free(pam2p[0]);
33914 X    free(pam2p);
33915 X  }
33916 }
33917 X
33918 /* sortbest has now become comparison function specific so that we can use
33919 X   a different comparison for fasts/f 
33920 */
33921 #if !defined(FASTS) && !defined (FASTF) && !defined(FASTM)
33922 #ifndef PCOMPLIB
33923 void
33924 qshuffle() {}
33925 #endif
33926 X
33927 int
33928 last_calc(unsigned char *aa0, unsigned char *aa1, int maxn,
33929 X         struct beststr **bestp_arr, int nbest,
33930 X         struct mngmsg *m_msg, struct pstruct *pst,
33931 X         void **f_str, void *rs_str)
33932 {
33933 X  return nbest;
33934 }
33935 X
33936 void sortbest (bptr, nbest, irelv)
33937 struct beststr **bptr;
33938 int nbest, irelv;
33939 {
33940 X    int gap, i, j;
33941 X    struct beststr *tmp;
33942 X
33943 X    for (gap = nbest/2; gap > 0; gap /= 2)
33944 X       for (i = gap; i < nbest; i++)
33945 X           for (j = i - gap; j >= 0; j-= gap) {
33946 X             if (bptr[j]->score[irelv] >= bptr[j + gap]->score[irelv]) break;
33947 X             tmp = bptr[j];
33948 X             bptr[j] = bptr[j + gap];
33949 X             bptr[j + gap] = tmp;
33950 X           }
33951 }
33952 X
33953 void show_aux(FILE *fp, struct beststr *bptr) {}
33954 void header_aux(FILE *fp) {}
33955 X
33956 #else
33957 void sortbest (bptr, nbest, irelv)
33958 struct beststr **bptr;
33959 int nbest, irelv;
33960 {
33961 X    int gap, i, j;
33962 X    struct beststr *tmp;
33963 X
33964 X    for (gap = nbest/2; gap > 0; gap /= 2)
33965 X       for (i = gap; i < nbest; i++)
33966 X           for (j = i - gap; j >= 0; j-= gap) {
33967 X             if (bptr[j]->escore < bptr[j + gap]->escore) break;
33968 X             tmp = bptr[j];
33969 X             bptr[j] = bptr[j + gap];
33970 X             bptr[j + gap] = tmp;
33971 X           }
33972 }
33973 X
33974 #if defined(FASTS) || defined(FASTM)
33975 X
33976 #ifndef PCOMPLIB
33977 /* this shuffle is for FASTS  */
33978 /* convert ',' -> '\0', shuffle each of the substrings */
33979 void
33980 qshuffle(unsigned char *aa0, int n0, int nm0) {
33981 X
33982 X  unsigned char **aa0start, *aap, tmp;
33983 X  int i,j,k, ns;
33984 X
33985 X  if ((aa0start=(unsigned char **)calloc(nm0+1,
33986 X                                        sizeof(unsigned char *)))==NULL) {
33987 X    fprintf(stderr,"cannot calloc for qshuffle %d\n",nm0);
33988 X    exit(1);
33989 X  }
33990 X
33991 X  aa0start[0]=aa0;
33992 X  for (k=1,i=0; i<n0; i++) {
33993 X    if (aa0[i]==EOSEQ || aa0[i]==ESS) {
33994 X      aa0[i]='\0';
33995 X      aa0start[k++] = &aa0[i+1];
33996 X    }
33997 X  }  
33998 X
33999 X  /* aa0start has the beginning of each substring */
34000 X  for (k=0; k<nm0; k++) {
34001 X    aap=aa0start[k];
34002 X    ns = strlen((char *)aap);
34003 X    for (i=ns; i>1; i--) {
34004 X      j = nrand(i);
34005 X      tmp = aap[j];
34006 X      aap[j] = aap[i-1];
34007 X      aap[i-1] = tmp;
34008 X    }
34009 X    aap[ns] = 0;
34010 X  }
34011 X
34012 X  for (k=1; k<nm0; k++) {
34013 /*  aap = aa0start[k];
34014 X    while (*aap) fputc(pst.sq[*aap++],stderr);
34015 X    fputc('\n',stderr);
34016 */
34017 X    aa0start[k][-1]=ESS;
34018 X  }
34019 X
34020 X  free(aa0start);
34021 }
34022 #endif
34023 #endif
34024 X
34025 #ifdef FASTF
34026 #ifndef PCOMPLIB
34027 void qshuffle(unsigned char *aa0, int n0, int nm0) {
34028 X
34029 X  int i, j, k, nmpos;
34030 X  unsigned char tmp;
34031 X  int nmoff;
34032 X  
34033 X  nmoff = (n0 - nm0 - 1)/nm0 + 1;
34034 X
34035 X  for (i = nmoff-1 ; i > 0 ; i--) {
34036 X
34037 X    /* j = nrand(i); if (i == j) continue;*/       /* shuffle columns */ 
34038 X    j = (nmoff -1 ) - i; 
34039 X    if (i <= j) break; /* reverse columns */
34040 X
34041 X    /* swap all i'th column residues for all j'th column residues */
34042 X    for(nmpos = 0, k = 0 ; k < nm0 ; k++, nmpos += nmoff+1 ) {
34043 X      tmp = aa0[nmpos + i];
34044 X      aa0[nmpos + i] = aa0[nmpos + j];
34045 X      aa0[nmpos + j] = tmp;
34046 X    }
34047 X  }
34048 }
34049 #endif
34050 #endif
34051 X
34052 X
34053 /* show additional best_str values */
34054 void show_aux(FILE *fp, struct beststr *bptr) {
34055 X  fprintf(fp," %2d %3d",bptr->segnum,bptr->seglen);
34056 }
34057 X
34058 void header_aux(FILE *fp) {
34059 X  fprintf(fp, " sn  sl");
34060 }
34061 #endif
34062 X
34063 void
34064 fill_pam(int **pam2p, int n0, int nsq, double **freq2d, double scale) {
34065 X  int i, j;
34066 X  double freq;
34067 X
34068 X  /* fprintf(stderr, "scale: %g\n", scale); */
34069 X  
34070 X  /* now fill in the pam matrix: */
34071 X  for (i = 0 ; i < n0 ; i++) {
34072 X    for (j = 1 ; j <=20 ; j++) {
34073 X      freq = scale * freq2d[i][j-1];
34074 X      if ( freq < 0.0) freq -= 0.5;
34075 X      else freq += 0.5;
34076 X      pam2p[i][j] = (int)(freq);
34077 X    }
34078 X  }
34079 }
34080 X
34081 double
34082 get_lambda(int **pam2p, int n0, int nsq, unsigned char *query) {
34083 X  double lambda, H;
34084 X  double *pr, tot, sum;
34085 X  int i, ioff, j, min, max;
34086 X
34087 X  /* get min and max scores */
34088 X  min = BIGNUM;
34089 X  max = -BIGNUM;
34090 X  if(pam2p[0][1] == -BIGNUM) {
34091 X    ioff = 1;
34092 X    n0++;
34093 X  } else {
34094 X    ioff = 0;
34095 X  }
34096 X
34097 X  for (i = ioff ; i < n0 ; i++) {
34098 X    for (j = 1; j <= nsq ; j++) {
34099 X      if (min > pam2p[i][j])
34100 X       min = pam2p[i][j];
34101 X      if (max < pam2p[i][j])
34102 X       max = pam2p[i][j];
34103 X    }
34104 X  }
34105 X
34106 X  /*  fprintf(stderr, "min: %d\tmax:%d\n", min, max); */
34107 X  
34108 X  if ((pr = (double *) calloc(max - min + 1, sizeof(double))) == NULL) {
34109 X    fprintf(stderr, "Couldn't allocate memory for score probabilities: %d\n", max - min + 1);
34110 X    exit(1);
34111 X  }
34112 X
34113 X  tot = (double) rrtotal * (double) rrtotal * (double) n0;
34114 X  for (i = ioff ; i < n0 ; i++) {
34115 X    for (j = 1; j <= nsq ; j++) {
34116 X      pr[pam2p[i][j] - min] +=
34117 X       (double) ((double) rrcounts[aascii[query[i]]] * (double) rrcounts[j]) / tot;
34118 X    }
34119 X  }
34120 X
34121 X  sum = 0.0;
34122 X  for(i = 0 ; i <= max-min ; i++) { 
34123 X    sum += pr[i];
34124 X    /*     fprintf(stderr, "%3d: %g %g\n", i+min, pr[i], sum); */
34125 X  }
34126 X  /*   fprintf(stderr, "sum: %g\n", sum); */
34127 X
34128 X  for(i = 0 ; i <= max-min ; i++) { pr[i] /= sum; }
34129 X
34130 X  if (!karlin(min, max, pr, &lambda, &H)) {
34131 X    fprintf(stderr, "Karlin lambda estimation failed\n");
34132 X  }
34133 X
34134 X  /*   fprintf(stderr, "lambda: %g\n", lambda); */
34135 X  free(pr);
34136 X
34137 X  return lambda;
34138 }
34139 X
34140 /*
34141 X   *aa0 - query sequence
34142 X   n0   - length
34143 X   pamscale - scaling for pam matrix - provided by apam.c, either
34144 X              0.346574 = ln(2)/2 (P120, BL62) or
34145 X             0.231049 = ln(2)/3 (P250, BL50) 
34146 */
34147 X
34148 void
34149 scale_pssm(int **pssm2p, double **freq2d,
34150 X          unsigned char *query, int n0,
34151 X          int **pam2, double pamscale);
34152 X
34153 static unsigned char ustandard_aa[] ="\0ARNDCQEGHILKMFPSTWYV";
34154 X
34155 void
34156 read_pssm(unsigned char *aa0, int n0, int nsq,
34157 X         double pamscale, 
34158 X         FILE *fp, int pgpf_type, struct pstruct *ppst) {
34159 X  int i, j, len, k;
34160 X  int qi, rj;  /* qi - index query; rj - index residues (1-20) */
34161 X  int **pam2p;
34162 X  int first, too_high;
34163 X  unsigned char *query, ctmp;
34164 X  char dline[512];
34165 X  double freq, **freq2d, lambda, new_lambda;
34166 X  double scale, scale_high, scale_low;
34167 X
34168 X  pam2p = ppst->pam2p[0];
34169 X
34170 X  if (pgpf_type == 0) {
34171 X
34172 X    if(1 != fread(&len, sizeof(int), 1, fp)) {
34173 X      fprintf(stderr, "error reading from checkpoint file: %d\n", len);
34174 X      exit(1);
34175 X    }
34176 X
34177 X    if(len != n0) {
34178 X      fprintf(stderr, "profile length (%d) and query length (%d) don't match!\n",
34179 X             len,n0);
34180 X      exit(1);
34181 X    }
34182 X
34183 X    /* read over query sequence stored in BLAST profile */
34184 X    if(NULL == (query = (unsigned char *) calloc(len+2, sizeof(char)))) {
34185 X      fprintf(stderr, "Couldn't allocate memory for query!\n");
34186 X      exit(1);
34187 X    }
34188 X
34189 X    if(len != fread(query, sizeof(char), len, fp)) {
34190 X      fprintf(stderr, "Couldn't read query sequence from profile: %s\n", query);
34191 X      exit(1);
34192 X    }
34193 X  }
34194 X  else if (pgpf_type == 1) {
34195 X
34196 X    if ((fgets(dline,sizeof(dline),fp) == NULL)  ||
34197 X       (1 != sscanf(dline, "%d",&len))) {
34198 X      fprintf(stderr, "error reading from checkpoint file: %d\n", len);
34199 X      exit(1);
34200 X    }
34201 X
34202 X    if(len != n0) {
34203 X      fprintf(stderr, "profile length (%d) and query length (%d) don't match!\n",
34204 X             len,n0);
34205 X      exit(1);
34206 X    }
34207 X
34208 X    /* read over query sequence stored in BLAST profile */
34209 X    if(NULL == (query = (unsigned char *) calloc(len+2, sizeof(char)))) {
34210 X      fprintf(stderr, "Couldn't allocate memory for query!\n");
34211 X      exit(1);
34212 X    }
34213 X
34214 X    if (fgets((char *)query,len+2,fp)==NULL) {
34215 X      fprintf(stderr, "Couldn't read query sequence from profile: %s\n", query);
34216 X      exit(1);
34217 X    }
34218 X  }  
34219 X  else {
34220 X    fprintf(stderr," Unrecognized PSSM file type: %d\n",pgpf_type);
34221 X    exit(1);
34222 X  }
34223 X
34224 X  /* currently we don't do anything with query; ideally, we should
34225 X     check to see that it actually matches aa0 ... */
34226 X
34227 X  /* quick 2d array alloc: */
34228 X  if((freq2d = (double **) calloc(n0, sizeof(double *))) == NULL) {
34229 X    fprintf(stderr, "Couldn't allocate memory for frequencies!\n");
34230 X    exit(1);
34231 X  }
34232 X
34233 X  if((freq2d[0] = (double *) calloc(n0 * 20, sizeof(double))) == NULL) {
34234 X    fprintf(stderr, "Couldn't allocate memory for frequencies!\n");
34235 X    exit(1);
34236 X  }
34237 X
34238 X  /* a little pointer arithmetic to fill out 2d array: */
34239 X  for (i = 1 ; i < n0 ; i++) {
34240 X    freq2d[i] = freq2d[i-1] + 20;
34241 X  }
34242 X
34243 X  if (pgpf_type == 0) {
34244 X    for (qi = 0 ; qi < n0 ; qi++) {
34245 X      for (rj = 0 ; rj < 20 ; rj++) {
34246 X       if(1 != fread(&freq, sizeof(double), 1, fp)) {
34247 X         fprintf(stderr, "Error while reading frequencies!\n");
34248 X         exit(1);
34249 X       }
34250 X       freq2d[qi][rj] = freq;
34251 X      }
34252 X    }
34253 X  }
34254 X  else {
34255 X    for (qi = 0 ; qi < n0 ; qi++) {
34256 X      if ((fgets(dline,sizeof(dline),fp) ==NULL) ||
34257 X      (k = sscanf(dline,"%c %lg %lg %lg %lg %lg %lg %lg %lg %lg %lg %lg %lg %lg %lg %lg %lg %lg %lg %lg %lg\n",
34258 X                &ctmp, &freq2d[qi][0], &freq2d[qi][1], &freq2d[qi][2], &freq2d[qi][3], &freq2d[qi][4], 
34259 X                &freq2d[qi][5], &freq2d[qi][6], &freq2d[qi][7], &freq2d[qi][8], &freq2d[qi][9],
34260 X                &freq2d[qi][10], &freq2d[qi][11], &freq2d[qi][12], &freq2d[qi][13], &freq2d[qi][14],
34261 X                     &freq2d[qi][15], &freq2d[qi][16], &freq2d[qi][17], &freq2d[qi][18], &freq2d[qi][19]))<1) {
34262 X       fprintf(stderr, "Error while reading frequencies: %d read!\n",k);
34263 X       exit(1);
34264 X      }
34265 X      for (rj=0; rj<20; rj++) { freq2d[qi][rj] /= 10.0; }      /* reverse scaling */
34266 X    }
34267 X  }
34268 X
34269 X  scale_pssm(ppst->pam2p[0], freq2d, query, n0, ppst->pam2[0],pamscale);
34270 X
34271 X  free(freq2d[0]);
34272 X  free(freq2d);
34273 X
34274 X  free(query);
34275 }
34276 X
34277 void
34278 scale_pssm(int **pssm2p, double **freq2d, unsigned char *query, int n0, int **pam2, double pamscale) {
34279 X  int i, qi, rj;
34280 X  double freq, new_lambda, lambda;
34281 X  int first, too_high;
34282 X  double scale, scale_high, scale_low;
34283 X
34284 X  for (qi = 0 ; qi < n0 ; qi++) {
34285 X    for (rj = 0 ; rj < 20 ; rj++) {
34286 X      if (freq2d[qi][rj] > 1e-20) {
34287 X       freq = log(freq2d[qi][rj] /((double) (rrcounts[rj+1])/(double) rrtotal));
34288 X       freq /= pamscale; /* this gets us close to originial pam scores */
34289 X       freq2d[qi][rj] = freq;
34290 X      }
34291 X      else {           
34292 X       /* when blastpgp decides to leave something out, it puts 0's in all the frequencies
34293 X          in the binary checkpoint file.  In the ascii version, however, it uses BLOSUM62
34294 X          values.  I will put in scoring matrix values as well */
34295 X
34296 X       freq2d[qi][rj] = pam2[aascii[query[qi]]][rj+1];
34297 X      }
34298 X    }
34299 X  }
34300 X
34301 X  /* now figure out the right scale */
34302 X  scale = 1.0;
34303 X  lambda = get_lambda(pam2, 20, 20, ustandard_aa);
34304 X
34305 X  /* should be near 1.0 because of our initial scaling by ppst->pamscale */
34306 X  /* fprintf(stderr, "real_lambda: %g\n", lambda); */
34307 X
34308 X  /* get initial high/low scale values: */
34309 X  first = 1;
34310 X  while (1) {
34311 X    fill_pam(pssm2p, n0, 20, freq2d, scale);
34312 X    new_lambda = get_lambda(pssm2p, n0, 20, query); 
34313 X
34314 X    if (new_lambda > lambda) {
34315 X      if (first) {
34316 X       first = 0;
34317 X       scale = scale_high = 1.0 + 0.05;
34318 X       scale_low = 1.0;
34319 X       too_high = 1;
34320 X      } else {
34321 X       if (!too_high) break;
34322 X       scale = (scale_high += scale_high - 1.0);
34323 X      }
34324 X    } else if (new_lambda > 0) {
34325 X      if (first) {
34326 X       first = 0;
34327 X       scale_high = 1.0;
34328 X       scale = scale_low = 1.0 - 0.05;
34329 X       too_high = 0;
34330 X      } else {
34331 X       if (too_high) break;
34332 X       scale = (scale_low += scale_low - 1.0);
34333 X      }
34334 X    } else {
34335 X      fprintf(stderr, "new_lambda (%g) <= 0; matrix has positive average score", new_lambda);
34336 X      exit(1);
34337 X    }
34338 X  }
34339 X
34340 X  /* now do binary search between low and high */
34341 X  for (i = 0 ; i < 10 ; i++) {
34342 X    scale = 0.5 * (scale_high + scale_low);
34343 X    fill_pam(pssm2p, n0, 20, freq2d, scale);
34344 X    new_lambda = get_lambda(pssm2p, n0, 20, query);
34345 X    
34346 X    if (new_lambda > lambda) scale_low = scale;
34347 X    else scale_high = scale;
34348 X  }
34349 X
34350 X  scale = 0.5 * (scale_high + scale_low);
34351 X  fill_pam(pssm2p, n0, 20, freq2d, scale);
34352 X
34353 X  /*
34354 X  fprintf(stderr, "final scale: %g\n", scale);
34355 X
34356 X  for (qi = 0 ; qi < n0 ; qi++) {
34357 X    fprintf(stderr, "%4d %c:  ", qi+1, query[qi]);
34358 X    for (rj = 1 ; rj <= 20 ; rj++) {
34359 X      fprintf(stderr, "%4d", pssm2p[qi][rj]);
34360 X    }
34361 X    fprintf(stderr, "\n");
34362 X  }
34363 X  */
34364 }
34365 X
34366 #if defined(SSEARCH) || (defined(PRSS) && !defined(FASTX))
34367 int
34368 parse_pssm_asn_fa(FILE *afd, int *n_rows, int *n_cols,
34369 X                 unsigned char **query, double ***freqs,
34370 X                 char *matrix, int *gap_open, int *gap_extend,
34371 X                 double *lambda);
34372 X
34373 /* the ASN.1 pssm includes information about the scoring matrix used
34374 X   (though not the gap penalty in the current version PSSM:2) The PSSM
34375 X   scoring matrix and gap penalties should become the default if they
34376 X   have not been set explicitly.
34377 */
34378 X
34379 int
34380 read_asn_pssm(unsigned char *aa0, int n0, int nsq,
34381 X             double pamscale, FILE *fp, struct pstruct *ppst) {
34382 X
34383 X  int i, j, len, k;
34384 X  int qi, rj;  /* qi - index query; rj - index residues (1-20) */
34385 X  int **pam2p;
34386 X  int first, too_high;
34387 X  unsigned char *query, ctmp;
34388 X  char dline[512];
34389 X  char matrix[MAX_SSTR];
34390 X  double psi2_lambda;
34391 X  double freq, **freq2d, lambda, new_lambda;
34392 X  double scale, scale_high, scale_low;
34393 X  int gap_open, gap_extend;
34394 X  int n_rows, n_cols;
34395 X
34396 X  pam2p = ppst->pam2p[0];
34397 X
34398 X  if (parse_pssm_asn_fa(fp, &n_rows, &n_cols, &query, &freq2d,
34399 X                       matrix, &gap_open, &gap_extend, &psi2_lambda)<=0) {
34400 X    return -1;
34401 X  }
34402 X
34403 X  if (!gap_set) {
34404 X    if (gap_open) {
34405 X      if (gap_open > 0) {gap_open = -gap_open;}
34406 X      ppst->gdelval = gap_open;
34407 X    }
34408 X    else if (strncmp(matrix,"BLOSUM62",8)==0) {
34409 X      ppst->gdelval = -11;
34410 X    }
34411 X    gap_set = 1;
34412 X  }
34413 X  if (!del_set) {
34414 X    if (gap_extend) {
34415 X      if (gap_extend > 0) {gap_extend = -gap_extend;}
34416 X      ppst->ggapval = gap_extend;
34417 X    }
34418 X    else if (strncmp(matrix,"BLOSUM62",8)==0) {
34419 X      ppst->ggapval = -1;
34420 X    }
34421 X    del_set = 1;
34422 X  }
34423 X
34424 X  if (strncmp(matrix, "BLOSUM62", 8)== 0 && !ppst->pam_set) {
34425 X    strncpy(ppst->pamfile, "BL62", 120);
34426 X    standard_pam(ppst->pamfile,ppst,del_set, gap_set);
34427 X    if (!ppst->have_pam2) {
34428 X     alloc_pam (MAXSQ, MAXSQ, ppst);
34429 X    }
34430 X    init_pam2(ppst);
34431 X    ppst->pam_set = 1;
34432 X  }
34433 X
34434 X  if (n_cols < n0) { 
34435 X    fprintf(stderr, " query length: %d != n_cols: %d\n",n0, n_cols);
34436 X    exit(1);
34437 X  }
34438 X
34439 X  scale_pssm(ppst->pam2p[0], freq2d, query, n0, ppst->pam2[0],pamscale);
34440 X
34441 X  free(freq2d[0]);
34442 X  free(freq2d);
34443 X
34444 X  free(query);
34445 X  return 1;
34446 }
34447 #endif
34448 X
34449 void
34450 last_params(unsigned char *aa0, int n0, 
34451 X           struct mngmsg *m_msg,
34452 X           struct pstruct *ppst
34453 #ifdef PCOMPLIB
34454 X           , struct qmng_str *qm_msg
34455 #endif
34456 X           ) {
34457 X  int i, nsq;
34458 X  FILE *fp;
34459 X
34460 X  if (n0 < 0) { return;}
34461 X
34462 X  ppst->n0 = m_msg->n0;
34463 X
34464 X  if (ppst->ext_sq_set) { nsq = ppst->nsqx; }
34465 X  else {nsq = ppst->nsq;}
34466 X
34467 /* currently, profiles are only available for SSEARCH, PRSS */
34468 #if defined(SSEARCH) || defined(PRSS)
34469 X
34470 X  ppst->pam2p[0] = alloc_pam2p(n0,nsq);
34471 X  ppst->pam2p[1] = alloc_pam2p(n0,nsq);
34472 X
34473 X  if (ppst->pam_pssm) {
34474 X    if ((ppst->pgpfile_type == 0) && (fp=fopen(ppst->pgpfile,"rb"))) {
34475 X      read_pssm(aa0, n0, ppst->nsq, ppst->pamscale, fp, 0, ppst);
34476 X      extend_pssm(aa0, n0, ppst);
34477 X    }
34478 X    else if ((ppst->pgpfile_type == 1) && (fp=fopen(ppst->pgpfile,"r"))) {
34479 X      read_pssm(aa0, n0, ppst->nsq, ppst->pamscale, fp, 1, ppst);
34480 X      extend_pssm(aa0, n0, ppst);
34481 X    }
34482 #if defined(SSEARCH) || (defined(PRSS) && !defined(FASTX))
34483 X    else if ((ppst->pgpfile_type == 2) && (fp=fopen(ppst->pgpfile,"rb"))) {
34484 X      if (read_asn_pssm(aa0, n0, ppst->nsq, ppst->pamscale, fp, ppst)>0) {
34485 X       extend_pssm(aa0, n0, ppst);
34486 X      }
34487 X      else {
34488 X       fprintf(stderr," Could not parse PSSM file: %s\n",ppst->pgpfile);
34489 X       ppst->pam_pssm = 0;
34490 X       return;
34491 X      }
34492 X    }
34493 #endif
34494 X    else {
34495 X      fprintf(stderr," Could not open PSSM file: %s\n",ppst->pgpfile);
34496 X      ppst->pam_pssm = 0;
34497 X      return;
34498 X    }
34499 X  }
34500 #endif
34501 X
34502 #if defined(FASTF) || defined(FASTS) || defined(FASTM)
34503 X  m_msg->nm0 = 1;
34504 X  for (i=0; i<n0; i++)
34505 X    if (aa0[i]==EOSEQ || aa0[i]==ESS) m_msg->nm0++;
34506 X
34507 /*
34508 X  for FASTS, we can do statistics in one of two different ways
34509 X  if there are <= 10 query fragments, then we calculate probabilistic
34510 X  scores for every library sequence.  If there are > 10 fragments, this
34511 X  takes much too long and too much memory, so we use the old fashioned
34512 X  raw score only z-score normalized method initially, and then calculate
34513 X  the probabilistic scores for the best hits.  To scale those scores, we
34514 X  also need a set of random probabilistic scores.  So we do the qshuffle
34515 X  to get them.
34516 X
34517 X  For FASTF, precalculating probabilities is prohibitively expensive,
34518 X  so we never do it; FASTF always acts like FASTS with nfrags>10.
34519 X
34520 */
34521 X
34522 #if defined(FASTS) || defined(FASTM)
34523 X  if (m_msg->nm0 > 10) m_msg->escore_flg = 0;
34524 X  else m_msg->escore_flg = 1;
34525 #endif
34526 X
34527 X  if (m_msg->escore_flg && (ppst->zsflag&1)) {
34528 X    m_msg->last_calc_flg = 0;
34529 X    m_msg->qshuffle = 0;
34530 X  }
34531 X  else {       /* need random query, second set of 2000 scores */
34532 X    m_msg->last_calc_flg = 1;
34533 X    m_msg->qshuffle = 1;
34534 X  }
34535 #else
34536 X  m_msg->last_calc_flg = 0;
34537 X  m_msg->qshuffle = 0;
34538 X  m_msg->escore_flg = 0;
34539 X  m_msg->nm0 = 1;
34540 #endif
34541 X
34542 /* adjust the ktup if appropriate */  
34543 X
34544 X  if (!ktup_set && pgm_def_arr[ppst->pgm_id].ktup > 0) {
34545 X    if (m_msg->qdnaseq == SEQT_PROT) {
34546 X      ppst->param_u.fa.ktup = pgm_def_arr[ppst->pgm_id].ktup;
34547 #if defined(FASTS) || defined(FASTM)
34548 X      if (n0 > 100) ppst->param_u.fa.ktup = 2;
34549 #endif
34550 X      if (n0 < 40) ppst->param_u.fa.ktup = 1;
34551 X    }
34552 X    else if (m_msg->qdnaseq == SEQT_DNA || m_msg->qdnaseq == SEQT_RNA) {
34553 X      if (n0 < 20) ppst->param_u.fa.ktup = 1;
34554 #if defined(FASTS) || defined(FASTM)
34555 X      /* with the current (April 12 2005) dropfs2.c - ktup cannot be > 2 */
34556 X      else ppst->param_u.fa.ktup = 2;
34557 #else
34558 X      else if (n0 < 50) ppst->param_u.fa.ktup = 2;
34559 X      else if (n0 < 100)  ppst->param_u.fa.ktup = 3;
34560 #endif
34561 X    }
34562 X  }
34563 X
34564 #ifdef PCOMPLIB
34565 X  qm_msg->nm0 = m_msg->nm0;
34566 X  qm_msg->escore_flg = m_msg->escore_flg;
34567 X  qm_msg->qshuffle = m_msg->qshuffle;
34568 X  qm_msg->pam_pssm = 0;
34569 #endif
34570 }
34571 X
34572 /* given a good profile in ppst->pam2p[0], make an extended profile
34573 X   in ppst->pam2p[1]
34574 */
34575 void
34576 extend_pssm(unsigned char *aa0, int n0, struct pstruct *ppst) {
34577 X
34578 X  int i, j, nsq;
34579 X  int sa_x, sa_t, sa_b, sa_z;
34580 X  int **pam2p0, **pam2p1;
34581 X
34582 X  nsq = ppst->nsq;
34583 X
34584 X  pam2p0 = ppst->pam2p[0];
34585 X  pam2p1 = ppst->pam2p[1];
34586 X
34587 X  sa_x = pascii['X'];
34588 X  sa_t = pascii['*'];
34589 X  sa_b = pascii['B'];
34590 X  sa_z = pascii['Z'];
34591 X
34592 X  /* fill in boundaries, B, Z, *, X */
34593 X  for (i=0; i<n0; i++) {
34594 X    pam2p0[i][0] = -BIGNUM;
34595 X    pam2p0[i][sa_b] = (int)
34596 X      (((float)pam2p0[i][pascii['N']]+(float)pam2p0[i][pascii['D']]+0.5)/2.0);
34597 X    pam2p0[i][sa_z] = (int)
34598 X      (((float)pam2p0[i][pascii['Q']]+(float)pam2p0[i][pascii['E']]+0.5)/2.0);
34599 X    pam2p0[i][sa_x] = ppst->pam_xm;
34600 X    pam2p0[i][sa_t] = ppst->pam_xm;
34601 X  }
34602 X
34603 X  /* copy pam2p0 into pam2p1 */
34604 X  for (i=0; i<n0; i++) {
34605 X    pam2p1[i][0] = -BIGNUM;
34606 X    for (j=1; j<=ppst->nsq; j++) {
34607 X      pam2p1[i][j] = pam2p0[i][j];
34608 X    }
34609 X  }
34610 X
34611 X  /* then fill in extended characters, if necessary */
34612 X  if (ppst->ext_sq_set) {
34613 X    for (i=0; i<n0; i++) {
34614 X      for (j=1; j<=ppst->nsq; j++) {
34615 X       pam2p0[i][nsq+j] = pam2p0[i][j];
34616 X       pam2p1[i][nsq+j] = ppst->pam_xm;
34617 X      }
34618 X    }
34619 X  }
34620 }
34621 SHAR_EOF
34622 chmod 0644 initfa.c ||
34623 echo 'restore of initfa.c failed'
34624 Wc_c="`wc -c < 'initfa.c'`"
34625 test 54882 -eq "$Wc_c" ||
34626         echo 'initfa.c: original size 54882, current size' "$Wc_c"
34627 fi
34628 # ============= karlin.c ==============
34629 if test -f 'karlin.c' -a X"$1" != X"-c"; then
34630         echo 'x - skipping karlin.c (File already exists)'
34631 else
34632 echo 'x - extracting karlin.c (Text)'
34633 sed 's/^X//' << 'SHAR_EOF' > 'karlin.c' &&
34634 /**************** Statistical Significance Parameter Subroutine ****************
34635 X
34636 X    $Name: fa_34_26_5 $ - $Id: karlin.c,v 1.18 2006/06/01 16:05:30 wrp Exp $
34637 X
34638 X    Version 1.0        February 2, 1990
34639 X    Version 2.0        March 18,   1993
34640 X
34641 X    Program by:        Stephen Altschul
34642 X
34643 X    Address:   National Center for Biotechnology Information
34644 X    National Library of Medicine
34645 X    National Institutes of Health
34646 X    Bethesda, MD  20894
34647 X
34648 X    Internet:  altschul@ncbi.nlm.nih.gov
34649 X
34650 X    See:       Karlin, S. & Altschul, S.F. "Methods for Assessing the Statistical
34651 X    Significance of Molecular Sequence Features by Using General Scoring
34652 X    Schemes,"  Proc. Natl. Acad. Sci. USA 87 (1990), 2264-2268.
34653 X
34654 X    Computes the parameters lambda and K for use in calculating the
34655 X    statistical significance of high-scoring segments or subalignments.
34656 X
34657 X    The scoring scheme must be integer valued.  A positive score must be
34658 X    possible, but the expected (mean) score must be negative.
34659 X
34660 X    A program that calls this routine must provide the value of the lowest
34661 X    possible score, the value of the greatest possible score, and a pointer
34662 X    to an array of probabilities for the occurence of all scores between
34663 X    these two extreme scores.  For example, if score -2 occurs with
34664 X    probability 0.7, score 0 occurs with probability 0.1, and score 3
34665 X    occurs with probability 0.2, then the subroutine must be called with
34666 X    low = -2, high = 3, and pr pointing to the array of values
34667 X    { 0.7, 0.0, 0.1, 0.0, 0.0, 0.2 }.  The calling program must also provide
34668 X    pointers to lambda and K; the subroutine will then calculate the values
34669 X    of these two parameters.  In this example, lambda=0.330 and K=0.154.
34670 X
34671 X    The parameters lambda and K can be used as follows.  Suppose we are
34672 X    given a length N random sequence of independent letters.  Associated
34673 X    with each letter is a score, and the probabilities of the letters
34674 X    determine the probability for each score.  Let S be the aggregate score
34675 X    of the highest scoring contiguous segment of this sequence.  Then if N
34676 X    is sufficiently large (greater than 100), the following bound on the
34677 X    probability that S is greater than or equal to x applies:
34678 X       
34679 X    P( S >= x )   <=   1 - exp [ - KN exp ( - lambda * x ) ].
34680 X       
34681 X    In other words, the p-value for this segment can be written as
34682 X    1-exp[-KN*exp(-lambda*S)].
34683 X
34684 X    This formula can be applied to pairwise sequence comparison by assigning
34685 X    scores to pairs of letters (e.g. amino acids), and by replacing N in the
34686 X    formula with N*M, where N and M are the lengths of the two sequences
34687 X    being compared.
34688 X
34689 X    In addition, letting y = KN*exp(-lambda*S), the p-value for finding m
34690 X    distinct segments all with score >= S is given by:
34691 X
34692 X    2             m-1           -y
34693 X    1 - [ 1 + y + y /2! + ... + y   /(m-1)! ] e
34694 X
34695 X    Notice that for m=1 this formula reduces to 1-exp(-y), which is the same
34696 X    as the previous formula.
34697 X
34698 *******************************************************************************/
34699 X
34700 #include <stdio.h>
34701 #include <stdlib.h>
34702 #include <math.h>
34703 X
34704 #define MAXIT 25  /* Maximum number of iterations used in calculating lambda */
34705 #define NMAP_X 23
34706 #define NMAP 33
34707 X
34708 #define TINY 1e-6
34709 X
34710 /* first build a residue map to automatically put residues in score bins */
34711 X
34712 #include "defs.h"
34713 #include "param.h"
34714 X
34715 /* initialize the Karlin frequency, probability arrays using
34716 X   a specific query sequence */
34717 X
34718 int karlin(int , int, double *, double *, double *);
34719 static int karlin_k(int , int , double *, double *, double *, double *);
34720 X
34721 void init_karlin(const unsigned char *aa0, int n0, struct pstruct *ppst,
34722 X                double *aa0_f, double **kp)
34723 {
34724 X  int kar_nsq, kar_range, kar_min, kar_max;
34725 X
34726 X  const unsigned char *aa0p;
34727 X  int i;
34728 X  int r_cnt[NMAP+1];
34729 X  double fn0, *kar_p;
34730 X  
34731 X  kar_range = ppst->pam_h - ppst->pam_l + 1;
34732 X  if (*kp == NULL) {
34733 X    if ((kar_p=(double *)calloc(kar_range+1,sizeof(double)))==NULL) {
34734 X      fprintf(stderr," cannot allocate kar_p array: %d\n",kar_range+1);
34735 X      exit(1);
34736 X    }
34737 X    *kp = kar_p;
34738 X  }
34739 X  kar_nsq = ppst->nsq; /* alphabet size */
34740 X  kar_min = ppst->pam_l;       /* low pam value */
34741 X  kar_max = ppst->pam_h;       /* high pam value */
34742 X
34743 X  /* must have at least 1 residue of each type */
34744 X  r_cnt[NMAP]=0;
34745 X  for (i=1; i<=kar_nsq; i++) r_cnt[i]=1; 
34746
34747 X  fn0 = 100.0/(double)(n0+kar_nsq);    /* weight of each residue */
34748 X
34749 X  aa0p = aa0;
34750 X  /* increment residue count for each residue in query sequence */
34751 X  while (*aa0p) r_cnt[ppst->hsqx[*aa0p++]]++;
34752 X
34753 X  /* map all unmapped residues to 'X' */
34754 X  r_cnt[NMAP_X] += r_cnt[NMAP];
34755
34756 X  for (i=1; i<=kar_nsq; i++) aa0_f[i] = fn0*(double)r_cnt[i];
34757 }
34758 X
34759 double nt_f[] = {0.0, 0.25, 0.25, 0.25, 0.25 };
34760 X
34761 /* Robinson and Robinson frequencies */
34762 double aa_f[] = {
34763 /* NULL */ 0.00,
34764 /* A */   0.0780474700897585,
34765 /* R */   0.0512953149316987,
34766 /* N */   0.0448725775979007,
34767 /* D */   0.0536397361638076,
34768 /* C */   0.0192460110427568,
34769 /* Q */   0.0426436013507063,
34770 /* E */   0.0629485981204668,
34771 /* G */   0.0737715654561964,
34772 /* H */   0.0219922696262025,
34773 /* I */   0.0514196403000682,
34774 /* L */   0.090191394464413,
34775 /* K */   0.0574383201866657,
34776 /* M */   0.0224251883196316,
34777 /* F */   0.0385564048655621,
34778 /* P */   0.0520279465667327,
34779 /* S */   0.0711984743501224,
34780 /* T */   0.0584129422708473,
34781 /* W */   0.013298374223799,
34782 /* Y */   0.0321647488738564,
34783 /* V */   0.0644094211988074};
34784 X
34785 /* initialize the Karlin frequency, probability arrays using
34786 X   an "average" composition (average length if n0 <=0) */
34787 X
34788 void
34789 init_karlin_a(struct pstruct *ppst, double *aa0_f, double **kp)
34790 {
34791 X  int kar_nsq, kar_range;
34792 X
34793 X  int i;
34794 X  double fn0, *kar_p;
34795 X
34796 X  kar_range = ppst->pam_h - ppst->pam_l + 1;
34797 X  if (*kp == NULL) {
34798 X    if ((kar_p=(double *)calloc(kar_range+1,sizeof(double)))==NULL) {
34799 X      fprintf(stderr," cannot allocate kar_p array: %d\n",kar_range+1);
34800 X      exit(1);
34801 X    }
34802 X  *kp = kar_p;
34803 X  }
34804 X
34805 X  if (ppst->nt_align) {
34806 X    kar_nsq = 4;
34807 X    for (i=1; i<=kar_nsq; i++) aa0_f[i] = nt_f[i];
34808 X  }
34809 X  else if (ppst->dnaseq==SEQT_PROT || ppst->dnaseq == SEQT_UNK) {
34810 X    kar_nsq = 20;
34811 X    for (i=1; i<=kar_nsq; i++) aa0_f[i] = aa_f[i];
34812 X  }
34813 X  else {
34814 X    kar_nsq = ppst->nsq;
34815 X    fn0 = 1.0/(double)(kar_nsq-1);
34816 X    for (i=1; i< kar_nsq; i++) aa0_f[i] = fn0;
34817 X    aa0_f[kar_nsq]=0.0;
34818 X  }
34819 X
34820 }
34821 X
34822 /* calculate set up karlin() to calculate Lambda, K, by calculating
34823 X   aa1 frequencies */
34824 int
34825 do_karlin(const unsigned char *aa1, int n1,
34826 X         int **pam2, struct pstruct *ppst,
34827 X         double *aa0_f, double *kar_p, double *lambda, double *H)
34828 {
34829 X  register unsigned const char *aap;
34830 X  int kar_range, kar_min, kar_max, kar_nsq;
34831 X  int r_cnt[NMAP+1];
34832 X  double aa1_f[NMAP];
34833 X  double fn1, kar_tot;
34834 X  int i, j;
34835 X
34836 X  kar_nsq = ppst->nsq;
34837 X  kar_min = ppst->pam_l;
34838 X  kar_max = ppst->pam_h;
34839 X  kar_range = kar_max - kar_min + 1;
34840 X
34841 X  r_cnt[NMAP]=0;
34842 X  for (i=1; i<=kar_nsq; i++) r_cnt[i]=1;
34843 X
34844 X  /* residue counts */
34845 X
34846 X  aap=aa1;
34847 X  while (*aap) r_cnt[ppst->hsqx[*aap++]]++;
34848 X
34849 X  r_cnt[NMAP_X] += r_cnt[NMAP];
34850 X  
34851 X  /* residue frequencies */
34852 X  fn1 = 100.0/(double)(n1+kar_nsq);
34853 X  for (i=1; i<=kar_nsq; i++) aa1_f[i]= fn1*(double)r_cnt[i];
34854 X
34855 X  for (i=0; i<=kar_range; i++) kar_p[i] = 0.0;
34856 X
34857 X  for (i=1; i<=kar_nsq; i++) {
34858 X    for (j=1; j<=kar_nsq; j++)
34859 X      kar_p[pam2[i][j]-kar_min] += aa0_f[i]*aa1_f[j];
34860 X  }
34861 X
34862 X  kar_tot = 0.0;
34863 X  for (i=0; i<=kar_range; i++) kar_tot += kar_p[i];
34864 X  if (kar_tot <= 0.00001) return 0;
34865 X
34866 X  for (i=0; i<=kar_range; i++) kar_p[i] /= kar_tot;
34867 X
34868 X  return karlin(kar_min, kar_max, kar_p, lambda, H);
34869 }
34870 X
34871 int
34872 do_karlin_a(int **pam2, struct pstruct *ppst,
34873 X         double *aa0_f, double *kar_p, double *lambda, double *K, double *H)
34874 {
34875 X  double *aa1fp;
34876 X  int kar_range, kar_min, kar_max, kar_nsq;
34877 X  double aa1_f[NMAP];
34878 X  double fn1, kar_tot;
34879 X  int i, j;
34880 X
34881 X  kar_min = ppst->pam_l;
34882 X  kar_max = ppst->pam_h;
34883 X  kar_range = kar_max - kar_min + 1;
34884 X
34885 X  kar_tot = 0.0;
34886 X  if (ppst->nt_align ) {
34887 X    kar_nsq = 4;
34888 X    aa1fp = nt_f;
34889 X    for (i=1; i<=kar_nsq; i++) {kar_tot += aa1fp[i];}
34890 X    for (i=1; i<=kar_nsq; i++) {aa1_f[i]= aa1fp[i]/kar_tot;}
34891 X  }
34892 X  else if (!ppst->nt_align) {
34893 X    kar_nsq = 20;
34894 X    aa1fp = aa_f;
34895 X    for (i=1; i<=kar_nsq; i++) {kar_tot += aa1fp[i];}
34896 X    for (i=1; i<=kar_nsq; i++) {aa1_f[i]= aa1fp[i]/kar_tot;}
34897 X  }
34898 X  else {
34899 X    kar_nsq = ppst->nsq;
34900 X    fn1 = 1.0/(double)(kar_nsq-1);
34901 X    for (i=1; i< kar_nsq; i++) aa1_f[i] = fn1;
34902 X    aa1_f[kar_nsq]=0.0;
34903 X  }
34904 X
34905 X  for (i=0; i<=kar_range; i++) kar_p[i] = 0.0;
34906 X
34907 X  for (i=1; i<=kar_nsq; i++) {
34908 X    for (j=1; j<kar_nsq; j++)
34909 X      kar_p[pam2[i][j]-kar_min] += aa0_f[i]*aa1_f[j];
34910 X  }    
34911 X
34912 X  kar_tot = 0.0;
34913 X  for (i=0; i<=kar_range; i++) kar_tot += kar_p[i];
34914 X  if (kar_tot <= 0.00001) return 0;
34915 X
34916 X  for (i=0; i<=kar_range; i++) kar_p[i] /= kar_tot;
34917 X
34918 X  return karlin_k(kar_min, kar_max, kar_p, lambda, K, H);
34919 }
34920 X
34921 /* take a array of letters and pam information and get *lambda, *H */
34922 int
34923 karlin(int low,                 /* Lowest score (must be negative)    */
34924 X       int high,               /* Highest score (must be positive)   */
34925 X       double *pr,             /* Probabilities for various scores   */
34926 X       double *lambda_p,       /* Pointer to parameter lambda        */
34927 X       double *H_p)            /* Pointer to parameter H              */
34928 {
34929 X  int i,range, nit;
34930 X  double up,new,sum,av,beta,ftemp;
34931 X  double lambda;
34932 X  double *p,*ptr1;
34933 X
34934 X  /* Calculate the parameter lambda */
34935 X
34936 X  p = pr;
34937 X  range = high-low;
34938 X
34939 X  /* check for E() < 0.0 */
34940 X  sum = 0;
34941 X  ptr1 = pr;
34942 X  for (i=low; i <= high ; i++) sum += i* (*ptr1++);
34943 X  if (sum >= 0.0) {
34944 #ifdef DEBUG
34945 X    fprintf(stderr," (karlin lambda) non-negative expected score: %.4lg\n",
34946 X           sum);
34947 #endif
34948 X    return 0;
34949 X  }
34950 X
34951 X  /* up is upper bound on lambda */
34952 X  up=0.5;
34953 X  do {
34954 X    up *= 2.0;
34955 X    ptr1=p;
34956 X
34957 X    beta=exp(up);
34958 X
34959 X    ftemp=exp(up*(low-1));
34960 X    sum = 0.0;
34961 X    for (i=0; i<=range; ++i) sum+= *ptr1++ * (ftemp*=beta);
34962 X  }
34963 X  while (sum<1.0);
34964 X
34965 X  /* avoid overflow from very large lambda*S */
34966 /*
34967 X  do {
34968 X    up /= 2.0;
34969 X    ptr1=p;
34970 X    beta=exp(up);
34971 X
34972 X    ftemp=exp(up*(low-1));
34973 X    sum = 0.0;
34974 X    for (i=0; i<=range; ++i) sum+= *ptr1++ * (ftemp*=beta);
34975 X  } while (sum > 2.0);
34976 X
34977 X  up *= 2.0;
34978 */      /* we moved past, now back up */
34979 X
34980 X  /*   for (lambda=j=0;j<25;++j) { */
34981 X  lambda = 0.0;
34982 X  nit = 0;
34983 X  while ( nit++ < MAXIT ) {
34984 X    new = (lambda+up)/2.0;
34985 X    beta = exp(new);
34986 X    ftemp = exp(new*(low-1));
34987 X    ptr1=p;
34988 X    sum = 0.0;
34989 X    /* multiply by exp(new) for each score */
34990 X    for (i=0;i<=range;++i) sum+= *ptr1++ * (ftemp*=beta);
34991 X
34992 X    if (sum > 1.0 + TINY) up=new;
34993 X    else {
34994 X      if ( fabs(lambda - new) < TINY ) goto done;
34995 X      lambda = new;
34996 X    }
34997 X  }
34998 X
34999 X  if (lambda <= 1e-10) {
35000 X    lambda = -1.0;
35001 X    return 0;
35002 X  }
35003 X
35004 X done:
35005 X  *lambda_p = lambda;
35006 X
35007 X  /* Calculate the parameter K */
35008 X
35009 X  ptr1=p;
35010 X  ftemp=exp(lambda*(low-1));
35011 X  for (av=0.0, i=low; i<=high; ++i)
35012 X    av+= *ptr1++ *i*(ftemp*=beta);
35013 X  *H_p= lambda*av;
35014 X
35015 X  return 1;            /* Parameters calculated successfully */
35016 }
35017 X
35018 static int a_gcd (int, int);
35019 X
35020 /* take a array of letters and pam information and get *lambda, *K, *H */
35021 static int
35022 karlin_k(int low,               /* Lowest score (must be negative)    */
35023 X        int high,              /* Highest score (must be positive)   */
35024 X        double *pr,            /* Probabilities for various scores   */
35025 X        double *lambda_p,      /* Pointer to parameter lambda        */
35026 X        double *K_p,
35027 X        double *H_p)           /* Pointer to parameter H              */
35028 {
35029 X  int i,j,range,lo,hi,first,last, nit;
35030 X  double up,new,sum,Sum,av,beta,oldsum,ratio,ftemp;
35031 X  double lambda;
35032 X  double *p,*P,*ptrP,*ptr1,*ptr2;
35033 X
35034 X  /* Calculate the parameter lambda */
35035 X
35036 X  p = pr;
35037 X  range = high-low;
35038 X
35039 X  /* check for E() < 0.0 */
35040 X  sum = 0;
35041 X  ptr1 = pr;
35042 X  for (i=low; i <= high ; i++) sum += i* (*ptr1++);
35043 X  if (sum >= 0.0) {
35044 #ifdef DEBUG
35045 X    fprintf(stderr," (karlin lambda) non-negative expected score: %.4lg\n",
35046 X           sum);
35047 #endif
35048 X    return 0;
35049 X  }
35050 X
35051 X  /* up is upper bound on lambda */
35052 X  up=0.5;
35053 X  do {
35054 X    up *= 2.0;
35055 X    ptr1=p;
35056 X
35057 X    beta=exp(up);
35058 X
35059 X    ftemp=exp(up*(low-1));
35060 X    sum = 0.0;
35061 X    for (i=0; i<=range; ++i) sum+= *ptr1++ * (ftemp*=beta);
35062 X  }
35063 X  while (sum<1.0);
35064 X
35065 X  /* avoid overflow from very large lambda*S */
35066 X  /*
35067 X  do {
35068 X    up /= 2.0;
35069 X    ptr1=p;
35070 X    beta=exp(up);
35071 X
35072 X    ftemp=exp(up*(low-1));
35073 X    sum = 0.0;
35074 X    for (i=0; i<=range; ++i) sum+= *ptr1++ * (ftemp*=beta);
35075 X  } while (sum > 2.0);
35076 X
35077 X  up *= 2.0;
35078 X  */
35079 X  /* we moved past, now back up */
35080 X
35081 X  /*   for (lambda=j=0;j<25;++j) { */
35082 X  lambda = 0.0;
35083 X  nit = 0;
35084 X  while ( nit++ < MAXIT ) {
35085 X    new = (lambda+up)/2.0;
35086 X    beta = exp(new);
35087 X    ftemp = exp(new*(low-1));
35088 X    ptr1=p;
35089 X    sum = 0.0;
35090 X    /* multiply by exp(new) for each score */
35091 X    for (i=0;i<=range;++i) sum+= *ptr1++ * (ftemp*=beta);
35092 X
35093 X    if (sum > 1.0 + TINY) up=new;
35094 X    else {
35095 X      if ( fabs(lambda - new) < TINY ) goto done;
35096 X      lambda = new;
35097 X    }
35098 X  }
35099 X
35100 X  if (lambda <= 1e-10) {
35101 X    lambda = -1.0;
35102 X    return 0;
35103 X  }
35104 X
35105 X done:
35106 X  *lambda_p = lambda;
35107 X
35108 X  /* Calculate the parameter H */
35109 X
35110 X  ptr1=p;
35111 X  ftemp=exp(lambda*(low-1));
35112 X  for (av=0.0, i=low; i<=high; ++i) av+= *ptr1++ *i*(ftemp*=beta);
35113 X  *H_p= lambda*av;
35114 X
35115 X  /* Calculate the pamameter K */
35116 X  Sum=lo=hi=0;
35117 X  P= (double *) calloc(MAXIT*range+1,sizeof(double));
35118 X  for (*P=sum=oldsum=j=1;j<=MAXIT && sum>0.001;Sum+=sum/=j++) {
35119 X    first=last=range;
35120 X    for (ptrP=P+(hi+=high)-(lo+=low); ptrP>=P; *ptrP-- =sum) {
35121 X      ptr1=ptrP-first;
35122 X      ptr2=p+first;
35123 X      for (sum=0,i=first; i<=last; ++i) sum += *ptr1-- * *ptr2++;
35124 X      if (first) --first;
35125 X      if (ptrP-P<=range) --last;
35126 X    }
35127 X    ftemp=exp(lambda*(lo-1));
35128 X    for (sum=0,i=lo;i;++i) sum+= *++ptrP * (ftemp*=beta);
35129 X    for (;i<=hi;++i) sum+= *++ptrP;
35130 X    ratio=sum/oldsum;
35131 X    oldsum=sum;
35132 X  }
35133 X  for (;j<=200;Sum+=oldsum/j++) oldsum*=ratio;
35134 X  for (i=low;!p[i-low];++i);
35135 X  for (j= -i;i<high && j>1;) if (p[++i-low]) j=a_gcd(j,i);
35136 X  *K_p = (j*exp(-2*Sum))/(av*(1.0-exp(- lambda*j)));
35137 X  free(P);
35138 X
35139 X  return 1;            /* Parameters calculated successfully */
35140 }
35141 X
35142 int
35143 a_gcd(int a, int b)
35144 {
35145 X  int c;
35146 X
35147 X  if (b<0) b= -b;
35148 X  if (b>a) { c=a; a=b; b=c; }
35149 X  for (;b;b=c) { c=a%b; a=b; }
35150 X  return a;
35151 }
35152 X
35153 SHAR_EOF
35154 chmod 0644 karlin.c ||
35155 echo 'restore of karlin.c failed'
35156 Wc_c="`wc -c < 'karlin.c'`"
35157 test 13727 -eq "$Wc_c" ||
35158         echo 'karlin.c: original size 13727, current size' "$Wc_c"
35159 fi
35160 # ============= last_tat.c ==============
35161 if test -f 'last_tat.c' -a X"$1" != X"-c"; then
35162         echo 'x - skipping last_tat.c (File already exists)'
35163 else
35164 echo 'x - extracting last_tat.c (Text)'
35165 sed 's/^X//' << 'SHAR_EOF' > 'last_tat.c' &&
35166 X
35167 /* copyright (c) 1996, 1997, 1998, 1999 William R. Pearson and the
35168 X   U. of Virginia */
35169 X
35170 /* $Name: fa_34_26_5 $ - $Id: last_tat.c,v 1.8 2006/04/12 18:00:02 wrp Exp $ */
35171 X
35172 #include <stdio.h>
35173 #include <stdlib.h>
35174 #include <string.h>
35175 X
35176 #include "defs.h"
35177 #include "mm_file.h"
35178 X
35179 #include "structs.h"
35180 #include "param.h"
35181 X
35182 #ifndef PCOMPLIB
35183 #include "mw.h"
35184 #else
35185 #include "msg.h"
35186 #include "p_mw.h"
35187 X
35188 void do_stage2(struct beststr **bptr, int nbest, struct mngmsg m_msg0,
35189 X              int s_func, struct qmng_str *qm_msp);
35190 #endif
35191 X
35192 X
35193 extern int (*ranlib) (char *str, int cnt,
35194 X              fseek_t libpos, char *libstr,
35195 X              struct lmf_str *lm_fd);
35196 X
35197 #define RANLIB (m_fptr->ranlib)
35198 X
35199 #define MAX_BLINE 200
35200 X
35201 int
35202 re_getlib(unsigned char *, int, int, int, int, int, long *, long *, 
35203 X         struct lmf_str *m_fptr);
35204 X
35205 void
35206 do_work(unsigned char *aa0, int n0, unsigned char *aa1, int n1, int frame, 
35207 X       struct pstruct *ppst, void *f_str, int qr_flg, struct rstruct *rst);
35208 X
35209 extern void
35210 do_opt (unsigned char *aa0, int n0, unsigned char *aa1, int n1,
35211 X       int frame, struct pstruct *pst, void *f_str,
35212 X       struct rstruct *rst);
35213 X
35214 struct lmf_str *re_openlib(struct lmf_str *, int outtty);
35215 X
35216 void sortbestz (struct beststr **bptr, int nbest);
35217 X
35218 double zs_to_E(double zs,int n1, int isdna, long entries, struct db_str db);
35219 X
35220 double scale_one_score(int ipos, double escore, struct db_str db, void *rs_str);
35221 X
35222 void sortbests (struct beststr **bptr, int nbest)
35223 {
35224 X    int gap, i, j;
35225 X    struct beststr *tmp;
35226 X
35227 X    for (gap = nbest/2; gap > 0; gap /= 2)
35228 X       for (i = gap; i < nbest; i++)
35229 X           for (j = i - gap; j >= 0; j-= gap) {
35230 X             if (bptr[j]->score[0] >= bptr[j + gap]->score[0]) break;
35231 X             tmp = bptr[j];
35232 X             bptr[j] = bptr[j + gap];
35233 X             bptr[j + gap] = tmp;
35234 X           }
35235 }
35236 X
35237 int
35238 last_calc(
35239 #ifndef PCOMPLIB
35240 X         unsigned char **aa0, unsigned char *aa1, int maxn,
35241 #endif    
35242 X         struct beststr **bptr, int nbest, 
35243 X         struct mngmsg m_msg, struct pstruct *ppst
35244 #ifdef PCOMPLIB
35245 X         , struct qmng_str *qm_msp
35246 #else
35247 X         , void **f_str
35248 #endif
35249 X         , void *rstat_str)
35250 {
35251 X  int nopt, ib;
35252 X  struct beststr *bbp;
35253 X  long loffset, l_off;
35254 X  int n0, n1;
35255 X  struct rstruct rst;
35256 X  struct lmf_str *m_fptr;
35257 X  char bline[60];
35258 X  int tat_samp, tat_inc, loop_cnt, i;
35259 X  double min_escore, ess;
35260 X
35261 X  n0 = m_msg.n0;
35262 X
35263 X  sortbestz(bptr,nbest);
35264 X
35265 X  tat_inc = 500;
35266 /*
35267 X  if (zs_to_E(bptr[0]->zscore,bptr[0]->n1,0,ppst->zdb_size,m_msg.db)/ 
35268 X      zs_to_E(bptr[nbest-1]->zscore,bptr[nbest-1]->n1,0,ppst->zdb_size,m_msg.db)
35269 X       < 1e-20) { tat_inc /= 4 ;}
35270 */
35271 X
35272 /* || (zs_to_E(bptr[0]->zscore,bptr[0]->n1,0,ppst->zdb_size,m_msg.db)< 1e-5); */
35273 X
35274 X  ib = tat_samp = 0;
35275 X  for (loop_cnt = 0; loop_cnt < 5; loop_cnt++) {
35276 X    tat_samp += tat_inc;
35277 X    nopt = min(nbest,tat_samp);
35278 X    min_escore = 1000000.0;
35279 #ifndef PCOMPLIB
35280 X    for ( ; ib<nopt; ib++) {
35281 X      bbp = bptr[ib];
35282 X
35283 X      if (bbp->score[0] < 0) break;
35284 X
35285 X      if ((m_fptr=re_openlib(bbp->m_file_p,!m_msg.quiet))==NULL) {
35286 X       fprintf(stderr,"*** cannot re-open %s\n",bbp->m_file_p->lb_name);
35287 X       exit(1);
35288 X      }
35289 X      RANLIB(bline,sizeof(bline),bbp->lseek,bbp->libstr,m_fptr);
35290 X
35291 X      n1 = re_getlib(aa1,maxn,m_msg.maxt3,m_msg.loff,bbp->cont,m_msg.term_code,
35292 X                    &loffset,&l_off,bbp->m_file_p);
35293 X
35294 X      do_opt(aa0[bbp->frame],m_msg.n0,aa1,n1,bbp->frame,ppst,
35295 X            f_str[bbp->frame],&rst);
35296 X      bbp->score[0]=rst.score[0];
35297 X      bbp->score[1]=rst.score[1];
35298 X      bbp->score[2]=rst.score[2];
35299 X      bbp->escore=rst.escore;
35300 X      bbp->segnum = rst.segnum;
35301 X      bbp->seglen = rst.seglen;
35302 X
35303 X      if ((ess=scale_one_score(ib, bbp->escore, m_msg.db, rstat_str)) < 
35304 X       min_escore) { min_escore = ess;}
35305 X      /*
35306 X      fprintf(stderr,"%d: %4d %2d %3d %.4g %.4g\n",
35307 X             ib, bbp->score[0], bbp->segnum,bbp->seglen,bbp->escore, ess);
35308 X      */
35309 X    }
35310 #else
35311 X    do_stage2(&bptr[ib], nopt-ib, m_msg, DO_CALC_FLG, qm_msp);
35312 X
35313 X    for ( ; ib < nopt; ib++) {
35314 X      if ((ess=scale_one_score(ib, bptr[ib]->escore, m_msg.db, rstat_str)) < 
35315 X       min_escore) { min_escore = ess;}
35316 X      /*
35317 X      fprintf(stderr, "%d: %4d %2d %3d %.4g %.4g\n",
35318 X             ib,bptr[ib]->score[0],bptr[ib]->segnum,bptr[ib]->seglen,bptr[ib]->escore,ess);
35319 X      */
35320 X    }
35321 #endif
35322 X
35323 X
35324 X    if (min_escore > m_msg.e_cut) return ib;
35325 X  }
35326 X  return ib;
35327 }
35328 SHAR_EOF
35329 chmod 0644 last_tat.c ||
35330 echo 'restore of last_tat.c failed'
35331 Wc_c="`wc -c < 'last_tat.c'`"
35332 test 4128 -eq "$Wc_c" ||
35333         echo 'last_tat.c: original size 4128, current size' "$Wc_c"
35334 fi
35335 # ============= lcbo.aa ==============
35336 if test -f 'lcbo.aa' -a X"$1" != X"-c"; then
35337         echo 'x - skipping lcbo.aa (File already exists)'
35338 else
35339 echo 'x - extracting lcbo.aa (Text)'
35340 sed 's/^X//' << 'SHAR_EOF' > 'lcbo.aa' &&
35341 >LCBO - Prolactin precursor - Bovine
35342 MDSKGSSQKGSRLLLLLVVSNLLLCQGVVSTPVCPNGPGNCQVSLRDLFDRAVMVSHYIHDLSS
35343 EMFNEFDKRYAQGKGFITMALNSCHTSSLPTPEDKEQAQQTHHEVLMSLILGLLRSWNDPLYHL
35344 VTEVRGMKGAPDAILSRAIEIEEENKRLLEGMEMIFGQVIPGAKETEPYPVWSGLPSLQTKDED
35345 ARYSAFYNLLHCLRRDSSKIDTYLKLLNCRIIYNNNC*
35346 SHAR_EOF
35347 chmod 0644 lcbo.aa ||
35348 echo 'restore of lcbo.aa failed'
35349 Wc_c="`wc -c < 'lcbo.aa'`"
35350 test 271 -eq "$Wc_c" ||
35351         echo 'lcbo.aa: original size 271, current size' "$Wc_c"
35352 fi
35353 # ============= lib_sel.c ==============
35354 if test -f 'lib_sel.c' -a X"$1" != X"-c"; then
35355         echo 'x - skipping lib_sel.c (File already exists)'
35356 else
35357 echo 'x - extracting lib_sel.c (Text)'
35358 sed 's/^X//' << 'SHAR_EOF' > 'lib_sel.c' &&
35359 /* copyright (c) 1996, 1997, 1998, 1999 William R. Pearson and the
35360 X   U. of Virginia */
35361 X
35362 /* $Name: fa_34_26_5 $ - $Id: lib_sel.c,v 1.16 2006/12/06 17:30:52 wrp Exp $ */
35363 X
35364 /*      modified Dec 13, 1989 requires different FASTLIBS */
35365 X
35366 #include <stdio.h>
35367 #include <stdlib.h>
35368 #include <math.h>
35369 #include <ctype.h>
35370 #include <string.h>
35371 X
35372 #include "defs.h"
35373 #include "structs.h"
35374 X
35375 #ifdef NCBIBL13
35376 #define LASTLIB NCBIBL13+1
35377 #else
35378 #define LASTLIB 11
35379 #endif
35380 X
35381 X
35382 int getlnames(char *tname, struct mngmsg *m_msg);
35383 void addfile(char *, char *, struct mngmsg *);
35384 void libchoice(char *lname, int nl, struct mngmsg *m_msg);
35385 void libselect(char *lname, struct mngmsg *m_msg);
35386 void subs_env(char *dest, char *src, int dest_size);
35387 char *ulindex(char *str, char *chr);
35388 X
35389 static char ldname[MAX_FN];
35390 static char *libenv;
35391 X
35392 int
35393 getlnames(char *iname, struct mngmsg *m_msg)    /* read in the library names */
35394 {
35395 X  char *bp, tsave[MAX_STR], *tname;
35396 X  char lline[MAX_FN], *llp;
35397 X  FILE *tptr;
35398 X
35399 X  /* expand environment variables */
35400 X  
35401 X  tname = tsave;
35402 X  subs_env(tname, iname, sizeof(tsave));
35403 X
35404 X  if (*tname != '@') {addfile(tname,"\0",m_msg); return 1;}
35405 X  else tname++;
35406 X
35407 X  /* remove ' ' before deftype if present */
35408 X  if ((bp=strchr(tname,' '))!=NULL) *bp='\0';
35409 X
35410 X  if ((tptr=fopen(tname,"r"))==NULL) {
35411 X    fprintf(stderr," could not open file of names: %s\n",tname);
35412 X    return 0;
35413 X  }
35414 X
35415 X  while (fgets(lline,sizeof(lline),tptr)!=NULL) {
35416 X    if (lline[0]==';') continue;
35417 X    if ((bp=strchr(lline,'\n'))!=NULL) *bp='\0';
35418 X    subs_env(tsave, lline, sizeof(tsave));
35419 X    if (tsave[0]=='<') {
35420 X      strncpy(ldname,&tsave[1],sizeof(ldname));
35421 X      ldname[sizeof(ldname)-1]='\0';
35422 X      libenv=ldname;
35423 X    }
35424 X    else addfile(tsave,libenv,m_msg);
35425 X  }
35426 X  fclose(tptr);
35427 X  return 1;
35428 }
35429 X
35430 /* libchoice displays a list of potential library files
35431 X   in the new &lib& version, only traditional 1-letter files will be
35432 X   shown initially
35433 */
35434 X
35435 void
35436 libchoice(char *lname, int nl, struct mngmsg *m_msg)
35437 {
35438 X  FILE *fch;
35439 X  char line[MAX_STR], *bp;
35440 X  char *chstr[MAX_CH],*chfile[MAX_CH];
35441 X  char *chtmp, *charr;
35442 X  int i,j,k,chlen;
35443 X
35444 X  charr = NULL;
35445 X  if (strlen(m_msg->flstr)> (size_t)0) {
35446 X    chlen = MAX_CH*MAX_FN;
35447 X    if ((chtmp=charr=calloc((size_t)chlen,sizeof(char)))==NULL) {
35448 X      fprintf(stderr,"cannot allocate choice file array\n");
35449 X      goto l1;
35450 X    }
35451 X    chlen--;
35452 X    if ((fch=fopen(m_msg->flstr,"r"))==NULL) {
35453 X      fprintf(stderr," cannot open choice file: %s\n",m_msg->flstr);
35454 X      goto l1;
35455 X    }
35456 X    fprintf(stderr,"\n Choose sequence library:\n\n");
35457 X
35458 X    for (i=j=0; j<MAX_CH; i++) {
35459 X      if (fgets(line,sizeof(line),fch)==NULL) break;/* check for comment */
35460 X      if (line[0]==';') continue;
35461 X      if ((bp=strchr(line,'\n'))!=NULL) *bp='\0'; /* remove \n */
35462 X      if ((bp=strchr(line,'$'))==NULL) continue;  /* if no '$', continue */
35463 X      *bp++='\0';            /* replace $ with \0, bp points to libtype */
35464 X
35465 X      /* if libtypes don't match, continue */
35466 X      if ((*bp++ -'0')!=m_msg->ldnaseq) continue;
35467 X
35468 X      /* if the library file name is too long, quit */
35469 X      if ((k=strlen(line))>chlen) break;
35470 X
35471 X      /* save the library file name */
35472 X      strncpy(chstr[j]=chtmp,line,chlen);
35473 X      chtmp += k+1; chlen -= k+1;
35474 X
35475 X      if ((k=strlen(bp))>chlen) break;
35476 X      strncpy(chfile[j]=chtmp,bp,chlen);
35477 X      chtmp += k+1; chlen -= k+1;
35478 X      fprintf(stderr,"    %c: %s\n",*chfile[j++],line);
35479 X    }
35480 X  l2:  fprintf(stderr,"\n Enter library filename (e.g. %s), letter (e.g. P)\n",
35481 X              (m_msg->ldnaseq==0)? "prot.lib" : "dna.lib");
35482 X    fprintf(stderr," or a %% followed by a list of letters (e.g. %%PN): ");
35483 X    fflush(stderr);
35484 X    if (fgets(line,sizeof(line),stdin)==NULL) exit(0);
35485 X    if ((bp=strchr(line,'\n'))!=NULL) *bp='\0';
35486 X    if (strlen(line)==0) goto l2;
35487 X    strncpy(lname,line,nl);
35488 X  }
35489 X  else {
35490 X  l1: fprintf(stderr," library file name: ");
35491 X    fflush(stderr);
35492 X    if (fgets(line,sizeof(line),stdin)==NULL) exit(0);
35493 X    if ((bp=strchr(line,'\n'))!=NULL) *bp='\0';
35494 X    if (strlen(line)> (size_t)0) strncpy(lname,line,nl);
35495 X    else goto l1;
35496 X  }
35497 X  if (charr!=NULL) {
35498 X    fclose(fch);
35499 X    free(charr);
35500 X  }
35501 }
35502 X
35503 /* libselect parses the choices in char *lname and builds the list
35504 X   of library files
35505 */
35506 void
35507 libselect(char *lname, struct mngmsg *m_msg)
35508 {
35509 X  char line[MAX_FN*2], *bp, *bp1;
35510 X  char *llnames[MAX_LF]; /* pointers into new list of names */
35511 X  int new_abbr,ich, nch;         /* use new multi-letter abbr */
35512 X  FILE *fch;
35513 X
35514 X  new_abbr = 0;
35515 X  m_msg->nln = 0;
35516 X  if (strlen(lname) > (size_t)1 && *lname != '%' && *lname != '+') {
35517 X    getlnames(lname,m_msg); /* file name */ 
35518 X    return;
35519 X  }
35520 X  else {
35521 X    if (*m_msg->flstr=='\0') {
35522 X      fprintf(stderr," abbrv. list request but FASTLIBS undefined, cannot use %s\n",lname);
35523 X      exit(1);
35524 X    }
35525 X
35526 X    if (strchr(lname,'+')) {
35527 X      /* indicates list of database abbrevs (not files) */
35528 X      new_abbr=1;
35529 X      nch = 0;
35530 X      bp = lname+1; if (*bp == '+') bp++;
35531 X      for (bp1=bp; bp!=NULL && bp1!=NULL; bp=bp1+1) {
35532 X       if ((bp1=strchr(bp,'+'))!=NULL) *bp1='\0';
35533 X       llnames[nch++] = bp;
35534 X      }
35535 X    }
35536 X    else if (*lname=='%') {     /* list of single letter abbreviations */
35537 X      lname++; /* bump over '%' to get letters */
35538 X    }
35539 X
35540 X  /* else just use a single character abbreviation */
35541 X
35542 X  if (strlen(m_msg->flstr) > (size_t)0) {
35543 X    if ((fch=fopen(m_msg->flstr,"r"))==NULL) {
35544 X      fprintf(stderr," cannot open choice file: %s\n",m_msg->flstr);
35545 X      return;
35546 X    }
35547 X  }
35548 X  else {
35549 X    fprintf(stderr," FASTLIBS undefined\n");
35550 X    addfile(lname,"\0",m_msg);
35551 X    return;
35552 X  }
35553 X
35554 X  /* read each line of FASTLIBS */
35555 X    while (fgets(line,sizeof(line),fch)!=NULL) { 
35556 X      if (line[0]==';') continue;      /* skip comments */
35557 X      if ((bp=strchr(line,'\n'))!=NULL) *bp='\0';      /* remove '\n' */
35558 X      if ((bp=strchr(line,'$'))==NULL) continue; /* no delim, continue */
35559 X      *bp++='\0';      /* point to library type */
35560 X      if ((*bp++ -'0')!=m_msg->ldnaseq) continue; /* doesn't match, continue */
35561 X
35562 X      /* if !new_abbr, match on one letter with ulindex() */
35563 X      if (!new_abbr) {
35564 X       if (*bp=='+') continue; /* not a &lib& */
35565 X       else if (ulindex(lname,bp)!=NULL) { 
35566 X         strncpy(m_msg->ltitle,line,MAX_FN);
35567 X         getlnames(bp+1,m_msg);
35568 X       }
35569 X      }
35570 X      else {
35571 X       if (*bp!='+') continue;
35572 X       else {
35573 X         bp++;
35574 X         if ((bp1 = strchr(bp,'+'))!=NULL) {
35575 X           *bp1='\0';
35576 X           for (ich = 0; ich<nch; ich++) {
35577 X             if (strcmp(llnames[ich],bp)==0) {
35578 X               strncpy(m_msg->ltitle,line,MAX_FN);
35579 X               getlnames(bp1+1,m_msg);
35580 X               break;
35581 X             }
35582 X           }
35583 X           *bp1='+';
35584 X         }
35585 X         else fprintf(stderr,"%s missing final '+'\n",bp);
35586 X       }
35587 X      }
35588 X    }
35589 X    fclose(fch);
35590 X  }
35591 }
35592 X
35593 void
35594 addfile(char *fname, char *env, struct mngmsg *m_msg)
35595 {
35596 X  char tname[MAX_STR], *bp, *bp1;
35597 X  char *lbptr;
35598 X  int len, lenv, l_size;
35599 X
35600 X  /*  check for default directory for files  */
35601 X  if (env != NULL && *env != '\0') lenv = strlen(env)+1;
35602 X  else lenv = 0;
35603 X
35604 X  len=strlen(fname)+1+lenv;
35605 X
35606 X  if (lenv > 1 && *fname != '#') {     /* add default directory to file name */
35607 X    strncpy(tname,env,sizeof(tname)-1);
35608 #ifdef UNIX
35609 X    strcat(tname,"/");
35610 #endif
35611 X    }
35612 X  else tname[0]='\0';
35613 X
35614 X  /* add fname to tname, allocate space, and move to space */
35615 X  strncat(tname,fname,sizeof(tname)-strlen(tname)-1);
35616 X  len=strlen(tname)+1;
35617 X  if ((lbptr=calloc(len,sizeof(char)))==NULL) {
35618 X    fprintf(stderr,"no more space for filenames: %s ignored\n",fname);
35619 X    return;
35620 X  }
35621 X  else {
35622 X    strncpy(lbptr,tname,len);
35623 X    lbptr[len-1]='\0';
35624 X  }
35625 X
35626 X  if (m_msg->nln< MAX_LF) {
35627 X    m_msg->lbnames[m_msg->nln++]=lbptr;
35628 X  }
35629 X  else fprintf(stderr," no more file name slots: %s ignored\n",lbptr);
35630 }
35631 X
35632 char *
35633 ulindex(char *str, char *chr)
35634 {
35635 X  char c;
35636
35637 X  c = tolower((int)(*chr));
35638 X
35639 X  while (*str != '\0' && tolower(*str) !=c ) str++;
35640 X  if (*str=='\0') return NULL;
35641 X  else return str;
35642 }
35643 SHAR_EOF
35644 chmod 0644 lib_sel.c ||
35645 echo 'restore of lib_sel.c failed'
35646 Wc_c="`wc -c < 'lib_sel.c'`"
35647 test 7638 -eq "$Wc_c" ||
35648         echo 'lib_sel.c: original size 7638, current size' "$Wc_c"
35649 fi
35650 # ============= list_db.c ==============
35651 if test -f 'list_db.c' -a X"$1" != X"-c"; then
35652         echo 'x - skipping list_db.c (File already exists)'
35653 else
35654 echo 'x - extracting list_db.c (Text)'
35655 sed 's/^X//' << 'SHAR_EOF' > 'list_db.c' &&
35656 /* list_db.c - report values from map_db.c  */
35657 X
35658 /* copyright (c) 1999 William R. Pearson */
35659 X
35660 /* format of the index file:
35661 X
35662 1)  map_db version number ["MP"+2 bytes]
35663 2)  number of sequences in database [4 bytes]
35664 3)  total length of database        [8 bytes]
35665 4)  longest sequence in database    [8 bytes]
35666 5) list of offsets to definitions  [num_seq+1] int*8
35667 6) list of offsets to sequences    [num_seq+1] int*8
35668 7) list of flag characters for sequences [num_seq+1] bytes
35669 X    (used for GCG binary to encode 2bit or 4 bit representation)
35670 X
35671 X    sequence files will be as defined by their format
35672 */
35673 X
35674 #include <stdio.h>
35675 #include <stdlib.h>
35676 #include <string.h>
35677 X
35678 #include "uascii.h"
35679 #include "ncbl2_head.h"
35680 X
35681 void src_int4_write(FILE *, int);
35682 void src_int4_read(FILE *, int *);
35683 void src_long4_read(FILE *, long *);
35684 void src_long8_write(FILE *, long);
35685 void src_long8_read(FILE *, long *);
35686 X
35687 void newname(char *nname, char *oname, char *suff, int maxn);
35688 X
35689 main(int argc, char **argv)
35690 {
35691 X  FILE *libi;
35692 X  char lname[256];
35693 X  char iname[256];
35694 X  char format[4];
35695 X  char *bp;
35696 X
35697 X  int i;
35698 X  int d_pos;   /* start of description */
35699 X  int s_pos;   /* start of sequence */
35700 X  int attr;    /* sequence attribute */
35701 X  int lib_aa;  /* 0 => DNA, 1 => protein */
35702 X  int nlib;    /* number of entries */
35703 X  long f_size;
35704 X  long max_len;        /* longest sequence */
35705 X  long tot_len;        /* total sequence length */
35706 X  int n1;
35707 X  
35708 X  int lib_size;        /* current space available - may be realloc'ed */
35709 X  int lib_inc;
35710 X  int lib_type; /* 1 for protein, 0 for DNA */
35711 X  int lib_dna; /* dna=1; prot=0; */
35712 X  long *d_pos_arr;     /* array of description pointers */
35713 X  long *s_pos_arr;     /* array of description pointers */
35714 X  char *attr_arr;      /* array of attribute chars */
35715 X
35716 X  int mm64_flag;
35717 X
35718 X  lib_type = 0;
35719 X  lib_dna = 0;
35720 X
35721 X  /* open the database */
35722 X  if (argc > 1) strncpy(lname, argv[1],sizeof(lname));
35723 X  else {
35724 X    fprintf(stderr," Entry library name: ");
35725 X    fgets(lname,sizeof(lname),stdin);
35726 X    if ((bp=strchr(lname,'\n'))!=NULL) *bp='\0';
35727 X  }
35728 X    
35729 X  if ((bp=strchr(lname,' '))!=NULL) {
35730 X    lib_type = atoi(bp+1);
35731 X    *bp='\0';
35732 X  }
35733 X  else lib_type = 0;
35734 X
35735 X  newname(iname,lname,"xin",sizeof(iname));
35736 X
35737 X  if ((libi=fopen(iname,"r"))==NULL) {
35738 X    fprintf(stderr," cannot open %s\n",iname);
35739 X    exit(1);
35740 X  }
35741 X
35742 X  fread(format,1,sizeof(format),libi);
35743 X  printf("%c%c%d %d\n",format[0],format[1],format[2],format[3]);
35744 X  mm64_flag = (format[2]==1);
35745 X
35746 X  src_int4_read(libi,&lib_aa);
35747 X
35748 X  if (mm64_flag) src_long8_read(libi,&f_size);
35749 X  else src_long4_read(libi,&f_size);
35750 X
35751 X  src_int4_read(libi,&nlib);
35752 X
35753 X  if (mm64_flag) {
35754 X    src_long8_read(libi,&tot_len);
35755 X    src_long8_read(libi,&max_len);
35756 X  }
35757 X  else {
35758 X    src_long4_read(libi,&tot_len);
35759 X    src_long4_read(libi,&max_len);
35760 X  }
35761 X
35762 X  printf(" %d entries; tot: %ld; max: %ld\n",nlib,tot_len,max_len);
35763 X
35764 X  /* allocate array of description pointers */
35765 X  if ((d_pos_arr=(long *)calloc(nlib+1, sizeof(long)))==NULL) {
35766 X    fprintf(stderr," cannot allocate %d for desc. array\n",nlib+1);
35767 X    exit(1);
35768 X  }
35769 X  /* allocate array of sequence pointers */
35770 X  if ((s_pos_arr=(long *)calloc(nlib+1, sizeof(long)))==NULL) {
35771 X    fprintf(stderr," cannot allocate %d for seq. array\n",nlib+1);
35772 X    exit(1);
35773 X  }
35774 X  if ((attr_arr=(char *)calloc(nlib+1, sizeof(char)))==NULL) {
35775 X    fprintf(stderr," cannot allocate %d for attr. array\n",nlib+1);
35776 X    exit(1);
35777 X  }
35778 X  
35779 X  if (mm64_flag) {
35780 X    for (i=0; i<=nlib; i++) src_long8_read(libi,&d_pos_arr[i]);
35781 X    for (i=0; i<=nlib; i++) src_long8_read(libi,&s_pos_arr[i]);
35782 X  }
35783 X  else {
35784 X    for (i=0; i<=nlib; i++) src_long4_read(libi,&d_pos_arr[i]);
35785 X    for (i=0; i<=nlib; i++) src_long4_read(libi,&s_pos_arr[i]);
35786 X  }
35787 X
35788 X  fread(attr_arr,nlib+1,sizeof(char),libi);
35789 X  fclose(libi);
35790 X
35791 X  printf("header\tseq\n");
35792 X
35793 X  for (i=0; i<nlib; i++) printf("%ld\t%ld\n",d_pos_arr[i],s_pos_arr[i]);
35794 }
35795 X
35796 void src_int4_read(FILE *fd,  int *val)
35797 {
35798 X  int tval;
35799 #ifdef IS_BIG_ENDIAN
35800 X  fread(&tval,(size_t)4,(size_t)1,fd);
35801 X  *val = tval;
35802 #else
35803 X  unsigned char b[4];
35804 X
35805 X  fread((char *)&b[0],(size_t)1,(size_t)4,fd);
35806 X  *val = 0;
35807 X  *val = (int)((int)((int)(b[0]<<8)+(int)b[1]<<8)+(int)b[2]<<8)
35808 X         +(int)b[3];
35809 #endif
35810 }
35811 X
35812 void src_long4_read(FILE *fd,  long *val)
35813 {
35814 X  int tval;
35815 #ifdef IS_BIG_ENDIAN
35816 X  fread(&tval,(size_t)4,(size_t)1,fd);
35817 X  *val = tval;
35818 #else
35819 X  unsigned char b[4];
35820 X
35821 X  fread((char *)&b[0],(size_t)1,(size_t)4,fd);
35822 X  *val = 0;
35823 X  *val = (int)((int)((int)(b[0]<<8)+(int)b[1]<<8)+(int)b[2]<<8)
35824 X         +(int)b[3];
35825 #endif
35826 }
35827 X
35828 void src_long8_read(FILE *fd,  long *val)
35829 {
35830 #ifdef IS_BIG_ENDIAN
35831 X  fread((char *)val,(size_t)8,(size_t)1,fd);
35832 #else
35833 X  unsigned char b[8];
35834 X
35835 X  fread((char *)&b[0],(size_t)1,(size_t)8,fd);
35836 X  *val = 0;
35837 X  *val = (int)
35838 X    ((((((((int)b[0]<<8)+(int)b[1]<<8)+(int)b[2]<<8)+(int)b[3]<<8)+
35839 X               (int)b[4]<<8)+(int)b[5]<<8)+(int)b[6]<<8)+(int)b[7];
35840 #endif
35841 }
35842 X
35843 void src_int4_write(FILE *fd,  int val)
35844 {
35845 #ifdef IS_BIG_ENDIAN
35846 X  fwrite(&val,(size_t)4,(size_t)1,fd);
35847 #else
35848 X  unsigned char b[4];
35849 X
35850 X  b[3] = val & 255;
35851 X  b[2] = (val=val>>8)&255;
35852 X  b[1] = (val=val>>8)&255;
35853 X  b[0] = (val=val>>8)&255;
35854 X
35855 X  fwrite(b,(size_t)1,(size_t)4,fd);
35856 #endif
35857 }
35858 X
35859 void
35860 newname(char *nname, char *oname, char *suff, int maxn)
35861 {
35862 X  strncpy(nname,oname,maxn-1);
35863 X  strncat(nname,".",1);
35864 X  strncat(nname,suff,maxn-strlen(nname));
35865 }
35866 SHAR_EOF
35867 chmod 0644 list_db.c ||
35868 echo 'restore of list_db.c failed'
35869 Wc_c="`wc -c < 'list_db.c'`"
35870 test 5150 -eq "$Wc_c" ||
35871         echo 'list_db.c: original size 5150, current size' "$Wc_c"
35872 fi
35873 # ============= llgetaa.c ==============
35874 if test -f 'llgetaa.c' -a X"$1" != X"-c"; then
35875         echo 'x - skipping llgetaa.c (File already exists)'
35876 else
35877 echo 'x - extracting llgetaa.c (Text)'
35878 sed 's/^X//' << 'SHAR_EOF' > 'llgetaa.c' &&
35879 /* copyright (c) 1996, 1997, 1998, 1999 William R. Pearson and the
35880 X   U. of Virginia */
35881 X
35882 /* $Name: fa_34_26_5 $ - $Id: llgetaa.c,v 1.25 2007/01/08 15:38:46 wrp Exp $ */
35883 X
35884 /*
35885 X   Feb, 1998 - version for prss 
35886 X
35887 X   March, 2001 - modifications to support comp_thr.c: use libpos to indicate
35888 X   whether the score is shuffled==1 or unshuffled==0.  This simplifies
35889 X   complib.c and makes comp_thr.c possible
35890 X
35891 X   modified version of nxgetaa.c that generates random sequences
35892 X   for a library
35893 */
35894 X
35895 #include <stdio.h>
35896 #include <stdlib.h>
35897 #include <string.h>
35898 X
35899 #include "defs.h"
35900 #include "mm_file.h"
35901 X
35902 #include "uascii.h"
35903 #include "structs.h"
35904 X
35905 #define XTERNAL
35906 #include "upam.h"
35907 #undef XTERNAL
35908 X
35909 #define YES 1
35910 #define NO 0
35911 #define MAXLINE 512
35912 X
35913 #ifndef min
35914 #define min(x,y) ((x) > (y) ? (y) : (x))
35915 #endif
35916 X
35917 int nsfnum;     /* number of superfamily numbers */
35918 int sfnum[10];  /* superfamily number from types 0 and 5 */
35919 int nsfnum_n;
35920 int sfnum_n[10];
35921 X
35922 static int use_stdin=0;
35923 static char llibstr0[256];
35924 static char llibstr1[256];
35925 static char o_line[256];
35926 X
35927 #define NO_FORMAT 0
35928 #define FASTA_FORMAT 1
35929 #define GCG_FORMAT 2
35930 static int seq_format=NO_FORMAT;
35931 static char seq_title[200];
35932 X
35933 extern int irand(int);
35934 extern void shuffle(unsigned char *from, unsigned char *to, int n);
35935 extern void wshuffle(unsigned char *from, unsigned char *to, int n, int wsiz, int *ieven);
35936 X
35937 int
35938 getseq(char *filen, int *qascii,
35939 X       unsigned char *seq, int maxs, char *libstr,
35940 X       int n_libstr, long *sq0off)
35941 {
35942 X  FILE *fptr;
35943 X  char line[512],*bp;
35944 X  int i, j, n;
35945 X  int ic;
35946 X  int sstart, sstop, sset=0;
35947 X  int have_desc = 0;
35948 X  int desc_complete = 0;
35949 X  int llen, l_offset;
35950 X
35951 X  seq_title[0]='\0';
35952 X
35953 X  sstart = sstop = -1;
35954 #ifndef DOS
35955 X  if ((bp=strchr(filen,':'))!=NULL) {
35956 #else
35957 X  if ((bp=strchr(filen+3,':'))!=NULL) {
35958 #endif
35959 X    *bp='\0';
35960 X    if (*(bp+1)=='-') sscanf(bp+2,"%d",&sstop);
35961 X    else sscanf(bp+1,"%d-%d",&sstart,&sstop);
35962 X    sset=1;
35963 X  }
35964 X
35965 X  if (strcmp(filen,"-") && strcmp(filen,"@")) {
35966 X    if ((fptr=fopen(filen,"r"))==NULL) {
35967 X      fprintf(stderr," could not open %s\n",filen);
35968 X      return 0;
35969 X    }
35970 X  }
35971 X  else {
35972 X    fptr = stdin;
35973 X    use_stdin++;
35974 X  }
35975 X
35976 X  if (use_stdin > 1) {
35977 X    have_desc = 1;
35978 X    if ((bp=strchr(o_line,'\001'))!=NULL) *bp='\0';
35979 X    strncpy(llibstr1,o_line,sizeof(llibstr1));
35980 X    strncpy(libstr,o_line,n_libstr);
35981 X    libstr[n_libstr-1]='\0';
35982 X    l_offset = 0;
35983 X  }
35984 X
35985 X  if (sset==1) {
35986 X    filen[strlen(filen)]=':';
35987 X    if (*sq0off==1 || sstart>1) *sq0off = sstart;
35988 X  }
35989 X
35990 X  desc_complete = 0;
35991 X  n=0;
35992 X  while(fgets(line,sizeof(line),fptr)!=NULL) {
35993 X    if (line[0]=='>') {
35994 X      if (have_desc) {
35995 X       strncpy(o_line,line,sizeof(o_line));
35996 X       goto last;
35997 X      }
35998 X      l_offset = 0;
35999 X      seq_format = FASTA_FORMAT;
36000 #ifdef STAR_X
36001 X      qascii['*'] = qascii['X'];
36002 #endif
36003 X      sfnum[0] = nsfnum = 0;
36004 X
36005 X      if ((bp=(char *)strchr(line,'\n'))!=NULL) {
36006 X       *bp='\0';                               /* have newline */
36007 X       desc_complete = 1;
36008 X      }
36009 X
36010 X      if ((bp=strchr(line+1,'\001'))!=NULL) *bp='\0';
36011 X      strncpy(seq_title,line+1,sizeof(seq_title));
36012 X      strncpy(llibstr0,line+1,sizeof(llibstr0));
36013 X      if (n_libstr <= 20) {
36014 X       if ((bp=(char *)strchr(line,' '))!=NULL) *bp='\0';
36015 X      }
36016 X      strncpy(libstr,line+1,n_libstr);
36017 X      libstr[n_libstr-1]='\0';
36018 X
36019 X      if (!desc_complete) {
36020 X       while (fgets(line, sizeof(line), fptr) != NULL) {
36021 X         if (strchr(line,'\n') != NULL) {
36022 X           line[0]='>';
36023 X           break;
36024 X         }
36025 X       }
36026 X       desc_complete = 1;
36027 X      }
36028 X    }
36029 X    else if (seq_format==NO_FORMAT) {
36030 X      seq_format = GCG_FORMAT;
36031 X      qascii['*'] = qascii['X'];
36032 X      l_offset = 10;
36033 X      llen = strlen(line);
36034 X      while (strncmp(&line[llen-3],"..\n",(size_t)3) != 0) {
36035 X       if (fgets(line,sizeof(line),fptr)==NULL) return 0;
36036 X       llen = strlen(line);
36037 X      }
36038 X      if (n_libstr <= 20) {
36039 X       if ((bp=(char *)strchr(line,' '))!=NULL) *bp='\0';
36040 X       else if ((bp=(char *)strchr(line,'\n'))!=NULL) *bp='\0';
36041 X      }
36042 X      strncpy(libstr,line,n_libstr);
36043 X      libstr[n_libstr-1]='\0';
36044 X      if (fgets(line,sizeof(line),fptr)==NULL) return 0;
36045 X    }
36046 X
36047 X    if (seq_format==GCG_FORMAT && strlen(line)<l_offset) continue;
36048 X
36049 X    if (line[0]!='>'&& line[0]!=';') {
36050 X      for (i=l_offset; (n<maxs)&&
36051 X            ((ic=qascii[line[i]&AAMASK])<EL); i++)
36052 X       if (ic<NA) seq[n++]= ic;
36053 X      if (ic == ES) break;
36054 X    }
36055 X    else {
36056 X      if (have_desc) {
36057 X       strncpy(o_line,line,sizeof(o_line));
36058 X       goto last;
36059 X      }
36060 X      else {
36061 X       have_desc = 1;
36062 X      }
36063 X    }
36064 X  }
36065 X
36066 X last:
36067 X  if (n==maxs) {
36068 X    fprintf(stderr," sequence may be truncated %d %d\n",n,maxs);
36069 X    fflush(stderr);
36070 X  }
36071 X  if ((bp=strchr(libstr,'\n'))!=NULL) *bp = '\0';
36072 X  if ((bp=strchr(libstr,'\r'))!=NULL) *bp = '\0';
36073 X  seq[n]= EOSEQ;
36074 X
36075 X  if (fptr!=stdin) fclose(fptr);
36076 X
36077 X  if (sset) {
36078 X    if (sstart <= 0) sstart = 1;
36079 X    if (sstop <= 0) sstop = n;
36080 X    sstart--;
36081 X    sstop--;
36082 X    for (i=0, j=sstart; j<=sstop; i++,j++)
36083 X      seq[i] = seq[j];
36084 X    n = sstop - sstart +1;
36085 X    seq[n]=EOSEQ;
36086 X  }
36087 X
36088 X  return n;
36089 }
36090 X
36091 int
36092 gettitle(filen,title,len)
36093 X  char *filen, *title; int len;
36094 {
36095 X  FILE *fptr;
36096 X  char line[512];
36097 X  char *bp;
36098 X  int ll,sset;
36099 #ifdef WIN32
36100 X  char *strpbrk();
36101 #endif
36102 X  sset = 0;
36103 X
36104 X  if (use_stdin) {
36105 X    if (use_stdin == 1) {
36106 X      /*      use_stdin++; */
36107 X      strncpy(title,llibstr0,len);
36108 X    }
36109 X    else {
36110 X      strncpy(title,llibstr1,len);
36111 X    }
36112 X    if ((bp=strchr(title,'\001'))!=NULL) *bp='\0';
36113 X    return strlen(title);
36114 X  }
36115 X
36116 X  if ((bp=strchr(filen,':'))!=NULL) { *bp='\0'; sset=1;}
36117 X         
36118 X  if ((fptr=fopen(filen,"r"))==NULL) {
36119 X    fprintf(stderr," file %s was not found\n",filen);
36120 X    fflush(stderr);
36121 X    return 0;
36122 X  }
36123 X
36124 X  if (sset==1) filen[strlen(filen)]=':';
36125 X
36126 X  while(fgets(line,sizeof(line),fptr)!=0) {
36127 X    if (line[0]=='>'|| line[0]==';') goto found;
36128 X  }
36129 X  fclose(fptr);
36130 X  title[0]='\0';
36131 X  return 0;
36132 X
36133 X found:
36134 X  if ((bp=strchr(line,'\001'))!=NULL) *bp = 0;
36135 #ifdef WIN32
36136 X  bp = strpbrk(line,"\n\r");
36137 #else
36138 X  bp = strchr(line,'\n');
36139 #endif
36140 X  if (bp!=NULL) *bp = 0;
36141 X  strncpy(title,line,len);
36142 X  title[len-1]='\0';
36143 X  fclose(fptr);
36144 X  return strlen(title);
36145 }       
36146 X
36147 FILE *libf=NULL;
36148 X
36149 long lpos;
36150 char lline[MAXLINE];
36151 int lfflag=0;   /* flag for CRLF in EMBL CDROM files */
36152 #define LFCHAR '\015'  /* for MWC 5.5 */
36153 X
36154 int agetlib(); void aranlib();  /* pearson fasta format */
36155 X
36156 /*      the following is from fgetgb.c */
36157 X
36158 /* a file name for openlib may now include a library type suffix */
36159 /* only opens fasta format files */
36160 X
36161 static char libn_save[MAX_FN];
36162 static int ldna_save=0;
36163 static int do_shuffle;
36164 static int shuff_cnt=10;
36165 static int w_flag = 0;
36166 #ifdef DEBUG
36167 static FILE *dfile=NULL;
36168 #endif
36169 static unsigned char *aa_save;
36170 static int n1_save;
36171 static int i_even;
36172 X
36173 /* lmf_str * is used here for compatibility with the "normal" openlib,
36174 X   but is largely unnecessary */
36175 X
36176 void 
36177 set_shuffle(struct mngmsg m_msg) {
36178 X  char dfname[MAX_FN];
36179 X
36180 X  if (m_msg.shuff_wid > 0) w_flag = m_msg.shuff_wid;
36181 X  if (m_msg.shuff_max > shuff_cnt) shuff_cnt = m_msg.shuff_max;
36182 X
36183 #ifdef DEBUG
36184 X  if (m_msg.dfile[0]!='\0') {
36185 X    strncpy(dfname,m_msg.dfile,sizeof(dfname));
36186 X    strncat(dfname,"_rlib",sizeof(dfname));
36187 X    dfile = fopen(dfname,"w");
36188 X  }
36189 #endif
36190 }
36191 X
36192 struct lmf_str *
36193 openlib(char *lname, int ldnaseq, int *sascii, int quiet, struct lmf_str *m_fd)
36194 {
36195 X  char rline[10],libn[MAX_FN], *bp;
36196 X  int wcnt, ll, opnflg;
36197 X  int libtype;
36198 X  struct lmf_str *m_fptr;
36199 X
36200 X  wcnt = 0;
36201 X  libtype = 0;
36202 X
36203 X  strncpy(libn_save,lname,sizeof(libn_save));
36204 X
36205 X  /* now allocate a buffer for the opened text file */
36206 X  if ((m_fptr = calloc(1,sizeof(struct lmf_str)))==NULL) {
36207 X    fprintf(stderr," cannot allocate lmf_str (%ld) for %s\n",
36208 X           sizeof(struct lmf_str),lname);
36209 X    return NULL;
36210 X  }
36211 X
36212 X  strncpy(m_fptr->lb_name,lname,MAX_FN);
36213 X  m_fptr->lb_name[MAX_FN-1]='\0';
36214 X
36215 X  m_fptr->sascii = sascii;
36216 X  m_fptr->getlib = agetlib;
36217 X  m_fptr->ranlib = aranlib;
36218 X  m_fptr->mm_flg = 0;
36219 X
36220 X  do_shuffle = 0;
36221 X  irand(0);            /* initialize the random number generator */
36222 X
36223 X  return m_fptr;
36224 }
36225 X
36226 void
36227 closelib()
36228 {
36229 X  if (libf!=NULL) {
36230 X    fclose(libf);
36231 X    libf = NULL;
36232 X  }
36233 #ifdef DEBUG
36234 X  if (dfile) fclose(dfile);
36235 #endif
36236 }
36237 X
36238 static int ieven=0;
36239 static char *desc_save;
36240 X
36241 int
36242 agetlib(unsigned char *seq, 
36243 X       int maxs,
36244 X       char *libstr,
36245 X       int n_libstr,
36246 X       fseek_t *libpos,
36247 X       int *lcont, 
36248 X       struct lmf_str *lf_fd,
36249 X       long *l_off)
36250 {
36251 X  long sq1_off;
36252 X  char lib_desc[120];
36253 X  int i;
36254 X
36255 X  *l_off = 1;
36256 X
36257 X  if (!do_shuffle) {
36258 X    do_shuffle = 1;
36259 X    
36260 X    if ((n1_save = getseq(libn_save,lf_fd->sascii,
36261 X                         seq,maxs,lib_desc,sizeof(lib_desc),&sq1_off)) < 1)
36262 X      return n1_save;
36263 X
36264 X    strncpy(libstr,lib_desc,n_libstr);
36265 X    libstr[n_libstr-1]='\0';
36266 X
36267 X    if ((aa_save = (unsigned char *)calloc(n1_save+1,sizeof(unsigned char)))==
36268 X       NULL) fprintf(stderr," cannot allocate %d for saved sequence\n",
36269 X                      n1_save);
36270 X    memcpy((void *)aa_save,(void *)seq,n1_save);
36271 X
36272 X    if ((desc_save =
36273 X        (char *)calloc(strlen(lib_desc)+1,sizeof(char)))== NULL) {
36274 X      fprintf(stderr," cannot allocate saved desciption [%d]\n",
36275 X             strlen(lib_desc)+1);
36276 X    }
36277 X    else {
36278 X      strncpy (desc_save,lib_desc,strlen(lib_desc));
36279 X      desc_save[strlen(lib_desc)]=='\0';
36280 X    }
36281 X
36282 X    *libpos = 0;
36283 X    return n1_save;
36284 X  }
36285 X  else {       /* return a shuffled sequence - here we need a window size; */
36286 X    strncpy(libstr,desc_save,n_libstr);
36287 X    libstr[n_libstr-1]='\0';
36288 X
36289 X    if (shuff_cnt-- <= 0 ) return -1;
36290 X    if (w_flag > 0) wshuffle(aa_save,seq,n1_save,w_flag,&ieven);
36291 X    else shuffle(aa_save,seq,n1_save);
36292 X    seq[n1_save] = EOSEQ;
36293 #ifdef DEBUG
36294 X    if (dfile!=NULL) {
36295 X      fprintf(dfile,">%d\n",shuff_cnt);
36296 X      for (i=0; i<n1_save; i++) {
36297 X       if (aa[seq[i]]>0) fputc(aa[seq[i]],dfile);
36298 X       else {fprintf(stderr,"error aa0[%d]: %d %d\n",
36299 X                     i,seq[i],aa[seq[i]]);}
36300 X       if (i%60 == 59) fputc('\n',dfile);
36301 X      }
36302 X      fputc('\n',dfile);
36303 X    }
36304 #endif
36305 X    *libpos = 1;
36306 X    return n1_save;
36307 X  }
36308 }
36309 X
36310 void
36311 aranlib(char *str,
36312 X       int cnt,
36313 X       fseek_t seek,
36314 X       char *libstr,
36315 X       struct lmf_str *lm_fd)
36316 {
36317 X  char *bp;
36318 X  int ll;
36319 X
36320 X  if (use_stdin == 2) {
36321 X    if (llibstr1[0]=='>' || llibstr1[0]==';') {
36322 X      strncpy(str,llibstr1+1,cnt);
36323 X    }
36324 X    else {
36325 X      strncpy(str,llibstr1,cnt);
36326 X    }
36327 X  }
36328 X  else {
36329 X    strncpy(str,desc_save,cnt);
36330 X  }
36331 X  str[cnt-1]='\0';
36332 X  if ((bp = strchr(str,'\001'))!=NULL) *bp='\0';
36333 X  else if ((bp = strchr(str,'\n'))!=NULL) *bp='\0';
36334 X  else str[cnt-1]='\0';
36335 }
36336 X
36337 /*
36338 void
36339 revcomp(unsigned char *seq, int n, int *c_nt)
36340 {
36341 X  unsigned char tmp;
36342 X  int i, ni;
36343 X
36344 X
36345 X  for (i=0, ni = n-1; i< n/2; i++,ni--) {
36346 X    tmp = c_nt[seq[i]];
36347 X    seq[i] = c_nt[seq[ni]];
36348 X    seq[ni] = tmp;
36349 X  }
36350 X  if ((n%2)==1) {
36351 X    i = n/2;
36352 X    seq[i] = c_nt[seq[i]];
36353 X  }
36354 }
36355 */
36356 X
36357 struct lmf_str *
36358 re_openlib(struct lmf_str *om_fptr, int outtty)
36359 {
36360 X  return om_fptr;
36361 }
36362 X
36363 int re_getlib(unsigned char *aa1, int n1, int maxt3, int loff, int cont,
36364 X             int term_code, long *loffset, long *l_off,
36365 X             struct lmf_str *m_file_p)
36366 {
36367 X  *loffset = 0;
36368 X  *l_off = 1;
36369 X  return n1;
36370 }
36371 X
36372 SHAR_EOF
36373 chmod 0644 llgetaa.c ||
36374 echo 'restore of llgetaa.c failed'
36375 Wc_c="`wc -c < 'llgetaa.c'`"
36376 test 10617 -eq "$Wc_c" ||
36377         echo 'llgetaa.c: original size 10617, current size' "$Wc_c"
36378 fi
36379 # ============= m1r.aa ==============
36380 if test -f 'm1r.aa' -a X"$1" != X"-c"; then
36381         echo 'x - skipping m1r.aa (File already exists)'
36382 else
36383 echo 'x - extracting m1r.aa (Text)'
36384 sed 's/^X//' << 'SHAR_EOF' > 'm1r.aa' &&
36385 >test | 40001 90043 | mgstm1
36386 MGCEN,
36387 MIDYP,
36388 MLLAY,
36389 MLLGY
36390 SHAR_EOF
36391 chmod 0644 m1r.aa ||
36392 echo 'restore of m1r.aa failed'
36393 Wc_c="`wc -c < 'm1r.aa'`"
36394 test 56 -eq "$Wc_c" ||
36395         echo 'm1r.aa: original size 56, current size' "$Wc_c"
36396 fi
36397 # ============= m2.aa ==============
36398 if test -f 'm2.aa' -a X"$1" != X"-c"; then
36399         echo 'x - skipping m2.aa (File already exists)'
36400 else
36401 echo 'x - extracting m2.aa (Text)'
36402 sed 's/^X//' << 'SHAR_EOF' > 'm2.aa' &&
36403 >tests from mgstm1
36404 MILGYW,
36405 MLLEYT,
36406 MGDAPD,
36407 MLCYNP
36408 SHAR_EOF
36409 chmod 0644 m2.aa ||
36410 echo 'restore of m2.aa failed'
36411 Wc_c="`wc -c < 'm2.aa'`"
36412 test 50 -eq "$Wc_c" ||
36413         echo 'm2.aa: original size 50, current size' "$Wc_c"
36414 fi
36415 # ============= make_osx_univ.sh ==============
36416 if test -f 'make_osx_univ.sh' -a X"$1" != X"-c"; then
36417         echo 'x - skipping make_osx_univ.sh (File already exists)'
36418 else
36419 echo 'x - extracting make_osx_univ.sh (Text)'
36420 sed 's/^X//' << 'SHAR_EOF' > 'make_osx_univ.sh' &&
36421 #!/bin/csh
36422 X
36423 make -f Makefile.os_x all
36424 make -f Makefile.os_x install
36425 make -f Makefile.os_x clean-up
36426 X
36427 make -f Makefile.os_x86 all
36428 make -f Makefile.os_x86 install
36429 make -f Makefile.os_x86 clean-up
36430 X
36431 foreach n ( ppc/* )
36432 set f=$n:t
36433 lipo -create ppc/$f i386/$f -output bin/$f
36434 echo "Universal $f built"
36435 end
36436 echo "Done!"
36437 X
36438 SHAR_EOF
36439 chmod 0755 make_osx_univ.sh ||
36440 echo 'restore of make_osx_univ.sh failed'
36441 Wc_c="`wc -c < 'make_osx_univ.sh'`"
36442 test 312 -eq "$Wc_c" ||
36443         echo 'make_osx_univ.sh: original size 312, current size' "$Wc_c"
36444 fi
36445 # ============= map_db.1 ==============
36446 if test -f 'map_db.1' -a X"$1" != X"-c"; then
36447         echo 'x - skipping map_db.1 (File already exists)'
36448 else
36449 echo 'x - extracting map_db.1 (Text)'
36450 sed 's/^X//' << 'SHAR_EOF' > 'map_db.1' &&
36451 .TH MAP_DB "September, 1999"
36452 .SH NAME
36453 .B map_db
36454 \- read a FASTA (0), GENBANK flat file (1) PIR/VMS (5) or GCG binary
36455 (6) sequence database and produce the offsets necessary for efficient
36456 memory mapping.
36457 .SH SYNOPSIS
36458 .B map_db
36459 [-n] filename | "filename libtype"
36460 .SH DESCRIPTION
36461 .B map_db
36462 .I filename
36463 reads the sequence database in
36464 .I filename
36465 and produce a new file
36466 .I filename.xin
36467 with the offset information necessary for efficient memory mapping.
36468 .LP
36469 The programs in fasta version 32t08 can use memory mapped i/o to load
36470 sequence database files and read them efficiently.  Memory mapping is
36471 used only if a "\c
36472 .I .xin\c
36473 \&" file is available.  The "\c
36474 .I .xin\c
36475 \&" file is created by
36476 .B map_db\c
36477 \&.
36478 .LP
36479 In addition to
36480 .B map_db\c
36481 \&,
36482 .B list_db
36483 is available to display the database size, etc, and set of offsets calculated
36484 by
36485 .B map_db\c
36486 \&.
36487 .SH OPTIONS
36488 .TP
36489 \-n 
36490 Read file as DNA database.
36491 .SH BUGS
36492 .SH AUTHOR
36493 Bill Pearson
36494 .br
36495 wrp@virginia.EDU
36496 SHAR_EOF
36497 chmod 0644 map_db.1 ||
36498 echo 'restore of map_db.1 failed'
36499 Wc_c="`wc -c < 'map_db.1'`"
36500 test 948 -eq "$Wc_c" ||
36501         echo 'map_db.1: original size 948, current size' "$Wc_c"
36502 fi
36503 # ============= map_db.c ==============
36504 if test -f 'map_db.c' -a X"$1" != X"-c"; then
36505         echo 'x - skipping map_db.c (File already exists)'
36506 else
36507 echo 'x - extracting map_db.c (Text)'
36508 sed 's/^X//' << 'SHAR_EOF' > 'map_db.c' &&
36509 /* map_db.c - read a FASTA or GCG format database and generate a list
36510 X   of indices for rapid memory mapping */
36511 X
36512 /* copyright (c) 1999 William R. Pearson */
36513 X
36514 /* $Name: fa_34_26_5 $ - $Id: map_db.c,v 1.9 2005/09/27 15:32:58 wrp Exp $ */
36515 X
36516 /* input is a libtype 1,5, or 6 sequence database */
36517 /* output is a BLAST2 formatdb type index file */
36518 X
36519 /* format of the index file:
36520 X
36521 1)  map_db version number ["MP"+2 bytes]
36522 2)  number of sequences in database [4 bytes]
36523 3)  total length of database        [8 bytes]  (MP1, 4 bytes for MP0)
36524 4)  longest sequence in database    [8 bytes]  (MP1, 4 bytes for MP0)
36525 5) list of offsets to definitions  [num_seq+1] int*8 (MP1, 4 bytes for MP0)
36526 6) list of offsets to sequences    [num_seq+1] int*8 (MP1, 4 bytes for MP1)
36527 7) list of flag characters for sequences [num_seq+1]bytes
36528 X    (used for GCG binary to encode 2bit or 4 bit representation)
36529 X
36530 X    sequence files will be as defined by their format
36531 */
36532 X
36533 #include <stdio.h>
36534 #include <stdlib.h>
36535 #include <string.h>
36536 X
36537 #include <sys/types.h>
36538 #include <sys/stat.h>
36539 X
36540 #include "uascii.h"
36541 #include "ncbl2_head.h"
36542 X
36543 #define GCGBIN 6
36544 #define LASTLIB 6
36545 X
36546 int (*get_entry) ();
36547 X
36548 int a_get_ent(long *, long *);
36549 int v_get_ent(long *, long *);
36550 int gcg_get_ent(long *, long *);
36551 int gbf_get_ent(long *, long *);
36552 X
36553 void src_int4_write(FILE *, int);
36554 void src_int4_read(FILE *, int *);
36555 void src_long4_write(FILE *, long);
36556 void src_long4_read(FILE *, long *);
36557 void src_long8_write(FILE *, long);
36558 void src_long8_read(FILE *, long *);
36559 X
36560 void newname(char *nname, char *oname, char *suff, int maxn);
36561 X
36562 int (*get_ent_arr[LASTLIB+1])()={a_get_ent, gbf_get_ent, NULL, NULL, NULL,
36563 X                                v_get_ent, gcg_get_ent};
36564 X
36565 long openlib(char *, int);
36566 X
36567 static int *sascii;
36568 X
36569 main(int argc, char **argv)
36570 {
36571 X  FILE *libi;
36572 X  char lname[256];
36573 X  char iname[256];
36574 X  char format[4];
36575 X  char *bp;
36576 X
36577 X  int i;
36578 X  int nlib;    /* number of entries */
36579 X
36580 X  long max_len;        /* longest sequence */
36581 X  long tot_len;        /* total sequence length */
36582 X
36583 X  int n1;
36584 X  
36585 X  long f_size; /* file size from fstat() */
36586 X  int lib_size;        /* current space available - may be realloc'ed */
36587 X  int lib_inc;
36588 X  int lib_type; /* 1 for protein, 0 for DNA */
36589 X  int lib_aa;  /* dna=1; prot=0; */
36590 X
36591 X  /* file offsets */
36592 X  long d_pos;  /* start of description */
36593 X  long s_pos;  /* start of sequence */
36594 X  long *d_pos_arr;     /* array of description pointers */
36595 X  long *s_pos_arr;     /* array of description pointers */
36596 X
36597 X  lib_type = 0;
36598 X  lib_size = 200000;
36599 X  lib_inc  = 100000;
36600 X
36601 X  lib_aa = 1;
36602 X
36603 X  while (argc > 1 && *argv[1]=='-') {
36604 X    if (strcmp(argv[1],"-n")==0) lib_aa = 0;
36605 X    argv++;
36606 X    argc--;
36607 X  }
36608 X
36609 X  /* open the database */
36610 X  if (argc > 1) strncpy(lname, argv[1],sizeof(lname));
36611 X  else {
36612 X    fprintf(stderr," Entry library name: ");
36613 X    fgets(lname,sizeof(lname),stdin);
36614 X    if ((bp=strchr(lname,'\n'))!=NULL) *bp='\0';
36615 X  }
36616 X    
36617 X  if ((bp=strchr(lname,' '))!=NULL) {
36618 X    lib_type = atoi(bp+1);
36619 X    *bp='\0';
36620 X  }
36621 X  else lib_type = 0;
36622 X
36623 X  if (get_ent_arr[lib_type] == NULL) {
36624 X    fprintf(stderr," cannot index file %s type %d\n",lname,lib_type);
36625 X    exit(1);
36626 X  }
36627 X  
36628 X  if (lib_type == 6) lib_aa = 0;
36629 X  if (lib_type == 1) lib_aa = 0;
36630 X  
36631 X  if (lib_aa == 1) sascii = aascii;
36632 X  else sascii = nascii;
36633 X
36634 X  if ((f_size=openlib(lname,lib_type))==0) {
36635 X    fprintf(stderr," cannot open %s (type: %d)\n",lname,lib_type);
36636 X    exit(1);
36637 X  }
36638 X
36639 X  /* allocate array of description pointers */
36640 X  if ((d_pos_arr=(long *)calloc(lib_size, sizeof(long)))==NULL) {
36641 X    fprintf(stderr," cannot allocate %d for desc. array\n",lib_size);
36642 X    exit(1);
36643 X  }
36644 X  /* allocate array of sequence pointers */
36645 X  if ((s_pos_arr=(long *)calloc(lib_size, sizeof(long)))==NULL) {
36646 X    fprintf(stderr," cannot allocate %d for seq. array\n",lib_size);
36647 X    exit(1);
36648 X  }
36649 X
36650 X  /* allocate array of sequence flags */
36651 X
36652 X  nlib = 0; tot_len=0; max_len=-1;
36653 X  while ((n1=get_entry(&d_pos, &s_pos)) > 0) {
36654 X    d_pos_arr[nlib] = d_pos;
36655 X    s_pos_arr[nlib] = s_pos;
36656 X    nlib++;
36657 X    tot_len += n1;
36658 X    if (n1 > max_len) max_len = n1;
36659 X    if (nlib >= lib_size) { /* too many entries */
36660 X      lib_size += lib_inc;
36661 X      if ((d_pos_arr=(long *)realloc(d_pos_arr,lib_size*sizeof(long)))==NULL) {
36662 X       fprintf(stderr," cannot realloc allocate %d for desc.. array\n",
36663 X               lib_size);
36664 X       exit(1);
36665 X      }
36666 X      if ((s_pos_arr=(long *)realloc(s_pos_arr,lib_size*sizeof(long)))==NULL) {
36667 X       fprintf(stderr," cannot realloc allocate %d for seq. array\n",
36668 X               lib_size);
36669 X       exit(1);
36670 X      }
36671 X    }
36672 X  }
36673 X
36674 X  d_pos_arr[nlib]= d_pos;      /* put in the end of the file */
36675 X  s_pos_arr[nlib]=0;
36676 X
36677 X  /* all the information is in, write it out */
36678 X  
36679 X  newname(iname,lname,"xin",sizeof(iname));
36680 X
36681 X  if ((libi=fopen(iname,"w"))==NULL) {
36682 X    fprintf(stderr," cannot open %s for writing\n",iname);
36683 X    exit(1);
36684 X  }
36685 X
36686 X  /* write out format version */
36687 X  format[0]='M';
36688 X  format[1]='P';
36689 #ifdef BIG_LIB64
36690 X  format[2]= 1;                /* format 1 for 8-byte offsets */
36691 #else
36692 X  format[2]='\0';      /* format '\0' for original 4-byte */
36693 #endif
36694 X
36695 X  format[3]=lib_type;
36696 X  fwrite(format,4,sizeof(char),libi);
36697 X
36698 X  /* write out sequence type */
36699 X  src_int4_write(libi, lib_aa);
36700 X
36701 X  /* write out file fstat as integrity check */
36702 #ifdef BIG_LIB64
36703 X  src_long8_write(libi, f_size);
36704 #else
36705 X  src_int4_write(libi, f_size);
36706 #endif
36707 X
36708 X  /* write out num_seq */
36709 X  src_int4_write(libi, nlib);
36710 X
36711 #ifdef BIG_LIB64
36712 X  /* write out tot_len, max_len */
36713 X  src_long8_write(libi, tot_len);
36714 #else
36715 X  src_int4_write(libi, tot_len);
36716 #endif
36717 X  src_int4_write(libi, max_len);
36718 X
36719 #ifdef BIG_LIB64
36720 X  for (i=0; i<=nlib; i++) src_long8_write(libi,d_pos_arr[i]);
36721 X  for (i=0; i<=nlib; i++) src_long8_write(libi,s_pos_arr[i]);
36722 #else
36723 X  for (i=0; i<=nlib; i++) src_int4_write(libi,d_pos_arr[i]);
36724 X  for (i=0; i<=nlib; i++) src_int4_write(libi,s_pos_arr[i]);
36725 #endif
36726 X
36727 X  fclose(libi);
36728 X
36729 #ifdef BIG_LIB64
36730 X  fprintf(stderr," wrote %d sequences (tot=%ld, max=%ld) to %s\n",
36731 X         nlib,tot_len,max_len,iname);
36732 #else
36733 X  fprintf(stderr," wrote %d sequences (tot=%ld, max=%ld) to %s\n",
36734 X         nlib,tot_len,max_len,iname);
36735 #endif
36736 }
36737 X
36738 X
36739 FILE *libf=NULL;
36740 long lpos;
36741 X
36742 #define MAXLINE 4096
36743 char lline[MAXLINE+1];
36744 X
36745 long
36746 openlib(char *lname, int lib_type)
36747 {
36748 X  long f_size;
36749 X  struct stat stat_buf;
36750 X
36751 X  if (stat(lname,&stat_buf)<0) {
36752 X    fprintf(stderr," cannot stat library: %s\n",lname);
36753 X    return 0;
36754 X  }
36755 X
36756 X  if ((libf=fopen(lname,"r"))==NULL) {
36757 X    fprintf(stderr," cannot open library: %s (type: %d)\n",
36758 X           lname, lib_type);
36759 X    return 0;
36760 X  }
36761 X  
36762 X  f_size = stat_buf.st_size;
36763 X
36764 X  get_entry = get_ent_arr[lib_type];
36765 X
36766 X  lpos = ftell(libf);
36767 X  if (fgets(lline,MAXLINE,libf)==NULL) return 0;
36768 X  return f_size;
36769 }
36770 X
36771 int
36772 a_get_ent(long *d_pos, long *s_pos)
36773 {
36774 X  register char *cp;
36775 X  register int *ap, n1;
36776 X
36777 X  ap = sascii;
36778 X
36779 X  while (lline[0]!='>' && lline[0]!=';') {
36780 X    lpos = ftell(libf);
36781 X    if (fgets(lline,sizeof(lline),libf)==NULL) {
36782 X      *d_pos = lpos;
36783 X      return 0;
36784 X    }
36785 X  }
36786 X
36787 X  *d_pos = lpos;
36788 X
36789 X  /* make certain we have the end of the line */
36790 X  while (strchr((char *)lline,'\n')==NULL) {
36791 X    if (fgets(lline,sizeof(lline),libf)==NULL) break;
36792 X  }
36793 X
36794 X  *s_pos = ftell(libf);
36795 X  lline[0]='\0';
36796 X  n1 = 0;
36797 X  while (fgets(lline,sizeof(lline),libf)!=NULL) {
36798 X    if (lline[0]=='>') break;
36799 X    if (lline[0]==';') {
36800 X      if (strchr(lline,'\n')==NULL) {
36801 X       fprintf(stderr," excessive continuation\n%s",lline);
36802 X       return -1;
36803 X      }
36804 X    }
36805 X
36806 X    for (cp=lline; *cp; ) if (ap[*cp++]<NA) n1++;
36807 X    lpos = ftell(libf);
36808 X  }
36809 X  return n1;
36810 }
36811 X
36812 int
36813 v_get_ent(long *d_pos, long *s_pos)
36814 {
36815 X  register char *cp;
36816 X  register int *ap;
36817 X  int n1;
36818 X
36819 X  ap = sascii;
36820 X
36821 X  /* check for seq_id line */
36822 X  while (lline[0]!='>' && lline[0]!=';') {
36823 X    lpos = ftell(libf);
36824 X    if (fgets(lline,sizeof(lline),libf)==NULL) {
36825 X      *d_pos = lpos;
36826 X      return 0;
36827 X    }
36828 X  }
36829 X  *d_pos = lpos;
36830 X
36831 X  /* get the description line */
36832 X  if (fgets(lline,sizeof(lline),libf)==NULL) return 0;
36833 X  /* make certain we have the end of the line */
36834 X  while (strchr((char *)lline,'\n')==NULL) {
36835 X    if (fgets(lline,sizeof(lline),libf)==NULL) break;
36836 X  }
36837 X
36838 X  *s_pos = ftell(libf);
36839 X  lline[0]='\0';
36840 X  n1 = 0;
36841 X  while (fgets(lline,sizeof(lline),libf)!=NULL) {
36842 X    if (lline[0]=='>') break;
36843 X
36844 X    for (cp=lline; *cp; ) if (ap[*cp++]<NA) n1++;
36845 X    lpos = ftell(libf);
36846 X  }
36847 X  return n1;
36848 }
36849 X
36850 static char gcg_type[10];
36851 static long gcg_len;
36852 static int gcg_bton[4]={2,4,1,3};
36853 X
36854 int
36855 gcg_get_ent(long *d_pos, long *s_pos)
36856 {
36857 X  register char *cp;
36858 X  register int *ap;
36859 X  char libstr[20], dummy[20];
36860 X  char gcg_date[6];
36861 X  int r_block;
36862 X  int n1;
36863 X
36864 X  /* check for seq_id line */
36865 X  while (lline[0]!='>') {
36866 X    lpos = ftell(libf);
36867 X    if (fgets(lline,sizeof(lline),libf)==NULL) {
36868 X      *d_pos = lpos;
36869 X      return 0;
36870 X    }
36871 X  }
36872 X  *d_pos = lpos;
36873 X
36874 X  /* get the encoding/sequence length info */
36875 X
36876 X  sscanf(&lline[4],"%s %s %s %s %ld",
36877 X        libstr,gcg_date,gcg_type,dummy,&gcg_len);
36878 X
36879 X  /* get the description line */
36880 X  if (fgets(lline,MAXLINE,libf)==NULL) return;
36881 X
36882 X  *s_pos = ftell(libf);
36883 X  /* seek to the end of the sequence; +1 to jump over newline */
36884 X  if (gcg_type[0]=='2') {
36885 X    r_block = (gcg_len+3)/4;
36886 X    fseek(libf,r_block+1,SEEK_CUR);
36887 X  }
36888 X  else fseek(libf,gcg_len+1,SEEK_CUR);
36889 X
36890 X  lpos = ftell(libf);
36891 X  fgets(lline,MAXLINE,libf);
36892 X
36893 X  return gcg_len;
36894 }
36895 X
36896 int
36897 gbf_get_ent(long *d_pos, long *s_pos)
36898 {
36899 X  int n1;
36900 X  char *cp;
36901 X  register int *ap;
36902 X
36903 #if !defined(TFAST)
36904 X  ap = sascii;
36905 #else
36906 X  ap = nascii;
36907 #endif
36908 X
36909 X  while (lline[0]!='L' || lline[1]!='O' || 
36910 X        strncmp(lline,"LOCUS",5)) { /* find LOCUS */
36911 X    lpos = ftell(libf);
36912 X    if (fgets(lline,MAXLINE,libf)==NULL) return (-1);
36913 X  }
36914 X  *d_pos=lpos;
36915 X
36916 X  while (lline[0]!='O' || lline[1]!='R' ||
36917 X        strncmp(lline,"ORIGIN",6)) { /* find ORIGIN */
36918 X    if (fgets(lline,MAXLINE,libf)==NULL) return (-1);
36919 X  }
36920 X  *s_pos = ftell(libf);
36921 X
36922 X  lline[0]='\0';
36923 X  n1=0;
36924 X  while (fgets(lline,MAXLINE,libf)!=NULL) {
36925 X    if (lline[0]=='/') break;
36926 X    for (cp=lline; *cp; ) if (ap[*cp++]<NA) n1++;
36927 X  }
36928 X  lpos = ftell(libf);
36929 X  fgets(lline,MAXLINE,libf);
36930 X
36931 X  return n1;
36932 }
36933 X
36934 void src_int4_read(FILE *fd,  int *val)
36935 {
36936 #ifdef IS_BIG_ENDIAN
36937 X  fread((char *)val,(size_t)4,(size_t)1,fd);
36938 #else
36939 X  unsigned char b[4];
36940 X
36941 X  fread((char *)&b[0],(size_t)1,(size_t)4,fd);
36942 X  *val = 0;
36943 X  *val = (int)((int)((int)(b[0]<<8)+(int)b[1]<<8)+(int)b[2]<<8)
36944 X         +(int)b[3];
36945 #endif
36946 }
36947 X
36948 void src_int4_write(FILE *fd,  int val)
36949 {
36950 #ifdef IS_BIG_ENDIAN
36951 X  fwrite(&val,(size_t)4,(size_t)1,fd);
36952 #else
36953 X  unsigned char b[4];
36954 X
36955 X  b[3] = val & 255;
36956 X  b[2] = (val=val>>8)&255;
36957 X  b[1] = (val=val>>8)&255;
36958 X  b[0] = (val=val>>8)&255;
36959 X
36960 X  fwrite(b,(size_t)1,(size_t)4,fd);
36961 #endif
36962 }
36963 X
36964 void src_long8_write(FILE *fd,  long val)
36965 {
36966 #ifdef IS_BIG_ENDIAN
36967 X  fwrite(&val,(size_t)8,(size_t)1,fd);
36968 #else
36969 X  unsigned char b[8];
36970 X
36971 X  b[7] = val & 255;
36972 X  b[6] = (val=val>>8)&255;
36973 X  b[5] = (val=val>>8)&255;
36974 X  b[4] = (val=val>>8)&255;
36975 X  b[3] = (val=val>>8)&255;
36976 X  b[2] = (val=val>>8)&255;
36977 X  b[1] = (val=val>>8)&255;
36978 X  b[0] = (val=val>>8)&255;
36979 X
36980 X  fwrite(b,(size_t)1,(size_t)8,fd);
36981 #endif
36982 }
36983 X
36984 void
36985 newname(char *nname, char *oname, char *suff, int maxn)
36986 {
36987 X  strncpy(nname,oname,maxn-1);
36988 X  strncat(nname,".",1);
36989 X  strncat(nname,suff,maxn-strlen(nname));
36990 }
36991 SHAR_EOF
36992 chmod 0644 map_db.c ||
36993 echo 'restore of map_db.c failed'
36994 Wc_c="`wc -c < 'map_db.c'`"
36995 test 10852 -eq "$Wc_c" ||
36996         echo 'map_db.c: original size 10852, current size' "$Wc_c"
36997 fi
36998 # ============= mchu.aa ==============
36999 if test -f 'mchu.aa' -a X"$1" != X"-c"; then
37000         echo 'x - skipping mchu.aa (File already exists)'
37001 else
37002 echo 'x - extracting mchu.aa (Text)'
37003 sed 's/^X//' << 'SHAR_EOF' > 'mchu.aa' &&
37004 >MCHU - Calmodulin - Human, rabbit, bovine, rat, and chicken
37005 ADQLTEEQIAEFKEAFSLFDKDGDGTITTKELGTVMRSLGQNPTEAELQDMINEVDADGNGTID
37006 FPEFLTMMARKMKDTDSEEEIREAFRVFDKDGNGYISAAELRHVMTNLGEKLTDEEVDEMIREA
37007 DIDGDGQVNYEEFVQMMTAK
37008 SHAR_EOF
37009 chmod 0644 mchu.aa ||
37010 echo 'restore of mchu.aa failed'
37011 Wc_c="`wc -c < 'mchu.aa'`"
37012 test 212 -eq "$Wc_c" ||
37013         echo 'mchu.aa: original size 212, current size' "$Wc_c"
37014 fi
37015 # ============= md_10.mat ==============
37016 if test -f 'md_10.mat' -a X"$1" != X"-c"; then
37017         echo 'x - skipping md_10.mat (File already exists)'
37018 else
37019 echo 'x - extracting md_10.mat (Text)'
37020 sed 's/^X//' << 'SHAR_EOF' > 'md_10.mat' &&
37021 X   A   R   N   D   C   Q   E   G   H   I   L   K   M   F   P   S   T   W   Y   V   B   Z   X
37022 A  11 -13 -12 -11 -13 -13 -10  -8 -15 -13 -15 -14 -13 -18  -7  -5  -4 -20 -19  -6 -12 -11  -1
37023 R -12  12 -13 -18 -10  -5 -15  -9  -5 -17 -14  -2 -14 -22 -11 -10 -12  -9 -17 -17 -15 -10  -1
37024 N -12 -13  13  -3 -14 -11 -12 -11  -5 -13 -19  -6 -15 -20 -17  -4  -7 -21 -12 -17   5 -11  -1
37025 D -11 -18  -3  12 -20 -13  -2  -9 -10 -19 -21 -15 -18 -23 -18 -12 -14 -24 -13 -15   5  -7  -1
37026 C -13 -10 -14 -20  17 -19 -22 -12 -12 -18 -16 -21 -15 -11 -18  -7 -14  -9  -7 -12 -17 -21  -1
37027 Q -13  -5 -11 -13 -19  13  -5 -15  -3 -19 -12  -6 -14 -22  -8 -13 -13 -17 -16 -17 -12   4  -1
37028 E -10 -15 -12  -2 -22  -5  12  -9 -15 -19 -20  -8 -17 -23 -17 -15 -15 -20 -21 -14  -7   3  -1
37029 G  -8  -9 -11  -9 -12 -16  -9  11 -16 -21 -21 -15 -18 -22 -16  -7 -14 -13 -21 -13 -10 -13  -1
37030 H -16  -5  -5 -10 -12  -3 -15 -16  16 -17 -13 -13 -15 -14 -10 -11 -13 -20  -3 -19  -7  -9  -1
37031 I -13 -17 -14 -19 -17 -20 -19 -21 -18  12  -7 -17  -4 -11 -19 -14  -7 -20 -15  -1 -16 -19  -1
37032 L -15 -14 -19 -21 -16 -12 -20 -21 -13  -7  10 -18  -4  -6 -10 -13 -15 -13 -16  -8 -20 -16  -1
37033 K -14  -2  -6 -15 -21  -6  -8 -15 -13 -17 -18  12 -12 -24 -17 -13 -10 -19 -20 -18 -11  -7  -1
37034 M -13 -14 -15 -18 -15 -14 -18 -19 -15  -4  -4 -12  16 -14 -17 -15  -7 -16 -18  -5 -16 -16  -1
37035 F -18 -22 -19 -22 -11 -22 -23 -22 -14 -11  -6 -23 -14  14 -17 -11 -18 -13  -3 -12 -21 -22  -1
37036 P  -7 -12 -17 -18 -18  -8 -17 -16 -10 -19 -10 -16 -17 -17  13  -6  -9 -22 -20 -16 -17 -13  -1
37037 S  -5 -10  -4 -12  -7 -13 -15  -7 -11 -14 -13 -13 -15 -11  -6  11  -4 -15 -12 -14  -8 -14  -1
37038 T  -4 -12  -7 -14 -14 -13 -15 -14 -13  -7 -16 -10  -7 -19  -9  -4  12 -19 -17 -10 -10 -14  -1
37039 W -21  -9 -21 -21 -10 -17 -21 -13 -21 -21 -13 -21 -17 -13 -21 -15 -18  18 -12 -16 -21 -19  -1
37040 Y -20 -17 -12 -13  -7 -16 -21 -20  -3 -15 -16 -20 -17  -3 -20 -12 -17 -12  15 -18 -13 -19  -1
37041 V  -6 -17 -17 -15 -12 -17 -14 -13 -19  -1  -8 -18  -5 -12 -16 -14 -10 -16 -18  11 -16 -15  -1
37042 B -12 -15   5   5 -17 -12  -7 -10  -7 -16 -20 -11 -17 -21 -17  -8 -10 -22 -13 -16  13  -9  -1
37043 Z -16 -18 -17  -8 -32   1   9 -17 -17 -29 -26 -11 -24 -34 -21 -21 -21 -29 -29 -22  -9  13  -1
37044 XX  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1
37045 SHAR_EOF
37046 chmod 0644 md_10.mat ||
37047 echo 'restore of md_10.mat failed'
37048 Wc_c="`wc -c < 'md_10.mat'`"
37049 test 2255 -eq "$Wc_c" ||
37050         echo 'md_10.mat: original size 2255, current size' "$Wc_c"
37051 fi
37052 # ============= md_20.mat ==============
37053 if test -f 'md_20.mat' -a X"$1" != X"-c"; then
37054         echo 'x - skipping md_20.mat (File already exists)'
37055 else
37056 echo 'x - extracting md_20.mat (Text)'
37057 sed 's/^X//' << 'SHAR_EOF' > 'md_20.mat' &&
37058 X    A   R   N   D   C   Q   E   G   H   I   L   K   M   F   P   S   T   W   Y   V   B   Z   X
37059 A  10 -10  -9  -8 -10 -10  -7  -5 -12 -10 -12 -11  -9 -15  -5  -2  -1 -17 -16  -3  -9  -8  -1
37060 R -10  12 -10 -14  -7  -3 -11  -6  -3 -14 -12   0 -11 -18  -9  -7  -9  -6 -14 -14 -12  -7  -1
37061 N  -9 -10  13  -1 -11  -8  -9  -8  -2 -11 -15  -4 -12 -16 -13  -1  -4 -18  -9 -14   6  -8  -1
37062 D  -8 -14  -1  12 -16  -9   1  -6  -7 -16 -18 -11 -15 -20 -15  -9 -11 -20 -11 -12   6  -4  -1
37063 C -10  -7 -11 -16  17 -16 -19  -9  -9 -14 -13 -17 -12  -8 -14  -4 -11  -7  -4 -10 -14 -17  -1
37064 Q -10  -3  -8  -9 -16  13  -3 -12   0 -16  -9  -3 -11 -18  -5 -10 -10 -14 -12 -14  -9   5  -1
37065 E  -7 -11  -9   1 -19  -3  11  -7 -12 -16 -17  -5 -14 -20 -14 -12 -12 -17 -18 -11  -4   4  -1
37066 G  -5  -6  -8  -6  -9 -12  -7  11 -13 -17 -18 -12 -15 -19 -12  -5 -11 -10 -17 -11  -7  -9  -1
37067 H -12  -3  -2  -7  -9   0 -12 -13  15 -14 -10  -9 -12 -11  -7  -8 -10 -16   0 -15  -4  -6  -1
37068 I -10 -14 -11 -16 -14 -16 -16 -17 -14  12  -4 -14  -1  -8 -15 -11  -4 -16 -12   2 -13 -16  -1
37069 L -12 -11 -15 -18 -13  -9 -17 -18 -10  -4  10 -15  -2  -4  -7 -10 -12 -10 -13  -5 -17 -13  -1
37070 K -11   0  -4 -12 -17  -3  -5 -12  -9 -14 -15  12  -9 -21 -13 -10  -7 -16 -17 -15  -8  -4  -1
37071 M  -9 -11 -12 -15 -12 -11 -15 -16 -12  -1  -2  -9  15 -10 -14 -12  -4 -13 -14  -3 -13 -13  -1
37072 F -15 -19 -16 -19  -8 -18 -20 -19 -11  -8  -4 -19 -10  13 -14  -8 -15 -10   0  -9 -17 -19  -1
37073 P  -5  -9 -13 -15 -14  -5 -14 -12  -7 -15  -7 -13 -14 -14  12  -3  -7 -18 -16 -13 -14 -10  -1
37074 S  -2  -8  -1  -9  -4 -10 -12  -5  -8 -11 -10 -10 -12  -8  -3  10  -1 -12  -9 -11  -5 -11  -1
37075 T  -1  -9  -4 -11 -10 -10 -12 -11 -10  -4 -12  -7  -4 -15  -7  -1  11 -16 -14  -7  -7 -11  -1
37076 W -17  -6 -18 -18  -7 -14 -18 -10 -17 -17 -10 -17 -14 -10 -18 -12 -15  18  -9 -13 -18 -16  -1
37077 Y -16 -14  -9 -11  -4 -12 -18 -17   0 -12 -12 -17 -14   0 -16  -9 -13  -9  14 -15 -10 -15  -1
37078 V  -3 -14 -14 -12  -9 -14 -11 -11 -15   2  -5 -15  -2  -9 -13 -11  -7 -13 -14  11 -13 -12  -1
37079 B  -9 -12   6   6 -14  -9  -4  -7  -4 -13 -17  -8 -13 -18 -14  -5  -7 -19 -10 -13  12  -6  -1
37080 Z -12 -13 -13  -4 -27   4  10 -13 -12 -24 -21  -6 -20 -29 -17 -17 -17 -24 -24 -18  -6  12  -1
37081 XX  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1
37082 SHAR_EOF
37083 chmod 0644 md_20.mat ||
37084 echo 'restore of md_20.mat failed'
37085 Wc_c="`wc -c < 'md_20.mat'`"
37086 test 2256 -eq "$Wc_c" ||
37087         echo 'md_20.mat: original size 2256, current size' "$Wc_c"
37088 fi
37089 # ============= md_40.mat ==============
37090 if test -f 'md_40.mat' -a X"$1" != X"-c"; then
37091         echo 'x - skipping md_40.mat (File already exists)'
37092 else
37093 echo 'x - extracting md_40.mat (Text)'
37094 sed 's/^X//' << 'SHAR_EOF' > 'md_40.mat' &&
37095 X   A   R   N   D   C   Q   E   G   H   I   L   K   M   F   P   S   T   W   Y   V   B   Z   X
37096 A   9  -7  -6  -6  -7  -7  -5  -3 -10  -6  -9  -8  -7 -11  -2   0   1 -13 -12  -1  -6  -6  -1
37097 R  -7  11  -6 -10  -5   0  -8  -4   0 -10  -9   3  -8 -14  -6  -5  -6  -4 -10 -11  -8  -4  -1
37098 N  -6  -6  12   2  -8  -5  -5  -5   0  -8 -12  -1  -9 -13  -9   1  -2 -16  -6 -10   7  -5  -1
37099 D  -6 -10   2  11 -13  -6   3  -4  -5 -12 -15  -8 -11 -16 -11  -6  -7 -15  -8  -9   6  -1  -1
37100 C  -6  -5  -8 -13  16 -12 -15  -7  -6 -11 -11 -13  -9  -6 -11  -2  -7  -4  -2  -7 -11 -13  -1
37101 Q  -7   0  -5  -6 -12  12   0  -9   2 -13  -6   0  -8 -14  -3  -7  -7 -11  -9 -11  -6   6  -1
37102 E  -5  -8  -5   3 -15   0  10  -4  -8 -12 -13  -3 -11 -16 -10  -8  -8 -13 -14  -8  -1   5  -1
37103 G  -3  -4  -5  -4  -7  -9  -4  10 -10 -13 -14  -9 -12 -15  -9  -2  -8  -7 -15  -8  -5  -7  -1
37104 H -10   0   0  -5  -6   2  -8 -10  14 -11  -7  -6  -9  -7  -4  -6  -7 -12   2 -12  -2  -3  -1
37105 I  -6 -10  -8 -12 -11 -13 -12 -13 -11  11  -1 -11   1  -6 -11  -8  -2 -12  -9   4 -10 -12  -1
37106 L  -9  -9 -12 -14 -11  -6 -13 -14  -7  -1   9 -12   1  -1  -5  -7  -9  -7  -9  -2 -13 -10  -1
37107 K  -8   3  -1  -8 -13   0  -3  -9  -6 -11 -12  11  -7 -18 -10  -7  -5 -12 -13 -12  -5  -2  -1
37108 M  -7  -8  -9 -11  -8  -8 -11 -12  -9   1   1  -7  14  -7 -10  -8  -2 -11 -11   0 -10 -10  -1
37109 F -11 -14 -12 -16  -6 -14 -16 -15  -7  -6  -1 -17  -7  13 -11  -5 -11  -7   2  -6 -14 -15  -1
37110 P  -2  -6  -9 -12 -11  -3 -10  -9  -4 -11  -5 -10 -10 -11  12  -1  -4 -14 -12  -9 -11  -7  -1
37111 S   0  -5   1  -6  -2  -7  -8  -2  -6  -8  -7  -7  -8  -5  -1   9   1 -10  -7  -7  -3  -8  -1
37112 T   1  -6  -2  -7  -7  -7  -8  -8  -7  -2  -9  -5  -2 -11  -4   1  10 -14 -10  -4  -5  -8  -1
37113 W -14  -4 -17 -15  -4 -12 -13  -7 -11 -12  -7 -13 -11  -7 -14 -10 -14  18  -6 -11 -16 -12  -1
37114 Y -12  -9  -6  -8  -2  -9 -14 -14   2  -9  -9 -13 -11   2 -12  -7 -11  -6  14 -11  -7 -11  -1
37115 V  -1 -11 -10  -9  -7 -11  -8  -8 -12   4  -2 -12   0  -6 -10  -7  -4 -10 -11  10 -10  -9  -1
37116 B  -6  -8   7   6 -11  -6  -1  -5  -2 -10 -13  -5 -10 -14 -10  -3  -5 -16  -7 -10  11  -3  -1
37117 Z  -8  -8  -8   0 -21   6  10  -9  -7 -18 -16  -3 -15 -23 -12 -12 -12 -19 -18 -14  -3  11  -1
37118 XX  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1
37119 SHAR_EOF
37120 chmod 0644 md_40.mat ||
37121 echo 'restore of md_40.mat failed'
37122 Wc_c="`wc -c < 'md_40.mat'`"
37123 test 2255 -eq "$Wc_c" ||
37124         echo 'md_40.mat: original size 2255, current size' "$Wc_c"
37125 fi
37126 # ============= mgstm1.aa ==============
37127 if test -f 'mgstm1.aa' -a X"$1" != X"-c"; then
37128         echo 'x - skipping mgstm1.aa (File already exists)'
37129 else
37130 echo 'x - extracting mgstm1.aa (Text)'
37131 sed 's/^X//' << 'SHAR_EOF' > 'mgstm1.aa' &&
37132 >GT8.7 | 266 40001 90043 | transl. of pa875.con, 19 to 675
37133 MPMILGYWNVRGLTHPIRMLLEYTDSSYDEKR
37134 YTMGDAPDFDRSQWLNEKFKLGLDFPNLPYLI
37135 DGSHKITQSNAILRYLARKHHLDGETEEERIR
37136 ADIVENQVMDTRMQLIMLCYNPDFEKQKPEFL
37137 KTIPEKMKLYSEFLGKRPWFAGDKVTYVDFLA
37138 YDILDQYRMFEPKCLDAFPNLRDFLARFEGLK
37139 KISAYMKSSRYIATPIFSKMAHWSNK
37140 SHAR_EOF
37141 chmod 0644 mgstm1.aa ||
37142 echo 'restore of mgstm1.aa failed'
37143 Wc_c="`wc -c < 'mgstm1.aa'`"
37144 test 284 -eq "$Wc_c" ||
37145         echo 'mgstm1.aa: original size 284, current size' "$Wc_c"
37146 fi
37147 # ============= mgstm1.aaa ==============
37148 if test -f 'mgstm1.aaa' -a X"$1" != X"-c"; then
37149         echo 'x - skipping mgstm1.aaa (File already exists)'
37150 else
37151 echo 'x - extracting mgstm1.aaa (Text)'
37152 sed 's/^X//' << 'SHAR_EOF' > 'mgstm1.aaa' &&
37153 >GT8.7 | 266 40001 90043 | transl. of pa875.con, 19 to 675
37154 MPMILGY@WNVRGLT#HPIRMLLEY@T#DS*S*Y@DEKR
37155 Y@T#MGDAPDFDRS*QWLNEKFKLGLDFPNLPY@LI
37156 DGS*HKIT#QSNAILRY@LARKHHLDGET#EEERIR
37157 ADIVENQVMDT#RMQLIMLCY@NPDFEKQKPEFL
37158 KT#IPEKMKLY@SEFLGKRPWFAGDKVT#Y@VDFLA
37159 Y@DILDQY@RMFEPKCLDAFPNLRDFLARFEGLK
37160 KISAY@MKSSRY@IAT#PIFSKMAHWSNK
37161 SHAR_EOF
37162 chmod 0644 mgstm1.aaa ||
37163 echo 'restore of mgstm1.aaa failed'
37164 Wc_c="`wc -c < 'mgstm1.aaa'`"
37165 test 310 -eq "$Wc_c" ||
37166         echo 'mgstm1.aaa: original size 310, current size' "$Wc_c"
37167 fi
37168 # ============= mgstm1.e05 ==============
37169 if test -f 'mgstm1.e05' -a X"$1" != X"-c"; then
37170         echo 'x - skipping mgstm1.e05 (File already exists)'
37171 else
37172 echo 'x - extracting mgstm1.e05 (Text)'
37173 sed 's/^X//' << 'SHAR_EOF' > 'mgstm1.e05' &&
37174 >pGT875 | 266 with an average of 5% of residues modified by mutr.
37175 GCTGAAGCCTAGTTTGAGAAGACCACCAGCACCACCACCATGCCTATGATATGGGATACTG
37176 GAAAGTCCGCGGACTGACACACCCGATCCGCATGCTCCTGGAATACACAGACCCAAGTTA
37177 TGATGAGAAGAGATACACTATGGGTGACGGCTCCCGACTTTGACAGACAGTGGCTGA
37178 ATGAGAAGNTTCAAGCTGGGCCTGGAATTTCCCTAATCTGCCTTACTTGATCGATGGATCA
37179 CACAAGATCACCCAGAGAATGCCATCCTGCGCTACCTGGCCACAAAGCCCACCTGGAGGA
37180 GATGACAGAGGAGGAGAGGATCCGTGCAGACATTGTGGAGAACCAGATAGCATGGAAACC
37181 CGCTGCAGCNNNNCATGCTCTCGTTACAACCTTGACTTTGAGAAGCAGAAGCCAGAGTTC
37182 TTGAAGACCATCCCTGAGAAAATGAGCTCTACTCTGAGTTCCTGGGATGCAAGAGGCCATGGT
37183 TTGCATGGGACAAGTGTCACCTATGTGGATTTCTTTGCTTATGACATTCTTGACCAGTAC
37184 CGTATGTTTGAGCCAAGTGCCTGGACGCCTTCCCAAACCTGAGGTGACTTCCTGGCCCGC
37185 TTCGAGGGCCTCAAGAAGATCTCTGCTCTACATGAAGAGTAGCCGGTACATCGGCACAGC
37186 TCATATTTACAAAGATGGCCCACTGGAGTAACAAGCAGGCCCTTGCTACACGGCACTCAC
37187 TAGGAGGACCTGTCCNNACTGGTGGCTCCTGCAGTCCCTGTGTGGGGACAAGCACCCTGG
37188 CCTTCTGCACTGTGGCTCCTGGTTCCTCTCCTCCCGCTCCCTTCTGCAGTTGGTCAGCCC
37189 CATCTCCTCACCCTCTTCCCAGTCAAGGCCACACGCCTTCATTCGTCCCCGTCTTCTTTC
37190 ACATGGCCTCCTTCTTCGATTGGCTCCCTGACCCACACCTCACAGCCCGTTTCTGCGAAC
37191 TGAGGTCTGTCTGAACTCACGCTTCCTAGAATTACCCCGATGGTCAACCACTATCTTAGT
37192 GCTAGCCCTGCCCTAGAGTTACCCGAAGTCAATACTTGAAGTGCCAGCCTGCTTCCTGGT
37193 GGTAGTAGCCTCCCCAGGTCGGTCTCGTCTACAATAAAGTCATGAAACACACT
37194 SHAR_EOF
37195 chmod 0644 mgstm1.e05 ||
37196 echo 'restore of mgstm1.e05 failed'
37197 Wc_c="`wc -c < 'mgstm1.e05'`"
37198 test 1220 -eq "$Wc_c" ||
37199         echo 'mgstm1.e05: original size 1220, current size' "$Wc_c"
37200 fi
37201 # ============= mgstm1.eeq ==============
37202 if test -f 'mgstm1.eeq' -a X"$1" != X"-c"; then
37203         echo 'x - skipping mgstm1.eeq (File already exists)'
37204 else
37205 echo 'x - extracting mgstm1.eeq (Text)'
37206 sed 's/^X//' << 'SHAR_EOF' > 'mgstm1.eeq' &&
37207 >mgstm1 | 266
37208 ATGCCTATGATACTGGATACTGGAACGTCCGCGGACTGACACACCCGATCCGCATGCTC
37209 CTGGAATACACAGACTCAAGCTATAGATGAGAAGAGATACACCATGGGTGACGCTCCCGAC
37210 TTTGACAGAAGCCAGTGGCTGAAATGAGAAGTTCAAGCCTGGGCCTGGACTTTCCCAATCT
37211 GCCTTACTTATCGATGGATCACACAAGATCACCCAGAGCAATGCCATCCTGCGCTACCT
37212 TGCCCGAAAGCACCACCTGGATGGAGAGACAGAGGAGGAGAGGACCGTGCAGACATTGT
37213 GGAGAAGGCAGGTCATGGACACCCGCATGCAGCTCATCATGCTCTGTTACAACCCTGACTT
37214 TGAGAAGCAGAAGCCAGAGTTCTTGAAGACCATCCCTGAGAAAATGAAGCTCTACTCTGA
37215 GTTCCTGGCAAGAGGCCATGGTTTTGCAGGGGACAAGGTCACCTATGTGGATTTCCTTG
37216 CTTATGACATTCTTGACCAGTACCGTTGTTTGAGCCCAAGTGCCTGGACGCCTTCCCAA
37217 ACCTGAGGGACTTCCTTTGGCCCGCTTCGAGGGCCTCAAGAAGATCTCTGCCTACATGAAGA
37218 GTAGCCGCTACATCGCAACACCTATATTTTCAAAGATCCCACTGGAGTAACAAGTAGG
37219 CCCTTGCTACACGGGCACACTCACTAGGAGGACCTGTCCACACTGGGGATCCTGCAGGCCCT
37220 GGGTGGGGACAGCACCCTGGCCTTCACTGTGGCTCCTGGTTCTCTCTCCTTCCCGCT
37221 CCCTTCTGCAGCTTGTTTGTCAGCCCCATCTCCTCACCCTCTTCCCAGTCAAGTCCACACAGC
37222 CTTCATTCTCCCCAGTTTCTTTCACATGGCCCCTTCTTCTTGGCTCCTGACCCAACCT
37223 CACAGCCCGTTTCTGCGAATGAGGTCTGTCCTGAACTCACGCTTCCTAGAATTACCCCG
37224 ATGGTCAACACTATCTTAGTGCTAGCACCTCCCTAGAGTTACCCCGAAGTCAATACTTGAG
37225 TGCCAGCCTGTTCCTGGTGGAGTAGCCTCCCCAGGTCTGTCTCGTCTACAATAAAGTCTGC
37226 AAACACACTT
37227 SHAR_EOF
37228 chmod 0644 mgstm1.eeq ||
37229 echo 'restore of mgstm1.eeq failed'
37230 Wc_c="`wc -c < 'mgstm1.eeq'`"
37231 test 1122 -eq "$Wc_c" ||
37232         echo 'mgstm1.eeq: original size 1122, current size' "$Wc_c"
37233 fi
37234 # ============= mgstm1.esq ==============
37235 if test -f 'mgstm1.esq' -a X"$1" != X"-c"; then
37236         echo 'x - skipping mgstm1.esq (File already exists)'
37237 else
37238 echo 'x - extracting mgstm1.esq (Text)'
37239 sed 's/^X//' << 'SHAR_EOF' > 'mgstm1.esq' &&
37240 >mgstm1e 
37241 ATGCCTATGATACTGGGATACTGGGTCCGCGGACTGACACACCCGATCCGCATGCTC
37242 CTGGAATACACAGACTCAAGCTATGATGAGAAGAGATACACCATGGGTGACGCTCCCGAC
37243 TTTGACAGAAGCCAGTGGCTGAAATGAGAAGTTCAAGCTGGGCCTGGACTTTCCCAATCT
37244 GCCTTACTTGATCGATGGATCACACAAGATCACCCAGAGCAATGCCATCCTGCGCTACCT
37245 TGCCCGAAAGCACCACCTGGATGGAGAGACAGAGGAGGAGAGGATCCGTGCAGACATTGT
37246 GGAGAACCAGGTCATGGACACCCGCATGCAGCTCATCATGCTCTGTTACAACCCTGACTT
37247 TGAGAAGCAGAAGCCAGAGTTCTTGAAGACCATCCCTGAGAAAATGAAGCTCTACTCTGA
37248 GTTCCTGGGCAAGAGGCCATGGTTTTGCAGGGGACAAGGTCACCTATGTGGATTTCCTTG
37249 CTTATGACATTCTTGACCAGTACCGTATGTTTGAGCCCAAGTGCCTGGACGCCTTCCCAA
37250 ACCTGAGGGACTTCCTGGCCCGCTTCGAGGGCCTCAAGAAGATCTCTGCCTACATGAAGA
37251 GTAGCCGCTACATCGCAACACCTATATTTTCAAAGATGGCCCACTGGAGTAACAAGTAGG
37252 CCCTTGCTACACGGGCACTCACTAGGAGGACCTGTCCACACTGGGGATCCTGCAGGCCCT
37253 GGGTGGGGACAGCACCCTGGCCTTCTGCACTGTGGCTCCTGGTTCTCTCTCCTTCCCGCT
37254 CCCTTCTGCAGCTTGGTCAGCCCCATCTCCTCACCCTCTTCCCAGTCAAGTCCACACAGC
37255 CTTCATTCTCCCCAGTTTCTTTCACATGGCCCCTTCTTCATTGGCTCCCTGACCCAACCT
37256 CACAGCCCGTTTCTGCGAACTGAGGTCTGTCCTGAACTCACGCTTCCTAGAATTACCCCG
37257 ATGGTCAACACTATCTTAGTGCTAGCCCTCCCTAGAGTTACCCCGAAGTCAATACTTGAG
37258 TGCCAGCCTGTTCCTGGTGGAGTAGCCTCCCCAGGTCTGTCTCGTCTACAATAAAGTCTG
37259 AAACACACTT
37260 SHAR_EOF
37261 chmod 0644 mgstm1.esq ||
37262 echo 'restore of mgstm1.esq failed'
37263 Wc_c="`wc -c < 'mgstm1.esq'`"
37264 test 1116 -eq "$Wc_c" ||
37265         echo 'mgstm1.esq: original size 1116, current size' "$Wc_c"
37266 fi
37267 # ============= mgstm1.gcg ==============
37268 if test -f 'mgstm1.gcg' -a X"$1" != X"-c"; then
37269         echo 'x - skipping mgstm1.gcg (File already exists)'
37270 else
37271 echo 'x - extracting mgstm1.gcg (Text)'
37272 sed 's/^X//' << 'SHAR_EOF' > 'mgstm1.gcg' &&
37273 GT8.7 transl. of pa875.con, 19 to 675
37274 X    gt87  Length: 217  July 31, 1996 19:51  Type: P  Check: 9358  ..
37275 X
37276 X       1  PMILGYWNVR GLTHPIRMLL EYTDSSYDEK RYTMGDAPDF DRSQWLNEKF 
37277 X
37278 X      51  KLGLDFPNLP YLIDGSHKIT QSNAILRYLA RKHHLDGETE EERIRADIVE 
37279 X
37280 X     101  NQVMDTRMQL IMLCYNPDFE KQKPEFLKTI PEKMKLYSEF LGKRPWFAGD 
37281 X
37282 X     151  KVTYVDFLAY DILDQYRMFE PKCLDAFPNL RDFLARFEGL KKISAYMKSS 
37283 X
37284 X     201  RYIATPIFSK MAHWSNK
37285 X
37286 SHAR_EOF
37287 chmod 0644 mgstm1.gcg ||
37288 echo 'restore of mgstm1.gcg failed'
37289 Wc_c="`wc -c < 'mgstm1.gcg'`"
37290 test 406 -eq "$Wc_c" ||
37291         echo 'mgstm1.gcg: original size 406, current size' "$Wc_c"
37292 fi
37293 # ============= mgstm1.lc ==============
37294 if test -f 'mgstm1.lc' -a X"$1" != X"-c"; then
37295         echo 'x - skipping mgstm1.lc (File already exists)'
37296 else
37297 echo 'x - extracting mgstm1.lc (Text)'
37298 sed 's/^X//' << 'SHAR_EOF' > 'mgstm1.lc' &&
37299 >GT8.7 | 40001 ! 90043 | transl. of pa875.con, 19 to 675
37300 MPMILGYWNVRGLTHPIRMLLEYTDSSYDEKR
37301 ytmgdapdfdrsqwlnekfklgldfpnlpyli
37302 DGSHKITQSNAILRYLARKHHLDGETEEERIR
37303 adivenqvmdtrmqlimlcynpdfekqkpefl
37304 KTIPEKMKLYSEFLGKRPWFAGDKVTYVDFLA
37305 ydildqyrmfepkcldafpnlrdflarfeglk
37306 KISAYMKSSRYIATPIFSKMAHWSNK
37307 SHAR_EOF
37308 chmod 0644 mgstm1.lc ||
37309 echo 'restore of mgstm1.lc failed'
37310 Wc_c="`wc -c < 'mgstm1.lc'`"
37311 test 282 -eq "$Wc_c" ||
37312         echo 'mgstm1.lc: original size 282, current size' "$Wc_c"
37313 fi
37314 # ============= mgstm1.nt ==============
37315 if test -f 'mgstm1.nt' -a X"$1" != X"-c"; then
37316         echo 'x - skipping mgstm1.nt (File already exists)'
37317 else
37318 echo 'x - extracting mgstm1.nt (Text)'
37319 sed 's/^X//' << 'SHAR_EOF' > 'mgstm1.nt' &&
37320 >pGT875 
37321 ATGCCTATGATACTGGGATACTGGAACGTCCGCGGACTGACACACCCGATCCGCATGCTC
37322 CTGGAATACACAGACTCAAGCTATGATGAGAAGAGATACACCATGGGTGACGCTCCCGAC
37323 TTTGACAGAAGCCAGTGGCTGAATGAGAAGTTCAAGCTGGGCCTGGACTTTCCCAATCTG
37324 CCTTACTTGATCGATGGATCACACAAGATCACCCAGAGCAATGCCATCCTGCGCTACCTT
37325 GCCCGAAAGCACCACCTGGATGGAGAGACAGAGGAGGAGAGGATCCGTGCAGACATTGTG
37326 GAGAACCAGGTCATGGACACCCGCATGCAGCTCATCATGCTCTGTTACAACCCTGACTTT
37327 GAGAAGCAGAAGCCAGAGTTCTTGAAGACCATCCCTGAGAAAATGAAGCTCTACTCTGAG
37328 TTCCTGGGCAAGAGGCCATGGTTTGCAGGGGACAAGGTCACCTATGTGGATTTCCTTGCT
37329 TATGACATTCTTGACCAGTACCGTATGTTTGAGCCCAAGTGCCTGGACGCCTTCCCAAAC
37330 CTGAGGGACTTCCTGGCCCGCTTCGAGGGCCTCAAGAAGATCTCTGCCTACATGAAGAGT
37331 AGCCGCTACATCGCAACACCTATATTTTCAAAGATGGCCCACTGGAGTAACAAGTAG
37332 SHAR_EOF
37333 chmod 0644 mgstm1.nt ||
37334 echo 'restore of mgstm1.nt failed'
37335 Wc_c="`wc -c < 'mgstm1.nt'`"
37336 test 677 -eq "$Wc_c" ||
37337         echo 'mgstm1.nt: original size 677, current size' "$Wc_c"
37338 fi
37339 # ============= mgstm1.nts ==============
37340 if test -f 'mgstm1.nts' -a X"$1" != X"-c"; then
37341         echo 'x - skipping mgstm1.nts (File already exists)'
37342 else
37343 echo 'x - extracting mgstm1.nts (Text)'
37344 sed 's/^X//' << 'SHAR_EOF' > 'mgstm1.nts' &&
37345 >mgstm1
37346 GCACCATGCCTATGAT,
37347 GATACACCA,
37348 CCATCCTGCGCTACCTTGCC,
37349 aaggtcacctatgtggatttccttgcttat,
37350 CCTGTCCACACTGGG,
37351 TCAAGTCCACACAGCC,
37352 TCACGCTTCCTA,
37353 CAATACTTGAGTGCCAGCC
37354 SHAR_EOF
37355 chmod 0644 mgstm1.nts ||
37356 echo 'restore of mgstm1.nts failed'
37357 Wc_c="`wc -c < 'mgstm1.nts'`"
37358 test 160 -eq "$Wc_c" ||
37359         echo 'mgstm1.nts: original size 160, current size' "$Wc_c"
37360 fi
37361 # ============= mgstm1.raa ==============
37362 if test -f 'mgstm1.raa' -a X"$1" != X"-c"; then
37363         echo 'x - skipping mgstm1.raa (File already exists)'
37364 else
37365 echo 'x - extracting mgstm1.raa (Text)'
37366 sed 's/^X//' << 'SHAR_EOF' > 'mgstm1.raa' &&
37367 >mgstm1.aa shuffled
37368 LEGLPLKPCK RPQDRFSEDR VILFESFTYG FILAAWNMGY NEAEDMDRSH YLLTKELPKS
37369 YGGRRYYAPD FTYLFLILRN PPVKRAAPDR GNTMLQIFMA FLDDQYVMQD AFLPIGDGLK
37370 DKPMRSNMKY ITHNVYIDED IVRCKWIFAD EMSTPLLLWL MHKQKPGHRF LEKSWSHTRR
37371 EEEYNSIIDL KKSYKYLKNM AELKITSQTI FFDKDAE
37372 SHAR_EOF
37373 chmod 0644 mgstm1.raa ||
37374 echo 'restore of mgstm1.raa failed'
37375 Wc_c="`wc -c < 'mgstm1.raa'`"
37376 test 259 -eq "$Wc_c" ||
37377         echo 'mgstm1.raa: original size 259, current size' "$Wc_c"
37378 fi
37379 # ============= mgstm1.rev ==============
37380 if test -f 'mgstm1.rev' -a X"$1" != X"-c"; then
37381         echo 'x - skipping mgstm1.rev (File already exists)'
37382 else
37383 echo 'x - extracting mgstm1.rev (Text)'
37384 sed 's/^X//' << 'SHAR_EOF' > 'mgstm1.rev' &&
37385 >mgstm1 reverse complement
37386 AAGTGTGTTTCAGACTTTATTGTAGACGAGACAGACCTGGGGAGGCTACTCCACCAGGAACAGGCTGGCACTCAA
37387 GTATTGACTTCGGGGTAACTCTAGGGAGGGCTAGCACTAAGATAGTGTTGACCATCGGGGTAATTCTAGGAAGCG
37388 TGAGTTCAGGACAGACCTCAGTTCGCAGAAACGGGCTGTGAGGTTGGGTCAGGGAGCCAATGAAGAAGGGGCCAT
37389 gtgaaagaaactggggagaatgaaggctgtgtggacttgactgggaagagggtgaggagatggggctgaccaagc
37390 tgcagaagggagcgggaaggagagagaaccaggagccacagtgcagaaggccagggtgctgtccccacccagggc
37391 CTGCAGGATCCCCAGTGTGGACAGGTCCTCCTAGTGAGTGCCCGTGTAGCAAGGGCCTACTTGTTACTCCAGTGG
37392 GCCATCTTTGAAAATATAGGTGTTGCGATGTAGCGGCTACTCTTCATGTAGGCAGAGATCTTCTTGAGGCCCTCG
37393 AAGCGGGCCAGGAAGTCCCTCAGGTTTGGGAAGGCGTCCAGGCACTTGGGCTCAAACATACGGTACTGGTCAAGA
37394 ATGTCATAAGCAAGGAAATCCACATAGGTGACCTTGTCCCCTGCAAACCATGGCCTCTTGCCCAGGAACTCAGAG
37395 tagagcttcattttctcagggatggtcttcaagaactctggcttctgcttctcaaagtcagggttgtaacagagc
37396 atgatgagctgcatgcgggtgtccatgacctggttctccacaatgtctgcacggatcctctcctcctctgtctct
37397 ccatccaggtggtgctttcgggcaaggtagcgcaggatggcattgctctgggtgatcttgtgtgatccatcgatc
37398 AAGTAAGGCAGATTGGGAAAGTCCAGGCCCAGCTTGAACTTCTCATTCAGCCACTGGCTTCTGTCAAAGTCGGGA
37399 GCGTCACCCATGGTGTATCTCTTCTCATCATAGCTTGAGTCTGTGTATTCCAGGAGCATGCGGATCGGGTGTGTC
37400 AGTCCGCGGACGTTCCAGTATCCCAGTATCATAGGCATGGTGCTGGTGCTGTGGTCTTCTCAAACTGGCTTCAGC
37401 SHAR_EOF
37402 chmod 0644 mgstm1.rev ||
37403 echo 'restore of mgstm1.rev failed'
37404 Wc_c="`wc -c < 'mgstm1.rev'`"
37405 test 1167 -eq "$Wc_c" ||
37406         echo 'mgstm1.rev: original size 1167, current size' "$Wc_c"
37407 fi
37408 # ============= mgstm1.seq ==============
37409 if test -f 'mgstm1.seq' -a X"$1" != X"-c"; then
37410         echo 'x - skipping mgstm1.seq (File already exists)'
37411 else
37412 echo 'x - extracting mgstm1.seq (Text)'
37413 sed 's/^X//' << 'SHAR_EOF' > 'mgstm1.seq' &&
37414 >pGT875 | 266
37415 GCTGAAGCCAGTTTGAGAAGACCACAGCACCAGCACCATGCCTATGATACTGGGATACTG
37416 GAACGTCCGCGGACTGACACACCCGATCCGCATGCTCCTGGAATACACAGACTCAAGCTA
37417 TGATGAGAAGAGATACACCATGGGTGACGCTCCCGACTTTGACAGAAGCCAGTGGCTGAA
37418 TGAGAAGTTCAAGCTGGGCCTGGACTTTCCCAATCTGCCTTACTTGATCGATGGATCACA
37419 CAAGATCACCCAGAGCAATGCCATCCTGCGCTACCTTGCCCGAAAGCACCACCTGGATGG
37420 AGAGACAGAGGAGGAGAGGATCCGTGCAGACATTGTGGAGAACCAGGTCATGGACACCCG
37421 CATGCAGCtCATCATGCTCTGTTACAACCCTGACTTTGAGAAGCAGAAGCCAGAGTTCTT
37422 GAAGACCATCCCTGAGAAAATGAAGCTCTACTCTGAGTTCCTGGGCAAGAGGCCATGGTT
37423 TGCAGGGGACAAGGTCACCTATGTGGATTTCCTTGCTTATGACATTCTTGACCAGTACCG
37424 TATgTTTGAGCCCAAGTGCCTGGACGCCTTCCCAAACCTGAGGGACTTCCTGGCCCGCTT
37425 CGAGGGCCTCAAGAAGATCTCTGCCTACATGAAGAGTAGCCGCTACATCGCAACACCTAT
37426 ATTTTCAAAGATGGCCCACTGGAGTAACAAGTAGGCCCTTGCTACACGGGCACTCACTAG
37427 GAGGACCTGTCCACACTGGGgATCCTGCAGGCCCTGGGTGGGGACAGCACCCTGGCCTTC
37428 TGCACTGTGGCTCCTGGTTCTCTCTCCTTCCCGCTCCCTTCTGCAGCTTGGTCAGCCCCA
37429 TCTCCTCACCCTCTTCCCAGTCAAGTCCACACAGCCTTCATTCTCCCCAGTTTCTTTCAC
37430 ATGGCCCCTTCTTCATTGGCTCCCTGACCCAACCTCACAGCCCGTTTCTGCGAACTGAGG
37431 TCTGTCCTGAACTCACGCTTCCTAGAATTACCCCGATGGTCAACACTATCTTAGTGCTAG
37432 CCCTCCCTAGAGTTACCCCGAAGTCAATACTTGAGTGCCAGCCTGTTCCTGGTGGAGTAG
37433 CCTCCCCAGGTCTGTCTCGTCTACAATAAAGTCTGAAACACACTT
37434 SHAR_EOF
37435 chmod 0644 mgstm1.seq ||
37436 echo 'restore of mgstm1.seq failed'
37437 Wc_c="`wc -c < 'mgstm1.seq'`"
37438 test 1158 -eq "$Wc_c" ||
37439         echo 'mgstm1.seq: original size 1158, current size' "$Wc_c"
37440 fi
37441 # ============= mgtt2_x.seq ==============
37442 if test -f 'mgtt2_x.seq' -a X"$1" != X"-c"; then
37443         echo 'x - skipping mgtt2_x.seq (File already exists)'
37444 else
37445 echo 'x - extracting mgtt2_x.seq (Text)'
37446 sed 's/^X//' << 'SHAR_EOF' > 'mgtt2_x.seq' &&
37447 >>mgtt2_x      Length: 1089  January 26, 2000 04:00  Type: N  Check: 1394  ..
37448 CTGAGTTGGG TCCACGAAAG CCCAGCTAGG CCATTACCGC GTCCGGGTGA GACTAAGGTC CTGGGCTGGA TTCCTGGCTC CACGGTCCGC TGGAGCAAAT 
37449 CGCATAAGTC AGTCTGAGTG CGCGCGCCCT CAGCCCTGCT TTTGGTATAA AGTCCTCCAA AGCGTCTCCC TCCCCAANNN NGATCagCAg GtGTCAGCTA 
37450 TCCAGAGGAG GAAATCGTTT GGCTTGGcCA ACTGAGGcTG TGCTGGACCC CAGCTTGCTG TTATCGAACG CAGTCGGCAC ACCATCTTGT GTCGCTACCG 
37451 GCAATGGGCT TGGAGCTCTA CCTGGACCTG CTGTCACAAC CCAGCCGCGC TGTCTACATC tTCNGCCAaG AAGAATGGCA TCCCCTTCCA GACGCGTACC 
37452 GTGGATATAC TCAAAGGGCA GCACATGAGC GAGCAATTCT CCCAGGTGAA CTGCTTAAAC AAAGTTCCTG TACTCAAAGA CGGAAGCTTC GTGTTGACCG 
37453 AAAGCACAGC CATCTtGATT TACCTGAGTT CCAAGTACCA GGTGGCAGAC CACTGGTACC CGGCCGACCT ACAGGCCCGT GCCCAAGTCC ACGAATACCT 
37454 GGGCTGGCAT GcCGACAACA TCCgtGGTAC TTtcgGAGTG CTCCTATGGA CCNAAgGTGT TgGGGCCACT CATTGgGGTc CAgGTTCCCC agGAGAAGGT 
37455 GGAACgGAAC agAGATAGAA TGGTCCTGGt TCTGCaACAG CTGGAgGACA AGTTCTCAGG GACAGGsCTC CTGTTGGCAG CAGTGAGCTA GCGATCTCAT 
37456 TCTCTGGAGA GTGATGCAGC GTGCTCTTGC TATACCTGTT GAGGACGGCT CAGCTGACAG CATGCGAGAA AGGTGGAGGC GTCTTGGTGC TGAGCTGTGT 
37457 AGAGCTCATA GACATCTGGC ATCTGGACAA GCAGCAGAAA TGTACAGTAC CCCTTCGAGT CATGCACATG CACTCAATTG TAGATCCTGA TGGTTGACCA 
37458 CATAAGACTA TTTGTGTTAA AAAAGGGGGC CGTCCCATTC CCTTATGATC GATACATACT GGCTCCTTTA CACATNGATG GAAAACTGC
37459 SHAR_EOF
37460 chmod 0644 mgtt2_x.seq ||
37461 echo 'restore of mgtt2_x.seq failed'
37462 Wc_c="`wc -c < 'mgtt2_x.seq'`"
37463 test 1286 -eq "$Wc_c" ||
37464         echo 'mgtt2_x.seq: original size 1286, current size' "$Wc_c"
37465 fi
37466 # ============= mm_file.h ==============
37467 if test -f 'mm_file.h' -a X"$1" != X"-c"; then
37468         echo 'x - skipping mm_file.h (File already exists)'
37469 else
37470 echo 'x - extracting mm_file.h (Text)'
37471 sed 's/^X//' << 'SHAR_EOF' > 'mm_file.h' &&
37472 /*
37473 X  copyright (c) 1999 William R. Pearson
37474 */
37475 X
37476 /* $Name: fa_34_26_5 $ - $Id: mm_file.h,v 1.26 2006/10/05 18:20:40 wrp Exp $ */
37477 X
37478 /*
37479 X  mm_file.h - defines m_file_str for mmap()ed files 
37480 */
37481 X
37482 #include <sys/types.h>
37483 X
37484 #ifndef USE_FSEEKO
37485 #define FSEEK fseek
37486 #define FTELL ftell
37487 typedef long fseek_t;
37488 #else
37489 #define FSEEK fseeko
37490 #define FTELL ftello
37491 typedef off_t fseek_t;
37492 #endif
37493 #define FSEEK_T_DEF
37494 X
37495 #ifdef HAS_INTTYPES
37496 #include <inttypes.h>
37497 #else
37498 #ifdef WIN32
37499 typedef __int64 int64_t;
37500 typedef unsigned __int64 uint64_t;
37501 #else
37502 typedef long int64_t;
37503 typedef unsigned long uint64_t;
37504 #endif
37505 #endif
37506 #ifdef BIG_LIB64
37507 typedef int64_t MM_OFF;
37508 #else
37509 typedef long MM_OFF;
37510 #endif
37511 X
37512 #ifdef MYSQL_DB
37513 #include <mysql.h>
37514 #endif
37515 #ifdef PGSQL_DB
37516 #include <libpq-fe.h>
37517 #endif
37518 X
37519 struct lmf_str {
37520 X  FILE *libf;          /* sequence file being read */
37521 X  FILE *hfile;         /* BLAST2.0 description file */
37522 X  unsigned int *oid_list;      /* oid list for subsets */
37523 X  int oid_seqs;                /* start offset for mask array */
37524 X  int pref_db;         /* preferred database */
37525 X  unsigned int max_oid;        /* start offset for mask array */
37526 X
37527 X  char lb_name[120];   /* file name */
37528 X  int lb_type;         /* library type */
37529 X  int *sascii;         /* ascii -> sq mapping */
37530 X
37531 X  /* used by flat files */
37532 X  char *lline;         /* last line read */
37533 X  unsigned char *cpsave;       /* position in line for lgetlib() */
37534 X  fseek_t lpos;                        /* position in file */
37535 X
37536 X  /* Genbank Flat files */
37537 X  int lfflag;          /* flag for CRLF in EMBL CDROM files */
37538 X
37539 X  /* stuff for GCG format files (5,6) */
37540 X  int gcg_binary;      /* flag for binary gcg format */
37541 X  long gcg_len;                /* length of GCG sequence */
37542 X
37543 X  int bl_lib_pos;        /* for ncbl2 */
37544 X  int bl_format_ver;     /* blast formatdb version */
37545 X  char opt_text[MAX_FN];         /* text after filename */
37546 X
37547 X  /* used when memory mapping */
37548 X  int mm_flg;          /* mmap worked */
37549 X  int mmap_fd;         /* mmap_fd */
37550 X  char *mmap_base;     /* base */
37551 X  char *mmap_addr;     /* current pos */
37552 X  long st_size;                /* file size */
37553 X
37554 X  MM_OFF *d_pos_arr;   /* pointer to desc. offsets */
37555 X  MM_OFF *s_pos_arr;   /* pointer to seq. offsets */
37556 X  MM_OFF *a_pos_arr;   /* pointer to aux offsets */
37557 X
37558 X  /* currently available only for memory mapped files */
37559 X  int max_cnt;         /* # database entries */
37560 X  int64_t tot_len;     /* total residue length */
37561 X  long max_len;                /* maximum sequence lengh */
37562 X  int lib_aa;          /* 0 = DNA, 1 = prot */
37563 X  char *tmp_buf;       /* temporary buffer */
37564 X  int tmp_buf_max;     /* max size */
37565 X
37566 X  /* used for SQL database queries */
37567 X  char *sql_db, *sql_query, *sql_getdesc, *sql_getseq;
37568 X  int sql_reopen;
37569 X  char **sql_uid_arr;  /* indexed by lpos */
37570 X  /* used to get sequence data */
37571 X  char *sql_seqp;
37572 X
37573 #ifdef MYSQL_DB
37574 X  /* used to open the database */
37575 X  MYSQL *mysql_conn;
37576 X  MYSQL_RES *mysql_res;
37577 X  MYSQL_ROW mysql_row;
37578 #endif
37579 X
37580 #ifdef PGSQL_DB
37581 X  /* used to open the database */
37582 X  PGconn *pgsql_conn;
37583 X  PGresult *pgsql_res;
37584 #endif
37585 X
37586 X  int (*getlib)(unsigned char *seq, int maxs,
37587 X               char *libstr, int n_libstr,
37588 X               fseek_t *libpos,
37589 X               int *lcont,
37590 X               struct lmf_str *lm_fd,
37591 X               long *l_off);
37592 X
37593 X  void (*ranlib)(char *str, int cnt,
37594 X                fseek_t libpos, char *libstr,
37595 X                struct lmf_str *lm_fd);
37596 };
37597 X
37598 SHAR_EOF
37599 chmod 0644 mm_file.h ||
37600 echo 'restore of mm_file.h failed'
37601 Wc_c="`wc -c < 'mm_file.h'`"
37602 test 3057 -eq "$Wc_c" ||
37603         echo 'mm_file.h: original size 3057, current size' "$Wc_c"
37604 fi
37605 # ============= mmgetaa.c ==============
37606 if test -f 'mmgetaa.c' -a X"$1" != X"-c"; then
37607         echo 'x - skipping mmgetaa.c (File already exists)'
37608 else
37609 echo 'x - extracting mmgetaa.c (Text)'
37610 sed 's/^X//' << 'SHAR_EOF' > 'mmgetaa.c' &&
37611 /* mmgetaa.c - functions for mmap()ed access to libraries */
37612 X
37613 /* copyright (c) 1999,2000 William R. Pearson */
37614 X
37615 /* version 0 September, 1999 */
37616 X
37617 /*
37618 X  This is one of two alternative files that can be used to
37619 X  read a database.  The two files are nmgetaa.c, and mmgetaa.c
37620 X  (nxgetaa.c has been retired).
37621 X
37622 X  nmgetlib.c and mmgetaa.c are used together. nmgetlib.c provides
37623 X  the same functions as nxgetaa.c if memory mapping is not used,
37624 X  mmgetaa.c provides the database reading functions if memory
37625 X  mapping is used. The decision to use memory mapping is made on
37626 X  a file-by-file basis.
37627 */
37628 X
37629 /* $Name: fa_34_26_5 $ - $Id: mmgetaa.c,v 1.41 2006/04/12 18:00:02 wrp Exp $ */
37630 X
37631 #include <stdio.h>
37632 #include <stdlib.h>
37633 #include <unistd.h>
37634 #include <string.h>
37635 #include <errno.h>
37636 X
37637 #include <sys/types.h>
37638 #include <sys/stat.h>
37639 #include <sys/mman.h>
37640 #include <fcntl.h>
37641 X
37642 #define MAXLINE 512
37643 #define EOSEQ 0
37644 X
37645 #define XTERNAL
37646 #include "uascii.h"
37647 /* #include "upam.h" */
37648 #undef XTERNAL
37649 X
37650 #ifdef SUPERFAMNUM
37651 extern int nsfnum;      /* number of superfamily numbers */
37652 extern int sfnum[10];   /* superfamily number from types 0 and 5 */
37653 extern int nsfnum_n;
37654 extern int sfnum_n[10];
37655 static char tline[MAXLINE];
37656 #endif
37657 X
37658 #define GCGBIN 6
37659 X
37660 #ifndef MAP_FILE
37661 #define MAP_FILE 0
37662 #endif
37663 X
37664 #include "defs.h"
37665 #include "mm_file.h"
37666 X
37667 extern MM_OFF bl2_long8_cvt(int64_t);
37668 extern int bl2_uint4_cvt(int);
37669 X
37670 X
37671 long crck(char *, int);
37672 extern void src_int4_read(FILE *fd,  int *val);
37673 extern void src_long4_read(FILE *fd,  long  *valp);
37674 extern void src_long8_read(FILE *fd,  int64_t *val);
37675 X
37676 /* load_mmap() loads the d_pos[] and s_pos[] arrays for rapid access */
37677 X
37678 struct lmf_str *
37679 load_mmap(FILE *libi,   /* fd for already open ".xin" file */
37680 X         char *sname,  /* name of sequence database file */
37681 X         int lib_type, /* 0-Fasta, 5-vms_pir, 6-gcg_binary */
37682 X         int ldnaseq,  /* 1 for DNA, 0 for protein */
37683 X         struct lmf_str *m_fd)
37684 {
37685 X  char format[4];
37686 X  int i, lib_aa;
37687 X  MM_OFF f_size;
37688 X  long lf_size;
37689 X  struct stat statbuf;
37690 X  int max_cnt;
37691 X  MM_OFF *d_pos_arr, *s_pos_arr;
37692 X  int mm_flag, mm64_flag;
37693 X  int *tmp_pos_arr;
37694 X
37695 X  /* first check that the necessary indices are up-to-date */
37696 X  /* read the offsets in ".xin" file */
37697 X  if (fread(format,1,4,libi)==0) {
37698 X    fprintf(stderr," cannot read .xin format\n");
37699 X    return NULL;
37700 X  }
37701 X    
37702 X  mm64_flag = (format[2]==1);  /* 4 bytes or 8 bytes for long? */
37703 X
37704 #ifndef BIG_LIB64
37705 X  if (mm64_flag) {return NULL;}
37706 #endif
37707 X
37708 X  if (format[3]!=lib_type) {
37709 X    fprintf(stderr," cannot read format %d != lib_type %d\n",
37710 X           format[3],lib_type);
37711 X    return NULL;
37712 X  }
37713 X
37714 X  src_int4_read(libi,&lib_aa);
37715 X  if (lib_aa == ldnaseq) { /* database residue mismatch */
37716 X    fprintf(stderr," residue type mismatch %s != %s (.xin) in %s\n",
37717 X           (lib_aa ? "DNA" : "prot."),(ldnaseq ? "prot." : "DNA"),
37718 X           sname);
37719 X    return NULL;
37720 X  }
37721 X    
37722 X  /* everything looks good, allocate an lmf_str */
37723 X
37724 X  m_fd->lib_aa = lib_aa;
37725 X
37726 X  /* get get file size from index */
37727 X  if (mm64_flag) src_long8_read(libi,&f_size);
37728 X  else {
37729 X    src_long4_read(libi,&lf_size);
37730 X    f_size = lf_size;
37731 X  }
37732 X
37733 X  /* now, start to open mmap()ed file */
37734 X  mm_flag=((m_fd->mmap_fd=open(sname,O_RDONLY))>=0);
37735 X  if (!mm_flag) {
37736 X    fprintf(stderr," cannot open %s for mmap()", sname);
37737 X    perror("...");
37738 X    return NULL;       /* file did not open */
37739 X  }
37740 X
37741 X  /* fstat the library file and get size */
37742 X  if(fstat(m_fd->mmap_fd, &statbuf) < 0) {
37743 X    fprintf(stderr," cannot stat %s for mmap()", sname);
37744 X    perror("...");
37745 X    m_fd->mm_flg = 0;
37746 X    goto finish;
37747 X  }
37748 X
37749 X  /* check for identical sizes - if different, do not mmap */
37750 X  if (f_size != statbuf.st_size) {
37751 X    fprintf(stderr," %s file size (%lld) and expected size (%ld) don't match\n",
37752 X           sname,statbuf.st_size,f_size);
37753 X    mm_flag = 0;
37754 X    goto finish;    
37755 X  }
37756 X
37757 X  /* the index file and library file are open and the sizes match */
37758 X  /* allocate the m_file struct and  map the file */
37759 X
37760 X  m_fd->st_size = statbuf.st_size;
37761 X  if((m_fd->mmap_base = 
37762 X      mmap(NULL, m_fd->st_size, PROT_READ,
37763 X          MAP_FILE | MAP_SHARED, m_fd->mmap_fd, 0)) == (char *) -1) {
37764 X    mm_flag = 0;
37765 #ifdef DEBUG
37766 X    fprintf(stderr," cannot mmap %s", sname);
37767 X    perror("...");
37768 #endif
37769 X  }  
37770 X finish:
37771 X  close(m_fd->mmap_fd);
37772 X  if (!mm_flag) { return NULL; }
37773 X
37774 X  /* now finish reading the index file */
37775 X  src_int4_read(libi,&max_cnt);
37776 X
37777 X  if (mm64_flag) {
37778 X    src_long8_read(libi,&m_fd->tot_len);
37779 X  }
37780 X  else {
37781 X    src_long4_read(libi,&lf_size);
37782 X    m_fd->tot_len = lf_size;
37783 X  }
37784 X  src_long4_read(libi,&lf_size);
37785 X  m_fd->max_len = lf_size;
37786 X
37787 #ifdef DEBUG
37788 X  fprintf(stderr,
37789 X         "%s\tformat: %c%c%d %d; max_cnt: %d; tot_len: %lld max_len: %ld\n",
37790 X         sname,format[0],format[1],format[2],format[3],
37791 X         max_cnt,m_fd->tot_len,m_fd->max_len);
37792 #endif
37793 X
37794 X  /* allocate array of description pointers */
37795 X  if (!mm64_flag) {
37796 X    if ((tmp_pos_arr=(int *)calloc(max_cnt+1,sizeof(int)))==NULL) {
37797 X      fprintf(stderr," cannot allocate %d for tmp_pos array\n",
37798 X             max_cnt+1);
37799 X    }
37800 X  }
37801 X
37802 X  if ((d_pos_arr=(MM_OFF *)calloc(max_cnt+1, sizeof(MM_OFF)))==NULL) {
37803 X    fprintf(stderr," cannot allocate %d for desc. array\n",max_cnt+1);
37804 X    exit(1);
37805 X  }
37806 X
37807 X  /* read m_fd->d_pos[max_cnt+1] */
37808 X  if (mm64_flag) {
37809 X    if (fread(d_pos_arr,sizeof(MM_OFF),max_cnt+1,libi)!=
37810 X       max_cnt+1) {
37811 X      fprintf(stderr," error reading desc. offsets: %s\n",sname);
37812 X      return NULL;
37813 X    }
37814 X  }
37815 X  else {
37816 X    if (fread(tmp_pos_arr,sizeof(int),max_cnt+1,libi)!=
37817 X       max_cnt+1) {
37818 X      fprintf(stderr," error reading desc. offsets: %s\n",sname);
37819 X      return NULL;
37820 X    }
37821 #ifdef DEBUG
37822 X    fprintf(stderr,"d_pos_crc: %ld\n",
37823 X           crck((char *)tmp_pos_arr,sizeof(int)*(max_cnt+1)));
37824 #endif
37825 X  }
37826 X
37827 X
37828 #ifndef IS_BIG_ENDIAN
37829 X  if (mm64_flag)
37830 X    for (i=0; i<=max_cnt; i++) {
37831 X      d_pos_arr[i] = bl2_long8_cvt(d_pos_arr[i]);
37832 X    }
37833 X  else
37834 X    for (i=0; i<=max_cnt; i++) {
37835 X      d_pos_arr[i] = bl2_uint4_cvt(tmp_pos_arr[i]);
37836 X    }
37837 #else
37838 X  if (!mm64_flag) {
37839 X    for (i=0; i<=max_cnt; i++) {
37840 X      d_pos_arr[i] = tmp_pos_arr[i];
37841 X    }
37842 X  }
37843 #endif
37844 X
37845 #ifdef DEBUG
37846 X  for (i=0; i<max_cnt-1; i++) {
37847 X    if (d_pos_arr[i+1] <= d_pos_arr[i] )
37848 X      fprintf(stderr," ** dpos_error [%d]\t%ld\t%ld\n",
37849 X             i,d_pos_arr[i],d_pos_arr[i+1]);
37850 X  }
37851 #endif
37852 X
37853 X  /* allocate array of sequence pointers */
37854 X  if ((s_pos_arr=(MM_OFF *)calloc(max_cnt+1,sizeof(MM_OFF)))==NULL) {
37855 X    fprintf(stderr," cannot allocate %d for seq. array\n",max_cnt+1);
37856 X    exit(1);
37857 X  }
37858 X
37859 X  /* read m_fd->s_pos[max_cnt+1] */
37860 X  if (mm64_flag) {
37861 X    if (fread(s_pos_arr,sizeof(long),max_cnt+1,libi)!=
37862 X       max_cnt+1) {
37863 X      fprintf(stderr," error reading seq offsets: %s\n",sname);
37864 X      return NULL;
37865 X    }
37866 X  }
37867 X  else {
37868 X    if (fread(tmp_pos_arr,sizeof(int),max_cnt+1,libi)!=
37869 X       max_cnt+1) {
37870 X      fprintf(stderr," error reading seq offsets: %s\n",sname);
37871 X      return NULL;
37872 X    }
37873 #ifdef DEBUG
37874 X    fprintf(stderr,"s_pos_crc: %ld\n",
37875 X           crck((char *)tmp_pos_arr,sizeof(int)*(max_cnt+1)));
37876 #endif
37877 X  }
37878 X
37879 #ifndef IS_BIG_ENDIAN
37880 X  if (mm64_flag)
37881 X    for (i=0; i<=max_cnt; i++)
37882 X      s_pos_arr[i] = bl2_long8_cvt(s_pos_arr[i]);
37883 X  else
37884 X    for (i=0; i<=max_cnt; i++)
37885 X      s_pos_arr[i] = (long)bl2_uint4_cvt(tmp_pos_arr[i]);
37886 #else
37887 X  if (!mm64_flag) 
37888 X    for (i=0; i<=max_cnt; i++)
37889 X      s_pos_arr[i] = (long)tmp_pos_arr[i];
37890 #endif
37891 X
37892 #ifdef DEBUG
37893 X  for (i=1; i<max_cnt-1; i++) {
37894 X    if (s_pos_arr[i+1]<s_pos_arr[i])
37895 X      fprintf(stderr," ** spos_error [%d]\t%ld\t%ld\n",
37896 X             i,s_pos_arr[i],s_pos_arr[i]);
37897 X  }
37898 #endif
37899 X
37900 X  if (!mm64_flag) free(tmp_pos_arr);
37901 X
37902 X  m_fd->max_cnt = max_cnt;
37903 X  m_fd->d_pos_arr = d_pos_arr;
37904 X  m_fd->s_pos_arr = s_pos_arr;
37905 X  m_fd->lpos = 0;
37906 X
37907 X  /*   check_mmap(m_fd,-2); */
37908 X
37909 X  return m_fd;
37910 }  
37911
37912 char *mgets (char *s, int n, struct lmf_str *m_fd)
37913 {
37914 X  char *cs, *mfp;
37915 X
37916 X  mfp = m_fd->mmap_addr;
37917 X  cs = s;
37918 X
37919 X  while (--n > 0 && (*mfp != (char)EOF))
37920 X    if ((*cs++ = *mfp++) == '\n') break;
37921 X  *cs = '\0';
37922 X
37923 X  m_fd->mmap_addr = mfp;
37924 X  return (*mfp == (char)EOF && cs == s) ? NULL : s;
37925 }
37926 X
37927 int
37928 agetlibm(unsigned char *seq,
37929 X        int maxs,
37930 X        char *libstr,
37931 X        int n_libstr,
37932 X        fseek_t *libpos,
37933 X        int *lcont,
37934 X        struct lmf_str *m_fd,
37935 X        long *l_off)
37936 {
37937 X  register unsigned char *cp, *seqp;
37938 X  register int *ap;
37939 X  char *desc;
37940 X  int lpos;            /* entry number in library */
37941 X  long l;
37942 X  unsigned char *seqm, *seqm1;
37943 X  char *bp;
37944 X  static long seq_len;
37945 X  static unsigned char *cp_max;
37946 #ifdef SUPERFAMNUM
37947 X  char *bp1, *bpa, *tp;
37948 X  int i;
37949 #endif
37950 X
37951 X  *l_off = 1;
37952 X
37953 X  lpos = m_fd->lpos;
37954 X
37955 X  seqp = seq;
37956 X  seqm = &seq[maxs-9];
37957 X  seqm1 = seqm-1;
37958 X
37959 X  ap = m_fd->sascii;
37960 X
37961 X  if (*lcont==0) {
37962 X    if (lpos >= m_fd->max_cnt) return (-1);
37963 X    seq_len = m_fd->d_pos_arr[lpos+1] - m_fd->s_pos_arr[lpos];
37964 X    if (seq_len < 0 || (seq_len > m_fd->max_len && seq_len > (m_fd->max_len*5)/4)) {
37965 X      fprintf(stderr," ** sequence over-run: %ld at %d\n",seq_len,lpos);
37966 X      return(-1);
37967 X    }
37968 X    *libpos = (fseek_t)lpos;
37969 X
37970 X    desc = m_fd->mmap_base+m_fd->d_pos_arr[lpos]+1;
37971 X    strncpy(libstr,desc,n_libstr-1);
37972 X    libstr[n_libstr-1]='\0';
37973 X    if ((bp=strchr(libstr,'\r'))!=NULL) *bp='\0';
37974 X    if ((bp=strchr(libstr,'\n'))!=NULL) *bp='\0';
37975 X    if (n_libstr > MAX_UID) {
37976 X      bp = libstr;
37977 X      while (*bp++) if ( *bp=='\001' || *bp=='\t') *bp=' ';
37978 X    }
37979 X
37980 X    for (bp = desc; *bp && (*bp != '\n'); *bp++ )
37981 X      if (*bp == '@' && !strncmp(bp+1,"C:",2)) sscanf(bp+3,"%ld",l_off);
37982 X
37983 #ifdef SUPERFAMNUM
37984 X    sfnum[0]=nsfnum=0;
37985 X    strncpy(tline,desc,sizeof(tline));
37986 X    tline[MAXLINE-1]='\0';
37987 X    if ((bp=strchr(tline,'\n'))!=NULL) *bp='\0';
37988 X    if ((bp=strchr(tline,' ')) && (bp=strchr(bp+1,SFCHAR))) {
37989 X      if ((bpa = strchr(bp+1,'\001'))!=NULL) *bpa = '\0';
37990 X      if ((bp1=strchr(bp+1,SFCHAR))==NULL) {
37991 X       fprintf(stderr," second %c missing: %s\n",SFCHAR,tline);
37992 X      }
37993 X      else {
37994 X       *bp1 = '\0';
37995 X       i = 0;
37996 X       if ((tp = strtok(bp+1," \t"))!=NULL) {
37997 X         sfnum[i++] = atoi(tp);
37998 X         while ((tp = strtok((char *)NULL," \t")) != (char *)NULL) {
37999 X           sfnum[i++] = atoi(tp);
38000 X           if (i>=9) break;
38001 X         }
38002 X       }
38003 X       sfnum[nsfnum=i]= 0;
38004 X       if (nsfnum>1) sf_sort(sfnum,nsfnum);
38005 X       else {
38006 X         if (nsfnum<1) fprintf(stderr," found | but no sfnum: %s\n",libstr);
38007 X       }
38008 X      }
38009 X    }
38010 X    else {
38011 X      sfnum[0] = nsfnum = 0;
38012 X      }
38013 #endif
38014 X
38015 X    m_fd->mmap_addr = m_fd->mmap_base+m_fd->s_pos_arr[lpos];
38016 X    cp_max = (unsigned char *)(m_fd->mmap_addr+seq_len);
38017 X  }
38018 X
38019 X  for (cp=(unsigned char *)m_fd->mmap_addr; seqp<seqm1; ) {
38020 X    if ((*seqp++=ap[*cp++])<NA &&
38021 X       (*seqp++=ap[*cp++])<NA &&
38022 X       (*seqp++=ap[*cp++])<NA &&
38023 X       (*seqp++=ap[*cp++])<NA &&
38024 X       (*seqp++=ap[*cp++])<NA &&
38025 X       (*seqp++=ap[*cp++])<NA &&
38026 X       (*seqp++=ap[*cp++])<NA &&
38027 X       (*seqp++=ap[*cp++])<NA &&
38028 X       (*seqp++=ap[*cp++])<NA &&
38029 X       (*seqp++=ap[*cp++])<NA) continue;
38030 X    --seqp;
38031 X    if (cp >= cp_max) break;
38032 X  }
38033 X  m_fd->mmap_addr = (char *)cp;
38034 X
38035 X  if (seqp>=seqm1) (*lcont)++;
38036 X  else {
38037 X    *lcont=0;
38038 X    lpos++;
38039 X    m_fd->lpos = lpos;
38040 X  }
38041 X  *seqp = EOSEQ;
38042 X  /*   if ((int)(seqp-seq)==0) return 1; */
38043 X  return (int)(seqp-seq);
38044 }
38045 X
38046 void
38047 aranlibm(char *str,
38048 X        int cnt,
38049 X        fseek_t libpos,
38050 X        char *libstr,
38051 X        struct lmf_str *m_fd)
38052 {
38053 X  char *bp;
38054 X  int llen;
38055 X  int lpos;
38056 X
38057 X  lpos = (int) libpos;
38058 X
38059 X  llen = m_fd->s_pos_arr[lpos]-m_fd->d_pos_arr[lpos];
38060 X  if (llen >= cnt) llen = cnt-1;
38061 X
38062 X  strncpy(str,m_fd->mmap_base+m_fd->d_pos_arr[lpos]+1,llen);
38063 X  str[llen]='\0';
38064 X  if ((bp = strchr(str,'\r'))!=NULL) *bp='\0';
38065 X  if ((bp = strchr(str,'\n'))!=NULL) *bp='\0';
38066 X  bp = str;
38067 X  while (*bp++) if ( *bp=='\001' || *bp=='\t') *bp=' ';
38068 X  m_fd->lpos = lpos;
38069 }
38070 X
38071 /* there is no vgetlibm() because vgetlibm() and agetlibm() are
38072 X   identical - the difference in the two file formats relates to the
38073 X   location of the sequence, which is already available in spos_arr[].
38074 X
38075 X   however vranlibm must accomodate both type 5 and 6 files;
38076 X   type 6 has extra stuff after the seq_id.
38077 */
38078 X
38079 void
38080 vranlibm(char *str,
38081 X        int cnt,
38082 X        fseek_t libpos,
38083 X        char *libstr,
38084 X        struct lmf_str *m_fd)
38085 {
38086 X  char *bp, *mp;
38087 X  int llen;
38088 X  int lpos;
38089 X
38090 X  lpos = (int)libpos;
38091 X
38092 X  llen = m_fd->s_pos_arr[lpos]-m_fd->d_pos_arr[lpos];
38093 X
38094 X  mp = m_fd->mmap_base+m_fd->d_pos_arr[lpos];
38095 X  
38096 X  strncpy(str,mp+4,20);
38097 X  str[20]='\0';
38098 X  if ((bp=strchr(str,' '))!=NULL) *(bp+1) = '\0';
38099 X  else if ((bp=strchr(str,'\n'))!=NULL) *bp = ' ';
38100 X  bp = strchr(mp,'\n');
38101 X
38102 X  llen -= (bp-mp)-5;
38103 X  if (llen >  cnt-strlen(str)) llen = cnt-strlen(str)-1;
38104 X
38105 X  strncat(str,bp+1,llen);
38106 X  if ((bp = strchr(str,'\n'))!=NULL) *bp='\0';
38107 X  str[cnt-1]='\0';
38108 X  m_fd->lpos = lpos;
38109 }
38110 X
38111 void
38112 close_mmap(struct lmf_str *m_fd) {
38113 X  free(m_fd->s_pos_arr);
38114 X  free(m_fd->d_pos_arr);
38115 X  if (m_fd->mm_flg) {
38116 X    munmap(m_fd->mmap_base,m_fd->st_size);
38117 X    free(m_fd);
38118 X  }
38119 X  m_fd->mm_flg=0;
38120 }  
38121 X
38122 #ifndef min
38123 #define min(x,y) ((x) > (y) ? (y) : (x))
38124 #endif
38125 X
38126 static int gcg_bton[4]={2,4,1,3};
38127 X
38128 int
38129 gcg_getlibm(unsigned char *seq,
38130 X           int maxs,
38131 X           char *libstr,
38132 X           int n_libstr,
38133 X           fseek_t *libpos,
38134 X           int *lcont,
38135 X           struct lmf_str *m_fd,
38136 X           long *l_off)
38137 {
38138 X  char dummy[20];
38139 X  char gcg_date[6];
38140 X  char gcg_type[10];
38141 X  register unsigned char *cp, *seqp, stmp;
38142 X  register int *ap, lpos;
38143 X  unsigned char *seqm, *seqm1;
38144 X  long r_block, b_block, r_fact, r16_block;
38145 X
38146 X  *l_off = 1;
38147 X
38148 X  seqp = seq;
38149 X  seqm = &seq[maxs-9];
38150 X  seqm1 = seqm-1;
38151 X
38152 X  ap = m_fd->sascii;
38153 X  lpos = m_fd->lpos; 
38154 X
38155 X  if (*lcont==0) {
38156 X    if (lpos >= m_fd->max_cnt) return (-1);
38157 X    sscanf(m_fd->mmap_base+m_fd->d_pos_arr[lpos]+4,"%s %s %s %s %ld\n",
38158 X          libstr,gcg_date,gcg_type,dummy,&(m_fd->gcg_len));
38159 X
38160 X    m_fd->gcg_binary = (gcg_type[0]=='2');
38161 X
38162 X    libstr[12]='\0';
38163 X    *libpos = lpos;
38164 X    m_fd->mmap_addr = m_fd->mmap_base+m_fd->s_pos_arr[lpos];
38165 X  }
38166 X
38167 X  r_block = b_block = min((size_t)(seqm-seqp),m_fd->gcg_len);
38168 X  if (m_fd->gcg_binary) {
38169 X    r_block = (r_block+3)/4;
38170 X  }
38171 X
38172 X  cp=(unsigned char *)m_fd->mmap_addr; 
38173 X  if (!m_fd->gcg_binary) {
38174 X    r_fact = 1;
38175 X    r16_block = r_block/16;
38176 X    while (r16_block-- > 0) {
38177 X      *seqp++ = ap[*cp++];
38178 X      *seqp++ = ap[*cp++];
38179 X      *seqp++ = ap[*cp++];
38180 X      *seqp++ = ap[*cp++];
38181 X      *seqp++ = ap[*cp++];
38182 X      *seqp++ = ap[*cp++];
38183 X      *seqp++ = ap[*cp++];
38184 X      *seqp++ = ap[*cp++];
38185 X      *seqp++ = ap[*cp++];
38186 X      *seqp++ = ap[*cp++];
38187 X      *seqp++ = ap[*cp++];
38188 X      *seqp++ = ap[*cp++];
38189 X      *seqp++ = ap[*cp++];
38190 X      *seqp++ = ap[*cp++];
38191 X      *seqp++ = ap[*cp++];
38192 X      *seqp++ = ap[*cp++];
38193 X    }
38194 X    while (seqp<seq+r_block) *seqp++ = ap[*cp++];
38195 X  }
38196 X  else if (m_fd->gcg_binary) {
38197 X    r_fact = 4;
38198 X    r16_block = r_block/8;
38199 X    while(r16_block-- > 0) {
38200 X      stmp = *cp++;
38201 X      *seqp++ = gcg_bton[(stmp>>6) &3];
38202 X      *seqp++ = gcg_bton[(stmp>>4) &3];
38203 X      *seqp++ = gcg_bton[(stmp>>2) &3];
38204 X      *seqp++ = gcg_bton[(stmp) &3];
38205 X      stmp = *cp++;
38206 X      *seqp++ = gcg_bton[(stmp>>6) &3];
38207 X      *seqp++ = gcg_bton[(stmp>>4) &3];
38208 X      *seqp++ = gcg_bton[(stmp>>2) &3];
38209 X      *seqp++ = gcg_bton[(stmp) &3];
38210 X      stmp = *cp++;
38211 X      *seqp++ = gcg_bton[(stmp>>6) &3];
38212 X      *seqp++ = gcg_bton[(stmp>>4) &3];
38213 X      *seqp++ = gcg_bton[(stmp>>2) &3];
38214 X      *seqp++ = gcg_bton[(stmp) &3];
38215 X      stmp = *cp++;
38216 X      *seqp++ = gcg_bton[(stmp>>6) &3];
38217 X      *seqp++ = gcg_bton[(stmp>>4) &3];
38218 X      *seqp++ = gcg_bton[(stmp>>2) &3];
38219 X      *seqp++ = gcg_bton[(stmp) &3];
38220 X      stmp = *cp++;
38221 X      *seqp++ = gcg_bton[(stmp>>6) &3];
38222 X      *seqp++ = gcg_bton[(stmp>>4) &3];
38223 X      *seqp++ = gcg_bton[(stmp>>2) &3];
38224 X      *seqp++ = gcg_bton[(stmp) &3];
38225 X      stmp = *cp++;
38226 X      *seqp++ = gcg_bton[(stmp>>6) &3];
38227 X      *seqp++ = gcg_bton[(stmp>>4) &3];
38228 X      *seqp++ = gcg_bton[(stmp>>2) &3];
38229 X      *seqp++ = gcg_bton[(stmp) &3];
38230 X      stmp = *cp++;
38231 X      *seqp++ = gcg_bton[(stmp>>6) &3];
38232 X      *seqp++ = gcg_bton[(stmp>>4) &3];
38233 X      *seqp++ = gcg_bton[(stmp>>2) &3];
38234 X      *seqp++ = gcg_bton[(stmp) &3];
38235 X      stmp = *cp++;
38236 X      *seqp++ = gcg_bton[(stmp>>6) &3];
38237 X      *seqp++ = gcg_bton[(stmp>>4) &3];
38238 X      *seqp++ = gcg_bton[(stmp>>2) &3];
38239 X      *seqp++ = gcg_bton[(stmp) &3];
38240 X    }
38241 X
38242 X    while (seqp < seq+4*r_block) {
38243 X      stmp = *cp++;
38244 X      *seqp++ = gcg_bton[(stmp>>6) &3];
38245 X      *seqp++ = gcg_bton[(stmp>>4) &3];
38246 X      *seqp++ = gcg_bton[(stmp>>2) &3];
38247 X      *seqp++ = gcg_bton[(stmp) &3];
38248 X    }
38249 X  }
38250 X  if (r_fact * r_block >= m_fd->gcg_len) {
38251 X    *lcont = 0;
38252 X    m_fd->lpos++;
38253 X  }
38254 X  else {
38255 X    if (m_fd->gcg_binary) b_block = 4*r_block;
38256 X    m_fd->gcg_len -= b_block;
38257 X    (*lcont)++;
38258 X  }
38259 X
38260 X  seq[b_block] = EOSEQ;
38261 X  /*   if (b_block==0) return 1; else */
38262 X  return b_block;
38263 }
38264 X
38265 void lget_ann_m(struct lmf_str *lm_fd, char *libstr, int n_libstr);
38266 X
38267 int
38268 lgetlibm(unsigned char *seq,
38269 X        int maxs,
38270 X        char *libstr,
38271 X        int n_libstr,
38272 X        fseek_t *libpos,
38273 X        int *lcont,
38274 X        struct lmf_str *m_fd,
38275 X        long *l_off)
38276 {
38277 X  register unsigned char *cp, *seqp;
38278 X  register int *ap, lpos;
38279 X  unsigned char *seqm, *seqm1;
38280 X
38281 X  *l_off = 1;
38282 X
38283 X  seqp = seq;
38284 X  seqm = &seq[maxs-11];
38285 X  seqm1 = seqm-1;
38286 X
38287 X  lpos = m_fd->lpos;
38288 X  ap = m_fd->sascii;
38289 X
38290 X  if (*lcont==0) {
38291 X    if (lpos >= m_fd->max_cnt) return (-1);
38292 X
38293 X    if (n_libstr <= 21) {
38294 X      strncpy(libstr,m_fd->mmap_base+m_fd->d_pos_arr[lpos]+12,12);
38295 X      libstr[12]='\0';
38296 X    }
38297 X    else {
38298 X      lget_ann_m(m_fd,libstr,n_libstr);
38299 X    }
38300 X    *libpos = lpos;
38301 X
38302 X    m_fd->mmap_addr = m_fd->mmap_base+m_fd->s_pos_arr[lpos];
38303 X    cp = (unsigned char *)m_fd->mmap_addr;
38304 X  }
38305 X  else cp = (unsigned char *)m_fd->mmap_addr;
38306 X
38307 X  while (seqp<seqm1) {
38308 X    if (*cp=='/' && *(cp-1)=='\n') break;
38309 X    if ((*seqp++=ap[*cp++])<NA &&
38310 X       (*seqp++=ap[*cp++])<NA &&
38311 X       (*seqp++=ap[*cp++])<NA &&
38312 X       (*seqp++=ap[*cp++])<NA &&
38313 X       (*seqp++=ap[*cp++])<NA &&
38314 X       (*seqp++=ap[*cp++])<NA &&
38315 X       (*seqp++=ap[*cp++])<NA &&
38316 X       (*seqp++=ap[*cp++])<NA &&
38317 X       (*seqp++=ap[*cp++])<NA &&
38318 X       (*seqp++=ap[*cp++])<NA &&
38319 X       (*seqp++=ap[*cp++])<NA) continue;
38320 X    --seqp;
38321 X    if (*cp=='\n' && *(cp+1)==' ') cp += 11;
38322 X  }
38323 X
38324 X  if (seqp>=seqm1) {
38325 X    (*lcont)++;
38326 X    m_fd->mmap_addr = (char *)cp;
38327 X  }
38328 X  else {
38329 X    *lcont=0;
38330 X    m_fd->lpos++;
38331 X  }
38332 X
38333 X  *seqp = EOSEQ;
38334 X  return (int)(seqp-seq);
38335 }
38336 X
38337 void
38338 lget_ann_m(struct lmf_str *lm_fd, char *libstr, int n_libstr) {
38339 X  char *bp, *bp_gid, locus[120], desc[120], acc[120], ver[120];
38340 X
38341 X  /* copy in locus from lm_fd->lline */
38342 X  strncpy(locus,&lm_fd->mmap_addr[12],sizeof(locus));
38343 X  if ((bp=strchr(locus,' '))!=NULL) *(bp+1) = '\0';
38344 X
38345 X  /* get description */
38346 X  mgets(desc,sizeof(desc),lm_fd);
38347 X  while (desc[0]!='D' || desc[1]!='E' || strncmp(desc,"DEFINITION",10))
38348 X    mgets(desc,sizeof(desc),lm_fd);
38349 X  if ((bp = strchr(&desc[12],'\n'))!=NULL) *bp='\0';
38350 X
38351 X  /* get accession */
38352 X  mgets(acc,sizeof(acc),lm_fd);
38353 X  while (acc[0]!='A' || acc[1]!='C' || strncmp(acc,"ACCESSION",9)) {
38354 X    mgets(acc,sizeof(acc),lm_fd);
38355 X    if (acc[0]=='O' && acc[1]=='R' && strncmp(acc,"ORIGIN",6)==0)
38356 X      break;
38357 X  }
38358 X  if ((bp = strchr(&acc[12],'\n'))!=NULL) *bp='\0';
38359 X  if ((bp = strchr(&acc[12],' '))!=NULL) *bp='\0';
38360 X
38361 X  /* get version */
38362 X  mgets(ver,sizeof(ver),lm_fd);
38363 X  while (ver[0]!='V' || ver[1]!='E' || strncmp(ver,"VERSION",7)) {
38364 X    mgets(ver,sizeof(ver),lm_fd);
38365 X    if (ver[0]=='O' && ver[1]=='R' && strncmp(ver,"ORIGIN",6)==0)
38366 X      break;
38367 X  }
38368 X  if ((bp = strchr(&ver[12],'\n'))!=NULL) *bp='\0';
38369 X
38370 X      /* extract gi:123456 from version line */
38371 X  bp_gid = strchr(&ver[12],':');
38372 X  if (bp_gid != NULL) {
38373 X    if ((bp=strchr(bp_gid+1,' '))!=NULL) *bp='\0';
38374 X    bp_gid++;
38375 X  }
38376 X  if ((bp = strchr(&ver[12],' '))!=NULL) *bp='\0';
38377 X
38378 X      /* build up FASTA header line */
38379 X  if (bp_gid != NULL) {
38380 X    strncpy(libstr,"gi|",n_libstr-1);
38381 X    strncat(libstr,bp_gid,n_libstr-4);
38382 X    strncat(libstr,"|gb|",n_libstr-20);
38383 X  }
38384 X  else {libstr[0]='\0';}
38385 X
38386 X  /* if we have a version number, use it, otherwise accession, 
38387 X        otherwise locus/description */
38388 X
38389 X  if (ver[0]=='V') {
38390 X    strncat(libstr,&ver[12],n_libstr-1-strlen(libstr));
38391 X    strncat(libstr,"|",n_libstr-1-strlen(libstr));
38392 X  }
38393 X  else if (acc[0]=='A') {
38394 X    strncat(libstr,&acc[12],n_libstr-1-strlen(libstr));
38395 X    strncat(libstr," ",n_libstr-1-strlen(libstr));
38396 X  }
38397 X
38398 X  strncat(libstr,locus,n_libstr-1-strlen(libstr));
38399 X  strncat(libstr,&desc[11],n_libstr-1-strlen(libstr));
38400 X  libstr[n_libstr-1]='\0';
38401 }
38402 X
38403 void
38404 lranlibm(char *str,
38405 X        int cnt,
38406 X        fseek_t seek,
38407 X        char *libstr,
38408 X        struct lmf_str *m_fd)
38409 {
38410 X  char *bp, *llp;
38411 X  char acc[MAXLINE], desc[MAXLINE];
38412 X
38413 X  llp = m_fd->mmap_addr = m_fd->mmap_base + m_fd->d_pos_arr[seek];
38414 X
38415 X  lget_ann_m(m_fd,str,cnt);
38416 X
38417 X  str[cnt-1]='\0';
38418 X
38419 X  m_fd->lpos = seek;
38420 }
38421 X
38422 static int check_status=0;
38423 X
38424 void
38425 check_mmap(struct lmf_str *m_fd,long ntt) {
38426 X
38427 X  int i, seq_len, ok_stat;
38428 X  
38429 X  ok_stat = 1;
38430 X  if ( ++check_status > 5) return;
38431 X
38432 X  fprintf(stderr," ** checking %s %ld**\n", m_fd->lb_name,ntt);
38433 X  for (i=0; i<m_fd->max_cnt; i++) {
38434 X    seq_len = m_fd->d_pos_arr[i+1] - m_fd->s_pos_arr[i];
38435 X    if (seq_len < 0 || (seq_len > m_fd->max_len && seq_len > (m_fd->max_len*5)/4)) {
38436 X      fprintf(stderr,"%d:\t%ld\t%ld\t%ld\n",
38437 X             i,m_fd->d_pos_arr[i],m_fd->s_pos_arr[i],
38438 X             m_fd->d_pos_arr[i+1]-m_fd->s_pos_arr[i]);
38439 X      ok_stat=0;
38440 X    }
38441 X  }
38442 X  if (ok_stat) {
38443 X    if (check_status) fprintf(stderr," ** check_mmap OK %s %ld**\n",
38444 X                             m_fd->lb_name,ntt);
38445 X  }
38446 }
38447 X
38448 #ifdef DEBUG
38449 /*  C H K 3  --  Compute a type-3 Kermit block check.  */
38450 /*
38451 X Calculate the 16-bit CRC of a null-terminated string using a byte-oriented
38452 X tableless algorithm invented by Andy Lowry (Columbia University).  The
38453 X magic number 010201 is derived from the CRC-CCITT polynomial x^16+x^12+x^5+1.
38454 X Note - this function could be adapted for strings containing imbedded 0's
38455 X by including a length argument.
38456 */
38457 long
38458 crck(s,n)
38459 X    char *s; int n;
38460 {
38461 X    unsigned int c, q;
38462 X    long crc = 0;
38463 X
38464 X    while (n-->0) {
38465 X       c = *s++;
38466 X       /* if (parity)*/
38467 X       c &= 0177;
38468 X       q = (crc ^ c) & 017;            /* Low-order nibble */
38469 X       crc = (crc >> 4) ^ (q * 010201);
38470 X       q = (crc ^ (c >> 4)) & 017;     /* High order nibble */
38471 X       crc = (crc >> 4) ^ (q * 010201);
38472 X    }
38473 X    return(crc);
38474 }
38475 #endif
38476 SHAR_EOF
38477 chmod 0644 mmgetaa.c ||
38478 echo 'restore of mmgetaa.c failed'
38479 Wc_c="`wc -c < 'mmgetaa.c'`"
38480 test 21318 -eq "$Wc_c" ||
38481         echo 'mmgetaa.c: original size 21318, current size' "$Wc_c"
38482 fi
38483 # ============= ms1.aa ==============
38484 if test -f 'ms1.aa' -a X"$1" != X"-c"; then
38485         echo 'x - skipping ms1.aa (File already exists)'
38486 else
38487 echo 'x - extracting ms1.aa (Text)'
38488 sed 's/^X//' << 'SHAR_EOF' > 'ms1.aa' &&
38489 >test m1
38490 MPMIL,
38491 MLLEY,
38492 MGDAP,
38493 MDTRX,
38494 MLCYN
38495 SHAR_EOF
38496 chmod 0644 ms1.aa ||
38497 echo 'restore of ms1.aa failed'
38498 Wc_c="`wc -c < 'ms1.aa'`"
38499 test 43 -eq "$Wc_c" ||
38500         echo 'ms1.aa: original size 43, current size' "$Wc_c"
38501 fi
38502 # ============= msg.h ==============
38503 if test -f 'msg.h' -a X"$1" != X"-c"; then
38504         echo 'x - skipping msg.h (File already exists)'
38505 else
38506 echo 'x - extracting msg.h (Text)'
38507 sed 's/^X//' << 'SHAR_EOF' > 'msg.h' &&
38508 /* Concurrent read version */
38509 X
38510 /* $Name: fa_34_26_5 $ - $Id: msg.h,v 1.9 2006/03/17 18:34:59 wrp Exp $ */
38511 X
38512 /* Cube definitions */
38513 X
38514 #ifdef PVM_SRC
38515 #define FIRSTNODE       1
38516 #define FIRSTWORK       1
38517 #else
38518 #define FIRSTNODE       1
38519 #define FIRSTWORK       1
38520 #endif
38521 X
38522 #define MAXNOD          128
38523 #define ALLTYPES        -1
38524 #ifdef IPSC2
38525 #define HOSTPID         99
38526 #define MANAGEPID       100
38527 #define WORKPID         101
38528 #else
38529 #define HOSTPID         0
38530 #define MANAGEPID       0
38531 #define WORKPID         0
38532 #endif
38533 #define MANAGER         0
38534 #define ALLNODES        -1
38535 #define ALLPIDS         -1
38536 #define STARTTYPE0      0
38537 #define STARTTYPE1      1
38538 #define STARTTYPE2      2
38539 #define STARTTYPE3      3
38540 #define STARTTYPE4      4
38541 #define STARTTYPE5      5
38542 #define STARTTYPE6      6
38543 #define PARAMTYPE       7
38544 #define HSEQTYPE        3
38545 #define MSEQTYPE        4
38546 #define ONETYPE         5
38547 #define TWOTYPE         6
38548 #define MSEQTYPE0       7
38549 #define MSEQTYPE1       8
38550 #define MSEQTYPE2       8
38551 #define LISTTYPE        10
38552 #define LISTRTYPE       11
38553 #define CODERTYPE       12
38554 #define ALN1TYPE        21
38555 #define ALN2TYPE        22
38556 #define ALN3TYPE        23
38557 #define FINISHED        16384   /* this must be larger than BFR */
38558 X
38559 #define DO_SEARCH_FLG 0
38560 #define DO_OPT_FLG 1
38561 #define DO_ALIGN_FLG 2
38562 #define DO_CALC_FLG 3
38563 SHAR_EOF
38564 chmod 0644 msg.h ||
38565 echo 'restore of msg.h failed'
38566 Wc_c="`wc -c < 'msg.h'`"
38567 test 1085 -eq "$Wc_c" ||
38568         echo 'msg.h: original size 1085, current size' "$Wc_c"
38569 fi
38570 # ============= mshowalign.c ==============
38571 if test -f 'mshowalign.c' -a X"$1" != X"-c"; then
38572         echo 'x - skipping mshowalign.c (File already exists)'
38573 else
38574 echo 'x - extracting mshowalign.c (Text)'
38575 sed 's/^X//' << 'SHAR_EOF' > 'mshowalign.c' &&
38576 X
38577 /* copyright (c) 1996, 1997, 1998, 1999 William R. Pearson and the
38578 X   U. of Virginia */
38579 X
38580 /* $Name: fa_34_26_5 $ - $Id: mshowalign.c,v 1.43 2007/01/08 15:38:46 wrp Exp $ */
38581 X
38582 /* mshowalign.c - show sequence alignments in pvcomplib */
38583 X
38584 /* 
38585 X   this is a merged version of showalign.c that works properly with
38586 X   both the comp_lib (serial, threaded) and PCOMPLIB parallel versions
38587 X   of the programs.
38588 X
38589 X   In the serial and current threaded versions of the programs,
38590 X   showalign gets a list of high scoring sequences and must
38591 X   re_getlib() the sequence, do_walign(), and then calculate the
38592 X   alignment.
38593 X
38594 X   In the PCOMPLIB parallel versions, the worker programs do the
38595 X   aligning, so showalign() must send them the appropriate messages to
38596 X   have the alignment done, and then collect the alignment results
38597 X
38598 */
38599 X
38600 #include <stdio.h>
38601 #include <stdlib.h>
38602 #include <string.h>
38603 X
38604 #include "defs.h"
38605 #include "msg.h"
38606 #include "structs.h"
38607 #include "param.h"
38608 X
38609 #ifdef PCOMPLIB
38610 #ifdef PVM_SRC
38611 #include "pvm3.h"
38612 extern int pinums[];
38613 #endif
38614 #ifdef MPI_SRC
38615 #include "mpi.h"
38616 #endif
38617 #include "p_mw.h"
38618 #else
38619 #include "mm_file.h"
38620 #include "mw.h"
38621 #endif
38622 X
38623 #ifndef PCOMPLIB
38624 X
38625 /* used to position the library sequence for re_getlib - also gets
38626 X   description */
38627 #define RANLIB (m_fptr->ranlib)
38628 X
38629 extern struct lmf_str *
38630 re_openlib(struct lmf_str *, int outtty);
38631 X
38632 int
38633 re_getlib(unsigned char *aa1, int maxn, int maxt,
38634 X         int loff, int cont, int term_code,
38635 X         long *loffset, long *l_off, 
38636 X         struct lmf_str *m_fptr);
38637 X
38638 #include "drop_func.h"
38639 X
38640 #endif
38641 X
38642 X
38643 extern void cal_coord(int n0, int n1, long sq0off, long loffset,
38644 X                     struct a_struct *aln);
38645 X
38646 void initseq(char **, char **, char **, char **, int);
38647 void freeseq(char **, char **, char **, char **);
38648 X
38649 void do_show(FILE *fp, int n0, int n1, int score,
38650 X            char *name0, char *name1, int nml,
38651 X            struct mngmsg m_msg, struct pstruct pst,
38652 X            char *seqc0, char *seqc0a,  char *seqc1, char *seqca, int nc,
38653 X            float percent, float gpercent, int lc,
38654 X            struct a_struct *aln, long loffset);
38655 X
38656 extern void discons(FILE *fd, struct mngmsg m_msg, struct pstruct pst,
38657 X                   char *seqc0, char *seqc0a, char *seqc1, char *seqca,
38658 X                   int nc, 
38659 X                   int n0, int n1, char *name0, char *name1, int nml,
38660 X                   struct a_struct *aln,
38661 X                   long loffset);
38662 X
38663 extern void disgraph(FILE *fd, int n0, int n1,
38664 X                    float percent, int score,
38665 X                    int min0, int min1, int max0, int max1, long sq0off,
38666 X                    char *name0, char *name1, int nml, int llen, int markx);
38667 X
38668 extern double zs_to_bit(double, int, int);
38669 X
38670 extern void
38671 do_url1(FILE *, struct mngmsg, struct pstruct,  char *, int,
38672 X       struct a_struct , long);
38673 X
38674 #ifndef A_MARK
38675 #define A_MARK ">>"
38676 #endif
38677 X
38678 static char l_name[200];        /* link name */
38679 X
38680 #ifdef PCOMPLIB
38681 #define BBP_INFO(info) bbp->desptr->info
38682 #else
38683 #define BBP_INFO(info) bbp->info
38684 #endif
38685 X
38686 /* this version does not check for m_msg.e_cut because nshow/nbest has
38687 X   already been set to limit on e_cut */
38688 X
38689 void showalign (FILE *fp,
38690 #ifndef PCOMPLIB
38691 X               unsigned char **aa0, unsigned char *aa1, int maxn,
38692 #endif
38693 X               struct beststr **bptr, int nbest, int qlib, 
38694 X               struct mngmsg m_msg, struct pstruct pst, char *gstring2
38695 #ifndef PCOMPLIB
38696 X               , void **f_str
38697 #endif
38698 )
38699 {
38700 X  char tmp_str[20];
38701 X  char info_str[200];
38702 X  char bline[2048], *bl_ptr, *bp, fmt[40];
38703 X  int tmp_len, l_llen;
38704 X  int t_have_ares;
38705 X  char name0[80], name0s[80], name1[200];
38706 X  int istart = 0, istop, i = 0, ib, nml;
38707 X  int  n1tot;
38708 X  struct beststr *bbp;
38709 X  int nc, lc, maxc;
38710 X  float percent, gpercent;
38711 X  char *seqc0, *seqc0a, *seqc1, *seqca;
38712 X  long loffset, l_off;
38713 #ifdef PCOMPLIB
38714 X  struct stage2_str liblist;
38715 X  struct qmng_str qm_msg;
38716 #ifdef MPI_SRC
38717 X  int int_msg_b[10];
38718 X  MPI_Status mpi_status;
38719 #endif
38720 #else
38721 X  int n1;
38722 X  struct lmf_str *m_fptr;
38723 X  int ngap;
38724 #endif
38725 X
38726 #ifdef PCOMPLIB
38727 X  /* this function has its own copy of qm_msg, so we must fill it
38728 X     appropriately */
38729 X  qm_msg.n0 = m_msg.n0;
38730 X  strncpy(qm_msg.libstr,m_msg.qtitle,sizeof(qm_msg.libstr));
38731 #endif
38732 X
38733 X  /* set the name0,1 label length */
38734 X  if (m_msg.markx & MX_M10FORM) nml = 12;
38735 X  else nml = m_msg.nmlen;
38736 X
38737 X  if (strlen(m_msg.qtitle) > 0) {
38738 X    if (m_msg.qtitle[0]=='>') strncpy(name0s,&m_msg.qtitle[1],sizeof(name0s));
38739 X    else strncpy(name0s,m_msg.qtitle,sizeof(name0s));
38740 X  }
38741 X  else {
38742 X    strncpy(name0s,m_msg.tname,sizeof(name0s));
38743 X  }
38744 X  name0s[sizeof(name0s)-1]='\0';
38745 X
38746 X  if ((bp=strchr(name0s,' '))!=NULL) *bp='\0';
38747 X
38748 X  if (m_msg.revcomp) name0[nml-1]='-';
38749 X
38750 X  l_llen = m_msg.aln.llen;
38751 X  if ((m_msg.markx & MX_M9SUMM) && m_msg.show_code != SHOW_CODE_ID) {
38752 X    l_llen += 40;
38753 X    if (l_llen > 200) l_llen=200;
38754 X  }
38755 X
38756 X  sprintf(fmt,"%s%%-%ds (%%d %s)\n",A_MARK,l_llen-5,m_msg.sqnam);
38757 X
38758 X  if (!(m_msg.markx&MX_M10FORM)) fprintf(fp,"\n");
38759 X
38760 X  if (m_msg.ashow < 0) m_msg.ashow = m_msg.nshow;
38761 X  istart = 0; istop = min(min(nbest,m_msg.ashow),m_msg.nshow);
38762 X
38763 X  for (ib=istart; ib<istop; ib++) {
38764 X    bbp = bptr[ib];
38765 X
38766 #ifdef SHOWUN
38767 X    if (BBP_INFO(nsfnum) > 0 && sfn_cmp(m_msg.qsfnum,BBP_INFO(sfnum))) {
38768 X      istop = min(istop+1,nbest);
38769 X      continue;
38770 X    }
38771 #endif
38772 X    if (bbp->score[0] <= 0) break;
38773 X
38774 X    if (m_msg.quiet==1 && pst.zsflag>=0 
38775 X       && bbp->escore < m_msg.e_low) continue;
38776 X
38777 #ifndef PCOMPLIB
38778 X    /* get the alignment and score by re-aligning */
38779 X
38780 X    if ((m_fptr=re_openlib(bbp->m_file_p,!m_msg.quiet))==NULL)
38781 X      exit(1);
38782 X
38783 X    /* get the description - do not "edit" it yet */
38784 X
38785 X    if (!(m_msg.markx & MX_M10FORM)){
38786 X      if (m_msg.long_info) {tmp_len = sizeof(bline)-1;}
38787 X      else {tmp_len = l_llen-5;}
38788 X      RANLIB(bline,tmp_len,bbp->lseek,bbp->libstr,bbp->m_file_p);
38789 X      bline[tmp_len]='\0';
38790 X    }
38791 X    else {
38792 X      RANLIB(bline,sizeof(bline),bbp->lseek,bbp->libstr,bbp->m_file_p);
38793 X      bline[sizeof(bline)-1]='\0';
38794 X    }
38795 X
38796 X    n1 = re_getlib(aa1,maxn,m_msg.maxt3,m_msg.loff,bbp->cont,m_msg.term_code,
38797 X                  &loffset,&l_off,bbp->m_file_p);
38798 #ifdef DEBUG
38799 X    if (n1 != bbp->n1) {
38800 X      fprintf(stderr," library sequence: %s lengths differ: %d != %d\n",
38801 X             bline,bbp->n1, n1);
38802 X      fprintf(stderr, "offset is: %lld\n",bbp->lseek);
38803 X    }
38804 #endif
38805 X
38806 X    if (!bbp->have_ares) {
38807 X      bbp->sw_score = 
38808 X       do_walign(aa0[bbp->frame],m_msg.n0, aa1, n1, bbp->frame, &pst,
38809 X                 f_str[bbp->frame], &bbp->a_res, &t_have_ares);
38810 X    }
38811 X    else {
38812 X      pre_cons(aa1,n1,bbp->frame,f_str[bbp->frame]);
38813 X    }
38814 X
38815 X    aln_func_vals(bbp->frame, &m_msg.aln);
38816 X
38817 #else   /* PCOMPLIB - get the alignment information from a worker */
38818 X
38819 X    /* we have a sequence that we need an alignment for -
38820 X       send a message to the appropriate worker to produce an alignment 
38821 X       qm_msg.slist == 1  -> one alignment
38822 X       qm_msg.s_func == DO_ALIGN_FLG -> use the alignment function
38823 X       send mngmsg (MSEQTYPE)
38824 X       then send number of sequence to be aligned
38825 X    */
38826 X
38827 X    qm_msg.slist = 1;
38828 X    qm_msg.s_func = DO_ALIGN_FLG;
38829 X
38830 X    liblist.seqnm = bbp->seqnm;
38831 X    liblist.frame = bbp->frame;
38832 #ifdef PVM_SRC
38833 X    pvm_initsend(PvmDataRaw);
38834 X    pvm_pkbyte((char *)&qm_msg,sizeof(struct qmng_str),1);
38835 X    pvm_send(pinums[bbp->wrkr],MSEQTYPE);
38836 X
38837 X    pvm_initsend(PvmDataRaw);
38838 X    pvm_pkbyte((char *)&liblist,sizeof(struct stage2_str),1);
38839 X    pvm_send(pinums[bbp->wrkr],LISTTYPE);
38840 #endif
38841 #ifdef MPI_SRC
38842 X    MPI_Send(&qm_msg,sizeof(struct qmng_str),MPI_BYTE,bbp->wrkr,
38843 X            MSEQTYPE,MPI_COMM_WORLD);
38844 X    MPI_Send(&liblist,sizeof(struct stage2_str),MPI_BYTE,bbp->wrkr,
38845 X            LISTTYPE,MPI_COMM_WORLD);
38846 #endif
38847 X    /* information should be sent */
38848 X    /* pick up description */
38849 X    strncpy(bline,bbp->desptr->bline,l_llen-5);
38850 X    bline[l_llen-5]='\0';
38851 #endif  /* PCOMPLIB */
38852 X
38853 X    if (strlen(bline)==0) {
38854 X      bline[0]='>';
38855 X      strncpy(&bline[1],m_msg.lname,l_llen-5);
38856 X      bline[l_llen-5]='\0';
38857 X    }
38858 X    /* re-format bline */
38859 X    while ((bp=strchr(bline,'\n'))!=NULL) *bp=' ';
38860 X    if (m_msg.long_info) {
38861 X      tmp_len = strlen(bline);
38862 X      bl_ptr = bline;
38863 X      if (!(m_msg.markx & MX_M10FORM)) while (tmp_len > l_llen) {
38864 X       for (i=l_llen; i>10; i--)
38865 X         if (bl_ptr[i]==' ') {
38866 X           bl_ptr[i]='\n';
38867 X           break;
38868 X         }
38869 X       if (i <= 10) break;
38870 X       tmp_len -= i;
38871 X       bl_ptr += i;
38872 X      }
38873 X      bline[sizeof(bline)-1]='\0';
38874 X    }
38875 X
38876 X    n1tot = (BBP_INFO(n1tot_p)) ? *BBP_INFO(n1tot_p) : bbp->n1;
38877 X
38878 X    strncpy(name1,bline,sizeof(name1));
38879 X
38880 X    if ((!m_msg.markx & MX_M10FORM)) name1[nml]='\0';
38881 X    if ((bp = strchr(name1,' '))!=NULL) *bp = '\0';
38882 X
38883 X  /* l_name is used to build an HTML link from the bestscore line to
38884 X     the alignment.  It can also be used to discriminate multiple hits
38885 X     from the same long sequence.  Text must match that in showbest.c */
38886 X
38887 X    strncpy(name1,bline,sizeof(name1));
38888 X    name1[sizeof(name1)-1]='\0';
38889 X    if ((bp = strchr(name1,' '))!=NULL) *bp = '\0';
38890 X    strncpy(l_name,name1,sizeof(l_name));
38891 X    l_name[sizeof(l_name)-1]='\0';
38892 X    if ((bp=strchr(&l_name[3],'|'))!=NULL) *bp='\0';
38893 X    if (m_msg.nframe > 2) sprintf(&l_name[strlen(l_name)],"_%d",bbp->frame+1);
38894 X    else if (m_msg.qframe >= 0 && bbp->frame == 1)
38895 X      strncat(l_name,"_r",sizeof(l_name));
38896 X    if (bbp->cont-1 > 0) {
38897 X      sprintf(tmp_str,":%d",bbp->cont-1);
38898 X      strncat(l_name,tmp_str,sizeof(l_name)-strlen(l_name));
38899 X    }
38900 X
38901 X    if (!(m_msg.markx & MX_M10FORM)) name1[nml]='\0';
38902 X
38903 X    /* print out score information; */
38904 X
38905 X    if (m_msg.markx & MX_HTML ) {
38906 X      fprintf (fp,"<A name=%s>\n<tt><pre>\n",l_name);
38907 X    }
38908 X    strncpy(name0,name0s,nml);
38909 X    name0[nml]='\0';
38910 X
38911 X    if (pst.zsflag%10 == 6) {
38912 X      sprintf(info_str," comp: %.5f H: %.5f",bbp->comp,bbp->H);
38913 X    }
38914 X    else info_str[0]='\0';
38915 X
38916 X    if ((m_msg.markx & MX_ATYPE)!=7 && !(m_msg.markx & MX_M10FORM)) {
38917 X      fprintf (fp, fmt,bp=bline,n1tot);
38918 X      if (m_msg.nframe > 2) 
38919 X       fprintf (fp, "Frame: %d",bbp->frame+1);
38920 X      else if (m_msg.nframe > 1) 
38921 X       fprintf (fp, "Frame: %c",(bbp->frame? 'r': 'f'));
38922 X      else if (m_msg.qframe >= 0 && bbp->frame > 0 ) {
38923 X         fputs("rev-comp",fp);
38924 X         name0[nml-1]='\0';
38925 X         strcat(name0,"-");
38926 X      }
38927 X
38928 X      if (m_msg.arelv > 0)
38929 X       fprintf (fp, " %s: %3d", m_msg.alab[0],bbp->score[0]);
38930 X      if (m_msg.arelv > 1)
38931 X       fprintf (fp, " %s: %3d", m_msg.alab[1],bbp->score[1]);
38932 X      if (m_msg.arelv > 2)
38933 X       fprintf (fp, " %s: %3d", m_msg.alab[2],bbp->score[2]);
38934 X      fprintf(fp,"%s",info_str);
38935 X      if (pst.zsflag>=0) 
38936 X       fprintf (fp, "  Z-score: %4.1f  bits: %3.1f E(): %4.2g", 
38937 X                bbp->zscore,zs_to_bit(bbp->zscore,m_msg.n0,bbp->n1),bbp->escore);
38938 X      fprintf (fp, "\n");
38939 X    }
38940 X    else if (m_msg.markx & MX_M10FORM) {
38941 X      fprintf(fp,">>%s\n",bline);
38942 X      if (m_msg.qframe > -1) {
38943 X       if (m_msg.nframe > 2) {
38944 X         fprintf(fp,"; %s_frame: %d\n",m_msg.f_id0,bbp->frame+1);
38945 X       }
38946 X       else {
38947 X         fprintf(fp,"; %s_frame: %c\n",m_msg.f_id0,(bbp->frame > 0? 'r':'f'));
38948 X       }
38949 X      }
38950 X      fprintf (fp, "; %s_%s: %3d\n", m_msg.f_id0,m_msg.alab[0],bbp->score[0]);
38951 X      if (m_msg.arelv > 1)
38952 X       fprintf (fp,"; %s_%s: %3d\n", m_msg.f_id0,m_msg.alab[1],bbp->score[1]);
38953 X      if (m_msg.arelv > 2)
38954 X       fprintf (fp,"; %s_%s: %3d\n", m_msg.f_id0,m_msg.alab[2],bbp->score[2]);
38955 X      if (info_str[0]) fprintf(fp,"; %s_info: %s\n",m_msg.f_id0,info_str);
38956 X      if (pst.zsflag>=0) 
38957 X     fprintf (fp,"; %s_z-score: %4.1f\n; %s_bits: %3.1f\n; %s_expect: %6.2g\n",
38958 X             m_msg.f_id0,bbp->zscore,
38959 X             m_msg.f_id0,zs_to_bit(bbp->zscore,m_msg.n0,bbp->n1),
38960 X             m_msg.f_id0,bbp->escore);
38961 X    }
38962 X      
38963 X
38964 #ifdef PCOMPLIB
38965 X    /*  get the sw_score, alignment  information,  get seqc0, seqc1 */
38966 X
38967 #ifdef PVM_SRC
38968 X    /* get alignment lengths, percents */
38969 X    pvm_recv(pinums[bbp->wrkr],ALN1TYPE);
38970 X    pvm_upkint(&nc,1,1);
38971 X    pvm_upkint(&lc,1,1);
38972 X    pvm_upkint(&maxc,1,1);
38973 X
38974 X    pvm_upkfloat(&percent,1,1);
38975 X    pvm_upkfloat(&gpercent,1,1);
38976 X
38977 X    pvm_upkint(&bbp->sw_score,1,1);
38978 X    pvm_upkbyte((char *)&m_msg.aln,sizeof(struct a_struct),1);
38979 X
38980 X    initseq(&seqc0, &seqc0a, &seqc1, &seqca, maxc);
38981 X
38982 X    pvm_recv(pinums[bbp->wrkr],ALN2TYPE);
38983 X    pvm_upkbyte(seqc0,maxc,1);
38984 X    if (m_msg.ann_flg) pvm_upkbyte(seqc0a,maxc,1);
38985 X    pvm_upkbyte(seqc1,maxc,1);
38986 X    pvm_upkbyte(seqca,maxc,1);
38987 #endif
38988 #ifdef MPI_SRC
38989 X    MPI_Recv(int_msg_b,4,MPI_INT,bbp->wrkr,ALN1TYPE,MPI_COMM_WORLD,
38990 X            &mpi_status);
38991 X    nc = int_msg_b[0];
38992 X    lc = int_msg_b[1];
38993 X    maxc = int_msg_b[2];
38994 X    bbp->sw_score = int_msg_b[3];
38995 X    MPI_Recv(&percent,1,MPI_FLOAT,bbp->wrkr,ALN2TYPE,MPI_COMM_WORLD,
38996 X            &mpi_status);
38997 X    MPI_Recv(&gpercent,1,MPI_FLOAT,bbp->wrkr,ALN2TYPE,MPI_COMM_WORLD,
38998 X            &mpi_status);
38999 X    MPI_Recv(&m_msg.aln,sizeof(struct a_struct),MPI_BYTE,
39000 X            bbp->wrkr,ALN3TYPE,MPI_COMM_WORLD,&mpi_status);
39001 X
39002 X    initseq(&seqc0, &seqc0a, &seqc1, &seqca, maxc);
39003 X    MPI_Recv(seqc0,maxc,MPI_BYTE,bbp->wrkr,ALN2TYPE,MPI_COMM_WORLD,&mpi_status);
39004 X    if (m_msg.ann_flg)
39005 X      MPI_Recv(seqc0a,maxc,MPI_BYTE,bbp->wrkr,ALN2TYPE,MPI_COMM_WORLD,&mpi_status);
39006 X    MPI_Recv(seqc1,maxc,MPI_BYTE,bbp->wrkr,ALN3TYPE,MPI_COMM_WORLD,&mpi_status);
39007 X    MPI_Recv(seqca,maxc,MPI_BYTE,bbp->wrkr,ALN3TYPE,MPI_COMM_WORLD,&mpi_status);
39008 #endif
39009 X
39010 X    /* l_off is the coordinate of the first residue */
39011 X    l_off = 1;
39012 X    /* loffset is the offset of the aa1 in the full sequence */
39013 X    loffset = bbp->desptr->loffset-l_off;
39014 X
39015 #else   /* not PCOMPLIB */
39016 X
39017 X    /* estimate space for alignment consensus */
39018 X    if (m_msg.aln.showall==1) {
39019 X      maxc = bbp->a_res.nres + max(bbp->a_res.min0,bbp->a_res.min1)+
39020 X       max((m_msg.n0-bbp->a_res.max0),(n1-bbp->a_res.max1))+4;
39021 X    }
39022 X    else {
39023 X      maxc = bbp->a_res.nres + 4*m_msg.aln.llen+4;
39024 X    }
39025 X
39026 X    /* get space to put the sequence alignment consensus */
39027 X    initseq(&seqc0, &seqc0a, &seqc1, &seqca, maxc);
39028 X
39029 X    /* build consensus from res, nres (done by workers if PCOMPLIB) */
39030 X    if (!m_msg.ann_flg) {
39031 X      nc=calcons(aa0[bbp->frame],m_msg.n0,aa1,n1,
39032 X                &lc,&m_msg.aln, bbp->a_res, pst, seqc0, seqc1, seqca,
39033 X                f_str[bbp->frame]);
39034 X      memset(seqc0a,' ',nc);
39035 X      seqc0a[nc]='\0';
39036 X    }
39037 X    else {
39038 X      nc=calcons_a(aa0[bbp->frame],m_msg.aa0a,m_msg.n0,aa1,n1,
39039 X                  &lc,&m_msg.aln,bbp->a_res,pst, seqc0, seqc0a, 
39040 X                  seqc1, seqca, m_msg.ann_arr,f_str[bbp->frame]);
39041 X    }
39042 X
39043 X    /* PCOMPLIB workers return percent, gpercent, so calculate it here */
39044 X    if (lc > 0) percent = (100.0*(float)m_msg.aln.nident)/(float)lc;
39045 X    else percent = -1.00;
39046 X    ngap = m_msg.aln.ngap_q + m_msg.aln.ngap_l;
39047 #ifndef SHOWSIM
39048 X    if (lc-ngap> 0) gpercent =(100.0*(float)m_msg.aln.nident)/(float)(lc-ngap);
39049 #else
39050 X    if (lc > 0) gpercent =(100.0*(float)m_msg.aln.nsim)/(float)lc;
39051 #endif
39052 X    else gpercent = -1.00;
39053 #endif
39054 X
39055 X    if (max(strlen(seqc0),strlen(seqc1)) > nc) {
39056 X      fprintf(stderr," mshowalign: nc/maxc: %d/%d seqc0/1: %u/%u\n",
39057 X             nc,maxc,strlen(seqc0),strlen(seqc1));
39058 X    }
39059 X
39060 X    /* here PCOMPLIB/comp_lib logic is the same */
39061 X
39062 #ifdef DEBUG
39063 X    if (bbp->sw_score < bbp->score[pst.score_ix]) {
39064 X      fprintf(stderr," *** warning - SW score=%d < opt score=%d ***\n",
39065 X             bbp->sw_score, bbp->score[pst.score_ix]);
39066 X    }
39067 #endif
39068 X
39069 X    cal_coord(m_msg.n0,bbp->n1,m_msg.sq0off,loffset+l_off-1,&m_msg.aln);
39070 X
39071 #ifndef PCOMPLIB
39072 X    if (bbp->a_res.nres > 0)
39073 #endif
39074 X      do_show(fp, m_msg.n0, bbp->n1, bbp->sw_score, name0, name1, nml,
39075 X             m_msg, pst, seqc0, seqc0a, seqc1, seqca,
39076 X             nc, percent, gpercent, lc, &m_msg.aln,
39077 X             loffset+l_off-1);
39078 X
39079 X    if (m_msg.markx & MX_HTML) fprintf(fp,"</pre></tt>\n<hr>\n");
39080 X    fflush(fp);
39081 X
39082 X    freeseq(&seqc0,&seqc0a,&seqc1, &seqca);
39083 X  }
39084 X  if (fp!=stdout) fprintf(fp,"\n");
39085 }
39086 X
39087 void do_show(FILE *fp, int n0,int n1, int score,
39088 X            char *name0, char *name1, int nml,
39089 X            struct mngmsg m_msg, struct pstruct pst,
39090 X            char *seqc0, char *seqc0a,  char *seqc1, char *seqca, int nc,
39091 X            float percent, float gpercent, int lc,
39092 X            struct a_struct *aln, long loffset)
39093 {
39094 X  int tmp;
39095 X
39096 X  if (m_msg.markx & MX_AMAP && (m_msg.markx & MX_ATYPE)==7)
39097 X    disgraph(fp, n0, n1, percent, score,
39098 X            aln->amin0, aln->amin1, aln->amax0, aln->amax1, m_msg.sq0off,
39099 X            name0, name1, nml, aln->llen, m_msg.markx);
39100 X  else if (m_msg.markx & MX_M10FORM) {
39101 X    if (pst.sw_flag && m_msg.arelv>0)
39102 X      fprintf(fp,"; %s_score: %d\n",m_msg.f_id1,score);
39103 X    fprintf(fp,"; %s_ident: %5.3f\n",m_msg.f_id1,percent/100.0);
39104 #ifndef SHOWSIM
39105 X    fprintf(fp,"; %s_gident: %5.3f\n",m_msg.f_id1,gpercent/100.0);
39106 #else
39107 X    fprintf(fp,"; %s_sim: %5.3f\n",m_msg.f_id1,gpercent/100.0);
39108 #endif
39109 X
39110 X    fprintf(fp,"; %s_overlap: %d\n",m_msg.f_id1,lc);
39111 X    discons(fp, m_msg, pst, seqc0, seqc0a, seqc1, seqca, nc,
39112 X           n0, n1, name0, name1, nml, aln, loffset);
39113 X  }
39114 X  else {
39115 X    if (pst.sw_flag) fprintf(fp,"Smith-Waterman score: %d; ",score);
39116 X    else fprintf(fp,"banded Smith-Waterman score: %d; ",score);
39117 #ifndef SHOWSIM
39118 X    fprintf(fp," %6.3f%% identity (%6.3f%% ungapped) in %d %s overlap (%ld-%ld:%ld-%ld)\n",
39119 X           percent,gpercent,lc,m_msg.sqnam,aln->d_start0,aln->d_stop0,
39120 X           aln->d_start1,aln->d_stop1);
39121 #else
39122 X    fprintf(fp," %6.3f%% identity (%6.3f%% similar) in %d %s overlap (%ld-%ld:%ld-%ld)\n",
39123 X           percent,gpercent,lc,m_msg.sqnam,aln->d_start0,aln->d_stop0,
39124 X           aln->d_start1,aln->d_stop1);
39125 #endif
39126 X
39127 X    if (m_msg.markx & MX_HTML) {
39128 X      do_url1(fp, m_msg, pst, l_name,n1,*aln,loffset);
39129 X    }
39130 X
39131 X    if (m_msg.markx & MX_AMAP && (m_msg.markx & MX_ATYPE)!=7) {
39132 X      fputc('\n',fp);
39133 X      tmp = n0;
39134 X
39135 X      if (m_msg.qdnaseq == SEQT_DNA && m_msg.ldnaseq== SEQT_PROT)
39136 X       tmp /= 3;
39137 X
39138 X      disgraph(fp, tmp, n1, percent, score,
39139 X              aln->amin0, aln->amin1,
39140 X              aln->amax0, aln->amax1,
39141 X              m_msg.sq0off,
39142 X              name0, name1, nml, aln->llen,m_msg.markx);
39143 X    }
39144 X
39145 X    discons(fp, m_msg, pst, seqc0, seqc0a, seqc1, seqca, nc,
39146 X           n0, n1, name0, name1, nml, aln, loffset);
39147 X
39148 X    fputc('\n',fp);
39149 X
39150 X  }
39151 }
39152 X
39153 X
39154 #ifndef MPI_SRC
39155 void    /* initialize consensus arrays */
39156 initseq(char **seqc0, char **seqc0a, char **seqc1, char **seqca, int seqsiz)
39157 {
39158 X  *seqc0=(char *)calloc((size_t)seqsiz*4,sizeof(char));
39159 X  if (*seqc0==NULL)
39160 X    {fprintf(stderr,"cannot allocate consensus arrays %d\n",seqsiz);
39161 X     exit(1);}
39162 X  *seqc0a=*seqc0 + seqsiz;
39163 X  *seqc1=*seqc0a + seqsiz;
39164 X  *seqca=*seqc1 + seqsiz;
39165 }
39166 X
39167 void freeseq(char **seqc0, char **seqc0a, char **seqc1, char **seqca)
39168 {
39169 X  free(*seqc0);
39170 }
39171 #endif
39172 SHAR_EOF
39173 chmod 0644 mshowalign.c ||
39174 echo 'restore of mshowalign.c failed'
39175 Wc_c="`wc -c < 'mshowalign.c'`"
39176 test 17780 -eq "$Wc_c" ||
39177         echo 'mshowalign.c: original size 17780, current size' "$Wc_c"
39178 fi
39179 # ============= mshowbest.c ==============
39180 if test -f 'mshowbest.c' -a X"$1" != X"-c"; then
39181         echo 'x - skipping mshowbest.c (File already exists)'
39182 else
39183 echo 'x - extracting mshowbest.c (Text)'
39184 sed 's/^X//' << 'SHAR_EOF' > 'mshowbest.c' &&
39185 X
39186 /* copyright (c) 1996, 1997, 1998, 1999 William R. Pearson and the
39187 X   U. of Virginia */
39188 X
39189 /* $Name: fa_34_26_5 $ - $Id: mshowbest.c,v 1.44 2006/06/30 19:46:36 wrp Exp $ */
39190 X
39191 /*   29-Oct-2003 - changes so that bbp->cont < 0 => aa1 sequence is
39192 X     already in aa1, no re_openlib or re_getlib required
39193 */
39194 X
39195 /*   14-May-2003 Changes to use a more consistent coordinate numbering
39196 X     system for displays.  aln->d_start[01] is now consistently used
39197 X     to report the start of the alignment in all functions, and
39198 X     mshowbest.c has been modified to use d_start[01] instead of
39199 X     d_start[01]-1.  aln->min[01] now starts at 0 for all functions;
39200 X     instead of 1 for some functions (dropnfa.c, dropgsw.c, dropfs2.c
39201 X     earlier).
39202 */
39203 X
39204 #include <stdio.h>
39205 #include <stdlib.h>
39206 #include <string.h>
39207 X
39208 #include "defs.h"
39209 #include "structs.h"
39210 #include "param.h"
39211 X
39212 #ifndef PCOMPLIB
39213 #include "mm_file.h"
39214 #include "mw.h"
39215 #else
39216 #include "p_mw.h"
39217 #endif
39218 X
39219 X
39220 #define MAX_BLINE 256
39221 X
39222 #ifndef PCOMPLIB
39223 /* function calls necessary to re_getlib() the sequence and, do
39224 X   alignments, if necessary
39225 */
39226 X
39227 #define RANLIB (m_fptr->ranlib)
39228 X
39229 int
39230 re_getlib(unsigned char *, int, int, int, int, int, long *, long *, 
39231 X         struct lmf_str *m_fptr);
39232 X
39233 #include "drop_func.h"
39234 X
39235 struct lmf_str *re_openlib(struct lmf_str *, int outtty);
39236 #endif
39237 X
39238 extern void cal_coord(int n0, int n1, long sq0off, long loffset,
39239 X                     struct a_struct *aln);
39240 X
39241 void header_aux(FILE *);
39242 void show_aux(FILE *, struct beststr *);
39243 void w_abort (char *p, char *p1);
39244 X
39245 /* BBP_INFO get stuff directly from beststr or from beststr->desptr */
39246 #ifdef PCOMPLIB
39247 #define BBP_INFO(info) bbp->desptr->info
39248 #else
39249 #define BBP_INFO(info) bbp->info
39250 #endif
39251 X
39252 extern double zs_to_bit(double, int, int);
39253 X
39254 /* showbest() shows a list of high scoring sequence descriptions, and
39255 X   their scores.  If -m 9, then an additional complete set of
39256 X   alignment information is provided.
39257 X
39258 X   If PCOMPLIB or m_msg.quiet then the number of high scores to be
39259 X   shown is pre-determined by m_msg.mshow before showbest is called.
39260 X
39261 X   The comp_lib.c version re_getlib()'s the sequence for its
39262 X   discription, and then does another alignment for -m 9 (Thus, it
39263 X   needs an f_str.  The PCOMPLIB version has everything available in
39264 X   beststr before showbest() is called.
39265 */
39266 X
39267 void showbest (FILE *fp, 
39268 #ifndef PCOMPLIB
39269 X              unsigned char **aa0, unsigned char *aa1, int maxn,
39270 #endif
39271 X              struct beststr **bptr,int nbest, int qlib, struct mngmsg *m_msg,
39272 X              struct pstruct pst, struct db_str db,
39273 X              char *gstring2
39274 #ifndef PCOMPLIB
39275 X              ,void **f_str
39276 #endif
39277 )
39278 {
39279 X  int ntmp = 0;
39280 X  char bline[MAX_BLINE], fmt[40], pad[MAX_BLINE], rline[40];
39281 X  char l_name[128];
39282 X  int istart = 0, istop, ib;
39283 X  int nshow;
39284 X  int quiet;
39285 X  int r_margin;
39286 X  struct beststr *bbp;
39287 X  int n1tot;
39288 X  char *bp;
39289 X  char rel_label[12];
39290 X  char tmp_str[20], *seqc;
39291 X  int seqc_len;
39292 X  long loffset, l_off;
39293 X  int n0, n1;
39294 X  struct rstruct rst;
39295 X  int lc, maxc, nident, ngap;
39296 X  float percent, gpercent;
39297 X  struct a_struct *aln_p;
39298 X  int *tres;
39299 X  int gi_num;
39300 X
39301 #ifndef PCOMPLIB
39302 X  struct lmf_str *m_fptr;
39303 #endif
39304 X
39305 X  strncpy(rel_label,"\0",2);
39306 #ifdef SHOWREL
39307 X  strncpy(rel_label," related",sizeof(rel_label));
39308 #endif
39309 #ifdef SHOWUN
39310 X  strncpy(rel_label," unrelated",sizeof(rel_label));
39311 #endif
39312 X  rel_label[sizeof(rel_label)-1]='\0';
39313 X
39314 #ifdef PCOMPLIB
39315 X  quiet = 1;
39316 #else
39317 X  quiet = m_msg->quiet;
39318 #endif
39319 X
39320 X  n0 = m_msg->n0;
39321 X
39322 X  if (m_msg->aln.llen > MAX_BLINE) m_msg->aln.llen = MAX_BLINE;
39323 X
39324 X  if (pst.zsflag < 0) r_margin = 10;
39325 X  else if (pst.zsflag>=0  && m_msg->srelv > 1 ) r_margin = 19;
39326 X  else r_margin = 10;
39327 X
39328 X  if (m_msg->markx & MX_M9SUMM && m_msg->show_code == SHOW_CODE_ID) {
39329 #ifdef SHOWSIM
39330 X    r_margin += 15;
39331 #else
39332 X    r_margin += 10;
39333 #endif
39334 X  }
39335 X
39336 X  if (m_msg->nframe < 0) 
39337 #ifndef SUPERFAMNUM
39338 X    sprintf(fmt,"%%-%ds (%%4d)",m_msg->aln.llen-r_margin);
39339 #else
39340 X    sprintf(fmt,"%%-%ds [%%4d](%%4d)",m_msg->aln.llen-(r_margin+4));
39341 #endif
39342 X  else 
39343 X    sprintf(fmt,"%%-%ds (%%4d)",m_msg->aln.llen-(r_margin+4));
39344 X
39345 X  memset(pad,' ',m_msg->aln.llen-(r_margin+6));
39346 X  pad[m_msg->aln.llen-(r_margin+12)]='\0';
39347 X
39348 X  if (quiet != -1) {   /* quiet is set to -1 in comp_mlib.c to force
39349 X                          all significant hits to be shown */
39350 X    nshow = 20;
39351 X    if (m_msg->mshow == -1) nshow = nbest;             /* show all */
39352 X    /* show specified number */
39353 X    else if (m_msg->mshow_flg) {
39354 X      nshow = min (m_msg->mshow, nshow);
39355 X    }
39356 X  }
39357 X  else nshow = m_msg->nshow;
39358 X
39359 X  if (quiet==0) istop = 20;
39360 X  else istop = nshow;
39361 X
39362 X  if (quiet==0) {
39363 X    printf(" How many scores would you like to see? [%d] ",m_msg->nshow);
39364 X    fflush(stdout);
39365 X    if (fgets(rline,20,stdin)==NULL) exit(0);
39366 X    nshow = m_msg->nshow;
39367 X    if (rline[0]!='\n' && rline[0]!=0) sscanf(rline,"%d",&nshow);
39368 X    if (nshow<=0) nshow = min(20,nbest);
39369 X  }
39370 X
39371 X  if ((bp = strchr (m_msg->qtitle, '\n')) != NULL) *bp = '\0';
39372 /*   fprintf (fp, "%3d %s\n", qlib,m_msg->qtitle); */
39373 X
39374 X  if (m_msg->markx & MX_HTML) fprintf(fp,"<p><tt><pre>\n");
39375 X
39376 X  if (pst.zsflag >= 0) {
39377 X    if (bptr[0]->escore < m_msg->e_cut) {
39378 X      if (m_msg->z_bits==1) {/* show bit score */
39379 X       fprintf(fp,"The best%s scores are:%s%s bits E(%ld)",
39380 X              rel_label,pad,m_msg->label,pst.zdb_size);
39381 X      }
39382 X      else {/* show z-score */
39383 X       fprintf(fp,"The best%s scores are:%s%s z-sc E(%ld)",
39384 X             rel_label,pad,m_msg->label,pst.zdb_size);
39385 X      }
39386 X      header_aux(fp);
39387 X      if (m_msg->markx & MX_M9SUMM) {
39388 X       if (m_msg->show_code == SHOW_CODE_ID) {
39389 #ifdef SHOWSIM
39390 X         fprintf(fp," %%_id  %%_sim  alen");
39391 #else
39392 X         fprintf(fp," %%_id  alen");
39393 #endif
39394 X       }
39395 X       else {
39396 X       if (m_msg->markx & MX_HTML && m_msg->show_code !=1) { fprintf(fp,"<!-- ");}
39397 #ifndef SHOWSIM
39398 X         fprintf(fp,"\t%%_id  %%_gid %4s  alen  an0  ax0  pn0  px0  an1  ax1 pn1 px1 gapq gapl  fs ",m_msg->f_id1);
39399 #else
39400 X         fprintf(fp,"\t%%_id  %%_sim %4s  alen  an0  ax0  pn0  px0  an1  ax1 pn1 px1 gapq gapl  fs ",m_msg->f_id1);
39401 #endif
39402 X       }
39403 X       if (m_msg->show_code == SHOW_CODE_ALIGN) {      fprintf(fp," aln_code"); }
39404 X       if (m_msg->markx & MX_HTML && m_msg->show_code!=1) { fprintf(fp," -->");}
39405 X      }
39406 X      fprintf(fp,"\n");
39407 X    }
39408 X    else {
39409 X      fprintf(fp,"!! No library sequences with E() < %.2g\n",m_msg->e_cut);
39410 X      m_msg->nshow = 0;
39411 X      if (m_msg->markx & MX_HTML) fprintf(fp,"<p></tt></pre>\n");
39412 X      return;
39413 X    }
39414 X  }
39415 X  else {
39416 X    fprintf(fp,"The best%s scores are:%s%s",rel_label,pad,m_msg->label);
39417 X    header_aux(fp);
39418 X    if (m_msg->markx & MX_M9SUMM) {
39419 X      if (m_msg->show_code == SHOW_CODE_ID) {
39420 #ifdef SHOWSIM
39421 X       fprintf(fp," %%_id  %%_sm  alen");
39422 #else
39423 X       fprintf(fp," %%_id  alen");
39424 #endif
39425 X      }
39426 X      else {
39427 #ifndef SHOWSIM
39428 X       fprintf(fp,"\t%%_id  %%_gid %4s  alen  an0  ax0  pn0  px0  an1  ax1 pn1 px1 gapq gapl  fs ",m_msg->f_id1);
39429 #else
39430 X       fprintf(fp,"\t%%_id  %%_sim %4s  alen  an0  ax0  pn0  px0  an1  ax1 pn1 px1 gapq gapl  fs ",m_msg->f_id1);
39431 #endif
39432 X      }
39433 X    }
39434 X    if (m_msg->show_code == SHOW_CODE_ALIGN) { fprintf(fp," aln_code"); }
39435 X    fprintf(fp,"\n");
39436 X  }
39437 X
39438 X  istart = 0;
39439 l1:
39440 X  istop = min(nbest,nshow);
39441 X  for (ib=istart; ib<istop; ib++) {
39442 X    bbp = bptr[ib];
39443 #ifdef SUPERFAMNUM
39444 X    if (BBP_INFO(nsfnum) > 0 && sfn_cmp(m_msg->qsfnum_n,BBP_INFO(sfnum))) continue;
39445 #ifdef SHOWUN
39446 X    if (BBP_INFO(nsfnum) > 0 && sfn_cmp(m_msg->qsfnum,BBP_INFO(sfnum))) {
39447 X      istop = min(istop+1,nbest);
39448 X    /*
39449 X      fprintf(stderr,"skipping %d: %d==%d\n",ib,m_msg->qsfnum,BBP_INFO(sfnum));
39450 X      */
39451 X      continue;
39452 X    }
39453 #endif
39454 #ifdef SHOWREL
39455 X    if (BBP_INFO(nsfnum) == 0 || (BBP_INFO(nsfnum) > 0 && !sfn_cmp(m_msg->qsfnum,BBP_INFO(sfnum)))) {
39456 X      istop = min(istop+1,nbest);
39457 X    /*
39458 X      fprintf(stderr,"skipping %d: %d==%d\n",ib,m_msg->qsfnum,BBP_INFO(sfnum));
39459 X      */
39460 X      continue;
39461 X    }
39462 #endif
39463 #endif
39464 X    if (quiet==1 && pst.zsflag>=0) {
39465 X      if (bbp->escore > m_msg->e_cut) {
39466 X       nshow = ib;
39467 X       goto done;
39468 X      }
39469 X      else if (bbp->escore < m_msg->e_low) continue;
39470 X    }
39471 X
39472 #ifndef PCOMPLIB
39473 X    if ((m_fptr=re_openlib(bbp->m_file_p,!m_msg->quiet))==NULL) {
39474 X      fprintf(stderr,"*** cannot re-open %s\n",bbp->m_file_p->lb_name);
39475 X      exit(1);
39476 X    }
39477 X    RANLIB(bline,m_msg->aln.llen,bbp->lseek,bbp->libstr,m_fptr);
39478 #else
39479 X  strncpy(bline,BBP_INFO(bline),m_msg->aln.llen-r_margin);
39480 X  bline[m_msg->aln.llen]='\0';
39481 #endif
39482 X
39483 X  /* l_name is used to build an HTML link from the bestscore line to
39484 X     the alignment.  It can also be used to discriminate multiple hits
39485 X     from the same long sequence.  This requires that fast_pan use -m 6. */
39486 X
39487 X  strncpy(l_name,bline,sizeof(l_name)); /* get rid of text after second "|" */
39488 X  l_name[sizeof(l_name)-1]='\0';
39489 X  if ((bp=strchr(l_name,' '))!=NULL) *bp=0;
39490 X  if ((bp=strchr(&l_name[3],'|'))!=NULL) *bp='\0';
39491 X  if (m_msg->nframe > 2) sprintf(&l_name[strlen(l_name)],"_%d",bbp->frame+1);
39492 X  else if (m_msg->nframe > 0 && bbp->frame == 1)
39493 X    strncat(l_name,"_r",sizeof(l_name));
39494 X  if (bbp->cont-1 > 0) {
39495 X    sprintf(tmp_str,":%d",bbp->cont-1);
39496 X    strncat(l_name,tmp_str,sizeof(l_name)-strlen(l_name));
39497 X  }
39498 X
39499 X
39500 #ifndef PCOMPLIB
39501 X  if (m_msg->stages>1 || m_msg->markx & MX_M9SUMM) {
39502 X    if (bbp->cont >= 0) {
39503 X      n1 = re_getlib(aa1,maxn,m_msg->maxt3,m_msg->loff,bbp->cont,m_msg->term_code,
39504 X                    &loffset,&l_off,bbp->m_file_p);
39505 X    }
39506 X    else { n1 = maxn;}
39507 X    if (! m_msg->markx & MX_M9SUMM) {
39508 X      do_opt (aa0[bbp->frame], m_msg->n0, aa1, n1, bbp->frame, &pst, f_str[bbp->frame], &rst);
39509 X      bbp->score[2]=rst.score[2];
39510 X    }
39511 X    else {
39512 X      bbp->sw_score = 
39513 X       do_walign(aa0[bbp->frame],m_msg->n0, aa1, n1, bbp->frame, 
39514 X                 &pst, f_str[bbp->frame], &bbp->a_res, &bbp->have_ares);
39515 X
39516 X      
39517 X      /* save the alignment encoding for future use */
39518 X      if (bbp->have_ares && ((tres = calloc(bbp->a_res.nres+1,sizeof(int)))!=NULL)) {
39519 X       memcpy(tres,bbp->a_res.res,sizeof(int)*bbp->a_res.nres);
39520 X       bbp->a_res.res = tres;
39521 X      }
39522 X
39523 X      aln_func_vals(bbp->frame, &m_msg->aln);
39524 X
39525 X      maxc = bbp->a_res.nres + 4*m_msg->aln.llen+4;
39526 X      seqc = NULL;
39527 X      seqc_len = 0;
39528 X      if (m_msg->show_code == SHOW_CODE_ALIGN) {
39529 X       if ((seqc=(char *)calloc(maxc,sizeof(char)))!=NULL) {
39530 X         lc=calc_code(aa0[bbp->frame],m_msg->n0,
39531 X                      aa1,n1, 
39532 X                      &m_msg->aln,bbp->a_res,
39533 X                      pst,seqc,maxc,f_str[bbp->frame]);
39534 X         seqc_len = strlen(seqc);
39535 X       }
39536 X      }
39537 X      else {
39538 X       lc=calc_id(aa0[bbp->frame],m_msg->n0,aa1,n1,
39539 X                  &m_msg->aln, bbp->a_res,
39540 X                  pst,f_str[bbp->frame]);
39541 X      }
39542 X      m_msg->aln.a_len = lc;
39543 X
39544 X      nident = m_msg->aln.nident;
39545 X      if (lc > 0) percent = (100.0*(float)nident)/(float)lc;
39546 X      else percent = -1.00;
39547 X
39548 X      ngap = m_msg->aln.ngap_q + m_msg->aln.ngap_l;
39549 #ifndef SHOWSIM
39550 X      if (lc-ngap > 0) gpercent = (100.0*(float)nident)/(float)(lc-ngap);
39551 X      else gpercent = -1.00;
39552 #else
39553 X      if (lc-ngap > 0) gpercent = (100.0*(float)m_msg->aln.nsim)/(float)(lc);
39554 X      else gpercent = -1.00;
39555 #endif
39556 X
39557 X    }
39558 X  }
39559 #endif
39560 X
39561 X  n1tot = (BBP_INFO(n1tot_p)) ? *BBP_INFO(n1tot_p) : bbp->n1;
39562 X
39563 X  bp = bline;
39564 X  if ((m_msg->markx & MX_HTML) && !strncmp(bline,"gi|",3)) {
39565 X    bp = strchr(bline+4,'|')+1;
39566 X    *(bp-1) = 0;
39567 X    gi_num = atoi(bline+3);
39568 X  }
39569 X
39570 #ifndef SUPERFAMNUM
39571 X  bp[m_msg->aln.llen-r_margin]='\0';
39572 #else
39573 X  bp[m_msg->aln.llen-r_margin-5]='\0';
39574 #endif
39575 X
39576 X  if (m_msg->nframe == -1) bp[m_msg->aln.llen-r_margin]='\0';
39577 X  else bp[m_msg->aln.llen-(r_margin+4)]='\0';
39578 X
39579 #ifndef SUPERFAMNUM
39580 X  fprintf (fp, fmt,bp,n1tot);
39581 #else
39582 X  if (m_msg->nframe == -1) {
39583 X    fprintf (fp, fmt,bp,BBP_INFO(sfnum[0]),n1tot);
39584 X  }
39585 X  else {fprintf (fp, fmt,bp,n1tot);}
39586 #endif
39587 X
39588 X  if (m_msg->nframe > 2) fprintf (fp, " [%d]", bbp->frame+1);
39589 X  else if (m_msg->nframe >= 0) fprintf(fp," [%c]",(bbp->frame > 0 ?'r':'f'));
39590 X
39591 X  if (m_msg->srelv == 1) fprintf (fp, " %4d", bbp->score[pst.score_ix]);
39592 X  else {
39593 X    if (m_msg->srelv-1 > 0) fprintf (fp, " %4d", bbp->score[0]);
39594 X    if (m_msg->srelv-1 > 1 || m_msg->stages>1)
39595 X      fprintf (fp, " %4d", bbp->score[1]);
39596 X    fprintf (fp, " %4d", bbp->score[pst.score_ix]);
39597 X  }
39598 X
39599 X  if (pst.zsflag>=0) { 
39600 X    if (m_msg->z_bits==1) {
39601 X      fprintf (fp, " %.1f %7.2g",zs_to_bit(bbp->zscore,m_msg->n0,bbp->n1),bbp->escore);
39602 X    }
39603 X    else fprintf (fp, " %.1f %7.2g",bbp->zscore,bbp->escore);
39604 X  }
39605 X  show_aux(fp,bbp);
39606 X
39607 #ifdef PCOMPLIB
39608 X  n1 = bbp->n1;
39609 X  percent = bbp->percent;
39610 X  gpercent = bbp->gpercent;
39611 X  aln_p = bbp->aln_d;
39612 X  seqc = bbp->aln_code;
39613 X  seqc_len = bbp->aln_code_n;
39614 X  loffset = bbp->desptr->loffset;
39615 X  l_off = 0;
39616 #else
39617 X  aln_p = &(m_msg->aln);
39618 #endif
39619 X
39620 X  if (m_msg->markx & MX_M9SUMM) {
39621 X    if (m_msg->show_code != SHOW_CODE_ID) {
39622 X      if (m_msg->markx & MX_HTML) fprintf(fp,"<!-- ");
39623 X      cal_coord(m_msg->n0,bbp->n1,m_msg->sq0off,loffset+l_off-1,aln_p);
39624 X
39625 X      /*            %_id  %_sim s-w alen an0  ax0  pn0  px0  an1  ax1  pn1  px1 gapq gapl fs  */
39626 X      /*                    alignment    min  max            min  max */
39627 X      /*                    sequence coordinate    min  max            min  max */
39628 X      fprintf(fp,"\t%5.3f %5.3f %4d %4d %4ld %4ld %4ld %4ld %4ld %4ld %4ld %4ld %3d %3d %3d",
39629 X             percent/100.0,gpercent/100.0, bbp->sw_score,aln_p->a_len,
39630 X             aln_p->d_start0,aln_p->d_stop0,
39631 X             m_msg->sq0off, m_msg->sq0off+m_msg->n0-1,
39632 X             aln_p->d_start1,aln_p->d_stop1,
39633 X             loffset+l_off, loffset+l_off+bbp->n1-1,
39634 X             aln_p->ngap_q,aln_p->ngap_l,aln_p->nfs);
39635 X      if (m_msg->show_code == SHOW_CODE_ALIGN
39636 X         && seqc_len > 0 && seqc != NULL) {
39637 X       fprintf(fp,"\t%s",seqc);
39638 X      /*      fprintf(fp," [%2d:%d]",bbp->wrkr,bbp->seqnm); */
39639 X       free(seqc);
39640 X       seqc = NULL;
39641 X      }
39642 X      if (m_msg->markx & MX_HTML) fprintf(fp," -->");
39643 X    }
39644 X    else {
39645 #ifdef SHOWSIM
39646 X      fprintf(fp," %5.3f %5.3f %4d", percent/100.0,(float)aln_p->nsim/(float)aln_p->a_len,aln_p->a_len);
39647 #else
39648 X      fprintf(fp," %5.3f %4d", percent/100.0,aln_p->a_len);
39649 #endif
39650 X    }
39651 X  }
39652 X  if (m_msg->markx & MX_HTML) fprintf(fp," <A HREF=\"#%s\">align</A>",l_name);
39653 X  fprintf (fp, "\n");
39654 X  fflush(fp);
39655 X  }
39656 X
39657 X  if (quiet==0) {
39658 X    printf(" More scores? [0] ");
39659 X    fflush(stdout);
39660 X    if (fgets(rline,20,stdin)==NULL) exit(0);
39661 X    ntmp = 0;
39662 X    if (rline[0]!='\n' && rline[0]!=0) sscanf(rline,"%d",&ntmp);
39663 X    if (ntmp<=0) ntmp = 0;
39664 X    if (ntmp>0) {
39665 X      istart = istop;
39666 X      nshow += ntmp;
39667 X      goto l1;
39668 X    }
39669 X  }
39670 X  else if (quiet == 1)
39671 X    if (ib < nbest && (pst.zsflag>=0 && bbp->escore < m_msg->e_cut)) {
39672 X      if (m_msg->mshow_flg && istop >= m_msg->mshow) goto done;
39673 X      istart=istop;
39674 X      nshow += 10;
39675 X      goto l1;
39676 X    }
39677 X
39678 X done:
39679 X  m_msg->nshow = nshow;
39680 X  if (m_msg->markx & MX_HTML) fprintf(fp,"</pre></tt><p><hr><p>\n");
39681 X  if (fp!=stdout) fprintf(fp,"\n");
39682 }
39683 X
39684 /*
39685 X  q[] has one set of sfnums, 0 terminated
39686 X  s[] has second
39687 X  return first match or 0
39688 */
39689 SHAR_EOF
39690 chmod 0644 mshowbest.c ||
39691 echo 'restore of mshowbest.c failed'
39692 Wc_c="`wc -c < 'mshowbest.c'`"
39693 test 14393 -eq "$Wc_c" ||
39694         echo 'mshowbest.c: original size 14393, current size' "$Wc_c"
39695 fi
39696 # ============= mu.lib ==============
39697 if test -f 'mu.lib' -a X"$1" != X"-c"; then
39698         echo 'x - skipping mu.lib (File already exists)'
39699 else
39700 echo 'x - extracting mu.lib (Text)'
39701 sed 's/^X//' << 'SHAR_EOF' > 'mu.lib' &&
39702 >GTM1_MOUSE GLUTATHIONE S-TRANSFERASE GT8.7 (EC 2.5.1.18) (GST 1-1) (CLASS-MU
39703 PMILGYWNVRGLTHPIRMLLEYTDSSYDEKRYTMGDAPDFDRSQWLNEKFKLGLDFPNLPYLIDGSHKIT
39704 QSNAILRY
39705 LARKHHLDGETEEERIRADIVENQVMDTRMQLIMLCYNPDFEKQKPEFLKTIPEKMKLYSEFLGKRPWFA
39706 GDKVTYVD
39707 FLAYDILDQYRMFEPKCLDAFPNLRDFLARFEGLKKISAYMKSSRYIATPIFSKMAHWSNK 
39708 >GTM1_HUMAN GLUTATHIONE S-TRANSFERASE MU 1 (EC 2.5.1.18) (GSTM1-1) (HB SUBUNI
39709 PMILGYWDIRGLAHAIRLLLEYTDSSYEEKKYTMGDAPDYDRSQWLNEKFKLGLDFPNLPYLIDGAHKIT
39710 QSNAI
39711 LCYIARKHNLCGETEEEKIRVDILENQTMDNHMQLGMICYNPEFEKLKPKYLEELPEKLKLYSEFLGKRP
39712 WFAGN
39713 KITFVDFLVYDVLDLHRIFEPKCLDAFPNLKDFISRFEGLEKISAYMKSSRFLPRPVFSKMAVWGNK
39714 >GTMU_CRILO GLUTATHIONE S-TRANSFERASE Y1 (EC 2.5.1.18) (CHAIN 3) (CLASS-MU).
39715 PMILGYWNVRGLTNPIRLLLEYTDSSYEEKKYTMGDAPDSDRSQWLNEKFKLGLDFPNLPYLIDGSHKIT
39716 QSNAI
39717 LRYIARKHNLCGETEEERIRVDIVENQAMDTRMQLIMLCYNPDFEKQKPEFLKTIPEKMKMYSEFLGKRP
39718 WFAGD
39719 KVTLCGFLAYDVLDQYQMFEPKCLDPFPNLKDFLARFEGLKKISAYMKTSRFLRRPIFSKMAQWSNK
39720 >GTM1_RAT GLUTATHIONE S-TRANSFERASE YB1 (EC 2.5.1.18) (CHAIN 3) (CLASS-MU).
39721 PMILGYWNVRGLTHPIRLLLEYTDSSYEEKRYAMGDAPDYDRSQWLNEKFKLGLDFPNLPYLIDGSRKIT
39722 QSNAI
39723 MRYLARKHHLCGETEEERIRADIVENQVMDNRMQLIMLCYNPDFEKQKPEFLKTIPEKMKLYSEFLGKRP
39724 WFAGD
39725 KVTYVDFLAYDILDQYHIFEPKCLDAFPNLKDFLARFEGLKKISAYMKSSRYLSTPIFSKLAQWSNK
39726 >GTMU_RABIT GLUTATHIONE S-TRANSFERASE MU 1 (EC 2.5.1.18) (GST MU I) (CLASS-MU
39727 PMTLGYWDVRGLALPIRMLLEYTDTSYEEKKYTMGDAPNYDQSKWLSEKFTLGLDFPNLPYLIDGTHKLT
39728 QSNAI
39729 LRYLARKHGLCGETEEERIRVDILENQLMDNRFQLVNVCYSPDFEKLKPEYLKGLPEKLQLYSQFLGSLP
39730 WFAGD
39731 KITFADFLVYDVLDQNRIFVPGCLDAFPNLKDFHVRFEGLPKISAYMKSSRFIRVPVFLKKATWTGI
39732 >GTM4_HUMAN GLUTATHIONE S-TRANSFERASE MU 4 (EC 2.5.1.18) (GSTM4-4) (GTS-MU2) 
39733 MSMTLGYWDIRGLAHAIRLLLEYTDSSYEEKKYTMGDAPDYDRSQWLNEKFKLGLDFPNLPYLIDGAHKI
39734 TQSNAILC
39735 YIARKHNLCGETEEEKIRVDILENQAMDVSNQLARVCYSPDFEKLKPEYLEELPTMMQHFSQFLGKRPWF
39736 VGDKITFV
39737 DFLAYDVLDLHRIFEPNCLDAFPNLKDFISRFEGLEKISAYMKSSRFLPKPLYTRVAVWGNK 
39738 >GLNA_ANASP GLUTAMINE SYNTHETASE (EC 6.3.1.2) (GLUTAMATE--AMMONIA LIGASE).
39739 TTPQEVLKRIQDEKIELIDLKFIDTVGTWQHLTLYQNQIDESSFSDGVPFDGSSIRGWKAINESDMTMVL
39740 DPNTA
39741 WIDPFMEVPTLSIVCSIKEPRTGEWYNRCPRVIAQKAIDYLVSTGIGDTAFFGPEAEFFIFDSARFAQNA
39742 NEGYY
39743 FLDSVEGAWNSGKEGTADKPNLAYKPRFKEGYFPVSPTDSFQDIRTEMLLTMAKLGVPIEKHHHEVATGG
39744 QCELG
39745 FRFGKLIEAADWLMIYKYVIKNVAKKYGKTVTFMPKPIFGDNGSGMHCHQSIWKDGKPLFAGDQYAGLSE
39746 MGLYY
39747 IGGLLKHAPALLAITNPSTNSYKRLVPGYEAPVNLAYSQGNRSASIRIPLSGTNPKAKRLEFRCPDATSN
39748 PYLAF
39749 AAMLCAGIDGIKNKIHPGEPLDKNIYELSPEELAKVPSTPGSLELALEALENDHAFLTDTGVFTEDFIQN
39750 WIDYK
39751 LANEVKQMQLRPHPYEFSIYYDV
39752 SHAR_EOF
39753 chmod 0644 mu.lib ||
39754 echo 'restore of mu.lib failed'
39755 Wc_c="`wc -c < 'mu.lib'`"
39756 test 2361 -eq "$Wc_c" ||
39757         echo 'mu.lib: original size 2361, current size' "$Wc_c"
39758 fi
39759 # ============= musplfm.aa ==============
39760 if test -f 'musplfm.aa' -a X"$1" != X"-c"; then
39761         echo 'x - skipping musplfm.aa (File already exists)'
39762 else
39763 echo 'x - extracting musplfm.aa (Text)'
39764 sed 's/^X//' << 'SHAR_EOF' > 'musplfm.aa' &&
39765 >musplfm transl. of musplfm.seq, 2 to 676
39766 X M   L   P   S   L   I   Q   P   C   S   W   I   L   L   L  
39767 X L   L   V   N   S   S   L   L   W   K   N   V   A   S   F   P  
39768 X M   C   A   M   R   N   G   R   C   F   M   S   F   E   D   T  
39769 X F   E   L   A   G   S   L   S   H   N   I   S   I   E   V   S  
39770 X E   L   F   T   E   F   E   K   H   Y   S   N   V   S   G   L  
39771 X R   D   K   S   P   M   R   C   N   T   S   F   L   P   T   P  
39772 X E   N   K   E   Q   A   R   L   T   H   Y   S   A   L   L   K  
39773 X S   G   A   M   I   L   D   A   W   E   S   P   L   D   D   L  
39774 X V   S   E   L   S   T   I   K   N   V   P   D   I   I   I   S  
39775 X K   A   T   D   I   K   K   K   I   N   A   V   R   N   G   V  
39776 X N   A   L   M   S   T   M   L   Q   N   G   D   E   E   K   K  
39777 X N   P   A   W   F   L   Q   S   D   N   E   D   A   R   I   H  
39778 X S   L   Y   G   M   I   S   C   L   D   N   D   F   K   K   V  
39779 X D   I   Y   L   N   V   L   K   C   Y   M   L   K   I   D   N  
39780 X C  
39781 SHAR_EOF
39782 chmod 0644 musplfm.aa ||
39783 echo 'restore of musplfm.aa failed'
39784 Wc_c="`wc -c < 'musplfm.aa'`"
39785 test 953 -eq "$Wc_c" ||
39786         echo 'musplfm.aa: original size 953, current size' "$Wc_c"
39787 fi
39788 # ============= mw.h ==============
39789 if test -f 'mw.h' -a X"$1" != X"-c"; then
39790         echo 'x - skipping mw.h (File already exists)'
39791 else
39792 echo 'x - extracting mw.h (Text)'
39793 sed 's/^X//' << 'SHAR_EOF' > 'mw.h' &&
39794 /* Concurrent read version */
39795 X
39796 /* $Name: fa_34_26_5 $ - $Id: mw.h,v 1.20 2006/03/20 17:38:15 wrp Exp $ */
39797 X
39798 #include <sys/types.h>
39799 X
39800 #include "aln_structs.h"
39801 X
39802 #ifndef FSEEK_T_DEF
39803 #ifndef USE_FSEEKO
39804 typedef long fseek_t;
39805 #else
39806 typedef off_t fseek_t;
39807 #endif
39808 #endif
39809 X
39810 struct beststr {
39811 X  int n1;              /* sequence length */
39812 X  int *n1tot_p;                /* pointer (or NULL) to long sequence length */
39813 X  int score[3];                /* score */
39814 X  int sw_score;                /* do_walign() score */
39815 X  double comp;
39816 X  double H;
39817 X  double zscore;
39818 X  double escore;
39819 X  int segnum;
39820 X  int seglen;
39821 X  struct lmf_str *m_file_p;
39822 X  fseek_t lseek;
39823 X  char libstr[MAX_UID];
39824 X  int cont;
39825 X  int frame;
39826 X  int nsfnum;
39827 X  int sfnum[10];
39828 X  long loffset;
39829 X  struct a_struct aln_d;       /* these values are used by -m9 */
39830 X  struct a_res_str a_res;      /* need only a_res, not a_res[2], because different frames
39831 X                                  for the same sequence are stored separately */
39832 X  int have_ares;
39833 X  float percent, gpercent;
39834 };
39835 X
39836 struct stat_str {
39837 X  int score;
39838 X  int n1;
39839 X  double comp;
39840 X  double H;
39841 X  double escore;
39842 X  int segnum;
39843 X  int seglen;
39844 };
39845 X
39846 X
39847 SHAR_EOF
39848 chmod 0644 mw.h ||
39849 echo 'restore of mw.h failed'
39850 Wc_c="`wc -c < 'mw.h'`"
39851 test 1042 -eq "$Wc_c" ||
39852         echo 'mw.h: original size 1042, current size' "$Wc_c"
39853 fi
39854 # ============= mwkw.aa ==============
39855 if test -f 'mwkw.aa' -a X"$1" != X"-c"; then
39856         echo 'x - skipping mwkw.aa (File already exists)'
39857 else
39858 echo 'x - extracting mwkw.aa (Text)'
39859 sed 's/^X//' << 'SHAR_EOF' > 'mwkw.aa' &&
39860 >MWKW Myosin heavy chain - Caenorhabditis elegans
39861 MEHEKDPGWQYLRRTREQVLEDQSKPYDSKKNVWIPDPEEGYLAGEITATKGDQVTIVTAREMSVIQVTL
39862 KKELVQEMNPPKFEKTEDMSNLSFLNDASVLHNLRSRYAAMLIYTYSGLFCVVINPYKRLPIYTDSCARM
39863 FMGKRKTEMPPHLFAVSDEAYRNMLQDHENQSMLITGESGAGKTENTKKVICYFAAVGASQQEGGAEVDP
39864 NKKKVTLEDQIVQTNPVLEAFGNAKTVRNNNSSRFGKFIRIHFNKHGRLASCDIEHYLLEKSRVIRQAPG
39865 ERCYHIFYQIYSDFRPELKKELLLDLPIKDYWFVAQAELIIDGIDDVEEFQLTDEAFDILNFSAVEKQDC
39866 YRLMSAHMHMGNMKFKQRPREEQAEPDGTVEAEKASNMYGIGCE
39867 EFLKALTKPRVKVGTEWVSKGQNCEQVNWAVGAMAKGLYSRVFNWLVKKCNLTLDQKGIDRDYFIGVLDI
39868 AGFEIFDFNSFEQLWINFVNEKLQQFFNHHMFVLEQEEYAREGIQWVFIDFGLDLQACIELIEKPLGIIS
39869 MLDEECIVPKATDLTLASKLVDQHLGKHPNFEKPKPPKGKQGEAHFAMRHYAGTVRYNCLNWLEKNKDPL
39870 NDTVVSAMKQSKGNDLLVEIWQDYTTQEEAAAKAKEGGGGGKKKGKSGSFMTVSMLYRESLNNLMTMLNK
39871 THPHFIRCIIPNEKKQSGMIDAALVLNQLTCNGVLEGIRICRKGFPNRTLHPDFVQRYAILAAKEAKSDD
39872 DKKKCAEAIMSKLVNDGSLSEEMFRIGLTKVFFKAGVLAHLEDI
39873 RDEKLATILTGFQSQIRWHLGLKDRKRRMEQRAGLLIVQRNVRSWCTLRTWEWFKLYGKVKPMLKAGKEA
39874 EELEKINDKVKALEDSLAKEEKLRKELEESSAKLVEEKTSLFTNLESTKTQLSDAEERLAKLEAQQKDAS
39875 KQLSELNDQLADNEDRTADVQRAKKKIEAEVEALKKQIQDLEMSLRKAESEKQSKDHQIRSLQDEMQQQD
39876 EAIAKLNKEKKHQEEINRKLMEDLQSEEDKGNHQNKVKAKLEQTLDDLEDSLEREKRARADLDKQKRKVE
39877 GELKIAQENIDESGRQRHDLENNLKKKESELHSVSSRLEDEQALVSKLQRQIKDGQSRISELEEELENER
39878 QSRSKADRAKSDLQRELEELGEKLDEQGGATAAQVEVNKKREAE
39879 LAKLRRDLEEANMNHENQLGGLRKKHTDAVAELTDQLDQLNKAKAKVEKDKAQAVRDAEDLAAQLDQETS
39880 GKLNNEKLAKQFELQLTELQSKADEQSRQLQDFTSLKGRLHSENGDLVRQLEDAESQVNQLTRLKSQLTS
39881 QLEEARRTADEEARERQTVAAQAKNYQHEAEQLQESLEEEIEGKNEILRQLSKANADIQQWKARFEGEGL
39882 LKADELEDAKRRQAQKINELQEALDAANSKNASLEKTKSRLVGDLDDAQVDVERANGVASALEKKQKGFD
39883 KIIDEWRKKTDDLAAELDGAQRDLRNTSTDLFKAKNAQEELAEVVEGLRRENKSLSQEIKDLTDQLGEGG
39884 RSVHEMQKIIRRLEIEKEELQHALDEAEAALEAEESKVLRAQVE
39885 VSQIRSEIEKRIQEKEEEFENTRKNHARALESMQASLETEAKGKAELLRIKKKLEGDINELEIALDHANK
39886 ANADAQKNLKRYQEQVRELQLQVEEEQRNGADTREQFFNAEKRATLLQSEKEELLVANEAAERARKQAEY
39887 EAADARDQANEANAQVSSLTSAKRKLEGEIQAIHADLDETLNEYKAAEERSKKAIADATRLAEELRQEQE
39888 HSQHVDRLRKGLEQQLKEIQVRLDEAEAAALKGGKKVIAKLEQRVRELESELDGEQRRFQDANKNLGRAD
39889 RRVRELQFQVDEDKKNFERLQDLIDKLQQKLKTQKKQVEEAEELANLNLQKYKQLTHQLEDAEERADQAE
39890 NSLSKMRSKSRASASVAPGLQSSASAAVIRSPSRARASDF 
39891 SHAR_EOF
39892 chmod 0644 mwkw.aa ||
39893 echo 'restore of mwkw.aa failed'
39894 Wc_c="`wc -c < 'mwkw.aa'`"
39895 test 2047 -eq "$Wc_c" ||
39896         echo 'mwkw.aa: original size 2047, current size' "$Wc_c"
39897 fi
39898 # ============= mwrtc1.aa ==============
39899 if test -f 'mwrtc1.aa' -a X"$1" != X"-c"; then
39900         echo 'x - skipping mwrtc1.aa (File already exists)'
39901 else
39902 echo 'x - extracting mwrtc1.aa (Text)'
39903 sed 's/^X//' << 'SHAR_EOF' > 'mwrtc1.aa' &&
39904 >MWRTC1 - Myosin heavy chain 1, cardiac muscle - Rat (fragment)
39905 /DLTEQLGEGGKNVHELEKIRKQLEVEKLELQSALEEAEASLEHEEGKILRAQLEFNQIKAEIE
39906 SKLAEKDEEMEQAKRNHLRVVDSLQTSLDAETRSRNEALRVKKKMEGDLNEMEIQLSQANRIAS
39907 EAQKHLKNAQAHLKDTQLQLDDAVRANDDLKENIAIVERRNTLLQAELEELRAVVEQTERSRKL
39908 AEQELIETSERVQLLHSQNNSLINQKKKMDADLSQLQTEVEEAVQECRNAEEKAKKAITDAAMM
39909 AEELKKEQDTSAHLERMKKNMEQTIKDLQHRLDEAEQIALKGGKKQLQKLEARVRELENELEAE
39910 QKRNAESVKGMRKSERRIKELNYQTEEDKKNLVRLQDLVNKLQLKVKAYKRQAEEAEEQANTNL
39911 SKFRKVQHELDEAEERADIAESQVNKLRAKSRDIGAKQKIHDEE*
39912 SHAR_EOF
39913 chmod 0644 mwrtc1.aa ||
39914 echo 'restore of mwrtc1.aa failed'
39915 Wc_c="`wc -c < 'mwrtc1.aa'`"
39916 test 500 -eq "$Wc_c" ||
39917         echo 'mwrtc1.aa: original size 500, current size' "$Wc_c"
39918 fi
39919 # ============= myosin_bp.aa ==============
39920 if test -f 'myosin_bp.aa' -a X"$1" != X"-c"; then
39921         echo 'x - skipping myosin_bp.aa (File already exists)'
39922 else
39923 echo 'x - extracting myosin_bp.aa (Text)'
39924 sed 's/^X//' << 'SHAR_EOF' > 'myosin_bp.aa' &&
39925 >gi|46049110|ref|NP_996557| myosin binding protein C, slow type isoform 4; myosin-binding protein C, slow-type; skeletal muscle C-protein [Homo sapiens]
39926 MPEPTkkeenevpapapppeepskekeaGTTPAKDWTLVETPPGEEQAKQNANSQLSILF
39927 IEKPQGGTVKVGEDITFIAKVKAEDLLRKPTIKWFKGKWMDLASKAGKHLQLKETFERHS
39928 RVYTFEMQIIKAKDNFAGNYRCEVTYKDKFDSCSFDLEVHESTGTTPNIDIRSAFKRSGE
39929 GQEDAGELDFSGLLKRREVKQQEEEPQVDVWELLKNAKPSEYEKIAFQYGITDLRGmlkr
39930 lkrmrreekkSAAFAKILDPAYQVDKGGRVRFVVELADPKLEVKWYKNGQEIRPSTKYIF
39931 EHKGCQRILFINNCQMTDDSEYYVTAGDEKCSTELFVREPPIMVTKQLEDTTAYCGERVE
39932 LECEVSEDDANVKWFKNGEEIIPGPKSRYRIRVEGKKHILIIEGATKADAAEYSVMTTGG
39933 QSSAKLSVDLKPLKILTPLTDQTVNLGKEICLKCEISENIPGKWTKNGLPVQESDRLKVV
39934 HKGRIHKLVIANALTEDEGDYVFAPDAYNVTLPAKVHVIDPPKIILDGLDADNTVTVIAG
39935 NKLRLEIPISGEPPPKAMWSRGDKAIMEGSGRIRTESYPDSSTLVIDIAERDDSGVYHIN
39936 LKNEAGEAHASIkvkvvdfpdppvaptvtEVGDDWCIMNWEPPAYDGGSPILGYFIERKK
39937 KQSSRWMRLNFDLCKETTFEPKKMIEGVAYEVRIFAVNAIGISKPSMPSRPFVPLAVTSP
39938 PtlltvdsvtdttvtMRWRPPDHIGAAGLDGYVLEYCFEGTEDWIVANKDLIDKTKFTIT
39939 GLPTDAKIFVRVKAVNAAGASEPKYYSQPILVkeiieppkiriprHLKQTYIRRVGEAVN
39940 LVIPFQGKPRPELTWKKDGAEIDKNQINIRNSETDTIIFIRKAERSHSGKYDLQVKVDKF
39941 VETASIDIQIIDRPGPPQIVKIEDVWGENVALTWTPPKDDGNAAITGYTIQKADKKSMEW
39942 FTVIEHYHRTSATITELVIGNEYYFRVFSENMCGLSEDATMTKESAVIARDGKIYKNPVY
39943 EDFDFSEAPMFTQPLVNTYAIAGYNATLNCSVRGNPKPKITWMKNKVAIVDDPRYRMFSN
39944 QGVCTLEIRKPSPYDGGTYCCKAVNDLGTVEIECKLEVKVIAQ
39945 SHAR_EOF
39946 chmod 0644 myosin_bp.aa ||
39947 echo 'restore of myosin_bp.aa failed'
39948 Wc_c="`wc -c < 'myosin_bp.aa'`"
39949 test 1294 -eq "$Wc_c" ||
39950         echo 'myosin_bp.aa: original size 1294, current size' "$Wc_c"
39951 fi
39952 # ============= mysql_demo1.sql ==============
39953 if test -f 'mysql_demo1.sql' -a X"$1" != X"-c"; then
39954         echo 'x - skipping mysql_demo1.sql (File already exists)'
39955 else
39956 echo 'x - extracting mysql_demo1.sql (Text)'
39957 sed 's/^X//' << 'SHAR_EOF' > 'mysql_demo1.sql' &&
39958 xdb.wrplab seqdb_demo wrplab gstmu;
39959 SELECT acc, protein.seq, sp_name
39960 X FROM annot INNER JOIN protein USING(prot_id) WHERE annot.db='sp' LIMIT 50000;
39961 SELECT acc, concat('sp|',acc,'|',sp_name,' ',descr) FROM annot WHERE acc='#' AND db='sp';
39962 SELECT acc,protein.seq FROM protein INNER JOIN annot USING(prot_id)
39963 X WHERE annot.acc='#' AND db='sp';
39964 SHAR_EOF
39965 chmod 0644 mysql_demo1.sql ||
39966 echo 'restore of mysql_demo1.sql failed'
39967 Wc_c="`wc -c < 'mysql_demo1.sql'`"
39968 test 340 -eq "$Wc_c" ||
39969         echo 'mysql_demo1.sql: original size 340, current size' "$Wc_c"
39970 fi
39971 # ============= mysql_demo_pv.sql ==============
39972 if test -f 'mysql_demo_pv.sql' -a X"$1" != X"-c"; then
39973         echo 'x - skipping mysql_demo_pv.sql (File already exists)'
39974 else
39975 echo 'x - extracting mysql_demo_pv.sql (Text)'
39976 sed 's/^X//' << 'SHAR_EOF' > 'mysql_demo_pv.sql' &&
39977 xdb.wrplab seqdb_demo wrplab gstmu;
39978 SELECT acc, protein.seq, sp_name, concat('sp|',acc,'|',sp_name,' ',descr)
39979 X FROM annot INNER JOIN protein USING(prot_id) WHERE annot.db='sp' LIMIT 50000;
39980 SELECT acc, concat('sp|',acc,'|',sp_name,' ',descr) FROM annot WHERE acc='#' AND db='sp';
39981 SELECT acc,protein.seq FROM protein INNER JOIN annot USING(prot_id)
39982 X WHERE annot.acc='#' AND db='sp';
39983 SHAR_EOF
39984 chmod 0644 mysql_demo_pv.sql ||
39985 echo 'restore of mysql_demo_pv.sql failed'
39986 Wc_c="`wc -c < 'mysql_demo_pv.sql'`"
39987 test 381 -eq "$Wc_c" ||
39988         echo 'mysql_demo_pv.sql: original size 381, current size' "$Wc_c"
39989 fi
39990 # ============= mysql_lib.c ==============
39991 if test -f 'mysql_lib.c' -a X"$1" != X"-c"; then
39992         echo 'x - skipping mysql_lib.c (File already exists)'
39993 else
39994 echo 'x - extracting mysql_lib.c (Text)'
39995 sed 's/^X//' << 'SHAR_EOF' > 'mysql_lib.c' &&
39996 X
39997 /* mysql_lib.c copyright (c) 2000 William R. Pearson */
39998 X
39999 /* $Name: fa_34_26_5 $ - $Id: mysql_lib.c,v 1.21 2006/04/12 18:00:02 wrp Exp $ */
40000 X
40001 /* functions for opening, reading, seeking a mySQL database */
40002 X
40003 /*
40004 X  For the moment, this interface assumes that the file to be searched will
40005 X  be specified in a single, long, string with 4 parts:
40006 X
40007 X  (1) a database open string. This string has four fields, separated by
40008 X      whitespace (' \t'):
40009 X        hostname:port dbname user password
40010 X
40011 X   '--' dashes at the beginning of lines are ignored -
40012 X   thus the first line could be:
40013 X   -- hostname:port dbname user password
40014 X
40015 X  (2) a database query string that will return an unique ID (not
40016 X      necessarily numberic, but it must be < 12 characters as libstr[12]
40017 X      is used) and a sequence string
40018 X
40019 X  (2a) a series of mySQL commands that do not generate results
40020 X       starting with 'DO', followed by a select() statement.
40021 X
40022 X  (3) a database select string that will return a description
40023 X      given a unique ID
40024 X
40025 X  (4) a database select string that well return a sequence given a
40026 X      unique ID
40027 X
40028 X   Lines (3) and (4) are not required for pv34comp* libraries, but
40029 X   line (2) must generate a complete description as well as a sequence.
40030 X
40031 X
40032 X   18-July-2001
40033 X   Additional syntax has been added to support multiline SQL queries.
40034 X
40035 X   If the host line begins with '+', then the SQL is openned on the same
40036 X   connection as the previous SQL file.
40037 X
40038 X   If the host line contains '-' just before the terminal ';', then
40039 X   the file will not produce any output.
40040 X
40041 X   This string can contain "\n". ";" are used to separate the four
40042 X   functions, which must be specified in the order shown above.
40043 X   The last (fourth) query must terminate with a ';' */
40044 X
40045 #include <stdio.h>
40046 #include <stdlib.h>
40047 #include <string.h>
40048 #include <ctype.h>
40049 X
40050 #include <mysql.h>
40051 #define MYSQL_LIB 16
40052 X
40053 #include "defs.h"
40054 #include "mm_file.h"
40055 X
40056 #define XTERNAL
40057 #include "uascii.h"
40058 #define EOSEQ 0
40059 /* #include "upam.h" */
40060 X
40061 #ifdef SUPERFAMNUM
40062 int sfnum[10], nsfnum;
40063 #endif
40064 X
40065 int mysql_getlib(unsigned char *, int, char *, int, fseek_t *, int *, struct lmf_str *, long *);
40066 void mysql_ranlib(char *, int, fseek_t, char *, struct lmf_str *m_fd);
40067 X
40068 #define MYSQL_BUF 4096
40069 X
40070 struct lmf_str *
40071 mysql_openlib(char *sname, int ldnaseq, int *sascii) {
40072 X  FILE *sql_file;
40073 X  char *tmp_str, *ttmp_str;
40074 X  int tmp_str_len;
40075 X  char *bp, *bps, *bdp, *tp, tchar;
40076 X  int i, qs_len, qqs_len;
40077 X  char *sql_db, *sql_host, *sql_dbname, *sql_user, *sql_pass;
40078 X  char *sql_do;
40079 X  int sql_do_cnt;
40080 X  int sql_port;
40081 X  struct lmf_str *m_fptr;
40082 X
40083 X  /*  if (sql_reopen) return NULL; - should not be called for re-open */
40084 X
40085 X  tmp_str_len = MYSQL_BUF;
40086 X  if ((tmp_str=(char *)calloc(tmp_str_len,sizeof(char)))==NULL) {
40087 X    fprintf(stderr,"cannot allocate %d for mySQL buffer\n",tmp_str_len);
40088 X    return NULL;
40089 X  }
40090 X
40091 X  if (sname[0] == '%') {
40092 X    strncpy(tmp_str,sname+1,tmp_str_len);
40093 X    tmp_str[sizeof(tmp_str)-1]='\0';
40094 X  }
40095 X  else {
40096 X    if ((sql_file=fopen(sname,"r"))==NULL) {
40097 X      fprintf(stderr," cannot open mySQL file: %s\n",sname);
40098 X      return NULL;
40099 X    }
40100 X
40101 X    if ((qs_len=fread(tmp_str,sizeof(char),tmp_str_len-1,sql_file))<=0) {
40102 X      fprintf(stderr," cannot read mySQL file: %s\n",sname);
40103 X      return NULL;
40104 X    }
40105 X    else  {
40106 X      tmp_str[qs_len]='\0';
40107 X      qqs_len = qs_len;
40108 X      while (qqs_len >= tmp_str_len-1) {
40109 X       tmp_str_len += MYSQL_BUF;
40110 X       if ((tmp_str=(char *)realloc(tmp_str,tmp_str_len))==NULL) {
40111 X         fprintf(stderr,
40112 X                 " cannot reallocate %d for mySQL buffer\n",tmp_str_len);
40113 X         return NULL;
40114 X       }
40115 X       ttmp_str = &tmp_str[qqs_len];
40116 X       if ((qs_len=fread(ttmp_str,sizeof(char),MYSQL_BUF,sql_file))<0) {
40117 X         fprintf(stderr," cannot read mySQL file: %s\n",sname);
40118 X         return NULL;
40119 X       }
40120 X       ttmp_str[qs_len]='\0';
40121 X       qqs_len += qs_len;
40122 X      }
40123 X    }
40124 X    fclose(sql_file);
40125 X  }
40126 X
40127 X  bps = tmp_str;
40128 X  if ((bp=strchr(bps,';'))!=NULL) {
40129 X    *bp='\0';
40130 X    if ((sql_db=calloc(strlen(bps)+1,sizeof(char)))==NULL) {
40131 X      fprintf(stderr, " cannot allocate space for database name [%d], %s\n",
40132 X             strlen(bps),bps);
40133 X      return NULL;
40134 X    }
40135 X    /* have database name, parse the fields */
40136 X    else {
40137 X      strcpy(sql_db,bps);      /* strcpy OK because allocated strlen(bps) */
40138 X      bps = bp+1;      /* points to next char after ';' */
40139 X      while (isspace(*bps)) bps++;
40140 X      *bp=';'; /* replace ; */
40141 X      bp = sql_db;
40142 X      while (*bp=='-') {*bp++ = ' ';}
40143 X      sql_host = strtok(bp," \t\n");
40144 X      sql_dbname = strtok(NULL," \t\n");
40145 X      sql_user = strtok(NULL," \t\n");
40146 X      sql_pass = strtok(NULL," \t\n");
40147 X      if ((tp=strchr(sql_host,':'))!=NULL) {
40148 X       *tp='\0';
40149 X       sql_port=atoi(tp+1);
40150 X      }
40151 X      else sql_port = 0;
40152 X    }
40153 X  }
40154 X  else {
40155 X    fprintf(stderr," cannot find database fields:\n%s\n",tmp_str);
40156 X    return NULL;
40157 X  }
40158 X
40159 X  /* we have all the info we need to open a database, allocate lmf_str */
40160 X  if ((m_fptr = (struct lmf_str *)calloc(1,sizeof(struct lmf_str)))==NULL) {
40161 X    fprintf(stderr," cannot allocate lmf_str (%ld) for %s\n",
40162 X           sizeof(struct lmf_str),sname);
40163 X    return NULL;
40164 X  }
40165 X
40166 X  /* have our struct, initialize it */
40167 X
40168 X  strncpy(m_fptr->lb_name,sname,MAX_FN);
40169 X  m_fptr->lb_name[MAX_FN-1]='\0';
40170 X
40171 X  m_fptr->sascii = sascii;
40172 X
40173 X  m_fptr->sql_db = sql_db;
40174 X  m_fptr->getlib = mysql_getlib;
40175 X  m_fptr->ranlib = mysql_ranlib;
40176 X  m_fptr->mm_flg = 0;
40177 X  m_fptr->sql_reopen = 0;
40178 X  m_fptr->lb_type = MYSQL_LIB;
40179 X
40180 X  /* now open the database, if necessary */
40181 X  if ((m_fptr->mysql_conn=mysql_init(NULL))==NULL) {
40182 X    fprintf(stderr,"*** Error - mysql_init\n");
40183 X    goto error_r;
40184 X  }
40185 X
40186 X  if (mysql_real_connect(m_fptr->mysql_conn,
40187 X                        sql_host,sql_user,sql_pass,
40188 X                        sql_dbname,
40189 X                        sql_port,
40190 X                        NULL,
40191 X                        0)==NULL)
40192 X    {
40193 X      fprintf(stderr,"*** Error %u - could  not open database:\n%s\n%s",
40194 X             mysql_errno(m_fptr->mysql_conn),tmp_str,
40195 X             mysql_error(m_fptr->mysql_conn));
40196 X      goto error_r;
40197 X    }
40198 X  else {
40199 X    fprintf(stderr," Database %s opened on %s\n",sql_dbname,sql_host);
40200 X  }
40201 X
40202 X  /* check for 'DO' command - copy to 'DO' string */
40203 X  while (*bps == '-') { *bps++=' ';}
40204 X  if (isspace(bps[-1]) && toupper(bps[0])=='D' &&
40205 X      toupper(bps[1])=='O' && isspace(bps[2])) {
40206 X    /* have some 'DO' commands */
40207 X    /* check where the end of the last DO statement is */
40208 X
40209 X    sql_do_cnt = 1;    /* count up the number of 'DO' statements for later */
40210 X    bdp=bps+3;
40211 X    while ((bp=strchr(bdp,';'))!=NULL) {
40212 X      tp = bp+2; /* skip ;\n */
40213 X      while (isspace(*tp) || *tp == '-') {*tp++ = ' ';}
40214 X      if (toupper(*tp)=='D' && toupper(tp[1])=='O' && isspace(tp[2])) {
40215 X       sql_do_cnt++;           /* count the DO statements */
40216 X       bdp = tp+3;             /* move to the next DO statement */
40217 X      }
40218 X      else break;
40219 X    }
40220 X    if (bp != NULL) {  /* end of the last DO, begin of select */
40221 X      tchar = *(bp+1);
40222 X      *(bp+1)='\0';            /* terminate DO strings */
40223 X      if ((sql_do = calloc(strlen(bps)+1, sizeof(char)))==NULL) {
40224 X       fprintf(stderr," cannot allocate %d for sql_do\n",strlen(bps));
40225 X       goto error_r;
40226 X      }
40227 X      else {
40228 X       strcpy(sql_do,bps);
40229 X       *(bp+1)=tchar;  /* replace missing ';' */
40230 X      }
40231 X      bps = bp+1;
40232 X      while (isspace(*bps)) bps++;
40233 X    }
40234 X    else {
40235 X      fprintf(stderr," terminal ';' not found: %s\n",bps);
40236 X      goto error_r;
40237 X    }
40238 X    /* all the DO commands are in m_fptr->sql_do in the form: 
40239 X     DO command1; DO command2; DO command3; */
40240 X    bdp = sql_do;
40241 X    while (sql_do_cnt-- && (bp=strchr(bdp,';'))!=NULL) {
40242 X      /* do the mysql statement on bdp+3 */
40243 X      /* check for error */
40244 X      *bp='\0';
40245 X      if (mysql_query(m_fptr->mysql_conn,bdp+3)) {
40246 X       fprintf(stderr,"*** Error %u - query failed:\n%s\n%s\n",
40247 X               mysql_errno(m_fptr->mysql_conn), bdp+3, mysql_error(m_fptr->mysql_conn));
40248 X       goto error_r;
40249 X      }
40250 X      *bp=';';
40251 X      bdp = bp+1;
40252 X      while (isspace(*bdp)) bdp++;
40253 X    }
40254 X  }
40255 X
40256 X  /* copy 1st query field */
40257 X  if ((bp=strchr(bps,';'))!=NULL) {
40258 X    *bp='\0';
40259 X    if ((m_fptr->sql_query=calloc(strlen(bps)+1,sizeof(char)))==NULL) {
40260 X      fprintf(stderr, " cannot allocate space for query string [%d], %s\n",
40261 X             strlen(bps),bps);
40262 X      goto error_r;
40263 X    }
40264 X    /* have query, copy it */
40265 X    else {
40266 X      strcpy(m_fptr->sql_query,bps);
40267 X      *bp=';'; /* replace ; */
40268 X      bps = bp+1;
40269 X      while(isspace(*bps)) bps++;
40270 X    }
40271 X  }
40272 X  else {
40273 X    fprintf(stderr," cannot find database query field:\n%s\n",tmp_str);
40274 X    goto error_r;
40275 X  }
40276 X
40277 X  /* copy get_desc field */
40278 X  if ((bp=strchr(bps,';'))!=NULL) {
40279 X    *bp='\0';
40280 X    if ((m_fptr->sql_getdesc=calloc(strlen(bps)+1,sizeof(char)))==NULL) {
40281 X      fprintf(stderr, " cannot allocate space for database name [%d], %s\n",
40282 X             strlen(bps),bps);
40283 X      goto error_r;
40284 X    }
40285 X    /* have get_desc, copy it */
40286 X    else {
40287 X      strcpy(m_fptr->sql_getdesc,bps);
40288 X      *bp=';'; /* replace ; */
40289 X      bps = bp+1;
40290 X      while(isspace(*bps)) bps++;
40291 X    }
40292 X  }
40293 X  else {
40294 X    fprintf(stderr," cannot find getdesc field:\n%s\n",tmp_str);
40295 X    goto error_r;
40296 X  }
40297 X
40298 X  if ((bp=strchr(bps,';'))!=NULL) { *bp='\0';}
40299 X
40300 X  if ((m_fptr->sql_getseq=calloc(strlen(bps)+1,sizeof(char)))==NULL) {
40301 X    fprintf(stderr, " cannot allocate space for database name [%d], %s\n",
40302 X           strlen(bps),bps);
40303 X    goto error_r;
40304 X  }
40305 X
40306 X  if (strlen(bps) > 0) {
40307 X    strcpy(m_fptr->sql_getseq,bps);
40308 X  }
40309 X  else {
40310 X    fprintf(stderr," cannot find getseq field:\n%s\n",tmp_str);
40311 X    return 0;
40312 X  }
40313 X  if (bp!=NULL) *bp=';';
40314 X
40315 X  /* now do the query */    
40316 X
40317 X  if (mysql_query(m_fptr->mysql_conn,m_fptr->sql_query)) {
40318 X    fprintf(stderr,"*** Error %u - query failed:\n%s\n%s\n",
40319 X           mysql_errno(m_fptr->mysql_conn), m_fptr->sql_query, mysql_error(m_fptr->mysql_conn));
40320 X    goto error_r;
40321 X  }
40322 X
40323 X  if ((m_fptr->mysql_res = mysql_use_result(m_fptr->mysql_conn)) == NULL) {
40324 X    fprintf(stderr,"*** Error = use result failed\n%s\n",
40325 X           mysql_error(m_fptr->mysql_conn));
40326 X    goto error_r;
40327 X  }
40328 X  return m_fptr;
40329 X
40330 X error_r:
40331 X  free(m_fptr->sql_getseq);
40332 X  free(m_fptr->sql_getdesc);
40333 X  free(m_fptr->sql_query);
40334 X  free(m_fptr);
40335 X  free(sql_db);
40336 X  return NULL;
40337 }
40338 X
40339 struct lmf_str *
40340 mysql_reopen(struct lmf_str *m_fptr) {
40341 X  m_fptr->sql_reopen = 1;
40342 X  return m_fptr;
40343 }
40344 X
40345 void
40346 mysql_closelib(struct lmf_str *m_fptr) {
40347 X
40348 X  if (m_fptr == NULL) return;
40349 X  if (m_fptr->mysql_res != NULL)
40350 X    mysql_free_result(m_fptr->mysql_res);
40351 X  mysql_close(m_fptr->mysql_conn);
40352 X  m_fptr->sql_reopen=0;
40353 }
40354 X
40355 /*
40356 static char *sql_seq = NULL, *sql_seqp;
40357 static int sql_seq_len;
40358 static MYSQL_ROW sql_row;
40359 */
40360 X
40361 int
40362 mysql_getlib( unsigned char *seq,
40363 X             int maxs,
40364 X             char *libstr,
40365 X             int n_libstr,
40366 X             fseek_t *libpos,
40367 X             int *lcont,
40368 X             struct lmf_str *lm_fd,
40369 X             long *l_off)
40370 {
40371 X  register unsigned char *cp, *seqp;
40372 X  register int *ap;
40373 X  unsigned char *seqm, *seqm1;
40374 X  char *bp;
40375 X  /*   int l_start, l_stop, len; */
40376 X
40377 X  seqp = seq;
40378 X  seqm = &seq[maxs-9];
40379 X  seqm1 = seqm-1;
40380 X
40381 X  ap = lm_fd->sascii;
40382 X
40383 #ifdef SUPERFAMNUM
40384 X  sfnum[0]=nsfnum = 0;
40385 #endif
40386 X
40387 X  if (*lcont==0) {
40388 X    /* get a row, with UID, sequence */
40389 X    *l_off = 1;
40390 X    if ((lm_fd->mysql_row =mysql_fetch_row(lm_fd->mysql_res))!=NULL) {
40391 X      *libpos=(fseek_t)atol(lm_fd->mysql_row[0]);
40392 X
40393 X      /* for @P:1-n removed */
40394 X      /*
40395 X      if ((bp=strchr(lm_fd->mysql_row[2],'@'))!=NULL &&
40396 X         !strncmp(bp+1,"P:",2)) {
40397 X       sscanf(bp+3,"%d-%d",&l_start,&l_stop)
40398 X       l_start--;
40399 X       if (l_start < 0) l_start=0;
40400 X       if (l_stop > (len=strlen(lm_fd->mysql_row[1]))) l_stop= len-1;
40401 X       lm_fd->sql_seqp = lm_fd->mysql_row[1];
40402 X       lm_fd->sql_seqp[l_stop]='\0';
40403 X       lm_fd->sql_seqp += l_start;
40404 X      */
40405 X
40406 X      if (lm_fd->mysql_row[2] == NULL) {
40407 X       fprintf(stderr," NULL comment at: [%s] %ld\n",
40408 X               lm_fd->mysql_row[0],*libpos);
40409 X      }
40410 X      else if ((bp=strchr(lm_fd->mysql_row[2],'@'))!=NULL &&
40411 X         !strncmp(bp+1,"C:",2)) sscanf(bp+3,"%ld",l_off);
40412 X      else *l_off = 1;
40413 X
40414 X      lm_fd->sql_seqp = lm_fd->mysql_row[1];
40415 X
40416 X      /* because of changes in mysql_ranlib(), it is essential that
40417 X         libstr return the unique identifier; thus we must use
40418 X         sql_row[0], not sql_row[2]. Using libstr as the UID allows
40419 X         one to use any UID, not just numeric ones.  *libpos is not
40420 X         used for mysql libraries.
40421 X      */
40422 X
40423 X      if (n_libstr <= MAX_UID) {
40424 X       /* the normal case returns only GID/sequence */
40425 X       strncpy(libstr,lm_fd->mysql_row[0],MAX_UID-1);
40426 X       libstr[MAX_UID-1]='\0';
40427 X      }
40428 X      else {
40429 X       /* here we do not use the UID in libstr, because we are not
40430 X           going back into the db */
40431 X       /* the PVM case also returns a long description */
40432 X       if (lm_fd->mysql_row[2]!=NULL) {
40433 X         strncpy(libstr,lm_fd->mysql_row[2],n_libstr-1);
40434 X       }
40435 X       else {
40436 X         strncpy(libstr,lm_fd->mysql_row[0],n_libstr-1);
40437 X       }
40438 X       libstr[n_libstr-1]='\0';
40439 X      }
40440 X    }
40441 X    else {
40442 X      mysql_free_result(lm_fd->mysql_res);
40443 X      lm_fd->mysql_res=NULL;
40444 X      *lcont = 0;
40445 X      *seqp = EOSEQ;
40446 X      return -1;
40447 X    }
40448 X  }
40449 X
40450 X  for (cp=(unsigned char *)lm_fd->sql_seqp; seqp<seqm1 && *cp; ) {
40451 X    if ((*seqp++=ap[*cp++])<NA &&
40452 X       (*seqp++=ap[*cp++])<NA &&
40453 X       (*seqp++=ap[*cp++])<NA &&
40454 X       (*seqp++=ap[*cp++])<NA &&
40455 X       (*seqp++=ap[*cp++])<NA &&
40456 X       (*seqp++=ap[*cp++])<NA &&
40457 X       (*seqp++=ap[*cp++])<NA &&
40458 X       (*seqp++=ap[*cp++])<NA &&
40459 X       (*seqp++=ap[*cp++])<NA &&
40460 X       (*seqp++=ap[*cp++])<NA) continue;
40461 X    --seqp;
40462 X    if (*(cp-1)==0) break;
40463 X  }
40464 X  lm_fd->sql_seqp = (char *)cp;
40465 X
40466 X  if (seqp>=seqm1) (*lcont)++;
40467 X  else {
40468 X    *lcont=0;
40469 X    if (lm_fd->sql_reopen) {
40470 X      mysql_free_result(lm_fd->mysql_res);
40471 X      lm_fd->mysql_res = NULL;
40472 X    }
40473 X  }
40474 X
40475 X  *seqp = EOSEQ;
40476 X  /*   if ((int)(seqp-seq)==0) return 1; */
40477 X  return (int)(seqp-seq);
40478 }
40479 X
40480 void
40481 mysql_ranlib(char *str,
40482 X            int cnt,
40483 X            fseek_t libpos,
40484 X            char *libstr,
40485 X            struct lmf_str *lm_fd
40486 X            )
40487 {
40488 X  char tmp_query[1024], tmp_val[20];
40489 X  char *bp;
40490 X
40491 X  str[0]='\0';
40492 X
40493 X  /* put the UID into the query string - cannot use sprintf because of
40494 X     "%' etc */
40495 X
40496 X  /*   sprintf(tmp_query,lm_fd->sql_getdesc,libpos); */
40497 X
40498 X  if ((bp=strchr(lm_fd->sql_getdesc,'#'))==NULL) {
40499 X    fprintf(stderr, "no GID position in %s\n",lm_fd->sql_getdesc);
40500 X    goto next1;
40501 X  }
40502 X  else {
40503 X    *bp = '\0';
40504 X    strncpy(tmp_query,lm_fd->sql_getdesc,sizeof(tmp_query));
40505 X    tmp_query[sizeof(tmp_query)-1]='\0';
40506 X    /*    sprintf(tmp_val,"%ld",(long)libpos); */
40507 X    strncat(tmp_query,libstr,sizeof(tmp_query)-1);
40508 X    strncat(tmp_query,bp+1,sizeof(tmp_query)-1);
40509 X    *bp='#';
40510 X    lm_fd->lpos = libpos;
40511 X  }
40512 X
40513 X  /*  fprintf(stderr," requesting: %s\n",tmp_query); */
40514 X
40515 X  if (lm_fd->mysql_res !=NULL) {
40516 X    mysql_free_result(lm_fd->mysql_res);
40517 X    lm_fd->mysql_res = NULL;
40518 X  }
40519 X
40520 X  if (mysql_query(lm_fd->mysql_conn,tmp_query)) {
40521 X    fprintf(stderr,"*** Error - query failed:\n%s\n%s\n",tmp_query,
40522 X           mysql_error(lm_fd->mysql_conn));
40523 X    sprintf(str,"gi|%ld ***Error - query failed***",(long)libpos);
40524 X    goto next1;
40525 X  }
40526 X
40527 X  if ((lm_fd->mysql_res = mysql_use_result(lm_fd->mysql_conn)) == NULL) {
40528 /*     fprintf(stderr,"*** Error = use result failed\n%s\n", 
40529 X          mysql_error(lm_fd->mysql_conn)); */
40530 X    sprintf(str,"gi|%ld ***use result failed***",(long)libpos);
40531 X    goto next0;
40532 X  }
40533 X  
40534 X  /* have the description */
40535 X  if ((lm_fd->mysql_row = mysql_fetch_row(lm_fd->mysql_res))==NULL) {
40536 X    /*    fprintf(stderr," cannot fetch description: %s\n",tmp_query); */
40537 X    sprintf(str,"gi|%ld ***cannot fetch description***",(long)libpos);
40538 X    goto next0;
40539 X  }
40540 X  
40541 X  if (lm_fd->mysql_row[1] != NULL) strncpy(str,lm_fd->mysql_row[1],cnt-1);
40542 X  else strncpy(str,lm_fd->mysql_row[0],cnt-1);
40543 X  str[cnt-1]='\0';
40544 X  while (strlen(str) < cnt-1 &&
40545 X        (lm_fd->mysql_row = mysql_fetch_row(lm_fd->mysql_res))!=NULL) {
40546 X    strncat(str," ",cnt-2-strlen(str));
40547 X    if (lm_fd->mysql_row[1]!=NULL) 
40548 X      strncat(str,lm_fd->mysql_row[1],cnt-2-strlen(str));
40549 X    else break;
40550 X  }
40551 X
40552 X  str[cnt-1]='\0';
40553 X  if ((bp = strchr(str,'\r'))!=NULL) *bp='\0';
40554 X  if ((bp = strchr(str,'\n'))!=NULL) *bp='\0';
40555 X
40556 X next0:
40557 X  mysql_free_result(lm_fd->mysql_res);
40558 X next1: 
40559 X  lm_fd->mysql_res = NULL;
40560 X
40561 X  /* get the sequence, set up for mysql_getseq() */
40562 X  /* put the UID into the query string */
40563 X
40564 X  if ((bp=strchr(lm_fd->sql_getseq,'#'))==NULL) {
40565 X    fprintf(stderr, "no GID position in %s\n",lm_fd->sql_getseq);
40566 X    return;
40567 X  }
40568 X  else {
40569 X    *bp = '\0';
40570 X    strncpy(tmp_query,lm_fd->sql_getseq,sizeof(tmp_query));
40571 X    tmp_query[sizeof(tmp_query)-1]='\0';
40572 X    /*    sprintf(tmp_val,"%ld",(long)libpos); */
40573 X    strncat(tmp_query,libstr,sizeof(tmp_query));
40574 X    strncat(tmp_query,bp+1,sizeof(tmp_query));
40575 X    *bp='#';
40576 X  }
40577 X
40578 X  if (mysql_query(lm_fd->mysql_conn,tmp_query)) {
40579 X    fprintf(stderr,"*** Error - query failed:\n%s\n%s\n",tmp_query,
40580 X           mysql_error(lm_fd->mysql_conn));
40581 X  }
40582 X
40583 X  if ((lm_fd->mysql_res = mysql_use_result(lm_fd->mysql_conn)) == NULL) {
40584 X    fprintf(stderr,"*** Error = use result failed\n%s\n",
40585 X           mysql_error(lm_fd->mysql_conn));
40586 X  }
40587 }
40588 SHAR_EOF
40589 chmod 0644 mysql_lib.c ||
40590 echo 'restore of mysql_lib.c failed'
40591 Wc_c="`wc -c < 'mysql_lib.c'`"
40592 test 16406 -eq "$Wc_c" ||
40593         echo 'mysql_lib.c: original size 16406, current size' "$Wc_c"
40594 fi
40595 # ============= n0.aa ==============
40596 if test -f 'n0.aa' -a X"$1" != X"-c"; then
40597         echo 'x - skipping n0.aa (File already exists)'
40598 else
40599 echo 'x - extracting n0.aa (Text)'
40600 sed 's/^X//' << 'SHAR_EOF' > 'n0.aa' &&
40601 >mgstm1
40602 MGDAPDFD,
40603 MLLEYTD
40604 SHAR_EOF
40605 chmod 0644 n0.aa ||
40606 echo 'restore of n0.aa failed'
40607 Wc_c="`wc -c < 'n0.aa'`"
40608 test 26 -eq "$Wc_c" ||
40609         echo 'n0.aa: original size 26, current size' "$Wc_c"
40610 fi
40611 # ============= n1.aa ==============
40612 if test -f 'n1.aa' -a X"$1" != X"-c"; then
40613         echo 'x - skipping n1.aa (File already exists)'
40614 else
40615 echo 'x - extracting n1.aa (Text)'
40616 sed 's/^X//' << 'SHAR_EOF' > 'n1.aa' &&
40617 >tests from mgstm1
40618 MILGYW,
40619 MLLE,
40620 MGDAP,
40621 MLCYNP
40622 SHAR_EOF
40623 chmod 0644 n1.aa ||
40624 echo 'restore of n1.aa failed'
40625 Wc_c="`wc -c < 'n1.aa'`"
40626 test 47 -eq "$Wc_c" ||
40627         echo 'n1.aa: original size 47, current size' "$Wc_c"
40628 fi
40629 # ============= n2.aa ==============
40630 if test -f 'n2.aa' -a X"$1" != X"-c"; then
40631         echo 'x - skipping n2.aa (File already exists)'
40632 else
40633 echo 'x - extracting n2.aa (Text)'
40634 sed 's/^X//' << 'SHAR_EOF' > 'n2.aa' &&
40635 >gi|345664 gi|345664|pir||A45388 protein-tyrosine kinase (EC 2.7.1.112) - chicken [MASS=116670](65:883)
40636 GSIEREDGGLQGPAGNQHIYQPVGKPDHAAPPK,
40637 LIGVITENPVWIIMELCTLGELRSFLQVR,
40638 KPPRPGAPHLGSLASLNSPVDSYNEGVK,
40639 EDGGLQGPAGNQHIYQPVGKPDHAAPPK,
40640 QVTVSWDSGGSDEAPPKPSRPGYPSPR,
40641 GANPTHLADFNQVQTIQYSNSEDKDR,
40642 LPMPPNCPPTLYSLMTKCWAYDPSR,
40643 PGAPHLGSLASLNSPVDSYNEGVK,
40644 GANPTHLADFNQVQTIQYSNSEDK,
40645 LSHLQSEEVHWLHLDMGVSNVR,
40646 QVTVSWDSGGSDEAPPKPSR,
40647 VFHYFENSSEPTTWASIIR,
40648 TLLATVDESLPVLPASTHR,
40649 RQVTVSWDSGGSDEAPPK,
40650 AQLSTILEEEKLQQEER,
40651 EKFELAHPPEEWKYELR,
40652 LAQQYVMTSLQQEYKK,
40653 FELAHPPEEWKYELR,
40654 LVNGATQSFIIRPQK,
40655 KQMLTAAHALAVDAK,
40656 SNDKVYENVTGLVK,
40657 QMLTAAHALAVDAK,
40658 GMGQVLPTHLMEER,
40659 PQEISPPPTANLDR,
40660 IQPAPPEEYVPMVK,
40661 GMGQVLPTHLMEER,
40662 QFANLNREESILK,
40663 SHAR_EOF
40664 chmod 0644 n2.aa ||
40665 echo 'restore of n2.aa failed'
40666 Wc_c="`wc -c < 'n2.aa'`"
40667 test 692 -eq "$Wc_c" ||
40668         echo 'n2.aa: original size 692, current size' "$Wc_c"
40669 fi
40670 # ============= n2_fs.lib ==============
40671 if test -f 'n2_fs.lib' -a X"$1" != X"-c"; then
40672         echo 'x - skipping n2_fs.lib (File already exists)'
40673 else
40674 echo 'x - extracting n2_fs.lib (Text)'
40675 sed 's/^X//' << 'SHAR_EOF' > 'n2_fs.lib' &&
40676 >GT8.7 | 40001 90043 | transl. of pa875.con, 19 to 675
40677 ILGYWN,
40678 DQYRMFEP,
40679 SRYIATP,
40680 KCLDAFP,
40681 EYTDS,
40682 SYDEKR
40683 >GT8.7 | 40001 90043 | transl. of pa875.con, 19 to 675
40684 ILGYWN,
40685 DQYRMFEP,
40686 SRYIATP,
40687 KCLDAFP,
40688 EYTDS,
40689 SYDEKR,
40690 YTMGD,
40691 EKQKPEFL,
40692 VRGLTHP,
40693 TRMQLI,
40694 FKLGLDFP,
40695 NLPYLI,
40696 DGSHKIT,
40697 LRYLAR,
40698 KTIPEK,
40699 KRPWFA,
40700 ETEEERIR,
40701 GDKVTYVD,
40702 HWSNK
40703 >tests from mgstm1
40704 MLLE,
40705 MILGYW,
40706 MGADP,
40707 MLCYNP
40708 >gi|345664 gi|345664|pir||A45388 protein-tyrosine kinase (EC 2.7.1.112) - chicken [MASS=116670](65:883)
40709 GANPTHLADF,
40710 QVTVSWDSGG,
40711 EDGGLQGPA,
40712 TLLATVDE,
40713 LSHLQSEE,
40714 PGAPHLGS,
40715 GANPTHLA
40716 >gi|345664 gi|345664|pir||A45388 protein-tyrosine kinase (EC 2.7.1.112) - chicken [MASS=116670](65:883)
40717 GSIEREDGGLQGPAGNQHIYQPVGKPDHAAPPK,
40718 LIGVITENPVWIIMELCTLGELRSFLQVR,
40719 KPPRPGAPHLGSLASLNSPVDSYNEGVK,
40720 EDGGLQGPAGNQHIYQPVGKPDHAAPPK,
40721 QVTVSWDSGGSDEAPPKPSRPGYPSPR,
40722 GANPTHLADFNQVQTIQYSNSEDKDR,
40723 LPMPPNCPPTLYSLMTKCWAYDPSR,
40724 PGAPHLGSLASLNSPVDSYNEGVK,
40725 GANPTHLADFNQVQTIQYSNSEDK,
40726 LSHLQSEEVHWLHLDMGVSNVR,
40727 QVTVSWDSGGSDEAPPKPSR,
40728 VFHYFENSSEPTTWASIIR,
40729 TLLATVDESLPVLPASTHR,
40730 RQVTVSWDSGGSDEAPPK,
40731 AQLSTILEEEKLQQEER,
40732 EKFELAHPPEEWKYELR,
40733 LAQQYVMTSLQQEYKK,
40734 FELAHPPEEWKYELR,
40735 LVNGATQSFIIRPQK,
40736 KQMLTAAHALAVDAK,
40737 SNDKVYENVTGLVK,
40738 QMLTAAHALAVDAK,
40739 GMGQVLPTHLMEER,
40740 PQEISPPPTANLDR,
40741 IQPAPPEEYVPMVK,
40742 GMGQVLPTHLMEER,
40743 QFANLNREESILK,
40744 >gi|345664 gi|345664|pir||A45388 protein-tyrosine kinase (EC 2.7.1.112) - chicken [MASS=116670](65:883)
40745 GANPTHLADF,
40746 QVTVSWDSGG,
40747 EDGGLQGPA,
40748 TLLATVDE,
40749 LSHLQSEE,
40750 PGAPHLGS,
40751 GANPTHLA,
40752 AQLSTILE,
40753 KPPRPGA,
40754 GSIERED,
40755 VFHYFEN,
40756 LIGVIT,
40757 LPMPP,
40758 RQVTV,
40759 QVTV
40760 SHAR_EOF
40761 chmod 0644 n2_fs.lib ||
40762 echo 'restore of n2_fs.lib failed'
40763 Wc_c="`wc -c < 'n2_fs.lib'`"
40764 test 1482 -eq "$Wc_c" ||
40765         echo 'n2_fs.lib: original size 1482, current size' "$Wc_c"
40766 fi
40767 # ============= n2s.aa ==============
40768 if test -f 'n2s.aa' -a X"$1" != X"-c"; then
40769         echo 'x - skipping n2s.aa (File already exists)'
40770 else
40771 echo 'x - extracting n2s.aa (Text)'
40772 sed 's/^X//' << 'SHAR_EOF' > 'n2s.aa' &&
40773 >gi|345664 gi|345664|pir||A45388 protein-tyrosine kinase (EC 2.7.1.112) - chicken [MASS=116670](65:883)
40774 GANPTHLADF,
40775 QVTVSWDSGG,
40776 EDGGLQGPA,
40777 TLLATVDE,
40778 LSHLQSEE,
40779 PGAPHLGS,
40780 GANPTHLA
40781 SHAR_EOF
40782 chmod 0644 n2s.aa ||
40783 echo 'restore of n2s.aa failed'
40784 Wc_c="`wc -c < 'n2s.aa'`"
40785 test 178 -eq "$Wc_c" ||
40786         echo 'n2s.aa: original size 178, current size' "$Wc_c"
40787 fi
40788 # ============= n2t.aa ==============
40789 if test -f 'n2t.aa' -a X"$1" != X"-c"; then
40790         echo 'x - skipping n2t.aa (File already exists)'
40791 else
40792 echo 'x - extracting n2t.aa (Text)'
40793 sed 's/^X//' << 'SHAR_EOF' > 'n2t.aa' &&
40794 >gi|345664 gi|345664|pir||A45388 protein-tyrosine kinase (EC 2.7.1.112) - chicken [MASS=116670](65:883)
40795 GANPTHLADF,
40796 QVTVSWDSGG,
40797 EDGGLQGPA,
40798 TLLATVDE,
40799 LSHLQSEE,
40800 PGAPHLGS,
40801 GANPTHLA,
40802 AQLSTILE,
40803 KPPRPGA,
40804 GSIERED,
40805 VFHYFEN,
40806 LIGVIT,
40807 LPMPP,
40808 RQVTV,
40809 QVTV
40810 SHAR_EOF
40811 chmod 0644 n2t.aa ||
40812 echo 'restore of n2t.aa failed'
40813 Wc_c="`wc -c < 'n2t.aa'`"
40814 test 243 -eq "$Wc_c" ||
40815         echo 'n2t.aa: original size 243, current size' "$Wc_c"
40816 fi
40817 # ============= n_fs.lib ==============
40818 if test -f 'n_fs.lib' -a X"$1" != X"-c"; then
40819         echo 'x - skipping n_fs.lib (File already exists)'
40820 else
40821 echo 'x - extracting n_fs.lib (Text)'
40822 sed 's/^X//' << 'SHAR_EOF' > 'n_fs.lib' &&
40823 >tests from mgstm1
40824 MLLE,
40825 MILGYW,
40826 MGADP,
40827 MLCYNP
40828 >GT8.7 | 40001 90043 | transl. of pa875.con, 19 to 675
40829 ILGYWN,
40830 DQYRMFEP,
40831 SRYIATP,
40832 KCLDAFP,
40833 EYTDS,
40834 SYDEKR
40835 >gi|345664 gi|345664|pir||A45388 protein-tyrosine kinase (EC 2.7.1.112) - chicken [MASS=116670](65:883)
40836 GANPTHLADF,
40837 QVTVSWDSGG,
40838 EDGGLQGPA,
40839 TLLATVDE,
40840 LSHLQSEE,
40841 PGAPHLGS,
40842 GANPTHLA
40843 SHAR_EOF
40844 chmod 0644 n_fs.lib ||
40845 echo 'restore of n_fs.lib failed'
40846 Wc_c="`wc -c < 'n_fs.lib'`"
40847 test 330 -eq "$Wc_c" ||
40848         echo 'n_fs.lib: original size 330, current size' "$Wc_c"
40849 fi
40850 # ============= ncbl2_head.h ==============
40851 if test -f 'ncbl2_head.h' -a X"$1" != X"-c"; then
40852         echo 'x - skipping ncbl2_head.h (File already exists)'
40853 else
40854 echo 'x - extracting ncbl2_head.h (Text)'
40855 sed 's/^X//' << 'SHAR_EOF' > 'ncbl2_head.h' &&
40856 /* ncbl_head.h  header files for blast1.3 format */
40857 X
40858 /* $Name: fa_34_26_5 $ - $Id: ncbl2_head.h,v 1.3 2006/05/18 19:04:25 wrp Exp $ */
40859 X
40860 #define AMINO_ACID_SEQTYPE      1
40861 #define AA_SEQTYPE      AMINO_ACID_SEQTYPE
40862 #define AAFORMAT        AA_SEQTYPE
40863 X
40864 #define NUCLEIC_ACID_SEQTYPE    0
40865 #define NT_SEQTYPE      NUCLEIC_ACID_SEQTYPE
40866 #define NTFORMAT        NT_SEQTYPE
40867 X
40868 /* Filename extensions used by the two types of databases (a.a. and nt.) */
40869 #define AA_LIST_EXT     "pal"
40870 #define AA_HEADER_EXT   "phr"
40871 #define AA_INDEX_EXT    "pin"
40872 #define AA_SEARCHSEQ_EXT        "psq"
40873 X
40874 #define NT_LIST_EXT     "nal"
40875 #define NT_HEADER_EXT   "nhr"
40876 #define NT_INDEX_EXT    "nin"
40877 #define NT_SEARCHSEQ_EXT        "nsq"
40878 X
40879 #define FORMATDBV3      3       /* formatdb version */
40880 #define FORMATDBV4      4       /* formatdb version */
40881 X
40882 #define NULLB           '\0'    /* sentinel byte */
40883 X
40884 #ifndef CHAR_BIT
40885 #define CHAR_BIT        8       /* these values should match blast */
40886 #endif
40887 X
40888 #define NBPN            2
40889 #define NSENTINELS      2
40890 SHAR_EOF
40891 chmod 0644 ncbl2_head.h ||
40892 echo 'restore of ncbl2_head.h failed'
40893 Wc_c="`wc -c < 'ncbl2_head.h'`"
40894 test 882 -eq "$Wc_c" ||
40895         echo 'ncbl2_head.h: original size 882, current size' "$Wc_c"
40896 fi
40897 # ============= ncbl2_mlib.c ==============
40898 if test -f 'ncbl2_mlib.c' -a X"$1" != X"-c"; then
40899         echo 'x - skipping ncbl2_mlib.c (File already exists)'
40900 else
40901 echo 'x - extracting ncbl2_mlib.c (Text)'
40902 sed 's/^X//' << 'SHAR_EOF' > 'ncbl2_mlib.c' &&
40903 /*      ncbl2_lib.c     functions to read ncbi-blast format files from
40904 X                       formatdb (blast2.0 format files)
40905 X
40906 X               copyright (c) 1999 William R. Pearson
40907 */
40908 X
40909 /* $Name: fa_34_26_5 $ - $Id: ncbl2_mlib.c,v 1.56 2007/04/02 18:08:11 wrp Exp $ */
40910 X
40911 /* to turn on mmap()ing for Blast2 files: */
40912 X
40913 #include <stdio.h>
40914 #include <stdlib.h>
40915 #include <string.h>
40916 #include <sys/types.h>
40917 #include <sys/stat.h>
40918 #include <fcntl.h>
40919 #ifdef UNIX
40920 #include <unistd.h>
40921 #endif
40922 #include <errno.h>
40923 X
40924 X
40925 /* ****************************************************************
40926 X
40927 17-May-2006
40928 X
40929 Modified to read NCBI .[np]al and .msk files.  The .nal or .pal file
40930 provides a way to read sequences from a list of files.  The .msk file
40931 provides a compact way of indicating the subset of sequences in a
40932 larger database (typically nr or nt) that comprise a smaller database
40933 (e.g. swissprot or pdbaa).  A .pal file (e.g. swissprot.00.pal) that
40934 uses a .msk file has the form:
40935 X
40936 X       # Alias file generated by genmask
40937 X       # Date created: Mon Apr 10 11:24:05 2006
40938 X       #
40939 X       TITLE     Non-redundant SwissProt sequences
40940 X       DBLIST    nr.00
40941 X       OIDLIST   swissprot.00.msk
40942 X       LENGTH    74351250
40943 X       NSEQ      198346
40944 X       MAXOID    2617347
40945 X       MEMB_BIT 1
40946 X       # end of the file
40947 X
40948 To work with this file, we must first load the nr.00 file, and then
40949 read the swissprot.00.msk file, and then scan all the entries in the
40950 swissprot.00.msk file (which are packed 32 mask-bit to an int) to
40951 determine whether a specific libpos index entry is present in the
40952 subset database.
40953 X
40954 **************************************************************** */
40955 X
40956 X
40957 /* ****************************************************************
40958 This code reads NCBI Blast2 format databases from formatdb version 3 and 4
40959 X
40960 (From NCBI) This section describes the format of the databases.
40961 X
40962 Formatdb creates three main files for proteins containing indices,
40963 sequences, and headers with the extensions, respectively, of pin, psq,
40964 and phr (for nucleotides these are nin, nsq, and nhr).  A number of
40965 other ISAM indices are created, but these are described elsewhere.
40966 X
40967 FORMAT OF THE INDEX FILE
40968 ------------------------
40969 X
40970 1.) formatdb version number     [4 bytes].
40971 X
40972 2.) protein dump flag (1 for a protein database, 0 for a nucleotide
40973 X    database) [4 bytes].
40974 X
40975 3.) length of the database title in bytes       [4 bytes].
40976 4.) the database title          [length given in 3.)].
40977 5.) length of the date/time string      [4 bytes].
40978 6.) the date/time string        [length given in 5.)].
40979 7.) the number of sequences in the database     [4 bytes].
40980 8.) the total length of the database in residues/basepairs      [4 bytes].
40981 9.) the length of the longest sequence in the database          [4 bytes].
40982 X
40983 10.) a list of the offsets for definitions (one for each sequence) in
40984 the header file.  There are num_of_seq+1 of these, where num_of_seq is
40985 the number of sequences given in 7.).
40986 X
40987 11.) a list of the offsets for sequences (one for each sequence) in
40988 the sequence file.  There are num_of_seq+1 of these, where num_of_seq
40989 is the number of sequences given in 7.).
40990 X
40991 12.) a list of the offsets for the ambiguity characters (one for each
40992 sequence) in the sequence file.  This list is only present for
40993 nucleotide databases and, since the database is compressed 4/1 for
40994 nucleotides, allows the ambiguity characters to be restored when the
40995 sequence is generated.  There are num_of_seq+1 of these, where
40996 num_of_seq is the number of sequences given in 7.).
40997 X
40998 X
40999 FORMAT OF THE SEQUENCE FILE
41000 ---------------------------
41001 X
41002 There are different formats for the protein and nucleotide sequence files.
41003 X
41004 The protein sequence files is quite simple.  The first byte in the
41005 file is a NULL byte, followed by the sequence in ncbistdaa format
41006 (described in the NCBI Software Development Toolkit documentation).
41007 Following the sequence is another NULL byte, followed by the next
41008 sequence.  The file ends with a NULL byte, following the last
41009 sequence.
41010 X
41011 The nucleotide sequence file contains the nucleotide sequence, with
41012 four basepairs compressed into one byte.  The format used is NCBI2na,
41013 documented in the NCBI Software Development Toolkit manual.  Any
41014 ambiguity characters present in the original sequence are replaced at
41015 random by A, C, G or T.  The true value of ambiguity characters are
41016 stored at the end of each sequence to allow true reproduction of the
41017 original sequence.
41018 X
41019 FORMAT OF THE HEADER FILE  (formatdb version 3)
41020 -------------------------
41021 X
41022 The format of the header file depends on whether or not the identifiers in the
41023 original file were parsed or not.  For the case that they were not, then each
41024 entry has the format:
41025 X
41026 gnl|BL_ORD_ID|entry_number my favorite yeast sequence...
41027 X
41028 Here entry_number gives the ordinal number of the sequence in the
41029 database (with zero offset).  The identifier
41030 gnl|BL_ORD_ID|entry_number is used by the BLAST software to identify
41031 the entry, if the user has not provided another identifier.  If the
41032 identifier was parsed, then gnl|BL_ORD_ID|entry_number is replaced by
41033 the correct identifier, as described in
41034 ftp://ncbi.nlm.nih.gov/blast/db/README .
41035 X
41036 There are no separators between these deflines.
41037 X
41038 For formatdb version 4, the header file contains blast ASN.1 binary
41039 deflines, which can parsed with parse_fastadl_asn().
41040 X
41041 FORMAT OF THE .MSK FILE
41042 -----------------------
41043 X
41044 The .msk file is simply a packed list of masks for formatdb "oids" for
41045 some other file (typically nr).  The first value is the last oid
41046 available; the remainder are packed 32 oids/mask, so that the number
41047 of masks is 1/32 the number of sequences in the file.
41048 X
41049 **************************************************************** */
41050 X
41051 #ifdef USE_MMAP
41052 #include <sys/types.h>
41053 #include <sys/stat.h>
41054 #include <sys/mman.h>
41055 #ifdef IBM_AIX
41056 #include <fcntl.h>
41057 #else
41058 #include <sys/fcntl.h>
41059 #endif
41060 #endif
41061 X
41062 #ifdef USE_MMAP
41063 #ifndef MAP_FILE
41064 #define MAP_FILE 0
41065 #endif
41066 #endif
41067 X
41068 #ifdef UNIX
41069 #define RBSTR "r"
41070 #else
41071 #define RBSTR "rb"
41072 #endif
41073 X
41074 #ifdef WIN32
41075 #define SLASH_CHAR '\\'
41076 #define SLASH_STR "\\"
41077 #else
41078 #define SLASH_CHAR '/'
41079 #define SLASH_STR "/"
41080 #endif
41081 X
41082 #define XTERNAL
41083 #include "uascii.h"
41084 X
41085 #define XTERNAL
41086 #include "upam.h"
41087 #include "ncbl2_head.h"
41088 X
41089 #include "defs.h"
41090 #include "mm_file.h"
41091 X
41092 unsigned int bl2_uint4_cvt(unsigned int);
41093 unsigned int bl2_long4_cvt(long);
41094 int64_t bl2_long8_cvt(int64_t);
41095 void src_int4_read(FILE *fd,  int *valp);
41096 void src_uint4_read(FILE *fd,  unsigned int *valp);
41097 void src_long4_read(FILE *fd,  long *valp);
41098 void ncbi_long8_read(FILE *fd,  int64_t *valp);
41099 void src_char_read(FILE *fd,  char *valp);
41100 unsigned char *parse_fastadl_asn(unsigned char *asn_buff, unsigned char *asn_max,
41101 X                                int *gi_p, int *db, char *acc,  char *name,
41102 X                                char *title, int t_len, int *taxid);
41103 X
41104 /* nt_btoa maps  from blast 2bit  format to ascii  characters */
41105 static char nt_btoa[5] = {"ACGT"};
41106 X
41107 static char aa_b2toa[27]= {"-ABCDEFGHIKLMNPQRSTVWXYZU*"};
41108 X
41109 static int aa_btof[32]; /* maps to fasta alphabet */
41110 X
41111 static int dbtype, dbformat, amb_cnt;
41112 X
41113 #define NCBIBL20 12
41114 X
41115 int ncbl2_getliba(unsigned char *, int, char *, int, fseek_t *, int *, struct lmf_str *, long *);
41116 int ncbl2_getlibn(unsigned char *, int, char *, int, fseek_t *, int *, struct lmf_str *, long *);
41117 X
41118 int ncbl2_getliba_o(unsigned char *, int, char *, int, fseek_t *, int *, struct lmf_str *, long *);
41119 int ncbl2_getlibn_o(unsigned char *, int, char *, int, fseek_t *, int *, struct lmf_str *, long *);
41120 X
41121 void newname(char *, char *, char *, int);
41122 void parse_pal(char *, char *, int *, int *, FILE *);
41123 X
41124 void ncbl2_ranlib(char *, int, fseek_t, char *, struct lmf_str *m_fd);
41125 X
41126 /* ncbl2_openlib() is used to open (and memory map) a BLAST2.0 format
41127 X   file.  Ifdef USE_MMAP, then ncbl2_openlib returns a structure that can
41128 X   be used to read the database. */
41129 X   
41130 struct lmf_str *
41131 ncbl2_openlib(char *name, int ldnaseq)
41132 {
41133 X  char lname[256];
41134 X  char dname[256];
41135 X  char msk_name[256];
41136 X  char hname[256];
41137 X  char sname[256];
41138 X  char tname[256];
41139 X  char db_dir[256];
41140 X  int pref_db= -1;
41141 X  char *bp;
41142 X  int title_len;
41143 X  char *title_str=NULL;
41144 X  int date_len;
41145 X  char *date_str=NULL;
41146 X  long ltmp;
41147 X  int64_t l8tmp;
41148 X  int oid_seqs, max_oid;
41149 X  int oid_cnt, oid_len;
41150 X  unsigned int *oid_list, o_max;
41151 X  int tmp;
41152 X  int i;
41153 #ifdef USE_MMAP
41154 X  struct stat statbuf;
41155 #endif
41156 X  FILE *ifile; /* index offsets, also DB info */
41157 X  unsigned int *f_pos_arr;
41158 X  struct lmf_str *m_fptr;
41159 X
41160 X  if (ldnaseq==SEQT_PROT) {    /* read a protein database */
41161 X    newname(lname,name,AA_LIST_EXT,(int)sizeof(lname));
41162 X    newname(tname,name,AA_INDEX_EXT,(int)sizeof(tname));
41163 X    newname(hname,name,AA_HEADER_EXT,(int)sizeof(hname));
41164 X    newname(sname,name,AA_SEARCHSEQ_EXT,(int)sizeof(sname));
41165 X
41166 X    /* initialize map of BLAST2 amino acids to FASTA amino acids */
41167 X    for (i=0; i<sizeof(aa_b2toa); i++) {
41168 X      if ((tmp=aascii[aa_b2toa[i]])<NA) aa_btof[i]=tmp;
41169 X      else if (aa_b2toa[i]=='*') aa_btof[i]=aascii['X'];
41170 X      else aa_b2toa[i]=0;
41171 /*    else aa_btof[i]=aascii['X']; */
41172 X    }
41173 X  }
41174 X  else {       /* reading DNA library */
41175 X    newname(lname,name,NT_LIST_EXT,(int)sizeof(lname));
41176 X    newname(tname,name,NT_INDEX_EXT,(int)sizeof(tname));
41177 X    newname(hname,name,NT_HEADER_EXT,(int)sizeof(hname));
41178 X    newname(sname,name,NT_SEARCHSEQ_EXT,(int)sizeof(sname));
41179 X
41180 X  }
41181 X       
41182 X  /* check first for list name */
41183 X  max_oid = oid_seqs = 0;
41184 X  oid_list = NULL;
41185 X  if ((ifile = fopen(lname,"r"))!=NULL) {
41186 X
41187 X    if ((bp = strrchr(name,SLASH_CHAR))!=NULL) {
41188 X      *bp = '\0';
41189 X      strncpy(db_dir,name,sizeof(db_dir));
41190 X      strncat(db_dir,SLASH_STR,sizeof(db_dir)-strlen(db_dir)-1);
41191 X      *bp = SLASH_CHAR;
41192 X    }
41193 X    else {
41194 X      db_dir[0]='\0';
41195 X    }
41196 X
41197 X    /* we have a list file, we need to parse it */
41198 X    parse_pal(dname, msk_name, &oid_seqs, &max_oid, ifile);
41199 X    fclose(ifile);
41200 X
41201 X    pref_db = -1;
41202 X    if (oid_seqs > 0) {
41203 X
41204 X      /* get the pref_db before adding the directory */
41205 X      if (strncmp(msk_name,"swissprot",9)==0) {
41206 X       pref_db = 7;
41207 X      }
41208 X      else if (strncmp(msk_name,"pdbaa",5)==0) {
41209 X       pref_db = 14;
41210 X      }
41211 X
41212 X      /* need to add directory to both dname and msk_name */
41213 X      strncpy(tname,db_dir,sizeof(tname));
41214 X      strncat(tname,msk_name, sizeof(tname));
41215 X      strncpy(msk_name, tname, sizeof(msk_name));
41216 X
41217 X      strncpy(tname,db_dir,sizeof(tname));
41218 X      strncat(tname,dname, sizeof(tname));
41219 X      strncpy(dname,tname,sizeof(dname));
41220 X
41221 X      if (ldnaseq == SEQT_PROT) {
41222 X       newname(tname,dname,AA_INDEX_EXT,(int)sizeof(tname));
41223 X       newname(hname,dname,AA_HEADER_EXT,(int)sizeof(hname));
41224 X       newname(sname,dname,AA_SEARCHSEQ_EXT,(int)sizeof(sname));
41225 X      }
41226 X      else {   /* reading DNA library */
41227 X       newname(tname,dname,NT_INDEX_EXT,(int)sizeof(tname));
41228 X       newname(hname,dname,NT_HEADER_EXT,(int)sizeof(hname));
41229 X       newname(sname,dname,NT_SEARCHSEQ_EXT,(int)sizeof(sname));
41230 X      }
41231 X      /* now load the oid file */
41232 X      if ((ifile = fopen(msk_name,RBSTR))==NULL) {
41233 X       fprintf(stderr,"error - cannot load %s file\n",msk_name);
41234 X       return NULL;
41235 X      }
41236 X      else {
41237 X       src_uint4_read(ifile,&o_max);
41238 X       if (o_max != max_oid) {
41239 X         fprintf(stderr," error - oid count mismatch %d != %d\n",max_oid, o_max);
41240 X       }
41241 X       oid_len = (max_oid/32+1);
41242 X       if ((oid_list=(unsigned int *)calloc(oid_len,sizeof(int)))==NULL) {
41243 X         fprintf(stderr," error - cannot allocate oid_list[%d]\n",oid_len);
41244 X         return NULL;
41245 X       }
41246 X       if ((oid_cnt=fread(oid_list,sizeof(int),oid_len,ifile))==0) {
41247 X         fprintf(stderr," error - cannot read oid_list[%d]\n",oid_len);
41248 X         return NULL;
41249 X       }
41250 X       fclose(ifile);
41251 X      }
41252 X    }
41253 X    else {     /* we had a .msk file, but there are no oid's in it.
41254 X                  allocate an m_fptr and return it empty */
41255 X      if ((m_fptr=(struct lmf_str *)calloc(1,sizeof(struct lmf_str)))==NULL) {
41256 X       fprintf(stderr," cannot allocate lmf_str\n");
41257 X       return NULL;
41258 X      }
41259 X
41260 X      m_fptr->tmp_buf_max = 0;
41261 X
41262 X      /* load the oid info */
41263 X      m_fptr->max_oid = 0;
41264 X      m_fptr->oid_seqs = 0;
41265 X      m_fptr->oid_list = (unsigned int *)calloc(1,sizeof(int));
41266 X      m_fptr->pref_db= -1;
41267 X
41268 X      if (ldnaseq==SEQT_DNA) {
41269 X       m_fptr->getlib = ncbl2_getlibn_o;
41270 X       m_fptr->sascii = nascii;
41271 X      }
41272 X      else {
41273 X       m_fptr->getlib = ncbl2_getliba_o;
41274 X       m_fptr->sascii = aascii;
41275 X      }
41276 X      strncpy(m_fptr->lb_name,sname,MAX_FN);
41277 X      return m_fptr;
41278 X    }
41279 X  }
41280 X       
41281 X  /* open the index file */
41282 X  if ((ifile = fopen(tname,RBSTR))==NULL) {
41283 X    fprintf(stderr," cannot open %s (%s) INDEX file",tname,name);
41284 X    perror("...");
41285 X    return 0;
41286 X  }
41287 X  src_uint4_read(ifile,(unsigned *)&dbformat); /* get format DB version number */
41288 X  src_uint4_read(ifile,(unsigned *)&dbtype);   /* get 1 for protein/0 DNA */
41289 X
41290 X  if (dbformat != FORMATDBV3 && dbformat!=FORMATDBV4) {
41291 X    fprintf(stderr,"error - %s wrong formatdb version (%d/%d)\n",
41292 X           tname,dbformat,FORMATDBV3);
41293 X    return NULL;
41294 X  }
41295 X
41296 X  if ((ldnaseq==SEQT_PROT && dbtype != AAFORMAT) || 
41297 X      (ldnaseq==SEQT_DNA && dbtype!=NTFORMAT)) {
41298 X    fprintf(stderr,"error - %s wrong format (%d/%d)\n",
41299 X           tname,dbtype,(ldnaseq ? NTFORMAT: AAFORMAT));
41300 X    return NULL;
41301 X  }
41302 X
41303 X  /* the files are there - allocate lmf_str */
41304 X
41305 X  if ((m_fptr=(struct lmf_str *)calloc(1,sizeof(struct lmf_str)))==NULL) {
41306 X    fprintf(stderr," cannot allocate lmf_str\n");
41307 X    return NULL;
41308 X  }
41309 X
41310 X  m_fptr->tmp_buf_max = 4096;
41311 X  if ((m_fptr->tmp_buf=
41312 X       (char *)calloc(m_fptr->tmp_buf_max,sizeof(char)))==NULL) {
41313 X    fprintf(stderr," cannot allocate lmf_str->tmp_buffer\n");
41314 X    return NULL;
41315 X  }
41316 X
41317 X  /* load the oid info */
41318 X  m_fptr->max_oid = max_oid;
41319 X  m_fptr->oid_seqs = oid_seqs;
41320 X  m_fptr->oid_list = oid_list;
41321 X  m_fptr->pref_db= pref_db;
41322 X
41323 X  /* open the header file */
41324 X  if ((m_fptr->hfile = fopen(hname,RBSTR))==NULL) {
41325 X    fprintf(stderr," cannot open %s header file\n",hname);
41326 X    goto error_r;
41327 X  }
41328 X
41329 X  /* ncbl2_ranlib is used for all BLAST2.0 access */
41330 X  m_fptr->ranlib = ncbl2_ranlib;
41331 X  m_fptr->bl_format_ver = dbformat;
41332 X
41333 X  if (ldnaseq==SEQT_DNA) {
41334 X    if (oid_seqs > 0) {
41335 X      m_fptr->getlib = ncbl2_getlibn_o;
41336 X    }
41337 X    else {
41338 X      m_fptr->getlib = ncbl2_getlibn;
41339 X    }
41340 X    m_fptr->sascii = nascii;
41341 X  }
41342 X  else {
41343 X    if (oid_seqs > 0) {
41344 X      m_fptr->getlib = ncbl2_getliba_o;
41345 X    }
41346 X    else {
41347 X      m_fptr->getlib = ncbl2_getliba;
41348 X    }
41349 X    m_fptr->sascii = aascii;
41350 X  }
41351 X  strncpy(m_fptr->lb_name,sname,MAX_FN);
41352 X
41353 X  /* open the sequence file */
41354 X
41355 #if defined (USE_MMAP) 
41356 X  m_fptr->mm_flg=((m_fptr->mmap_fd=open(sname,O_RDONLY))>=0);
41357 X  if (!m_fptr->mm_flg) {
41358 X    fprintf(stderr," cannot open %s",sname);
41359 X    perror("...");
41360 X  }
41361 X  else {
41362 X    if(fstat(m_fptr->mmap_fd, &statbuf) < 0) {
41363 X      fprintf(stderr," cannot fstat %s",sname);
41364 X      perror("...");
41365 X      m_fptr->mm_flg = 0;
41366 X    }
41367 X    else {
41368 X      m_fptr->st_size = statbuf.st_size;
41369 X      if((m_fptr->mmap_base = 
41370 X         mmap(NULL, m_fptr->st_size, PROT_READ,
41371 X              MAP_FILE | MAP_SHARED, m_fptr->mmap_fd, 0)) == (char *) -1) {
41372 X       fprintf(stderr," cannot mmap %s",sname);
41373 X       perror("...");
41374 X       m_fptr->mm_flg = 0;
41375 X      }  
41376 X      else {
41377 X       m_fptr->mmap_addr = m_fptr->mmap_base;
41378 X       m_fptr->mm_flg = 1;
41379 X      }
41380 X    }
41381 X    /* regardless, close the open()ed version */
41382 X    close(m_fptr->mmap_fd);
41383 X  }
41384 #else
41385 X  m_fptr->mm_flg = 0;
41386 #endif
41387 X
41388 X  if  (!m_fptr->mm_flg) {
41389 X    if ((m_fptr->libf = fopen(sname,RBSTR))==NULL) {
41390 X      fprintf(stderr," cannot open %s sequence file",sname);
41391 X      perror("...");
41392 X      goto error_r;
41393 X    }
41394 X  }
41395 X
41396 /* all files should be open */
41397 X
41398 X  src_uint4_read(ifile,(unsigned *)&title_len);
41399 X
41400 X  if (title_len > 0) {
41401 X    if ((title_str = calloc((size_t)title_len+1,sizeof(char)))==NULL) {
41402 X      fprintf(stderr," cannot allocate title string (%d)\n",title_len);
41403 X      goto error_r;
41404 X    }
41405 X    fread(title_str,(size_t)1,(size_t)title_len,ifile);
41406 X  }
41407 X  
41408 X  src_uint4_read(ifile,(unsigned *)&date_len);
41409 X
41410 X  if (date_len > 0) {
41411 X    if ((date_str = calloc((size_t)date_len+1,sizeof(char)))==NULL) {
41412 X      fprintf(stderr," cannot allocate date string (%d)\n",date_len);
41413 X      goto error_r;
41414 X    }
41415 X    fread(date_str,(size_t)1,(size_t)date_len,ifile);
41416 X  }
41417 X  
41418 X  m_fptr->lpos = 0;
41419 X  src_uint4_read(ifile,(unsigned *)&m_fptr->max_cnt);
41420 X  
41421 X  if (dbformat == FORMATDBV3) {
41422 X    src_long4_read(ifile,&ltmp);
41423 X    m_fptr->tot_len = ltmp;
41424 X  }
41425 X  else {
41426 X    ncbi_long8_read(ifile,&l8tmp);
41427 X    m_fptr->tot_len = ltmp;
41428 X  }
41429 X
41430 X  src_long4_read(ifile,&ltmp);
41431 X  m_fptr->max_len = ltmp;
41432 X
41433 X  /* currently we are not using this information, but perhaps later */
41434 X  if (title_str!=NULL) free(title_str);
41435 X  if (date_str!=NULL) free(date_str);
41436 X
41437 #ifdef DEBUG
41438 X    fprintf(stderr,"%s format: BL2 (%s)  max_cnt: %d, totlen: %lld, maxlen %ld\n",
41439 X           name,m_fptr->mm_flg ? "mmap" : "fopen", 
41440 X           m_fptr->max_cnt,m_fptr->tot_len,m_fptr->max_len);
41441 #endif
41442 X
41443 X  /* allocate and read hdr indexes */
41444 X  if ((f_pos_arr=(unsigned int *)calloc((size_t)m_fptr->max_cnt+1,sizeof(int)))==NULL) {
41445 X      fprintf(stderr," cannot allocate tmp header pointers\n");
41446 X      goto error_r;
41447 X    }
41448 X
41449 X  if ((m_fptr->d_pos_arr=(MM_OFF *)calloc((size_t)m_fptr->max_cnt+1,sizeof(MM_OFF)))==NULL) {
41450 X      fprintf(stderr," cannot allocate header pointers\n");
41451 X      goto error_r;
41452 X    }
41453 X
41454 X  /* allocate and read sequence offsets */
41455 X  if ((m_fptr->s_pos_arr=(MM_OFF *)calloc((size_t)m_fptr->max_cnt+1,sizeof(MM_OFF)))==NULL) {
41456 X      fprintf(stderr," cannot allocate sequence pointers\n");
41457 X      goto error_r;
41458 X    }
41459 X
41460 X  /*
41461 X  for (i=0; i<=m_fptr->max_cnt; i++) src_uint4_read(ifile,&m_fptr->d_pos_arr[i]);
41462 X  for (i=0; i<=m_fptr->max_cnt; i++) src_uint4_read(ifile,&m_fptr->s_pos_arr[i]);
41463 X  */
41464 X  if (fread(f_pos_arr,(size_t)4,m_fptr->max_cnt+1,ifile)!=m_fptr->max_cnt+1) {
41465 X    fprintf(stderr," error reading hdr offsets: %s\n",tname);
41466 X    goto error_r;
41467 X  }
41468 X
41469 X  for (i=0; i<=m_fptr->max_cnt; i++)
41470 #ifdef IS_BIG_ENDIAN
41471 X    m_fptr->d_pos_arr[i] = f_pos_arr[i];
41472 #else
41473 X    m_fptr->d_pos_arr[i] = bl2_uint4_cvt(f_pos_arr[i]);
41474 #endif
41475 X
41476 X  if (fread(f_pos_arr,(size_t)4,m_fptr->max_cnt+1,ifile)!=m_fptr->max_cnt+1) {
41477 X    fprintf(stderr," error reading seq offsets: %s\n",tname);
41478 X    goto error_r;
41479 X  }
41480 X  for (i=0; i<=m_fptr->max_cnt; i++) {
41481 #ifdef IS_BIG_ENDIAN
41482 X    m_fptr->s_pos_arr[i] = f_pos_arr[i];
41483 #else
41484 X    m_fptr->s_pos_arr[i] = bl2_uint4_cvt(f_pos_arr[i]);
41485 #endif
41486 X  }
41487 X
41488 X  if (dbtype == NTFORMAT) {
41489 X    /* allocate and ambiguity  offsets */
41490 X    if ((m_fptr->a_pos_arr=(MM_OFF *)calloc((size_t)m_fptr->max_cnt+1,sizeof(MM_OFF)))==NULL) {
41491 X      fprintf(stderr," cannot allocate sequence pointers\n");
41492 X      goto error_r;
41493 X    }
41494 X
41495 X    /*
41496 X    for (i=0; i<=m_fptr->max_cnt; i++) src_uint4_read(ifile,&m_fptr->a_pos_arr[i]);
41497 X    */
41498 X
41499 X    if (fread(f_pos_arr,(size_t)4,m_fptr->max_cnt+1,ifile)!=m_fptr->max_cnt+1) {
41500 X      fprintf(stderr," error reading seq offsets: %s\n",tname);
41501 X      goto error_r;
41502 X    }
41503 X    for (i=0; i<=m_fptr->max_cnt; i++) {
41504 #ifdef IS_BIG_ENDIAN
41505 X      m_fptr->a_pos_arr[i] = f_pos_arr[i];
41506 #else
41507 X      m_fptr->a_pos_arr[i] = bl2_uint4_cvt(f_pos_arr[i]);
41508 #endif
41509 X    }
41510 X  }
41511 X
41512 X  /*
41513 X  for (i=0; i < min(m_fptr->max_cnt,10); i++) {
41514 X    fprintf(stderr,"%d: %d %d %d\n",i,m_fptr->s_pos_arr[i],m_fptr->a_pos_arr[i],m_fptr->d_pos_arr[i]);
41515 X  }
41516 X  */
41517 X
41518 X  /* all done with ifile, close it */
41519 X  fclose(ifile);
41520 X
41521 X  free(f_pos_arr);
41522 X
41523 X  if (!m_fptr->mm_flg) {
41524 X    tmp = fgetc(m_fptr->libf);
41525 X    if (tmp!=NULLB)
41526 X      fprintf(stderr," phase error: %d:%d found\n",0,tmp);
41527 X  }
41528 X
41529 X  m_fptr->bl_lib_pos = 1;
41530 X  amb_cnt = 0;
41531 X  return m_fptr;
41532 X
41533 X error_r:
41534 X  /* here if failure after m_fptr allocated */
41535 X  free(m_fptr);
41536 X  return NULL;
41537 }
41538 X
41539 void ncbl2_closelib(struct lmf_str *m_fptr)
41540 {
41541 X  if (m_fptr->tmp_buf != NULL) {
41542 X    free(m_fptr->tmp_buf);
41543 X    m_fptr->tmp_buf_max = 0;
41544 X  }
41545 X
41546 X  if (m_fptr->s_pos_arr !=NULL) {
41547 X    free(m_fptr->s_pos_arr);
41548 X    m_fptr->s_pos_arr = NULL;
41549 X  }
41550 X  if (m_fptr->a_pos_arr!=NULL) {
41551 X    free(m_fptr->a_pos_arr);
41552 X    m_fptr->a_pos_arr = NULL;
41553 X  }
41554 X
41555 X  if (m_fptr->hfile !=NULL ) {
41556 X    fclose(m_fptr->hfile); m_fptr->hfile=NULL;
41557 X    free(m_fptr->d_pos_arr); m_fptr->d_pos_arr = NULL;
41558 X  }
41559 X
41560 X  if (m_fptr->oid_list != NULL) {
41561 X    free(m_fptr->oid_list); m_fptr->oid_list = NULL;
41562 X    m_fptr->oid_seqs = m_fptr->max_oid = 0;
41563 X  }
41564 X
41565 #ifdef use_mmap
41566 X  if (m_fptr->mm_flg) {
41567 X    munmap(m_fptr->mmap_base,m_fptr->st_size);
41568 X    m_fptr->mmap_fd = -1;
41569 X  }
41570 X  else 
41571 #endif
41572 X    if (m_fptr->libf !=NULL ) {fclose(m_fptr->libf); m_fptr->libf=NULL;}
41573 }
41574 X
41575 int
41576 ncbl2_getliba_o(unsigned char *seq,
41577 X               int maxs,
41578 X               char *libstr,
41579 X               int n_libstr,
41580 X               fseek_t *libpos,
41581 X               int *lcont,
41582 X               struct lmf_str *m_fd,
41583 X               long *l_off)
41584 {
41585 X  int tpos;
41586 X  unsigned int t_mask, t_shift, oid_mask;
41587 X  
41588 X  /* get to the next valid pointer */
41589 X  
41590 X  for ( tpos = m_fd->lpos ;tpos <= m_fd->max_oid; tpos++) {
41591 X    t_mask = tpos / 32;
41592 X    t_shift = 31 - (tpos % 32);
41593 X    if ((oid_mask = m_fd->oid_list[t_mask])==0) {  continue; }
41594 X
41595 X    if ((bl2_uint4_cvt(oid_mask) & 0x1 << t_shift)) {
41596 X      if (!m_fd->mm_flg) fseek(m_fd->libf,m_fd->s_pos_arr[tpos],0);
41597 X      m_fd->lpos = tpos;       /* already bumped up */
41598 X      m_fd->bl_lib_pos = m_fd->s_pos_arr[tpos];
41599 X      return ncbl2_getliba(seq, maxs, libstr, n_libstr,
41600 X                          libpos, lcont, m_fd, l_off);
41601 X    }
41602 X  }
41603 X  return -1;
41604 }
41605 X
41606 int
41607 ncbl2_getliba(unsigned char *seq,
41608 X             int maxs,
41609 X             char *libstr,
41610 X             int n_libstr,
41611 X             fseek_t *libpos,
41612 X             int *lcont,
41613 X             struct lmf_str *m_fd,
41614 X             long *l_off)
41615 {
41616 X  unsigned char *sptr, *dptr;
41617 X  int s_chunk, d_len, lib_cnt;
41618 X  long seqcnt;
41619 X  long tmp;
41620 X  static long seq_len;
41621 #if defined(DEBUG) || defined(PCOMPLIB)
41622 X  int gi, my_db, taxid;
41623 X  char acc[20], title[21], name[20];
41624 #endif
41625 X  
41626 X  *l_off = 1;
41627 X
41628 X  lib_cnt = m_fd->lpos;
41629 X  *libpos = (fseek_t)m_fd->lpos;
41630 X
41631 X  if (*lcont==0) {
41632 X    if (lib_cnt >= m_fd->max_cnt) return -1;   /* no more sequences */
41633 X    seq_len = m_fd->s_pos_arr[lib_cnt+1] - m_fd->s_pos_arr[lib_cnt]; /* value is +1 off to get the NULL */
41634 X    if (m_fd->mm_flg) m_fd->mmap_addr = m_fd->mmap_base+m_fd->s_pos_arr[lib_cnt];
41635 #if !defined(DEBUG) && !defined(PCOMPLIB)
41636 X    libstr[0]='\0';
41637 #else
41638 X    /* get the name from the header file */
41639 X    fseek(m_fd->hfile,m_fd->d_pos_arr[lib_cnt],0);
41640 X
41641 X    if (m_fd->bl_format_ver == FORMATDBV3) {
41642 X      d_len = min(n_libstr-1,m_fd->d_pos_arr[lib_cnt+1]-m_fd->d_pos_arr[lib_cnt]-1);
41643 X      fread(libstr,(size_t)1,(size_t)d_len,m_fd->hfile);
41644 X      libstr[d_len]='\0';
41645 X    }
41646 X    else {
41647 X      d_len = min(m_fd->tmp_buf_max,m_fd->d_pos_arr[lib_cnt+1]-m_fd->d_pos_arr[lib_cnt]-1);
41648 X      fread(m_fd->tmp_buf,(size_t)1,(size_t)d_len,m_fd->hfile);
41649 X      parse_fastadl_asn((unsigned char *)m_fd->tmp_buf, (unsigned char *)m_fd->tmp_buf+d_len,
41650 X                       &gi, &my_db, acc, name, title, 20, &taxid);
41651 X      sprintf(libstr,"gi|%d",gi);
41652 X    }
41653 #endif
41654 X  }
41655 X  if (seq_len <= maxs) { /* sequence fits */
41656 X    seqcnt = seq_len;
41657 X    m_fd->lpos++;
41658 X    *lcont = 0;
41659 X  }
41660 X  else {               /* doesn't fit */
41661 X    seqcnt = maxs-1;
41662 X    (*lcont)++;
41663 X  } 
41664 X
41665 X  if (m_fd->mm_flg) sptr = (unsigned char *)m_fd->mmap_addr;
41666 X  else {
41667 X    if ((tmp=fread(seq,(size_t)1,(size_t)seq_len,m_fd->libf))!=(size_t)seq_len) {
41668 X      fprintf(stderr," could not read sequence record: %ld %ld != %ld\n",
41669 X             *libpos,tmp,seq_len);
41670 X      goto error; 
41671 X    }
41672 X    sptr = seq;
41673 X  }
41674 X  if (seq_len <= maxs) {seqcnt = --seq_len;}
41675 X
41676 X  /* everything is ready, set up dst. pointer, seq_len */
41677 X  dptr = seq;
41678 X
41679 X  if (aa_b2toa[sptr[seq_len-1]]=='*') seq_len--;
41680 X  s_chunk = seqcnt/16;
41681 X  while (s_chunk-- > 0) {
41682 X    *dptr++ = aa_btof[*sptr++];
41683 X    *dptr++ = aa_btof[*sptr++];
41684 X    *dptr++ = aa_btof[*sptr++];
41685 X    *dptr++ = aa_btof[*sptr++];
41686 X    *dptr++ = aa_btof[*sptr++];
41687 X    *dptr++ = aa_btof[*sptr++];
41688 X    *dptr++ = aa_btof[*sptr++];
41689 X    *dptr++ = aa_btof[*sptr++];
41690 X    *dptr++ = aa_btof[*sptr++];
41691 X    *dptr++ = aa_btof[*sptr++];
41692 X    *dptr++ = aa_btof[*sptr++];
41693 X    *dptr++ = aa_btof[*sptr++];
41694 X    *dptr++ = aa_btof[*sptr++];
41695 X    *dptr++ = aa_btof[*sptr++];
41696 X    *dptr++ = aa_btof[*sptr++];
41697 X    *dptr++ = aa_btof[*sptr++];
41698 X  }
41699 X  while (dptr < seq+seqcnt) *dptr++ = aa_btof[*sptr++];
41700 X
41701 X  if (m_fd->mm_flg) m_fd->mmap_addr = (char *)sptr;
41702 X
41703 X  /* we didn't get it all, so reset for more */
41704 X  if (*lcont) seq_len -= seqcnt;
41705 X
41706 X  seq[seqcnt]= EOSEQ;
41707 X  return (seqcnt);
41708 X  
41709 error:  fprintf(stderr," error reading %s at %ld\n",libstr,*libpos);
41710 X  fflush(stderr);
41711 X  return (-1);
41712 }
41713 X
41714 int 
41715 ncbl2_getlibn_o(unsigned char *seq,
41716 X               int maxs,
41717 X               char *libstr,
41718 X               int n_libstr,
41719 X               fseek_t *libpos,
41720 X               int *lcont,
41721 X               struct lmf_str *m_fd,
41722 X               long *l_off)
41723 {
41724 X  int tpos;
41725 X  unsigned int t_mask, t_shift, oid_mask;
41726 X  
41727 X  /* get to the next valid pointer */
41728 X  
41729 X  for (tpos = m_fd->lpos; tpos <= m_fd->max_oid; tpos++) {
41730 X    t_mask = tpos / 32;
41731 X    t_shift = 31 - (tpos % 32);
41732 X    if ((oid_mask = m_fd->oid_list[t_mask])==0) {  continue; }
41733 X
41734 X    if ((bl2_uint4_cvt(oid_mask) & 0x1 << t_shift)) {
41735 X      if (!m_fd->mm_flg) fseek(m_fd->libf,m_fd->s_pos_arr[tpos],0);
41736 X      m_fd->lpos = tpos;       /* already bumped up */
41737 X      m_fd->bl_lib_pos = m_fd->s_pos_arr[tpos];
41738 X      return ncbl2_getlibn(seq, maxs, libstr, n_libstr,
41739 X                          libpos, lcont, m_fd, l_off);
41740 X    }
41741 X  }
41742 X  return -1;
41743 }
41744 X
41745 static char tmp_amb[4096];
41746 X
41747 int
41748 ncbl2_getlibn(unsigned char *seq,
41749 X             int maxs,
41750 X             char *libstr,
41751 X             int n_libstr,
41752 X             fseek_t *libpos,
41753 X             int *lcont,
41754 X             struct lmf_str *m_fd,
41755 X             long *l_off)
41756 {
41757 X  unsigned char *sptr, *tptr, stmp;
41758 X  long seqcnt;
41759 X  int s_chunk, lib_cnt;
41760 X  size_t tmp;
41761 X  char ch;
41762 X  static long seq_len;
41763 X  static int c_len,c_pad;
41764 X  int c_len_set, d_len;
41765 X
41766 X  *l_off = 1;
41767 X
41768 X  lib_cnt = m_fd->lpos;
41769 X  *libpos = (fseek_t)lib_cnt;
41770 X  if (*lcont==0) {     /* not a continuation of previous */
41771 X    if (lib_cnt >= m_fd->max_cnt) return (-1);
41772 X    c_len = m_fd->a_pos_arr[lib_cnt]- m_fd->s_pos_arr[lib_cnt];
41773 X    if (!m_fd->mm_flg) {
41774 X      if (m_fd->bl_lib_pos != m_fd->s_pos_arr[lib_cnt]) { /* are we positioned to read? */
41775 X       amb_cnt++;
41776 X       if ((m_fd->bl_lib_pos - m_fd->s_pos_arr[lib_cnt]) < sizeof(tmp_amb)) {
41777 X         /* jump over amb_ray */
41778 X         fread(tmp_amb,(size_t)1,(size_t)(m_fd->s_pos_arr[lib_cnt]-m_fd->bl_lib_pos),m_fd->libf);
41779 X       }
41780 X       else {  /* fseek over amb_ray */
41781 X         fseek(m_fd->libf,m_fd->s_pos_arr[lib_cnt],0);
41782 X       }
41783 X       m_fd->bl_lib_pos = m_fd->s_pos_arr[lib_cnt];
41784 X      }
41785 X    }
41786 X    else m_fd->mmap_addr = m_fd->mmap_base + m_fd->s_pos_arr[lib_cnt];
41787 #if !defined(DEBUG) && !defined(PCOMPLIB)
41788 X    libstr[0]='\0';
41789 #else
41790 X    /* get the name from the header file */
41791 X    fseek(m_fd->hfile,m_fd->d_pos_arr[lib_cnt],0);
41792 X
41793 X    d_len = min(n_libstr-1,m_fd->d_pos_arr[lib_cnt+1]-m_fd->d_pos_arr[lib_cnt]-1);
41794 X    fread(libstr,(size_t)1,(size_t)d_len,m_fd->hfile);
41795 X    libstr[d_len]='\0';
41796 #endif
41797 X  }                    /* end of *lcont==0 */
41798 X
41799 X  /* To avoid the situation where c_len <= 1; we must anticipate what
41800 X     c_len will be after this pass.  If it will be <= 64, back off this
41801 X     time so next time it will be > 64 */
41802 X
41803 X  seq_len = c_len*4;
41804 X
41805 X  if ((seq_len+4 > maxs) && (seq_len+4 - maxs  <= 256)) {
41806 X    /* we won't be done but we will have less than 256 to go */
41807 X    c_len -= 64; seq_len -= 256; c_len_set = 1; maxs -= 256;}
41808 X  else c_len_set = 0;
41809 X
41810 X  /*
41811 X  fprintf(stderr," lib_cnt: %d %d %d %d\n",lib_cnt,c_len,seq_len,maxs);
41812 X  */
41813 X
41814 X  /* does the rest of the sequence fit? */
41815 X  if (seq_len <= maxs-4 && !c_len_set) {
41816 X    seqcnt = c_len;
41817 X    if (!m_fd->mm_flg) {
41818 X      if ((tmp=fread(seq,(size_t)1,(size_t)seqcnt,m_fd->libf))!=(size_t)seqcnt) {
41819 X       fprintf(stderr,
41820 X               " could not read sequence record: %s %lld %ld != %ld: %d\n",
41821 X               libstr,*libpos,tmp,seqcnt,*seq);
41822 X       goto error; 
41823 X      }
41824 X      m_fd->bl_lib_pos += tmp;
41825 X      sptr = seq + seqcnt;
41826 X    }
41827 X    else sptr = (unsigned char *)(m_fd->mmap_addr+seqcnt);
41828 X
41829 X    *lcont = 0;                /* this is the last chunk */
41830 X    lib_cnt++;         /* increment to the next sequence */
41831 X    /* the last byte is either '0' (no remainder) or the last 1-3 chars and the remainder */
41832 X    c_pad = *(sptr-1);
41833 X    c_pad &= 0x3;      /* get the last (low) 2 bits */
41834 X    seq_len -= (4 - c_pad);    /* if the last 2 bits are 0, its a NULL byte */
41835 X  }
41836 X  else {       /* get the next chunk, but more to come */
41837 X    seqcnt = ((maxs+3)/4)-1;
41838 X    if (!m_fd->mm_flg) {
41839 X      if ((tmp=fread(seq,(size_t)1,(size_t)(seqcnt),m_fd->libf))!=(size_t)(seqcnt)) {
41840 X       fprintf(stderr," could not read sequence record: %lld %ld/%ld\n",
41841 X               *libpos,tmp,seqcnt);
41842 X       goto error;
41843 X      }
41844 X      m_fd->bl_lib_pos += tmp;
41845 X      sptr = seq + seqcnt;
41846 X    }
41847 X    else {
41848 X      sptr = (unsigned char *)(m_fd->mmap_addr+seqcnt);
41849 X      m_fd->mmap_addr += seqcnt;
41850 X    }
41851 X    seq_len = 4*seqcnt;
41852 X    c_len -= seqcnt;
41853 X    if (c_len_set) {c_len += 64; maxs += 256;}
41854 X    (*lcont)++;
41855 /*  hopefully we don't need this because of c_len -= 64. */
41856 /*
41857 X    if (c_len == 1) {
41858 #if !defined (USE_MMAP)
41859 X      c_pad = fgetc(m_fd->libf);
41860 X      *sptr=c_pad;
41861 #else
41862 X      c_pad = *m_fd->mmap_addr++;
41863 X      sptr = m_fd->mmap_addr;
41864 #endif
41865 X      c_pad &= 0x3;
41866 X      seq_len += c_pad;
41867 X      seqcnt++;
41868 X      lib_cnt++;
41869 X      *lcont = 0;
41870 X    }
41871 */
41872 X  }
41873 X
41874 X  /* point to the last packed byte and to the end of the array
41875 X     seqcnt is the exact number of bytes read
41876 X     tptr points to the destination, use multiple of 4 to simplify math
41877 X     sptr points to the source, note that the last byte will be read 4 cycles
41878 X     before it is written
41879 X     */
41880 X  
41881 X  tptr = seq + 4*seqcnt;
41882 X  s_chunk = seqcnt/8;
41883 X  while (s_chunk-- > 0) {
41884 X    stmp = *--sptr;
41885 X    *--tptr = (stmp&3) +1;
41886 X    *--tptr = ((stmp >>= 2)&3)+1;
41887 X    *--tptr = ((stmp >>= 2)&3)+1;
41888 X    *--tptr = ((stmp >>= 2)&3)+1;
41889 X    stmp = *--sptr;
41890 X    *--tptr = (stmp&3) +1;
41891 X    *--tptr = ((stmp >>= 2)&3)+1;
41892 X    *--tptr = ((stmp >>= 2)&3)+1;
41893 X    *--tptr = ((stmp >>= 2)&3)+1;
41894 X    stmp = *--sptr;
41895 X    *--tptr = (stmp&3) +1;
41896 X    *--tptr = ((stmp >>= 2)&3)+1;
41897 X    *--tptr = ((stmp >>= 2)&3)+1;
41898 X    *--tptr = ((stmp >>= 2)&3)+1;
41899 X    stmp = *--sptr;
41900 X    *--tptr = (stmp&3) +1;
41901 X    *--tptr = ((stmp >>= 2)&3)+1;
41902 X    *--tptr = ((stmp >>= 2)&3)+1;
41903 X    *--tptr = ((stmp >>= 2)&3)+1;
41904 X    stmp = *--sptr;
41905 X    *--tptr = (stmp&3) +1;
41906 X    *--tptr = ((stmp >>= 2)&3)+1;
41907 X    *--tptr = ((stmp >>= 2)&3)+1;
41908 X    *--tptr = ((stmp >>= 2)&3)+1;
41909 X    stmp = *--sptr;
41910 X    *--tptr = (stmp&3) +1;
41911 X    *--tptr = ((stmp >>= 2)&3)+1;
41912 X    *--tptr = ((stmp >>= 2)&3)+1;
41913 X    *--tptr = ((stmp >>= 2)&3)+1;
41914 X    stmp = *--sptr;
41915 X    *--tptr = (stmp&3) +1;
41916 X    *--tptr = ((stmp >>= 2)&3)+1;
41917 X    *--tptr = ((stmp >>= 2)&3)+1;
41918 X    *--tptr = ((stmp >>= 2)&3)+1;
41919 X    stmp = *--sptr;
41920 X    *--tptr = (stmp&3) +1;
41921 X    *--tptr = ((stmp >>= 2)&3)+1;
41922 X    *--tptr = ((stmp >>= 2)&3)+1;
41923 X    *--tptr = ((stmp >>= 2)&3)+1;
41924 X  }
41925 X  while (tptr>seq) {
41926 X    stmp = *--sptr;
41927 X    *--tptr = (stmp&3) +1;
41928 X    *--tptr = ((stmp >>= 2)&3)+1;
41929 X    *--tptr = ((stmp >>= 2)&3)+1;
41930 X    *--tptr = ((stmp >>= 2)&3)+1;
41931 X  }
41932 X  /*
41933 X    for (sptr=seq; sptr < seq+seq_len; sptr++) {
41934 X    printf("%c",nt[*sptr]);
41935 X    if ((int)(sptr-seq) % 60 == 59) printf("\n");
41936 X    }
41937 X    printf("\n");
41938 X    */
41939 X
41940 X  m_fd->lpos = lib_cnt;
41941 X  if (seqcnt*4 >= seq_len) {   /* there was enough room */
41942 X    seq[seq_len]= EOSEQ;
41943 X    /* printf("%d\n",seq_len); */
41944 X    return seq_len;
41945 X  }
41946 X  else {                               /* not enough room */
41947 X    seq[seqcnt*4]=EOSEQ;
41948 X    seq_len -= 4*seqcnt;
41949 X    return (4*seqcnt);
41950 X  }
41951 X  
41952 error:  fprintf(stderr," error reading %s at %ld\n",libstr,*libpos);
41953 X  fflush(stderr);
41954 X  return (-1);
41955 }
41956 X
41957 X                /*   0     1     2     3    4     5     6    7
41958 X                    8     9    10    11   12    13    14   15
41959 X                    16    17 */
41960 static char
41961 *db_type_arr[] = {"lcl","gib","gim","gii","gb","emb","pir","sp",
41962 X                 "pat","ref","gnl","gi","dbj","prf","pdb","tpg",
41963 X                 "tpe","tpd"};
41964 X
41965 void
41966 ncbl2_ranlib(char *str,
41967 X            int cnt,
41968 X            fseek_t libpos,
41969 X            char *libstr,
41970 X            struct lmf_str *m_fd)
41971 {
41972 X  int llen, lib_cnt;
41973 X  char *bp;
41974 X  unsigned char *my_buff=NULL;
41975 X  char descr[2048];
41976 X  unsigned char *abp;
41977 X  int gi, taxid;
41978 X  int my_db;
41979 X  char db[5], acc[20], name[20];
41980 X  char title[1024];
41981 X  int have_my_buff=0;
41982 X  int have_descr = 0;
41983 X
41984 X  lib_cnt = (int)libpos;
41985 X  llen = m_fd->d_pos_arr[lib_cnt+1]-m_fd->d_pos_arr[lib_cnt];
41986 X
41987 X  fseek(m_fd->hfile,m_fd->d_pos_arr[libpos],0);
41988 X
41989 X  if (m_fd->bl_format_ver == FORMATDBV3) {
41990 X    if (llen >= cnt) llen = cnt-1;
41991 X    fread(str,(size_t)1,(size_t)(llen),m_fd->hfile);
41992 X  }
41993 X  else {
41994 X    if (llen >= m_fd->tmp_buf_max) {
41995 X      if ((my_buff=(unsigned char *)calloc(llen,sizeof(char)))==NULL) {
41996 X       fprintf(stderr," cannot allocate ASN.1 buffer: %d\n",llen);
41997 X       my_buff = (unsigned char *)m_fd->tmp_buf;
41998 X       llen = m_fd->tmp_buf_max;
41999 X      }
42000 X      else have_my_buff = 1;
42001 X    }
42002 X    else { 
42003 X      my_buff = (unsigned char *)m_fd->tmp_buf;
42004 X    }
42005 X    abp = my_buff;
42006 X    fread(my_buff,(size_t)1,llen,m_fd->hfile);
42007 X
42008 X    do {
42009 X      abp = parse_fastadl_asn(abp, my_buff+llen,
42010 X                             &gi, &my_db, acc, name,
42011 X                             title, sizeof(title), &taxid);
42012 X
42013 X      if (gi > 0) {
42014 X       sprintf(descr,"gi|%d|%s|%s|%s ",gi,db_type_arr[my_db],acc,name);
42015 X      }
42016 X      else {
42017 X       if (acc[0] != '\0') sprintf(descr,"%s ",acc);
42018 X       else descr[0] = '\0';
42019 X       if (name[0] != '\0' && strcmp(name,"BL_ORD_ID")!=0) sprintf(descr+strlen(descr),"%s ", name);
42020 X      }
42021 X      if (m_fd->pref_db < 0) {
42022 X       if (!have_descr) {
42023 X         strncpy(str,descr,cnt-1);
42024 X         have_descr = 1;
42025 X       }
42026 X       else {
42027 X         strncat(str,"\001",cnt-strlen(str)-1);
42028 X         strncat(str,descr,cnt-strlen(str)-1);
42029 X       }
42030 X       strncat(str,title,cnt-strlen(str)-1);
42031 X       if (strlen(str) >= cnt-1) break;
42032 X      }
42033 X      else if (m_fd->pref_db == my_db) {
42034 X       have_descr = 1;
42035 X       strncpy(str,descr,cnt-1);
42036 X       strncat(str,title,cnt-strlen(str)-1);
42037 X       break;
42038 X      }
42039 X    } while (abp);
42040 X
42041 X    if (!have_descr) {
42042 X      strncpy(str,descr,cnt-1);
42043 X      strncat(str,descr,cnt-strlen(str)-1);
42044 X    }
42045 X
42046 X    if (have_my_buff) free(my_buff);
42047 X  }
42048 X
42049 X  str[cnt-1]='\0';
42050 X
42051 X  bp = str;
42052 X  while((bp=strchr(bp,'\001'))!=NULL) {*bp++=' ';}
42053 X
42054 X  if (!m_fd->mm_flg) fseek(m_fd->libf,m_fd->s_pos_arr[libpos],0);
42055 X
42056 X  m_fd->lpos = lib_cnt;
42057 X  m_fd->bl_lib_pos = m_fd->s_pos_arr[lib_cnt];
42058 }
42059 X
42060 unsigned int bl2_uint4_cvt(unsigned int val)
42061 {
42062 X  unsigned int res;
42063 #ifdef IS_BIG_ENDIAN
42064 X  return val;
42065 #else /* it better be LITTLE_ENDIAN */
42066 X  res = ((val&255)*256)+ ((val>>8)&255);
42067 X  res = (res<<16) + (((val>>16)&255)*256) + ((val>>24)&255);
42068 X  return res;
42069 #endif
42070 }  
42071 X
42072 unsigned int bl2_long4_cvt(long val)
42073 {
42074 X  int val4;
42075 X  unsigned int res;
42076 #ifdef IS_BIG_ENDIAN
42077 X  val4 = val;
42078 X  return val4;
42079 #else /* it better be LITTLE_ENDIAN */
42080 X  res = ((val&255)*256)+ ((val>>8)&255);
42081 X  res = (res<<16) + (((val>>16)&255)*256) + ((val>>24)&255);
42082 X  return res;
42083 #endif
42084 }  
42085 X
42086 int64_t bl2_long8_cvt(int64_t val)
42087 {
42088 X  int64_t res;
42089 #ifdef IS_BIG_ENDIAN
42090 X  return val;
42091 #else /* it better be LITTLE_ENDIAN */
42092 X  res = ((val&255)*256)+ ((val>>8)&255);
42093 X  res = (res<<16) + (((val>>16)&255)*256) + ((val>>24)&255);
42094 #ifdef BIG_LIB64
42095 X  res = (res<<16) + (((val>>32)&255)*256) + ((val>>40)&255);
42096 X  res = (res<<16) + (((val>>48)&255)*256) + ((val>>56)&255);
42097 #else
42098 X  fprintf(stderr,"Cannot use bl2_long8_cvt without 64-bit longs\n");
42099 X  exit(1);
42100 #endif
42101 X  return res;
42102 #endif
42103 }  
42104 X
42105 void src_int4_read(FILE *fd,  int *val)
42106 {
42107 #ifdef IS_BIG_ENDIAN
42108 X  fread((char *)val,(size_t)4,(size_t)1,fd);
42109 #else
42110 X  unsigned char b[4];
42111 X
42112 X  fread((char *)&b[0],(size_t)1,(size_t)4,fd);
42113 X  *val = 0;
42114 X  *val = (int)((int)((int)(b[0]<<8)+(int)b[1]<<8)+(int)b[2]<<8)
42115 X         +(int)b[3];
42116 #endif
42117 }
42118 X
42119 void src_long4_read(FILE *fd,  long *valp)
42120 {
42121 X  int val4;
42122 #ifdef IS_BIG_ENDIAN
42123 X  fread(&val4,(size_t)4,(size_t)1,fd);
42124 X  *valp = val4;
42125 #else
42126 X  unsigned char b[4];
42127 X
42128 X  fread((char *)&b[0],(size_t)1,(size_t)4,fd);
42129 X  val4 = 0;
42130 X  val4 = (int)((int)((int)(b[0]<<8)+(int)b[1]<<8)+(int)b[2]<<8)
42131 X         +(int)b[3];
42132 X  *valp = val4;
42133 #endif
42134 }
42135 X
42136 void src_uint4_read(FILE *fd,  unsigned int *valp)
42137 {
42138 #ifdef IS_BIG_ENDIAN
42139 X  fread(valp,(size_t)4,(size_t)1,fd);
42140 #else
42141 X  unsigned char b[4];
42142 X
42143 X  fread((char *)&b[0],(size_t)1,(size_t)4,fd);
42144 X  *valp = 0;
42145 X  *valp = (unsigned int)((int)((int)(b[0]<<8)+(int)b[1]<<8)+(int)b[2]<<8)
42146 X         +(int)b[3];
42147 #endif
42148 }
42149 X
42150 void src_long8_read(FILE *fd,  long *val)
42151 {
42152 #ifdef IS_BIG_ENDIAN
42153 X  fread((void *)val,(size_t)8,(size_t)1,fd);
42154 #else
42155 X  unsigned char b[8];
42156 X
42157 X  fread((char *)&b[0],(size_t)1,(size_t)8,fd);
42158 X  *val = 0;
42159 X  *val = (long)((((((long)((long)(b[0]<<8)+(long)b[1]<<8)+(long)b[2]<<8)
42160 X                 +(long)b[3]<<8)+(long)b[4]<<8)+(long)b[5]<<8)
42161 X               +(long)b[6]<<8)+(long)b[7];
42162 #endif
42163 }
42164 X
42165 void ncbi_long8_read(FILE *fd,  int64_t *val)
42166 {
42167 X  unsigned char b[8];
42168 X
42169 X  fread((char *)&b[0],(size_t)1,(size_t)8,fd);
42170 X  *val = 0;
42171 X  *val = (long)((((((long)((long)(b[7]<<8)+(long)b[6]<<8)+(long)b[5]<<8)
42172 X                 +(long)b[4]<<8)+(long)b[3]<<8)+(long)b[2]<<8)
42173 X               +(long)b[1]<<8)+(long)b[0];
42174 }
42175 X
42176 void src_char_read(FILE *fd, char *val)
42177 {
42178 X  fread(val,(size_t)1,(size_t)1,fd);
42179 }
42180 X
42181 void src_fstr_read(FILE *fd, char *val,  int slen)
42182 {
42183 X  fread(val,(size_t)slen,(size_t)1,fd);
42184 }
42185 X
42186 void
42187 newname(char *nname, char *oname, char *suff, int maxn)
42188 {
42189 X  strncpy(nname,oname,maxn-1);
42190 X  strncat(nname,".",1);
42191 X  strncat(nname,suff,maxn-strlen(nname));
42192 }
42193 X
42194 #define ASN_SEQ 0x30
42195 #define ASN_IS_BOOL 1
42196 #define ASN_IS_INT 2
42197 #define ASN_IS_STR 26
42198 X
42199 unsigned char *
42200 get_asn_int(unsigned char *abp, int *val) {
42201 X
42202 X  int v_len, v;
42203 X
42204 X  v = 0;
42205 X  if (*abp++ != ASN_IS_INT) { /* check for int */
42206 X    fprintf(stderr," int missing\n");
42207 X  }
42208 X  else {
42209 X    v_len = *abp++;
42210 X    while (v_len-- > 0) {
42211 X      v *= 256;
42212 X      v += *abp++;
42213 X    }
42214 X    abp += 2;  /* skip over null's */
42215 X  }
42216 X  *val = v;
42217 X  return abp;
42218 }
42219 X
42220 unsigned char *
42221 get_asn_text(unsigned char *abp, char *text, int t_len) {
42222 X  int tch, at_len;
42223 X
42224 X  text[0] = '\0';
42225 X  if (*abp++ != ASN_IS_STR) { /* check for str */
42226 X    fprintf(stderr," str missing\n");
42227 X  }
42228 X  else {
42229 X    if ((tch = *abp++) > 128) {        /* string length is in next bytes */
42230 X      tch &= 0x7f;     /* get number of bytes for len */
42231 X      at_len = 0;
42232 X      while (tch-- > 0) { at_len = (at_len << 8) + *abp++;}
42233 X    }
42234 X    else {
42235 X      at_len = tch;
42236 X    }
42237 X
42238 X    if ( at_len < t_len-1) {
42239 X      memcpy(text, abp, at_len);
42240 X      text[at_len] = '\0';
42241 X    }
42242 X    else {
42243 X      memcpy(text, abp, t_len-1);
42244 X      text[t_len-1] = '\0';
42245 X    }
42246 X    abp += at_len + 2;
42247 X  }
42248 X  return abp;
42249 }
42250 X
42251 /* something to try to skip over stuff we don't want */
42252 unsigned char *
42253 get_asn_junk(unsigned char *abp) {
42254 X
42255 X  int seq_cnt = 0;
42256 X  int tmp;
42257 X  char string[256];
42258 X
42259 X  while (*abp) {
42260 X    if ( *abp  == ASN_SEQ) { abp += 2; seq_cnt++;}
42261 X    else if ( *abp == ASN_IS_BOOL ) {abp = get_asn_int(abp, &tmp);}
42262 X    else if ( *abp == ASN_IS_INT ) {abp = get_asn_int(abp, &tmp);}
42263 X    else if ( *abp == ASN_IS_STR ) {abp = get_asn_text(abp, string, sizeof(string)-1);}
42264 X  }
42265 X
42266 X  while (seq_cnt-- > 0) abp += 2;
42267 X  return abp;
42268 }
42269 X
42270 unsigned char *
42271 get_asn_textseq_id(unsigned char *abp, 
42272 X                  char *name, char *acc)
42273 {
42274 X  char release[20], ver_str[10];
42275 X  int version;
42276 X  int seqcnt = 0;
42277 X
42278 X  ver_str[0]='\0';
42279 X
42280 X  if (*abp == ASN_SEQ) { abp += 2; seqcnt++;}
42281 X
42282 X  while (*abp) {
42283 X    switch (*abp) {
42284 X    case 0xa0:
42285 X      abp = get_asn_text(abp+2, name, 20);
42286 X      break;
42287 X    case 0xa1:
42288 X      abp = get_asn_text(abp+2, acc, 20);
42289 X      break;
42290 X    case 0xa2:
42291 X      abp = get_asn_text(abp+2, release, sizeof(release));
42292 X      break;
42293 X    case 0xa3:
42294 X      abp = get_asn_int(abp+2, &version);
42295 X      sprintf(ver_str,".%d",version);
42296 X      break;
42297 X    default: abp += 2;
42298 X    }
42299 X  }
42300 X  while (seqcnt-- > 0) abp += 4;
42301 X  strncat(acc,ver_str,20-strlen(acc));
42302 X  acc[19]='\0';
42303 X  return abp;  /* skip 2 NULL's */
42304 }
42305 X
42306 unsigned char *
42307 get_asn_local_id(unsigned char *abp, char *acc)
42308 {
42309 X  int seqcnt = 0;
42310 X
42311 X  if (*abp == ASN_SEQ) { abp += 2; seqcnt++;}
42312 X
42313 X  abp = get_asn_text(abp+2, acc, 20);
42314 X
42315 X  while (seqcnt-- > 0) abp += 4;
42316 X  acc[19]='\0';
42317 X  return abp;  /* skip 2 NULL's */
42318 }
42319 X
42320 unsigned char *
42321 get_asn_dbtag(unsigned char *abp, char *name, char *str, int *id_p) {
42322 X
42323 X  if (*abp == ASN_SEQ) { abp += 2;}
42324 X
42325 X  if (*abp == 0xa0) {  /* get db */
42326 X    abp = get_asn_text(abp+2, name, 20);
42327 X  }
42328 X  else {
42329 X    fprintf(stderr," missing dbtag:db %d %d\n",abp[0],abp[1]);
42330 X    abp += 2;
42331 X  }
42332 X
42333 X  if (*abp == 0xa1) {  /* get tag */
42334 X    abp += 2;
42335 X    abp += 2; /* skip over id */
42336 X    if (*abp == 2) abp = get_asn_int(abp,id_p);
42337 X    else abp = get_asn_text(abp+2, str, 20);
42338 X  }
42339 X  else {
42340 X    fprintf(stderr," missing dbtag:tag %2x %2x\n",abp[0],abp[1]);
42341 X    abp += 2;
42342 X  }
42343 X  return abp+2;        /* skip 2 NULL's */
42344 }
42345 X
42346 unsigned char *
42347 get_asn_pdb_id(unsigned char *abp, char *acc, char *chain)
42348 {
42349 X  int ichain, seq_cnt=0;
42350 X
42351 X  if (*abp == ASN_SEQ) { abp += 2; seq_cnt++;}
42352 X
42353 X  while (*abp) {
42354 X    switch (*abp) {
42355 X    case 0: abp += 2; break;
42356 X    case 0xa0: /* mol-id */
42357 X      abp = get_asn_text(abp+2, acc, 20);
42358 X      break;
42359 X    case 0xa1:
42360 X      abp = get_asn_int(abp+2, &ichain);
42361 X      chain[0] = ichain;
42362 X      chain[1] = '\0';
42363 X      break;
42364 X    case 0xa2: /* ignore date - scan until NULL's */
42365 X      while (*abp++) {}
42366 X      abp += 2;                /* skip the NULL's */
42367 X      break;
42368 X    default: abp+=2;
42369 X    }
42370 X  }
42371 X  while (seq_cnt-- > 0) {abp += 4;}
42372 X  return abp;
42373 }
42374 X
42375 #define ASN_TYPE_MASK 31
42376 X
42377 unsigned char
42378 *get_asn_seqid(unsigned char *abp,
42379 X              int *gi_p, int *db, char *acc, char *name) {
42380 X
42381 X  int db_type, itmp, seq_cnt=0;
42382 X
42383 X  *gi_p = 0;
42384 X
42385 X  if (*abp != ASN_SEQ) {
42386 X    fprintf(stderr, "seqid - missing SEQ 1: %2x %2x\n",abp[0], abp[1]);
42387 X    return abp;
42388 X  }
42389 X  else { abp += 2; seq_cnt++;}
42390 X
42391 X  db_type = (*abp & ASN_TYPE_MASK);
42392 X
42393 X  if (db_type == 11) { /* gi */
42394 X    abp = get_asn_int(abp+2,gi_p);
42395 X  }
42396 X  
42397 X  while (*abp == ASN_SEQ) {abp += 2; seq_cnt++;}
42398 X
42399 X  db_type = (*abp & ASN_TYPE_MASK);
42400 X  if (db_type > 17) {db_type = 0;}
42401 X  *db = db_type;
42402 X
42403 X  switch(db_type) {
42404 X  case 0: 
42405 X    abp = get_asn_local_id(abp+2, acc);
42406 X    break;
42407 X  case 1:
42408 X  case 2:
42409 X    abp = get_asn_int(abp+2,&itmp);
42410 X    abp += 2;
42411 X    break;
42412 X  case 11:
42413 X    abp = get_asn_int(abp+2,&itmp);
42414 X    break;
42415 X  case 4:
42416 X  case 5:
42417 X  case 6:
42418 X  case 7:
42419 X  case 9:
42420 X  case 12:
42421 X  case 13:
42422 X  case 15:
42423 X  case 16:
42424 X  case 17:
42425 X    abp = get_asn_textseq_id(abp+2,name,acc);
42426 X    break;
42427 X  case 10:
42428 X    abp = get_asn_dbtag(abp+2,name,acc,&itmp);
42429 X  case 14:
42430 X    abp = get_asn_pdb_id(abp+2,acc,name);
42431 X    break;
42432 X  default: abp += 2;
42433 X  }
42434 X  
42435 X  while (seq_cnt-- > 0) { abp += 4;}
42436 X  return abp; /* skip over 2 NULL's */
42437 }
42438 X
42439 #define ASN_FADL_TITLE 0xa0
42440 #define ASN_FADL_SEQID 0xa1
42441 #define ASN_FADL_TAXID 0xa2
42442 #define ASN_FADL_MEMBERS 0xa3
42443 #define ASN_FADL_LINKS 0xa4
42444 #define ASN_FADL_OTHER 0xa5
42445 X
42446 unsigned char *
42447 parse_fastadl_asn(unsigned char *asn_buff, unsigned char *asn_max,
42448 X                 int *gi_p, int *db, char *acc,
42449 X                 char *name, char *title, int t_len, int *taxid_p) {
42450 X  unsigned char *abp;
42451 X  char tmp_db[4], tmp_acc[32], tmp_name[32];
42452 X  int this_db;
42453 X  int seq_cnt = 0;
42454 X  int tmp_gi;
42455 X
42456 X  acc[0] = name[0] = db[0] = title[0] = '\0';
42457 X
42458 X  abp = asn_buff;
42459 X  while ( abp < asn_max && *abp) {
42460 X    if (*abp == ASN_SEQ) { abp += 2; seq_cnt++; }
42461 X    else if (*abp == ASN_FADL_TITLE) {
42462 X      abp = get_asn_text(abp+2, title, t_len);
42463 X    }
42464 X    else if (*abp == ASN_FADL_SEQID ) {
42465 X      abp = get_asn_seqid(abp+2, gi_p, db, acc, name);
42466 X      if (*db > 17) *db = 0;
42467 X    }
42468 X    else if (*abp == ASN_FADL_TAXID ) {
42469 X      abp = get_asn_int(abp+2, taxid_p);
42470 X    }
42471 X    else if (*abp == ASN_FADL_MEMBERS) {
42472 X      abp = get_asn_junk(abp+2);
42473 X    }
42474 X    else if (*abp == ASN_FADL_LINKS ) {
42475 X      abp = get_asn_junk(abp+2);
42476 X    }
42477 X    else if (*abp == ASN_FADL_OTHER ) {
42478 X      abp = get_asn_junk(abp+2);
42479 X    }
42480 X    else {
42481 X      /*       fprintf(stderr, " Error - missing ASN.1 %2x:%2x:%2x:%2x\n", 
42482 X              abp[-2],abp[-1],abp[0],abp[1]); */
42483 X      abp += 2;
42484 X    }
42485 X  }
42486 X  while (abp < asn_max && *abp == '\0'  ) abp++;
42487 X  if (abp >= asn_max) return NULL;
42488 X  else return abp;
42489 }
42490 X
42491 X
42492 void
42493 parse_pal(char *dname, char *msk_name,
42494 X         int *oid_seqs, int *max_oid,
42495 X         FILE *fd) {
42496 X
42497 X  char line[MAX_STR];
42498 X
42499 X  while (fgets(line,sizeof(line),fd)) {
42500 X    if (line[0] == '#') continue;
42501 X
42502 X    if (strncmp(line, "DBLIST", 6)==0) {
42503 X      sscanf(line+7,"%s",dname);
42504 X    }
42505 X    else if (strncmp(line, "OIDLIST", 7)==0) {
42506 X      sscanf(line+8,"%s",msk_name);
42507 X    }
42508 X    else if (strncmp(line, "NSEQ", 4)==0) {
42509 X      sscanf(line+5,"%d",oid_seqs);
42510 X    }
42511 X    else if (strncmp(line, "MAXOID", 6)==0) {
42512 X      sscanf(line+7,"%d",max_oid);
42513 X    }
42514 X  }
42515 }
42516 SHAR_EOF
42517 chmod 0644 ncbl2_mlib.c ||
42518 echo 'restore of ncbl2_mlib.c failed'
42519 Wc_c="`wc -c < 'ncbl2_mlib.c'`"
42520 test 42930 -eq "$Wc_c" ||
42521         echo 'ncbl2_mlib.c: original size 42930, current size' "$Wc_c"
42522 fi
42523 # ============= ncbl_head.h ==============
42524 if test -f 'ncbl_head.h' -a X"$1" != X"-c"; then
42525         echo 'x - skipping ncbl_head.h (File already exists)'
42526 else
42527 echo 'x - extracting ncbl_head.h (Text)'
42528 sed 's/^X//' << 'SHAR_EOF' > 'ncbl_head.h' &&
42529 /* ncbl_head.h  header files for blast1.3 format */
42530 X
42531 /* $Name: fa_34_26_5 $ - $Id: ncbl_head.h,v 1.1.1.1 1999/10/22 20:56:01 wrp Exp $ */
42532 X
42533 #define AMINO_ACID_SEQTYPE      1
42534 #define AA_SEQTYPE      AMINO_ACID_SEQTYPE
42535 #define NUCLEIC_ACID_SEQTYPE    2
42536 #define NT_SEQTYPE      NUCLEIC_ACID_SEQTYPE
42537 X
42538 /* Filename extensions used by the two types of databases (a.a. and nt.) */
42539 #define AA_HEADER_EXT   "ahd"
42540 #define AA_TABLE_EXT    "atb"
42541 #define AA_SEARCHSEQ_EXT        "bsq"
42542 #define NT_HEADER_EXT   "nhd"
42543 #define NT_TABLE_EXT    "ntb"
42544 #define NT_SEARCHSEQ_EXT        "csq"
42545 X
42546 #define DB_TYPE_PRO     0x78857a4f      /* Magic # for a protein sequence database */
42547 #define DB_TYPE_NUC     0x788325f8      /* Magic # for a nt. sequence database */
42548 X
42549 #define AAFORMAT        3       /* Latest a.a. database format ID number */
42550 #define NTFORMAT        6       /* Latest nt. database format ID number */
42551 X
42552 #define NULLB           '\0'    /* sentinel byte */
42553 #define NT_MAGIC_BYTE   0xfc    /* Magic byte at end of compressed nt db */
42554 X
42555 #ifndef CHAR_BIT
42556 #define CHAR_BIT        8       /* these values should match blast */
42557 #endif
42558 X
42559 #define NBPN            2
42560 #define NSENTINELS      2
42561 SHAR_EOF
42562 chmod 0644 ncbl_head.h ||
42563 echo 'restore of ncbl_head.h failed'
42564 Wc_c="`wc -c < 'ncbl_head.h'`"
42565 test 1034 -eq "$Wc_c" ||
42566         echo 'ncbl_head.h: original size 1034, current size' "$Wc_c"
42567 fi
42568 # ============= ncbl_lib.c ==============
42569 if test -f 'ncbl_lib.c' -a X"$1" != X"-c"; then
42570         echo 'x - skipping ncbl_lib.c (File already exists)'
42571 else
42572 echo 'x - extracting ncbl_lib.c (Text)'
42573 sed 's/^X//' << 'SHAR_EOF' > 'ncbl_lib.c' &&
42574 /*      ncbl_lib.c      functions to read ncbi-blast format files from
42575 X                       setdb (blastp 1.3.2) format files
42576 X
42577 X               copyright (c) 1992 William R. Pearson
42578 */
42579 X
42580 /* $Name: fa_34_26_5 $ - $Id: ncbl_lib.c,v 1.9 2006/10/05 18:22:07 wrp Exp $ */
42581 X
42582 #include <stdio.h>
42583 #include <stdlib.h>
42584 #include <string.h>
42585 X
42586 #ifndef WIN32
42587 #define RBSTR "r"
42588 #else
42589 #define RBSTR "rb"
42590 #endif
42591 X
42592 #define XTERNAL
42593 #include "uascii.h"
42594 #include "upam.h"
42595 #include "ncbl_head.h"
42596 #include "mm_file.h"
42597 X
42598 int ncbl_getliba(char *, int, char *, int, fseek_t *, int *, struct lmf_str *, long *);
42599 int ncbl_getlibn(char *, int, char *, int, fseek_t *, int *, struct lmf_str *, long *);
42600 X
42601 void src_ulong_read();
42602 X
42603 #ifndef NCBL13_ONLY
42604 static void src_char_read();
42605 static void newname(char *, char *, char *, int);
42606 #else
42607 void src_char_read();
42608 void newname(char *, char *, char *, int);
42609 #endif
42610 X
42611 /* nt_btoa maps  from blast 2bit  format to ascii  characters */
42612 static char nt_btoa[5] = {"ACGT"};
42613 X
42614 static char aa_btoa[27]= {"-ARNDCQEGHILKMFPSTWYVBZX*"};
42615 static int aa_btof[32]; /* maps to fasta alphabet */
42616 X
42617 static FILE *tfile=NULL,        /* table of offsets, also DB info */
42618 X           *hfile=NULL,        /* description lines */
42619 X           *sfile=NULL;        /* binary sequence data */
42620 X
42621 static unsigned long lib_cnt, max_cnt, totlen, mxlen, dbline_len;
42622 static unsigned long *seq_beg, *hdr_beg;
42623 static unsigned char *ambiguity_ray;
42624 static long seq_format, dbtype, dbformat;
42625 static char dline[512];
42626 X
42627 #define NCBIBL13 11
42628 X
42629 struct lmf_str *
42630 ncbl_openlib(char *name, int ldnaseq)
42631 {
42632 X  char hname[256];
42633 X  char sname[256];
42634 X  char tname[256];
42635 X  long title_len;
42636 X  char *title_str;
42637 X  int rdtmp;
42638 X  int i;
42639 X  unsigned long line_len, c_len, clean_count;
42640 X
42641 X  if (ldnaseq!=1) {
42642 X    newname(tname,name,AA_TABLE_EXT,(int)sizeof(tname));
42643 X    if ((tfile = fopen(tname,RBSTR))==NULL) {
42644 X      fprintf(stderr," cannot open %s (%s.%s) table file\n",
42645 X             name,tname,NT_TABLE_EXT);
42646 X      return (-1);
42647 X    }
42648 X    seq_format = AAFORMAT;
42649 X  }
42650 X  else {
42651 X    newname(tname,name,NT_TABLE_EXT,(int)sizeof(tname));
42652 X    if ((tfile = fopen(tname,RBSTR))==NULL) {
42653 X      fprintf(stderr," cannot open %s (%s.%s) table file\n",
42654 X             name,tname,NT_TABLE_EXT);
42655 X      return (-1);
42656 X    }
42657 X    seq_format = NTFORMAT;
42658 X  }
42659 X       
42660 X  src_ulong_read(tfile,&dbtype);
42661 X  src_ulong_read(tfile,&dbformat);
42662 X
42663 X  if (seq_format == AAFORMAT && (dbformat != seq_format || dbtype !=
42664 X                                DB_TYPE_PRO)) {
42665 X    fprintf(stderr,"error - %s wrong type (%ld/%d) or format (%ld/%ld)\n",
42666 X           tname,dbtype,DB_TYPE_PRO,dbformat,seq_format);
42667 X    return (-1);
42668 X  }
42669 X  else if (seq_format == NTFORMAT && (dbformat != seq_format || dbtype !=
42670 X                                DB_TYPE_NUC)) {
42671 X    fprintf(stderr,"error - %s wrong type (%ld/%d) or format (%ld/%ld)\n",
42672 X           tname,dbtype,DB_TYPE_NUC,dbformat,seq_format);
42673 X    return (-1);
42674 X  }
42675 X
42676 X  if (seq_format == AAFORMAT) {
42677 X    newname(hname,name,AA_HEADER_EXT,(int)sizeof(hname));
42678 X    if ((hfile = fopen(hname,RBSTR))==NULL) {
42679 X      fprintf(stderr," cannot open %s header file\n",hname);
42680 X      return (-1);
42681 X    }
42682 X    newname(sname,name,AA_SEARCHSEQ_EXT,(int)sizeof(sname));
42683 X    if ((sfile = fopen(sname,RBSTR))==NULL) {
42684 X      fprintf(stderr," cannot open %s sequence file\n",sname);
42685 X      return (-1);
42686 X    }
42687 X  }
42688 X  else {
42689 X    newname(hname,name,NT_HEADER_EXT,(int)sizeof(hname));
42690 X    if ((hfile = fopen(hname,RBSTR))==NULL) {
42691 X      fprintf(stderr," cannot open %s header file\n",hname);
42692 X      return (-1);
42693 X    }
42694 X    newname(sname,name,NT_SEARCHSEQ_EXT,(int)sizeof(sname));
42695 X    if ((sfile = fopen(sname,RBSTR))==NULL) {
42696 X      fprintf(stderr," cannot open %s sequence file\n",sname);
42697 X      return (-1);
42698 X    }
42699 X  }
42700 X
42701 /* all files should be open */
42702 X
42703 X  src_ulong_read(tfile,&title_len);
42704 X  rdtmp = title_len + ((title_len%4 !=0 ) ? 4-(title_len%4) : 0);
42705 X  if ((title_str = calloc((size_t)rdtmp,sizeof(char)))==NULL) {
42706 X    fprintf(stderr," cannot allocate title string (%d)\n",rdtmp);
42707 X    return(-1);
42708 X  }
42709 X  fread(title_str,(size_t)1,(size_t)rdtmp,tfile);
42710 X
42711 X  lib_cnt = 0;
42712 X  if (seq_format == AAFORMAT) {
42713 X    src_ulong_read(tfile,&max_cnt);
42714 X    src_ulong_read(tfile,&totlen);
42715 X    src_ulong_read(tfile,&mxlen);
42716 X
42717 X    /* fprintf(stderr," max_cnt: %d, totlen: %d\n",max_cnt,totlen); */
42718 X
42719 X    if ((seq_beg=(unsigned long *)calloc((size_t)max_cnt+1,sizeof(long)))==NULL) {
42720 X      fprintf(stderr," cannot allocate sequence pointers\n");
42721 X      return -1;
42722 X    }
42723 X    if ((hdr_beg=(unsigned long *)calloc((size_t)max_cnt+1,sizeof(long)))==NULL) {
42724 X      fprintf(stderr," cannot allocate header pointers\n");
42725 X      return -1;
42726 X    }
42727 X    for (i=0; i<max_cnt+1; i++) src_ulong_read(tfile,&seq_beg[i]);
42728 X    for (i=0; i<max_cnt+1; i++) src_ulong_read(tfile,&hdr_beg[i]);
42729 X
42730 X    for (i=0; i<sizeof(aa_btoa); i++) {
42731 X      if ((rdtmp=aascii[aa_btoa[i]])<NA) aa_btof[i]=rdtmp;
42732 X      else aa_btof[i]=aascii['X'];
42733 X    }
42734 X  }
42735 X  else if (seq_format == NTFORMAT) {
42736 X    src_ulong_read(tfile,&dbline_len); /* length of uncompress DB lines */
42737 X    src_ulong_read(tfile,&max_cnt);    /* number of entries */
42738 X    src_ulong_read(tfile,&mxlen);      /* maximum length sequence */
42739 X    src_ulong_read(tfile,&totlen);     /* total count */
42740 X    src_ulong_read(tfile,&c_len);      /* compressed db length */
42741 X    src_ulong_read(tfile,&clean_count);        /* count of nt's cleaned */
42742 X
42743 X    fseek(tfile,(size_t)((clean_count)*4),1);
42744 X                                        /* seek over clean_count */
42745 X    if ((seq_beg=(unsigned long *)calloc((size_t)max_cnt+1,sizeof(long)))==NULL) {
42746 X      fprintf(stderr," cannot allocate sequence pointers\n");
42747 X      return -1;
42748 X    }
42749 X    if ((hdr_beg=(unsigned long *)calloc((size_t)max_cnt+1,sizeof(long)))==NULL) {
42750 X      fprintf(stderr," cannot allocate header pointers\n");
42751 X      return -1;
42752 X    }
42753 X    if ((ambiguity_ray=
42754 X        (unsigned char *)calloc((size_t)max_cnt/CHAR_BIT+1,sizeof(char)))==NULL) {
42755 X      fprintf(stderr," cannot allocate ambiguity_ray\n");
42756 X      return -1;
42757 X    }
42758 X
42759 X    for (i=0; i<max_cnt+1; i++) src_ulong_read(tfile,&seq_beg[i]);
42760 X    fseek(tfile,(size_t)((max_cnt+1)*4),1);
42761 X                                        /* seek over seq_beg */
42762 X    for (i=0; i<max_cnt+1; i++) src_ulong_read(tfile,&hdr_beg[i]);
42763 X    for (i=0; i<max_cnt/CHAR_BIT+1; i++)
42764 X      src_char_read(tfile,&ambiguity_ray[i]);
42765 X  }
42766 X  return 1;
42767 }
42768 X
42769 void ncbl_closelib()
42770 {
42771 X  if (tfile !=NULL ) {fclose(tfile); tfile=NULL;}
42772 X  if (hfile !=NULL ) {fclose(hfile); hfile=NULL;}
42773 X  if (sfile !=NULL ) {fclose(sfile); sfile=NULL;}
42774 }
42775 X
42776 int
42777 ncbl_getliba(char *seq, int maxs,
42778 X            char *libstr, int n_libstr,
42779 X            fseek_t *libpos,
42780 X            int lcont)
42781 {
42782 X  register char *sptr;
42783 X  long seqcnt;
42784 X  long tmp;
42785 X  char ch;
42786 X  static long seq_len;
42787 X  
42788 X  *libpos = lib_cnt;
42789 X  if (*lcont==0) {
42790 X    if (lib_cnt >= max_cnt) return -1;
42791 X    seq_len = seq_beg[lib_cnt+1] - seq_beg[lib_cnt] -1;
42792 X    tmp=(long)fgetc(sfile);    /* skip the null byte */
42793 X    if (tmp!=NULLB)
42794 X      fprintf(stderr," phase error: %ld:%ld found\n",lib_cnt,tmp);
42795 X    libstr[0]='\0';
42796 X    }
42797 X  
42798 X  if (seq_len < maxs) {
42799 X    if ((tmp=fread(seq,(size_t)1,(size_t)seq_len,sfile))!=(size_t)seq_len) {
42800 X      fprintf(stderr," could not read sequence record: %ld %ld != %ld\n",
42801 X             *libpos,tmp,seq_len);
42802 X      goto error; 
42803 X    }
42804 X    if (aa_btoa[seq[seq_len-1]]=='*') seqcnt = seq_len-1;
42805 X    else seqcnt=seq_len;
42806 X    lib_cnt++;
42807 X    *lcont = 0;
42808 X  }
42809 X  else {
42810 X    if (fread(seq,(size_t)1,(size_t)(maxs-1),sfile)!=(size_t)(maxs-1)) {
42811 X      fprintf(stderr," could not read sequence record: %ld %ld\n",
42812 X             *libpos,seq_len);
42813 X      goto error;
42814 X    }
42815 X    (*lcont)++;
42816 X    seqcnt = maxs-1;
42817 X    seq_len -= seqcnt;
42818 X  }
42819 X  sptr = seq+seqcnt;
42820 X
42821 X  while (--sptr >= seq) *sptr = aa_btof[*sptr];
42822 X  
42823 X  seq[seqcnt]= EOSEQ;
42824 X  return (seqcnt);
42825 X  
42826 error:  fprintf(stderr," error reading %ld at %ld\n",libstr,*libpos);
42827 X  fflush(stderr);
42828 X  return (-1);
42829 }
42830 X
42831 int
42832 ncbl_getlibn(char *seq, int maxs,
42833 X            char *libstr, int n_libstr,
42834 X            fseek_t *libpos, int *lcont)
42835 {
42836 X  register char *sptr, *tptr, stmp;
42837 X  long seqcnt;
42838 X  long tmp;
42839 X  char ch;
42840 X  static long seq_len;
42841 X  static int c_len,c_pad;
42842 X  
42843 X  *libpos = lib_cnt;
42844 X  if (*lcont==0) {
42845 X    if (lib_cnt >= max_cnt) return -1;
42846 X    c_len = seq_beg[lib_cnt+1]/(CHAR_BIT/NBPN)
42847 X               - seq_beg[lib_cnt]/(CHAR_BIT/NBPN);
42848 X    c_len -= NSENTINELS;
42849 X
42850 X    seq_len = c_len*(CHAR_BIT/NBPN);
42851 X    c_pad = seq_beg[lib_cnt] & ((CHAR_BIT/NBPN)-1);
42852 X    if (c_pad != 0) seq_len -= ((CHAR_BIT/NBPN) - c_pad);
42853 X
42854 X    tmp=fgetc(sfile);  /* skip the null byte */
42855 X    if (tmp!=NT_MAGIC_BYTE) {
42856 X      fprintf(stderr," phase error: %ld:%ld (%ld/%d) found\n",
42857 X             lib_cnt,seq_len,tmp,NT_MAGIC_BYTE);
42858 X      goto error;
42859 X    }
42860 X    libstr[0]='\0';
42861 X  }
42862 X
42863 X  if (seq_len < maxs-3) {
42864 X    seqcnt=(seq_len+3)/4;
42865 X    if (seqcnt==0) seqcnt++;
42866 X    if ((tmp=fread(seq,(size_t)1,(size_t)seqcnt,sfile))
42867 X       !=(size_t)seqcnt) {
42868 X      fprintf(stderr,
42869 X             " could not read sequence record: %s %ld %ld != %ld: %d\n",
42870 X             libstr,*libpos,tmp,seqcnt,*seq);
42871 X      goto error; 
42872 X    }
42873 X    tmp=fgetc(sfile);  /* skip the null byte */
42874 X    if (tmp!=(unsigned char)NT_MAGIC_BYTE) {
42875 X      fprintf(stderr," phase2 error: %ld:%ld (%ld/%d) next ",
42876 X             lib_cnt,seqcnt,tmp,NT_MAGIC_BYTE);
42877 X      
42878 X      goto error;
42879 X    }
42880 X    *lcont = 0;
42881 X    lib_cnt++;
42882 X  }
42883 X  else {
42884 X    seqcnt = ((maxs+3)/4)-1;
42885 X    if (fread(seq,(size_t)1,(size_t)(seqcnt),sfile)!=(size_t)(seqcnt)) {
42886 X      fprintf(stderr," could not read sequence record: %s %ld %ld\n",
42887 X             libstr,*libpos,seqcnt);
42888 X      goto error;
42889 X    }
42890 X    (*lcont)++;
42891 X  }
42892 X  
42893 X  /* point to the last packed byte and to the end of the array
42894 X     seqcnt is the exact number of bytes read
42895 X     tptr points to the destination, use multiple of 4 to simplify math
42896 X     sptr points to the source, note that the last byte will be read 4 cycles
42897 X     before it is written
42898 X     */
42899 X  
42900 X  sptr = seq + seqcnt;
42901 X  tptr = seq + 4*seqcnt;
42902 X  while (sptr>seq) {
42903 X    stmp = *--sptr;
42904 X    *--tptr = (stmp&3) +1;
42905 X    *--tptr = ((stmp >>= 2)&3)+1;
42906 X    *--tptr = ((stmp >>= 2)&3)+1;
42907 X    *--tptr = ((stmp >>= 2)&3)+1;
42908 X  }
42909 X  /*
42910 X    for (sptr=seq; sptr < seq+seq_len; sptr++) {
42911 X    printf("%c",nt[*sptr]);
42912 X    if ((int)(sptr-seq) % 60 == 59) printf("\n");
42913 X    }
42914 X    printf("\n");
42915 X    */
42916 X  if (seqcnt*4 >= seq_len) {   /* there was enough room */
42917 X    seq[seq_len]= EOSEQ;
42918 X    /* printf("%d\n",seq_len); */
42919 X    return seq_len;
42920 X  }
42921 X  else {                               /* not enough room */
42922 X    seq[seqcnt*4]=EOSEQ;
42923 X    seq_len -= 4*seqcnt;
42924 X    return (4*seqcnt);
42925 X  }
42926 X  
42927 error:  fprintf(stderr," error reading %ld at %ld\n",libstr,*libpos);
42928 X  fflush(stderr);
42929 X  return (-1);
42930 }
42931 X
42932 void
42933 ncbl_ranlib(str,cnt,libpos)
42934 X       char *str; int cnt;
42935 X       long libpos;
42936 {
42937 X  char hline[256], *bp, *bp0;
42938 X  int llen;
42939 X  long spos;
42940 X
42941 X  lib_cnt = libpos;
42942 X  llen = hdr_beg[lib_cnt+1]-hdr_beg[lib_cnt];
42943 X  if (llen > sizeof(hline)) llen = sizeof(hline);
42944 X  fseek(hfile,hdr_beg[lib_cnt]+1,0);
42945 X
42946 X  fread(hline,(size_t)1,(size_t)(llen-1),hfile);
42947 X  hline[llen-1]='\0';
42948 X
42949 X  if (hline[9]=='|' || hline[10]=='|') {
42950 X    bp0 = strchr(hline+3,'|');
42951 X    if ((bp=strchr(bp0+1,' '))!=NULL) *bp='\0';
42952 X    if (dbformat == NTFORMAT && 
42953 X       (ambiguity_ray[lib_cnt/CHAR_BIT]&(1<<lib_cnt%CHAR_BIT))) {
42954 X      sprintf(str,"*%-9s ",bp0+1);
42955 X    }
42956 X    else sprintf(str,"%-10s ",bp0+1);
42957 X    strncat(str+11,bp+1,cnt-strlen(str));
42958 X  }
42959 X  else {
42960 X    if (dbformat == NTFORMAT && 
42961 X       (ambiguity_ray[lib_cnt/CHAR_BIT]&(1<<lib_cnt%CHAR_BIT))) {
42962 X      str[0]='*'; 
42963 X      strncpy(str+1,hline,cnt-1);
42964 X    }
42965 X    else strncpy(str,hline,cnt);
42966 X  }
42967 X  str[cnt-1]='\0';
42968 X
42969 X  if (dbformat == AAFORMAT)
42970 X    fseek(sfile,seq_beg[lib_cnt]-1,0);
42971 X  else {
42972 X    spos = (seq_beg[lib_cnt])/(CHAR_BIT/NBPN);
42973 X    fseek(sfile,spos-1,0);
42974 X  }
42975 }
42976 X
42977 void src_ulong_read(fd, val)
42978 X     FILE *fd;
42979 X     unsigned long *val;
42980 {
42981 #ifdef IS_BIG_ENDIAN
42982 X  fread((char *)val,(size_t)4,(size_t)1,fd);
42983 #else
42984 X  unsigned char b[4];
42985 X
42986 X  fread((char *)&b[0],(size_t)1,(size_t)4,fd);
42987 X  *val = 0;
42988 X  *val = (unsigned long)((unsigned long)((unsigned long)(b[0]<<8) +
42989 X        (unsigned long)b[1]<<8) + (unsigned long)b[2]<<8)+(unsigned long)b[3];
42990 #endif
42991 }
42992 X
42993 void src_long_read(fd,val)
42994 X     FILE *fd;
42995 X     long *val;
42996 {
42997 #ifdef IS_BIG_ENDIAN
42998 X  fread((char *)val,(size_t)4,(size_t)1,fd);
42999 #else
43000 X  unsigned char b[4];
43001 X
43002 X  fread((char *)&b[0],(size_t)1,(size_t)4,fd);
43003 X  *val = 0;
43004 X  *val = (long)((long)((long)(b[0]<<8)+(long)b[1]<<8)+(long)b[2]<<8)
43005 X         +(long)b[3];
43006 #endif
43007 }
43008 X
43009 #ifndef NCBL13_ONLY
43010 static void
43011 #else
43012 void
43013 #endif
43014 src_char_read(fd, val)
43015 X     FILE *fd;
43016 X     char *val;
43017 {
43018 X  fread(val,(size_t)1,(size_t)1,fd);
43019 }
43020 X
43021 #ifndef NCBL13_ONLY
43022 static void
43023 #else
43024 void
43025 #endif
43026 src_fstr_read(fd, val, slen)
43027 X     FILE *fd;
43028 X     char *val;
43029 X     long slen;
43030 {
43031 X  fread(val,(size_t)slen,(size_t)1,fd);
43032 }
43033 X
43034 #ifndef NCBL13_ONLY
43035 static void
43036 #else
43037 void
43038 #endif
43039 newname(char *nname, char *oname, char *suff, int maxn)
43040 {
43041 X  char *tptr;
43042 X
43043 X  if (oname[0]=='@') strncpy(nname,&oname[1],maxn);
43044 X  else strncpy(nname,oname,maxn);
43045 X  for (tptr=nname; *tptr=='.' && *tptr; tptr++);
43046 X  for (; *tptr!='.'&& *tptr; tptr++); /* get to '.' or EOS */
43047 X  *tptr++='.'; *tptr='\0';
43048 X  strncat(nname,suff,maxn);
43049 }
43050 X
43051 SHAR_EOF
43052 chmod 0644 ncbl_lib.c ||
43053 echo 'restore of ncbl_lib.c failed'
43054 Wc_c="`wc -c < 'ncbl_lib.c'`"
43055 test 12694 -eq "$Wc_c" ||
43056         echo 'ncbl_lib.c: original size 12694, current size' "$Wc_c"
43057 fi
43058 # ============= ngt.aa ==============
43059 if test -f 'ngt.aa' -a X"$1" != X"-c"; then
43060         echo 'x - skipping ngt.aa (File already exists)'
43061 else
43062 echo 'x - extracting ngt.aa (Text)'
43063 sed 's/^X//' << 'SHAR_EOF' > 'ngt.aa' &&
43064 >GT8.7 | 40001 90043 | transl. of pa875.con, 19 to 675
43065 ILGYWN,
43066 DQYRMFEP,
43067 SRYIATP,
43068 KCLDAFP,
43069 EYTDS,
43070 SYDEKR,
43071 YTMGD,
43072 EKQKPEFL,
43073 VRGLTHP,
43074 TRMQLI,
43075 FKLGLDFP,
43076 NLPYLI,
43077 DGSHKIT,
43078 LRYLAR,
43079 KTIPEK,
43080 KRPWFA,
43081 ETEEERIR,
43082 GDKVTYVD,
43083 HWSNK
43084 SHAR_EOF
43085 chmod 0644 ngt.aa ||
43086 echo 'restore of ngt.aa failed'
43087 Wc_c="`wc -c < 'ngt.aa'`"
43088 test 217 -eq "$Wc_c" ||
43089         echo 'ngt.aa: original size 217, current size' "$Wc_c"
43090 fi
43091 # ============= ngts.aa ==============
43092 if test -f 'ngts.aa' -a X"$1" != X"-c"; then
43093         echo 'x - skipping ngts.aa (File already exists)'
43094 else
43095 echo 'x - extracting ngts.aa (Text)'
43096 sed 's/^X//' << 'SHAR_EOF' > 'ngts.aa' &&
43097 >GT8.7 | 40001 90043 | transl. of pa875.con, 19 to 675
43098 ILGY*WN,
43099 EYTDS?,
43100 S?YDEKR,
43101 DQY*RMFEP,
43102 KCLDAFP,
43103 S*RY*IATP
43104 SHAR_EOF
43105 chmod 0644 ngts.aa ||
43106 echo 'restore of ngts.aa failed'
43107 Wc_c="`wc -c < 'ngts.aa'`"
43108 test 111 -eq "$Wc_c" ||
43109         echo 'ngts.aa: original size 111, current size' "$Wc_c"
43110 fi
43111 # ============= nmgetlib.c ==============
43112 if test -f 'nmgetlib.c' -a X"$1" != X"-c"; then
43113         echo 'x - skipping nmgetlib.c (File already exists)'
43114 else
43115 echo 'x - extracting nmgetlib.c (Text)'
43116 sed 's/^X//' << 'SHAR_EOF' > 'nmgetlib.c' &&
43117 X
43118 /* $Name: fa_34_26_5 $ - $Id: nmgetlib.c,v 1.35 2007/01/08 15:38:46 wrp Exp $ */
43119 X
43120 /*      May, June 1987  - modified for rapid read of database
43121 X
43122 X       copyright (c) 1987,1988,1989,1992,1995,2000 William R. Pearson
43123 X
43124 X       revised (split) version of nmgetaa.c -> renamed nmgetlib.c
43125 X
43126 X       This version seeks to be a thread safe, no global, library
43127 X       reading program.  While adjusting the routines in this file
43128 X       should be relatively easy, ncbl2_mlib.c and mysql_lib.c may be
43129 X       more difficult.
43130 X
43131 X       nmgetlib.c and mmgetaa.c are used together.  nmgetlib.c provides
43132 X       the same functions as nxgetaa.c if memory mapping is not used,
43133 X       mmgetaa.c provides the database reading functions if memory
43134 X       mapping is used. The decision to use memory mapping is made on
43135 X       a file-by-file basis.
43136 X
43137 X       June 2, 1987 - added TFASTA
43138 X       March 30, 1988 - combined ffgetaa, fgetgb;
43139 X       April 8, 1988 - added PIRLIB format for unix
43140 X       Feb 4, 1989 - added universal subroutines for libraries
43141 X       December, 1995 - added range option file.name:1-1000
43142 X       September, 1999 - added option for mmap()ed files using ".xin" */
43143 X
43144 X
43145 /*
43146 X       February 4, 1988 - this starts a major revision of the getaa
43147 X       routines.  The goal is to be able to seach the following format
43148 X       libraries:
43149 X
43150 X       0 - normal FASTA format
43151 X       1 - full Genbank tape format
43152 X       2 - NBRF/PIR CODATA format
43153 X       3 - EMBL/Swiss-prot format
43154 X       4 - Intelligentics format
43155 X       5 - NBRF/PIR VMS format
43156 X       6 - GCG 2bit format
43157 X
43158 X       11 - NCBI setdb/blastp (1.3.2) AA/NT
43159 X       12 - NCBI setdb/blastp (2.0) AA/NT
43160 X       16 - mySQL queries
43161 X
43162 X       see file altlib.h to confirm numbers
43163 X
43164 */
43165 X
43166 #include <stdio.h>
43167 #include <stdlib.h>
43168 #include <string.h>
43169 #include <ctype.h>
43170 X
43171 #include "defs.h"
43172 #include "structs.h"
43173 X
43174 #ifndef SFCHAR
43175 #define SFCHAR ':'
43176 #endif
43177 X
43178 #define EOSEQ 0
43179 X
43180 #include "uascii.h"
43181 /* #include "upam.h" */
43182 X
43183 #define LFCHAR '\015'  /* for MWC 5.5 */
43184 X
43185 #include "altlib.h"
43186 X
43187 X
43188 #include <fcntl.h>
43189 #ifndef O_RAW
43190 #ifdef O_BINARY
43191 #define O_RAW O_BINARY
43192 #else
43193 #define O_RAW 0
43194 #endif          /* O_BINARY */
43195 #endif          /* O_RAW */
43196 X
43197 #ifdef WIN32
43198 #define RBSTR "rb"      /* read file in binary mode */
43199 #else
43200 #define RBSTR "r"
43201 #endif
43202 X
43203 #include "mm_file.h"
43204 struct lmf_str *load_mmap(FILE *, char *, int, int, struct lmf_str *);
43205 struct lmf_str *ncbl2_reopen(struct lmf_str *);
43206 struct lmf_str *ncbl2_openlib(char *, int);
43207 X
43208 static struct lmf_str *last_m_fptr=NULL;
43209 X
43210 #ifdef MYSQL_DB
43211 struct lmf_str *mysql_openlib(char *, int, int *);
43212 struct lmf_str *mysql_reopen(struct lmf_str *);
43213 #endif
43214 X
43215 #ifdef PGSQL_DB
43216 struct lmf_str *pgsql_openlib(char *, int, int *);
43217 struct lmf_str *pgsql_reopen(struct lmf_str *);
43218 #endif
43219 X
43220 void closelib(struct lmf_str *m_fptr);
43221 extern void newname(char *nname, char *oname, char *suff, int maxn);
43222 X
43223 /* a file name for openlib may include a library type suffix */
43224 X
43225 struct lmf_str *
43226 openlib(char *lname, int ldnaseq, int *sascii,
43227 X       int outtty, struct lmf_str *om_fptr)
43228 {
43229 X  char rline[10],sname[MAX_FN], iname[MAX_FN], *bp;
43230 X  char opt_text[MAX_FN];       /* save text after ':' */
43231 X  int wcnt, opnflg;
43232 X  int libtype;
43233 X  FILE *libi=NULL;
43234 X  FILE *libf;
43235 X  int use_stdin;
43236 X  struct lmf_str *m_fptr=NULL;
43237 X
43238 X  /* this is currently unavailable - later it can return a value somewhere */
43239 X  /*
43240 X  if (lname[0]=='#') {return -9;}
43241 X  */
43242 X
43243 X  if (om_fptr != NULL && om_fptr->mm_flg) {
43244 X    om_fptr->lpos = 0;
43245 X    return om_fptr;
43246 X  }
43247 X
43248 X  wcnt = 0;    /* number of times to ask for file name */
43249 X
43250 X  /* check to see if there is a file option ":1-100" */
43251 #ifndef WIN32
43252 X  if ((bp=strchr(lname,':'))!=NULL && *(bp+1)!='\0') {
43253 #else
43254 X  if ((bp=strchr(lname+3,':'))!=NULL && *(bp+1)!='\0') {
43255 #endif
43256 X    strncpy(opt_text,bp+1,sizeof(opt_text));
43257 X    opt_text[sizeof(opt_text)-1]='\0';
43258 X    *bp = '\0';
43259 X  }
43260 X  else opt_text[0]='\0';
43261 X
43262 X  if (lname[0] == '-' || lname[0] == '@') {
43263 X    use_stdin = 1;
43264 X  }
43265 X  else use_stdin=0;
43266 X
43267 X  strncpy(sname,lname,sizeof(sname));
43268 X  sname[sizeof(sname)-1]='\0';
43269 X    /* check for library type */
43270 X  if ((bp=strchr(sname,' '))!=NULL) {
43271 X    *bp='\0';
43272 X    sscanf(bp+1,"%d",&libtype);
43273 X    if (libtype<0 || libtype >= LASTLIB) {
43274 X      fprintf(stderr," invalid library type: %d (>%d)- resetting\n%s\n",
43275 X             libtype,LASTLIB,lname);
43276 X      libtype=0;
43277 X    }
43278 X  }
43279 X  else libtype=0;
43280 X
43281 X  if (use_stdin && libtype !=0) {
43282 X    fprintf(stderr," @/- STDIN libraries must be in FASTA format\n");
43283 X    return NULL;
43284 X  }
43285 X
43286 X  /* check to see if file can be open()ed? */
43287 X
43288 X l1:
43289 X  if (libtype<=LASTTXT) {
43290 X    if (!use_stdin) {
43291 X      opnflg=((libf=fopen(sname,RBSTR))!=NULL);
43292 X    }
43293 X    else {
43294 X      libf=stdin;
43295 X      strncpy(sname,"STDIN",sizeof(sname));
43296 X      sname[sizeof(sname)-1]='\0';
43297 X      opnflg=1;
43298 X    }
43299 X  } 
43300 #ifdef NCBIBL13
43301 X  else if (libtype==NCBIBL13) opnflg=(ncbl_openlib(sname,ldnaseq)!= -1);
43302 #endif
43303 #ifdef NCBIBL20
43304 X  else if (libtype==NCBIBL20) {
43305 X    opnflg=((m_fptr=ncbl2_openlib(sname,ldnaseq))!=NULL);
43306 X  }
43307 #endif
43308 X
43309 #ifdef MYSQL_DB
43310 X  /* a mySQL filename contains mySQL commands, not sequences */
43311 X  else if (libtype==MYSQL_LIB) {
43312 X    opnflg=((m_fptr=mysql_openlib(sname,ldnaseq,sascii))!=NULL);
43313 X  }
43314 #endif
43315 #ifdef PGSQL_DB
43316 X  /* a mySQL filename contains mySQL commands, not sequences */
43317 X  else if (libtype==PGSQL_LIB) {
43318 X    opnflg=((m_fptr=pgsql_openlib(sname,ldnaseq,sascii))!=NULL);
43319 X  }
43320 #endif
43321 X
43322 X  if (!opnflg) {       /* here if open failed */
43323 X    if (outtty) {
43324 X      fprintf(stderr," cannot open %s library\n",sname);
43325 X      fprintf(stderr," enter new file name or <RET> to quit ");
43326 X      fflush(stderr);
43327 X      if (fgets(sname,sizeof(sname),stdin)==NULL) return NULL;
43328 X      if ((bp=strchr(sname,'\n'))!=0) *bp='\0';
43329 X      if (strlen(sname)==0) return NULL;
43330 X      if (++wcnt > 10) return NULL;
43331 X      strncpy(lname,sname,sizeof(lname)-1);
43332 X      lname[sizeof(lname)-1]='\0';
43333 X      goto l1;
43334 X    }
43335 X    else return NULL;
43336 X  }    /* !openflg */
43337 X
43338 X  if (libtype <= LASTTXT) {
43339 X    /* now allocate a buffer for the opened text file */
43340 X    if ((m_fptr = calloc(1,sizeof(struct lmf_str)))==NULL) {
43341 X      fprintf(stderr," cannot allocate lmf_str (%ld) for %s\n",
43342 X             sizeof(struct lmf_str),sname);
43343 X      return NULL;
43344 X    }
43345 X    if ((m_fptr->lline = calloc(MAX_STR,sizeof(char)))==NULL) {
43346 X      fprintf(stderr," cannot allocate lline (%d) for %s\n",
43347 X             MAX_STR,sname);
43348 X      return NULL;
43349 X    }
43350 X
43351 X    strncpy(m_fptr->lb_name,sname,MAX_FN);
43352 X    m_fptr->lb_name[MAX_FN-1]='\0';
43353 X    strncpy(m_fptr->opt_text,opt_text,MAX_FN);
43354 X    m_fptr->opt_text[MAX_FN-1]='\0';
43355 X    m_fptr->sascii = sascii;
43356 X
43357 X    m_fptr->libf = libf;
43358 X    m_fptr->lb_type = libtype;
43359 X    m_fptr->getlib = getliba[libtype];
43360 X    m_fptr->ranlib = ranliba[libtype];
43361 X    m_fptr->mm_flg = 0;
43362 X    m_fptr->tot_len = 0;
43363 X    m_fptr->max_len = 0;
43364 X    m_fptr->lib_aa = (ldnaseq==0);
43365 X  }
43366 X  last_m_fptr = m_fptr;
43367 X
43368 #ifdef USE_MMAP
43369 X  /* check for possible mmap()ed files */
43370 X  if (!use_stdin && (libtype <= LASTTXT) && (getlibam[libtype]!=NULL)) {
43371 X    /* this is a file we can mmap() */
43372 X    /* look for .xin file */
43373 X    newname(iname,sname,"xin",sizeof(iname));
43374 X    if ((libi=fopen(iname,"r"))!=NULL) { /* have a *.xin file, use mmap */
43375 X      if (load_mmap(libi,sname,libtype,ldnaseq,m_fptr)!=NULL) {
43376 X       fclose(libi);   /* close index file */
43377 X       m_fptr->lb_type = libtype;
43378 X       m_fptr->getlib = getlibam[libtype];
43379 X       m_fptr->ranlib = ranlibam[libtype];
43380 X       m_fptr->mm_flg = 1;
43381 X       return m_fptr;
43382 X      }
43383 X    fclose(libi);      /* memory mapping failed, but still must close file */
43384 X    }
43385 X  }
43386 #endif
43387 X
43388 X  if (libtype <= LASTTXT) {
43389 X    m_fptr->lpos = 0;
43390 X    if (fgets(m_fptr->lline,MAX_STR,libf)==NULL) return NULL;
43391 X  }
43392 X  return m_fptr;
43393 }
43394 X
43395 void
43396 closelib(struct lmf_str *m_fptr) {
43397 X
43398 X
43399 #ifdef MMAP
43400 X  if (m_fptr->mm_flag) {
43401 /* don't close memory mapped files
43402 X    close_mmap(m_fptr);
43403 */
43404 X    return;
43405 X  }
43406 #endif
43407 X
43408 X  if (m_fptr->libf!=NULL && m_fptr->libf != stdin) {
43409 X    fclose(m_fptr->libf);
43410 X    m_fptr->libf = NULL;
43411 X  }
43412 X
43413 #ifdef NCBIBL13
43414 X  if (m_fptr->lb_type == NCBIBL13) ncbl_closelib(m_fptr);
43415 #endif
43416 #ifdef NCBIBL20
43417 X  if (m_fptr->lb_type == NCBIBL20) ncbl2_closelib(m_fptr);
43418 #endif
43419 #ifdef MYSQL_DB
43420 X  if (m_fptr->lb_type == MYSQL_LIB) mysql_closelib(m_fptr);
43421 #endif
43422 }
43423 X
43424 struct lmf_str *
43425 re_openlib(struct lmf_str *om_fptr, int outtty)
43426 {
43427 X  int opnflg;
43428 X
43429 X  /* if the file mmap()ed and has been opened - use it and return */
43430 X  if (om_fptr->mm_flg) {
43431 X    return om_fptr;
43432 X  }
43433 #ifdef MYSQL_DB
43434 X  /* if this is a mysql database - use it and return */
43435 X  else if (om_fptr->lb_type == MYSQL_LIB) {
43436 X    return om_fptr;
43437 X  }
43438 #endif
43439 X
43440 X  /* data is available, but file is closed or not memory mapped, open it */
43441 X  /* no longer check to memory map - because we could not do it before */
43442 X
43443 X  opnflg = 1;
43444 X  if (om_fptr->lb_type<=LASTTXT && om_fptr->libf==NULL)
43445 X    opnflg=((om_fptr->libf=fopen(om_fptr->lb_name,RBSTR))!=NULL);
43446 #ifdef NCBIBL13
43447 X  else if (om_fptr->lb_type==NCBIBL13)
43448 X    opnflg=(ncbl_openlib(om_fptr->lb_name,!om_fptr->lib_aa)!= -1);
43449 #endif
43450 #ifdef NCBIBL20
43451 X  else if (om_fptr->lb_type==NCBIBL20) {
43452 X    opnflg=((om_fptr=ncbl2_openlib(om_fptr->lb_name,!om_fptr->lib_aa))!=NULL);
43453 X  }
43454 #endif
43455 #ifdef MYSQL_DB
43456 X  /* a mySQL filename contains mySQL commands, not sequences */
43457 X  else if (om_fptr->lb_type==MYSQL_LIB) 
43458 X    opnflg=(mysql_reopen(om_fptr)!=NULL);
43459 #endif
43460 X
43461 X  if (!opnflg) {
43462 X    fprintf(stderr,"*** could not re_open %s\n",om_fptr->lb_name);
43463 X    return NULL;
43464 X  }
43465 X
43466 X  /* use the old buffer for the opened text file */
43467 X  om_fptr->mm_flg = 0;
43468 X  last_m_fptr =  om_fptr;
43469 X
43470 X  return om_fptr;
43471 }
43472 X
43473 #ifdef SUPERFAMNUM
43474 static char tline[512];
43475 extern int nsfnum;      /* number of superfamily numbers */
43476 extern int sfnum[10];   /* superfamily number from types 0 and 5 */
43477 extern int nsfnum_n;
43478 extern int sfnum_n[10];
43479 #endif
43480 X
43481 void sf_sort(int *, int);
43482 X
43483 int
43484 agetlib(unsigned char *seq, int maxs,
43485 X       char *libstr, int n_libstr,
43486 X       fseek_t *libpos,
43487 X       int *lcont,
43488 X       struct lmf_str *lm_fd,
43489 X       long *l_off)
43490 {
43491 X  int i;
43492 X  register unsigned char *cp, *seqp;
43493 X  register int *ap;
43494 X  unsigned char *seqm, *seqm1;
43495 X  /* int ic, l_start, l_stop, l_limit, rn; */
43496 X  char *bp, *bp1, *bpa, *tp;
43497 X
43498 X  seqp = seq;
43499 X  seqm = &seq[maxs-9];
43500 X  seqm1 = seqm-1;
43501 X
43502 X  ap = lm_fd->sascii;
43503 X
43504 X  if (*lcont==0) {
43505 X    *l_off = 1;
43506 X    while (lm_fd->lline[0]!='>' && lm_fd->lline[0]!=';') {
43507 X      if (lm_fd->libf != stdin) lm_fd->lpos = FTELL(lm_fd->libf);
43508 X      if (fgets(lm_fd->lline,MAX_STR,lm_fd->libf)==NULL) return (-1);
43509 X    }
43510 #ifdef SUPERFAMNUM
43511 X    strncpy(tline,lm_fd->lline+1,sizeof(tline));
43512 X    tline[sizeof(tline)-1]='\0';
43513 X    sfnum[0]=nsfnum=0;
43514 X    if ((bp=strchr(tline,' ')) && (bp=strchr(bp+1,SFCHAR))) {
43515 X      if ((bpa = strchr(bp+1,'\001'))!=NULL) *bpa = '\0';
43516 X      if ((bp1=strchr(bp+1,SFCHAR))==NULL) {
43517 /*      fprintf(stderr," second %c missing: %s\n",SFCHAR,libstr); */
43518 X      }
43519 X      else {
43520 X       *bp1 = '\0';
43521 X       i = 0;
43522 X       if ((tp = strtok(bp+1," \t"))!=NULL) {
43523 X         sfnum[i++] = atoi(tp);
43524 X         while ((tp = strtok((char *)NULL," \t")) != (char *)NULL) {
43525 X           if (isdigit(*tp)) sfnum[i++] = atoi(tp);
43526 X           if (i>=9) break;
43527 X         }
43528 X       }
43529 X       sfnum[nsfnum=i]= 0;
43530 X       if (nsfnum>1) sf_sort(sfnum,nsfnum);
43531 X       else {
43532 X         if (nsfnum<1) fprintf(stderr," found | but no sfnum: %s\n",libstr);
43533 X       }
43534 X      }
43535 X    }
43536 X    else {
43537 X      sfnum[0] = nsfnum = 0;
43538 X      }
43539 #endif
43540 X
43541 X    if ((bp=strchr(lm_fd->lline,'@'))!=NULL && !strncmp(bp+1,"C:",2)) {
43542 X      sscanf(bp+3,"%ld",l_off);
43543 X    }
43544 X
43545 X    strncpy(libstr,lm_fd->lline+1,n_libstr-1);
43546 X    libstr[n_libstr-1]='\0';
43547 X    if ((bp=strchr(libstr,'\r'))!=NULL) *bp='\0';
43548 X    if ((bp=strchr(libstr,'\n'))!=NULL) *bp='\0';
43549 X    if (n_libstr > MAX_UID) {
43550 X      tp = libstr;
43551 X      while (*tp++) if (*tp == '\001' || *tp== '\t') *tp = ' ';
43552 X    }
43553 X
43554 X    *libpos = lm_fd->lpos;
43555 X
43556 X    /* make certain we have the end of the line */
43557 X    while (strchr((char *)lm_fd->lline,'\n')==NULL) {
43558 X      if (strlen(lm_fd->lline)<MAX_STR/2) 
43559 X       fgets(&lm_fd->lline[strlen(lm_fd->lline)],MAX_STR/2,lm_fd->libf);
43560 X      else 
43561 X       fgets(&lm_fd->lline[MAX_STR/2],MAX_STR/2,lm_fd->libf);
43562 X    }
43563 X    lm_fd->lline[MAX_STR-1]='\0';
43564 X  }
43565 X
43566 X  lm_fd->lline[0]='\0';
43567 X  while (seqp<seqm1 && fgets((char *)seqp,(size_t)(seqm-seqp),lm_fd->libf)!=NULL) {
43568 X    if (*seqp=='>') goto new;
43569 X    if (*seqp==';') {
43570 X      if (strchr((char *)seqp,'\n')==NULL) goto cont;
43571 X      continue;
43572 X    }
43573 X
43574 X    /* removed - used for @P:1-n 
43575 X       if (l_limit) {
43576 X       for (cp=seqp; seqp<seqm1 && rn < l_stop && (ic=ap[*cp++])<EL; )
43577 X       if (ic < NA && ++rn > l_start) *seqp++ = (unsigned char)ic;
43578 X       if (rn > l_stop) goto finish;
43579 X       }
43580 X       else {
43581 X    */
43582 X    for (cp=seqp; seqp<seqm1; ) {
43583 X      if ((*seqp++=ap[*cp++])<NA &&
43584 X         (*seqp++=ap[*cp++])<NA &&
43585 X         (*seqp++=ap[*cp++])<NA &&
43586 X         (*seqp++=ap[*cp++])<NA &&
43587 X         (*seqp++=ap[*cp++])<NA &&
43588 X         (*seqp++=ap[*cp++])<NA &&
43589 X         (*seqp++=ap[*cp++])<NA &&
43590 X         (*seqp++=ap[*cp++])<NA &&
43591 X         (*seqp++=ap[*cp++])<NA) continue;
43592 X      if (*(--seqp)>NA) break;
43593 X    }
43594 X    if (*seqp==ES) goto done;
43595 X    if (lm_fd->libf != stdin) lm_fd->lpos = FTELL(lm_fd->libf);
43596 X  }
43597 X  goto done;
43598 X new:
43599 X  strncpy(lm_fd->lline,(char *)seqp,MAX_STR);
43600 X  lm_fd->lline[MAX_STR-1]='\0';
43601 X  /* be certain to get complete line, if possible */
43602 X  if (strchr(lm_fd->lline,'\n')==NULL)
43603 X    fgets(&lm_fd->lline[strlen(lm_fd->lline)],MAX_STR-strlen(lm_fd->lline),lm_fd->libf);
43604 X  lm_fd->lline[MAX_STR-1]='\0';
43605 X  if (strchr(lm_fd->lline,'\n')==NULL && strchr((char *)seqp,'\n')!=NULL)
43606 X    lm_fd->lline[strlen(lm_fd->lline)-1]='\n';
43607 X  goto done;
43608 X
43609 X  /* removed - used for @P:1-n
43610 finish: 
43611 X   while (lm_fd->lline[0]!='>' && 
43612 X         fgets(lm_fd->lline,MAX_STR,lm_fd->libf)!=NULL) {
43613 X     if (lm_fd->libf != stdin) lm_fd->lpos = FTELL(lm_fd->libf);
43614 X   }
43615 X   goto done;
43616 */
43617 X cont:
43618 X  fgets(lm_fd->lline,MAX_STR,lm_fd->libf);
43619 X  seqm1 = seqp;
43620 X done:
43621 X  if (seqp>=seqm1) (*lcont)++;
43622 X  else {
43623 X    *lcont=0;
43624 X  }
43625 X
43626 X  *seqp = EOSEQ;
43627 X  /*  if ((int)(seqp-seq)==0) return 1; */
43628 X  return (int)(seqp-seq);
43629 }
43630 X
43631 void
43632 aranlib(char *str, int cnt, fseek_t seek, char *libstr, struct lmf_str *lm_fd)
43633 {
43634 X  char *bp;
43635 X
43636 X  if (lm_fd->libf != stdin) {
43637 X    FSEEK(lm_fd->libf, seek, 0);
43638 X    fgets(lm_fd->lline,MAX_STR,lm_fd->libf);
43639 X
43640 X    if (lm_fd->lline[0]=='>' || lm_fd->lline[0]==';') {
43641 X      strncpy(str,lm_fd->lline+1,cnt);
43642 X      str[cnt-1]='\0';
43643 X      if ((bp = strchr(str,'\r'))!=NULL) *bp='\0';
43644 X      if ((bp = strchr(str,'\n'))!=NULL) *bp='\0';
43645 X      /*
43646 X       if ((bp = strchr(str,SFCHAR))!=NULL) *bp='\0';
43647 X       else if ((bp = strchr(str,'\001'))!=NULL) *bp='\0';
43648 X       else if ((bp = strchr(str,'\n'))!=NULL) *bp='\0';
43649 X       else str[cnt-1]='\0';
43650 X      */
43651 X      bp = str;
43652 X      while (*bp++) if (*bp=='\001' || *bp=='\t') *bp=' ';
43653 X    }
43654 X    else {
43655 X      str[0]='\0';
43656 X    }
43657 X  }
43658 X  else str[0]='\0';
43659 }
43660 X
43661 void lget_ann(struct lmf_str *, char *, int);
43662 X
43663 int
43664 lgetlib(unsigned char *seq,
43665 X       int maxs,
43666 X       char *libstr,
43667 X       int n_libstr,
43668 X       fseek_t *libpos,
43669 X       int *lcont,
43670 X       struct lmf_str *lm_fd,
43671 X       long *l_off)
43672 {
43673 X  register unsigned char *cp, *seqp;
43674 X  register int *ap;
43675 X  unsigned char *seqm, *seqm1;
43676 X  char *bp, *bp_gid;
43677 X
43678 X  *l_off = 1;
43679 X
43680 X  seqp = seq;
43681 X  seqm = &seq[maxs-11];
43682 X  seqm1 = seqm-1;
43683 X
43684 X  ap = lm_fd->sascii;
43685 X
43686 X  if (*lcont==0) {
43687 X    while (lm_fd->lline[0]!='L' || lm_fd->lline[1]!='O' || 
43688 X          strncmp(lm_fd->lline,"LOCUS",5)) { /* find LOCUS */
43689 X      lm_fd->lpos = FTELL(lm_fd->libf);
43690 X      if (fgets(lm_fd->lline,MAX_STR,lm_fd->libf)==NULL) return (-1);
43691 X      if (lm_fd->lfflag) getc(lm_fd->libf);
43692 X    }
43693 X    *libpos= lm_fd->lpos;
43694 X
43695 X    if (n_libstr <= 21) {
43696 X      strncpy(libstr,&lm_fd->lline[12],12);
43697 X      libstr[12]='\0';
43698 X    }
43699 X    else {
43700 X      lget_ann(lm_fd,libstr,n_libstr);
43701 X      fgets(lm_fd->lline,MAX_STR,lm_fd->libf);
43702 X    }
43703 X
43704 X    while (lm_fd->lline[0]!='O' || lm_fd->lline[1]!='R' ||
43705 X          strncmp(lm_fd->lline,"ORIGIN",6)) { /* find ORIGIN */
43706 X      if (fgets(lm_fd->lline,MAX_STR,lm_fd->libf)==NULL) return (-1);
43707 X      if (lm_fd->lfflag) getc(lm_fd->libf);
43708 X    }
43709 X  }
43710 X  else {
43711 X    for (cp= lm_fd->cpsave; seqp<seqm1; ) {
43712 X      if ((*seqp++=ap[*cp++])<NA) continue;
43713 X      if (*(--seqp)>NA) break;
43714 X    }
43715 X  }
43716 X
43717 X  lm_fd->lline[0]='\0';
43718 X  while (seqp<seqm1 && fgets(lm_fd->lline,MAX_STR,lm_fd->libf)!=NULL) {
43719 X    if (lm_fd->lfflag) getc(lm_fd->libf);
43720 X    if (lm_fd->lline[0]=='/') goto new;
43721 X    for (cp= (unsigned char *)&lm_fd->lline[10]; seqp<seqm1; ) {
43722 X      if ((*seqp++=ap[*cp++])<NA &&
43723 X         (*seqp++=ap[*cp++])<NA &&
43724 X         (*seqp++=ap[*cp++])<NA &&
43725 X         (*seqp++=ap[*cp++])<NA &&
43726 X         (*seqp++=ap[*cp++])<NA &&
43727 X         (*seqp++=ap[*cp++])<NA &&
43728 X         (*seqp++=ap[*cp++])<NA &&
43729 X         (*seqp++=ap[*cp++])<NA &&
43730 X         (*seqp++=ap[*cp++])<NA &&
43731 X         (*seqp++=ap[*cp++])<NA &&
43732 X         (*seqp++=ap[*cp++])<NA) continue;
43733 X      if (*(--seqp)>NA) break;
43734 X    }
43735 X  }
43736 X  goto done;
43737 new:
43738 X  lm_fd->lpos = FTELL(lm_fd->libf);
43739 X  fgets(lm_fd->lline,MAX_STR,lm_fd->libf);
43740 X  if (lm_fd->lfflag) getc(lm_fd->libf);
43741 X
43742 done:
43743 X  if (seqp>=seqm1) {
43744 X    lm_fd->cpsave = cp;
43745 X    (*lcont)++;
43746 X  }
43747 X  else *lcont=0;
43748 X
43749 X  *seqp = EOSEQ;
43750 X  /*  if ((int)(seqp-seq)==0) return 1; */
43751 X  return (int)(seqp-seq);
43752 }
43753 X
43754 void
43755 lget_ann(struct lmf_str *lm_fd, char *libstr, int n_libstr) {
43756 X  char *bp, *bp_gid, locus[120], desc[120], acc[120], ver[120];
43757 X
43758 X  /* copy in locus from lm_fd->lline */
43759 X  strncpy(locus,&lm_fd->lline[12],sizeof(locus));
43760 X  if ((bp=strchr(locus,' '))!=NULL) *(bp+1) = '\0';
43761 X
43762 X  /* get description */
43763 X  fgets(desc,sizeof(desc),lm_fd->libf);
43764 X  while (desc[0]!='D' || desc[1]!='E' || strncmp(desc,"DEFINITION",10))
43765 X    fgets(desc,sizeof(desc),lm_fd->libf);
43766 X  if ((bp = strchr(&desc[12],'\n'))!=NULL) *bp='\0';
43767 X
43768 X  /* get accession */
43769 X  fgets(acc,sizeof(acc),lm_fd->libf);
43770 X  while (acc[0]!='A' || acc[1]!='C' || strncmp(acc,"ACCESSION",9)) {
43771 X    fgets(acc,sizeof(acc),lm_fd->libf);
43772 X    if (acc[0]=='O' && acc[1]=='R' && strncmp(acc,"ORIGIN",6)==0)
43773 X      break;
43774 X  }
43775 X  if ((bp = strchr(&acc[12],'\n'))!=NULL) *bp='\0';
43776 X  if ((bp = strchr(&acc[12],' '))!=NULL) *bp='\0';
43777 X
43778 X  /* get version */
43779 X  fgets(ver,sizeof(ver),lm_fd->libf);
43780 X  while (ver[0]!='V' || ver[1]!='E' || strncmp(ver,"VERSION",7)) {
43781 X    fgets(ver,sizeof(ver),lm_fd->libf);
43782 X    if (ver[0]=='O' && ver[1]=='R' && strncmp(ver,"ORIGIN",6)==0)
43783 X      break;
43784 X  }
43785 X  if ((bp = strchr(&ver[12],'\n'))!=NULL) *bp='\0';
43786 X
43787 X      /* extract gi:123456 from version line */
43788 X  bp_gid = strchr(&ver[12],':');
43789 X  if (bp_gid != NULL) {
43790 X    if ((bp=strchr(bp_gid+1,' '))!=NULL) *bp='\0';
43791 X    bp_gid++;
43792 X  }
43793 X  if ((bp = strchr(&ver[12],' '))!=NULL) *bp='\0';
43794 X
43795 X      /* build up FASTA header line */
43796 X  if (bp_gid != NULL) {
43797 X    strncpy(libstr,"gi|",n_libstr-1);
43798 X    strncat(libstr,bp_gid,n_libstr-4);
43799 X    strncat(libstr,"|gb|",n_libstr-20);
43800 X  }
43801 X  else {libstr[0]='\0';}
43802 X
43803 X  /* if we have a version number, use it, otherwise accession, 
43804 X        otherwise locus/description */
43805 X
43806 X  if (ver[0]=='V') {
43807 X    strncat(libstr,&ver[12],n_libstr-1-strlen(libstr));
43808 X    strncat(libstr,"|",n_libstr-1-strlen(libstr));
43809 X  }
43810 X  else if (acc[0]=='A') {
43811 X    strncat(libstr,&acc[12],n_libstr-1-strlen(libstr));
43812 X    strncat(libstr," ",n_libstr-1-strlen(libstr));
43813 X  }
43814 X
43815 X  strncat(libstr,locus,n_libstr-1-strlen(libstr));
43816 X  strncat(libstr,&desc[11],n_libstr-1-strlen(libstr));
43817 X  libstr[n_libstr-1]='\0';
43818 }
43819 X
43820 X
43821 /* this code seeks to provide both the various accession numbers
43822 X   necessary to identify the sequence, and also some description.
43823 X
43824 X   Unfortunately, the various contributors to Genbank use three
43825 X   slightly different formats for including the accession number.
43826 X
43827 (1)LOCUS       HSJ214M20  107422 bp    DNA             HTG       16-JUN-2000
43828 X   DEFINITION  Homo sapiens chromosome 6 clone RP1-214M20 map p12.1-12.3, ***
43829 X               SEQUENCING IN PROGRESS ***, in unordered pieces.
43830 X   ACCESSION   AL121969
43831 X
43832 (2)LOCUS       AL359201   117444 bp    DNA             HTG       15-JUN-2000
43833 X   DEFINITION  Homo sapiens chromosome 1 clone RP4-671C13 map p13.2-21.1, ***
43834 X               SEQUENCING IN PROGRESS ***, in unordered pieces.
43835 X   ACCESSION   AL359201
43836 X
43837 (3)LOCUS       BB067000      280 bp    mRNA            EST       19-JUN-2000
43838 X   DEFINITION  BB067000 RIKEN full-length enriched, 15 days embryo male testis Mus
43839 X               musculus cDNA clone 8030456L01 3', mRNA sequence.
43840 X   ACCESSION   BB067000
43841 X
43842 This makes it more difficult to both provide the accession number in a
43843 standard location and to conserve definition space
43844 */
43845 X
43846 void
43847 lranlib(char *str,
43848 X       int cnt,
43849 X       fseek_t seek,
43850 X       char *libstr,
43851 X       struct lmf_str *lm_fd)
43852 {
43853 X  char *bp, acc[MAX_STR], desc[MAX_STR];
43854 X
43855 X  FSEEK(lm_fd->libf, seek, 0);
43856 X  fgets(lm_fd->lline,MAX_STR,lm_fd->libf);
43857 X  if (lm_fd->lfflag) getc(lm_fd->libf);
43858 X
43859 X  lget_ann(lm_fd, str, cnt);
43860 X  str[cnt-1]='\0';
43861 X
43862 X  FSEEK(lm_fd->libf,seek,0);
43863 X  fgets(lm_fd->lline,MAX_STR,lm_fd->libf);
43864 X  if (lm_fd->lfflag) getc(lm_fd->libf);
43865 }
43866 X
43867 int
43868 pgetlib(unsigned char *seq,
43869 X       int maxs,
43870 X       char *libstr,
43871 X       int n_libstr,
43872 X       fseek_t *libpos,
43873 X       int *lcont,
43874 X       struct lmf_str *lm_fd,
43875 X       long *l_off)
43876 {
43877 X  int ic;
43878 X  register unsigned char *cp, *seqp;
43879 X  register int *ap;
43880 X  unsigned char *seqm, *seqm1;
43881 X
43882 X  *l_off = 1;
43883 X
43884 X  seqp = seq;
43885 X  seqm = &seq[maxs-11];
43886 X  seqm1 = seqm-1;
43887 X
43888 X  ap = lm_fd->sascii;
43889 X
43890 X  if (*lcont==0) {
43891 X    while (lm_fd->lline[0]!='E' || lm_fd->lline[1]!='N' || strncmp(lm_fd->lline,"ENTRY",5))
43892 X      { /* find ENTRY */
43893 X       lm_fd->lpos = FTELL(lm_fd->libf);
43894 X       if (fgets(lm_fd->lline,MAX_STR,lm_fd->libf)==NULL) return (-1);
43895 X      }
43896 X    strncpy(libstr,&lm_fd->lline[16],8);
43897 X    libstr[8]='\0';
43898 X    *libpos = lm_fd->lpos;
43899 X    while (lm_fd->lline[2]!='Q' || lm_fd->lline[0]!='S' || strncmp(lm_fd->lline,"SEQUENCE",8))
43900 X      { /* find SEQUENCE */
43901 X       if (fgets(lm_fd->lline,MAX_STR,lm_fd->libf)==NULL) return (-1);
43902 X      }
43903 X    fgets(lm_fd->lline,MAX_STR,lm_fd->libf); /* get the extra line */
43904 X  }
43905 X  else {
43906 X    for (cp= lm_fd->cpsave; seqp<seqm1; ) {
43907 X      if ((*seqp++=ap[*cp++])<NA) continue;
43908 X      if (*(--seqp)>NA) break;
43909 X    }
43910 X    if (*seqp==ES) goto done;
43911 X  }
43912 X
43913 X  lm_fd->lline[0]='\0';
43914 X  while (seqp<seqm1 && fgets(lm_fd->lline,MAX_STR,lm_fd->libf)!=NULL) {
43915 X    if (lm_fd->lline[0]=='/') goto new;
43916 X    for (cp= (unsigned char *)&lm_fd->lline[8]; seqp<seqm1; ) {
43917 X      if ((*seqp++=ap[*cp++])<NA) continue;
43918 X      if (*(--seqp)>NA) break;
43919 X    };
43920 X    if (*seqp==ES) goto done;
43921 X  }
43922 X  goto done;
43923 new:
43924 X  lm_fd->lpos = FTELL(lm_fd->libf);
43925 X  fgets(lm_fd->lline,MAX_STR,lm_fd->libf);
43926 X
43927 done:
43928 X  if (seqp>=seqm1) {
43929 X    lm_fd->cpsave = cp;
43930 X    (*lcont)++;
43931 X  }
43932 X  else *lcont=0;
43933 X
43934 X  *seqp = EOSEQ;
43935 X  /*  if ((int)(seqp-seq)==0) return 1; */
43936 X  return (int)(seqp-seq);
43937 }
43938 X
43939 void
43940 pranlib(char *str,
43941 X       int cnt,
43942 X       fseek_t seek,
43943 X       char *libstr,
43944 X       struct lmf_str *lm_fd)
43945 {
43946 X  char *bp;
43947 X
43948 X  FSEEK(lm_fd->libf, seek, 0);
43949 X  fgets(lm_fd->lline,MAX_STR,lm_fd->libf);
43950 X
43951 X  strncpy(str,&lm_fd->lline[16],8);
43952 X  str[8]='\0';
43953 X  fgets(lm_fd->lline,MAX_STR,lm_fd->libf);
43954 X  while (lm_fd->lline[0]!='T' || lm_fd->lline[1]!='I' || strncmp(lm_fd->lline,"TITLE",5))
43955 X    fgets(lm_fd->lline,MAX_STR,lm_fd->libf);
43956 X  strncpy(&str[8],&lm_fd->lline[16],cnt-9);
43957 X  str[cnt-9]='\0';
43958 X  if ((bp = strchr(str,'\n'))!=NULL) *bp='\0';
43959 X
43960 X  FSEEK(lm_fd->libf,seek,0);
43961 X  fgets(lm_fd->lline,MAX_STR,lm_fd->libf);
43962 }
43963 X
43964 int
43965 egetlib(unsigned char *seq,
43966 X       int maxs,
43967 X       char *libstr,
43968 X       int n_libstr,
43969 X       fseek_t *libpos,
43970 X       int *lcont,
43971 X       struct lmf_str *lm_fd,
43972 X       long *l_off)
43973 {
43974 X  int ll;
43975 X  int ic;
43976 X  register unsigned char *cp, *seqp;
43977 X  register int *ap;
43978 X  unsigned char *seqm, *seqm1;
43979 X  char id[11];  /* Holds Identifier */
43980 X
43981 X  *l_off=1;
43982 X
43983 X  seqp = seq;
43984 X  seqm = &seq[maxs-11];
43985 X  seqm1 = seqm-1;
43986 X
43987 X  ap = lm_fd->sascii;
43988 X
43989 X  if (*lcont==0) {
43990 X    while (lm_fd->lline[0]!='I' || lm_fd->lline[1]!='D') { /* find ID */
43991 X      lm_fd->lpos = FTELL(lm_fd->libf);
43992 X      if (fgets(lm_fd->lline,MAX_STR,lm_fd->libf)==NULL) return (-1);
43993 X      if (lm_fd->lfflag) getc(lm_fd->libf);
43994 X    }
43995 X    sscanf(&lm_fd->lline[5],"%s",id);
43996 X    sprintf(libstr,"%-12.12s",id);
43997 X    libstr[12]='\0';
43998 X    *libpos = lm_fd->lpos;
43999 X    while (lm_fd->lline[0]!='S' || lm_fd->lline[1]!='Q') { /* find ORIGIN */
44000 X      if (fgets(lm_fd->lline,MAX_STR,lm_fd->libf)==NULL) return (-1);
44001 X      if (lm_fd->lfflag) getc(lm_fd->libf);
44002 X    }
44003 X    sscanf(&lm_fd->lline[14],"%ld",&lm_fd->gcg_len);
44004 X  }
44005 X  else {
44006 X    for (cp= lm_fd->cpsave; seqp<seqm1; ) {
44007 X      if ((*seqp++=ap[*cp++])<NA) continue;
44008 X      if (*(--seqp)>NA) break;
44009 X    }
44010 X    if (*seqp==ES) goto done;
44011 X  }
44012 X
44013 X  lm_fd->lline[0]='\0';
44014 X  while (seqp<seqm1 && fgets(lm_fd->lline,MAX_STR,lm_fd->libf)!=NULL) {
44015 X    if (lm_fd->lfflag) getc(lm_fd->libf);
44016 X    if (lm_fd->lline[0]=='/') goto new;
44017 X    lm_fd->lline[70]='\0';
44018 X    for (cp= (unsigned char *)&lm_fd->lline[5]; seqp<seqm1; ) {
44019 X      if ((*seqp++=ap[*cp++])<NA &&
44020 X         (*seqp++=ap[*cp++])<NA &&
44021 X         (*seqp++=ap[*cp++])<NA &&
44022 X         (*seqp++=ap[*cp++])<NA &&
44023 X         (*seqp++=ap[*cp++])<NA &&
44024 X         (*seqp++=ap[*cp++])<NA &&
44025 X         (*seqp++=ap[*cp++])<NA &&
44026 X         (*seqp++=ap[*cp++])<NA &&
44027 X         (*seqp++=ap[*cp++])<NA &&
44028 X         (*seqp++=ap[*cp++])<NA &&
44029 X         (*seqp++=ap[*cp++])<NA) continue;
44030 X      if (*(--seqp)>NA) break;
44031 X    }
44032 X    if (*seqp==ES) goto done;
44033 X  }
44034 X  goto done;
44035 new:    lm_fd->lpos = FTELL(lm_fd->libf);
44036 fgets(lm_fd->lline,MAX_STR,lm_fd->libf);
44037 if (lm_fd->lfflag) getc(lm_fd->libf);
44038 goto done;
44039 X
44040 done:   if (seqp>=seqm1) {
44041 X  lm_fd->cpsave = cp;
44042 X  (*lcont)++;
44043 X  lm_fd->gcg_len -= (long)(seqp-seq);
44044 }
44045 else *lcont=0;
44046 X
44047 *seqp = EOSEQ;
44048 /* if ((int)(seqp-seq)==0) return 1; */
44049 /*      if (*lcont==0 && (long)(seqp-seq)!=lm_fd->gcg_len)
44050 X       printf("%s read %d of %d\n",libstr,(int)(seqp-seq),lm_fd->gcg_len);
44051 X       */
44052 return (int)(seqp-seq);
44053 }
44054 X
44055 void
44056 eranlib(char *str,
44057 X       int cnt,
44058 X       fseek_t seek,
44059 X       char *libstr,
44060 X       struct lmf_str *lm_fd)
44061 {
44062 X  char *bp;
44063 X  char id[11];  /* Holds Identifier */
44064 X
44065 X  FSEEK(lm_fd->libf, seek, 0);
44066 X  fgets(lm_fd->lline,MAX_STR,lm_fd->libf);
44067 X  if (lm_fd->lfflag) getc(lm_fd->libf);
44068 X
44069 X  sscanf(&lm_fd->lline[5],"%s",id);
44070 X  sprintf(str,"%-10.10s ",id);
44071 X  fgets(lm_fd->lline,MAX_STR,lm_fd->libf);
44072 X  if (lm_fd->lfflag) getc(lm_fd->libf);
44073 X  while (lm_fd->lline[0]!='D' || lm_fd->lline[1]!='E') fgets(lm_fd->lline,MAX_STR,lm_fd->libf);
44074 X  strncpy(&str[11],&lm_fd->lline[5],cnt-11);
44075 X  str[cnt-11]='\0';
44076 X  if ((bp = strchr(str,'\r'))!=NULL) *bp='\0';
44077 X  if ((bp = strchr(str,'\n'))!=NULL) *bp='\0';
44078 X
44079 X  FSEEK(lm_fd->libf,seek,0);
44080 X  fgets(lm_fd->lline,MAX_STR,lm_fd->libf);
44081 X  if (lm_fd->lfflag) getc(lm_fd->libf);
44082 }
44083 X
44084 int
44085 igetlib(unsigned char *seq,
44086 X       int maxs,
44087 X       char *libstr,
44088 X       int n_libstr,
44089 X       fseek_t *libpos,
44090 X       int *lcont,
44091 X       struct lmf_str *lm_fd,
44092 X       long *l_off)
44093 {
44094 X       register unsigned char *cp, *seqp;
44095 X       register int *ap;
44096 X       unsigned char *seqm, *seqm1;
44097 X       char *bp;
44098 X
44099 X       *l_off = 1;
44100 X
44101 X       seqp = seq;
44102 X       seqm = &seq[maxs-9];
44103 X       seqm1 = seqm-1;
44104 X
44105 X       ap = lm_fd->sascii;
44106 X
44107 X       if (*lcont==0) {
44108 X               while (lm_fd->lline[0]!=';') {
44109 X                       lm_fd->lpos = FTELL(lm_fd->libf);
44110 X                       if (fgets(lm_fd->lline,MAX_STR,lm_fd->libf)==NULL) return (-1);
44111 X                       }
44112 X               *libpos = lm_fd->lpos;
44113 X               while (lm_fd->lline[0]==';') fgets(lm_fd->lline,MAX_STR,lm_fd->libf);
44114 X               strncpy(libstr,lm_fd->lline+1,12);
44115 X               libstr[12]='\0';
44116 X               if((bp=strchr(libstr,'\n'))!=NULL) *bp='\0';
44117 X               }
44118 X
44119 X       lm_fd->lline[0]='\0';
44120 X       while (seqp<seqm1 && fgets((char *)seqp,(size_t)(seqm-seqp),lm_fd->libf)!=NULL) {
44121 X               if (*seqp=='>') goto new;
44122 X               if (*seqp==';') {
44123 X                       if (strchr((char *)seqp,'\n')==NULL) goto cont;
44124 X                       continue;
44125 X                       }
44126 X               for (cp=seqp; seqp<seqm1; ) {
44127 X                       if ((*seqp++=ap[*cp++])<NA &&
44128 X                           (*seqp++=ap[*cp++])<NA &&
44129 X                           (*seqp++=ap[*cp++])<NA &&
44130 X                           (*seqp++=ap[*cp++])<NA &&
44131 X                           (*seqp++=ap[*cp++])<NA &&
44132 X                           (*seqp++=ap[*cp++])<NA &&
44133 X                           (*seqp++=ap[*cp++])<NA &&
44134 X                           (*seqp++=ap[*cp++])<NA &&
44135 X                           (*seqp++=ap[*cp++])<NA) continue;
44136 X                           if (*(--seqp)>NA) break;
44137 X                           }
44138 X               if (*seqp==ES) goto done;
44139 X               lm_fd->lpos = FTELL(lm_fd->libf);
44140 X               }
44141 X       goto done;
44142 new:    strncpy(lm_fd->lline,(char *)seqp,MAX_STR);
44143 X       lm_fd->lline[MAX_STR-1]='\0';
44144 X       if (strchr((char *)seqp,'\n')==NULL)
44145 X           fgets(lm_fd->lline,MAX_STR-strlen(lm_fd->lline),lm_fd->libf);
44146 X       goto done;
44147 X
44148 cont:
44149 X       fgets(lm_fd->lline,MAX_STR,lm_fd->libf);
44150 X       seqm1 = seqp;
44151 X
44152 done:   if (seqp>=seqm1) {
44153 X               (*lcont)++;
44154 X               }
44155 X       else {
44156 X       *lcont=0;
44157 X               }
44158 X
44159 X
44160 X       *seqp = EOSEQ;
44161 X       /*      if ((int)(seqp-seq)==0) return 1; */
44162 X       return (int)(seqp-seq);
44163 X       }
44164 X
44165 void
44166 iranlib(char *str,
44167 X       int cnt,
44168 X       fseek_t seek,
44169 X       char *libstr,
44170 X       struct lmf_str *lm_fd)
44171 {
44172 X       char *bp;
44173 X       char tline[MAX_FN];
44174 X
44175 X       FSEEK(lm_fd->libf, seek, 0);
44176 X       fgets(lm_fd->lline,MAX_STR,lm_fd->libf);
44177 X
44178 X       if (lm_fd->lline[0]=='>' || lm_fd->lline[0]==';') {
44179 X               strncpy(tline,lm_fd->lline+1,sizeof(tline));
44180 X               tline[sizeof(tline)-1]='\0';
44181 X               if ((bp = strchr(tline,'\n'))!=NULL) *bp='\0';
44182 X               }
44183 X       else {
44184 X               tline[0]='\0';
44185 X               }
44186 X
44187 X       while (lm_fd->lline[0]==';') fgets(lm_fd->lline,MAX_STR,lm_fd->libf);
44188 X       if ((bp=strchr(lm_fd->lline,'\n'))!=NULL) *bp=0;
44189 X       if ((bp=strchr(lm_fd->lline,' '))!=NULL) *bp=0;
44190 X       strncpy(str,lm_fd->lline,cnt);
44191 X       str[cnt-1]='\0';
44192 X       strncat(str,"  ",cnt-strlen(str)-1);
44193 X       strncat(str,tline,cnt-strlen(str)-1);
44194 X       
44195 X       FSEEK(lm_fd->libf,seek,0);
44196 X       fgets(lm_fd->lline,MAX_STR,lm_fd->libf);
44197 X       }
44198 X
44199 int
44200 vgetlib(unsigned char *seq,
44201 X       int maxs,
44202 X       char *libstr,
44203 X       int n_libstr,
44204 X       fseek_t *libpos,
44205 X       int *lcont,
44206 X       struct lmf_str *lm_fd,
44207 X       long *l_off)
44208 {
44209 X  int i, ich;
44210 X  register unsigned char *cp, *seqp;
44211 X  register int *ap;
44212 X  unsigned char *seqm, *seqm1;
44213 X  char *bp, *tp;
44214 X
44215 X  *l_off = 1;
44216 X
44217 X  seqp = seq;
44218 X  seqm = &seq[maxs-9];
44219 X  seqm1 = seqm-1;
44220 X
44221 X  ap = lm_fd->sascii;
44222 X
44223 X  if (*lcont==0) {
44224 X    while (lm_fd->lline[0]!='>' && lm_fd->lline[0]!=';') {
44225 X      lm_fd->lpos = FTELL(lm_fd->libf);
44226 X      if (fgets(lm_fd->lline,MAX_STR,lm_fd->libf)==NULL) return (-1);
44227 X      if (lm_fd->lfflag) getc(lm_fd->libf);
44228 X    }
44229 X
44230 #ifdef SUPERFAMNUM
44231 X    if ((bp=strchr(&lm_fd->lline[1],' ')) &&
44232 X        (bp=strchr(bp+1,SFCHAR))) {
44233 X      i=0;
44234 X      if ((tp = strtok(bp+1," \t\n"))!=NULL) sfnum[i++] = atoi(tp);
44235 X      while ((tp = strtok(NULL," \t")) != NULL) {
44236 X       sfnum[i++] = atoi(tp);
44237 X       if (i>=10) break;
44238 X      }
44239 X      sfnum[nsfnum=i]= 0;
44240 X      if (nsfnum>1) sf_sort(sfnum,nsfnum);
44241 X      else {
44242 X       if (nsfnum < 1) fprintf(stderr," found | but no sfnum: %s\n",libstr);
44243 X      }
44244 X    }
44245 X    else sfnum[0]=nsfnum=0;
44246 #endif
44247 X
44248 X    if ((bp=strchr(lm_fd->lline,'\n'))!=NULL) *bp='\0';
44249 X    strncpy(libstr,&lm_fd->lline[4],12);
44250 X    libstr[12]='\0';
44251 X    if ((bp=strchr(libstr,' '))!=NULL) *bp='\0';
44252 X    if ((bp=strchr(libstr,'\n'))!=NULL) *bp='\0';
44253 X    
44254 X    fgets(lm_fd->lline,MAX_STR,lm_fd->libf);
44255 X    if (lm_fd->lfflag) getc(lm_fd->libf);
44256 X
44257 X    if (n_libstr > 21) {
44258 X      strcat(libstr," ");
44259 X      strncat(libstr,lm_fd->lline,n_libstr-1-strlen(libstr));
44260 X      if ((bp=strchr(libstr,'\n'))!=NULL) *bp='\0';
44261 X      libstr[n_libstr-1]='\0';
44262 X    }
44263 X    *libpos = lm_fd->lpos;
44264 X  }
44265 X
44266 X  lm_fd->lline[0]='\0';
44267 X  while (seqp<seqm1 && fgets((char *)seqp,(size_t)(seqm-seqp),lm_fd->libf)!=NULL) {
44268 X    if (lm_fd->lfflag && (ich=getc(lm_fd->libf))!=LFCHAR) ungetc(ich,lm_fd->libf);
44269 X    if (*seqp=='>') goto new;
44270 X    if (*seqp==';') {
44271 X      if (strchr((char *)seqp,'\n')==NULL) goto cont;
44272 X      continue;
44273 X    }
44274 X    for (cp=seqp; seqp<seqm1; ) {
44275 X      if ((*seqp++=ap[*cp++])<NA &&
44276 X         (*seqp++=ap[*cp++])<NA &&
44277 X         (*seqp++=ap[*cp++])<NA &&
44278 X         (*seqp++=ap[*cp++])<NA &&
44279 X         (*seqp++=ap[*cp++])<NA &&
44280 X         (*seqp++=ap[*cp++])<NA &&
44281 X         (*seqp++=ap[*cp++])<NA &&
44282 X         (*seqp++=ap[*cp++])<NA &&
44283 X         (*seqp++=ap[*cp++])<NA) continue;
44284 X      if (*(--seqp)>NA) break;
44285 X    }
44286 X    if (*seqp==ES) goto done;
44287 X    lm_fd->lpos = FTELL(lm_fd->libf);
44288 X  }
44289 X  goto done;
44290 new:
44291 X  strncpy(lm_fd->lline,(char *)seqp,MAX_STR);
44292 X  lm_fd->lline[MAX_STR-1]='\0';
44293 X  if (strchr((char *)seqp,'\n')==NULL) {
44294 X    fgets(&lm_fd->lline[strlen(lm_fd->lline)],MAX_STR-strlen(lm_fd->lline),lm_fd->libf);
44295 X    if (lm_fd->lfflag && (ich=getc(lm_fd->libf))!=LFCHAR) ungetc(ich,lm_fd->libf);
44296 X  }
44297 X  goto done;
44298 X
44299 cont:
44300 X  fgets(lm_fd->lline,MAX_STR,lm_fd->libf);
44301 X  if (lm_fd->lfflag && (ich=getc(lm_fd->libf))!=LFCHAR) ungetc(ich,lm_fd->libf);
44302 X  seqm1 = seqp;
44303 X
44304 done:
44305 X  if (seqp>=seqm1) {
44306 X    (*lcont)++;
44307 X  }
44308 X  else {
44309 X    *lcont=0;
44310 X  }
44311 X
44312 X  *seqp = EOSEQ;
44313 X  /*   if ((int)(seqp-seq)==0) return 1;*/
44314 X  return (int)(seqp-seq);
44315 }
44316 X
44317 void
44318 vranlib(char *str,
44319 X       int cnt,
44320 X       fseek_t seek,
44321 X       char *libstr,
44322 X       struct lmf_str *lm_fd)
44323 {
44324 X  char *bp, *llp;
44325 X
44326 X  FSEEK(lm_fd->libf, seek, 0);
44327 X  fgets(lm_fd->lline,MAX_STR,lm_fd->libf);
44328 X  if (lm_fd->lfflag) getc(lm_fd->libf);
44329 X
44330 X  if (lm_fd->lline[0]=='>'&&(lm_fd->lline[3]==';'||lm_fd->lline[3]=='>')) {
44331 X    strncpy(str,&lm_fd->lline[4],cnt-1);
44332 X    str[cnt-1]='\0';
44333 X
44334 X    if ((bp = strchr(str,':'))!=NULL) *bp='\0';
44335 X    if ((bp=strchr(str,'\r'))!=NULL) *bp='\0';
44336 X    else if ((bp = strchr(str,'\n'))!=NULL) *bp='\0';
44337 X    else str[cnt-1]='\0';
44338 X
44339 X    fgets(lm_fd->lline,MAX_STR,lm_fd->libf);
44340 X    if (lm_fd->lfflag) getc(lm_fd->libf);
44341 X
44342 X    /* skip over redundant stuff */
44343 X    for (llp=lm_fd->lline,bp=str; *llp==*bp; llp++,bp++);
44344 X    if ((int)(llp-lm_fd->lline)<5) llp = lm_fd->lline;
44345 X
44346 X    if ((bp=strchr(llp,'\r'))!=NULL) *bp=' ';
44347 X    if ((bp=strchr(llp,'\n'))!=NULL) *bp='\0';
44348 X    strncat(str," ",(size_t)1);
44349 X    strncat(str,llp,(size_t)cnt-strlen(str)-1);
44350 X  }
44351 X  else {
44352 X    str[0]='\0';
44353 X  }
44354 X
44355 X  FSEEK(lm_fd->libf,seek,0);
44356 X  fgets(lm_fd->lline,MAX_STR,lm_fd->libf);
44357 X  if (lm_fd->lfflag) getc(lm_fd->libf);
44358 }
44359 X
44360 static int gcg_bton[4]={2,4,1,3};
44361 X
44362 int
44363 gcg_getlib(unsigned char *seq,
44364 X          int maxs,
44365 X          char *libstr,
44366 X          int n_libstr,
44367 X          fseek_t *libpos,
44368 X          int *lcont,
44369 X          struct lmf_str *lm_fd,
44370 X          long *l_off)
44371 {
44372 X  char dummy[20];
44373 X  char gcg_date[10];
44374 X  register unsigned char *cp, *seqp, stmp;
44375 X  register int *ap;
44376 X  char gcg_type[10];
44377 X  unsigned char *seqm, *seqm1;
44378 X  long r_block, b_block;
44379 X  char *bp;
44380 X
44381 X  *l_off = 1;
44382 X
44383 X  seqp = seq;
44384 X  seqm = &seq[maxs-9];
44385 X  seqm1 = seqm-1;
44386 X
44387 X  ap = lm_fd->sascii;
44388 X
44389 X  if (*lcont==0) {
44390 X    while (lm_fd->lline[0]!='>' && lm_fd->lline[0]!=';') {
44391 X      lm_fd->lpos = FTELL(lm_fd->libf);
44392 X      if (fgets(lm_fd->lline,MAX_STR,lm_fd->libf)==NULL) return (-1);
44393 X    }
44394 X    sscanf(&lm_fd->lline[4],"%s %s %s %s %ld",
44395 X          libstr,gcg_date,gcg_type,dummy,&(lm_fd->gcg_len));
44396 X
44397 X    lm_fd->gcg_binary = (gcg_type[0]=='2');
44398 X
44399 X    fgets(lm_fd->lline,MAX_STR,lm_fd->libf);
44400 X    while (strchr((char *)lm_fd->lline,'\n')==NULL) {
44401 X      if (strlen(lm_fd->lline)<MAX_STR/2) 
44402 X       fgets(&lm_fd->lline[strlen(lm_fd->lline)],MAX_STR/2,lm_fd->libf);
44403 X      else 
44404 X      fgets(&lm_fd->lline[strlen(lm_fd->lline)-MAX_STR/2],MAX_STR/2,lm_fd->libf);
44405 X    }
44406 X    lm_fd->lline[MAX_STR-1]='\0';
44407 X    if (n_libstr <= 21) {
44408 X      libstr[12]='\0';
44409 X    }
44410 X    else {
44411 X      strncat(libstr," ",1);
44412 X      strncat(libstr,lm_fd->lline,n_libstr-1-strlen(libstr));
44413 X      if ((bp = strchr(libstr,'\n'))!=NULL) *bp='\0';
44414 X      libstr[n_libstr-1]='\0';
44415 X    }
44416 X    *libpos = lm_fd->lpos;
44417 X  }
44418 X
44419 X  lm_fd->lline[0]='\0';
44420 X
44421 X  r_block = b_block = min((size_t)(seqm-seqp),lm_fd->gcg_len);
44422 X  if (lm_fd->gcg_binary) { r_block = (r_block+3)/4; }
44423 X
44424 X  fread((char *)seqp,(size_t)r_block,(size_t)1,lm_fd->libf);
44425 X  if (!lm_fd->gcg_binary) 
44426 X    for (cp=seqp; seqp<seq+r_block; ) *seqp++ = ap[*cp++];
44427 X  else if (lm_fd->gcg_binary) {
44428 X    seqp = seq + r_block;
44429 X    cp = seq + 4*r_block;
44430 X    while (seqp > seq) {
44431 X      stmp = *--seqp;
44432 X      *--cp = gcg_bton[stmp&3];
44433 X      *--cp = gcg_bton[(stmp >>= 2)&3];
44434 X      *--cp = gcg_bton[(stmp >>= 2)&3];
44435 X      *--cp = gcg_bton[(stmp >>= 2)&3];
44436 X    }
44437 X  }
44438 X  if (4 * r_block >= lm_fd->gcg_len) {
44439 X    fgets(lm_fd->lline,MAX_STR,lm_fd->libf);
44440 X    *lcont = 0;
44441 X  }
44442 X  else {
44443 X    if (lm_fd->gcg_binary) b_block = 4*r_block;
44444 X    lm_fd->gcg_len -= b_block;
44445 X    (*lcont)++;
44446 X  }
44447 X
44448 X  seq[b_block] = EOSEQ;
44449 X  /*   if (b_block==0) return 1; else */
44450 X  return b_block;
44451 }
44452 X
44453 void
44454 gcg_ranlib(char *str,
44455 X          int cnt,
44456 X          fseek_t seek,
44457 X          char *libstr,
44458 X          struct lmf_str *lm_fd)
44459 {
44460 X  char *bp, *bp1, *llp;
44461 X
44462 X  FSEEK(lm_fd->libf, seek, 0);
44463 X  fgets(lm_fd->lline,MAX_STR,lm_fd->libf);
44464 X
44465 X  if (lm_fd->lline[0]=='>'&&(lm_fd->lline[3]==';'||lm_fd->lline[3]=='>')) {
44466 X    strncpy(str,&lm_fd->lline[4],cnt-1);
44467 X    str[cnt-1]='\0';
44468 X    if ((bp = strchr(str,' '))!=NULL) *bp='\0';
44469 X    else if ((bp=strchr(str,'\r'))!=NULL) *bp='\0';
44470 X    else if ((bp = strchr(str,'\n'))!=NULL) *bp='\0';
44471 X    else str[cnt-1]='\0';
44472 X
44473 X    fgets(lm_fd->lline,MAX_STR,lm_fd->libf);
44474 X
44475 X    /* check beginning of line it is a duplicate */
44476 X    for (llp=lm_fd->lline,bp=str; *llp == *bp; llp++,bp++);
44477 X    if ((int)(llp-lm_fd->lline)<5) llp = lm_fd->lline;
44478 X
44479 X    /* here we would like to skip over some species stuff */
44480 X       /*
44481 X    if ((bp1 = strchr(llp,';'))!=NULL && (int)(bp1-llp)<50) {
44482 X      if ((bp2 = strchr(bp1+1,';'))!=NULL && (int)(bp2-bp1)<50) {
44483 X       *(bp2+1)='\0'; bp1 = bp2+2;
44484 X      }
44485 X      else {bp1=llp;}
44486 X    }
44487 X    else if ((bp1=strchr(llp,'.'))!=NULL && *(bp1+1)==' ') {
44488 X      *(bp1+1) = '\0'; bp1 += 2;}
44489 X    else bp1 = llp;
44490 X    */
44491 X    
44492 X    bp1 = llp;
44493 X    if ((bp=strchr(bp1,'\r'))!=NULL) *bp='\0';
44494 X    if ((bp=strchr(bp1,'\n'))!=NULL) *bp='\0';
44495 X    strncat(str," ",(size_t)1);
44496 X    strncat(str,bp1,(size_t)cnt-strlen(str));
44497 X    if (bp1!=llp) strncat(str,llp,(size_t)cnt-strlen(str));
44498 X  }
44499 X  else {
44500 X    str[0]='\0';
44501 X  }
44502 X
44503 X  FSEEK(lm_fd->libf,seek,0);
44504 X  fgets(lm_fd->lline,MAX_STR,lm_fd->libf);
44505 }
44506 X
44507 void
44508 sf_sort(s,n)
44509 X     int *s, n;
44510 {
44511 X  int gap, i, j;
44512 X  int itmp;
44513 X
44514 X  if (n == 1) return;
44515 X       
44516 X  for (i=0; i<n-1; i++)
44517 X    if (s[i]>s[i+1]) goto l2;
44518 X  return;
44519 X
44520 l2:
44521 X  for (gap=n/2; gap>0; gap/=2)
44522 X    for (i=gap; i<n; i++)
44523 X      for (j=i-gap; j>=0; j -= gap) {
44524 X       if (s[j] <= s[j+gap]) break;
44525 X       itmp = s[j];
44526 X       s[j]=s[j+gap];
44527 X       s[j+gap]=itmp;
44528 X      }
44529 }
44530 SHAR_EOF
44531 chmod 0644 nmgetlib.c ||
44532 echo 'restore of nmgetlib.c failed'
44533 Wc_c="`wc -c < 'nmgetlib.c'`"
44534 test 36301 -eq "$Wc_c" ||
44535         echo 'nmgetlib.c: original size 36301, current size' "$Wc_c"
44536 fi
44537 # ============= nr_to_sql.pl ==============
44538 if test -f 'nr_to_sql.pl' -a X"$1" != X"-c"; then
44539         echo 'x - skipping nr_to_sql.pl (File already exists)'
44540 else
44541 echo 'x - extracting nr_to_sql.pl (Text)'
44542 sed 's/^X//' << 'SHAR_EOF' > 'nr_to_sql.pl' &&
44543 #!/usr/bin/perl -w
44544 X
44545 use DBI;
44546 X
44547 $SIG{__WARN__} = sub { die @_ };
44548 X
44549 my $mysql = DBI->connect("DBI:mysql:database=seq_demo;user=seq_demo;password=demo_pass");
44550 X
44551 $mysql->do(q{LOCK TABLES prot WRITE,
44552 X            annot WRITE,
44553 X            sp WRITE });
44554 X
44555 my $EL = 125;
44556 my $NA = 123;
44557 X
44558 my @aatrans = ($EL,$NA,$NA,$NA,$NA,$NA,$NA,$NA,$NA,$NA,$EL,$NA,$NA,$EL,$NA,$NA,
44559 X              $NA,$NA,$NA,$NA,$NA,$NA,$NA,$NA,$NA,$NA,$NA,$NA,$NA,$NA,$NA,$NA,
44560 X              $NA,$NA,$NA,$NA,$NA,$NA,$NA,$NA,$NA,$NA, 24,$NA,$NA,$NA,$NA,$NA,
44561 X              $NA,$NA,$NA,$NA,$NA,$NA,$NA,$NA,$NA,$NA,$NA,$NA,$NA,$NA,$NA,$NA,
44562 X              $NA,  1, 21,  5,  4,  7, 14,  8,  9, 10,$NA, 12, 11, 13,  3,$NA,
44563 X               15,  6,  2, 16, 17,$NA, 20, 18, 23, 19, 22,$NA,$NA,$NA,$NA,$NA,
44564 X              $NA,  1, 21,  5,  4,  7, 14,  8,  9, 10,$NA, 12, 11, 13,  3,$NA,
44565 X               15,  6,  2, 16, 17,$NA, 20, 18, 23, 19, 22,$NA,$NA,$NA,$NA,$NA
44566 X             );
44567 X
44568 my $ins_prot = $mysql->prepare(q{
44569 X    INSERT INTO prot (seq,bin,len) VALUES (?, ?, ?)
44570 X    });
44571 X
44572 my $ins_annot = $mysql->prepare(q{
44573 X    INSERT INTO annot (gi, prot_id, db, descr) VALUES (?, ?, ?, ?)
44574 X    });
44575 X
44576 my $ins_sp = $mysql->prepare(q{
44577 X    INSERT INTO sp (gi, acc, name) VALUES (?, ?, ?)
44578 X    });
44579 X
44580 use vars qw( $seq $bin $tot_seq $tot_annot $tot_sp );
44581 use vars qw( $gi $prot_id $db $desc $sp_acc $sp_name );
44582 use vars qw( $header $seq @entries );
44583 use vars qw( $gi $db $db_acc $db_name $desc);
44584 X
44585 $tot_seq = $tot_annot = $tot_sp = 0;
44586 X
44587 for my $db_file ( @ARGV ) {
44588 X    open(DATA, "<$db_file") or die $!;
44589 X    local $/ = "\n>";
44590 X    while (<DATA>) {
44591 X       chomp; # remove trailing "\n>" record header
44592 X       ($header, $seq) = $_ =~ m/^>?  # record separator (first entry)
44593 X           ( [^\n]* ) \n  # header line
44594 X               (     .* )     # the sequence
44595 X                   /osx; # optimize, multiline, commented
44596 X       
44597 X       $seq =~ s/\W|\d//sg;
44598 X       $bin = pack('C*', map { $aatrans[unpack('C', $_)] } split(//, $seq));
44599 X       $ins_prot->execute($seq,$bin,length($seq));
44600 X       $prot_id = $ins_prot->{mysql_insertid};
44601 X
44602 X       $tot_seq++;
44603 X
44604 #       print STDERR "Inserted $prot_id: ". length($seq)."\n";
44605 X
44606 X       @entries = split(/\001/, $header);
44607 X
44608 X       for ( @entries ) {
44609 X           ($gi,$db,$db_acc,$db_name,$desc)= 
44610 X               $_ =~ /^gi\|(\d+)\|([a-z]+)\|(\S*)\|(\S*) (.*)$/o;
44611 #           print "$prot_id: $gi\t$db\t$db_acc\t$desc\n";
44612 X           $ins_annot->execute($gi,$prot_id,$db,$desc);
44613 X
44614 X           $tot_annot++;
44615 X
44616 X           if ($db eq "sp") {
44617 X               $ins_sp->execute($gi,$db_acc,$db_name);
44618 X               $tot_sp++;
44619 X           }
44620 X       }
44621 X    }
44622 X    close(DATA);
44623 }
44624 X
44625 print "Inserted $tot_seq sequences; $tot_annot annotations; $tot_sp swissprot\n";
44626 X
44627 X
44628 X
44629 SHAR_EOF
44630 chmod 0755 nr_to_sql.pl ||
44631 echo 'restore of nr_to_sql.pl failed'
44632 Wc_c="`wc -c < 'nr_to_sql.pl'`"
44633 test 2452 -eq "$Wc_c" ||
44634         echo 'nr_to_sql.pl: original size 2452, current size' "$Wc_c"
44635 fi
44636 # ============= nrand.c ==============
44637 if test -f 'nrand.c' -a X"$1" != X"-c"; then
44638         echo 'x - skipping nrand.c (File already exists)'
44639 else
44640 echo 'x - extracting nrand.c (Text)'
44641 sed 's/^X//' << 'SHAR_EOF' > 'nrand.c' &&
44642 X
44643 /* copyright (c) 1996, 1997, 1998, 1999 William R. Pearson and the
44644 X   U. of Virginia */
44645 X
44646 /* $Name: fa_34_26_5 $ - $Id: nrand.c,v 1.2 2005/09/23 16:27:25 wrp Exp $ */
44647 X
44648 #include <stdlib.h>
44649 #include <time.h>
44650 X
44651 int
44652 irand(int n)    /* initialize random number generator */
44653 {
44654 X
44655 X  if (n == 0) {
44656 X    n = time(NULL);
44657 X    n = n % 16381;
44658 X    if ((n % 2)==0) n++;
44659 X
44660 X  }
44661 X  srand(n);
44662 }
44663 X
44664 int
44665 nrand(int n)    /* returns a random number between 1 and n where n < 64K) */
44666 {
44667 X  int rand();
44668 X  long rn;
44669 X
44670 X  rn = rand();
44671 #ifdef RAND32
44672 X  rn = rn >> 16;
44673 #endif
44674 X  rn = rn % n;
44675 X  return (int)rn;
44676 }
44677 X
44678 X
44679 X
44680 X
44681 SHAR_EOF
44682 chmod 0644 nrand.c ||
44683 echo 'restore of nrand.c failed'
44684 Wc_c="`wc -c < 'nrand.c'`"
44685 test 566 -eq "$Wc_c" ||
44686         echo 'nrand.c: original size 566, current size' "$Wc_c"
44687 fi
44688 # ============= nrand48.c ==============
44689 if test -f 'nrand48.c' -a X"$1" != X"-c"; then
44690         echo 'x - skipping nrand48.c (File already exists)'
44691 else
44692 echo 'x - extracting nrand48.c (Text)'
44693 sed 's/^X//' << 'SHAR_EOF' > 'nrand48.c' &&
44694 X
44695 /* copyright (c) 1996, 1997, 1998, 1999 William R. Pearson and the
44696 X   U. of Virginia */
44697 X
44698 /* $Name: fa_34_26_5 $ - $Id: nrand48.c,v 1.4 2006/04/12 18:00:02 wrp Exp $ */
44699 X
44700 #include <stdlib.h>
44701 #include <time.h>
44702 X
44703 void 
44704 irand(int n)    /* initialize random number generator */
44705 {
44706 X  if (n == 0) {
44707 X    n = time(NULL);
44708 X    n = n % 16381;
44709 X    if ((n % 2)==0) n++;
44710 X  }
44711 X  srand48(n);
44712 }
44713 X
44714 int
44715 nrand(int n)    /* returns a random number between 0 and n-1 where n < 64K) */
44716 {
44717 X  int rn;
44718 X
44719 X  rn = lrand48();
44720 X  rn = rn >> 16;
44721 X  rn = (rn % n);
44722 X  return rn;
44723 }
44724 X
44725 SHAR_EOF
44726 chmod 0644 nrand48.c ||
44727 echo 'restore of nrand48.c failed'
44728 Wc_c="`wc -c < 'nrand48.c'`"
44729 test 533 -eq "$Wc_c" ||
44730         echo 'nrand48.c: original size 533, current size' "$Wc_c"
44731 fi
44732 # ============= nrandom.c ==============
44733 if test -f 'nrandom.c' -a X"$1" != X"-c"; then
44734         echo 'x - skipping nrandom.c (File already exists)'
44735 else
44736 echo 'x - extracting nrandom.c (Text)'
44737 sed 's/^X//' << 'SHAR_EOF' > 'nrandom.c' &&
44738 X
44739 /* copyright (c) 1996, 1997, 1998, 1999 William R. Pearson and the
44740 X   U. of Virginia */
44741 X
44742 /* $Name: fa_34_26_5 $ - $Id: nrandom.c,v 1.2 2006/04/12 18:00:02 wrp Exp $ */
44743 X
44744 #include <stdlib.h>
44745 #include <time.h>
44746 X
44747 void 
44748 irand(n)        /* initialize random number generator */
44749 X     int n;
44750 {
44751 X  if (n == 0) {
44752 X    n = time(NULL);
44753 X    n = n % 16381;
44754 X    if ((n % 2)==0) n++;
44755 X  }
44756 X  srandom(n);
44757 }
44758 X
44759 int
44760 nrand(n)        /* returns a random number between 0 and n-1 where n < 2^24) */
44761 X     int n;
44762 {
44763 X  int rn;
44764 X
44765 X  rn = random();
44766 X  rn = (rn % n);
44767 X  return rn;
44768 }
44769 X
44770 SHAR_EOF
44771 chmod 0644 nrandom.c ||
44772 echo 'restore of nrandom.c failed'
44773 Wc_c="`wc -c < 'nrandom.c'`"
44774 test 532 -eq "$Wc_c" ||
44775         echo 'nrandom.c: original size 532, current size' "$Wc_c"
44776 fi
44777 # ============= oohu.aa ==============
44778 if test -f 'oohu.aa' -a X"$1" != X"-c"; then
44779         echo 'x - skipping oohu.aa (File already exists)'
44780 else
44781 echo 'x - extracting oohu.aa (Text)'
44782 sed 's/^X//' << 'SHAR_EOF' > 'oohu.aa' &&
44783 >OOHU | 1358 rhodopsin - human
44784 MNGTEGPNFYVPFSNATGVVRSPFEYPQYYLAEPWQFSMLAAYMFLLIVLGFPINFLTLYVTVQHKKLRT
44785 PLNYILLNLAVADLFMVLGGFTSTLYTSLHGYFVFGPTGCNLEGFFATLGGEIALWSLVVLAIERYVVVC
44786 KPMSNFRFGENHAIMGVAFTWVMALACAAPPLAGWSRYIPEGLQCSCGIDYYTLKPEVNNESFVIYMFVV
44787 HFTIPMIIIFFCYGQLVFTVKEAAAQQQESATTQKAEKEVTRMVIIMVIAFLICWVPYASVAFYIFTHQG
44788 SNFGPIFMTIPAFFAKSAAIYNPVIYIMMNKQFRNCMLTTICCGKNPLGDDEASATVSKTETSQVAPA 
44789 SHAR_EOF
44790 chmod 0644 oohu.aa ||
44791 echo 'restore of oohu.aa failed'
44792 Wc_c="`wc -c < 'oohu.aa'`"
44793 test 385 -eq "$Wc_c" ||
44794         echo 'oohu.aa: original size 385, current size' "$Wc_c"
44795 fi
44796 # ============= oohu.raa ==============
44797 if test -f 'oohu.raa' -a X"$1" != X"-c"; then
44798         echo 'x - skipping oohu.raa (File already exists)'
44799 else
44800 echo 'x - extracting oohu.raa (Text)'
44801 sed 's/^X//' << 'SHAR_EOF' > 'oohu.raa' &&
44802 >oohu.aa shuffled
44803 KLILINAIFT GLQNSGCTAQ PTPEFFVMAQ YLFAMVSNMG GVFFQTALLN SAGQGFYSWC
44804 IFIFMTYPGF MLFIQLTGAD FVTVNEGANL CMTFCTQVTA VEYAKPTPVN AAPSSYRILR
44805 VIGGPYQAIF HSIATVFINS PTTEELQFLR IVVIHIAFIV VAVPLTDPRA VKFNAGELTF
44806 GCIFYMQYYM VISLFAANPF YYAFIRVPFE VYCETELIMG PLCAKRYVLA AASNGAYLGW
44807 LKLLEVYSAF PSVKCLNMLR GHVFTTIPET QNAVMYKDVI SSTLFVLSEQ LSAWITSEYP
44808 VPGKCYWMPF GANTHKNINP DPFAEHEKEY ILVWMVCKFG LGMTVMAG
44809 SHAR_EOF
44810 chmod 0644 oohu.raa ||
44811 echo 'restore of oohu.raa failed'
44812 Wc_c="`wc -c < 'oohu.raa'`"
44813 test 401 -eq "$Wc_c" ||
44814         echo 'oohu.raa: original size 401, current size' "$Wc_c"
44815 fi
44816 # ============= p2_complib.c ==============
44817 if test -f 'p2_complib.c' -a X"$1" != X"-c"; then
44818         echo 'x - skipping p2_complib.c (File already exists)'
44819 else
44820 echo 'x - extracting p2_complib.c (Text)'
44821 sed 's/^X//' << 'SHAR_EOF' > 'p2_complib.c' &&
44822 /* copyright (c) 1996, 1997, 1998, 1999 William R. Pearson and the
44823 X   U. of Virginia */
44824 X
44825 /* $Name: fa_34_26_5 $ - $Id: p2_complib.c,v 1.96 2007/01/12 20:15:16 wrp Exp $ */
44826 X
44827 /*
44828 X * pcomplib.c : Parallel library search
44829 X * 
44830 X *     #define FIRSTNODE 0/1 (in msg.h) can be used to reserve one node
44831 X *     for collecting results
44832 X *
44833 X * Parallel specific options (from doinit.c):
44834 X *     -J # jump to query #
44835 X *     -I   self-comparison, do (N choose 2) comparisons
44836 X *     -T # number of workers
44837 X */
44838 X
44839 /* This version is modifed to read all files, query and database,
44840 X   through the manager process. Workers will now receive their
44841 X   database from the manager, rather than reading it themselves.  This
44842 X   cuts down considerably on NFS traffic, simplifies searches of
44843 X   multiple files, and allows use of clusters of slave nodes that do
44844 X   not have NFS access
44845 */
44846 X
44847 /* modified 5-November-2004 to ensure 15 byte (SEQ_PAD) NULL
44848 X   padding
44849 X
44850 X   modified 12-December-2006 to ensure n0>0 before SEQ_PAD padding.
44851 X */
44852 X
44853 #include <stdio.h>
44854 #include <stdlib.h>
44855 #include <string.h>
44856 #include <ctype.h>
44857 #include <time.h>
44858 X
44859 #include <limits.h>
44860 #include <float.h>
44861 #include <math.h>
44862 X
44863 #include <unistd.h>
44864 #include <sys/types.h>
44865 #include <signal.h>
44866 #include <sys/stat.h>
44867 X
44868 #ifdef PVM_SRC
44869 #include "pvm3.h"
44870 char *mp_verstr="34.26, January 12, 2007 PVM";
44871 #endif
44872 X
44873 #ifdef MPI_SRC
44874 #include "mpi.h"
44875 char *mp_verstr="34.26, January 12, 2007 MPI";
44876 #endif
44877 X
44878 #include "msg.h"
44879 #include "defs.h"
44880 #include "mm_file.h"
44881 X
44882 #include "structs.h"
44883 #include "param.h"
44884 #include "p_mw.h"
44885 X
44886 #define XTERNAL
44887 #include "uascii.h"
44888 X
44889 char pgmdir[MAX_FN];
44890 char workerpgm[MAX_FN];
44891 char managepgm[MAX_FN];
44892 X
44893 #define XTERNAL
44894 #include "upam.h"
44895 #undef XTERNAL
44896 X
44897 /********************************/
44898 /* global variable declarations */
44899 /********************************/
44900 char gstring2[MAX_STR];                  /* string for label */
44901 char gstring3[MAX_STR];                  /* string for label */
44902 char hstring1[MAX_STR];
44903 X
44904 int nsfnum;     /* number of superfamily numbers */
44905 int sfnum[10];  /* superfamily number from types 0 and 5 */
44906 int nsfnum_n;
44907 int sfnum_n[10];
44908 X
44909 /********************************/
44910 /* extern variable declarations */
44911 /********************************/
44912 extern char *prog_func;         /* function label */
44913 extern char *verstr, *iprompt0, *iprompt1, *iprompt2, *refstr;
44914 X
44915 /********************************/
44916 /*extern function declarations  */
44917 /********************************/
44918 X
44919 void libchoice(char *lname, int, struct mngmsg *); /* lib_sel.c */
44920 void libselect(char *lname, struct mngmsg *);   /* lib_sel.c */
44921 X
44922 extern void closelib();
44923 /* check for DNA sequence (nxgetaa.c) */
44924 extern int scanseq(unsigned char *seq, int n, char *str);
44925 extern void re_ascii(int *qascii, int *sascii);
44926 extern int recode(unsigned char *seq, int n, int *qascii, int nsq);
44927 X
44928 /* 1d to 2d pam (initxx.c) */
44929 extern void initpam2 (struct pstruct *ppst);
44930 /* initialize environment (doinit.c) */
44931 extern void h_init (struct pstruct *ppst, struct mngmsg *, char *);
44932 extern void s_abort (char *p,  char *p1);
44933 extern void query_parm (struct mngmsg *m_msp, struct pstruct *ppst);
44934 extern void last_init (struct mngmsg *, struct pstruct *, int);
44935 X
44936 extern void initenv (int argc, char **argv, struct mngmsg *m_msg,
44937 X                    struct pstruct *ppst, unsigned char **aa0);
44938 X
44939 /* print hist, summaries, timing information */
44940 void prhist(FILE *, struct mngmsg, struct pstruct, struct hist_str, int nstats, struct db_str, char *);
44941 void printsum(FILE *);
44942 extern void ptime (FILE *, time_t);
44943 X
44944 /* reset parameters if DNA sequence (initxx.c) */
44945 extern void resetp (struct mngmsg *, struct pstruct *);
44946 X
44947 /* read a sequence (nmgetlib.c) */
44948 struct lmf_str *openlib(char *, int, int *, int, struct lmf_str *);
44949 X
44950 #define QGETLIB (q_file_p->getlib)
44951 #define LGETLIB (l_file_p->getlib)
44952 X
44953 /* these functions are in scaleswn.c */
44954 extern int process_hist(struct stat_str *sptr, int nstat,
44955 X                       struct mngmsg m_msg, struct pstruct pst,
44956 X                       struct hist_str *hist, void **pstat_void, int);
44957 extern double zs_to_E(double zs, int n1, int isdna, long, struct db_str ntt);
44958 extern double (*find_zp)(int score, double escore, int length, double comp, void *);
44959 void addhistz(double zscore, struct hist_str *);        /* scaleswn.c */
44960 void last_stats(const unsigned char *aa0, int n0,  
44961 X               struct stat_str *sptr, int nstats,
44962 X               struct beststr **bestp_arr, int nbest,
44963 X               struct mngmsg m_msg, struct pstruct pst,
44964 X               struct hist_str *histp, void *rs);
44965 X
44966 void selectbestz(struct beststr **, int, int);
44967 void sortbest(struct beststr **, int, int);
44968 X
44969 void showbest (FILE *fp, struct beststr **bptr, int nbest,
44970 X              int qlib, struct mngmsg *m_msg, struct pstruct pst,
44971 X              struct db_str ntt, char *gstring2);
44972 X
44973 void showalign (FILE *fp, 
44974 X               struct beststr **bptr, int nbest,int qlib, struct mngmsg m_msg,
44975 X               struct pstruct pst, char *gstring2);
44976 X
44977 #ifdef PVM_SRC
44978 char worknode[120];
44979 int pinums[MAXNOD],hosttid;
44980 int narch;
44981 struct pvmhostinfo *hostp;
44982 #endif
44983 X
44984 FILE *outfd;                    /* Output file */
44985 X
44986 extern time_t s_time ();                 /* fetches time for timing */
44987 X
44988 /* this information is global for fsigint() */
44989 time_t tstart, tscan, tprev, tdone;     /* Timing */
44990 time_t tdstart, tddone, time();
44991 int max_nodes, nnodes;                  /* number of nodes */
44992 int node_map[MAXWRKR], node_id[MAXWRKR];
44993 int tot_speed,h_speed;
44994 int  qlib = 0;  /* number of sequences scanned */
44995 struct db_str ntt, qtt;
44996 X
44997 extern int max_workers, worker_1, worker_n;
44998 int  wlsn [MAXWRKR + 1];        /* number of library sequences in worker */
44999 int  clsn [MAXWRKR + 1];        /* number of 1st library sequence in worker */
45000 X
45001 int max_buf_cnt;
45002 X
45003 #ifdef PVM_SRC
45004 #ifndef WORKERPGM
45005 #define WORKERPGM "c34.work"
45006 #endif
45007 #endif
45008 X
45009 main (int argc, char *argv[])
45010 {
45011 X  unsigned char *aa00, *aa01, *aa0p0, *aa0p1;
45012 X  unsigned char *aa1, *aa1ptr, *aa1prev;
45013 X  int aa1i, *aa1i_arr; /* integer offset of sequence in buffer */
45014 X
45015 X  int n1;
45016 X  int *n1tot_ptr=NULL, *n1tot_cur;
45017 X  int n1tot_cnt=0;
45018 X  int n1tot_v;
45019 X
45020 X  long l_off;
45021 X  char nodefile[240];
45022 X  struct pstruct pst;
45023 X  int i_score;
45024 X  struct lmf_str *q_file_p;
45025 X  struct lmf_str *l_file_p;
45026 X
45027 X  /* from manage code */
45028 X  struct mngmsg m_msg0, m_msg1;        /* Message from host to manager */
45029 X  struct mngmsg *m_msp0, *m_msp1;      /* alternating pointers */
45030 X  struct qmng_str qm_msg0, qm_msg1;    /* stuff updated for each query */
45031 X  char q_sqnam[4]; 
45032 X  int sstart, sstop;
45033 X    
45034 X  struct qmng_str *qm_msp0, *qm_msp1;  /* pointer to stuff updated */
45035 X  int last_msg_b[10];  /* last set of numbers */
45036 X  long curtype = ONETYPE;      /* current message type */
45037 X  int nclib;
45038 X  struct beststr *best,                /* array of best scores */
45039 X                 **bptr;       /* array of pointers */
45040 X  struct comstr bestr[BFR+1];  /* temporary structure array */
45041 X  struct comstr2 bestr2[BFR2+1];       /* temporary structure array */
45042 X  struct a_struct *aln_d_base=NULL;    /* alignment info for -m 9 */
45043 X  int qres_bufsize;            /* buffer size for results */
45044 X  struct stat_str *stats=NULL, *qstats=NULL;
45045 X  int best_flag = 1;           /* bptr[] must be re-initialized */
45046 X  int fast_flag = 0;           /* send new sequences before old displayed */
45047 X  int nstats, nqstats, kstats, jstats;
45048 X  int nbest, nres;             /* number of best scores */
45049 X  double zbestcut = -BIGNUM;   /* z-value cutoff */
45050 X  int lcnt;                    /* counters */
45051 X  int nopt;
45052 X  int i, j, k, is, id, iw, ires, naa0 = 0;
45053 X
45054 X  FILE *fdata=NULL;            /* file for full results */
45055 X  struct sql *desptr;
45056 X  struct sql *ldes;            /* descriptive lines for all lib sequences */
45057 X  char *bline_buf, *bline_bufp;
45058 X  char *bline_buf_mx;  /* buffer for blines */
45059 X  char q_bline[256];
45060 X  char t_bline[256];
45061 X  int max_bline_b, bline_inc;
45062 X  int *n1_arr, *m_seqnm_arr;
45063 X  unsigned char *aa1_buf;
45064 X
45065 X  char tlibstr[11];            /* used only for fdata *.res files */
45066 X  
45067 X  int node, snode, zero;       /* Number of nodes */
45068 X  int bufid, numt, tid;
45069 X
45070 X  int ave_seq_len;
45071 X  int max_sql;
45072 X  int ntbuff, nseq, m_seqnm;
45073 X  int iln, ocont, maxt;
45074 X  long loffset;
45075 X
45076 X  int leng;                    /* leng is length of the descriptive line */
45077 X  fseek_t qseek,lseek;         /* seek into library of current sequence */
45078 X  int qlcont,lcont;                    /* continued sequence */
45079 X  int n_proc, n_tmp;
45080 X  char errstr[120];
45081 X  int stats_done =0;                   /* flag for z-value processing */
45082 X  int tm_best, t_rbest, t_qrbest, t_best, t_n1;
45083 X  double e_score, tm_escore, t_rescore, t_qrescore;
45084 X  double zscore;                       /* tmp value */
45085 X  double k_H, k_comp;
45086 X  char tmp_str[MAX_FN];
45087 X  char pgm_abbr[MAX_SSTR];
45088 X  char *bp;
45089 #ifdef MPI_SRC
45090 X  MPI_Status mpi_status;
45091 #endif
45092 X
45093 X  void fsigint();
45094 X  
45095 X  signal(SIGHUP,SIG_IGN);
45096 X  if (signal(SIGINT,SIG_IGN) != SIG_IGN) signal(SIGINT,fsigint);
45097 X  if (signal(SIGQUIT,SIG_IGN) != SIG_IGN) signal(SIGQUIT,fsigint);
45098 /*  if (signal(SIGSEGV,SIG_IGN) != SIG_IGN) signal(SIGSEGV,fsigint); */
45099 X
45100 X  /* Initialization */
45101 X
45102 X
45103 #if defined(UNIX)
45104 X  m_msg0.quiet = !isatty(1);
45105 #endif
45106 X
45107 X  /* BFR must be %6 = 0 for TFASTA */
45108 X  if ((BFR%6) != 0) {
45109 X    fprintf(stderr," BFR size %d not %%6=0 - recompile\n",BFR);
45110 X    exit(1);
45111 X  }
45112 X
45113 #ifdef MPI_SRC
45114 X  MPI_Init(&argc, &argv);
45115 X  MPI_Comm_rank(MPI_COMM_WORLD,&tid);
45116 X  if (tid > 0) {
45117 X    workcomp(tid); 
45118 X    MPI_Finalize();
45119 X    exit(0);
45120 X  }
45121 #endif
45122 X
45123 X  printf("#");
45124 X  for (i=0; i<argc; i++) {
45125 X    if (strchr(argv[i],' ')) printf(" \"%s\"",argv[i]);
45126 X    else printf(" %s",argv[i]);
45127 X  }
45128 X  printf("\n");
45129 X
45130 #ifdef MPI_SRC
45131 X  MPI_Comm_size(MPI_COMM_WORLD,&nnodes);
45132 X  if (nnodes <= 1) {
45133 X    fprintf(stderr," nnodes = %d; no workers available\n",nnodes);
45134 X    exit(1);
45135 X  }
45136 X  else fprintf(stderr," have %d nodes\n",nnodes);
45137 X
45138 X  tot_speed = nnodes*100;
45139 #endif
45140 X
45141 X  h_init (&pst,&m_msg0, pgm_abbr);
45142 X
45143 X  initenv (argc, argv, &m_msg0, &pst, &aa00);
45144 X
45145 #ifdef PVM_SRC
45146 X  strncpy (workerpgm, WORKERPGM,sizeof(workerpgm)-1);
45147 X  strncat(workerpgm, pgm_abbr, sizeof(workerpgm)-strlen(workerpgm)-1);
45148 X  workerpgm[sizeof(workerpgm)-1] = '\0';
45149 #endif
45150 X  
45151 X  strncpy(q_sqnam,"aa",sizeof(q_sqnam));
45152 X  m_msg0.quiet = 1;
45153 X  if (m_msg0.qdnaseq != SEQT_UNK && 
45154 X      (m_msg0.qdnaseq == SEQT_DNA || m_msg0.qdnaseq == SEQT_RNA))
45155 X    strncpy(q_sqnam,"nt",sizeof(q_sqnam));
45156 X
45157 X  m_msg0.pstat_void = NULL;
45158 X  m_msg0.hist.hist_a = NULL;
45159 X
45160 X  fprintf (stderr, "Pcomp library processor\n");
45161 X  fprintf (stderr, "Using %s\n", prog_func);
45162 X  
45163 X  tstart = tscan = s_time();
45164 X  tdstart = time(NULL);
45165 X  
45166 X
45167 #ifdef PVM_SRC
45168 X  if ((hosttid=pvm_mytid())<0) {
45169 X    pvm_perror("initialization");
45170 X    fprintf(stderr,"can't initialize %s\n", argv[0]);
45171 X    pvm_exit();
45172 X    exit(1);
45173 X  }
45174 X  
45175 X  pvm_config(&nnodes,&narch,&hostp);
45176 X  fprintf(stderr,"nnodes: %d, narch: %d\n",nnodes, narch);
45177 X  max_nodes = nnodes;
45178 X
45179 #ifdef DEBUG
45180 X  pvm_catchout(stderr);
45181 #endif
45182 X
45183 /*  if (nnodes < 2 ) nnodes = 4; */
45184 X  if (max_workers > 0  && nnodes > max_workers) {
45185 X    nnodes = max_workers+FIRSTNODE;
45186 X    fprintf(stderr," workers reset from %d to %d\n",
45187 X           max_nodes,nnodes-FIRSTNODE);
45188 X  }
45189 X  else max_workers = nnodes;
45190 X  
45191 X  strncpy(nodefile,pgmdir,sizeof(nodefile)-1);
45192 X  strncat(nodefile,workerpgm,sizeof(nodefile)-strlen(nodefile)-1);
45193 X  nodefile[sizeof(nodefile)-1] = '\0';
45194 X
45195 X  if (worker_1 > 0) {
45196 X    /* remap configuration to specific nodes */
45197 X    for (i=FIRSTNODE, j=worker_1; i<nnodes && j<=worker_n; i++,j++)
45198 X      node_id[i]=j;
45199 X    nnodes = i;
45200 X    max_workers = i-FIRSTNODE;
45201 X    fprintf(stderr," workers remapped from %d to %d\n",
45202 X           max_nodes,nnodes-FIRSTNODE);
45203 X    max_nodes = nnodes;
45204 X  }
45205 X  else {
45206 X    for (i=0; i< nnodes; i++) node_map[i]=node_id[i] = i;
45207 X  }
45208 X
45209 X  if (nnodes < max_nodes) {
45210 X    hostp++;   /* bump over host name for spawn */
45211 X    rand_nodes(node_map,nnodes,max_nodes-1);
45212 X    for (i=FIRSTNODE; i<nnodes; i++) {
45213 X      numt+=pvm_spawn(nodefile,NULL,PvmTaskHost,hostp[node_map[i]].hi_name,
45214 X                     1,&pinums[i]);
45215 X    }
45216 X  }
45217 X  else {
45218 X    /* i counts through nodes (machines) */
45219 X    /* j counts through processes (multiple processes/node) */
45220 X    /* node map maps the process (virtual node) to a physical node (machine) */
45221 X
45222 X    for (i=j=FIRSTNODE; i<nnodes && j < MAXWRKR; i++) {
45223 X      n_proc = hostp[node_id[i]].hi_speed%100;
45224 X      if (n_proc == 0) n_proc = 1;
45225 X      if (n_proc > max_workers) n_proc = max_workers;
45226 X
45227 X      n_tmp =pvm_spawn(nodefile,NULL,PvmTaskHost,hostp[node_id[i]].hi_name,
45228 X                      n_proc,&pinums[j]);
45229 X      if (n_tmp < n_proc)
45230 X       fprintf(stderr," spawn problem: %d\n", pinums[j]);
45231 X      if (n_tmp > 0) {
45232 X       for (k=j; k < j+n_tmp; k++) node_map[k]=node_id[i];
45233 X       j += n_tmp;
45234 X      }
45235 X    }
45236 X    nnodes = numt = j;
45237 X  }
45238 X
45239 X  if (numt < nnodes) {
45240 X    if (numt <= 0) {
45241 X      pvm_perror("");
45242 X      pvm_exit();
45243 X      exit(1);
45244 X    }
45245 X    nnodes = numt;
45246 X  }
45247 X
45248 X  for (tot_speed=0,i=FIRSTNODE; i<nnodes; i++) {
45249 X    if (pinums[i]<0) {
45250 X      fprintf(stderr," tids %d %8o\n",i,pinums[i]);
45251 X      pvm_perror("");
45252 X      pvm_exit();
45253 X      exit(1);
45254 X    }
45255 X    else {
45256 X      h_speed = hostp[node_map[tidtonode(pinums[i])]].hi_speed;
45257 X      if (h_speed <= 0) h_speed = 100;
45258 X      fprintf(stderr," tids %d %8o %s %5d\n",i,pinums[i],
45259 X             hostp[node_map[tidtonode(pinums[i])]].hi_name,
45260 X             h_speed);
45261 X      tot_speed +=(hostp[node_map[tidtonode(pinums[i])]].hi_speed);
45262 X    }
45263 X  }
45264 X
45265 X  strncpy(worknode,nodefile,sizeof(worknode));
45266 X  fprintf (stderr, "%3d worker programs loaded from %s\n",
45267 X          nnodes-FIRSTNODE,worknode);
45268 #endif  
45269 X
45270 X  /* need to allocate two aa0 arrays so that the old is saved for alignments */
45271 X
45272 X  /* Allocate space for the query sequence */
45273 X  if ((aa00 = (unsigned char *) malloc ((MAXTST + SEQ_PAD + 1)* sizeof (char))) == NULL)
45274 X    s_abort ("Unable to allocate query sequence", "");
45275 X  
45276 X  if ((aa01 = (unsigned char *) malloc ((MAXTST + SEQ_PAD + 1) * sizeof (char))) == NULL)
45277 X    s_abort ("Unable to allocate query sequence", "");
45278 X  
45279 X  fputs(iprompt0,stdout);
45280 X  fprintf(stdout," %s%s\n",verstr,refstr);
45281 X
45282 X  /* Query library */
45283 X  if (m_msg0.tname[0] == '\0') {
45284 X      if (m_msg0.quiet == 1) s_abort("query sequence undefined","");
45285 X      
45286 X      fprintf(stderr, "Pvcomplib [%s]\n",mp_verstr);
45287 X    l1:        fputs (iprompt1, stdout);
45288 X      fflush  (stdout);
45289 X      if (fgets (m_msg0.tname, 80, stdin) == NULL)
45290 X       s_abort ("Unable to read query library name","");
45291 X      if ((bp=strchr(m_msg0.tname,'\n'))!=NULL) *bp='\0';
45292 X      if (m_msg0.tname[0] == '\0') goto l1;
45293 X    }
45294 X  
45295 X  /* Open query library */
45296 X  if ((q_file_p=
45297 X       openlib(m_msg0.tname, m_msg0.qdnaseq,qascii,!m_msg0.quiet,NULL))==NULL) {
45298 X      s_abort(" cannot open library ",m_msg0.tname);
45299 X    }
45300 X  /*
45301 X  else {
45302 X    printf ("searching %s library\n",m_msg0.tname);
45303 X  }
45304 X  */
45305 X
45306 X  ntt.entries = qtt.entries = 0;
45307 X  ntt.carry = qtt.carry = 0;
45308 X  ntt.length = qtt.length = 0l;
45309 X
45310 X  /* Fetch first sequence */
45311 X  qlcont = 0;
45312 X  while (qlib < m_msg0.ql_start) {     /* skip through query sequences */
45313 X    pst.n0 = qm_msg0.n0 = m_msg0.n0 = 
45314 X      QGETLIB (aa00, MAXTST, q_bline, sizeof(q_bline), &qseek, &qlcont,
45315 X              q_file_p,&m_msg0.sq0off);
45316 X
45317 X    strncpy(qm_msg0.libstr,q_bline,sizeof(qm_msg0.libstr)-20);
45318 X    qm_msg0.libstr[sizeof(qm_msg0.libstr)-21]='\0';
45319 X    if ((bp=strchr(qm_msg0.libstr,' '))!=NULL) *bp='\0';
45320 X
45321 X    /* if annotations are included in sequence, remove them */
45322 X    if (m_msg0.ann_flg) {
45323 X      pst.n0 = qm_msg0.n0 = m_msg0.n0 = 
45324 X       ann_scan(aa00, m_msg0.n0, &m_msg0, m_msg0.qdnaseq);
45325 #ifdef DEBUG
45326 X      fprintf(stderr,"m_msp0->/aa0a is: %o/%o\n",&m_msg0,m_msg0.aa0a);
45327 #endif
45328 X    }
45329 X
45330 X    if (m_msg0.term_code && 
45331 X       !(m_msg0.qdnaseq == SEQT_DNA || m_msg0.qdnaseq==SEQT_RNA) &&
45332 X       aa00[m_msg0.n0-1]!='*') {
45333 X      aa00[m_msg0.n0++]='*';
45334 X      aa00[m_msg0.n0]=0;
45335 X      pst.n0 = qm_msg0.n0 = m_msg0.n0;
45336 X    }
45337 X
45338 X    /* check for subset */
45339 X    if (q_file_p->opt_text[0]!='\0') {
45340 X      if (q_file_p->opt_text[0]=='-') {
45341 X       sstart=0; sscanf(&q_file_p->opt_text[1],"%d",&sstop);
45342 X      }
45343 X      else {
45344 X       sscanf(&q_file_p->opt_text[0],"%d-%d",&sstart,&sstop);
45345 X       sstart--;
45346 X       if (sstop <= 0 ) sstop = BIGNUM;
45347 X      }
45348 X      for (id=0,is=sstart; is<min(m_msg0.n0,sstop); ) aa00[id++]=aa00[is++];
45349 X      aa00[id]=0;
45350 X      pst.n0 = qm_msg0.n0 = m_msg0.n0 = min(m_msg0.n0,sstop)-sstart;
45351 X      if (m_msg0.sq0off==1) m_msg0.sq0off = sstart+1;
45352 X    }
45353 X
45354 X    qlib++;
45355 X
45356 X    if (m_msg0.n0 <= 0)
45357 X      s_abort ("Unable to fetch sequence from library: ", m_msg0.tname);
45358 X  }
45359 X  qtt.entries=1;
45360 X  qm_msg0.slist = 0;
45361 X
45362 X  /* now have correct query sequence - check sequence type and reset */
45363 X  if (m_msg0.qdnaseq == SEQT_UNK) {    /* check for DNA sequence */
45364 X    if (m_msg0.n0 > 20 &&
45365 X       (float)scanseq(aa00,m_msg0.n0,"ACGTUNacgtun")/(float)m_msg0.n0>0.85) {
45366 X      pascii = nascii;
45367 X      m_msg0.qdnaseq = SEQT_DNA;
45368 X    }
45369 X    else {     /* its protein */
45370 X      pascii = aascii;
45371 X      m_msg0.qdnaseq = SEQT_PROT;
45372 X    }
45373 X
45374 X    re_ascii(qascii,pascii);
45375 X    init_ascii(pst.ext_sq_set,qascii,m_msg0.qdnaseq);
45376 X    m_msg0.n0 = recode(aa00,m_msg0.n0,qascii,pst.nsqx);
45377 X  }
45378 X
45379 X  /* for ALTIVEC, must pad with 15 NULL's */
45380 X  for (i=0; i<SEQ_PAD+1; i++) {aa00[m_msg0.n0+i]=0;}
45381 X
45382 X  qtt.length = m_msg0.n0;
45383 X
45384 X  if (qlib <= 0) {
45385 X    fprintf(stderr," no sequences found in query library\n");
45386 X    exit(1);
45387 X  }
45388 X
45389 X  resetp (&m_msg0, &pst);
45390 X
45391 X  sprintf(tmp_str," %d %s", qm_msg0.n0, q_sqnam);
45392 X  leng = strlen (qm_msg0.libstr);
45393 X  if (leng + strlen(tmp_str) >= sizeof(qm_msg0.libstr))
45394 X    qm_msg0.libstr[sizeof(qm_msg0.libstr)-strlen(tmp_str)-2] = '\0';
45395 X  strncat(&qm_msg0.libstr[0],tmp_str,
45396 X         sizeof(qm_msg0.libstr)-strlen(qm_msg0.libstr)-1);
45397 X  qm_msg0.libstr[sizeof(qm_msg0.libstr)-1]='\0';
45398 X
45399 X  qm_msg0.seqnm = qlib-1;
45400 X  
45401 X  /* Library */
45402 X
45403 X  if (strlen (m_msg0.lname) == 0) {
45404 X    if (m_msg0.quiet == 1) s_abort("library name undefined","");
45405 X    libchoice(m_msg0.lname, sizeof(m_msg0.lname), &m_msg0);
45406 X  }
45407 X
45408 X  libselect(m_msg0.lname, &m_msg0);
45409 X
45410 X  /* Get additional parameters here */
45411 X  if (!m_msg0.quiet) query_parm (&m_msg0, &pst);
45412 X  
45413 X  last_init(&m_msg0, &pst,nnodes-FIRSTNODE);
45414 X  memcpy(&m_msg1, &m_msg0, sizeof(m_msg0));
45415 X  
45416 X  /* m_msg0.maxn needs to be set to MAXLIB or MAXTRN, depending on the
45417 X     function - max_tot has the MAXTST + (MAXLIB|MAXTRN) */
45418 X  if (m_msg0.maxn <= 0) m_msg0.maxn = m_msg0.max_tot - MAXTST;
45419 X
45420 X  if (m_msg0.maxn < 2 * m_msg0.dupn) m_msg0.maxn = 5*m_msg0.dupn;
45421 X  pst.maxlen = m_msg0.maxn;
45422 X
45423 X  m_msg0.loff = m_msg0.dupn;
45424 X  m_msg0.maxt3 = m_msg0.maxn-m_msg0.loff;
45425 X
45426 X
45427 X  /* ******************** */
45428 X  /* initial manager code */
45429 X  /* ******************** */
45430 X  
45431 X  outfd = stdout;
45432 X  if (m_msg0.outfile[0]!='\0') {
45433 X    if ((outfd = fopen(m_msg0.outfile,"w"))==NULL) {
45434 X      fprintf(stderr, "cannot open %s for output\n", m_msg0.outfile);
45435 X      outfd = stdout;
45436 X    }
45437 X  }
45438 X
45439 X  /* Label the output */
45440 X  printf("Query library %s vs %s library\n", m_msg0.tname, m_msg0.lname);
45441 X  
45442 X  /* Allocate space for saved scores */
45443 X  if ((best = 
45444 X       (struct beststr *)malloc((MAXBEST+1)*sizeof(struct beststr)))==NULL)
45445 X    s_abort ("Cannot allocate best struct","");
45446 X  if ((bptr = 
45447 X       (struct beststr **)malloc((MAXBEST+1)*sizeof(struct beststr *)))==NULL)
45448 X    s_abort ("Cannot allocate bptr","");
45449 X  
45450 X  /* Initialize bptr */
45451 X  for (nbest = 0; nbest < MAXBEST+1; nbest++)
45452 X    bptr[nbest] = &best[nbest];
45453 X
45454 X  best++; bptr++;
45455 X  best[-1].score[0]=best[-1].score[1]=best[-1].score[2]=INT_MAX;
45456 X  best[-1].zscore = FLT_MAX;
45457 X  best[-1].escore = FLT_MIN;
45458 X  best_flag = 0;
45459 X  
45460 X  if ((stats =
45461 X       (struct stat_str *)calloc((size_t)MAXSTATS,sizeof(struct stat_str)))
45462 X      ==NULL)
45463 X    s_abort ("Cannot allocate stats struct","");
45464 X  nstats = 0;
45465 X
45466 X  /* Now open the second library, divide it, send sequences to all workers */
45467 X  /* Set up buffer for reading the library:
45468 X
45469 X     We will start by using a 2 Mbyte buffer for each worker.  For
45470 X     proteins, that means 5,000 sequences of length 400 (average).
45471 X     For DNA, that means 2,000 sequences of length 1000.  At the moment,
45472 X     those are good averages.
45473 X     */
45474 X
45475 X  if (max_buf_cnt <= 0) {
45476 X    if (m_msg0.ldnaseq==SEQT_DNA) max_buf_cnt = MAX_NT_BUF;
45477 X    else max_buf_cnt = MAX_AA_BUF;
45478 X  }
45479 X
45480 X  if (m_msg0.ldnaseq==SEQT_DNA) ave_seq_len = AVE_NT_LEN;
45481 X  else ave_seq_len = AVE_AA_LEN;
45482 X
45483 X  /* however - buffer sizes should be a function of the number of
45484 X     workers so that all the workers are kept busy.  Assuming a 10,000
45485 X     entry library is the smallest we want to schedule, then
45486 X     */
45487 X
45488 X  if (max_buf_cnt > 10000/(nnodes-FIRSTNODE)) 
45489 X    max_buf_cnt = 10000/(2*(nnodes-FIRSTNODE));
45490 X
45491 X  /* allocate space for sequence buffers */
45492 X
45493 X  m_msg0.pbuf_siz=max_buf_cnt*ave_seq_len;
45494 X  if (m_msg0.pbuf_siz < 5*m_msg0.maxn)
45495 X    m_msg0.pbuf_siz = 5*m_msg0.maxn;
45496 X
45497 #ifdef PVM_SRC 
45498 #ifdef ROUTE_DIRECT
45499 X  pvm_setopt(PvmRoute,PvmRouteDirect);
45500 #endif
45501 X  pvm_initsend(PvmDataRaw);
45502 X  pvm_pkint(&nnodes,1,1);
45503 X  pvm_pkint(pinums,nnodes,1);
45504 X  pvm_pkbyte((char *)&m_msg0,(int)sizeof(m_msg0),1);
45505 X  for (node = FIRSTNODE; node<nnodes; node++) 
45506 X    if (pvm_send(pinums[node],STARTTYPE0)<0) {
45507 X      pvm_perror("pvm_send1");
45508 X      pvm_exit();
45509 X      exit(1);
45510 X    }
45511 #endif
45512 #ifdef MPI_SRC
45513 X  for (node = FIRSTNODE; node<nnodes; node++)  {
45514 X    MPI_Send(&m_msg0,(int)sizeof(m_msg0),MPI_BYTE,node,STARTTYPE0,
45515 X            MPI_COMM_WORLD);
45516 X  }
45517 #endif
45518 X
45519 X  /* now send pst, sascii */
45520 #ifdef PVM_SRC
45521 X  pvm_initsend(PvmDataRaw);
45522 X  pvm_pkbyte((char *)&pst,(int)sizeof(pst),1);
45523 X  pvm_pkbyte((char *)pascii,(int)sizeof(aascii),1);
45524 X
45525 X  for (node = FIRSTNODE; node< nnodes; node++)
45526 X    pvm_send(pinums[node],STARTTYPE1);
45527 X
45528 X  /* send pam12 */
45529 X  pvm_initsend(PvmDataRaw);
45530 X  pvm_pkint(pam12,m_msg0.pamd1*m_msg0.pamd2,1);
45531 X  for (node = FIRSTNODE; node< nnodes; node++)
45532 X    pvm_send(pinums[node],STARTTYPE2);
45533 X
45534 X  /* send pam12x */
45535 X  pvm_initsend(PvmDataRaw);
45536 X  pvm_pkint(pam12x,m_msg0.pamd1*m_msg0.pamd2,1);
45537 X  for (node = FIRSTNODE; node< nnodes; node++)
45538 X    pvm_send(pinums[node],STARTTYPE3);
45539 X
45540 #endif
45541 #ifdef MPI_SRC
45542 X  for (node=FIRSTNODE; node < nnodes; node++) {
45543 X    MPI_Send(&pst,(int)sizeof(pst),MPI_BYTE,node,STARTTYPE1,
45544 X            MPI_COMM_WORLD);
45545 X    MPI_Send(pascii,(int)sizeof(aascii),MPI_BYTE,node,STARTTYPE1,
45546 X            MPI_COMM_WORLD);
45547 X    MPI_Send(pam12,m_msg0.pamd1*m_msg0.pamd2,MPI_INT,node,STARTTYPE2,
45548 X            MPI_COMM_WORLD);
45549 X    MPI_Send(pam12x,m_msg0.pamd1*m_msg0.pamd2,MPI_INT,node,STARTTYPE3,
45550 X            MPI_COMM_WORLD);
45551 X  }
45552 #endif
45553 X
45554 X  if ((n1_arr =
45555 X       (int *)calloc((size_t)(max_buf_cnt+1),sizeof(int)))
45556 X      ==NULL) {
45557 X    fprintf(stderr," cannot allocate n1_arr %d\n",max_buf_cnt+1);
45558 X    s_abort(" cannot allocate n1_arr","");
45559 X    exit(1);
45560 X  }
45561 X
45562 X  if ((aa1i_arr =
45563 X       (int *)calloc((size_t)(max_buf_cnt+1),sizeof(int)))
45564 X      ==NULL) {
45565 X    fprintf(stderr," cannot allocate aa1i_arr %d\n",max_buf_cnt+1);
45566 X    s_abort(" cannot allocate aa1i_arr","");
45567 X    exit(1);
45568 X  }
45569 X
45570 X  if ((m_seqnm_arr=
45571 X       (int *)calloc((size_t)(max_buf_cnt+1),sizeof(int)))
45572 X      ==NULL) {
45573 X    fprintf(stderr," cannot allocate m_seqnm_arr %d\n",max_buf_cnt+1);
45574 X    s_abort(" cannot allocate m_seqnm_arr","");
45575 X    exit(1);
45576 X  }
45577 X
45578 X  if ((aa1_buf =
45579 X       (unsigned char *)calloc((size_t)(m_msg0.pbuf_siz),sizeof(unsigned char)))
45580 X      ==NULL) {
45581 X    s_abort(" cannot allocate library buffer %d","");
45582 X    exit(1);
45583 X  }
45584 X
45585 X
45586 X  /* also allocate space for descriptions.  Assume max of 250,000 sequences/
45587 X     worker for now
45588 X  */
45589 X
45590 X  /* max_sql is the maxinum number of library sequences that can be stored */
45591 X  max_sql = MAXSQL;
45592 X
45593 X  if ((ldes=(struct sql *)calloc(max_sql,sizeof(struct sql)))==NULL) {
45594 X    fprintf(stderr," failure to allocate ldes(%d) %ld\n",
45595 X           max_sql,max_sql*sizeof(struct sql));
45596 X    s_abort("cannot allocate ldes","");
45597 X    exit(1);
45598 X  }
45599 X
45600 X  max_bline_b = MAXSQL * (m_msg0.aln.llen+1)/4;
45601 X  bline_inc = m_msg0.aln.llen;
45602 X  if (m_msg0.markx & MX_M9SUMM) bline_inc += 40;
45603 X
45604 X  i = 4;
45605 X  while (i-- > 0) {
45606 X    if ((bline_buf=(char *)calloc(max_bline_b,sizeof(char)))!=NULL) break;
45607 X    max_bline_b /= 2;
45608 X    bline_inc /= 2;
45609 X  }
45610 X  if (bline_buf == NULL) {
45611 X    fprintf(stderr," failure to allocate bline_buf(%d) %d\n",
45612 X           max_sql,max_bline_b);
45613 X    s_abort(" cannot allocate bline_buf","");
45614 X  }
45615 X
45616 X  bline_bufp = bline_buf;
45617 X  bline_buf_mx = bline_buf+max_bline_b;
45618 X
45619 X  /* the code for filling the buffers is copied from comp_thr.c */
45620 X  /* the major differences reflect the fact that all library descriptions
45621 X     will be kept in memory, indexed by sequence number.
45622 X
45623 X     As a result, one buffer is filled by this loop -
45624 X       ldes[] has the descriptive information for every sequence
45625 X       this array could potentially be quite large
45626 X  */
45627 X
45628 X  /* now open the library and start reading */
45629 X  /* get a buffer and fill it up */
45630 X
45631 X  ntbuff = 0;
45632 X  m_seqnm = 0; /* m_seqnm is the number of this library sequence */
45633 X  nseq = 0;
45634 X
45635 X  node = FIRSTNODE;
45636 X
45637 X  /* sqs2_buf[0].aa1 = aa1_buf; */
45638 X  aa1 = aa1_buf;
45639 X
45640 X  /* iln counts through each library */
45641 X  for (iln = 0; iln < m_msg0.nln; iln++) {
45642 X    if ((l_file_p=
45643 X        openlib(m_msg0.lbnames[iln], m_msg0.ldnaseq,lascii,!m_msg0.quiet,NULL))==NULL) {
45644 X      fprintf(stderr," cannot open library %s\n",m_msg0.lbnames[iln]);
45645 X      continue;
45646 X    }
45647 X    else {
45648 X      printf ("searching %s library\n",m_msg0.lbnames[iln]);
45649 X    }
45650 X
45651 X    lcont = ocont = 0;
45652 X    n1tot_v = n1tot_cnt = 0;
45653 X    n1tot_ptr = n1tot_cur = NULL;
45654 X    maxt = m_msg0.maxn;
45655 X    loffset = 0l;
45656 X
45657 X    /* read sequence directly into buffer */
45658 X    aa1ptr = aa1; /* = sqs2_buf[0].aa1; */
45659 X
45660 X    while ((n1= LGETLIB(aa1ptr,maxt,t_bline,sizeof(t_bline),&lseek,&lcont,
45661 X                       l_file_p,&l_off))>=0) {
45662 X
45663 X      /* skip sequences outside range */
45664 X      if (n1 < m_msg0.n1_low || n1 > m_msg0.n1_high) goto loop1;
45665 X      
45666 X      /* add termination code for proteins, if asked */
45667 X      if (m_msg0.term_code && !lcont && 
45668 X         m_msg0.ldnaseq==SEQT_PROT && aa1ptr[n1-1]!=m_msg0.term_code) {
45669 X       aa1ptr[n1++]=m_msg0.term_code;
45670 X       aa1ptr[n1]=0;
45671 X      }
45672 X
45673 X      /* check for a continued sequence and provide a pointer to 
45674 X        the n1_tot array if lcont || ocont */
45675 X      n1tot_v += n1;
45676 X      if (lcont && !ocont) {   /* get a new pointer */
45677 X       if (n1tot_cnt <= 0) {
45678 X         if ((n1tot_ptr=calloc(1000,sizeof(int)))==NULL) {
45679 X           fprintf(stderr," cannot allocate n1tot_ptr\n");
45680 X           exit(1);
45681 X         }
45682 X         else {n1tot_cnt=1000;}
45683 X       }
45684 X       n1tot_cnt--;
45685 X       n1tot_cur = n1tot_ptr++;
45686 X      }
45687 X
45688 X      if (bline_bufp + bline_inc > bline_buf_mx) {
45689 X       i = 4;
45690 X       while (i-- > 0) {
45691 X         if ((bline_buf=(char *)calloc(max_bline_b,sizeof(char)))!=NULL)
45692 X           break;
45693 X         fprintf(stderr," failure to allocate bline_buf(%d) %d\n",
45694 X                 max_sql,max_bline_b);
45695 X         max_bline_b /= 2;
45696 X         bline_inc /= 2;
45697 X       }
45698 X       if (bline_buf != NULL) {
45699 X         bline_bufp = bline_buf;
45700 X         bline_buf_mx = bline_buf+max_bline_b;
45701 X       }
45702 X       else {
45703 X         s_abort("cannot allocate bline_buf ","");
45704 X         exit(1);
45705 X       }
45706 X      }
45707 X
45708 X      if (bline_bufp+bline_inc < bline_buf_mx ) {
45709 X       strncpy(bline_bufp,t_bline,bline_inc);
45710 X       ldes[m_seqnm].bline = bline_bufp;
45711 X       bline_bufp[bline_inc]= '\0';
45712 X       bline_bufp += bline_inc+1;
45713 X      }
45714 X      else {
45715 X       fprintf(stderr," bline_buf overrun\n");
45716 X      }
45717 X
45718 X      ntt.entries++;           /* inc number of sequences */
45719 X      ntt.length += n1;        /* update total library length */
45720 X      if (ntt.length > LONG_MAX) {ntt.length -= LONG_MAX; ntt.carry++;}
45721 X
45722 #ifdef DEBUG
45723 X      /* This discovers most reasons for core dumps */
45724 X      if (pst.debug_lib)
45725 X       for (i=0; i<n1; i++)
45726 X         if (aa1[i]>pst.nsq) {
45727 X           fprintf(stderr,
45728 X                   "%s residue[%d/%d] %d range (%d) lcont/ocont: %d/%d\n%s\n",
45729 X                   qm_msg0.libstr,i,n1,aa1[i],pst.nsq,lcont,ocont,aa1ptr+i);
45730 X           aa1[i]=0;
45731 X           n1=i-1;
45732 X           break;
45733 X         }
45734 #endif
45735 X
45736 X      /* for ALTIVEC, must pad with 15 NULL's */
45737 X      for (i=0; i<SEQ_PAD+1; i++) {aa1ptr[n1+i]=0;}
45738 X
45739 X      /* don't count long sequences more than once */
45740 X      if (aa1!=aa1ptr) {
45741 X       n1 += m_msg0.loff; m_msg0.db.entries--; ntt.entries--;
45742 X      }
45743 X
45744 X      if (n1>1) {
45745 X
45746 X       desptr = &ldes[m_seqnm];
45747 X
45748 X       aa1i_arr[nseq] = (int)(aa1-aa1_buf);
45749 X       m_seqnm_arr[nseq] = m_seqnm;
45750 X       desptr->n1 = n1_arr[nseq] = n1;
45751 X       desptr->n1tot_p = n1tot_cur;
45752 X       desptr->lseek = lseek;
45753 X       desptr->loffset = loffset+l_off;
45754 X       desptr->cont = ocont;
45755 X       desptr->wrkr = node;
45756 X       desptr->nsfnum = nsfnum;
45757 #ifdef SUPERFAMNUM
45758 X       if ((desptr->sfnum[0]=sfnum[0])>0 &&
45759 X           (desptr->sfnum[1]=sfnum[1])>0 &&
45760 X           (desptr->sfnum[2]=sfnum[2])>0 &&
45761 X           (desptr->sfnum[3]=sfnum[3])>0 &&
45762 X           (desptr->sfnum[4]=sfnum[4])>0 &&
45763 X           (desptr->sfnum[5]=sfnum[5])>0 &&
45764 X           (desptr->sfnum[6]=sfnum[6])>0 &&
45765 X           (desptr->sfnum[7]=sfnum[7])>0 &&
45766 X           (desptr->sfnum[8]=sfnum[8])>0 &&
45767 X           (desptr->sfnum[9]=sfnum[9])>0) ;
45768 #endif
45769 X       m_seqnm++;
45770 X       nseq++;
45771 X
45772 X       if (m_seqnm >= max_sql) {
45773 X         max_sql += MAXSQL;
45774 X         if ((ldes=(struct sql *)realloc(ldes,max_sql*sizeof(struct sql)))
45775 X             ==NULL) {
45776 X           fprintf(stderr," failure to realloc ldes(%d) %ld\n",
45777 X                   max_sql,max_sql*sizeof(struct sql));
45778 X           s_abort("cannot allocate ldes","");
45779 X           exit(1);
45780 X         }
45781 X       }
45782 X
45783 X       /* increment ptrs */
45784 X       aa1prev = aa1;
45785 X
45786 X       aa1 += n1+1+SEQ_PAD;
45787 X       ntbuff += n1+1+SEQ_PAD;
45788 X
45789 X       /* if the buffer is filled */
45790 X       if (nseq >= max_buf_cnt || ntbuff >= m_msg0.pbuf_siz - m_msg0.maxn) {
45791 X         /* provide filled buffer to workers */
45792 #ifdef PVM_SRC
45793 X         pvm_initsend(PvmDataRaw);
45794 X         pvm_pkint(&nseq,1,1);
45795 X         pvm_pkint(&ntbuff,1,1);
45796 X         pvm_pkint(n1_arr,nseq,1);
45797 X         pvm_pkint(aa1i_arr,nseq,1);
45798 X         pvm_pkint(m_seqnm_arr,nseq,1);
45799 X         pvm_send(pinums[node],STARTTYPE4);
45800 X
45801 X         pvm_initsend(PvmDataRaw);
45802 X         pvm_pkbyte((char *)aa1_buf,ntbuff,1);
45803 X         pvm_send(pinums[node],STARTTYPE5);
45804 #endif
45805 #ifdef MPI_SRC
45806 X         MPI_Send(&nseq,1,MPI_INT,node,STARTTYPE4, MPI_COMM_WORLD);
45807 X         MPI_Send(&ntbuff,1,MPI_INT,node,STARTTYPE4, MPI_COMM_WORLD);
45808 X         MPI_Send(n1_arr,nseq,MPI_INT,node,STARTTYPE4, MPI_COMM_WORLD);
45809 X         MPI_Send(aa1i_arr,nseq,MPI_INT,node,STARTTYPE4, MPI_COMM_WORLD);
45810 X         MPI_Send(m_seqnm_arr,nseq,MPI_INT,node,STARTTYPE4, MPI_COMM_WORLD);
45811 X
45812 X         MPI_Send(aa1_buf,ntbuff,MPI_BYTE,node,STARTTYPE5,MPI_COMM_WORLD);
45813 #endif
45814 X         nseq =  0;
45815 X
45816 X         aa1 = aa1_buf;
45817 X         ntbuff = 0;
45818 X         if (++node >= nnodes) node = FIRSTNODE;
45819 X       }
45820 X
45821 X      loop1:
45822 X       if (lcont) {
45823 X         memcpy(aa1,&aa1prev[n1-m_msg0.loff],m_msg0.loff);
45824 X         aa1ptr = &aa1[m_msg0.loff];
45825 X         ocont = lcont;
45826 X         maxt = m_msg0.maxt3;
45827 X         loffset += n1 - m_msg0.loff;
45828 X       }
45829 X       else {
45830 X         if (ocont) *n1tot_cur = n1tot_v;
45831 X         n1tot_v = 0;
45832 X         n1tot_cur = NULL;
45833 X
45834 X         ocont = 0;
45835 X         aa1ptr = aa1;
45836 X         maxt = m_msg0.maxn;
45837 X         loffset = 0l;
45838 X       }
45839 X      }
45840 X    }
45841 X  }    /* for (iln < nln) */
45842 X
45843 X  if (nseq > 0) {
45844 #ifdef PVM_SRC
45845 X    pvm_initsend(PvmDataRaw);
45846 X    pvm_pkint(&nseq,1,1);
45847 X    pvm_pkint(&ntbuff,1,1);
45848 X    pvm_pkint(n1_arr,nseq,1);
45849 X    pvm_pkint(aa1i_arr,nseq,1);
45850 X    pvm_pkint(m_seqnm_arr,nseq,1);
45851 X    pvm_send(pinums[node],STARTTYPE4);
45852 X
45853 X    pvm_initsend(PvmDataRaw);
45854 X    pvm_pkbyte((char *)aa1_buf,ntbuff,1);
45855 X    pvm_send(pinums[node],STARTTYPE5);
45856 #endif
45857 #ifdef MPI_SRC
45858 X    MPI_Send(&nseq,1,MPI_INT,node,STARTTYPE4, MPI_COMM_WORLD);
45859 X    MPI_Send(&ntbuff,1,MPI_INT,node,STARTTYPE4, MPI_COMM_WORLD);
45860 X    MPI_Send(n1_arr,nseq,MPI_INT,node,STARTTYPE4, MPI_COMM_WORLD);
45861 X    MPI_Send(aa1i_arr,nseq,MPI_INT,node,STARTTYPE4, MPI_COMM_WORLD);
45862 X    MPI_Send(m_seqnm_arr,nseq,MPI_INT,node,STARTTYPE4, MPI_COMM_WORLD);
45863 X
45864 X    MPI_Send(aa1_buf,ntbuff,MPI_BYTE,node,STARTTYPE5,MPI_COMM_WORLD);
45865 #endif
45866 X  }
45867 X
45868 X  /*   fprintf(stderr," all sequences sent\n"); */
45869 X
45870 X  if (ntt.entries <= 0) {
45871 X    s_abort("no reference library sequences found\n","");
45872 X  }
45873 X
45874 X  zero = 0;
45875 X  for (node=FIRSTNODE; node < nnodes; node++) {
45876 #ifdef PVM_SRC
45877 X    pvm_initsend(PvmDataRaw);
45878 X    pvm_pkint(&zero,1,1);
45879 X    pvm_pkint(&zero,1,1);
45880 X    pvm_pkint(n1_arr,1,1);
45881 X    pvm_pkint(aa1i_arr,1,1);
45882 X    pvm_pkint(m_seqnm_arr,1,1);
45883 X    pvm_send(pinums[node],STARTTYPE4);
45884 #endif
45885 #ifdef MPI_SRC
45886 X    MPI_Send(&zero,1,MPI_INT,node,STARTTYPE4, MPI_COMM_WORLD);
45887 X    MPI_Send(&zero,1,MPI_INT,node,STARTTYPE4, MPI_COMM_WORLD);
45888 X    MPI_Send(n1_arr,0,MPI_INT,node,STARTTYPE4, MPI_COMM_WORLD);
45889 X    MPI_Send(aa1i_arr,0,MPI_INT,node,STARTTYPE4, MPI_COMM_WORLD);
45890 X    MPI_Send(m_seqnm_arr,0,MPI_INT,node,STARTTYPE4, MPI_COMM_WORLD);
45891 #endif
45892 X  }
45893 X
45894 X  for (node = FIRSTNODE; node < nnodes; node++) {
45895 #ifdef PVM_SRC
45896 X    bufid = pvm_recv(-1,STARTTYPE0);
45897 X    pvm_bufinfo(bufid,NULL,NULL,&tid);
45898 X    snode = tidtonode(tid);
45899 X    pvm_upkint(&lcnt,1,1);
45900 X    pvm_freebuf(bufid);
45901 #endif
45902 #ifdef MPI_SRC
45903 X    MPI_Recv(&lcnt,1,MPI_INT,MPI_ANY_SOURCE,STARTTYPE0,
45904 X            MPI_COMM_WORLD,&mpi_status);
45905 X    snode= mpi_status.MPI_SOURCE;
45906 #endif
45907 X    wlsn [snode-FIRSTNODE] = lcnt;
45908 X    fprintf(stderr," %d sequences at %d\n",lcnt,snode);
45909 X  }
45910 X
45911 X  /* print out all descriptions */
45912 X  /*
45913 X  for (node = FIRSTNODE; node < nnodes; node++)
45914 X    for (lcnt = 0; lcnt < wlsn[node-FIRSTNODE]; lcnt ++)
45915 X      printf("%2d:%3d\t%s\n",node,lcnt,ldes[lcnt].bline);
45916 X  */
45917 X
45918 X  /* Calculate cumulative totals and send to workers for a self search */
45919 X
45920 X  clsn [0] = nclib= 0;
45921 X  for (node = FIRSTNODE; node < nnodes-1; node++) {
45922 X    /* clsn[] is for the next node */
45923 X    clsn[node-FIRSTNODE+1] = nclib += wlsn[node-FIRSTNODE];
45924 X  }
45925 X
45926 X  if (m_msg0.self)
45927 X    for (node = FIRSTNODE; node < nnodes; node++) {
45928 #ifdef PVM_SRC
45929 X      pvm_initsend(PvmDataRaw);
45930 X      pvm_pkint(&clsn[node-FIRSTNODE],1,1);
45931 X      pvm_send(pinums[node],STARTTYPE1);
45932 #endif
45933 #ifdef MPI_SRC
45934 X    MPI_Send(&clsn[node-FIRSTNODE],1,MPI_INT,node,STARTTYPE1,MPI_COMM_WORLD);
45935 #endif
45936 X      fprintf(stderr,"sending lend: %d to worker %d\n",clsn[node-FIRSTNODE],node);
45937 X    }
45938 X
45939 X  last_msg_b[0] = m_msg0.nbr_seq = m_msg1.nbr_seq = ntt.entries;
45940 X
45941 X  qres_bufsize = BFR;
45942 X  /* if BFR is too big for this library, reduce it */
45943 X  while ( ntt.entries*(m_msg0.nitt1+1)/(2*nnodes) < qres_bufsize) {
45944 X    qres_bufsize /= 2;
45945 X    if ((qres_bufsize%(m_msg0.nitt1+1))!= 0) {
45946 X      qres_bufsize *= (m_msg0.nitt1+1);
45947 X      break;
45948 X    }
45949 X    if (qres_bufsize < 50) break;
45950 X  }
45951 X  last_msg_b[1] = qres_bufsize;
45952 X
45953 X  fprintf(stderr," using BFR=%d/%d\n",qres_bufsize,BFR);
45954 X
45955 #ifdef PVM_SRC
45956 X  pvm_initsend(PvmDataRaw);
45957 X  pvm_pkint(last_msg_b,2,1);
45958 X  for (node=FIRSTNODE; node < nnodes; node++)
45959 X    pvm_send(pinums[node],STARTTYPE0);
45960 #endif
45961 #ifdef MPI_SRC
45962 X  for (node=FIRSTNODE; node < nnodes; node++)
45963 X    MPI_Send(last_msg_b,2,MPI_INT,node,STARTTYPE0,MPI_COMM_WORLD);
45964 #endif  
45965 X
45966 X  tscan = tprev = s_time();
45967 X
45968 /**************************************
45969 X  The logic of this section has been simplified to allow multistage
45970 X  comparison functions to be used and alignments to be generated.
45971 X
45972 X       send 1st query to workers
45973 X       get next query sequence from host (m_msp1)
45974 X    L1:        get results from next-1 search (m_msp0)
45975 X       sort the results of the next-1 search
45976 X       (possibly) do additional stages of search
45977 X       (possibly produce alignments for search
45978 X       send next query to workers (m_msp1)
45979 X       display result of next-1 search (m_msp0)
45980 X       get next query sequence from host (m_msp1)
45981 X       goto L1;
45982 X
45983 As a result of the interleaving, there must be two qm_msg structures,
45984 one for the next-1 sequence (which is required for labeling the
45985 output), and one for the next sequence (which is sent to the workers
45986 while the results are being displayed.  qm_msp0 and qm_msp1 alternate
45987 between these two structures.
45988 ***************************************/
45989 X
45990 /*
45991 X  qm_msp0 points to the older qm_msg 
45992 X  qm_msp1 points to the newer qm_msg
45993 X  the assignment below goes with curtype==ONETYPE
45994 */
45995 X  m_msp0 = &m_msg0;
45996 X  m_msp1 = &m_msg1;
45997 X
45998 X  qm_msp0 = &qm_msg0;
45999 X  qm_msp1 = &qm_msg1;
46000 X  
46001 X  aa0p0 = aa00;                /* aa0p0 is the "old" sequence */
46002 X  aa0p1 = aa01;                /* aa0p1 is the "new" sequence */
46003 X
46004 X  last_params(aa00,m_msp0->n0,m_msp0,&pst,qm_msp0);
46005 X
46006 X  /* process_hist() is called here to get find_zp(), and some other
46007 X     structures initialized that would otherwise not be initialized
46008 X     because z-scores are not being calculated */
46009 X
46010 X  if (m_msp0->escore_flg) {
46011 X     pst.zsflag_f = process_hist(stats,nstats,*m_msp0,pst,
46012 X                                &m_msp0->hist,&m_msp0->pstat_void,0);
46013 X     stats_done=1;
46014 X  }
46015 X
46016 X  if (m_msp0->qshuffle && qstats==NULL) {
46017 X    if ((qstats =
46018 X        (struct stat_str *)calloc(m_msg0.shuff_max+1,sizeof(struct stat_str)))==NULL)
46019 X      s_abort ("Cannot allocate qstats struct","");
46020 X  }
46021 X  nqstats = 0;
46022 X
46023 /* Send first query sequence to each worker */
46024 X
46025 X  if (m_msg0.dfile[0] && (fdata=fopen(m_msg0.dfile,"w"))!=NULL)
46026 X    fprintf(fdata,"%3d>%-50s\n",qlib,qm_msp0->libstr);
46027 X
46028 #ifdef PVM_SRC
46029 X  pvm_initsend(PvmDataRaw);
46030 X  pvm_pkbyte((char *)qm_msp0,sizeof(qm_msg0),1);
46031 X  if (qm_msp0->n0 > 0) {
46032 X    pvm_pkbyte((char *)aa0p0,qm_msp0->n0+1+SEQ_PAD,1);
46033 X    if (m_msg0.ann_flg) pvm_pkbyte((char *)m_msp0->aa0a,qm_msp0->n0+1,1);
46034 X  }
46035 X  for (node = FIRSTNODE; node < nnodes; node++)
46036 X    pvm_send(pinums[node],MSEQTYPE);
46037 #endif
46038 #ifdef MPI_SRC
46039 X  for (node = FIRSTNODE; node < nnodes; node++) {
46040 X    MPI_Send(qm_msp0,sizeof(qm_msg0),MPI_BYTE,node,MSEQTYPE,MPI_COMM_WORLD);
46041 X    if (qm_msp0->n0 > 0) {
46042 X      MPI_Send(aa0p0,qm_msp0->n0+1+SEQ_PAD,MPI_BYTE,node,
46043 X              MSEQTYPE1,MPI_COMM_WORLD);
46044 X      if (m_msg0.ann_flg) {
46045 X       if (m_msp0->aa0a == NULL) {
46046 X         fprintf(stderr," m_msp0: %o/%oaa0a is null\n",m_msp0,m_msp0->aa0a);
46047 X       }
46048 X       MPI_Send(m_msp0->aa0a,qm_msp0->n0+1,MPI_BYTE,node, MSEQTYPE2,MPI_COMM_WORLD);
46049 X      }
46050 X    }
46051 X  }
46052 #endif
46053 X
46054 X  /* Get second query sequence (additional query sequences are read in
46055 X     the main loop */
46056 X
46057 X  m_msp1->n0 = qm_msp1->n0 = 
46058 X    QGETLIB(aa0p1,MAXTST,q_bline, sizeof(q_bline),&qseek, &qlcont,q_file_p,&m_msp1->sq0off);
46059 X  strncpy(qm_msp1->libstr,q_bline,sizeof(qm_msg0.libstr)-20);
46060 X  qm_msp1->libstr[sizeof(qm_msg0.libstr)-21]='\0';
46061 X  if ((bp=strchr(qm_msp1->libstr,' '))!=NULL) *bp='\0';
46062 X
46063 X  /* if annotations are included in sequence, remove them */
46064 X  if (m_msg0.ann_flg) {
46065 X    m_msp1->n0 = qm_msp1->n0 = 
46066 X      ann_scan(aa0p1,qm_msp1->n0,m_msp1,m_msp1->qdnaseq);
46067 #ifdef DEBUG
46068 X    fprintf(stderr,"m_msp1->/aa0a is: %o/%o\n",m_msp1,m_msp1->aa0a);
46069 #endif
46070 X  }
46071 X
46072 X  if (qm_msp1->n0 > 0 && m_msg0.term_code && !qlcont && 
46073 X      m_msg0.qdnaseq == SEQT_PROT &&
46074 X      aa0p1[m_msp1->n0-1]!=m_msg0.term_code) {
46075 X    aa0p1[m_msp1->n0++]=m_msg0.term_code;
46076 X    aa0p1[m_msp1->n0]=0;
46077 X    qm_msp1->n0 = m_msp1->n0;
46078 X  }
46079 X
46080 X  /* for ALTIVEC, must pad with 15 NULL's */
46081 X  if (m_msp1->n0 > 0) {
46082 X    for (i=0; i<SEQ_PAD+1; i++) {aa0p1[m_msp1->n0+i]=0;}
46083 X  }
46084 X
46085 X  qm_msp1->slist = 0;
46086 X  qm_msp1->seqnm = qlib;
46087 X
46088 X  last_params(aa0p1,m_msp1->n0,m_msp1,&pst,qm_msp1);
46089 X
46090 X  sprintf(tmp_str," - %d %s", qm_msp1->n0, q_sqnam);
46091 X  if (strlen(qm_msp1->libstr) + strlen(tmp_str) >= sizeof(qm_msg0.libstr))
46092 X    qm_msp1->libstr[sizeof(qm_msg0.libstr)-strlen(tmp_str)-2] = '\0';
46093 X  strncat(qm_msp1->libstr,tmp_str,
46094 X         sizeof(qm_msg0.libstr)-strlen(qm_msp1->libstr)-1);
46095 X  qm_msp1->libstr[sizeof(qm_msg0.libstr)-1]='\0';
46096 X
46097 X  naa0 = 0;  /* reset node counter */
46098 X
46099 X  /* sit in loop and collect results */
46100 X  nbest = nopt = 0;
46101 X  zbestcut = -BIGNUM;
46102 X
46103 X
46104 X  while (1) {
46105 X
46106 #ifdef PVM_SRC
46107 X    bufid = pvm_recv(-1,curtype);
46108 X    pvm_bufinfo(bufid,NULL,NULL,&tid);
46109 X    pvm_upkbyte((char *)&bestr[0],sizeof(struct comstr)*(qres_bufsize+1),1);
46110 X    snode = tidtonode(tid);
46111 X    pvm_freebuf(bufid);
46112 #endif
46113 #ifdef MPI_SRC
46114 X    MPI_Recv(bestr,sizeof(struct comstr)*(qres_bufsize+1),
46115 X            MPI_BYTE,MPI_ANY_SOURCE,curtype,MPI_COMM_WORLD,&mpi_status);
46116 X    snode = mpi_status.MPI_SOURCE;
46117 #endif
46118 X
46119 X    nres = bestr[qres_bufsize].seqnm & ~FINISHED;
46120 X
46121 #ifdef DEBUG
46122 X    fprintf(stderr,"%d results from %d\n",nres,snode);
46123 #endif
46124 X
46125 X    if (bestr[qres_bufsize].seqnm&FINISHED) {  /* a worker is finished */
46126 X      naa0++;
46127 X
46128 X      /* fast_flag == 1 => send new sequences immediately */
46129 X      fast_flag = ((m_msp0->stages==1) && !(m_msp0->markx & MX_M9SUMM) &&
46130 X                  (m_msp0->ashow == 0) && (m_msp0->last_calc_flg==0));
46131 X      /* send a new query sequence if no more processing required */
46132 X      if (fast_flag) {
46133 #ifdef PVM_SRC
46134 X       pvm_initsend(PvmDataRaw);
46135 X       pvm_pkbyte((char *)qm_msp1,sizeof(qm_msg1),1);
46136 X       if (qm_msp1->n0 != -1) {
46137 X         pvm_pkbyte((char *)aa0p1,qm_msp1->n0+1+SEQ_PAD,1);
46138 X         if (m_msp1->ann_flg) pvm_pkbyte((char *)m_msp1->aa0a,qm_msp1->n0+1,1);
46139 X       }
46140 X       pvm_send(tid,MSEQTYPE);
46141 #endif
46142 #ifdef MPI_SRC
46143 X       MPI_Send(qm_msp1,sizeof(qm_msg1),MPI_BYTE,snode,MSEQTYPE,MPI_COMM_WORLD);
46144 X       if (qm_msp1->n0 != -1) {
46145 X         MPI_Send(aa0p1,qm_msp1->n0+1+SEQ_PAD,MPI_BYTE,snode,MSEQTYPE1,MPI_COMM_WORLD);
46146 X         if (m_msp1->ann_flg)
46147 X           MPI_Send(m_msp1->aa0a,qm_msp1->n0+1,MPI_BYTE,snode,MSEQTYPE2,MPI_COMM_WORLD);
46148 X       }
46149 #endif
46150 X      }
46151 X    }
46152 X
46153 #ifdef DEBUG
46154 X    if (pst.debug_lib)
46155 X      fprintf(stderr," unpacking %d from %d; nbest %d\n",nres,snode,nbest);
46156 #endif
46157 X
46158 X    /* this section is now more complex because can get groups of
46159 X       sequence results; e.g. forward and reverse frame */
46160 X
46161 X    t_best = t_rbest = t_qrbest = -1;
46162 X    tm_escore = t_rescore = t_qrescore = FLT_MAX;
46163 X    for (ires = 0; ires < nres; ires++) {
46164 X      desptr = &ldes[bestr[ires].m_seqnm];
46165 X
46166 X      /* save raw results */
46167 X      if (fdata) {
46168 X       strncpy(tlibstr,desptr->bline,10);
46169 X       if ((bp=strchr(tlibstr,' '))!=NULL) *bp='\0';
46170 X       fprintf(fdata,"%-10s\t%4d\t%4d\t%d\t%4d\t%4d\t%4d\t%8ld\n",
46171 X               tlibstr,desptr->sfnum[0],desptr->n1,bestr[ires].frame,
46172 X               bestr[ires].score[0],bestr[ires].score[1],bestr[ires].score[2],
46173 X               desptr->lseek);
46174 X      }
46175 X
46176 X      i_score = bestr[ires].score[pst.score_ix];
46177 X      e_score = bestr[ires].escore;
46178 X      k_comp = bestr[ires].comp;
46179 X      k_H = bestr[ires].H;
46180 X
46181 X      t_n1 = desptr->n1;
46182 X      if (i_score > t_best) {tm_best = t_best = i_score;}
46183 X      if (e_score < tm_escore) tm_escore = e_score;
46184 X
46185 X      if (m_msp0->qshuffle) {
46186 X       if (bestr[ires].qr_score > t_qrbest) 
46187 X         t_qrbest = bestr[ires].qr_score;
46188 X       if (bestr[ires].qr_escore < t_qrescore) 
46189 X         t_qrescore = bestr[ires].qr_escore;
46190 X
46191 X       if (bestr[ires].frame==m_msp0->nitt1 && 
46192 X           nqstats < m_msp0->shuff_max &&
46193 X           bestr[ires].qr_score >= 0) {
46194 X         qstats[nqstats].n1 = t_n1;    /* save the best score */
46195 X         qstats[nqstats].comp =  bestr[ires].comp;
46196 X         qstats[nqstats].H = bestr[ires].H;
46197 X         qstats[nqstats].escore = t_qrescore;
46198 X         qstats[nqstats++].score = t_qrbest;
46199 X         t_qrbest = -1;        /* reset t_qrbest, t_qrescore */
46200 X         t_qrescore = FLT_MAX;
46201 X       }
46202 X      }
46203 X
46204 X      if (pst.zsflag >= 10 && bestr[ires].r_score > t_rbest) {
46205 X       t_rbest = bestr[ires].r_score;
46206 X       t_rescore = bestr[ires].r_escore;
46207 X      }
46208 X
46209 X      if (nstats < MAXSTATS) {
46210 X       if (bestr[ires].frame == m_msg0.nitt1) {
46211 X         stats[nstats].n1 = t_n1;
46212 X         stats[nstats].comp = k_comp;
46213 X         stats[nstats].H = k_H;
46214 X
46215 X         if (pst.zsflag > 10) {
46216 X           tm_best = t_rbest;
46217 X           tm_escore = t_rescore;
46218 X           t_rbest = -1;
46219 X           t_rescore = FLT_MAX;
46220 X         }
46221 X         stats[nstats].escore = tm_escore;
46222 X         stats[nstats++].score = tm_best;
46223 X         tm_escore = FLT_MAX;
46224 X         t_best = -1;
46225 X       }
46226 X      }
46227 X      else if (pst.zsflag >=0) {       /* nstats >= MAXSTATS, zsflag >=0 */
46228 X       if (!stats_done ) {
46229 X         pst.n0 = qm_msp0->n0;
46230 X         pst.zsflag_f = process_hist(stats,nstats,*m_msp0,pst,
46231 X                                     &m_msp0->hist, &m_msp0->pstat_void,0);
46232 X         stats_done = 1;
46233 X         kstats = nstats;
46234 X         for (i=0; i<nbest; i++) {
46235 X           bptr[i]->zscore = (*find_zp)(bptr[i]->score[pst.score_ix],
46236 X                                        bptr[i]->escore,bptr[i]->n1,
46237 X                                        bptr[i]->comp, m_msp0->pstat_void);
46238 X         }
46239 X       }
46240 #ifdef SAMP_STATS
46241 X       if (!m_msp0->escore_flg) {
46242 X         jstats = nrand(kstats++);
46243 X         if (jstats < MAXSTATS) {
46244 X           stats[jstats].n1 = t_n1;    /* save the best score */
46245 X           stats[jstats].comp =  k_comp;
46246 X           stats[jstats].H = k_H;
46247 X           if (pst.zsflag >=10) t_best = t_rbest;
46248 X           stats[jstats].score = t_best;
46249 X         }
46250 X       }
46251 #endif
46252 X      }
46253 X
46254 X      if (stats_done) {
46255 X       zscore=(*find_zp)(i_score,e_score,desptr->n1,k_comp,
46256 X                         m_msp0->pstat_void);
46257 X       if (bestr[ires].frame == m_msg0.nitt1) {
46258 X         addhistz((*find_zp)(tm_best,tm_escore,t_n1,k_comp,
46259 X                             m_msp0->pstat_void),
46260 X                  &(m_msp0->hist));
46261 X         t_best = t_rbest = -1;
46262 X       }
46263 X
46264 X      }
46265 X      else zscore = (double) i_score;
46266 X
46267 X      if (zscore > zbestcut) {
46268 X       if (nbest>=MAXBEST) {
46269 X         selectbestz(bptr, nbest-MAXBEST/4-1, nbest); 
46270 X         nbest -= MAXBEST/4;
46271 X         zbestcut = bptr[nbest-1]->zscore;
46272 X         best_flag = 0;
46273 X       }
46274 X       /* if zbestcut == -BIGNUM, bptr[] has not been reinitialized */
46275 X       else if (best_flag) bptr[nbest]=&best[nbest];
46276 X
46277 X       bptr[nbest]->m_seqnm  = bestr[ires].m_seqnm ;
46278 X       bptr[nbest]->seqnm  = bestr[ires].seqnm;
46279 X       bptr[nbest]->score[0] = bestr[ires].score[0];
46280 X       bptr[nbest]->score[1] = bestr[ires].score[1];
46281 X       bptr[nbest]->score[2] = bestr[ires].score[2];
46282 X       bptr[nbest]->escore = bestr[ires].escore;
46283 X       bptr[nbest]->segnum = bestr[ires].segnum;
46284 X       bptr[nbest]->seglen = bestr[ires].seglen;
46285 X       bptr[nbest]->comp = bestr[ires].comp;
46286 X       bptr[nbest]->H = bestr[ires].H;
46287 X       bptr[nbest]->zscore = zscore;
46288 X       bptr[nbest]->wrkr   = snode;
46289 X       bptr[nbest]->desptr = desptr;
46290 X       bptr[nbest]->lseek = desptr->lseek; /* needed for identifying alternate
46291 X                                           strand scores from same sequence */
46292 X       bptr[nbest]->n1 = desptr->n1;
46293 X       bptr[nbest]->frame = bestr[ires].frame;
46294 X
46295 X       /*      this was used when -m 9 info was calculated in 1st scan */
46296 X       /*
46297 X       bptr[nbest]->sw_score = bestr[ires].sw_score;
46298 X       if (bestr[ires].sw_score > -1) {
46299 X         nopt++;
46300 X         bptr[nbest]->a_len = bestr[ires].a_len;
46301 X         bptr[nbest]->percent = bestr[ires].percent;
46302 X         bptr[nbest]->gpercent = bestr[ires].gpercent;
46303 X         bptr[nbest]->min0 = bestr[ires].min0;
46304 X         bptr[nbest]->min1 = bestr[ires].min1;
46305 X         bptr[nbest]->max0 = bestr[ires].max0;
46306 X         bptr[nbest]->max1 = bestr[ires].max1;
46307 X         bptr[nbest]->ngap_q = bestr[ires].ngap_q;
46308 X         bptr[nbest]->ngap_l = bestr[ires].ngap_l;
46309 X       }
46310 X       else {
46311 X         bptr[nbest]->percent = -1.0;
46312 X         bptr[nbest]->min0 = bptr[nbest]->min1 = bptr[nbest]->max0 = 
46313 X           bptr[nbest]->max1 = 0;
46314 X       }
46315 X       */
46316 X
46317 X       nbest++;
46318 X      }
46319 X    }  /* for loop */
46320 X    if (naa0 < nnodes-FIRSTNODE) continue;
46321 X
46322 X    gstring2[0]='\0';
46323 X
46324 X    /* get gstring2,3 - algorithm/parameter description */
46325 #ifdef PVM_SRC
46326 X    bufid = pvm_recv(pinums[FIRSTNODE],PARAMTYPE);
46327 X    pvm_upkbyte(gstring2,sizeof(gstring2),1);
46328 X    pvm_upkbyte(gstring3,sizeof(gstring3),1);
46329 X    pvm_freebuf(bufid);
46330 #endif
46331 #ifdef MPI_SRC
46332 X    MPI_Recv(gstring2,sizeof(gstring2),MPI_BYTE,FIRSTNODE,PARAMTYPE,
46333 X            MPI_COMM_WORLD,&mpi_status);
46334 X    MPI_Recv(gstring3,sizeof(gstring3),MPI_BYTE,FIRSTNODE,PARAMTYPE,
46335 X            MPI_COMM_WORLD,&mpi_status);
46336 #endif
46337 X
46338 /* ********************** */
46339 /* analyze the results    */
46340 /* ********************** */
46341 X    
46342 X    if (!stats_done) {
46343 X      if (nbest < 20 || pst.zsflag <= 0) {
46344 X       pst.zsflag_f = -1;
46345 X      }
46346 X      else {
46347 X       pst.n0 = qm_msp0->n0;
46348 X       pst.zsflag_f = process_hist(stats,nstats,*m_msp0,pst,
46349 X                                   &m_msp0->hist, &m_msp0->pstat_void,stats_done);
46350 X
46351 X       for (i=0; i<nbest; i++)
46352 X         bptr[i]->zscore = (*find_zp)(bptr[i]->score[pst.score_ix],
46353 X                                      bptr[i]->escore, bptr[i]->n1,
46354 X                                      bptr[i]->comp, m_msp0->pstat_void);
46355 X      }
46356 X    }
46357 X
46358 X    m_msp0->db.entries = ntt.entries;
46359 X    m_msp0->db.length = ntt.length;
46360 X    m_msp0->db.carry = ntt.carry;
46361 X
46362 X    if (pst.zdb_size < 1) pst.zdb_size = ntt.entries;
46363 X
46364 X    if (!qm_msp0->qshuffle) {
46365 X      last_stats(aa0p0, m_msp0->n0,
46366 X                stats,nstats, bptr,nbest, *m_msp0, pst, 
46367 X                &m_msp0->hist, &m_msp0->pstat_void);
46368 X    }
46369 X    else {
46370 X      last_stats(aa0p0, m_msp0->n0,
46371 X                qstats,nqstats, bptr,nbest, *m_msp0, pst, 
46372 X                &m_msp0->hist, &m_msp0->pstat_void);
46373 X    }
46374 X
46375 X    if (m_msp0->last_calc_flg) {
46376 X      nbest = last_calc(bptr,nbest, *m_msp0, &pst,qm_msp0,
46377 X                       m_msp0->pstat_void);
46378 X    }
46379 X
46380 X    sortbeste(bptr,nbest);
46381 X    scale_scores(bptr,nbest,m_msp0->db,pst,m_msp0->pstat_void);
46382 X
46383 X    if (pst.zsflag >= 0 && bptr[0]->escore >= m_msg0.e_cut) goto no_results;
46384 X
46385 X    /*      else sortorder(bptr,nbest,wlsn,nnodes); */
46386 X
46387 /* if more than one stage or markx==9, calculate opt scores or do alignment */
46388 /* send results to workers as available */
46389 X
46390 X    if (m_msg0.stages > 1 || m_msg0.markx & MX_M9SUMM) {
46391 X
46392 X      /* to determine how many sequences to re-align (either for
46393 X        do_opt() or calc_id() we need to modify m_msg.mshow to get
46394 X        the correct number of alignments */
46395 X
46396 X      if (m_msg0.mshow_flg != 1 && pst.zsflag >= 0) {
46397 X       for (i=0; i<nbest && bptr[i]->escore< m_msg0.e_cut; i++) {}
46398 X       m_msg0.mshow = i;
46399 X      }
46400 X
46401 X      /* allocate space for a_struct info */
46402 X      if (m_msg0.markx & MX_M9SUMM && m_msg0.mshow > 0) {
46403 X       if ((aln_d_base=(struct a_struct *)
46404 X            calloc((size_t)m_msg0.mshow,sizeof(struct a_struct)))==NULL) {
46405 X         fprintf(stderr," cannot allocate a_struct %d\n", m_msg0.mshow);
46406 X         exit(1);
46407 X       }
46408 X
46409 X       for (is = 0; is < m_msg0.mshow; is++ ) {
46410 X         bptr[is]->aln_d = &aln_d_base[is];
46411 X       }
46412 X      }
46413 X
46414 X      do_stage2(bptr,m_msg0.mshow, *m_msp0, DO_OPT_FLG, qm_msp0);
46415 X    }
46416 X
46417 X  no_results:
46418 X    tdone = s_time();
46419 X    tddone = time(NULL);
46420 X
46421 X    /* changed from >> to >>> because qm_msp0->libstr is missing '>' */
46422 X    fprintf (outfd, "%3d>>>%s\n", qlib,qm_msp0->libstr);
46423 X
46424 X    /* make certain that m_msp0->n0, libstr are current */
46425 X    m_msp0->n0 = qm_msp0->n0;
46426 X    /*    strncpy(m_msp0->libstr,qm_msp0->libstr,sizeof(m_msg0.libstr)); */
46427 X
46428 X    prhist (outfd,*m_msp0,pst,m_msp0->hist,nstats,m_msp0->db,gstring2);
46429 X
46430 X    if (bptr[0]->escore < m_msg0.e_cut) {
46431 X
46432 X      showbest (outfd, bptr, nbest, qlib, m_msp0,pst,ntt,gstring2);
46433 X
46434 X      if (m_msg0.markx & MX_M9SUMM) {
46435 X       fprintf(outfd,"\n>>>%s#%d %s%s, %d %s vs %s library\n",
46436 X               m_msg0.tname,qlib,qm_msp0->libstr,
46437 X               (m_msg0.revcomp ? "-":"\0"), qm_msp0->n0, m_msg0.sqnam,
46438 X               m_msg0.lname);
46439 X      }
46440 X      else if (m_msg0.markx & MX_M10FORM) {
46441 X       if ((bp=strchr(qm_msp0->libstr,' '))!=NULL) *bp = '\0';
46442 X       fprintf(outfd,"\n>>>%s#%d %s%s, %d %s vs %s library\n",
46443 X               m_msg0.tname,qlib,qm_msp0->libstr,
46444 X               (m_msg0.revcomp ? "-":"\0"), qm_msp0->n0, m_msg0.sqnam,
46445 X               m_msg0.lname);
46446 X       if (bp!=NULL) *bp=' ';
46447 X       fprintf(outfd,"; mp_name: %s\n",argv[0]);
46448 X       fprintf(outfd,"; mp_ver: %s\n",mp_verstr);
46449 X       fprintf(outfd,"; mp_argv:");
46450 X       for (i=0; i<argc; i++)
46451 X         fprintf(outfd," %s",argv[i]);
46452 X       fputc('\n',outfd);
46453 X       fputs(gstring3,outfd);
46454 X       fputs(hstring1,outfd);
46455 X      }
46456 X
46457 X      /* ashow is -1 if not set, -d 0 indicates no alignments, > 0 if set */
46458 X      /* if ashow is -1, m_msg.nshow (set by e_cut above) sets limit
46459 X        in showalign */
46460 X      
46461 X      if (m_msp0->ashow != 0) {
46462 X       /* showalign needs m_msp->qtitle, so fill it in */
46463 X       strncpy(m_msp0->qtitle,qm_msp0->libstr,MAX_FN-1);
46464 X       m_msp0->qtitle[MAX_FN-1]='\0';
46465 X       showalign (outfd, bptr, nbest, qlib, *m_msp0, pst, gstring2);
46466 X      }
46467 X    }
46468 X    else {
46469 X      if (m_msg0.markx & (MX_M9SUMM + MX_M10FORM)) {
46470 X       fprintf(outfd,"\n>>>%s#%d %s%s, %d %s vs %s library\n",
46471 X               m_msg0.tname,qlib,qm_msp0->libstr,(m_msg0.revcomp ? "-":"\0"), qm_msg0.n0, m_msg0.sqnam,
46472 X               m_msg0.lname);
46473 X       fprintf(outfd,">>>!!! No sequences with E() < %f\n",m_msg0.e_cut);
46474 X      }
46475 X      else fprintf(outfd,"!! No sequences with E() < %f\n",m_msg0.e_cut);
46476 X    }
46477 X
46478 X    if (! (m_msg0.markx & (MX_M9SUMM + MX_M10FORM))) {
46479 X      fprintf(outfd,"/** search time: ");
46480 X      ptime(outfd,tdone-tprev);
46481 X      fprintf(outfd," **/\n");
46482 X      tprev = tdone;
46483 X    }
46484 X    else if (m_msg0.markx & MX_M9SUMM) {
46485 X      if (aln_d_base != NULL) {
46486 X       free((void *)aln_d_base);
46487 X       aln_d_base = NULL;
46488 X      }
46489 X      fprintf(outfd,">>>***\n");
46490 X      fprintf(outfd,"/** %s **/\n",gstring2);
46491 X      fprintf(outfd,"/** %s **/\n",m_msp0->hist.stat_info);
46492 X      fprintf(outfd,">>><<<\n");
46493 X    }
46494 X    else if (m_msg0.markx & MX_M10FORM) {
46495 X      fprintf(outfd,">>><<<\n");
46496 X    }
46497 X    fflush(outfd);
46498 X    
46499 /* *********************** */
46500 /* end of analysis/display */
46501 /* *********************** */
46502 X
46503 X
46504 /* *********************** */
46505 /* start the next search   */                                           
46506 /* *********************** */
46507 X
46508 X    if (fdata) {               /* label the results file */
46509 X      fprintf(fdata,"/** %s **/\n",gstring2);
46510 X      fprintf(fdata,"%3d>%-50s\n",qlib-1,qm_msp1->libstr);
46511 X      fflush(fdata);
46512 X    }
46513 X    
46514 X    if (m_msp1->escore_flg) {  /* re-initialize some stats stuff before search */
46515 X      pst.zsflag_f = process_hist(stats,nstats,*m_msp1,pst,
46516 X                                 &m_msp1->hist,&m_msp1->pstat_void,0);
46517 X      stats_done=1;
46518 X    }
46519 X    else stats_done = 0;
46520 X
46521 X    /* set up qstats if necessary - different queries have different qshuffle */
46522 X    if (m_msp1->qshuffle && qstats==NULL) {
46523 X      if ((qstats =
46524 X          (struct stat_str *)calloc(m_msg0.shuff_max+1,sizeof(struct stat_str)))==NULL)
46525 X       s_abort ("Cannot allocate qstats struct","");
46526 X    }
46527 X
46528 X    nqstats = nstats = 0;
46529 X
46530 X    /* send new qm_msp, sequence */
46531 X    if (!fast_flag) {
46532 #ifdef PVM_SRC
46533 X      pvm_initsend(PvmDataRaw);
46534 X      pvm_pkbyte((char *)qm_msp1,sizeof(qm_msg1),1);
46535 X      if (qm_msp1->n0 != -1) {
46536 X       pvm_pkbyte((char *)aa0p1,qm_msp1->n0+1+SEQ_PAD,1);
46537 X       if (m_msp1->ann_flg) {
46538 X         pvm_pkbyte((char *)m_msp1->aa0a,qm_msp1->n0+1,1);
46539 X       }         
46540 X      }
46541 X      for (node = FIRSTNODE; node < nnodes; node++)
46542 X       pvm_send(pinums[node],MSEQTYPE);
46543 #endif
46544 #ifdef MPI_SRC
46545 X      for (node=FIRSTNODE; node < nnodes; node++) {
46546 X       MPI_Send(qm_msp1,sizeof(qm_msg1),MPI_BYTE,node,MSEQTYPE,
46547 X                MPI_COMM_WORLD);
46548 X       if (qm_msp1->n0 != -1) {
46549 X         MPI_Send(aa0p1,qm_msp1->n0+1+SEQ_PAD,MPI_BYTE,node,MSEQTYPE1,MPI_COMM_WORLD);
46550 X         if (m_msp1->ann_flg)
46551 X           MPI_Send(m_msp1->aa0a,qm_msp1->n0+1,MPI_BYTE,snode,MSEQTYPE2,MPI_COMM_WORLD);
46552 X       }
46553 X      }
46554 #endif
46555 X    }
46556 X
46557 X    qlib++;
46558 X    if (qm_msp1->n0 != -1) {
46559 X      qtt.entries++;
46560 X      qtt.length += qm_msp1->n0;
46561 X    }
46562 X    else goto done;
46563 X    
46564 /* ******************************** */
46565 /* flip m_msg, qm_msg, aa0 pointers */
46566 /* ******************************** */
46567 X
46568 X    naa0 = 0;
46569 X    best_flag = 1;
46570 X    nbest = nopt = 0;
46571 X    zbestcut = -BIGNUM;
46572 X    if (curtype == ONETYPE) {
46573 X      curtype = TWOTYPE;
46574 X      qm_msp0 = &qm_msg1;
46575 X      qm_msp1 = &qm_msg0;
46576 X      m_msp0 = &m_msg1;
46577 X      m_msp1 = &m_msg0;
46578 X      aa0p0 = aa01;
46579 X      aa0p1 = aa00;
46580 X    }
46581 X    else  {
46582 X      curtype = ONETYPE;
46583 X      qm_msp0 = &qm_msg0;
46584 X      qm_msp1 = &qm_msg1;
46585 X      m_msp0 = &m_msg0;
46586 X      m_msp1 = &m_msg1;
46587 X      aa0p0 = aa00;
46588 X      aa0p1 = aa01;
46589 X    }
46590 X
46591 X
46592 /* **********************************************************/
46593 /* all library sequences are done get next library sequence */
46594 /* **********************************************************/
46595 X
46596 X    m_msp1->n0 = qm_msp1->n0 = 
46597 X      QGETLIB(aa0p1,MAXTST,q_bline, sizeof(q_bline),&qseek, &qlcont,q_file_p,&m_msp1->sq0off);
46598 X    strncpy(qm_msp1->libstr,q_bline,sizeof(qm_msg0.libstr)-20);
46599 X    qm_msp1->libstr[sizeof(qm_msg0.libstr)-21]='\0';
46600 X
46601 X    if ((qlib+1) >= m_msg0.ql_stop) { qm_msp1->n0 = m_msp1->n0 = -1;}
46602 X
46603 X    if (qm_msp1->n0 > 0 && m_msg0.term_code && !qlcont &&
46604 X       m_msg0.qdnaseq==SEQT_PROT &&
46605 X       aa0p1[m_msp1->n0-1]!=m_msg0.term_code) {
46606 X      aa0p1[m_msp1->n0++]=m_msg0.term_code;
46607 X      aa0p1[m_msp1->n0]=0;
46608 X      qm_msp1->n0 = m_msp1->n0;
46609 X    }
46610 X
46611 X    /* for ALTIVEC, must pad with 15 NULL's */
46612 X    if (m_msg0.n0 > 0) {
46613 X       for (i=0; i<SEQ_PAD+1; i++) {aa00[m_msg0.n0+i]=0;}
46614 X    }
46615 X
46616 X    qm_msp1->slist = 0;
46617 X    /*
46618 X    leng = strlen (qm_msp1->libstr);
46619 X    sprintf (&(qm_msp1->libstr[leng]), " %d %s", qm_msp1->n0, q_sqnam);
46620 X    */
46621 X    sprintf(tmp_str," %d %s", qm_msp1->n0, q_sqnam);
46622 X    if (strlen(qm_msp1->libstr) + strlen(tmp_str) >= sizeof(qm_msg0.libstr))
46623 X      qm_msp1->libstr[sizeof(qm_msg0.libstr)-strlen(tmp_str)-2] = '\0';
46624 X    strncat(qm_msp1->libstr,tmp_str,
46625 X           sizeof(qm_msg0.libstr)-strlen(qm_msp1->libstr)-1);
46626 X    qm_msp1->libstr[sizeof(qm_msg0.libstr)-1]='\0';
46627 X
46628 X    qm_msp1->seqnm = qlib;
46629 X
46630 X    last_params(aa0p1,m_msp1->n0,m_msp1,&pst,qm_msp1);
46631 X
46632 X  }        /* while loop */
46633 X  
46634 X  /* ******************** */
46635 X  /* end of library while */
46636 X  /* ******************** */
46637 X
46638 X done:
46639 X  tdone = s_time();
46640 X  if (m_msg0.markx & (MX_M9SUMM + MX_M10FORM)) fputs(">>>///\n",outfd);
46641 X  printsum(outfd);
46642 X  if (outfd!=stdout) printsum(stdout);
46643 X  printsum(stderr);
46644 #ifdef PVM_SRC
46645 X  pvm_exit();
46646 #endif
46647 #ifdef MPI_SRC
46648 X  MPI_Finalize();
46649 #endif
46650 X
46651 X  exit(0);
46652 }   /* End of main program */
46653 X
46654 void
46655 printsum(FILE *fd)
46656 {
46657 X  double db_tt;
46658 X  char tstr1[26], tstr2[26];
46659 X
46660 X  strncpy(tstr1,ctime(&tdstart),sizeof(tstr1));
46661 X  strncpy(tstr2,ctime(&tddone),sizeof(tstr1));
46662 X  tstr1[24]=tstr2[24]='\0';
46663 X
46664 X  /* Print timing to output file as well */
46665 X  if (qtt.carry==0) {
46666 X    fprintf(fd, "\n%ld residues in %d query   sequences\n", qtt.length, qtt.entries);
46667 X  }
46668 X  else {
46669 X    db_tt = (double)qtt.carry*(double)LONG_MAX + (double)qtt.length;
46670 X    fprintf(fd, "\n%.0g residues in %d query   sequences\n", db_tt, qtt.entries);
46671 X  }
46672 X
46673 X  if (ntt.carry==0) {
46674 X    fprintf(fd, "%ld residues in %ld library sequences\n", ntt.length, ntt.entries);
46675 X  }
46676 X  else {
46677 X    db_tt = (double)ntt.carry*(double)LONG_MAX + (double)ntt.length;
46678 X    fprintf(fd, "%.6f residues in %ld library sequences\n", db_tt, ntt.entries);
46679 X  }
46680 X
46681 X  fprintf(fd," %d processors (%d workers) were used\n",
46682 X         nnodes+-FIRSTNODE+1,nnodes-FIRSTNODE);
46683 X  fprintf(fd," Pvcomplib [%s]\n start: %s done: %s\n",mp_verstr,tstr1,tstr2);
46684 X  fprintf(fd," Loading time: ");
46685 X  ptime(fd, tscan - tstart);
46686 X  fprintf (fd," Scan time: ");
46687 X  ptime (fd, tdone - tscan);
46688 X  fprintf (fd,"\n");
46689 X  fprintf (fd, "\nFunction used was %s [%s]\n", prog_func,verstr);
46690 }
46691 X
46692 void fsigint()
46693 {
46694 X  int i;
46695 X
46696 X  tdone = s_time();
46697 X  tddone = time(NULL);
46698 X
46699 X  if (outfd!=stdout) fprintf(outfd,"/*** interrupted ***/\n");
46700 X  fprintf(stderr,"/*** interrupted ***/\n");
46701 X
46702 X  printsum(stdout);
46703 X  if (outfd!=stdout) printsum(outfd);
46704 X
46705 #ifdef PVM_SRC
46706 X  for (i=FIRSTNODE; i<nnodes; i++) pvm_kill(pinums[i]);
46707 X  pvm_exit();
46708 #endif
46709 #ifdef MPI_SRC
46710 X  MPI_Abort(MPI_COMM_WORLD,1);
46711 X  MPI_Finalize();
46712 #endif
46713 X  exit(1);
46714 }
46715 SHAR_EOF
46716 chmod 0644 p2_complib.c ||
46717 echo 'restore of p2_complib.c failed'
46718 Wc_c="`wc -c < 'p2_complib.c'`"
46719 test 55578 -eq "$Wc_c" ||
46720         echo 'p2_complib.c: original size 55578, current size' "$Wc_c"
46721 fi
46722 # ============= p2_workcomp.c ==============
46723 if test -f 'p2_workcomp.c' -a X"$1" != X"-c"; then
46724         echo 'x - skipping p2_workcomp.c (File already exists)'
46725 else
46726 echo 'x - extracting p2_workcomp.c (Text)'
46727 sed 's/^X//' << 'SHAR_EOF' > 'p2_workcomp.c' &&
46728 X
46729 /* copyright (c) 1996, 1997, 1998, 1999 William R. Pearson and the
46730 X   U. of Virginia */
46731 X
46732 /* $Name: fa_34_26_5 $ - $Id: p2_workcomp.c,v 1.49 2007/01/02 17:24:36 wrp Exp $ */
46733 X
46734 /* This version is modifed to read all files, query and database,
46735 X   through the manager process. Workers will now receive their
46736 X   database from the manager, rather than reading it themselves.  This
46737 X   cuts down considerably on NFS traffic, simplifies searches of
46738 X   multiple files, and allows use of clusters of slave nodes that do
46739 X   not have NFS access */
46740 X
46741 /* September, 1994 - this version has been modified to do two kinds of
46742 X   searches, a general library search, or list of library sequences search.
46743 X   The latter would be used to generate optimized scores for fasta and
46744 X   to produce alignments */
46745 X
46746 /* modified July, 2002, to provide query shuffle */
46747 X
46748 /* modified October, 2005, to support struct a_res_str a_res -
46749 X   coordinates of alignment in aa0[], aa1[].  Future modifications
46750 X   will cause do_walign to be run only once - subsequent calls for
46751 X   seqc[0,1] can be filled using a_res, by adding a_res to the
46752 X   struct sqs2 array.
46753 X
46754 X   19-March-2006 - modifications to call do_walign() only once, and
46755 X   use the resulting a_res structure for subsequent calls to calc_id,
46756 X   calcons, calcons_a, have been implemented.  Also, the -V option is
46757 X   now valid with the parallel programs.
46758 X
46759 X   31-May-2006 - some functions (e.g. dropfs and dropff do not store
46760 X   complete information in a_res - thus they cannot use this shortcut
46761 X   (yet).
46762 X
46763 */
46764 X
46765 X
46766 X
46767 #include <stdio.h>
46768 #include <stdlib.h>
46769 #include <string.h>
46770 X
46771 #ifdef PVM_SRC
46772 #include "pvm3.h"
46773 #endif
46774 X
46775 #ifdef MPI_SRC
46776 #include "mpi.h"
46777 #endif
46778 X
46779 /*
46780 #define PvmDataDefault 0
46781 #define PvmTaskDefault 0
46782 */
46783 #include "msg.h"
46784 #include "defs.h"
46785 #include "param.h"
46786 #include "w_mw.h"
46787 #include "structs.h"
46788 X
46789 #ifdef MPI_SRC
46790 #define XTERNAL
46791 #endif
46792 #include "upam.h"
46793 #include "uascii.h"
46794 X
46795 #ifdef PVM_SRC
46796 int worker, mytid;
46797 int nnodes, pinums[MAXNOD];
46798 #endif
46799 X
46800 #include "drop_func.h"
46801 X
46802 extern void alloc_pam (int d1, int d2, struct pstruct *ppst); /* allocate ppst->pam12,pam12x */
46803 extern int **alloc_pam2p (int len, int nsq); 
46804 extern void w_init ();
46805 extern void irand(int);
46806 extern void revcomp(unsigned char *, int, int *);
46807 X
46808 X
46809 X
46810 extern void initseq(char **seqc0, char **seqc0a, char **seqc1, char **seqca, int seqsiz);
46811 extern void freeseq(char **seqc0, char **seqc0a, char **seqc1, char **seqca);
46812 X
46813 void send_bestr(int, int, struct comstr *, int, int);
46814 void send_bestr2(int, struct comstr2 *, int);
46815 void send_code(int, char *, int);
46816 X
46817 extern void get_param (struct pstruct *ppst, char *pstring2, char *pstring3);
46818 extern void update_param(struct qmng_str *qm_msg, struct mngmsg *m_msg,
46819 X                        struct pstruct *ppst);
46820 extern int shuffle(unsigned char *, unsigned char *, int);
46821 extern int wshuffle(unsigned char *, unsigned char *, int, int, int *);
46822 X
46823 extern char err_str[];
46824 X
46825 /* local function declarations */
46826 void free_ares(struct sqs2 *, int itt, int *, int walign_cnt, int worker);
46827 X
46828 X
46829 X
46830 void w_abort (p, p1)
46831 char *p, *p1;
46832 {
46833 X    fprintf (stderr, " %s %s\n", p, p1);
46834 #ifdef PVM_SRC
46835 X    pvm_exit();
46836 X    exit (1);
46837 #endif
46838 #ifdef MPI_SRC
46839 X  MPI_Abort(MPI_COMM_WORLD,1);
46840 #endif
46841 }
46842 X
46843 #ifdef PVM_SRC
46844 main ()
46845 #endif
46846 #ifdef MPI_SRC
46847 void
46848 workcomp(int worker)
46849 #endif
46850 {
46851 X  unsigned char *aa0[6], *aa1s, *aa0s; /* Query and library sequences */
46852 X  struct mngmsg m_msg; /* start message from manager to worker 1 */
46853 X  struct qmng_str qm_msg; /* updated for each query */
46854 X  int last_msg_b[10];  /* last set of numbers */
46855 X  struct sqs2 *seqpt;          /* sequence pointers for chunk */
46856 X  int seqbuf_n,seqbuf_s;       /* number of sequences, length of sequences */
46857 X  int max_sql;                 /* maximum number of sequences/node */
46858 X  int *n1_arr;                 /* array of sequence lengths in buffer */
46859 X  int *m_seqnm_arr;            /* array of sequence numbers in buffer */
46860 X  int *aa1i_arr;               /* array of offsets into the buffer */
46861 X  unsigned char *seq_buf;      /* space for sequence data */
46862 X  int ntx;
46863 X  int nsq;                     /* effective alphabet size */
46864 X  long curtype = ONETYPE;      /* current send message type */
46865 X  int ieven=0;                 /* flag for window shuffle */
46866 X  int cur_n0;
46867 X  int n1, n1over;              /* length of query, library sequences */
46868 X  struct comstr bestr[BFR+1];  /* best structures */
46869 X  struct comstr2 bestr2[BFR2+1];       /* best structures */
46870 X  struct a_struct aln, *aln_dp;
46871 X  int qres_bufsize;            /* results buffer size */
46872 X  int bestcnt = 0;             /* how many best structures are full */
46873 X  char gstring2[MAX_STR];              /* parameter string for manager */
46874 X  char gstring3[MAX_STR];              /* parameter string for manager */
46875 X  struct pstruct pst;          /* parameter structure */
46876 X  struct rstruct rst, qrst, rrst;      /* results structure */
46877 X  void *f_str[6], *qf_str;
46878 X  int sw_score;
46879 X  int lcnt, count, seqnm;      /* counters */
46880 X  int *walign_done[2], walign_cnt[2];  /* index of current valid a_res in seqpt */
46881 X  int have_walign;
46882 X  int *tres;                   /* allocated storage for seqpt[].a_res[].res */
46883 X  int lend;                    /*global library sequence number information */
46884 X  int lsn;                     /* library sequence number */
46885 X  struct stage2_str *liblist=NULL;     /* list of sequences to search */
46886 X  int i, j;            /* my turn to send sequence descriptions */
46887 X  char libstr[21];
46888 X  char errstr[128];
46889 X  int itt=0;
46890 X  int bufid;
46891 X  char *seqc0, *seqc0a, *seqc1, *seqca;
46892 X  char *seqc, *seqc_buff;
46893 X  int seqc_buff_cnt, seqc_buff_len, seqc_flag;
46894 X  int maxc, lc, nc, nident, ngap, aln_code_n;
46895 X  float percent, gpercent;
46896 X  int old_shuffle=0;   /* did a qshuffle last time */
46897 X  int hosttid=0;
46898 X  char worker_str[5];
46899 X
46900 #ifdef MPI_SRC
46901 X  MPI_Status mpi_status;
46902 #endif
46903 X  
46904 #ifdef PVM_SRC
46905 X  mytid = pvm_mytid();
46906 X  hosttid = pvm_parent();
46907 #endif
46908 X
46909 X  w_init();    /* sets up default sascii, hsq, sq */
46910 X
46911 X  /* Allocate space for the query sequence */
46912 X  if ((aa0[0] = (unsigned char *) malloc ((MAXTST+2+SEQ_PAD)*sizeof (char))) == NULL) {
46913 X    w_abort ("Unable to allocate sequence array[0] - exiting!","");
46914 X  }
46915 X  *aa0[0]='\0';
46916 X  aa0[0]++;
46917 X
46918 X  /* initial messages set up various parameter structures:
46919 X
46920 X     STARTTYPE0: &nnodes
46921 X                pinums
46922 X                &m_msg
46923 X
46924 X     STARTTYPE1  &pst
46925 X
46926 X     STARTTYPE2         pam12
46927 X     STARTTYPE3         pam12x
46928 X  */
46929 X
46930 #ifdef PVM_SRC
46931 #ifdef ROUTE_DIRECT
46932 X  pvm_setopt(PvmRoute,PvmRouteDirect);
46933 #endif
46934 X  /* get number of nodes, pinums */
46935 X  bufid = pvm_recv(hosttid,STARTTYPE0);
46936 X  pvm_upkint(&nnodes,1,1);
46937 X  pvm_upkint(pinums,nnodes,1);
46938 X  pvm_upkbyte((char *)&m_msg,(int)sizeof(m_msg),1);
46939 X  worker = tidtonode(mytid);
46940 X  pvm_freebuf(bufid);
46941 #endif
46942 X
46943 X  sprintf(worker_str,"@%d",worker);
46944 X
46945 #ifdef MPI_SRC
46946 X  MPI_Recv(&m_msg,sizeof(m_msg),MPI_BYTE,hosttid,STARTTYPE0,MPI_COMM_WORLD,
46947 X          &mpi_status);
46948 #endif
46949 X
46950 X  /* the aln structure needs some information from m_msg0.aln */
46951 X  memcpy(&aln,&m_msg.aln,sizeof(struct a_struct));
46952 X
46953 X  /*
46954 X  fprintf(stderr,"d1: %d d2: %d\n",m_msg.pamd1,m_msg.pamd2);
46955 X  */
46956 X
46957 X  /* get pst params */
46958 #ifdef PVM_SRC
46959 X  bufid = pvm_recv(hosttid,STARTTYPE1);
46960 X  pvm_upkbyte((char *)&pst,(int)sizeof(pst),1);
46961 X  /* 31t nsq = pst.nsq; */
46962 X  pvm_upkbyte((char *)pascii,(int)sizeof(aascii),1);
46963 X  pvm_freebuf(bufid);
46964 #endif
46965 #ifdef MPI_SRC
46966 X  MPI_Recv(&pst,(int)sizeof(pst),MPI_BYTE,hosttid,STARTTYPE1,MPI_COMM_WORLD,
46967 X          &mpi_status);
46968 X
46969 X  MPI_Recv(pascii,(int)sizeof(aascii)/sizeof(int),MPI_INT,hosttid,STARTTYPE1,MPI_COMM_WORLD,
46970 X          &mpi_status);
46971 #endif
46972 X
46973 X  if (pst.ext_sq_set) { nsq = pst.nsqx;}
46974 X  else { nsq = pst.nsq;}
46975 X
46976 X  aa0[5] = aa0[4] = aa0[3] = aa0[2] = aa0[1] = aa0[0];
46977 X  if (m_msg.qframe == 2) {
46978 X    if ((aa0[1]=(unsigned char *)malloc((MAXTST+2)*sizeof (char)))==NULL)
46979 X      w_abort ("Unable to allocate sequence[1] array - exiting!","");
46980 X    *aa0[1]='\0';
46981 X    aa0[1]++;
46982 X  }
46983 X
46984 X  if ((aa1s=(unsigned char *)malloc((m_msg.max_tot+1)*sizeof (char)))==NULL)
46985 X      w_abort ("Unable to allocate shuffled library sequence", "");
46986 X  *aa1s=0;
46987 X  aa1s++;
46988 X
46989 X  irand(0);    /* necessary for shuffled sequences */
46990 X
46991 X  /* this function allocates pam12, pam12x
46992 X     assigns pst.pam[0][0]=pam12, pst.pam[1][0] = pam12x
46993 X     and sets up the correct pst.pam[0][0][0] pointers */
46994 X
46995 X  alloc_pam(m_msg.pamd1,m_msg.pamd2,&pst);
46996 X
46997 #ifdef PVM_SRC
46998 X  bufid = pvm_recv(hosttid,STARTTYPE2);
46999 X  pvm_upkint(pam12,m_msg.pamd1*m_msg.pamd2,1);
47000 X  pvm_freebuf(bufid);
47001 X
47002 X  bufid = pvm_recv(hosttid,STARTTYPE3);
47003 X  pvm_upkint(pam12x,m_msg.pamd1*m_msg.pamd2,1);
47004 X  pvm_freebuf(bufid);
47005 #endif  
47006 X
47007 #ifdef DEBUG
47008 X  if (worker==FIRSTNODE) {
47009 X    fprintf(stderr,"ext?: %d\tnsq: %d\tnsqx: %d\n",pst.ext_sq_set,pst.nsq, pst.nsqx);
47010 X    for (i=1; i<5; i++) {
47011 X      for (j=1; j <= i; j++) fprintf(stderr," %c,%c:%2d",pst.sq[i],pst.sq[j],pst.pam2[0][i][j]);
47012 X      fprintf(stderr,"\n");
47013 X    }
47014 X    for (i=pst.nsq+1; i<pst.nsq+5; i++) {
47015 X      for (j=pst.nsq+1; j <= i; j++) fprintf(stderr," %c,%c:%2d",pst.sqx[i],pst.sqx[j],pst.pam2[0][i][j]);
47016 X      fprintf(stderr,"\n");
47017 X    }
47018 X
47019 X    for (i=1; i<5; i++) {
47020 X      for (j=1; j <= i; j++) fprintf(stderr," %c,%c:%2d",pst.sqx[i],pst.sqx[j],pst.pam2[1][i][j]);
47021 X      fprintf(stderr,"\n");
47022 X    }
47023 X    for (i=pst.nsq+1; i<pst.nsq+5; i++) {
47024 X      for (j=pst.nsq+1; j <= i; j++) fprintf(stderr," %c,%c:%2d",pst.sqx[i],pst.sqx[j],pst.pam2[1][i][j]);
47025 X      fprintf(stderr,"\n");
47026 X    }
47027 X  }
47028 #endif
47029 X
47030 #ifdef MPI_SRC
47031 X  MPI_Recv(pam12,m_msg.pamd1*m_msg.pamd2,MPI_INT,hosttid,STARTTYPE2,
47032 X          MPI_COMM_WORLD,&mpi_status);
47033 X
47034 X  MPI_Recv(pam12x,m_msg.pamd1*m_msg.pamd2,MPI_INT,hosttid,STARTTYPE3,
47035 X          MPI_COMM_WORLD,&mpi_status);
47036 #endif
47037 X
47038 /*
47039 X  We have the PAM matrices - get the library sequences
47040 */
47041 X
47042 X  /* Allocate space for the sequences */
47043 X  max_sql = MAXSQL/2;
47044 X
47045 X  if ((seqpt=(struct sqs2 *)calloc(max_sql,sizeof(struct sqs2)))==NULL)
47046 X    w_abort("cannot allocate seqpt(sqs2)","");
47047 X
47048 X  if ((n1_arr=(int *)calloc(m_msg.pbuf_siz+1,sizeof(int)))==NULL)
47049 X    w_abort("cannot allocate n1_arr","");
47050 X
47051 X  if ((aa1i_arr=(int *)calloc(m_msg.pbuf_siz+1,sizeof(int)))==NULL)
47052 X    w_abort("cannot allocate n1_arr","");
47053 X
47054 X  if ((m_seqnm_arr=(int *)calloc(m_msg.pbuf_siz+1,sizeof(int)))==NULL)
47055 X    w_abort("cannot allocate m_seqnm_arr","");
47056 X
47057 /*****************************************************************/
47058 /* This section gets all the database sequences from the manager */
47059 /*****************************************************************/
47060 X
47061 X  lcnt = 0;
47062 X  while (1) {
47063 #ifdef PVM_SRC
47064 X    /* get the number of sequences, sequence lengths */
47065 X    bufid = pvm_recv(hosttid,STARTTYPE4);
47066 X    pvm_upkint(&seqbuf_n,1,1); /* number of sequences */
47067 X    pvm_upkint(&seqbuf_s,1,1); /* size of sequence buffer */
47068 X    pvm_upkint(n1_arr,seqbuf_n,1);     /* length of each sequence in buffer */
47069 X    pvm_upkint(aa1i_arr,seqbuf_n,1);    /* indexes for each sequence */
47070 X    pvm_upkint(m_seqnm_arr,seqbuf_n,1);        /* number of each library sequence */
47071 X    pvm_freebuf(bufid);
47072 #endif
47073 #ifdef MPI_SRC
47074 X    MPI_Recv(&seqbuf_n,1,MPI_INT,hosttid,STARTTYPE4,MPI_COMM_WORLD,
47075 X            &mpi_status);
47076 X    MPI_Recv(&seqbuf_s,1,MPI_INT,hosttid,STARTTYPE4,MPI_COMM_WORLD,
47077 X            &mpi_status);
47078 X    MPI_Recv(n1_arr,seqbuf_n,MPI_INT,hosttid,STARTTYPE4,MPI_COMM_WORLD,
47079 X            &mpi_status);
47080 X    MPI_Recv(aa1i_arr,seqbuf_n,MPI_INT,hosttid,STARTTYPE4,MPI_COMM_WORLD,
47081 X            &mpi_status);
47082 X    MPI_Recv(m_seqnm_arr,seqbuf_n,MPI_INT,hosttid,STARTTYPE4,MPI_COMM_WORLD,
47083 X            &mpi_status);
47084 #endif
47085 X
47086 X    if (seqbuf_n <= 0) break;
47087 #ifdef DEBUG    
47088 X    /*
47089 X    fprintf(stderr,"[%d] seqbuf_n: %d seqbuf_s: %d\n",
47090 X           worker,seqbuf_n,seqbuf_s);
47091 X    fprintf(stderr,"[%d] lcnt: %d n1: %d seqnm %d\n",
47092 X           worker,0,n1_arr[0],m_seqnm_arr[0]);
47093 X    fprintf(stderr,"[%d] lcnt: %d n1: %d seqnm %d\n",
47094 X           worker,1,n1_arr[1],m_seqnm_arr[1]);
47095 X    */
47096 #endif
47097 X
47098 X    /* allocate space for sequences */
47099 X    if ((seq_buf = (unsigned char *)calloc((size_t)seqbuf_s+1,sizeof(char)))
47100 X       ==NULL) {
47101 X      w_abort("cannot allocate tmp_seq","");
47102 X    }
47103 X    seq_buf++; /* leave a '\0' at the start */
47104 X
47105 X    /* get the sequence buffer */
47106 #ifdef PVM_SRC
47107 X    bufid = pvm_recv(hosttid,STARTTYPE5);
47108 X    pvm_upkbyte((char *)seq_buf,seqbuf_s,1);
47109 X    pvm_freebuf(bufid);
47110 #endif  
47111 #ifdef MPI_SRC
47112 X    MPI_Recv(seq_buf,seqbuf_s,MPI_BYTE,hosttid,STARTTYPE5,MPI_COMM_WORLD,
47113 X            &mpi_status);
47114 #endif
47115 X
47116 X    /* now we have everything  - update the pointers */
47117 X    if (lcnt+seqbuf_n >= max_sql) {
47118 X      max_sql += max(MAXSQL/2,seqbuf_n);
47119 X      if ((seqpt=(struct sqs2 *)realloc(seqpt,max_sql*sizeof(struct sqs2)))
47120 X         ==NULL)
47121 X       w_abort("cannot allocate seqpt(sqs2)","");
47122 X    }
47123 X
47124 X    /* convert from offsets to pointers into buffer */
47125 X    /* ntx = 0; */
47126 X    for (i=0; i<seqbuf_n; i++,lcnt++) {
47127 X      seqpt[lcnt].n1 = n1_arr[i];
47128 X      seqpt[lcnt].m_seqnm = m_seqnm_arr[i];
47129 X      seqpt[lcnt].aa1 = &seq_buf[aa1i_arr[i]];
47130 X      /*      ntx += n1_arr[i]+1 + SEQ_PAD */
47131 X
47132 #ifdef DEBUG
47133 X      /* must have null's at both ends of sequence */
47134 X      if (seqpt[lcnt].aa1[-1]!= '\0') {
47135 X       fprintf(stderr,"Missing null at start: %d %d\n",
47136 X               lcnt,seqpt[lcnt].aa1[-1]);
47137 X       seqpt[lcnt].aa1[-1]='\0';
47138 X      }
47139 X      if (seqpt[lcnt].aa1[seqpt[lcnt].n1]!= '\0') {
47140 X       fprintf(stderr,"Missing null at end: %d %d\n",
47141 X               lcnt,seqpt[lcnt].aa1[seqpt[lcnt].n1]);
47142 X       seqpt[lcnt].aa1[seqpt[lcnt].n1]='\0';
47143 X      }
47144 #endif
47145 X    }
47146 X  }
47147 X  /* all done - lcnt has the total number of library sequences */
47148 X
47149 #ifdef DEBUG
47150 X  if (lcnt > 0)
47151 X    for (i=0; i<10; i++) {
47152 X      for (j=0; j<10; j++) libstr[j]=pst.sq[seqpt[i].aa1[j]];
47153 X      libstr[10]='\0';
47154 X      fprintf(stderr,"[%d] n1: %d seqnm: %d aa1: %s\n",
47155 X             worker,seqpt[i].n1,seqpt[i].m_seqnm,libstr);
47156 X    }
47157 #endif
47158 X
47159 X  /* send back the number of descriptions received */
47160 X
47161 #ifdef PVM_SRC
47162 X  pvm_initsend(PvmDataRaw);
47163 X  pvm_pkint(&lcnt,1,1);
47164 X  pvm_send(hosttid,STARTTYPE0);
47165 #endif
47166 #ifdef MPI_SRC
47167 /*  p4_dprintf(" have %d descriptions to send\n",lcnt); */
47168 X  MPI_Send(&lcnt,1,MPI_INT,hosttid,STARTTYPE0,MPI_COMM_WORLD);
47169 #endif  
47170 X
47171 /*****************************************************************/
47172 /* Library reads are finished, get ready to do searches          */
47173 /*****************************************************************/
47174 X
47175 X  /* get last set of numbers */
47176 #ifdef PVM_SRC
47177 X  bufid = pvm_recv(hosttid,STARTTYPE0);
47178 X  pvm_upkint(last_msg_b,2,1);
47179 X  pvm_freebuf(bufid);
47180 #endif
47181 #ifdef MPI_SRC
47182 X  MPI_Recv(last_msg_b, 2, MPI_INT, hosttid, STARTTYPE0, MPI_COMM_WORLD,
47183 X            &mpi_status);
47184 #endif
47185 X  m_msg.nbr_seq = last_msg_b[0];
47186 X  qres_bufsize = last_msg_b[1];
47187 X
47188 #ifdef DEBUG
47189 #ifdef PVM_SRC
47190 X  fprintf(stderr,"[%d] have nbr_seq %d qres_bufsize %d\n",worker,
47191 X            m_msg.nbr_seq, qres_bufsize);
47192 #endif
47193 #ifdef MPI_SRC
47194 X  /*  p4_dprintf("[%d] have nbr_seq %d qres_bufsize %d\n",worker,
47195 X            m_msg.nbr_seq, qres_bufsize);
47196 X  */;
47197 #endif
47198 #endif  
47199 X  /* If self search, receive sequence numbering data */
47200 X  if (m_msg.self) {
47201 #ifdef PVM_SRC
47202 X    bufid = pvm_recv(hosttid,STARTTYPE1);
47203 X    pvm_upkint(&lend,1,1);
47204 X    pvm_freebuf(bufid);
47205 #endif
47206 #ifdef MPI_SRC
47207 X    MPI_Recv(&lend,1,MPI_INT,hosttid,STARTTYPE1,MPI_COMM_WORLD,&mpi_status);
47208 #endif
47209 X  }
47210 X  
47211 X  /* allocate space for a_res flag array */
47212 X
47213 X  if ((walign_done[0] = (int *)calloc(lcnt,sizeof(int)))==NULL) {
47214 X    w_abort("cannot allocate walign_done");
47215 X  }
47216 X  walign_cnt[0]=0;
47217 X
47218 X  if ((walign_done[1] = (int *)calloc(lcnt,sizeof(int)))==NULL) {
47219 X    w_abort("cannot allocate walign_done");
47220 X  }
47221 X  walign_cnt[1]=0;
47222 X
47223 X  /* was commented in for only FASTX/TFASTX, but do it always to
47224 X     simplify */
47225 X  aainit(pst.tr_type, pst.debug_lib);
47226 X  pst.maxlen = m_msg.maxn;
47227 X
47228 /*****************************************************************/
47229 /* Main search loop, which calles do_work() repeatedly           */
47230 /*****************************************************************/
47231 X
47232 X  cur_n0 = 0;
47233 X  while (1)  {
47234 /*
47235 #ifdef DEBUG
47236 #ifdef PVM_SRC
47237 X    fprintf(stderr," W: %d waiting MSEQTYPE\n",worker);
47238 #endif
47239 #ifdef MPI_SRC
47240 X    p4_dprintf(" W: %d waiting MSEQTYPE\n",worker);
47241 #endif
47242 #endif
47243 */
47244 X
47245 /*****************************************************************/
47246 /* Wait for a query sequence from the manager                    */
47247 /*****************************************************************/
47248 X
47249 #ifdef PVM_SRC
47250 X    bufid = pvm_recv(hosttid,MSEQTYPE);
47251 X    pvm_upkbyte((char *)&qm_msg,sizeof(qm_msg),1);
47252 #endif
47253 #ifdef MPI_SRC
47254 X    MPI_Recv(&qm_msg,sizeof(struct mngmsg),MPI_BYTE,hosttid,MSEQTYPE,
47255 X            MPI_COMM_WORLD,&mpi_status);
47256 #endif
47257 #ifdef DEBUG
47258 X    fprintf(stderr,"[%d] have MSEQTYPE n0: %d s_func: %d slist: %d qf: %d\n",
47259 X           worker,qm_msg.n0,qm_msg.s_func,qm_msg.slist,qm_msg.qshuffle);
47260 #endif
47261 X
47262 /*****************************************************************/
47263 /* New query sequence indicated by qm_msg.slist=0                */
47264 /*****************************************************************/
47265 X
47266 X    if (qm_msg.n0 > 0 && qm_msg.slist == 0) {
47267 X
47268 X      if (cur_n0 > 0) {
47269 X
47270 /*****************************************************************/
47271 /*    free everything associated with previous search            */
47272 /*****************************************************************/
47273 X
47274 X       close_work (aa0[0], cur_n0, &pst, &f_str[0]);  
47275 X       free_ares(seqpt, 0, walign_done[0], walign_cnt[0], worker);
47276 X       walign_cnt[0] = 0;
47277 X       if (m_msg.ann_flg) free(m_msg.aa0a);
47278 X
47279 X
47280 X       if (m_msg.qframe == 2) {
47281 X         close_work(aa0[1], cur_n0, &pst, &f_str[1]);
47282 X         free_ares(seqpt, 1, walign_done[1], walign_cnt[1], worker);
47283 X         walign_cnt[1] = 0;
47284 X       }
47285 X       if (old_shuffle) {
47286 X         close_work(aa0s,cur_n0, &pst, &qf_str);
47287 X         aa0s--;
47288 X         free(aa0s);
47289 X         old_shuffle = 0;
47290 X       }
47291 X       if (pst.pam_pssm) {
47292 X         free_pam2p(pst.pam2p[0]);
47293 X         free_pam2p(pst.pam2p[1]);
47294 X       }
47295 X      }
47296 X
47297 /*****************************************************************/
47298 /*    Start allocating things for the next search                */
47299 /*****************************************************************/
47300 X
47301 X      pst.pam_pssm = qm_msg.pam_pssm;
47302 X      cur_n0 = qm_msg.n0;
47303 X      if (m_msg.ann_flg) {
47304 X       if ((m_msg.aa0a = calloc(qm_msg.n0+1,sizeof(char)))==NULL) {
47305 X         w_abort(" cannot allocate aa0a");
47306 X       }
47307 X      }
47308 X
47309 /*****************************************************************/
47310 /*    Get the next query sequence                                */
47311 /*****************************************************************/
47312 X
47313 #ifdef PVM_SRC
47314 X      pvm_upkbyte((char *)aa0[0],qm_msg.n0+1+SEQ_PAD,1);
47315 X      if (m_msg.ann_flg) {
47316 X       pvm_upkbyte((char *)m_msg.aa0a,qm_msg.n0+1,1);
47317 X      }
47318 #endif
47319 #ifdef MPI_SRC
47320 X      MPI_Recv(aa0[0],qm_msg.n0+1+SEQ_PAD,MPI_BYTE,hosttid,
47321 X              MSEQTYPE1,MPI_COMM_WORLD, &mpi_status);
47322 X      if (m_msg.ann_flg) {
47323 X       MPI_Recv(m_msg.aa0a,qm_msg.n0+1,MPI_BYTE,hosttid,
47324 X                MSEQTYPE2,MPI_COMM_WORLD, &mpi_status);
47325 X      }
47326 #endif
47327 X
47328 #ifdef DEBUG
47329 X      /* must have null's at both ends of sequence */
47330 X      if (aa0[0][-1]!= '\0') {
47331 X       fprintf(stderr,"Missing null at start: %s %d\n",
47332 X               qm_msg.libstr,aa0[0][-1]);
47333 X       aa0[0][-1]='\0';
47334 X      }
47335 X      if (aa0[0][qm_msg.n0]!= '\0') {
47336 X       fprintf(stderr,"Missing null at end: %s %d\n",
47337 X               qm_msg.libstr,aa0[0][qm_msg.n0]);
47338 X       aa0[qm_msg.n0]='\0';
47339 X      }
47340 X
47341 X      /* This discovers most reasons for core dumps */
47342 X      if (pst.debug_lib)
47343 X       for (j=0; j<qm_msg.n0; j++)
47344 X         if (aa0[0][j]>pst.nsq) {
47345 X           fprintf(stderr,
47346 X                   "seq: %s residue[%d/%d] %d range (%d)\n",
47347 X                   qm_msg.libstr,j,qm_msg.n0,aa0[0][j],pst.nsq);
47348 X           aa0[0][j]=0;
47349 X           qm_msg.n0=j-1;
47350 X           break;
47351 X         }
47352 #endif
47353 X      update_params(&qm_msg,&m_msg,&pst);
47354 X    }
47355 X
47356 /*****************************************************************/
47357 /*    End of free()'s/ initialization for new sequence           */
47358 /*****************************************************************/
47359 X
47360 #ifdef PVM_SRC
47361 X    pvm_freebuf(bufid);
47362 #endif
47363 X
47364 X    if (qm_msg.n0 == -1) {
47365 X
47366 /*****************************************************************/
47367 /*   All done with searches                                      */
47368 /*****************************************************************/
47369 /*    printf(" %d: got n0 == -1\n",worker); */
47370 X      break;
47371 X    }
47372 X
47373 X    /*    p4_dprintf(" W:%d n0:%d slist:%d s_func:%d (%d)\n",worker,qm_msg.n0,qm_msg.slist,qm_msg.s_func,qres_bufsize); */
47374 X
47375 /*****************************************************************/
47376 /*   if qm_msg.slist > 0, search specific sequences, to be sent  */
47377 /*****************************************************************/
47378 X
47379 X    if (qm_msg.slist > 0) {  /* list search, not library search */
47380 X      if (liblist != NULL) free(liblist);
47381 X
47382 X      /* get the list of sequences */
47383 X      if ((liblist=(struct stage2_str *)
47384 X          calloc(qm_msg.slist,sizeof(struct stage2_str)))==NULL) {
47385 X         sprintf(errstr,"sequence list %d",qm_msg.slist);
47386 X         w_abort (errstr, "");
47387 X       }
47388 X
47389 #ifdef PVM_SRC
47390 X      bufid = pvm_recv(hosttid,LISTTYPE);
47391 X      pvm_upkbyte((char *)liblist,qm_msg.slist*sizeof(struct stage2_str),1);
47392 X      pvm_freebuf(bufid);
47393 #endif
47394 #ifdef MPI_SRC
47395 X      MPI_Recv(liblist,qm_msg.slist*sizeof(struct stage2_str),MPI_BYTE,
47396 X              hosttid,LISTTYPE,MPI_COMM_WORLD, &mpi_status);
47397 #endif
47398 X    }
47399 X
47400 /*****************************************************************/
47401 /* have list of sequences to be compared/aligned                 */
47402 /*****************************************************************/
47403 X
47404 X    /* Initial stuff */
47405 X    if (qm_msg.slist == 0) {
47406 /*****************************************************************/
47407 /* New query - set up matrices and init_work()                   */
47408 /*****************************************************************/
47409 #ifdef DEBUG
47410 /*
47411 X      fprintf(stderr,"n1: %d\t",qm_msg.n0);
47412 X      for (i=0; i<10; i++) fprintf(stderr,"%c",nt[aa0[0][i]]);
47413 X      fprintf(stderr,"\n");
47414 */
47415 #endif
47416 X      if (pst.pam_pssm) {
47417 X       pst.pam2p[0] = alloc_pam2p(qm_msg.n0,nsq);
47418 X       pst.pam2p[1] = alloc_pam2p(qm_msg.n0,nsq);
47419 X      }
47420 X
47421 X      init_work (aa0[0], qm_msg.n0, &pst, &f_str[0]);
47422 X      f_str[5]=f_str[4]=f_str[3]=f_str[2]=f_str[1]=f_str[0];
47423 X
47424 X      if (qm_msg.qshuffle) {
47425 X       if ((aa0s=(unsigned char *)malloc((qm_msg.n0+2)*sizeof (char)))==NULL)
47426 X         w_abort ("Unable to allocate aa0s array - exiting!","");
47427 X       *aa0s='\0';
47428 X       aa0s++;
47429 X
47430 X       memcpy(aa0s,aa0[0],qm_msg.n0+1);
47431 X       qshuffle(aa0s,qm_msg.n0,qm_msg.nm0);
47432 #ifdef DEBUG
47433 X       fprintf(stderr,"[%d] shuffle: %d\n",worker,qm_msg.n0);
47434 X       fputs("   ",stderr);
47435 X       for (i=0; i<5; i++) {fprintf(stderr,"%c",pst.sq[aa0s[i]]);}
47436 X       fputc('\n',stderr);
47437 #endif
47438 X
47439 X       init_work (aa0s, qm_msg.n0, &pst, &qf_str);
47440 X       old_shuffle=1;
47441 X      }
47442 X
47443 X      if (m_msg.qframe == 2) {
47444 X       memcpy(aa0[1],aa0[0],qm_msg.n0+1);
47445 X       revcomp(aa0[1],qm_msg.n0,&pst.c_nt[0]);
47446 X       init_work (aa0[1], qm_msg.n0, &pst, &f_str[1]);
47447 X      }
47448 #ifdef DEBUG
47449 /*
47450 X       fprintf(stderr,"[%d] init_work qf: %d nf: %d\n",worker,m_msg.qframe,m_msg.nframe);
47451 */
47452 #endif
47453 X    }
47454 X
47455 /*****************************************************************/
47456 /* Finished with initialization,                                 */
47457 /* start doing comparisons or alignments                         */
47458 /*****************************************************************/
47459 X
47460 X    bestcnt = 0;
47461 X    if (qm_msg.slist == 0) {   /* library search */
47462 X
47463 /*****************************************************************/
47464 /* Start library search                                          */
47465 /*****************************************************************/
47466 X
47467 X      for (count=0; count < lcnt; count++) {
47468 X
47469 X       for (itt=m_msg.revcomp; itt<=m_msg.nitt1; itt++) {
47470 X
47471 X         rst.score[0] = rst.score[1] = rst.score[2] = 0;
47472 X         if (m_msg.self) {
47473 X           lsn = lend + count;
47474 X           if ((qm_msg.seqnm > lsn) && (((qm_msg.seqnm + lsn) % 2) != 0)) {
47475 X             do_work (aa0[itt], qm_msg.n0,seqpt[count].aa1, seqpt[count].n1,
47476 X                      itt, &pst, f_str[itt], 0, &rst);
47477 X           }
47478 X           else if ((qm_msg.seqnm <= lsn) && (((qm_msg.seqnm+lsn)%2) == 0)) {
47479 X             do_work (aa0[itt], qm_msg.n0, seqpt[count].aa1, seqpt[count].n1, 
47480 X                      itt, &pst, f_str[itt], 0, &rst);
47481 X           }
47482 X           else continue;
47483 X         }
47484 X         else {
47485 X           do_work (aa0[itt], qm_msg.n0, seqpt[count].aa1, seqpt[count].n1,
47486 X                    itt, &pst, f_str[itt], 0, &rst);
47487 X           if (qm_msg.qshuffle) {
47488 X             do_work (aa0s, qm_msg.n0, seqpt[count].aa1, seqpt[count].n1,
47489 X                    itt, &pst, qf_str, 1, &qrst);
47490 X           }
47491 X         }
47492 #ifdef DEBUG
47493 /*
47494 X         if (count < 10 || (count % 200 == 199)) {
47495 X           fprintf(stderr,"[node %d] itt:%d/%d (%d) %3d %3d %3d - %d/%d\n",
47496 X                   worker,itt,m_msg.nitt1,count,
47497 X                   rst.score[0],rst.score[1],rst.score[2],
47498 X                   seqpt[count].m_seqnm,seqpt[count].n1);
47499 X         }
47500 */
47501 #endif
47502 X         sw_score = -1;
47503 X
47504 X         bestr[bestcnt].seqnm  = count;
47505 X         bestr[bestcnt].m_seqnm  = seqpt[count].m_seqnm;
47506 X         bestr[bestcnt].score[0] = rst.score[0];
47507 X         bestr[bestcnt].score[1] = rst.score[1];
47508 X         bestr[bestcnt].score[2] = rst.score[2];
47509 X         bestr[bestcnt].escore = rst.escore;
47510 X         bestr[bestcnt].segnum = rst.segnum;
47511 X         bestr[bestcnt].seglen = rst.seglen;
47512 X         bestr[bestcnt].frame = itt;
47513 X         bestr[bestcnt].comp = rst.comp;
47514 X         bestr[bestcnt].H = rst.H;
47515 X
47516 X         bestr[bestcnt].qr_score = qrst.score[pst.score_ix];
47517 X         bestr[bestcnt].qr_escore = qrst.escore;
47518 X
47519 X         if (pst.zsflag >= 10) {
47520 X           if (pst.zs_win > 0) 
47521 X             wshuffle(seqpt[count].aa1, aa1s,seqpt[count].n1,pst.zs_win,&ieven);
47522 X           else 
47523 X             shuffle(seqpt[count].aa1, aa1s,seqpt[count].n1);
47524 X
47525 X           do_work(aa0[itt],qm_msg.n0,aa1s,seqpt[count].n1,itt, &pst, 
47526 X                   f_str[itt], 0, &rst);
47527 X           bestr[bestcnt].r_score = rst.score[pst.score_ix];
47528 X         }
47529 X
47530 X         bestcnt++;
47531 X         if (bestcnt >= qres_bufsize) {
47532 #ifdef DEBUG
47533 X           fprintf(stderr," worker: %d sending %d results\n",worker,qres_bufsize);
47534 #endif
47535 X           send_bestr(hosttid,curtype,bestr,qres_bufsize,bestcnt);
47536 X           bestcnt = 0;
47537 X         }
47538 X       }
47539 X      }        /* END - for count loop */
47540 X      send_bestr(hosttid, curtype, bestr,qres_bufsize, (bestcnt | FINISHED));
47541 X    }
47542 X
47543 /*****************************************************************/
47544 /* End of library search section                                 */
47545 /*****************************************************************/
47546 X
47547 /*****************************************************************/
47548 /* Do do_opt() from list   s_func=DO_CALC_FLG                    */
47549 /*****************************************************************/
47550 X
47551 X    else if (qm_msg.s_func== DO_CALC_FLG) {  /* qm_msg.slist > 0 */
47552 X
47553 X      bestcnt = 0;
47554 X      for (count=0; count < qm_msg.slist; count++) {
47555 X       rst.score[0] = rst.score[1] = rst.score[2] = 0;
47556 X       itt = liblist[count].frame;
47557 X       seqnm = bestr2[bestcnt].seqnm  = liblist[count].seqnm;
47558 X       bestr2[bestcnt].m_seqnm = seqpt[seqnm].m_seqnm;
47559 X
47560 X       do_opt (aa0[itt], qm_msg.n0, seqpt[seqnm].aa1,
47561 X                seqpt[seqnm].n1, itt,
47562 X                &pst, f_str[itt], &rst);
47563 X
47564 X       bestr2[bestcnt].score[0] = rst.score[0];
47565 X       bestr2[bestcnt].score[1] = rst.score[1];
47566 X       bestr2[bestcnt].score[2] = rst.score[2];
47567 X       bestr2[bestcnt].escore = rst.escore;
47568 X       bestr2[bestcnt].segnum = rst.segnum;
47569 X       bestr2[bestcnt].seglen = rst.seglen;
47570 X       bestr2[bestcnt].aln_code_n = 0;
47571 X       bestcnt++;
47572 X
47573 X       if (bestcnt >= BFR2) {
47574 X         send_bestr2(hosttid,bestr2,bestcnt);
47575 X         bestcnt = 0;
47576 X       }
47577 X      }        /* END - for count loop */
47578 X
47579 X      send_bestr2(hosttid,bestr2,(bestcnt|FINISHED));
47580 X    }
47581 X
47582 /*****************************************************************/
47583 /* s_func=DO_OPT_FLG                                             */
47584 /*                                                               */
47585 /* from list:                                                    */
47586 /* if (m_msg.stages > 1) do_opt()                                */
47587 /* do_walign()                                                   */
47588 /* calc_id or calc_code, no calcons                              */
47589 /*****************************************************************/
47590 X
47591 X    /* s_func == 1 means do_opt if necessary */
47592 X    else if (qm_msg.s_func== DO_OPT_FLG) {  /* qm_msg.slist > 0 */
47593 #ifdef DEBUG
47594 X      fprintf(stderr," [%d] starting s_func:1 slist: %d\n",
47595 X             worker,qm_msg.slist);
47596 #endif
47597 X      /* get the buffer once - re-use it for the entire slist */
47598 X      if (m_msg.show_code == SHOW_CODE_ALIGN) {
47599 X       seqc_buff_len = (BFR2+5)*256;
47600 X       seqc = seqc_buff = (char *)calloc(seqc_buff_len,sizeof(char));
47601 X       seqc_buff_cnt = 0;
47602 X       if (seqc_buff == NULL) {
47603 X         seqc_buff_cnt = seqc_buff_len = 0;
47604 X       }
47605 X      }
47606 X
47607 X      bestcnt = 0;
47608 X      for (count=0; count < qm_msg.slist; count++) {
47609 X       rst.score[0] = rst.score[1] = rst.score[2] = 0;
47610 X       itt = liblist[count].frame;
47611 X       seqnm = liblist[count].seqnm;
47612 X
47613 X       bestr2[bestcnt].seqnm  = seqnm;
47614 X       bestr2[bestcnt].m_seqnm = seqpt[seqnm].m_seqnm;
47615 X       if (m_msg.stages > 1) {
47616 X         do_opt (aa0[itt], qm_msg.n0, seqpt[seqnm].aa1,
47617 X                 seqpt[seqnm].n1, itt,
47618 X                 &pst, f_str[itt], &rst);
47619 X
47620 X         bestr2[bestcnt].score[0] = rst.score[0];
47621 X         bestr2[bestcnt].score[1] = rst.score[1];
47622 X         bestr2[bestcnt].score[2] = rst.score[2];
47623 X       }
47624 X
47625 X       if (m_msg.markx & MX_M9SUMM) {
47626 #ifdef DEBUG
47627 X         fprintf(stderr," [%d] starting do_walign seqnm: %d n1: %d\n",
47628 X                 worker,seqnm,seqpt[seqnm].n1);
47629 #endif
47630 X         aln_dp = &bestr2[bestcnt].aln_d;
47631 X         memcpy(aln_dp, &aln,sizeof(struct a_struct));
47632 X
47633 X         sw_score = do_walign(aa0[itt], qm_msg.n0,
47634 X                              seqpt[seqnm].aa1, seqpt[seqnm].n1,
47635 X                              itt, &pst, f_str[itt],
47636 X                              &seqpt[seqnm].a_res[itt],
47637 X                              &have_walign);
47638 X         seqpt[seqnm].sw_score[itt] = sw_score;
47639 X
47640 X         /* the a_res[itt] provided by do_walign is re-used - so it
47641 X            must be copied to a valid location */
47642 X
47643 X         if (have_walign) {
47644 X           if ((tres = calloc(seqpt[seqnm].a_res[itt].nres+1,sizeof(int)))==NULL) {
47645 X             w_abort(" cannot allocate tres");
47646 X           }
47647 X           else {
47648 X             memcpy(tres,seqpt[seqnm].a_res[itt].res,sizeof(int)*seqpt[seqnm].a_res[itt].nres);
47649 X             seqpt[seqnm].a_res[itt].res = tres;
47650 X             /*
47651 X               fprintf(stderr, " [%d] saving %d:%d[%d]:%o\n", worker, 
47652 X               walign_cnt[itt],seqnm,itt, seqpt[seqnm].a_res[itt].res);
47653 X             */
47654 X             if (walign_cnt[itt] < lcnt) walign_done[itt][walign_cnt[itt]++] = seqnm;
47655 X             else w_abort(" walign_cnt overrun");
47656 X             seqpt[seqnm].walign_dflg[itt] = 1;
47657 X           }
47658 X         }
47659 X         aln_func_vals(itt, aln_dp);
47660 X
47661 #ifdef DEBUG
47662 X         fprintf(stderr," [%d] starting calc_id sw_score: %d\n",
47663 X                 worker,sw_score);
47664 X         fprintf(stderr,"bi: %d seqc_buff_cnt: %d - seqc_buff_len: %d\n",
47665 X                 bestcnt, seqc_buff_cnt, seqc_buff_len);
47666 #endif
47667 X         aln_code_n = 0;       /* must be set in case no seqc_code */
47668 X         if (m_msg.show_code == SHOW_CODE_ALIGN) {
47669 X           if (seqc_buff_cnt < seqc_buff_len - 256) {
47670 X             lc=calc_code(aa0[itt],qm_msg.n0,
47671 X                          seqpt[seqnm].aa1, seqpt[seqnm].n1,
47672 X                          aln_dp,seqpt[seqnm].a_res[itt],pst,
47673 X                          seqc,seqc_buff_len-seqc_buff_cnt-10,
47674 X                          f_str[itt]);
47675 X             aln_code_n = strlen(seqc);
47676 X             seqc_buff_cnt += aln_code_n + 1;
47677 /*
47678 X             fprintf(stderr,"%d:%d:%d: %d/%d - [%d] %s\n",
47679 X                     worker,seqnm,bestcnt,aln_code_n,seqc_buff_cnt, seqc-seqc_buff,seqc);
47680 */
47681 X             seqc += aln_code_n;
47682 X             *seqc++ = '\0';
47683 X           }
47684 X         }
47685 X         else {
47686 X           lc=calc_id(aa0[itt],qm_msg.n0,
47687 X                      seqpt[seqnm].aa1, seqpt[seqnm].n1,
47688 X                      aln_dp,seqpt[seqnm].a_res[itt],pst,f_str[itt]);
47689 X         }
47690 X
47691 X         nident = aln_dp->nident;
47692 X         aln_dp->a_len = lc;
47693 X
47694 X         if (lc > 0) percent = (100.0*(float)nident)/(float)lc;
47695 X         else percent = 0.0;
47696 X
47697 X         ngap = aln_dp->ngap_q + aln_dp->ngap_l;
47698 #ifndef SHOWSIM
47699 X         if (lc-ngap > 0) gpercent = (100.0*(float)nident)/(float)(lc-ngap);
47700 #else
47701 X         if (lc > 0) gpercent =(100.0*(float)aln_dp->nsim)/(float)lc;
47702 #endif
47703 X         else gpercent = -1.0;
47704 X
47705 X         bestr2[bestcnt].sw_score = sw_score;
47706 X         bestr2[bestcnt].percent = percent;
47707 X         bestr2[bestcnt].gpercent = gpercent;
47708 X         bestr2[bestcnt].aln_code_n = aln_code_n;
47709 X       }
47710 X       bestcnt++;
47711 X
47712 X       if (bestcnt >= BFR2) {
47713 X         send_bestr2(hosttid,bestr2,bestcnt);
47714 X         if (m_msg.show_code == SHOW_CODE_ALIGN) {
47715 X           send_code(hosttid,seqc_buff,seqc_buff_cnt);
47716 X           memset(seqc_buff,0,seqc_buff_len);
47717 X           seqc = seqc_buff;
47718 X           seqc_buff_cnt = 0;
47719 X         }
47720 X         bestcnt = 0;
47721 X       }
47722 X      }        /* END - for count loop */
47723 X
47724 X      send_bestr2(hosttid,bestr2,(bestcnt|FINISHED));
47725 X      if (m_msg.show_code == SHOW_CODE_ALIGN) {
47726 X       send_code(hosttid,seqc_buff,seqc_buff_cnt);
47727 X       if (seqc_buff) free(seqc_buff);
47728 X      }
47729 X    }
47730 X    /* get alignments */
47731 X
47732 /*****************************************************************/
47733 /* s_list >                                                      */
47734 /* s_func=DO_ALIGN_FLG                                           */
47735 /*                                                               */
47736 /* from list:                                                    */
47737 /* do_walign() if not done already                               */ 
47738 /* calcons()                                                     */
47739 /*****************************************************************/
47740 X
47741 X    else if (qm_msg.s_func==DO_ALIGN_FLG) {
47742 X      for (count=0; count < qm_msg.slist; count++) {
47743 X       itt = liblist[count].frame;
47744 X       seqnm = liblist[count].seqnm;
47745 /*
47746 X       fprintf(stderr,"worker: %d; %s, frame: %d\n",worker,qm_msg.libstr,itt);
47747 */
47748 X       if (!seqpt[seqnm].walign_dflg[itt]) {
47749 X         seqpt[seqnm].sw_score[itt] = 
47750 X           sw_score = do_walign (aa0[itt], qm_msg.n0,seqpt[seqnm].aa1,
47751 X                                 seqpt[seqnm].n1, itt,
47752 X                                 &pst, f_str[itt],
47753 X                                 &seqpt[seqnm].a_res[itt],
47754 X                                 &have_walign);
47755 X       }
47756 X       else {
47757 X         sw_score = seqpt[seqnm].sw_score[itt];
47758 X         pre_cons(seqpt[seqnm].aa1,seqpt[seqnm].n1,itt,f_str[itt]);
47759 X       }
47760 X
47761 X       aln_func_vals(itt, &aln);
47762 X
47763 X       if (aln.showall==1)
47764 X         maxc = seqpt[seqnm].a_res[itt].nres + max(seqpt[seqnm].a_res[itt].min0,seqpt[seqnm].a_res[itt].min1)+
47765 X           max((qm_msg.n0-seqpt[seqnm].a_res[itt].max0),
47766 X               (seqpt[seqnm].n1-seqpt[seqnm].a_res[itt].max1))+4;
47767 X       else  maxc = seqpt[seqnm].a_res[itt].nres + 4*aln.llen+4;
47768 X
47769 X       initseq(&seqc0, &seqc0a, &seqc1, &seqca, maxc);
47770 X
47771 X       if (!m_msg.ann_flg) {
47772 X         nc=calcons(aa0[itt],qm_msg.n0,
47773 X                  seqpt[seqnm].aa1, seqpt[seqnm].n1,
47774 X                  &lc,&aln,seqpt[seqnm].a_res[itt],pst,
47775 X                  seqc0,seqc1,seqca,f_str[itt]);
47776 X         memset(seqc0a,' ',nc);
47777 X         seqc0a[nc]='\0';
47778 X       }
47779 X       else {
47780 X         nc=calcons_a(aa0[itt],m_msg.aa0a,qm_msg.n0,
47781 X                      seqpt[seqnm].aa1, seqpt[seqnm].n1,
47782 X                      &lc,&aln,seqpt[seqnm].a_res[itt],pst,
47783 X                      seqc0,seqc0a,seqc1,seqca,
47784 X                      m_msg.ann_arr,f_str[itt]);
47785 X       }
47786 X
47787 X       /*
47788 X       fprintf(stderr,"[%d] nident: %d nsim: %d lc: %d\n",aln.nident, aln.nsim, lc);
47789 X       */
47790 X
47791 X       maxc = max(strlen(seqc0),strlen(seqc1))+1;
47792 X       nident = aln.nident;
47793 X       percent = (100.0*(float)nident)/(float)lc;
47794 X       ngap = aln.ngap_q+aln.ngap_l;
47795 #ifndef SHOWSIM
47796 X       if (lc-ngap > 0) gpercent = (100.0*(float)nident)/(float)(lc-ngap);
47797 #else
47798 X       if (lc > 0) gpercent = (100.0*(float)aln.nsim)/(float)lc;
47799 #endif
47800 X       else gpercent = -1.0;
47801 X
47802 #ifdef PVM_SRC
47803 X       pvm_initsend(PvmDataRaw);
47804 X       pvm_pkint(&nc,1,1);
47805 X       pvm_pkint(&lc,1,1);
47806 X       pvm_pkint(&maxc,1,1);
47807 X       pvm_pkfloat(&percent,1,1);
47808 X       pvm_pkfloat(&gpercent,1,1);
47809 X       pvm_pkint(&sw_score,1,1);
47810 X       pvm_pkbyte((char *)&aln,sizeof(struct a_struct),1);
47811 X       pvm_send(hosttid,ALN1TYPE);
47812 #ifdef DEBUG
47813 X       fprintf(stderr,"[%d] ALN1TYPE sent: %d\n",worker,qm_msg.n0);
47814 #endif
47815 X       pvm_initsend(PvmDataRaw);
47816 X       pvm_pkbyte(seqc0,maxc,1);
47817 X       if (m_msg.ann_flg) pvm_pkbyte(seqc0a,maxc,1);
47818 X       pvm_pkbyte(seqc1,maxc,1);
47819 X       pvm_pkbyte(seqca,maxc,1);
47820 X       pvm_send(hosttid,ALN2TYPE);
47821 #endif
47822 #ifdef MPI_SRC
47823 X       last_msg_b[0]=nc;
47824 X       last_msg_b[1]=lc;
47825 X       last_msg_b[2]=maxc;
47826 X       last_msg_b[3]=sw_score;
47827 X       MPI_Send(last_msg_b,4,MPI_INT,hosttid,ALN1TYPE,MPI_COMM_WORLD);
47828 X       MPI_Send(&percent,1,MPI_FLOAT,hosttid,ALN2TYPE,MPI_COMM_WORLD);
47829 X       MPI_Send(&gpercent,1,MPI_FLOAT,hosttid,ALN2TYPE,MPI_COMM_WORLD);
47830 X
47831 /*      p4_dprintf("[%d] sending aln\n",worker); */
47832 X       MPI_Send(&aln,sizeof(struct a_struct),MPI_BYTE,hosttid,
47833 X                ALN3TYPE,MPI_COMM_WORLD);
47834 X
47835 X       MPI_Send(seqc0,maxc,MPI_BYTE,hosttid,ALN2TYPE,MPI_COMM_WORLD);
47836 X       if (m_msg.ann_flg) MPI_Send(seqc0a,maxc,MPI_BYTE,hosttid,ALN2TYPE,MPI_COMM_WORLD);
47837 X       MPI_Send(seqc1,maxc,MPI_BYTE,hosttid,ALN3TYPE,MPI_COMM_WORLD);
47838 X       MPI_Send(seqca,maxc,MPI_BYTE,hosttid,ALN3TYPE,MPI_COMM_WORLD);
47839 #endif
47840 X       freeseq(&seqc0,&seqc0a,&seqc1,&seqca);
47841 X      }        
47842 X    }
47843 X    
47844 /* send back parameter settings */
47845 X    if (worker==FIRSTWORK && qm_msg.slist==0) {
47846 X      get_param(&pst, gstring2,gstring3);
47847 #ifdef PVM_SRC
47848 X      pvm_initsend(PvmDataRaw);
47849 X      pvm_pkbyte(gstring2,sizeof(gstring2),1);
47850 X      pvm_pkbyte(gstring3,sizeof(gstring3),1);
47851 X      pvm_send(hosttid,PARAMTYPE);
47852 #endif
47853 #ifdef MPI_SRC
47854 X      MPI_Send(gstring2,sizeof(gstring2),MPI_BYTE,
47855 X              hosttid,PARAMTYPE,MPI_COMM_WORLD);
47856 X      MPI_Send(gstring3,sizeof(gstring3),MPI_BYTE,
47857 X              hosttid,PARAMTYPE,MPI_COMM_WORLD);
47858 #endif
47859 X    }
47860 X    
47861 X    if (qm_msg.slist==0) {
47862 X      if (curtype == ONETYPE) curtype = TWOTYPE;
47863 X      else curtype = ONETYPE;
47864 X    }
47865 X  }        /* END - while (1) loop */
47866 #ifdef PVM_SRC
47867 X  pvm_exit();
47868 #endif
47869 #ifdef MPI_SRC
47870 /*  MPI_Finalize(); */
47871 #endif
47872 }
47873 X
47874 void
47875 send_bestr(int hosttid, int curtype, 
47876 X          struct comstr *bestr, int buf_size, int lastcnt) {
47877 X
47878 X  bestr[buf_size].seqnm = lastcnt;
47879 #ifdef PVM_SRC
47880 X  pvm_initsend(PvmDataRaw);
47881 X  pvm_pkbyte((char *)&bestr[0],sizeof(struct comstr)*(buf_size+1),1);
47882 X  pvm_send(hosttid,curtype);
47883 #endif
47884 #ifdef MPI_SRC
47885 X  MPI_Send(bestr,sizeof(struct comstr)*(buf_size+1),MPI_BYTE,
47886 X          hosttid,curtype,MPI_COMM_WORLD);
47887 #endif
47888 }
47889 X
47890 void
47891 send_bestr2(int hosttid, struct comstr2 *bestr2,
47892 X           int lastcnt)
47893 {
47894 X  bestr2[BFR2].seqnm = lastcnt;
47895 #ifdef PVM_SRC
47896 X  pvm_initsend(PvmDataRaw);
47897 X  pvm_pkbyte((char *)&bestr2[0],sizeof(struct comstr2)*(BFR2+1),1);
47898 X  pvm_send(hosttid,LISTRTYPE);
47899 #endif
47900 #ifdef MPI_SRC
47901 X  MPI_Send(&bestr2[0],sizeof(struct comstr2)*(BFR2+1),MPI_BYTE,
47902 X          hosttid,LISTRTYPE,MPI_COMM_WORLD);
47903 #endif
47904 }
47905 X
47906 void
47907 send_code(int hosttid, char *seqc_buff, int seqc_buff_len) {
47908 X
47909 #ifdef PVM_SRC
47910 X  pvm_initsend(PvmDataRaw);
47911 X  pvm_pkint(&seqc_buff_len,1,1);
47912 X  if (seqc_buff_len > 0) pvm_pkbyte(seqc_buff,seqc_buff_len,1);
47913 X  pvm_send(hosttid,CODERTYPE);
47914 #endif
47915 #ifdef MPI_SRC
47916 X  MPI_Send(&seqc_buff_len,1,MPI_INT,
47917 X          hosttid,CODERTYPE,MPI_COMM_WORLD);
47918 X  if (seqc_buff_len>0) MPI_Send(seqc_buff,seqc_buff_len,MPI_BYTE,
47919 X                              hosttid,CODERTYPE,MPI_COMM_WORLD);
47920 #endif
47921 }
47922 X
47923 #ifdef PVM_SRC
47924 int tidtonode(tid)
47925 X     int tid;
47926 {
47927 X  int i;
47928 X  for (i=FIRSTNODE; i< nnodes; i++) if (tid==pinums[i]) return i;
47929 X  fprintf(stderr," cannot find tid %d\n",tid);
47930 X  return -1;
47931 }
47932 #endif
47933 X
47934 void
47935 free_ares(struct sqs2 *seqpt, int itt, int *walign_done, int walign_cnt, int worker) {
47936 X
47937 X  int i, seqnm;
47938 X
47939 X  for (i=0; i< walign_cnt; i++) {
47940 X    seqnm = walign_done[i];
47941 X    walign_done[i]=0;
47942 X    if (seqpt[seqnm].walign_dflg[itt]) {
47943 X      if (seqpt[seqnm].a_res[itt].nres > 0 ) {
47944 X       /*
47945 X       fprintf(stderr, "[%d] freeing %d:%d[%d]:%o\n",
47946 X               worker,i,seqnm,itt,seqpt[seqnm].a_res[itt].res);
47947 X       */
47948 X       seqpt[seqnm].a_res[itt].nres = 0;
47949 X       free(seqpt[seqnm].a_res[itt].res);
47950 X      }
47951 X    }
47952 X    else {
47953 X      w_abort(" have walign_done but no walign_dflag");
47954 X    }
47955 X    seqpt[seqnm].walign_dflg[itt] = 0;
47956 X  }
47957 }
47958 SHAR_EOF
47959 chmod 0644 p2_workcomp.c ||
47960 echo 'restore of p2_workcomp.c failed'
47961 Wc_c="`wc -c < 'p2_workcomp.c'`"
47962 test 37611 -eq "$Wc_c" ||
47963         echo 'p2_workcomp.c: original size 37611, current size' "$Wc_c"
47964 fi
47965 # ============= p_mw.h ==============
47966 if test -f 'p_mw.h' -a X"$1" != X"-c"; then
47967         echo 'x - skipping p_mw.h (File already exists)'
47968 else
47969 echo 'x - extracting p_mw.h (Text)'
47970 sed 's/^X//' << 'SHAR_EOF' > 'p_mw.h' &&
47971 /* Concurrent read version */
47972 X
47973 /* $Name: fa_34_26_5 $ - $Id: p_mw.h,v 1.17 2006/04/12 18:00:02 wrp Exp $ */
47974 X
47975 #ifndef FSEEK_T_DEF
47976 #ifndef USE_FSEEKO
47977 typedef long fseek_t;
47978 #else
47979 typedef off_t fseek_t;
47980 #endif
47981 #endif
47982 X
47983 struct beststr {
47984 X  int n1;              /* sequence number */
47985 X  int score[3];                /* score */
47986 X  int rscore;  /* score from shuffled sequence */
47987 X  int sw_score;        /* optimal score from alignment */
47988 X  double comp; /* karlin 1/lambda comp.parameter */
47989 X  double H;    /* karlin H information content */
47990 X  double zscore;
47991 X  double escore;
47992 X  double r_escore;
47993 X  int segnum;
47994 X  int seglen;
47995 X  int  lib;
47996 X  fseek_t lseek;
47997 X  int cont;
47998 X  int frame;
47999 X  int m_seqnm;
48000 X  int seqnm;
48001 X  int wrkr;
48002 X  struct sql *desptr;
48003 X  struct a_struct *aln_d;
48004 X  char *aln_code;
48005 X  int aln_code_n;
48006 X  float percent, gpercent;
48007 };
48008 X
48009 struct stat_str {
48010 X  int score;
48011 X  int n1;
48012 X  double comp;
48013 X  double H;
48014 X  double escore;
48015 X  int segnum;
48016 X  int seglen;
48017 };
48018 X
48019 /* this structure passes library sequences to the worker threads
48020 X   and returns scores */
48021 X
48022 #include "w_mw.h"
48023 X
48024 /*
48025 struct pbuf_head {
48026 X  int buf_cnt;
48027 X  unsigned char *start;
48028 X  struct sqs2 *buf;
48029 };
48030 */
48031 SHAR_EOF
48032 chmod 0644 p_mw.h ||
48033 echo 'restore of p_mw.h failed'
48034 Wc_c="`wc -c < 'p_mw.h'`"
48035 test 1096 -eq "$Wc_c" ||
48036         echo 'p_mw.h: original size 1096, current size' "$Wc_c"
48037 fi
48038 # ============= pam120.mat ==============
48039 if test -f 'pam120.mat' -a X"$1" != X"-c"; then
48040         echo 'x - skipping pam120.mat (File already exists)'
48041 else
48042 echo 'x - extracting pam120.mat (Text)'
48043 sed 's/^X//' << 'SHAR_EOF' > 'pam120.mat' &&
48044 #
48045 # This matrix was produced by "pam" Version 1.0.6 [28-Jul-93]
48046 #
48047 # PAM 120 substitution matrix, scale = ln(2)/2 = 0.346574
48048 #
48049 # Expected score = -1.64, Entropy = 0.979 bits
48050 #
48051 # Lowest score = -8, Highest score = 12
48052 #
48053 X   A  R  N  D  C  Q  E  G  H  I  L  K  M  F  P  S  T  W  Y  V  B  Z  X
48054 A  3 -3 -1  0 -3 -1  0  1 -3 -1 -3 -2 -2 -4  1  1  1 -7 -4  0  0 -1 -1
48055 R -3  6 -1 -3 -4  1 -3 -4  1 -2 -4  2 -1 -5 -1 -1 -2  1 -5 -3 -2 -1 -2
48056 N -1 -1  4  2 -5  0  1  0  2 -2 -4  1 -3 -4 -2  1  0 -4 -2 -3  3  0 -1
48057 D  0 -3  2  5 -7  1  3  0  0 -3 -5 -1 -4 -7 -3  0 -1 -8 -5 -3  4  3 -2
48058 C -3 -4 -5 -7  9 -7 -7 -4 -4 -3 -7 -7 -6 -6 -4  0 -3 -8 -1 -3 -6 -7 -4
48059 Q -1  1  0  1 -7  6  2 -3  3 -3 -2  0 -1 -6  0 -2 -2 -6 -5 -3  0  4 -1
48060 E  0 -3  1  3 -7  2  5 -1 -1 -3 -4 -1 -3 -7 -2 -1 -2 -8 -5 -3  3  4 -1
48061 G  1 -4  0  0 -4 -3 -1  5 -4 -4 -5 -3 -4 -5 -2  1 -1 -8 -6 -2  0 -2 -2
48062 H -3  1  2  0 -4  3 -1 -4  7 -4 -3 -2 -4 -3 -1 -2 -3 -3 -1 -3  1  1 -2
48063 I -1 -2 -2 -3 -3 -3 -3 -4 -4  6  1 -3  1  0 -3 -2  0 -6 -2  3 -3 -3 -1
48064 L -3 -4 -4 -5 -7 -2 -4 -5 -3  1  5 -4  3  0 -3 -4 -3 -3 -2  1 -4 -3 -2
48065 K -2  2  1 -1 -7  0 -1 -3 -2 -3 -4  5  0 -7 -2 -1 -1 -5 -5 -4  0 -1 -2
48066 M -2 -1 -3 -4 -6 -1 -3 -4 -4  1  3  0  8 -1 -3 -2 -1 -6 -4  1 -4 -2 -2
48067 F -4 -5 -4 -7 -6 -6 -7 -5 -3  0  0 -7 -1  8 -5 -3 -4 -1  4 -3 -5 -6 -3
48068 P  1 -1 -2 -3 -4  0 -2 -2 -1 -3 -3 -2 -3 -5  6  1 -1 -7 -6 -2 -2 -1 -2
48069 S  1 -1  1  0  0 -2 -1  1 -2 -2 -4 -1 -2 -3  1  3  2 -2 -3 -2  0 -1 -1
48070 T  1 -2  0 -1 -3 -2 -2 -1 -3  0 -3 -1 -1 -4 -1  2  4 -6 -3  0  0 -2 -1
48071 W -7  1 -4 -8 -8 -6 -8 -8 -3 -6 -3 -5 -6 -1 -7 -2 -6 12 -2 -8 -6 -7 -5
48072 Y -4 -5 -2 -5 -1 -5 -5 -6 -1 -2 -2 -5 -4  4 -6 -3 -3 -2  8 -3 -3 -5 -3
48073 V  0 -3 -3 -3 -3 -3 -3 -2 -3  3  1 -4  1 -3 -2 -2  0 -8 -3  5 -3 -3 -1
48074 B  0 -2  3  4 -6  0  3  0  1 -3 -4  0 -4 -5 -2  0  0 -6 -3 -3  4  2 -1
48075 Z -1 -1  0  3 -7  4  4 -2  1 -3 -3 -1 -2 -6 -1 -1 -2 -7 -5 -3  2  4 -1
48076 XX -1 -2 -1 -2 -4 -1 -1 -2 -2 -1 -2 -2 -2 -3 -2 -1 -1 -5 -3 -1 -1 -1 -2
48077 X
48078 SHAR_EOF
48079 chmod 0644 pam120.mat ||
48080 echo 'restore of pam120.mat failed'
48081 Wc_c="`wc -c < 'pam120.mat'`"
48082 test 1922 -eq "$Wc_c" ||
48083         echo 'pam120.mat: original size 1922, current size' "$Wc_c"
48084 fi
48085 # ============= pam250.mat ==============
48086 if test -f 'pam250.mat' -a X"$1" != X"-c"; then
48087         echo 'x - skipping pam250.mat (File already exists)'
48088 else
48089 echo 'x - extracting pam250.mat (Text)'
48090 sed 's/^X//' << 'SHAR_EOF' > 'pam250.mat' &&
48091 #
48092 # This matrix was produced by "pam" Version 1.0.6 [28-Jul-93]
48093 #
48094 # PAM 250 substitution matrix, scale = ln(2)/3 = 0.231049
48095 #
48096 # Expected score = -0.844, Entropy = 0.354 bits
48097 #
48098 # Lowest score = -8, Highest score = 17
48099 #
48100 X   A  R  N  D  C  Q  E  G  H  I  L  K  M  F  P  S  T  W  Y  V  B  Z  X
48101 A  2 -2  0  0 -2  0  0  1 -1 -1 -2 -1 -1 -3  1  1  1 -6 -3  0  0  0  0
48102 R -2  6  0 -1 -4  1 -1 -3  2 -2 -3  3  0 -4  0  0 -1  2 -4 -2 -1  0 -1
48103 N  0  0  2  2 -4  1  1  0  2 -2 -3  1 -2 -3  0  1  0 -4 -2 -2  2  1  0
48104 D  0 -1  2  4 -5  2  3  1  1 -2 -4  0 -3 -6 -1  0  0 -7 -4 -2  3  3 -1
48105 C -2 -4 -4 -5 12 -5 -5 -3 -3 -2 -6 -5 -5 -4 -3  0 -2 -8  0 -2 -4 -5 -3
48106 Q  0  1  1  2 -5  4  2 -1  3 -2 -2  1 -1 -5  0 -1 -1 -5 -4 -2  1  3 -1
48107 E  0 -1  1  3 -5  2  4  0  1 -2 -3  0 -2 -5 -1  0  0 -7 -4 -2  3  3 -1
48108 G  1 -3  0  1 -3 -1  0  5 -2 -3 -4 -2 -3 -5  0  1  0 -7 -5 -1  0  0 -1
48109 H -1  2  2  1 -3  3  1 -2  6 -2 -2  0 -2 -2  0 -1 -1 -3  0 -2  1  2 -1
48110 I -1 -2 -2 -2 -2 -2 -2 -3 -2  5  2 -2  2  1 -2 -1  0 -5 -1  4 -2 -2 -1
48111 L -2 -3 -3 -4 -6 -2 -3 -4 -2  2  6 -3  4  2 -3 -3 -2 -2 -1  2 -3 -3 -1
48112 K -1  3  1  0 -5  1  0 -2  0 -2 -3  5  0 -5 -1  0  0 -3 -4 -2  1  0 -1
48113 M -1  0 -2 -3 -5 -1 -2 -3 -2  2  4  0  6  0 -2 -2 -1 -4 -2  2 -2 -2 -1
48114 F -3 -4 -3 -6 -4 -5 -5 -5 -2  1  2 -5  0  9 -5 -3 -3  0  7 -1 -4 -5 -2
48115 P  1  0  0 -1 -3  0 -1  0  0 -2 -3 -1 -2 -5  6  1  0 -6 -5 -1 -1  0 -1
48116 S  1  0  1  0  0 -1  0  1 -1 -1 -3  0 -2 -3  1  2  1 -2 -3 -1  0  0  0
48117 T  1 -1  0  0 -2 -1  0  0 -1  0 -2  0 -1 -3  0  1  3 -5 -3  0  0 -1  0
48118 W -6  2 -4 -7 -8 -5 -7 -7 -3 -5 -2 -3 -4  0 -6 -2 -5 17  0 -6 -5 -6 -4
48119 Y -3 -4 -2 -4  0 -4 -4 -5  0 -1 -1 -4 -2  7 -5 -3 -3  0 10 -2 -3 -4 -2
48120 V  0 -2 -2 -2 -2 -2 -2 -1 -2  4  2 -2  2 -1 -1 -1  0 -6 -2  4 -2 -2 -1
48121 B  0 -1  2  3 -4  1  3  0  1 -2 -3  1 -2 -4 -1  0  0 -5 -3 -2  3  2 -1
48122 Z  0  0  1  3 -5  3  3  0  2 -2 -3  0 -2 -5  0  0 -1 -6 -4 -2  2  3 -1
48123 XX  0 -1  0 -1 -3 -1 -1 -1 -1 -1 -1 -1 -1 -2 -1  0  0 -4 -2 -1 -1 -1 -1
48124 X
48125 SHAR_EOF
48126 chmod 0644 pam250.mat ||
48127 echo 'restore of pam250.mat failed'
48128 Wc_c="`wc -c < 'pam250.mat'`"
48129 test 1923 -eq "$Wc_c" ||
48130         echo 'pam250.mat: original size 1923, current size' "$Wc_c"
48131 fi
48132 # ============= param.h ==============
48133 if test -f 'param.h' -a X"$1" != X"-c"; then
48134         echo 'x - skipping param.h (File already exists)'
48135 else
48136 echo 'x - extracting param.h (Text)'
48137 sed 's/^X//' << 'SHAR_EOF' > 'param.h' &&
48138 /* $Name: fa_34_26_5 $ - $Id: param.h,v 1.41 2007/04/26 18:37:19 wrp Exp $ */
48139 X
48140 X
48141 #ifndef P_STRUCT
48142 #define P_STRUCT
48143 X
48144 #define MAXSQ 50
48145 X
48146 X
48147 /* Concurrent read version */
48148 X
48149 struct fastr {
48150 X  int ktup;
48151 X  int cgap;
48152 X  int pgap;
48153 X  int pamfact;
48154 X  int scfact;
48155 X  int bestoff;
48156 X  int bestscale;
48157 X  int bkfact;
48158 X  int bktup;
48159 X  int bestmax;
48160 X  int altflag;
48161 X  int optflag;
48162 X  int iniflag;
48163 X  int optcut;
48164 X  int optcut_set;
48165 X  int optwid;
48166 };
48167 X
48168 struct prostr {
48169 X    int gopen;
48170 X    int gextend;
48171 X    int width;
48172 };
48173 X
48174 struct pstruct          /* parameters */
48175 {
48176 X  int n0;      /* length of query sequence, used for statistics */
48177 X  int gdelval; /* value gap open (-10) */
48178 X  int ggapval; /* value for additional residues in gap (-2) */
48179 X  int gshift;  /* frameshift for fastx, fasty */
48180 X  int gsubs;   /* nt substitution in fasty */
48181 X  int p_d_mat; /* dna match penalty */
48182 X  int p_d_mis; /* dna mismatch penalty */
48183 X  int p_d_set; /* using match/mismatch */
48184 X  int score_ix;        /* index to sorted score */
48185 X  int zsflag;  /* use scalebest() */
48186 X  int zsflag_f;        /* use scalebest() */
48187 X  int zs_win;
48188 X  int histint;         /* histogram interval */
48189 X  char sq[MAXSQ+1];
48190 X  int hsq[MAXSQ+1];
48191 X  int nsq;             /* length of normal sq */
48192 X  int ext_sq_set;      /* flag for using extended alphabet */
48193 X  char sqx[MAXSQ];
48194 X  int hsqx[MAXSQ+1];
48195 X  int c_nt[MAXSQ+1];
48196 X  int nsqx;    /* length of extended sq */
48197 X  int dnaseq;  /* -1 = not set (protein); 0 = protein; 1 = DNA; 2 = other, 3 RNA */
48198 X  int nt_align;        /* DNA/RNA alignment = 1 */
48199 X  int debug_lib;
48200 X  int tr_type; /* codon table */
48201 X  int sw_flag;
48202 X  char pamfile[120];   /* pam file type */
48203 X  char pgpfile[120];
48204 X  int pgpfile_type;
48205 X  float pamscale;
48206 X  int pam_pssm;
48207 X  int pam_set;
48208 X  int have_pam2;
48209 X  int **pam2[2];
48210 X  int **pam2p[2];
48211 X  int pamoff;  /* offset for pam values */
48212 X  int pam_l, pam_h, pam_xx, pam_xm;    /* lowest, highest pam value */
48213 X  int pam_x_set;
48214 X  int pam_ms;          /* use a Mass Spec pam matrix */
48215 X  int maxlen;
48216 X  long zdb_size; /* force database size */
48217 X  int pgm_id;
48218 X  union {
48219 X    struct fastr fa;
48220 X    struct prostr pr;
48221 X  } param_u;
48222 X  int pseudocts;
48223 X  int shuff_node;
48224 };
48225 X
48226 /* Result structure - do not remove */
48227 struct rstruct
48228 {
48229 X  int score[3];
48230 X  double comp;
48231 X  double H;
48232 X  double escore;
48233 X  int segnum;
48234 X  int seglen;
48235 };
48236 X
48237 #ifndef PCOMPLIB
48238 struct thr_str {
48239 X  int worker;
48240 X  void *status;
48241 X  int max_work_buf;
48242 X  int qframe;
48243 X  struct pstruct *ppst;
48244 X  int qshuffle;
48245 X  unsigned char *aa0;
48246 X  int n0;
48247 X  int nm0;
48248 X  int max_tot;
48249 };
48250 X
48251 #include <sys/types.h>
48252 X
48253 /* this structure passes library sequences to the worker threads
48254 X   and returns scores */
48255 X
48256 struct buf_str {
48257 X  int n1;
48258 X  int *n1tot_p;
48259 X  unsigned char *aa1b;
48260 #ifndef USE_FSEEKO
48261 X  long lseek;
48262 #else
48263 X  off_t lseek;
48264 #endif
48265 X  struct lmf_str *m_file_p;
48266 X  int cont;
48267 X  int qframe;
48268 X  int frame;
48269 X  int nsfnum;
48270 X  int sfnum[10];
48271 X  char libstr[20];     /* set to MAX_UID */
48272 X  struct rstruct rst;
48273 X  int r_score, qr_score;
48274 X  double r_escore, qr_escore;
48275 };
48276 X
48277 struct buf_head {
48278 X  int buf_cnt;
48279 X  int have_results;
48280 X  unsigned char *start;
48281 X  struct buf_str *buf;
48282 };
48283 X
48284 #endif
48285 X
48286 #endif  /* PSTRUCT */
48287 X
48288 #include "aln_structs.h"
48289 SHAR_EOF
48290 chmod 0644 param.h ||
48291 echo 'restore of param.h failed'
48292 Wc_c="`wc -c < 'param.h'`"
48293 test 3002 -eq "$Wc_c" ||
48294         echo 'param.h: original size 3002, current size' "$Wc_c"
48295 fi
48296 # ============= pgsql_lib.c ==============
48297 if test -f 'pgsql_lib.c' -a X"$1" != X"-c"; then
48298         echo 'x - skipping pgsql_lib.c (File already exists)'
48299 else
48300 echo 'x - extracting pgsql_lib.c (Text)'
48301 sed 's/^X//' << 'SHAR_EOF' > 'pgsql_lib.c' &&
48302 X
48303 /* pgsql_lib.c copyright (c) 2004 William R. Pearson */
48304 X
48305 /* $Name: fa_34_26_5 $ - $Id: pgsql_lib.c,v 1.3 2006/04/12 18:00:02 wrp Exp $ */
48306 X
48307 /* functions for opening, reading, seeking a pgsql database */
48308 X
48309 /*
48310 X  For the moment, this interface assumes that the file to be searched will
48311 X  be specified in a single, long, string with 4 parts:
48312 X
48313 X  (1) a database open string. This string has four fields, separated by
48314 X      whitespace (' \t'):
48315 X        hostname:port dbname user password
48316 X
48317 X   '--' dashes at the beginning of lines are ignored -
48318 X   thus the first line could be:
48319 X   -- hostname:port dbname user password
48320 X
48321 X  (2) a database query string that will return an unique ID (not
48322 X      necessarily numberic, but it must be < 12 characters as libstr[12]
48323 X      is used) and a sequence string
48324 X
48325 X  (2a) a series of pgsql commands that do not generate results
48326 X       starting with 'DO', followed by a select() statement.
48327 X
48328 X  (3) a database select string that will return a description
48329 X      given a unique ID
48330 X
48331 X  (4) a database select string that well return a sequence given a
48332 X      unique ID
48333 X
48334 X   Lines (3) and (4) are not required for pv34comp* libraries, but
48335 X   line (2) must generate a complete description as well as a sequence.
48336 X
48337 X
48338 X   18-July-2001
48339 X   Additional syntax has been added to support multiline SQL queries.
48340 X
48341 X   If the host line begins with '+', then the SQL is openned on the same
48342 X   connection as the previous SQL file.
48343 X
48344 X   If the host line contains '-' just before the terminal ';', then
48345 X   the file will not produce any output.
48346 X
48347 X   This string can contain "\n". ";" are used to separate the four
48348 X   functions, which must be specified in the order shown above.
48349 X   The last (fourth) query must terminate with a ';'
48350 X
48351 X   19-July-2004
48352 X
48353 X   This file is designed for PostgreSQL, which uses a different syntax
48354 X   for getting rows of data.  Specifically, a select statement must be
48355 X   associated with a "cursor", so that one can fetch a single row.
48356 X
48357 X   This can be simply done with the statment:
48358 X
48359 X   DECLARE next_seq CURSOR FOR "select statement ..."
48360 X
48361 X   The need for a CURSOR complicates the getlib()/ranlib() design, which
48362 X   assumes that ranlib() can set something up that getlib() can read.
48363 X   This can be avoided by setting up an otherwise unnecessary cursor for
48364 X   the ranlib statement that gets a sequence.
48365 X
48366 */
48367 X
48368 #include <stdio.h>
48369 #include <stdlib.h>
48370 #include <string.h>
48371 #include <ctype.h>
48372 X
48373 #include <libpq-fe.h>
48374 #define PGSQL_LIB 17
48375 X
48376 #include "defs.h"
48377 #include "mm_file.h"
48378 X
48379 #define XTERNAL
48380 #include "uascii.h"
48381 #define EOSEQ 0
48382 /* #include "upam.h" */
48383 X
48384 #ifdef SUPERFAMNUM
48385 int sfnum[10], nsfnum;
48386 #endif
48387 X
48388 int pgsql_getlib(unsigned char *, int, char *, int, fseek_t *, int *, struct lmf_str *, long *);
48389 void pgsql_ranlib(char *, int, fseek_t, char *, struct lmf_str *m_fd);
48390 X
48391 #define PGSQL_BUF 4096
48392 X
48393 struct lmf_str *
48394 pgsql_openlib(char *sname, int ldnaseq, int *sascii) {
48395 X  FILE *sql_file;
48396 X  PGconn *conn;
48397 X  PGresult *res;
48398 X  char *tmp_str, *ttmp_str;
48399 X  int tmp_str_len;
48400 X  char *bp, *bps, *bdp, *tp, tchar;
48401 X  int i, qs_len, qqs_len;
48402 X  char *sql_db, *sql_host, *sql_dbname, *sql_user, *sql_pass;
48403 X  char *sql_port;
48404 X  char *sql_do;
48405 X  int sql_do_cnt;
48406 X  struct lmf_str *m_fptr;
48407 X
48408 X  /*  if (sql_reopen) return NULL; - should not be called for re-open */
48409 X
48410 X  tmp_str_len = PGSQL_BUF;
48411 X  if ((tmp_str=(char *)calloc(tmp_str_len,sizeof(char)))==NULL) {
48412 X    fprintf(stderr,"cannot allocate %d for pgSQL buffer\n",tmp_str_len);
48413 X    return NULL;
48414 X  }
48415 X
48416 X  if (sname[0] == '%') {
48417 X    strncpy(tmp_str,sname+1,tmp_str_len);
48418 X    tmp_str[sizeof(tmp_str)-1]='\0';
48419 X  }
48420 X  else {
48421 X    if ((sql_file=fopen(sname,"r"))==NULL) {
48422 X      fprintf(stderr," cannot open pgSQL file: %s\n",sname);
48423 X      return NULL;
48424 X    }
48425 X
48426 X    if ((qs_len=fread(tmp_str,sizeof(char),tmp_str_len-1,sql_file))<=0) {
48427 X      fprintf(stderr," cannot read pgSQL file: %s\n",sname);
48428 X      return NULL;
48429 X    }
48430 X    else  {
48431 X      tmp_str[qs_len]='\0';
48432 X      qqs_len = qs_len;
48433 X      while (qqs_len >= tmp_str_len-1) {
48434 X       tmp_str_len += PGSQL_BUF;
48435 X       if ((tmp_str=(char *)realloc(tmp_str,tmp_str_len))==NULL) {
48436 X         fprintf(stderr,
48437 X                 " cannot reallocate %d for pgSQL buffer\n",tmp_str_len);
48438 X         return NULL;
48439 X       }
48440 X       ttmp_str = &tmp_str[qqs_len];
48441 X       if ((qs_len=fread(ttmp_str,sizeof(char),PGSQL_BUF,sql_file))<0) {
48442 X         fprintf(stderr," cannot read pgSQL file: %s\n",sname);
48443 X         return NULL;
48444 X       }
48445 X       ttmp_str[qs_len]='\0';
48446 X       qqs_len += qs_len;
48447 X      }
48448 X    }
48449 X    fclose(sql_file);
48450 X  }
48451 X
48452 X  bps = tmp_str;
48453 X  if ((bp=strchr(bps,';'))!=NULL) {
48454 X    *bp='\0';
48455 X    if ((sql_db=calloc(strlen(bps)+1,sizeof(char)))==NULL) {
48456 X      fprintf(stderr, " cannot allocate space for database name [%d], %s\n",
48457 X             strlen(bps),bps);
48458 X      return NULL;
48459 X    }
48460 X    /* have database name, parse the fields */
48461 X    else {
48462 X      strcpy(sql_db,bps);      /* strcpy OK because allocated strlen(bps) */
48463 X      bps = bp+1;      /* points to next char after ';' */
48464 X      while (isspace(*bps)) bps++;
48465 X      *bp=';'; /* replace ; */
48466 X      bp = sql_db;
48467 X      while (*bp=='-') {*bp++ = ' ';}
48468 X      sql_host = strtok(bp," \t\n");
48469 X      if (sql_host[0]=='@') sql_host="";
48470 X      sql_dbname = strtok(NULL," \t\n");
48471 X      sql_user = strtok(NULL," \t\n");
48472 X      if (sql_user[0]=='@') sql_user="";
48473 X      sql_pass = strtok(NULL," \t\n");
48474 X      if (sql_pass[0]=='@') sql_pass="";
48475 X      if ((tp=strchr(sql_host,':'))!=NULL) {
48476 X       sql_port = tp+1;
48477 X       *tp='\0';
48478 X      }
48479 X      else sql_port = "";
48480 X    }
48481 X  }
48482 X  else {
48483 X    fprintf(stderr," cannot find database fields:\n%s\n",tmp_str);
48484 X    return NULL;
48485 X  }
48486 X
48487 X  /* we have all the info we need to open a database, allocate lmf_str */
48488 X  if ((m_fptr = (struct lmf_str *)calloc(1,sizeof(struct lmf_str)))==NULL) {
48489 X    fprintf(stderr," cannot allocate lmf_str (%ld) for %s\n",
48490 X           sizeof(struct lmf_str),sname);
48491 X    return NULL;
48492 X  }
48493 X
48494 X  /* have our struct, initialize it */
48495 X
48496 X  strncpy(m_fptr->lb_name,sname,MAX_FN);
48497 X  m_fptr->lb_name[MAX_FN-1]='\0';
48498 X
48499 X  m_fptr->sascii = sascii;
48500 X
48501 X  m_fptr->sql_db = sql_db;
48502 X  m_fptr->getlib = pgsql_getlib;
48503 X  m_fptr->ranlib = pgsql_ranlib;
48504 X  m_fptr->mm_flg = 0;
48505 X  m_fptr->sql_reopen = 0;
48506 X  m_fptr->lb_type = PGSQL_LIB;
48507 X
48508 X  /* now open the database, if necessary */
48509 X  conn = PQsetdbLogin(sql_host,
48510 X                     sql_port,
48511 X                     NULL,
48512 X                     NULL,
48513 X                     sql_dbname,
48514 X                     sql_user,
48515 X                     sql_pass);
48516 X
48517 X  if (PQstatus(conn) != CONNECTION_OK)     {
48518 X    fprintf(stderr, "Connection to database '%s' failed.\n", PQdb(conn));
48519 X    fprintf(stderr, "%s", PQerrorMessage(conn));
48520 X    PQfinish(conn);
48521 X    goto error_r;
48522 X  }
48523 X  else {
48524 X    m_fptr->pgsql_conn = conn;
48525 X    fprintf(stderr," Database %s opened on %s\n",sql_dbname,sql_host);
48526 X  }
48527 X
48528 X  /* check for 'DO' command - copy to 'DO' string */
48529 X  while (*bps == '-') { *bps++=' ';}
48530 X  if (isspace(bps[-1]) && toupper(bps[0])=='D' &&
48531 X      toupper(bps[1])=='O' && isspace(bps[2])) {
48532 X    /* have some 'DO' commands */
48533 X    /* check where the end of the last DO statement is */
48534 X
48535 X    sql_do_cnt = 1;    /* count up the number of 'DO' statements for later */
48536 X    bdp=bps+3;
48537 X    while ((bp=strchr(bdp,';'))!=NULL) {
48538 X      tp = bp+2; /* skip ;\n */
48539 X      while (isspace(*tp) || *tp == '-') {*tp++ = ' ';}
48540 X      if (toupper(*tp)=='D' && toupper(tp[1])=='O' && isspace(tp[2])) {
48541 X       sql_do_cnt++;           /* count the DO statements */
48542 X       bdp = tp+3;             /* move to the next DO statement */
48543 X      }
48544 X      else break;
48545 X    }
48546 X    if (bp != NULL) {  /* end of the last DO, begin of select */
48547 X      tchar = *(bp+1);
48548 X      *(bp+1)='\0';            /* terminate DO strings */
48549 X      if ((sql_do = calloc(strlen(bps)+1, sizeof(char)))==NULL) {
48550 X       fprintf(stderr," cannot allocate %d for sql_do\n",strlen(bps));
48551 X       goto error_r;
48552 X      }
48553 X      else {
48554 X       strcpy(sql_do,bps);
48555 X       *(bp+1)=tchar;  /* replace missing ';' */
48556 X      }
48557 X      bps = bp+1;
48558 X      while (isspace(*bps)) bps++;
48559 X    }
48560 X    else {
48561 X      fprintf(stderr," terminal ';' not found: %s\n",bps);
48562 X      goto error_r;
48563 X    }
48564 X    /* all the DO commands are in m_fptr->sql_do in the form: 
48565 X     DO command1; DO command2; DO command3; */
48566 X    bdp = sql_do;
48567 X    while (sql_do_cnt-- && (bp=strchr(bdp,';'))!=NULL) {
48568 X      /* do the pgsql statement on bdp+3 */
48569 X      /* check for error */
48570 X      *bp='\0';
48571 X      res = PQexec(m_fptr->pgsql_conn,bdp+3);
48572 X      if (PQresultStatus(res) != PGRES_COMMAND_OK) {
48573 X       fprintf(stderr,"*** Error %s - query failed:\n%s\n",
48574 X               PQerrorMessage(m_fptr->pgsql_conn), bdp+3);
48575 X       PQclear(res);
48576 X       goto error_r;
48577 X      }
48578 X      PQclear(res);
48579 X
48580 X      *bp=';';
48581 X      bdp = bp+1;
48582 X      while (isspace(*bdp)) bdp++;
48583 X    }
48584 X  }
48585 X
48586 X  /* copy 1st query field */
48587 X  if ((bp=strchr(bps,';'))!=NULL) {
48588 X    *bp='\0';
48589 X    if ((m_fptr->sql_query=calloc(strlen(bps)+41,sizeof(char)))==NULL) {
48590 X      fprintf(stderr, " cannot allocate space for query string [%d], %s\n",
48591 X             strlen(bps),bps);
48592 X      goto error_r;
48593 X    }
48594 X    /* have query, copy it */
48595 X    else {
48596 X      strncpy(m_fptr->sql_query,"DECLARE next_seq CURSOR FOR ",40);
48597 X      strcat(m_fptr->sql_query,bps);
48598 X      *bp=';'; /* replace ; */
48599 X      bps = bp+1;
48600 X      while(isspace(*bps)) bps++;
48601 X    }
48602 X  }
48603 X  else {
48604 X    fprintf(stderr," cannot find database query field:\n%s\n",tmp_str);
48605 X    goto error_r;
48606 X  }
48607 X
48608 X  /* copy get_desc field */
48609 X  if ((bp=strchr(bps,';'))!=NULL) {
48610 X    *bp='\0';
48611 X    if ((m_fptr->sql_getdesc=calloc(strlen(bps)+1,sizeof(char)))==NULL) {
48612 X      fprintf(stderr, " cannot allocate space for database name [%d], %s\n",
48613 X             strlen(bps),bps);
48614 X      goto error_r;
48615 X    }
48616 X    /* have get_desc, copy it */
48617 X    else {
48618 X      strcpy(m_fptr->sql_getdesc,bps);
48619 X      *bp=';'; /* replace ; */
48620 X      bps = bp+1;
48621 X      while(isspace(*bps)) bps++;
48622 X    }
48623 X  }
48624 X  else {
48625 X    fprintf(stderr," cannot find getdesc field:\n%s\n",tmp_str);
48626 X    goto error_r;
48627 X  }
48628 X
48629 X  if ((bp=strchr(bps,';'))!=NULL) { *bp='\0';}
48630 X
48631 X  if ((m_fptr->sql_getseq=calloc(strlen(bps)+1,sizeof(char)))==NULL) {
48632 X    fprintf(stderr, " cannot allocate space for database name [%d], %s\n",
48633 X           strlen(bps),bps);
48634 X    goto error_r;
48635 X  }
48636 X
48637 X  if (strlen(bps) > 0) {
48638 X    strcpy(m_fptr->sql_getseq,bps);
48639 X  }
48640 X  else {
48641 X    fprintf(stderr," cannot find getseq field:\n%s\n",tmp_str);
48642 X    return NULL;
48643 X  }
48644 X  if (bp!=NULL) *bp=';';
48645 X
48646 X  /* now do the fetch */
48647 X
48648 X  res = PQexec(m_fptr->pgsql_conn,"BEGIN;");
48649 X  if (PQresultStatus(res) != PGRES_COMMAND_OK) {
48650 X    fprintf(stderr,"*** Error %s - BEGIN failed:\n",
48651 X           PQerrorMessage(conn));
48652 X    PQclear(res);
48653 X    goto error_r;
48654 X  }
48655 X  PQclear(res);
48656 X
48657 X  res = PQexec(m_fptr->pgsql_conn, m_fptr->sql_query);
48658 X  if (PQresultStatus(res) != PGRES_COMMAND_OK) {
48659 X    fprintf(stderr,"*** Error %d:%s - query failed:\n%s\n",
48660 X           PQresultStatus(res),PQerrorMessage(conn), m_fptr->sql_query);
48661 X    PQclear(res);
48662 X    goto error_r;
48663 X  }
48664 X  PQclear(res);
48665 X  m_fptr->pgsql_res=NULL;
48666 X
48667 X  return m_fptr;
48668 X
48669 X error_r:
48670 X  free(m_fptr->sql_getseq);
48671 X  free(m_fptr->sql_getdesc);
48672 X  free(m_fptr->sql_query);
48673 X  free(m_fptr);
48674 X  free(sql_db);
48675 X  return NULL;
48676 }
48677 X
48678 struct lmf_str *
48679 pgsql_reopen(struct lmf_str *m_fptr) {
48680 X  m_fptr->sql_reopen = 1;
48681 X  return m_fptr;
48682 }
48683 X
48684 void
48685 pgsql_closelib(struct lmf_str *m_fptr) {
48686 X
48687 X  if (m_fptr == NULL) return;
48688 X  if (m_fptr->pgsql_res != NULL) PQclear(m_fptr->pgsql_res);
48689 X  PQfinish(m_fptr->pgsql_conn);
48690 X  m_fptr->sql_reopen=0;
48691 }
48692 X
48693 /*
48694 static char *sql_seq = NULL, *sql_seqp;
48695 static int sql_seq_len;
48696 */
48697 X
48698 int
48699 pgsql_getlib( unsigned char *seq,
48700 X             int maxs,
48701 X             char *libstr,
48702 X             int n_libstr,
48703 X             fseek_t *libpos,
48704 X             int *lcont,
48705 X             struct lmf_str *lm_fd,
48706 X             long *l_off)
48707 {
48708 X  register unsigned char *cp, *seqp;
48709 X  register int *ap;
48710 X  unsigned char *seqm, *seqm1;
48711 X  PGresult *res;
48712 X
48713 X  char *bp;
48714 X  /*   int l_start, l_stop, len; */
48715 X
48716 X  seqp = seq;
48717 X  seqm = &seq[maxs-9];
48718 X  seqm1 = seqm-1;
48719 X
48720 X  ap = lm_fd->sascii;
48721 X
48722 #ifdef SUPERFAMNUM
48723 X  sfnum[0]=nsfnum = 0;
48724 #endif
48725 X
48726 X  if (*lcont==0) {
48727 X    /* get a row, with UID, sequence */
48728 X    *l_off = 1;
48729 X
48730 X    /* check to see if we already have a valid result */
48731 X    if (lm_fd->pgsql_res==NULL) {
48732 X      res = PQexec(lm_fd->pgsql_conn,"FETCH next_seq");
48733 X      if (PQresultStatus(res) != PGRES_TUPLES_OK) {
48734 X       fprintf(stderr,"*** Error %s - getlib FETCH failed:\n%s\n",
48735 X               PQerrorMessage(lm_fd->pgsql_conn), lm_fd->sql_query);
48736 X       PQclear(res);
48737 X       lm_fd->pgsql_res = NULL;
48738 X       *lcont = 0;
48739 X       *seqp = EOSEQ;
48740 X       return -1;
48741 X      }
48742 X    }
48743 X    else {res = lm_fd->pgsql_res;}
48744 X
48745 X    if (PQntuples(res)>0) {
48746 X      lm_fd->pgsql_res = res;
48747 X      *libpos=(fseek_t)atol(PQgetvalue(res,0,0));
48748 X       
48749 X      *l_off = 1;
48750 X      if (PQnfields(res) > 2 && (bp=strchr(PQgetvalue(res,0,2),'@'))!=NULL &&
48751 X         !strncmp(bp+1,"C:",2)) sscanf(bp+3,"%ld",l_off);
48752 X
48753 X      lm_fd->sql_seqp = PQgetvalue(res,0,1);
48754 X    
48755 X      /* because of changes in pgsql_ranlib(), it is essential that
48756 X         libstr return the unique identifier; thus we must use
48757 X         sql_row[0], not sql_row[2]. Using libstr as the UID allows
48758 X         one to use any UID, not just numeric ones.  *libpos is not
48759 X         used for pgsql libraries.
48760 X      */
48761 X
48762 X      if (n_libstr <= MAX_UID) {
48763 X       /* the normal case returns only GID/sequence */
48764 X       strncpy(libstr,PQgetvalue(res,0,0),MAX_UID-1);
48765 X       libstr[MAX_UID-1]='\0';
48766 X      }
48767 X      else {
48768 X       /* here we do not use the UID in libstr, because we are not
48769 X           going back into the db */
48770 X       /* the PVM case also returns a long description */
48771 X       if (PQnfields(res)>2) {
48772 X         strncpy(libstr,PQgetvalue(res,0,2),n_libstr-1);
48773 X       }
48774 X       else {
48775 X         strncpy(libstr,PQgetvalue(res,0,0),n_libstr-1);
48776 X       }
48777 X       libstr[n_libstr-1]='\0';
48778 X      }
48779 X    }
48780 X    else {
48781 X      PQclear(lm_fd->pgsql_res);
48782 X      lm_fd->pgsql_res=NULL;
48783 X      *lcont = 0;
48784 X      *seqp = EOSEQ;
48785 X      return -1;
48786 X    }
48787 X  }
48788 X
48789 X  for (cp=(unsigned char *)lm_fd->sql_seqp; seqp<seqm1 && *cp; ) {
48790 X    if ((*seqp++=ap[*cp++])<NA &&
48791 X       (*seqp++=ap[*cp++])<NA &&
48792 X       (*seqp++=ap[*cp++])<NA &&
48793 X       (*seqp++=ap[*cp++])<NA &&
48794 X       (*seqp++=ap[*cp++])<NA &&
48795 X       (*seqp++=ap[*cp++])<NA &&
48796 X       (*seqp++=ap[*cp++])<NA &&
48797 X       (*seqp++=ap[*cp++])<NA &&
48798 X       (*seqp++=ap[*cp++])<NA &&
48799 X       (*seqp++=ap[*cp++])<NA) continue;
48800 X    --seqp;
48801 X    if (*(cp-1)==0) break;
48802 X  }
48803 X  lm_fd->sql_seqp = (char *)cp;
48804 X
48805 X  if (seqp>=seqm1) (*lcont)++;
48806 X  else {
48807 X    *lcont=0;
48808 X    PQclear(lm_fd->pgsql_res);
48809 X    lm_fd->pgsql_res = NULL;
48810 X  }
48811 X
48812 X  *seqp = EOSEQ;
48813 X  /*   if ((int)(seqp-seq)==0) return 1; */
48814 X  return (int)(seqp-seq);
48815 }
48816 X
48817 void
48818 pgsql_ranlib(char *str,
48819 X            int cnt,
48820 X            fseek_t libpos,
48821 X            char *libstr,
48822 X            struct lmf_str *lm_fd
48823 X            )
48824 {
48825 X  char tmp_query[1024], tmp_val[20];
48826 X  PGresult *res;
48827 X  char *bp;
48828 X
48829 X  str[0]='\0';
48830 X
48831 X  /* put the UID into the query string - cannot use sprintf because of
48832 X     "%' etc */
48833 X
48834 X  /*   sprintf(tmp_query,lm_fd->sql_getdesc,libpos); */
48835 X
48836 X  if ((bp=strchr(lm_fd->sql_getdesc,'#'))==NULL) {
48837 X    fprintf(stderr, "no KEY position in %s\n",lm_fd->sql_getdesc);
48838 X    goto next1;
48839 X  }
48840 X  else {
48841 X    *bp = '\0';
48842 X    strncpy(tmp_query,lm_fd->sql_getdesc,sizeof(tmp_query));
48843 X    tmp_query[sizeof(tmp_query)-1]='\0';
48844 X    /*    sprintf(tmp_val,"%ld",(long)libpos); */
48845 X    strncat(tmp_query,libstr,sizeof(tmp_query)-1);
48846 X    strncat(tmp_query,bp+1,sizeof(tmp_query)-1);
48847 X    *bp='#';
48848 X    lm_fd->lpos = libpos;
48849 X  }
48850 X
48851 X  /*  fprintf(stderr," requesting: %s\n",tmp_query); */
48852 X
48853 X  if (lm_fd->pgsql_res !=NULL) {
48854 X    PQclear(lm_fd->pgsql_res);
48855 X    lm_fd->pgsql_res = NULL;
48856 X  }
48857 X
48858 X  res = PQexec(lm_fd->pgsql_conn,tmp_query);
48859 X  if (PQresultStatus(res) != PGRES_TUPLES_OK) {
48860 X    lm_fd->pgsql_res = NULL;
48861 X
48862 X    sprintf(str,"gi|%ld ***Error - query failed***",(long)libpos);
48863 X    fprintf(stderr,"*** Error %s - ranlib DESC failed:\n%s\n",
48864 X           PQerrorMessage(lm_fd->pgsql_conn), tmp_query);
48865 X    PQclear(res);
48866 X    goto next1;
48867 X  }
48868 X
48869 X  if (PQntuples(res)<=0) {
48870 /*     fprintf(stderr,"*** Error = use result failed\n%s\n", 
48871 X          pgsql_error(lm_fd->pgsql_conn)); */
48872 X    sprintf(str,"gi|%ld ***use result failed***",(long)libpos);
48873 X    goto next0;
48874 X  }
48875 X
48876 X  if (PQgetvalue(res,0,1)!= NULL) strncpy(str,PQgetvalue(res,0,1),cnt-1);
48877 X  else strncpy(str,PQgetvalue(res,0,0),cnt-1);
48878 X  str[cnt-1]='\0';
48879 X  /* change this later to support multiple row returns */
48880 X  /*
48881 X  while (strlen(str) < cnt-1 &&
48882 X        (lm_fd->sql_row = pgsql_fetch_row(lm_fd->pgsql_res))!=NULL) {
48883 X    strncat(str," ",cnt-2-strlen(str));
48884 X    if (lm_fd->sql_row[1]!=NULL) 
48885 X      strncat(str,lm_fd->sql_row[1],cnt-2-strlen(str));
48886 X    else break;
48887 X  }
48888 X  */
48889 X
48890 X  str[cnt-1]='\0';
48891 X  if ((bp = strchr(str,'\r'))!=NULL) *bp='\0';
48892 X  if ((bp = strchr(str,'\n'))!=NULL) *bp='\0';
48893 X
48894 X next0:
48895 X  PQclear(res);
48896 X next1: 
48897 X  lm_fd->pgsql_res = NULL;
48898 X
48899 X  /* get the sequence, set up for pgsql_getseq() */
48900 X  /* put the UID into the query string */
48901 X
48902 X  if ((bp=strchr(lm_fd->sql_getseq,'#'))==NULL) {
48903 X    fprintf(stderr, "no GID position in %s\n",lm_fd->sql_getseq);
48904 X    return;
48905 X  }
48906 X  else {
48907 X    *bp = '\0';
48908 X    strncpy(tmp_query,lm_fd->sql_getseq,sizeof(tmp_query));
48909 X    tmp_query[sizeof(tmp_query)-1]='\0';
48910 X    /*    sprintf(tmp_val,"%ld",(long)libpos); */
48911 X    strncat(tmp_query,libstr,sizeof(tmp_query));
48912 X    strncat(tmp_query,bp+1,sizeof(tmp_query));
48913 X    *bp='#';
48914 X  }
48915 X
48916 X  res = PQexec(lm_fd->pgsql_conn,tmp_query);
48917 X  if (PQresultStatus(res) != PGRES_TUPLES_OK) {
48918 X    PQclear(res);
48919 X    lm_fd->pgsql_res = NULL;
48920 X    fprintf(stderr,"*** Error - ranlib SEQ failed:\n%s\n%s\n",tmp_query,
48921 X           PQerrorMessage(lm_fd->pgsql_conn));
48922 X    exit(1);
48923 X  }
48924 X  else {
48925 X    lm_fd->pgsql_res = res;
48926 X  }
48927 }
48928 SHAR_EOF
48929 chmod 0644 pgsql_lib.c ||
48930 echo 'restore of pgsql_lib.c failed'
48931 Wc_c="`wc -c < 'pgsql_lib.c'`"
48932 test 16978 -eq "$Wc_c" ||
48933         echo 'pgsql_lib.c: original size 16978, current size' "$Wc_c"
48934 fi
48935 # ============= pirpsd.sql ==============
48936 if test -f 'pirpsd.sql' -a X"$1" != X"-c"; then
48937         echo 'x - skipping pirpsd.sql (File already exists)'
48938 else
48939 echo 'x - extracting pirpsd.sql (Text)'
48940 sed 's/^X//' << 'SHAR_EOF' > 'pirpsd.sql' &&
48941 xdb.wrplab PIRPSD seq_demo demo_pass;
48942 SELECT PIRID, SEQUENCES, PIRID
48943 X FROM c_psdsequence;
48944 SELECT PIRID, concat(PIRID," ",TITLE) FROM c_psdmain
48945 X WHERE PIRID='#';
48946 SELECT PIRID, SEQUENCES, PIRID
48947 X FROM c_psdsequence
48948 X WHERE PIRID='#';
48949 SHAR_EOF
48950 chmod 0644 pirpsd.sql ||
48951 echo 'restore of pirpsd.sql failed'
48952 Wc_c="`wc -c < 'pirpsd.sql'`"
48953 test 230 -eq "$Wc_c" ||
48954         echo 'pirpsd.sql: original size 230, current size' "$Wc_c"
48955 fi
48956 # ============= print_pssm.c ==============
48957 if test -f 'print_pssm.c' -a X"$1" != X"-c"; then
48958         echo 'x - skipping print_pssm.c (File already exists)'
48959 else
48960 echo 'x - extracting print_pssm.c (Text)'
48961 sed 's/^X//' << 'SHAR_EOF' > 'print_pssm.c' &&
48962 /* print_pssm.c - 21-Jan-2005 
48963 X
48964 X   copyright (c) 2005 - William R. Pearson and the University of Virginia
48965 X
48966 X   read a binary PSSM checkpoint file from blastpgp, and produce an ascii
48967 X   formatted file
48968 */
48969 X
48970 #include <stdio.h>
48971 #include <stdlib.h>
48972 #include <sys/types.h>
48973 #include <math.h>
48974 #include <string.h>
48975 X
48976 #include "defs.h"
48977 #include "mm_file.h"
48978 #include "param.h"
48979 X
48980 #include "uascii.h"
48981 #include "upam.h"
48982 X
48983 void initenv(int, char **, struct pstruct *, char *);
48984 void read_pssm();
48985 void alloc_pam();
48986 int **alloc_pam2p();
48987 void initpam2();
48988 void fill_pam();
48989 double get_lambda();
48990 X
48991 extern int optind;
48992 extern char *optarg;
48993 X
48994 main(int argc, char **argv) {
48995 X
48996 X  char *aa0;
48997 X  char libstr[MAX_FN];
48998 X  char qname[MAX_FN];
48999 X  int sq0off;
49000 X  int i, n0;
49001 X  FILE *fp;
49002 X  struct pstruct pst, *ppst;
49003 X
49004 X  /* stuff from initfa.c/h_init() */
49005 X
49006 X  memcpy(qascii,aascii,sizeof(qascii));
49007 X
49008 X  /* initialize a pam matrix */
49009 X  ppst = &pst;
49010 X  strncpy(ppst->pamfile,"BL50",MAX_FN);
49011 X  standard_pam(ppst->pamfile,ppst,0,0);
49012 X
49013 X  /* this is always protein by default */
49014 X  ppst->nsq = naa;
49015 X  ppst->nsqx = naax;
49016 X  for (i=0; i<=ppst->nsqx; i++) {
49017 X    ppst->sq[i] = aa[i];
49018 X    ppst->hsq[i] = haa[i];
49019 X    ppst->sqx[i]=aax[i];       /* sq = aa */
49020 X    ppst->hsqx[i]=haax[i];     /* hsq = haa */
49021 X  }
49022 X  ppst->sq[ppst->nsqx+1] = ppst->sqx[ppst->nsqx+1] = '\0';
49023 X
49024 X  if ((aa0 = calloc(MAXTST,sizeof(char)))==NULL) {
49025 X    fprintf(stderr,"Cannot allocate aa0\n");
49026 X    exit(1);
49027 X  }
49028 X
49029 X  initenv(argc, argv, &pst, qname);
49030 X  alloc_pam(pst.nsq+1,pst.nsq+1, &pst);
49031 X  initpam2(&pst);
49032 X
49033 X  n0 = getseq (qname, qascii, aa0, MAXTST, libstr,&sq0off);
49034 X
49035 X  if (!pst.pam_pssm) {
49036 X    fprintf(stderr," ** ERROR ** No -P PSSM provided\n");
49037 X  }
49038 X  else {
49039 X    ppst->pam2p[0] = alloc_pam2p(n0,pst.nsq);
49040 X    ppst->pam2p[1] = alloc_pam2p(n0,pst.nsq);
49041 X    if ((fp = fopen(pst.pgpfile,"rb"))!=NULL) {
49042 X      read_pssm(aa0, n0, pst.nsq, pst.pamscale,fp,ppst);
49043 X    }
49044 X  }
49045 }
49046 X
49047 void
49048 initenv(int argc, char **argv, struct pstruct *ppst, char *qname) {
49049 X  char copt;
49050 X
49051 X  pascii = aascii;
49052 X
49053 X  while ((copt = getopt(argc, argv, "P:s:"))!=EOF) {
49054 X    switch (copt) {
49055 X      case 'P':
49056 X       strncpy(ppst->pgpfile,optarg,MAX_FN);
49057 X       ppst->pgpfile[MAX_FN-1]='\0';
49058 X       ppst->pam_pssm = 1;
49059 X       break;
49060 X
49061 X      case 's':
49062 X       strncpy (ppst->pamfile, optarg, 120);
49063 X       ppst->pamfile[120-1]='\0';
49064 X       if (!standard_pam(ppst->pamfile,ppst,0, 0)) {
49065 X         initpam (ppst->pamfile, ppst);
49066 X       }
49067 X       ppst->pam_set=1;
49068 X       break;
49069 X    }
49070 X  }
49071 X  optind--;
49072 X
49073 X  if (argc - optind > 1) strncpy(qname, argv[optind+1], MAX_FN);
49074 }
49075 X
49076 X
49077 /*
49078 X   *aa0 - query sequence
49079 X   n0   - length
49080 X   pamscale - scaling for pam matrix - provided by apam.c, either
49081 X              0.346574 = ln(2)/2 (P120, BL62) or
49082 X             0.231049 = ln(2)/3 (P250, BL50) 
49083 */
49084 X
49085 #define N_EFFECT 20
49086 X
49087 void
49088 read_pssm(unsigned char *aa0, int n0, int nsq, double pamscale, FILE *fp, struct pstruct *ppst) {
49089 X  int i, j, len;
49090 X  int qi, rj;
49091 X  int **pam2p;
49092 X  int first, too_high;
49093 X  char *query;
49094 X  double freq, **freq2d, lambda, new_lambda;
49095 X  double scale, scale_high, scale_low;
49096 X
49097 X  pam2p = ppst->pam2p[0];
49098 X
49099 X  if(1 != fread(&len, sizeof(int), 1, fp)) {
49100 X    fprintf(stderr, "error reading from checkpoint file: %d\n", len);
49101 X    exit(1);
49102 X  }
49103 X
49104 X  if(len != n0) {
49105 X    fprintf(stderr, "profile length (%d) and query length (%d) don't match!\n",
49106 X           len,n0);
49107 X    exit(1);
49108 X  }
49109 X
49110 X  /* read over query sequence stored in BLAST profile */
49111 X  if(NULL == (query = (char *) calloc(len, sizeof(char)))) {
49112 X    fprintf(stderr, "Couldn't allocate memory for query!\n");
49113 X    exit(1);
49114 X  }
49115 X
49116 X  if(len != fread(query, sizeof(char), len, fp)) {
49117 X    fprintf(stderr, "Couldn't read query sequence from profile: %s\n", query);
49118 X    exit(1);
49119 X  }
49120 X
49121 X  printf("%d\n%s\n",len,query);
49122 X
49123 X  /* currently we don't do anything with query; ideally, we should
49124 X     check to see that it actually matches aa0 ... */
49125 X
49126 X  /* quick 2d array alloc: */
49127 X  if((freq2d = (double **) calloc(n0, sizeof(double *))) == NULL) {
49128 X    fprintf(stderr, "Couldn't allocate memory for frequencies!\n");
49129 X    exit(1);
49130 X  }
49131 X
49132 X  if((freq2d[0] = (double *) calloc(n0 * N_EFFECT, sizeof(double))) == NULL) {
49133 X    fprintf(stderr, "Couldn't allocate memory for frequencies!\n");
49134 X    exit(1);
49135 X  }
49136 X
49137 X  /* a little pointer arithmetic to fill out 2d array: */
49138 X  for (qi = 1 ; qi < n0 ; qi++) {
49139 X    freq2d[qi] = freq2d[0] + (N_EFFECT * qi);
49140 X  }
49141 X
49142 X  for (qi = 0 ; qi < n0 ; qi++) {
49143 X    printf("%c",query[qi]);
49144 X    for (rj = 0 ; rj < N_EFFECT ; rj++) {
49145 X      if(1 != fread(&freq, sizeof(double), 1, fp)) {
49146 X       fprintf(stderr, "Error while reading frequencies!\n");
49147 X       exit(1);
49148 X      }
49149 X      printf(" %8.7g",freq*10.0);
49150 X
49151 X      if (freq > 1e-12) {
49152 X       freq = log(freq /((double) (rrcounts[rj+1])/(double) rrtotal));
49153 X       freq /= pamscale; /* this gets us close to originial pam scores */
49154 X       freq2d[qi][rj] = freq;
49155 X      }
49156 X      else {freq2d[qi][rj] = freq;}
49157 X    }
49158 X    printf("\n");
49159 X  }
49160 X
49161 X
49162 X  /* now figure out the right scale */
49163 X  scale = 1.0;
49164 X  lambda = get_lambda(ppst->pam2[0], 20, 20, "\0ARNDCQEGHILKMFPSTWYV");
49165 X
49166 X  /* should be near 1.0 because of our initial scaling by ppst->pamscale */
49167 X  fprintf(stderr, "real_lambda: %g\n", lambda);
49168 X
49169 X  /* get initial high/low scale values: */
49170 X  first = 1;
49171 X  while (1) {
49172 X    fill_pam(pam2p, n0, 20, freq2d, scale);
49173 X    new_lambda = get_lambda(pam2p, n0, 20, query); 
49174 X
49175 X    if (new_lambda > lambda) {
49176 X      if (first) {
49177 X       first = 0;
49178 X       scale = scale_high = 1.0 + 0.05;
49179 X       scale_low = 1.0;
49180 X       too_high = 1;
49181 X      } else {
49182 X       if (!too_high) break;
49183 X       scale = (scale_high += scale_high - 1.0);
49184 X      }
49185 X    } else if (new_lambda > 0) {
49186 X      if (first) {
49187 X       first = 0;
49188 X       scale_high = 1.0;
49189 X       scale = scale_low = 1.0 - 0.05;
49190 X       too_high = 0;
49191 X      } else {
49192 X       if (too_high) break;
49193 X       scale = (scale_low += scale_low - 1.0);
49194 X      }
49195 X    } else {
49196 X      fprintf(stderr, "new_lambda (%g) <= 0; matrix has positive average score", new_lambda);
49197 X      exit(1);
49198 X    }
49199 X  }
49200 X
49201 X  /* now do binary search between low and high */
49202 X  for (i = 0 ; i < 10 ; i++) {
49203 X    scale = 0.5 * (scale_high + scale_low);
49204 X    fill_pam(pam2p, n0, 20, freq2d, scale);
49205 X    new_lambda = get_lambda(pam2p, n0, 20, query);
49206 X    
49207 X    if (new_lambda > lambda) scale_low = scale;
49208 X    else scale_high = scale;
49209 X  }
49210 X
49211 X  scale = 0.5 * (scale_high + scale_low);
49212 X  fill_pam(pam2p, n0, 20, freq2d, scale);
49213 X
49214 X  fprintf(stderr, "final scale: %g\n", scale);
49215 X
49216 X  for (qi = 0 ; qi < n0 ; qi++) {
49217 X    fprintf(stderr, "%4d %c:  ", qi+1, query[qi]);
49218 X    for (rj = 1 ; rj <= 20 ; rj++) {
49219 X      fprintf(stderr, "%4d", pam2p[qi][rj]);
49220 X    }
49221 X    fprintf(stderr, "\n");
49222 X  }
49223 X
49224 X  free(freq2d[0]);
49225 X  free(freq2d);
49226 X
49227 X  free(query);
49228 }
49229 X
49230 /*
49231 X * alloc_pam(): allocates memory for the 2D pam matrix as well
49232 X * as for the integer array used to transmit the pam matrix
49233 X */
49234 void
49235 alloc_pam (int d1, int d2, struct pstruct *ppst)
49236 {
49237 X  int     i, *d2p;
49238 X
49239 X  if ((ppst->pam2[0] = (int **) malloc (d1 * sizeof (int *))) == NULL) {
49240 X     fprintf(stderr,"Cannot allocate 2D pam matrix: %d",d1);
49241 X     exit(1);
49242 X  }
49243 X
49244 X  if ((ppst->pam2[1] = (int **) malloc (d1 * sizeof (int *))) == NULL) {
49245 X     fprintf(stderr,"Cannot allocate 2D pam matrix: %d",d1);
49246 X     exit(1);
49247 X  }
49248 X
49249 X  if ((d2p = pam12 = (int *) malloc (d1 * d2 * sizeof (int))) == NULL) {
49250 X     fprintf(stderr,"Cannot allocate 2D pam matrix: %d",d1);
49251 X     exit(1);
49252 X   }
49253 X
49254 X   for (i = 0; i < d1; i++, d2p += d2)
49255 X      ppst->pam2[0][i] = d2p;
49256 X
49257 X   if ((d2p=pam12x= (int *) malloc (d1 * d2 * sizeof (int))) == NULL) {
49258 X     fprintf(stderr,"Cannot allocate 2d pam matrix: %d",d2);
49259 X     exit(1);
49260 X   }
49261 X
49262 X   for (i = 0;  i < d1; i++, d2p += d2)
49263 X      ppst->pam2[1][i] = d2p;
49264 }
49265 X
49266 void
49267 fill_pam(int **pam2p, int n0, int nsq, double **freq2d, double scale) {
49268 X  int i, j;
49269 X  double freq;
49270 X
49271 X  /* fprintf(stderr, "scale: %g\n", scale); */
49272 X  
49273 X  /* now fill in the pam matrix: */
49274 X  for (i = 0 ; i < n0 ; i++) {
49275 X    for (j = 1 ; j <=nsq ; j++) {
49276 X      freq = scale * freq2d[i][j-1];
49277 X      if ( freq < 0.0) freq -= 0.5;
49278 X      else freq += 0.5;
49279 X      pam2p[i][j] = (int)(freq);
49280 X    }
49281 X  }
49282 }
49283 X
49284 /*
49285 X *  initpam2(struct pstruct pst): Converts 1-D pam matrix to 2-D
49286 X */
49287 void initpam2 (struct pstruct *ppst)
49288 {
49289 X   int i, j, k, nsq, pam_xx, pam_xm;
49290 X   int sa_x, sa_t, tmp;
49291 X
49292 X   nsq = ppst->nsq;
49293 X   sa_x = pascii['X'];
49294 X   sa_t = pascii['*'];
49295 X
49296 X   ppst->pam2[0][0][0] = -BIGNUM;
49297 X   ppst->pam_h = -1; ppst->pam_l = 1;
49298 X
49299 X   k = 0;
49300 X   for (i = 1; i <= nsq; i++) {
49301 X     ppst->pam2[0][0][i] = ppst->pam2[0][i][0] = -BIGNUM;
49302 X     for (j = 1; j <= i; j++) {
49303 X       ppst->pam2[0][j][i] = ppst->pam2[0][i][j] = pam[k++] - ppst->pamoff;
49304 X       if (ppst->pam_l > ppst->pam2[0][i][j]) ppst->pam_l =ppst->pam2[0][i][j];
49305 X       if (ppst->pam_h < ppst->pam2[0][i][j]) ppst->pam_h =ppst->pam2[0][i][j];
49306 X     }
49307 X   }
49308 X
49309 X   ppst->nt_align = (ppst->dnaseq== SEQT_DNA || ppst->dnaseq == SEQT_RNA);
49310 X
49311 X   if (ppst->dnaseq == SEQT_RNA) {
49312 X     tmp = ppst->pam2[0][nascii['G']][nascii['G']] - 1;
49313 X     ppst->pam2[0][nascii['A']][nascii['G']] = 
49314 X       ppst->pam2[0][nascii['C']][nascii['T']] = 
49315 X       ppst->pam2[0][nascii['C']][nascii['U']] = tmp;
49316 X   }
49317 X
49318 X   if (ppst->pam_x_set) {
49319 X     for (i=1; i<=nsq; i++) {
49320 X       ppst->pam2[0][sa_x][i] = ppst->pam2[0][i][sa_x]=ppst->pam_xm;
49321 X       ppst->pam2[0][sa_t][i] = ppst->pam2[0][i][sa_t]=ppst->pam_xm;
49322 X     }
49323 X     ppst->pam2[0][sa_x][sa_x]=ppst->pam_xx;
49324 X     ppst->pam2[0][sa_t][sa_t]=ppst->pam_xm;
49325 X   }
49326 X   else {
49327 X     ppst->pam_xx = ppst->pam2[0][sa_x][sa_x];
49328 X     ppst->pam_xm = ppst->pam2[0][1][sa_x];
49329 X   }
49330 }
49331 X
49332 double
49333 get_lambda(int **pam2p, int n0, int nsq, char *aa0) {
49334 X  double lambda, H;
49335 X  double *pr, tot, sum;
49336 X  int i, ioff, j, min, max;
49337 X
49338 X  /* get min and max scores */
49339 X  min = BIGNUM;
49340 X  max = -BIGNUM;
49341 X  if(pam2p[0][1] == -BIGNUM) {
49342 X    ioff = 1;
49343 X    n0++;
49344 X  } else {
49345 X    ioff = 0;
49346 X  }
49347 X
49348 X  for (i = ioff ; i < n0 ; i++) {
49349 X    for (j = 1; j <= nsq ; j++) {
49350 X      if (min > pam2p[i][j])
49351 X       min = pam2p[i][j];
49352 X      if (max < pam2p[i][j])
49353 X       max = pam2p[i][j];
49354 X    }
49355 X  }
49356 X
49357 X  /*  fprintf(stderr, "min: %d\tmax:%d\n", min, max); */
49358 X  
49359 X  if ((pr = (double *) calloc(max - min + 1, sizeof(double))) == NULL) {
49360 X    fprintf(stderr, "Couldn't allocate memory for score probabilities: %d\n", max - min + 1);
49361 X    exit(1);
49362 X  }
49363 X
49364 X  tot = (double) rrtotal * (double) rrtotal * (double) n0;
49365 X  for (i = ioff ; i < n0 ; i++) {
49366 X    for (j = 1; j <= nsq ; j++) {
49367 X      pr[pam2p[i][j] - min] +=
49368 X       (double) ((double) rrcounts[aascii[aa0[i]]] * (double) rrcounts[j]) / tot;
49369 X    }
49370 X  }
49371 X
49372 X  sum = 0.0;
49373 X  for(i = 0 ; i <= max-min ; i++) { 
49374 X    sum += pr[i];
49375 X    /*    fprintf(stderr, "%3d: %g %g\n", i+min, pr[i], sum); */
49376 X  }
49377 X  /*  fprintf(stderr, "sum: %g\n", sum); */
49378 X
49379 X  for(i = 0 ; i <= max-min ; i++) { pr[i] /= sum; }
49380 X
49381 X  if (!karlin(min, max, pr, &lambda, &H)) {
49382 X    fprintf(stderr, "Karlin lambda estimation failed\n");
49383 X  }
49384 X
49385 X  /*   fprintf(stderr, "lambda: %g\n", lambda); */
49386 X  free(pr);
49387 X
49388 X  return lambda;
49389 }
49390 X
49391 int **
49392 alloc_pam2p(int len, int nsq) {
49393 X  int i;
49394 X  int **pam2p;
49395 X
49396 X  if ((pam2p = (int **)calloc(len,sizeof(int *)))==NULL) {
49397 X    fprintf(stderr," Cannot allocate pam2p: %d\n",len);
49398 X    return NULL;
49399 X  }
49400 X
49401 X  if((pam2p[0] = (int *)calloc((nsq+1)*len,sizeof(int)))==NULL) {
49402 X    fprintf(stderr, "Cannot allocate pam2p[0]: %d\n", (nsq+1)*len);
49403 X    free(pam2p);
49404 X    return NULL;
49405 X  }
49406 X
49407 X  for (i=1; i<len; i++) {
49408 X    pam2p[i] = pam2p[0] + (i*(nsq+1));
49409 X  }
49410 X
49411 X  return pam2p;
49412 }
49413 X
49414 void free_pam2p(int **pam2p) {
49415 X  if (pam2p) {
49416 X    free(pam2p[0]);
49417 X    free(pam2p);
49418 X  }
49419 }
49420 X
49421 SHAR_EOF
49422 chmod 0644 print_pssm.c ||
49423 echo 'restore of print_pssm.c failed'
49424 Wc_c="`wc -c < 'print_pssm.c'`"
49425 test 11147 -eq "$Wc_c" ||
49426         echo 'print_pssm.c: original size 11147, current size' "$Wc_c"
49427 fi
49428 # ============= prio_atepa.aa ==============
49429 if test -f 'prio_atepa.aa' -a X"$1" != X"-c"; then
49430         echo 'x - skipping prio_atepa.aa (File already exists)'
49431 else
49432 echo 'x - extracting prio_atepa.aa (Text)'
49433 sed 's/^X//' << 'SHAR_EOF' > 'prio_atepa.aa' &&
49434 >PRIO_ATEPA | 90377   | MAJOR PRION PROTEIN PRECURSOR (PRP) (PRP27-30) (PRP33-35C).
49435 MANLGYWMLVLFVATWSDLGLCKKRPKPGGWNTGGSRYPGQGSPGGNRYPPQGGGWGQPHGGGWGQPHGGGWGQP
49436 HGGGWGQPHGGGWGQAGGTHNQWNKPSKPKTNMKHMAGAAAAGAVVGGLGGYMLGSAMSRPLIHFGNDYEDRYYR
49437 ENMYRYPNQVYYRPVDQYNNQNNFVHDCVNITIKQHTVTTTTKGENLTETDVKMMERVVEQMCITQYERESQAYY
49438 QRGSSMVLFSSPPVILLISFLIFLIVG
49439 SHAR_EOF
49440 chmod 0644 prio_atepa.aa ||
49441 echo 'restore of prio_atepa.aa failed'
49442 Wc_c="`wc -c < 'prio_atepa.aa'`"
49443 test 340 -eq "$Wc_c" ||
49444         echo 'prio_atepa.aa: original size 340, current size' "$Wc_c"
49445 fi
49446 # ============= prot_test.lib ==============
49447 if test -f 'prot_test.lib' -a X"$1" != X"-c"; then
49448         echo 'x - skipping prot_test.lib (File already exists)'
49449 else
49450 echo 'x - extracting prot_test.lib (Text)'
49451 sed 's/^X//' << 'SHAR_EOF' > 'prot_test.lib' &&
49452 >HAHU | 1114 | Hemoglobin alpha chain - Human, chimpanzee, and pygmy chimpanzee
49453 VLSPADKTNVKAAWGKVGAHAGEYGAEALERMFLSFPTTKTYFPHFDLSHGSAQVKGHGKKVADALTNAV
49454 AHVDDMPNALSALSDLHAHKLRVDPVNFKLLSHCLLVTLAAHLPAEFTPAVHASLDKFLASVSTVLTSKY
49455
49456 >K1HUAG | 1091 |  Ig kappa chain V-I region (Ag) - Human
49457 DIQMTQSPSSLSASVGDRVTITCQASQDINHYLNWYQQGPKKAPKILIYDASNLETGVPSRFSGSGFGTD
49458 FTFTISGLQPEDIATYYCQQYDTLPRTFGQGTKLEIKR/ 
49459 >CCHU | 1 | Cytochrome c - Human
49460 MGDVEKGKKIFIMKCSQCHTVEKGGKHKTGPNLHGLFGRKTGQAPGYSYTAANKNKGIIWGEDTLMEYLE
49461 NPKKYIPGTKMIFVGIKKKEERADLIAYLKKATNE 
49462 >N2KF1U | 1021 | Long neurotoxin 1 - Many-banded krait
49463 IVCHTTATIPSSAVTCPPGENLCYRKMWCDAFCSSRGKVVELGCAATCPSKKPYEEVTCCSTDKCNHPPK
49464 RQPG 
49465 >TPHUCS | 1322 | Troponin C, skeletal muscle - Human
49466 DTQQAEARSYLSEEMIAEFKAAFDMFDADGGGDISVKELGTVMRMLGQTPTKEELDAIIEEVDEDGSGTI
49467 DFEEFLVMMVRQMKEDAKGKSEEELAECFRIFDRNADGYIDPEELAEIFRASGEHVTDEEIESLMKDGDK
49468 NNDGRIDFDEFLKMMEGVQ 
49469 >FEPE | 25 | Ferredoxin - Peptostreptococcus asaccharolyticus
49470 AYVINDSCIACGACKPECPVNIQQGSIYAIDADSCIDCGSCASVCPVGAPNPED 
49471 >RKMDS | 677 | Ribulose-bisphosphate carboxylase (EC 4.1.1.39) small chain - Cry
49472 MRLTQGAFSFLPDLTDEQIVKQIQYAISKNWALNVEWTDDPHPRNAYWDLWGLPLFGIKDPAAVMFEINA
49473 CRKAKPACYVKVNAFDNSRGVESCCLSFIVQRPTSNEPGFQLIRSEVDSRNIRYTIQSYASTRPEGERY*
49474 X
49475 >K3HU | 1099 | Ig kappa chain C region - Human
49476 /TVAAPSVFIFPPSDEQLKSGTASVVCLLNNFYPREAKVQWKVDNALQSGNSQESVTEQDSKDSTYSLSS
49477 TLTLSKADYEKHKVYACEVTHQGLSSPVTKSFNRGEC 
49478 >HMIVV | 2581 | Hemagglutinin precursor - Influenza A virus (2 strains)
49479 MKTIIALSYIFCLVFAQDLPGNDNNSTATLCLGHHAVPNGTLVKTITNDQIEVTNATELVQSSSTGKICN
49480 NPHRILDGINCTLIDALLGDPHCDGFQNEKWDLFVERSKAFSNCYPYDVPDYASLRSLVASSGTLEFINE
49481 GFNWTGVTQNGGSSACKRGPDSGFFSRLNWLYKSGSTYPVQNVTMPNNDNSDKLYIWGVHHPSTDKEQTN
49482 LYVQASGKVTVSTKRSQQTIIPNVGSRPWVRGLSSRISIYWTIVKPGDILVINSNGNLIAPRGYFKMRTG
49483 KSSI
49484 MRSDAPIGTCSSECITPNGSIPNDKPFQNVNKITYGACPKYVKQNTLKLATGMRNVPEKQTRGIFGAIAG
49485 FIENGWEGMIDGWYGFRHQNSEGTGQAADLKSTQAAIDQINGKLNRVIEKTNEKFHQIEKEFSEVEGRIQ
49486 DLEKYVEDTKIDLWSYNAELLVALENQHTIDLTDSEMNKLFEKTRRQLRENAEDMGNGCFKIYHKCDNAC
49487 IGSIRNGTYDHDVYRDEALNNRFQIKGVELKSGYKDWILWISFAISCFLLCVVLLGFIMWACQKGNIRCN
49488 ICI 
49489 >OKBO2C | 296 | Protein kinase (EC 2.7.1.37), cAMP-dependent, catalytic chain - B
49490 GNAAAAKKGSEQESVKEFLAKAKEDFLKKWENPAQNTAHLDQFERIKTLGTGSFGRVMLVKHMETGNHYA
49491 MKILDKQKVVKLKQIEHTLNEKRILQAVNFPFLVKLEFSFKDNSNLYMVMEYVPGGEMFSHLRRIGRFSE
49492 PHARFYAAQIVLTFEYLHSLDLIYRDLKPENLLIDQQGYIQVTDFGFAKRVKGRTWTLCGTPEYLAPEII
49493 LSKGYNKAVDWWALGVLIYEMAAGYPPFFADQPIQIYEKIVSGKVRFPSHFSSDLKDLLRNLLQVDLTKR
49494 FGNLKDGVNDIKNHKWFATTDWIAIYQRKVEAPFIPKFKGPGDTSNFDDYEEEEIRVSINEKCGKEFSEF
49495 >GT8.7 | 266 | transl. of pa875.con, 19 to 675
49496 MPMILGYWNVRGLTHPIRMLLEYTDSSYDEKR
49497 YTMGDAPDFDRSQWLNEKFKLGLDFPNLPYLI
49498 DGSHKITQSNAILRYLARKHHLDGETEEERIR
49499 ADIVENQVMDTRMQLIMLCYNPDFEKQKPEFL
49500 KTIPEKMKLYSEFLGKRPWFAGDKVTYVDFLA
49501 YDILDQYRMFEPKCLDAFPNLRDFLARFEGLK
49502 KISAYMKSSRYIATPIFSKMAHWSNK
49503 SHAR_EOF
49504 chmod 0644 prot_test.lib ||
49505 echo 'restore of prot_test.lib failed'
49506 Wc_c="`wc -c < 'prot_test.lib'`"
49507 test 2741 -eq "$Wc_c" ||
49508         echo 'prot_test.lib: original size 2741, current size' "$Wc_c"
49509 fi
49510 # ============= prot_test.lseg ==============
49511 if test -f 'prot_test.lseg' -a X"$1" != X"-c"; then
49512         echo 'x - skipping prot_test.lseg (File already exists)'
49513 else
49514 echo 'x - extracting prot_test.lseg (Text)'
49515 sed 's/^X//' << 'SHAR_EOF' > 'prot_test.lseg' &&
49516 >HAHU | 1114 | Hemoglobin alpha chain - Human, chimpanzee, and pygmy chimpanzee @P:1-50
49517 VLSPADKTNVKAAWGKVGAHAGEYGAEALERMFLSFPTTKTYFPHFDLSHGSAQVKGHGK
49518 KVADALTNAVAHVDDMPNALSALSDLHAHKLRVDPVNFKLLSHCLLVTLAAHLPAEFTPA
49519 VHASLDKFLASVSTVLTSKYR
49520 X
49521 >K1HUAG | 1091 |  Ig kappa chain V-I region (Ag) - Human @P:51-90
49522 DIQMTQSPSSLSASVGDRVTITCQASQDINHYLNWYQQGPKKAPKILIYDASNLETGVPs
49523 rfsgsgfgtdftftisgLQPEDIATYYCQQYDTLPRTFGQGTKLEIKR*
49524 X
49525 >CCHU | 1 | Cytochrome c - Human @P:25-85
49526 MGDVEKGKKIFIMKCSQCHTVEKGGKHKTGPNLHGLFGRKTGQAPGYSYTAANKNKGIIW
49527 GEDTLMEYLENPKKYIPGTKMIFVGIKKKEERADLIAYLKKATNE
49528 X
49529 >N2KF1U | 1021 | Long neurotoxin 1 - Many-banded krait
49530 IVCHTTATIPSSAVTCPPGENLCYRKMWCDAFCSSRGKVVELGCAATCPSKKPYEEVTCC
49531 STDKCNHPPKRQPG
49532 X
49533 >TPHUCS | 1322 | Troponin C, skeletal muscle - Human @P:50-125
49534 DTQQAEARSYLSEEMIAEfkaafdmfdadgggdISVKELGTVMRMLGQTPTKEELDAIIE
49535 EVDEDGSGTIDFEEFLVMMVRQMKEDAKGKSEEELAECFRIFDRNADGYIDPEELAEIFR
49536 ASGEHVTDEEIESLMKDGDKNNDGRIDFDEFLKMMEGVQ
49537 X
49538 >FEPE | 25 | Ferredoxin - Peptostreptococcus asaccharolyticus
49539 AYVINDSCIACGACKPECPVNIQQGSIYAIDADSCIDCGSCASVCPVGAPNPED
49540 X
49541 >RKMDS | 677 | Ribulose-bisphosphate carboxylase (EC 4.1.1.39) small chain - Cry
49542 MRLTQGAFSFLPDLTDEQIVKQIQYAISKNWALNVEWTDDPHPRNAYWDLWGLPLFGIKD
49543 PAAVMFEINACRKAKPACYVKVNAFDNSRGVESCCLSFIVQRPTSNEPGFQLIRSEVDSR
49544 NIRYTIQSYASTRPEGERY*
49545 X
49546 >K3HU | 1099 | Ig kappa chain C region - Human
49547 TVAAPSVFIFPPSDEQLKSGTASVVCLLNNFYPREAKVQWKVDNALQSGNSQESVTEQDS
49548 KDstyslsstltlsKADYEKHKVYACEVTHQGLSSPVTKSFNRGEC
49549 >HMIVV | 2581 | Hemagglutinin precursor - Influenza A virus (2 strains)
49550 MKTIIALSYIFCLVFAQDLPGNDNNSTATLCLGHHAVPNGTLVKTITNDQIEVTNATELV
49551 QSSSTGKICNNPHRILDGINCTLIDALLGDPHCDGFQNEKWDLFVERSKAFSNCYPYDVP
49552 DYASLRSLVASSGTLEFINEGFNWTGVTQNGGSSACKRGPDSGFFSRLNWLYKSGSTYPV
49553 QNVTMPNNDNSDKLYIWGVHHPSTDKEQTNLYVQASGKVTVSTKRSQQTIIPNVGSRPWV
49554 RGLSSRISIYWTIVKPGDILVINSNGNLIAPRGYFKMRTGKSSIMRSDAPIGTCSSECIT
49555 PNGSIPNDKPFQNVNKITYGACPKYVKQNTLKLATGMRNVPEKQTRGIFGAIAGFIENGW
49556 EGMIDGWYGFRHQNSEGTGQAADLKSTQAAIDQINGKLNRVIEKTNEKFHQIEKEFSEVE
49557 GRIQDLEKYVEDTKIDLWSYNAELLVALENQHTIDLTDSEMNKLFEKTRRQLRENAEDMG
49558 NGCFKIYHKCDNACIGSIRNGTYDHDVYRDEALNNRFQIKGVELKSGYKDWILWISFAIS
49559 CFLLCVVLLGFIMWACQKGNIRCNICI
49560 >OKBO2C | 296 | Protein kinase (EC 2.7.1.37), cAMP-dependent, catalytic chain - B
49561 GNAAAAKKGSEQESVKEFLAKAKEDFLKKWENPAQNTAHLDQFERIKTLGTGSFGRVMLV
49562 KHMETGNHYAMKILDKQKVVKLKQIEHTLNEKRILQAVNFPFLVKLEFSFKDNSNLYMVM
49563 EYVPGGEMFSHLRRIGRFSEPHARFYAAQIVLTFEYLHSLDLIYRDLKPENLLIDQQGYI
49564 QVTDFGFAKRVKGRTWTLCGTPEYLAPEIILSKGYNKAVDWWALGVLIYEMAAGYPPFFA
49565 DQPIQIYEKIVSGKVRFPSHFSSDLKDLLRNLLQVDLTKRFGNLKDGVNDIKNHKWFATT
49566 DWIAIYQRKVEAPFIPKFKGPGDTSNFDDYEEEEIRVSINEKCGKEFSEF
49567 >GT8.7 | 266 | transl. of pa875.con, 19 to 675 @P:21-180
49568 MPMILGYWNVRGLTHPIRMLLEYTDSSYDEKRYTMGDAPDFDRSQWLNEKFKLGLDFPNL
49569 pylidgshkitqsnailrylarkhhldget
49570 EEERIRADIVENQVMDTRMQLIMLCYNPDF
49571 ekqkpeflktipekmklyseflgkrpwfag
49572 DKVTYVDFLAYDILDQYRMFEPKCLDAFPN
49573 LRDFLARFEGLKKISAYMKSSRYIATPIFSKMAHWSNK
49574 X
49575 SHAR_EOF
49576 chmod 0644 prot_test.lseg ||
49577 echo 'restore of prot_test.lseg failed'
49578 Wc_c="`wc -c < 'prot_test.lseg'`"
49579 test 2786 -eq "$Wc_c" ||
49580         echo 'prot_test.lseg: original size 2786, current size' "$Wc_c"
49581 fi
49582 # ============= prss3.1 ==============
49583 if test -f 'prss3.1' -a X"$1" != X"-c"; then
49584         echo 'x - skipping prss3.1 (File already exists)'
49585 else
49586 echo 'x - extracting prss3.1 (Text)'
49587 sed 's/^X//' << 'SHAR_EOF' > 'prss3.1' &&
49588 .TH PRSS3 1 local
49589 .SH NAME
49590 prss \- test a protein sequence similarity for significance
49591 .SH SYNOPSIS
49592 .B prss34
49593 \&[-Q -A -f # -g # -H -O file -s SMATRIX -w # -Z #
49594 .I -k # -v #
49595 ]
49596 sequence-file-1 sequence-file-2
49597 [
49598 .I #-of-shuffles
49599 ]
49600 X
49601 .B prfx34
49602 \&[-Q -A -f # -g # -H -O file -s SMATRIX -w # -z 1,3 -Z #
49603 .I -k # -v #
49604 ]
49605 sequence-file-1 sequence-file-2
49606 [
49607 .I ktup
49608 ]
49609 [
49610 .I #-of-shuffles
49611 ]
49612 X
49613 .B prss34(_t)/prfx34(_t)
49614 [-AfghksvwzZ]
49615 \- interactive mode
49616 X
49617 .SH DESCRIPTION
49618 .B prss34
49619 and
49620 .B prfx34
49621 are used to evaluate the significance of a protein:protein, DNA:DNA
49622 (
49623 .B prss34
49624 ), or translated-DNA:protein (
49625 .B prfx34
49626 ) sequence similarity score
49627 by comparing two sequences and calculating optimal similarity scores,
49628 and then repeatedly shuffling the second sequence, and calculating
49629 optimal similarity scores using the Smith-Waterman algorithm. An
49630 extreme value distribution is then fit to the shuffled-sequence
49631 scores.  The characteristic parameters of the extreme value
49632 distribution are then used to estimate the probability that each of
49633 the unshuffled sequence scores would be obtained by chance in one
49634 sequence, or in a number of sequences equal to the number of shuffles.
49635 This program is derived from
49636 .B rdf2\c
49637 \&, described by Pearson and Lipman, PNAS (1988) 85:2444-2448, and
49638 Pearson (Meth. Enz.  183:63-98).  Use of the extreme value
49639 distribution for estimating the probabilities of similarity scores was
49640 described by Altshul and Karlin, PNAS (1990) 87:2264-2268.  The
49641 'z-values' calculated by rdf2 are not as informative as the P-values
49642 and expectations calculated by prdf.
49643 .B prss34
49644 calculates optimal scores using the same rigorous Smith-Waterman
49645 algorithm (Smith and Waterman, J. Mol. Biol. (1983) 147:195-197) used by the
49646 .B ssearch34
49647 program.
49648 .B prfx34
49649 calculates scores using the FASTX algorithm (Pearson et al. (1997) Genomics 46:24-36.
49650 .PP
49651 .B prss34
49652 and 
49653 .B prfx34
49654 also allow a more sophisticated shuffling method: residues can be shuffled
49655 within a local window, so that the order of residues 1-10, 11-20, etc,
49656 is destroyed but a residue in the first 10 is never swapped with a residue
49657 outside the first ten, and so on for each local window.
49658 .SH EXAMPLES
49659 .TP
49660 (1)
49661 .B prss34
49662 \& -v 10 musplfm.aa lcbo.aa
49663 .PP
49664 Compare the amino acid sequence in the file musplfm.aa with that
49665 in lcbo.aa, then shuffle lcbo.aa 200 times using a local shuffle with
49666 a window of 10.  Report the significance of the
49667 unshuffled musplfm/lcbo comparison scores with respect to the shuffled
49668 scores.
49669 .TP
49670 (2)
49671 .B prss34
49672 musplfm.aa lcbo.aa 1000
49673 .PP
49674 Compare the amino acid sequence in the file musplfm.aa with the sequences
49675 in the file lcbo.aa, shuffling \fClcbo.aa\fP 1000 times.  Shuffles can also be specified with the -k # option.
49676 .TP
49677 (3)
49678 .B prfx34
49679 mgstm1.esq xurt8c.aa 2 1000
49680 .PP
49681 Translate the DNA sequence in the \fCmgstm1.esq\fP file in all six
49682 frames and compare it to the amino acid sequence in the file
49683 \fCxurt8c.aa\fP, using ktup=2 and shuffling \fCxurt8c.aa\fP 1000
49684 times.  Each comparison considers the best forward or reverse
49685 alignment with frameshifts, using the fastx algorithm (Pearson et al
49686 (1997) Genomics 46:24-36).
49687 .TP
49688 (4)
49689 .B prss34/prfx34
49690 .PP
49691 Run prss in interactive mode.  The program will prompt for the file
49692 name of the two query sequence files and the number of shuffles to be
49693 used.
49694 .SH OPTIONS
49695 .PP
49696 .B prss34/prfx34
49697 can be directed to change the scoring matrix, gap penalties, and
49698 shuffle parameters by entering options on the command line (preceeded
49699 by a `\-'). All of the options should preceed the file names number of
49700 shuffles.
49701 .TP
49702 \-A
49703 Show unshuffled alignment.
49704 .TP
49705 \-f #
49706 Penalty for opening a gap (-10 by default for proteins).
49707 .TP
49708 \-g #
49709 Penalty for additional residues in a gap (-2 by default) for proteins.
49710 .TP
49711 \-H
49712 Do not display histogram of similarity scores.
49713 .TP
49714 \-k #
49715 Number of shuffles (200 is the default)
49716 .TP
49717 \-Q -q
49718 "quiet" - do not prompt for filename.
49719 .TP
49720 \-O filename
49721 send copy of results to "filename."
49722 .TP
49723 \-s str
49724 specify the scoring matrix.  BLOSUM50 is used by default for proteins;
49725 +5/-4 is used by defaul for DNA. 
49726 .B prss34
49727 recognizes the same scoring matrices as fasta34, ssearch34, fastx34, etc;
49728 e.g. BL50, P250, BL62, BL80, MD10, MD20, and other matrices in BLAST1.4
49729 matrix format.
49730 .TP
49731 \-v #
49732 Use a local window shuffle with a window size of #.
49733 .TP
49734 \-z #
49735 Calculate statistical significance using the mean/variance
49736 (moments) approach used by fasta34/ssearch or from maximum likelihood
49737 estimates of lambda and K.
49738 .TP
49739 \-Z #
49740 Present statistical significance as if a '#' entry database had
49741 been searched (e.g. "-Z 50000" presents statistical significance as if
49742 50,000 sequences had been compared).
49743 .SH ENVIRONMENT VARIABLES
49744 .PP
49745 .B (SMATRIX)
49746 the filename of an alternative scoring matrix file.  For protein
49747 sequences, BLOSUM50 is used by default; PAM250 can be used with the
49748 command line option
49749 .B -s P250\c
49750 (or with -s pam250.mat).  BLOSUM62 (-s BL62) and PAM120 (-S P120).
49751 .SH "SEE ALSO"
49752 ssearch3(1), fasta3(1).
49753 .SH AUTHOR
49754 Bill Pearson
49755 .br
49756 wrp@virginia.EDU
49757 X
49758 SHAR_EOF
49759 chmod 0644 prss3.1 ||
49760 echo 'restore of prss3.1 failed'
49761 Wc_c="`wc -c < 'prss3.1'`"
49762 test 4969 -eq "$Wc_c" ||
49763         echo 'prss3.1: original size 4969, current size' "$Wc_c"
49764 fi
49765 # ============= prss3.rsp ==============
49766 if test -f 'prss3.rsp' -a X"$1" != X"-c"; then
49767         echo 'x - skipping prss3.rsp (File already exists)'
49768 else
49769 echo 'x - extracting prss3.rsp (Text)'
49770 sed 's/^X//' << 'SHAR_EOF' > 'prss3.rsp' &&
49771 compacc.obj doinit.obj karlin.obj scaleswn.obj htime.obj apam.obj lib_sel.obj getopt.obj showrss.obj pssm_asn_subs.obj
49772 SHAR_EOF
49773 chmod 0644 prss3.rsp ||
49774 echo 'restore of prss3.rsp failed'
49775 Wc_c="`wc -c < 'prss3.rsp'`"
49776 test 119 -eq "$Wc_c" ||
49777         echo 'prss3.rsp: original size 119, current size' "$Wc_c"
49778 fi
49779 # ============= psql_demo.sql ==============
49780 if test -f 'psql_demo.sql' -a X"$1" != X"-c"; then
49781         echo 'x - skipping psql_demo.sql (File already exists)'
49782 else
49783 echo 'x - extracting psql_demo.sql (Text)'
49784 sed 's/^X//' << 'SHAR_EOF' > 'psql_demo.sql' &&
49785 @ seqdb_demo seqdb_demo @;
49786 SELECT acc, protein.seq, sp_name
49787 X FROM annot INNER JOIN protein USING(prot_id) WHERE annot.db='sp';
49788 SELECT acc, 'sp|'||acc||'|'||sp_name||' '||descr FROM annot WHERE acc='#' AND db='sp';
49789 SELECT acc,protein.seq FROM protein INNER JOIN annot USING(prot_id)
49790 X WHERE annot.acc='#' AND db='sp';
49791 X
49792 SHAR_EOF
49793 chmod 0644 psql_demo.sql ||
49794 echo 'restore of psql_demo.sql failed'
49795 Wc_c="`wc -c < 'psql_demo.sql'`"
49796 test 317 -eq "$Wc_c" ||
49797         echo 'psql_demo.sql: original size 317, current size' "$Wc_c"
49798 fi
49799 # ============= psql_demo1.sql ==============
49800 if test -f 'psql_demo1.sql' -a X"$1" != X"-c"; then
49801         echo 'x - skipping psql_demo1.sql (File already exists)'
49802 else
49803 echo 'x - extracting psql_demo1.sql (Text)'
49804 sed 's/^X//' << 'SHAR_EOF' > 'psql_demo1.sql' &&
49805 xdb.wrplab seqdb_demo wrplab gstmu;
49806 SELECT acc, protein.seq, 'sp|'||acc||'|'||sp_name||' '||descr
49807 X FROM annot INNER JOIN protein USING(prot_id) WHERE annot.db='sp' LIMIT 50000;
49808 SELECT acc, 'sp|'||acc||'|'||sp_name||' '||descr FROM annot WHERE acc='#' AND db='sp';
49809 SELECT acc,protein.seq FROM protein INNER JOIN annot USING(prot_id)
49810 X WHERE annot.acc='#' AND db='sp';
49811 SHAR_EOF
49812 chmod 0644 psql_demo1.sql ||
49813 echo 'restore of psql_demo1.sql failed'
49814 Wc_c="`wc -c < 'psql_demo1.sql'`"
49815 test 366 -eq "$Wc_c" ||
49816         echo 'psql_demo1.sql: original size 366, current size' "$Wc_c"
49817 fi
49818 # ============= psql_demo_pv.sql ==============
49819 if test -f 'psql_demo_pv.sql' -a X"$1" != X"-c"; then
49820         echo 'x - skipping psql_demo_pv.sql (File already exists)'
49821 else
49822 echo 'x - extracting psql_demo_pv.sql (Text)'
49823 sed 's/^X//' << 'SHAR_EOF' > 'psql_demo_pv.sql' &&
49824 xdb.wrplab seqdb_demo wrplab gstmu;
49825 SELECT acc, protein.seq, 'sp|'||acc||'|'||sp_name||' '||descr
49826 X FROM annot INNER JOIN protein USING(prot_id) WHERE annot.db='sp' LIMIT 50000;
49827 SELECT acc, descr FROM annot WHERE acc='#' AND db='sp';
49828 SELECT acc,protein.seq FROM protein INNER JOIN annot USING(prot_id)
49829 X WHERE annot.acc='#' AND db='sp';
49830 X
49831 SHAR_EOF
49832 chmod 0644 psql_demo_pv.sql ||
49833 echo 'restore of psql_demo_pv.sql failed'
49834 Wc_c="`wc -c < 'psql_demo_pv.sql'`"
49835 test 336 -eq "$Wc_c" ||
49836         echo 'psql_demo_pv.sql: original size 336, current size' "$Wc_c"
49837 fi
49838 # ============= pssm_asn_subs.c ==============
49839 if test -f 'pssm_asn_subs.c' -a X"$1" != X"-c"; then
49840         echo 'x - skipping pssm_asn_subs.c (File already exists)'
49841 else
49842 echo 'x - extracting pssm_asn_subs.c (Text)'
49843 sed 's/^X//' << 'SHAR_EOF' > 'pssm_asn_subs.c' &&
49844 /* pssm_asn_subs.c */
49845 X
49846 X
49847 /* $Name: fa_34_26_5 $ - $Id: pssm_asn_subs.c,v 1.15 2007/04/02 18:08:11 wrp Exp $ */
49848 X
49849 /* copyright (C) 2005 by William R. Pearson and the U. of Virginia */
49850 X
49851 /* this code is designed to parse the ASN.1 binary encoded scoremat
49852 X   object produced by blastpgp -C file.ckpt_asn -u 2 */
49853 X
49854 #include <stdio.h>
49855 #include <stdlib.h>
49856 #include <string.h>
49857 X
49858 #include "defs.h"
49859 X
49860 int parse_pssm_asn();
49861 int parse_pssm2_asn();
49862 X
49863 int
49864 parse_pssm_asn_fa(FILE *afd, int *n_rows, int *n_cols,
49865 X                 unsigned char **query, double ***freqs,
49866 X                 char *matrix, int *gap_open, int *gap_extend,
49867 X                 double *lambda);
49868 X
49869 X
49870 X
49871 #define COMPO_NUM_TRUE_AA 20
49872 X
49873 /**positions of true characters in protein alphabet*/
49874 /*
49875 static int trueCharPositions[COMPO_NUM_TRUE_AA] = {
49876 X  1,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,22
49877 };
49878 */
49879 X
49880 #define COMPO_LARGEST_ALPHABET 28
49881 X
49882 /*
49883 static char ncbieaatoa[COMPO_LARGEST_ALPHABET] = {"-ABCDEFGHIJKLMNOPQRSTUVWXYZ"};
49884 X
49885 static int alphaConvert[COMPO_LARGEST_ALPHABET] = {
49886 X  (-1), 0, (-1), 4, 3, 6, 13, 7, 8, 9, 11, 10, 12, 2, 14, 5, 1, 15,
49887 X  16, 19,   17, (-1), 18, (-1), (-1), (-1), (-1), (-1)
49888 };
49889 */
49890 X
49891 int pssm_aa_order[20] = { 1,  /*A*/
49892 X                         16, /*R*/
49893 X                         13, /*N*/
49894 X                          4, /*D*/
49895 X                          3, /*C*/
49896 X                         15, /*Q*/
49897 X                          5, /*E*/
49898 X                          7, /*G*/
49899 X                          8, /*H*/
49900 X                          9, /*I*/
49901 X                         11, /*L*/
49902 X                         10, /*K*/
49903 X                         12, /*M*/
49904 X                          6, /*F*/
49905 X                         14, /*P*/
49906 X                         17, /*S*/
49907 X                         18, /*T*/
49908 X                         20, /*W*/
49909 X                         22, /*Y*/
49910 X                         19}; /*V*/
49911 X
49912 X
49913 #define ASN_SEQ 48
49914 #define ASN_SEQOF 49
49915 X
49916 #define ASN_PSSM_QUERY 166
49917 #define ASN_PSSM2_QUERY 162
49918 X
49919 #define ASN_PSSM_IS_PROT 160
49920 #define ASN_PSSM2_MATRIX 161
49921 #define ASN_PSSM_NROWS 162
49922 #define ASN_PSSM_NCOLS 163
49923 X
49924 #define ASN_PSSM2_NCOLS 163
49925 #define ASN_PSSM2_NROWS 164
49926 #define ASN_PSSM_BYCOL 165
49927 #define ASN_PSSM_INTERMED_DATA 167
49928 #define ASN_PSSM_FREQS 162
49929 #define ASN_PSSM2_FREQS 165
49930 #define ASN_PSSM2_LAMBDA 166
49931 X
49932 #define ASN_IS_STR 26
49933 #define ASN_IS_INT  2
49934 #define ASN_IS_BOOL 1
49935 #define ASN_IS_ENUM 10
49936 X
49937 struct asn_bstruct {
49938 X  FILE *fd;
49939 X  unsigned char *buf;
49940 X  unsigned char *abp;
49941 X  unsigned char *buf_max;
49942 X  int len;
49943 };
49944 X
49945 #define ASN_BUF 1024
49946 X
49947 unsigned char *
49948 chk_asn_buf(struct asn_bstruct *asnp, int v) {
49949 X  int new_buf;
49950 X  
49951 X  if (v > ASN_BUF) {
49952 X    fprintf(stderr," attempt to read %d bytes ASN.1 data > buffer size (%d)\n",
49953 X           v, ASN_BUF);
49954 X    exit(1);
49955 X  }
49956 X
49957 X  if (asnp->abp + v > asnp->buf_max) {
49958 X
49959 X    /* move down the left over stuff */
49960 X    asnp->len = asnp->buf_max - asnp->abp;
49961 X
49962 X    memmove(asnp->buf, asnp->abp, asnp->len);
49963 X
49964 X    asnp->abp = asnp->buf;
49965 X    new_buf = ASN_BUF - asnp->len;
49966 X    
49967 X    if (!feof(asnp->fd) && 
49968 X       (new_buf=fread(asnp->buf + asnp->len, sizeof(char), new_buf, asnp->fd)) != 0) {
49969 X      asnp->len += new_buf;
49970 X    }
49971 X
49972 X    asnp->buf_max = asnp->buf + asnp->len;
49973 X
49974 X    if (asnp->len < v) {
49975 X      fprintf(stderr, " Unable to read %d bytes\n",v);
49976 X      exit(1);
49977 X    }
49978 X  }
49979 X  /* otherwise, v bytes are currently in the buffer */
49980 X
49981 X  return asnp->abp;
49982 }
49983 X
49984 /* read_asn_dest reads v bytes into oct_str if v <= o_len */
49985 /* read_asn_dest is required for ASN data entities that are longer than ASN_BUF (1024) */
49986 unsigned char *
49987 read_asn_dest(struct asn_bstruct *asnp, int v, unsigned char *oct_str, int o_len) {
49988 X  int new_buf;
49989 X  unsigned char *oct_ptr;
49990 X  
49991 X
49992 X  if (v > o_len) {
49993 X    fprintf(stderr, " read_asn_dest - cannot read %d bytes into %d buffer\n",
49994 X           v, o_len);
49995 X    exit(1);
49996 X  }
49997 X
49998 X  if (asnp->abp + v <= asnp->buf_max) {
49999 X    memmove(oct_str, asnp->abp, v);
50000 X    return asnp->abp+v;
50001 X  }
50002 X  else {
50003 X    /* move down the left over stuff */
50004 X
50005 X    asnp->len = asnp->buf_max - asnp->abp;
50006 X
50007 X    memmove(oct_str, asnp->abp, asnp->len);
50008 X    oct_ptr = oct_str+asnp->len;
50009 X    v -= asnp->len;
50010 X
50011 X    asnp->abp = asnp->buf;
50012 X    new_buf = ASN_BUF;
50013 X    
50014 X    while ((new_buf=fread(asnp->buf, sizeof(char), new_buf, asnp->fd)) != 0) {
50015 X      asnp->len = new_buf;
50016 X      asnp->buf_max = asnp->buf + asnp->len;
50017 X      if (v <= new_buf) {      /* we have it all this time */
50018 X       memmove(oct_ptr, asnp->buf, v);
50019 X       asnp->len -= v;
50020 X       asnp->abp = asnp->buf + v;
50021 X       break;
50022 X      }
50023 X      else {   /* we need to read some more */
50024 X       memmove(oct_ptr, asnp->buf, new_buf);
50025 X       v -= new_buf;
50026 X       new_buf = ASN_BUF;
50027 X      }
50028 X    }
50029 X  }
50030 X  return asnp->buf + v;
50031 }
50032 X
50033 unsigned char *
50034 get_astr_bool(struct asn_bstruct *asnp, int *val) {
50035 X
50036 X  int v_len, v;
50037 X
50038 X  asnp->abp = chk_asn_buf(asnp,5);
50039 X
50040 X  v = 0;
50041 X  if (*asnp->abp++ != 1) { /* check for int */
50042 X    fprintf(stderr," bool missing\n");
50043 X  }
50044 X  else {
50045 X    v_len = *asnp->abp++;
50046 X    if (v_len != 1) {
50047 X      fprintf(stderr, "boolean length != 1 : %d\n", v_len);
50048 X      v = *asnp->abp++;
50049 X    }
50050 X    else { v = *asnp->abp++;}
50051 X  }
50052 X  asnp->abp += 2;      /* skip over null's */
50053 X  *val = v;
50054 X  return asnp->abp;
50055 }
50056 X
50057 unsigned char *
50058 get_astr_int(struct asn_bstruct *asnp,
50059 X           int *val) {
50060 X
50061 X  int v_len, v;
50062 X
50063 X  v = 0;
50064 X
50065 X  asnp->abp = chk_asn_buf(asnp,8);
50066 X
50067 X  if (*asnp->abp++ != 2) { /* check for int */
50068 X    fprintf(stderr," int missing\n");
50069 X  }
50070 X  else {
50071 X    v_len = *asnp->abp++;
50072 X    while (v_len-- > 0) {
50073 X      v *= 256;
50074 X      v += *asnp->abp++;
50075 X    }
50076 X    asnp->abp += 2;    /* skip over null's */
50077 X  }
50078 X  *val = v;
50079 X  return asnp->abp;
50080 }
50081 X
50082 unsigned char *
50083 get_astr_enum(struct asn_bstruct *asnp, int *val) {
50084 X
50085 X  int v_len, v;
50086 X
50087 X  asnp->abp = chk_asn_buf(asnp,5);
50088 X
50089 X  v = 0;
50090 X  if (*asnp->abp++ != ASN_IS_ENUM) { /* check for int */
50091 X    fprintf(stderr," enum missing\n");
50092 X  }
50093 X  else {
50094 X    v_len = *asnp->abp++;
50095 X    while (v_len-- > 0) { v *= 256;  v += *asnp->abp++; }
50096 X    asnp->abp += 2;    /* skip over null's */
50097 X  }
50098 X  *val = v;
50099 X
50100 X  return asnp->abp;
50101 }
50102 X
50103 unsigned char *
50104 get_astr_packedfloat(struct asn_bstruct *asnp, double *val) {
50105 X
50106 X  int v_len, v;
50107 X  char tmp_str[64];
50108 X
50109 X  asnp->abp = chk_asn_buf(asnp,2);
50110 X
50111 X  v = 0;
50112 X  if (*asnp->abp++ != 9) { /* check for packed float */
50113 X    fprintf(stderr," float missing\n");
50114 X    *val = 0;
50115 X    return asnp->abp;
50116 X  }
50117 X  else {
50118 X    v_len = *asnp->abp++;
50119 X
50120 X    if (v_len > 63) {
50121 X      fprintf(stderr," real string too long: %d\n",v_len);
50122 X    }
50123 X
50124 X    asnp->abp = chk_asn_buf(asnp,v_len);
50125 X
50126 X    if (v_len == 2  && *asnp->abp == '\0' && *(asnp->abp+1)=='0') {
50127 X      asnp->abp += 2;
50128 X      *val = 0.0;
50129 X    }
50130 X    else {     /* copy and scan it */
50131 X      if (*asnp->abp != '\0') {
50132 X       fprintf(stderr, " packedfloat - expected 0, got %d\n", *asnp->abp);
50133 X       *val = -1.0;
50134 X       return asnp->abp;
50135 X      }
50136 X      asnp->abp++;
50137 X      strncpy(tmp_str, (char *)asnp->abp, sizeof(tmp_str)-1);
50138 X      tmp_str[v_len-1] = '\0';
50139 X      tmp_str[63] = '\0';
50140 X      sscanf(tmp_str,"%lg",val);
50141 X      asnp->abp += v_len-1;
50142 X    }
50143 X  }
50144 X  return asnp->abp;
50145 }
50146 X
50147 unsigned char *
50148 get_astr_str(struct asn_bstruct *asnp, char *text, int t_len) {
50149 X
50150 X  int v_len;
50151 X
50152 X  asnp->abp = chk_asn_buf(asnp,2);
50153 X
50154 X  text[0] = '\0';
50155 X  if (*asnp->abp++ != ASN_IS_STR) { /* check for str */
50156 X    fprintf(stderr," str missing\n");
50157 X  }
50158 X  else {
50159 X    v_len = *asnp->abp++;
50160 X    if (v_len > 128) { /* need to read the length from the next bytes */
50161 X      t_len = v_len &0x7f;
50162 X
50163 X      asnp->abp = chk_asn_buf(asnp,t_len);
50164 X
50165 X      for (v_len =0; t_len; t_len--) { v_len = (v_len << 8) + *asnp->abp++; }
50166 X    }
50167 X
50168 X    /* read v_len bytes */
50169 X
50170 X    asnp->abp = read_asn_dest(asnp,v_len, (unsigned char *)text, t_len);
50171 X    asnp->abp += 2; /* skip over last nulls */
50172 X  }
50173 X  return asnp->abp;
50174 }
50175 X
50176 #define ASN_BIOSEQ_SEQ 160
50177 #define ASN_BIOSEQ_ID  160
50178 #define ASN_BIOSEQ_ID_VAL 160
50179 X
50180 #define ASN_BIOSEQ_ID_LOCAL 161
50181 #define ASN_BIOSEQ_ID_GIBBSQ 162
50182 #define ASN_BIOSEQ_ID_GIBBMT 163
50183 #define ASN_BIOSEQ_ID_GB 164
50184 #define ASN_BIOSEQ_ID_EMBL 165
50185 #define ASN_BIOSEQ_ID_PIR 166
50186 #define ASN_BIOSEQ_ID_SP 167
50187 #define ASN_BIOSEQ_ID_PATENT 168
50188 #define ASN_BIOSEQ_ID_OTHER 169
50189 #define ASN_BIOSEQ_ID_GEN 170
50190 #define ASN_BIOSEQ_ID_GI 171
50191 X
50192 #define ASN_BIOSEQ_TEXTID_NAME 160
50193 #define ASN_BIOSEQ_TEXTID_ACC 161
50194 #define ASN_BIOSEQ_TEXTID_REL 162
50195 #define ASN_BIOSEQ_TEXTID_VER 163
50196 X
50197 #define ASN_BIOSEQ_DESCR  161
50198 #define ASN_BIOSEQ_INST  162
50199 #define ASN_BIOSEQ_TITLE  164
50200 #define ASN_BIOSEQ_INST_REPR  160
50201 #define ASN_BIOSEQ_INST_MOL  161
50202 #define ASN_BIOSEQ_INST_LEN  162
50203 #define ASN_BIOSEQ_INST_TOPOL  166
50204 #define ASN_BIOSEQ_INST_SEQD  167
50205 #define ASN_OCTET_STR  65
50206 #define ASN_NCBIeaa 65
50207 X
50208 unsigned char *
50209 get_astr_seqdescr(struct asn_bstruct *asnp,
50210 X                char *descr) {
50211 X
50212 X  int end_seq=0;
50213 X  
50214 X  /* get seqof '1' */
50215 X  /* get 164/128 -  title */
50216 X  /* get string */
50217 X  /* pop nulls */
50218 X
50219 X  asnp->abp = chk_asn_buf(asnp,6);
50220 X
50221 X  if (*asnp->abp == ASN_SEQOF) {
50222 X    end_seq++;
50223 X    asnp->abp += 2;
50224 X  }
50225 X  else {
50226 X    fprintf(stderr, " missing ASN_SEQOF '1': %0x %0x\n",*asnp->abp, asnp->abp[1]);
50227 X  }
50228 X
50229 X  if (*asnp->abp == ASN_BIOSEQ_TITLE) { 
50230 X    asnp->abp+=2;
50231 X    asnp->abp = get_astr_str(asnp, descr, MAX_STR);
50232 X  }
50233 X  else {
50234 X    fprintf(stderr, " missing ASN_BIOSEQ_TITLE '1': %0x %0x\n",*asnp->abp, asnp->abp[1]);
50235 X  }
50236 X
50237 X  asnp->abp = chk_asn_buf(asnp,2);
50238 X
50239 X  asnp->abp += 2; /* skip over nulls */
50240 X
50241 X  return asnp->abp;
50242 }
50243 X
50244 unsigned char *
50245 get_astr_octstr(struct asn_bstruct *asnp,
50246 X              unsigned char *oct_str,
50247 X              int o_len) {
50248 X
50249 X  int q_len, v_len;
50250 X
50251 X  asnp->abp = chk_asn_buf(asnp,2);
50252 X
50253 X  if (*asnp->abp++ == ASN_NCBIeaa) {
50254 X    /* get length  of length */
50255 X    if (*asnp->abp > 128) {
50256 X      v_len = *asnp->abp++ & 0x7f;
50257 X
50258 X      asnp->abp = chk_asn_buf(asnp,v_len);
50259 X
50260 X      q_len = 0;
50261 X      while (v_len-- > 0) {
50262 X       q_len *= 256;
50263 X       q_len += *asnp->abp++;
50264 X      }
50265 X    }
50266 X    else {
50267 X      q_len = *asnp->abp++ & 0x7f;
50268 X    }
50269 X
50270 X    asnp->abp = read_asn_dest(asnp, q_len, oct_str, o_len);
50271 X
50272 X    oct_str[min(q_len,o_len)]='\0';
50273 X
50274 X    asnp->abp += 2;    /* skip characters and NULL's */
50275 X  }
50276 X  return asnp->abp;
50277 }
50278 X
50279 unsigned char *
50280 get_astr_seqinst(struct asn_bstruct *asnp,
50281 X               unsigned char **query,
50282 X               int *nq) {
50283 X
50284 X  int end_seq=0, tmp;
50285 X
50286 X  /* get sequence '0' */
50287 X  /* get 160/128/10/len/val -  repr enum raw val */
50288 X  /* get 161/128/10/len/val -  mol enum aa val */
50289 X  /* get 162/128/02/len/val -  length int val */
50290 X  /* get 166/128 - topology (empty) */
50291 X  /* get 167/128 - seq-data */
50292 X  /* get 65/len+128/len/octet_string */
50293 X  /* pop nulls */
50294 X
50295 X  asnp->abp = chk_asn_buf(asnp,12);
50296 X
50297 X  if (*asnp->abp == ASN_SEQ) {
50298 X    end_seq++;
50299 X    asnp->abp += 2;
50300 X  }
50301 X  else {
50302 X    fprintf(stderr, " missing ASN_SEQ '0': %0x %0x\n",*asnp->abp, asnp->abp[1]);
50303 X  }
50304 X
50305 X  if (*asnp->abp == ASN_BIOSEQ_INST_REPR && *(asnp->abp+1) == 128) {
50306 X    asnp->abp+=2;
50307 X    asnp->abp = get_astr_enum(asnp, &tmp);
50308 X  }
50309 X  else {
50310 X    fprintf(stderr, " missing ASN_BIOSEQ_INST_REPR 160: %0x %0x\n",*asnp->abp, asnp->abp[1]);
50311 X  }
50312 X
50313 X  if (*asnp->abp == ASN_BIOSEQ_INST_MOL && *(asnp->abp+1) == 128) {
50314 X    asnp->abp+=2;
50315 X    asnp->abp = get_astr_enum(asnp, &tmp);
50316 X  }
50317 X  else {
50318 X    fprintf(stderr, " missing ASN_BIOSEQ_INST_MOL 161: %0x %0x\n",*asnp->abp, asnp->abp[1]);
50319 X  }
50320 X
50321 X  if (*asnp->abp == ASN_BIOSEQ_INST_LEN) {
50322 X    asnp->abp+=2;
50323 X    asnp->abp = get_astr_int(asnp, nq);
50324 X  }
50325 X  else {
50326 X    fprintf(stderr, " missing ASN_BIOSEQ_INST_LEN 161: %0x %0x\n",*asnp->abp, asnp->abp[1]);
50327 X    return asnp->abp;
50328 X  }
50329 X
50330 X  if ((*query = (unsigned char *)calloc(*nq + 1, sizeof(char)))==NULL) {
50331 X    fprintf(stderr, " cannot read %d char query\n", *nq+1);
50332 X  }
50333 X
50334 X  if (*asnp->abp == ASN_BIOSEQ_INST_TOPOL && *(asnp->abp+1) == 128 ) {
50335 X    asnp->abp += 2;
50336 X  }
50337 X
50338 X  if (*asnp->abp == ASN_BIOSEQ_INST_SEQD) {
50339 X    asnp->abp+=2;
50340 X    asnp->abp = get_astr_octstr(asnp, *query, *nq );
50341 X  }
50342 X  else {
50343 X    fprintf(stderr, " missing ASN_BIOSEQ_INST_SEQD 166: %0x %0x\n",*asnp->abp, asnp->abp[1]);
50344 X    return asnp->abp;
50345 X  }
50346 X
50347 X  asnp->abp += 4; /* skip over nulls */
50348 X
50349 X  return asnp->abp;
50350 }
50351 X
50352 X
50353 unsigned char *
50354 get_astr_textid( struct asn_bstruct *asnp,
50355 X               char *name,
50356 X               char *acc) {
50357 X  int end_seq = 0;
50358 X  int ver;
50359 X
50360 X  chk_asn_buf(asnp,16);
50361 X
50362 X  if (*asnp->abp != ASN_SEQ) {
50363 X    fprintf(stderr, " Expected ASN_SEQ: %0x %0x\n",*asnp->abp, asnp->abp[1]);
50364 X  }
50365 X  else {asnp->abp += 2; end_seq++;}
50366 X
50367 X  name[0] = acc[0] = '\0';
50368 X  
50369 X  while (*asnp->abp != '\0') {
50370 X    if (*asnp->abp == ASN_BIOSEQ_TEXTID_NAME) {
50371 X      asnp->abp+=2;
50372 X      asnp->abp = get_astr_str(asnp, name, MAX_SSTR);
50373 X    }
50374 X    if (*asnp->abp == ASN_BIOSEQ_TEXTID_ACC) {
50375 X      asnp->abp+=2;
50376 X      asnp->abp = get_astr_str(asnp, acc, MAX_SSTR);
50377 X    }
50378 X    if (*asnp->abp == ASN_BIOSEQ_TEXTID_VER) {
50379 X      asnp->abp+=2;
50380 X      asnp->abp = get_astr_int(asnp, &ver);
50381 X    }
50382 X  }
50383 X  asnp->abp += 4;
50384 X  while (end_seq-- > 0) { asnp->abp += 4; }
50385 X  return asnp->abp;
50386 }
50387 X
50388 unsigned char *
50389 get_astr_query(struct asn_bstruct *asnp,
50390 X             int *gi,
50391 X             char *name,
50392 X             char *acc,
50393 X             char *descr,
50394 X             unsigned char **query,
50395 X             int *nq
50396 X             ) {
50397 X
50398 X  int end_seq = 0;
50399 X
50400 X  asnp->abp = chk_asn_buf(asnp,32);
50401 X
50402 X  if (*asnp->abp != ASN_BIOSEQ_SEQ) {
50403 X    fprintf(stderr, "Bioseq - missing SEQ 1: %2x %2x\n",*asnp->abp, asnp->abp[1]);
50404 X    return asnp->abp;
50405 X  }
50406 X  else { asnp->abp += 2;}
50407 X
50408 X  if (*asnp->abp != ASN_SEQ && *asnp->abp != ASN_SEQOF ) {
50409 X    fprintf(stderr, "Bioseq - missing SEQUENCE tag 1: %2x %2x\n",*asnp->abp, asnp->abp[1]);
50410 X    return asnp->abp;
50411 X  }
50412 X  else { 
50413 X    end_seq++;
50414 X    asnp->abp += 2;
50415 X  }
50416 X
50417 X  if (*asnp->abp != ASN_BIOSEQ_ID) {
50418 X    fprintf(stderr, "Bioseq - missing ID tag: %2x %2x\n",*asnp->abp, asnp->abp[1]);
50419 X    return asnp->abp;
50420 X  }
50421 X  else {
50422 X    asnp->abp += 2;
50423 X    if (*asnp->abp != ASN_SEQOF) {
50424 X      fprintf(stderr, "missing bioseq/id/SEQOF tag: %d\n",*asnp->abp);
50425 X      return asnp->abp;
50426 X    }
50427 X    else {
50428 X      asnp->abp += 2;
50429 X      if (*asnp->abp == ASN_BIOSEQ_ID_VAL && *(asnp->abp+1)==128) { asnp->abp += 2;}
50430 X
50431 X      if (*asnp->abp == ASN_BIOSEQ_ID_GI ) {
50432 X       asnp->abp+=2;
50433 X       asnp->abp = get_astr_int(asnp, gi);
50434 X      }
50435 X
50436 X      if (*asnp->abp == ASN_BIOSEQ_ID_LOCAL) {
50437 X       *gi = 0;
50438 X       acc[0] = '\0';
50439 X
50440 X       asnp->abp+=2;
50441 X       asnp->abp = get_astr_str(asnp, name, MAX_SSTR);
50442 X       asnp->abp += 2;
50443 X      }
50444 X      else if (*asnp->abp == ASN_BIOSEQ_ID_SP || *asnp->abp == ASN_BIOSEQ_ID_EMBL ||
50445 X         *asnp->abp == ASN_BIOSEQ_ID_GB || *asnp->abp == ASN_BIOSEQ_ID_PIR ||
50446 X         *asnp->abp == ASN_BIOSEQ_ID_OTHER ) {
50447 X
50448 X       asnp->abp+=2;
50449 X       asnp->abp = get_astr_textid(asnp, name, acc);
50450 X      }
50451 X    }
50452 X  }
50453 X
50454 X  while (*asnp->abp == 0) asnp->abp += 2;
50455 X
50456 X  if (*asnp->abp == ASN_BIOSEQ_DESCR) {
50457 X    asnp->abp+=2;
50458 X    asnp->abp = get_astr_seqdescr(asnp, descr);
50459 X    asnp->abp += 2;            /* skip nulls */
50460 X  }
50461 X  else { descr[0] = '\0';}
50462 X
50463 X  if (*asnp->abp != ASN_BIOSEQ_INST) {
50464 X    fprintf(stderr, "Bioseq - missing ID tag: %2x %2x\n",*asnp->abp, asnp->abp[1]);
50465 X    return asnp->abp;
50466 X  }
50467 X  else { 
50468 X    asnp->abp += 2;
50469 X    asnp->abp = get_astr_seqinst(asnp, query, nq);
50470 X    asnp->abp += 2;            /* skip nulls */
50471 X  }
50472 X  return asnp->abp;
50473 }
50474 X
50475 unsigned char *
50476 get_astr_query2(struct asn_bstruct *asnp,
50477 X             int *gi,
50478 X             char *name,
50479 X             char *acc,
50480 X             char *descr,
50481 X             unsigned char **query,
50482 X             int *nq
50483 X             ) {
50484 X
50485 X  int end_seq = 0;
50486 X
50487 X  asnp->abp = chk_asn_buf(asnp,32);
50488 X
50489 X  if (*asnp->abp != ASN_BIOSEQ_SEQ) {
50490 X    fprintf(stderr, "Bioseq - missing SEQ 1: %2x %2x\n",*asnp->abp, asnp->abp[1]);
50491 X    return asnp->abp;
50492 X  }
50493 X  else { asnp->abp += 2;}
50494 X
50495 X  if (*asnp->abp != ASN_SEQOF ) {
50496 X    fprintf(stderr, "Bioseq2 - missing SEQOF tag 1: %2x %2x\n",*asnp->abp, asnp->abp[1]);
50497 X    return asnp->abp;
50498 X  }
50499 X  else { 
50500 X    end_seq++;
50501 X    asnp->abp += 2;
50502 X  }
50503 X
50504 X  if (*asnp->abp != ASN_BIOSEQ_ID) {
50505 X    fprintf(stderr, "Bioseq - missing ID tag: %2x %2x\n",*asnp->abp, asnp->abp[1]);
50506 X    return asnp->abp;
50507 X  }
50508 X  else {
50509 X    asnp->abp += 2;
50510 X    if (*asnp->abp == ASN_SEQOF) {
50511 X      asnp->abp += 2;
50512 X    }
50513 X
50514 X    if (*asnp->abp == ASN_BIOSEQ_ID_VAL && *(asnp->abp+1)==128) { asnp->abp += 2;}
50515 X
50516 X    if (*asnp->abp == ASN_BIOSEQ_ID_GI ) {
50517 X      asnp->abp+=2;
50518 X      asnp->abp = get_astr_int(asnp, gi);
50519 X    }
50520 X
50521 X    if (*asnp->abp == ASN_BIOSEQ_ID_LOCAL) {
50522 X      *gi = 0;
50523 X      acc[0] = '\0';
50524 X
50525 X      asnp->abp+=2;
50526 X      asnp->abp = get_astr_str(asnp, name, MAX_SSTR);
50527 X      asnp->abp += 2;
50528 X      }
50529 X    else if (*asnp->abp == ASN_BIOSEQ_ID_SP || *asnp->abp == ASN_BIOSEQ_ID_EMBL ||
50530 X            *asnp->abp == ASN_BIOSEQ_ID_GB || *asnp->abp == ASN_BIOSEQ_ID_PIR ||
50531 X            *asnp->abp == ASN_BIOSEQ_ID_OTHER ) {
50532 X
50533 X      asnp->abp+=2;
50534 X      asnp->abp = get_astr_textid(asnp, name, acc);
50535 X    }
50536 X  }
50537 X
50538 X  while (*asnp->abp == 0) asnp->abp += 2;
50539 X
50540 X  if (*asnp->abp == ASN_BIOSEQ_DESCR) {
50541 X    asnp->abp+=2;
50542 X    asnp->abp = get_astr_seqdescr(asnp, descr);
50543 X    asnp->abp += 2;            /* skip nulls */
50544 X  }
50545 X  else { descr[0] = '\0';}
50546 X
50547 X  if (*asnp->abp != ASN_BIOSEQ_INST) {
50548 X    fprintf(stderr, "Bioseq - missing ID tag: %2x %2x\n",*asnp->abp, asnp->abp[1]);
50549 X    return asnp->abp;
50550 X  }
50551 X  else { 
50552 X    asnp->abp += 2;
50553 X    asnp->abp = get_astr_seqinst(asnp, query, nq);
50554 X    asnp->abp += 2;            /* skip nulls */
50555 X  }
50556 X  return asnp->abp;
50557 }
50558 X
50559 unsigned char *
50560 get_pssm_freqs(struct asn_bstruct *asnp,
50561 X              double **freqs,
50562 X              int n_rows,  
50563 X              int n_cols,
50564 X              int by_row) {
50565 X
50566 X  int i_rows, i_cols;
50567 X  int in_seq = 0;
50568 X
50569 X  double f_val;
50570 X
50571 X  asnp->abp = chk_asn_buf(asnp,4);
50572 X
50573 X  if (*asnp->abp == ASN_SEQ) {
50574 X    in_seq = 1;
50575 X    asnp->abp += 2;
50576 X    in_seq = 1;
50577 X  }
50578 X
50579 X  if (!by_row) {
50580 X    for (i_cols = 0; i_cols < n_cols; i_cols++) {
50581 X      for (i_rows = 0; i_rows < n_rows; i_rows++) {
50582 X       asnp->abp = get_astr_packedfloat(asnp, &f_val);
50583 X       freqs[i_cols][i_rows] = f_val;
50584 X      }
50585 X    }
50586 X  }
50587 X  else {
50588 X    for (i_rows = 0; i_rows < n_rows; i_rows++) {
50589 X      for (i_cols = 0; i_cols < n_cols; i_cols++) {
50590 X       asnp->abp = get_astr_packedfloat(asnp, &f_val);
50591 X       freqs[i_cols][i_rows] = f_val;
50592 X      }
50593 X    }
50594 X  }
50595 X  if (in_seq) {asnp->abp +=2;} /* skip nulls */
50596 X  asnp->abp += 2;
50597 X  return asnp->abp;
50598 }
50599 X
50600 unsigned char *
50601 get_pssm_intermed(struct asn_bstruct *asnp,
50602 X                 double **freqs,
50603 X                 int n_rows,
50604 X                 int n_cols,
50605 X                 int by_row) {
50606 X
50607 X  asnp->abp = chk_asn_buf(asnp,4);
50608 X
50609 X  if (*asnp->abp == ASN_SEQ) {
50610 X    asnp->abp += 2;
50611 X    if (*asnp->abp == ASN_PSSM_FREQS) {
50612 X      asnp->abp+=2;
50613 X      asnp->abp = get_pssm_freqs(asnp, freqs, n_rows, n_cols, by_row);
50614 X    }
50615 X    asnp->abp +=2;     /* skip nulls */
50616 X  }
50617 X  asnp->abp += 2;
50618 X  return asnp->abp;
50619 }
50620 X
50621 X
50622 #define ASN_PSSM_PARAMS 161
50623 #define ASN_PSSM_PARAMS_PSEUDOCNT 160
50624 #define ASN_PSSM_PARAMS_RPSPARAMS 161
50625 #define ASN_PSSM_RPSPARAMS_MATRIX 160
50626 #define ASN_PSSM_RPSPARAMS_GAPOPEN 161
50627 #define ASN_PSSM_RPSPARAMS_GAPEXT 162
50628 X
50629 unsigned char *
50630 get_pssm_rpsparams(struct asn_bstruct *asnp,
50631 X              char *matrix,
50632 X              int *gap_open,
50633 X              int *gap_ext) {
50634 X
50635 X  int end_seq=0;
50636 X
50637 X  asnp->abp = chk_asn_buf(asnp,4);
50638 X
50639 X  if (*asnp->abp == ASN_SEQ) {
50640 X    asnp->abp += 2;
50641 X    end_seq++;
50642 X  }
50643 X
50644 X  if (*asnp->abp == ASN_PSSM_RPSPARAMS_MATRIX) {
50645 X    asnp->abp+=2;
50646 X    asnp->abp = get_astr_str(asnp, matrix, MAX_SSTR);
50647 X  }
50648 X
50649 X  if (*asnp->abp == ASN_PSSM_RPSPARAMS_GAPOPEN) {
50650 X    asnp->abp+=2;
50651 X    asnp->abp = get_astr_int(asnp, gap_open);
50652 X  }
50653 X
50654 X  if (*asnp->abp == ASN_PSSM_RPSPARAMS_GAPEXT) {
50655 X    asnp->abp+=2;
50656 X    asnp->abp = get_astr_int(asnp, gap_ext);
50657 X  }
50658 X
50659 X  if (end_seq) { chk_asn_buf(asnp,end_seq * 2); }
50660 X  while (end_seq-- > 0) { asnp->abp += 2; }
50661 X  return asnp->abp;
50662 }
50663 X
50664 unsigned char *
50665 get_pssm_params(struct asn_bstruct *asnp,
50666 X              int *pseudo_cnts,
50667 X              char *matrix,
50668 X              int *gap_open,
50669 X              int *gap_ext) {
50670 X
50671 X  int end_seq=0;
50672 X
50673 X  asnp->abp = chk_asn_buf(asnp,6);
50674 X
50675 X  if (*asnp->abp == ASN_SEQ) {
50676 X    asnp->abp += 2;
50677 X    end_seq++;
50678 X  }
50679 X
50680 X  if (*asnp->abp == ASN_PSSM_PARAMS_PSEUDOCNT) {
50681 X    asnp->abp+=2;
50682 X    asnp->abp = get_astr_int(asnp, pseudo_cnts);
50683 X  }
50684 X
50685 X  if (*asnp->abp == ASN_PSSM_PARAMS_RPSPARAMS) {
50686 X    asnp->abp+=2;
50687 X    asnp->abp = get_pssm_rpsparams(asnp, matrix, gap_open, gap_ext);
50688 X    asnp->abp += 2;
50689 X  }
50690 X  while (end_seq-- > 0) { asnp->abp+=2; }
50691 X  return asnp->abp;
50692 }
50693 X
50694 X
50695 unsigned char *
50696 get_pssm2_intermed(struct asn_bstruct *asnp,
50697 X                  double ***freqs,
50698 X                  int n_rows,
50699 X                  int n_cols) {
50700 X
50701 X  int i;
50702 X  double **my_freqs;
50703 X
50704 X  if ((my_freqs = (double **) calloc(n_cols, sizeof(double *)))==NULL) {
50705 X    fprintf(stderr, " cannot allocate freq cols - %d\n", n_cols);
50706 X    exit(1);
50707 X  }
50708 X
50709 X  if ((my_freqs[0] = (double *) calloc(n_cols * n_rows, sizeof(double)))==NULL) {
50710 X    fprintf(stderr, " cannot allocate freq rows * cols - %d * %d\n", n_rows, n_cols);
50711 X    exit(1);
50712 X  }
50713 X
50714 X  for (i=1; i < n_cols; i++) {
50715 X    my_freqs[i] = my_freqs[i-1] + n_rows;
50716 X  }
50717 X
50718 X  *freqs = my_freqs;
50719 X
50720 X  chk_asn_buf(asnp, 8);
50721 X
50722 X  return get_pssm_freqs(asnp, my_freqs, n_rows, n_cols, 0);
50723 }
50724 X
50725 int
50726 parse_pssm2_asn(struct asn_bstruct *asnp,
50727 X               int *gi,
50728 X               char *name,
50729 X               char *acc,
50730 X               char *descr,
50731 X               unsigned char **query, 
50732 X               int *nq,
50733 X               int *n_rows,
50734 X               int *n_cols,
50735 X               double ***freqs,
50736 X               int *pseudo_cnts,
50737 X               char *matrix, 
50738 X               double *lambda_p) {
50739 X
50740 X  int is_protein;
50741 X  int have_rows, have_cols;
50742 X
50743 X  chk_asn_buf(asnp, 32);
50744 X
50745 X  if (memcmp(asnp->abp, "\241\2000\200",4) != 0) {
50746 X    fprintf(stderr, "improper PSSM2 start\n");
50747 X    return -1;
50748 X  }
50749 X  else {asnp->abp+=4;}
50750 X
50751 X  if (*asnp->abp == ASN_BIOSEQ_SEQ ) {
50752 X    asnp->abp = get_astr_query2(asnp, gi, name, acc, descr, query, nq);
50753 X  }
50754 X
50755 X  /* finish up the nulls */
50756 X  while (*asnp->abp == '\0') { asnp->abp += 2;}
50757 X
50758 X  if (*asnp->abp == ASN_PSSM2_QUERY && 
50759 X       asnp->abp[2] != ASN_SEQ ) {
50760 X      fprintf(stderr, "improper PSSM2 start\n");
50761 X      return -1;
50762 X  }
50763 X  else {asnp->abp += 4;}
50764 X
50765 X  while (*asnp->abp != '\0' ) {
50766 X
50767 X    switch (*asnp->abp) {
50768 X    case ASN_PSSM_IS_PROT :
50769 X      asnp->abp+=2;
50770 X      asnp->abp = get_astr_bool(asnp, &is_protein);
50771 X      break;
50772 X
50773 X    case ASN_PSSM2_MATRIX :
50774 X      asnp->abp+=2;
50775 X      asnp->abp = get_astr_str(asnp, matrix, MAX_SSTR);
50776 X      break;
50777 X
50778 X    case ASN_PSSM2_NROWS :
50779 X      asnp->abp+=2;
50780 X      asnp->abp = get_astr_int(asnp, n_rows);
50781 X      
50782 X      if (*n_rows > 0) { have_rows = 1; }
50783 X      else {
50784 X       fprintf(stderr, " bad n_row count\n");
50785 X       exit(1);
50786 X      }
50787 X      break;
50788 X
50789 X    case  ASN_PSSM2_NCOLS :
50790 X      asnp->abp+=2;
50791 X      asnp->abp = get_astr_int(asnp, n_cols);
50792 X      if (*n_cols > 0) {
50793 X       have_cols = 1;
50794 X      }
50795 X      else {
50796 X       fprintf(stderr, " bad n_row count\n");
50797 X       exit(1);
50798 X      }
50799 X      break;
50800 X    
50801 X    case ASN_PSSM2_FREQS :
50802 X      asnp->abp += 4;
50803 X      if (*asnp->abp == '\0') { asnp->abp += 4;}
50804 X      break;
50805 X
50806 X    case ASN_PSSM2_LAMBDA :
50807 X      asnp->abp += 2;
50808 X      asnp->abp = get_astr_packedfloat(asnp,lambda_p);
50809 X      asnp->abp +=2;   /* skip over end of ASN_PSSM2_LAMBDA */
50810 X      break;
50811 X
50812 X    case ASN_PSSM_INTERMED_DATA :
50813 X      asnp->abp += 2;
50814 X      asnp->abp = get_pssm2_intermed(asnp, freqs, *n_rows, *n_cols);
50815 X      asnp->abp += 4;
50816 X      break;
50817 X
50818 X    default: asnp->abp += 2;
50819 X    }
50820 X  }
50821 X
50822 X
50823 X  return 1;
50824 }
50825 X
50826 int
50827 parse_pssm_asn(FILE *afd,
50828 X              int *gi,
50829 X              char *name,
50830 X              char *acc,
50831 X              char *descr,
50832 X              unsigned char **query, 
50833 X              int *nq,
50834 X              int *n_rows,
50835 X              int *n_cols,
50836 X              double ***freqs,
50837 X              int *pseudo_cnts,
50838 X              char *matrix,
50839 X              int *gap_open,
50840 X              int *gap_ext,
50841 X              double *lambda_p) {
50842 X
50843 X  int is_protein, pssm_version;
50844 X  int i;
50845 X  int have_rows, have_cols, by_col;
50846 X  double **my_freqs;
50847 X
50848 X  struct asn_bstruct asn_str;
50849 X
50850 X  if ((asn_str.buf = (unsigned char *)calloc(ASN_BUF, sizeof(char))) == NULL ) {
50851 X    fprintf(stderr, " cannot allocate asn_buf (%d)\n",ASN_BUF);
50852 X    exit(1);
50853 X  }
50854 X
50855 X  asn_str.fd = afd;
50856 X  asn_str.len = ASN_BUF;
50857 X  asn_str.abp = asn_str.buf_max = asn_str.buf + ASN_BUF;
50858 X
50859 X  chk_asn_buf(&asn_str, 32);
50860 X
50861 X  if (memcmp(asn_str.abp, "0\200\240\200",4) != 0) {
50862 X    fprintf(stderr, "improper PSSM header -");
50863 X    return -1;
50864 X  }
50865 X  else {asn_str.abp+=4;}
50866 X
50867 X  if (*asn_str.abp == ASN_IS_INT) {
50868 X    asn_str.abp = get_astr_int(&asn_str, &pssm_version);
50869 X    if (pssm_version != 2) {
50870 X      fprintf(stderr, "PSSM2 version mismatch: %d\n",pssm_version);
50871 X      return -1;
50872 X    }
50873 X    *gap_open = *gap_ext = 0;
50874 X    return parse_pssm2_asn(&asn_str, gi, name, acc, descr,
50875 X                          query, nq,
50876 X                          n_rows, n_cols, freqs,
50877 X                          pseudo_cnts, matrix,
50878 X                          lambda_p);
50879 X  }
50880 X
50881 X  if (*asn_str.abp == ASN_SEQ) { asn_str.abp += 2;  }
50882 X
50883 X  if (*asn_str.abp == ASN_PSSM_IS_PROT ) {
50884 X    asn_str.abp+=2;
50885 X    asn_str.abp = get_astr_bool(&asn_str, &is_protein);
50886 X  }
50887 X
50888 X  if (*asn_str.abp == ASN_PSSM_NROWS ) {
50889 X    asn_str.abp+=2;
50890 X    asn_str.abp = get_astr_int(&asn_str, n_rows);
50891 X
50892 X    if (*n_rows > 0) { have_rows = 1; }
50893 X    else {
50894 X      fprintf(stderr, " bad n_row count\n");
50895 X      exit(1);
50896 X    }
50897 X  }
50898 X
50899 X  if (*asn_str.abp == ASN_PSSM_NCOLS ) {
50900 X    asn_str.abp+=2;
50901 X    asn_str.abp = get_astr_int(&asn_str, n_cols);
50902 X    if (*n_cols > 0) {
50903 X      have_cols = 1;
50904 X    }
50905 X    else {
50906 X      fprintf(stderr, " bad n_row count\n");
50907 X      exit(1);
50908 X    }
50909 X  }
50910 X
50911 X  if (*asn_str.abp == ASN_PSSM_BYCOL ) {
50912 X    asn_str.abp+=2;
50913 X    asn_str.abp = get_astr_bool(&asn_str, &by_col);
50914 X  }
50915 X
50916 X  /* we have read everything up to the query 
50917 X
50918 X     n_cols gives us the query length, which we can allocate;
50919 X  */
50920 X
50921 X  if (*asn_str.abp == ASN_PSSM_QUERY ) {
50922 X    asn_str.abp+=2;
50923 X    asn_str.abp = get_astr_query(&asn_str, gi, name, acc, descr, query, nq);
50924 X    *nq = *n_cols;
50925 X  }
50926 X
50927 X  /* finish up the nulls */
50928 X  while (*asn_str.abp == '\0') { asn_str.abp += 2;}
50929 X
50930 X  if (*asn_str.abp == ASN_PSSM_INTERMED_DATA) {
50931 X
50932 X    if (!have_rows || !have_cols) {
50933 X      fprintf(stderr, " cannot allocate freq - missing rows/cols - %d/%d\n",
50934 X             have_rows, have_cols);
50935 X      return -1;
50936 X    }
50937 X
50938 X    if ((my_freqs = (double **) calloc(*n_cols, sizeof(double *)))==NULL) {
50939 X      fprintf(stderr, " cannot allocate freq cols - %d\n", *n_cols);
50940 X      return -1;
50941 X    }
50942 X
50943 X    if ((my_freqs[0] = (double *) calloc(*n_cols * *n_rows, sizeof(double)))==NULL) {
50944 X      fprintf(stderr, " cannot allocate freq rows * cols - %d * %d\n", *n_rows, *n_cols);
50945 X      return -1;
50946 X    }
50947 X    for (i=1; i < *n_cols; i++) {
50948 X      my_freqs[i] = my_freqs[i-1] + *n_rows;
50949 X    }
50950 X
50951 X    *freqs = my_freqs;
50952 X
50953 X    asn_str.abp+=2;
50954 X    asn_str.abp = get_pssm_intermed(&asn_str, my_freqs, *n_rows, *n_cols, by_col);
50955 X    asn_str.abp += 4;
50956 X  }
50957 X
50958 X  if (*asn_str.abp == ASN_PSSM_PARAMS ) {
50959 X      asn_str.abp+=2;
50960 X      asn_str.abp = get_pssm_params(&asn_str, pseudo_cnts, matrix, gap_open, gap_ext);
50961 X  }
50962 X  else if (*asn_str.abp == 0) {asn_str.abp+=2;}
50963 X  return 1;
50964 }
50965 X
50966 int
50967 parse_pssm_asn_fa( FILE *fd, 
50968 X                  int *n_rows_p, int *n_cols_p,
50969 X                  unsigned char **query,
50970 X                  double ***freq2d,
50971 X                  char *matrix,
50972 X                  int *gap_open_p,
50973 X                  int *gap_extend_p,
50974 X                  double *lambda_p) {
50975 X
50976 X  int qi, rj;
50977 X  int gi;
50978 X  double tmp_freqs[COMPO_LARGEST_ALPHABET];
50979 X  char name[MAX_SSTR], acc[MAX_SSTR], descr[MAX_STR];
50980 X  int  nq;
50981 X  int pseudo_cnts, ret_val;
50982 X
50983 X  /* parse the file */
50984 X
50985 X  ret_val = parse_pssm_asn(fd, &gi, name, acc, descr, query, &nq,
50986 X                          n_rows_p, n_cols_p, freq2d,
50987 X                          &pseudo_cnts, matrix, gap_open_p, gap_extend_p,
50988 X                          lambda_p);
50989 X
50990 X  if (ret_val <=0) return ret_val;
50991 X
50992 X  /* transform the frequencies */
50993 X
50994 X  for (qi = 0; qi < *n_cols_p; qi++) {
50995 X    for (rj = 0; rj < *n_rows_p; rj++) { tmp_freqs[rj] = (*freq2d)[qi][rj];}
50996 X
50997 X    for (rj = 0; rj < COMPO_NUM_TRUE_AA; rj++) {
50998 X      (*freq2d)[qi][rj] = tmp_freqs[pssm_aa_order[rj]];
50999 X    }
51000 X  }
51001 X  return 1;
51002 }
51003 SHAR_EOF
51004 chmod 0644 pssm_asn_subs.c ||
51005 echo 'restore of pssm_asn_subs.c failed'
51006 Wc_c="`wc -c < 'pssm_asn_subs.c'`"
51007 test 26268 -eq "$Wc_c" ||
51008         echo 'pssm_asn_subs.c: original size 26268, current size' "$Wc_c"
51009 fi
51010 # ============= pthr_subs.h ==============
51011 if test -f 'pthr_subs.h' -a X"$1" != X"-c"; then
51012         echo 'x - skipping pthr_subs.h (File already exists)'
51013 else
51014 echo 'x - extracting pthr_subs.h (Text)'
51015 sed 's/^X//' << 'SHAR_EOF' > 'pthr_subs.h' &&
51016 X
51017 X
51018 /* $Name: fa_34_26_5 $ - $Id: pthr_subs.h,v 1.1.1.1 1999/10/22 20:56:01 wrp Exp $ */
51019 X
51020 X
51021 #include <pthread.h>
51022 X
51023 /* error macro for thread calls */
51024 X
51025 #define check(status,string) \
51026 X   if (status != 0) {fprintf(stderr,string); \
51027 X     fprintf(stderr,"%s\n",strerror(status)); } /* error macro */
51028 X
51029 /*
51030 #define check(status,string) \
51031 X     if (status == -1) perror(string)  */ /* error macro for thread calls */
51032 X
51033 X
51034 #ifndef XTERNAL
51035 pthread_t threads[MAX_WORKERS];
51036 X
51037 /* mutex stuff */
51038 X
51039 pthread_mutex_t reader_mutex;      /* empty buffer pointer structure lock */
51040 pthread_mutex_t worker_mutex;      /* full buffer pointer structure lock */
51041 X
51042 /* condition variable stuff */
51043 X
51044 pthread_cond_t reader_cond_var;    /* condition variable for reader */
51045 pthread_cond_t worker_cond_var;    /* condition variable for workers */
51046 X
51047 pthread_mutex_t start_mutex;       /* start-up synchronisation lock */
51048 pthread_cond_t start_cond_var;     /* start-up synchronisation condition variable */
51049 X
51050 extern pthread_t threads[];
51051 X
51052 /* mutex stuff */
51053 X
51054 extern pthread_mutex_t reader_mutex;
51055 extern pthread_mutex_t worker_mutex;
51056 X
51057 /* condition variable stuff */
51058 X
51059 extern pthread_cond_t reader_cond_var;
51060 extern pthread_cond_t worker_cond_var;
51061 X
51062 extern pthread_mutex_t start_mutex;
51063 extern pthread_cond_t start_cond_var;
51064 extern int start_thread;
51065 X
51066 #endif
51067 SHAR_EOF
51068 chmod 0644 pthr_subs.h ||
51069 echo 'restore of pthr_subs.h failed'
51070 Wc_c="`wc -c < 'pthr_subs.h'`"
51071 test 1301 -eq "$Wc_c" ||
51072         echo 'pthr_subs.h: original size 1301, current size' "$Wc_c"
51073 fi
51074 # ============= pthr_subs2.c ==============
51075 if test -f 'pthr_subs2.c' -a X"$1" != X"-c"; then
51076         echo 'x - skipping pthr_subs2.c (File already exists)'
51077 else
51078 echo 'x - extracting pthr_subs2.c (Text)'
51079 sed 's/^X//' << 'SHAR_EOF' > 'pthr_subs2.c' &&
51080 X
51081 /* copyright (c) 1996, 1997, 1998, 1999 William R. Pearson and the
51082 X   U. of Virginia */
51083 X
51084 /* modified to do more initialization of work_info here, rather than in main() */
51085 X
51086 /* $Name: fa_34_26_5 $ - $Id: pthr_subs2.c,v 1.9 2006/06/22 02:35:05 wrp Exp $ */
51087 X
51088 /* this file isolates the pthreads calls from the main program */
51089 X
51090 #include <stdio.h>
51091 #include <stdlib.h>
51092 #include <string.h>
51093 #include <time.h>
51094 #include <sys/types.h>
51095 #include <signal.h>
51096 X
51097 #include "defs.h"
51098 #include "structs.h"            /* mngmsg, libstruct */
51099 #include "param.h"              /* pstruct, thr_str, buf_head, rstruct */
51100 X
51101 #include <pthread.h>
51102 #define XTERNAL
51103 #include "thr.h"
51104 #undef XTERNAL
51105 #include "pthr_subs.h"
51106 X
51107 extern void work_thread (struct thr_str *);
51108 X
51109 /* start the threads working */
51110 X
51111 void init_thr(int nthreads, struct thr_str *work_info,
51112 X             struct mngmsg m_msg, struct pstruct *ppst,
51113 X             unsigned char *aa0, int max_work_buf)
51114 {
51115 X  int status, i;
51116 X  pthread_attr_t thread_attr;
51117 X
51118 X  if (nthreads > MAX_WORKERS) {
51119 X    fprintf ( stderr," cannot start %d threads, max: %d\n",
51120 X             nthreads, MAX_WORKERS);
51121 X    exit(1);
51122 X  }
51123 X
51124 X  /* set up work_info[] structure, set parameters */
51125 X
51126 X  for (i=0; i<nthreads; i++) {
51127 X    work_info[i].n0 = m_msg.n0;
51128 X    work_info[i].nm0 = m_msg.nm0;
51129 X    work_info[i].qframe = m_msg.qframe;
51130 X    work_info[i].qshuffle = m_msg.qshuffle;
51131 X    work_info[i].ppst = ppst;
51132 X    work_info[i].aa0 = aa0;
51133 X    work_info[i].max_work_buf=max_work_buf;
51134 X    work_info[i].worker=i;
51135 X    work_info[i].max_tot=m_msg.max_tot;
51136 X  }
51137 X
51138 X  /* mutex and condition variable initialisation */
51139 X
51140 X  status = pthread_mutex_init(&reader_mutex, NULL);
51141 X  check(status,"Reader_mutex init bad status\n");
51142 X   
51143 X  status = pthread_mutex_init(&worker_mutex, NULL);
51144 X  check(status,"Worker_mutex init bad status\n");
51145 X
51146 X  status = pthread_cond_init(&reader_cond_var, NULL);
51147 X  check(status,"Reader_cond_var init bad status\n");
51148 X
51149 X  status = pthread_cond_init(&worker_cond_var, NULL);
51150 X  check(status,"Worker_cond_var init bad status\n");
51151 X
51152 X  status = pthread_mutex_init(&start_mutex, NULL);
51153 X  check(status,"Start_mutex init bad status\n");
51154 X
51155 X  status = pthread_cond_init(&start_cond_var, NULL);
51156 X  check(status,"Start_cond_var init bad status\n");
51157 X
51158 X  /* change stacksize on threads */    /***************************/
51159 X
51160 X  status = pthread_attr_init( &thread_attr );
51161 X  check(status,"attribute create bad status\n");
51162 X
51163 #ifdef IRIX
51164 X  if (pthread_attr_setscope( &thread_attr, 2) != NULL) 
51165 X    status = pthread_attr_setscope( &thread_attr,PTHREAD_SCOPE_PROCESS);
51166 X  check(status,"set scope on IRIX bad status\n");
51167 #endif
51168 X
51169 #ifdef FASTA_setscope
51170 X  status = pthread_attr_setscope( &thread_attr, PTHREAD_SCOPE_SYSTEM);
51171 X  check(status,"set scope bad status\n");
51172 #endif
51173 X
51174 X  /* start the worker threads */
51175 X
51176 X  for (i=0; i < nthreads; i++) {
51177 X    /**********************/
51178 X    status=pthread_create(&threads[i],&thread_attr,
51179 X                         (void *(*)(void *))&work_thread,&work_info[i]);
51180 X    check(status,"Pthread_create failed\n");
51181 X  }
51182 }
51183 X
51184 /* start_mutex/start_cont_var provides exclusive access to 
51185 X   extern int start_thread */
51186 X
51187 void start_thr()
51188 {
51189 X  int status;
51190 X
51191 X  /* tell threads to proceed */
51192 X
51193 X  status = pthread_mutex_lock(&start_mutex);
51194 X  check(status,"Start_mutex lock bad status in main\n");
51195 X
51196 X  start_thread = 0;  /* lower predicate */
51197 X
51198 X  status = pthread_cond_broadcast(&start_cond_var);
51199 X  status = pthread_mutex_unlock(&start_mutex);
51200 X  check(status,"Start_mutex unlock bad status in main\n");
51201 }
51202 X
51203 void get_rbuf(struct buf_head **cur_buf, int max_work_buf)
51204 {
51205 X  int status;
51206 X
51207 X  status = pthread_mutex_lock(&reader_mutex);  /* lock reader_buf structure */
51208 X
51209 X  check(status,"Reader_mutex lock in master bad status\n");
51210 X
51211 X  /* no reader bufs:  wait for signal to proceed */
51212 X  while (num_reader_bufs == 0) {
51213 X    pthread_cond_wait(&reader_cond_var,&reader_mutex);
51214 X  }
51215 X
51216 X  *cur_buf = reader_buf[reader_buf_readp];  /* get the buffer address */
51217 X  reader_buf_readp = (reader_buf_readp+1)%(max_work_buf);  /* increment index */
51218 X  num_reader_bufs--;
51219 X
51220 X  status = pthread_mutex_unlock(&reader_mutex);  /* unlock structure */
51221 X  check(status,"Reader_mutex unlock in master bad status\n");
51222 }
51223 X
51224 void put_rbuf(struct buf_head *cur_buf, int max_work_buf)
51225 {
51226 X  int status;
51227 X
51228 X  /* give the buffer to a thread, and wait for more */
51229 X  status = pthread_mutex_lock(&worker_mutex);  /* lock worker_buf_structure */
51230 X  check(status,"Worker_mutex lock in master bad status\n");
51231 X
51232 X  /*  Put buffer onto available for workers list */
51233 X  worker_buf[worker_buf_readp] = cur_buf;
51234 X  worker_buf_readp = (worker_buf_readp+1)%(max_work_buf);
51235 X  num_worker_bufs++;   /* increment number of buffers available to workers */
51236 X
51237 X  /*  Signal one worker to wake and start work */
51238 X  status = pthread_cond_signal(&worker_cond_var);
51239 X
51240 X  status = pthread_mutex_unlock(&worker_mutex);
51241 X  check(status,"Worker_mutex unlock in master bad status\n"); 
51242 }
51243 X
51244 void put_rbuf_done(int nthreads, struct buf_head *cur_buf, int max_work_buf)
51245 {
51246 X  int status, i;
51247 X  void *exit_value;
51248 X
51249 X  /* give the buffer to a thread, and wait for more */
51250 X  status = pthread_mutex_lock(&worker_mutex);  /* lock worker_buf_structure */
51251 X  check(status,"Worker_mutex lock in master bad status\n");
51252 X
51253 X  /*  Put buffer onto available for workers list */
51254 X  worker_buf[worker_buf_readp] = cur_buf;
51255 X  worker_buf_readp = (worker_buf_readp+1)%(max_work_buf);
51256 X  num_worker_bufs++;   /* increment number of buffers available to workers */
51257 X
51258 X  /*  Signal one worker to wake and start work */
51259 X
51260 X  reader_done = 1;
51261 X  status = pthread_cond_broadcast(&worker_cond_var);
51262 X
51263 X  status = pthread_mutex_unlock(&worker_mutex);
51264 X  check(status,"Worker_mutex unlock in master bad status\n"); 
51265 X
51266 X  /* wait for all buffers available (means all do_workers are done) */
51267
51268 X  for (i=0; i < nthreads; i++) {
51269 X    status = pthread_join( threads[i], &exit_value);
51270 X    check(status,"Pthread_join bad status\n");
51271 X  } 
51272 }
51273 X
51274 /* wait for extern int start_thread == 0 */
51275 X
51276 void wait_thr()
51277 {
51278 X  int status;
51279 X
51280 X  /* Wait on master to give start signal */
51281 X  status = pthread_mutex_lock(&start_mutex);
51282 X  check(status,"Start_mutex lock bad status in worker\n");
51283 X
51284 X  while (start_thread) {
51285 X         status = pthread_cond_wait(&start_cond_var, &start_mutex);
51286 X         check(status,"Start_cond_wait bad status in worker\n");
51287 X  }
51288 X
51289 X  status = pthread_mutex_unlock(&start_mutex);
51290 X  check(status,"Start_mutex unlock bad status in worker\n");
51291 }
51292 X
51293 int get_wbuf(struct buf_head **cur_buf, int max_work_buf)
51294 {
51295 X  int status;
51296 X
51297 X  /* get a buffer to work on */
51298 X  status = pthread_mutex_lock(&worker_mutex);
51299 X  check(status,"First worker_mutex lock in worker bad status\n");
51300 X
51301 X  /*  No worker_bufs available:  wait for reader to produce some */
51302 X  while (num_worker_bufs == 0) {
51303 X    /*  Exit if reader has finished */
51304 X    if (reader_done) {
51305 X      pthread_mutex_unlock(&worker_mutex);
51306 X      return 0;
51307 X    }
51308 X    pthread_cond_wait(&worker_cond_var,&worker_mutex);
51309 X  } /* end while */
51310 X
51311 X  /*  Get the buffer from list */
51312 X  *cur_buf = worker_buf[worker_buf_workp];
51313 X  worker_buf_workp = (worker_buf_workp+1)%(max_work_buf);
51314 X  num_worker_bufs--;
51315 X
51316 X  status = pthread_mutex_unlock(&worker_mutex);
51317 X  check(status,"First worker_mutex unlock in worker bad status\n");
51318 X  return 1;
51319 }
51320 X
51321 void put_wbuf(struct buf_head *cur_buf, int max_work_buf)
51322 {
51323 X  int status;
51324 X
51325 X  /* put buffer back on list for reader */
51326 X  status = pthread_mutex_lock(&reader_mutex);
51327 X  check(status,"Reader_mutex lock in worker bad status\n");
51328 X    
51329 X  reader_buf[reader_buf_workp] = cur_buf;
51330 X  reader_buf_workp = (reader_buf_workp+1)%(max_work_buf);
51331 X  num_reader_bufs++;
51332 X
51333 X  /* No reader_bufs available:  wake reader */
51334 X  if (num_reader_bufs == 1) {
51335 X    pthread_cond_signal(&reader_cond_var);
51336 X  }
51337 X
51338 X  status = pthread_mutex_unlock(&reader_mutex);
51339 X  check(status,"Reader_mutex unlock in worker bad status\n");
51340 }
51341 SHAR_EOF
51342 chmod 0644 pthr_subs2.c ||
51343 echo 'restore of pthr_subs2.c failed'
51344 Wc_c="`wc -c < 'pthr_subs2.c'`"
51345 test 7689 -eq "$Wc_c" ||
51346         echo 'pthr_subs2.c: original size 7689, current size' "$Wc_c"
51347 fi
51348 # ============= pvcomp.1 ==============
51349 if test -f 'pvcomp.1' -a X"$1" != X"-c"; then
51350         echo 'x - skipping pvcomp.1 (File already exists)'
51351 else
51352 echo 'x - extracting pvcomp.1 (Text)'
51353 sed 's/^X//' << 'SHAR_EOF' > 'pvcomp.1' &&
51354 .TH PVCOMPFA/PVCOMPSW/v3.4 1 "January, 2003"
51355 .SH NAME
51356 .B pv34compfa
51357 \- scan a protein or DNA sequence library for similar
51358 sequences using the FASTA algorithm in parallel on a network of
51359 machines running pvm3.
51360 X
51361 .B pv34compsw
51362 \- scan a protein or DNA sequence library for similar
51363 sequences using the Smith-Waterman algorithm in parallel on a network
51364 of machines running pvm3.
51365 X
51366 .B ps34compfa
51367 \- evaluate sequence comparison parameters using the FASTA
51368 algorithm and super-family-annotated libraries.
51369 X
51370 .B ps34compsw
51371 \- evaluate sequence comparison parameters using the
51372 Smith-Waterman algorithm and super-family-annotated libraries.
51373 X
51374 .SH SYNOPSIS
51375 .B pv34compfa
51376 [-Q|q -B -b # -d # -E # -f # -g # -H -i J # -n -o -p #
51377 \& -R
51378 .I STATFILE
51379 \& -r "+n/-m" \& -S -s
51380 .I SMATRIX
51381 \& -w # -1 ] query-library reference-library [
51382 .I ktup
51383 ]
51384 .B pv34compfa
51385 [\-QBbcefgHiJnopRrSsw1] \- interactive mode
51386 X
51387 .B pv34compsw
51388 [-Q|q -B -b # -e -f delval -g gapval -i
51389 \& -n -p # -R -R
51390 .I STATFILE
51391 \& -r "+n/-m" \& -S -s
51392 \& -s
51393 .I SMATRIX
51394 X ] query-library reference-library [
51395 .I ktup
51396 ]
51397 X
51398 .B pv34compsw
51399 [\-QBbefgnpRrsS] \- interactive mode
51400 X
51401 .SH DESCRIPTION
51402 .B pv34compfa
51403 and
51404 .B pv34compsw
51405 compare all of the sequences in one DNA or protein sequence library
51406 (the query library) with to all of the entries in a reference sequence
51407 library using the FASTA (pv34compfa) or Smith-Waterman (pv34compsw)
51408 algorithms.  For example,
51409 .B pv34compfa
51410 can compare a library of protein sequences to all of the sequences in
51411 the NBRF PIR protein sequence database.
51412 .B pv34compfa
51413 and
51414 .B pv34compsw
51415 are designed to run in parallel on networks of unix workstations using
51416 the PVM parallel programming system. (For more information on PVM,
51417 send email to "netlib@ornl.gov" with the message "send index for pvm3").
51418 .PP
51419 .B pv34compfa
51420 uses the rapid sequence comparison algorithm
51421 described in Pearson and Lipman, Proc. Natl. Acad. USA, (1988) 85:2444.
51422 The program can be invoked either with command line arguments or in
51423 interactive mode.  The optional third argument,
51424 .I ktup
51425 sets the sensitivity and speed of the search.  If
51426 .I ktup=2,
51427 similar regions in the two sequences being compared are found by
51428 looking at pairs of aligned residues; if
51429 .I ktup=1,
51430 single aligned amino acids are examined.
51431 .I ktup
51432 can be set to 2 or 1 for protein sequences, or from 1 to 6 for DNA sequences.
51433 The default if
51434 .I
51435 ktup
51436 is not specified is 2 for proteins and 6 for DNA.
51437 .PP
51438 .B pv34compfa
51439 compares a library of query sequences (there need be only one) to a
51440 reference sequence library.  Normally
51441 .B pv34compfa
51442 sorts the output by the
51443 .I initn
51444 score.  By using the
51445 .I \-1
51446 option, sequences are ranked by their
51447 .B init1
51448 score.  Alternative, the
51449 .I \-o
51450 option causes optimized scores to be calculated for every sequence
51451 greater than a threshold and the output to be sorted by the optimized
51452 scores.
51453 .PP
51454 .B pv34compsw
51455 uses the rigorous Smith-Waterman algorithm to compare protein or
51456 DNA sequences. The gap penalties and scoring matrices can be
51457 modified with the 
51458 .I -f\c
51459 \&, 
51460 .I -k\c
51461 \&, and 
51462 .I -s
51463 options.
51464 .PP
51465 .B pv34compfa
51466 (and
51467 .B pv34compsw\c
51468 \&) will automatically decide whether the query sequence is DNA or
51469 protein by reading the query sequence as protein and determining
51470 whether the `amino-acid composition' is more than 85% A+C+G+T.
51471 .PP
51472 .B ps34compfa
51473 and
51474 .B ps34compsw
51475 are versions of
51476 .B pv34compfa
51477 and
51478 .B pv34compsw
51479 that evaluate the quality of a search by reporting how many
51480 high-scoring related sequences and low-scoring unrelated sequences
51481 were found.  These programs require that both the query library and
51482 the reference library be annotated with superfamily numbers for every
51483 sequence in the library.
51484 .SH OPTIONS
51485 .LP
51486 .B Pv34compfa
51487 and
51488 .B pv34compsw
51489 now support all the options of the fasta3(_t) programs.
51490 .TP
51491 \-B
51492 Report z-score, rather than bit-score, in list of best hits.
51493 .TP
51494 \-b #
51495 The number of similarity scores to be shown (10 by default).
51496 .TP
51497 \-E #
51498 Expectation value limit for displaying best scores.
51499 .TP
51500 \-d #
51501 The number of alignments to be shown.
51502 .TP
51503 \-f #
51504 (delval) penalty for the first residue in a gap. -12 by default for proteins.
51505 .TP
51506 \-g #
51507 (gapval) penalty for additional residues in a gap after the first. -2
51508 by default for proteins.
51509 .TP
51510 \-H #
51511 turn on histogram display (off by default).
51512 .TP
51513 \-i
51514 invert (reverse complement) DNA sequence.
51515 .TP
51516 \-J M:N
51517 start at the M-th sequence in the query library and continue to the
51518 "N-th".  By default, J=1 and the search begins with the first sequence
51519 and ends with the last, but sometimes it makes sense to start in the
51520 middle of the query library if a run partially completed, and to
51521 finish "early" if the analysis will be run on several parallel
51522 clusters.
51523 .TP
51524 \-n
51525 Force the program to use DNA sequence parameters.
51526 .TP
51527 \-p #
51528 Number of "slave" processors to use.  Typically, one less than
51529 the number of processors available with
51530 .B pv34compfa
51531 so that one processor can be used to collate results.  With
51532 .B pv34compsw\c
51533 \&, it is more efficient to use every processor as a slave and
51534 not use this option.
51535 .TP
51536 \-Q \-q
51537 Quiet option.  The programs will not prompt for input.
51538 .TP
51539 \-R file
51540 (STATFILE) Causes
51541 .B pv34compfa
51542 and
51543 .B pv34compsw
51544 to write out the sequence identifier, superfamily number (if available),
51545 and similarity scores to 
51546 .I STATFILE
51547 for every sequence in the library.  These results are not sorted.
51548 .TP
51549 \-r
51550 specify DNA match/mismatch ratio as "+3/-2".  Default is "+5/-4".
51551 The "+" and "-" are required.
51552 .TP
51553 \-S
51554 Treat lower case residues as low complexity regions.
51555 .TP
51556 \-s file
51557 the filename of an alternative scoring matrix file.
51558 .LP
51559 .B
51560 pv34compfa
51561 only
51562 .TP
51563 \-1
51564 sort similarity scores by
51565 .I init1
51566 scores instead of
51567 .I initn
51568 scores.
51569 .TP
51570 \-c #
51571 (OPTCUT) the threshold for optimization with the
51572 .B -o
51573 option.
51574 .TP
51575 \-o
51576 (no-optimize); causes 
51577 .B pv34compfa
51578 not to perform the default optimization on all of the sequences in the library
51579 with
51580 .B initn
51581 scores greater than
51582 .B OPTCUT\c
51583 \&.
51584 .TP
51585 \-y #
51586 Width for limited optimization (32 by default).
51587 .SH FILES
51588 .LP
51589 Query library files must be in Pearson/FASTA format, e.g.
51590 .in +0.5i
51591 .nf
51592 >seq-id | sfnum descriptive line
51593 tmlyrghi... (sequence)
51594 X
51595 .fi
51596 .in -0.5i
51597 .PP
51598 .B pv34compfa
51599 and
51600 .B pv34compsw
51601 recognize the following library formats: 0 - Pearson/FASTA; 1 - Genbank tape;
51602 2 - NBRF/PIR Codata; 3 - EMBL/SWISS-PROT; 5 - NBRF/PIR VMS.
51603 .PP
51604 .I Scoring matrices \-
51605 These programs use a different format for the scoring (PAM) matrix
51606 file from FASTA; they use the PAM matrix file that is used by BLASTP
51607 and produced by Altshul's "pam.c" program in the BLAST package.
51608 .SH BUGS
51609 The program has been tested extensively only with type 0 and type 5
51610 files.  This documentation file may not be up to date.
51611 .SH AUTHOR
51612 Bill Pearson
51613 .br
51614 wrp@virginia.EDU
51615 SHAR_EOF
51616 chmod 0644 pvcomp.1 ||
51617 echo 'restore of pvcomp.1 failed'
51618 Wc_c="`wc -c < 'pvcomp.1'`"
51619 test 6657 -eq "$Wc_c" ||
51620         echo 'pvcomp.1: original size 6657, current size' "$Wc_c"
51621 fi
51622 # ============= qrhuld.aa ==============
51623 if test -f 'qrhuld.aa' -a X"$1" != X"-c"; then
51624         echo 'x - skipping qrhuld.aa (File already exists)'
51625 else
51626 echo 'x - extracting qrhuld.aa (Text)'
51627 sed 's/^X//' << 'SHAR_EOF' > 'qrhuld.aa' &&
51628 >QRHULD LDL receptor precursor - Human
51629 MGPWGWKLRWTVALLLAAAGTAVGDRCERNEFQCQDGKCISYKWVCDGSAECQDGSDESQETCLSVTCKS
51630 GDFSCGGRVNRCIPQFWRCDGQVDCDNGSDEQGCPPKTCSQDEFRCHDGKCISRQFVCDSDRDCLDGSDE
51631 ASCPVLTCGPASFQCNSSTCIPQLWACDNDPDCEDGSDEWPQRCRGLYVFQGDSSPCSAFEFHCLSGECI
51632 HSSWRCDGGPDCKDKSDEENCAVATCRPDEFQCSDGNCIHGSRQCDREYDCKDMSDEVGCVNVTLCEGPN
51633 KFKCHSGECITLDKVCNMARDCRDWSDEPIKECGTNECLDNNGGCSHVCNDLKIGYECLCPDGFQLVAQR
51634 RCEDIDECQDPDTCSQLCVNLEGGYKCQCEEGFQLDPHTKACKAVGSIAYLFFTNRHEVRKMTLDRSEYT
51635 SLIPNLRNVVA
51636 LDTEVASNRIYWSDLSQRMICSTQLDRAHGVSSYDTVISRDIQAPDGLAVDWIHSNIYWTDSVLGTVSVA
51637 DTKGVKRKTLFRENGSKPRAIVVDPVHGFMYWTDWGTPAKIKKGGLNGVDIYSLVTENIQWPNGITLDLL
51638 SGRLYWVDSKLHSISSIDVNGGNRKTILEDEKRLAHPFSLAVFEDKVFWTDIINEAIFSANRLTGSDVNL
51639 LAENLLSPEDMVLFHNLTQPRGVNWCERTTLSNGGCQYLCLPAPQINPHSPKFTCACPDGMLLARDMRSC
51640 LTEAEAAVATQETSTVRLKVSSTAVRTQHTTTRPVPDTSRLPGATPGLTTVEIVTMSHQALGDVAGRGNE
51641 KKPSSVRALSIVLPIVLLVFLCLGVFLLWKNWRLKNINSINFDNPVYQKTTEDEVHICHNQDGYSYPSRQ
51642 MVSLEDDVA 
51643 SHAR_EOF
51644 chmod 0644 qrhuld.aa ||
51645 echo 'restore of qrhuld.aa failed'
51646 Wc_c="`wc -c < 'qrhuld.aa'`"
51647 test 914 -eq "$Wc_c" ||
51648         echo 'qrhuld.aa: original size 914, current size' "$Wc_c"
51649 fi
51650 # ============= randtest.c ==============
51651 if test -f 'randtest.c' -a X"$1" != X"-c"; then
51652         echo 'x - skipping randtest.c (File already exists)'
51653 else
51654 echo 'x - extracting randtest.c (Text)'
51655 sed 's/^X//' << 'SHAR_EOF' > 'randtest.c' &&
51656 #include <stdio.h>
51657 #include <stdlib.h>
51658 #include <sys/time.h>
51659 X
51660 main(argc, argv)
51661 X     int argc; char **argv;
51662 {
51663 X  int i, n, s;
51664 X  struct timeval t;
51665 X
51666 X  if (argc < 2) n = 10;
51667 X  else n = atoi(argv[1]);
51668 X
51669 X  gettimeofday(&t,NULL);
51670 X  printf(" seed: %d\n",t.tv_usec);
51671 X  srandom(t.tv_usec);
51672 X
51673 X  for (i=0; i< n; i++)
51674 X    printf("%3d\n",random()%100);
51675 X
51676 }
51677 SHAR_EOF
51678 chmod 0644 randtest.c ||
51679 echo 'restore of randtest.c failed'
51680 Wc_c="`wc -c < 'randtest.c'`"
51681 test 339 -eq "$Wc_c" ||
51682         echo 'randtest.c: original size 339, current size' "$Wc_c"
51683 fi
51684 # ============= re_getlib.c ==============
51685 if test -f 're_getlib.c' -a X"$1" != X"-c"; then
51686         echo 'x - skipping re_getlib.c (File already exists)'
51687 else
51688 echo 'x - extracting re_getlib.c (Text)'
51689 sed 's/^X//' << 'SHAR_EOF' > 're_getlib.c' &&
51690 /* re_getlib.c - re-acquire a sequence given lseek, lcont */
51691 X
51692 #include <stdio.h>
51693 #include <stdlib.h>
51694 #include <string.h>
51695 X
51696 #include "defs.h"
51697 #include "mm_file.h"
51698 X
51699 #define GETLIB (m_fptr->getlib)
51700 X
51701 int
51702 re_getlib(unsigned char *aa1,
51703 X         int maxn,     /* longest aa1 */
51704 X         int maxt3,    /* alternate maxn */
51705 X         int loff,     /* overlap */
51706 X         int lcont,
51707 X         int term_code,
51708 X         long *loffset,        /* offset from real start of sequence */
51709 X         long *l_off_p,        /* coordinate of sequence start */
51710 X         struct lmf_str *m_fptr) {
51711 X
51712 X  unsigned char *aa1ptr;
51713 X  int icont, maxt, ccont, n1;
51714 X  char libstr[20];
51715 X  fseek_t lmark; 
51716 X  
51717 X  aa1ptr = aa1;
51718 X  icont=0;
51719 X
51720 X  *loffset = 0l;
51721 X  maxt = maxn;
51722 X  n1 = -1;
51723 X  for (ccont=0; ccont<=lcont-1; ccont++) {
51724 X
51725 X    n1= GETLIB(aa1ptr,maxt,libstr,sizeof(libstr),&lmark,&icont,m_fptr,l_off_p);
51726 X
51727 X    if (term_code && m_fptr->lib_aa && aa1ptr[n1-1]!=term_code) {
51728 X      aa1ptr[n1++]=term_code;
51729 X      aa1ptr[n1]=0;
51730 X    }
51731 X
51732 X    if (aa1ptr!=aa1) n1 += loff;
51733 X
51734 X    if (icont>lcont-1) break;
51735 X
51736 X    if (icont) {
51737 X      maxt = maxt3;
51738 X      memcpy(aa1,&aa1[n1-loff],loff);
51739 X      aa1ptr= &aa1[loff];
51740 X      *loffset += n1 - loff;
51741 X    }
51742 X    else {
51743 X      maxt = maxn;
51744 X      aa1ptr=aa1;
51745 X    }
51746 X  }
51747 X  return n1;
51748 }
51749 SHAR_EOF
51750 chmod 0644 re_getlib.c ||
51751 echo 'restore of re_getlib.c failed'
51752 Wc_c="`wc -c < 're_getlib.c'`"
51753 test 1184 -eq "$Wc_c" ||
51754         echo 're_getlib.c: original size 1184, current size' "$Wc_c"
51755 fi
51756 # ============= readme.mpi_3.3 ==============
51757 if test -f 'readme.mpi_3.3' -a X"$1" != X"-c"; then
51758         echo 'x - skipping readme.mpi_3.3 (File already exists)'
51759 else
51760 echo 'x - extracting readme.mpi_3.3 (Text)'
51761 sed 's/^X//' << 'SHAR_EOF' > 'readme.mpi_3.3' &&
51762 X
51763 X $Name: fa_34_26_5 $ - $Id: readme.mpi_3.3,v 1.4 2001/08/20 21:18:47 wrp Exp $
51764 X
51765 20-August-2001
51766 X
51767 This file is obsolete - see readme.v34t0, readme.v33t0, and
51768 readme.pvm_3.4 for more up-to-date information.  With version 3.4, the
51769 MPI programs are mp34comp*, mu34comp*, etc.
51770 X
51771 ================
51772 X
51773 20 January 2000
51774 X
51775 This distribution includes the first full-function MPI implementation of
51776 the libary-vs-library comparison programs.  The following programs are
51777 available:
51778 X
51779 Programs to produce conventional scores and alignments:
51780 X
51781 mp3compfa       protein vs protein, DNA vs DNA
51782 mp3compsw       protein vs protein, DNA vs DNA
51783 mp3compfx/      DNA vs protein
51784 mp3comptfx/y    protein vs DNA
51785 X
51786 Programs to summarize the effectiveness of a search (require
51787 super-family-labeled databases):
51788 X
51789 ms3compfa       protein vs protein, DNA vs DNA
51790 ms3compsw       protein vs protein, DNA vs DNA
51791 ms3compfx/      DNA vs protein
51792 ms3comptfx/y    protein vs DNA
51793 X
51794 Programs to report the scores and alignments of the highest scoring
51795 unrelated sequence (require super-family-labeled databases). These
51796 programs are used to evaluate the super-family labeling.
51797 X
51798 mu3compfa       protein vs protein, DNA vs DNA
51799 mu3compsw       protein vs protein, DNA vs DNA
51800 mucompfx/       DNA vs protein
51801 mu3comptfx/y    protein vs DNA
51802 X
51803 Note that the current parallel implementations distribute the second
51804 database among 'N' parallel workers by approximately dividing the
51805 database into 'N' parts by seeking into the middle of the database and
51806 finding the next entry.  This strategy fails when the database is a
51807 single long sequence (the first worker gets the entire database, the
51808 others get nothing).
51809 X
51810 This version has been tested using the MPICH implementation of MPI,
51811 which is available from:
51812 X
51813 X       ftp://ftp.mcs.anl.gov/mpi
51814 X
51815 See readme.pvm_3.3 for other information about the development of
51816 these programs.  Both the PVM (pv3compfa, etc.) and MPI (mp3compfa,
51817 etc.) sets of programs use the same sets of source files; differences
51818 in the two implementations are specified with #define PVM_SRC and
51819 #define MPI_SRC.
51820 X
51821 SHAR_EOF
51822 chmod 0644 readme.mpi_3.3 ||
51823 echo 'restore of readme.mpi_3.3 failed'
51824 Wc_c="`wc -c < 'readme.mpi_3.3'`"
51825 test 1994 -eq "$Wc_c" ||
51826         echo 'readme.mpi_3.3: original size 1994, current size' "$Wc_c"
51827 fi
51828 # ============= readme.pvm_3.2 ==============
51829 if test -f 'readme.pvm_3.2' -a X"$1" != X"-c"; then
51830         echo 'x - skipping readme.pvm_3.2 (File already exists)'
51831 else
51832 echo 'x - extracting readme.pvm_3.2 (Text)'
51833 sed 's/^X//' << 'SHAR_EOF' > 'readme.pvm_3.2' &&
51834 --> August, 1999
51835 X
51836 Corrected problem with opt_cut initialization that only appeared
51837 with p?compfa programs.
51838 X
51839 --> v3.26       July, 1999
51840 X
51841 pvcomp* programs now use the same method for working with forward and
51842 reverse strands as the standard fast*3(_t) programs.  Thus, statistics
51843 for DNA sequences should be very similar for pvcompfa and fasta3 or
51844 fasta3_t.
51845 X
51846 X               February, 1999
51847 X
51848 With release fasta32t02 of the FASTA package, the alignment
51849 routines for pvcompfa, pvcompsw, etc now work properly
51850 again.
51851 X
51852 The PVM versions of the FASTA and Smith-Waterman search programs
51853 should now be functionally identical to the multithreaded (fasta3_t,
51854 ssearch3_t) and non-threaded (fasta3, ssearch3) versions.
51855 X
51856 The programs have also been updated to provide similar -m 10
51857 information to the non-pvm versions.  There are some slight
51858 differences, because the pvcomp* versions are designed to work with
51859 multiple sequences.  But, in general, a script that looks for /^>>>/
51860 to start an alignment set and /^>>><<</ to end the set work work
51861 properly.
51862 X
51863 --> v3.23       March, 1999 
51864 X
51865 Modified Makefile.pvm, showsum.c so that showsum.c is used by
51866 both the complib/_thr and pvcomplib (pvm parallel) versions.
51867 X
51868 Corrected bug in reading first query for DNA sequences.
51869 X
51870 --> v3.25       May, 1999
51871 X
51872 Fixed pvm_showalign.c so that FIRSTNODE (in msg.h) can be 1, rather
51873 than 0.  #define FIRSTNODE 1 is recommended when the virtual machine
51874 has 8 or more nodes.
51875 X
51876 SHAR_EOF
51877 chmod 0644 readme.pvm_3.2 ||
51878 echo 'restore of readme.pvm_3.2 failed'
51879 Wc_c="`wc -c < 'readme.pvm_3.2'`"
51880 test 1404 -eq "$Wc_c" ||
51881         echo 'readme.pvm_3.2: original size 1404, current size' "$Wc_c"
51882 fi
51883 # ============= readme.pvm_3.3 ==============
51884 if test -f 'readme.pvm_3.3' -a X"$1" != X"-c"; then
51885         echo 'x - skipping readme.pvm_3.3 (File already exists)'
51886 else
51887 echo 'x - extracting readme.pvm_3.3 (Text)'
51888 sed 's/^X//' << 'SHAR_EOF' > 'readme.pvm_3.3' &&
51889 X
51890 X $Name: fa_34_26_5 $ - $Id: readme.pvm_3.3,v 1.13 2000/08/04 18:45:15 wrp Exp $
51891 X
51892 ================
51893 pvcomp* - FAQ's, November, 1999
51894 X
51895 (The comments below apply to the pv3comp* programs.  This problem has
51896 been addressed in the pv4comp* programs, by dramatically changing
51897 the way databases are distributed.)
51898 X
51899 I believe that the number one reason why the pvcomp* programs do not
51900 work properly is that the second library must be fully specified.
51901 If you simply type:
51902 X
51903 X       pv3compfa query.lib database.lib
51904 X
51905 The program will not be able to find database.lib on the worker machines.
51906 You need to use:
51907 X
51908 X       pv3compfa query.lib /home/user/lib/database.lib
51909 X
51910 and /home/user/lib/database.lib must be accessible to all of the worker
51911 nodes.
51912 X
51913 To find error messages from the workers, look at /tmp/pvml.uid, where
51914 uid is your unix uid.
51915 X
51916 ================
51917 Program summary:
51918 X
51919 Programs to produce conventional scores and alignments:
51920 X
51921 pv3compfa       protein vs protein, DNA vs DNA
51922 pv3compsw       protein vs protein, DNA vs DNA
51923 pv3compfx/      DNA vs protein
51924 pv3comptfx/y    protein vs DNA
51925 X
51926 Programs to summarize the effectiveness of a search (require
51927 super-family-labeled databases):
51928 X
51929 ps3compfa       protein vs protein, DNA vs DNA
51930 ps3compsw       protein vs protein, DNA vs DNA
51931 ps3compfx/      DNA vs protein
51932 ps3comptfx/y    protein vs DNA
51933 X
51934 Programs to report the scores and alignments of the highest scoring
51935 unrelated sequence (require super-family-labeled databases). These
51936 programs are used to evaluate the super-family labeling.
51937 X
51938 pu3compfa       protein vs protein, DNA vs DNA
51939 pu3compsw       protein vs protein, DNA vs DNA
51940 pucompfx/       DNA vs protein
51941 pu3comptfx/y    protein vs DNA
51942 X
51943 Note that the current parallel implementations distribute the second
51944 database among 'N' parallel workers by approximately dividing the
51945 database into 'N' parts by seeking into the middle of the database and
51946 finding the next entry.  This strategy fails when the database is a
51947 single long sequence (the first worker gets the entire database, the
51948 others get nothing).
51949 X
51950 ================
51951 Release notes:
51952 X
51953 --> July 18, 2000
51954 X
51955 Increase SQSZ in pxgetaa.c to 200000 for long Genbank entries.  This
51956 may still not be long enough.  This increase may allow overlaps to
51957 occur.
51958 X
51959 --> July 10, 2000
51960 X
51961 Corrections to the code for breaking up very long sequences.  The last
51962 portion of a long sequence did not have the correct offset.
51963 X
51964 --> July 1, 2000
51965 X
51966 Modified pxgetaa.c to read Genbank flatfiles.
51967 X
51968 Additional pieces of a long sequence no longer have a '+' at the
51969 beginning.
51970 X
51971 --> June 12, 2000
51972 X
51973 Restructured p_complib.c, p_workcomp.c to make the -m 9 display more
51974 consistent with the fast33(_t) set of programs.  The alignment (%_id,
51975 swscore, boundary) information is now calculated at the do_opt() stage
51976 of the calculation.  This rearrangement uncovered a problem with the
51977 do_opt() stage (s_func=1) that has been fixed.  This has not yet been
51978 tested with the MPI implementation.
51979 X
51980 Many changes were made to allow k_H, k_comp information to be passed
51981 back so that the -z 6 scaleswn.c (proc_hist_mle2) function could be
51982 used.
51983 X
51984 --> February 6, 2000
51985 X
51986 Corrected some problems with proc_hist_ml() to correctly reinitialize
51987 hist_db_size and num_db_entries.
51988 X
51989 --> January 20, 2000
51990 X
51991 X   The structure of the p[vsu]comp* programs has not changed, but the
51992 the code has been modified to accomodate both PVM and MPI versions of
51993 the programs from the same source code.  Thus, all of the PVM-specific
51994 code is now surrounded by #ifdef PVM_SRC/#endif.  The source files
51995 pvcomplib.c and pvworkcomp.c have been replaced by p_complib.c and
51996 p_workcomp.c, respectively.  Additional changes were made to ensure
51997 that "FIRSTNODE" is used appropriately.  In general, FIRSTNODE=0 for
51998 PVM programs (although with > 8 nodes, FIRSTNODE=1 may be more
51999 effective), but FIRSTNODE=1 for MPI programs.
52000 X
52001 X  Modest changes were made to reduce warning messages during
52002 compilation.
52003 X
52004 --> January, 2000
52005 X
52006 X   Modification to hxgetaa.c, pxgetaa.c to handle library sequences,
52007 such as those from NCBI/NR, with very long comment lines.  Additional
52008 modifications to correct problems with long comments, long DNA
52009 sequences with pv3comptfx/tfy.
52010 X
52011 --> v3.33       December, 1999
52012 X
52013 Substantial updates to pvcomplib.c/pvworkcomp.c to improve efficiency
52014 and to provide pv3compf[xy] and pv3comptf[xy].  Previous versions of
52015 pvcomplib.c/pvworkcomp.c passed the entire struct mngmsg (structs.h)
52016 each time a new query was initiated or alignments were required.  This
52017 version sends struct mngmsg only once and sends struct qmng_str
52018 (w_msg.h), which is much smaller, for the queries and alignments. In
52019 addition, the buffer size for results is now variable (but can be as
52020 large as 1200, vs 600 previously), which may improve performance when
52021 large numbers of workers are available.  The maximum number of library
52022 sequences per worker has been raised to 200,000 from 50,000.
52023 Nevertheless, very large databases (est_human) may have too many
52024 entries to be examined by 4 workers.
52025 X
52026 It is likely that pv3comptf[xy] may have problems with very long
52027 sequences.  pv3compf[xy]/tf[xy] have not been tested extensively.
52028 X
52029 --> v3.32 December, 1999
52030 X
52031 Substantial corrections to showsum.c (showbest()) for the case of DNA
52032 queries, where two scores are calculated for each query.  As a result
52033 of the changes, bptr[] no longer mapped exactly to best[], which
52034 caused a bug that was very difficult to track down.  To ensure that
52035 bptr[]=best[], bptr[] is now re-initialized for each query.
52036 X
52037 The output format has changed significantly as well.  Lots of
52038 redundant /** **/ comments have been removed.  An E() value has been
52039 added to the "equ num:" line in showsum.c.
52040 X
52041 The organization of the inner while() loop in pvcomplib.c has been
52042 modified so that new query sequences can be sent to workers
52043 immediately as soon as a worker is available, rather than waiting for
52044 all to finish and the statistical analysis.
52045 X
52046 --> v3.30       October, 1999
52047 X
52048 The p*comp*/c.work* programs have been renamed to pv3compfa,
52049 ps3compfa, etc.  and c3.work* so that the older version 3.2 programs
52050 can co-exist with this version.
52051 X
52052 Corrected problem with "-n" option that prevented it from functioning
52053 properly.  Include "ACGTCN" in check for DNA query library.a
52054 X
52055 (from readme.pvm_3.2)
52056 X
52057 --> August, 1999
52058 X
52059 Corrected problem with opt_cut initialization that only appeared
52060 with p?compfa programs.
52061 X
52062 --> v3.26       July, 1999
52063 X
52064 pvcomp* programs now use the same method for working with forward and
52065 reverse strands as the standard fast*3(_t) programs.  Thus, statistics
52066 for DNA sequences should be very similar for pvcompfa and fasta3 or
52067 fasta3_t.
52068 X
52069 X               February, 1999
52070 X
52071 With release fasta32t02 of the FASTA package, the alignment
52072 routines for pvcompfa, pvcompsw, etc now work properly
52073 again.
52074 X
52075 The PVM versions of the FASTA and Smith-Waterman search programs
52076 should now be functionally identical to the multithreaded (fasta3_t,
52077 ssearch3_t) and non-threaded (fasta3, ssearch3) versions.
52078 X
52079 The programs have also been updated to provide similar -m 10
52080 information to the non-pvm versions.  There are some slight
52081 differences, because the pvcomp* versions are designed to work with
52082 multiple sequences.  But, in general, a script that looks for /^>>>/
52083 to start an alignment set and /^>>><<</ to end the set work
52084 properly.
52085 X
52086 --> v3.23       March, 1999 
52087 X
52088 Modified Makefile.pvm, showsum.c so that showsum.c is used by
52089 both the complib/_thr and pvcomplib (pvm parallel) versions.
52090 X
52091 Corrected bug in reading first query for DNA sequences.
52092 X
52093 --> v3.25       May, 1999
52094 X
52095 Fixed pvm_showalign.c so that FIRSTNODE (in msg.h) can be 1, rather
52096 than 0.  #define FIRSTNODE 1 is recommended when the virtual machine
52097 has 8 or more nodes.
52098 X
52099 SHAR_EOF
52100 chmod 0644 readme.pvm_3.3 ||
52101 echo 'restore of readme.pvm_3.3 failed'
52102 Wc_c="`wc -c < 'readme.pvm_3.3'`"
52103 test 7535 -eq "$Wc_c" ||
52104         echo 'readme.pvm_3.3: original size 7535, current size' "$Wc_c"
52105 fi
52106 # ============= readme.pvm_3.4 ==============
52107 if test -f 'readme.pvm_3.4' -a X"$1" != X"-c"; then
52108         echo 'x - skipping readme.pvm_3.4 (File already exists)'
52109 else
52110 echo 'x - extracting readme.pvm_3.4 (Text)'
52111 sed 's/^X//' << 'SHAR_EOF' > 'readme.pvm_3.4' &&
52112 X
52113 X $Name: fa_34_26_5 $ - $Id: readme.pvm_3.4,v 1.3 2001/09/17 21:18:19 wrp Exp $
52114 X
52115 X
52116 20-August-2001
52117 X
52118 The pvm/mpi complib programs have been substantially updated with
52119 release 3.4.  See readme.v34t0 for more information.  With version
52120 3.4, the MPI programs are mp34comp*, mu34comp*, etc.
52121 X
52122 A major effect of this change is to disable automatic sequence type
52123 (protein/DNA) recognition with pv34compfa/mp34compfa.  By default,
52124 protein libraries are assumed.  Thus, pv34compfa/mp34compfa require
52125 the "-n" command line option when running pv34compfa/mp34compfa on DNA
52126 sequence libraries.  This issue does not occur with the other
52127 programs, which will recognize the appropriate sequence type, because
52128 it is determined by the program (e.g. pv34compfx requires
52129 DNA:protein).
52130 X
52131 ================
52132 pv4comp* - July, August, 2000
52133 X
52134 As noted in readme.pvm_3.3 - the major problem that users have had
52135 with the PVM/MPI version of the programs is in reading database files
52136 on the nodes.  All previous versions of the program (pvcompfa,
52137 pv3compfa, etc) had the nodes read the databases in parallel. Thus,
52138 the database file had to be visible to the nodes, typically through
52139 NFS on modern clusters of workstations.
52140 X
52141 This strategy caused some problems. It did not work on beowulf-type
52142 systems, where most of the nodes are in an isolated local network and
52143 do not have NFS access to the outside world.  And it made it
52144 complicated to read more than one database file.  Because specialized
52145 functions were used, the nodes could not read the full set of library
52146 file formats available to the other fasta programs.
52147 X
52148 These problems have been addressed by significantly changing the the
52149 way the pv4comp*/mp4comp* programs read the second "reference"
52150 library.  With these versions, both databases, but specifically the
52151 reference library, are read by a manager process.  The manager process
52152 then sends the sequences to the workers.  This solves problems with
52153 NFS reads from the workers (they don't do any), and uses exactly the
52154 same functions as the other fasta programs, so the full set of
52155 database formats can be read. In addition, the FASTLIBS database
52156 abbreviations are available. This also should also solve problems with
52157 searches of very long sequences (bacterial genomes); they can now be
52158 broken up into smaller pieces with the -N ##### option, as with
52159 fasta33/tfastx33.
52160 X
52161 Thus, you are encouraged to use the pv4comp*/mp4comp* versions of the
52162 programs, which should run more like fasta33.
52163 X
52164 ================
52165 Program summary:
52166 X
52167 Programs to produce conventional scores and alignments:
52168 X
52169 pv4compfa       protein vs protein, DNA vs DNA
52170 pv4compsw       protein vs protein, DNA vs DNA
52171 pv4compfx/      DNA vs protein
52172 pv4comptfx/y    protein vs DNA
52173 X
52174 Programs to summarize the effectiveness of a search (require
52175 super-family-labeled databases):
52176 X
52177 ps4compfa       protein vs protein, DNA vs DNA
52178 ps4compsw       protein vs protein, DNA vs DNA
52179 ps4compfx/      DNA vs protein
52180 ps4comptfx/y    protein vs DNA
52181 X
52182 Programs to report the scores and alignments of the highest scoring
52183 unrelated sequence (require super-family-labeled databases). These
52184 programs are used to evaluate the super-family labeling.
52185 X
52186 pu4compfa       protein vs protein, DNA vs DNA
52187 pu4compsw       protein vs protein, DNA vs DNA
52188 pucompfx/       DNA vs protein
52189 pu4comptfx/y    protein vs DNA
52190 X
52191 ================
52192 Release notes:
52193 X
52194 --> Aug. 4, 2000
52195 X
52196 Compiled and tested mp4compfa/mp4compsw programs.
52197 X
52198 --> July 22, 2000
52199 X
52200 First release of restructured p2_complib.c/p2_workcomp.c, which use
52201 the manager program to read both sequence databases and send the
52202 "reference database" to the workers.
52203 X
52204 SHAR_EOF
52205 chmod 0644 readme.pvm_3.4 ||
52206 echo 'restore of readme.pvm_3.4 failed'
52207 Wc_c="`wc -c < 'readme.pvm_3.4'`"
52208 test 3539 -eq "$Wc_c" ||
52209         echo 'readme.pvm_3.4: original size 3539, current size' "$Wc_c"
52210 fi
52211 # ============= readme.v30 ==============
52212 if test -f 'readme.v30' -a X"$1" != X"-c"; then
52213         echo 'x - skipping readme.v30 (File already exists)'
52214 else
52215 echo 'x - extracting readme.v30 (Text)'
52216 sed 's/^X//' << 'SHAR_EOF' > 'readme.v30' &&
52217 X
52218 Because of interdependencies in the Makefile, sometimes you must
52219 type "make" a second time to get everything built.
52220 X
52221 June 12, 1996 - fasta30t1
52222 X
52223 X       Fixed bug in reading blast-format DNA sequence files.
52224 X       Fixed core-dump for some large libraries on some machines.
52225 X
52226 June 19, 1996 - fasta30t2
52227 X
52228 X       Fixed a serious bug in the Smith-Waterman alignment routines used
52229 X       by both fasta3 (dropnfa.c) and ssearch3 (dropgsw.c) that caused
52230 X       the amount of memory required to depend on the library sequence
52231 X       size, rather than the query sequence size.
52232 X
52233 X       Fixed some memory-overwrite errors in showalign.c
52234 X
52235 June 27, 1996 - fasta30t3
52236 X
52237 X       Found and fixed bugs in comp_thr.c and nxgetaa.c that caused core
52238 X       dumps when reading DNA libraries with long sequences in fasta
52239 X       format.
52240 X
52241 July 6, 1996  - fasta30t4
52242 X
52243 X       ibm_pthread_subs.c available, Makefile.ibm for multiprocessor
52244 X       IBM RS/6000 AIX systems.
52245 X
52246 X       Finally (?) fixed the previous bug that caused core dumps when
52247 X       reading DNA libraries in fasta format.
52248 X
52249 X       Corrections to the fastx algorithm.
52250 X
52251 July 10, 1996
52252 X
52253 X       Fixed reading of compressed GCG DNA format.
52254 X
52255 SHAR_EOF
52256 chmod 0644 readme.v30 ||
52257 echo 'restore of readme.v30 failed'
52258 Wc_c="`wc -c < 'readme.v30'`"
52259 test 1070 -eq "$Wc_c" ||
52260         echo 'readme.v30: original size 1070, current size' "$Wc_c"
52261 fi
52262 # ============= readme.v30t6 ==============
52263 if test -f 'readme.v30t6' -a X"$1" != X"-c"; then
52264         echo 'x - skipping readme.v30t6 (File already exists)'
52265 else
52266 echo 'x - extracting readme.v30t6 (Text)'
52267 sed 's/^X//' << 'SHAR_EOF' > 'readme.v30t6' &&
52268 X
52269 >>August 24, 1996
52270 X
52271 New programs - tfastx3, tfastx3_t, compare a protein sequence to
52272 forward and reverse translations of a DNA sequence database.  An excellent
52273 replacement for tfasta3.
52274 X
52275 Sun multiprocessing - change in thr_create() to use all CPU's if available.
52276 X
52277 GCG formats - now can search with simple GCG-format query sequences and
52278 results with GCG format Swissprot and Genpept are more readable.
52279 X
52280 >>August 26, 1996
52281 X
52282 Fixed bugs in tfastx3(_t) and fastx3(_t) including an ancient problem
52283 with aatran().  Less redundancy in gcg_ranlib().
52284 X
52285 X
52286 >>August 31, 1996
52287 X
52288 Included support for BLOSUM62 (-s BL62) as per documentation.
52289 X
52290 Rearranged Makefile's so that they would make everything in one pass.
52291 X
52292 >>September 6, 1996
52293 X
52294 Corrected yet another problem with the fastx/tfastx code.
52295 X
52296 Noticed that searching without optimized scores gave no optimized
52297 scores on the final list of scores - fixed this.
52298 X
52299 The pvm version now does alignments - not thoroughly tested.
52300 X
52301 >>September 13, 1996
52302 X
52303 Fixed display of best scores to stdout.
52304 X
52305 Fixed problem with alignments when -o flag used.
52306 X
52307 pvcompfa/pvcompsw have now been tested on DEC Alpha, Solaris X86, and
52308 SGI PVM implementations.  Several bugs were corrected.
52309 X
52310 >>September 18, 1996
52311 X
52312 Fixed bug selectbestz() that caused core dumps in pvcomplib.c
52313 (changes to pvcomplib.c, comp_thr.c, complib.c).
52314 X
52315 >>September 23, 1996
52316 X
52317 Corrected showalign.c/pvm_showalign.c addressing bug found and fixed
52318 by Erik Wallin. (erikw@biokemi.su.se).
52319 X
52320 >>October 15, 1996
52321 X
52322 Corrected bug so alternative scoring matrices are used.
52323 X
52324 >>October 22, 1996
52325 X
52326 Remove singularities from regression routine.
52327 X
52328 -z 0 now means no statistics (same as -z -1).
52329 X
52330 No longer show alignment for 0 score.
52331 X
52332 >>October 26, 1996
52333 X
52334 Fix problem with -b, -d when Z-values disabled.
52335 X
52336 >>November 1, 1996
52337 X
52338 Altschul-Gish statistical estimates (-z 3) now work properly.
52339 X
52340 Fix problem with mean_var==0.0.
52341 X
52342 SHAR_EOF
52343 chmod 0644 readme.v30t6 ||
52344 echo 'restore of readme.v30t6 failed'
52345 Wc_c="`wc -c < 'readme.v30t6'`"
52346 test 1871 -eq "$Wc_c" ||
52347         echo 'readme.v30t6: original size 1871, current size' "$Wc_c"
52348 fi
52349 # ============= readme.v30t7 ==============
52350 if test -f 'readme.v30t7' -a X"$1" != X"-c"; then
52351         echo 'x - skipping readme.v30t7 (File already exists)'
52352 else
52353 echo 'x - extracting readme.v30t7 (Text)'
52354 sed 's/^X//' << 'SHAR_EOF' > 'readme.v30t7' &&
52355 >> October 30, 1996
52356 X
52357 A new program, sc_to_e, can be used to calculate expectation values
52358 from the regression coefficients reported from a search.  The
52359 expectation value is based on similarity score, sequence length, and
52360 database size.
52361 X
52362 >> November 8, 1996
52363 X
52364 fasta30t7 differs from fasta30t6 in the amount of information provided
52365 with the -m 10 option.
52366 X
52367 (1) The query and library sequence identifiers are no longer abbreviated.
52368 X
52369 (2) New information about the program and program version are provided:
52370 X
52371 The new information provided is:
52372 X
52373 X       mp_name: program name (actually argv[0])
52374 X       mp_ver: main program version (can be different from function version)
52375 X       mp_argv: command line arguments (duplicates argv[0])
52376 X
52377 X    Some statistical information is provided as well:
52378 X       mp_extrap: XXXX YYY - statistics extrapolated from XXX to YYY
52379 X       mp_stats: indicates type of statistics used for E() value
52380 X       mp_KS: Kolmogorov-Smirnoff statistic
52381 X
52382 The "mp_" (main program) information is function independent, while the "pg_"
52383 information is produced by a particular comparison function (ssearch,
52384 fastx, fasta, etc).  "pg_" should probably be called "fn_", and "mp_"
52385 called "pg_", but I remain backwards compatible.
52386 X
52387 (3) The end of the "parseable" records is denoted with:
52388 X
52389 X       >>><<<
52390 X
52391 (4) There now an compile-time option -DM10_CONS, that allows you to
52392 display a final alignment summary:
52393 X
52394 ;al_cons:
52395 X     .::.:-   .:: ..  :.    .:.---:   :  .--.:. : 
52396 ..  .---  ..: :: ... :..: .::.:. .  .---.  .   .: 
52397 X : .  . . :    ..   .    :..: .--. . : .:. .. :  .
52398 X .:.:::  ..:. :
52399 X
52400 or, if M10_CONS_L is defined (in addition to M10_CONS), the output is:
52401 ;al_cons:
52402 X     p==p=-mmmp==mpzmm=pmmmmz=p---=mmm=mmp--p=zm=m
52403 pzmmp---mmzp=m==mzzzm=zp=mz==z=pmzmmz---pmmpmmmp=m
52404 m=mzmmzmpm=mmmmppmmmpmmmm=pp=mp--pmpm=mp=pmzzm=mmp
52405 mp=z===mmpz=zm=
52406 X
52407 where '=' indicates identical residues, '-' a gap in one or the other
52408 sequence, 'p' indicates a positive pam value, 'm' indicates a negative
52409 pam value, and 'z' indicates a zero pam value.
52410 X
52411 A typical run now looks like:
52412 X
52413 >>>gtm1_mouse.aa, 217 aa vs s library
52414 ; mp_name: fasta3_t
52415 ; mp_ver: version 3.0t7 November, 1996
52416 ; mp_argv: fasta3_t -q -m 10 gtm1_mouse.aa s
52417 ; pg_name: FASTA
52418 ; pg_ver: 3.06 Sept, 1996
52419 ; pg_matrix: BL50
52420 ; pg_gap-pen: -12 -2
52421 ; pg_ktup: 2
52422 ; pg_optcut: 24
52423 ; pg_cgap: 36
52424 ; mp_extrap: 50000 51933
52425 ; mp_stats: Expectation fit: rho(ln(x))= 5.8855+/-0.000527; mu= 1.5386+/- 0.029;  mean_var=73.0398+/-15.283
52426 ; mp_KS: 0.0133 (N=29) at  42
52427 >>GTM1_MOUSE GLUTATHIONE S-TRANSFERASE GT8.7 (EC 2.5.1.18) (GST 1-1) (CLASS-MU).
52428 ; fa_initn: 1490
52429 ; fa_init1: 1490
52430 ; fa_opt: 1490
52431 ; fa_z-score: 1754.6
52432 ; fa_expect:      0
52433 ; sw_score: 1490
52434 ; sw_ident: 1.000
52435 ; sw_overlap: 217
52436 >GTM1_MOUSE ..
52437 ; sq_len: 217
52438 ; sq_type: p
52439 ; al_start: 1
52440 ; al_stop: 217
52441 ; al_display_start: 1
52442 PMILGYWNVRGLTHPIRMLLEYTDSSYDEKRYTMGDAPDFDRSQWLNEKF
52443 KLGLDFPNLPYLIDGSHKITQSNAILRYLARKHHLDGETEEERIRADIVE
52444 NQVMDTRMQLIMLCYNPDFEKQKPEFLKTIPEKMKLYSEFLGKRPWFAGD
52445 KVTYVDFLAYDILDQYRMFEPKCLDAFPNLRDFLARFEGLKKISAYMKSS
52446 RYIATPIFSKMAHWSNK
52447 >GTM1_MOUSE ..
52448 ; sq_len: 217
52449 ; sq_type: p
52450 ; al_start: 1
52451 ; al_stop: 217
52452 ; al_display_start: 1
52453 PMILGYWNVRGLTHPIRMLLEYTDSSYDEKRYTMGDAPDFDRSQWLNEKF
52454 KLGLDFPNLPYLIDGSHKITQSNAILRYLARKHHLDGETEEERIRADIVE
52455 NQVMDTRMQLIMLCYNPDFEKQKPEFLKTIPEKMKLYSEFLGKRPWFAGD
52456 KVTYVDFLAYDILDQYRMFEPKCLDAFPNLRDFLARFEGLKKISAYMKSS
52457 RYIATPIFSKMAHWSNK
52458 >>GTM1_RAT GLUTATHIONE S-TRANSFERASE YB1 (EC 2.5.1.18) (CHAIN 3) (CLASS-MU).
52459 ; fa_initn: 1406
52460 ; fa_init1: 1406
52461 ; fa_opt: 1406
52462 ; fa_z-score: 1656.3
52463 ; fa_expect:      0
52464 ; sw_score: 1406
52465 ; sw_ident: 0.931
52466 ; sw_overlap: 217
52467 >GTM1_MOUSE ..
52468 ; sq_len: 217
52469 ; sq_type: p
52470 ; al_start: 1
52471 ; al_stop: 217
52472 ; al_display_start: 1
52473 PMILGYWNVRGLTHPIRMLLEYTDSSYDEKRYTMGDAPDFDRSQWLNEKF
52474 KLGLDFPNLPYLIDGSHKITQSNAILRYLARKHHLDGETEEERIRADIVE
52475 NQVMDTRMQLIMLCYNPDFEKQKPEFLKTIPEKMKLYSEFLGKRPWFAGD
52476 KVTYVDFLAYDILDQYRMFEPKCLDAFPNLRDFLARFEGLKKISAYMKSS
52477 RYIATPIFSKMAHWSNK
52478 >GTM1_RAT ..
52479 ; sq_len: 217
52480 ; sq_type: p
52481 ; al_start: 1
52482 ; al_stop: 217
52483 ; al_display_start: 1
52484 PMILGYWNVRGLTHPIRLLLEYTDSSYEEKRYAMGDAPDYDRSQWLNEKF
52485 KLGLDFPNLPYLIDGSRKITQSNAIMRYLARKHHLCGETEEERIRADIVE
52486 NQVMDNRMQLIMLCYNPDFEKQKPEFLKTIPEKMKLYSEFLGKRPWFAGD
52487 KVTYVDFLAYDILDQYHIFEPKCLDAFPNLKDFLARFEGLKKISAYMKSS
52488 RYLSTPIFSKLAQWSNK
52489 ;al_cons:
52490 :::::::::::::::::.:::::::::.::::.::::::.::::::::::
52491 ::::::::::::::::.::::::::.::::::::: ::::::::::::::
52492 :::::.::::::::::::::::::::::::::::::::::::::::::::
52493 ::::::::::::::::..::::::::::::.:::::::::::::::::::
52494 ::..::::::.:.::::
52495 >>><<<
52496 X
52497 X
52498 217 residues in 1 query   sequences
52499 18531385 residues in 52205 library sequences
52500 X Tcomplib (4 proc)[version 3.0t7 November, 1996]
52501 X start: Fri Nov  8 18:20:26 1996 done: Fri Nov  8 18:20:41 1996
52502 X Scan time: 38.434 Display time:  2.166
52503 X
52504 Function used was  FASTA 
52505 X
52506 ================================================================
52507 X
52508 >> November 11, 1996
52509 X
52510 X --> v30t71
52511 X
52512 Made changes to complib.c, comp_thr.c, nxgetaa.c to allow scoring
52513 matrix to be modified in fastx3, fastx3_t.
52514 X
52515 ================================================================
52516 X
52517 >> November 15, 1996
52518 X
52519 X --> v30t72
52520 X
52521 nxgetaa.c now accepts query sequences from "stdin" by using "-" as the
52522 input file name.  If DNA sequences are read in this mode, the "-n"
52523 option must be used.
52524 X
52525 > November 23, 1996
52526 X
52527 Included code in nxgetaa.c and Makefile.sgi to get around a bug in SGI's
52528 sscanf() that prevented compressed GCG databases from being read properly.
52529 X
52530 SHAR_EOF
52531 chmod 0644 readme.v30t7 ||
52532 echo 'restore of readme.v30t7 failed'
52533 Wc_c="`wc -c < 'readme.v30t7'`"
52534 test 5283 -eq "$Wc_c" ||
52535         echo 'readme.v30t7: original size 5283, current size' "$Wc_c"
52536 fi
52537 # ============= readme.v31t0 ==============
52538 if test -f 'readme.v31t0' -a X"$1" != X"-c"; then
52539         echo 'x - skipping readme.v31t0 (File already exists)'
52540 else
52541 echo 'x - extracting readme.v31t0 (Text)'
52542 sed 's/^X//' << 'SHAR_EOF' > 'readme.v31t0' &&
52543 X
52544 >>November 1, 1997
52545 X
52546 X --> v31t0
52547 X
52548 version 31t of the fasta program package uses a more modular
52549 structure for comparison functions.  In addition to modular functions
52550 to initialize, calculate and align sequences, v31 provides a modular
52551 function for creating the alignment display.  This was required for
52552 fasty and fastf, which have very different alignment strategies from
52553 the other search programs.
52554 X
52555 >>February 13, 1998
52556 X
52557 modified nascii[] so that 0, 1, 2 are no longer end of sequence
52558 characters.
52559 X
52560 prss3 added.  Unlike prss, prss3 uses -d # to specify the number of
52561 shuffles.
52562 X
52563 >>March 18, 1998
52564 X
52565 First public release.  Corrected problems with dropfz.c (which is
52566 used in fasty3, tfasty3).  Makefile is well tested, but other Makefile's
52567 are not.  PVM versions not tested.
52568 X
52569 >>March 19, 1998
52570 X
52571 Problem with unthreaded tfastx3, tfasty3 caused by bug in complib.c
52572 fixed. All Makefiles (Makefile.alpha Makefile.sun, Makefile.sgi,
52573 Makefile.linux) have been tested and work properly. Threaded versions
52574 do not work on linux (yet).  Function labeling problems with fasty3,
52575 tfasty3 corrected.
52576 X
52577 >>March 20, 1998
52578 X
52579 X --> v31t02
52580 X
52581 Fixed problem with inconsistent openlib() calls that broke BLAST databases
52582 on some platforms.
52583 X
52584 >>March 27, 1998
52585 X
52586 X --> v31t04
52587 X
52588 Fixed a long standing problem with fastx/tfastx and fasty/tfasty that
52589 caused various memory allocation problems and core dumps.
52590 X
52591 The PVM version works again, but cannot produce alignments.  The
52592 change in the location of the modular display functions will require
52593 significant changes in the pvm display functions.  For the moment,
52594 showalign() has been commented out.
52595 X
52596 Code tested on Macintosh without changes.
52597 X
52598 Added some additional information in the results file.
52599 X
52600 X
52601 Please report bugs to wrp@virginia.edu
52602 X
52603 >>April 3, 1998
52604 X
52605 Removed some debugging code in faatran.c now that fastx/fasty bugs
52606 seem corrected.
52607 X
52608 X  FASTA --> v3.14
52609 X
52610 Corrected uninitialized array elements in dropnfa.c.
52611 X
52612 >>April 10, 1998
52613 X
52614 Added facility for specifying SRCH_URL (the URL string that will be
52615 used to re-search the database) and REF_RUL (the URL string that
52616 will be used to lookup the sequence) ini url_subs.c.  This allows perl
52617 scripts to provide different databases for re-searching dynamically.
52618 X
52619 >>April 16, 1998
52620 X
52621 X --> v31t05
52622 X
52623 Corrected problem with ignoring ','s in databases (','s are found in
52624 PIR).
52625 X
52626 >>April 18, 1998
52627 X
52628 Corrected some problems with sequence names for Entrez lookups and
52629 re-searching databases.
52630 X
52631 Made minor modifications to nxgetaa.c and compacc.c for compatibility
52632 with Borland 'C' compiler for Win32 systems.  Including makefile.tc
52633 fasta.rsp, prss.rsp, and test.bat for Borland 'C'/win32.
52634 X
52635 >>April 24, 1998
52636 X
52637 X --> v31t06
52638 X
52639 Fixed another bug in fasty3/tfasty3 alignment routines.
52640 X
52641 Added additional information to the do_url1() (url_subs.c) function.
52642 The re-search URL can now reference the start, stop, and length of the
52643 library sequence to be re-searched with.  For DNA library sequences,
52644 these values are always in nucleotides, even with tfasta/x/y.
52645 X
52646 X
52647 >>May 12, 1998
52648 X
52649 (no version change as v31t06 was not released prior to this)
52650 X
52651 Correct nxgetaa.c GETLIB to deal correctly with BLAST NR database
52652 sequences with exceptionally long title lines.
52653 X
52654 Fix bug with long -O results files.
52655 X
52656 >>May 18, 1998
52657 X
52658 X --> v31t07
52659 X
52660 Corrected some bugs in information string lengths (e.g. gstring1,
52661 stat_str), disabling statistics with -z 0, translation of 'X' by
52662 saatran() (faatran.c) that caused problems with FASTX.
52663 X
52664 A serious bug has been fixed in the FASTX alignment routines.
52665 For some pathological sequences, % identity increases from < 10%
52666 to 40%. The version number of the main program has not changed,
52667 but the version number of the fastx function has changed to 3.2.
52668 X
52669 >>June 19, 1998
52670 X
52671 X --> v31t08
52672 X
52673 Corrected some problems with alignments with -m 10.
52674 X
52675 Added -Z db_size option to modify apparent database size for
52676 expectation value calculation (used only for protein/protein FASTA and
52677 SSEARCH, FASTX, FASTY, TFASTX, and TFASTY).
52678 X
52679 >>July 1, 1998
52680 X
52681 X (no version change)
52682 X
52683 Corrected size of lbnames[], lb_size[] in structs.h to accomodate MAX_LF
52684 files.
52685 X
52686 >>July 13, 1998
52687 X
52688 X --> v31t09
52689 X
52690 Corrected problem in nxgetaa.c encountered when reading long sequences
52691 (that must be split) in fasta format.
52692 X
52693 Corrected problem in statistics calculation encountered with a small number
52694 of very long DNA sequences.
52695 X
52696 >>July 17, 1998
52697 X
52698 X (no version change, date change for ssearch3)
52699 X
52700 Corrected default expectation cutoff (it was 10, now it is 2.0) for
52701 DNA with ssearch3.
52702 X
52703 SHAR_EOF
52704 chmod 0644 readme.v31t0 ||
52705 echo 'restore of readme.v31t0 failed'
52706 Wc_c="`wc -c < 'readme.v31t0'`"
52707 test 4461 -eq "$Wc_c" ||
52708         echo 'readme.v31t0: original size 4461, current size' "$Wc_c"
52709 fi
52710 # ============= readme.v31t1 ==============
52711 if test -f 'readme.v31t1' -a X"$1" != X"-c"; then
52712         echo 'x - skipping readme.v31t1 (File already exists)'
52713 else
52714 echo 'x - extracting readme.v31t1 (Text)'
52715 sed 's/^X//' << 'SHAR_EOF' > 'readme.v31t1' &&
52716 >>July 22, 1998
52717 X
52718 X --> v31t10
52719 X
52720 Corrected problem with histogram when unscaled statistics used (e.g. prss3).
52721 X
52722 Corrected problems with prss3 shuffled sequence prompt.  Provided option
52723 to enter number of shuffles, window size, for prss3.  Number of shuffles
52724 for prss3 can be entered as an option (-d #) or as the third argument
52725 on the command line (prss3 query lib 1000).
52726 X
52727 Modified nrand.c, nrand48.c to use time to set random number.
52728 X
52729 Corrected problems reading GCG formatted files with prss3.
52730 X
52731 Corrected various problems with pvcomp* programs, but they still do
52732 not produce alignments with version 3.1.
52733 X
52734 Two new programs, fastf3(_t) and tfastf3(_t) are available.  These
52735 programs compare a set of mixed peptide sequences from an Edman
52736 sequencer to a protein (fastf3) or DNA (tfastf3) database, using 
52737 the database sequences to de-convolve the peptide mixture.
52738 X
52739 See fastf3.1
52740 X
52741 >>August 11, 1998
52742 X
52743 (no version change)
52744 X
52745 Modified initfa.c so that using '-n' on the fastx/fasty command line
52746 would not cause problems.
52747 X
52748 Changed labeling of query sequence length for fastx/fasty from 'aa' to 'nt'.
52749 X
52750 >>August 18, 1998
52751 X
52752 (no version change)
52753 X
52754 Modified complib.c, comp_thr.c scaleswn.c, to report E()-value for only
52755 one related sequence if -z 3 is used.
52756 X
52757 >>August 23, 1998
52758 X
52759 X -->v31t11
52760 X
52761 Some serious problems with prss3 have been corrected:
52762 X
52763 (1) use dropnsw.c rather than dropgsw.c for more accurate low scores
52764 X
52765 (2) modify estimation program; use scaleswe.c rather than scaleswn.c.
52766 X    scaleswe.c has some improvements for estimation by moments and can
52767 X    use MLE as well as mu/var (-z 3).
52768 X
52769 (3) add p() estimate.
52770 X
52771 (4) correct bugs in nrand48, which caused bad sequences for llgetaa.c
52772 X
52773 (5) -Z number works properly for prss3 and other programs (fixed histogram).
52774 X
52775 (6) a new program, ssearch3e, is available that uses the same scaling
52776 X    routines as prss3 (scaleswe.c). prss3 will save the random
52777 X    sequences it generates when the -r file option is given; the
52778 X    sequences are in file_rlib.  ssearch3e (or ssearch3 or fasta) can
52779 X    then do a search on exactly the same sequences that were used by prss3.
52780 X
52781 A bug reading GCG format compressed DNA databases was fixed.
52782 X
52783 Fixed a bug that caused query sequence not to be displayed with -m 10.
52784 X
52785 Simple optimization in dropnfa.c improves performance 10%.
52786 X
52787 >>Sept. 1, 1998
52788 X
52789 (no version change)
52790 X
52791 Modified nxgetaa.c to recognize "ACGTX" as nucleotides.
52792 X
52793 >>Sept. 7, 1998
52794 X
52795 X --> v31t12
52796 X
52797 Added -z 11 - 15, which use shuffled sequences, rather than real
52798 sequences to calculate statistical estimates.  Because a shuffled
52799 sequence score is calculated for each sequence score, the search
52800 process takes twice as long.  In this first version, codons are not
52801 preserved during shuffles, so tfasta/x/y shuffles may not be as
52802 informative as they should be.
52803 X
52804 Also fix a problem with prss3 shuffles.
52805 X
52806 >>Sept. 14, 1998
52807 X
52808 X (no version change; previous version not released)
52809 X
52810 Corrected bugs in tfastx3/tfasty3 caused by using the -3 option with
52811 or without -i.  With the bug fixes; "-3" and "-3 -i" work as expected;
52812 "-3" gives the forward three frames, while "-3 -i" gives the reverse
52813 three frames.
52814 X
52815 In addition, tfasta3/tfasta3_t was upgraded to perform the same way
52816 that tfastx/y3 does - i.e. a search with "-i -3" searches only frames
52817 4,5, and 6, while "-3" searches only frames 1, 2, and 3.
52818 X
52819 >>Sept. 29, 1998
52820 X
52821 X --> v31t13
52822 X
52823 Corrected bugs in dropfx.c that were corrected in fasta30 last May,
52824 but lingered in fasta31.  Also included code to ensure that tfastx/y
52825 alignments against long introns would not overrun the alignment
52826 buffer.  Instead of overrunning the buffer, the message: ***aligment
52827 truncated *** is displayed.
52828 X
52829 SHAR_EOF
52830 chmod 0644 readme.v31t1 ||
52831 echo 'restore of readme.v31t1 failed'
52832 Wc_c="`wc -c < 'readme.v31t1'`"
52833 test 3632 -eq "$Wc_c" ||
52834         echo 'readme.v31t1: original size 3632, current size' "$Wc_c"
52835 fi
52836 # ============= readme.v32t0 ==============
52837 if test -f 'readme.v32t0' -a X"$1" != X"-c"; then
52838         echo 'x - skipping readme.v32t0 (File already exists)'
52839 else
52840 echo 'x - extracting readme.v32t0 (Text)'
52841 sed 's/^X//' << 'SHAR_EOF' > 'readme.v32t0' &&
52842 X
52843 FASTX/Y and FASTA (DNA) are now half as fast, because the programs now
52844 search both the forward and reverse strands by default.
52845 X
52846 The documentation in fasta3x.me/fasta3x.doc has been substantially
52847 revised.
52848 X
52849 >>October 9, 1999
52850 X --> v32t08 (no version number change)
52851 X
52852 Added "-M low-high" option, where low and high are inclusion limits
52853 for library sequences.  If a library sequence is shorter than "low" or
52854 longer than "high", it will not be considered in the search.  Thus,
52855 "-M 200-250" limits the database search to proteins between 200 and
52856 250 residues in length.  This should be particularly useful for fasts3
52857 and fastf3.  This limit applies only to protein sequences.
52858 X
52859 Modified scaleswn.c to fall back to maximum likelihood estimates of
52860 lambda, K rather than mean/variance estimates. (This allows MLE
52861 estimation to be used instead of proc_hist_n when a limited range of
52862 scores is examined.)
52863 X
52864 >>October 20, 1999
52865 (no version change)
52866 X
52867 Modify nxgetaa.c/nmgetaa.c to recognize 'N' as a possible DNA character.
52868 X
52869 >>October 9, 1999
52870 X --> v32t08 (no version number change)
52871 X
52872 Added "-M low-high" option, where low and high are inclusion limits
52873 for library sequences.  If a library sequence is shorter than "low" or
52874 longer than "high", it will not be considered in the search.  Thus,
52875 "-M 200-250" limits the database search to proteins between 200 and
52876 250 residues in length.  This should be particularly useful for fasts3
52877 and fastf3.  -M -500 searches library sequences < 500; -M 200 -
52878 searches sequences > 200. This limit applies only to protein
52879 sequences.
52880 X
52881 Modified scaleswn.c to fall back to maximum likelihood estimates of
52882 lambda, K rather than mean/variance estimates. (This allows MLE
52883 estimation to be used instead of proc_hist_n when a limited range of
52884 scores is examined.)
52885 X
52886 >>October 2, 1999
52887 X --> v32t08
52888 X
52889 Many changes:
52890 X
52891 (1) memory mapped (mmap()ed) database reading - other database reading fixes
52892 (2) BLAST2 databases supported
52893 (3) true maximum likelihood estimates for Lambda, K
52894 (4) Misc. minor fixes
52895 X
52896 (1) (Sept. 26 - Oct. 2, 1999) Memory mapped database access.
52897 It is now possible to use mmap()ed access to FASTA format databases,
52898 if the "map_db" program has been used to produce an ".xin" file.  If
52899 USE_MMAP is defined at compile time and a ".xin" file is present, the
52900 ".xin" will be used to access sequences directly after the file is
52901 mmap()ed.  On my 4-processor Alpha, this can reduce elapsed time by
52902 50%. It is not quite as efficient as BLAST2 format, but it is close.
52903 X
52904 Currently, memory mapping is supported for type 0 (FASTA), 5
52905 (PIR/GCG ascii), and 6 (GCG binary).  Memory mapping is used if a
52906 ".xin" file is present. ".xin" files are created by the new program
52907 "map_db".  The syntax for "map_db" is:
52908 X
52909 X       map_db [-n] "/dir/database.fa"
52910 X
52911 which creates the file /dir/database.fa.xin.  Library types can be
52912 included in the filename; thus:
52913 X
52914 X       map_db -n "/gcggenbank/gb_om.seq 6"
52915 X
52916 would be used for a type 6 GCG binary file. 
52917 X
52918 The ".xin" file must be updated each time the database file changes.
52919 map_db writes the size of the database file into the ".xin" file, so
52920 that if the database file changes, making the ".xin" offset
52921 information invalid, the ".xin" file is not used. "list_db" is
52922 provided to print out the offset information in the ".xin" file.
52923 X
52924 (Oct 2, 1999) The memory mapping routines have been changed to
52925 allow several files to be memory mapped simultaneously. Indeed, once a
52926 database has been memory mapped, it will not be unmap()ed until the
52927 program finishes.  This fixes a problem under Digital Unix, and should
52928 make re-access to mmap()ed files (as when displaying high scores and
52929 alignments) much more efficient.  If no more memory is available for
52930 mmap()ing, the file will be read using conventional fread/fgets.
52931 X
52932 (Oct 2, 1999) The names of the database reading functions has been
52933 changed to allow both Blast1.4 and Blast2.0 databases to be read.  In
52934 addition, Makefile.common now includes an option to link both
52935 ncbl_lib.o and ncbl2_lib.o, which provides support for both libraries.
52936 However, Blast1.4 support has not been tested.
52937 X
52938 The Makefile structure has been improved.  Each architecture specific
52939 Makefile (Makefile.alpha, Makefile.linux, etc) now includes
52940 Makefile.common.  Thus, changes to the program structure should be
52941 correct for all platforms.  "map_db" and "list_db" are not made with
52942 "make all".
52943 X
52944 The database reading functions in nxgetaa.c can now return a database
52945 length of 0, which indicates that no residues were read.  Previously,
52946 0-length sequences returned a length of 1, which were ignored.
52947 Complib.c and comp_thr.c have changed to accommodate this
52948 modification.  This change was made to ensure that each residue,
52949 including the last, of each sequence is read.
52950 X
52951 Corrected bug in nxgetaa.c with FASTA format files with very long
52952 (>512 char) definition lines.
52953 X
52954 (2) (September 20, 1999) BLAST2 format databases supported
52955 X
52956 This release supports NCBI Blast2.0 format databases, using either
52957 conventional file reading or memory mapped files.  The Blast2.0 format
52958 can be read very efficiently, so there is only a modest improvement in
52959 performance with memory mapping.  The decision to use mmap()'ed files
52960 is made at compile time, by defining USE_MMAP.  My thanks to Eamonn
52961 O'Toole of DEC/Compaq, and Daryl Madura of Sun Microsystems, for
52962 providing mmap()'ed modifications to fasta3.  On my machines, Blast2.0
52963 format reduces search time by about 30%.  At the moment, ambiguous DNA
52964 sequences are not decoded properly.
52965 X
52966 (3) (September 30, 1999) A new statistical estimation option is
52967 available.  -z 2 has been changed from ln()-scaling, which never
52968 should have been used, to scaling using Maximum Likelihood Estimates
52969 (MLEs) of Lambda and K.  The MLE estimation routines were written by
52970 Aaron Mackey, based on a discussion of MLE estimates of Lambda and K
52971 written by Sean Eddy.  The MLE estimation examines the middle 95% of
52972 scores, if there are fewer than 10000 sequences in the database;
52973 otherwise it excludes (censors) the top 250 scores and the bottom 250
52974 scores.  This approach seems to effectively prevent related sequences
52975 from contaminating the estimation process.  As with -z 1, -z 12 causes
52976 the program to generate a shuffled sequence score for each of the
52977 library sequences; in this case, no censoring is done.  If the
52978 estimation process is reliable, Lambda and K should not vary much with
52979 different queries or query lengths.  Lambda appears not to vary much
52980 with the comparison algorithm, although K does.
52981 X
52982 (4) Minor changes include fixes to some of the alignment display routines,
52983 individual copies of the pstruct structure for each thread, and some
52984 changes to ensure that every last residue in a library is available
52985 for matching (sometime the last residue could be ignored).  This
52986 version has undergone extensive testing with high-throughput sequences
52987 to confirm that long sequences are read properly.  Problems with
52988 fastf3/fasts3 alignment display have also been addressed.
52989 X
52990 >>August 26, 1999 (no version change - not released)
52991 X
52992 Corrected problem in "apam.c" that prevented scoring matrices from
52993 being imported for [t]fasts3/[t]fastf3.
52994 X
52995 >>August 17, 1999
52996 X --> v32t07
52997 X
52998 Corrected problem with opt_cut initialization that only appeared
52999 with pvcomp* programs.
53000 X
53001 Improved calculation of FASTA optcut threshold for DNA sequence
53002 comparison for match scores much less than +5 (e.g. +3).  The previous
53003 optcut theshold was too high when the match penalty was < 4 and
53004 ktup=6; it is now scaled more appropriately.
53005 X
53006 Optcut thresholds have also been raised slightly for
53007 fastx/y3/tfastx/y3.  This should improve performance with minimal
53008 effects on sensitivity.
53009 X
53010 >>July 29, 1999
53011 (no version change - date change)
53012 X
53013 Corrected various uninitialized variables and buffer overruns
53014 detected.
53015 X
53016 >>July 26, 1999 - new distribution
53017 (no version change - v32t06, previous version not released)
53018 X
53019 Changed the location of "(reverse complement)" label in tfasta/x/y/s/f
53020 programs.
53021 X
53022 Statistical calculations for tfasta/x/y in unthreaded version
53023 corrected.  Statistical estimates for threaded and unthreaded versions
53024 of the tfasta/x/y/s/f programs should be much more consistent.
53025 X
53026 Substantial modifications in alignment coordinate calculation/
53027 presentation.  Minor error in fastx/y/tfastx/y end of alignment
53028 corrected.  Major problems with tfasta alignment coordinates
53029 corrected.  tfasta and tfastx/y coordinates should now be consistent.
53030 X
53031 Corrected problem with -N 5000 in tfasta/x/y3(_t) searches encountered
53032 with long query sequences.
53033 X
53034 Updated pthr_subs.c/Makefile.linux to increase the pthreads stacksize
53035 to try to avoid "cannot allocate diagonal arrays" error message.
53036 Pthreads stacksize can be changed with RedHat 6.0, but not RedHat 5.2,
53037 so Makefile.linux uses -DLINUX5 for RedHat5.* (no pthreads stack size).
53038 I am still getting this message, so it has not been completely
53039 successful.  Makefile.linux now uses -DALLOCN0 to avoid this problem,
53040 at some cost in speed.
53041 X
53042 The pvcomp* programs have been updated to work properly with
53043 forward/reverse DNA searches.  See readme.pvm_3.2.
53044 X
53045 >>July 7, 1999 - not released
53046 X --> v32t06
53047 X
53048 Corrected bug in complib.c (fasta3, fastx3, etc) that caused core
53049 dumps with "-o" option.
53050 X
53051 Corrected a subtle bug in fastx/y/tfastx/y alignment display.
53052 X
53053 >>June 30, 1999 - new distribution
53054 (no version change)
53055 X
53056 Corrected doinit.c to allow DNA substitution matrices with -s matrix
53057 option.
53058 X
53059 Changed ".gbl" files to ".h" files.
53060 X
53061 >>June 2 - 9, 1999 - new distribution
53062 (no version change)
53063 X
53064 Added additional DNA lambda/K/H to alt_param.h.  Corrected some
53065 other problems with those table. for the case where (inf,inf)
53066 gap penalties were not included.
53067 X
53068 Fixed complib.c/comp_thr.c error message to properly report filename
53069 when library file is not found.
53070 X
53071 Included approximate Lambda/K/H for BL80 in alt_parms.h.
53072 BL80 scoring matrix changed from 1/3 bit to 1/2 bit units.
53073 X
53074 Included some additional perl files for searchfa.cgi, searchnn.cgi
53075 in the distribution (my-cgi.pl, cgi-lib.pl).
53076 X
53077 >>May 30, 1999, June 2, 1999 - new distribution
53078 (no version number change)
53079 X
53080 Added Makefile.NetBSD, if !defined(__NetBSD__) for values.h.  Changed
53081 zs_to_E() and z_to_E() in scaleswn.c to correctly calculate E() value
53082 when only one sequence is compared and -z 3 is used.
53083 X
53084 >>May 27, 1999
53085 (no version number change)
53086 X
53087 Corrected bug in alignment numbering on the % identity line
53088 X       27.4% identity in 234 aa (101-234:110-243)
53089 for reverse complements with offset coordinates (test.aa:101-250)
53090 X
53091 >>May 23, 1999
53092 (no version number change)
53093 X
53094 Correction to Makefile.linux (tgetaa.o : failed to -DTFAST). 
53095 X
53096 >>May 19, 1999
53097 (no version number change)
53098 X
53099 Minor changes to pvm_showalign.c to allow #define FIRSTNODE 1.
53100 Changes to showsum.c to change off-end reporting.  (Neither of these
53101 changes is likely to affect anyone outside my research group.)
53102 X
53103 >>May 12, 1999
53104 X --> v32t05
53105 X
53106 Fixed a serious bug in the fastx3/tfastx3 alignment display which
53107 caused t/fastx3 to produce incorrect alignments (and incorrectly low
53108 percent identities).  The scores were correct, but the alignment
53109 percent identities were too low and the alignments were wrong.
53110 X
53111 Numbering errors were also corrected in fastx3/tfastx3 and
53112 fasty3/tfasty3 and when partial query sequences were used.
53113 X
53114 >>May 7, 1999
53115 X
53116 Fixed a subtle bug in dropgsw.c that caused do_work() to calculate
53117 incorrect Smith-Waterman scores after do_walign() had been called.
53118 This affected only pvcompsw searches with the "-m 9" option.
53119 X
53120 >>May 5, 1999
53121 X
53122 Modified showalign.c to provide improved alignment information that
53123 includes explicitly the boundaries of the alignment.  Default
53124 alignments now say:
53125 X
53126 Smith-Waterman score: 175;  24.645% identity in 211 aa overlap (5:207-7:207)
53127 X
53128 >>May 3, 1999
53129 X
53130 Modified nxgetaa.c, showsum.c, showbest.c, manshowun.c to allow a
53131 "not" superfamily annotation for the query sequence only.  The
53132 goal is to be able to specify that certain superfamily numbers be
53133 ignored in some of the search summaries.  Thus, a description line
53134 of the form:
53135 X
53136 >GT8.7 | 40001 ! 90043 | transl. of pa875.con, 19 to 675
53137 X
53138 says that GT8.7 belongs to superfamily 40001, but any library
53139 sequences with superfamily number 90043 should be ignored in any
53140 listing or summary of best scores.
53141 X
53142 In addition, it is now possible to make a fasta3r/prcompfa, which is
53143 the converse of fasta3u/pucompfa. fasta3u reports the highest scoring
53144 unrelated sequences in a search using the superfamily annotation.
53145 fasta3r shows only the scores of related sequences.  This might be
53146 used in combination with the -F e_val option to show the scores
53147 obtained by the most distantly related members of a family.
53148 X
53149 >>April 25, 1999
53150 X
53151 X -->v32t04 (not distributed)
53152 X
53153 Modified nxgetaa.c to remove the dependence of tgetaa.o on TFASTA
53154 (necessary for a more rational Makefile structure).  No code changes.
53155 X
53156 >>April 19, 1999
53157 X
53158 Fixed a bug in showalign.c that displayed incorrect alignment coordinates.
53159 (no version number change).
53160 X
53161 >>April 17, 1999
53162 X
53163 X --> v32t03
53164 X
53165 A serious bug in DNA alignments when the sequence has been broken into
53166 multiple segments that was introduced in version fasta32 has been
53167 fixed.  In addition, several minor problems with -z 3 statistics on
53168 DNA sequences were fixed.
53169 X
53170 Added -m 9 option, which unfortunately does different things in
53171 pvcompfa/sw and fasta3/ssearch3.  In both programs, -m 9 provides the
53172 id's of the two sequences, length, E(), %_ident, and start and end of
53173 the alignment in both sequences.  pvcompfa/sw provides this
53174 information with the list of high scoring sequences.  fasta3/ssearch3
53175 provides the information in lieu of an alignment.
53176 X
53177 >>March 18, 1999
53178 X
53179 X --> v32t02
53180 X
53181 Added information on the algorithm/parameter description line to
53182 report the range of the pam matrices.  Useful for matrices like
53183 MD_10, _20, and _40 which require much higher gap penalties.
53184 X
53185 >>March 13, 1999 (not distributed)
53186 X
53187 X --> v32t01 
53188 X
53189 X -r results.file  has been changed to -R results.file to accomodate
53190 X DNA match/mismatch penalties of the form: -r "+1/-3".
53191 X
53192 >>February 10, 1999
53193 X
53194 Modify functions in scalesw*.c to prevent underflow after exp() on
53195 Alpha Linux machines.  The Alpha/LINUX gcc compiler is buggy and
53196 doesn't behave properly with "denormalized" numbers, so "gcc -g -m
53197 ieee" is recommended.
53198 X
53199 Add "Display alignments also (y/n)[n] "
53200 X
53201 pvcomplib.c again provides alignments!!  In addition, there is a
53202 new "-m 9" option, which reports alignments as:
53203 X
53204 >>>/home/wrp/slib/hlibs/hum0.aa#5>HS5 gi:1280326 T-cell receptor beta chain 30 aa, 30 aa vs /home/wrp/slib/hlibs/hum0.seg library
53205 HS5               30    HS5               30    1.873e-11       1.000     30       1      30       1      30
53206 HS5               30    HS2249            40    1.061e-07       0.774     31       1      30       7      37
53207 HS5               30    HS2221            38    1.207e-07       0.833     30       1      30       7      35
53208 HS5               30    HS2283            40    1.455e-07       0.774     31       1      30       7      37
53209 HS5               30    HS2239            38    1.939e-07       0.800     30       1      30       7      35
53210 X
53211 where the columns are:
53212 X
53213 query-name      q-len   lib-name      lib-len   E()             %id    align-len  q-start q-end   l-start l-end
53214 X
53215 >>February 9, 1999
53216 X
53217 Corrected bug in showalign.c that offset reverse complement alignments
53218 by one.
53219 X
53220 >>Febrary 2, 1999
53221 X
53222 Changed the formatting slightly in showbest.c to have columns line up better.
53223 X
53224 >>January 11, 1999
53225 X
53226 Corrected some bugs introduced into fastf3(_t) in the previous version.
53227 X
53228 >>December 28, 1998
53229 X
53230 Corrected various problems in dropfz.c affecting alignment scores
53231 and coordinates.
53232 X
53233 Introduced a new program, fasts3(_t), for searching with peptide
53234 sequences.
53235 X
53236 >>November 11, 1998
53237 X
53238 X  --> v32t0
53239 X
53240 Added code to correct problems with coordinate number in long library
53241 sequences with tfastx/tfasty.  With this release, sequences should be
53242 numbered properly, and sequence numbers count down with reverse
53243 complement library sequences.
53244 X
53245 In addition, with this release, fastx/y and tfastx/y translated
53246 protein alignments are numbered as nucleotides (increasing by 3,
53247 labels every 30 nucleotides) rather than codons.
53248 X
53249 SHAR_EOF
53250 chmod 0644 readme.v32t0 ||
53251 echo 'restore of readme.v32t0 failed'
53252 Wc_c="`wc -c < 'readme.v32t0'`"
53253 test 15841 -eq "$Wc_c" ||
53254         echo 'readme.v32t0: original size 15841, current size' "$Wc_c"
53255 fi
53256 # ============= readme.v33t0 ==============
53257 if test -f 'readme.v33t0' -a X"$1" != X"-c"; then
53258         echo 'x - skipping readme.v33t0 (File already exists)'
53259 else
53260 echo 'x - extracting readme.v33t0 (Text)'
53261 sed 's/^X//' << 'SHAR_EOF' > 'readme.v33t0' &&
53262 X
53263 X $Name: fa_34_26_5 $ - $Id: readme.v33t0,v 1.45 2001/07/10 18:03:42 wrp Exp $
53264 X
53265 ================ readme.v33t0 ================
53266 X
53267 This release includes an MPI implementation of the parallel
53268 library-vs-library comparison code.  See readme.mpi_3.3 and
53269 readme.pvm_3.3 for more information.
53270 X
53271 =====
53272 >>July 9, 2001
53273 X
53274 Considerable changes to support no-global library functions. 
53275 X
53276 (1) Separate ascii/sequence mapping arrays are used by the
53277 X    query-reading (qascii), library-reading (lascii), and sequence
53278 X    comparison function (pascii) routines.  As a result, there is no
53279 X    longer a need for tgetlib.o/lgetlib.o - lgetlib.o can serve both
53280 X    functions.
53281 X
53282 (2) This also allows us to remove all #ifdef TFAST/FASTX conditionals
53283 X    from complib.c/comp_thr.c/p2_complib.c.  We no longer need
53284 X    tcomp_thr.o, comp_thrx.o, etc.  We still have a variety of
53285 X    p2_complib.o variations to support the different c34.work* files.
53286 X
53287 (3) Because non-global openlib/getlib functions are available, exactly
53288 X    the same open/get functions are available for reading both the
53289 X    query and reference libraries in pv34comp* programs.  The
53290 X    host-specific openlib/getlib functions in hxgetaa.c are now
53291 X    provided by nmgetlib.c, etc. This has two effect:
53292 X
53293 X    (a) it is now possible to compare a query database generated by an
53294 X        SQL query to a library database generated by a different SQL
53295 X        query.
53296 X
53297 X    (b) pv34comp* has lost (at least in this version) the ability to
53298 X        automatically detect the query sequence type. To search with a
53299 X        DNA query, you MUST use "-n".
53300 X
53301 (4) the resetp() function is now responsible for almost all of the
53302 X    function sepcific (TFAST/FASTX/etc) initializations.  All of the
53303 X    function specific code has been removed from complib.c/comp_thr.c
53304 X    and most of it has been moved to initfa.c/resetp().
53305 X
53306 (5) manageacc.c has been merged into compacc.c (mostly prhist()).
53307 X
53308 (6) Although it may reflect a subtle bug in my code, it is not
53309 X    possible to reliably run threaded/memory mapped versions of the
53310 X    fasta34_t code.  I have spent considerable time tracking down the
53311 X    problem, and have determined that, in threaded code, something
53312 X    happens during the thread initialization to corrupt the
53313 X    description offset information used when files are memory mapped.
53314 X    This never occurs when the unthreaded versions of the code are
53315 X    used.  And it does not occur under MacOSX, Compaq Tru64Unix, Sun
53316 X    Solaris/Sparc, or SGI IRIX.
53317 X
53318 X    Thus, I cannot recommend using the threaded code versions (_t)
53319 X    under Linux (RH6.2 or 7.1).
53320 X
53321 =====
53322 >>June 1, 2001
53323 X
53324 Many changes to accomodate a new - no global variable - strategy for
53325 reading sequence databases.  Every time a file is opened, a struct
53326 lmf_str is allocated which can be used for memory mapped files, ncbl2,
53327 files, and mysql files.
53328 X
53329 In addition, an open'ed file has a default sequence type: DNA or
53330 protein, or one can open a file in a mode that will allow the sequence
53331 type to be changed.
53332 X
53333 =====
53334 >>May 18, 2001          CVS: fa33t09d0
53335 X
53336 A new compile time parameter - -DGAP_OPEN, is available to change the
53337 definition of the "-f gap-open" parameter from the penalty for the
53338 first residue in a gap to a true gap-open penalty, as is used in BLAST
53339 and many other comparison algorithms.  This will probably become the
53340 default for fasta in version 3.4.
53341 X
53342 Fixes to conflicts between "-S" and "-s matrix".  When a scoring
53343 matrix file was specified, lower-case alignments were not displayed
53344 with -S (although the scores were calculated properly).
53345 X
53346 More extensive testting of mysql_lib.c (mySQL query-libraries) with
53347 the pv4comp* and mp4comp* programs.
53348 X
53349 =====
53350 >>April 5, 2001         CVS: fa33t08d4b3
53351 X
53352 Changes in nmgetlib.c and ncbl2_mlib.c to return long sequence
53353 descriptions for PCOMPLIB (pv4/mp3comp*).  Also fix p2_complib.c to
53354 request DNA library for translated comparisons.
53355 X
53356 Fix for prss33(_t) to read both sequences from stdin.
53357 X
53358 =====
53359 >>March 27, 2001        CVS: fa33t08d4
53360 X --> fa33t08d4
53361 X
53362 Problems in ncbl2_mlib.c found searching NCBI non-redundant nucleotide
53363 database "nt" were fixed.  Testing revealed a minor memory leak, which
53364 was fixed by modifying showbest.c, showalign.c, comp_thr.c, complib.c,
53365 and p2_complib.c to remember the last opened database file more
53366 effectively.
53367 X
53368 Modifications to allow 64-bit fseek/ftell on machines like Sun,
53369 Linux/Intel, that support -D_FILE_OFFSET_BITS=64, -D_LARGE_FILE_SOURCE
53370 off_t, and fseeko(), ftello() with the option -DUSE_FSEEKO.  Machines
53371 with 64-bit long's do not need this option.  Machines with 32-bit
53372 longs that allow files >2 Gb can do so with 64-bit file access
53373 functions, including fseeko() and ftello(), which work with off_t file
53374 offsets instead of long's.
53375 X
53376 =====
53377 >>March 3, 2001         CVS: fa33t08d2
53378 X
53379 Corrected problems in nmgetaa.c and mysql_lib.c with parallel
53380 programs, and one serious problem with alternate DNA scoring matrices
53381 (initfa.c, initsw.c) not being set properly.  A subtle problem with
53382 the merge of scaleswn.c and scaleswg.c is fixed.
53383 X
53384 >>February 17, 2001
53385 X
53386 Modified mysql_lib.c to use "#", rather than "%ld", to indicate the
53387 position of the GID.  This change was made because sprintf() cannot be
53388 used reliably to generate an SQL string, as '"' and '%' are used in 
53389 such strings.
53390 X
53391 =====
53392 >>January 17, 2001
53393 (no version change, date change)
53394 X
53395 Minro fixes to initfa.c, initsw.c to deal with DNA scoring matrices
53396 properly. "-n -s dna.mat" is required for the sequence/matrix to be
53397 recognized as DNA.
53398 X
53399 >>January 16, 2001
53400 -->v34t00
53401 X
53402 Merge of the main CVS trunk - fa33t06 with the latest release branch,
53403 fa33t08.
53404 X
53405 In addition, PCOMPLIB mods have been made to mysql_lib.c.  Because
53406 p2_complib.c gets sequence description information during the first
53407 read of the database, the mysql_query must be changed to return:
53408 result[0]=GID, result[1]=description, result[2]=sequence.  In the
53409 PCOMPLIB case, the other SQL queries (for GID description, sequence)
53410 are not necessary but must still be provided.
53411 X
53412 =====
53413 >>January 16, 2001
53414 (no version change, previous version not released)
53415 X
53416 changes to p2_complib.c to correct openlib() incompatibility.
53417 X
53418 changes to nmgetaa.c, ncbl2_lib.c to incorporate PCOMPLIB.  nxgetaa.c
53419 removed.
53420 X
53421 =====
53422 >>January 12, 2001
53423 (no version change, previous version not released)
53424 X
53425 Change to initfa.c to move ktup check from query_parm() to last_init().
53426 X
53427 =====
53428 >>January 10, 2001
53429 --> v33t08
53430 X
53431 Fixes to complib.c, comp_thr.c to deal properly with long query
53432 protein sequences when a short library chunk (e.g. -N 5000) was given.
53433 In the case where the chunk size is too short, it will be reset to a
53434 length which allows the search to proceed, by including an amount of
53435 new sequence that is equal to the amount of overlap sequence.
53436 X
53437 scaleswn.c and scaleswg.c have been merged.
53438 X
53439 v33t08 includes the initial implementation for mySQL described below
53440 for v33t07x.
53441 X
53442 ======
53443 >>Dec. 20, 2000
53444 --> v33t07x
53445 X
53446 Initial implementation of a syntax for mySQL database queries.  A new
53447 file, mysql_lib.c has been added, and changes have been made to
53448 nmgetaa.c (which should now replace nxgetaa.c) and altlib.h.  A mySQL
53449 database search needs a file with 4 parts:
53450 X
53451 (1) description of the database, user, password
53452 (2) a select statement that generates the set of protein sequences
53453 X    as: UID, sequence
53454 (3) a select statement that generates a UID, description given a UID
53455 (4) a select statement that generats a single UID, sequence given a UID
53456 X       
53457 Each of the four parts should be separated by ';'.  For example, in
53458 the database that we are using for testing, a file "demo.sql" that
53459 contains:
53460 X
53461 ================
53462 localhost taxonomy username secret;
53463 SELECT proteins.gid, proteins.sequence FROM proteins,swissprot WHERE proteins.gid=swissprot.gid AND swissprot.spid IS NOT NULL;
53464 select proteins.gid, concat(swissprot.spid," ",proteins.description) from proteins,swissprot where proteins.gid=%ld AND swissprot.gid=proteins.gid;
53465 select gid, sequence from proteins where gid=%ld;
53466 ================
53467 X
53468 will find all the proteins in the BLAST "nr" database that also have
53469 SwissProt ID's when given the command line:
53470 X
53471 X       fasta33 -q query.aa "demo.sql 16"
53472 X
53473 At least for simple queries, there is surprisingly little overhead for the
53474 search.  For more complex queries involving several tables, the overhead
53475 can be significant.
53476 X
53477 At the moment, libraries that need the functions in mysql_lib.c will
53478 use library type 16.  We may also use file type 17 for SQL queries
53479 that return binary sequences.
53480 X
53481 This implementation of mysql_lib.c was written to require a minimal
53482 amount of change to the other programs.  Only nmgetaa.c and altlib.h
53483 needed to be changed to incorporate this new capability.  One result
53484 of this limitation is that one cannot mix mySQL databases queries with
53485 other databases in the same search.  Eventually, I would like to make
53486 a mySQL database like any other, so that several mysql database
53487 queries could be searched in the same run, and mysql databases could
53488 be mixed with other (flat file) databases, but this will require some
53489 changes in the function calls throughout the code.  (Right now, the
53490 various programs do not distinguish between an openlib() that is made
53491 before searching a large database, and one before retrieving a single
53492 sequence.  This must be changed for a database query like mySQL to
53493 behave like other databases.
53494 X
53495 Several mySQL demo files have been provided: mysql_demo*.sql.
53496 X
53497 (10 January 2001) The mySQL code has been tested on Intel Linux and
53498 Compaq/Alpha/Tru64 Unix.
53499 X
53500 >>Dec. 9, 2000
53501 X
53502 Changes to apam.c that to tie different default gap penalties to
53503 alternate scoring matrices.  In addition, changes to apam.c, to deal
53504 with user-specified matrices with or without '*'.
53505 X
53506 >>Nov. 5, 2000 (date updated)
53507 X
53508 pst.dnaseq can now have 3 values, -1, or 0-> protein, 1->DNA, and 2->other.
53509 This becomes important for thing like init_karlin_a, which needs a
53510 background frequency of residues.
53511 X
53512 >>Nov. 1, 2000
53513 X
53514 Significant bug fixes for the -z 6/-z 16 option.  An ininitialized
53515 variable was fixed in karlin.c, and comp_thr.c did not pass the
53516 correct composition argument type in find_zp().  The -z 6/16 option
53517 has now been tested and works correctly on Alphas, Linux x86, SGI, Sun
53518 and Mac OSX. Another problem was fixed in scaleswn.c (simplex()) that
53519 prevented the code from being reused by the pv4/mp4 complib programs.
53520 X
53521 >>Oct. 9, 2000
53522 X
53523 Several changes made to accomodate Mac OSX.  Longer lists of superfamily
53524 numbers now supported in p[su]4comp/m[su]4comp programs.
53525 X
53526 >>Sept 25, 2000
53527 X
53528 All global variables have been removed from scaleswn.c. The last to
53529 go, db_struct db, required many edits, because until now, the fasta
53530 programs have kept two versions of the db_struct data (entries,
53531 length). One version was kept by the main program, which updated entry
53532 number and db length as sequences were read; a second copy of this
53533 information was kept by the statistical estimation routines.  Now
53534 there is only one copy, which means that the E() values will be a
53535 function of the complete database, not the database with some high
53536 scoring sequences removed.
53537 X
53538 >>Sept 23, 2000
53539 X
53540 Continued removal of global variables from scaleswn.c.  Only one
53541 global is left, db_struct db, which contains the number of entries in
53542 the database and the number of residues.  It will be the next to go
53543 (changing all the zs_to_*() functions) and scaleswn. will be free
53544 of globals.  scaleswg.c is gone - scaleswn.c compiles to scaleswg.c
53545 with -DNORMAL_DIST.
53546 X
53547 >>Sept 20, 2000
53548 X
53549 Removal of histogram globals required changes in p2_complib.c as well.
53550 p_complib.c has not been updated.  scaleswg.c has been modified to
53551 reflect the new histogram strategy.
53552 X
53553 >>Sept 19, 2000
53554 X
53555 Substantial changes to remove globals for printing histogram.  m_msg
53556 now contains a hist_str, which keeps histogram information.
53557 X
53558 >>Sept. 19, 2000
53559 (no version change, previous version not released)
53560 X
53561 Correct bug introduced into scaleswn.c (inithist()) by changing
53562 score2_sums[], score_sums[] from int to double.
53563 X
53564 Reporting of version numbers is more consistent between fasta33,
53565 fasta33_t, and pv4compfa/mp4compfa.  The programs now report the same
53566 numbers/dates in similar places.
53567 X
53568 >>Sept. 15, 2000
53569 --> v33t07
53570 X
53571 Changes to fix problems with statistical estimates when a large
53572 fraction (but not all) of the database is related.  Several users
53573 reported problems when searching with rRNA genes with version 33t06.
53574 In some cases, a 100% identitical match over 1500 nt would not be
53575 statistically significant against a search of the bacterial division
53576 of Genbank.  This problem was not seen with some releases of v33t05.
53577 X
53578 The cause of the problem was a change between v33t05 and v33t06 to
53579 allow scoring matrices with unusual scaling to be used.  In v33t05,
53580 there was a line that excluded all scores > 300 from the statistical
53581 estimation procedure.  While 300 is a high score with any "normal"
53582 scoring matrix, some investigators were using matrices scaled 10X, so
53583 that a score of 300 was really a score of 30 with a conventional
53584 matrix, and should not be excluded.  Unfortunately, removing the test
53585 to exclude scores > 300 meant that when a rRNA sequence was used to
53586 search the bacterial division, tens of thousands of high scoring
53587 related sequences were treated as if they were unrelated, with the
53588 result that the variance estimates were much too high, and thus high
53589 real scores had low z-scores, and thus were not statistically
53590 significant.  (There appear to be more than 20,000 rRNA sequences in
53591 the bacterial division of Genbank, almost 25% of all sequences).
53592 X
53593 The solution to the problem is a substantial enhancement in the
53594 strategies used to exclude high-scoring, related sequences, the -z 1,
53595 4, and 5 parameter estimation strategies.  The programs now estimate
53596 the expected high scoring sequence by calculating an ungapped Lambda
53597 and K, and then use a relatively conservative threshold for excluding
53598 scores that are higher than would be expected 0.01 times by chance.
53599 By calculating Lambda and K, we can scale the cutoff thresholds to
53600 allow scoring matrices with unusual scales.  For "normal" searches,
53601 there should be little change, but there should be an improvement for
53602 searches with large numbers of related sequences in the database.
53603 X
53604 As a result of testing for this change, a bug in the karlin() function
53605 used with -z 6 was found and corrected.
53606 X
53607 =======
53608 >>Sept. 9, 2000
53609 X
53610 Changes to manshowbest.c to include correct display coordinates.
53611 X
53612 Significant changes to structs.h, param.h, p2_complib.c,
53613 p2_workcomp.c, to store and use a reliable a_struct for alignment
53614 coordinates.
53615 X
53616 Other cosmetic changes.
53617 X
53618 >>Sept. 7, 2000
53619 X
53620 Minor changes to complib.c, showrss.c, so that prss33 -q uses 200
53621 shuffles and prss33 provides bit scores, rather than z-scores.
53622 (no version number change).
53623 X
53624 Modifications to p2_complib.c to include superfamily numbers for
53625 ps4comp* ms4comp*.
53626 X
53627 >>Aug 22, 2000
53628 X
53629 Changes to mmgetaa.c, ncbl2_mlib.c, dropfs.c to accomodate AIX.
53630 00README.1st updated to reflect the current version and correct
53631 outdated information on threads.
53632 X
53633 >>Aug. 3, 2000
53634 X
53635 Modifications to initpam2() in initsw.c to correct a problem with pam_x
53636 when the -S option is used.
53637 X
53638 Modifications to compacc.c, scaleswn.c to ensure that residue numbers
53639 are calculated properly when more than 2 Gb of sequence is searched.
53640 X
53641 >>July 12, 2000
53642 X
53643 Modifications to dropnfa.c so that DNA matches to 'N' will be included
53644 in the "ungapped %identity".  Thus, a sequence that is 100% identical
53645 for 100 nt on either side of a 100 nt region that has been masked to
53646 'NNNNN' will be reported as: "67% identical (100% ungapped)".  This
53647 has been added to deal with masked BAC-end databases.  It would be
53648 better if masking changed the letters to lowercase, but the mouse
53649 BAC-end sequences at TIGR use 'NNNNN'.  This is currently available
53650 only for the fasta function, not [t]fast[x/y], etc, and only for DNA
53651 sequences.
53652 X
53653 mk_n_pam() in apam.c modified to ensure that mismatch scores of -1
53654 remain -1.
53655 X
53656 >>June 25, 2000
53657 X
53658 Modification to nxgetaa.c, nmgetaa.c, mmgetaa.c to return Genbank Accession
53659 number as part of the descriptive string.
53660 X
53661 >>June 11, 2000
53662 X
53663 (no version change - not yet released)
53664 X
53665 Modifications to calcons(), calc_id(), showbest(), p_workcomp.c to
53666 provide ngap_q (number of alignment gaps in query) , ngap_l (number
53667 of gaps in library) information for -m 9 output.
53668 X
53669 >>June 6, 2000
53670 X
53671 (no version change - not yet released)
53672 X
53673 Modified scaleswn.c to provide better support for unconventional
53674 scoring scoring matrices, in particular, scoring matrices where every
53675 value is 50-times higher.  Previous versions of the MLE estimator (-z
53676 2) started with lambda = 0.2, which is too high for a scoring matrix
53677 going from -500:+1500. The initial estimate for lambda is now
53678 calculated using the formula: lambda = pi/sqrt(6*variance).  For the
53679 default -z 1, a restriction to limit scores to a maximum of 300 for
53680 the statistical analysis was removed.
53681 X
53682 >>June 3, 2000
53683 X
53684 Modified aligment output, and -m 9 and -m10, to report an "ungapped"
53685 identity as well as the traditional "gapped" identity.  The
53686 traditional "gapped" identity reports the number of identities divided
53687 by the overall length of the alignment, including gaps.  The
53688 "ungapped" identity does not include gaps in the length of the
53689 alignment.  This new value is included for alignments that include
53690 introns; thus, a tfastx33 search might find the 100% identical genomic
53691 sequence but report the gapped percent identity if a short intron were
53692 included in the alignment (the alignment probably would not span a
53693 long exon) as 66%.  The "ungapped" identity would remain 100%.  The
53694 ungapped identity value is also shown in the "-m 9" output line after
53695 the "gapped" fraction identical.
53696 X
53697 >>June 1, 2000
53698 X
53699 Modified -m 9 output to provide fraction identical, alignment boundary
53700 information with the initial list of high scoring sequences, just as
53701 the pv3comp and mp_comp versions do.  The -m 9 option now shows the
53702 same alignment display as -m 0, but the width of the alignment is
53703 increased by 40.  Thus, by default, -m 9 will show the list of best
53704 hits, with percent identity, Smith-Waterman score, and alignment
53705 boundaries initially, and then show alignments standard (-m 0)
53706 alignments with 100 residues/line.
53707 X
53708 >>May 29, 2000
53709 X
53710 Correct some problems with reading data files with <CR>'s under unix.
53711 X
53712 nmgetaa.c/nxgetaa.c/mmgetaa.c have been modified to convert <TAB>
53713 ('\t') to <SPC> (' ') in descriptive lines.
53714 X
53715 =======
53716 X
53717 >>May 3, 2000
53718 X
53719 X  Corrected problem with very low mean_var in fit_llen() in scaleswn.c.
53720 X
53721 >>May 2, 2000
53722 X  (no version number change - previous version not released)
53723 X
53724 X  Merged fasta33t05d2 with fasta33t06.  Also removed restriction on
53725 "-M size-range" to proteins - the size range now can be applied to DNA
53726 as well.
53727 X
53728 >>May 1, 2000
53729 X (changes to v33t05d merged into v33t06) 
53730 X
53731 Introduced changes to include '*' as a valid sequence character, which
53732 indicates termination.  Thus, 'TGA', 'TAG', and 'TAA' are now
53733 tranlated to '*' rather than 'X', and the protein PAM matrices have
53734 been modified to provide a match score of approximately 1/2 the max
53735 identity score for a '*:*' match.  Otherise, '*' is the same as 'X'.
53736 This change only affects query sequences that include a '*' to
53737 indicate an end of sequence, the '*' is not there by default.
53738 X
53739 The inclusion of '*' broke some things in tfasts33, tfastf33, fasty33,
53740 and tfasty33, which were fixed today.
53741 X
53742 >>March 28, 2000/April 24, 2000
53743 X --> v33t06
53744 X
53745 (a) -z 6 statistics that factor in composition
53746 (b) -smatrix-offset pam-offset parameter
53747 X
53748 (a) This release provides a new statistics option, -z 6, which
53749 provides a more sophisticated model that accounts for sequence
53750 composition.  When -z 6 is used (only for fasta33(_t) and
53751 ssearch33(_t)), the program calculates a composition parameter
53752 comp=1/lambda using a modified version of the Karlin-Altschul karlin()
53753 function.  As a result, every sequence in the database has an
53754 associated length (n1) and composition (comp).
53755 X
53756 The length n1 and composition comp are used in the maximum likelihood
53757 estimation described by Mott (1992) Bull. Math. Biol. 54:59-75.  Four
53758 parameters are estimated, a0, a1, a2, and b1, and the probability of
53759 obtaining a score is then:
53760 X
53761 p(s >= x) = 1-exp(-exp(-( a0 + a1*comp + a2*comp*log(n0*n1) + x)/(b1*comp)))
53762 X
53763 The maximum likelihood estimates of a0, a1, a2, and b1 are calculated
53764 using the Nelder-Mead simplex search strategy.
53765 X
53766 The average Lambda is reported for the search using Lambda =
53767 1/(b1*ave_comp).  Where ave_comp is the geometric mean of the comp values
53768 calculated during the statistical estimates.
53769 X
53770 The "lambda/comp" calculation can fail for sequences with very biased
53771 amino acid composition.  When this occurs, 'comp' is set to -1.0 (as
53772 is 'H', the information content parameter) and the 'ave_comp' value is
53773 used to calculate statistical significance.  (But obviously 'ave_comp'
53774 is not really appropriate, since if the sequence had an average 'comp'
53775 value, it would have been calculated.)  When -z 6 is used, the
53776 alignment display shows the 'comp' and 'H' values for that library
53777 sequence.
53778 X
53779 (b) Scoring matrix offsets - The main reason that the "lamdba/comp"
53780 calculation fails is that, for the particular query/library sequence
53781 pair, the expected score is not < 0, instead, Sum {p_ij S_ij} >= 0.0.
53782 This problem is reported to 'stderr' when it occurs.  The simplest
53783 solution to the problem is to provide an offset to the scoring matrix;
53784 for example, to use Blosum62 - 1, which ranges from +10 to -5, rather
53785 than the standard +11 to -4.  This option used to be available with
53786 the -S offset option, but -S is now used to specify a lower-case
53787 seg-ed database.  The offset can now be specified as part of the
53788 scoring matrix name.  Thus, "-s BL62-1" uses Blosum62 reduced by 1 at
53789 each entry.  The '-' character is used to indicate an offset, so
53790 scoring matrix files must not have a '-' in their name.
53791 Alternatively, "-s BL80+1" or "-s BL80--1" would add one to each value.
53792 X
53793 nxgetaa.c, nmgetaa.c, and mmgetaa.c have been edited to avoid string
53794 run-off problems after strncpy().
53795 X
53796 Fixed problem where positive gap extension penalties in ssearch33
53797 were not converted to negative values.
53798 X
53799 >>April 8, 2000
53800 X
53801 Fixed problem in calculating corrected sequence lengths for
53802 Altschul-Gish probabilities.
53803 X
53804 >>March 30, 2000
53805 X  (no version change, date updated to March 30, 2000)
53806 X
53807 Corrected problem with -m 9 option.
53808 X
53809 The '*' character is now available to allow translated alignments to
53810 extend through the termination codon. Thus, if a protein sequence ends
53811 with a '*', and matches in to a translated termination codon, the
53812 score will be increased.  The *:* match score is set to 1/2 the max
53813 positive score for the matrix (see upam.h).  This strategy can also be
53814 used to upweight a match that extends all the way to the end of a
53815 full-length sequence by putting '*' at the end of both the query and
53816 library protein sequences.  Recognition of '*' will probably become a
53817 command line option.
53818 X
53819 >>March 21, 2000
53820 X  (no version change, previous version not distributed)
53821 X
53822 Changes to map_db.c, list_db.c, and mmgetaa.c to accomodate large
53823 sequence files.  Long (64-bit on some systems) variables are now used
53824 to specify file and memory position for the memory mapped functions.
53825 As a result, there are now two *.xin (memory mapped index) file
53826 formats: MP0, which uses 32-bit longs, and MP1, which uses 64-bit
53827 longs. On 64-bit machines, MP0 32-bit indices are read properly, but
53828 limit the database size to 2 or 4 Gb; MP1 64-bit indices allow very
53829 large databases.  Blast2.0 formatdb databases are still limited to
53830 4Gb.  To compile map_db.c to generate 64-bit index files, include the
53831 compile time option -DBIG_LIB64 in the Makefile.  (Currently this
53832 option has been tested only on the DEC Alpha and SGI platforms, and
53833 will work only with Unix versions that provide 64-bit longs and 64-bit
53834 ftell()'s.)
53835 X
53836 The -R results file now uses sfn_cmp() to report a matching
53837 superfamily number, if one exists, and '0' otherwise.
53838 X
53839 >>March 12, 2000
53840 X  (no version change, previous version not distributed)
53841 X
53842 Provide new strategy for specifying library abbreviations.  In
53843 addition to:
53844 X
53845 X       fasta33 query.aa %anr
53846 X
53847 one can also specify:
53848 X
53849 X       fasta33 query.aa %pir1+sp+nr
53850 or
53851 X       fasta33 query.aa +pir1+sp+nr
53852 or 
53853 X       fasta33 query.aa %+pir1+sp+nr
53854 X
53855 where the + anywhere in the library name string indicates that
53856 variable length library names, separated by '+', are being used (the
53857 last '+' is optional).  The FASTLIBS file then becomes:
53858 X
53859 ================
53860 PIR1 Annotated Protein Database (rel 56)$0+pir1+/slib2/blast/pir1.lseg
53861 NBRF Protein database (complete)$0+nbrf+@/seqlib/lib/NBRF.nam
53862 NRL_3d structure database$0D/seqlib/lib/nrl_3d.seq 5
53863 NCBI/Blast non-redundant proteins$0+nr+/slib2/blast/nr.lseg
53864 NCBI/Blast Swissprot$0+sp+/slib2/blast/swissprot.lseg
53865 ================
53866 X
53867 The two abbreviation types, single letter and +word+, cannot be
53868 intermixed, and at least initially, +word+ specifiers are
53869 case-sensitive (single letter abbreviations are not) and will not be
53870 available interactively, only on the command line.
53871 X
53872 Removed 'K' estimate for Expectation_n, Expectation_i fits to the
53873 distribution of unrelated similarity scores.  'K' cannot be calculated
53874 from the data available.  'Lamdba' can be calculated, it is
53875 1.28255/sqrt(mean_var), and is still available.
53876 X
53877 >>March 3, 2000 
53878 X (no version change)
53879 X
53880 changed Makefile33.common, Makefile.common, to incorporate $(NRAND)
53881 rather than "rand48".  Provide nrandom.c which uses random(), as
53882 replacement for nrand.c, which uses rand48().
53883 X
53884 >>February 8, 2000
53885 X  --> v33t05
53886 X
53887 Fixes to scaleswn.c (proc_hist_ml) to set num_db_entries properly.
53888 Scaleswn.c also provides Lambda estimates for -z 1/11 (Expectation_n),
53889 and -z 1/14 (Expectation_i) statistical estimates.
53890 X
53891 Modifications to calc_id() to correct bug in counting identities.
53892 Modified showalign() to use calc_id() with -m 9, for simpler
53893 debugging.
53894 X
53895 Additional modifications to dropfa*.c files to deal properly with 'n's
53896 and 'x's.
53897 X
53898 Added new option: -x #, which allows one to override the penalty for a
53899 match against 'x' (or 'N') provided by the scoring matrix.  This
53900 option is particularly useful in fast[x/y] searches, where out of
53901 frame low complexity regions can generate high scores.
53902 X
53903 The old function of '-x' - to specify an alternate coordinate system,
53904 is now available as '-X # #'.
53905 X
53906 Updated scaleswn.c to provide window shuffle information for -z 12.
53907 X
53908 Updated compacc.c, workacc.c, to fix serious bug in wshuffle()
53909 that destroyed aa1[n1]=0.
53910 X
53911 >>January 25, 2000
53912 X  --> v33t04
53913 X
53914 X  A serious bug in all of the fasta related programs has been
53915 corrected.  The new code in fasta33 which ignores certain residues
53916 failed to initialize one of the arrays properly.  As a result, in
53917 pathological situations, a very strong match could be missed.
53918 X
53919 X  Corrected minor bug in initsw.c that cause misplaced "ktup" command
53920 line argument, which should be ingnored by ssearch, to be read as -d
53921 ktup.
53922 X
53923 X  Improved error message for 0 length query sequence.
53924 X
53925 >>January 17, 2000
53926 X  --> no external version number change
53927 X
53928 Modified mmgetaa.c, map_db.c, and nmgetaa.c to provide memory mapping
53929 of genbank flatfile (format=1) files.  This format could be read much
53930 more efficiently, however.
53931 X
53932 >>January 12, 2000
53933 X  --> no external version number change
53934 X
53935 Changed the behavior of the options that set the number of high scores
53936 (-b) and alignments (-d) that are displayed.  Previously, fasta33 -E
53937 10.0 -d 10 would show 50 best scores, rather than all the scores with
53938 E() < 10.0.  To get the -E threshold to limit, -E 10.0 -b 10000 -d 10
53939 was required. This is now fixed. Setting "-d 10" does not affect the
53940 number of best scores shown.
53941 X
53942 Minor change in mw.h to remove unused defines.
53943 X
53944 fasta3x.me (fasta3x.doc) updated.
53945 X
53946 >>January 6, 2000
53947 X  --> v33t03
53948 X
53949 Corrected bug in memory mapped reads of gcg_binary format files
53950 that potentially caused the last 63 residues to be read improperly.
53951 X
53952 Changes to comp_thr.c, pthr_subs.c, uthr_subs.c, ibm_pthr_subs.c to
53953 ensure that each thread has its own work_info structure. This solves
53954 some minor race conditions that sometimes caused some parameters
53955 not to be reported properly.
53956 X
53957 Changes to most of the drop*.c files to correct some minor problems
53958 with sequence alphabets. Code in mmgetaa.c (memory mapped code for
53959 FASTA, GCG compressed files) reordered to prevent files from being
53960 memory mapped if appropriate index files are not available.
53961 X
53962 See readme.pvm_3.3 for updates to the pvm programs.
53963 X
53964 >>December 10, 1999
53965 X  (no version change - modifications largely affect ps3comp*)
53966 X
53967 Modifications to showsum.c to deal with 2 scores/sequence.  Modifications
53968 to mmgetaa.c for superfamily numbers.
53969 X
53970 >>December 7, 1999
53971 X (no version change, previous version not released)
53972 X
53973 Corrected problem in mmgetaa.c that caused searches on a memory mapped
53974 single long sequence (e.g. Chr22) to fail.  Corrected bug in map_db.c
53975 that caused it to crash on some architectures if a filename was not
53976 specified.  Corrected off-by-three error in fasty/tfasty.  Corrected
53977 indexing error in dropfz2.c.
53978 X
53979 >>December 5, 1999
53980 X --> v33t02 
53981
53982 corrected some bugs in inifa.c/initsw.c/doinit.c that caused
53983 abbreviated function names to be lost.
53984 X
53985 modify showbest.c, showalign.c to include information on position in
53986 library sequence (bbp->cont) to distinguish subsegment of very long
53987 sequences.  Currently, the new label is available only with -m 6.
53988 X
53989 >>November 29, 1999
53990 X [t]fastz33 uses v33t02 of fasty function.
53991 X
53992 Replace dropfz.c with dropfz2.c.  Dropfz2.c interprets any codons,
53993 that include the nucleotide 'N' as the amino 'X'. Previously, 'N' was
53994 treated as 'A', so 'NNN' ended up 'K'.  This modification, together
53995 with the -S option and lower-case pseg'ed databases, should ensure
53996 that DNA queries with large numbers of 'N's do not match low
53997 complexity regions.
53998 X
53999 >>November 20, 1999
54000 X (no version change, previous version not released)
54001 X
54002 Modify initfa.c to disply initn, init1 scores for [t]fast[fs].
54003 Include "-B" option to show previous z-scores.
54004 X
54005 >>November 17, 1999
54006 X (no version change, previous version not released)
54007
54008 Modify dropfx.c to use saatran(), rather than aatran().  saatran
54009 translates any 'N' containing codon as 'X'.  aatran() treats 'N' as
54010 an 'A'.  Although more steps are required for translation, the program
54011 appears to run just as fast.
54012 X
54013 >>November 7, 1999
54014 X --> v33t01
54015 X
54016 Substantial changes to the output format in showbest.c (the list of
54017 high scoring sequences) and showalign.c (the alignments).  The classic
54018 list of best scores:
54019 X
54020 The best scores are:                             initn init1 opt z-sc E(82014)
54021 gi|121716|sp|P10649|GTM1_MOUSE GLUTATHIO  ( 218) 1497 1497 1497 1761.1 2.3e-91
54022 gi|121717|sp|P04905|GTM1_RAT GLUTATHIONE  ( 218) 1413 1413 1413 1662.9 6.7e-86
54023 X
54024 has been replaced by:
54025 X
54026 The best scores are:                                       opt bits E(82138)
54027 gi|121716|sp|P10649|GTM1_MOUSE GLUTATHIONE S-TRAN  ( 218) 1497 354 7.6e-98
54028 gi|121717|sp|P04905|GTM1_RAT GLUTATHIONE S-TRANSF  ( 218) 1413 335 5.3e-92
54029 X
54030 This display provides more information and removes the outdated initn
54031 and init1 scores, which are no longer used. The "bit" score is
54032 comparable to the blast2 bit score.  It is calculated as: (lambda*S -
54033 ln K)/ln 2, where S is the raw similarity score, lambda and K are
54034 statistical parameters estimated from the distribution of unrelated
54035 sequence similarity scores.  All of the similarity scores, including
54036 init1, initn, and z-scores are reported with the alignment data.
54037 Z-scores are displayed instead of bit scores in the list of high
54038 scores if the command line option "-B" is specified.
54039 X
54040 In addition, the alignment score line has changed from:
54041 X
54042 >>gi|2506495|sp|P20136|GTM2_CHICK GLUTATHIONE S-TRANSFER  (220 aa)
54043 X initn: 954 init1: 954 opt: 958 Z-score: 1130.9 expect() 1.1e-56
54044 Smith-Waterman score: 958;  61.927% identity in 218 aa overlap (1-218:1-218)
54045 X
54046 to:
54047 X
54048 >>gi|2506495|sp|P20136|GTM2_CHICK GLUTATHIONE S-TRANSFER  (220 aa)
54049 X initn: 954 init1: 954 opt: 958  Z-score: 1130.9  bits: 216.4 E(): 2.8e-56
54050 Smith-Waterman score: 958;  61.927% identity in 218 aa overlap (1-218:1-218)
54051 X
54052 In addition to the addition of the "bits:" score, the "expect()" label
54053 has changed to "E()" to save some space.
54054 X
54055 >>November 4,12, 1999
54056 (no version change)
54057 X
54058 Fixed serious bug in -z 2 lambda/K calculation in scaleswn.c
54059 X
54060 Fixed bugs in llgetaa.c (openlib()) and definition of superfamily
54061 numbers.
54062 X
54063 >>October 21, 1999
54064 (no version change)
54065 X
54066 Begin using CVS for version control. Correct faulty error message in
54067 dropfs.c.  Corrected bad "goto loopl;" in dropfz.c.  Corrected prss3.rsp
54068 for Makefile.tc (Win32 version).
54069 X
54070 >>October 18, 1999
54071 X --> v33t0
54072 X
54073 Corrected some serious bugs with the various fasta/x/y programs when
54074 the -DALLOCN0 was used to save memory.  Improvements to fasta3x.me/.doc
54075 documentation.
54076 X
54077 >>October 12, 1999
54078 X --> v33tx
54079 X
54080 For this initial release of version 33 of the FASTA programs, the
54081 Makefile's have been modified to make "fasta33(_t)", "fastx33(_t)",
54082 etc, so that you can test fasta33 while retaining fasta3 (from release
54083 v32t08).  The FASTA33 programs are somewhat slower than previous
54084 releases, but I believe the ability to handle low complexity regions
54085 without 'X'ing them out outweighs the slowdown.  By (temporarily)
54086 changing the names of the programs slightly, it will be easier for you
54087 to judge the relative cost and benefit.  To "make" the programs as
54088 "fasta3(_t)", etc, simply replace "Makefile33.common" with
54089 "Makefile.common" in the "Makefile" that you use.
54090 X
54091 >>September 30, 1999
54092 X
54093 ssearch3/fasta3/fastx3/fasty3 have been modified to search databases
54094 containing both upper and lower case letters, where lower case letters
54095 indicate low-complexity regions.  With the modified programs, lower
54096 case letters are treated as 'X's' in the initial scan, but are then
54097 treated normally in the final alignment.  In addition, alignments can
54098 contain lower case letters.  Lower case letters are treated as
54099 low-complexity regions during the seach phase of the program, but as
54100 "conventional" residues during the alignment phase, with the "-S"
54101 option.  Currently, lower case letters are mapped to 'X's during the
54102 scan of the entire library.  In the future, alternate weights will be
54103 available. This is a substantial improvement for very large scale
54104 comparison, where one seeks both accurate statistical estimates and
54105 accurate %identities and alignments, and for translated DNA:protein
54106 comparisons, like "fastx3" and "fasty3", where out-of-frame
54107 translations tend to match low complexity regions (see Pearson et
54108 al. (1997) Genomics 46:24-36).
54109 X
54110 Protein databases (and query sequences) can be generated in the
54111 appropriate format using John Wooton's "pseg" program, available from
54112 ftp://ncbi.nlm.nih.gov/pub/seg/pseg.  Once you have compiled the "pseg"
54113 program, use the command:
54114 X
54115 X       pseg database.fasta -z 1 -q  > database.lc_seg
54116 X
54117 Once you have database.lc_seg, run the command "map_db" to generate
54118 a ".xin" file that can be used to efficiently memory map the database.
54119 X
54120 You can then search database.lc_seg with or without the "-S" option.
54121 Without "-S", the database is treated as any other FASTA format file -
54122 all the residues are present.  With "-S", lower case residues will be
54123 treated as 'x's' during the initial scan but as normal residues when
54124 final alignments are displayed.
54125 X
54126 When the -S option is used, the matrix information line is changed
54127 from: "BL50 matrix (15:-5)" to "BL50 matrix (15:-5)xS".  The "-S"
54128 option is no longer available to provide a scoring matrix offset.
54129 X
54130 Unfortunately, Blast2.0 format files cannot contain lower case
54131 letters.  We have addressed this problem by providing efficient memory
54132 mapped access to Fasta and GCG/PIR, and GCG/compressed-binary files in
54133 the last release of fasta32t08. The memory mapped file I/O
54134 improvements are provided in fasta33 as well.
54135 X
54136 ================ readme.v32 ================
54137 X
54138 FASTX/Y and FASTA (DNA) are now half as fast, because the programs now
54139 search both the forward and reverse strands by default.
54140 X
54141 The documentation in fasta3x.me/fasta3x.doc has been substantially
54142 revised.
54143 X
54144 >>October 20, 1999
54145 (no version change)
54146 X
54147 Modify nxgetaa.c/nmgetaa.c to recognize 'N' as a possible DNA character.
54148 X
54149 >>October 9, 1999
54150 X --> v32t08 (no version number change)
54151 X
54152 Added "-M low-high" option, where low and high are inclusion limits
54153 for library sequences.  If a library sequence is shorter than "low" or
54154 longer than "high", it will not be considered in the search.  Thus,
54155 "-M 200-250" limits the database search to proteins between 200 and
54156 250 residues in length.  This should be particularly useful for fasts3
54157 and fastf3.  -M -500 searches library sequences < 500; -M 200 -
54158 searches sequences > 200.  This limit applies only to protein
54159 sequences.
54160 X
54161 Modified scaleswn.c to fall back to maximum likelihood estimates of
54162 lambda, K rather than mean/variance estimates. (This allows MLE
54163 estimation to be used instead of proc_hist_n when a limited range of
54164 scores is examined.)
54165 X
54166 >>October 2, 1999
54167 X --> v32t08
54168 X
54169 Many changes:
54170 X
54171 (1) memory mapped (mmap()ed) database reading - other database reading fixes
54172 (2) BLAST2 databases supported
54173 (3) true maximum likelihood estimates for Lambda, K
54174 (4) Misc. minor fixes
54175 X
54176 (1) (Sept. 26 - Oct. 2, 1999) Memory mapped database access.
54177 It is now possible to use mmap()ed access to FASTA format databases,
54178 if the "map_db" program has been used to produce an ".xin" file.  If
54179 USE_MMAP is defined at compile time and a ".xin" file is present, the
54180 ".xin" will be used to access sequences directly after the file is
54181 mmap()ed.  On my 4-processor Alpha, this can reduce elapsed time by
54182 50%. It is not quite as efficient as BLAST2 format, but it is close.
54183 X
54184 Currently, memory mapping is supported for type 0 (FASTA), 5
54185 (PIR/GCG ascii), and 6 (GCG binary).  Memory mapping is used if a
54186 ".xin" file is present. ".xin" files are created by the new program
54187 "map_db".  The syntax for "map_db" is:
54188 X
54189 X       map_db [-n] "/dir/database.fa"
54190 X
54191 which creates the file /dir/database.fa.xin.  Library types can be
54192 included in the filename; thus:
54193 X
54194 X       map_db -n "/gcggenbank/gb_om.seq 6"
54195 X
54196 would be used for a type 6 GCG binary file. 
54197 X
54198 The ".xin" file must be updated each time the database file changes.
54199 map_db writes the size of the database file into the ".xin" file, so
54200 that if the database file changes, making the ".xin" offset
54201 information invalid, the ".xin" file is not used. "list_db" is
54202 provided to print out the offset information in the ".xin" file.
54203 X
54204 (Oct 2, 1999) The memory mapping routines have been changed to
54205 allow several files to be memory mapped simultaneously. Indeed, once a
54206 database has been memory mapped, it will not be unmap()ed until the
54207 program finishes.  This fixes a problem under Digital Unix, and should
54208 make re-access to mmap()ed files (as when displaying high scores and
54209 alignments) much more efficient.  If no more memory is available for
54210 mmap()ing, the file will be read using conventional fread/fgets.
54211 X
54212 (Oct 2, 1999) The names of the database reading functions has been
54213 changed to allow both Blast1.4 and Blast2.0 databases to be read.  In
54214 addition, Makefile.common now includes an option to link both
54215 ncbl_lib.o and ncbl2_lib.o, which provides support for both libraries.
54216 However, Blast1.4 support has not been tested.
54217 X
54218 The Makefile structure has been improved.  Each architecture specific
54219 Makefile (Makefile.alpha, Makefile.linux, etc) now includes
54220 Makefile.common.  Thus, changes to the program structure should be
54221 correct for all platforms.  "map_db" and "list_db" are not made with
54222 "make all".
54223 X
54224 The database reading functions in nxgetaa.c can now return a database
54225 length of 0, which indicates that no residues were read.  Previously,
54226 0-length sequences returned a length of 1, which were ignored.
54227 Complib.c and comp_thr.c have changed to accommodate this
54228 modification.  This change was made to ensure that each residue,
54229 including the last, of each sequence is read.
54230 X
54231 Corrected bug in nxgetaa.c with FASTA format files with very long
54232 (>512 char) definition lines.
54233 X
54234 (2) (September 20, 1999) BLAST2 format databases supported
54235 X
54236 This release supports NCBI Blast2.0 format databases, using either
54237 conventional file reading or memory mapped files.  The Blast2.0 format
54238 can be read very efficiently, so there is only a modest improvement in
54239 performance with memory mapping.  The decision to use mmap()'ed files
54240 is made at compile time, by defining USE_MMAP.  My thanks to Eamonn
54241 O'Toole of DEC/Compaq, and Daryl Madura of Sun Microsystems, for
54242 providing mmap()'ed modifications to fasta3.  On my machines, Blast2.0
54243 format reduces search time by about 30%.  At the moment, ambiguous DNA
54244 sequences are not decoded properly.
54245 X
54246 (3) (September 30, 1999) A new statistical estimation option is
54247 available.  -z 2 has been changed from ln()-scaling, which never
54248 should have been used, to scaling using Maximum Likelihood Estimates
54249 (MLEs) of Lambda and K.  The MLE estimation routines were written by
54250 Aaron Mackey, based on a discussion of MLE estimates of Lambda and K
54251 written by Sean Eddy.  The MLE estimation examines the middle 95% of
54252 scores, if there are fewer than 10000 sequences in the database;
54253 otherwise it excludes (censors) the top 250 scores and the bottom 250
54254 scores.  This approach seems to effectively prevent related sequences
54255 from contaminating the estimation process.  As with -z 1, -z 12 causes
54256 the program to generate a shuffled sequence score for each of the
54257 library sequences; in this case, no censoring is done.  If the
54258 estimation process is reliable, Lambda and K should not vary much with
54259 different queries or query lengths.  Lambda appears not to vary much
54260 with the comparison algorithm, although K does.
54261 X
54262 (4) Minor changes include fixes to some of the alignment display routines,
54263 individual copies of the pstruct structure for each thread, and some
54264 changes to ensure that every last residue in a library is available
54265 for matching (sometime the last residue could be ignored).  This
54266 version has undergone extensive testing with high-throughput sequences
54267 to confirm that long sequences are read properly.  Problems with
54268 fastf3/fasts3 alignment display have also been addressed.
54269 X
54270 >>August 26, 1999 (no version change - not released)
54271 X
54272 Corrected problem in "apam.c" that prevented scoring matrices from
54273 being imported for [t]fasts3/[t]fastf3.
54274 X
54275 >>August 17, 1999
54276 X --> v32t07
54277 X
54278 Corrected problem with opt_cut initialization that only appeared
54279 with pvcomp* programs.
54280 X
54281 Improved calculation of FASTA optcut threshold for DNA sequence
54282 comparison for match scores much less than +5 (e.g. +3).  The previous
54283 optcut theshold was too high when the match penalty was < 4 and
54284 ktup=6; it is now scaled more appropriately.
54285 X
54286 Optcut thresholds have also been raised slightly for
54287 fastx/y3/tfastx/y3.  This should improve performance with minimal
54288 effects on sensitivity.
54289 X
54290 >>July 29, 1999
54291 (no version change - date change)
54292 X
54293 Corrected various uninitialized variables and buffer overruns
54294 detected.
54295 X
54296 >>July 26, 1999 - new distribution
54297 (no version change - v32t06, previous version not released)
54298 X
54299 Changed the location of "(reverse complement)" label in tfasta/x/y/s/f
54300 programs.
54301 X
54302 Statistical calculations for tfasta/x/y in unthreaded version
54303 corrected.  Statistical estimates for threaded and unthreaded versions
54304 of the tfasta/x/y/s/f programs should be much more consistent.
54305 X
54306 Substantial modifications in alignment coordinate calculation/
54307 presentation.  Minor error in fastx/y/tfastx/y end of alignment
54308 corrected.  Major problems with tfasta alignment coordinates
54309 corrected.  tfasta and tfastx/y coordinates should now be consistent.
54310 X
54311 Corrected problem with -N 5000 in tfasta/x/y3(_t) searches encountered
54312 with long query sequences.
54313 X
54314 Updated pthr_subs.c/Makefile.linux to increase the pthreads stacksize
54315 to try to avoid "cannot allocate diagonal arrays" error message.
54316 Pthreads stacksize can be changed with RedHat 6.0, but not RedHat 5.2,
54317 so Makefile.linux uses -DLINUX5 for RedHat5.* (no pthreads stack size).
54318 I am still getting this message, so it has not been completely
54319 successful.  Makefile.linux now uses -DALLOCN0 to avoid this problem,
54320 at some cost in speed.
54321 X
54322 The pvcomp* programs have been updated to work properly with
54323 forward/reverse DNA searches.  See readme.pvm_3.2.
54324 X
54325 >>July 7, 1999 - not released
54326 X --> v32t06
54327 X
54328 Corrected bug in complib.c (fasta3, fastx3, etc) that caused core
54329 dumps with "-o" option.
54330 X
54331 Corrected a subtle bug in fastx/y/tfastx/y alignment display.
54332 X
54333 >>June 30, 1999 - new distribution
54334 (no version change)
54335 X
54336 Corrected doinit.c to allow DNA substitution matrices with -s matrix
54337 option.
54338 X
54339 Changed ".gbl" files to ".h" files.
54340 X
54341 >>June 2 - 9, 1999 - new distribution
54342 (no version change)
54343 X
54344 Added additional DNA lambda/K/H to alt_param.h.  Corrected some
54345 other problems with those table. for the case where (inf,inf)
54346 gap penalties were not included.
54347 X
54348 Fixed complib.c/comp_thr.c error message to properly report filename
54349 when library file is not found.
54350 X
54351 Included approximate Lambda/K/H for BL80 in alt_parms.h.
54352 BL80 scoring matrix changed from 1/3 bit to 1/2 bit units.
54353 X
54354 Included some additional perl files for searchfa.cgi, searchnn.cgi
54355 in the distribution (my-cgi.pl, cgi-lib.pl).
54356 X
54357 >>May 30, 1999, June 2, 1999 - new distribution
54358 (no version number change)
54359 X
54360 Added Makefile.NetBSD, if !defined(__NetBSD__) for values.h.  Changed
54361 zs_to_E() and z_to_E() in scaleswn.c to correctly calculate E() value
54362 when only one sequence is compared and -z 3 is used.
54363 X
54364 >>May 27, 1999
54365 (no version number change)
54366 X
54367 Corrected bug in alignment numbering on the % identity line
54368 X       27.4% identity in 234 aa (101-234:110-243)
54369 for reverse complements with offset coordinates (test.aa:101-250)
54370 X
54371 >>May 23, 1999
54372 (no version number change)
54373 X
54374 Correction to Makefile.linux (tgetaa.o : failed to -DTFAST). 
54375 X
54376 >>May 19, 1999
54377 (no version number change)
54378 X
54379 Minor changes to pvm_showalign.c to allow #define FIRSTNODE 1.
54380 Changes to showsum.c to change off-end reporting.  (Neither of these
54381 changes is likely to affect anyone outside my research group.)
54382 X
54383 >>May 12, 1999
54384 X --> v32t05
54385 X
54386 Fixed a serious bug in the fastx3/tfastx3 alignment display which
54387 caused t/fastx3 to produce incorrect alignments (and incorrectly low
54388 percent identities).  The scores were correct, but the alignment
54389 percent identities were too low and the alignments were wrong.
54390 X
54391 Numbering errors were also corrected in fastx3/tfastx3 and
54392 fasty3/tfasty3 and when partial query sequences were used.
54393 X
54394 >>May 7, 1999
54395 X
54396 Fixed a subtle bug in dropgsw.c that caused do_work() to calculate
54397 incorrect Smith-Waterman scores after do_walign() had been called.
54398 This affected only pvcompsw searches with the "-m 9" option.
54399 X
54400 >>May 5, 1999
54401 X
54402 Modified showalign.c to provide improved alignment information that
54403 includes explicitly the boundaries of the alignment.  Default
54404 alignments now say:
54405 X
54406 Smith-Waterman score: 175;  24.645% identity in 211 aa overlap (5:207-7:207)
54407 X
54408 >>May 3, 1999
54409 X
54410 Modified nxgetaa.c, showsum.c, showbest.c, manshowun.c to allow a
54411 "not" superfamily annotation for the query sequence only.  The
54412 goal is to be able to specify that certain superfamily numbers be
54413 ignored in some of the search summaries.  Thus, a description line
54414 of the form:
54415 X
54416 >GT8.7 | 40001 ! 90043 | transl. of pa875.con, 19 to 675
54417 X
54418 says that GT8.7 belongs to superfamily 40001, but any library
54419 sequences with superfamily number 90043 should be ignored in any
54420 listing or summary of best scores.
54421 X
54422 In addition, it is now possible to make a fasta3r/prcompfa, which is
54423 the converse of fasta3u/pucompfa. fasta3u reports the highest scoring
54424 unrelated sequences in a search using the superfamily annotation.
54425 fasta3r shows only the scores of related sequences.  This might be
54426 used in combination with the -F e_val option to show the scores
54427 obtained by the most distantly related members of a family.
54428 X
54429 >>April 25, 1999
54430 X
54431 X -->v32t04 (not distributed)
54432 X
54433 Modified nxgetaa.c to remove the dependence of tgetaa.o on TFASTA
54434 (necessary for a more rational Makefile structure).  No code changes.
54435 X
54436 >>April 19, 1999
54437 X
54438 Fixed a bug in showalign.c that displayed incorrect alignment coordinates.
54439 (no version number change).
54440 X
54441 >>April 17, 1999
54442 X
54443 X --> v32t03
54444 X
54445 A serious bug in DNA alignments when the sequence has been broken into
54446 multiple segments that was introduced in version fasta32 has been
54447 fixed.  In addition, several minor problems with -z 3 statistics on
54448 DNA sequences were fixed.
54449 X
54450 Added -m 9 option, which unfortunately does different things in
54451 pvcompfa/sw and fasta3/ssearch3.  In both programs, -m 9 provides the
54452 id's of the two sequences, length, E(), %_ident, and start and end of
54453 the alignment in both sequences.  pvcompfa/sw provides this
54454 information with the list of high scoring sequences.  fasta3/ssearch3
54455 provides the information in lieu of an alignment.
54456 X
54457 >>March 18, 1999
54458 X
54459 X --> v32t02
54460 X
54461 Added information on the algorithm/parameter description line to
54462 report the range of the pam matrices.  Useful for matrices like
54463 MD_10, _20, and _40 which require much higher gap penalties.
54464 X
54465 >>March 13, 1999 (not distributed)
54466 X
54467 X --> v32t01 
54468 X
54469 X -r results.file  has been changed to -R results.file to accomodate
54470 X DNA match/mismatch penalties of the form: -r "+1/-3".
54471 X
54472 >>February 10, 1999
54473 X
54474 Modify functions in scalesw*.c to prevent underflow after exp() on
54475 Alpha Linux machines.  The Alpha/LINUX gcc compiler is buggy and
54476 doesn't behave properly with "denormalized" numbers, so "gcc -g -m
54477 ieee" is recommended.
54478 X
54479 Add "Display alignments also (y/n)[n] "
54480 X
54481 pvcomplib.c again provides alignments!!  In addition, there is a
54482 new "-m 9" option, which reports alignments as:
54483 X
54484 >>>/home/wrp/slib/hlibs/hum0.aa#5>HS5 gi:1280326 T-cell receptor beta chain 30 aa, 30 aa vs /home/wrp/slib/hlibs/hum0.seg library
54485 HS5               30    HS5               30    1.873e-11       1.000     30       1      30       1      30
54486 HS5               30    HS2249            40    1.061e-07       0.774     31       1      30       7      37
54487 HS5               30    HS2221            38    1.207e-07       0.833     30       1      30       7      35
54488 HS5               30    HS2283            40    1.455e-07       0.774     31       1      30       7      37
54489 HS5               30    HS2239            38    1.939e-07       0.800     30       1      30       7      35
54490 X
54491 where the columns are:
54492 X
54493 query-name      q-len   lib-name      lib-len   E()             %id    align-len  q-start q-end   l-start l-end
54494 X
54495 >>February 9, 1999
54496 X
54497 Corrected bug in showalign.c that offset reverse complement alignments
54498 by one.
54499 X
54500 >>Febrary 2, 1999
54501 X
54502 Changed the formatting slightly in showbest.c to have columns line up better.
54503 X
54504 >>January 11, 1999
54505 X
54506 Corrected some bugs introduced into fastf3(_t) in the previous version.
54507 X
54508 >>December 28, 1998
54509 X
54510 Corrected various problems in dropfz.c affecting alignment scores
54511 and coordinates.
54512 X
54513 Introduced a new program, fasts3(_t), for searching with peptide
54514 sequences.
54515 X
54516 >>November 11, 1998
54517 X
54518 X  --> v32t0
54519 X
54520 Added code to correct problems with coordinate number in long library
54521 sequences with tfastx/tfasty.  With this release, sequences should be
54522 numbered properly, and sequence numbers count down with reverse
54523 complement library sequences.
54524 X
54525 In addition, with this release, fastx/y and tfastx/y translated
54526 protein alignments are numbered as nucleotides (increasing by 3,
54527 labels every 30 nucleotides) rather than codons.
54528 X
54529 SHAR_EOF
54530 chmod 0644 readme.v33t0 ||
54531 echo 'restore of readme.v33t0 failed'
54532 Wc_c="`wc -c < 'readme.v33t0'`"
54533 test 50697 -eq "$Wc_c" ||
54534         echo 'readme.v33t0: original size 50697, current size' "$Wc_c"
54535 fi
54536 # ============= readme.v34t0 ==============
54537 if test -f 'readme.v34t0' -a X"$1" != X"-c"; then
54538         echo 'x - skipping readme.v34t0 (File already exists)'
54539 else
54540 echo 'x - extracting readme.v34t0 (Text)'
54541 sed 's/^X//' << 'SHAR_EOF' > 'readme.v34t0' &&
54542 X
54543 X $Name: fa_34_26_5 $ - $Id: readme.v34t0,v 1.167 2007/04/26 18:42:43 wrp Exp $
54544 X
54545 >>April 26, 2007
54546 X
54547 Modify scaleswn.c to prevent mle_cen() from hanging when it fails to
54548 converge.  Also, free() more arrays in work_thr.c; initialize
54549 m_msg.hist.entries=0 in comp_lib.c, and various clean-ups for a_res
54550 encoded alignments.
54551 X
54552 >>March 22, 2007
54553 X
54554 Update faatran.c genetic codes (and documentation on -t option).  Update
54555 ncbl2_mlib.c to parse non-NCBI format 12 databases better.
54556 X
54557 >>March 21, 2007        fasta-34_26_2
54558 X
54559 Fix conflict between "-S" "-s matrix.file".
54560 X
54561 >>February 26, 2007     fasta-34_26_2
54562 X
54563 Fix problem with dropfs2.c (curv.start = lpos before initialized).
54564 X
54565 >>January 12, 2007
54566 X
54567 Fix a problem with pssm_asn_subs.c reading strings (sequences) longer
54568 than 1024 bytes.
54569 X
54570 Remove searchfa.cgi, searchnn.cgi, cgi-lib.pl, my-cgi.pl - this code
54571 was used for an ancient FASTA WWW implementation and has been replaced
54572 by the FASTA_WWW package.
54573 X
54574 FASTA Version numbers are being modified to make releases easier to
54575 track, thus fa34t26b5 has become fasta-34_26_1.  I would prefer to use
54576 decimal versions, but CVS does not allow '.' in tags.
54577 X
54578 >>January 4, 2007       fasta-34_26_1
54579 X
54580 Include scripts for building Mac OS X Universal binaries on a PPC
54581 machine.  Programs are compiled first with Makefile.os_x (gcc-3.3 for
54582 PPC) and then installed into ./ppc/.  Programs are next compiled with
54583 Makefile.os_x86 for i386, and the resulting executables installed into
54584 ./i386/.  Finally, the "make_osx_univ.sh" script is run to build the
54585 universal binaries from the two executables using "lipo".
54586 X
54587 >>December 12, 2006
54588 X
54589 Fix some problems with p2_workcomp.c: (1) no longer initialize pad
54590 characters for non-existant sequences. (2) deal with small libraries
54591 consistently with the serial versions.
54592 X
54593 >>November 17, 2006     fa34t26b5
54594 X
54595 Fixed a problem reading ASN.1 format 2 PSSM's.  It is now possible to
54596 download a PSI-BLAST PSSM RID and search properly.  Next, the query
54597 sequence from the PSSM should be used instead of the provided query
54598 sequence, so that the query sequence is ignored.
54599 X
54600 >>October 19, 2006      fa34t26b4
54601 X
54602 Fixed problem with SSE2 code when PSSM's are used.
54603 X
54604 >>October 6, 2006       fa34t26b3
54605 X
54606 A new set of WIN32 programs is now available that use the Intel C++
54607 9.1 compiler, rather than the much older Borland Turbo-C compiler. All
54608 of the unthreaded programs that are part of the Unix and MacOSX FASTA
54609 distributions are now available.  Threaded (multiprocessor) versions
54610 of the program as available as well, as are sse2 accelerated versions
54611 of ssearch34 (ssearch34sse2.exe, ssearch34sse2_t.exe).
54612 X
54613 Th new WIN32 code also uses Microsoft's "nmake" program to build the
54614 programs, which allows much greater consistency between the Unix and
54615 Windows versions.
54616 X
54617 X
54618 >>September 18, 2006
54619 X
54620 Static global alignment variables removed from dropnfa.c, dropfx.c,
54621 dropfz2.c.  dropnfa.c, dropfx.c and dropfz2.c should be thread safe.
54622 Together with the earlier changes, all the FASTA functions should now
54623 be thread safe during the alignment process.
54624 X
54625 >>August 17, 2006
54626 X
54627 Begin removal of static variables from Smith-Waterman alignment
54628 functions.  These variables kept the functions from being thread-safe.
54629 Now dropgsw.c and dropnsw.c are thread-safe.
54630 X
54631 >>August 15, 2006       fa34t26b2
54632 X
54633 Fixed a problem with pv34compfx/mp34compfx (and fy) producing
54634 improperly labeled alignments and de-allocating memory for the reverse
54635 complement.
54636 X
54637 >>July 18, 2006
54638 X
54639 The library file name parsing programs now provide the option for
54640 environment variable substitions.  For example, SLIB2=/slib2 as an
54641 environment variable (e.g. export SLIB2=/slib2 for ksh and bash), then
54642 X
54643 X       fasta34 -q query.aa '${SLIB2}/swissprot.fa'  expands as expected.
54644 X
54645 While this is not important for command lines, where the Unix shell
54646 would expand things anyway, it is very helpful for various
54647 configuration files, such as files of file names, where:
54648 X
54649 X       <${SLIB2}/blast
54650 X       swissprot.fa
54651 X
54652 now expands properly, and in FASTLIBS files the line:
54653 X
54654 X       NCBI/Blast Swissprot$0S${SLIB2}/blast/swissprot.fa
54655 X
54656 expands properly.  Currently, Environment variable expansion only
54657 takes place for library file names, and the <directory in a file of
54658 file names.
54659 X
54660 >>July 14, 2006   fa34t26b1
54661 X
54662 Updated Farrar smith_waterman_sse2.c code to address possible bug
54663 (code from Michael Farrar).  Include <sunmedia_intrin.h> for
54664 compilation with Sun compiler with Makefile.sun_x86.
54665 X
54666 >>July 2, 2006    fa34t26b0
54667 X
54668 This release provides an extremely efficient SSE2 implementation of
54669 the Smith-Waterman algorithm for the SSE2 vector instructions written
54670 by Michael Farrar (farrar.michael@gmail.com).  The SSE code speeds up
54671 Smith-Waterman 8 - 10-fold in my tests, making it comparable to Eric
54672 Lindahl's Altivec code for the Apple/IBM G4/G5 architecture.
54673 X
54674 The Farrar code is largely confined to smith_waterman_sse2.c and
54675 smith_waterman_sse2.h, which are copyright (2006) by Michael Farrar,
54676 and cannot be redistributed without his permission.  Mr. Farrar has
54677 agreed to provide his code under the same policy used by FASTA -
54678 e.g. the code can be used without permission, but not redistributed.
54679 X
54680 The Farrar code uses GCC version 4.0 SSE2 intrinsic functions to avoid
54681 assembly language code.  Unfortunately, in my hands, "gcc -O3" causes
54682 "out of memory" errors, and other problems, so "gcc -O" is used instead.
54683 X
54684 >>June 23, 2006   fa34t25d10
54685 X
54686 Modifications to comp_lib.c, compacc.c, and other files to ensure that
54687 function-specific MAXTOT values are used properly.  MAXTOT is now
54688 available as m_msg.max_tot, which is set in initfa.c (m_msg.max_tot =
54689 MAXTOT) to ensure that functions that need very large MAXTOT values
54690 (e.g. TFASTX) can get them.  tfastx can now search successfully with
54691 titin, a 27,000 residue protein.
54692 X
54693 Other changes have been made to accomodate long query sequences.
54694 X
54695 A serious bug was found in fastx34(_t) that caused alignment
54696 coordinates to be calculated improperly when the DNA sequence was much
54697 longer than the protein sequence.
54698 X
54699 >>May 31, 2006  fa34t25d9
54700 X
54701 Fixed some problems with fasts/fastf alignments when -m 9 options were
54702 used.  Unlike the other algorithms, the a_res structure does not
54703 capture all the information to re-produce an alignment, so do_walign
54704 now sets bptr->have_ares to indicate whether the a_res structure is
54705 valid.
54706 X
54707 Various problems with bad library names, and short query titles were
54708 also fixed.
54709 X
54710 Updated version number/date on all drop*.c functions.
54711 X
54712 >>May 24, 2006  fa34t25d8
54713 X
54714 Revised code for NCBI *.pal/*.nal databases has been tested on all
54715 architectures, including Windows.
54716 X
54717 In addition, support for ASN.1 PSSM:2 files provided by the NCBI
54718 PSI-BLAST WWW site is included.  This code will not work with
54719 iteration 0 PSSM's (which have no PSSM information).  For ASN.1
54720 PSSM's, which provide the matrix name (and in some cases the gap
54721 penalties), the scoring matrix and gap penalties are set appropriately
54722 if they were not specified on the command line. ASN.1 PSSM's are type 2:
54723 X       ssearch34 -P "pssm.asn1 2" .....
54724 X
54725 >>May 18, 2006
54726 X
54727 Support for NCBI Blast formatdb databases has been expanded.  The
54728 FASTA programs can now read some NCBI *.pal and *.nal files, which are
54729 used to specify subsets of databases.  Specifically, the
54730 swissprot.00.pal and pdbaa.00.pal files are supported.  FASTA supports
54731 files that refer to *.msk files (i.e. swissprot.00.pal refers to
54732 swissprot.00.msk); it does not currently support .pal files that
54733 simply list other .pal or database files (e.g. FASTA does not support
54734 nr.pal or swissprot.pal).
54735 X
54736 In the process of providing this support, the routines used to read
54737 ASN.1 binary formatdb files were substantially improved.  It is now
54738 possible to see multiple description lines for a single sequence.
54739 X
54740 IS_BIG_ENDIAN has been removed from all of the Makefiles.  The code
54741 now looks for the definition of __BIG_ENDIAN__ or _BIG_ENDIAN to
54742 decide whether the architecture IS_BIG_ENDIAN.  If, for some reason,
54743 one of these macros is not defined on a BIG_ENDIAN architecture, then
54744 -DIS_BIG_ENDIAN is required.
54745 X
54746 >>May 12, 2006  CVS fa34t25d7
54747 X
54748 Corrected serious problem with coordinate display calculation for
54749 fasta34 and ssearch34 - in some cases the coordinates and alignment
54750 symbols were off by the length of the context (typically 30 residues).
54751 X
54752 Added capability to read ASN.1 binary PSSM information.  This
54753 information is provided (in an encoded form) from the NCBI PSI-BLAST
54754 WWW site.  (What is actually provided from the WWW site is a bzip2-ed
54755 binary file that is converted to ASCII HEX.  The ASCII HEX file must
54756 be converted to binary, and then bunzip'ed. This bunzip-ed file is
54757 binary ASN.1.)  These files can also be generated by 
54758 X
54759 X blastpgp -J T -C pssm.asn1_bin -u 2
54760 X
54761 I am parsing the ASN.1 binary manually, not using the NCBI toolkit, so
54762 there may be some files that are not parsed properly - if so, let me
54763 know.
54764 X
54765 (May 12, 2006 - The NCBI changed the format of the psi-blast ASN.1
54766 PSSM - and has not yet provided documentation of the new structure, so
54767 this code does not work. It does work with blastpgp v 2.2.13, but not
54768 with the web site version 2.2.14.  A fix was provided 24-May-2006)
54769 X
54770 >>April 18, 2006
54771 X
54772 Small modification in mshowbest.c to provide more consistent display
54773 widths with -m 9i in list of best hits.
54774 X
54775 >>April 11, 2006 CVS fa34t25d6
54776 X
54777 Corrected a problem introduced with the new, more efficient method for
54778 displaying alignments.  For the tfast* programs, which must translate
54779 the library sequence, translations were not done when alignments were
54780 re-displayed.
54781 X
54782 Corrected an older problem with tfastx34 against very long sequence
54783 databases - the code to more efficiently do the display alignment did
54784 not use the correct sequence coordinates.
54785 X
54786 Modifications to dropfs2.c to ensure that exact peptide matches are
54787 captured more frequently.
54788 X
54789 >>March 16, 2006 CVS fa34t25d5
54790 X
54791 Change to initfa.c to allow lower case DNA libraries using the
54792 -DDNALIB_LC compile time option.
54793 X
54794 Modify p2_complib.c, p2_worklib.c (and doinit.c, msg.h) to allow the
54795 -V annotation option for the parallel programs.  Also modify to allow
54796 specification of the query range (but only for the first query, like
54797 fasta34) for the parallel programs.
54798 X
54799 Modification of p2_workcomp.c to correct some problems presenting
54800 percent similarity.  Also correct unreleased bugs in the alignment
54801 routines that allow more efficient alignment re-calculation.
54802 X
54803 >>Nov 20, 2005
54804 X
54805 Changes to support asymmetric matrices - a scoring matrix read in from
54806 a file can be asymmetric.  Default matrices are all symmetric.
54807 X
54808 >>Oct 24, 2005
54809 X
54810 Modifications extended to p2_complib.c/p2_workcomp.c.  Incorporation
54811 of drop_func.h into p2_workcomp.c greatly simplifies things.  No
54812 changes in communication - struct a_res_str is internal to
54813 p2_workcomp.c.
54814 X
54815 Additional changes to do_walign() so that aln_func_vals() must be
54816 called to set llfact, qlfact, etc in a_struct aln before or after
54817 do_walign is called.  do_walign produces a_res_str a_res, which has
54818 all the information necessary to produce a calcons() or calc_code()
54819 alignment.
54820 X
54821 >>Oct 19, 2005 CVS fa34t26b0
54822 X
54823 Modifications to drop*.c and c_dispn.c to separate (and simplify) some
54824 of the alignment coordinate calculations.  Before, the "a_struct" had
54825 the coordinates of the alignment used in the display (seqc0, seqc1)
54826 AND in the original sequences (aa0, aa1), as well as other information
54827 used to calculate alignment coordinates.  In the new version, astruct
54828 coordinates always refer to seqc0,1, while a new structure, a_res_str,
54829 has coordinates for aa0, aa1 as well as the alignment encoding in res[nres].
54830 Eventually, this should make it possible to display multiple local
54831 alignments from the same two sequences.
54832 X
54833 In addition, the file "drop_func.h" has been added to the project, and
54834 is included by many of the files (all the drop*.c functions,
54835 mshowbest.c, mshowalign.c) to ensure that the various functions are
54836 declared and used consistently.
54837 X
54838 >>Sept 19, 2005 CVS fa34t25d4
54839 X
54840 Changes to support Mac OS 10.4 - Tiger (include sys/types.h in more
54841 files).  Documentation update for prss34/prfx34. Modifications to
54842 comp_lib.c to support prss34_t/prfx34_t.  Shuffle numbers for
54843 prss/prfx can now be specified by "-k #".
54844 X
54845 >>Sept 2, 2005
54846 X
54847 The prss34 program has been modified to use the same display routines
54848 as the other search programs.  To be more consistent with the other
54849 programs, the old "-w shuffle-window-size" is now "-v window-size".
54850 X
54851 prss34/prfx34 will also show the optimal alignment for which the
54852 significance is calculated by using the "-A" option. 
54853 X
54854 Since the new program reports results exactly like other
54855 fasta/ssearch/fastxy34 programs, parsing for statistical significance
54856 is considerably different.  The old format program can be make using
54857 "make prss34o".
54858 X
54859 >>Aug 26, 2005
54860 X
54861 Modifications to save_best() in comp_lib.c to support prss34_t.  It
54862 did not work before.
54863 X
54864 >>July 25, 2005
54865 X
54866 Modify mshowbest.c to suppress gi|12345 in HTML mode.
54867 X
54868 >>July 18, 2005 CVS fa34t25d3
54869 X
54870 Modifications to Makefile.tc to support NCBI formatdb formats under
54871 Windows.
54872 X
54873 >>May 19, 2005  CVS fa34t25d2
54874 X
54875 Modifications to dropfs2.c to fix an obscure bug that occurred when
54876 correctly ordered peptides aligned one residue apart.
54877 X
54878 >>May 5, 2005 CVS fa34t25d1
54879 X
54880 Modification to the -x option, so that both an "X:X" match score and
54881 an "X:not-X" mismatch score can be specified. (This score is also used
54882 X
54883 give a positive score to a "*:*" match - the end of a reading frame,
54884 while giving a negative score to "*:not-*".
54885 X
54886 >>March 14, 2005  CVS fa34t25b4
54887 X
54888 Fixed some problems caused by padding characters required for
54889 Smith-Waterman ALTIVEC in the parallel (p2_complib.c, p2_workcomp.c)
54890 versions.
54891 X
54892 >>Feb 24, 2005  CVS fa34t25b3
54893 X
54894 Changes to comp_lib.c (and Makefile.pcom) to support prss34_t.
54895 X
54896 >>Feb 12, 2005
54897 X
54898 Modify dropfs.c to dynamically allocate space for alignments, so that
54899 queries with a large number of fragments can still place all the
54900 fragments on the alignment.  Also fix a problem produced by removing
54901 -DBIGMEM from most of the Makefile's, but not fixing defs.h to use
54902 BIGMEM sizes by default.
54903 X
54904 >>Jan 24, 2005
54905 X
54906 Include a new program, "print_pssm", which reads a blastpgp binary
54907 checkpoint file and writes out the frequency values as text.  These
54908 values can be used with a new option with ssearch34(_t) and prss34,
54909 which provides the ability to read a text PSSM file.  To specify a
54910 text PSSM, use the option -P "query.ckpt 1" where the "1" indicates a
54911 text, rather than a binary checkpoint file.  "initfa.c" has also been
54912 modified to work with PSSM files with zero's in the in the frequency
54913 table.  Presumably these positions (at the ends) do not provide
54914 information. (Jan 26, 2005) blastpgp actually uses BLOSUM62 values
54915 when zero frequencies are provided, so read_pssm() has been modified
54916 to use scoring matrix values for zero frequencies as well.
54917 X
54918 >>Jan 13, 2005
54919 X
54920 Change to initfa.c to have fasts34 do a protein comparison by default,
54921 rather than an unknown sequence type.  Automatic checking for fasts34
54922 does not work reliably, because queries can be very short.  Likewise
54923 for fastm34.  [Jan 26, 2004] Undo this change, which broke DNA
54924 comparison when "-n" was specified.
54925 X
54926 >>Jan 7, 2005
54927 X
54928 Changes to tatstats.h, dropfs2.c to allow larger numbers of peptides
54929 to match when fasts is used to show coverage on a proteomics
54930 experiment.  Previously fasts could match no more than 30 peptides,
54931 that has been increased to 50.  In addition, ktup=2 can be used
54932 to increase the likelihood that short exact matchs trump longer
54933 mismatched regions.  
54934 X
54935 >>Nov 11, 2004     CVS fa34t25
54936 X
54937 Finished merge of earlier fa34t24 branch with HEAD.  Correct
54938 labeling of TFASTM.
54939 X
54940 >>Nov 4-8, 2004    
54941 X
54942 Incorporation of Erik Lindahl "anti-diagonal" Altivec code for
54943 Smith-Waterman, only.  Altivec SSEARCH is now faster than FASTA for
54944 query sequences < 250 amino acids.
54945 X
54946 Small modifications to output score display to ensure that the correct
54947 scores are shown, and that they are correctly labeled.
54948 X
54949 >>Aug 25,26, 2004  CVS fa34t24b3
54950 X
54951 Small change in output format for p34comp* programs in
54952 ">>>query_file#1 string" line before alignments.  This line is not present
54953 in the non-parallel versions - it would be better for them to be consistent.
54954 X
54955 Change in last_stats.c to properly label fasts statistics with -z != 1.
54956 X
54957 Change in dropfs2.c to ensure that tatprobs are not precalculated with -z 4.
54958 X
54959 Modify -m 9i output option to show in HTML output.
54960 X
54961 Add "#ifdef NOOVERHANG" to dropfs2.c that causes overlapping
54962 alignments to score a 0, rather than the partial overlap score.
54963 Useful for SAGE alignments, because "fasts" requires global alignments
54964 (except for for overhangs, unless NOOVERHANG is defined).
54965 X
54966 >>Aug 23, 2004
54967 X
54968 Fix problem with very long definition lines with formatdb version4
54969 ASN databases.  Fix mshowalign.c to re-enable "-L" option.
54970 X
54971 >>July 28, 2004 
54972 X
54973 Fix to re-enable -w window shuffle for PRSS.  Modify comp_lib.c
54974 for PRSS to ensure that the unshuffled score and probability
54975 are shown, even for very high probabililty alignments.
54976 X
54977 >>July 21, 2004
54978 X
54979 Modifications to support PostgreSQL databases with the same commands
54980 as MySQL databases.  MySQL database libraries are type 16, PostgreSQL
54981 are type 17.  Makefile.linux_sql and Makefile.pvm4_sql support both
54982 database types simultaneously.
54983 X
54984 >>June 23, 2004 CVS fa34t24b2
54985 X
54986 Additional fixes to enable -n or -p with fasts34 and
54987 fastm34. Makefile.pcom was fixed for fastm34_t.  A new file,
54988 mgstm1.nts, of DNA fragments from mgstm1.seq, is included for testing
54989 fasts34 and fastm34.
54990 X
54991 >>May 4, 2004  
54992 X
54993 Fixes to initfa.c to allow DNA:DNA for FASTS, FASTM.  This change
54994 introduced a bug that broke FASTS completely, but was fixed June 18,
54995 2004 (and retagged fa34t24b2).
54996 X
54997 >>April 23, 2004 CVS fa34t24b1
54998 X
54999 Fix bug in initfa.c that caused tfasts/tfastf not to examine all six
55000 frames.
55001 X
55002 >>May 4, 2004
55003 X
55004 Fixes to initfa.c to allow DNA:DNA for FASTS, FASTM.
55005 X
55006 >>March 19, 2004 CVS fa34t24b0
55007 X
55008 Modify all the drop*.c files, plus mshowbest.c and mshowalign.c, to
55009 display percent similarity, rather than percent ungapped.  An
55010 alignment is counted as similar if the score is greater than or equal
55011 to zero (the same criterion used for placing ".". To disable this
55012 change, remove -DSHOWSIM from the appropriate Makefile.*.
55013 X
55014 >>March 18, 2004 CVS fa34t23b8
55015 X
55016 Fix bug in initfa.c tables that caused prss to generally compare
55017 proteins.
55018 X
55019 >>March 15, 2004 
55020 X
55021 Fix bug in calls to revcomp(); make revcomp() guarantee NULL termination.
55022 X
55023 >>March 2, 2004 CVS fa34t23b7
55024 X
55025 Fix a very embarrassing and surprising bug that caused insertions
55026 in fasta alignments to appear in the wrong sequence.
55027 X
55028 >>Feb 7, 2004   CVS fa34t23b6
55029 X
55030 Change initfa.c to allow "-i" (reverse complement) and "-i -3" with
55031 "fastx34" and "prfx34".  In addition, "prfx34" now examines both query
55032 DNA strands in calculated the shuffled statistical significance.
55033 X
55034 >>Feb 5, 2004
55035 X
55036 Reverse assignments for G:U baseparing in initfa.c.
55037 X
55038 Fix memory allocation error caused by doubling DNA alignment width.
55039 X
55040 >>Jan 7, 2004   CVS fa34t23b5
55041 X
55042 Change in do_walign() in dropnfa.c to make final DNA alignments use a
55043 band that is 2X as large as the search band width.
55044 X
55045 >>Dec 22, 2003  CVS fa34t23b4
55046 X
55047 Fix typo in p2_complib.c that prevented compilation.  Fix problem
55048 with karlin.c for assymetrical matrices, such as used with -U.
55049 X
55050 >>Dec 10, 2003  CVS fa34t23b3
55051 X
55052 Fix problem in resetp()/initfa.c that disabled banded Smith-Waterman
55053 DNA alignments.
55054 X
55055 Allow spam() to do extended alignments for DNA if one of the sequences
55056 is < 50 nt.
55057 X
55058 Cause default ktup to drop for short sequences.  For protein < 50, ktup=1;
55059 for DNA < 20, 50, 100 ktup = 1, 2, 3, respectively.
55060 X
55061 >>Dec 7, 2003
55062 X
55063 A new option, "-U" is available for RNA sequence comparison.  "-U"
55064 functions like "-n", indicating that the query is an RNA sequence.  In
55065 addition, to account for "G:U" base pairs, "-U" modifies the scoring
55066 matrices so that a "G:A" match has the same score as a "G:G" match,
55067 and "T:C" match has the same score as a "T:T" match.  The asymmetric
55068 matrix required changes in dropnfa.c that were similar to the changes
55069 in dropgsw.c required for profiles.  In addition, m_msg.qdnaseq and pst.dnaseq
55070 X can now be SEQT_DNA, SEQT_RNA, SEQT_PROT, SEQT_UNK, or SEQT_OTHER.
55071 m_msg.ldnaseq does not use SEQT_RNA, only SEQT_DNA.  A new member of
55072 struct pstruct: int nt_align, is used to indicate nucleotide
55073 alignments.
55074 X
55075 >>Nov 19, 2003
55076 X
55077 Changes to Makefile's to distinguish between tatstats_fs.o and
55078 tatstats_ff.o.
55079 X
55080 >>Nov 2, 2003
55081 X
55082 Substantial changes to comp_lib.c, p2_complib.c, mshowbest.c, and
55083 mshowalign.c to support more sophisticated display options.
55084 Previously, one could have only on "-m #" option, even though several
55085 of the options were orthogonal (-m 9c is independent of -m 1 and -m2,
55086 which is independent of -m 6 (HTML)).  The programs now use a bitmask
55087 that allows independent options to be combined.  In particular -m 9c
55088 can be combined with -m 6, which can be very helpful for runs that
55089 need HTML output but can also exploit the encoding provided by -m 9c.
55090 X
55091 The "-m 9" option now also allows "-m 9i", which shows the standard
55092 best score information, plus percent identity and alignment length.
55093 X
55094 >>Oct 26, 2003  CVS fa34t23b1
55095 X
55096 Additional fixes to Makefiles to enable tfastf34(_t).  Changes to
55097 support ossearch34 (a non-Phil Green optimized Smith-Waterman).
55098 X
55099 >>Oct 8, 2003   CVS fa34t23b0
55100 X
55101 Fixes to get DNA queries working in both directions, and to fix PCOMPLIB
55102 programs for "-V" option.  Currently, the parallel programs cannot use
55103 the "-V" option.
55104 X
55105 >>Sept 25, 2003
55106 X
55107 A new option is available for annotating alignments.  -V '@#?!'
55108 can be used to annotate sites in a sequence, e.g:
55109 X       >GTM1_HUMAN ...
55110 X       PMILGYWDIRGLAHAIRLLLEYTDS@S?YEEKKYT@MG
55111 X       DAPDYDRS@QWLNEKFKLGLDFPNLPYLIDGAHKIT
55112 might mark known and expected (S,T) phosphorylation sites.  These
55113 symbols are then displayed on the query coordinate line:
55114 X
55115 X               10        20    @?  30  @     40  @     50        60
55116 GTM1_H PMILGYWDIRGLAHAIRLLLEYTDSSYEEKKYTMGDAPDYDRSQWLNEKFKLGLDFPNLP
55117 X       ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
55118 gtm1_h PMILGYWDIRGLAHAIRLLLEYTDSSYEEKKYTMGDAPDYDRSQWLNEKFKLGLDFPNLP
55119 X               10        20        30        40        50        60
55120 X
55121 This annotation is mostly designed to display post-translational
55122 modifications detected by MassSpec with FASTS, but is also available
55123 with FASTA and SSEARCH.
55124 X
55125 >>Sept 22, 2003   CVS fa34t22b5
55126 X
55127 The Altivec Smith-Waterman code has been removed.
55128 X
55129 >>Sept 17, 2003   CVS fa34t22b4
55130 X
55131 A variety of different bugs have been fixed.  (1) All the functions in
55132 the old initsw.c are now in initfa.c; initsw.c will be removed.
55133 Specifically, the Profile/PSSM code is now in initfa.c.  initfa.c is
55134 now fully table driven. (2) various problems with prss34 and prfx34
55135 have been fixed in initfa.c.  (3) An additional ncbl2_mlib.c buffer
55136 overrun has been fixed. (4) fastf34 is now available in this package.
55137 Its performance is very similar to, but not identical to, fastf33.  I
55138 am tracking down the differences.  In general, the raw scores
55139 calculated by both programs are the same, but the statistical analysis
55140 seems to be slightly different.
55141 X
55142 >>July 30, 2003   CVS fa34t22b3
55143 X
55144 Fix bug in ncbl2_mlib.c that caused buffer overrun with blast/formatdb
55145 v3 description lines.
55146 X
55147 >>July 28, 2003
55148 X
55149 The initfa.c file has been substantially re-structured to use a
55150 table-driven approach to parameter setting, rather than the previous
55151 confusing combinations of #ifdef's.  Two tables of parameters are
55152 used, pgm_def_arr[] and msg_def_arr[], which specify values like the
55153 program name, reference, scoring matrix, default gap penalties, etc.
55154 msg_def_arr[] has the sequence types for the query, library, and
55155 algorithm, as well as other parameters (qframe, nframe, nrelv, etc),
55156 which greatly simplifies the sequence recognition logic.  ppst->pgm_id
55157 can be used to identify the program that is running.  Eventually,
55158 almost all of the program specific #ifdef's will be removed from
55159 initfa.c.  initfa.c now provides initsw.c functionality, so that
55160 initsw.c is no longer needed.
55161 X
55162 >>July 25, 2003
55163 X
55164 A new file is included - fasta.defaults - that lists the scoring
55165 matrix, gap penalty, and other defaults for all of the fasta34
55166 programs.  This file will be used soon to simplify parameter setting
55167 for the FASTA programs, and should also be used by Javascript WWW
55168 interfaces to the FASTA programs.
55169 X
55170 >>July 22, 2003    CVS fa34t22b2
55171 X
55172 Fixes to dropfs2.c, tatprobs.c to ensure that negative probabilities
55173 cannot occur.  Negative probabilities were never seen with standard
55174 matrices, but did occur with BL50.  Another optimization in dropfs.c
55175 considerably improves fasts34 performance in some cases.
55176 X
55177 Fix a problem with formatdb v4 ASN.1 format files.
55178 X
55179 >>July 12, 2003
55180 X
55181 Fix a bug that prevented "-L" (long sequence descriptions) from
55182 working.
55183 X
55184 >>July 9, 2003
55185 X
55186 Fix reverse complement (M:K) error.  Fix off-by-one error for FASTA
55187 DNA alignments that caused the first aligned residue pair to be
55188 missed.
55189 X
55190 >>July 4 - 8, 2003
55191 X
55192 Incorporate blast-def-line ASN.1 parsing so that NCBI formatdb version
55193 4 files can be read.
55194 X
55195 >>June 26, 2003
55196 X
55197 The strategy for displaying the match/mismatch line (" .:" for -m 0)
55198 has been changed dramatically to acommodate more sophisticated
55199 strategies for indicating conservative replacements, e.g. because of
55200 PSSM's.  In addition to seqc0 and seqc1, which hold the aligned
55201 sequences for display, there is also seqca, which holds the alignment
55202 symbol.  calcons(), do_show(), and discons() have all changed to
55203 include seqca.  calcons() is somewhat more complex; discons() is much
55204 simpler.  (June 29, 2003 - dropgsw.c calcons() now displays profile
55205 similarity accurately - it is very very illuminating.)
55206 X
55207 >>June 16, 2003 version: fasta34t22
55208 X
55209 ssearch34 now supports PSI-BLAST PSSM/profiles.  Currently, it only
55210 supports the "checkpoint" file produced by blastall, and only on
55211 certain architectures where byte-reordering is unnecessary.  It has not
55212 been tested extensively with the -S option.
55213 X
55214 X       ssearch34 -P blast.ckpt -f -11 -g -1 -s BL62 query.aa library
55215 X
55216 Will use the frequency information in the blast.chkpt file to do a
55217 position specific scoring matrix (PSSM) search using the
55218 Smith-Waterman algorithm.  Because ssearch34 calculates scores for
55219 each of the sequences in the database, we anticipate that PSSM
55220 ssearch34 statistics will be more reliable than PSI-Blast statistics.
55221 X
55222 The Blast checkpoint file is mostly double precision frequency
55223 numbers, which are represented in a machine specific way.  Thus, you
55224 must generate the checkpoint file on the same machine that you run
55225 ssearch34 or prss34 -P query.ckpt.  To generate a checkpoint file,
55226 run:
55227 X
55228 blastpgp -j 2 -h 1e-6 -i query.fa -d swissprot -C query.ckpt -o /dev/null
55229 X
55230 (This searches swissprot for 2 iterations ("-j 2" using a E()
55231 threshold 1e-6 saving the resulting position specific frequencies in
55232 query.ckpt.  Note that the original query.fa and query.ckpt must
55233 match.)
55234 X
55235 >>June 5, 2003
55236 X
55237 Fix to mshowbest.c to get -m 9 coordinates correct on reverse strand
55238 with pv34comp*.  Some additional fixes for prfx34.
55239 X
55240 >>May 22, 2003
55241 X
55242 Changes to llgetaa.c, getseq.c, comp_lib.c to provide a different
55243 library residue lookup table (sascii) for queries and libraries.  This
55244 allows one to make a prfx34 (like prss34, but using the fastx
55245 algorithm).  prfx34 is now available.
55246 X
55247 >>May 13,14 2003
55248 X
55249 Fixes to most of the drop*.c files, and mshowbest.c, to ensure that
55250 coordinates displayed with -m 9(c) and the final alignment are
55251 consistent.  They were consistent for fasta34/ssearch34/fasts34, but
55252 not for fastx34/fasty34.  The alignment coordinate system has been
55253 been revised for consistency in allthe drop*.c programs (coordinates
55254 used to be off-by-one for some, but not other functions).
55255 X
55256 Fixes to -m 9c for fasty34/pv34compfy.  In addition, a problem was
55257 fixed with fastx34/fasty34 that appeared with a protein sequence was
55258 considerably longer than the DNA query, e.g. an EST vs titin (26K
55259 residues).  This problem only appeared on pv34compfx/fy on Xserve's
55260 under OS_X; but it should improve fastx34/fasty34 performance with
55261 very long protein sequences on all platforms.
55262 X
55263 >>May 7,8 2003
55264 X
55265 Changes to p2_workcomp.c, compacc.c, and p_mw.h to fix persistent
55266 bugs in the -m 9c display.  Previous pv34comp* programs would not
55267 return the correct coded alignment if more than 100 alignments came
55268 from the same node, or if an encoding was longer than 127 chars.
55269 X
55270 Also, fixes to p2_complib.c, comp_lib.c, to allow long query sequences
55271 to be segmented.  Previously, only the first 20,000 residues were
55272 used.  The segmented queries are not overlapped; segmented library
55273 sequences are.
55274 X
55275 >>May 5, 2003
55276 X
55277 Changes to last_tat.c, scaleswt.c to ensure that all fasts alignments
55278 that are likely to have significant scores are displayed.  In previous
55279 implementations, if the query had more than 10 fragments, only the 100
55280 best scores were shown.  Now, we rescore up to 2500 alignments.  The
55281 new approach allows large mixtures to be used for searches, where some
55282 of the fragments from the mixture match too many proteins
55283 (e.g. actins).  Some differences between the fasts34 and pv34compfs
55284 implementations have been fixed.  The two programs typically will not
55285 give exactly the same results, because of small differences in the
55286 sampling procedures, but the results are essentially equivalent.
55287 X
55288 >>Apr 11, 2003  CVS fa34t21b3
55289 X
55290 Fixes for "-E" and "-F" with ssearch34, which was inadvertantly disabled.
55291 X
55292 A new option, "-t t", is available to specify that all the protein
55293 sequences have implicit termination codons "*" at the end.  Thus, all
55294 protein sequences are one residue longer, and full length matches are
55295 extended one extra residue and get a higher score.  For
55296 fastx34/tfastx34, this helps extend alignments to the very end in
55297 cases where there may be a mismatch at the C-terminal residues.
55298 X
55299 -m 9c has also been modified to indicate locations of termination
55300 codons ( *1).
55301 X
55302 >>Mar 17, 2003  CVS fa34t21b2
55303 X
55304 A new option on scoring matrices "-MS" (e.g. "BL50-MS") can be used to
55305 turn the I/L, K/Q identities on or off.  Thus, to make "fastm34" use
55306 the isobaric identities, use "-s M20-MS".  To turn them off for "fasts34",
55307 use "-s M20".
55308 X
55309 More fixes for correct alignment coordinates.  There was a conflict between
55310 -m 9 and -m 9c and subsequent alignment displays.
55311 X
55312 >>Mar 13, 2003  
55313 X
55314 Various fixes to produce correct fastm34 alignments.  Changes to all
55315 functions to correct potential problem with -m 9 alignment coordinates
55316 when both -m 9 and actual alignments are shown.
55317 X
55318 >>Feb 25,27, 2003
55319 X
55320 Modifications to re-activate showsum.c, which included corrections to
55321 the showbest() call in p2_complib.c.
55322 X
55323 >>Feb 13, 2003  CVS fa34t21b1
55324 X
55325 Modifications to dropfx.c to dramatically improve alignment speed for
55326 cases where the DNA sequence is considerably longer than the protein
55327 sequence.  Previously, a 200 aa vs 5000 nt comparison would do a full
55328 200 x 5000 Smith-Waterman alignment; with this modification, no more
55329 than a 200 x 1200 (2x3x200) alignment is done.  This optimization has
55330 not (yet) been applied to dropfz2.c (fasty/tfasty).
55331 X
55332 >>Feb 11, 2003
55333 X
55334 Small modifications to comp_lib.c, p2_complib.c, and nmgetlib.c to
55335 pass openlib() a possibly old lmf_str.  This allows openlib() to
55336 re-use memory mapped files.  closelib() no longer releases memory
55337 mapped file buffers.  Under Linux, memory mapped file buffers were not
55338 really released, so when comparing a set of sequences against nr, the
55339 program could not mmap() the database after several searches.  This
55340 will also speed up memory mapped multiple sequence searches.
55341 X
55342 >>Jan 28-31, 2003  CVS fa34t21b0
55343 X
55344 Fix another bug (all of v34t20) involved with overlapping long
55345 sequences.  And another bug that occurred when using sampled
55346 statistics, but appeared only on the SGI platform - thanks to Dmitri
55347 Mikhailov.  Several other issues have been addressed based on more
55348 instrumented runtime testing.
55349 X
55350 Fix an old (all v34) bug that caused problems with -z 11-16 (shuffled
55351 sequence array was not allocated properly).  Fixed another bug with -z
55352 6/16 when using threaded (_t) searches in fasta34_t.
55353 X
55354 Restructure statistical analysis functions (scaleswn.c, scaleswt.c) to
55355 return the "final" statistical estimation routine done in pst.zsflag_f.
55356 This allows the program to cope with searches against a single sequence
55357 correctly.
55358 X
55359 Corrected an error for DNA sequences needing Altschul-Gish statistics.
55360 X
55361 >>Jan 25, 2003
55362 X
55363 Add option "-J start:stop" to pv34comp*/mp34comp*.  "-J x" used to
55364 allow one to start at query sequence "x"; now both start and stop can
55365 be specified.
55366 X
55367 >>Jan 14, 2003
55368 X
55369 Changes to apam.c to provide an error message on stderr when a scoring
55370 matrix cannot be found.
55371 X
55372 Changes to dropfs2.c, initsw.c, initfa.c to provide -m9c information
55373 for fasts34 searches.  Modify the alignment algorithm to use
55374 probabilistic scores properly.
55375 X
55376 >>Dec 22, 2002
55377 X
55378 Change to compacc.c (sortbeste()) to do a second sort on zscore when
55379 several sequences have E() == 0.
55380 X
55381 >>Nov 27, 2002
55382 X
55383 Change FSEEK_T to fseek_t to keep Borland BCC5 happy. 
55384 X
55385 >>Nov 14-22, 2002  CVS fa34t20b6
55386 X
55387 Include compile-time define (-DPGM_DOC) that causes all the fasta
55388 programs to provide the same command line echo that is provided by the
55389 PVM and MPI parallel programs.  Thus, if you run the program:
55390 X
55391 X    fasta34_t -q -S gtt1_drome.aa /slib/swissprot 12
55392 X
55393 the first lines of output from FASTA will be:
55394 X
55395 X    # fasta34_t -q gtt1_drome.aa /slib/swissprot
55396 X     FASTA searches a protein or DNA sequence data bank
55397 X     version 3.4t20 Nov 10, 2002
55398 X    Please cite:
55399 X     W.R. Pearson & D.J. Lipman PNAS (1988) 85:2444-2448
55400 X
55401 This has been turned on by default in most FASTA Makefiles.  
55402 X
55403 Fix p2_complib.c so that qstats[] is always allocated before it is used.
55404 X
55405 Fix serious bug in non-threaded comp_lib.c that caused some high
55406 scoring sequences to be missed by fasts34.  New tests are included in
55407 test.sh to detect this problem in the future.
55408 X
55409 The shell sort algorithm in sortbeste(), sortbestz(), and sortbesto()
55410 has been modified to use an improved algorithm that will not go
55411 quadratic in pathological cases.
55412 X
55413 nmgetlib.c and mmgetaa.c have been modified to remove "^A" in libstr
55414 when used with p2_complib.c.
55415 X
55416 Fix problem with MAXSEG in tatstats.h with IBM/AIX.
55417 X
55418 Changes to most Makefiles to use -DSAMP_STATS; fixes to p2_complib.c
55419 for SAMP_STATS.
55420 X
55421 >>Oct 22, Nov 3, Nov 9, 2002   CVS tag fa34t20b5
55422 X
55423 Fix problem in comp_lib.c that caused the query sequence length to be
55424 counted twice.
55425 X
55426 Fixed problem with prss34 (updated find_zp in showrss.c).
55427 X
55428 Correct shuffling function in several places.
55429 X
55430 Add jitter back to addhistz() - improves appearance with prss34.
55431 X
55432 Changes to fix problems with aln_code using -m 9c.
55433 X
55434 Fix to serious bug in scaleswt.c (fasts34, etc) that caused sorts on
55435 the high scores to take much to long.  The program is now 10X faster,
55436 and scales well on PVM/MPI.
55437 X
55438 Fix to llgetaa.c to work with new getseq() API with automatic alphabet
55439 recognition.
55440 X
55441 >>Oct 12, 2002 CVS tag fa34t20b4
55442 X
55443 Several very obscure (and sometimes old) bugs that appeared in certain
55444 MPI environments have been fixed.  This occurred because the pst.sq[]
55445 array did not always have a '\0' at the end.  In addition,
55446 mshowalign.c/p2_workcomp.c sometimes failed to put the '\0' at the end
55447 of seqc0/seqc1.  Correct bug introduced in fa34t20b3 for fasts34(_t).
55448 X
55449 >>Oct 9, 2002 CVS tag fa34t20b3
55450 X
55451 Fix to apam.c build_xascii() to not zero-out qascii[0].  Fix
55452 Makefile.pvm4.  Mix problem with -m 9c with compacc.c.
55453 X
55454 >>Sept 28, 2002 
55455 X
55456 Additional fixes to -m 9c in p2_complib.c/compacc.c/mshowbest.c.
55457 Remove restriction in fasts34(_t) to less than 30 peptides (though no
55458 more than 30 peptides can be aligned currently).
55459 X
55460 >>Sept 24, 2002
55461 X
55462 Fix p2_workcomp.c so that e_scores are delivered correctly when
55463 last_calc flag is set, and -m 9c provides alignments when only one
55464 best hit is present.
55465 X
55466 Fix comp_lib.c to use different maxn and overlap for each different
55467 query sequence.  fasta34 and fasta34_t now have identical results when
55468 a long sequence is searched.
55469 X
55470 Add '@C:101' support to memory mapped FASTA format files.
55471 X
55472 Fix mshowalign.c so that coordinates returned by cal_coord() use
55473 loffset+l_off.
55474 X
55475 >>Sept 14, 2002 CVS tag fa34t20b2
55476 X
55477 Changes to p2_complib.c, compacc.c to fix statistics problems with
55478 pv34compfs on query sequences with more than 10 fragments.
55479 X
55480 >>Aug 27, 2002
55481 X
55482 Modifications to mshowbest.c and drop*.c (and p2_workcomp.c,
55483 compacc.c, doinit.c, etc.) to provide more information about the
55484 alignment with the -m 9 option.  There is now a "-m 9c" option, which
55485 displays an encoded alignment after the -m 9 alignment information.
55486 The encoding is a string of the form: "=#mat+#ins=#mat-#del=#mat".
55487 Thus, an alignment over 218 amino acids with no gaps (not necessarily
55488 100% identical) would be =218.  The alignment:
55489 X
55490 X       10        20        30        40        50          60         70  
55491 GT8.7  NVRGLTHPIRMLLEYTDSSYDEKRYTMGDAPDFDRSQWLNEKFKL--GLDFPNLPYL-IDGSHKITQ
55492 X       :.::  . :: ::  .   .:::         : .:    ::.:   .: : ..:.. :::  :..:
55493 XXURTG  NARGRMECIRWLLAAAGVEFDEK---------FIQSPEDLEKLKKDGNLMFDQVPMVEIDG-MKLAQ
55494 X               20        30                 40        50        60        
55495 X
55496 would be encoded: "=23+9=13-2=10-1=3+1=5".  The alignment encoding is
55497 with respect to the beginning of the alignment, not the beginning of
55498 either sequence.  The beginning of the alignment in either sequence is
55499 given by the an0/an1 values. This capability is particularly useful
55500 for [t]fast[xy], where it can be used to indicate frameshift positions
55501 "/#\#" compactly.  If "-m 9c" is used, the "The best scores" title
55502 line includes "aln_code".
55503 X
55504 >>Aug 14, 2002  CVS tag fa34t20
55505 X
55506 Changes to nmgetlib.c to allow multiple query searches coming from
55507 STDIN, either through pipes or input redirection.  Thus, the command
55508 X
55509 X       cat prot_test.lseg | fasta34 -q -S @ /seqlib/swissprot
55510 X
55511 produces 11 searches.  If you use the multiple query functions, the
55512 query subset applies only to the first sequence.
55513 X
55514 Unfortunately, it is not possible to search against a STDIN library,
55515 because the FASTA programs do not keep the entire library in memory
55516 and need to be able to re-read high-scoring library sequences.  Since
55517 it is not possible to fseek() against STDIN, searching against a STDIN
55518 library is not possible.
55519 X
55520 >>Aug 5, 2002
55521 X
55522 fasts34(_t) and fastm34(_t) have been modified to allow searches with
55523 DNA sequences.  This gives a new capability to search for DNA motifs,
55524 or to search for ordered or unordered DNA sequences spaced at
55525 arbitrary distances.
55526 X
55527 >>Aug 4, 2002
55528 X
55529 comp_lib.c has been modified to provide comp_mlib.c function.
55530 comp_mlib.c is no longer used.  comp_lib.c with the "mlib" function
55531 can now recognize protein or DNA sequences automatically, and reads
55532 from stdin can now detect DNA/protein sequence types automatically.
55533 Changes to compacc.c, getseq.c, doinit.c initfa.c, initsw.c, and
55534 nmgetlib.c to support automatic sequence type detection.
55535 X
55536 >>July 28-31, 2002
55537 X
55538 (1) The various Makefile's have been "normalized".  The fast*34[_t]
55539 X    (Makefile.34m.common[_sql]), Makefile.pvm4[_sql], and
55540 X    Makefile.mpi4[_sql] make files all use a common set of filenames,
55541 X    described in Makefile.fcom.  This greatly simplifies adding
55542 X    programs, but requires that all *.o files be deleted when moving
55543 X    from fast*34* to pv34comp* to mp34comp*.
55544 X
55545 (2) showalign.c/p_showalign.c have been merged into mshowalign.c
55546 X    showbest.c/manshowbest.c have been merged into mshowbest.c.  Some
55547 X    of the related files (showun.c, manshowun.c, have not been merged
55548 X    or tested).
55549 X
55550 (3) Code for ranking scores with valid e_value's incorporated.
55551 X
55552 (4) Bug fixes in p2_complib.c, so that fasts34/fasts34_t/pvcompfs
55553 X    provide identical statistics.
55554 X
55555 >>July 26, 2002
55556 X
55557 Makefile.pvm4_sql and Makefile.pvm4 have been substantially simplified
55558 by providing the worker program name from the h_init() function in the
55559 initfa.c/initsw.c files.
55560 X
55561 >>July 24, 2002
55562 X
55563 Substantial modifications to param.h, structs.h to ensure that no
55564 sequence specific information is kept in struct pstruct.  This
55565 structure now holds the pam[] matrix, and other scoring parameters,
55566 but nothing that is dependent on aa0.  The aa0 dependent stuff (nm0,
55567 Lambda, K, etc) is now stored in struct mngmsg.  This was mostly done
55568 to support the pv34comp* programs, which have separate mngmsg
55569 structures but the same pstructs.
55570 X
55571 The fasts34, fasts34_t, and pv34compfs/c34.workfs have all been tested
55572 successfully.
55573 X
55574 >>July 19, 2002
55575 X
55576 Fix an old bug in the calculation of E()-values in DNA databases
55577 longer than 2147483647 residues on machines with 32-bit longs.
55578 X
55579 X
55580 >>July 28-31, 2002
55581 X
55582 (1) The various Makefile's have been "normalized".  The fast*34[_t]
55583 X    (Makefile.34m.common[_sql]), Makefile.pvm4[_sql], and
55584 X    Makefile.mpi4[_sql] make files all use a common set of filenames,
55585 X    described in Makefile.fcom.  This greatly simplifies adding
55586 X    programs, but requires that all *.o files be deleted when moving
55587 X    from fast*34* to pv34comp* to mp34comp*.
55588 X
55589 (2) showalign.c/p_showalign.c have been merged into mshowalign.c
55590 X    showbest.c/manshowbest.c have been merged into mshowbest.c.  Some
55591 X    of the related files (showun.c, manshowun.c, have not been merged
55592 X    or tested).
55593 X
55594 (3) Code for ranking scores with valid e_value's incorporated.
55595 X
55596 (4) Bug fixes in p2_complib.c, so that fasts34/fasts34_t/pvcompfs
55597 X    provide identical statistics.
55598 X
55599 >>July 26, 2002
55600 X
55601 Makefile.pvm4_sql and Makefile.pvm4 have been substantially simplified
55602 by providing the worker program name from the h_init() function in the
55603 initfa.c/initsw.c files.
55604 X
55605 >>July 24, 2002
55606 X
55607 Substantial modifications to param.h, structs.h to ensure that no
55608 sequence specific information is kept in struct pstruct.  This
55609 structure now holds the pam[] matrix, and other scoring parameters,
55610 but nothing that is dependent on aa0.  The aa0 dependent stuff (nm0,
55611 Lambda, K, etc) is now stored in struct mngmsg.  This was mostly done
55612 to support the pv34comp* programs, which have separate mngmsg
55613 structures but the same pstructs.
55614 X
55615 The fasts34, fasts34_t, and pv34compfs/c34.workfs have all been tested
55616 successfully.
55617 X
55618 >>July 8, 2002
55619 X
55620 Modifications to comp_lib.c, initfa.c and new scaleswt.c, tatstats.c
55621 to support FASTS with Tatusov statistics.
55622 X
55623 last_params() has been introduced to allow aa0 dependent changes in m_msg/pstr.
55624 X
55625 sortbest() has been moved into initfa.c/initsw.c to make it function specific.
55626 X
55627 find_z() takes an additional parameter, escore.
55628 X
55629 The do_work() results structure, beststr, and stat_str all accommodate
55630 escores as well as integer scores (stat_str also saves segn and segl
55631 but doesn't need them).
55632 X
55633 In scaleswt.c, process_hist() now knows much more about Tatusov statistics.
55634 X
55635 last_stats() provided to accommodate rank-based statistical corrections.
55636 X
55637 scale_scores() is the last function to modify the beststr scores
55638 (final calculation of E-value).
55639 X
55640 Some sortbest*() calls and some bptr[i]->zscore=find_zp() loops have
55641 been moved into scale_scores();
55642 X
55643 >>July 3,5, 2002
55644 X
55645 Modifications to allow mySQL comments (--) in "library.sql 16" files.
55646 Thus, a first line of:
55647 X
55648 X       --host seqdb user password;
55649 X
55650 is read by FASTA as the login information to a mySQL server, but is
55651 ignored by mySQL.  "DO" commands in FASTA mySQL files can also be
55652 rendered invisible to mySQL in this way.  See "do.sql".
55653 X
55654 Modifications to mysql_lib.c to allow very long SQL statements.  The
55655 buffer is now dynamically reallocated in 4Kb chunks.
55656 X
55657 The fasta3.1 man page has been updated and re-organized.
55658 X
55659 >>June 26, 2002
55660 X
55661 Minor modifications to nmgetaa.c (openlib()) to use the same arguments
55662 for searching and PRSS.  PRSS needs access to all of m_msg, but
55663 searches do not.  Other small fixes to comp_mlib.c, towards the goal
55664 of merging comp_mlib.c and comp_lib.c.
55665 X
55666 >>June 25, 2002
55667 X
55668 Modify the statistical estimation strategy to sample all the sequences
55669 in the database, not just the first 60,000.  The histogram is still
55670 based only on the first 60,000 scores and lengths, though all scores
55671 an lengths are shown.  The fit to the data may be better than the
55672 histogram indicates, but it should not be worse.
55673 X
55674 Currently, this modification is available only if the -DSAMPLE_STATS
55675 option is defined.
55676 X
55677 >>June 23, 2002 CVS fa34t11d4
55678 X
55679 Fix a very long-standing bug in fasty/tfasty that caused 'NNN' to be
55680 translated as 'S', rather than 'X'.  fastx/tfastx has done this
55681 correctly for many years, but the fasty/tfasty code that I received
55682 from Zheng Zhang was not implemented correctly (my fault, his code was
55683 fine).
55684 X
55685 >>June 19, 2002
55686 X
55687 Added "-C #" option, where 6 <= # <= MAX_UID (20), to specify the
55688 length of the sequence name display on the alignment labels.  Until
55689 now, only 6 characters were ever displayed.  Now, up to MAX_UID
55690 characters are available.
55691 X
55692 >>May 30, 2002  CVS fa34t11d3
55693 X
55694 Fixed problem with programs using the default -E cutoff when -b was
55695 provided.  With this implementation, -E can override -b, but -b
55696 overrides the default -E.
55697 X
55698 Fixed problem with 64-bit file offsets in param.h (change USE_FSEEK0
55699 -> USE_FSEEKO, include -D_LARGEFILE_SOURCE and -D_LARGEFILE64_SOURCE
55700 in Makefile.linux_sql).  Put limits on alignment display length (200
55701 chars).  More checks for null returns from SQL queries.
55702 X
55703 >>Apr 17, 2002  CVS fa34t11d2
55704 X
55705 Fixed bug in mm_file.h/ncbl2_mlib.c that caused the SGI version to be
55706 unable to read blast2 format files.
55707 X
55708 Changed "mp_*" tags to "pg_*" for -m 10 option.
55709 X
55710 >>Mar 30, 2002
55711 X
55712 Fix embarrassing bug in revcomp() (getseq.c) that failed to complement
55713 the central nucleotide in a sequence with an odd number of residues.
55714 X
55715 Small changes to dropfs.c for more segments.
55716 X
55717 >>Mar 16, 2002
55718 X
55719 Added create_seq_demo.sql, nt_to_sql.pl to show how to build an SQL
55720 protein sequence database that can be used with with the mySQL
55721 versions of the fasta34 programs.  Once the mySQL seq_demo database
55722 has been installed, it can be searched using the command:
55723 X
55724 X       fasta34 -q mgstm1.aa "seq_demo.sql 16"
55725 X
55726 mysql_lib.c has been modified to remove the restriction that mySQL
55727 protein sequence unique identifiers be integers.  This allows the
55728 program to be used with the PIRPSD database.  The RANLIB() function
55729 call has been changed to include "libstr", to support SQL text keys.
55730 Due to the size of libstr[], unique ID's must be < MAX_UID (20)
55731 characters.
55732 X
55733 A "pirpsd.sql" file is available for searching the mySQL distribution
55734 of the PIRPSD database.  PIRPSD is available from
55735 ftp://nbrfa.georgetown.edu/pir_databases/psd/mysql.
55736 X
55737 >>Mar 6, 2002
55738 X
55739 Fix showbest.c showbest() to report pst.zdb_size as database size.
55740 Fix dropnfa.c spam() to address off-by-one on end of run, and double
55741 counting on backwards scan.  Fix dropnfa.c do_fasta() to fix another
55742 problem introduced by -S.  Changes to comp_lib.c to ensure that both
55743 the beginning and end of the query and library sequence have '\0'
55744 present.  Changes to initfa.c, initsw.c to ensure that a match to a
55745 lower-case letter with -S gets exactly the same score as a match to an
55746 'X'.  Changes to mmgetlib.c to work with 64-bit longs in *.xin files.
55747 X
55748 >>Feb 26, 2002
55749 X
55750 Fixes to doinit.c, initfa.c, initsw.c to allow DNA matrices using the
55751 "-s dna.mat" option.  A new matrix, "d50ry.mat" is available that
55752 scores +5 for a match, -2 for a transition, and -5 for a
55753 transversion. "d50ry.mat" corresponds to DNA PAM50 with transitions
55754 twice as common as transversions.  When "-s dna.mat" is used, "-n"
55755 MUST be used as well.
55756 X
55757 Query sequence names ("aa", "nt") should be more accurate.
55758 X
55759 >>Feb 22, 2002
55760 X
55761 Fix to getseq.c to allow "plain" sequence files.
55762 X
55763 >>Feb 12, 2002
55764 X
55765 Minor fix to res_stats.c.
55766 X
55767 >>Jan 28, 2002
55768 X
55769 Fixes to resurrect res_stats.c.  res_stats (cc -o res_stats
55770 res_stats.c scaleswn.c -lm) takes the output from a current "-R
55771 file.res" file and calculates statistical significance - this allows
55772 one to take exactly the same set of scores (and lengths) and calculate
55773 statistical estimates using different strategies.
55774 X
55775 >>Jan 24, 2002
55776 X
55777 modifications to mmgetlib.c, ncbl2_mlib.c to more robustly read memory
55778 mapped files (*.xin, map_db) on machines lacking "native" 64-bit
55779 longs.  If the machine provides some definition for a 64-bit long
55780 (e.g. "long long", "int64_t"), things should work. 64-bit offsets into
55781 memory mapped files work properly on Alpha, SGI, i386 Linux, and
55782 MacOSX.  The current implementation depends either on 64 bit longs
55783 (Compaq Alpha's pre 4.0G) or the <sys/inttype.h> file.  Makefile,
55784 Makefile.alpha, and Makefile.linux have been modified.
55785 X
55786 Modifications to nmgetlib.c, mmgetlib.c to provide GI numbers and
55787 Accession versions for Genbank searches.  If the GI:123456 number is
55788 available, it will be used and the description line will be formatted:
55789 X
55790 X       gi|123456|gb|ACC1234.1|LOCUS description
55791 X
55792 This should help FAST_PAN runs, where the version of a sequence
55793 changes frequently.
55794 X
55795 >>Jan 10, 2002
55796 X
55797 Modifications to p2_complib.c, p2_workcomp.c to more reliably allocate
55798 space for library sequence descriptions on the master and workers.
55799 X
55800 >>Jan 2-3, 2002         CVS fa34t10c/fa34t10d3
55801 X
55802 Fixes to comp_lib.c to support Macintosh and Windows/Turbo-C
55803 compilation.  New Makefile.tc.  Macintosh version supports both
55804 "Classic" and "Carbon" environments.
55805 X
55806 "<values.h>" has been replaced with the more modern "<limits.h>"
55807 X
55808 Fixes to p2_complib.c to support n_libstr (libstr length) in GETLIB().
55809 X
55810 comp_thr.c, complib.c removed.
55811 X
55812 >>Dec 16, 2001
55813 X
55814 Complete integration of comp_mlib.c with both the unthreaded and
55815 threaded programs.  Comp_mlib allows fasta34 and fasta34_t to compare
55816 a database with a second database, just as pv34compfa does.  Using
55817 multiple queries with fasta34_t is not as efficient as pv34compfa (and
55818 it cannot use networks of Unix workstations), but it is much easier to
55819 use and install.
55820 X
55821 With the comp_mlib.c option, fasta34 cannot automatically recognize
55822 DNA sequences, just as pv34compfa no longer recognizes DNA sequences.
55823 You must use the "-n" option to search with DNA sequences.  The other
55824 programs (fastx34, tfastx34, etc) "know" the type of the query and
55825 database sequences, so "-n" is only required for fasta34(_t).
55826 X
55827 >>Dec 14, 2001          CVS tag fa34t10b
55828 X
55829 Fix problems reading DNA databases in blast2 format.
55830 X
55831 >>Dec 11, 2001
55832 X
55833 Changes to spam() in dropnfa.c so that, for DNA sequences, the
55834 previous behavior for finding the boundaries of a local alignment
55835 region use the same algorithm as previous versions of fasta.  For
55836 protein sequences, the algorithm will extend the local region beyond
55837 the "ktup" boundaries if a better score can be found.  For DNA
55838 sequences, this raises the noise rather than increasing sensitivity,
55839 so it is turned off and "ktup" boundaries are respected.  The old,
55840 "ktup" boundary algorithm is available with -DNOSPAM_EXT.
55841 X
55842 This version also includes a working res_stats.c, which can be used to
55843 test various statistical estimates on exactly the same set of scores.
55844 X
55845 Fixed problems with -m 9 percent identity for fastx/fasty/tfastx/tfasty.
55846 These errors have been present since -m 9 was implemented.
55847 X
55848 >>Dec 10, 2001
55849 X
55850 Fix to map_db.c to work correctly with files > 2 Gb when 64-bit longs
55851 are available.  It is not yet designed to work with ftello() and other
55852 offset types.
55853 X
55854 >>Nov 11,21, 2001       CVS tag fa34t10a, fa34t10d1
55855 X
55856 Substantial changes to revcomp(), getseq(), and other functions to
55857 correct problems with -S on DNA sequences.  Sequences with lower case
55858 nucleotides were not recognized or reverse complemented properly.
55859 X
55860 Fix to dropnfa.c (v34t07, Nov 21, 2001) bg_align() to re-initialize
55861 static globals - this fixes a problem encountered with pv34compfa.  A
55862 new main program, comp_mlib.c has been added to the CVS archive,
55863 although it is not referenced in any of the Makefile.  comp_mlib.c
55864 works like p2_complib.c and compares a library against another
55865 library.
55866 X
55867 >>Nov 4, 2001
55868 X
55869 Change to dropnfa.c spam () while(1) -> while(lpos <= dmax->stop).
55870 This fixes a problem with ktup=1 on Suns only, so far.
55871 X
55872 >>Oct 4, 2001           CVS tag fa34t10
55873 X
55874 Add comp_lib.c file, which merges complib.c (unthreaded) and
55875 comp_thr.c (threaded) code into one file.
55876 X
55877 Modifications to nmgetlib.c, mmgetaa.c to allow Genbank flatfile
55878 format without DESCRIPTION or ACCESSION lines.
55879 X
55880 Additional fix for -S with ktup=1.
55881 X
55882 >>Sept. 24, 2001
55883 X
55884 Fix to have correct gap-penalties for short scoring matrices with
55885 tfastx/fastx.
55886 X
55887 >>Sept. 10, 2001        CVS tag fa34t05d6
55888 X
55889 Fix a bug introduced by -S fix in fa34t05d5.  Also, try to remove
55890 changes in p34compfa compared to pv4compfa output.
55891 X
55892 >>Sept. 6, 2001         CVS tag fa34t05d5
55893 X
55894 Fix the -S dropnfa/fx/fz2 bug that was not actually fixed in
55895 fa34t05d4.  Incorporate the correct scaleswn.c refered to in
55896 fa34t05d4.
55897 X
55898 >>Sept. 5, 2001         CVS tag fa34t05d4
55899 X
55900 Fix problem with m_msg.quiet that prevented interactive prompts for
55901 ktup, file name, etc with threaded programs.
55902 X
55903 Fix serious bug in dropnfa.c/dropfx.c/dropfz2.c that caused -S to work
55904 improperly on sequences with effective length of 3 or less.
55905 X
55906 Change to scaleswn.c to make mle_cen(), mle_cen2() more robust to cases
55907 where the top and bottom scores are the same.
55908 X
55909 Change p2_complib.c to avoid compiler complaints with (void *)wstage2p=NULL
55910 on some platforms.
55911 X
55912 >>Aug. 30, 2001         CVS tag fa34t05d3
55913 X
55914 Fixed problem with uthr_subs.c for Suns, but changed Makefile.sun to
55915 use pthreads rather than Sun Unix threads.  Removed SQL stuff from
55916 Makefile.mpi4/pvm4 and added Makefile.mpi4_sql/pvm4_sql.  
55917 X
55918 fa34t05d2 - fix to map_db.c to provide *sascii.
55919 X
55920 fa34t05d1 - fixes to ibm_pthr_subs.c and Makefile.ibm from IBM.
55921 X
55922 >>Aug. 20, 2001         CVS tag fa34t05d0
55923 X
55924 The pvm/mpi complib programs have been substantially updated with
55925 release 3.4.  See readme.v34t0 for more information.  With version
55926 3.4, the MPI programs are mp34comp*, mu34comp*, etc.
55927 X
55928 A major effect of this change is to disable automatic sequence type
55929 (protein/DNA) recognition with pv34compfa/mp34compfa.  By default,
55930 protein libraries are assumed.  Thus, pv34compfa/mp34compfa require
55931 the "-n" command line option when running pv34compfa/mp34compfa on DNA
55932 sequence libraries.  This issue does not occur with the other
55933 programs, which will recognize the appropriate sequence type, because
55934 it is determined by the program (e.g. pv34compfx requires
55935 DNA:protein).
55936 X
55937 Fixed substantial problem with 64-bit file offsets for Linux in
55938 complib.c/comp_thr.c, p2_complib.c.  This problem, solved by Doug
55939 Blair, was preventing the threaded versions from working properly in
55940 memory mapped mode.
55941 X
55942 In all earlier versions of fasta, when very long sequences were
55943 searched, the sequence length reported was that of the "chunk" that
55944 was actually searched (typically 80,000-query_length) rather than the
55945 actual library sequence length.  The peculiar behavior now changed,
55946 and the full length of the library sequence, not the sequence chunk,
55947 is reported as the library sequence length.  Note that chunks are
55948 still used, however, which can cause the same alignment to be shown
55949 twice.  In addition, the "-m 9" output format has changed to report
55950 the coordinates of the query and library sequence (see below), which
55951 may be different from 1-sequence_length because the the query and
55952 library sequences may have been extracted from larger sequences.  Four
55953 additional fields have been added, "pn0", "px0","pn1", "px1" that are
55954 the positions in for the beginning (pn0/1) and end (px0/1) of they
55955 query/library sequence.  pn0/1 would typically be changed with the
55956 "@C:#" directive, described below.
55957 X
55958 Changes to doinit.c/initfa.c/initsw.c to provide a new function -
55959 f_lastenv() - that allows function-specific adjustments to parameters
55960 after the command line options have been read but before the first
55961 sequence is read.  This change solved problems with "mp/pv34compfx -S".
55962 X
55963 fasts34/tfasts34 now recognize that 'I/L' are the same, as are 'Q/K'
55964 (which are apparently indistinguishable by Mass-Spec).  The latter
55965 identity is on by default, but can be turned off with "-h 0".
55966 X
55967 The MPI/PVM versions of the programs have been tested extensively with
55968 compfa, compfx, and comptfx.  Makefile.mpi4 now works properly.
55969 Changes to p2complib.c to support the PVM option "-T 1-4", which
55970 allows one to run on nodes 1-4 of a (presumably larger) PVM virtual
55971 machine.  This option has no effect on the mp34comp* programs.  The
55972 old "-T 4" to run on 4 nodes, is also available.  If each node has 2
55973 cpu's, as indicated in the "pvmd hostfile", both CPU's will be used
55974 for a total, in this example, of 8 processes. This allows one to
55975 specify a large PVM machine and use separate parts of it
55976 independently.
55977 X
55978 Changes to nmgetlib.c to fix problems with longer dates in GCG files
55979 (Y2K).  Fixes to faatran.c for extended alphabets and 'X's.  Various
55980 code clean-ups to make "gcc -Wall" a little bit (not much) happier.
55981 X
55982 This is the first distributed fasta34 version.
55983 X
55984 ================
55985 >>Aug 9, 2001           CVS tag fa34t05
55986 X
55987 Corrections to initfa.c to allow -S to work with tfastx/y.
55988 Fix to manshowbest.c for query position with -m 9.
55989 X
55990 >>July 18, 2001         CVS tag fa34t04
55991 X
55992 Various changes to complib.c, comp_thr.c, p2_complib.c, showbest.c,
55993 showalign.c to deal with overlapping alignments in long sequences that
55994 have been segmented.  When long sequences are segmented (lcont>0), the
55995 eventual total length (n1tot_v) is saved at beststr->n1tot_p.  If
55996 there was no lcont, then beststr->n1tot_p = NULL, and beststr->n1
55997 should be used as the sequence length.  This has the advantage of
55998 requiring space only when long sequences are encountered, and
55999 requiring only one integer for several segments.
56000 X
56001 m_msg.noshow has been removed.
56002 X
56003 The -m 9 format has been changed - 5 fields have been added, 4
56004 (pmn0/pmx0/pmn1/pmx1) provide the beginning and end coordinates of the
56005 query and library sequence; the last (fs) reports the number of
56006 frameshifts.  The names of the alignment boundaries have been changed
56007 from min0/max0/min1/max1 to amn0/amx0/amn1/amx1 (Alignment miN/maX).
56008 X
56009 The SQL format has been extended to provide for statements that do
56010 things but do not generate results, such as creating and selecting into a temporary table, e.g.:
56011 ================
56012 X    do
56013 X    create temporary table seq_pos (
56014 X    id int unsigned not null auto_increment primary key,
56015 X    prot_id int unsigned not null default 0,
56016 X    start int unsigned not null default 0,
56017 X    length int unsigned not null default 0,
56018 X    )
56019 X    ;
56020 X    do
56021 X    insert into seq_pos (prot_id, start, length)
56022 X      select id, 11, len-10
56023 X      from protein, annot
56024 X      where len > 100
56025 X      and annot.protein_id = protein.id
56026 X      and annot.pref=1
56027 X    ;
56028 X    select seq_pos.id,
56029 X       substring(protein.seq, start, length),
56030 X       concat("@C:", start, " ", descr)
56031 X    from protein, seq_pos, annot
56032 X    where protein.id = annot.protein_id
56033 X      and protein.id = seq_pos.prot_id
56034 X      and annot.pref = 1
56035 X    ;
56036 X    select prot_id,
56037 X       concat("@C:", start, " ", descr)
56038 X    from seq_pos, annot
56039 X    where annot.protein_id = seq_pos.prot_id
56040 X      and seq_pos.id = #
56041 X      and annot.pref = 1
56042 X     ;
56043 ================
56044 X
56045 X  In the current implementation, these statements must start with "DO"
56046 as the first two characters on the line, and come immediately after a
56047 line ending with ';'.  The text from "DO" to the next ";", excluding
56048 the "DO", is executed when the database connection is made.
56049 X
56050 ===== >>July 12, 2001
56051 X
56052 The allocation of the work_info data structure used to send
56053 information to the worker threads has been changed.  The old method
56054 worked, possibly by accident.
56055 X
56056 A bug in p2_complib.c that caused E()-values to be calculated
56057 improperly for the first query sequence has been fixed.
56058 X
56059 >>July 11, 2001 --> fa34t02
56060 X
56061 It is now possible to specify output coordinates in library sequences
56062 by including the string: "@C:number" on the description line, e.g.
56063 X
56064 X   >gtm1_human gi|12345 human glutathione transferase M1 @C:21
56065 X
56066 would label the first residue in the library sequence "21" rather than
56067 "1".  This capability has been included to provide accurate
56068 coordinates for searches done against subsequences generated by an SQL
56069 query.  For example, one could use a query of the form:
56070 X
56071 X SELECT protein.id, substring(protein.seq,11,length(protein.seq)-20),
56072 X       concat(protein.name," @C:11 ",protein.descr)
56073 X FROM protein;
56074 X
56075 to generate a sequence set with each sequence starting with residue
56076 11.  Without the "@C:11" option on the description line, the program
56077 would number the alignment positions starting at 1, even though the
56078 first residue of the sequence really started at 11.  "@C:11" allows
56079 one to correct the coordinate system.
56080 X
56081 Currently, "@C:offset" is available only with library type 1 (fasta
56082 format) and 16 (mySQL).
56083 X
56084 The SQL-generated database with "@C:offset" can be used with both the
56085 fast*34(_t) programs and with pv34comp*.  However, the SQL syntax is
56086 used differently in the fasta34 and pv34compfa programs.  fast*34(_t)
56087 requires three SQL statements during a search: (1) a statement to
56088 generate a large set of library sequences; (2) a statement to generate
56089 a description of a single sequence, given a unique identifier provided
56090 by (1); and (3) a statement to generate a single sequence given a
56091 unique identifier provided by (1).  For fast*34 searches, the third
56092 (3) SQL statement must provide the "@C:offset" information in the
56093 third results field for the offset to be used.  It is optional in (1)
56094 and (2).
56095 X
56096 The pv34comp* programs only require one SQL statement, statement (1)
56097 above, which must provide three fields, a unique identifier, the
56098 sequence, and a complete description that must include "@C:offset" if
56099 substrings are used.  If SQL queries (2) and (3) are provided, they
56100 are  ignored.  Thus, the same files can be used by both programs, but
56101 the "@C:offset" is required in different SQL queries by the fast*34
56102 and pv34comp* programs.
56103 X
56104 Other changes:
56105 X
56106 Re-incorporation of GAP_OPEN option; fix to Altschul-Gish stats when
56107 GAP_OPEN is used.
56108 X
56109 Re-incorporation of A. Mackey's spam() improvement in dropnfa.
56110 X
56111 Fixes to include file ordering to allow fast*34(_t) pv34comp* programs
56112 to compile.
56113 X
56114 Fix to lascii[] for SQL database queries.
56115 X
56116 Fix to an old bug in comp_thr.c to send individual worker_info
56117 structures to threads (does not fix LINUX threads problems, however).
56118 X
56119 =====
56120 >>July 9, 2001
56121 X
56122 Considerable changes to support no-global library functions. 
56123 X
56124 (1) Separate ascii/sequence mapping arrays are used by the
56125 X    query-reading (qascii), library-reading (lascii), and sequence
56126 X    comparison function (pascii) routines.  As a result, there is no
56127 X    longer a need for tgetlib.o/lgetlib.o - lgetlib.o can serve both
56128 X    functions.
56129 X
56130 (2) This also allows us to remove all #ifdef TFAST/FASTX conditionals
56131 X    from complib.c/comp_thr.c/p2_complib.c.  We no longer need
56132 X    tcomp_thr.o, comp_thrx.o, etc.  We still have a variety of
56133 X    p2_complib.o variations to support the different c34.work* files.
56134 X
56135 (3) Because non-global openlib/getlib functions are available, exactly
56136 X    the same open/get functions are available for reading both the
56137 X    query and reference libraries in pv34comp* programs.  The
56138 X    host-specific openlib/getlib functions in hxgetaa.c are now
56139 X    provided by nmgetlib.c, etc. This has two effect:
56140 X
56141 X    (a) it is now possible to compare a query database generated by an
56142 X        SQL query to a library database generated by a different SQL
56143 X        query.
56144 X
56145 X    (b) pv34comp* has lost (at least in this version) the ability to
56146 X        automatically detect the query sequence type. To search with a
56147 X        DNA query, you MUST use "-n".
56148 X
56149 (4) the resetp() function is now responsible for almost all of the
56150 X    function sepcific (TFAST/FASTX/etc) initializations.  All of the
56151 X    function specific code has been removed from complib.c/comp_thr.c
56152 X    and most of it has been moved to initfa.c/resetp().
56153 X
56154 (5) manageacc.c has been merged into compacc.c (mostly prhist()).
56155 X
56156 =====
56157 >>June 1, 2001
56158 X
56159 Many changes to accommodate a new - no global variable - strategy for
56160 reading sequence databases.  Every time a file is opened, a struct
56161 lmf_str is allocated which can be used for memory mapped files, ncbl2,
56162 files, and mysql files.
56163 X
56164 In addition, an open'ed file has a default sequence type: DNA or
56165 protein, or one can open a file in a mode that will allow the sequence
56166 type to be changed.
56167 X
56168 =====
56169 >>May 18, 2001          CVS: fa33t09d0
56170 X
56171 A new compile time parameter - -DGAP_OPEN, is available to change the
56172 definition of the "-f gap-open" parameter from the penalty for the
56173 first residue in a gap to a true gap-open penalty, as is used in BLAST
56174 and many other comparison algorithms.  This will probably become the
56175 default for fasta in version 3.4.
56176 X
56177 Fixes to conflicts between "-S" and "-s matrix".  When a scoring
56178 matrix file was specified, lower-case alignments were not displayed
56179 with -S (although the scores were calculated properly).
56180 X
56181 More extensive testting of mysql_lib.c (mySQL query-libraries) with
56182 the pv4comp* and mp4comp* programs.
56183 X
56184 =====
56185 >>April 5, 2001         CVS: fa33t08d4b3
56186 X
56187 Changes in nmgetlib.c and ncbl2_mlib.c to return long sequence
56188 descriptions for PCOMPLIB (pv4/mp3comp*).  Also fix p2_complib.c to
56189 request DNA library for translated comparisons.
56190 X
56191 Fix for prss33(_t) to read both sequences from stdin.
56192 X
56193 =====
56194 >>March 27, 2001        CVS: fa33t08d4
56195 X
56196 Modifications to allow 64-bit fseek/ftell on machines like Sun,
56197 Linux/Intel, that support -D_FILE_OFFSET_BITS=64, -D_LARGE_FILE_SOURCE
56198 off_t, and fseeko(), ftello() with the option -DUSE_FSEEKO.  Machines
56199 with 64-bit long's do not need this option.  Machines with 32-bit
56200 longs that allow files >2 Gb can do so with 64-bit file access
56201 functions, including fseeko() and ftello(), which work with off_t file
56202 offsets instead of long's.
56203 X
56204 =====
56205 >>March 3, 2001         CVS: fa33t08d2
56206 X
56207 Corrected problems in nmgetaa.c and mysql_lib.c with parallel
56208 programs, and one serious problem with alternate DNA scoring matrices
56209 (initfa.c, initsw.c) not being set properly.  A subtle problem with
56210 the merge of scaleswn.c and scaleswg.c is fixed.
56211 X
56212 >>February 17, 2001
56213 X
56214 Modified mysql_lib.c to use "#", rather than "%ld", to indicate the
56215 position of the GID.  This change was made because sprintf() cannot be
56216 used reliably to generate an SQL string, as '"' and '%' are used in 
56217 such strings.
56218 X
56219 =====
56220 >>January 17, 2001
56221 (no version change, date change)
56222 X
56223 Minor fixes to initfa.c, initsw.c to deal with DNA scoring matrices
56224 properly. "-n -s dna.mat" is required for the sequence/matrix to be
56225 recognized as DNA.
56226 X
56227 >>January 16, 2001
56228 -->v34t00
56229 X
56230 Merge of the main CVS trunk - fa33t06 with the latest release branch,
56231 fa33t08.
56232 X
56233 In addition, PCOMPLIB mods have been made to mysql_lib.c.  Because
56234 p2_complib.c gets sequence description information during the first
56235 read of the database, the mysql_query must be changed to return:
56236 result[0]=GID, result[1]=description, result[2]=sequence.  In the
56237 PCOMPLIB case, the other SQL queries (for GID description, sequence)
56238 are not necessary but must still be provided.
56239 SHAR_EOF
56240 chmod 0644 readme.v34t0 ||
56241 echo 'restore of readme.v34t0 failed'
56242 Wc_c="`wc -c < 'readme.v34t0'`"
56243 test 66121 -eq "$Wc_c" ||
56244         echo 'readme.v34t0: original size 66121, current size' "$Wc_c"
56245 fi
56246 # ============= readme.w32 ==============
56247 if test -f 'readme.w32' -a X"$1" != X"-c"; then
56248         echo 'x - skipping readme.w32 (File already exists)'
56249 else
56250 echo 'x - extracting readme.w32 (Text)'
56251 sed 's/^X//' << 'SHAR_EOF' > 'readme.w32' &&
56252 October 6, 2006
56253 X
56254 The FASTA programs for Windows32 environments (WindowsNT, 2000, XP)
56255 has undergone a major upgrade, so that now all the programs in the
56256 Unix/MacOSX distribution are available to Windows users.  Moreover,
56257 Windows users with modern (SSE2 compatible) processors can run greatly
56258 accelerated versions of the Smith-Waterman ssearch program.
56259 X
56260 Moreover, these programs work both with FASTA formatted files, and
56261 NCBI BLAST formatted files.
56262 X
56263 The following programs are available:
56264 X
56265 X    fasta34.exe                protein-protein or DNA-DNA database searches
56266 X    fastf34.exe
56267 X    fastm34.exe
56268 X    fasts34.exe
56269 X    fastx34.exe                compare DNA query to protein library with frameshifts
56270 X    fasty34.exe                compare DNA query to protein library with frameshifts
56271 X    prfx34.exe
56272 X    prss34.exe         evaluate statistical significance using shuffles
56273 X    prss34sse2.exe
56274 X    ssearch34.exe      Smith-Waterman for prot-prot or DNA-DNA searches
56275 X    ssearch34sse2.exe  Smith-Waterman, accelerated with SSE2 extensions
56276 X    tfastf34.exe
56277 X    tfastm34.exe
56278 X    tfasts34.exe
56279 X    tfastx34.exe       compare protein to DNA library with frameshifts
56280 X    tfasty34.exe       compare protein to DNA library with frameshifts
56281 X
56282 Each of these programs also has a "threaded" version, which can run on
56283 multiple processors (or dual cores) if they are available.  However,
56284 they are built using the Unix pthreads API, so to use these programs,
56285 you must download the pthreadVC2.dll from:
56286 X
56287 ftp://sources.redhat.com/pub/pthreads-win32/dll-latest/lib/pthreadVC2.dll
56288 X
56289 see also http://sourceware.org/pthreads-win32/
56290 X
56291 X    fasta34_t.exe
56292 X    fastf34_t.exe
56293 X    fastm34_t.exe
56294 X    fasts34_t.exe
56295 X    fastx34_t.exe
56296 X    fasty34_t.exe
56297 X    prfx34_t.exe
56298 X    prss34_t.exe
56299 X    prss34sse2_t.exe
56300 X    ssearch34_t.exe
56301 X    ssearch34sse2_t.exe
56302 X    tfastf34_t.exe
56303 X    tfasts34_t.exe
56304 X    tfastx34_t.exe
56305 X    tfasty34_t.exe
56306 X
56307 Without that DLL, the threaded programs will not run at all. The
56308 current compilation supports two threads, and speeds up searches about
56309 2-fold on dual-core processors.
56310 X
56311 The programs have been tested with protein and DNA databases in FASTA
56312 format, PIR/GCG-text format, and Genbank flatfile format.  The program
56313 does not work properly with GCG binary format databases, but it seems
56314 unlikely that Windows users would need these. 
56315 X
56316 Be certain to use an program that can work with long file names when
56317 unpacking the program source files.
56318 X
56319 Please report bugs to:
56320 X
56321 X       wrp@virginia.edu
56322 SHAR_EOF
56323 chmod 0644 readme.w32 ||
56324 echo 'restore of readme.w32 failed'
56325 Wc_c="`wc -c < 'readme.w32'`"
56326 test 2402 -eq "$Wc_c" ||
56327         echo 'readme.w32: original size 2402, current size' "$Wc_c"
56328 fi
56329 # ============= res_stats.c ==============
56330 if test -f 'res_stats.c' -a X"$1" != X"-c"; then
56331         echo 'x - skipping res_stats.c (File already exists)'
56332 else
56333 echo 'x - extracting res_stats.c (Text)'
56334 sed 's/^X//' << 'SHAR_EOF' > 'res_stats.c' &&
56335 /* calculate stats from results file using scalesws.c */
56336 X
56337 #include <stdio.h>
56338 #include <stdlib.h>
56339 #include <string.h>
56340 X
56341 #include <limits.h>
56342 #include <math.h>
56343 X
56344 #define MAX_LLEN 200
56345 X
56346 #define LN_FACT 10.0
56347 X
56348 #include "defs.h"
56349 #include "structs.h"
56350 #include "param.h"
56351 X
56352 struct beststr {
56353 X  int score;   /* smith-waterman score */
56354 X  int sscore;  /* duplicate for compatibility with fasta */
56355 X  double comp;
56356 X  double H;
56357 X  double zscore;
56358 X  double escore;
56359 X  int n1;
56360 #ifndef USE_FTELLO
56361 X  long lseek;  /* position in library file */
56362 #else
56363 X  off_t lseek;
56364 #endif
56365 X  int cont;    /* offset into sequence */
56366 X  int frame;
56367 X  int lib;
56368 X  char libstr[13];
56369 } *bbp, *bestptr, **bptr, *best;
56370 X
56371 struct stat_str {
56372 X  int score;
56373 X  int n1;
56374 X  double comp;
56375 X  double H;
56376 };
56377 X
56378 static struct db_str qtt = {0l, 0l, 0};
56379 X
56380 char gstring2[MAX_STR];                  /* string for label */
56381 char gstring3[MAX_STR];
56382 char hstring1[MAX_STR];
56383 X
56384 FILE *outfd;
56385 X
56386 int nbest;      /* number of sequences better than bestcut in best */
56387 int bestcut=1;  /* cut off for getting into MAXBEST */
56388 int bestfull;
56389 X
56390 int dohist = 0;
56391 int zsflag = 1;
56392 int outtty=1;
56393 int llen=40;
56394 X
56395 /* statistics functions */
56396 extern void
56397 process_hist(struct stat_str *sptr, int nstat, struct pstruct pst,
56398 X            struct hist_str *hist, void **);
56399 extern void addhistz(double, struct hist_str *); /* scaleswn.c */
56400 void selectbestz(struct beststr **, int, int );
56401 X
56402 extern double zs_to_E(double, int, int, long, struct db_str);
56403 extern double zs_to_Ec(double zs, long entries);
56404 X
56405 extern double (*find_zp)(int score, int length, double comp, void *);
56406 X
56407 void prhist(FILE *, struct mngmsg, struct pstruct, struct hist_str, 
56408 X           int, struct db_str, char *);
56409 X
56410 int nshow=20, mshow=50, ashow= -1;
56411 double e_cut=10.0;
56412 X
56413 main(argc, argv)
56414 X     int argc; char **argv;
56415 {
56416 X  FILE *fin;
56417 X  char line[512];
56418 X  int max, icol, iarg, i, qsfnum, lsfnum, n0, n1, s[3], frame;
56419 X  double comp, H;
56420 X  int idup, ndup, max_s;
56421 X  char libstr[20], *bp;
56422 X  char bin_file[80];
56423 X  FILE *bout=NULL;
56424 X  struct mngmsg m_msg;         /* Message from host to manager */
56425 X  struct pstruct pst;
56426 X  struct stat_str *stats;
56427 X  int nstats;
56428 X  double zscor, mu, var;
56429 X
56430 #if defined(UNIX)
56431 X  outtty = isatty(1);
56432 #else
56433 X  outtty = 1;
56434 #endif
56435 X
56436 X  if (argc < 2 ) {
56437 X    fprintf(stderr," useage - res_stats -c col -r bin_file file\n");
56438 X    exit(1);
56439 X  }
56440 X
56441 X  m_msg.db.length = qtt.length = 0l;
56442 X  m_msg.db.entries = m_msg.db.carry = qtt.entries = qtt.carry = 0;
56443 X  m_msg.pstat_void = NULL;
56444 X  m_msg.hist.hist_a = NULL;
56445 X  m_msg.nohist = 0;
56446 X  m_msg.markx = 0;
56447 X
56448 X  pst.n0 = 200;                /* sensible dummy value */
56449 X  pst.zsflag = 1;
56450 X  pst.dnaseq = 0;
56451 X  pst.histint = 2;
56452 X
56453 X  bin_file[0]='\0';
56454 X  icol = 1;
56455 X  iarg = 1;
56456 X  ndup = 1;
56457 X  while (1) {
56458 X    if (argv[iarg][0]=='-' && argv[iarg][1]=='c') {
56459 X      sscanf(argv[iarg+1],"%d",&icol);
56460 X      iarg += 2;
56461 X    }
56462 X    else if (argv[iarg][0]=='-' && argv[iarg][1]=='r') {
56463 X      strncpy(bin_file,argv[iarg+1],sizeof(bin_file));
56464 X      iarg += 2;
56465 X    }
56466 X    else if (argv[iarg][0]=='-' && argv[iarg][1]=='z') {
56467 X      sscanf(argv[iarg+1],"%d",&pst.zsflag);
56468 X      iarg += 2;
56469 X    }
56470 X    else if (argv[iarg][0]=='-' && argv[iarg][1]=='n') {
56471 X      pst.dnaseq = 1;
56472 X      iarg += 1;
56473 X    }
56474 X    else if (argv[iarg][0]=='-' && argv[iarg][1]=='s') {
56475 X      sscanf(argv[iarg+1],"%d",&ndup);
56476 X      iarg += 2;
56477 X    }
56478 X    else if (argv[iarg][0]=='-' && argv[iarg][1]=='q') {
56479 X      outtty = 0;
56480 X      iarg += 1;
56481 X    }
56482 X    else break;
56483 X  }
56484 X
56485 X  icol--;
56486 X
56487 X  if ((fin=fopen(argv[iarg],"r"))==NULL) {
56488 X    fprintf(stderr," cannot open %s\n",argv[1]);
56489 X    exit(1);
56490 X  }
56491 X
56492 X  if (bin_file[0]!='\0' && ((bout=fopen(bin_file,"w"))==NULL)) {
56493 X    fprintf(stderr,"cannot open %s for output\n",bin_file);
56494 X  }
56495 X
56496 X  if ((stats =
56497 X       (struct stat_str *)malloc((MAXSTATS)*sizeof(struct stat_str)))==NULL)
56498 X    s_abort ("Cannot allocate stats struct","");
56499 X  nstats = 0;
56500 X
56501 X  initbest(MAXBEST+1); /* +1 required for select() */
56502 X
56503 X  for (nbest=0; nbest<MAXBEST+1; nbest++)
56504 X    bptr[nbest] = &best[nbest];
56505 X  bptr++; best++;
56506 X  best[-1].score= BIGNUM;
56507 X  
56508 X  nbest = 0;
56509 X
56510 X  pst.Lambda=0.232;
56511 X  pst.K = 0.11;
56512 X  pst.H = 0.34;
56513 X
56514 X  /* read the best scores from the results file */
56515 X
56516 X  max_s = -1;
56517 X  idup = 0;
56518 X
56519 X  /* get first line with sequence length */
56520 X  fgets(line,sizeof(line),fin);
56521 X  sscanf(line,"%d",&n0);
56522 X  if (n0 > 0) pst.n0 = n0;
56523 X
56524 X  while (fgets(line,sizeof(line),fin)!=NULL) {
56525 X    if (line[0]=='/' && line[1]=='*') {
56526 X      fputs(line,stdout);
56527 X      strncpy(gstring2,line,sizeof(gstring2));
56528 X      if ((bp=strchr(gstring2,'\n'))!=NULL) *bp = '\0';
56529 X      break;
56530 X    }
56531 X    if (line[0]==';') {
56532 X      if ((bp=strchr(line,'|'))!=NULL) qsfnum = atoi(bp+1);
56533 X      else continue;
56534 X      if ((bp=strchr(line,'('))!=NULL) {
56535 X       n0 = atoi(bp+1);
56536 X       pst.n0 = n0;
56537 X      }
56538 X      else {
56539 X       fprintf(stderr, "cannot find n0:\n %s\n",line);
56540 X       continue;
56541 X      }
56542 X    }
56543 X    else {
56544 X       sscanf(line,"%s %d %d %d %lf %lf %d %d %d",
56545 X              libstr,&lsfnum,&n1,&frame,&comp, &H, &s[0],&s[1],&s[2]);
56546 X       if (lsfnum==0 && n1==0) {
56547 X         fputs(line,stderr);
56548 X         continue;
56549 X       }
56550 X       if (n1 < 10 || s[icol]<=0) fputs(line,stderr);
56551 X       idup++;
56552 X
56553 X       if (s[icol] > max_s) max_s = s[icol];
56554 X       if (idup < ndup) continue;
56555 X
56556 X       m_msg.db.entries++;
56557 X       m_msg.db.length += n1;
56558 X
56559 X       if (dohist) addhistz(zscor=(*find_zp)(max_s,n1,comp,m_msg.pstat_void),
56560 X                            &m_msg.hist);
56561 X       else zscor = (double)max_s;
56562 X
56563 X       if (nstats < MAXSTATS) {
56564 X         stats[nstats].n1 = n1;
56565 X         stats[nstats].comp = comp;
56566 X         stats[nstats].H = H;
56567 X         stats[nstats++].score = max_s;
56568 X       }
56569 X
56570 X       else if (!dohist) {
56571 X         /*      do_bout(bout,stats,nstats); */
56572 X         process_hist(stats,nstats,pst,&m_msg.hist, &m_msg.pstat_void);
56573 X         for (i=0; i<nbest; i++)
56574 X           bptr[i]->zscore = 
56575 X             (*find_zp)(bptr[i]->score,bptr[i]->n1,bptr[i]->comp,
56576 X                        m_msg.pstat_void);
56577 X         dohist = 1;
56578 X       }
56579 X
56580 X       if (dohist) {
56581 X         zscor =(*find_zp)(max_s,n1,comp,m_msg.pstat_void);
56582 X         addhistz(zscor,&m_msg.hist);
56583 X       }
56584 X       else zscor = (double)max_s;
56585 X
56586 X       if (nbest >= MAXBEST) {
56587 X         bestfull = nbest-MAXBEST/4;
56588 X         selectz(bestfull-1,nbest);
56589 X         bestcut = (int)(bptr[bestfull-1]->zscore+0.5);
56590 X         nbest = bestfull;
56591 X       }
56592 X       bestptr = bptr[nbest];
56593 X       bestptr->score = max_s;
56594 X       bestptr->sscore = max_s;
56595 X       bestptr->n1 = n1;
56596 X       bestptr->comp = comp;
56597 X       bestptr->H = H;
56598 X       bestptr->lib = lsfnum;
56599 X       bestptr->zscore = zscor;
56600 X       strncpy(bestptr->libstr,libstr,12);
56601 X       bestptr->libstr[12]='\0';
56602 X       nbest++;
56603 X
56604 X       max_s = -1;
56605 X       idup = 0;
56606 X    }
56607 X  }    /* done with reading results */
56608 X
56609 X  if (!dohist) {
56610 X    if (nbest < 20) {
56611 X      zsflag = 0;
56612 X    }
56613 X    else {
56614 X      /*      do_bout(bout,stats,nstats); */
56615 X      process_hist(stats,nstats,pst,&m_msg.hist,&m_msg.pstat_void);
56616 X      for (i=0; i<nbest; i++)
56617 X       bptr[i]->zscore = 
56618 X         (*find_zp)(bptr[i]->score,bptr[i]->n1,bptr[i]->comp,m_msg.pstat_void);
56619 X      dohist = 1;
56620 X    }
56621 X  }
56622 X  
56623 X  printf(" using n0: %d\n",pst.n0);
56624 X
56625 X  /* print histogram, statistics */
56626 X
56627 X  m_msg.nbr_seq = m_msg.db.entries;
56628 X  pst.zdb_size = m_msg.db.entries;
56629 X  /* get_param(&pst, gstring2,gstring3); */
56630 X
56631 X  prhist(stdout,m_msg,pst,m_msg.hist,nstats,m_msg.db,gstring2);
56632 X
56633 X  if (!zsflag) sortbest();
56634 X  else {
56635 X    sortbestz(bptr,nbest);
56636 X    for (i=0; i<nbest; i++)
56637 X      bptr[i]->escore = zs_to_E(bptr[i]->zscore,bptr[i]->n1,pst.dnaseq,
56638 X                               pst.zdb_size, m_msg.db);
56639 X  }
56640 X  
56641 X  outfd = stdout;
56642 X  showbest(m_msg.db);  /* display best matches */
56643 }
56644 X
56645 initbest(nbest)         /* allocate arrays for best sort */
56646 X     int nbest;
56647 {
56648 X
56649 X  if ((best=(struct beststr *)calloc((size_t)nbest,sizeof(struct beststr)))
56650 X      == NULL) {fprintf(stderr,"cannot allocate best struct\n"); exit(1);}
56651 X  if ((bptr=(struct beststr **)calloc((size_t)nbest,sizeof(struct beststr *)))
56652 X      == NULL) {fprintf(stderr,"cannot allocate bptr\n"); exit(1);}
56653 }
56654 X
56655 void
56656 prhist(FILE *fd, struct mngmsg m_msg,
56657 X       struct pstruct pst, 
56658 X       struct hist_str hist, 
56659 X       int nstats,
56660 X       struct db_str ntt,
56661 X       char *gstring2)
56662 {
56663 X  int i,j,hl,hll, el, ell, ev;
56664 X  char hline[80], pch, *bp;
56665 X  int mh1, mht;
56666 X  int maxval, maxvalt, dotsiz, ddotsiz,doinset;
56667 X  double cur_e, prev_e, f_int;
56668 X  double max_dev, x_tmp;
56669 X  double db_tt;
56670 X  int n_chi_sq, cum_hl, max_i;
56671 X
56672 X
56673 X  fprintf(fd,"\n");
56674 X  
56675 X  if (pst.zsflag < 0 || nstats <= 10) {
56676 X    fprintf(fd, "%7ld residues in %5ld sequences\n", ntt.length,ntt.entries);
56677 X    fprintf(fd,"\n%s\n",gstring2);
56678 X    return;
56679 X  }
56680 X
56681 X  max_dev = 0.0;
56682 X  mh1 = hist.maxh-1;
56683 X  mht = (3*hist.maxh-3)/4 - 1;
56684 X
56685 X  if (!m_msg.nohist && mh1 > 0) {
56686 X    for (i=0,maxval=0,maxvalt=0; i<hist.maxh; i++) {
56687 X      if (hist.hist_a[i] > maxval) maxval = hist.hist_a[i];
56688 X      if (i >= mht &&  hist.hist_a[i]>maxvalt) maxvalt = hist.hist_a[i];
56689 X    }
56690 X    n_chi_sq = 0;
56691 X    cum_hl = -hist.hist_a[0];
56692 X    dotsiz = (maxval-1)/60+1;
56693 X    ddotsiz = (maxvalt-1)/50+1;
56694 X    doinset = (ddotsiz < dotsiz && dotsiz > 2);
56695 X
56696 X    if (pst.zsflag>=0)
56697 X      fprintf(fd,"       opt      E()\n");
56698 X    else 
56699 X      fprintf(fd,"     opt\n");
56700 X
56701 X    prev_e =  zs_to_Ec((double)(hist.min_hist-hist.histint/2),hist.entries);
56702 X    for (i=0; i<=mh1; i++) {
56703 X      pch = (i==mh1) ? '>' : ' ';
56704 X      pch = (i==0) ? '<' : pch;
56705 X      hll = hl = hist.hist_a[i];
56706 X      if (pst.zsflag>=0) {
56707 X       cum_hl += hl;
56708 X       f_int = (double)(i*hist.histint+hist.min_hist)+(double)hist.histint/2.0;
56709 X       cur_e = (double)zs_to_Ec(f_int,hist.entries);
56710 X       ev = el = ell = (int)(cur_e - prev_e + 0.5);
56711 X       if (hl > 0  && i > 5 && i < (90-hist.min_hist)/hist.histint) {
56712 X         x_tmp  = fabs(cum_hl - cur_e);
56713 X         if ( x_tmp > max_dev) {
56714 X           max_dev = x_tmp;
56715 X           max_i = i;
56716 X         }
56717 X         n_chi_sq++;
56718 X       }
56719 X       if ((el=(el+dotsiz-1)/dotsiz) > 60) el = 60;
56720 X       if ((ell=(ell+ddotsiz-1)/ddotsiz) > 40) ell = 40;
56721 X       fprintf(fd,"%c%3d %5d %5d:",
56722 X               pch,(i<mh1)?(i)*hist.histint+hist.min_hist :
56723 X               mh1*hist.histint+hist.min_hist,hl,ev);
56724 X      }
56725 X      else fprintf(fd,"%c%3d %5d :",
56726 X                  pch,(i<mh1)?(i)*hist.histint+hist.min_hist :
56727 X                  mh1*hist.histint+hist.min_hist,hl);
56728 X
56729 X      if ((hl=(hl+dotsiz-1)/dotsiz) > 60) hl = 60;
56730 X      if ((hll=(hll+ddotsiz-1)/ddotsiz) > 40) hll = 40;
56731 X      for (j=0; j<hl; j++) hline[j]='='; 
56732 X      if (pst.zsflag>=0) {
56733 X       if (el <= hl ) {
56734 X         if (el > 0) hline[el-1]='*';
56735 X         hline[hl]='\0';
56736 X       }
56737 X       else {
56738 X         for (j = hl; j < el; j++) hline[j]=' ';
56739 X         hline[el-1]='*';
56740 X         hline[hl=el]='\0';
56741 X       }
56742 X      }
56743 X      else hline[hl] = 0;
56744 X      if (i==1) {
56745 X       for (j=hl; j<10; j++) hline[j]=' ';
56746 X       sprintf(&hline[10]," one = represents %d library sequences",dotsiz);
56747 X      }
56748 X      if (doinset && i == mht-2) {
56749 X       for (j = hl; j < 10; j++) hline[j]=' ';
56750 X       sprintf(&hline[10]," inset = represents %d library sequences",ddotsiz);
56751 X      }
56752 X      if (i >= mht&& doinset ) {
56753 X       for (j = hl; j < 10; j++) hline[j]=' ';
56754 X       hline[10]=':';
56755 X       for (j = 11; j<11+hll; j++) hline[j]='=';
56756 X       hline[11+hll]='\0';
56757 X       if (pst.zsflag>=0) {
56758 X         if (ell <= hll) hline[10+ell]='*';
56759 X         else {
56760 X           for (j = 11+hll; j < 10+ell; j++) hline[j]=' ';
56761 X           hline[10+ell] = '*';
56762 X           hline[11+ell] = '\0';
56763 X         }
56764 X       }
56765 X      }
56766 X
56767 X      fprintf(fd,"%s\n",hline);
56768 X      prev_e = cur_e;
56769 X    }
56770 X  }
56771 X
56772 X  if (ntt.carry==0) {
56773 X    fprintf(fd, "%7ld residues in %5ld sequences\n", ntt.length, ntt.entries);
56774 X  }
56775 X  else {
56776 X    db_tt = (double)ntt.carry*(double)LONG_MAX + (double)ntt.length;
56777 X    fprintf(fd, "%.0f residues in %5ld library sequences\n", db_tt, ntt.entries);
56778 X  }
56779 X
56780 X  if (pst.zsflag>=0) {
56781 X    if (MAXSTATS < hist.entries)
56782 X      fprintf(fd," statistics extrapolated from %d to %ld sequences\n",
56783 X             MAXSTATS,hist.entries);
56784 X    /*    summ_stats(stat_info); */
56785 X    fprintf(fd," %s\n",hist.stat_info);
56786 X    if (!m_msg.nohist && cum_hl > 0)
56787 X      fprintf(fd," Kolmogorov-Smirnov  statistic: %6.4f (N=%d) at %3d\n",
56788 X             max_dev/(double)cum_hl, n_chi_sq,max_i*hist.histint+hist.min_hist);
56789 X    if (m_msg.markx & MX_M10FORM) {
56790 X      while ((bp=strchr(hist.stat_info,'\n'))!=NULL) *bp=' ';
56791 X      if (cum_hl <= 0) cum_hl = -1;
56792 X      sprintf(hstring1,"; mp_extrap: %d %ld\n; mp_stats: %s\n; mp_KS: %6.4f (N=%d) at %3d\n",
56793 X             MAXSTATS,hist.entries,hist.stat_info,max_dev/(double)cum_hl, n_chi_sq,max_i*hist.histint+hist.min_hist);
56794 X    }
56795 X  }
56796 X  fprintf(fd,"\n%s\n",gstring2);
56797 X  fflush(fd);
56798 }
56799 X
56800 showbest(struct db_str ntt)
56801 X  {
56802 X    int ib, istart, istop;
56803 X    char bline[200], fmt[40], pad[200];
56804 X    char rline[20];
56805 X    int ntmp;
56806 X    int lcont, ccont, loff;
56807 X    int hcutoff;
56808 X
56809 X    sprintf(fmt,"%%-%ds (%%3d)",llen-10);
56810 X
56811 X    nshow = min(20,nbest);
56812 X    mshow = min(20,nbest);
56813 X
56814 X    if (outtty) {
56815 X      printf(" How many scores would you like to see? [%d] ",nshow);
56816 X      fflush(stdout);
56817 X      if (fgets(rline,sizeof(rline),stdin)==NULL) exit(0);
56818 X      if (rline[0]!='\n' && rline[0]!=0) sscanf(rline,"%d",&nshow);
56819 X      if (nshow<=0) nshow = min(20,nbest);
56820 X    }
56821 X    else nshow=mshow;
56822 X
56823 X    memset(pad,' ',llen-10);
56824 X    pad[llen-31]='\0';
56825 X    if (zsflag)
56826 X      fprintf(outfd,"The best scores are:%s s-w Z-score E(%ld)\n",pad,ntt.entries);
56827 X    else
56828 X      fprintf(outfd,"The best scores are:%s s-w\n",pad);
56829 X
56830 X    if (outfd != stdout)
56831 X      if (zsflag)
56832 X       fprintf(stdout,"The best scores are:%s s-w Z-score E(%ld)\n",pad,ntt.entries);
56833 X      else
56834 X       fprintf(stdout,"The best scores are:%s s-w\n",pad);
56835 X
56836 X    istart = 0;
56837 X  l1:  istop = min(nbest,nshow);
56838 X  for (ib=istart; ib<istop; ib++) {
56839 X    bbp = bptr[ib];
56840 X
56841 X    if (!outtty && zsflag && bbp->escore > e_cut) {
56842 X      nshow = ib;
56843 X      goto done;
56844 X    }
56845 X
56846 X    sprintf(bline,"%-12s %d",bbp->libstr,bbp->lib);
56847 X    bline[13]='\0';
56848 X
56849 X    fprintf(outfd,fmt,bline,bbp->n1);
56850 X
56851 X    if (zsflag)
56852 X      fprintf(outfd,"%4d %4.1f %6.2g\n",
56853 X             bbp->score,bbp->zscore,
56854 X             bbp->escore);
56855 X    else 
56856 X      fprintf(outfd,"%4d\n",bbp->score);
56857 X
56858 X    if (outfd!=stdout) {
56859 X      fprintf(stdout,fmt,bline,bbp->n1);
56860 X      if (zsflag)
56861 X       printf("%4d %4.1f %6.2g\n",
56862 X              bbp->score,bbp->zscore,
56863 X              bbp->escore);
56864 X      else 
56865 X       printf("%4d\n",bbp->score);
56866 X    }
56867 X  }
56868 X
56869 X  fflush(outfd); if (outfd!=stdout) fflush(stdout);
56870 X
56871 X  if (outtty) {
56872 X    printf(" More scores? [0] ");
56873 X    fflush(stdout);
56874 X    if (fgets(rline,sizeof(rline),stdin)==NULL) exit(0);
56875 X    ntmp = 0;
56876 X    if (rline[0]!='\n' && rline[0]!=0) sscanf(rline,"%d",&ntmp);
56877 X    if (ntmp<=0) ntmp = 0;
56878 X    if (ntmp>0) {
56879 X      istart = istop;
56880 X      nshow += ntmp;
56881 X      mshow += ntmp;
56882 X      goto l1;
56883 X    }
56884 X  }
56885 X  else if (zsflag && bbp->escore < e_cut) {
56886 X    istart=istop;
56887 X    nshow += 10;
56888 X    goto l1;
56889 X  }
56890 X
56891 X  done:
56892 X  if (outfd!=stdout) fprintf(outfd,"\n");
56893 }
56894 X
56895 selectz(k,n)    /* k is rank in array */
56896 X     int k,n;
56897 {
56898 X  int t, i, j, l, r;
56899 X  double v;
56900 X  struct beststr *tmptr;
56901 X
56902 X  l=0; r=n-1;
56903 X
56904 X  while ( r > l ) {
56905 X    i = l-1;
56906 X    j = r;
56907 X    v = bptr[r]->zscore;
56908 X    do {
56909 X      while (bptr[++i]->zscore > v ) ;
56910 X      while (bptr[--j]->zscore < v ) ;
56911 X      tmptr = bptr[i]; bptr[i]=bptr[j]; bptr[j]=tmptr;
56912 X    } while (j > i);
56913 X    bptr[j]=bptr[i]; bptr[i]=bptr[r]; bptr[r]=tmptr;
56914 X    if (i>=k) r = i-1;
56915 X    if (i<=k) l = i+1;
56916 X  }
56917 }
56918 X
56919 sortbest()
56920 {
56921 X  int cmps(), cmp1(), cmpa(), cmpz();
56922 X  ksort(bptr,nbest,cmps);
56923 }
56924 X
56925 sortbeste()
56926 {
56927 X  int cmpe();
56928 X  ksort(bptr,nbest,cmpe);
56929 }
56930 X
56931 sortbestz()
56932 {
56933 X  int cmpz();
56934 X  ksort(bptr,nbest,cmpz);
56935 }
56936 X
56937 cmps(ptr1,ptr2)
56938 X     struct beststr *ptr1, *ptr2;
56939 {
56940 X  if (ptr1->score < ptr2->score) return (1);
56941 X  else if (ptr1->score > ptr2->score) return (-1);
56942 X  else return (0);
56943 }
56944 X
56945 cmpe(ptr1,ptr2)
56946 X     struct beststr *ptr1, *ptr2;
56947 {
56948 X  if (ptr1->escore < ptr2->escore) return (-1);
56949 X  else if (ptr1->escore > ptr2->escore) return (1);
56950 X  else return (0);
56951 }
56952 X
56953 cmpz(ptr1,ptr2)
56954 X     struct beststr *ptr1, *ptr2;
56955 {
56956 X  if (ptr1->zscore < ptr2->zscore) return (1);
56957 X  else if (ptr1->zscore > ptr2->zscore) return (-1);
56958 X  else return (0);
56959 }
56960 X
56961 ksort(v,n,comp)
56962 X     char *v[]; int n, (*comp)();
56963 {
56964 X  int gap, i, j;
56965 X  char *tmp;
56966 X       
56967 X  for (gap=n/2; gap>0; gap/=2)
56968 X    for (i=gap; i<n; i++)
56969 X      for (j=i-gap; j>=0; j -= gap) {
56970 X       if ((*comp)(v[j],v[j+gap]) <=0)
56971 X         break;
56972 X       tmp = v[j]; v[j]=v[j+gap]; v[j+gap]=tmp;
56973 X      }
56974 }
56975 X
56976 /*
56977 do_bout(FILE *bout,struct stat_str **bptr, int nbest)
56978 {
56979 X  int i, min_hist, max_hist;
56980 X  double mu, var;
56981 X
56982 X  if (bout==NULL) return;
56983 X
56984 X  inithist();
56985 X  for (i = 0; i<nbest; i++)
56986 X    addhist(bptr[i]->score,bptr[i]->n1);
56987 X
56988 X  for (i=0; i<MAX_LLEN; i++)
56989 X    if (llen_hist[i]>0) {
56990 X      min_hist=i;
56991 X      break;
56992 X    }
56993 X
56994 X  for (i=MAX_LLEN-1; i>=0; i--)
56995 X    if (llen_hist[i]>0) {
56996 X      max_hist=i;
56997 X      break;
56998 X    }
56999 X
57000 X  for (i=min_hist; i<=max_hist; i++) {
57001 X    mu=(double)score_sums[i]/(double)llen_hist[i];
57002 X    if (llen_hist[i]>1) {
57003 X      var = ((double)score2_sums[i]-(double)llen_hist[i]*mu*mu)/
57004 X       (double)(llen_hist[i]-1);
57005 X
57006 X      fprintf(bout,"%d\t%d\t%.1f\t%.1f\t%.1f\t%.4f\t%.4f\n",
57007 X             i,llen_hist[i],exp(((double)(i))/LN_FACT),
57008 X             score_sums[i],score2_sums[i],mu,var);
57009 X    }
57010 X  }
57011 X  free_hist();
57012 X  fclose(bout);
57013 }
57014 */
57015 X
57016 s_abort()
57017 {
57018 X  exit(1);
57019 }
57020 SHAR_EOF
57021 chmod 0644 res_stats.c ||
57022 echo 'restore of res_stats.c failed'
57023 Wc_c="`wc -c < 'res_stats.c'`"
57024 test 16277 -eq "$Wc_c" ||
57025         echo 'res_stats.c: original size 16277, current size' "$Wc_c"
57026 fi
57027 # ============= rna.mat ==============
57028 if test -f 'rna.mat' -a X"$1" != X"-c"; then
57029         echo 'x - skipping rna.mat (File already exists)'
57030 else
57031 echo 'x - extracting rna.mat (Text)'
57032 sed 's/^X//' << 'SHAR_EOF' > 'rna.mat' &&
57033 #  Sample rna matrix with +2 for G:A, TU:C
57034 X   A  C  G  T  U  R  Y  M  W  S  K  D  H  V  B  N  X 
57035 A  5 -4  2 -4 -4  2 -1  2  2 -1 -1  1  1  1 -2 -1 -1
57036 C -4  5 -4  2  2 -1  2  2 -1  2 -1 -2  1  1  1 -1 -1
57037 G  2 -4  5 -4 -4  2 -1 -1 -1  2  2  1 -2  1  1 -1 -1
57038 T -4  2 -4  5  5 -1  2 -1  2 -1  2  1  1 -2  1 -1 -1
57039 U -4  2 -4  5  5 -1  2 -1  2 -1  2  1  1 -2  1 -1 -1
57040 R  2 -1  2 -1 -1  2 -2 -1  1  1  1  1 -1  1 -1 -1 -1
57041 Y -1  2 -1  2  2 -2  2 -1  1  1  1 -1  1 -1  1 -1 -1
57042 M  2  2 -1 -1 -1 -1 -1  2  1  1 -1 -1  1  1 -1 -1 -1
57043 W  2 -1 -1  2  2  1  1  1  2 -1  1  1  1 -1 -1 -1 -1
57044 S -1  2  2 -1 -1  1  1  1 -1  2  1 -1 -1  1  1 -1 -1
57045 K -1 -1  2  2  2  1  1 -1  1  1  2  1 -1 -1  1 -1 -1
57046 D  1 -2  1  1  1  1 -1 -1  1 -1  1  1 -1 -1 -1 -1 -1
57047 H  1  1 -2  1  1 -1  1  1  1 -1 -1 -1  1 -1 -1 -1 -1
57048 V  1  1  1 -2 -2  1 -1  1 -1  1 -1 -1 -1  1 -1 -1 -1
57049 B -2  1  1  1  1 -1  1 -1 -1  1  1 -1 -1 -1  1 -1 -1
57050 N -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
57051 XX -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
57052 SHAR_EOF
57053 chmod 0644 rna.mat ||
57054 echo 'restore of rna.mat failed'
57055 Wc_c="`wc -c < 'rna.mat'`"
57056 test 998 -eq "$Wc_c" ||
57057         echo 'rna.mat: original size 998, current size' "$Wc_c"
57058 fi
57059 # ============= sc_to_e.c ==============
57060 if test -f 'sc_to_e.c' -a X"$1" != X"-c"; then
57061         echo 'x - skipping sc_to_e.c (File already exists)'
57062 else
57063 echo 'x - extracting sc_to_e.c (Text)'
57064 sed 's/^X//' << 'SHAR_EOF' > 'sc_to_e.c' &&
57065 X
57066 /* copyright (c) 1996, 1997, 1998, 1999 William R. Pearson and the
57067 X   U. of Virginia */
57068 X
57069 /* $Name: fa_34_26_5 $ - $Id: sc_to_e.c,v 1.2 2006/04/12 18:00:02 wrp Exp $ */
57070 X
57071 /* sc_to_e  uses statistical parameters from search and
57072 X           score, length, and database size to calculate E()
57073 */
57074 X
57075 #include <stdio.h>
57076 #include <stdlib.h>
57077 #include <math.h>
57078 X
57079 double mean_var, mu, rho;
57080 X
57081 main(argc, argv)
57082 X     int argc; char **argv;
57083 {
57084 X  char line[128];
57085 X  int score, length, db_size;
57086 X  double z_val, s_to_zv(), zv_to_E();
57087 X
57088 X  if (argc == 4) {
57089 X    sscanf(argv[1],"%lf",&rho);
57090 X    sscanf(argv[2],"%lf",&mu);
57091 X    sscanf(argv[3],"%lf",&mean_var);
57092 X  }
57093 X  else {
57094 X    fprintf(stderr," enter rho mu mean_var: ");
57095 X    fgets(line,sizeof(line),stdin);
57096 X    sscanf(line,"%lf %lf %lf",&rho, &mu, &mean_var);
57097 X  }
57098 X
57099 X  while (1) {
57100 X    fprintf(stderr," enter score length db_size: ");
57101 X    if (fgets(line,sizeof(line),stdin)==NULL) exit(0);
57102 X    if (line[0]=='\n') exit(0);
57103 X    sscanf(line,"%d %d %d",&score, &length, &db_size);
57104 X    if (db_size < 1) db_size = 50000;
57105 X
57106 X    z_val = s_to_zv(score, length);
57107 X
57108 X    printf(" s: %d (%d) E(%d): %4.2g\n",score,length,db_size,zv_to_E(z_val,db_size));
57109 X  }
57110 }
57111 X
57112 double s_to_zv(int score, int length)
57113 {
57114 X  return ((double)score - rho * log((double)length) - mu)/sqrt(mean_var);
57115 }
57116 X
57117 double zv_to_E(double zv, int db_size)
57118 {
57119 X  double e;
57120 X
57121 X  e = exp(-1.282554983 * zv - .577216);
57122 X  return (double)db_size * (e > .01 ? 1.0 - exp(-e) : e);
57123 }
57124 SHAR_EOF
57125 chmod 0644 sc_to_e.c ||
57126 echo 'restore of sc_to_e.c failed'
57127 Wc_c="`wc -c < 'sc_to_e.c'`"
57128 test 1427 -eq "$Wc_c" ||
57129         echo 'sc_to_e.c: original size 1427, current size' "$Wc_c"
57130 fi
57131 # ============= scaleswn.c ==============
57132 if test -f 'scaleswn.c' -a X"$1" != X"-c"; then
57133         echo 'x - skipping scaleswn.c (File already exists)'
57134 else
57135 echo 'x - extracting scaleswn.c (Text)'
57136 sed 's/^X//' << 'SHAR_EOF' > 'scaleswn.c' &&
57137 /* scaleswn.c */
57138 X
57139 /* $Name: fa_34_26_5 $ - $Id: scaleswn.c,v 1.60 2007/04/26 18:32:48 wrp Exp $ */
57140 X
57141 /* as of 24 Sept, 2000 - scaleswn uses no global variables */
57142 X
57143 /*
57144 X       Provide statistical estimates using an extreme value distribution
57145 X
57146 X       copyright (c) 1995, 1996, 2000 William R. Pearson
57147 X
57148 X       This code provides multiple methods for scaling sequence
57149 X       similarity scores to correct for length effects.
57150 X
57151 X       Currently, six methods are available:
57152 X
57153 X       pst.zsflag = 0 - no scaling  (AVE_STATS)
57154 X       pst.zsflag = 1 - regression-scaled scores (REG_STATS)
57155 X       pst.zsflag = 2 - (revised) MLE Lmabda/K scaled scores (MLE_STATS)
57156 X       pst.zsflag = 3 - scaling using Altschul's parameters (AG_STATS)
57157 X       pst.zsflag = 4 - regression-scaled with iterative outlier removal (REGI_STATS)
57158 X       pst.zsflag = 5 = like 1, but length scaled variance (REG2_STATS)
57159 X       pst.zsflag = 6 = like 2, but uses lambda composition/scale (MLE2_STATS)
57160 X       pst.zsflag = 11 = 10 + 1 - use random shuffles, method 1
57161 */
57162 X
57163 #include <stdio.h>
57164 #include <stdlib.h>
57165 #include <math.h>
57166 #include <string.h>
57167 X
57168 #include <limits.h>
57169 X
57170 #include "defs.h"
57171 #include "param.h"
57172 #include "structs.h"
57173 #ifndef PCOMPLIB
57174 #include "mw.h"
57175 #else
57176 #include "p_mw.h"
57177 #endif
57178 X
57179 #define MAXHIST 50
57180 #define MAX_LLEN 200
57181 #define LHISTC 5
57182 #define VHISTC 5
57183 #define MAX_SSCORE 300
57184 X
57185 #define LENGTH_CUTOFF 10 /* minimum database sequence length allowed, for fitting */
57186 X
57187 #define LN_FACT 10.0
57188 #ifndef M_LN2
57189 #define M_LN2 0.69314718055994530942
57190 #endif
57191 #define EULER_G 0.57721566490153286060
57192 #define PI_SQRT6 1.28254983016186409554
57193 X
57194 #ifndef M_SQRT2
57195 #define M_SQRT2 1.41421356237
57196 #endif
57197 #define LN200 5.2983173666
57198 #define ZS_MAX 400.0    /* used to prevent underflow on some machines */
57199 #define TOLERANCE 1.0e-12
57200 #define TINY 1.0e-6
57201 X
57202 /* used by AVE_STATS, REG_STATS, REGI_STATS, REG2_STATS*/
57203 struct rstat_str {
57204 X  double rho, rho_e, mu, mu_e, mean_var, var_e;  /* ?_e:std. error of ? */
57205 /* used by REG2_STATS */
57206 X  double rho2, mu2, var_cutoff;
57207 X  int n_trimmed; /* excluded because of high z-score */
57208 X  int n1_trimmed, nb_trimmed, nb_tot; /* excluded because of bin */
57209 };
57210 X
57211 /* used by AG_STATS, MLE_STATS */
57212 struct ag_stat_str {
57213 X  double K, Lambda, H, a_n0f, a_n0;
57214 };
57215 X
57216 /* used by MLE2_STATS */
57217 struct mle2_stat_str {
57218 X  double a_n0;
57219 X  double mle2_a0, mle2_a1, mle2_a2, mle2_b1;
57220 X  double ave_comp, max_comp, ave_H;
57221 };
57222 X
57223 struct pstat_str {
57224 X  double ngLambda, ngK, ngH;
57225 X  union {
57226 X    struct rstat_str rg;
57227 X    struct ag_stat_str ag;
57228 X    struct mle2_stat_str m2;
57229 X  } r_u;
57230 };
57231 X
57232 #define AVE_STATS 0     /* no length effect, only mean/variance */
57233 double find_zn(int score, double escore, int len, double comp, struct pstat_str *);
57234 X
57235 int proc_hist_n(struct stat_str *sptr, int n, 
57236 X               struct pstruct pst, struct hist_str *histp, int do_trim,
57237 X               struct pstat_str *);
57238 X
57239 #define REG_STATS 1     /* length-regression scaled */
57240 #define REGI_STATS 4    /* length regression, iterative */
57241 double find_zr(int score, double escore, int len, double comp, struct pstat_str *);
57242 int proc_hist_r(struct stat_str *sptr, int n,
57243 X               struct pstruct pst, struct hist_str *histp,
57244 X               int do_trim, struct pstat_str *pu);
57245 X
57246 #define MLE_STATS 2     /* MLE for lambda, K */
57247 double find_ze(int score, double escore, int len, double comp, struct pstat_str *);
57248 int proc_hist_ml(struct stat_str *sptr, int n,
57249 X                struct pstruct pst, struct hist_str *histp, int do_trim,
57250 X                struct pstat_str *);
57251 X
57252 #define AG_STATS 3      /* Altschul-Gish parameters */
57253 double find_za(int score, double escore, int len, double comp, struct pstat_str *);
57254 int proc_hist_a(struct stat_str *sptr, int n,
57255 X               struct pstruct pst, struct hist_str *histp, int do_trim,
57256 X               struct pstat_str *);
57257 X
57258 #define REG2_STATS 5    /* length regression on mean + variance */
57259 double find_zr2(int score, double escore, int len, double comp, struct pstat_str *);
57260 int proc_hist_r2(struct stat_str *sptr, int n,
57261 X                struct pstruct pst, struct hist_str *histp, int do_trim,
57262 X                struct pstat_str *);
57263 X
57264 #define MLE2_STATS 6    /* MLE stats using comp(lambda) */
57265 double find_ze2(int score, double escore, int length, double comp, struct pstat_str *);
57266 int proc_hist_ml2(struct stat_str *sptr, int n,
57267 X                 struct pstruct pst, struct hist_str *histp, int do_trim,
57268 X                 struct pstat_str *);
57269 X
57270 #ifdef USE_LNSTATS
57271 #define LN_STATS 2
57272 double find_zl(int score, double escore, int len, double comp, struct pstat_str *);
57273 int proc_hist_ln(struct stat_str *sptr, int n, 
57274 X                struct pstruct pst, struct hist_str *histp, int do_trim,
57275 X                struct pstat_str *);
57276 #endif
57277 X
57278 /* scaleswn.c local variables that belong in their own structure */
57279 X
57280 double (*find_zp)(int score, double escore, int len, double comp, struct pstat_str *) = &find_zr;
57281 X
57282 /* void s_sort (double **ptr, int nbest); */
57283 void ss_sort ( int *sptr, int n);
57284 X
57285 struct llen_str {
57286 X  int min, max;
57287 X  int max_score, min_score;
57288 X  int *hist;
57289 X  double *score_sums, *score2_sums;
57290 X  double *score_var;
57291 X  int max_length, min_length, zero_s;
57292 X  int fit_flag;
57293 };
57294 X
57295 static void inithist(struct llen_str *, struct pstruct, int);
57296 static void free_hist( struct llen_str *);
57297 static void addhist(struct llen_str *, int, int, int);
57298 static void prune_hist(struct llen_str *, int, int, int, long *);
57299 void inithistz(int, struct hist_str *histp);
57300 void addhistz(double zs, struct hist_str *histp);
57301 void addhistzp(double zs, struct hist_str *histp);
57302 X
57303 static void fit_llen(struct llen_str *, struct rstat_str *);
57304 static void fit_llen2(struct llen_str *, struct rstat_str *);
57305 static void fit_llens(struct llen_str *, struct rstat_str *);
57306 X
57307 extern void sortbeste(struct beststr **bptr, int nbest);
57308 X
57309 /* void set_db_size(int, struct db_str *, struct hist_str *); */
57310 X
57311 #ifdef DEBUG
57312 FILE *tmpf;
57313 #endif
57314 X
57315 int
57316 process_hist(struct stat_str *sptr, int nstats, 
57317 X            struct mngmsg m_msg,
57318 X            struct pstruct pst,
57319 X            struct hist_str *histp,
57320 X            struct pstat_str **ps_sp,
57321 X            int do_hist)
57322 {
57323 X  int zsflag, do_trim, i;
57324 X  struct pstat_str *ps_s;
57325 X
57326 X  if (pst.zsflag < 0) {
57327 X    *ps_sp = NULL;
57328 X    return pst.zsflag;
57329 X  }
57330 X
57331 X  if (*ps_sp == NULL) {
57332 X    if ((ps_s=(struct pstat_str *)calloc(1,sizeof(struct pstat_str)))==NULL) {
57333 X      fprintf(stderr," cannot allocate pstat_union: %ld\n",sizeof(struct pstat_str));
57334 X      exit(1);
57335 X    }
57336 X    else *ps_sp = ps_s;
57337 X  }
57338 X  else {
57339 X    ps_s = *ps_sp;
57340 X    memset(ps_s,0,sizeof(struct pstat_str));
57341 X  }
57342 X
57343 X  ps_s->ngLambda = m_msg.Lambda;
57344 X  ps_s->ngK = m_msg.K;
57345 X  ps_s->ngH = m_msg.H;
57346 X
57347 X  if (nstats < 10) pst.zsflag = AG_STATS;
57348 X
57349 X  zsflag = pst.zsflag;
57350 X
57351 /*
57352 #ifdef DEBUG
57353 X  if (pst.debug_lib) {
57354 X    tmpf=fopen("tmp_stats.res","w+");
57355 X    for (i=0; i<nstats; i++) fprintf(tmpf,"%d\t%d\n",sptr[i].score,sptr[i].n1);
57356 X    fclose(tmpf);
57357 X  }
57358 #endif
57359 */
57360 X
57361 X  if (zsflag >= 10) {
57362 X    zsflag -= 10;
57363 X    do_trim = 0;
57364 X  }
57365 X  else do_trim = 1;
57366 X
57367 #ifdef USE_LNSCALE
57368 X  if (zsflag==LN_STATS) {
57369 X    find_zp = &find_zl;
57370 X    pst.zsflag = proc_hist_ln(sptr, nstats, histp, do_trim, ps_s);
57371 X  }
57372 #else
57373 X  if (zsflag==MLE_STATS) {
57374 X    find_zp = &find_ze;
57375 X    pst.zsflag = proc_hist_ml(sptr, nstats, pst, histp, do_trim, ps_s);
57376 X  }
57377 #endif
57378 X  else if (zsflag==REG_STATS) {
57379 X    find_zp = &find_zr;
57380 X    pst.zsflag = proc_hist_r(sptr, nstats,pst, histp, do_trim,  ps_s);
57381 X  }
57382 X  else if (zsflag==AG_STATS) {
57383 X    find_zp = &find_za;
57384 X    pst.zsflag = proc_hist_a(sptr, nstats, pst, histp, do_trim,  ps_s);
57385 X  }
57386 X  else if (zsflag==REGI_STATS) {
57387 X    find_zp = &find_zr;
57388 X    pst.zsflag = proc_hist_r2(sptr,nstats, pst, histp, do_trim,  ps_s);
57389 X  }
57390 X  else if (zsflag==REG2_STATS) {
57391 X    find_zp = &find_zr2;
57392 X    pst.zsflag = proc_hist_r(sptr,nstats,pst, histp, do_trim,  ps_s);
57393 X  }
57394 #if !defined(TFAST) && !defined(FASTX)
57395 X  else if (zsflag == MLE2_STATS) {
57396 X    find_zp = &find_ze2;
57397 X    pst.zsflag = proc_hist_ml2(sptr, nstats, pst, histp, do_trim,  ps_s);
57398 X  }
57399 #endif
57400 X  else {       /* AVE_STATS */
57401 X    find_zp = &find_zn;
57402 X    pst.zsflag = proc_hist_n(sptr,nstats, pst, histp, do_trim,  ps_s);
57403 X  }
57404 X
57405 X  if (!do_hist) {
57406 X    histp->entries = nstats; /* db->entries = 0; */
57407 X    inithistz(MAXHIST, histp);
57408 X    for (i = 0; i < nstats; i++) {
57409 X      if (sptr[i].n1 < 0) sptr[i].n1 = -sptr[i].n1;
57410 X      addhistz(find_zp(sptr[i].score,sptr[i].escore,sptr[i].n1,sptr[i].comp,ps_s),
57411 X              histp);
57412 X    }
57413 X  }
57414 X  return pst.zsflag;
57415 }
57416 X
57417 int
57418 calc_thresh(struct pstruct pst, int nstats, 
57419 X           double Lambda, double K, double H, double *zstrim)
57420 {
57421 X  int max_hscore;
57422 X  double ave_n1, tmp_score, z, l_fact;
57423 X
57424 X  if (pst.dnaseq == SEQT_DNA || pst.dnaseq == SEQT_RNA) {
57425 X    ave_n1 = 5000.0;
57426 X    l_fact = 1.0;
57427 X  }
57428 X  else {
57429 X    ave_n1 = 400.0;
57430 X    l_fact = 0.7;
57431 X  }
57432 X
57433 /*  max_hscore = MAX_SSCORE; */
57434 /*  mean expected for pst.n0 * 400 for protein, 5000 for DNA */
57435 /*  we want a number of offsets that is appropriate for the database size so
57436 X    far (nstats)
57437 */
57438 X
57439 /*
57440 X  the calculation below sets a high-score threshold using an
57441 X  ungapped lambda, but errs towards the high-score side by using
57442 X  E()=0.001 and calculating with 0.70*lambda, which is the correct for
57443 X  going from ungapped to -12/-2 gapped lambda with BLOSUM50
57444 */
57445 X
57446 #ifndef NORMAL_DIST
57447 X  tmp_score = 0.01/((double)nstats*K*(double)pst.n0*ave_n1);
57448 X  tmp_score = -log(tmp_score)/(Lambda*l_fact);
57449 X  max_hscore = (int)(tmp_score+0.5);
57450 X
57451 X  z = 1.0/(double)nstats;
57452 X  z = (log(z)+EULER_G)/(- PI_SQRT6);
57453 #else
57454 X  max_hscore = 100;
57455 X  z = 5.0;
57456 #endif
57457 X  *zstrim = 10.0*z+50.0;
57458 X  return max_hscore;
57459 }
57460 X
57461 int
57462 proc_hist_r(struct stat_str *sptr, int nstats,
57463 X           struct pstruct pst, struct hist_str *histp,
57464 X           int do_trim, struct pstat_str *pu)
57465 {
57466 X  int i, max_hscore;
57467 X  double zs, ztrim;
57468 X  char s_string[128];
57469 X  struct llen_str llen;
57470 X  char *f_string;
57471 X  llen.fit_flag=1;
57472 X  llen.hist=NULL;
57473 X
57474 X  max_hscore = calc_thresh(pst, nstats, pu->ngLambda,
57475 X                          pu->ngK, pu->ngH, &ztrim);
57476 X
57477 X  inithist(&llen,pst,max_hscore);
57478 X
57479 X  f_string = &(histp->stat_info[0]);
57480 X
57481 X  for (i = 0; i<nstats; i++)
57482 X    addhist(&llen,sptr[i].score,sptr[i].n1, max_hscore);
57483 X
57484 X  if ((llen.max_score - llen.min_score) < 10) {
57485 X    free_hist(&llen);
57486 X    llen.fit_flag = 0;
57487 X    find_zp = &find_zn;
57488 X    return proc_hist_n(sptr, nstats, pst, histp, do_trim, pu);
57489 X  }
57490 X
57491 X  fit_llen(&llen, &(pu->r_u.rg)); /* now we have rho, mu, rho2, mu2, mean_var
57492 X                                to set the parameters for the histogram */
57493 X
57494 X  if (!llen.fit_flag) {        /* the fit failed, fall back to proc_hist_ml */
57495 X    free_hist(&llen);
57496 X    find_zp = &find_ze;
57497 X    return proc_hist_ml(sptr,nstats, pst, histp, do_trim, pu);
57498 X  }
57499 X
57500 X  pu->r_u.rg.n_trimmed= pu->r_u.rg.n1_trimmed = pu->r_u.rg.nb_trimmed = 0;
57501 X
57502 X  if (do_trim) {
57503 X    if (llen.fit_flag) {
57504 X      for (i = 0; i < nstats; i++) {
57505 X       zs = find_zr(sptr[i].score,sptr[i].escore,sptr[i].n1,sptr[i].comp, pu);
57506 X       if (zs < 20.0 || zs > ztrim) {
57507 X         pu->r_u.rg.n_trimmed++;
57508 X         prune_hist(&llen,sptr[i].score,sptr[i].n1, max_hscore,
57509 X                    &(histp->entries));
57510 X       }
57511 X      }
57512 X    }
57513 X
57514 X  /*  fprintf(stderr,"Z-trimmed %d entries with z > 5.0\n", pu->r_u.rg.n_trimmed); */
57515 X
57516 X    if (llen.fit_flag) fit_llens(&llen, &(pu->r_u.rg));
57517 X
57518 X  /*   fprintf(stderr,"Bin-trimmed %d entries in %d bins\n", pu->r_u.rg.n1_trimmed,pu->r_u.rg.nb_trimmed); */
57519 X  }
57520 X
57521 X  free_hist(&llen);
57522 X
57523 X  /* put all the scores in the histogram */
57524 X
57525 X  if (pst.zsflag < 10) s_string[0]='\0';
57526 X  else if (pst.zs_win > 0)
57527 X    sprintf(s_string,"(shuffled, win: %d)",pst.zs_win);
57528 X  else strncpy(s_string,"(shuffled)",sizeof(s_string));
57529 X
57530 X  if (pst.zsflag == REG2_STATS || pst.zsflag == 10+REG2_STATS) 
57531 X    sprintf(f_string,"%s Expectation_v fit: rho(ln(x))= %6.4f+/-%6.3g; mu= %6.4f+/-%6.3f;\n rho2=%6.2f; mu2= %6.2f, 0's: %d Z-trim: %d  B-trim: %d in %d/%d",
57532 X           s_string, pu->r_u.rg.rho*LN_FACT,sqrt(pu->r_u.rg.rho_e),pu->r_u.rg.mu,sqrt(pu->r_u.rg.mu_e),
57533 X           pu->r_u.rg.rho2,pu->r_u.rg.mu2,llen.zero_s,
57534 X           pu->r_u.rg.n_trimmed, pu->r_u.rg.n1_trimmed, pu->r_u.rg.nb_trimmed, pu->r_u.rg.nb_tot);
57535 X  else 
57536 X    sprintf(f_string,"%s Expectation_n fit: rho(ln(x))= %6.4f+/-%6.3g; mu= %6.4f+/-%6.3f\n mean_var=%6.4f+/-%6.3f, 0's: %d Z-trim: %d  B-trim: %d in %d/%d\n Lambda= %8.6f",
57537 X           s_string,
57538 X           pu->r_u.rg.rho*LN_FACT,sqrt(pu->r_u.rg.rho_e),pu->r_u.rg.mu,sqrt(pu->r_u.rg.mu_e), pu->r_u.rg.mean_var,sqrt(pu->r_u.rg.var_e),
57539 X           llen.zero_s, pu->r_u.rg.n_trimmed, pu->r_u.rg.n1_trimmed, pu->r_u.rg.nb_trimmed, pu->r_u.rg.nb_tot,
57540 X           PI_SQRT6/sqrt(pu->r_u.rg.mean_var));
57541 X  return REG_STATS;
57542 }
57543 X
57544 X
57545 int
57546 proc_hist_r2(struct stat_str *sptr, int nstats,
57547 X            struct pstruct pst, struct hist_str *histp,
57548 X            int do_trim, struct pstat_str *pu)
57549 {
57550 X  int i, nit, nprune, max_hscore;
57551 X  double zs, ztrim;
57552 X  char s_string[128];
57553 X  char *f_string;
57554 X  struct llen_str llen;
57555 X
57556 X  llen.fit_flag=1;
57557 X  llen.hist=NULL;
57558 X
57559 X  max_hscore = calc_thresh(pst, nstats, pu->ngLambda,
57560 X                          pu->ngK, pu->ngH, &ztrim);
57561 X
57562 X  inithist(&llen, pst,max_hscore);
57563 X  f_string = &(histp->stat_info[0]);
57564 X
57565 X  for (i = 0; i<nstats; i++)
57566 X    addhist(&llen,sptr[i].score,sptr[i].n1,max_hscore);
57567 X
57568 X  pu->r_u.rg.n_trimmed= pu->r_u.rg.n1_trimmed = pu->r_u.rg.nb_trimmed = 0;
57569 X  if (do_trim) nit = 5;
57570 X  else nit = 0;
57571 X
57572 X  while (nit-- > 0) {
57573 X    nprune = 0;
57574 X    fit_llen2(&llen, &(pu->r_u.rg));
57575 X
57576 X    for (i = 0; i < nstats; i++) {
57577 X      if (sptr[i].n1 < 0) continue;
57578 X      zs = find_zr(sptr[i].score,sptr[i].escore,sptr[i].n1,sptr[i].comp,pu);
57579 X      if (zs < 20.0 || zs > ztrim ) {
57580 X       nprune++;
57581 X       pu->r_u.rg.n_trimmed++;
57582 X       prune_hist(&llen,sptr[i].score,sptr[i].n1,max_hscore,
57583 X                  &(histp->entries));
57584 X       sptr[i].n1 = -sptr[i].n1;
57585 X      }
57586 X    }
57587 X    /*    fprintf(stderr," %d Z-trimmed at %d\n",nprune,nit); */
57588 X    if (nprune < LHISTC) { break; }
57589 X  }
57590 X
57591 X  fit_llen(&llen, &(pu->r_u.rg));
57592 X
57593 X  free_hist(&llen);
57594 X
57595 X  if (pst.zsflag < 10) s_string[0]='\0';
57596 X  else if (pst.zs_win > 0)
57597 X    sprintf(s_string,"(shuffled, win: %d)",pst.zs_win);
57598 X  else strncpy(s_string,"(shuffled)",sizeof(s_string));
57599 X
57600 X  sprintf(f_string,"%s Expectation_i fit: rho(ln(x))= %6.4f+/-%6.3g; mu= %6.4f+/-%6.3f;\n mean_var=%6.4f+/-%6.3f 0's: %d Z-trim: %d N-it: %d\n Lambda= %8.6f",
57601 X         s_string,
57602 X         pu->r_u.rg.rho*LN_FACT,sqrt(pu->r_u.rg.rho_e),pu->r_u.rg.mu,sqrt(pu->r_u.rg.mu_e),
57603 X         pu->r_u.rg.mean_var,sqrt(pu->r_u.rg.var_e),llen.zero_s,pu->r_u.rg.n_trimmed, nit,
57604 X         PI_SQRT6/sqrt(pu->r_u.rg.mean_var));
57605 X  return REGI_STATS;
57606 }
57607 X
57608 /* this procedure implements Altschul's pre-calculated values for lambda, K */
57609 X
57610 #include "alt_parms.h"
57611 X
57612 int
57613 look_p(struct alt_p parm[], int gap, int ext, 
57614 X       double *K, double *Lambda, double *H);
57615 X
57616 int
57617 proc_hist_a(struct stat_str *sptr, int nstats, 
57618 X           struct pstruct pst, struct hist_str *histp,
57619 X           int do_trim, struct pstat_str *pu)
57620 {
57621 X  double Lambda, K, H;
57622 X  char *f_string;
57623 X  int r_v;
57624 X  int t_gdelval, t_ggapval;
57625 X
57626 #ifdef OLD_FASTA_GAP
57627 X  t_gdelval = pst.gdelval;
57628 X  t_ggapval = pst.ggapval;
57629 #else
57630 X  t_gdelval = pst.gdelval+pst.ggapval;
57631 X  t_ggapval = pst.ggapval;
57632 #endif
57633 X
57634 X  f_string = &(histp->stat_info[0]);
57635 X
57636 X  if (strcmp(pst.pamfile,"BL50")==0 || strcmp(pst.pamfile,"BLOSUM50")==0)
57637 X      r_v = look_p(bl50_p,t_gdelval,t_ggapval,&K,&Lambda,&H);
57638 X  else if (strcmp(pst.pamfile,"BL62")==0 || strcmp(pst.pamfile,"BLOSUM62")==0)
57639 X      r_v = look_p(bl62_p,t_gdelval,t_ggapval,&K,&Lambda,&H);
57640 X  else if (strcmp(pst.pamfile,"BL80")==0 || strcmp(pst.pamfile,"BLOSUM80")==0)
57641 X      r_v = look_p(bl80_p,t_gdelval,t_ggapval,&K,&Lambda,&H);
57642 X  else if (strcmp(pst.pamfile,"P250")==0)
57643 X      r_v = look_p(p250_p,t_gdelval,t_ggapval,&K,&Lambda,&H);
57644 X  else if (strcmp(pst.pamfile,"P120")==0)
57645 X      r_v = look_p(p120_p,t_gdelval,t_ggapval,&K,&Lambda,&H);
57646 X  else if (strcmp(pst.pamfile,"MD_10")==0)
57647 X      r_v = look_p(md10_p,t_gdelval,t_ggapval,&K,&Lambda,&H);
57648 X  else if (strcmp(pst.pamfile,"MD_20")==0)
57649 X      r_v = look_p(md20_p,t_gdelval,t_ggapval,&K,&Lambda,&H);
57650 X  else if (strcmp(pst.pamfile,"MD_40")==0)
57651 X      r_v = look_p(md40_p,t_gdelval,t_ggapval,&K,&Lambda,&H);
57652 X  else if (strcmp(pst.pamfile,"DNA")==0 || strcmp(pst.pamfile,"+5/-4")==0)
57653 X      r_v = look_p(nt54_p,t_gdelval,t_ggapval,&K,&Lambda,&H);
57654 X  else if (strcmp(pst.pamfile,"+3/-2")==0)
57655 X      r_v = look_p(nt32_p,t_gdelval,t_ggapval,&K,&Lambda,&H);
57656 X  else if (strcmp(pst.pamfile,"+1/-3")==0)
57657 X      r_v = look_p(nt13_p,t_gdelval,t_ggapval,&K,&Lambda,&H);
57658 X  else r_v = 0;
57659 X
57660 X  pu->r_u.ag.Lambda = Lambda;
57661 X  pu->r_u.ag.K = K;
57662 X  pu->r_u.ag.H = H;
57663 X
57664 X  if (r_v == 0) {
57665 X    fprintf(stderr,"Parameters not available for: %s: %d/%d\n",
57666 X           pst.pamfile,t_gdelval,t_ggapval);
57667 X
57668 X    find_zp = &find_zr;
57669 X    return proc_hist_r(sptr, nstats,pst, histp, do_trim, pu);
57670 X  }
57671 X
57672 X  /*
57673 X    fprintf(stderr," the parameters are: Lambda: %5.3f K: %5.3f H: %5.3f\n",
57674 X           Lambda, K, H);
57675 X           */
57676 X
57677 X    pu->r_u.ag.a_n0 = (double)pst.n0;
57678 X    pu->r_u.ag.a_n0f = log (K * pu->r_u.ag.a_n0)/H;
57679 X
57680 X    sprintf(f_string,"Altschul/Gish params: n0: %d Lambda: %5.3f K: %5.3f H: %5.3f",
57681 X           pst.n0,Lambda, K, H);
57682 X    return AG_STATS;
57683 }
57684 X
57685 int 
57686 ag_parm(char *pamfile, int gdelval, int ggapval, struct pstat_str *pu)
57687 {
57688 X  double Lambda, K, H;
57689 X  int r_v;
57690 X
57691 X  if (strcmp(pamfile,"BL50")==0)
57692 X    r_v = look_p(bl50_p,gdelval,ggapval,&K,&Lambda,&H);
57693 X  else if (strcmp(pamfile,"BL62")==0)
57694 X      r_v = look_p(bl62_p,gdelval,ggapval,&K,&Lambda,&H);
57695 X  else if (strcmp(pamfile,"P250")==0)
57696 X      r_v = look_p(p250_p,gdelval,ggapval,&K,&Lambda,&H);
57697 X  else if (strcmp(pamfile,"P120")==0)
57698 X      r_v = look_p(p120_p,gdelval,ggapval,&K,&Lambda,&H);
57699 X  else if (strcmp(pamfile,"MD_10")==0)
57700 X      r_v = look_p(md10_p,gdelval,ggapval,&K,&Lambda,&H);
57701 X  else if (strcmp(pamfile,"MD_20")==0)
57702 X      r_v = look_p(md20_p,gdelval,ggapval,&K,&Lambda,&H);
57703 X  else if (strcmp(pamfile,"MD_40")==0)
57704 X      r_v = look_p(md40_p,gdelval,ggapval,&K,&Lambda,&H);
57705 X  else if (strcmp(pamfile,"DNA")==0 || strcmp(pamfile,"+5/-4")==0)
57706 X      r_v = look_p(nt54_p,gdelval,ggapval, &K,&Lambda,&H);
57707 X  else if (strcmp(pamfile,"+3/-2")==0)
57708 X      r_v = look_p(nt32_p,gdelval,ggapval, &K,&Lambda,&H);
57709 X  else if (strcmp(pamfile,"+1/-3")==0)
57710 X      r_v = look_p(nt13_p,gdelval,ggapval, &K,&Lambda,&H);
57711 X  else r_v = 0;
57712 X
57713 X  pu->r_u.ag.K = K;
57714 X  pu->r_u.ag.Lambda = Lambda;
57715 X  pu->r_u.ag.H = H;
57716 X
57717 X  if (r_v == 0) {
57718 X    fprintf(stderr,"Parameters not available for: %s: %d/%d\n",
57719 X           pamfile,gdelval,ggapval);
57720 X    }
57721 X  return r_v;
57722 }
57723 X
57724 int
57725 look_p(struct alt_p parm[], int gap, int ext,
57726 X       double *K, double *Lambda, double *H)
57727 {
57728 X  int i;
57729 X
57730 X  gap = -gap;
57731 X  ext = -ext;
57732 X
57733 X  if (gap > parm[1].gap) {
57734 X    *K = parm[0].K;
57735 X    *Lambda = parm[0].Lambda;
57736 X    *H = parm[0].H;
57737 X    return 1;
57738 X  }
57739 X
57740 X  for (i=1; parm[i].gap > 0; i++) {
57741 X    if (parm[i].gap > gap) continue;
57742 X    else if (parm[i].gap == gap && parm[i].ext > ext ) continue;
57743 X    else if (parm[i].gap == gap && parm[i].ext == ext) {
57744 X      *K = parm[i].K;
57745 X      *Lambda = parm[i].Lambda;
57746 X      *H = parm[i].H;
57747 X      return 1;
57748 X    }
57749 X    else break;
57750 X  }
57751 X  return 0;
57752 }
57753 X
57754 /* uncensored and censored maximum likelihood estimates developed
57755 X   by Aaron Mackey based on a preprint from Sean Eddy */
57756 X
57757 int mle_cen  (struct stat_str *, int, int, double, double *, double *);
57758 X
57759 int
57760 proc_hist_ml(struct stat_str *sptr, int nstats, 
57761 X            struct pstruct pst, struct hist_str *histp,
57762 X            int do_trim, struct pstat_str *pu)
57763 {
57764 X  double f_cen;
57765 X  char s_string[128];
57766 X  char *f_string;
57767 X
57768 X  f_string = &(histp->stat_info[0]);
57769 X  pu->r_u.ag.a_n0 = (double)pst.n0;
57770 X
57771 X  if (pst.zsflag < 10) s_string[0]='\0';
57772 X  else if (pst.zs_win > 0)
57773 X    sprintf(s_string,"(shuffled, win: %d)",pst.zs_win);
57774 X  else strncpy(s_string,"(shuffled)",sizeof(s_string));
57775 X
57776 X  if (!do_trim) {
57777 X    if (mle_cen(sptr, nstats, pst.n0, 0.0, &pu->r_u.ag.Lambda, &pu->r_u.ag.K) == -1)
57778 X      goto bad_mle;
57779 X    sprintf(f_string,"%s MLE statistics: Lambda= %6.4f;  K=%6.4g",
57780 X           s_string,pu->r_u.ag.Lambda,pu->r_u.ag.K);
57781 X  }
57782 X  else {
57783 X    if (nstats/20 > 1000) f_cen = 1000.0/(double)nstats;
57784 X    else f_cen = 0.05;
57785 X    if (mle_cen(sptr, nstats, pst.n0, f_cen, &pu->r_u.ag.Lambda, &pu->r_u.ag.K) == -1)
57786 X      goto bad_mle;
57787 X    sprintf(f_string,"MLE_cen statistics: Lambda= %6.4f;  K=%6.4g (cen=%d)",
57788 X           pu->r_u.ag.Lambda,pu->r_u.ag.K,(int)((double)nstats*f_cen));
57789 X  }    
57790 X
57791 X  return MLE_STATS;
57792 X bad_mle:
57793 X  find_zp = &find_zn;
57794 X  
57795 X  return proc_hist_n(sptr, nstats, pst, histp, do_trim, pu);
57796 }
57797 X
57798 int
57799 mle_cen2  (struct stat_str *, int, int, double, double *, double *, double *, double *);
57800 X
57801 X
57802 int
57803 proc_hist_ml2(struct stat_str *sptr, int nstats, 
57804 X             struct pstruct pst, struct hist_str *histp,
57805 X             int do_trim, struct pstat_str *pu)
57806 {
57807 X  int i, ns=0, nneg=0;
57808 X  double f_cen, ave_lambda;
57809 X  char s_string[128], ex_string[64];
57810 X  char *f_string;
57811 X
57812 X  f_string = &(histp->stat_info[0]);
57813 X  pu->r_u.m2.a_n0 = (double)pst.n0;
57814 X
57815 X  if (pst.zsflag < 10) s_string[0]='\0';
57816 X  else if (pst.zs_win > 0)
57817 X    sprintf(s_string,"(shuffled, win: %d)",pst.zs_win);
57818 X  else strncpy(s_string,"(shuffled)",sizeof(s_string));
57819 X
57820 X  pu->r_u.m2.ave_comp = 0.0;
57821 X  pu->r_u.m2.max_comp = -1.0;
57822 X
57823 X  ns = nneg = 0;
57824 X  for (i=0; i<nstats; i++) {
57825 X    if (sptr[i].comp > pu->r_u.m2.max_comp) pu->r_u.m2.max_comp = sptr[i].comp;
57826 X    if (sptr[i].comp > 0.0) {
57827 X      pu->r_u.m2.ave_comp += log(sptr[i].comp);
57828 X      ns++;
57829 X    }
57830 X    else nneg++;
57831 X  }
57832 X  pu->r_u.m2.ave_comp /= (double)ns;
57833 X  pu->r_u.m2.ave_comp = exp(pu->r_u.m2.ave_comp);
57834 X  for (i=0; i<nstats; i++) if (sptr[i].comp < 0.0) {
57835 X    sptr[i].comp = pu->r_u.m2.ave_comp;
57836 X  }
57837 X
57838 X  if (nneg > 0)
57839 X    sprintf(ex_string,"composition = -1 for %d sequences",nneg);
57840 X  else ex_string[0]='\0';
57841 X
57842 X  if (!do_trim) {
57843 X    if (mle_cen2(sptr, nstats, pst.n0, 0.0,
57844 X            &pu->r_u.m2.mle2_a0, &pu->r_u.m2.mle2_a1,
57845 X            &pu->r_u.m2.mle2_a2, &pu->r_u.m2.mle2_b1) == -1) goto bad_mle2;
57846 X    ave_lambda = 1.0/(pu->r_u.m2.ave_comp*pu->r_u.m2.mle2_b1);
57847 X
57848 X    sprintf(f_string,"%s MLE-2 statistics: a0= %6.4f;  a1=%6.4f; a2=%6.4f; b1=%6.4f\n  ave Lamdba: %6.4f",
57849 X           s_string, pu->r_u.m2.mle2_a0, pu->r_u.m2.mle2_a1, pu->r_u.m2.mle2_a2, pu->r_u.m2.mle2_b1,ave_lambda);
57850 X  }
57851 X  else {
57852 X    if (nstats/20 > 500) f_cen = 500.0/(double)nstats;
57853 X    else f_cen = 0.05;
57854 X    if (mle_cen2(sptr, nstats, pst.n0, f_cen, &pu->r_u.m2.mle2_a0, &pu->r_u.m2.mle2_a1, &pu->r_u.m2.mle2_a2, &pu->r_u.m2.mle2_b1)== -1) goto bad_mle2;
57855 X
57856 X    ave_lambda = 1.0/(pu->r_u.m2.ave_comp*pu->r_u.m2.mle2_b1);
57857 X
57858 X    sprintf(f_string,"%s MLE-2-cen statistics: a0= %6.4f;  a1=%6.4f; a2=%6.4f; b1=%6.4f (cen=%d)\n  ave Lambda:%6.4f",
57859 X           s_string, pu->r_u.m2.mle2_a0, pu->r_u.m2.mle2_a1, pu->r_u.m2.mle2_a2, pu->r_u.m2.mle2_b1, (int)((double)nstats*f_cen),ave_lambda);
57860 X  }    
57861 X
57862 X  return MLE2_STATS;
57863 X bad_mle2:
57864 X  find_zp = &find_zn;
57865 X  return proc_hist_n(sptr, nstats, pst, histp, do_trim, pu);
57866 }
57867 X
57868 double first_deriv_cen(double lambda, struct stat_str *sptr, 
57869 X                      int start, int stop,
57870 X                      double sumlenL, double cenL,
57871 X                      double sumlenH, double cenH);
57872 X
57873 double second_deriv_cen(double lambda, struct stat_str *sptr,
57874 X                       int start, int stop,
57875 X                       double sumlenL, double cenL,
57876 X                       double sumlenH, double cenH);
57877 X
57878 static void
57879 st_sort (struct stat_str *v, int n) {
57880 X   int gap, i, j;
57881 X   int tmp;
57882 X
57883 X   for (gap = 1; gap < n/3; gap = 3*gap +1) ;
57884 X
57885 X   for (; gap > 0; gap = (gap-1)/3)
57886 X      for (i = gap; i < n; i++)
57887 X        for (j = i - gap; j >= 0; j -= gap) {
57888 X          if (v[j].score <= v[j + gap].score) break;
57889 X
57890 X          tmp = v[j].score;
57891 X          v[j].score = v[j + gap].score;
57892 X          v[j + gap].score = tmp;
57893 X
57894 X          tmp = v[j].n1;
57895 X          v[j].n1 = v[j + gap].n1;
57896 X          v[j + gap].n1 = tmp;
57897 X        }
57898 }
57899 X
57900 /* sptr[].score, sptr[].n1; sptr[] must be sorted
57901 X   int n = total number of samples
57902 X   int M = length of query
57903 X   double fn = fraction of scores to be censored fn/2.0 from top, bottom
57904 X   double *Lambda = Lambda estimate
57905 X   double *K = K estimate
57906 */
57907 X
57908 #define MAX_NIT 100
57909 X
57910 int
57911 mle_cen(struct stat_str *sptr, int n, int M, double fc,
57912 X       double *Lambda, double *K) {
57913 X
57914 X  double sumlenL, sumlenH, cenL, cenH;
57915 X  double sum_s, sum2_s, mean_s, var_s, dtmp;
57916 X  int start, stop;
57917 X  int i, nf;
57918 X  int nit = 0;
57919 X  double deriv, deriv2, lambda, old_lambda, sum = 0.0;
57920 X  /*
57921 X   int sumlenL, int sumlenghtsR = sum of low (Left), right (High) seqs.
57922 X   int cenL, cenH = censoring score low, high 
57923 X  */
57924 X
57925 X  nf = (fc/2.0) * n;
57926 X  start = nf;
57927 X  stop = n - nf;
57928 X
57929 X  st_sort(sptr,n);
57930 X
57931 X  sum_s = sum2_s = 0.0;
57932 X  for (i=start; i<stop; i++) {
57933 X    sum_s += sptr[i].score;
57934 X  }
57935 X  dtmp = (double)(stop-start);
57936 X  mean_s = sum_s/dtmp;
57937 X
57938 X  for (i=start; i<stop; i++) {
57939 X    sum2_s += sptr[i].score * sptr[i].score;
57940 X  }
57941 X  var_s = sum2_s/(dtmp-1.0);
57942 X
57943 X  sumlenL = sumlenH = 0.0;
57944 X  for (i=0; i<start; i++) sumlenL += (double)sptr[i].n1;
57945 X  for (i=stop; i<n; i++) sumlenH += (double)sptr[i].n1;
57946 X
57947 X  if (nf > 0) {
57948 X    cenL = (double)sptr[start].score;
57949 X    cenH = (double)sptr[stop].score;
57950 X  }
57951 X  else {
57952 X    cenL = (double)sptr[start].score/2.0;
57953 X    cenH = (double)sptr[start].score*2.0;
57954 X  }
57955 X
57956 X  if (cenL >= cenH) return -1;
57957 X
57958 X  /* initial guess for lambda is 0.2 - this does not work for matrices
57959 X     with very different scales */
57960 X  /*  lambda = 0.2; */
57961 X  lambda = PI_SQRT6/sqrt(var_s);
57962 X  if (lambda > 1.0) {
57963 X    fprintf(stderr," Lambda initial estimate error: lambda: %6.4g; var_s: %6.4g\n",lambda,var_s);
57964 X    lambda = 0.2;
57965 X  }
57966 X
57967 X  do {
57968 X    deriv = first_deriv_cen(lambda, sptr, start, stop,
57969 X                           sumlenL, cenL, sumlenH, cenH);
57970 X    /*   (uncensored version)
57971 X        first_deriv(lambda, &sptr[start], stop - start))
57972 X    */
57973 X
57974 X    /*  (uncensored version)
57975 X    deriv2 = second_deriv(lambda, &sptr[start], stop-start);
57976 X    */
57977 X    deriv2 = second_deriv_cen(lambda, sptr, start, stop,
57978 X                            sumlenL, cenL, sumlenH, cenH); 
57979 X
57980 X    old_lambda = lambda;
57981 X    if (lambda - deriv/deriv2 > 0.0) lambda = lambda - deriv/deriv2;
57982 X    else lambda = lambda/2.0;
57983 X    nit++;
57984 X  } while (fabs((lambda - old_lambda)/lambda) > TINY && nit < MAX_NIT);
57985 X
57986 X  /*  fprintf(stderr," mle_cen nit: %d\n",nit); */
57987 X
57988 X  if (nit >= MAX_NIT) return -1;
57989 X  
57990 X  for(i = start; i < stop ; i++) {
57991 X    sum += (double) sptr[i].n1 * exp(- lambda * (double)sptr[i].score);
57992 X  }
57993 X
57994 X  *Lambda = lambda;
57995 X  /* 
57996 X  *K = (double)(stop-start)/((double)M*sum);
57997 X  */
57998 X  *K = (double)n/((double)M*
57999 X                 (sum+sumlenL*exp(-lambda*cenL)-sumlenH*exp(-lambda*cenH)));
58000 X  return 0;
58001 }
58002 X
58003 /*
58004 double
58005 first_deriv(double lambda, struct stat_str *sptr, int n) {
58006 X
58007 X  int i;
58008 X  double sum = 0.0, sum1 = 0.0, sum2 = 0.0;
58009 X  double s, l, es;
58010 X
58011 X  for(i = 0 ; i < n ; i++) {
58012 X    s = (double)sptr[i].score;
58013 X    l = (double)sptr[i].n1;
58014 X    es = exp(-lambda * s );
58015 X    sum += s;
58016 X    sum2 += l * es;
58017 X    sum1 += s * l * es;
58018 X  }
58019 X
58020 X  return (1.0/lambda) - (sum/(double)n) + (sum1/sum2);
58021 }
58022 */
58023 X
58024 /*
58025 double
58026 second_deriv(double lambda, struct stat_str *sptr, int n) {
58027 X  double sum1 = 0.0, sum2 = 0.0, sum3 = 0.0;
58028 X  double s, l, es;
58029 X  int i;
58030 X
58031 X  for(i = 0 ; i < n ; i++) {
58032 X    l = (double)sptr[i].n1;
58033 X    s = (double)sptr[i].score;
58034 X    es = exp(-lambda * s);
58035 X    sum2 += l * es;
58036 X    sum1 += l * s * es;
58037 X    sum3 += l * s * s * es;
58038 X  }
58039 X
58040 X  return ((sum1*sum1)/(sum2*sum2)) - (sum3/sum2) -  (1.0/(lambda*lambda));
58041 }
58042 */
58043 X
58044 double
58045 first_deriv_cen(double lambda, struct stat_str *sptr, int start, int stop,
58046 X               double sumlenL, double cenL, double sumlenH, double cenH) {
58047 X  int i;
58048 X  double sum = 0.0, sum1 = 0.0, sum2 = 0.0;
58049 X  double s, l, es;
58050 X
58051 X  for(i = start ; i < stop ; i++) {
58052 X    s = (double)sptr[i].score;
58053 X    l = (double)sptr[i].n1;
58054 X    es = exp(-lambda * s );
58055 X    sum += s;
58056 X    sum2 += l * es;
58057 X    sum1 += s * l * es;
58058 X  }
58059 X
58060 X  sum1 += sumlenL*cenL*exp(-lambda*cenL) - sumlenH*cenH*exp(-lambda*cenH);
58061 X  sum2 += sumlenL*exp(-lambda*cenL) - sumlenH*exp(-lambda*cenH);
58062 X
58063 X  return (1.0 / lambda) - (sum /(double)(stop-start)) + (sum1 / sum2);
58064 }
58065 X
58066 double
58067 second_deriv_cen(double lambda, struct stat_str *sptr, int start, int stop,
58068 X                double sumlenL, double cenL, double sumlenH, double cenH) {
58069 X
58070 X  double sum1 = 0.0, sum2 = 0.0, sum3 = 0.0;
58071 X  double s, l, es;
58072 X  int i;
58073 X
58074 X  for(i = start ; i < stop ; i++) {
58075 X    s = (double)sptr[i].score;
58076 X    l = (double)sptr[i].n1;
58077 X    es = exp(-lambda * s);
58078 X    sum2 += l * es;
58079 X    sum1 += l * s * es;
58080 X    sum3 += l * s * s * es;
58081 X  }
58082 X
58083 X  sum1 += sumlenL*cenL*exp(-lambda*cenL) - sumlenH*cenH*exp(-lambda*cenH);
58084 X  sum2 += sumlenL*exp(-lambda * cenL) -  sumlenH*exp(-lambda * cenH);
58085 X  sum3 += sumlenL*cenL*cenL * exp(-lambda * cenL) -
58086 X    sumlenH*cenH*cenH * exp(-lambda * cenH);
58087 X  return ((sum1 * sum1) / (sum2 * sum2)) - (sum3 / sum2)
58088 X    - (1.0 / (lambda * lambda));
58089 }
58090 X
58091 double mle2_func(double *params,
58092 X                double *consts,
58093 X                struct stat_str *values,
58094 X                int n, int start, int stop);
58095 X
58096 void simplex(double *fitparams,
58097 X            double *lambda,
58098 X            int nparam,
58099 X            double (*minfunc) (double *tryparams, double *consts, 
58100 X                               struct stat_str *data, int ndata,
58101 X                               int start, int stop),
58102 X            double *consts,
58103 X            void *data,
58104 X            int ndata, int start, int stop
58105 X            );
58106 X
58107 int
58108 mle_cen2(struct stat_str *sptr, int n, int M, double fc,
58109 X       double *a0, double *a1, double *a2, double *b1) {
58110 X
58111 X  double params[4], lambdas[4], consts[9];
58112 X  double avglenL, avglenH, avgcompL, avgcompH, cenL, cenH;
58113 X  int start, stop;
58114 X  int i, nf;
58115 X
58116 X  nf = (fc/2.0) * n;
58117 X  start = nf;
58118 X  stop = n - nf;
58119 X
58120 X  st_sort(sptr,n);
58121 X
58122 X  /* choose arithmetic or geometic mean for compositions by appropriate commenting */
58123 X
58124 X  if (nf > 0) {
58125 X    avglenL = avglenH = 0.0;
58126 X    avgcompL = avgcompH = 0.0;
58127 X    /* avgcompL = avgcompH = 1.0 */
58128 X    for (i=0; i<start; i++) {
58129 X      avglenL += (double)sptr[i].n1;
58130 X      avgcompL += (double)sptr[i].comp;
58131 X      /* avgcompL *= (double) sptr[i].comp; */
58132 X    }
58133 X    avglenL /= (double) start;
58134 X    avgcompL /= (double) start;
58135 X    /* avgcompL = pow(avgcompL, 1.0/(double) start); */
58136 X  
58137 X    for (i=stop; i<n; i++) {
58138 X      avglenH += (double)sptr[i].n1;
58139 X      avgcompH += (double)sptr[i].comp;
58140 X      /* avgcompH *= (double) sptr[i].comp; */
58141 X    }
58142 X    avglenH /= (double) (n - stop);
58143 X    avgcompH /= (double) (n - stop);
58144 X    /* avgcompL = pow(avgcompL, 1.0/(double) (n - stop)); */
58145 X
58146 X    cenL = (double)sptr[start].score;
58147 X    cenH = (double)sptr[stop].score;
58148 X    if (cenL >= cenH) return -1;
58149 X  }
58150 X  else {
58151 X    avglenL = avglenH = cenL = cenH = 0.0;
58152 X    avgcompL = avgcompH = 1.0;
58153 X  }
58154 X
58155 X  params[0] = 10.0;
58156 X  params[1] = -10.0;
58157 X  params[2] = 1.0;
58158 X  params[3] = 1.0;
58159 X
58160 X  lambdas[0] = 1.0;
58161 X  lambdas[1] = 0.5;
58162 X  lambdas[2] = 0.1;
58163 X  lambdas[3] = 0.01;
58164 X
58165 X  consts[0] = M;
58166 X  consts[1] = (double) start;
58167 X  consts[2] = (double) stop;
58168 X  consts[3] = cenL;
58169 X  consts[4] = cenH;
58170 X  consts[5] = avglenL;
58171 X  consts[6] = avglenH;
58172 X  consts[7] = avgcompL;
58173 X  consts[8] = avgcompH;
58174 X
58175 X  simplex(params, lambdas, 4,
58176 X         (double (*) (double *, double *, struct stat_str *, int, int, int) )mle2_func,
58177 X         consts, sptr, n, start, stop);
58178 X
58179 X  *a0 = params[0];
58180 X  *a1 = params[1];
58181 X  *a2 = params[2];
58182 X  *b1 = params[3];
58183 X
58184 X  return 0;
58185 }
58186 X
58187 double mle2_func(double *params,
58188 X                double *consts,
58189 X                struct stat_str *values,
58190 X                int n, int start, int stop
58191 X                ) {
58192 X
58193 X  double a0, a1, a2, b1, M;
58194 X  double score, length, comp;
58195 X  double cenL, cenH, avglenL, avglenH, avgcompL, avgcompH;
58196 X  double L, y;
58197 X
58198 X  int i;
58199 X
58200 X  a0 = params[0];
58201 X  a1 = params[1];
58202 X  a2 = params[2];
58203 X  b1 = params[3];
58204 X
58205 X  M = consts[0];
58206 X  /*
58207 X  start = (int) consts[1];
58208 X  stop = (int) consts[2];
58209 X  */
58210 X  cenL = consts[3];
58211 X  cenH = consts[4];
58212 X  avglenL = consts[5];
58213 X  avglenH = consts[6];
58214 X  avgcompL = consts[7];
58215 X  avgcompH = consts[8];
58216 X
58217 X  L = 0;
58218 X  y = 0;
58219 X
58220 X  if (start > 0) {
58221 X    y = -(cenL - (a0 + a1*avgcompL +a2*avgcompL*log(M*avglenL)))/(b1*avgcompL);
58222 X    L += (double) start * exp(y);
58223 X  }
58224 X
58225 X  for(i = start ; i < stop ; i++) {
58226 X    score = (double) values[i].score;
58227 X    length = (double) values[i].n1;
58228 X    comp = (double) values[i].comp;
58229 X
58230 X    y = - (score - (a0 + a1*comp + a2 * comp * log(M*length))) / (b1*comp);
58231 X
58232 X    L += -y + exp(y) + log(b1 * comp);
58233 X  }
58234 X
58235 X  if (stop < n) {
58236 X    y = -(cenH -(a0 + a1*avgcompH + a2*avgcompH*log(M*avglenH)))/(b1*avgcompH);
58237 X    L -= (double) (n - stop) * exp(y);
58238 X  }
58239 X  return L;
58240 }
58241 X
58242 /* Begin Nelder-Mead simplex code: */
58243 X
58244 double evalfunc(double **param,
58245 X               double *vals,
58246 X               double *psums,
58247 X               double *ptry,
58248 X               int nparam,
58249 X               double (*minfunc) (double *params, double *consts,
58250 X                                  struct stat_str *data, int ndata,
58251 X                                  int start, int stop),
58252 X               double *consts,
58253 X               void *data,
58254 X               int ndata, int start, int stop,
58255 X               int ihi,
58256 X               double factor);
58257 X
58258 void simplex(double *fitparams,
58259 X            double *lambda,
58260 X            int nparam,
58261 X            double (*minfunc) (double *tryparams, double *consts,
58262 X                               struct stat_str *data, int ndata, 
58263 X                               int start, int stop),
58264 X            double *consts,
58265 X            void *data,
58266 X            int ndata,
58267 X            int start,
58268 X            int stop
58269 X            )
58270 {
58271 X
58272 X  int i, j, ilo, ihi, inhi;
58273 X  double rtol, sum, tmp, ysave, ytry;
58274 X  double *psum, *vals, *ptry, **param;
58275 X
58276 X
58277 X  psum = (double *) calloc(nparam, sizeof(double));
58278 X  ptry = (double *) calloc(nparam, sizeof(double));
58279 X
58280 X  vals = (double *) calloc(nparam + 1, sizeof(double));
58281 X
58282 X  param = (double **) calloc(nparam + 1, sizeof(double *));
58283 X  param[0] = (double *) calloc((nparam + 1) * nparam, sizeof(double));
58284 X  for( i = 1 ; i < (nparam + 1) ; i++ ) {
58285 X    param[i] = param[0] + i * nparam;
58286 X  }
58287 X
58288 X  /* Get our N+1 initial parameter values for the simplex */
58289 X
58290 X  for( i = 0 ; i < nparam ; i++ ) {
58291 X    param[0][i] = fitparams[i];
58292 X  }
58293 X
58294 X  for( i = 1 ; i < (nparam + 1) ; i++ ) {
58295 X    for( j = 0 ; j < nparam ; j++ ) {
58296 X      param[i][j] = fitparams[j] + lambda[j] * ( (i - 1) == j ? 1 : 0 );
58297 X    }
58298 X  }
58299 X
58300 X  /* calculate initial values at the simplex nodes */
58301 X
58302 X  for( i = 0 ; i < (nparam + 1) ; i++ ) {
58303 X    vals[i] = minfunc(param[i], consts, data, ndata, start, stop);
58304 X  }
58305 X
58306 X  /* Begin Nelder-Mead simplex algorithm from Numerical Recipes in C */
58307 X
58308 X  for( j = 0 ; j < nparam ; j++ ) {
58309 X    for( sum = 0.0, i = 0 ; i < nparam + 1 ; i++ ) {
58310 X      sum += param[i][j];
58311 X    }
58312 X    psum[j] = sum;
58313 X  }
58314 X
58315 X
58316 X  while( 1 ) {
58317 /*
58318 X      determine which point is highest (ihi), next highest (inhi) and
58319 X      lowest (ilo) by looping over the points in the simplex
58320 */
58321 X    ilo = 0;
58322 X
58323 /*  ihi = vals[0] > vals[1] ? (inhi = 1, 0) : (inhi = 0, 1); */
58324 X    if(vals[0] > vals[1]) { ihi = 0; inhi = 1; }
58325 X    else { ihi = 1; inhi = 0; }
58326 X
58327 X    for( i = 0 ; i < nparam + 1 ; i++) {
58328 X      if( vals[i] <= vals[ilo] ) ilo = i;
58329 X      if( vals[i] > vals[ihi] ) {
58330 X       inhi = ihi;
58331 X       ihi = i;
58332 X      } else if ( vals[i] > vals[inhi] && i != ihi ) inhi = i;
58333 X    }
58334 X
58335 X    /* Are we finished? */
58336 X
58337 X    rtol = 2.0 * fabs(vals[ihi] - vals[ilo]) / 
58338 X      (fabs(vals[ihi]) + fabs(vals[ilo]) + TINY);
58339 X
58340 X    if( rtol < TOLERANCE ) {
58341 X
58342 /* put the best value and best parameters into the first index */
58343 X
58344 X      tmp = vals[0];
58345 X      vals[0] = vals[ilo];
58346 X      vals[ilo] = tmp;
58347 X
58348 X      for( i = 0 ; i < nparam ; i++ ) {
58349 X       tmp = param[0][i];
58350 X       param[0][i] = param[ilo][i];
58351 X       param[ilo][i] = tmp;
58352 X      }
58353 X
58354 X      /* et voila, c'est finis */
58355 X      break;
58356 X    }
58357 X
58358 X    /* Begin a new iteration */
58359 X
58360 X    /* first, extrapolate by -1 through the face of the simplex across from ihi */
58361 X
58362 X    ytry = evalfunc(param, vals, psum, ptry, nparam, minfunc, consts,
58363 X                   data, ndata, start, stop, ihi, -1.0);
58364 X
58365 X    if( ytry <= vals[ilo] ) {
58366 X
58367 X      /* Good result, try additional extrapolation by 2 */
58368 X
58369 X      ytry = evalfunc(param, vals, psum, ptry, nparam, minfunc, consts, 
58370 X                     data, ndata, start, stop, ihi, 2.0);
58371 X
58372 X    } else if ( ytry >= vals[inhi] ) {
58373 X
58374 X      /* no good, look for an intermediate lower point by contracting */
58375 X
58376 X      ysave = vals[ihi];
58377 X      ytry = evalfunc(param, vals, psum, ptry, nparam, minfunc, consts,
58378 X                     data, ndata, start, stop, ihi, 0.5);
58379 X
58380 X      if( ytry >= ysave ) {
58381 X
58382 X       /* Still no good.  Contract around lowest (best) point. */
58383 X
58384 X       for( i = 0 ; i < nparam + 1 ; i++ ) {
58385 X         if( i != ilo ) {
58386 X           for ( j = 0 ; j < nparam ; j++ ) {
58387 X             param[i][j] = psum[j] = 0.5 * (param[i][j] + param[ilo][j]);
58388 X           }
58389 X           vals[i] = minfunc(psum, consts, data, ndata, start, stop);
58390 X         }
58391 X       }
58392 X
58393 X
58394 X       for( j = 0 ; j < nparam ; j++ ) {
58395 X         for( sum = 0.0, i = 0 ; i < nparam + 1 ; i++ ) {
58396 X           sum += param[i][j];
58397 X         }
58398 X         psum[j] = sum;
58399 X       }
58400 X
58401 X      }
58402 X    }
58403 X  }
58404 X                          
58405 X  for( i = 0 ; i < nparam ; i++ ) {
58406 X    fitparams[i] = param[0][i];
58407 X  }
58408 X
58409 X  if (ptry!=NULL) {
58410 X    free(ptry);
58411 X    ptry=NULL;
58412 X  }
58413 X  free(param[0]);
58414 X  free(param);
58415 X  free(vals);
58416 X  free(psum);
58417 }
58418 X
58419 X
58420 double evalfunc(double **param,
58421 X               double *vals,
58422 X               double *psum,
58423 X               double *ptry,
58424 X               int nparam,
58425 X               double (*minfunc)(double *tryparam, double *consts,
58426 X                                 struct stat_str *data, int ndata,
58427 X                                 int start, int stop),
58428 X               double *consts,
58429 X               void *data,
58430 X               int ndata, int start, int stop,
58431 X               int ihi,
58432 X               double factor) {
58433 X
58434 X  int j;
58435 X  double fac1, fac2, ytry;
58436 X
58437 X
58438 X  fac1 = (1.0 - factor) / nparam;
58439 X  fac2 = fac1 - factor;
58440 X
58441 X  for( j = 0 ; j < nparam ; j++ ) {
58442 X    ptry[j] = psum[j] * fac1 - param[ihi][j] * fac2;
58443 X  }
58444 X
58445 X  ytry = minfunc(ptry, consts, data, ndata, start, stop);
58446 X
58447 X  if( ytry < vals[ihi] ) {
58448 X    vals[ihi] = ytry;
58449 X    for( j = 0 ; j < nparam ; j++ ) {
58450 X      psum[j] += ptry[j] - param[ihi][j];
58451 X      param[ihi][j] = ptry[j];
58452 X    }
58453 X  }
58454 X
58455 X  return ytry;
58456 }
58457 X
58458 /* end of Nelder-Mead simplex code */
58459 X
58460 int
58461 proc_hist_n(struct stat_str *sptr, int nstats,
58462 X           struct pstruct pst, struct hist_str *histp,
58463 X           int do_trim, struct pstat_str *pu)
58464 {
58465 X  int i, j;
58466 X  double s_score, s2_score, ssd, ztrim;
58467 X  int nit, max_hscore;
58468 X  char s_string[128];
58469 X  char *f_string;
58470 X
58471 X  f_string = &(histp->stat_info[0]);
58472 X
58473 X  max_hscore = calc_thresh(pst, nstats, pu->ngLambda,
58474 X                          pu->ngK, pu->ngH, &ztrim);
58475 X
58476 X  s_score = s2_score = 0.0;
58477 X
58478 X  for ( j = 0, i = 0; i < nstats; i++) {
58479 X    if (sptr[i].score > 0 && sptr[i].score <= max_hscore) {
58480 X      s_score += (ssd=(double)sptr[i].score);
58481 X      s2_score += ssd * ssd;
58482 X      j++;
58483 X    }
58484 X  }
58485 X
58486 X  if (j > 1 ) {
58487 X    pu->r_u.rg.mu = s_score/(double)j;
58488 X    pu->r_u.rg.mean_var = s2_score - (double)j * pu->r_u.rg.mu * pu->r_u.rg.mu;
58489 X    pu->r_u.rg.mean_var /= (double)(j-1);
58490 X  }
58491 X  else {
58492 X    pu->r_u.rg.mu = 50.0;
58493 X    pu->r_u.rg.mean_var = 10.0;
58494 X  }
58495 X  
58496 X  if (pu->r_u.rg.mean_var < 0.01) {
58497 X    pu->r_u.rg.mean_var = (pu->r_u.rg.mu > 1.0) ? pu->r_u.rg.mu: 1.0;
58498 X  }
58499 X
58500 X  /* now remove some scores */
58501 X
58502 X  nit = 5;
58503 X  while (nit-- > 0) {
58504 X    pu->r_u.rg.n_trimmed = 0;
58505 X
58506 X    for (i=0; i< nstats; i++) {
58507 X      if (sptr[i].n1 < 0) continue;
58508 X      ssd = find_zn(sptr[i].score,sptr[i].escore,sptr[i].n1,sptr[i].comp, pu);
58509 X      if (ssd > ztrim || ssd < 20.0) {
58510 X       /*      fprintf(stderr,"removing %3d %3d %4.1f\n",
58511 X               sptr[i].score, sptr[i].n1,ssd); */
58512 X       ssd = sptr[i].score;
58513 X       s_score -= ssd;
58514 X       s2_score -= ssd*ssd;
58515 X       j--;
58516 X       pu->r_u.rg.n_trimmed++;
58517 X       histp->entries--;
58518 X       sptr[i].n1 = -sptr[i].n1;
58519 X      }
58520 X    }
58521 X
58522 X    if (j > 1 ) {
58523 X      pu->r_u.rg.mu = s_score/(double)j;
58524 X      pu->r_u.rg.mean_var = s2_score - (double)j * pu->r_u.rg.mu * pu->r_u.rg.mu;
58525 X      pu->r_u.rg.mean_var /= (double)(j-1);
58526 X    }
58527 X    else {
58528 X      pu->r_u.rg.mu = 50.0;
58529 X      pu->r_u.rg.mean_var = 10.0;
58530 X    }
58531 X
58532 X    if (pu->r_u.rg.mean_var < 0.01) {
58533 X      pu->r_u.rg.mean_var = (pu->r_u.rg.mu > 1.0) ? pu->r_u.rg.mu: 1.0;
58534 X    }
58535 X
58536 X    if (pu->r_u.rg.n_trimmed < LHISTC) {
58537 X      /*
58538 X       fprintf(stderr,"nprune %d at %d\n",nprune,nit);
58539 X       */
58540 X      break;
58541 X    }
58542 X  }
58543 X
58544 X  if (pst.zsflag < 10) s_string[0]='\0';
58545 X  else if (pst.zs_win > 0)
58546 X    sprintf(s_string,"(shuffled, win: %d)",pst.zs_win);
58547 X  else strncpy(s_string,"(shuffled)",sizeof(s_string));
58548 X
58549 X  sprintf(f_string,"%s unscaled statistics: mu= %6.4f  var=%6.4f; Lambda= %6.4f",
58550 X         s_string, pu->r_u.rg.mu,pu->r_u.rg.mean_var,PI_SQRT6/sqrt(pu->r_u.rg.mean_var));
58551 X  return AVE_STATS;
58552 }
58553 X
58554 /*
58555 This routine calculates the maximum likelihood estimates for the
58556 extreme value distribution exp(-exp(-(-x-a)/b)) using the formula
58557 X
58558 X       <lambda> = x_m - sum{ x[i] * exp (-x[i]<lambda>)}/sum{exp (-x[i]<lambda>)}
58559 X       <a> = -<1/lambda> log ( (1/nlib) sum { exp(-x[i]/<lambda> } )
58560 X
58561 X       The <a> parameter can be transformed into and K
58562 X       of the formula: 1 - exp ( - K m n exp ( - lambda S ))
58563 X       using the transformation: 1 - exp ( -exp -(lambda S + log(K m n) ))
58564 X                       1 - exp ( -exp( - lambda ( S + log(K m n) / lambda))
58565 X
58566 X                       a = log(K m n) / lambda
58567 X                       a lambda = log (K m n)
58568 X                       exp(a lambda)  = K m n 
58569 X        but from above: a lambda = log (1/nlib sum{exp( -x[i]*lambda)})
58570 X        so:            K m n = (1/n sum{ exp( -x[i] *lambda)})
58571 X                       K = sum{}/(nlib m n )
58572 X
58573 */
58574 X
58575 void
58576 alloc_hist(struct llen_str *llen)
58577 {
58578 X  int max_llen, i;
58579 X  max_llen = llen->max;
58580 X
58581 X  if (llen->hist == NULL) {
58582 X    llen->hist = (int *)calloc((size_t)(max_llen+1),sizeof(int));
58583 X    llen->score_sums = (double *)calloc((size_t)(max_llen + 1),sizeof(double));
58584 X    llen->score2_sums =(double *)calloc((size_t)(max_llen + 1),sizeof(double));
58585 X    llen->score_var = (double *)calloc((size_t)(max_llen + 1),sizeof(double));
58586 X  }
58587 X
58588 X  for (i=0; i< max_llen+1; i++) {
58589 X      llen->hist[i] = 0;
58590 X      llen->score_var[i] = llen->score_sums[i] = llen->score2_sums[i] = 0.0;
58591 X  }
58592 }
58593 X  
58594 void
58595 free_hist(struct llen_str *llen)
58596 {
58597 X  if (llen->hist!=NULL) {
58598 X    free(llen->score_var);
58599 X    free(llen->score2_sums);
58600 X    free(llen->score_sums);
58601 X    free(llen->hist);
58602 X    llen->hist=NULL;
58603 X  }
58604 }
58605 X
58606 void
58607 inithist(struct llen_str *llen, struct pstruct pst, int max_hscore)
58608 {
58609 X  llen->max = MAX_LLEN;
58610 X
58611 X  llen->max_score = -1;
58612 X  llen->min_score=10000;
58613 X
58614 X  alloc_hist(llen);
58615 X
58616 X  llen->zero_s = 0;
58617 X  llen->min_length = 10000;
58618 X  llen->max_length = 0;
58619 }
58620 X
58621 void
58622 addhist(struct llen_str *llen, int score, int length, int max_hscore)
58623 {
58624 X  int llength; 
58625 X  double dscore;
58626 X
58627 X  if ( score<=0 || length < LENGTH_CUTOFF) {
58628 X    llen->min_score = 0;
58629 X    llen->zero_s++;
58630 X    return;
58631 X  }
58632 X
58633 X  if (score < llen->min_score) llen->min_score = score;
58634 X  if (score > llen->max_score) llen->max_score = score;
58635 X
58636 X  if (length > llen->max_length) llen->max_length = length;
58637 X  if (length < llen->min_length) llen->min_length = length;
58638 X  if (score > max_hscore) score = max_hscore;
58639 X
58640 X  llength = (int)(LN_FACT*log((double)length)+0.5);
58641 X
58642 X  if (llength < 0 ) llength = 0;
58643 X  if (llength > llen->max) llength = llen->max;
58644 X  llen->hist[llength]++;
58645 X  dscore = (double)score;
58646 X  llen->score_sums[llength] += dscore;
58647 X  llen->score2_sums[llength] += dscore * dscore;
58648 }
58649 X
58650 /* histogram will go from z-scores of 20 .. 100 with mean 50 and z=10 */
58651 X
58652 void
58653 inithistz(int mh, struct hist_str *histp )
58654 {
58655 X  int i;
58656 X
58657 X  histp->z_calls = 0;
58658 X
58659 X  histp->min_hist = 20;
58660 X  histp->max_hist = 120;
58661 X
58662 X  histp->histint = (int)
58663 X    ((double)(histp->max_hist - histp->min_hist + 2)/(double)mh+0.5);
58664 X  histp->maxh = (int)
58665 X    ((double)(histp->max_hist - histp->min_hist + 2)/(double)histp->histint+0.5);
58666 X
58667 X  if (histp->hist_a==NULL) {
58668 X    if ((histp->hist_a=(int *)calloc((size_t)histp->maxh,sizeof(int)))==
58669 X       NULL) {
58670 X      fprintf(stderr," cannot allocate %d for histogram\n",histp->maxh);
58671 X      histp->histflg = 0;
58672 X    }
58673 X    else histp->histflg = 1;
58674 X  }
58675 X  else {
58676 X    for (i=0; i<histp->maxh; i++) histp->hist_a[i]=0;
58677 X  }
58678 X  histp->entries = 0;
58679 }
58680 X
58681 static double nrv[100]={
58682 X  0.3098900570,-0.0313400923, 0.1131975903,-0.2832547606, 0.0073672659,
58683 X  0.2914489107, 0.4209306311,-0.4630181404, 0.3326537896, 0.0050140359,
58684 X -0.1117435426,-0.2835630301, 0.2302997065,-0.3102716394, 0.0819894916,
58685 X -0.1676455701,-0.3782225018,-0.3204509938,-0.3594969187,-0.0308950398,
58686 X  0.2922813812, 0.1337170751, 0.4666577031,-0.2917784349,-0.2438179916,
58687 X  0.3002301394, 0.0231147123, 0.5687927366,-0.2318208709,-0.1476839273,
58688 X -0.0385043851,-0.1213476523, 0.1486341995, 0.1027917167, 0.1409192644,
58689 X -0.3280652579, 0.4232041455, 0.0775993309, 0.1159071787, 0.2769424442,
58690 X  0.3197284751, 0.1507346903, 0.0028580909, 0.4825103412,-0.0496843610,
58691 X -0.2754357656, 0.6021881753,-0.0816123956,-0.0899148991, 0.4847183201,
58692 X  0.2151621865,-0.4542246220, 0.0690709102, 0.2461894193, 0.2126042295,
58693 X -0.0767060668, 0.4819746149, 0.3323031326, 0.0177600676, 0.1143185210,
58694 X  0.2653977455, 0.0921872958,-0.1330986718, 0.0412287716,-0.1691604748,
58695 X -0.0529679078,-0.0194157955,-0.6117493924, 0.1199067932, 0.0210243193,
58696 X -0.5832259838,-0.1685528664, 0.0008591271,-0.1120347822, 0.0839125069,
58697 X -0.2787486831,-0.1937017962,-0.1915733940,-0.7888453635,-0.3316745163,
58698 X  0.1180885226,-0.3347001067,-0.2477492636,-0.2445697600, 0.0001342482,
58699 X -0.0015759812,-0.1516473992,-0.5202267615, 0.2136975210, 0.2500423188,
58700 X -0.2402926401,-0.1094186280,-0.0618869933,-0.0815221188, 0.2623337275,
58701 X  0.0219427302 -0.1774469919, 0.0828245026,-0.3271952808,-0.0632898028};
58702 X
58703 void
58704 addhistz(double zs, struct hist_str *histp)
58705 {
58706 X  int ih, zi;
58707 X  double rv;
58708 X
58709 X   rv = nrv[histp->z_calls++ % 100];
58710 X  zi = (int)(zs + 0.5+rv );
58711 X
58712 X  if ((zi >= 0) && (zi <= 120)) histp->entries++;
58713 X
58714 X  if (zi < histp->min_hist) zi = histp->min_hist;
58715 X  if (zi > histp->max_hist) zi = histp->max_hist;
58716 X  
58717 X  ih = (zi - histp->min_hist)/histp->histint;
58718 X
58719 X  histp->hist_a[ih]++;
58720 }
58721 X
58722 /* addhistzp() does not increase histp->entries since addhist did it already */
58723 /*
58724 void
58725 addhistzp(double zs, struct hist_str *histp)
58726 {
58727 X  int ih, zi;
58728 X  double rv;
58729 X
58730 X  rv = nrv[histp->z_calls++ %100];
58731 X  zi = (int)(zs + 0.5 + rv);
58732 X
58733 X  if (zi < histp->min_hist) zi = histp->min_hist;
58734 X  if (zi > histp->max_hist) zi = histp->max_hist;
58735 X  
58736 X  ih = (zi - histp->min_hist)/histp->histint;
58737 X
58738 X  histp->hist_a[ih]++;
58739 }
58740 */
58741 X
58742 void
58743 prune_hist(struct llen_str *llen, int score, int length, int max_hscore,
58744 X          long *entries)
58745 {
58746 X  int llength;
58747 X  double dscore;
58748 X
58749 X  if (score <= 0 || length < LENGTH_CUTOFF) return;
58750 X
58751 X  if (score > max_hscore) score = max_hscore;
58752 X
58753 X  llength = (int)(LN_FACT*log((double)length)+0.5);
58754 X
58755 X  if (llength < 0 ) llength = 0;
58756 X  if (llength > llen->max) llength = llen->max;
58757 X  llen->hist[llength]--;
58758 X  dscore = (double)score;
58759 X  llen->score_sums[llength] -= dscore;
58760 X  llen->score2_sums[llength] -= dscore * dscore;
58761 X
58762 /*  (*entries)--; histp->entries is not yet initialized */
58763 }  
58764 X
58765 /* fit_llen: no trimming
58766 X   (1) regress scores vs log(n) using weighted variance
58767 X   (2) calculate mean variance after length regression
58768 */
58769 X
58770 void
58771 fit_llen(struct llen_str *llen, struct rstat_str *pr)
58772 {
58773 X  int j;
58774 X  int n;
58775 X  int n_size;
58776 X  double x, y2, u, z;
58777 X  double mean_x, mean_y, var_x, var_y, covar_xy;
58778 X  double mean_y2, covar_xy2, var_y2, dllj;
58779 X
58780 X  double sum_x, sum_y, sum_x2, sum_xy, sum_v, det, n_w;
58781 X  
58782 /* now fit scores to best linear function of log(n), using
58783 X   simple linear regression */
58784 X  
58785 X  for (llen->min=0; llen->min < llen->max; llen->min++)
58786 X    if (llen->hist[llen->min]) break;
58787 X  llen->min--;
58788 X
58789 X  for (n_size=0,j = llen->min; j < llen->max; j++) {
58790 X    if (llen->hist[j] > 1) {
58791 X      dllj = (double)llen->hist[j];
58792 X      llen->score_var[j] = llen->score2_sums[j]/dllj
58793 X       - (llen->score_sums[j]/dllj)*(llen->score_sums[j]/dllj);
58794 X      llen->score_var[j] /= (double)(llen->hist[j]-1);
58795 X      if (llen->score_var[j] <= 0.1 ) llen->score_var[j] = 0.1;
58796 X      n_size++;
58797 X    }
58798 X  }
58799 X
58800 X  pr->nb_tot = n_size;
58801 X
58802 X  n_w = 0.0;
58803 X  sum_x = sum_y = sum_x2 = sum_xy = sum_v = 0;
58804 X  for (j = llen->min; j < llen->max; j++)
58805 X    if (llen->hist[j] > 1) {
58806 X      x = j + 0.5;
58807 X      dllj = (double)llen->hist[j];
58808 X      n_w += dllj/llen->score_var[j];
58809 X      sum_x +=   dllj * x / llen->score_var[j] ;
58810 X      sum_y += llen->score_sums[j] / llen->score_var[j];
58811 X      sum_x2 +=  dllj * x * x /llen->score_var[j];
58812 X      sum_xy +=  x * llen->score_sums[j]/llen->score_var[j];
58813 X    }
58814 X
58815 X  if (n_size < 5 ) {
58816 X    llen->fit_flag=0;
58817 X    pr->rho = 0;
58818 X    pr->mu = sum_y/n_w;
58819 X    return;
58820 X  }
58821 X  else {
58822 X    det = n_w * sum_x2 - sum_x * sum_x;
58823 X    if (det > 0.001) {
58824 X      pr->rho = (n_w * sum_xy  - sum_x * sum_y)/det;
58825 X      pr->rho_e = n_w/det;
58826 X      pr->mu = (sum_x2 * sum_y - sum_x * sum_xy)/det;
58827 X      pr->mu_e = sum_x2/det;
58828 X    }
58829 X    else {
58830 X      llen->fit_flag = 0;
58831 X      pr->rho = 0;
58832 X      pr->mu = sum_y/n_w;
58833 X      return;
58834 X    }
58835 X  }
58836 X
58837 X  det = n_w * sum_x2 - sum_x * sum_x;
58838 X  pr->rho = (n_w * sum_xy  - sum_x * sum_y)/det;
58839 X  pr->mu = (sum_x2 * sum_y - sum_x * sum_xy)/det;
58840 X
58841 X  n = 0;
58842 X  mean_x = mean_y = mean_y2 = 0.0;
58843 X  var_x = var_y = 0.0;
58844 X  covar_xy = covar_xy2 = 0.0;
58845 X
58846 X  for (j = llen->min; j <= llen->max; j++) 
58847 X   if (llen->hist[j] > 1 ) {
58848 X      n += llen->hist[j];
58849 X      x = (double)j + 0.5;
58850 X      mean_x += (double)llen->hist[j] * x;
58851 X      mean_y += llen->score_sums[j];
58852 X      var_x += (double)llen->hist[j] * x * x;
58853 X      var_y += llen->score2_sums[j];
58854 X      covar_xy += x * llen->score_sums[j];
58855 X    }
58856 X  mean_x /= n; mean_y /= n;
58857 X  var_x = var_x / n - mean_x * mean_x;
58858 X  var_y = var_y / n - mean_y * mean_y;
58859 X  
58860 X  covar_xy = covar_xy / n - mean_x * mean_y;
58861 /*
58862 X  pr->rho = covar_xy / var_x;
58863 X  pr->mu = mean_y - pr->rho * mean_x;
58864 */
58865 X  mean_y2 = covar_xy2 = var_y2 = 0.0;
58866 X  for (j = llen->min; j <= llen->max; j++) 
58867 X    if (llen->hist[j] > 1) {
58868 X      x = (double)j + 0.5;
58869 X      u = pr->rho * x + pr->mu;
58870 X      y2 = llen->score2_sums[j] - 2.0 * llen->score_sums[j] * u + llen->hist[j] * u * u;
58871 /*
58872 X      dllj = (double)llen->hist[j];
58873 X      fprintf(stderr,"%.2f\t%d\t%g\t%g\n",x/LN_FACT,llen->hist[j],
58874 X             llen->score_sums[j]/dllj,y2/dllj);
58875 */
58876 X      mean_y2 += y2;
58877 X      var_y2 += y2 * y2;
58878 X      covar_xy2 += x * y2;
58879 X      /*      fprintf(stderr,"%6.1f %4d %8d %8d %7.2f %8.2f\n",
58880 X             x,llen->hist[j],llen->score_sums[j],llen->score2_sums[j],u,y2); */
58881 X    }
58882 X  
58883 X  pr->mean_var = mean_y2 /= (double)n;
58884 X  covar_xy2 = covar_xy2 / (double)n - mean_x * mean_y2;
58885 X
58886 X  if (pr->mean_var <= 0.01) {
58887 X    llen->fit_flag = 0;
58888 X    pr->mean_var = (pr->mu > 1.0) ? pr->mu: 1.0;
58889 X  }
58890 X
58891 X  /*
58892 X  fprintf(stderr," rho1/mu1: %.4f/%.4f mean_var %.4f\n",
58893 X         pr->rho*LN_FACT,pr->mu,pr->mean_var);
58894 X  */
58895 X  if (n > 1) pr->var_e = (var_y2/n - mean_y2 * mean_y2)/(n-1);
58896 X  else pr->var_e = 0.0;
58897 X
58898 X  if (llen->fit_flag) {
58899 X    pr->rho2 = covar_xy2 / var_x;
58900 X    pr->mu2 = pr->mean_var - pr->rho2 * mean_x;
58901 X  }
58902 X  else {
58903 X    pr->rho2 = 0;
58904 X    pr->mu2 = pr->mean_var;
58905 X  }
58906 X
58907 X  if (pr->rho2 < 0.0 )
58908 X    z = (pr->rho2 * LN_FACT*log((double)llen->max_length) + pr->mu2 > 0.0) ? llen->max_length : exp((-1.0 - pr->mu2 / pr->rho2)/LN_FACT);
58909 X  else z =  pr->rho2 ? exp((1.0 - pr->mu2 / pr->rho2)/LN_FACT) : LENGTH_CUTOFF;
58910 X  if (z < 2*LENGTH_CUTOFF) z = 2*LENGTH_CUTOFF;
58911 X
58912 X  pr->var_cutoff = pr->rho2 * LN_FACT*log(z) + pr->mu2;
58913 }
58914 X
58915 /* fit_llens: trim high variance bins
58916 X   (1) regress scores vs log(n) using weighted variance
58917 X   (2) regress residuals vs log(n)
58918 X   (3) remove high variance bins
58919 X   (4) calculate mean variance after length regression
58920 */
58921 X
58922 void
58923 fit_llens(struct llen_str *llen, struct rstat_str *pr)
58924 {
58925 X  int j;
58926 X  int n, n_u2;
58927 X  double x, y, y2, u, u2, v, z;
58928 X  double mean_x, mean_y, var_x, var_y, covar_xy;
58929 X  double mean_y2, covar_xy2;
58930 X  double mean_u2, mean_3u2, dllj;
58931 X  double sum_x, sum_y, sum_x2, sum_xy, sum_v, det, n_w;
58932 X
58933 /* now fit scores to best linear function of log(n), using
58934 X   simple linear regression */
58935 X  
58936 X  for (llen->min=0; llen->min < llen->max; llen->min++)
58937 X    if (llen->hist[llen->min]) break;
58938 X  llen->min--;
58939 X
58940 X  for (j = llen->min; j < llen->max; j++) {
58941 X    if (llen->hist[j] > 1) {
58942 X      dllj = (double)llen->hist[j];
58943 X      llen->score_var[j] = (double)llen->score2_sums[j]/dllj
58944 X       - (llen->score_sums[j]/dllj)*(llen->score_sums[j]/dllj);
58945 X      llen->score_var[j] /= (double)(llen->hist[j]-1);
58946 X      if (llen->score_var[j] <= 1.0 ) llen->score_var[j] = 1.0;
58947 X    }
58948 X  }
58949 X         
58950 X  n_w = 0.0;
58951 X  sum_x = sum_y = sum_x2 = sum_xy = sum_v = 0;
58952 X  for (j = llen->min; j < llen->max; j++)
58953 X    if (llen->hist[j] > 1) {
58954 X      x = j + 0.5;
58955 X      dllj = (double)llen->hist[j];
58956 X      n_w += dllj/llen->score_var[j];
58957 X      sum_x +=   dllj * x / llen->score_var[j] ;
58958 X      sum_y += llen->score_sums[j] / llen->score_var[j];
58959 X      sum_x2 +=  dllj * x * x /llen->score_var[j];
58960 X      sum_xy +=  x * llen->score_sums[j]/llen->score_var[j];
58961 X    }
58962 X
58963 X  det = n_w * sum_x2 - sum_x * sum_x;
58964 X  pr->rho = (n_w * sum_xy  - sum_x * sum_y)/det;
58965 X  pr->mu = (sum_x2 * sum_y - sum_x * sum_xy)/det;
58966 X
58967 /* printf(" rho1/mu1: %.2f/%.2f\n",pr->rho*LN_FACT,pr->mu); */
58968 X
58969 X  n = 0;
58970 X  mean_x = mean_y = mean_y2 = 0.0;
58971 X  var_x = var_y = 0.0;
58972 X  covar_xy = covar_xy2 = 0.0;
58973 X
58974 X  for (j = llen->min; j <= llen->max; j++) 
58975 X    if (llen->hist[j] > 1 ) {
58976 X      n += llen->hist[j];
58977 X      x = (double)j + 0.5;
58978 X      dllj = (double)llen->hist[j];
58979 X      mean_x += dllj * x;
58980 X      mean_y += llen->score_sums[j];
58981 X      var_x += dllj * x * x;
58982 X      var_y += llen->score2_sums[j];
58983 X      covar_xy += x * llen->score_sums[j];
58984 X    }
58985 X  mean_x /= n; mean_y /= n;
58986 X  var_x = var_x / n - mean_x * mean_x;
58987 X  var_y = var_y / n - mean_y * mean_y;
58988 X  
58989 X  covar_xy = covar_xy / n - mean_x * mean_y;
58990 /*  pr->rho = covar_xy / var_x;
58991 X  pr->mu = mean_y - pr->rho * mean_x;
58992 */
58993 X
58994 X  mean_y2 = covar_xy2 = 0.0;
58995 X  for (j = llen->min; j <= llen->max; j++) 
58996 X    if (llen->hist[j] > 1) {
58997 X      x = (double)j + 0.5;
58998 X      u = pr->rho * x + pr->mu;
58999 X      y2 = llen->score2_sums[j] - 2 * llen->score_sums[j] * u + llen->hist[j] * u * u;
59000 X      mean_y2 += y2;
59001 X      covar_xy2 += x * y2;
59002 X    }
59003 X  
59004 X  mean_y2 /= n;
59005 X  covar_xy2 = covar_xy2 / n - mean_x * mean_y2;
59006 X  pr->rho2 = covar_xy2 / var_x;
59007 X  pr->mu2 = mean_y2 - pr->rho2 * mean_x;
59008 X
59009 X  if (pr->rho2 < 0.0 )
59010 X    z = (pr->rho2 * LN_FACT*log((double)llen->max_length) + pr->mu2 > 0.0) ? llen->max_length : exp((-1.0 - pr->mu2 / pr->rho2)/LN_FACT);
59011 X  else z =  pr->rho2 ? exp((1.0 - pr->mu2 / pr->rho2)/LN_FACT) : LENGTH_CUTOFF;
59012 X  if (z < 2* LENGTH_CUTOFF) z = 2*LENGTH_CUTOFF;
59013 X
59014 X  pr->var_cutoff = pr->rho2*LN_FACT*log(z) + pr->mu2;
59015 X
59016 /*  fprintf(stderr,"\nminimum allowed predicted variance (%0.2f) at n = %.0f\n",
59017 X        pr->var_cutoff,z);
59018 */
59019 X  mean_u2 = 0.0;
59020 X  n_u2 = 0;
59021 X  for ( j = llen->min; j < llen->max; j++) {
59022 X    y = j+0.5;
59023 X    dllj = (double)llen->hist[j];
59024 X    x = pr->rho * y + pr->mu;
59025 X    v = pr->rho2 * y + pr->mu2;
59026 X    if (v < pr->var_cutoff) v = pr->var_cutoff;
59027 X    if (llen->hist[j]> 1) {
59028 X      u2 =  (llen->score2_sums[j] - 2 * x * llen->score_sums[j] + dllj * x * x) - v*dllj;
59029 X      mean_u2 += llen->score_var[j] = u2*u2/(llen->hist[j]-1);
59030 X      n_u2++;
59031 X      /*      fprintf(stderr," %d (%d) u2: %.2f v*ll: %.2f %.2f\n",
59032 X             j,llen->hist[j],u2,v*dllj,sqrt(llen->score_var[j])); */
59033 X    }
59034 X    else llen->score_var[j] = -1.0;
59035 X  }
59036 X
59037 X  mean_u2 = sqrt(mean_u2/(double)n_u2);
59038 X  /* fprintf(stderr," mean s.d.: %.2f\n",mean_u2); */
59039 X
59040 X  mean_3u2 = mean_u2*3.0;
59041 X
59042 X  for (j = llen->min; j < llen->max; j++) {
59043 X    if (llen->hist[j] <= 1) continue;
59044 X    if (sqrt(llen->score_var[j]) > mean_3u2) {
59045 X      /*      fprintf(stderr," removing %d %d %.2f\n",
59046 X            j, (int)(exp((double)j/LN_FACT)-0.5),
59047 X            sqrt(llen->score_var[j]));
59048 X            */
59049 X      pr->nb_trimmed++;
59050 X      pr->n1_trimmed += llen->hist[j];
59051 X      llen->hist[j] = 0;
59052 X    }
59053 X  }
59054 X  fit_llen(llen, pr);
59055 }
59056 X
59057 struct s2str {double s; int n;};
59058 void s2_sort ( struct s2str *sptr, int n);
59059 X
59060 void
59061 fit_llen2(struct llen_str *llen, struct rstat_str *pr)
59062 {
59063 X  int j;
59064 X  int n, n_y2, llen_delta, llen_del05;
59065 X  int n_size;
59066 X  double x, y2, u;
59067 X  double mean_x, mean_y, var_x, var_y, covar_xy;
59068 X  double mean_y2, covar_xy2;
59069 X  struct s2str *ss2;
59070 X
59071 X  double sum_x, sum_y, sum_x2, sum_xy, sum_v, det, n_w;
59072 X  
59073 /* now fit scores to best linear function of log(n), using
59074 X   simple linear regression */
59075 X  
59076 X  for (llen->min=0; llen->min < llen->max; llen->min++)
59077 X    if (llen->hist[llen->min]) break;
59078 X
59079 X  for ( ; llen->max > llen->min; llen->max--)
59080 X    if (llen->hist[llen->max]) break;
59081 X
59082 X  for (n_size=0,j = llen->min; j < llen->max; j++) {
59083 X    if (llen->hist[j] > 1) {
59084 X      llen->score_var[j] = llen->score2_sums[j]/(double)llen->hist[j]
59085 X       - (llen->score_sums[j]/(double)llen->hist[j])
59086 X       * (llen->score_sums[j]/(double)llen->hist[j]);
59087 X      llen->score_var[j] /= (double)(llen->hist[j]-1);
59088 X      if (llen->score_var[j] <= 1.0 ) llen->score_var[j] = 1.0;
59089 X      n_size++;
59090 X    }
59091 X  }
59092 X         
59093 X  n_w = 0.0;
59094 X  sum_x = sum_y = sum_x2 = sum_xy = sum_v = 0;
59095 X  for (j = llen->min; j < llen->max; j++)
59096 X    if (llen->hist[j] > 1) {
59097 X      x = j + 0.5;
59098 X      n_w += (double)llen->hist[j]/llen->score_var[j];
59099 X      sum_x +=   (double)llen->hist[j] * x / llen->score_var[j] ;
59100 X      sum_y += llen->score_sums[j] / llen->score_var[j];
59101 X      sum_x2 +=  (double)llen->hist[j] * x * x /llen->score_var[j];
59102 X      sum_xy +=  x * llen->score_sums[j]/llen->score_var[j];
59103 X    }
59104 X
59105 X  if (n_size < 5 ) {
59106 X    llen->fit_flag=0;
59107 X    pr->rho = 0;
59108 X    pr->mu = sum_y/n_w;
59109 X  }
59110 X  else {
59111 X    det = n_w * sum_x2 - sum_x * sum_x;
59112 X    if (det > 0.001) {
59113 X      pr->rho = (n_w * sum_xy  - sum_x * sum_y)/det;
59114 X      pr->rho_e = n_w/det;
59115 X      pr->mu = (sum_x2 * sum_y - sum_x * sum_xy)/det;
59116 X      pr->mu_e = sum_x2/det;
59117 X    }
59118 X    else {
59119 X      llen->fit_flag = 0;
59120 X      pr->rho = 0;
59121 X      pr->mu = sum_y/n_w;
59122 X    }
59123 X  }
59124 X
59125 X  det = n_w * sum_x2 - sum_x * sum_x;
59126 X  pr->rho = (n_w * sum_xy  - sum_x * sum_y)/det;
59127 X  pr->mu = (sum_x2 * sum_y - sum_x * sum_xy)/det;
59128 X
59129 /*   fprintf(stderr," rho1/mu1: %.2f/%.2f\n",pr->rho*LN_FACT,pr->mu); */
59130 X
59131 X  n = 0;
59132 X  mean_x = mean_y = mean_y2 = 0.0;
59133 X  var_x = var_y = 0.0;
59134 X  covar_xy = covar_xy2 = 0.0;
59135 X
59136 X  for (j = llen->min; j <= llen->max; j++) 
59137 X    if (llen->hist[j] > 1 ) {
59138 X      n += llen->hist[j];
59139 X      x = (double)j + 0.5;
59140 X      mean_x += (double)llen->hist[j] * x;
59141 X      mean_y += llen->score_sums[j];
59142 X      var_x += (double)llen->hist[j] * x * x;
59143 X      var_y += llen->score2_sums[j];
59144 X      covar_xy += x * llen->score_sums[j];
59145 X    }
59146 X  mean_x /= n; mean_y /= n;
59147 X  var_x = var_x / n - mean_x * mean_x;
59148 X  var_y = var_y / n - mean_y * mean_y;
59149 X  
59150 X  covar_xy = covar_xy / n - mean_x * mean_y;
59151 /*
59152 X  pr->rho = covar_xy / var_x;
59153 X  pr->mu = mean_y - pr->rho * mean_x;
59154 */
59155 X
59156 X  if ((ss2=(struct s2str *)calloc(llen->max+1,sizeof(struct s2str)))==NULL) {
59157 X    fprintf(stderr," cannot allocate ss2\n");
59158 X    return;
59159 X  }
59160 X
59161 X  mean_y2 = 0.0;
59162 X  n_y2 = n = 0;
59163 X  for (j = llen->min; j <= llen->max; j++) 
59164 X    if (llen->hist[j] > VHISTC) {
59165 X      n++;
59166 X      n_y2 += ss2[j].n = llen->hist[j];
59167 X      x = (double)j + 0.5;
59168 X      u = pr->rho * x + pr->mu;
59169 X      ss2[j].s = y2 = llen->score2_sums[j] - 2*llen->score_sums[j]*u + llen->hist[j]*u*u;
59170 X      mean_y2 += y2;
59171 X    }
59172 X  pr->mean_var = mean_y2/(double)n_y2;
59173 X
59174 X  s2_sort(ss2+llen->min,llen->max-llen->min+1);
59175 X  
59176 X  /*  fprintf(stderr,"llen->min: %d, max: %d\n",llen->min,llen->max); */
59177 X  llen_delta = 0;
59178 X  for (j=llen->min; j<=llen->max; j++) {
59179 X    if (ss2[j].n > 1) {
59180 X      llen_delta++;
59181 /*      fprintf(stderr,"%d\t%d\t%.2f\t%.4f\n",
59182 X             j,ss2[j].n,ss2[j].s,ss2[j].s/ss2[j].n);
59183 */
59184 X    }
59185 X  }
59186 X
59187 X  llen_del05 = llen_delta/20;
59188 X  mean_y2 = 0.0;
59189 X  n_y2 = 0;
59190 X  for (j = llen->min; j<llen->min+llen_del05; j++) {
59191 X    pr->n1_trimmed += ss2[j].n;
59192 X    pr->nb_trimmed++;
59193 X  }
59194 X  for (j = llen->min+llen_del05; j <= llen->min+llen_delta-llen_del05; j++) 
59195 X    if (ss2[j].n > 1) {
59196 X      mean_y2 += ss2[j].s;
59197 X      n_y2 += ss2[j].n;
59198 X    }
59199 X  for (j = llen->min+llen_delta-llen_del05+1; j< llen->max; j++) {
59200 X    pr->n1_trimmed += ss2[j].n;
59201 X    pr->nb_trimmed++;
59202 X  }
59203 X  
59204 X  free(ss2);
59205 X  if (n_y2 > 1) pr->mean_var = mean_y2/(double)n_y2;
59206 X
59207 X  /*    fprintf(stderr," rho1/mu1: %.4f/%.4f mean_var: %.4f/%d\n",
59208 X         pr->rho*LN_FACT,pr->mu,pr->mean_var,n); */
59209 X
59210 X    pr->var_e = 0.0;
59211 }
59212 X
59213 /* REG_STATS - Z() from rho/mu/mean_var */
59214 double find_zr(int score, double escore, int length, double comp, struct pstat_str *pu)
59215 {
59216 X  double log_len, z;
59217 X  
59218 X  if (score <= 0) return 0;
59219 X  if ( length < LENGTH_CUTOFF) return 0;
59220 X
59221 X  log_len = LN_FACT*log((double)(length));
59222 /*  var = pu->r_u.rg.rho2 * log_len + pu->r_u.rg.mu2;
59223 X  if (var < pu->r_u.rg.var_cutoff) var = pu->r_u.rg.var_cutoff;
59224 */
59225 X
59226 X  z = ((double)score - pu->r_u.rg.rho * log_len - pu->r_u.rg.mu) / sqrt(pu->r_u.rg.mean_var);
59227 X
59228 X  return (50.0 + z*10.0);
59229 }
59230 X
59231 /* REG2_STATS Z() from rho/mu, rho2/mu2 */
59232 double find_zr2(int score, double escore, int length, double comp, struct pstat_str *pu)
59233 {
59234 X  double log_len, var;
59235 X  double z;
59236 X  
59237 X  if ( length < LENGTH_CUTOFF) return 0;
59238 X
59239 X  log_len = LN_FACT*log((double)(length));
59240 X
59241 X  var = pu->r_u.rg.rho2 * log_len + pu->r_u.rg.mu2;
59242 X  if (var < pu->r_u.rg.var_cutoff) var = pu->r_u.rg.mean_var;
59243 X
59244 X  z = ((double)score - pu->r_u.rg.rho * log_len - pu->r_u.rg.mu) / sqrt(var);
59245 X
59246 X  return (50.0 + z*10.0);
59247 }
59248 X
59249 #ifdef USE_LNSTATS
59250 /* LN_STATS - ln()-scaled mu, mean_var */
59251 double find_zl(int score, int length, double comp, struct pstat_str *pu)
59252 {
59253 X  double ls, z;
59254 X  
59255 X  ls = (double)score*LN200/log((double)length);
59256 X
59257 X  z = (ls - pu->r_u.rg.mu) / sqrt(pu->r_u.rg.mean_var);
59258 X
59259 X  return (50.0 + z*10.0);
59260 }
59261 #endif
59262 X
59263 /* MLE_STATS - Z() from MLE for lambda, K */
59264 double
59265 find_ze(int score, double escore, int length, double comp, struct pstat_str *pu)
59266 {
59267 X  double z, mp, np, a_n1;
59268 X  
59269 X  a_n1 = (double)length; 
59270 X
59271 X  mp = pu->r_u.ag.a_n0;
59272 X  np = a_n1;
59273 X
59274 X  if (np < 1.0) np = 1.0;
59275 X  if (mp < 1.0) mp = 1.0;
59276 X
59277 X  z = pu->r_u.ag.Lambda * score - log(pu->r_u.ag.K * np * mp);
59278 X
59279 X  z = -z + EULER_G;
59280 X  z /= - PI_SQRT6;
59281 X
59282 X  return (50.0 + z*10.0);
59283 }
59284 X
59285 /* MLE2_STATS - Z() from MLE for mle_a0..2, mle_b1, length, comp */
59286 double
59287 find_ze2(int score, double escore, int length, double comp, struct pstat_str *pu)
59288 {
59289 X  double z, mp, np, a_n1;
59290 X  
59291 X  a_n1 = (double)length; 
59292 X
59293 X  if (comp <= 0.0) comp = pu->r_u.m2.ave_comp;
59294 X
59295 X  /* avoid very biased comp estimates */
59296 X  /* comp = exp((4.0*log(comp)+log(pu->r_u.m2.ave_comp))/5.0); */
59297 X
59298 X  mp = pu->r_u.m2.a_n0;
59299 X  np = a_n1;
59300 X
59301 X  if (np < 1.0) np = 1.0;
59302 X  if (mp < 1.0) mp = 1.0;
59303 X
59304 X  z = (-(pu->r_u.m2.mle2_a0 + pu->r_u.m2.mle2_a1 * comp + pu->r_u.m2.mle2_a2 * comp * log(np * mp)) + score) / (pu->r_u.m2.mle2_b1 * comp);
59305 X
59306 X  z = -z + EULER_G;
59307 X  z /= - PI_SQRT6;
59308 X
59309 X  return (50.0 + z*10.0);
59310 }
59311 X
59312 /* AG_STATS - Altschul-Gish Lamdba, K */
59313 double
59314 find_za(int score, double escore, int length, double comp, struct pstat_str *pu)
59315 {
59316 X  double z, mp, np, a_n1, a_n1f;
59317 X  
59318 X  a_n1 = (double)length; 
59319 X  a_n1f = log(a_n1)/pu->r_u.ag.H;
59320 X
59321 X  mp = pu->r_u.ag.a_n0 - pu->r_u.ag.a_n0f - a_n1f;
59322 X  np = a_n1 - pu->r_u.ag.a_n0f - a_n1f;
59323 X
59324 X  if (np < 1.0) np = 1.0;
59325 X  if (mp < 1.0) mp = 1.0;
59326 X
59327 X  z = pu->r_u.ag.Lambda * score - log(pu->r_u.ag.K * np * mp);
59328 X
59329 X  z = -z + EULER_G;
59330 X  z /= - PI_SQRT6;
59331 X
59332 X  return (50.0 + z*10.0);
59333 }
59334 X
59335 double find_zn(int score, double escore, int length, double comp, struct pstat_str *pu)
59336 {
59337 X  double z;
59338 X  
59339 X  z = ((double)score - pu->r_u.rg.mu) / sqrt(pu->r_u.rg.mean_var);
59340 X
59341 X  return (50.0 + z*10.0);
59342 }
59343 X
59344 /* computes E value for a given z value, assuming extreme value distribution */
59345 double
59346 z_to_E(double zs, long entries, struct db_str db)
59347 {
59348 X  double e, n;
59349 X
59350 X  /*  if (db->entries < 5) return (double)db.entries; */
59351 X  if (entries < 1) { n = db.entries;}
59352 X  else {n = entries;}
59353 X
59354 X  if (zs > ZS_MAX) return 0.0;
59355 X
59356 #ifndef NORMAL_DIST
59357 X  e = exp(- PI_SQRT6 * zs - .577216);
59358 X  return n * (e > .01 ? 1.0 - exp(-e) : e);
59359 #else
59360 X  return n * erfc(zs/M_SQRT2)/2.0; 
59361 #endif
59362 }
59363 X
59364 double
59365 zs_to_p(double zs)
59366 {
59367 X  double e, z;
59368 X
59369 X  /*  if (db.entries < 5) return 0.0; */
59370 X
59371 X  z = (zs - 50.0)/10.0;
59372 X
59373 X  if (z > ZS_MAX) return 0.0;
59374 X
59375 #ifndef NORMAL_DIST
59376 X  e = exp(- PI_SQRT6 * z - EULER_G);
59377 X  return (e > .01 ? 1.0 - exp(-e) : e);
59378 #else
59379 X  return erfc(zs/M_SQRT2)/2.0; 
59380 #endif
59381 }
59382 X
59383 double
59384 zs_to_bit(double zs, int n0, int n1)
59385 {
59386 X  double z, a_n0, a_n1;
59387 X
59388 X  z = (zs - 50.0)/10.0;
59389 X  a_n0 = (double)n0;
59390 X  a_n1 = (double)n1;
59391 X
59392 X  return (PI_SQRT6 * z + EULER_G + log(a_n0*a_n1))/M_LN2 ;
59393 }
59394 X
59395 /* computes E-value for a given z value, assuming extreme value distribution */
59396 double
59397 zs_to_E(double zs,int n1, int dnaseq, long entries, struct db_str db)
59398 {
59399 X  double e, z, k;
59400 X
59401 X  /*  if (db->entries < 5) return 0.0; */
59402 X
59403 X  z = (zs - 50.0)/10.0;
59404 X
59405 X  if (z > ZS_MAX ) return 0.0;
59406 X
59407 X  if (entries < 1) entries = db.entries;
59408 X
59409 X  if (dnaseq == SEQT_DNA || dnaseq == SEQT_RNA) {
59410 X    k = (double)db.length /(double)n1;
59411 X    if (db.carry > 0) {
59412 X      k += ((double)db.carry * (double)LONG_MAX)/(double)n1;
59413 X    }
59414 X  }
59415 X  else k = (double)entries;
59416 X
59417 X  if (k < 1.0) k = 1.0;
59418 X
59419 #ifndef NORMAL_DIST
59420 X  z *= PI_SQRT6;
59421 X  z += EULER_G;
59422 X  e = exp(-z);
59423 X  return k * (e > .01 ? 1.0 - exp(-e) : e);
59424 #else
59425 X  return k * erfc(z/M_SQRT2)/2.0; 
59426 #endif
59427 }
59428 X
59429 #ifdef NORMAL_DIST
59430 double np_to_z(double, int *);
59431 #endif
59432 X
59433 /* computes E-value for a given z value, assuming extreme value distribution */
59434 double
59435 E_to_zs(double E, long entries)
59436 {
59437 X  double e, z;
59438 X  int error;
59439 X
59440 X  e = E/(double)entries;
59441 X
59442 #ifndef NORMAL_DIST
59443 X  z = (log(e)+EULER_G)/(- PI_SQRT6);
59444 X  return z*10.0+50.0;
59445 #else
59446 X  z = np_to_z(1.0-e,&error);
59447 X
59448 X  if (!error) return z*10.0+50.0;
59449 X  else return 0.0;
59450 #endif
59451 }
59452 X
59453 /* computes 1.0 - E value for a given z value, assuming extreme value
59454 X   distribution */
59455 double
59456 zs_to_Ec(double zs, long entries)
59457 {
59458 X  double e, z;
59459 X
59460 X  if (entries < 5) return 0.0;
59461 X
59462 X  z = (zs - 50.0)/10.0;
59463 X
59464 X  if (z > ZS_MAX) return 1.0;
59465 X
59466 #ifndef NORMAL_DIST
59467 X  e =  exp(- PI_SQRT6 * z - EULER_G);
59468 X  return (double)entries * (e > .01 ?  exp(-e) : 1.0 - e);
59469 #else
59470 X  return (double)entries*erf(z/M_SQRT2)/2.0; 
59471 #endif
59472 }
59473 X
59474 /* calculate a threshold score, given an E() value and Lambda,K,H */
59475 X
59476 int
59477 E1_to_s(double e_val, int n0, int n1, struct pstat_str *pu) {
59478 X  double mp, np, a_n0, a_n0f, a_n1;
59479 X  int score;
59480 X
59481 X  a_n0 = (double)n0;
59482 X  a_n1 = (double)n1;
59483 X  a_n0f = log(pu->r_u.ag.K * a_n0 * a_n1)/pu->r_u.ag.H;
59484 X
59485 X  mp = a_n0 - a_n0f;
59486 X  np = a_n1 - a_n0f;
59487 X
59488 X  if (np < 1.0) np = 1.0;
59489 X  if (mp < 1.0) mp = 1.0;
59490 X
59491 X  score = (int)((log( pu->r_u.ag.K * mp * np) - log(e_val))/pu->r_u.ag.Lambda +0.5);
59492 X  if (score < 0) score = 0;
59493 X  return score;
59494 }
59495 X
59496 /* no longer used; stat_str returned by process_hist
59497 void
59498 summ_stats(char *s_str, struct pstat_str *pu)
59499 {
59500 X  strcpy(s_str,f_string);
59501 }
59502 */
59503 X
59504 void
59505 vsort(v,s,n)
59506 X       double *v; int *s, n;
59507 {
59508 X  int gap, i, j;
59509 X  double tmp;
59510 X  int itmp;
59511 X       
59512 X  for (gap=n/2; gap>0; gap/=2)
59513 X    for (i=gap; i<n; i++)
59514 X      for (j=i-gap; j>=0; j -= gap) {
59515 X       if (v[j] >= v[j+gap]) break;
59516 X       tmp = v[j]; v[j]=v[j+gap]; v[j+gap]=tmp;
59517 X       itmp = s[j]; s[j]=s[j+gap]; s[j+gap]=itmp;
59518 X      }
59519 }
59520 X
59521 /*
59522 void s_sort (double **ptr, int nbest)
59523 {
59524 X  int gap, i, j;
59525 X  double *tmp;
59526 X
59527 X  for (gap = nbest/2; gap > 0; gap /= 2)
59528 X    for (i = gap; i < nbest; i++)
59529 X      for (j = i - gap; j >= 0; j-= gap) {
59530 X       if (*ptr[j] >= *ptr[j + gap]) break;
59531 X       tmp = ptr[j];
59532 X       ptr[j] = ptr[j + gap];
59533 X       ptr[j + gap] = tmp;
59534 X      }
59535 }
59536 */
59537 X
59538 void ss_sort (int *ptr, int n)
59539 {
59540 X  int gap, i, j;
59541 X  int tmp;
59542 X
59543 X  for (gap = n/2; gap > 0; gap /= 2)
59544 X    for (i = gap; i < n; i++)
59545 X      for (j = i - gap; j >= 0; j-= gap) {
59546 X       if (ptr[j] >= ptr[j + gap]) break;
59547 X       tmp = ptr[j];
59548 X       ptr[j] = ptr[j + gap];
59549 X       ptr[j + gap] = tmp;
59550 X      }
59551 }
59552 X
59553 X
59554 void s2_sort (struct s2str *ptr, int n)
59555 {
59556 X  int gap, i, j;
59557 X  struct s2str tmp;
59558 X
59559 X  for (gap = n/2; gap > 0; gap /= 2)
59560 X    for (i = gap; i < n; i++)
59561 X      for (j = i - gap; j >= 0; j-= gap) {
59562 X       if (ptr[j].s >= ptr[j + gap].s) break;
59563 X       tmp.s = ptr[j].s;
59564 X       tmp.n = ptr[j].n;
59565 X       ptr[j].s = ptr[j + gap].s;
59566 X       ptr[j].n = ptr[j + gap].n;
59567 X       ptr[j + gap].s = tmp.s;
59568 X       ptr[j + gap].n = tmp.n;
59569 X      }
59570 }
59571 X
59572 void last_stats() {}
59573 X
59574 void
59575 scale_scores(struct beststr **bptr, int nbest, struct db_str db,
59576 X            struct pstruct pst, struct pstat_str *rs)
59577 {
59578 X  int i;
59579 X  double zscore;
59580 X
59581 X  if (pst.zsflag < 0 || pst.zsflag_f < 0) return;
59582 X
59583 X  for (i=0; i<nbest; i++) {
59584 X    zscore = find_zp(bptr[i]->score[pst.score_ix], bptr[i]->escore,
59585 X                    bptr[i]->n1,bptr[i]->comp,rs);
59586 X    bptr[i]->zscore = zscore;
59587 X    bptr[i]->escore
59588 X      =zs_to_E(zscore,bptr[i]->n1,pst.dnaseq, pst.zdb_size,db);
59589 X  }
59590 X  sortbeste(bptr,nbest);
59591 }
59592 X
59593 #ifdef NORMAL_DIST
59594 /*     ALGORITHM AS241  APPL. STATIST. (1988) VOL. 37, NO. 3
59595 X
59596 X       Produces the normal deviate Z corresponding to a given lower
59597 X       tail area of P; Z is accurate to about 1 part in 10**16.
59598 X
59599 X       The hash sums below are the sums of the mantissas of the
59600 X       coefficients.   They are included for use in checking
59601 X       transcription.
59602 */
59603 X
59604 double np_to_z(double p, int *fault) {
59605 X
59606 X  double q, r, ppnd16;
59607 X
59608 X  double zero = 0.0, one = 1.0, half = 0.5;
59609 X  double split1 = 0.425, split2 = 5.0;
59610 X  double const1 = 0.180625, const2 = 1.6;
59611 X
59612 /*   Coefficients for P close to 0.5 */
59613 X
59614 X  double a0 = 3.3871328727963666080e0;
59615 X  double a1 = 1.3314166789178437745e+2;
59616 X  double a2 = 1.9715909503065514427e+3;
59617 X  double a3 = 1.3731693765509461125e+4;
59618 X  double a4 = 4.5921953931549871457e+4;
59619 X  double a5 = 6.7265770927008700853e+4;
59620 X  double a6 = 3.3430575583588128105e+4;
59621 X  double a7 = 2.5090809287301226727e+3;
59622 X  double b1 = 4.2313330701600911252e+1;
59623 X  double b2 = 6.8718700749205790830e+2;
59624 X  double b3 = 5.3941960214247511077e+3;
59625 X  double b4 = 2.1213794301586595867e+4;
59626 X  double b5 = 3.9307895800092710610e+4;
59627 X  double b6 = 2.8729085735721942674e+4;
59628 X  double b7 = 5.2264952788528545610e+3;
59629 X
59630 X  double sum_ab= 55.8831928806149014439;
59631 /* 
59632 X  Coefficients for P not close to 0, 0.5 or 1.
59633 */
59634 X
59635 X  double c0 = 1.42343711074968357734;
59636 X  double c1 = 4.63033784615654529590;
59637 X  double c2 = 5.76949722146069140550;
59638 X  double c3 = 3.64784832476320460504;
59639 X  double c4 = 1.27045825245236838258;
59640 X  double c5 = 2.41780725177450611770e-1;
59641 X  double c6 = 2.27238449892691845833e-2;
59642 X  double c7 = 7.74545014278341407640e-4;
59643 X  double d1 = 2.05319162663775882187;
59644 X  double d2 = 1.67638483018380384940;
59645 X  double d3 = 6.89767334985100004550e-1;
59646 X  double d4 = 1.48103976427480074590e-1;
59647 X  double d5 = 1.51986665636164571966e-2;
59648 X  double d6 = 5.47593808499534494600e-4;
59649 X  double d7 = 1.05075007164441684324e-9;
59650 X
59651 X  double sum_cd=49.33206503301610289036;
59652 /*
59653 X       Coefficients for P near 0 or 1.
59654 */
59655 X  double e0 = 6.65790464350110377720e0;
59656 X  double e1 = 5.46378491116411436990e0;
59657 X  double e2 = 1.78482653991729133580e0;
59658 X  double e3 = 2.96560571828504891230e-1;
59659 X  double e4 = 2.65321895265761230930e-2;
59660 X  double e5 = 1.24266094738807843860e-3;
59661 X  double e6 = 2.71155556874348757815e-5;
59662 X  double e7 = 2.01033439929228813265e-7;
59663 X  double f1 = 5.99832206555887937690e-1;
59664 X  double f2 = 1.36929880922735805310e-1;
59665 X  double f3 = 1.48753612908506148525e-2;
59666 X  double f4 = 7.86869131145613259100e-4;
59667 X  double f5 = 1.84631831751005468180e-5;
59668 X  double f6 = 1.42151175831644588870e-7;
59669 X  double f7 = 2.04426310338993978564e-15;
59670 X
59671 X  double sum_ef=47.52583317549289671629;
59672 X
59673 X  double sum_tmp = 0.0;
59674 X
59675 X  /*
59676 X  sum_tmp = a0+a1+a2+a3+a4+a5+a6+a7+b1+b2+b3+b4+b5+b6+b7;
59677 X  if (fabs(sum_tmp - sum_ab) > 1e-12) {
59678 X    fprintf (stderr," sum_ab error: %lg %lg\n",sum_tmp,sum_ab);
59679 X    *fault = 1;
59680 X    return zero;
59681 X  }
59682 X
59683 X  sum_tmp = c0+c1+c2+c3+c4+c5+c6+c7+d1+d2+d3+d4+d5+d6+d7;
59684 X  if (fabs(sum_tmp - sum_cd) > 1e-12) {
59685 X    fprintf (stderr," sum_cd error: %lg %lg\n",sum_tmp,sum_cd);
59686 X    *fault = 1;
59687 X    return zero;
59688 X  }
59689 X  sum_tmp = e0+e1+e2+e3+e4+e5+e6+e7+f1+f2+f3+f4+f5+f6+f7;
59690 X  if (fabs(sum_tmp - sum_ef) > 1e-12) {
59691 X    fprintf (stderr," sum_ef error: %lg %lg\n",sum_tmp,sum_ef);
59692 X    *fault = 1;
59693 X    return zero;
59694 X  }
59695 X  */
59696 X
59697 X  *fault = 0;
59698 X  q = p - half;
59699 X  if (fabs(q) <= split1) {
59700 X    r = const1 - q * q;
59701 X    return q * (((((((a7 * r + a6) * r + a5) * r + a4) * r + a3)
59702 X                   * r + a2) * r + a1) * r + a0) /
59703 X      (((((((b7 * r + b6) * r + b5) * r + b4) * r + b3)
59704 X        * r + b2) * r + b1) * r + one);
59705 X  }
59706 X  else {
59707 X    r = (q < zero) ?  p : one - p;
59708 X    if (r <= zero) {
59709 X      *fault = 1;
59710 X      return zero;
59711 X    }
59712 X    r = sqrt(-log(r));
59713 X    if (r <= split2) {
59714 X      r -= const2;
59715 X      ppnd16 = (((((((c7 * r + c6) * r + c5) * r + c4) * r + c3)
59716 X                 * r + c2) * r + c1) * r + c0) /
59717 X       (((((((d7 * r + d6) * r + d5) * r + d4) * r + d3)
59718 X          * r + d2) * r + d1) * r + one);
59719 X    }
59720 X    else {
59721 X      r -= split2;
59722 X      ppnd16 = (((((((e7 * r + e6) * r + e5) * r + e4) * r + e3)
59723 X                 * r + e2) * r + e1) * r + e0) /
59724 X       (((((((f7 * r + f6) * r + f5) * r + f4) * r + f3)
59725 X          * r + f2) * r + f1) * r + one);
59726 X    }
59727 X    if (q < zero) return -ppnd16;
59728 X    else return ppnd16;
59729 X  }
59730 }
59731 #endif
59732 SHAR_EOF
59733 chmod 0644 scaleswn.c ||
59734 echo 'restore of scaleswn.c failed'
59735 Wc_c="`wc -c < 'scaleswn.c'`"
59736 test 69722 -eq "$Wc_c" ||
59737         echo 'scaleswn.c: original size 69722, current size' "$Wc_c"
59738 fi
59739 # ============= scaleswt.c ==============
59740 if test -f 'scaleswt.c' -a X"$1" != X"-c"; then
59741         echo 'x - skipping scaleswt.c (File already exists)'
59742 else
59743 echo 'x - extracting scaleswt.c (Text)'
59744 sed 's/^X//' << 'SHAR_EOF' > 'scaleswt.c' &&
59745 /* scaleswt.c */
59746 X
59747 /* $Name: fa_34_26_5 $ - $Id: scaleswt.c,v 1.21 2006/04/12 18:50:01 wrp Exp $ */
59748 /* as of 24 Sept, 2000 - scaleswn uses no global variables */
59749 X
59750 /*
59751 X  copyright (c) 1995, 1996, 2000, 2002 William R. Pearson
59752 X
59753 X  This version is designed for fasts/f, which used Tatusov
59754 X  probabilities for statistical estimates, but still needs a
59755 X  quick-and-dirty linear regression fit to rank things
59756 X
59757 X  For comparisons that obey tatusov statistics, we try whenever
59758 X  possible to provide accurate e_scores, rather than raw scores.  As a
59759 X  result, no lambda/K fitting is required; and process_hist() can be
59760 X  called atthe very beginning of the search to initialize some of the
59761 X  statistics structures and find_zp().
59762 X
59763 X  find_zp() must still return a valid z_score surrogate, as
59764 X  comp_lib.c/p2_complib.c continue to use z_score's to rank hits, save
59765 X  the best, etc.
59766 X
59767 X  If e_score's cannot be calculated, the process_hist() provides
59768 X  linear regression fitting for conventional z_score estimates.
59769 X
59770 */
59771 X
59772 #include <stdio.h>
59773 #include <stdlib.h>
59774 #include <string.h>
59775 X
59776 #include <limits.h>
59777 #include <float.h>
59778 #include <math.h>
59779 X
59780 #include <limits.h>
59781 X
59782 #include "defs.h"
59783 #include "param.h"
59784 #include "structs.h"
59785 #ifndef PCOMPLIB
59786 #include "mw.h"
59787 #else
59788 #include "p_mw.h"
59789 #endif
59790 X
59791 #define MAXHIST 50
59792 #define MAX_LLEN 200
59793 #define LHISTC 5
59794 #define VHISTC 5
59795 #define MAX_SSCORE 300
59796 X
59797 #define LENGTH_CUTOFF 10 /* minimum database sequence length allowed, for fitting */
59798 X
59799 #define LN_FACT 10.0
59800 #ifndef M_LN2
59801 #define M_LN2 0.69314718055994530942
59802 #endif
59803 X
59804 #define EULER_G 0.57721566490153286060
59805 #define PI_SQRT6 1.28254983016186409554
59806 X
59807 #ifndef M_SQRT2
59808 #define M_SQRT2 1.41421356237
59809 #endif
59810 #define LN200 5.2983173666
59811 #define ZS_MAX 400.0    /* used to prevent underflow on some machines */
59812 #define TOLERANCE 1.0e-12
59813 #define TINY 1.0e-6
59814 X
59815 /* used by AVE_STATS, REG_STATS, REGI_STATS, REG2_STATS*/
59816 struct rstat_str {
59817 X  double ngLambda, ngK, ngH;
59818 X  double rho, rho_e, mu, mu_e, mean_var, var_e;  /* ?_e:std. error of ? */
59819 /* used by REG2_STATS */
59820 X  double rho2, mu2, var_cutoff;
59821 X  int n_trimmed; /* excluded because of high z-score */
59822 X  int n1_trimmed, nb_trimmed, nb_tot; /* excluded because of bin */
59823 X  double tat_a, tat_b, tat_c, spacefactor;
59824 X  int have_tat;
59825 X  int tie_j;
59826 };
59827 X
59828 #define AVE_STATS 0     /* no length effect, only mean/variance */
59829 double find_zt(int score, double escore, int len, double comp, struct rstat_str *);
59830 X
59831 double find_zn(int score, double escore, int len, double comp, struct rstat_str *);
59832 X
59833 double power(double, int);
59834 X
59835 void sortbesto(double *, int );
59836 extern void sortbeste(struct beststr **bptr, int nbest);
59837 X
59838 int proc_hist_n(struct stat_str *sptr, int n, 
59839 X                struct pstruct pst, struct hist_str *histp, int do_trim,
59840 X                struct rstat_str *);
59841 X
59842 #define REG_STATS 1     /* length-regression scaled */
59843 double find_zr(int score, double escore, int len, double comp, struct rstat_str *);
59844 X
59845 int proc_hist_r(struct stat_str *sptr, int n,
59846 X                struct pstruct pst, struct hist_str *histp,
59847 X                int do_trim, struct rstat_str *rs);
59848 X
59849 double (*find_zp)(int score, double escore, int len, double comp,
59850 X                struct rstat_str *) = &find_zr;
59851 X
59852 struct llen_str {
59853 X  int min, max;
59854 X  int max_score, min_score;
59855 X  int *hist;
59856 X  double *score_sums, *score2_sums;
59857 X  double *score_var;
59858 X  int max_length, min_length, zero_s;
59859 X  int fit_flag;
59860 };
59861 X
59862 static void inithist(struct llen_str *, struct pstruct, int);
59863 static void free_hist( struct llen_str *);
59864 static void addhist(struct llen_str *, int, int, int);
59865 static void prune_hist(struct llen_str *, int, int, int, long *);
59866 void inithistz(int, struct hist_str *histp);
59867 void addhistz(double zs, struct hist_str *histp);
59868 X
59869 static void fit_llen(struct llen_str *, struct rstat_str *);
59870 static void fit_llens(struct llen_str *, struct rstat_str *);
59871 X
59872 void linreg(double *lny, double *x, double *lnx, int n,
59873 X           double *a, double *b, double *c, int start);
59874 X
59875 double calc_spacefactor(const unsigned char *, int, int, int);
59876 X
59877 double det(double a11, double a12, double a13,
59878 X          double a21, double a22, double a23,
59879 X          double a31, double a32, double a33);
59880 X
59881 double factorial (int a, int b);
59882 X
59883 /* void set_db_size(int, struct db_str *, struct hist_str *); */
59884 X
59885 #ifdef DEBUG
59886 FILE *tmpf;
59887 #endif
59888 X
59889 int
59890 process_hist(struct stat_str *sptr, int nstats, 
59891 X            struct mngmsg m_msg,
59892 X            struct pstruct pst,
59893 X            struct hist_str *histp,
59894 X            struct rstat_str **rs_sp,
59895 X            int do_hist
59896 X            )
59897 {
59898 X  int zsflag, do_trim;
59899 X  struct rstat_str *rs_s;
59900 X
59901 X  if (pst.zsflag < 0) {
59902 X    *rs_sp = NULL;
59903 X    return pst.zsflag;
59904 X  }
59905 X
59906 X  if (*rs_sp == NULL) {
59907 X    if ((rs_s=(struct rstat_str *)calloc(1,sizeof(struct rstat_str)))==NULL) {
59908 X      fprintf(stderr," cannot allocate rs_snion: %ld\n",sizeof(struct rstat_str));
59909 X      exit(1);
59910 X    }
59911 X    else *rs_sp = rs_s;
59912 X  }
59913 X  else {
59914 X    rs_s = *rs_sp;
59915 X    memset(rs_s,0,sizeof(struct rstat_str));
59916 X  }
59917 X
59918 X  if (m_msg.escore_flg) {
59919 X    find_zp = &find_zt;
59920 X    inithistz(MAXHIST,histp);
59921 X    return 1;
59922 X  }
59923 X
59924 X  if (nstats < 20) {
59925 X    fprintf(stderr," too few sequences for sampling: %d\n",nstats);
59926 X    free(rs_s);
59927 X    *rs_sp = NULL;
59928 X    return -1;
59929 X  }
59930 X
59931 X  rs_s->ngLambda = m_msg.Lambda;
59932 X  rs_s->ngK = m_msg.K;
59933 X  rs_s->ngH = m_msg.H;
59934 X
59935 X  zsflag = pst.zsflag;
59936 X
59937 X  if (zsflag >= 10) {
59938 X    zsflag -= 10;
59939 X    do_trim = 0;
59940 X  }
59941 X  else do_trim = 1;
59942 X
59943 X  find_zp = &find_zr;
59944 X  return proc_hist_r(sptr, nstats,pst, histp, do_trim,  rs_s);
59945 }
59946 X
59947 int
59948 calc_thresh(struct pstruct pst, int nstats, 
59949 X           double Lambda, double K, double H, double *zstrim)
59950 {
59951 X  int max_hscore;
59952 X  double ave_n1, tmp_score, z, l_fact;
59953 X
59954 X  if (pst.dnaseq == SEQT_DNA || pst.dnaseq == SEQT_RNA) {
59955 X    ave_n1 = 5000.0;
59956 X    l_fact = 1.0;
59957 X  }
59958 X  else {
59959 X    ave_n1 = 400.0;
59960 X    l_fact = 0.7;
59961 X  }
59962 X
59963 /*  max_hscore = MAX_SSCORE; */
59964 /*  mean expected for pst.n0 * 400 for protein, 5000 for DNA */
59965 /*  we want a number of offsets that is appropriate for the database size so
59966 X    far (nstats)
59967 */
59968 X
59969 /*
59970 X  the calculation below sets a high-score threshold using an
59971 X  ungapped lambda, but errs towards the high-score side by using
59972 X  E()=0.001 and calculating with 0.70*lambda, which is the correct for
59973 X  going from ungapped to -12/-2 gapped lambda with BLOSUM50
59974 */
59975 X
59976 #ifndef NORMAL_DIST
59977 X  tmp_score = 0.01/((double)nstats*K*(double)pst.n0*ave_n1);
59978 X  tmp_score = -log(tmp_score)/(Lambda*l_fact);
59979 X  max_hscore = (int)(tmp_score+0.5);
59980 X
59981 X  z = 1.0/(double)nstats;
59982 X  z = (log(z)+EULER_G)/(-PI_SQRT6);
59983 #else
59984 X  max_hscore = 100;
59985 X  z = 5.0;
59986 #endif
59987 X  *zstrim = 10.0*z+50.0;
59988 X  return max_hscore;
59989 }
59990 X
59991 int
59992 proc_hist_r(struct stat_str *sptr, int nstats,
59993 X           struct pstruct pst, struct hist_str *histp,
59994 X           int do_trim, struct rstat_str *rs)
59995 {
59996 X  int i, max_hscore;
59997 X  double zs, ztrim;
59998 X  char s_string[128];
59999 X  struct llen_str llen;
60000 X  char *f_string;
60001 X  llen.fit_flag=1;
60002 X  llen.hist=NULL;
60003 X
60004 X  max_hscore = calc_thresh(pst, nstats, rs->ngLambda,
60005 X                          rs->ngK, rs->ngH, &ztrim);
60006 X
60007 X  inithist(&llen,pst,max_hscore);
60008 X  f_string = &(histp->stat_info[0]);
60009 X
60010 X  for (i = 0; i<nstats; i++)
60011 X    addhist(&llen,sptr[i].score,sptr[i].n1, max_hscore);
60012 X  histp->entries = nstats - llen.zero_s;
60013 X
60014 X  if ((llen.max_score - llen.min_score) < 10) {
60015 X    free_hist(&llen);
60016 X    llen.fit_flag = 0;
60017 X    find_zp = &find_zn;
60018 X    return proc_hist_n(sptr, nstats, pst, histp, do_trim, rs);
60019 X  }
60020 X
60021 X  fit_llen(&llen, rs); /* now we have rho, mu, rho2, mu2, mean_var
60022 X                         to set the parameters for the histogram */
60023 X
60024 X  if (!llen.fit_flag) {        /* the fit failed, fall back to proc_hist_n */
60025 X    free_hist(&llen);
60026 X    find_zp = &find_zn;
60027 X    return proc_hist_n(sptr,nstats, pst, histp, do_trim, rs);
60028 X  }
60029 X
60030 X  rs->n_trimmed= rs->n1_trimmed = rs->nb_trimmed = 0;
60031 X
60032 X  if (do_trim) {
60033 X    if (llen.fit_flag) {
60034 X      for (i = 0; i < nstats; i++) {
60035 X       zs = find_zr(sptr[i].score,sptr[i].escore,sptr[i].n1,sptr[i].comp, rs);
60036 X       if (zs < 20.0 || zs > ztrim) {
60037 X         rs->n_trimmed++;
60038 X         prune_hist(&llen,sptr[i].score,sptr[i].n1, max_hscore,
60039 X                    &(histp->entries));
60040 X       }
60041 X      }
60042 X    }
60043 X
60044 X  /*  fprintf(stderr,"Z-trimmed %d entries with z > 5.0\n", rs->n_trimmed); */
60045 X
60046 X    if (llen.fit_flag) fit_llens(&llen, rs);
60047 X
60048 X  /*   fprintf(stderr,"Bin-trimmed %d entries in %d bins\n", rs->n1_trimmed,rs->nb_trimmed); */
60049 X  }
60050 X
60051 X
60052 X  free_hist(&llen);
60053 X
60054 X  /* rst all the scores in the histogram */
60055 X
60056 X  if (pst.zsflag < 10) s_string[0]='\0';
60057 X  else if (pst.zs_win > 0)
60058 X    sprintf(s_string,"(shuffled, win: %d)",pst.zs_win);
60059 X  else strncpy(s_string,"(shuffled)",sizeof(s_string));
60060 X
60061 X  inithistz(MAXHIST, histp);
60062 X
60063 X  sprintf(f_string,"%s Expectation_n fit: rho(ln(x))= %6.4f+/-%6.3g; mu= %6.4f+/-%6.3f\n mean_var=%6.4f+/-%6.3f, 0's: %d Z-trim: %d  B-trim: %d in %d/%d\n Lambda= %6.4f",
60064 X         s_string,
60065 X         rs->rho*LN_FACT,sqrt(rs->rho_e),rs->mu,sqrt(rs->mu_e), rs->mean_var,sqrt(rs->var_e),
60066 X         llen.zero_s, rs->n_trimmed, rs->n1_trimmed, rs->nb_trimmed, rs->nb_tot,
60067 X         PI_SQRT6/sqrt(rs->mean_var));
60068 X    return REG_STATS;
60069 }
60070 X
60071 X
60072 int
60073 proc_hist_n(struct stat_str *sptr, int nstats,
60074 X           struct pstruct pst, struct hist_str *histp,
60075 X           int do_trim, struct rstat_str *rs)
60076 {
60077 X  int i, j;
60078 X  double s_score, s2_score, ssd;
60079 X  double ztrim;
60080 X  int nit, max_hscore;
60081 X  char s_string[128];
60082 X  char *f_string;
60083 X
60084 X  f_string = &(histp->stat_info[0]);
60085 X  /*   db->entries = db->length = db->carry = 0; */
60086 X
60087 X  max_hscore = calc_thresh(pst, nstats, rs->ngLambda,
60088 X                          rs->ngK, rs->ngH, &ztrim);
60089 X
60090 X  s_score = s2_score = 0.0;
60091 X
60092 X  histp->entries = 0;
60093 X
60094 X  for ( j = 0, i = 0; i < nstats; i++) {
60095 X    if (sptr[i].score > 0 && sptr[i].score <= max_hscore) {
60096 X      s_score += (ssd=(double)sptr[i].score);
60097 X      s2_score += ssd * ssd;
60098 X      histp->entries++;
60099 X      /* 
60100 X      db->length += sptr[i].n1;
60101 X      if (db->length > LONG_MAX) {
60102 X       db->carry++;
60103 X       db->length -= LONG_MAX;
60104 X      }
60105 X      */
60106 X      j++;
60107 X    }
60108 X  }
60109 X
60110 X  if (j > 1 ) {
60111 X    rs->mu = s_score/(double)j;
60112 X    rs->mean_var = s2_score - (double)j * rs->mu * rs->mu;
60113 X    rs->mean_var /= (double)(j-1);
60114 X  }
60115 X  else {
60116 X    rs->mu = 50.0;
60117 X    rs->mean_var = 10.0;
60118 X  }
60119 X  
60120 X  if (rs->mean_var < 0.01) {
60121 X    rs->mean_var = (rs->mu > 1.0) ? rs->mu: 1.0;
60122 X  }
60123 X
60124 X  /* now remove some scores */
60125 X
60126 X  nit = 5;
60127 X  while (nit-- > 0) {
60128 X    rs->n_trimmed = 0;
60129 X
60130 X    for (i=0; i< nstats; i++) {
60131 X      if (sptr[i].n1 < 0) continue;
60132 X      ssd = find_zn(sptr[i].score,sptr[i].escore,sptr[i].n1,sptr[i].comp, rs);
60133 X      if (ssd > ztrim || ssd < 20.0) {
60134 X       /*      fprintf(stderr,"removing %3d %3d %4.1f\n",
60135 X               sptr[i].score, sptr[i].n1,ssd); */
60136 X       ssd = sptr[i].score;
60137 X       s_score -= ssd;
60138 X       s2_score -= ssd*ssd;
60139 X       j--;
60140 X       rs->n_trimmed++;
60141 X       histp->entries--;
60142 X       sptr[i].n1 = -sptr[i].n1;
60143 X      }
60144 X    }
60145 X
60146 X    if (j > 1 ) {
60147 X      rs->mu = s_score/(double)j;
60148 X      rs->mean_var = s2_score - (double)j * rs->mu * rs->mu;
60149 X      rs->mean_var /= (double)(j-1);
60150 X    }
60151 X    else {
60152 X      rs->mu = 50.0;
60153 X      rs->mean_var = 10.0;
60154 X    }
60155 X
60156 X    if (rs->mean_var < 0.01) {
60157 X      rs->mean_var = (rs->mu > 1.0) ? rs->mu: 1.0;
60158 X    }
60159 X
60160 X    if (rs->n_trimmed < LHISTC) {
60161 X      /*
60162 X       fprintf(stderr,"nprune %d at %d\n",nprune,nit);
60163 X       */
60164 X      break;
60165 X    }
60166 X  }
60167 X
60168 X  if (pst.zsflag < 10) s_string[0]='\0';
60169 X  else if (pst.zs_win > 0)
60170 X    sprintf(s_string,"(shuffled, win: %d)",pst.zs_win);
60171 X  else strncpy(s_string,"(shuffled)",sizeof(s_string));
60172 X
60173 X  sprintf(f_string,"%s unscaled statistics: mu= %6.4f  var=%6.4f; Lambda= %6.4f",
60174 X         s_string, rs->mu,rs->mean_var,PI_SQRT6/sqrt(rs->mean_var));
60175 X  return AVE_STATS;
60176 }
60177 X
60178 X
60179 /*
60180 This routine calculates the maximum likelihood estimates for the
60181 extreme value distribution exp(-exp(-(-x-a)/b)) using the formula
60182 X
60183 X       <lambda> = x_m - sum{ x[i] * exp (-x[i]<lambda>)}/sum{exp (-x[i]<lambda>)}
60184 X       <a> = -<1/lambda> log ( (1/nlib) sum { exp(-x[i]/<lambda> } )
60185 X
60186 X       The <a> parameter can be transformed into and K
60187 X       of the formula: 1 - exp ( - K m n exp ( - lambda S ))
60188 X       using the transformation: 1 - exp ( -exp -(lambda S + log(K m n) ))
60189 X                       1 - exp ( -exp( - lambda ( S + log(K m n) / lambda))
60190 X
60191 X                       a = log(K m n) / lambda
60192 X                       a lambda = log (K m n)
60193 X                       exp(a lambda)  = K m n 
60194 X        but from above: a lambda = log (1/nlib sum{exp( -x[i]*lambda)})
60195 X        so:            K m n = (1/n sum{ exp( -x[i] *lambda)})
60196 X                       K = sum{}/(nlib m n )
60197 X
60198 */
60199 X
60200 void
60201 alloc_hist(struct llen_str *llen)
60202 {
60203 X  int max_llen, i;
60204 X  max_llen = llen->max;
60205 X
60206 X  if (llen->hist == NULL) {
60207 X    llen->hist = (int *)calloc((size_t)(max_llen+1),sizeof(int));
60208 X    llen->score_sums = (double *)calloc((size_t)(max_llen + 1),sizeof(double));
60209 X    llen->score2_sums =(double *)calloc((size_t)(max_llen + 1),sizeof(double));
60210 X    llen->score_var = (double *)calloc((size_t)(max_llen + 1),sizeof(double));
60211 X  }
60212 X
60213 X  for (i=0; i< max_llen+1; i++) {
60214 X      llen->hist[i] = 0;
60215 X      llen->score_var[i] = llen->score_sums[i] = llen->score2_sums[i] = 0.0;
60216 X  }
60217 }
60218 X  
60219 void
60220 free_hist(struct llen_str *llen)
60221 {
60222 X  if (llen->hist!=NULL) {
60223 X    free(llen->score_var);
60224 X    free(llen->score2_sums);
60225 X    free(llen->score_sums);
60226 X    free(llen->hist);
60227 X    llen->hist=NULL;
60228 X  }
60229 }
60230 X
60231 void
60232 inithist(struct llen_str *llen, struct pstruct pst, int max_hscore)
60233 {
60234 X  llen->max = MAX_LLEN;
60235 X
60236 X  llen->max_score = -1;
60237 X  llen->min_score=10000;
60238 X
60239 X  alloc_hist(llen);
60240 X
60241 X  llen->zero_s = 0;
60242 X  llen->min_length = 10000;
60243 X  llen->max_length = 0;
60244 }
60245 X
60246 void
60247 addhist(struct llen_str *llen, int score, int length, int max_hscore)
60248 {
60249 X  int llength; 
60250 X  double dscore;
60251 X
60252 X  if ( score<=0 || length < LENGTH_CUTOFF) {
60253 X    llen->min_score = 0;
60254 X    llen->zero_s++;
60255 X    return ;
60256 X  }
60257 X
60258 X  if (score < llen->min_score) llen->min_score = score;
60259 X  if (score > llen->max_score) llen->max_score = score;
60260 X
60261 X  if (length > llen->max_length) llen->max_length = length;
60262 X  if (length < llen->min_length) llen->min_length = length;
60263 X  if (score > max_hscore) score = max_hscore;
60264 X
60265 X  llength = (int)(LN_FACT*log((double)length)+0.5);
60266 X
60267 X  if (llength < 0 ) llength = 0;
60268 X  if (llength > llen->max) llength = llen->max;
60269 X  llen->hist[llength]++;
60270 X  dscore = (double)score;
60271 X  llen->score_sums[llength] += dscore;
60272 X  llen->score2_sums[llength] += dscore * dscore;
60273 X
60274 X  /*
60275 X  db->entries++;
60276 X  db->length += length;
60277 X  if (db->length > LONG_MAX) {db->carry++;db->length -= LONG_MAX;}
60278 X  */
60279 }
60280 X
60281 /* histogram will go from z-scores of 20 .. 100 with mean 50 and z=10 */
60282 X
60283 X
60284 void
60285 inithistz(int mh, struct hist_str *histp )
60286 {
60287 X  int i;
60288 X
60289 X  histp->min_hist = 20;
60290 X  histp->max_hist = 120;
60291 X
60292 X  histp->histint = (int)
60293 X    ((double)(histp->max_hist - histp->min_hist + 2)/(double)mh+0.5);
60294 X  histp->maxh = (int)
60295 X    ((double)(histp->max_hist - histp->min_hist + 2)/(double)histp->histint+0.5);
60296 X
60297 X  if (histp->hist_a==NULL) {
60298 X    if ((histp->hist_a=(int *)calloc((size_t)histp->maxh,sizeof(int)))==
60299 X       NULL) {
60300 X      fprintf(stderr," cannot allocate %d for histogram\n",histp->maxh);
60301 X      histp->histflg = 0;
60302 X    }
60303 X    else histp->histflg = 1;
60304 X  }
60305 X  else {
60306 X    for (i=0; i<histp->maxh; i++) histp->hist_a[i]=0;
60307 X  }
60308 }
60309 X
60310 /* fasts/f will not show any histogram */
60311 void
60312 addhistz(double zs, struct hist_str *histp)
60313 {
60314 }
60315 X
60316 void
60317 prune_hist(struct llen_str *llen, int score, int length, int max_hscore,
60318 X          long *entries)
60319 {
60320 X  int llength;
60321 X  double dscore;
60322 X
60323 X  if (score <= 0 || length < LENGTH_CUTOFF) return;
60324 X
60325 X  if (score > max_hscore) score = max_hscore;
60326 X
60327 X  llength = (int)(LN_FACT*log((double)length)+0.5);
60328 X
60329 X  if (llength < 0 ) llength = 0;
60330 X  if (llength > llen->max) llength = llen->max;
60331 X  llen->hist[llength]--;
60332 X  dscore = (double)score;
60333 X  llen->score_sums[llength] -= dscore;
60334 X  llen->score2_sums[llength] -= dscore * dscore;
60335 X
60336 X  (*entries)--;
60337 X  /*
60338 X  if (length < db->length) db->length -= length;
60339 X  else {db->carry--; db->length += (LONG_MAX - (unsigned long)length);}
60340 X  */
60341 }  
60342 X
60343 /* fit_llen: no trimming
60344 X   (1) regress scores vs log(n) using weighted variance
60345 X   (2) calculate mean variance after length regression
60346 */
60347 X
60348 void
60349 fit_llen(struct llen_str *llen, struct rstat_str *pr)
60350 {
60351 X  int j;
60352 X  int n;
60353 X  int n_size;
60354 X  double x, y2, u, z;
60355 X  double mean_x, mean_y, var_x, var_y, covar_xy;
60356 X  double mean_y2, covar_xy2, var_y2, dllj;
60357 X
60358 X  double sum_x, sum_y, sum_x2, sum_xy, sum_v, delta, n_w;
60359 X  
60360 /* now fit scores to best linear function of log(n), using
60361 X   simple linear regression */
60362 X  
60363 X  for (llen->min=0; llen->min < llen->max; llen->min++)
60364 X    if (llen->hist[llen->min]) break;
60365 X  llen->min--;
60366 X
60367 X  for (n_size=0,j = llen->min; j < llen->max; j++) {
60368 X    if (llen->hist[j] > 1) {
60369 X      dllj = (double)llen->hist[j];
60370 X      llen->score_var[j] = llen->score2_sums[j]/dllj
60371 X       - (llen->score_sums[j]/dllj)*(llen->score_sums[j]/dllj);
60372 X      llen->score_var[j] /= (double)(llen->hist[j]-1);
60373 X      if (llen->score_var[j] <= 0.1 ) llen->score_var[j] = 0.1;
60374 X      n_size++;
60375 X    }
60376 X  }
60377 X
60378 X  pr->nb_tot = n_size;
60379 X
60380 X  n_w = 0.0;
60381 X  sum_x = sum_y = sum_x2 = sum_xy = sum_v = 0;
60382 X  for (j = llen->min; j < llen->max; j++)
60383 X    if (llen->hist[j] > 1) {
60384 X      x = j + 0.5;
60385 X      dllj = (double)llen->hist[j];
60386 X      n_w += dllj/llen->score_var[j];
60387 X      sum_x +=   dllj * x / llen->score_var[j] ;
60388 X      sum_y += llen->score_sums[j] / llen->score_var[j];
60389 X      sum_x2 +=  dllj * x * x /llen->score_var[j];
60390 X      sum_xy +=  x * llen->score_sums[j]/llen->score_var[j];
60391 X    }
60392 X
60393 X  if (n_size < 5 ) {
60394 X    llen->fit_flag=0;
60395 X    pr->rho = 0;
60396 X    pr->mu = sum_y/n_w;
60397 X    return;
60398 X  }
60399 X  else {
60400 X    delta = n_w * sum_x2 - sum_x * sum_x;
60401 X    if (delta > 0.001) {
60402 X      pr->rho = (n_w * sum_xy  - sum_x * sum_y)/delta;
60403 X      pr->rho_e = n_w/delta;
60404 X      pr->mu = (sum_x2 * sum_y - sum_x * sum_xy)/delta;
60405 X      pr->mu_e = sum_x2/delta;
60406 X    }
60407 X    else {
60408 X      llen->fit_flag = 0;
60409 X      pr->rho = 0;
60410 X      pr->mu = sum_y/n_w;
60411 X      return;
60412 X    }
60413 X  }
60414 X
60415 X  delta = n_w * sum_x2 - sum_x * sum_x;
60416 X  pr->rho = (n_w * sum_xy  - sum_x * sum_y)/delta;
60417 X  pr->mu = (sum_x2 * sum_y - sum_x * sum_xy)/delta;
60418 X
60419 X  n = 0;
60420 X  mean_x = mean_y = mean_y2 = 0.0;
60421 X  var_x = var_y = 0.0;
60422 X  covar_xy = covar_xy2 = 0.0;
60423 X
60424 X  for (j = llen->min; j <= llen->max; j++) 
60425 X   if (llen->hist[j] > 1 ) {
60426 X      n += llen->hist[j];
60427 X      x = (double)j + 0.5;
60428 X      mean_x += (double)llen->hist[j] * x;
60429 X      mean_y += llen->score_sums[j];
60430 X      var_x += (double)llen->hist[j] * x * x;
60431 X      var_y += llen->score2_sums[j];
60432 X      covar_xy += x * llen->score_sums[j];
60433 X    }
60434 X  mean_x /= n; mean_y /= n;
60435 X  var_x = var_x / n - mean_x * mean_x;
60436 X  var_y = var_y / n - mean_y * mean_y;
60437 X  
60438 X  covar_xy = covar_xy / n - mean_x * mean_y;
60439 /*
60440 X  pr->rho = covar_xy / var_x;
60441 X  pr->mu = mean_y - pr->rho * mean_x;
60442 */
60443 X  mean_y2 = covar_xy2 = var_y2 = 0.0;
60444 X  for (j = llen->min; j <= llen->max; j++) 
60445 X    if (llen->hist[j] > 1) {
60446 X      x = (double)j + 0.5;
60447 X      u = pr->rho * x + pr->mu;
60448 X      y2 = llen->score2_sums[j] - 2.0 * llen->score_sums[j] * u + llen->hist[j] * u * u;
60449 /*
60450 X      dllj = (double)llen->hist[j];
60451 X      fprintf(stderr,"%.2f\t%d\t%g\t%g\n",x/LN_FACT,llen->hist[j],
60452 X             llen->score_sums[j]/dllj,y2/dllj);
60453 */
60454 X      mean_y2 += y2;
60455 X      var_y2 += y2 * y2;
60456 X      covar_xy2 += x * y2;
60457 X      /*      fprintf(stderr,"%6.1f %4d %8d %8d %7.2f %8.2f\n",
60458 X             x,llen->hist[j],llen->score_sums[j],llen->score2_sums[j],u,y2); */
60459 X    }
60460 X  
60461 X  pr->mean_var = mean_y2 /= (double)n;
60462 X  covar_xy2 = covar_xy2 / (double)n - mean_x * mean_y2;
60463 X
60464 X  if (pr->mean_var <= 0.01) {
60465 X    llen->fit_flag = 0;
60466 X    pr->mean_var = (pr->mu > 1.0) ? pr->mu: 1.0;
60467 X  }
60468 X
60469 X  /*
60470 X  fprintf(stderr," rho1/mu1: %.4f/%.4f mean_var %.4f\n",
60471 X         pr->rho*LN_FACT,pr->mu,pr->mean_var);
60472 X  */
60473 X  if (n > 1) pr->var_e = (var_y2/n - mean_y2 * mean_y2)/(n-1);
60474 X  else pr->var_e = 0.0;
60475 X
60476 X  if (llen->fit_flag) {
60477 X    pr->rho2 = covar_xy2 / var_x;
60478 X    pr->mu2 = pr->mean_var - pr->rho2 * mean_x;
60479 X  }
60480 X  else {
60481 X    pr->rho2 = 0;
60482 X    pr->mu2 = pr->mean_var;
60483 X  }
60484 X
60485 X  if (pr->rho2 < 0.0 )
60486 X    z = (pr->rho2 * LN_FACT*log((double)llen->max_length) + pr->mu2 > 0.0) ? llen->max_length : exp((-1.0 - pr->mu2 / pr->rho2)/LN_FACT);
60487 X  else z =  pr->rho2 ? exp((1.0 - pr->mu2 / pr->rho2)/LN_FACT) : LENGTH_CUTOFF;
60488 X  if (z < 2*LENGTH_CUTOFF) z = 2*LENGTH_CUTOFF;
60489 X
60490 X  pr->var_cutoff = pr->rho2 * LN_FACT*log(z) + pr->mu2;
60491 }
60492 X
60493 /* fit_llens: trim high variance bins
60494 X   (1) regress scores vs log(n) using weighted variance
60495 X   (2) regress residuals vs log(n)
60496 X   (3) remove high variance bins
60497 X   (4) calculate mean variance after length regression
60498 */
60499 X
60500 void
60501 fit_llens(struct llen_str *llen, struct rstat_str *pr)
60502 {
60503 X  int j;
60504 X  int n, n_u2;
60505 X  double x, y, y2, u, u2, v, z;
60506 X  double mean_x, mean_y, var_x, var_y, covar_xy;
60507 X  double mean_y2, covar_xy2;
60508 X  double mean_u2, mean_3u2, dllj;
60509 X  double sum_x, sum_y, sum_x2, sum_xy, sum_v, delta, n_w;
60510 X
60511 /* now fit scores to best linear function of log(n), using
60512 X   simple linear regression */
60513 X  
60514 X  for (llen->min=0; llen->min < llen->max; llen->min++)
60515 X    if (llen->hist[llen->min]) break;
60516 X  llen->min--;
60517 X
60518 X  for (j = llen->min; j < llen->max; j++) {
60519 X    if (llen->hist[j] > 1) {
60520 X      dllj = (double)llen->hist[j];
60521 X      llen->score_var[j] = (double)llen->score2_sums[j]/dllj
60522 X       - (llen->score_sums[j]/dllj)*(llen->score_sums[j]/dllj);
60523 X      llen->score_var[j] /= (double)(llen->hist[j]-1);
60524 X      if (llen->score_var[j] <= 1.0 ) llen->score_var[j] = 1.0;
60525 X    }
60526 X  }
60527 X         
60528 X  n_w = 0.0;
60529 X  sum_x = sum_y = sum_x2 = sum_xy = sum_v = 0;
60530 X  for (j = llen->min; j < llen->max; j++)
60531 X    if (llen->hist[j] > 1) {
60532 X      x = j + 0.5;
60533 X      dllj = (double)llen->hist[j];
60534 X      n_w += dllj/llen->score_var[j];
60535 X      sum_x +=   dllj * x / llen->score_var[j] ;
60536 X      sum_y += llen->score_sums[j] / llen->score_var[j];
60537 X      sum_x2 +=  dllj * x * x /llen->score_var[j];
60538 X      sum_xy +=  x * llen->score_sums[j]/llen->score_var[j];
60539 X    }
60540 X
60541 X  delta = n_w * sum_x2 - sum_x * sum_x;
60542 X  pr->rho = (n_w * sum_xy  - sum_x * sum_y)/delta;
60543 X  pr->mu = (sum_x2 * sum_y - sum_x * sum_xy)/delta;
60544 X
60545 /* printf(" rho1/mu1: %.2f/%.2f\n",pr->rho*LN_FACT,pr->mu); */
60546 X
60547 X  n = 0;
60548 X  mean_x = mean_y = mean_y2 = 0.0;
60549 X  var_x = var_y = 0.0;
60550 X  covar_xy = covar_xy2 = 0.0;
60551 X
60552 X  for (j = llen->min; j <= llen->max; j++) 
60553 X    if (llen->hist[j] > 1 ) {
60554 X      n += llen->hist[j];
60555 X      x = (double)j + 0.5;
60556 X      dllj = (double)llen->hist[j];
60557 X      mean_x += dllj * x;
60558 X      mean_y += llen->score_sums[j];
60559 X      var_x += dllj * x * x;
60560 X      var_y += llen->score2_sums[j];
60561 X      covar_xy += x * llen->score_sums[j];
60562 X    }
60563 X  mean_x /= n; mean_y /= n;
60564 X  var_x = var_x / n - mean_x * mean_x;
60565 X  var_y = var_y / n - mean_y * mean_y;
60566 X  
60567 X  covar_xy = covar_xy / n - mean_x * mean_y;
60568 /*  pr->rho = covar_xy / var_x;
60569 X  pr->mu = mean_y - pr->rho * mean_x;
60570 */
60571 X
60572 X  mean_y2 = covar_xy2 = 0.0;
60573 X  for (j = llen->min; j <= llen->max; j++) 
60574 X    if (llen->hist[j] > 1) {
60575 X      x = (double)j + 0.5;
60576 X      u = pr->rho * x + pr->mu;
60577 X      y2 = llen->score2_sums[j] - 2 * llen->score_sums[j] * u + llen->hist[j] * u * u;
60578 X      mean_y2 += y2;
60579 X      covar_xy2 += x * y2;
60580 X    }
60581 X  
60582 X  mean_y2 /= n;
60583 X  covar_xy2 = covar_xy2 / n - mean_x * mean_y2;
60584 X  pr->rho2 = covar_xy2 / var_x;
60585 X  pr->mu2 = mean_y2 - pr->rho2 * mean_x;
60586 X
60587 X  if (pr->rho2 < 0.0 )
60588 X    z = (pr->rho2 * LN_FACT*log((double)llen->max_length) + pr->mu2 > 0.0) ? llen->max_length : exp((-1.0 - pr->mu2 / pr->rho2)/LN_FACT);
60589 X  else z =  pr->rho2 ? exp((1.0 - pr->mu2 / pr->rho2)/LN_FACT) : LENGTH_CUTOFF;
60590 X  if (z < 2* LENGTH_CUTOFF) z = 2*LENGTH_CUTOFF;
60591 X
60592 X  pr->var_cutoff = pr->rho2*LN_FACT*log(z) + pr->mu2;
60593 X
60594 /*  fprintf(stderr,"\nminimum allowed predicted variance (%0.2f) at n = %.0f\n",
60595 X        pr->var_cutoff,z);
60596 */
60597 X  mean_u2 = 0.0;
60598 X  n_u2 = 0;
60599 X  for ( j = llen->min; j < llen->max; j++) {
60600 X    y = j+0.5;
60601 X    dllj = (double)llen->hist[j];
60602 X    x = pr->rho * y + pr->mu;
60603 X    v = pr->rho2 * y + pr->mu2;
60604 X    if (v < pr->var_cutoff) v = pr->var_cutoff;
60605 X    if (llen->hist[j]> 1) {
60606 X      u2 =  (llen->score2_sums[j] - 2 * x * llen->score_sums[j] + dllj * x * x) - v*dllj;
60607 X      mean_u2 += llen->score_var[j] = u2*u2/(llen->hist[j]-1);
60608 X      n_u2++;
60609 X      /*      fprintf(stderr," %d (%d) u2: %.2f v*ll: %.2f %.2f\n",
60610 X             j,llen->hist[j],u2,v*dllj,sqrt(llen->score_var[j])); */
60611 X    }
60612 X    else llen->score_var[j] = -1.0;
60613 X  }
60614 X
60615 X  mean_u2 = sqrt(mean_u2/(double)n_u2);
60616 X  /* fprintf(stderr," mean s.d.: %.2f\n",mean_u2); */
60617 X
60618 X  mean_3u2 = mean_u2*3.0;
60619 X
60620 X  for (j = llen->min; j < llen->max; j++) {
60621 X    if (llen->hist[j] <= 1) continue;
60622 X    if (sqrt(llen->score_var[j]) > mean_3u2) {
60623 X      /*      fprintf(stderr," removing %d %d %.2f\n",
60624 X            j, (int)(exp((double)j/LN_FACT)-0.5),
60625 X            sqrt(llen->score_var[j]));
60626 X            */
60627 X      pr->nb_trimmed++;
60628 X      pr->n1_trimmed += llen->hist[j];
60629 X      llen->hist[j] = 0;
60630 X    }
60631 X  }
60632 X  fit_llen(llen, pr);
60633 }
60634 X
60635 X
60636 /* REG_STATS - Z() from rho/mu/mean_var */
60637 double find_zr(int score, double escore, int length, double comp, 
60638 X             struct rstat_str *rs)
60639 {
60640 X  double log_len, z;
60641 X  
60642 X  if (score <= 0) return 0.0;
60643 X  if ( length < LENGTH_CUTOFF) return 0.0;
60644 X
60645 X  log_len = LN_FACT*log((double)(length));
60646 /*  var = rs->rho2 * log_len + rs->mu2;
60647 X  if (var < rs->var_cutoff) var = rs->var_cutoff;
60648 */
60649 X
60650 X  z = ((double)score - rs->rho * log_len - rs->mu) / sqrt(rs->mean_var);
60651 X
60652 X  return (50.0 + z*10.0);
60653 }
60654 X
60655 double find_zt(int score, double escore, int length, double comp, 
60656 X             struct rstat_str *rs)
60657 {
60658 X  if (escore > 0.0) return -log(escore)/M_LN2;
60659 X  else return 744.440071/M_LN2;
60660 }
60661 X
60662 double find_zn(int score, double escore, int length, double comp,
60663 X             struct rstat_str *rs)
60664 {
60665 X  double z;
60666 X  
60667 X  z = ((double)score - rs->mu) / sqrt(rs->mean_var);
60668 X
60669 X  return (50.0 + z*10.0);
60670 }
60671 X
60672 /* computes E value for a given z value, assuming extreme value distribution */
60673 double
60674 z_to_E(double zs, long entries, struct db_str db)
60675 {
60676 X  double e, n;
60677 X
60678 X  /*  if (db->entries < 5) return (double)db.entries; */
60679 X  if (entries < 1) { n = db.entries;}
60680 X  else {n = entries;}
60681 X
60682 X  if (zs > ZS_MAX) return 0.0;
60683 X
60684 X  e = exp(-PI_SQRT6 * zs - EULER_G);
60685 X  return n * (e > .01 ? 1.0 - exp(-e) : e);
60686 }
60687 X
60688 double
60689 zs_to_p(double zs)
60690 {
60691 X  return zs;
60692 }
60693 X
60694 /* this version assumes the probability is in the ->zscore variable,
60695 X   which is provided by this file after last_scale()
60696 */
60697 X
60698 double
60699 zs_to_bit(double zs, int n0, int n1)
60700 {
60701 X  return zs+log((double)(n0*n1))/M_LN2 ;
60702 }
60703 X
60704 /* computes E-value for a given z value, assuming extreme value distribution */
60705 double
60706 zs_to_E(double zs,int n1, int dnaseq, long entries, struct db_str db)
60707 {
60708 X  double e, z, k;
60709 X
60710 X  /*  if (db->entries < 5) return 0.0; */
60711 X
60712 X  if (zs > ZS_MAX ) return 0.0;
60713 X
60714 X  if (entries < 1) entries = db.entries;
60715 X
60716 X  if (dnaseq == SEQT_DNA || dnaseq == SEQT_RNA) {
60717 X    k = (double)db.length /(double)n1;
60718 X    if (db.carry > 0) { k *= (double)db.carry * (double)LONG_MAX;}
60719 X  }
60720 X  else k = (double)entries;
60721 X
60722 X  if (k < 1.0) k = 1.0;
60723 X
60724 X  zs *= M_LN2;
60725 X  if ( zs > 100.0) e = 0.0;
60726 X  else e =  exp(-zs);
60727 X  return k * e;
60728 }
60729 X
60730 /* computes E-value for a given z value, assuming extreme value distribution */
60731 double
60732 E_to_zs(double E, long entries)
60733 {
60734 X  double e, z;
60735 X  int error;
60736 X
60737 X  e = E/(double)entries;
60738 X
60739 #ifndef NORMAL_DIST
60740 X  z = (log(e)+EULER_G)/(-PI_SQRT6);
60741 X  return z*10.0+50.0;
60742 #else
60743 X  z = np_to_z(1.0-e,&error);
60744 X
60745 X  if (!error) return z*10.0+50.0;
60746 X  else return 0.0;
60747 #endif
60748 }
60749 X
60750 /* computes 1.0 - E value for a given z value, assuming extreme value
60751 X   distribution */
60752 double
60753 zs_to_Ec(double zs, long entries)
60754 {
60755 X  double e, z;
60756 X
60757 X  if (entries < 5) return 0.0;
60758 X
60759 X  z = (zs - 50.0)/10.0;
60760 X
60761 X  if (z > ZS_MAX) return 1.0;
60762 X
60763 X  e =  exp(-PI_SQRT6 * z - EULER_G);
60764 X  return (double)entries * (e > .01 ?  exp(-e) : 1.0 - e);
60765 }
60766 X
60767 void
60768 vsort(v,s,n)
60769 X       double *v; int *s, n;
60770 {
60771 X  int gap, i, j;
60772 X  double tmp;
60773 X  int itmp;
60774 X       
60775 X  for (gap=n/2; gap>0; gap/=2)
60776 X    for (i=gap; i<n; i++)
60777 X      for (j=i-gap; j>=0; j -= gap) {
60778 X       if (v[j] >= v[j+gap]) break;
60779 X       tmp = v[j]; v[j]=v[j+gap]; v[j+gap]=tmp;
60780 X       itmp = s[j]; s[j]=s[j+gap]; s[j+gap]=itmp;
60781 X      }
60782 }
60783 X
60784 void
60785 sort_escore(double *v, int n)
60786 {
60787 X  int gap, i, j;
60788 X  double dtmp;
60789 X       
60790 X  for (gap=n/2; gap>0; gap/=2) {
60791 X    for (i=gap; i<n; i++) {
60792 X      for (j=i-gap; j>=0; j -= gap) {
60793 X       if (v[j] <= v[j+gap]) break;
60794 X       dtmp = v[j];
60795 X       v[j] = v[j+gap];
60796 X       v[j+gap] = dtmp;
60797 X      }
60798 X    }
60799 X  }
60800 }
60801 X
60802 /* scale_tat - compute 'a', 'b', 'c' coefficients for scaling fasts/f
60803 X   escores 
60804 X   5-May-2003 - also calculate index for high ties
60805 */
60806 void
60807 scale_tat(double *escore, int nstats,
60808 X         long db_entries, int do_trim,
60809 X         struct rstat_str *rs)
60810 {
60811 X  int i, j, k, start;
60812 X  double *x, *lnx, *lny;
60813 X
60814 X  /*   sort_escore(escore, nstats); */
60815 X
60816 X  while (*escore<0.0) {escore++; nstats--; }
60817 X
60818 X  x = (double *) calloc(nstats, sizeof(double));
60819 X  if(x == NULL) {
60820 X    fprintf(stderr, "Couldn't calloc tatE/x\n");
60821 X    exit(1);
60822 X  }
60823 X
60824 X  lnx = (double *) calloc(nstats,sizeof(double));
60825 X  if(lnx == NULL) {
60826 X    fprintf(stderr, "Couldn't calloc tatE/lnx\n");
60827 X    exit(1);
60828 X  }
60829 X  
60830 X  lny = (double *) calloc(nstats,sizeof(double));
60831 X  if(lny == NULL) {
60832 X    fprintf(stderr, "Couldn't calloc tatE/lny\n");
60833 X    exit(1);
60834 X  }
60835 X  
60836 X  for(i = 0 ; i < nstats ; ) {
60837 X
60838 X    lny[i] = log(escore[i]);
60839 X
60840 X    for(j = i+1 ; j < nstats ; j++) {
60841 X       if(escore[j] != escore[i]) break;
60842 X    }
60843 X
60844 X    x[i] = ((((double)i + (double)(j - i - 1)/2.0)*(double)nstats/(double)db_entries)+1.0)/(double)nstats;
60845 X    lnx[i] = log(x[i]);
60846 X
60847 X    for(k = i+1 ; k < j ; k++) {
60848 X      lny[k]=lny[i];
60849 X      x[k] = x[i];
60850 X      lnx[k]=lnx[i];
60851 X    }
60852 X    i = k;
60853 X  }
60854 X
60855 X  if (!do_trim) {
60856 X    start = 0;
60857 X  } else {
60858 X    start = 0.05 * (double) nstats;
60859 X    start = start > 500 ? 500 : start;
60860 X  }
60861 X
60862 X  linreg(lny, x, lnx, nstats, &rs->tat_a, &rs->tat_b, &rs->tat_c, start);
60863 X
60864 X  /* I have the coefficients I need - a, b, c; free arrays */
60865 X
60866 X  free(lny);
60867 X  free(lnx);
60868 X  free(x);
60869 X
60870 X  /* calculate tie_j - the index below which all scores are considered
60871 X     positional ties */
60872 X
60873 X  rs->tie_j = 0.005 * db_entries;
60874 }
60875 X
60876 void
60877 linreg(double *lny, double *x, double *lnx, int n,
60878 X       double *a, double *b, double *c, int start) {
60879 X
60880 X  double yf1, yf2, yf3;
60881 X  double f1f1, f1f2, f1f3;
60882 X  double f2f2, f2f3;
60883 X  double f3f3, delta;
60884 X
60885 X  int i;
60886 X
60887 X  yf1 = yf2 = yf3 = 0.0;
60888 X  f1f1 = f1f2 = f1f3 = f2f2 = f2f3 = f3f3 = 0.0;
60889 X
60890 X  for(i = start; i < n; i++) {
60891 X    yf1 += lny[i] * lnx[i];
60892 X    yf2 += lny[i] * x[i];
60893 X    yf3 += lny[i];
60894 X
60895 X    f1f1 += lnx[i] * lnx[i];
60896 X    f1f2 += lnx[i] * x[i];
60897 X    f1f3 += lnx[i];
60898 X
60899 X    f2f2 += x[i] * x[i];
60900 X    f2f3 += x[i];
60901 X
60902 X    f3f3 += 1.0;
60903 X  }
60904 X
60905 X  delta = det(f1f1, f1f2, f1f3, f1f2, f2f2, f2f3, f1f3, f2f3, f3f3);
60906 X
60907 X  *a = det(yf1, f1f2, f1f3, yf2, f2f2, f2f3, yf3, f2f3, f3f3) / delta;
60908 X  *b = det(f1f1, yf1, f1f3, f1f2, yf2, f2f3, f1f3, yf3, f3f3) / delta;
60909 X  *c = det(f1f1, f1f2, yf1, f1f2, f2f2, yf2, f1f3, f2f3, yf3) / delta;
60910 X
60911 }
60912 X
60913 double det(double a11, double a12, double a13,
60914 X          double a21, double a22, double a23,
60915 X          double a31, double a32, double a33)
60916 {
60917 X  double result;
60918 X
60919 X  result = a11 * (a22 * a33 - a32 * a23);
60920 X  result -= a12 * (a21 * a33 - a31 * a23);
60921 X  result += a13 * (a21 * a32 - a31 * a22);
60922 X    
60923 X  return result;
60924 }
60925 X
60926 void
60927 last_stats(const unsigned char *aa0, int n0,
60928 X          struct stat_str *sptr, int nstats,
60929 X          struct beststr **bestp_arr, int nbest,
60930 X          struct mngmsg m_msg, struct pstruct pst,
60931 X          struct hist_str *histp, struct rstat_str **rs_sp)
60932 {
60933 X  double *obs_escore;
60934 X  int i, nobs, nobs_t, do_trim;
60935 X  long db_entries;
60936 X  struct rstat_str *rs_s;
60937 X
60938 X  if (*rs_sp == NULL) {
60939 X    if ((rs_s=(struct rstat_str *)calloc(1,sizeof(struct rstat_str)))==NULL) {
60940 X      fprintf(stderr," cannot allocate rs_s: %ld\n",sizeof(struct rstat_str));
60941 X      exit(1);
60942 X    }
60943 X    else *rs_sp = rs_s;
60944 X  }
60945 X  else rs_s = *rs_sp;
60946 X    
60947 X  histp->entries = 0;
60948 X
60949 X  sortbeste(bestp_arr,nbest);
60950 X
60951 X  rs_s->spacefactor = 
60952 X    calc_spacefactor(aa0, n0, m_msg.nm0,pst.nsq);
60953 X
60954 X  if (pst.zsflag >= 1 && pst.zsflag <= 4) {
60955 X    if (m_msg.escore_flg) {
60956 X      nobs = nbest;
60957 X      do_trim = 1;
60958 X    }
60959 X    else {
60960 X      nobs = nstats;
60961 X      do_trim = 0;
60962 X    }
60963 X
60964 X    if ((obs_escore = (double *)calloc(nobs,sizeof(double)))==NULL) {
60965 X      fprintf(stderr," cannot allocate obs_escore[%d]\n",nbest);
60966 X      exit(1);
60967 X    }
60968 X
60969 X    if (m_msg.escore_flg) {
60970 X      for (i=nobs=0; i<nbest; i++) {
60971 X       if (bestp_arr[i]->escore<= 1.00)
60972 X         obs_escore[nobs++]=bestp_arr[i]->escore;
60973 X      }
60974 X      /*
60975 X      nobs_t = nobs;
60976 X      for (i=0; i<nbest; i++) {
60977 X       if (bestp_arr[i]->escore >= 0.99 &&
60978 X           bestp_arr[i]->escore <= 1.00)
60979 X         obs_escore[nobs++]=bestp_arr[i]->escore;
60980 X      }
60981 X      */
60982 X      db_entries = m_msg.db.entries;
60983 X    }
60984 X    else {
60985 X      for (i=nobs=0; i<nstats; i++) {
60986 X       if (sptr[i].escore <= 1.00 ) obs_escore[nobs++]=sptr[i].escore;
60987 X      }
60988 X      /*
60989 X      nobs_t = nobs;
60990 X      for (i=0; i<nstats; i++) {
60991 X       if (sptr[i].escore >= 0.99 &&
60992 X           sptr[i].escore <= 1.0) obs_escore[nobs++]=sptr[i].escore;
60993 X      }
60994 X      */
60995 X      db_entries = nobs;
60996 /*    db_entries = m_msg.db.entries;*/
60997 X    }
60998 X
60999 X    sortbesto(obs_escore,nobs);
61000 X    if (nobs > 100) {
61001 X      scale_tat(obs_escore,nobs,db_entries,do_trim,rs_s);
61002 X      rs_s->have_tat=1;
61003 X      sprintf(histp->stat_info,"scaled Tatusov statistics (%d): tat_a: %6.4f tat_b: %6.4f tat_c: %6.4f",
61004 X             nobs,rs_s->tat_a, rs_s->tat_b, rs_s->tat_c);
61005 X    }
61006 X    else {
61007 X      rs_s->have_tat=0;
61008 X      sprintf(histp->stat_info,"Space_factor %.4g scaled statistics",
61009 X           rs_s->spacefactor);
61010 X    }
61011 X    free(obs_escore);
61012 X  }
61013 X  else {
61014 X    rs_s->have_tat=0;
61015 X    histp->stat_info[0] = '\0';
61016 X  }
61017 }
61018 X
61019 /* scale_scores() takes the best (real) scores and re-scales them;
61020 X   beststr bptr[] must be sorted */
61021 X
61022 void
61023 scale_scores(struct beststr **bptr, int nbest, struct db_str db,
61024 X            struct pstruct pst, struct rstat_str *rs)
61025 {
61026 X  int i, j, k;
61027 X  double obs, r_a, r_b, r_c;
61028 X
61029 X  /* this scale function absolutely requires that the results be sorted
61030 X     before it is used */
61031 X
61032 X  sortbeste(bptr,nbest);
61033 X
61034 X  if (!rs->have_tat) {
61035 X    for (i=0; i<nbest; i++) {
61036 X      bptr[i]->escore *= rs->spacefactor;
61037 X    }
61038 X  }
61039 X  else {
61040 X
61041 X    /* here if more than 1000 scores */
61042 X
61043 X    r_a = rs->tat_a; r_b = rs->tat_b; r_c = rs->tat_c;
61044 X
61045 X  /* the problem with scaletat is that the E() value is related to
61046 X     ones position in the list of top scores - thus, knowing the score
61047 X     is not enough - one must know the rank */
61048 X
61049 X    for(i = 0 ; i < nbest ; ) {
61050 X      /* take the bottom 0.5%, and the ties, and treat them all the same */
61051 X      j = i + 1;
61052 X      while (j< nbest && 
61053 X            (j <= (0.005 * db.entries) || bptr[j]->escore == bptr[i]->escore)
61054 X            ) {
61055 X       j++;
61056 X      }
61057 X
61058 X      /* observed frequency */
61059 X      obs = ((double)i + ((double)(j - i - 1)/ 2.0) + 1.0)/(double)db.entries;
61060 X
61061 X      /* make certain ties all have the same correction */
61062 X      for (k = i ; k < j ; k++) {
61063 X       bptr[k]->escore *= obs/exp(r_a*log(obs) + r_b*obs + r_c);
61064 X      }
61065 X      i = k;
61066 X    }
61067 X  }
61068 X
61069 X  for (i=0; i<nbest; i++) {
61070 X    if(bptr[i]->escore > 0.01)
61071 X      bptr[i]->escore = 1.0 - exp(-bptr[i]->escore);
61072 X    if (bptr[i]->escore > 0.0)
61073 X      bptr[i]->zscore = -log(bptr[i]->escore)/M_LN2;
61074 X    else 
61075 X      bptr[i]->zscore = 744.440071/M_LN2;
61076 X    bptr[i]->escore *= pst.zdb_size;
61077 X  }
61078 }
61079 X
61080 double scale_one_score (int ipos, double escore,
61081 X                        struct db_str db,
61082 X                        struct rstat_str *rs) {
61083 X  double obs;
61084 X  double a, b, c;
61085 X
61086 X  if (!rs->have_tat)
61087 X    return escore * rs->spacefactor;
61088 X
61089 X  if (ipos < rs->tie_j) ipos = rs->tie_j/2;
61090 X
61091 X  a = rs->tat_a; b = rs->tat_b; c = rs->tat_c;
61092 X
61093 X  obs = ((double)ipos + 1.0)/(double)db.entries;
61094 X
61095 X  escore *= obs/exp(a*log(obs) + b*obs + c);
61096 X
61097 X  return escore;
61098 }
61099 X
61100 double calc_spacefactor(const unsigned char *aa0, int n0,
61101 X                       int nm0, int nsq) {
61102 X
61103 #if !defined(FASTF)
61104 X  return pow(2.0, (double) nm0) - 1.0;
61105 #else
61106 X
61107 X  int i, j, n, l, nr, bin, k;
61108 X  int nmoff;
61109 X  int **counts;
61110 X  int **factors;
61111 X  double tmp, result = 0.0;
61112 X
61113 X  nmoff = (n0 - nm0 + 1)/nm0+1;
61114 X
61115 X  counts = (int **) calloc(nsq, sizeof(int *));
61116 X  if(counts == NULL) {
61117 X    fprintf(stderr, "couldn't calloc counts array!\n");
61118 X    exit(1);
61119 X  }
61120 X
61121 X  counts[0] = (int *) calloc(nsq * (nmoff - 1), sizeof(int));
61122 X  if(counts[0] == NULL) {
61123 X    fprintf(stderr, "couldn't calloc counts array!\n");
61124 X    exit(1);
61125 X  }
61126 X
61127 X  for(i = 0 ; i < nsq ; i++) {
61128 X    counts[i] = counts[0] + (i * (nmoff - 1));
61129 X  }
61130 X
61131 X  for(i = 0 ; i < nm0 ; i++) {
61132 X    for(j = 0 ; j < (nmoff - 1) ; j++) {
61133 X      counts[ aa0[nmoff * i + j] ] [ j ] ++;
61134 X    }
61135 X  }
61136 X
61137 X  factors = (int **) calloc(nm0 + 1, sizeof(int *));
61138 X  if(factors == NULL) {
61139 X    fprintf(stderr, "Couldn't calloc factors array!\n");
61140 X    exit(1);
61141 X  }
61142 X
61143 X  factors[0] = (int *) calloc((nm0 + 1) * (nmoff - 1), sizeof(int));
61144 X  if(factors[0] == NULL) {
61145 X    fprintf(stderr, "Couldn't calloc factors array!\n");
61146 X    exit(1);
61147 X  }
61148 X
61149 X  for(i = 0 ; i <= nm0 ; i++) {
61150 X    factors[i] = factors[0] + (i * (nmoff - 1));
61151 X  }
61152 X
61153 X  /*
61154 X    this algorithm was adapted from the GAP4 library's NrArrangement function:
61155 X    The GAP Group, GAP --- Groups, Algorithms, and Programming,
61156 X    Version 4.1; Aachen, St Andrews, 1999.
61157 X    (http://www-gap.dcs.st-and.ac.uk/ gap)
61158 X  */
61159 X
61160 X  /* calculate K factors for each column in query: */
61161 X  for(j = 0 ; j < (nmoff - 1) ; j++) {
61162 X
61163 X    /* only one way to select 0 elements */
61164 X    factors[0][j] = 1;
61165 X
61166 X    /* for each of the possible elements in this column */
61167 X    for(n = 0 ; n < nsq ; n++) {
61168 X
61169 X      /* if there aren't any of these, skip it */
61170 X      if(counts[n][j] == 0) { continue; }
61171 X
61172 X      /* loop over the possible lengths of the arrangement: K..0 */
61173 X      for(l = nm0 ; l >= 0 ; l--) {
61174 X       nr = 0;
61175 X       bin = 1;
61176 X
61177 X       /*
61178 X         compute the number of arrangements of length <l>
61179 X         using only the first <n> elements of <mset>
61180 X       */
61181 X       for(i = 0, k = min(counts[n][j], l); i <= k ; i++) {
61182 X
61183 X         /* 
61184 X            add the number of arrangements of length <l>
61185 X            that consist of <l>-<i> of the first <n>-1 elements
61186 X            and <i> copies of the <n>th element
61187 X         */
61188 X         nr += bin * factors[l-i][j];
61189 X         bin = (int) ((float) bin * (float) (l - i) / (float) (i + 1));
61190 X       }
61191 X
61192 X       factors[l][j] = nr;
61193 X      }
61194 X    }
61195 X  }
61196 X
61197 X  result = 0.0;
61198 X  for(i = 1 ; i <= nm0 ; i++) {
61199 X    tmp = 1.0;
61200 X    for(j = 0 ; j < (nmoff - 1) ; j++) {
61201 X      tmp *= (double) factors[i][j];
61202 X    }
61203 X    tmp /= factorial(i, 1);
61204 X    result += tmp;
61205 X  }
61206 X  
61207 X  free(counts[0]);
61208 X  free(counts);
61209 X  free(factors[0]);
61210 X  free(factors);
61211 X
61212 X  return result;
61213 #endif
61214 }
61215 X
61216 void sortbesto (double *obs, int nobs)
61217 {
61218 X  int gap, i, j, k;
61219 X  double v;
61220 X  int incs[16] = { 1391376, 463792, 198768, 86961, 33936,
61221 X                  13776, 4592, 1968, 861, 336, 
61222 X                  112, 48, 21, 7, 3, 1 };
61223 X
61224 X  for ( k = 0; k < 16; k++)
61225 X    for (gap = incs[k], i=gap; i < nobs; i++) {
61226 X      v = obs[i];
61227 X      j = i;
61228 X      while ( j >= gap && obs[j-gap] > v) {
61229 X       obs[j] = obs[j - gap];
61230 X       j -= gap;
61231 X      }
61232 X      obs[j] = v;
61233 X    }
61234 }
61235 SHAR_EOF
61236 chmod 0644 scaleswt.c ||
61237 echo 'restore of scaleswt.c failed'
61238 Wc_c="`wc -c < 'scaleswt.c'`"
61239 test 37581 -eq "$Wc_c" ||
61240         echo 'scaleswt.c: original size 37581, current size' "$Wc_c"
61241 fi
61242 # ============= search.html ==============
61243 if test -f 'search.html' -a X"$1" != X"-c"; then
61244         echo 'x - skipping search.html (File already exists)'
61245 else
61246 echo 'x - extracting search.html (Text)'
61247 sed 's/^X//' << 'SHAR_EOF' > 'search.html' &&
61248 <html>
61249 <head>
61250 <title>FASTA Sequence Comparison Engine</title></head>
61251 <body bgcolor="white" >
61252 X
61253 <h1 align=center>Search with FASTA</h1>
61254 X
61255 <form action="http://fasta.bioch.virginia.edu/fasta/cgi/searchnn.cgi" method=post>
61256 X
61257 <b>Choose program and database(s) to query:</b><br>
61258 <b>Program:</b>
61259 <select name = "program">
61260 X <option> FASTA 
61261 X <option> FASTX 
61262 X <option> FASTY
61263 X <option> FASTF
61264 X <option> FASTS
61265 X <option> TFASTX 
61266 X <option> TFASTY 
61267 X <option> TFASTF 
61268 X <option> TFASTS
61269 X <option> SSEARCH
61270 </select><br><br>
61271 X
61272 <b>Databases:</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="blue">Blue databases</font> and possibly DNA databases can be re-searched<br>
61273 <table align=center cellspacing=10>
61274 <tr>
61275 <td><b>Protein</b><br>
61276 X  <input type=checkbox name = "libpa" value="a">NBRF Annotated Protein Database (rel. 53)<br>
61277 X  <input type=checkbox name = "libpp" value="p">NBRF Protein Database (complete)<br>
61278 X  <input type=checkbox name = "libpd" value="d">NRL_3d structure database<br>
61279 X  <input type=checkbox name = "libpn" value="n"><font color="blue">NCBI/Blast NR protein database</font><br>
61280 X  <input type=checkbox name = "libpk" value="k"><font color="blue">NCBI/Blast NR protein database (seg)</font><br>
61281 X  <input type=checkbox name = "libps" value="q"><font color="blue">NCBI/Blast Swiss-Prot</font><br>
61282 X  <input type=checkbox name = "libpr" value="r"><font color="blue">NCBI/BLAST Swiss-Prot (seg)</font><br>
61283 X  <input type=checkbox name = "libpo" value="o">OWL Nonredundant database<br>
61284 X  <input type=checkbox name = "libpy" value="y">Yeast Proteins<br>
61285 </td>
61286 X
61287 <td><b>DNA</b><br>
61288 X  <input type=checkbox name = "libnp" value="p">Primate<br>
61289 X  <input type=checkbox name = "libnr" value="r">Rodent<br>
61290 X  <input type=checkbox name = "libnm" value="m">Other Mammals<br> 
61291 X  <input type=checkbox name = "libnb" value="b">Vertebrates<br>
61292 X  <input type=checkbox name = "libnh" value="h">High Throughput Genomics<br>
61293 X  <input type=checkbox name = "libni" value="i">Invertebrates<br>
61294 X  <input type=checkbox name = "libnl" value="l">Plants<br>
61295 X  <input type=checkbox name = "libnt" value="t">Bacteria<br>
61296 </td>
61297 X
61298 <td valign=top><br>
61299 X  <input type=checkbox name = "libns" value="s">Structural RNA<br>
61300 X  <input type=checkbox name = "libnv" value="v">Viral<br>
61301 X  <input type=checkbox name = "libng" value="g">Phage<br>
61302 X  <input type=checkbox name = "libnz" value="z">Synthetics<br>
61303 X  <input type=checkbox name = "libne" value="e">EST sequences<br>
61304 X  <input type=checkbox name = "libnf" value="f"><font color="blue">BLAST human ESTs</A><br>
61305 X  <input type=checkbox name = "libnc" value="c"><font color="blue">BLAST mouse ESTs</A><br>
61306 </td>
61307 </tr>
61308 </table>
61309 <p>
61310 <b>Sequence type:</b><br>
61311 <input type=radio name="seqtype" value=1 checked>Protein 
61312 <input type=radio name="seqtype" value=2>DNA (both strands)
61313 <input type=radio name="seqtype" value=3>DNA (forward only)
61314 <input type=radio name="seqtype" value=4>DNA (rev-comp only)
61315 X
61316 <p>
61317 <b>Enter query sequence:&nbsp;</b><select name="in_seq"><option>FASTA format<option>Accession/GI number</select>  <b>Subset range:</b>
61318 <input type=text name="ssr" maxlength=20 size=10></input>
61319 <table>
61320 <tr>
61321 <td>
61322 <textarea name="sequence" rows=6 cols=60 wrap=hard align=left></textarea>
61323 <td valign=top>
61324 <a href="http://www.ncbi.nlm.nih.gov/Entrez/protein.html" target="entrez_window">Entrez protein sequence browser</A><br><br>
61325 <a href="http://www.ncbi.nlm.nih.gov/Entrez/nucleotide.html" target="entrez_window">Entrez DNA sequence browser</A>
61326 <br><br>
61327 <input type=submit name="input" value="Submit Query">
61328 </table>
61329 <br><br>
61330 X
61331 <b>Other options:</b><br>
61332 <table>
61333 <tr>
61334 <td>
61335 <b>Ktup:</b><br>
61336 <input type=text name="ktup" maxlength=3 size=3></input>
61337 <td>
61338 <b>Protein matrix:</b><br>
61339 <select name = "pmatrix">
61340 X <option> Default
61341 X <option> Blosum50
61342 X <option> Blosum62
61343 X <option> Blosum80
61344 X <option> Pam250
61345 X <option> Pam120
61346 X <option> MD20
61347 X <option> MD10
61348 </select>
61349 <td>
61350 X <b>DNA matrix:</b><br>
61351 <select name = "dmatrix">
61352 X <option> Default
61353 X <option> +4/-3
61354 X <option> blastn2
61355 X <option> +4/-4
61356 X <option> +4/-8
61357 </select>
61358 <td>
61359 X  <b>gap:</b><br>
61360 <input type=text name="gap" maxlength=4 size=3></input>
61361 <td>
61362 X  <b>ext:</b><br>
61363 <input type=text name="ext" maxlength=4 size=3></input>
61364 <td>
61365 <b>misc:</b><br>
61366 <input type=text name="out_opt" maxlength=10 size=5></input>
61367 </tr>
61368 </table>
61369 <br>
61370 X
61371 <b>Output limits:</b><br>
61372 <b>E():</b><input type=text name="eval" maxlength=6 size=4></input>
61373 <b>Highest E():</b><input type=text name="etop" maxlength=6 size=4></input>
61374 <b>scores:</b><input type=text name="best" maxlength=3 size=3></input>
61375 <b>alignments:</b><input type=text name="align" maxlength=3 size=3></input>
61376 </form>
61377 <br>
61378 X
61379 <hr>
61380 <CENTER>
61381 <a href="http://fasta.bioch.virginia.edu/">FASTA Home</a> | <a href="search.html">Search FASTA</a> | 
61382 <a href="ftp://ftp.virginia.edu/pub/fasta/"> Get FASTA</a> |  
61383 <a href="http://www.people.virginia.edu/~wrp/pearson.html">About the Author </a>
61384 <hr>
61385 X
61386 <br>
61387 X
61388 <font size=-1><i><br> 
61389 Copyright 1988, 1991, 1992, 1993, 1994 1995, 1997, 1999 by
61390 William R. Pearson and the University of Virginia.  All rights
61391 reserved. The FASTA program and documentation may not be sold or
61392 incorporated into a commercial product, in whole or in part, without
61393 written consent of William R. Pearson and the University of Virginia.
61394 X
61395 </center>
61396 X
61397 </body>
61398 X </frameset>
61399 </html>
61400 SHAR_EOF
61401 chmod 0644 search.html ||
61402 echo 'restore of search.html failed'
61403 Wc_c="`wc -c < 'search.html'`"
61404 test 5247 -eq "$Wc_c" ||
61405         echo 'search.html: original size 5247, current size' "$Wc_c"
61406 fi
61407 # ============= showrss.c ==============
61408 if test -f 'showrss.c' -a X"$1" != X"-c"; then
61409         echo 'x - skipping showrss.c (File already exists)'
61410 else
61411 echo 'x - extracting showrss.c (Text)'
61412 sed 's/^X//' << 'SHAR_EOF' > 'showrss.c' &&
61413 X
61414 /* copyright (c) 1996, 1997, 1998, 1999 William R. Pearson and the
61415 X   U. of Virginia */
61416 X
61417 /* $Name: fa_34_26_5 $ - $Id: showrss.c,v 1.12 2006/04/12 18:00:02 wrp Exp $ */
61418 X
61419 #include <stdio.h>
61420 #include <stdlib.h>
61421 #include <string.h>
61422 X
61423 #include "defs.h"
61424 #ifndef PCOMPLIB
61425 #include "mw.h"
61426 #else
61427 #include "p_mw.h"
61428 #endif
61429 X
61430 #include "structs.h"
61431 #include "param.h"
61432 X
61433 extern double
61434 zs_to_E(double zs, int n1, int isdna, long entries,struct db_str db);
61435 extern double zs_to_bit(double zs, int n0, int n1);
61436 extern double zs_to_p(double zs);
61437 X
61438 extern double (*find_zp)(int score, double escore, int length, double comp, void *);
61439 X
61440 extern char *prog_func;
61441 X
61442 void showbest (FILE *fp, unsigned char **aa0, unsigned char *aa1, int maxn,
61443 X              struct beststr **bptr, int nbest, int qlib, struct mngmsg *m_msg,
61444 X              struct pstruct pst, struct db_str db,
61445 X              char *gstring2, void **f_str)
61446 {
61447 X  double zs;
61448 X  int score;
61449 X  char *rlabel;
61450 X  struct beststr *bbp;
61451 X
61452 X  if ((rlabel=strrchr(m_msg->label,' '))==NULL) rlabel = m_msg->label;
61453 X
61454 X  fprintf(fp,"\n %s - %d shuffles; ",prog_func,m_msg->shuff_max);
61455 X  if (m_msg->shuff_wid > 0)
61456 X    fprintf(fp," window shuffle, window size: %d\n",m_msg->shuff_wid);
61457 X  else
61458 X    fprintf(fp," uniform shuffle\n");
61459 X
61460 X  bbp = bptr[0];
61461 X
61462 X  fprintf(fp," unshuffled %s score: %d;  bits(s=%d|n_l=%d): %4.1f p(%d) < %g\n",
61463 X         rlabel,bbp->score[0],bbp->score[0], bbp->n1,
61464 X         zs_to_bit(bbp->zscore,m_msg->n0,bbp->n1),bbp->score[0],zs_to_p(bbp->zscore));
61465 X
61466 X  fprintf(fp,"For %ld sequences, a score >= %d is expected %4.4g times\n\n", 
61467 X         pst.zdb_size,bbp->score[0],zs_to_E(bbp->zscore,bbp->n1,0l,pst.zdb_size,db)); 
61468 }
61469 X
61470 void showalign (FILE *fp, unsigned char *aa0, unsigned char *aa1, int maxn,
61471 X               struct beststr **bptr, int nbest,int qlib, struct mngmsg m_msg,
61472 X               struct pstruct pst, void *f_str, char *gstring2)
61473 {
61474 }
61475 X
61476 void
61477 aancpy(char *to, char *from, int count,
61478 X       struct pstruct pst)
61479 {
61480 X  char *tp;
61481 X
61482 X  tp=to;
61483 X  while (count-- && *from) {
61484 X    if (*from <= pst.nsq) *tp++ = pst.sq[*(from++)];
61485 X    else *tp++ = *from++;
61486 X  }
61487 X  *tp='\0';
61488 }
61489 SHAR_EOF
61490 chmod 0644 showrss.c ||
61491 echo 'restore of showrss.c failed'
61492 Wc_c="`wc -c < 'showrss.c'`"
61493 test 2033 -eq "$Wc_c" ||
61494         echo 'showrss.c: original size 2033, current size' "$Wc_c"
61495 fi
61496 # ============= showsum.c ==============
61497 if test -f 'showsum.c' -a X"$1" != X"-c"; then
61498         echo 'x - skipping showsum.c (File already exists)'
61499 else
61500 echo 'x - extracting showsum.c (Text)'
61501 sed 's/^X//' << 'SHAR_EOF' > 'showsum.c' &&
61502 /* copyright (c) 1996, 1997, 1998, 1999 William R. Pearson and the
61503 X   U. of Virginia */
61504 X
61505 /* $Name: fa_34_26_5 $ - $Id: showsum.c,v 1.21 2006/06/22 15:00:51 wrp Exp $ */
61506 X
61507 /* 10 December 1999 --
61508 X
61509 X   code modified to reflect the fact that there may be two scores for
61510 X   each sequence - e.g. forward and reverse strand - and only one of them
61511 X   - presumably the best - is a related score.
61512 */
61513 X
61514 /* showsum.c should report statistics for success -
61515 X
61516 X   given the sorted results
61517 X
61518 X   (1) find the highest scoring unrelated sequence: unf_score0
61519 X       find the number of related sequences missed: relm_num0
61520 X   (2) find the 0.5% highest scoring unrelated sequence: unf_score05
61521 X       find the number of related sequences missed: relm_num05
61522 X   (3) find the score where the number of related sequences
61523 X       missed and the number of unrelated sequences found
61524 X       matches; report the score and the number: equ_score, equ_num;
61525 X
61526 The query sequence library number will be put in qsfnum.
61527 X
61528 */
61529 X
61530 #include <stdio.h>
61531 #include <stdlib.h>
61532 #include <string.h>
61533 #include <math.h>
61534 X
61535 #include "defs.h"
61536 #include "param.h"
61537 #ifndef PCOMPLIB
61538 #include "mw.h"
61539 #else
61540 #include "p_mw.h"
61541 #endif
61542 X
61543 #include "structs.h"
61544 X
61545 #ifndef SFCHAR
61546 #define SFCHAR ':'
61547 #define NSFCHAR '!'
61548 #endif
61549 X
61550 #ifdef PCOMPLIB
61551 #define BSFNUM(i) bptr[i]->desptr->sfnum
61552 #define QSFNUM qsfnum
61553 #define NQSFNUM qsfnum_n
61554 #else
61555 #define BSFNUM(i) bptr[i]->sfnum
61556 #define QSFNUM m_msg->qsfnum
61557 #define NQSFNUM m_msg->qsfnum_n
61558 #endif
61559 X
61560 #define MAX_BLINE 200
61561 X
61562 double E_to_zs(double, long);
61563 double zs_to_E(double,int,int,long,struct db_str db);
61564 double zs_to_bit(double,int,int);
61565 #ifdef PVM_SRC
61566 void sf_sort(int *s, int n);
61567 #endif
61568 void lnum_sort(struct beststr **s, int n);
61569 X
61570 void showbest (FILE *fp, 
61571 #ifndef PCOMPLIB
61572 X              unsigned char **aa0, unsigned char *aa1, int maxn,
61573 #endif
61574 X              struct beststr **bptr,int nbest,
61575 X              int qlib, struct mngmsg *m_msg, struct pstruct pst,
61576 X              struct db_str db,
61577 X              char *gstring2
61578 #ifndef PCOMPLIB
61579 X              ,void *f_str
61580 #endif
61581 X              )
61582 {
61583 X  int i, j, k, rel_tot;
61584 X  int irelv;
61585 X
61586 X  int unf_num0, relm_num0;
61587 X  int unf_num01,relm_num01;
61588 X  int unf_num02, relm_num02;
61589 X  int unf_num05, relm_num05;
61590 X  int unf_num100, relm_num100;
61591 X  int equ_num, rel_3_num, rel_1_num;
61592 X
61593 X  double unf_score0, unf_score01, unf_score02 ,unf_score05;
61594 X  double unf_score100, equ_score, rel_3_score, rel_1_score;
61595 X  double unf_score0_b, unf_score01_b, unf_score02_b ,unf_score05_b;
61596 X  double unf_score100_b, equ_score_b, rel_3_score_b, rel_1_score_b;
61597 X  char *bp;
61598 X
61599 #ifdef PCOMPLIB
61600 X  int qsfnum[10],qsfnum_n[10],isf,nsf,nsf_n;
61601 X  char  *bp1, *bpn, *tp;
61602 X  char sfstr[MAX_FN];
61603 #endif
61604 X
61605 #ifdef PCOMPLIB
61606 X  /*   not done here because done in pvcomplib.c */
61607 X  if ((bp=strchr(m_msg->qtitle,SFCHAR))!=NULL) {
61608 X    strncpy(sfstr,bp+1,sizeof(sfstr));
61609 X    sfstr[sizeof(sfstr)-1]='\0';
61610 X    if ((bp1=strchr(sfstr,SFCHAR)) != NULL) { /* look for second | */
61611 X      if ((bpn=strchr(sfstr,NSFCHAR))!=NULL) *bpn = '\0';
61612 X      *bp1='\0';
61613 X      tp = strtok(sfstr," \t");
61614 X      qsfnum[0]=atoi(tp);
61615 X      isf = 1;
61616 X      while ((tp=strtok(NULL," \t"))!=NULL) {
61617 X       qsfnum[isf++] = atoi(tp);
61618 X       if (isf >= 10) {
61619 X         fprintf(stderr," error - too many superfamilies: %d\n %s\n",
61620 X                 isf,m_msg->qtitle);
61621 X         break;
61622 X       }
61623 X      }
61624 X      qsfnum[nsf=isf]=0;
61625 X      sf_sort(qsfnum,nsf);
61626 X
61627 X      /* now get negatives */
61628 X      qsfnum_n[0]= nsf_n = 0;
61629 X      if (bpn != NULL) {
61630 X       tp = strtok(bpn+1," \t");
61631 X       qsfnum_n[0]=atoi(tp);
61632 X       isf = 1;
61633 X       while ((tp=strtok(NULL," \t"))!=NULL) {
61634 X         qsfnum_n[isf++] = atoi(tp);
61635 X         if (isf >= 10) {
61636 X           fprintf(stderr,
61637 X                   " error - too many negative superfamilies: %d\n %s\n",
61638 X                   isf,m_msg->qtitle);
61639 X           break;
61640 X         }
61641 X       }
61642 X       qsfnum[nsf_n=isf]=0;
61643 X       sf_sort(qsfnum_n,nsf_n);
61644 X      }
61645 X    }
61646 X    else {     /* only one sfnum */
61647 X      sscanf(bp+1,"%d",qsfnum);
61648 X      qsfnum[1]=0;
61649 X      qsfnum_n[0]= nsf_n = 0;
61650 X    }
61651 X  }
61652 X  else {
61653 X    fprintf(stderr," no query superfamily number\n %s\n",m_msg->qtitle);
61654 X    return;
61655 X  }
61656 #endif
61657 X
61658 X  if (m_msg->qframe > 1 || m_msg->nframe > 1) {
61659 X
61660 X    /* this code is included for cases where there are several scores -
61661 X       forward and reverse, or six in the case of tfastf33s, for each
61662 X       sequence
61663 X
61664 X       lnum_sort sorts the library by lseek position, which will be
61665 X       the same for the same sequence
61666 X    */
61667 X
61668 X    lnum_sort(bptr,nbest);
61669 X
61670 X  /* merge, saving the best score */
61671 X    i = j = 0;
61672 X
61673 X    /* i has the source position we are currently examining
61674 X       k has the adjacent alternative scores ( k > i) 
61675 X       j has the destination 
61676 X    */
61677 X
61678 X    while (i<nbest) {
61679 X      for (k=i+1; k < nbest && bptr[i]->lseek == bptr[k]->lseek; k++) {
61680 X       if (bptr[i]->zscore < bptr[k]->zscore) bptr[i] = bptr[k];
61681 X      }
61682 X      bptr[j++]=bptr[i];
61683 X      i = k;
61684 X    }
61685 X
61686 X    if (j != m_msg->nbr_seq) {
61687 X      fprintf(stderr,"*** warning ***, nbest (%d/%d) != nbr_seq (%d)\n",
61688 X             j,nbest,m_msg->nbr_seq);
61689 X      fprintf(stdout,"*** warning ***, nbest (%d/%d) != nbr_seq (%d)\n",
61690 X             j,nbest,m_msg->nbr_seq);
61691 X    }
61692 X    nbest = j;
61693 X
61694 X    if (pst.zsflag >=0) sortbeste(bptr, nbest);
61695 X    else sortbest(bptr,nbest,pst.score_ix);
61696 X  }
61697 X
61698 /* fprintf(stderr," %1d label is %s (%s)\n",irelv,labptr,label); */
61699 X
61700 /* get the query superfamily */
61701 X  
61702 X  for (i=0; i<nbest; i++) {
61703 X    /*    if (sfn_cmp(BSFNUM(i),NQSFNUM)) continue; */
61704 X    if (sfn_cmp(BSFNUM(i),QSFNUM)==0 && sfn_cmp(BSFNUM(i),NQSFNUM)==0) {
61705 X      unf_num0=i;
61706 X      unf_score0=bptr[i]->zscore;
61707 X      unf_score0_b=zs_to_bit(bptr[i]->zscore,m_msg->n0,bptr[i]->n1);
61708 X      break;
61709 X    }
61710 X  }
61711 X
61712 X  if (i>=nbest) {
61713 X    fprintf(stderr," %s: %d\n error - no unrelated sequences\n",
61714 X           m_msg->qtitle,QSFNUM[0]);
61715 X    return;
61716 X  }
61717 X  
61718 X  for (i=rel_tot=relm_num0=0; i<nbest; i++) {
61719 X    /*    if (sfn_cmp(BSFNUM(i),NQSFNUM)) continue; */
61720 X    if (sfn_cmp(BSFNUM(i),QSFNUM)>0 ) {
61721 X      rel_tot++;                       /* total related */
61722 X      if (bptr[i]->zscore <= unf_score0) relm_num0++;
61723 #ifdef DEBUG      
61724 X      if (pst.debug_lib)
61725 X       fprintf(stderr,"%d\t%l\t%.1f\n",i,bptr[i]->lseek,bptr[i]->zscore);
61726 #endif
61727 X    }
61728 X  }
61729 X  
61730 X  /* relm_num0, unf_num0, unf_score0 done */
61731 X  
61732 X  /* now calculate number missed at various expectation value cutoffs */
61733 X  /* calculate z-score cutoff for E()=0.01, 0.02, 0.05 */
61734 X
61735 X  unf_score01 = E_to_zs(0.01,db.entries);
61736 X  unf_score02 = E_to_zs(0.02,db.entries);
61737 X  unf_score05 = E_to_zs(0.05,db.entries);
61738 X  unf_score100 = E_to_zs(1.00,db.entries);
61739 X
61740 X  /* relm_num01, unf_num01, unf_score01 done */
61741 X  
61742 X  for (i=unf_num01=0,relm_num01=rel_tot;
61743 X       i<nbest && bptr[i]->zscore >= unf_score01; i++) {
61744 /*    if (sfn_cmp(BSFNUM(i),NQSFNUM)) continue; */
61745 X    if (sfn_cmp(BSFNUM(i),QSFNUM)==0) {
61746 X      if (sfn_cmp(BSFNUM(i),NQSFNUM)==0) unf_num01++;
61747 X    }
61748 X    else relm_num01--;
61749 X  }
61750 X  unf_score01_b=zs_to_bit(bptr[i]->zscore,m_msg->n0,bptr[i]->n1);
61751 X
61752 X  for (i=unf_num02=0,relm_num02=rel_tot;
61753 X       i<nbest && bptr[i]->zscore >= unf_score02; i++) {
61754 /*    if (sfn_cmp(BSFNUM(i),NQSFNUM)) continue; */
61755 X    if (sfn_cmp(BSFNUM(i),QSFNUM)==0) {
61756 X      if (sfn_cmp(BSFNUM(i),NQSFNUM)==0) unf_num02++;
61757 X    }
61758 X    else relm_num02--;
61759 X  }
61760 X  unf_score02_b=zs_to_bit(bptr[i]->zscore,m_msg->n0,bptr[i]->n1);
61761 X      
61762 X  for (i=unf_num05=0,relm_num05=rel_tot;
61763 X       i<nbest && bptr[i]->zscore >= unf_score05; i++) {
61764 /*    if (sfn_cmp(BSFNUM(i),NQSFNUM)) continue; */
61765 X    if (sfn_cmp(BSFNUM(i),QSFNUM)==0) {
61766 X      if (sfn_cmp(BSFNUM(i),NQSFNUM)==0) unf_num05++;
61767 X    }
61768 X    else relm_num05--;
61769 X  }
61770 X  unf_score05_b=zs_to_bit(bptr[i]->zscore,m_msg->n0,bptr[i]->n1);
61771 X      
61772 X  for (i=unf_num100=0,relm_num100=rel_tot;
61773 X       i<nbest && bptr[i]->zscore >= unf_score100; i++) {
61774 /*     if (sfn_cmp(BSFNUM(i),NQSFNUM)) continue; */
61775 X    if (sfn_cmp(BSFNUM(i),QSFNUM)==0) {
61776 X      if (sfn_cmp(BSFNUM(i),NQSFNUM)==0) unf_num100++;
61777 X    }
61778 X    else relm_num100--;
61779 X  }
61780 X  unf_score100_b=zs_to_bit(bptr[i]->zscore,m_msg->n0,bptr[i]->n1);
61781 X      
61782 X  /* the final criterion finds the score and the number of sequences
61783 X     where the number of unrelated sequences found == the number of
61784 X     related sequences missed. */
61785 X  
61786 X  equ_num=0;
61787 X  i = 0; j=nbest-1;
61788 X
61789 /* j is counting up the list of scores (actually down the array) from
61790 X  the lowest scoring related sequence
61791 X
61792 X  i is counting down the list of scores (actually up the array)
61793 X  from the highest scoring unrelated sequence */
61794 X
61795 X  for (i=0, j=nbest-1; j>=0 && i<nbest; i++,j--) {
61796 X    /* i++ while sequences are related, stop at next unrelated */
61797 X    while (i<nbest && (sfn_cmp(BSFNUM(i),QSFNUM) || sfn_cmp(BSFNUM(i),NQSFNUM))) i++; 
61798 X    /* j-- while sequences are unrelated, stop at next related */
61799 X    while (j>=0 && ( sfn_cmp(BSFNUM(j),QSFNUM)==0)) j--;
61800 X    /*
61801 X      fprintf(stderr,"i: %3d %3d %4d; j: %3d %3d %4d\n",i,bptr[i]->zscore,
61802 X      BSFNUM(i),j,bptr[j]->zscore,BSFNUM(j));
61803 X      */
61804 X    /* if unrelated [i] score <= related [j] score, quit */
61805 X    if (bptr[i]->zscore <= bptr[j]->zscore) break;
61806 X    equ_num++;
61807 X  }
61808 X  
61809 X  equ_score = 0.0;
61810 X  if (i>=nbest || j<0) {
61811 #ifndef PCOMPLIB
61812 X    if (pst.debug_lib) 
61813 #endif
61814 X      fprintf(stderr," i (%3d), j (%3d) off end\n %s\n", i, j,m_msg->qtitle);
61815 X    equ_num = rel_tot+1; equ_score = 0.0;
61816 X  }
61817 X  else {
61818 X    equ_score=bptr[i]->zscore;
61819 X    equ_score_b =zs_to_bit(bptr[i]->zscore,m_msg->n0,bptr[i]->n1);
61820 X  }
61821 X  
61822 X  /* get the lowest scoring related */
61823 X  for (i=0,rel_1_num=rel_tot-1; i<nbest && rel_1_num > 0; i++) {
61824 /*    if (sfn_cmp(BSFNUM(i),NQSFNUM)) continue; */
61825 X    if (sfn_cmp(BSFNUM(i),QSFNUM)) rel_1_num--;
61826 X  }
61827 X  rel_1_num = i;
61828 X  rel_1_score = bptr[i]->zscore;
61829 X  rel_1_score_b=zs_to_bit(bptr[i]->zscore,m_msg->n0,bptr[i]->n1);
61830 X
61831 X  /* get the 3rd lowest scoring related */
61832 X  for (i=0,rel_3_num=rel_tot-3; i<nbest && rel_3_num > 0; i++) {
61833 /*     if (sfn_cmp(BSFNUM(i),NQSFNUM)) continue; */
61834 X    if (sfn_cmp(BSFNUM(i),QSFNUM)) rel_3_num--;
61835 X  }
61836 X  rel_3_num = i;
61837 X  rel_3_score = bptr[i]->zscore;
61838 X  rel_3_score_b=zs_to_bit(bptr[i]->zscore,m_msg->n0,bptr[i]->n1);
61839 X
61840 X  fprintf(fp,"%3d>%s - %d (%d/%d)\n",
61841 X         qlib,m_msg->qtitle, QSFNUM[0],rel_tot,nbest);
61842 X  fprintf(fp," 0.0 criterion- relm: %3d pos: %3d score: %5.1f exp: %6.4g\n",
61843 X         relm_num0, unf_num0+1, unf_score0_b,
61844 X         zs_to_E(unf_score0,m_msg->n0,pst.dnaseq,pst.zdb_size,db));
61845 X  fprintf(fp," 0.01 criterion- relm: %3d unf: %3d score: %5.1f exp: %6.4g\n",
61846 X         relm_num01, unf_num01, unf_score01_b,
61847 X         zs_to_E(unf_score01,m_msg->n0,pst.dnaseq,pst.zdb_size,db));
61848 X  fprintf(fp," 0.02 criterion- relm: %3d unf: %3d score: %5.1f exp: %6.4g\n",
61849 X         relm_num02, unf_num02, unf_score02_b,
61850 X         zs_to_E(unf_score02,m_msg->n0,pst.dnaseq,pst.zdb_size,db));
61851 X  fprintf(fp," 0.05 criterion- relm: %3d unf: %3d score: %5.1f exp: %6.4g\n",
61852 X         relm_num05, unf_num05, unf_score05_b,
61853 X         zs_to_E(unf_score05,m_msg->n0,pst.dnaseq,pst.zdb_size,db));
61854 X  fprintf(fp," 1.00 criterion- relm: %3d unf: %3d score: %5.1f exp: %6.4g\n",
61855 X         relm_num100, unf_num100, unf_score100_b,
61856 X         zs_to_E(unf_score100,m_msg->n0,pst.dnaseq,pst.zdb_size,db));
61857 X
61858 X  fprintf(fp," equ num: %3d score: %5.1f exp: %6.4g\n",equ_num,equ_score_b,
61859 X         zs_to_E(equ_score,m_msg->n0,pst.dnaseq,pst.zdb_size,db));
61860 X
61861 X  fprintf(fp," rel[-1]: %3d score: %5.1f exp: %6.4g\n",rel_1_num+1,rel_1_score_b,
61862 X         zs_to_E(rel_1_score,m_msg->n0,pst.dnaseq,pst.zdb_size,db));
61863 X  fprintf(fp," rel[-3]: %3d score: %5.1f exp: %6.4g\n",rel_3_num+1,rel_3_score_b,
61864 X         zs_to_E(rel_3_score,m_msg->n0,pst.dnaseq,pst.zdb_size,db));
61865 X
61866 X  /* 
61867 X  fprintf(fp,"/ ** %s ** /\n",gstring2);
61868 X  fflush(fp);
61869 X  */
61870 X  m_msg->nshow = m_msg->ashow;
61871 }
61872 X
61873 #ifdef PCOMPLIB
61874 void showalign()
61875 {}
61876 X
61877 #if !defined(MPI_SRC) && !defined(PCOMPLIB)
61878 void
61879 sf_sort(int *s, int n)
61880 {
61881 X  int gap, i, j;
61882 X  int itmp;
61883 X       
61884 X  for (i=0; i<n-1; i++)
61885 X    if (s[i]>s[i+1]) goto l2;
61886 X  return;
61887 X
61888 l2:
61889 X  for (gap=n/2; gap>0; gap/=2)
61890 X    for (i=gap; i<n; i++)
61891 X      for (j=i-gap; j>=0; j -= gap) {
61892 X       if (s[j] <= s[j+gap]) break;
61893 X       itmp = s[j];
61894 X       s[j]=s[j+gap];
61895 X       s[j+gap]=itmp;
61896 X      }
61897 }
61898 X
61899 #endif
61900 #endif
61901 X
61902 void
61903 lnum_sort(struct beststr **s, int n)
61904 {
61905 X  int gap, i, j;
61906 X  struct beststr *btmp;
61907 X       
61908 X  for (i=0; i<n-1; i++)
61909 X    if (s[i]->lseek > s[i+1]->lseek) goto l2;
61910 X  return;
61911 X
61912 l2:
61913 X  for (gap=n/2; gap>0; gap/=2)
61914 X    for (i=gap; i<n; i++)
61915 X      for (j=i-gap; j>=0; j -= gap) {
61916 X       if (s[j]->lseek <= s[j+gap]->lseek) break;
61917 X       btmp = s[j];
61918 X       s[j]=s[j+gap];
61919 X       s[j+gap]=btmp;
61920 X      }
61921 }  
61922 X
61923 #ifdef MPI_SRC
61924 void
61925 aancpy(char *to, char *from, int count, struct pstruct pst)
61926 {
61927 X  char *tp, *sq;
61928 X  int nsq;
61929 X
61930 X  if (pst.ext_sq_set) {
61931 X    nsq = pst.nsqx;
61932 X    sq = pst.sqx;
61933 X  }
61934 X  else {
61935 X    nsq = pst.nsq;
61936 X    sq = pst.sq;
61937 X  }
61938 X
61939 X  tp=to;
61940 X  while (count-- && *from) {
61941 X    if (*from <= nsq) *tp++ = sq[*(from++)];
61942 X    else *tp++ = *from++;
61943 X  }
61944 X  *tp='\0';
61945 }
61946 #endif
61947 SHAR_EOF
61948 chmod 0644 showsum.c ||
61949 echo 'restore of showsum.c failed'
61950 Wc_c="`wc -c < 'showsum.c'`"
61951 test 12412 -eq "$Wc_c" ||
61952         echo 'showsum.c: original size 12412, current size' "$Wc_c"
61953 fi
61954 # ============= smith_waterman_altivec.c ==============
61955 if test -f 'smith_waterman_altivec.c' -a X"$1" != X"-c"; then
61956         echo 'x - skipping smith_waterman_altivec.c (File already exists)'
61957 else
61958 echo 'x - extracting smith_waterman_altivec.c (Text)'
61959 sed 's/^X//' << 'SHAR_EOF' > 'smith_waterman_altivec.c' &&
61960 X
61961 /* Implementation of the Wozniak "anti-diagonal" vectorization
61962 X   strategy for Smith-Waterman comparison, Wozniak (1997) Comp.
61963 X   Appl. Biosci. 13:145-150
61964 X
61965 X   November, 2004
61966 */
61967 X
61968 /*
61969 X  Written by Erik Lindahl, Stockholm Bioinformatics Center, 2004.
61970 X  Please send bug reports and/or suggestions to lindahl@sbc.su.se.
61971 */
61972 X
61973 #include <stdio.h>
61974 X
61975 #include "defs.h"
61976 #include "param.h"
61977 #include "dropgsw.h"
61978 X
61979 #ifdef SW_ALTIVEC
61980 X
61981 int
61982 smith_waterman_altivec_word(unsigned char *     query_sequence,
61983 X                            unsigned short *    query_profile_word,
61984 X                            int                 query_length,
61985 X                            unsigned char *     db_sequence,
61986 X                            int                 db_length,
61987 X                            unsigned short      bias,
61988 X                            unsigned short      gap_open,
61989 X                            unsigned short      gap_extend,
61990 X                            struct f_struct *   f_str)
61991 {
61992 X    int                     i,j,k;
61993 X    unsigned short *        p;
61994 X    unsigned short          score;   
61995 X    unsigned char *         p_dbseq;
61996 X    int                     alphabet_size = f_str->alphabet_size;
61997 X    unsigned short *        workspace     = (unsigned short *)f_str->workspace;
61998 X
61999 X    vector unsigned short   Fup,Hup1,Hup2,E,F,H,tmp;
62000 X    vector unsigned char    perm;
62001 X    vector unsigned short   v_maxscore;
62002 X    vector unsigned short   v_bias,v_gapopen,v_gapextend;
62003 X    vector unsigned short   v_score;
62004 X    vector unsigned short   v_score_q1;
62005 X    vector unsigned short   v_score_q2;
62006 X    vector unsigned short   v_score_q3;
62007 X    vector unsigned short   v_score_load; 
62008 X    vector unsigned char    queue1_to_score  = (vector unsigned char)(16,17,2,3,4,5,6,7,8,9,10,11,12,13,14,15);
62009 X    vector unsigned char    queue2_to_queue1 = (vector unsigned char)(0,1,18,19,4,5,6,7,8,9,10,11,12,13,14,15);
62010 X    vector unsigned char    queue3_to_queue2 = (vector unsigned char)(16,16,16,16,16,21,16,0,16,1,16,2,16,3,16,4);
62011 X    vector unsigned char    queue3_with_load = (vector unsigned char)(23,5,6,7,8,25,9,10,11,27,12,13,29,14,31,16);
62012 X        
62013 X    /* Load the bias to all elements of a constant */
62014 X    v_bias           = vec_lde(0,&bias);
62015 X    perm             = vec_lvsl(0,&bias);
62016 X    v_bias           = vec_perm(v_bias,v_bias,perm);
62017 X    v_bias           = vec_splat(v_bias,0);
62018 X    
62019 X    /* Load gap opening penalty to all elements of a constant */
62020 X    v_gapopen        = vec_lde(0,&gap_open);
62021 X    perm             = vec_lvsl(0,&gap_open);
62022 X    v_gapopen        = vec_perm(v_gapopen,v_gapopen,perm);
62023 X    v_gapopen        = vec_splat(v_gapopen,0);
62024 X
62025 X    /* Load gap extension penalty to all elements of a constant */
62026 X    v_gapextend      = vec_lde(0,&gap_extend);  
62027 X    perm             = vec_lvsl(0,&gap_extend);
62028 X    v_gapextend      = vec_perm(v_gapextend,v_gapextend,perm);
62029 X    v_gapextend      = vec_splat(v_gapextend,0);
62030 X    
62031 X    v_maxscore = vec_xor(v_maxscore,v_maxscore);
62032 X   
62033 X    // Zero out the storage vector 
62034 X    k = 2*(db_length+7);
62035 X        
62036 X    for(i=0,j=0;i<k;i++,j+=16)
62037 X    {
62038 X        // borrow the zero value in v_maxscore to have something to store
62039 X        vec_st(v_maxscore,j,workspace);
62040 X    }
62041 X    
62042 X    for(i=0;i<query_length;i+=8)
62043 X    {
62044 X        // fetch first data asap.
62045 X        p_dbseq    = db_sequence;
62046 X        k          = *p_dbseq++;
62047 X        v_score_load = vec_ld(16*k,query_profile_word);
62048 X
62049 X        // zero lots of stuff. 
62050 X        // We use both the VPERM and VSIU unit to knock off some cycles.
62051 X        
62052 X        E          = vec_splat_u16(0);
62053 X        F          = vec_xor(F,F);
62054 X        H          = vec_splat_u16(0);
62055 X        Hup2       = vec_xor(Hup2,Hup2);
62056 X        v_score_q1 = vec_splat_u16(0);
62057 X        v_score_q2 = vec_xor(v_score_q2,v_score_q2);
62058 X        v_score_q3 = vec_splat_u16(0);
62059 X
62060 X        // reset pointers to the start of the saved data from the last row
62061 X        p = workspace;
62062 X                
62063 X        // PROLOGUE 1
62064 X        // prefetch next residue
62065 X        k          = *p_dbseq++;
62066 X        
62067 X        // Create the actual diagonal score vector
62068 X        // and update the queue of incomplete score vectors
62069 X        
62070 X        v_score    = vec_perm(v_score_q1, v_score_load, queue1_to_score);
62071 X        v_score_q1 = vec_perm(v_score_q2, v_score_load, queue2_to_queue1);
62072 X        v_score_q2 = vec_perm(v_score_q3, v_score_load, queue3_to_queue2);
62073 X        v_score_q3 = vec_perm(v_score_q3, v_score_load, queue3_with_load);
62074 X        
62075 X        // prefetch score for next step 
62076 X        v_score_load = vec_ld(16*k,query_profile_word);            
62077 X        
62078 X        // load values of F and H from previous row (one unit up)
62079 X        Fup    = vec_ld(0,  p);
62080 X        Hup1   = vec_ld(16, p);
62081 X        p += 16; // move ahead 32 bytes
62082 X        
62083 X        // shift into place so we have complete F and H vectors
62084 X        // that refer to the values one unit up from each cell
62085 X        // that we are currently working on.
62086 X        Fup    = vec_sld(Fup,F,14);
62087 X        Hup1   = vec_sld(Hup1,H,14);            
62088 X        
62089 X        // do the dynamic programming 
62090 X
62091 X        // update E value
62092 X        E   = vec_subs(E,v_gapextend);
62093 X        tmp = vec_subs(H,v_gapopen);
62094 X        E   = vec_max(E,tmp);
62095 X        
62096 X        // update F value
62097 X        F   = vec_subs(Fup,v_gapextend);
62098 X        tmp = vec_subs(Hup1,v_gapopen);
62099 X        F   = vec_max(F,tmp);
62100 X        
62101 X        // add score to H
62102 X        H   = vec_adds(Hup2,v_score);
62103 X        H   = vec_subs(H,v_bias);
62104 X        
62105 X        // set H to max of H,E,F
62106 X        H   = vec_max(H,E);
62107 X        H   = vec_max(H,F);
62108 X        
62109 X        // Save value to use for next diagonal H 
62110 X        Hup2 = Hup1;
62111 X        
62112 X        // Update highest score encountered this far
62113 X        v_maxscore = vec_max(v_maxscore,H);
62114 X        
62115 X        
62116 X        // PROLOGUE 2
62117 X        // prefetch next residue
62118 X        k          = *p_dbseq++;
62119 X        
62120 X        // Create the actual diagonal score vector
62121 X        // and update the queue of incomplete score vectors
62122 X        
62123 X        v_score    = vec_perm(v_score_q1, v_score_load, queue1_to_score);
62124 X        v_score_q1 = vec_perm(v_score_q2, v_score_load, queue2_to_queue1);
62125 X        v_score_q2 = vec_perm(v_score_q3, v_score_load, queue3_to_queue2);
62126 X        v_score_q3 = vec_perm(v_score_q3, v_score_load, queue3_with_load);
62127 X        
62128 X        // prefetch score for next step 
62129 X        v_score_load = vec_ld(16*k,query_profile_word);            
62130 X        
62131 X        // load values of F and H from previous row (one unit up)
62132 X        Fup    = vec_ld(0,  p);
62133 X        Hup1   = vec_ld(16, p);
62134 X        p += 16; // move ahead 32 bytes
62135 X        
62136 X        // shift into place so we have complete F and H vectors
62137 X        // that refer to the values one unit up from each cell
62138 X        // that we are currently working on.
62139 X        Fup    = vec_sld(Fup,F,14);
62140 X        Hup1   = vec_sld(Hup1,H,14);            
62141 X        
62142 X        // do the dynamic programming 
62143 X
62144 X        // update E value
62145 X        E   = vec_subs(E,v_gapextend);
62146 X        tmp = vec_subs(H,v_gapopen);
62147 X        E   = vec_max(E,tmp);
62148 X        
62149 X        // update F value
62150 X        F   = vec_subs(Fup,v_gapextend);
62151 X        tmp = vec_subs(Hup1,v_gapopen);
62152 X        F   = vec_max(F,tmp);
62153 X        
62154 X        // add score to H
62155 X        H   = vec_adds(Hup2,v_score);
62156 X        H   = vec_subs(H,v_bias);
62157 X        
62158 X        // set H to max of H,E,F
62159 X        H   = vec_max(H,E);
62160 X        H   = vec_max(H,F);
62161 X        
62162 X        // Save value to use for next diagonal H 
62163 X        Hup2 = Hup1;
62164 X        
62165 X        // Update highest score encountered this far
62166 X        v_maxscore = vec_max(v_maxscore,H);
62167 X        
62168 X
62169 X        // PROLOGUE 3
62170 X        // prefetch next residue
62171 X        k          = *p_dbseq++;
62172 X        
62173 X        // Create the actual diagonal score vector
62174 X        // and update the queue of incomplete score vectors
62175 X        
62176 X        v_score    = vec_perm(v_score_q1, v_score_load, queue1_to_score);
62177 X        v_score_q1 = vec_perm(v_score_q2, v_score_load, queue2_to_queue1);
62178 X        v_score_q2 = vec_perm(v_score_q3, v_score_load, queue3_to_queue2);
62179 X        v_score_q3 = vec_perm(v_score_q3, v_score_load, queue3_with_load);
62180 X
62181 X        // prefetch score for next step 
62182 X        v_score_load = vec_ld(16*k,query_profile_word);            
62183 X        
62184 X        // load values of F and H from previous row (one unit up)
62185 X        Fup    = vec_ld(0,  p);
62186 X        Hup1   = vec_ld(16, p);
62187 X        p += 16; // move ahead 32 bytes
62188 X        
62189 X        // shift into place so we have complete F and H vectors
62190 X        // that refer to the values one unit up from each cell
62191 X        // that we are currently working on.
62192 X        Fup    = vec_sld(Fup,F,14);
62193 X        Hup1   = vec_sld(Hup1,H,14);            
62194 X        
62195 X        // do the dynamic programming 
62196 X
62197 X        // update E value
62198 X        E   = vec_subs(E,v_gapextend);
62199 X        tmp = vec_subs(H,v_gapopen);
62200 X        E   = vec_max(E,tmp);
62201 X        
62202 X        // update F value
62203 X        F   = vec_subs(Fup,v_gapextend);
62204 X        tmp = vec_subs(Hup1,v_gapopen);
62205 X        F   = vec_max(F,tmp);
62206 X        
62207 X        // add score to H
62208 X        H   = vec_adds(Hup2,v_score);
62209 X        H   = vec_subs(H,v_bias);
62210 X        
62211 X        // set H to max of H,E,F
62212 X        H   = vec_max(H,E);
62213 X        H   = vec_max(H,F);
62214 X        
62215 X        // Save value to use for next diagonal H 
62216 X        Hup2 = Hup1;
62217 X        
62218 X        // Update highest score encountered this far
62219 X        v_maxscore = vec_max(v_maxscore,H);
62220 X        
62221 X
62222 X        // PROLOGUE 4
62223 X        // prefetch next residue
62224 X        k          = *p_dbseq++;
62225 X        
62226 X        // Create the actual diagonal score vector
62227 X        // and update the queue of incomplete score vectors
62228 X        
62229 X        v_score    = vec_perm(v_score_q1, v_score_load, queue1_to_score);
62230 X        v_score_q1 = vec_perm(v_score_q2, v_score_load, queue2_to_queue1);
62231 X        v_score_q2 = vec_perm(v_score_q3, v_score_load, queue3_to_queue2);
62232 X        v_score_q3 = vec_perm(v_score_q3, v_score_load, queue3_with_load);
62233 X        
62234 X        // prefetch score for next step 
62235 X        v_score_load = vec_ld(16*k,query_profile_word);            
62236 X        
62237 X        // load values of F and H from previous row (one unit up)
62238 X        Fup    = vec_ld(0,  p);
62239 X        Hup1   = vec_ld(16, p);
62240 X        p += 16; // move ahead 32 bytes
62241 X        
62242 X        // shift into place so we have complete F and H vectors
62243 X        // that refer to the values one unit up from each cell
62244 X        // that we are currently working on.
62245 X        Fup    = vec_sld(Fup,F,14);
62246 X        Hup1   = vec_sld(Hup1,H,14);            
62247 X        
62248 X        // do the dynamic programming 
62249 X        
62250 X        // update E value
62251 X        E   = vec_subs(E,v_gapextend);
62252 X        tmp = vec_subs(H,v_gapopen);
62253 X        E   = vec_max(E,tmp);
62254 X        
62255 X        // update F value
62256 X        F   = vec_subs(Fup,v_gapextend);
62257 X        tmp = vec_subs(Hup1,v_gapopen);
62258 X        F   = vec_max(F,tmp);
62259 X        
62260 X        // add score to H
62261 X        H   = vec_adds(Hup2,v_score);
62262 X        H   = vec_subs(H,v_bias);
62263 X        
62264 X        // set H to max of H,E,F
62265 X        H   = vec_max(H,E);
62266 X        H   = vec_max(H,F);
62267 X        
62268 X        // Save value to use for next diagonal H 
62269 X        Hup2 = Hup1;
62270 X        
62271 X        // Update highest score encountered this far
62272 X        v_maxscore = vec_max(v_maxscore,H);
62273 X        
62274 X
62275 X        // PROLOGUE 5
62276 X        // prefetch next residue
62277 X        k          = *p_dbseq++;
62278 X        
62279 X        // Create the actual diagonal score vector
62280 X        // and update the queue of incomplete score vectors
62281 X        
62282 X        v_score    = vec_perm(v_score_q1, v_score_load, queue1_to_score);
62283 X        v_score_q1 = vec_perm(v_score_q2, v_score_load, queue2_to_queue1);
62284 X        v_score_q2 = vec_perm(v_score_q3, v_score_load, queue3_to_queue2);
62285 X        v_score_q3 = vec_perm(v_score_q3, v_score_load, queue3_with_load);
62286 X        
62287 X        // prefetch score for next step 
62288 X        v_score_load = vec_ld(16*k,query_profile_word);            
62289 X        
62290 X        // load values of F and H from previous row (one unit up)
62291 X        Fup    = vec_ld(0,  p);
62292 X        Hup1   = vec_ld(16, p);
62293 X        p += 16; // move ahead 32 bytes
62294 X        
62295 X        // shift into place so we have complete F and H vectors
62296 X        // that refer to the values one unit up from each cell
62297 X        // that we are currently working on.
62298 X        Fup    = vec_sld(Fup,F,14);
62299 X        Hup1   = vec_sld(Hup1,H,14);            
62300 X        
62301 X        // do the dynamic programming 
62302 X        
62303 X        // update E value
62304 X        E   = vec_subs(E,v_gapextend);
62305 X        tmp = vec_subs(H,v_gapopen);
62306 X        E   = vec_max(E,tmp);
62307 X        
62308 X        // update F value
62309 X        F   = vec_subs(Fup,v_gapextend);
62310 X        tmp = vec_subs(Hup1,v_gapopen);
62311 X        F   = vec_max(F,tmp);
62312 X        
62313 X        // add score to H
62314 X        H   = vec_adds(Hup2,v_score);
62315 X        H   = vec_subs(H,v_bias);
62316 X        
62317 X        // set H to max of H,E,F
62318 X        H   = vec_max(H,E);
62319 X        H   = vec_max(H,F);
62320 X        
62321 X        // Save value to use for next diagonal H 
62322 X        Hup2 = Hup1;
62323 X        
62324 X        // Update highest score encountered this far
62325 X        v_maxscore = vec_max(v_maxscore,H);
62326 X        
62327 X
62328 X        // PROLOGUE 6
62329 X        // prefetch next residue
62330 X        k          = *p_dbseq++;
62331 X        
62332 X        // Create the actual diagonal score vector
62333 X        // and update the queue of incomplete score vectors
62334 X        
62335 X        v_score    = vec_perm(v_score_q1, v_score_load, queue1_to_score);
62336 X        v_score_q1 = vec_perm(v_score_q2, v_score_load, queue2_to_queue1);
62337 X        v_score_q2 = vec_perm(v_score_q3, v_score_load, queue3_to_queue2);
62338 X        v_score_q3 = vec_perm(v_score_q3, v_score_load, queue3_with_load);
62339 X        
62340 X        // prefetch score for next step 
62341 X        v_score_load = vec_ld(16*k,query_profile_word);            
62342 X        
62343 X        // load values of F and H from previous row (one unit up)
62344 X        Fup    = vec_ld(0,  p);
62345 X        Hup1   = vec_ld(16, p);
62346 X        p += 16; // move ahead 32 bytes
62347 X        
62348 X        // shift into place so we have complete F and H vectors
62349 X        // that refer to the values one unit up from each cell
62350 X        // that we are currently working on.
62351 X        Fup    = vec_sld(Fup,F,14);
62352 X        Hup1   = vec_sld(Hup1,H,14);            
62353 X        
62354 X        // do the dynamic programming 
62355 X        
62356 X        // update E value
62357 X        E   = vec_subs(E,v_gapextend);
62358 X        tmp = vec_subs(H,v_gapopen);
62359 X        E   = vec_max(E,tmp);
62360 X        
62361 X        // update F value
62362 X        F   = vec_subs(Fup,v_gapextend);
62363 X        tmp = vec_subs(Hup1,v_gapopen);
62364 X        F   = vec_max(F,tmp);
62365 X        
62366 X        // add score to H
62367 X        H   = vec_adds(Hup2,v_score);
62368 X        H   = vec_subs(H,v_bias);
62369 X        
62370 X        // set H to max of H,E,F
62371 X        H   = vec_max(H,E);
62372 X        H   = vec_max(H,F);
62373 X        
62374 X        // Save value to use for next diagonal H 
62375 X        Hup2 = Hup1;
62376 X        
62377 X        // Update highest score encountered this far
62378 X        v_maxscore = vec_max(v_maxscore,H);
62379 X
62380 X        
62381 X        // PROLOGUE 7
62382 X        // prefetch next residue
62383 X        k          = *p_dbseq++;
62384 X        
62385 X        // Create the actual diagonal score vector
62386 X        // and update the queue of incomplete score vectors
62387 X        
62388 X        v_score    = vec_perm(v_score_q1, v_score_load, queue1_to_score);
62389 X        v_score_q1 = vec_perm(v_score_q2, v_score_load, queue2_to_queue1);
62390 X        v_score_q2 = vec_perm(v_score_q3, v_score_load, queue3_to_queue2);
62391 X        v_score_q3 = vec_perm(v_score_q3, v_score_load, queue3_with_load);
62392 X        
62393 X        // prefetch score for next step 
62394 X        v_score_load = vec_ld(16*k,query_profile_word);            
62395 X        
62396 X        // load values of F and H from previous row (one unit up)
62397 X        Fup    = vec_ld(0,  p);
62398 X        Hup1   = vec_ld(16, p);
62399 X        p += 16; // move ahead 32 bytes
62400 X        
62401 X        // shift into place so we have complete F and H vectors
62402 X        // that refer to the values one unit up from each cell
62403 X        // that we are currently working on.
62404 X        Fup    = vec_sld(Fup,F,14);
62405 X        Hup1   = vec_sld(Hup1,H,14);            
62406 X        
62407 X        // do the dynamic programming 
62408 X        
62409 X        // update E value
62410 X        E   = vec_subs(E,v_gapextend);
62411 X        tmp = vec_subs(H,v_gapopen);
62412 X        E   = vec_max(E,tmp);
62413 X        
62414 X        // update F value
62415 X        F   = vec_subs(Fup,v_gapextend);
62416 X        tmp = vec_subs(Hup1,v_gapopen);
62417 X        F   = vec_max(F,tmp);
62418 X        
62419 X        // add score to H
62420 X        H   = vec_adds(Hup2,v_score);
62421 X        H   = vec_subs(H,v_bias);
62422 X        
62423 X        // set H to max of H,E,F
62424 X        H   = vec_max(H,E);
62425 X        H   = vec_max(H,F);
62426 X        
62427 X        // Save value to use for next diagonal H 
62428 X        Hup2 = Hup1;
62429 X        
62430 X        // Update highest score encountered this far
62431 X        v_maxscore = vec_max(v_maxscore,H);
62432 X        
62433 X
62434 X        // PROLOGUE 8
62435 X        // prefetch next residue
62436 X        k          = *p_dbseq++;
62437 X        
62438 X        // Create the actual diagonal score vector
62439 X        // and update the queue of incomplete score vectors
62440 X        
62441 X        v_score    = vec_perm(v_score_q1, v_score_load, queue1_to_score);
62442 X        v_score_q1 = vec_perm(v_score_q2, v_score_load, queue2_to_queue1);
62443 X        v_score_q2 = vec_perm(v_score_q3, v_score_load, queue3_to_queue2);
62444 X        v_score_q3 = vec_perm(v_score_q3, v_score_load, queue3_with_load);
62445 X        
62446 X        // prefetch score for next step 
62447 X        v_score_load = vec_ld(16*k,query_profile_word);            
62448 X        
62449 X        // load values of F and H from previous row (one unit up)
62450 X        Fup    = vec_ld(0,  p);
62451 X        Hup1   = vec_ld(16, p);
62452 X        p += 16; // move ahead 32 bytes
62453 X        
62454 X        // shift into place so we have complete F and H vectors
62455 X        // that refer to the values one unit up from each cell
62456 X        // that we are currently working on.
62457 X        Fup    = vec_sld(Fup,F,14);
62458 X        Hup1   = vec_sld(Hup1,H,14);            
62459 X        
62460 X        // do the dynamic programming 
62461 X        
62462 X        // update E value
62463 X        E   = vec_subs(E,v_gapextend);
62464 X        tmp = vec_subs(H,v_gapopen);
62465 X        E   = vec_max(E,tmp);
62466 X        
62467 X        // update F value
62468 X        F   = vec_subs(Fup,v_gapextend);
62469 X        tmp = vec_subs(Hup1,v_gapopen);
62470 X        F   = vec_max(F,tmp);
62471 X        
62472 X        // add score to H
62473 X        H   = vec_adds(Hup2,v_score);
62474 X        H   = vec_subs(H,v_bias);
62475 X        
62476 X        // set H to max of H,E,F
62477 X        H   = vec_max(H,E);
62478 X        H   = vec_max(H,F);
62479 X        
62480 X        // Save value to use for next diagonal H 
62481 X        Hup2 = Hup1;
62482 X        
62483 X        // Update highest score encountered this far
62484 X        v_maxscore = vec_max(v_maxscore,H);
62485 X    
62486 X
62487 X        // reset pointers to the start of the saved data from the last row
62488 X        p = workspace;
62489 X
62490 X        for(j=8;j<db_length;j+=8)
62491 X        {           
62492 X            // STEP 1
62493 X            
62494 X            // prefetch next residue
62495 X            k          = *p_dbseq++;
62496 X            
62497 X            // Create the actual diagonal score vector
62498 X            // and update the queue of incomplete score vectors
62499 X
62500 X            v_score    = vec_perm(v_score_q1, v_score_load, queue1_to_score);
62501 X            v_score_q1 = vec_perm(v_score_q2, v_score_load, queue2_to_queue1);
62502 X            v_score_q2 = vec_perm(v_score_q3, v_score_load, queue3_to_queue2);
62503 X            v_score_q3 = vec_perm(v_score_q3, v_score_load, queue3_with_load);
62504 X            
62505 X            // prefetch score for next step
62506 X            v_score_load = vec_ld(16*k,query_profile_word);
62507 X            
62508 X            // load values of F and H from previous row (one unit up)
62509 X            Fup    = vec_ld(256, p);
62510 X            Hup1   = vec_ld(272, p);
62511 X            
62512 X            // save old values of F and H to use on next row
62513 X            vec_st(F, 0,  p);
62514 X            vec_st(H, 16, p);
62515 X            p += 16; // move ahead 32 bytes
62516 X            
62517 X            // shift into place so we have complete F and H vectors
62518 X            // that refer to the values one unit up from each cell
62519 X            // that we are currently working on.
62520 X            Fup    = vec_sld(Fup,F,14);
62521 X            Hup1   = vec_sld(Hup1,H,14);            
62522 X
62523 X            // do the dynamic programming 
62524 X            
62525 X            // update E value
62526 X            E   = vec_subs(E,v_gapextend);
62527 X            tmp = vec_subs(H,v_gapopen);
62528 X            E   = vec_max(E,tmp);
62529 X            
62530 X            // update F value
62531 X            F   = vec_subs(Fup,v_gapextend);
62532 X            tmp = vec_subs(Hup1,v_gapopen);
62533 X            F   = vec_max(F,tmp);
62534 X
62535 X            // add score to H
62536 X            H   = vec_adds(Hup2,v_score);
62537 X            H   = vec_subs(H,v_bias);
62538 X            
62539 X            // set H to max of H,E,F
62540 X            H   = vec_max(H,E);
62541 X            H   = vec_max(H,F); 
62542 X            
62543 X            
62544 X            // Update highest score encountered this far
62545 X            v_maxscore = vec_max(v_maxscore,H);
62546 X            
62547
62548
62549 X            // STEP 2
62550 X            
62551 X            // prefetch next residue
62552 X            k          = *p_dbseq++;
62553 X            
62554 X            // Create the actual diagonal score vector
62555 X            // and update the queue of incomplete score vectors
62556 X            
62557 X            v_score    = vec_perm(v_score_q1, v_score_load, queue1_to_score);
62558 X            v_score_q1 = vec_perm(v_score_q2, v_score_load, queue2_to_queue1);
62559 X            v_score_q2 = vec_perm(v_score_q3, v_score_load, queue3_to_queue2);
62560 X            v_score_q3 = vec_perm(v_score_q3, v_score_load, queue3_with_load);
62561 X            
62562 X            // prefetch score for next step
62563 X            v_score_load = vec_ld(16*k,query_profile_word);
62564 X            
62565 X            // load values of F and H from previous row (one unit up)
62566 X            Fup    = vec_ld(256, p);
62567 X            Hup2   = vec_ld(272, p);
62568 X            
62569 X            // save old values of F and H to use on next row
62570 X            vec_st(F, 0,  p);
62571 X            vec_st(H, 16, p);
62572 X            p += 16; // move ahead 32 bytes
62573 X            
62574 X            // shift into place so we have complete F and H vectors
62575 X            // that refer to the values one unit up from each cell
62576 X            // that we are currently working on.
62577 X            Fup    = vec_sld(Fup,F,14);
62578 X            Hup2   = vec_sld(Hup2,H,14);            
62579 X            
62580 X            // do the dynamic programming 
62581 X            
62582 X            // update E value
62583 X            E   = vec_subs(E,v_gapextend);
62584 X            tmp = vec_subs(H,v_gapopen);
62585 X            E   = vec_max(E,tmp);
62586 X            
62587 X            // update F value
62588 X            F   = vec_subs(Fup,v_gapextend);
62589 X            tmp = vec_subs(Hup2,v_gapopen);
62590 X            F   = vec_max(F,tmp);
62591 X            
62592 X            // add score to H
62593 X            H   = vec_adds(Hup1,v_score);
62594 X            H   = vec_subs(H,v_bias);
62595 X            
62596 X            // set H to max of H,E,F
62597 X            H   = vec_max(H,E);
62598 X            H   = vec_max(H,F); 
62599 X            
62600 X            
62601 X            // Update highest score encountered this far
62602 X            v_maxscore = vec_max(v_maxscore,H);
62603 X            
62604 X
62605 X
62606 X            // STEP 3
62607 X            
62608 X            // prefetch next residue
62609 X            k          = *p_dbseq++;
62610 X            
62611 X            // Create the actual diagonal score vector
62612 X            // and update the queue of incomplete score vectors
62613 X            
62614 X            v_score    = vec_perm(v_score_q1, v_score_load, queue1_to_score);
62615 X            v_score_q1 = vec_perm(v_score_q2, v_score_load, queue2_to_queue1);
62616 X            v_score_q2 = vec_perm(v_score_q3, v_score_load, queue3_to_queue2);
62617 X            v_score_q3 = vec_perm(v_score_q3, v_score_load, queue3_with_load);
62618 X            
62619 X            // prefetch score for next step
62620 X            v_score_load = vec_ld(16*k,query_profile_word);
62621 X            
62622 X            // load values of F and H from previous row (one unit up)
62623 X            Fup    = vec_ld(256, p);
62624 X            Hup1   = vec_ld(272, p);
62625 X            
62626 X            // save old values of F and H to use on next row
62627 X            vec_st(F, 0,  p);
62628 X            vec_st(H, 16, p);
62629 X            p += 16; // move ahead 32 bytes
62630 X            
62631 X            // shift into place so we have complete F and H vectors
62632 X            // that refer to the values one unit up from each cell
62633 X            // that we are currently working on.
62634 X            Fup    = vec_sld(Fup,F,14);
62635 X            Hup1   = vec_sld(Hup1,H,14);            
62636 X            
62637 X            // do the dynamic programming 
62638 X            
62639 X            // update E value
62640 X            E   = vec_subs(E,v_gapextend);
62641 X            tmp = vec_subs(H,v_gapopen);
62642 X            E   = vec_max(E,tmp);
62643 X            
62644 X            // update F value
62645 X            F   = vec_subs(Fup,v_gapextend);
62646 X            tmp = vec_subs(Hup1,v_gapopen);
62647 X            F   = vec_max(F,tmp);
62648 X            
62649 X            // add score to H
62650 X            H   = vec_adds(Hup2,v_score);
62651 X            H   = vec_subs(H,v_bias);
62652 X            
62653 X            // set H to max of H,E,F
62654 X            H   = vec_max(H,E);
62655 X            H   = vec_max(H,F); 
62656 X            
62657 X
62658 X            
62659 X            // Update highest score encountered this far
62660 X            v_maxscore = vec_max(v_maxscore,H);
62661 X            
62662 X
62663 X            
62664 X            // STEP 4
62665 X            
62666 X            // prefetch next residue
62667 X            k          = *p_dbseq++;
62668 X            
62669 X            // Create the actual diagonal score vector
62670 X            // and update the queue of incomplete score vectors
62671 X            
62672 X            v_score    = vec_perm(v_score_q1, v_score_load, queue1_to_score);
62673 X            v_score_q1 = vec_perm(v_score_q2, v_score_load, queue2_to_queue1);
62674 X            v_score_q2 = vec_perm(v_score_q3, v_score_load, queue3_to_queue2);
62675 X            v_score_q3 = vec_perm(v_score_q3, v_score_load, queue3_with_load);
62676 X            
62677 X            // prefetch score for next step
62678 X            v_score_load = vec_ld(16*k,query_profile_word);
62679 X            
62680 X            // load values of F and H from previous row (one unit up)
62681 X            Fup    = vec_ld(256, p);
62682 X            Hup2   = vec_ld(272, p);
62683 X            
62684 X            // save old values of F and H to use on next row
62685 X            vec_st(F, 0,  p);
62686 X            vec_st(H, 16, p);
62687 X            p += 16; // move ahead 32 bytes
62688 X            
62689 X            // shift into place so we have complete F and H vectors
62690 X            // that refer to the values one unit up from each cell
62691 X            // that we are currently working on.
62692 X            Fup    = vec_sld(Fup,F,14);
62693 X            Hup2   = vec_sld(Hup2,H,14);            
62694 X            
62695 X            // do the dynamic programming 
62696 X            
62697 X            // update E value
62698 X            E   = vec_subs(E,v_gapextend);
62699 X            tmp = vec_subs(H,v_gapopen);
62700 X            E   = vec_max(E,tmp);
62701 X            
62702 X            // update F value
62703 X            F   = vec_subs(Fup,v_gapextend);
62704 X            tmp = vec_subs(Hup2,v_gapopen);
62705 X            F   = vec_max(F,tmp);
62706 X            
62707 X            // add score to H
62708 X            H   = vec_adds(Hup1,v_score);
62709 X            H   = vec_subs(H,v_bias);
62710 X            
62711 X            // set H to max of H,E,F
62712 X            H   = vec_max(H,E);
62713 X            H   = vec_max(H,F); 
62714 X
62715 X            
62716 X            // Update highest score encountered this far
62717 X            v_maxscore = vec_max(v_maxscore,H);
62718 X            
62719 X
62720 X
62721 X            // STEP 5
62722 X            
62723 X            // prefetch next residue
62724 X            k          = *p_dbseq++;
62725 X            
62726 X            // Create the actual diagonal score vector
62727 X            // and update the queue of incomplete score vectors
62728 X            
62729 X            v_score    = vec_perm(v_score_q1, v_score_load, queue1_to_score);
62730 X            v_score_q1 = vec_perm(v_score_q2, v_score_load, queue2_to_queue1);
62731 X            v_score_q2 = vec_perm(v_score_q3, v_score_load, queue3_to_queue2);
62732 X            v_score_q3 = vec_perm(v_score_q3, v_score_load, queue3_with_load);
62733 X            
62734 X            // prefetch score for next step
62735 X            v_score_load = vec_ld(16*k,query_profile_word);
62736 X            
62737 X            // load values of F and H from previous row (one unit up)
62738 X            Fup    = vec_ld(256, p);
62739 X            Hup1   = vec_ld(272, p);
62740 X            
62741 X            // save old values of F and H to use on next row
62742 X            vec_st(F, 0,  p);
62743 X            vec_st(H, 16, p);
62744 X            p += 16; // move ahead 32 bytes
62745 X            
62746 X            // shift into place so we have complete F and H vectors
62747 X            // that refer to the values one unit up from each cell
62748 X            // that we are currently working on.
62749 X            Fup    = vec_sld(Fup,F,14);
62750 X            Hup1   = vec_sld(Hup1,H,14);            
62751 X            
62752 X            // do the dynamic programming 
62753 X            
62754 X            // update E value
62755 X            E   = vec_subs(E,v_gapextend);
62756 X            tmp = vec_subs(H,v_gapopen);
62757 X            E   = vec_max(E,tmp);
62758 X            
62759 X            // update F value
62760 X            F   = vec_subs(Fup,v_gapextend);
62761 X            tmp = vec_subs(Hup1,v_gapopen);
62762 X            F   = vec_max(F,tmp);
62763 X            
62764 X            // add score to H
62765 X            H   = vec_adds(Hup2,v_score);
62766 X            H   = vec_subs(H,v_bias);
62767 X            
62768 X            // set H to max of H,E,F
62769 X            H   = vec_max(H,E);
62770 X            H   = vec_max(H,F); 
62771 X            
62772 X            
62773 X            // Update highest score encountered this far
62774 X            v_maxscore = vec_max(v_maxscore,H);
62775 X            
62776 X
62777 X
62778 X            // STEP 6
62779 X            
62780 X            // prefetch next residue
62781 X            k          = *p_dbseq++;
62782 X            
62783 X            // Create the actual diagonal score vector
62784 X            // and update the queue of incomplete score vectors
62785 X            
62786 X            v_score    = vec_perm(v_score_q1, v_score_load, queue1_to_score);
62787 X            v_score_q1 = vec_perm(v_score_q2, v_score_load, queue2_to_queue1);
62788 X            v_score_q2 = vec_perm(v_score_q3, v_score_load, queue3_to_queue2);
62789 X            v_score_q3 = vec_perm(v_score_q3, v_score_load, queue3_with_load);
62790 X            
62791 X            // prefetch score for next step
62792 X            v_score_load = vec_ld(16*k,query_profile_word);
62793 X            
62794 X            // load values of F and H from previous row (one unit up)
62795 X            Fup    = vec_ld(256, p);
62796 X            Hup2   = vec_ld(272, p);
62797 X            
62798 X            // save old values of F and H to use on next row
62799 X            vec_st(F, 0,  p);
62800 X            vec_st(H, 16, p);
62801 X            p += 16; // move ahead 32 bytes
62802 X            
62803 X            // shift into place so we have complete F and H vectors
62804 X            // that refer to the values one unit up from each cell
62805 X            // that we are currently working on.
62806 X            Fup    = vec_sld(Fup,F,14);
62807 X            Hup2   = vec_sld(Hup2,H,14);            
62808 X            
62809 X            // do the dynamic programming 
62810 X            
62811 X            // update E value
62812 X            E   = vec_subs(E,v_gapextend);
62813 X            tmp = vec_subs(H,v_gapopen);
62814 X            E   = vec_max(E,tmp);
62815 X            
62816 X            // update F value
62817 X            F   = vec_subs(Fup,v_gapextend);
62818 X            tmp = vec_subs(Hup2,v_gapopen);
62819 X            F   = vec_max(F,tmp);
62820 X            
62821 X            // add score to H
62822 X            H   = vec_adds(Hup1,v_score);
62823 X            H   = vec_subs(H,v_bias);
62824 X            
62825 X            // set H to max of H,E,F
62826 X            H   = vec_max(H,E);
62827 X            H   = vec_max(H,F); 
62828 X            
62829 X
62830 X            
62831 X            // Update highest score encountered this far
62832 X            v_maxscore = vec_max(v_maxscore,H);
62833 X            
62834 X
62835 X            
62836 X            // STEP 7
62837 X            
62838 X            // prefetch next residue
62839 X            k          = *p_dbseq++;
62840 X            
62841 X            // Create the actual diagonal score vector
62842 X            // and update the queue of incomplete score vectors
62843 X            
62844 X            v_score    = vec_perm(v_score_q1, v_score_load, queue1_to_score);
62845 X            v_score_q1 = vec_perm(v_score_q2, v_score_load, queue2_to_queue1);
62846 X            v_score_q2 = vec_perm(v_score_q3, v_score_load, queue3_to_queue2);
62847 X            v_score_q3 = vec_perm(v_score_q3, v_score_load, queue3_with_load);
62848 X            
62849 X            // prefetch score for next step
62850 X            v_score_load = vec_ld(16*k,query_profile_word);
62851 X            
62852 X            // load values of F and H from previous row (one unit up)
62853 X            Fup    = vec_ld(256, p);
62854 X            Hup1   = vec_ld(272, p);
62855 X            
62856 X            // save old values of F and H to use on next row
62857 X            vec_st(F, 0,  p);
62858 X            vec_st(H, 16, p);
62859 X            p += 16; // move ahead 32 bytes
62860 X            
62861 X            // shift into place so we have complete F and H vectors
62862 X            // that refer to the values one unit up from each cell
62863 X            // that we are currently working on.
62864 X            Fup    = vec_sld(Fup,F,14);
62865 X            Hup1   = vec_sld(Hup1,H,14);            
62866 X            
62867 X            // do the dynamic programming 
62868 X            
62869 X            // update E value
62870 X            E   = vec_subs(E,v_gapextend);
62871 X            tmp = vec_subs(H,v_gapopen);
62872 X            E   = vec_max(E,tmp);
62873 X            
62874 X            // update F value
62875 X            F   = vec_subs(Fup,v_gapextend);
62876 X            tmp = vec_subs(Hup1,v_gapopen);
62877 X            F   = vec_max(F,tmp);
62878 X            
62879 X            // add score to H
62880 X            H   = vec_adds(Hup2,v_score);
62881 X            H   = vec_subs(H,v_bias);
62882 X            
62883 X            // set H to max of H,E,F
62884 X            H   = vec_max(H,E);
62885 X            H   = vec_max(H,F); 
62886 X            
62887 X
62888 X            
62889 X            // Update highest score encountered this far
62890 X            v_maxscore = vec_max(v_maxscore,H);
62891 X            
62892 X
62893 X
62894 X            // STEP 8
62895 X            
62896 X            // prefetch next residue
62897 X            k          = *p_dbseq++;
62898 X            
62899 X            // Create the actual diagonal score vector
62900 X            // and update the queue of incomplete score vectors
62901 X            
62902 X            v_score    = vec_perm(v_score_q1, v_score_load, queue1_to_score);
62903 X            v_score_q1 = vec_perm(v_score_q2, v_score_load, queue2_to_queue1);
62904 X            v_score_q2 = vec_perm(v_score_q3, v_score_load, queue3_to_queue2);
62905 X            v_score_q3 = vec_perm(v_score_q3, v_score_load, queue3_with_load);
62906 X            
62907 X            // prefetch score for next step
62908 X            v_score_load = vec_ld(16*k,query_profile_word);
62909 X            
62910 X            // load values of F and H from previous row (one unit up)
62911 X            Fup    = vec_ld(256, p);
62912 X            Hup2   = vec_ld(272, p);
62913 X            
62914 X            // save old values of F and H to use on next row
62915 X            vec_st(F, 0,  p);
62916 X            vec_st(H, 16, p);
62917 X            p += 16; // move ahead 32 bytes
62918 X            
62919 X            // shift into place so we have complete F and H vectors
62920 X            // that refer to the values one unit up from each cell
62921 X            // that we are currently working on.
62922 X            Fup    = vec_sld(Fup,F,14);
62923 X            Hup2   = vec_sld(Hup2,H,14);            
62924 X            
62925 X            // do the dynamic programming 
62926 X            
62927 X            // update E value
62928 X            E   = vec_subs(E,v_gapextend);
62929 X            tmp = vec_subs(H,v_gapopen);
62930 X            E   = vec_max(E,tmp);
62931 X            
62932 X            // update F value
62933 X            F   = vec_subs(Fup,v_gapextend);
62934 X            tmp = vec_subs(Hup2,v_gapopen);
62935 X            F   = vec_max(F,tmp);
62936 X            
62937 X            // add score to H
62938 X            H   = vec_adds(Hup1,v_score);
62939 X            H   = vec_subs(H,v_bias);
62940 X            
62941 X            // set H to max of H,E,F
62942 X            H   = vec_max(H,E);
62943 X            H   = vec_max(H,F); 
62944 X            
62945 X            
62946 X            // Update highest score encountered this far
62947 X            v_maxscore = vec_max(v_maxscore,H);
62948 X        }
62949 X        
62950 X        v_score_load = vec_splat_u16(0);
62951 X        
62952 X        for(;j<db_length+7;j++)
62953 X        {
62954 X            // Create the actual diagonal score vector
62955 X            // and update the queue of incomplete score vectors
62956 X            //
62957 X            // This could of course be done with only vec_perm or vec_sel,
62958 X            // but since they use different execution units we have found
62959 X            // it to be slightly faster to mix them.
62960 X            v_score    = vec_perm(v_score_q1, v_score_load, queue1_to_score);
62961 X            v_score_q1 = vec_perm(v_score_q2, v_score_load, queue2_to_queue1);
62962 X            v_score_q2 = vec_perm(v_score_q3, v_score_load, queue3_to_queue2);
62963 X            v_score_q3 = vec_perm(v_score_q3, v_score_load, queue3_with_load);
62964 X            
62965 X            // save old values of F and H to use on next row
62966 X            vec_st(F, 0,  p);
62967 X            vec_st(H, 16, p);
62968 X            p += 16; // move ahead 32 bytes
62969 X            
62970 X            // v_score_load contains all zeros
62971 X            Fup    = vec_sld(v_score_load,F,14);
62972 X            Hup1   = vec_sld(v_score_load,H,14);            
62973 X            
62974 X            // do the dynamic programming 
62975 X            
62976 X            // update E value
62977 X            E   = vec_subs(E,v_gapextend);
62978 X            tmp = vec_subs(H,v_gapopen);
62979 X            E   = vec_max(E,tmp);
62980 X            
62981 X            // update F value
62982 X            F   = vec_subs(Fup,v_gapextend);
62983 X            tmp = vec_subs(Hup1,v_gapopen);
62984 X            F   = vec_max(F,tmp);
62985 X            
62986 X            // add score to H
62987 X            H   = vec_adds(Hup2,v_score);
62988 X            H   = vec_subs(H,v_bias);
62989 X            
62990 X            // set H to max of H,E,F
62991 X            H   = vec_max(H,E);
62992 X            H   = vec_max(H,F);
62993 X            
62994 X            // Save value to use for next diagonal H 
62995 X            Hup2 = Hup1;
62996 X            
62997 X            // Update highest score encountered this far
62998 X            v_maxscore = vec_max(v_maxscore,H);
62999 X        }
63000 X        vec_st(F, 0,  p);
63001 X        vec_st(H, 16, p);
63002 X
63003 X        query_profile_word += 8*alphabet_size;
63004 X    }
63005 X
63006 X    // find largest score in the v_maxscore vector
63007 X    tmp = vec_sld(v_maxscore,v_maxscore,8);
63008 X    v_maxscore = vec_max(v_maxscore,tmp);
63009 X    tmp = vec_sld(v_maxscore,v_maxscore,4);
63010 X    v_maxscore = vec_max(v_maxscore,tmp);
63011 X    tmp = vec_sld(v_maxscore,v_maxscore,2);
63012 X    v_maxscore = vec_max(v_maxscore,tmp);
63013 X
63014 X    // store in temporary variable
63015 X    vec_ste(v_maxscore,0,&score);
63016 X    
63017 X    // return largest score
63018 X    return score;
63019 }
63020 X
63021 int
63022 smith_waterman_altivec_byte(unsigned char *     query_sequence,
63023 X                            unsigned char *     query_profile_byte,
63024 X                            int                 query_length,
63025 X                            unsigned char *     db_sequence,
63026 X                            int                 db_length,
63027 X                            unsigned char       bias,
63028 X                            unsigned char       gap_open,
63029 X                            unsigned char       gap_extend,
63030 X                            struct f_struct *   f_str)
63031 {
63032 X    int                     i,j,k,k8;
63033 X    int                     overflow;
63034 X    unsigned char *         p;
63035 X    unsigned char           score;   
63036 X    int                     alphabet_size = f_str->alphabet_size;
63037 X    unsigned char *         workspace     = (unsigned char *)f_str->workspace;
63038 X    
63039 X    vector unsigned char    Fup,Hup1,Hup2,E,F,H,tmp;
63040 X    vector unsigned char    perm;
63041 X    vector unsigned char    v_maxscore;
63042 X    vector unsigned char    v_bias,v_gapopen,v_gapextend;
63043 X    vector unsigned char    v_score;
63044 X    vector unsigned char    v_score_q1;
63045 X    vector unsigned char    v_score_q2;
63046 X    vector unsigned char    v_score_q3;
63047 X    vector unsigned char    v_score_q4;
63048 X    vector unsigned char    v_score_q5;
63049 X    vector unsigned char    v_score_load1;
63050 X    vector unsigned char    v_score_load2;  
63051 X    vector unsigned char    v_zero;  
63052 X
63053 X    vector unsigned char    queue1_to_score  = (vector unsigned char)(16,1,2,3,4,5,6,7,24,9,10,11,12,13,14,15);
63054 X    vector unsigned char    queue2_to_queue1 = (vector unsigned char)(16,17,2,3,4,5,6,7,24,25,10,11,12,13,14,15);
63055 X    vector unsigned char    queue3_to_queue2 = (vector unsigned char)(16,17,18,3,4,5,6,7,24,25,26,11,12,13,14,15);
63056 X    vector unsigned char    queue4_to_queue3 = (vector unsigned char)(16,17,18,19,4,5,6,7,24,25,26,27,12,13,14,15);
63057 X    vector unsigned char    queue5_to_queue4 = (vector unsigned char)(16,17,18,19,20,2,3,4,24,25,26,27,28,10,11,12);
63058 X    vector unsigned char    queue5_with_load = (vector unsigned char)(19,20,21,5,6,22,7,23,27,28,29,13,14,30,15,31);
63059 X    vector unsigned char    merge_score_load = (vector unsigned char)(0,1,2,3,4,5,6,7,24,25,26,27,28,29,30,31);
63060 X
63061 X    v_zero           = vec_splat_u8(0);
63062 X        
63063 X    /* Load the bias to all elements of a constant */
63064 X    v_bias           = vec_lde(0,&bias);
63065 X    perm             = vec_lvsl(0,&bias);
63066 X    v_bias           = vec_perm(v_bias,v_bias,perm);
63067 X    v_bias           = vec_splat(v_bias,0);
63068 X    
63069 X    /* Load gap opening penalty to all elements of a constant */
63070 X    v_gapopen        = vec_lde(0,&gap_open);
63071 X    perm             = vec_lvsl(0,&gap_open);
63072 X    v_gapopen        = vec_perm(v_gapopen,v_gapopen,perm);
63073 X    v_gapopen        = vec_splat(v_gapopen,0);
63074 X
63075 X    /* Load gap extension penalty to all elements of a constant */
63076 X    v_gapextend      = vec_lde(0,&gap_extend);  
63077 X    perm             = vec_lvsl(0,&gap_extend);
63078 X    v_gapextend      = vec_perm(v_gapextend,v_gapextend,perm);
63079 X    v_gapextend      = vec_splat(v_gapextend,0);
63080 X    
63081 X    v_maxscore = vec_xor(v_maxscore,v_maxscore);
63082 X   
63083 X    // Zero out the storage vector 
63084 X    k = (db_length+15);
63085 X    for(i=0,j=0;i<k;i++,j+=32)
63086 X    {
63087 X        // borrow the zero value in v_maxscore to have something to store
63088 X        vec_st(v_maxscore,j,workspace);
63089 X        vec_st(v_maxscore,j+16,workspace);
63090 X    }
63091 X    
63092 X    for(i=0;i<query_length;i+=16)
63093 X    {
63094 X        // zero lots of stuff. 
63095 X        // We use both the VPERM and VSIU unit to knock off some cycles.
63096 X        
63097 X        E          = vec_splat_u8(0);
63098 X        F          = vec_xor(F,F);
63099 X        H          = vec_splat_u8(0);
63100 X        Hup2      = vec_xor(Hup2,Hup2);
63101 X        v_score_q1 = vec_splat_u8(0);
63102 X        v_score_q2 = vec_xor(v_score_q2,v_score_q2);
63103 X        v_score_q3 = vec_splat_u8(0);
63104 X        v_score_q4 = vec_xor(v_score_q4,v_score_q4);
63105 X        v_score_q5 = vec_splat_u8(0);
63106 X
63107 X        // reset pointers to the start of the saved data from the last row
63108 X        p = workspace;
63109 X        
63110 X        // start directly and prefetch score column
63111 X        k             = db_sequence[0];
63112 X        k8            = k;
63113 X        v_score_load1 = vec_ld(16*k,query_profile_byte);
63114 X        v_score_load2 = v_score_load1;
63115 X        v_score_load1 = vec_perm(v_score_load1,v_zero,merge_score_load);
63116 X
63117 X        // PROLOGUE 1
63118 X        // prefetch next residue
63119 X        k                = db_sequence[1];
63120 X        
63121 X        v_score     = vec_perm(v_score_q1,  v_score_load1,  queue1_to_score);
63122 X        v_score_q1  = vec_perm(v_score_q2,  v_score_load1,  queue2_to_queue1);
63123 X        v_score_q2  = vec_perm(v_score_q3,  v_score_load1,  queue3_to_queue2);
63124 X        v_score_q3  = vec_perm(v_score_q4,  v_score_load1,  queue4_to_queue3);
63125 X        v_score_q4  = vec_perm(v_score_q5,  v_score_load1,  queue5_to_queue4);
63126 X        v_score_q5  = vec_perm(v_score_q5,  v_score_load1,  queue5_with_load);
63127 X        
63128 X        // prefetch score for next step 
63129 X        v_score_load1 = vec_ld(16*k,query_profile_byte);            
63130 X        
63131 X        // load values of F and H from previous row (one unit up)
63132 X        Fup    = vec_ld(0,  p);
63133 X        Hup1   = vec_ld(16, p);
63134 X        p += 32; // move ahead 32 bytes
63135 X        
63136 X        // shift into place so we have complete F and H vectors
63137 X        // that refer to the values one unit up from each cell
63138 X        // that we are currently working on.
63139 X        Fup    = vec_sld(Fup,F,15);
63140 X        Hup1    = vec_sld(Hup1,H,15);            
63141 X        
63142 X        // do the dynamic programming 
63143 X        
63144 X        // update E value
63145 X        E   = vec_subs(E,v_gapextend);
63146 X        tmp = vec_subs(H,v_gapopen);
63147 X        E   = vec_max(E,tmp);
63148 X        
63149 X        // update F value
63150 X        F   = vec_subs(Fup,v_gapextend);
63151 X        tmp = vec_subs(Hup1,v_gapopen);
63152 X        F   = vec_max(F,tmp);
63153 X        
63154 X        v_score_load1 = vec_perm(v_score_load1,v_zero,merge_score_load);
63155 X        
63156 X        // add score to H
63157 X        H   = vec_adds(Hup2,v_score);
63158 X        H   = vec_subs(H,v_bias);
63159 X        
63160 X        // set H to max of H,E,F
63161 X        H   = vec_max(H,E);
63162 X        H   = vec_max(H,F);
63163 X        
63164 X        // Update highest score encountered this far
63165 X        v_maxscore = vec_max(v_maxscore,H);
63166 X        
63167 X        
63168 X        
63169 X        
63170 X        // PROLOGUE 2
63171 X        // prefetch next residue
63172 X        k                = db_sequence[2];
63173 X        
63174 X        v_score     = vec_perm(v_score_q1,  v_score_load1,  queue1_to_score);
63175 X        v_score_q1  = vec_perm(v_score_q2,  v_score_load1,  queue2_to_queue1);
63176 X        v_score_q2  = vec_perm(v_score_q3,  v_score_load1,  queue3_to_queue2);
63177 X        v_score_q3  = vec_perm(v_score_q4,  v_score_load1,  queue4_to_queue3);
63178 X        v_score_q4  = vec_perm(v_score_q5,  v_score_load1,  queue5_to_queue4);
63179 X        v_score_q5  = vec_perm(v_score_q5,  v_score_load1,  queue5_with_load);
63180 X        
63181 X  
63182 X        // prefetch score for next step 
63183 X        v_score_load1 = vec_ld(16*k,query_profile_byte);            
63184 X        
63185 X        // load values of F and H from previous row (one unit up)
63186 X        Fup    = vec_ld(0,  p);
63187 X        Hup2   = vec_ld(16, p);
63188 X        p += 32; // move ahead 32 bytes
63189 X        
63190 X        // shift into place so we have complete F and H vectors
63191 X        // that refer to the values one unit up from each cell
63192 X        // that we are currently working on.
63193 X        Fup    = vec_sld(Fup,F,15);
63194 X        Hup2   = vec_sld(Hup2,H,15);            
63195 X        
63196 X        // do the dynamic programming 
63197 X        
63198 X        // update E value
63199 X        E   = vec_subs(E,v_gapextend);
63200 X        tmp = vec_subs(H,v_gapopen);
63201 X        E   = vec_max(E,tmp);
63202 X        
63203 X        // update F value
63204 X        F   = vec_subs(Fup,v_gapextend);
63205 X        tmp = vec_subs(Hup2,v_gapopen);
63206 X        F   = vec_max(F,tmp);
63207 X        
63208 X        v_score_load1 = vec_perm(v_score_load1,v_zero,merge_score_load);
63209 X        
63210 X        // add score to H
63211 X        H   = vec_adds(Hup1,v_score);
63212 X        H   = vec_subs(H,v_bias);
63213 X        
63214 X        // set H to max of H,E,F
63215 X        H   = vec_max(H,E);
63216 X        H   = vec_max(H,F);
63217 X        
63218 X        // Update highest score encountered this far
63219 X        v_maxscore = vec_max(v_maxscore,H);
63220 X     
63221 X        
63222 X        // PROLOGUE 3
63223 X        // prefetch next residue
63224 X        k                = db_sequence[3];
63225 X  
63226 X        v_score     = vec_perm(v_score_q1,  v_score_load1,  queue1_to_score);
63227 X        v_score_q1  = vec_perm(v_score_q2,  v_score_load1,  queue2_to_queue1);
63228 X        v_score_q2  = vec_perm(v_score_q3,  v_score_load1,  queue3_to_queue2);
63229 X        v_score_q3  = vec_perm(v_score_q4,  v_score_load1,  queue4_to_queue3);
63230 X        v_score_q4  = vec_perm(v_score_q5,  v_score_load1,  queue5_to_queue4);
63231 X        v_score_q5  = vec_perm(v_score_q5,  v_score_load1,  queue5_with_load);
63232 X        
63233 X
63234 X        // prefetch score for next step 
63235 X        v_score_load1 = vec_ld(16*k,query_profile_byte);            
63236 X        
63237 X        // load values of F and H from previous row (one unit up)
63238 X        Fup    = vec_ld(0,  p);
63239 X        Hup1   = vec_ld(16, p);
63240 X        p += 32; // move ahead 32 bytes
63241 X        
63242 X        // shift into place so we have complete F and H vectors
63243 X        // that refer to the values one unit up from each cell
63244 X        // that we are currently working on.
63245 X        Fup    = vec_sld(Fup,F,15);
63246 X        Hup1    = vec_sld(Hup1,H,15);            
63247 X        
63248 X        // do the dynamic programming 
63249 X        
63250 X        // update E value
63251 X        E   = vec_subs(E,v_gapextend);
63252 X        tmp = vec_subs(H,v_gapopen);
63253 X        E   = vec_max(E,tmp);
63254 X        
63255 X        // update F value
63256 X        F   = vec_subs(Fup,v_gapextend);
63257 X        tmp = vec_subs(Hup1,v_gapopen);
63258 X        F   = vec_max(F,tmp);
63259 X        
63260 X        v_score_load1 = vec_perm(v_score_load1,v_zero,merge_score_load);
63261 X        
63262 X        // add score to H
63263 X        H   = vec_adds(Hup2,v_score);
63264 X        H   = vec_subs(H,v_bias);
63265 X        
63266 X        // set H to max of H,E,F
63267 X        H   = vec_max(H,E);
63268 X        H   = vec_max(H,F);
63269 X        
63270 X        // Update highest score encountered this far
63271 X        v_maxscore = vec_max(v_maxscore,H);
63272 X        
63273 X        
63274 X        // PROLOGUE 4
63275 X        // prefetch next residue
63276 X        k                = db_sequence[4];
63277 X        
63278 X        v_score     = vec_perm(v_score_q1,  v_score_load1,  queue1_to_score);
63279 X        v_score_q1  = vec_perm(v_score_q2,  v_score_load1,  queue2_to_queue1);
63280 X        v_score_q2  = vec_perm(v_score_q3,  v_score_load1,  queue3_to_queue2);
63281 X        v_score_q3  = vec_perm(v_score_q4,  v_score_load1,  queue4_to_queue3);
63282 X        v_score_q4  = vec_perm(v_score_q5,  v_score_load1,  queue5_to_queue4);
63283 X        v_score_q5  = vec_perm(v_score_q5,  v_score_load1,  queue5_with_load);
63284 X        
63285 X
63286 X        // prefetch score for next step 
63287 X        v_score_load1 = vec_ld(16*k,query_profile_byte);            
63288 X        
63289 X        // load values of F and H from previous row (one unit up)
63290 X        Fup    = vec_ld(0,  p);
63291 X        Hup2   = vec_ld(16, p);
63292 X        p += 32; // move ahead 32 bytes
63293 X        
63294 X        // shift into place so we have complete F and H vectors
63295 X        // that refer to the values one unit up from each cell
63296 X        // that we are currently working on.
63297 X        Fup    = vec_sld(Fup,F,15);
63298 X        Hup2   = vec_sld(Hup2,H,15);            
63299 X        
63300 X        // do the dynamic programming 
63301 X        
63302 X        // update E value
63303 X        E   = vec_subs(E,v_gapextend);
63304 X        tmp = vec_subs(H,v_gapopen);
63305 X        E   = vec_max(E,tmp);
63306 X        
63307 X        // update F value
63308 X        F   = vec_subs(Fup,v_gapextend);
63309 X        tmp = vec_subs(Hup2,v_gapopen);
63310 X        F   = vec_max(F,tmp);
63311 X        
63312 X        v_score_load1 = vec_perm(v_score_load1,v_zero,merge_score_load);
63313 X        
63314 X        // add score to H
63315 X        H   = vec_adds(Hup1,v_score);
63316 X        H   = vec_subs(H,v_bias);
63317 X        
63318 X        // set H to max of H,E,F
63319 X        H   = vec_max(H,E);
63320 X        H   = vec_max(H,F);
63321 X        
63322 X        // Update highest score encountered this far
63323 X        v_maxscore = vec_max(v_maxscore,H);
63324 X        
63325 X        
63326 X        // PROLOGUE 5
63327 X        // prefetch next residue
63328 X        k                = db_sequence[5];
63329 X        
63330 X        v_score     = vec_perm(v_score_q1,  v_score_load1,  queue1_to_score);
63331 X        v_score_q1  = vec_perm(v_score_q2,  v_score_load1,  queue2_to_queue1);
63332 X        v_score_q2  = vec_perm(v_score_q3,  v_score_load1,  queue3_to_queue2);
63333 X        v_score_q3  = vec_perm(v_score_q4,  v_score_load1,  queue4_to_queue3);
63334 X        v_score_q4  = vec_perm(v_score_q5,  v_score_load1,  queue5_to_queue4);
63335 X        v_score_q5  = vec_perm(v_score_q5,  v_score_load1,  queue5_with_load);
63336 X     
63337 X
63338 X        // prefetch score for next step 
63339 X        v_score_load1 = vec_ld(16*k,query_profile_byte);            
63340 X        
63341 X        // load values of F and H from previous row (one unit up)
63342 X        Fup    = vec_ld(0,  p);
63343 X        Hup1   = vec_ld(16, p);
63344 X        p += 32; // move ahead 32 bytes
63345 X        
63346 X        // shift into place so we have complete F and H vectors
63347 X        // that refer to the values one unit up from each cell
63348 X        // that we are currently working on.
63349 X        Fup    = vec_sld(Fup,F,15);
63350 X        Hup1    = vec_sld(Hup1,H,15);            
63351 X        
63352 X        // do the dynamic programming 
63353 X        
63354 X        // update E value
63355 X        E   = vec_subs(E,v_gapextend);
63356 X        tmp = vec_subs(H,v_gapopen);
63357 X        E   = vec_max(E,tmp);
63358 X        
63359 X        // update F value
63360 X        F   = vec_subs(Fup,v_gapextend);
63361 X        tmp = vec_subs(Hup1,v_gapopen);
63362 X        F   = vec_max(F,tmp);
63363 X        
63364 X        v_score_load1 = vec_perm(v_score_load1,v_zero,merge_score_load);
63365 X        
63366 X        // add score to H
63367 X        H   = vec_adds(Hup2,v_score);
63368 X        H   = vec_subs(H,v_bias);
63369 X        
63370 X        // set H to max of H,E,F
63371 X        H   = vec_max(H,E);
63372 X        H   = vec_max(H,F);
63373 X        
63374 X        // Update highest score encountered this far
63375 X        v_maxscore = vec_max(v_maxscore,H);
63376 X        
63377 X        
63378 X        // PROLOGUE 6
63379 X        // prefetch next residue
63380 X        k                = db_sequence[6];
63381 X        
63382 X        v_score     = vec_perm(v_score_q1,  v_score_load1,  queue1_to_score);
63383 X        v_score_q1  = vec_perm(v_score_q2,  v_score_load1,  queue2_to_queue1);
63384 X        v_score_q2  = vec_perm(v_score_q3,  v_score_load1,  queue3_to_queue2);
63385 X        v_score_q3  = vec_perm(v_score_q4,  v_score_load1,  queue4_to_queue3);
63386 X        v_score_q4  = vec_perm(v_score_q5,  v_score_load1,  queue5_to_queue4);
63387 X        v_score_q5  = vec_perm(v_score_q5,  v_score_load1,  queue5_with_load);
63388 X        
63389 X
63390 X        // prefetch score for next step 
63391 X        v_score_load1 = vec_ld(16*k,query_profile_byte);            
63392 X        
63393 X        // load values of F and H from previous row (one unit up)
63394 X        Fup    = vec_ld(0,  p);
63395 X        Hup2   = vec_ld(16, p);
63396 X        p += 32; // move ahead 32 bytes
63397 X        
63398 X        // shift into place so we have complete F and H vectors
63399 X        // that refer to the values one unit up from each cell
63400 X        // that we are currently working on.
63401 X        Fup    = vec_sld(Fup,F,15);
63402 X        Hup2   = vec_sld(Hup2,H,15);            
63403 X        
63404 X        // do the dynamic programming 
63405 X        
63406 X        // update E value
63407 X        E   = vec_subs(E,v_gapextend);
63408 X        tmp = vec_subs(H,v_gapopen);
63409 X        E   = vec_max(E,tmp);
63410 X        
63411 X        // update F value
63412 X        F   = vec_subs(Fup,v_gapextend);
63413 X        tmp = vec_subs(Hup2,v_gapopen);
63414 X        F   = vec_max(F,tmp);
63415 X        
63416 X        v_score_load1 = vec_perm(v_score_load1,v_zero,merge_score_load);
63417 X        
63418 X        // add score to H
63419 X        H   = vec_adds(Hup1,v_score);
63420 X        H   = vec_subs(H,v_bias);
63421 X        
63422 X        // set H to max of H,E,F
63423 X        H   = vec_max(H,E);
63424 X        H   = vec_max(H,F);
63425 X        
63426 X        // Update highest score encountered this far
63427 X        v_maxscore = vec_max(v_maxscore,H);
63428 X        
63429 X        
63430 X        
63431 X        // PROLOGUE 7
63432 X        // prefetch next residue
63433 X        k                = db_sequence[7];
63434 X        
63435 X        v_score     = vec_perm(v_score_q1,  v_score_load1,  queue1_to_score);
63436 X        v_score_q1  = vec_perm(v_score_q2,  v_score_load1,  queue2_to_queue1);
63437 X        v_score_q2  = vec_perm(v_score_q3,  v_score_load1,  queue3_to_queue2);
63438 X        v_score_q3  = vec_perm(v_score_q4,  v_score_load1,  queue4_to_queue3);
63439 X        v_score_q4  = vec_perm(v_score_q5,  v_score_load1,  queue5_to_queue4);
63440 X        v_score_q5  = vec_perm(v_score_q5,  v_score_load1,  queue5_with_load);
63441 X        
63442 X
63443 X        // prefetch score for next step 
63444 X        v_score_load1 = vec_ld(16*k,query_profile_byte);            
63445 X        
63446 X        // load values of F and H from previous row (one unit up)
63447 X        Fup    = vec_ld(0,  p);
63448 X        Hup1   = vec_ld(16, p);
63449 X        p += 32; // move ahead 32 bytes
63450 X        
63451 X        // shift into place so we have complete F and H vectors
63452 X        // that refer to the values one unit up from each cell
63453 X        // that we are currently working on.
63454 X        Fup    = vec_sld(Fup,F,15);
63455 X        Hup1    = vec_sld(Hup1,H,15);            
63456 X        
63457 X        // do the dynamic programming 
63458 X        
63459 X        // update E value
63460 X        E   = vec_subs(E,v_gapextend);
63461 X        tmp = vec_subs(H,v_gapopen);
63462 X        E   = vec_max(E,tmp);
63463 X        
63464 X        // update F value
63465 X        F   = vec_subs(Fup,v_gapextend);
63466 X        tmp = vec_subs(Hup1,v_gapopen);
63467 X        F   = vec_max(F,tmp);
63468 X        
63469 X        v_score_load1 = vec_perm(v_score_load1,v_zero,merge_score_load);
63470 X        
63471 X        // add score to H
63472 X        H   = vec_adds(Hup2,v_score);
63473 X        H   = vec_subs(H,v_bias);
63474 X        
63475 X        // set H to max of H,E,F
63476 X        H   = vec_max(H,E);
63477 X        H   = vec_max(H,F);
63478 X        
63479 X        // Update highest score encountered this far
63480 X        v_maxscore = vec_max(v_maxscore,H);
63481 X        
63482 X        
63483 X        
63484 X        // PROLOGUE 8
63485 X        // prefetch next residue
63486 X        k                = db_sequence[8];
63487 X        
63488 X        v_score     = vec_perm(v_score_q1,  v_score_load1,  queue1_to_score);
63489 X        v_score_q1  = vec_perm(v_score_q2,  v_score_load1,  queue2_to_queue1);
63490 X        v_score_q2  = vec_perm(v_score_q3,  v_score_load1,  queue3_to_queue2);
63491 X        v_score_q3  = vec_perm(v_score_q4,  v_score_load1,  queue4_to_queue3);
63492 X        v_score_q4  = vec_perm(v_score_q5,  v_score_load1,  queue5_to_queue4);
63493 X        v_score_q5  = vec_perm(v_score_q5,  v_score_load1,  queue5_with_load);
63494 X        
63495 X
63496 X        // prefetch score for next step 
63497 X        v_score_load1 = vec_ld(16*k,query_profile_byte);            
63498 X        
63499 X        // load values of F and H from previous row (one unit up)
63500 X        Fup    = vec_ld(0,  p);
63501 X        Hup2   = vec_ld(16, p);
63502 X        p += 32; // move ahead 32 bytes
63503 X        
63504 X        // shift into place so we have complete F and H vectors
63505 X        // that refer to the values one unit up from each cell
63506 X        // that we are currently working on.
63507 X        Fup    = vec_sld(Fup,F,15);
63508 X        Hup2   = vec_sld(Hup2,H,15);            
63509 X        
63510 X        // do the dynamic programming 
63511 X        
63512 X        // update E value
63513 X        E   = vec_subs(E,v_gapextend);
63514 X        tmp = vec_subs(H,v_gapopen);
63515 X        E   = vec_max(E,tmp);
63516 X        
63517 X        // update F value
63518 X        F   = vec_subs(Fup,v_gapextend);
63519 X        tmp = vec_subs(Hup2,v_gapopen);
63520 X        F   = vec_max(F,tmp);
63521 X        
63522 X        v_score_load1 = vec_perm(v_score_load1,v_score_load2,merge_score_load);
63523 X        
63524 X        // add score to H
63525 X        H   = vec_adds(Hup1,v_score);
63526 X        H   = vec_subs(H,v_bias);
63527 X        
63528 X        // set H to max of H,E,F
63529 X        H   = vec_max(H,E);
63530 X        H   = vec_max(H,F);
63531 X        
63532 X        // Update highest score encountered this far
63533 X        v_maxscore = vec_max(v_maxscore,H);
63534 X        
63535 X        
63536 X        
63537 X        
63538 X        // PROLOGUE 9
63539 X        // prefetch next residue
63540 X        k                = db_sequence[9];
63541 X        k8               = db_sequence[1];
63542 X        
63543 X        v_score     = vec_perm(v_score_q1,  v_score_load1,  queue1_to_score);
63544 X        v_score_q1  = vec_perm(v_score_q2,  v_score_load1,  queue2_to_queue1);
63545 X        v_score_q2  = vec_perm(v_score_q3,  v_score_load1,  queue3_to_queue2);
63546 X        v_score_q3  = vec_perm(v_score_q4,  v_score_load1,  queue4_to_queue3);
63547 X        v_score_q4  = vec_perm(v_score_q5,  v_score_load1,  queue5_to_queue4);
63548 X        v_score_q5  = vec_perm(v_score_q5,  v_score_load1,  queue5_with_load);
63549 X        
63550 X
63551 X        // prefetch score for next step 
63552 X        v_score_load1 = vec_ld(16*k,query_profile_byte);            
63553 X        v_score_load2 = vec_ld(16*k8,query_profile_byte);
63554 X        
63555 X        // load values of F and H from previous row (one unit up)
63556 X        Fup    = vec_ld(0,  p);
63557 X        Hup1    = vec_ld(16, p);
63558 X        p += 32; // move ahead 32 bytes
63559 X        
63560 X        // shift into place so we have complete F and H vectors
63561 X        // that refer to the values one unit up from each cell
63562 X        // that we are currently working on.
63563 X        Fup    = vec_sld(Fup,F,15);
63564 X        Hup1    = vec_sld(Hup1,H,15);            
63565 X        
63566 X        // do the dynamic programming 
63567 X        
63568 X        // update E value
63569 X        E   = vec_subs(E,v_gapextend);
63570 X        tmp = vec_subs(H,v_gapopen);
63571 X        E   = vec_max(E,tmp);
63572 X        
63573 X        // update F value
63574 X        F   = vec_subs(Fup,v_gapextend);
63575 X        tmp = vec_subs(Hup1,v_gapopen);
63576 X        F   = vec_max(F,tmp);
63577 X        
63578 X        v_score_load1 = vec_perm(v_score_load1,v_score_load2,merge_score_load);
63579 X        
63580 X        // add score to H
63581 X        H   = vec_adds(Hup2,v_score);
63582 X        H   = vec_subs(H,v_bias);
63583 X        
63584 X        // set H to max of H,E,F
63585 X        H   = vec_max(H,E);
63586 X        H   = vec_max(H,F);
63587 X        
63588 X        // Update highest score encountered this far
63589 X        v_maxscore = vec_max(v_maxscore,H);
63590 X        
63591 X        
63592 X        
63593 X        // PROLOGUE 10
63594 X        // prefetch next residue
63595 X        k                = db_sequence[10];
63596 X        k8               = db_sequence[2];
63597 X        
63598 X        v_score     = vec_perm(v_score_q1,  v_score_load1,  queue1_to_score);
63599 X        v_score_q1  = vec_perm(v_score_q2,  v_score_load1,  queue2_to_queue1);
63600 X        v_score_q2  = vec_perm(v_score_q3,  v_score_load1,  queue3_to_queue2);
63601 X        v_score_q3  = vec_perm(v_score_q4,  v_score_load1,  queue4_to_queue3);
63602 X        v_score_q4  = vec_perm(v_score_q5,  v_score_load1,  queue5_to_queue4);
63603 X        v_score_q5  = vec_perm(v_score_q5,  v_score_load1,  queue5_with_load);
63604 X        
63605 X
63606 X        // prefetch score for next step 
63607 X        v_score_load1 = vec_ld(16*k,query_profile_byte);            
63608 X        v_score_load2 = vec_ld(16*k8,query_profile_byte);
63609 X        
63610 X        // load values of F and H from previous row (one unit up)
63611 X        Fup    = vec_ld(0,  p);
63612 X        Hup2   = vec_ld(16, p);
63613 X        p += 32; // move ahead 32 bytes
63614 X        
63615 X        // shift into place so we have complete F and H vectors
63616 X        // that refer to the values one unit up from each cell
63617 X        // that we are currently working on.
63618 X        Fup    = vec_sld(Fup,F,15);
63619 X        Hup2   = vec_sld(Hup2,H,15);            
63620 X        
63621 X        // do the dynamic programming 
63622 X        
63623 X        // update E value
63624 X        E   = vec_subs(E,v_gapextend);
63625 X        tmp = vec_subs(H,v_gapopen);
63626 X        E   = vec_max(E,tmp);
63627 X        
63628 X        // update F value
63629 X        F   = vec_subs(Fup,v_gapextend);
63630 X        tmp = vec_subs(Hup2,v_gapopen);
63631 X        F   = vec_max(F,tmp);
63632 X        
63633 X        v_score_load1 = vec_perm(v_score_load1,v_score_load2,merge_score_load);
63634 X        
63635 X        // add score to H
63636 X        H   = vec_adds(Hup1,v_score);
63637 X        H   = vec_subs(H,v_bias);
63638 X        
63639 X        // set H to max of H,E,F
63640 X        H   = vec_max(H,E);
63641 X        H   = vec_max(H,F);
63642 X        
63643 X        // Update highest score encountered this far
63644 X        v_maxscore = vec_max(v_maxscore,H);
63645 X        
63646 X        
63647 X        
63648 X        
63649 X        // PROLOGUE 11
63650 X        // prefetch next residue
63651 X        k                = db_sequence[11];
63652 X        k8               = db_sequence[3];
63653 X        
63654 X        v_score     = vec_perm(v_score_q1,  v_score_load1,  queue1_to_score);
63655 X        v_score_q1  = vec_perm(v_score_q2,  v_score_load1,  queue2_to_queue1);
63656 X        v_score_q2  = vec_perm(v_score_q3,  v_score_load1,  queue3_to_queue2);
63657 X        v_score_q3  = vec_perm(v_score_q4,  v_score_load1,  queue4_to_queue3);
63658 X        v_score_q4  = vec_perm(v_score_q5,  v_score_load1,  queue5_to_queue4);
63659 X        v_score_q5  = vec_perm(v_score_q5,  v_score_load1,  queue5_with_load);
63660 X        
63661 X
63662 X        // prefetch score for next step 
63663 X        v_score_load1 = vec_ld(16*k,query_profile_byte);            
63664 X        v_score_load2 = vec_ld(16*k8,query_profile_byte);
63665 X        
63666 X        // load values of F and H from previous row (one unit up)
63667 X        Fup    = vec_ld(0,  p);
63668 X        Hup1    = vec_ld(16, p);
63669 X        p += 32; // move ahead 32 bytes
63670 X        
63671 X        // shift into place so we have complete F and H vectors
63672 X        // that refer to the values one unit up from each cell
63673 X        // that we are currently working on.
63674 X        Fup    = vec_sld(Fup,F,15);
63675 X        Hup1    = vec_sld(Hup1,H,15);            
63676 X        
63677 X        // do the dynamic programming 
63678 X        
63679 X        // update E value
63680 X        E   = vec_subs(E,v_gapextend);
63681 X        tmp = vec_subs(H,v_gapopen);
63682 X        E   = vec_max(E,tmp);
63683 X        
63684 X        // update F value
63685 X        F   = vec_subs(Fup,v_gapextend);
63686 X        tmp = vec_subs(Hup1,v_gapopen);
63687 X        F   = vec_max(F,tmp);
63688 X        
63689 X        v_score_load1 = vec_perm(v_score_load1,v_score_load2,merge_score_load);
63690 X        
63691 X        // add score to H
63692 X        H   = vec_adds(Hup2,v_score);
63693 X        H   = vec_subs(H,v_bias);
63694 X        
63695 X        // set H to max of H,E,F
63696 X        H   = vec_max(H,E);
63697 X        H   = vec_max(H,F);
63698 X        
63699 X        // Update highest score encountered this far
63700 X        v_maxscore = vec_max(v_maxscore,H);
63701 X        
63702 X        
63703 X        
63704 X        // PROLOGUE 12
63705 X        // prefetch next residue
63706 X        k                = db_sequence[12];
63707 X        k8               = db_sequence[4];
63708 X        
63709 X        v_score     = vec_perm(v_score_q1,  v_score_load1,  queue1_to_score);
63710 X        v_score_q1  = vec_perm(v_score_q2,  v_score_load1,  queue2_to_queue1);
63711 X        v_score_q2  = vec_perm(v_score_q3,  v_score_load1,  queue3_to_queue2);
63712 X        v_score_q3  = vec_perm(v_score_q4,  v_score_load1,  queue4_to_queue3);
63713 X        v_score_q4  = vec_perm(v_score_q5,  v_score_load1,  queue5_to_queue4);
63714 X        v_score_q5  = vec_perm(v_score_q5,  v_score_load1,  queue5_with_load);
63715 X        
63716 X
63717 X        // prefetch score for next step 
63718 X        v_score_load1 = vec_ld(16*k,query_profile_byte);            
63719 X        v_score_load2 = vec_ld(16*k8,query_profile_byte);
63720 X        
63721 X        // load values of F and H from previous row (one unit up)
63722 X        Fup    = vec_ld(0,  p);
63723 X        Hup2   = vec_ld(16, p);
63724 X        p += 32; // move ahead 32 bytes
63725 X        
63726 X        // shift into place so we have complete F and H vectors
63727 X        // that refer to the values one unit up from each cell
63728 X        // that we are currently working on.
63729 X        Fup    = vec_sld(Fup,F,15);
63730 X        Hup2   = vec_sld(Hup2,H,15);            
63731 X        
63732 X        // do the dynamic programming 
63733 X        
63734 X        // update E value
63735 X        E   = vec_subs(E,v_gapextend);
63736 X        tmp = vec_subs(H,v_gapopen);
63737 X        E   = vec_max(E,tmp);
63738 X        
63739 X        // update F value
63740 X        F   = vec_subs(Fup,v_gapextend);
63741 X        tmp = vec_subs(Hup2,v_gapopen);
63742 X        F   = vec_max(F,tmp);
63743 X        
63744 X        v_score_load1 = vec_perm(v_score_load1,v_score_load2,merge_score_load);
63745 X        
63746 X        // add score to H
63747 X        H   = vec_adds(Hup1,v_score);
63748 X        H   = vec_subs(H,v_bias);
63749 X        
63750 X        // set H to max of H,E,F
63751 X        H   = vec_max(H,E);
63752 X        H   = vec_max(H,F);
63753 X        
63754 X        // Update highest score encountered this far
63755 X        v_maxscore = vec_max(v_maxscore,H);
63756 X        
63757 X        
63758 X        
63759 X        
63760 X        // PROLOGUE 13
63761 X        // prefetch next residue
63762 X        k                = db_sequence[13];
63763 X        k8               = db_sequence[5];
63764 X        
63765 X        v_score     = vec_perm(v_score_q1,  v_score_load1,  queue1_to_score);
63766 X        v_score_q1  = vec_perm(v_score_q2,  v_score_load1,  queue2_to_queue1);
63767 X        v_score_q2  = vec_perm(v_score_q3,  v_score_load1,  queue3_to_queue2);
63768 X        v_score_q3  = vec_perm(v_score_q4,  v_score_load1,  queue4_to_queue3);
63769 X        v_score_q4  = vec_perm(v_score_q5,  v_score_load1,  queue5_to_queue4);
63770 X        v_score_q5  = vec_perm(v_score_q5,  v_score_load1,  queue5_with_load);
63771 X        
63772 X
63773 X        // prefetch score for next step 
63774 X        v_score_load1 = vec_ld(16*k,query_profile_byte);            
63775 X        v_score_load2 = vec_ld(16*k8,query_profile_byte);
63776 X        
63777 X        // load values of F and H from previous row (one unit up)
63778 X        Fup    = vec_ld(0,  p);
63779 X        Hup1    = vec_ld(16, p);
63780 X        p += 32; // move ahead 32 bytes
63781 X        
63782 X        // shift into place so we have complete F and H vectors
63783 X        // that refer to the values one unit up from each cell
63784 X        // that we are currently working on.
63785 X        Fup    = vec_sld(Fup,F,15);
63786 X        Hup1    = vec_sld(Hup1,H,15);            
63787 X        
63788 X        // do the dynamic programming 
63789 X        
63790 X        // update E value
63791 X        E   = vec_subs(E,v_gapextend);
63792 X        tmp = vec_subs(H,v_gapopen);
63793 X        E   = vec_max(E,tmp);
63794 X        
63795 X        // update F value
63796 X        F   = vec_subs(Fup,v_gapextend);
63797 X        tmp = vec_subs(Hup1,v_gapopen);
63798 X        F   = vec_max(F,tmp);
63799 X        
63800 X        v_score_load1 = vec_perm(v_score_load1,v_score_load2,merge_score_load);
63801 X        
63802 X        // add score to H
63803 X        H   = vec_adds(Hup2,v_score);
63804 X        H   = vec_subs(H,v_bias);
63805 X        
63806 X        // set H to max of H,E,F
63807 X        H   = vec_max(H,E);
63808 X        H   = vec_max(H,F);
63809 X        
63810 X        // Update highest score encountered this far
63811 X        v_maxscore = vec_max(v_maxscore,H);
63812 X        
63813 X        
63814 X        
63815 X        // PROLOGUE 14
63816 X        // prefetch next residue
63817 X        k                = db_sequence[14];
63818 X        k8               = db_sequence[6];
63819 X        
63820 X        v_score     = vec_perm(v_score_q1,  v_score_load1,  queue1_to_score);
63821 X        v_score_q1  = vec_perm(v_score_q2,  v_score_load1,  queue2_to_queue1);
63822 X        v_score_q2  = vec_perm(v_score_q3,  v_score_load1,  queue3_to_queue2);
63823 X        v_score_q3  = vec_perm(v_score_q4,  v_score_load1,  queue4_to_queue3);
63824 X        v_score_q4  = vec_perm(v_score_q5,  v_score_load1,  queue5_to_queue4);
63825 X        v_score_q5  = vec_perm(v_score_q5,  v_score_load1,  queue5_with_load);
63826 X        
63827 X
63828 X        // prefetch score for next step 
63829 X        v_score_load1 = vec_ld(16*k,query_profile_byte);            
63830 X        v_score_load2 = vec_ld(16*k8,query_profile_byte);
63831 X        
63832 X        // load values of F and H from previous row (one unit up)
63833 X        Fup    = vec_ld(0,  p);
63834 X        Hup2   = vec_ld(16, p);
63835 X        p += 32; // move ahead 32 bytes
63836 X        
63837 X        // shift into place so we have complete F and H vectors
63838 X        // that refer to the values one unit up from each cell
63839 X        // that we are currently working on.
63840 X        Fup    = vec_sld(Fup,F,15);
63841 X        Hup2   = vec_sld(Hup2,H,15);            
63842 X        
63843 X        // do the dynamic programming 
63844 X        
63845 X        // update E value
63846 X        E   = vec_subs(E,v_gapextend);
63847 X        tmp = vec_subs(H,v_gapopen);
63848 X        E   = vec_max(E,tmp);
63849 X        
63850 X        // update F value
63851 X        F   = vec_subs(Fup,v_gapextend);
63852 X        tmp = vec_subs(Hup2,v_gapopen);
63853 X        F   = vec_max(F,tmp);
63854 X        
63855 X        v_score_load1 = vec_perm(v_score_load1,v_score_load2,merge_score_load);
63856 X        
63857 X        // add score to H
63858 X        H   = vec_adds(Hup1,v_score);
63859 X        H   = vec_subs(H,v_bias);
63860 X        
63861 X        // set H to max of H,E,F
63862 X        H   = vec_max(H,E);
63863 X        H   = vec_max(H,F);
63864 X        
63865 X        // Update highest score encountered this far
63866 X        v_maxscore = vec_max(v_maxscore,H);
63867 X        
63868 X        
63869 X        
63870 X        // PROLOGUE 15
63871 X        // prefetch next residue
63872 X        k                = db_sequence[15];
63873 X        k8               = db_sequence[7];
63874 X        
63875 X        v_score     = vec_perm(v_score_q1,  v_score_load1,  queue1_to_score);
63876 X        v_score_q1  = vec_perm(v_score_q2,  v_score_load1,  queue2_to_queue1);
63877 X        v_score_q2  = vec_perm(v_score_q3,  v_score_load1,  queue3_to_queue2);
63878 X        v_score_q3  = vec_perm(v_score_q4,  v_score_load1,  queue4_to_queue3);
63879 X        v_score_q4  = vec_perm(v_score_q5,  v_score_load1,  queue5_to_queue4);
63880 X        v_score_q5  = vec_perm(v_score_q5,  v_score_load1,  queue5_with_load);
63881 X        
63882 X
63883 X        // prefetch score for next step 
63884 X        v_score_load1 = vec_ld(16*k,query_profile_byte);            
63885 X        v_score_load2 = vec_ld(16*k8,query_profile_byte);
63886 X        
63887 X        // load values of F and H from previous row (one unit up)
63888 X        Fup    = vec_ld(0,  p);
63889 X        Hup1    = vec_ld(16, p);
63890 X        p += 32; // move ahead 32 bytes
63891 X        
63892 X        // shift into place so we have complete F and H vectors
63893 X        // that refer to the values one unit up from each cell
63894 X        // that we are currently working on.
63895 X        Fup    = vec_sld(Fup,F,15);
63896 X        Hup1    = vec_sld(Hup1,H,15);            
63897 X        
63898 X        // do the dynamic programming 
63899 X        
63900 X        // update E value
63901 X        E   = vec_subs(E,v_gapextend);
63902 X        tmp = vec_subs(H,v_gapopen);
63903 X        E   = vec_max(E,tmp);
63904 X        
63905 X        // update F value
63906 X        F   = vec_subs(Fup,v_gapextend);
63907 X        tmp = vec_subs(Hup1,v_gapopen);
63908 X        F   = vec_max(F,tmp);
63909 X        
63910 X        v_score_load1 = vec_perm(v_score_load1,v_score_load2,merge_score_load);
63911 X        
63912 X        // add score to H
63913 X        H   = vec_adds(Hup2,v_score);
63914 X        H   = vec_subs(H,v_bias);
63915 X        
63916 X        // set H to max of H,E,F
63917 X        H   = vec_max(H,E);
63918 X        H   = vec_max(H,F);
63919 X        
63920 X        // Update highest score encountered this far
63921 X        v_maxscore = vec_max(v_maxscore,H);
63922 X        
63923 X        
63924 X        
63925 X        // PROLOGUE 16
63926 X        // prefetch next residue
63927 X        k                = db_sequence[16];
63928 X        k8               = db_sequence[8];
63929 X        
63930 X        v_score     = vec_perm(v_score_q1,  v_score_load1,  queue1_to_score);
63931 X        v_score_q1  = vec_perm(v_score_q2,  v_score_load1,  queue2_to_queue1);
63932 X        v_score_q2  = vec_perm(v_score_q3,  v_score_load1,  queue3_to_queue2);
63933 X        v_score_q3  = vec_perm(v_score_q4,  v_score_load1,  queue4_to_queue3);
63934 X        v_score_q4  = vec_perm(v_score_q5,  v_score_load1,  queue5_to_queue4);
63935 X        v_score_q5  = vec_perm(v_score_q5,  v_score_load1,  queue5_with_load);
63936 X        
63937 X
63938 X        // prefetch score for next step 
63939 X        v_score_load1 = vec_ld(16*k,query_profile_byte);            
63940 X        v_score_load2 = vec_ld(16*k8,query_profile_byte);
63941 X        
63942 X        // load values of F and H from previous row (one unit up)
63943 X        Fup    = vec_ld(0,  p);
63944 X        Hup2   = vec_ld(16, p);
63945 X        p += 32; // move ahead 32 bytes
63946 X        
63947 X        // shift into place so we have complete F and H vectors
63948 X        // that refer to the values one unit up from each cell
63949 X        // that we are currently working on.
63950 X        Fup    = vec_sld(Fup,F,15);
63951 X        Hup2   = vec_sld(Hup2,H,15);            
63952 X        
63953 X        // do the dynamic programming 
63954 X        
63955 X        // update E value
63956 X        E   = vec_subs(E,v_gapextend);
63957 X        tmp = vec_subs(H,v_gapopen);
63958 X        E   = vec_max(E,tmp);
63959 X        
63960 X        // update F value
63961 X        F   = vec_subs(Fup,v_gapextend);
63962 X        tmp = vec_subs(Hup2,v_gapopen);
63963 X        F   = vec_max(F,tmp);
63964 X        
63965 X        v_score_load1 = vec_perm(v_score_load1,v_score_load2,merge_score_load);
63966 X        
63967 X        // add score to H
63968 X        H   = vec_adds(Hup1,v_score);
63969 X        H   = vec_subs(H,v_bias);
63970 X        
63971 X        // set H to max of H,E,F
63972 X        H   = vec_max(H,E);
63973 X        H   = vec_max(H,F);
63974 X        
63975 X        // Update highest score encountered this far
63976 X        v_maxscore = vec_max(v_maxscore,H);
63977 X        
63978 X        p = workspace;
63979 X        
63980 X        for(j=16;j<db_length;j+=16)
63981 X        { 
63982 X            // STEP 1
63983 X            
63984 X            // prefetch next residue 
63985 X            k                = db_sequence[j+1];
63986 X            k8               = db_sequence[j-7];
63987 X            
63988 X            v_score     = vec_perm(v_score_q1,  v_score_load1,  queue1_to_score);
63989 X            v_score_q1  = vec_perm(v_score_q2,  v_score_load1,  queue2_to_queue1);
63990 X            v_score_q2  = vec_perm(v_score_q3,  v_score_load1,  queue3_to_queue2);
63991 X            v_score_q3  = vec_perm(v_score_q4,  v_score_load1,  queue4_to_queue3);
63992 X            v_score_q4  = vec_perm(v_score_q5,  v_score_load1,  queue5_to_queue4);
63993 X            v_score_q5  = vec_perm(v_score_q5,  v_score_load1,  queue5_with_load);
63994 X            
63995 X            // prefetch scores for next step
63996 X            v_score_load1 = vec_ld(16*k,query_profile_byte);
63997 X            v_score_load2 = vec_ld(16*k8,query_profile_byte);
63998 X       
63999 X            // load values of F and H from previous row (one unit up)
64000 X            Fup    = vec_ld(512, p);
64001 X            Hup1   = vec_ld(528, p);
64002 X            
64003 X            // save old values of F and H to use on next row
64004 X            vec_st(F, 0,  p);
64005 X            vec_st(H, 16, p);
64006 X            p += 32;
64007 X            
64008 X            // shift into place so we have complete F and H vectors
64009 X            // that refer to the values one unit up from each cell
64010 X            // that we are currently working on.
64011 X            Fup    = vec_sld(Fup,F,15);
64012 X            Hup1    = vec_sld(Hup1,H,15);            
64013 X
64014 X            // do the dynamic programming 
64015 X            
64016 X            // update E value
64017 X            E   = vec_subs(E,v_gapextend);
64018 X            tmp = vec_subs(H,v_gapopen);
64019 X            E   = vec_max(E,tmp);
64020 X            
64021 X            // update F value
64022 X            F   = vec_subs(Fup,v_gapextend);
64023 X            tmp = vec_subs(Hup1,v_gapopen);
64024 X            F   = vec_max(F,tmp);
64025 X
64026 X            v_score_load1 = vec_perm(v_score_load1,v_score_load2,merge_score_load);
64027 X            
64028 X            // add score to H
64029 X            H   = vec_adds(Hup2,v_score);
64030 X            H   = vec_subs(H,v_bias);
64031 X            
64032 X            // set H to max of H,E,F
64033 X            H   = vec_max(H,E);
64034 X            H   = vec_max(H,F);
64035 X            
64036 X
64037 X            
64038 X            // Update highest score encountered this far
64039 X            v_maxscore = vec_max(v_maxscore,H);
64040 X          
64041 X
64042 X            
64043 X            
64044 X            
64045 X            // STEP 2
64046 X            
64047 X            // prefetch next residue
64048 X            k                = db_sequence[j+2];
64049 X            k8               = db_sequence[j-6];
64050 X            
64051 X            v_score     = vec_perm(v_score_q1,  v_score_load1,  queue1_to_score);
64052 X            v_score_q1  = vec_perm(v_score_q2,  v_score_load1,  queue2_to_queue1);
64053 X            v_score_q2  = vec_perm(v_score_q3,  v_score_load1,  queue3_to_queue2);
64054 X            v_score_q3  = vec_perm(v_score_q4,  v_score_load1,  queue4_to_queue3);
64055 X            v_score_q4  = vec_perm(v_score_q5,  v_score_load1,  queue5_to_queue4);
64056 X            v_score_q5  = vec_perm(v_score_q5,  v_score_load1,  queue5_with_load);
64057 X            
64058 X            
64059 X            // prefetch scores for next step
64060 X            v_score_load1 = vec_ld(16*k,query_profile_byte);
64061 X            v_score_load2 = vec_ld(16*k8,query_profile_byte);
64062 X            
64063 X            // load values of F and H from previous row (one unit up)
64064 X            Fup    = vec_ld(512, p);
64065 X            Hup2   = vec_ld(528, p);
64066 X            
64067 X            // save old values of F and H to use on next row
64068 X            vec_st(F, 0,  p);
64069 X            vec_st(H, 16, p);
64070 X            p += 32;
64071 X            
64072 X            // shift into place so we have complete F and H vectors
64073 X            // that refer to the values one unit up from each cell
64074 X            // that we are currently working on.
64075 X            Fup    = vec_sld(Fup,F,15);
64076 X            Hup2   = vec_sld(Hup2,H,15);            
64077 X            
64078 X            // do the dynamic programming 
64079 X            
64080 X            // update E value
64081 X            E   = vec_subs(E,v_gapextend);
64082 X            tmp = vec_subs(H,v_gapopen);
64083 X            E   = vec_max(E,tmp);
64084 X            
64085 X            // update F value
64086 X            F   = vec_subs(Fup,v_gapextend);
64087 X            tmp = vec_subs(Hup2,v_gapopen);
64088 X            F   = vec_max(F,tmp);
64089 X            
64090 X            v_score_load1 = vec_perm(v_score_load1,v_score_load2,merge_score_load);
64091 X            
64092 X            // add score to H
64093 X            H   = vec_adds(Hup1,v_score);
64094 X            H   = vec_subs(H,v_bias);
64095 X            
64096 X            // set H to max of H,E,F
64097 X            H   = vec_max(H,E);
64098 X            H   = vec_max(H,F);
64099 X            
64100 X            
64101 X            // Update highest score encountered this far
64102 X            v_maxscore = vec_max(v_maxscore,H);
64103 X            
64104 X            
64105 X
64106 X            
64107 X            
64108 X            
64109 X            // STEP 3
64110 X            
64111 X            // prefetch next residue
64112 X            k                = db_sequence[j+3];
64113 X            k8               = db_sequence[j-5];
64114 X            
64115 X            v_score     = vec_perm(v_score_q1,  v_score_load1,  queue1_to_score);
64116 X            v_score_q1  = vec_perm(v_score_q2,  v_score_load1,  queue2_to_queue1);
64117 X            v_score_q2  = vec_perm(v_score_q3,  v_score_load1,  queue3_to_queue2);
64118 X            v_score_q3  = vec_perm(v_score_q4,  v_score_load1,  queue4_to_queue3);
64119 X            v_score_q4  = vec_perm(v_score_q5,  v_score_load1,  queue5_to_queue4);
64120 X            v_score_q5  = vec_perm(v_score_q5,  v_score_load1,  queue5_with_load);
64121 X            
64122 X            
64123 X            // prefetch scores for next step
64124 X            v_score_load1 = vec_ld(16*k,query_profile_byte);
64125 X            v_score_load2 = vec_ld(16*k8,query_profile_byte);
64126 X            
64127 X            // load values of F and H from previous row (one unit up)
64128 X            Fup    = vec_ld(512, p);
64129 X            Hup1   = vec_ld(528, p);
64130 X            
64131 X            // save old values of F and H to use on next row
64132 X            vec_st(F, 0,  p);
64133 X            vec_st(H, 16, p);
64134 X            p += 32;
64135 X            
64136 X            // shift into place so we have complete F and H vectors
64137 X            // that refer to the values one unit up from each cell
64138 X            // that we are currently working on.
64139 X            Fup    = vec_sld(Fup,F,15);
64140 X            Hup1    = vec_sld(Hup1,H,15);            
64141 X            
64142 X            // do the dynamic programming 
64143 X            
64144 X            // update E value
64145 X            E   = vec_subs(E,v_gapextend);
64146 X            tmp = vec_subs(H,v_gapopen);
64147 X            E   = vec_max(E,tmp);
64148 X            
64149 X            // update F value
64150 X            F   = vec_subs(Fup,v_gapextend);
64151 X            tmp = vec_subs(Hup1,v_gapopen);
64152 X            F   = vec_max(F,tmp);
64153 X            
64154 X            v_score_load1 = vec_perm(v_score_load1,v_score_load2,merge_score_load);
64155 X            
64156 X            // add score to H
64157 X            H   = vec_adds(Hup2,v_score);
64158 X            H   = vec_subs(H,v_bias);
64159 X            
64160 X            // set H to max of H,E,F
64161 X            H   = vec_max(H,E);
64162 X            H   = vec_max(H,F);
64163 X            
64164 X            // Update highest score encountered this far
64165 X            v_maxscore = vec_max(v_maxscore,H);
64166 X            
64167 X      
64168 X            
64169 X
64170 X            
64171 X            
64172 X            // STEP 4
64173 X            
64174 X            // prefetch next residue
64175 X            k                = db_sequence[j+4];
64176 X            k8               = db_sequence[j-4];
64177 X            
64178 X            v_score     = vec_perm(v_score_q1,  v_score_load1,  queue1_to_score);
64179 X            v_score_q1  = vec_perm(v_score_q2,  v_score_load1,  queue2_to_queue1);
64180 X            v_score_q2  = vec_perm(v_score_q3,  v_score_load1,  queue3_to_queue2);
64181 X            v_score_q3  = vec_perm(v_score_q4,  v_score_load1,  queue4_to_queue3);
64182 X            v_score_q4  = vec_perm(v_score_q5,  v_score_load1,  queue5_to_queue4);
64183 X            v_score_q5  = vec_perm(v_score_q5,  v_score_load1,  queue5_with_load);
64184 X            
64185 X            
64186 X            // prefetch scores for next step
64187 X            v_score_load1 = vec_ld(16*k,query_profile_byte);
64188 X            v_score_load2 = vec_ld(16*k8,query_profile_byte);
64189 X            
64190 X            // load values of F and H from previous row (one unit up)
64191 X            Fup    = vec_ld(512, p);
64192 X            Hup2   = vec_ld(528, p);
64193 X            
64194 X            // save old values of F and H to use on next row
64195 X            vec_st(F, 0,  p);
64196 X            vec_st(H, 16, p);
64197 X            p += 32;
64198 X            
64199 X            // shift into place so we have complete F and H vectors
64200 X            // that refer to the values one unit up from each cell
64201 X            // that we are currently working on.
64202 X            Fup    = vec_sld(Fup,F,15);
64203 X            Hup2   = vec_sld(Hup2,H,15);            
64204 X            
64205 X            // do the dynamic programming 
64206 X            
64207 X            // update E value
64208 X            E   = vec_subs(E,v_gapextend);
64209 X            tmp = vec_subs(H,v_gapopen);
64210 X            E   = vec_max(E,tmp);
64211 X            
64212 X            // update F value
64213 X            F   = vec_subs(Fup,v_gapextend);
64214 X            tmp = vec_subs(Hup2,v_gapopen);
64215 X            F   = vec_max(F,tmp);
64216 X            
64217 X            v_score_load1 = vec_perm(v_score_load1,v_score_load2,merge_score_load);
64218 X            
64219 X            // add score to H
64220 X            H   = vec_adds(Hup1,v_score);
64221 X            H   = vec_subs(H,v_bias);
64222 X            
64223 X            // set H to max of H,E,F
64224 X            H   = vec_max(H,E);
64225 X            H   = vec_max(H,F);
64226 X            
64227 X            // Update highest score encountered this far
64228 X            v_maxscore = vec_max(v_maxscore,H);
64229 X            
64230 X            
64231 X            
64232 X
64233 X            
64234 X            
64235 X            // STEP 5
64236 X            
64237 X            // prefetch next residue
64238 X            k                = db_sequence[j+5];
64239 X            k8               = db_sequence[j-3];
64240 X            
64241 X            v_score     = vec_perm(v_score_q1,  v_score_load1,  queue1_to_score);
64242 X            v_score_q1  = vec_perm(v_score_q2,  v_score_load1,  queue2_to_queue1);
64243 X            v_score_q2  = vec_perm(v_score_q3,  v_score_load1,  queue3_to_queue2);
64244 X            v_score_q3  = vec_perm(v_score_q4,  v_score_load1,  queue4_to_queue3);
64245 X            v_score_q4  = vec_perm(v_score_q5,  v_score_load1,  queue5_to_queue4);
64246 X            v_score_q5  = vec_perm(v_score_q5,  v_score_load1,  queue5_with_load);
64247 X            
64248 X            
64249 X            // prefetch scores for next step
64250 X            v_score_load1 = vec_ld(16*k,query_profile_byte);
64251 X            v_score_load2 = vec_ld(16*k8,query_profile_byte);
64252 X            
64253 X            // load values of F and H from previous row (one unit up)
64254 X            Fup    = vec_ld(512, p);
64255 X            Hup1    = vec_ld(528, p);
64256 X            
64257 X            // save old values of F and H to use on next row
64258 X            vec_st(F, 0,  p);
64259 X            vec_st(H, 16, p);
64260 X            p += 32;
64261 X            
64262 X            // shift into place so we have complete F and H vectors
64263 X            // that refer to the values one unit up from each cell
64264 X            // that we are currently working on.
64265 X            Fup    = vec_sld(Fup,F,15);
64266 X            Hup1   = vec_sld(Hup1,H,15);            
64267 X            
64268 X            // do the dynamic programming 
64269 X            
64270 X            // update E value
64271 X            E   = vec_subs(E,v_gapextend);
64272 X            tmp = vec_subs(H,v_gapopen);
64273 X            E   = vec_max(E,tmp);
64274 X            
64275 X            // update F value
64276 X            F   = vec_subs(Fup,v_gapextend);
64277 X            tmp = vec_subs(Hup1,v_gapopen);
64278 X            F   = vec_max(F,tmp);
64279 X            
64280 X            v_score_load1 = vec_perm(v_score_load1,v_score_load2,merge_score_load);
64281 X            
64282 X            // add score to H
64283 X            H   = vec_adds(Hup2,v_score);
64284 X            H   = vec_subs(H,v_bias);
64285 X            
64286 X            // set H to max of H,E,F
64287 X            H   = vec_max(H,E);
64288 X            H   = vec_max(H,F);
64289 X            
64290 X            // Update highest score encountered this far
64291 X            v_maxscore = vec_max(v_maxscore,H);
64292 X            
64293 X            
64294 X
64295 X            
64296 X            
64297 X            
64298 X            // STEP 6
64299 X            
64300 X            // prefetch next residue
64301 X            k                = db_sequence[j+6];
64302 X            k8               = db_sequence[j-2];
64303 X            
64304 X            v_score     = vec_perm(v_score_q1,  v_score_load1,  queue1_to_score);
64305 X            v_score_q1  = vec_perm(v_score_q2,  v_score_load1,  queue2_to_queue1);
64306 X            v_score_q2  = vec_perm(v_score_q3,  v_score_load1,  queue3_to_queue2);
64307 X            v_score_q3  = vec_perm(v_score_q4,  v_score_load1,  queue4_to_queue3);
64308 X            v_score_q4  = vec_perm(v_score_q5,  v_score_load1,  queue5_to_queue4);
64309 X            v_score_q5  = vec_perm(v_score_q5,  v_score_load1,  queue5_with_load);
64310 X            
64311 X            
64312 X            // prefetch scores for next step
64313 X            v_score_load1 = vec_ld(16*k,query_profile_byte);
64314 X            v_score_load2 = vec_ld(16*k8,query_profile_byte);
64315 X            
64316 X            // load values of F and H from previous row (one unit up)
64317 X            Fup    = vec_ld(512, p);
64318 X            Hup2   = vec_ld(528, p);
64319 X            
64320 X            // save old values of F and H to use on next row
64321 X            vec_st(F, 0,  p);
64322 X            vec_st(H, 16, p);
64323 X            p += 32;
64324 X            
64325 X            // shift into place so we have complete F and H vectors
64326 X            // that refer to the values one unit up from each cell
64327 X            // that we are currently working on.
64328 X            Fup    = vec_sld(Fup,F,15);
64329 X            Hup2   = vec_sld(Hup2,H,15);            
64330 X            
64331 X            // do the dynamic programming 
64332 X            
64333 X            // update E value
64334 X            E   = vec_subs(E,v_gapextend);
64335 X            tmp = vec_subs(H,v_gapopen);
64336 X            E   = vec_max(E,tmp);
64337 X            
64338 X            // update F value
64339 X            F   = vec_subs(Fup,v_gapextend);
64340 X            tmp = vec_subs(Hup2,v_gapopen);
64341 X            F   = vec_max(F,tmp);
64342 X            
64343 X            v_score_load1 = vec_perm(v_score_load1,v_score_load2,merge_score_load);
64344 X            
64345 X            // add score to H
64346 X            H   = vec_adds(Hup1,v_score);
64347 X            H   = vec_subs(H,v_bias);
64348 X            
64349 X            // set H to max of H,E,F
64350 X            H   = vec_max(H,E);
64351 X            H   = vec_max(H,F);
64352 X            
64353 X            // Update highest score encountered this far
64354 X            v_maxscore = vec_max(v_maxscore,H);
64355 X            
64356 X            
64357 X
64358 X            
64359 X            
64360 X            
64361 X            // STEP 7
64362 X            
64363 X            // prefetch next residue
64364 X            k                = db_sequence[j+7];
64365 X            k8               = db_sequence[j-1];
64366 X            
64367 X            v_score     = vec_perm(v_score_q1,  v_score_load1,  queue1_to_score);
64368 X            v_score_q1  = vec_perm(v_score_q2,  v_score_load1,  queue2_to_queue1);
64369 X            v_score_q2  = vec_perm(v_score_q3,  v_score_load1,  queue3_to_queue2);
64370 X            v_score_q3  = vec_perm(v_score_q4,  v_score_load1,  queue4_to_queue3);
64371 X            v_score_q4  = vec_perm(v_score_q5,  v_score_load1,  queue5_to_queue4);
64372 X            v_score_q5  = vec_perm(v_score_q5,  v_score_load1,  queue5_with_load);
64373 X            
64374 X            
64375 X            // prefetch scores for next step
64376 X            v_score_load1 = vec_ld(16*k,query_profile_byte);
64377 X            v_score_load2 = vec_ld(16*k8,query_profile_byte);
64378 X            
64379 X            // load values of F and H from previous row (one unit up)
64380 X            Fup    = vec_ld(512, p);
64381 X            Hup1    = vec_ld(528, p);
64382 X            
64383 X            // save old values of F and H to use on next row
64384 X            vec_st(F, 0,  p);
64385 X            vec_st(H, 16, p);
64386 X            p += 32;
64387 X            
64388 X            // shift into place so we have complete F and H vectors
64389 X            // that refer to the values one unit up from each cell
64390 X            // that we are currently working on.
64391 X            Fup    = vec_sld(Fup,F,15);
64392 X            Hup1    = vec_sld(Hup1,H,15);            
64393 X            
64394 X            // do the dynamic programming 
64395 X            
64396 X            // update E value
64397 X            E   = vec_subs(E,v_gapextend);
64398 X            tmp = vec_subs(H,v_gapopen);
64399 X            E   = vec_max(E,tmp);
64400 X            
64401 X            // update F value
64402 X            F   = vec_subs(Fup,v_gapextend);
64403 X            tmp = vec_subs(Hup1,v_gapopen);
64404 X            F   = vec_max(F,tmp);
64405 X            
64406 X            v_score_load1 = vec_perm(v_score_load1,v_score_load2,merge_score_load);
64407 X            
64408 X            // add score to H
64409 X            H   = vec_adds(Hup2,v_score);
64410 X            H   = vec_subs(H,v_bias);
64411 X            
64412 X            // set H to max of H,E,F
64413 X            H   = vec_max(H,E);
64414 X            H   = vec_max(H,F);
64415 X            
64416 X            // Update highest score encountered this far
64417 X            v_maxscore = vec_max(v_maxscore,H);
64418 X            
64419 X            
64420 X            
64421 X
64422 X            
64423 X            
64424 X            // STEP 8
64425 X            
64426 X            // prefetch next residue
64427 X            k                = db_sequence[j+8];
64428 X            k8               = db_sequence[j];
64429 X            
64430 X            v_score     = vec_perm(v_score_q1,  v_score_load1,  queue1_to_score);
64431 X            v_score_q1  = vec_perm(v_score_q2,  v_score_load1,  queue2_to_queue1);
64432 X            v_score_q2  = vec_perm(v_score_q3,  v_score_load1,  queue3_to_queue2);
64433 X            v_score_q3  = vec_perm(v_score_q4,  v_score_load1,  queue4_to_queue3);
64434 X            v_score_q4  = vec_perm(v_score_q5,  v_score_load1,  queue5_to_queue4);
64435 X            v_score_q5  = vec_perm(v_score_q5,  v_score_load1,  queue5_with_load);
64436 X            
64437 X            
64438 X            // prefetch scores for next step
64439 X            v_score_load1 = vec_ld(16*k,query_profile_byte);
64440 X            v_score_load2 = vec_ld(16*k8,query_profile_byte);
64441 X            
64442 X            // load values of F and H from previous row (one unit up)
64443 X            Fup    = vec_ld(512, p);
64444 X            Hup2   = vec_ld(528, p);
64445 X            
64446 X            // save old values of F and H to use on next row
64447 X            vec_st(F, 0,  p);
64448 X            vec_st(H, 16, p);
64449 X            p += 32;
64450 X            
64451 X            // shift into place so we have complete F and H vectors
64452 X            // that refer to the values one unit up from each cell
64453 X            // that we are currently working on.
64454 X            Fup    = vec_sld(Fup,F,15);
64455 X            Hup2   = vec_sld(Hup2,H,15);            
64456 X            
64457 X            // do the dynamic programming 
64458 X            
64459 X            // update E value
64460 X            E   = vec_subs(E,v_gapextend);
64461 X            tmp = vec_subs(H,v_gapopen);
64462 X            E   = vec_max(E,tmp);
64463 X            
64464 X            // update F value
64465 X            F   = vec_subs(Fup,v_gapextend);
64466 X            tmp = vec_subs(Hup2,v_gapopen);
64467 X            F   = vec_max(F,tmp);
64468 X            
64469 X            v_score_load1 = vec_perm(v_score_load1,v_score_load2,merge_score_load);
64470 X            
64471 X            // add score to H
64472 X            H   = vec_adds(Hup1,v_score);
64473 X            H   = vec_subs(H,v_bias);
64474 X            
64475 X            // set H to max of H,E,F
64476 X            H   = vec_max(H,E);
64477 X            H   = vec_max(H,F);
64478 X            
64479 X            // Update highest score encountered this far
64480 X            v_maxscore = vec_max(v_maxscore,H);
64481 X            
64482 X            
64483 X            
64484 X
64485 X            
64486 X            
64487 X            // STEP 9
64488 X            
64489 X            // prefetch next residue
64490 X            k                = db_sequence[j+9];
64491 X            k8               = db_sequence[j+1];
64492 X            
64493 X            v_score     = vec_perm(v_score_q1,  v_score_load1,  queue1_to_score);
64494 X            v_score_q1  = vec_perm(v_score_q2,  v_score_load1,  queue2_to_queue1);
64495 X            v_score_q2  = vec_perm(v_score_q3,  v_score_load1,  queue3_to_queue2);
64496 X            v_score_q3  = vec_perm(v_score_q4,  v_score_load1,  queue4_to_queue3);
64497 X            v_score_q4  = vec_perm(v_score_q5,  v_score_load1,  queue5_to_queue4);
64498 X            v_score_q5  = vec_perm(v_score_q5,  v_score_load1,  queue5_with_load);
64499 X            
64500 X            
64501 X            // prefetch scores for next step
64502 X            v_score_load1 = vec_ld(16*k,query_profile_byte);
64503 X            v_score_load2 = vec_ld(16*k8,query_profile_byte);
64504 X            
64505 X            // load values of F and H from previous row (one unit up)
64506 X            Fup    = vec_ld(512, p);
64507 X            Hup1   = vec_ld(528, p);
64508 X            
64509 X            // save old values of F and H to use on next row
64510 X            vec_st(F, 0,  p);
64511 X            vec_st(H, 16, p);
64512 X            p += 32;
64513 X            
64514 X            // shift into place so we have complete F and H vectors
64515 X            // that refer to the values one unit up from each cell
64516 X            // that we are currently working on.
64517 X            Fup    = vec_sld(Fup,F,15);
64518 X            Hup1   = vec_sld(Hup1,H,15);            
64519 X            
64520 X            // do the dynamic programming 
64521 X            
64522 X            // update E value
64523 X            E   = vec_subs(E,v_gapextend);
64524 X            tmp = vec_subs(H,v_gapopen);
64525 X            E   = vec_max(E,tmp);
64526 X            
64527 X            // update F value
64528 X            F   = vec_subs(Fup,v_gapextend);
64529 X            tmp = vec_subs(Hup1,v_gapopen);
64530 X            F   = vec_max(F,tmp);
64531 X            
64532 X            v_score_load1 = vec_perm(v_score_load1,v_score_load2,merge_score_load);
64533 X            
64534 X            // add score to H
64535 X            H   = vec_adds(Hup2,v_score);
64536 X            H   = vec_subs(H,v_bias);
64537 X            
64538 X            // set H to max of H,E,F
64539 X            H   = vec_max(H,E);
64540 X            H   = vec_max(H,F);
64541 X            
64542 X            // Update highest score encountered this far
64543 X            v_maxscore = vec_max(v_maxscore,H);
64544 X            
64545 X            // STEP 10
64546 X            
64547 X            // prefetch next residue
64548 X            k                = db_sequence[j+10];
64549 X            k8               = db_sequence[j+2];
64550 X            
64551 X            v_score     = vec_perm(v_score_q1,  v_score_load1,  queue1_to_score);
64552 X            v_score_q1  = vec_perm(v_score_q2,  v_score_load1,  queue2_to_queue1);
64553 X            v_score_q2  = vec_perm(v_score_q3,  v_score_load1,  queue3_to_queue2);
64554 X            v_score_q3  = vec_perm(v_score_q4,  v_score_load1,  queue4_to_queue3);
64555 X            v_score_q4  = vec_perm(v_score_q5,  v_score_load1,  queue5_to_queue4);
64556 X            v_score_q5  = vec_perm(v_score_q5,  v_score_load1,  queue5_with_load);
64557 X            
64558 X            
64559 X            // prefetch scores for next step
64560 X            v_score_load1 = vec_ld(16*k,query_profile_byte);
64561 X            v_score_load2 = vec_ld(16*k8,query_profile_byte);
64562 X            
64563 X            // load values of F and H from previous row (one unit up)
64564 X            Fup    = vec_ld(512, p);
64565 X            Hup2   = vec_ld(528, p);
64566 X            
64567 X            // save old values of F and H to use on next row
64568 X            vec_st(F, 0,  p);
64569 X            vec_st(H, 16, p);
64570 X            p += 32;
64571 X            
64572 X            // shift into place so we have complete F and H vectors
64573 X            // that refer to the values one unit up from each cell
64574 X            // that we are currently working on.
64575 X            Fup    = vec_sld(Fup,F,15);
64576 X            Hup2   = vec_sld(Hup2,H,15);            
64577 X            
64578 X            // do the dynamic programming 
64579 X            
64580 X            // update E value
64581 X            E   = vec_subs(E,v_gapextend);
64582 X            tmp = vec_subs(H,v_gapopen);
64583 X            E   = vec_max(E,tmp);
64584 X            
64585 X            // update F value
64586 X            F   = vec_subs(Fup,v_gapextend);
64587 X            tmp = vec_subs(Hup2,v_gapopen);
64588 X            F   = vec_max(F,tmp);
64589 X            
64590 X            v_score_load1 = vec_perm(v_score_load1,v_score_load2,merge_score_load);
64591 X            
64592 X            // add score to H
64593 X            H   = vec_adds(Hup1,v_score);
64594 X            H   = vec_subs(H,v_bias);
64595 X            
64596 X            // set H to max of H,E,F
64597 X            H   = vec_max(H,E);
64598 X            H   = vec_max(H,F);
64599 X        
64600 X            // Update highest score encountered this far
64601 X            v_maxscore = vec_max(v_maxscore,H);
64602 X            
64603 X            // STEP 11
64604 X            
64605 X            // prefetch next residue
64606 X            k                = db_sequence[j+11];
64607 X            k8               = db_sequence[j+3];
64608 X            
64609 X            v_score     = vec_perm(v_score_q1,  v_score_load1,  queue1_to_score);
64610 X            v_score_q1  = vec_perm(v_score_q2,  v_score_load1,  queue2_to_queue1);
64611 X            v_score_q2  = vec_perm(v_score_q3,  v_score_load1,  queue3_to_queue2);
64612 X            v_score_q3  = vec_perm(v_score_q4,  v_score_load1,  queue4_to_queue3);
64613 X            v_score_q4  = vec_perm(v_score_q5,  v_score_load1,  queue5_to_queue4);
64614 X            v_score_q5  = vec_perm(v_score_q5,  v_score_load1,  queue5_with_load);
64615 X            
64616 X            
64617 X            // prefetch scores for next step
64618 X            v_score_load1 = vec_ld(16*k,query_profile_byte);
64619 X            v_score_load2 = vec_ld(16*k8,query_profile_byte);
64620 X            
64621 X            // load values of F and H from previous row (one unit up)
64622 X            Fup    = vec_ld(512, p);
64623 X            Hup1   = vec_ld(528, p);
64624 X            
64625 X            // save old values of F and H to use on next row
64626 X            vec_st(F, 0,  p);
64627 X            vec_st(H, 16, p);
64628 X            p += 32;
64629 X            
64630 X            // shift into place so we have complete F and H vectors
64631 X            // that refer to the values one unit up from each cell
64632 X            // that we are currently working on.
64633 X            Fup    = vec_sld(Fup,F,15);
64634 X            Hup1   = vec_sld(Hup1,H,15);            
64635 X            
64636 X            // do the dynamic programming 
64637 X            
64638 X            // update E value
64639 X            E   = vec_subs(E,v_gapextend);
64640 X            tmp = vec_subs(H,v_gapopen);
64641 X            E   = vec_max(E,tmp);
64642 X            
64643 X            // update F value
64644 X            F   = vec_subs(Fup,v_gapextend);
64645 X            tmp = vec_subs(Hup1,v_gapopen);
64646 X            F   = vec_max(F,tmp);
64647 X            
64648 X            v_score_load1 = vec_perm(v_score_load1,v_score_load2,merge_score_load);
64649 X            
64650 X            // add score to H
64651 X            H   = vec_adds(Hup2,v_score);
64652 X            H   = vec_subs(H,v_bias);
64653 X            
64654 X            // set H to max of H,E,F
64655 X            H   = vec_max(H,E);
64656 X            H   = vec_max(H,F);
64657 X            
64658 X            // Update highest score encountered this far
64659 X            v_maxscore = vec_max(v_maxscore,H);
64660 X            
64661 X            // STEP 12
64662 X            
64663 X            // prefetch next residue
64664 X            k                = db_sequence[j+12];
64665 X            k8               = db_sequence[j+4];
64666 X            
64667 X            v_score     = vec_perm(v_score_q1,  v_score_load1,  queue1_to_score);
64668 X            v_score_q1  = vec_perm(v_score_q2,  v_score_load1,  queue2_to_queue1);
64669 X            v_score_q2  = vec_perm(v_score_q3,  v_score_load1,  queue3_to_queue2);
64670 X            v_score_q3  = vec_perm(v_score_q4,  v_score_load1,  queue4_to_queue3);
64671 X            v_score_q4  = vec_perm(v_score_q5,  v_score_load1,  queue5_to_queue4);
64672 X            v_score_q5  = vec_perm(v_score_q5,  v_score_load1,  queue5_with_load);
64673 X            
64674 X            
64675 X            // prefetch scores for next step
64676 X            v_score_load1 = vec_ld(16*k,query_profile_byte);
64677 X            v_score_load2 = vec_ld(16*k8,query_profile_byte);
64678 X            
64679 X            // load values of F and H from previous row (one unit up)
64680 X            Fup    = vec_ld(512, p);
64681 X            Hup2   = vec_ld(528, p);
64682 X            
64683 X            // save old values of F and H to use on next row
64684 X            vec_st(F, 0,  p);
64685 X            vec_st(H, 16, p);
64686 X            p += 32;
64687 X            
64688 X            // shift into place so we have complete F and H vectors
64689 X            // that refer to the values one unit up from each cell
64690 X            // that we are currently working on.
64691 X            Fup    = vec_sld(Fup,F,15);
64692 X            Hup2   = vec_sld(Hup2,H,15);            
64693 X            
64694 X            // do the dynamic programming 
64695 X            
64696 X            // update E value
64697 X            E   = vec_subs(E,v_gapextend);
64698 X            tmp = vec_subs(H,v_gapopen);
64699 X            E   = vec_max(E,tmp);
64700 X            
64701 X            // update F value
64702 X            F   = vec_subs(Fup,v_gapextend);
64703 X            tmp = vec_subs(Hup2,v_gapopen);
64704 X            F   = vec_max(F,tmp);
64705 X            
64706 X            v_score_load1 = vec_perm(v_score_load1,v_score_load2,merge_score_load);
64707 X            
64708 X            // add score to H
64709 X            H   = vec_adds(Hup1,v_score);
64710 X            H   = vec_subs(H,v_bias);
64711 X            
64712 X            // set H to max of H,E,F
64713 X            H   = vec_max(H,E);
64714 X            H   = vec_max(H,F);
64715 X            
64716 X            // Update highest score encountered this far
64717 X            v_maxscore = vec_max(v_maxscore,H);
64718 X            
64719 X            // STEP 13
64720 X            
64721 X            // prefetch next residue
64722 X            k                = db_sequence[j+13];
64723 X            k8               = db_sequence[j+5];
64724 X            
64725 X            v_score     = vec_perm(v_score_q1,  v_score_load1,  queue1_to_score);
64726 X            v_score_q1  = vec_perm(v_score_q2,  v_score_load1,  queue2_to_queue1);
64727 X            v_score_q2  = vec_perm(v_score_q3,  v_score_load1,  queue3_to_queue2);
64728 X            v_score_q3  = vec_perm(v_score_q4,  v_score_load1,  queue4_to_queue3);
64729 X            v_score_q4  = vec_perm(v_score_q5,  v_score_load1,  queue5_to_queue4);
64730 X            v_score_q5  = vec_perm(v_score_q5,  v_score_load1,  queue5_with_load);
64731 X            
64732 X            
64733 X            // prefetch scores for next step
64734 X            v_score_load1 = vec_ld(16*k,query_profile_byte);
64735 X            v_score_load2 = vec_ld(16*k8,query_profile_byte);
64736 X            
64737 X            // load values of F and H from previous row (one unit up)
64738 X            Fup    = vec_ld(512, p);
64739 X            Hup1   = vec_ld(528, p);
64740 X            
64741 X            // save old values of F and H to use on next row
64742 X            vec_st(F, 0,  p);
64743 X            vec_st(H, 16, p);
64744 X            p += 32;
64745 X            
64746 X            // shift into place so we have complete F and H vectors
64747 X            // that refer to the values one unit up from each cell
64748 X            // that we are currently working on.
64749 X            Fup    = vec_sld(Fup,F,15);
64750 X            Hup1   = vec_sld(Hup1,H,15);            
64751 X            
64752 X            // do the dynamic programming 
64753 X            
64754 X            // update E value
64755 X            E   = vec_subs(E,v_gapextend);
64756 X            tmp = vec_subs(H,v_gapopen);
64757 X            E   = vec_max(E,tmp);
64758 X            
64759 X            // update F value
64760 X            F   = vec_subs(Fup,v_gapextend);
64761 X            tmp = vec_subs(Hup1,v_gapopen);
64762 X            F   = vec_max(F,tmp);
64763 X            
64764 X            v_score_load1 = vec_perm(v_score_load1,v_score_load2,merge_score_load);
64765 X            
64766 X            // add score to H
64767 X            H   = vec_adds(Hup2,v_score);
64768 X            H   = vec_subs(H,v_bias);
64769 X            
64770 X            // set H to max of H,E,F
64771 X            H   = vec_max(H,E);
64772 X            H   = vec_max(H,F);
64773 X            
64774 X            // Update highest score encountered this far
64775 X            v_maxscore = vec_max(v_maxscore,H);
64776 X            
64777 X            // STEP 14
64778 X            
64779 X            // prefetch next residue
64780 X            k                = db_sequence[j+14];
64781 X            k8               = db_sequence[j+6];
64782 X            
64783 X            v_score     = vec_perm(v_score_q1,  v_score_load1,  queue1_to_score);
64784 X            v_score_q1  = vec_perm(v_score_q2,  v_score_load1,  queue2_to_queue1);
64785 X            v_score_q2  = vec_perm(v_score_q3,  v_score_load1,  queue3_to_queue2);
64786 X            v_score_q3  = vec_perm(v_score_q4,  v_score_load1,  queue4_to_queue3);
64787 X            v_score_q4  = vec_perm(v_score_q5,  v_score_load1,  queue5_to_queue4);
64788 X            v_score_q5  = vec_perm(v_score_q5,  v_score_load1,  queue5_with_load);
64789 X            
64790 X            
64791 X            // prefetch scores for next step
64792 X            v_score_load1 = vec_ld(16*k,query_profile_byte);
64793 X            v_score_load2 = vec_ld(16*k8,query_profile_byte);
64794 X            
64795 X            // load values of F and H from previous row (one unit up)
64796 X            Fup    = vec_ld(512, p);
64797 X            Hup2   = vec_ld(528, p);
64798 X            
64799 X            // save old values of F and H to use on next row
64800 X            vec_st(F, 0,  p);
64801 X            vec_st(H, 16, p);
64802 X            p += 32;
64803 X            
64804 X            // shift into place so we have complete F and H vectors
64805 X            // that refer to the values one unit up from each cell
64806 X            // that we are currently working on.
64807 X            Fup    = vec_sld(Fup,F,15);
64808 X            Hup2   = vec_sld(Hup2,H,15);            
64809 X            
64810 X            // do the dynamic programming 
64811 X            
64812 X            // update E value
64813 X            E   = vec_subs(E,v_gapextend);
64814 X            tmp = vec_subs(H,v_gapopen);
64815 X            E   = vec_max(E,tmp);
64816 X            
64817 X            // update F value
64818 X            F   = vec_subs(Fup,v_gapextend);
64819 X            tmp = vec_subs(Hup2,v_gapopen);
64820 X            F   = vec_max(F,tmp);
64821 X            
64822 X            v_score_load1 = vec_perm(v_score_load1,v_score_load2,merge_score_load);
64823 X            
64824 X            // add score to H
64825 X            H   = vec_adds(Hup1,v_score);
64826 X            H   = vec_subs(H,v_bias);
64827 X            
64828 X            // set H to max of H,E,F
64829 X            H   = vec_max(H,E);
64830 X            H   = vec_max(H,F);
64831 X            
64832 X            // Update highest score encountered this far
64833 X            v_maxscore = vec_max(v_maxscore,H);
64834 X            
64835 X            // STEP 15
64836 X            
64837 X            // prefetch next residue
64838 X            k                = db_sequence[j+15];
64839 X            k8               = db_sequence[j+7];
64840 X            
64841 X            v_score     = vec_perm(v_score_q1,  v_score_load1,  queue1_to_score);
64842 X            v_score_q1  = vec_perm(v_score_q2,  v_score_load1,  queue2_to_queue1);
64843 X            v_score_q2  = vec_perm(v_score_q3,  v_score_load1,  queue3_to_queue2);
64844 X            v_score_q3  = vec_perm(v_score_q4,  v_score_load1,  queue4_to_queue3);
64845 X            v_score_q4  = vec_perm(v_score_q5,  v_score_load1,  queue5_to_queue4);
64846 X            v_score_q5  = vec_perm(v_score_q5,  v_score_load1,  queue5_with_load);
64847 X                        
64848 X            // prefetch scores for next step
64849 X            v_score_load1 = vec_ld(16*k,query_profile_byte);
64850 X            v_score_load2 = vec_ld(16*k8,query_profile_byte);
64851 X            
64852 X            // load values of F and H from previous row (one unit up)
64853 X            Fup    = vec_ld(512, p);
64854 X            Hup1   = vec_ld(528, p);
64855 X            
64856 X            // save old values of F and H to use on next row
64857 X            vec_st(F, 0,  p);
64858 X            vec_st(H, 16, p);
64859 X            p += 32;
64860 X            
64861 X            // shift into place so we have complete F and H vectors
64862 X            // that refer to the values one unit up from each cell
64863 X            // that we are currently working on.
64864 X            Fup    = vec_sld(Fup,F,15);
64865 X            Hup1   = vec_sld(Hup1,H,15);            
64866 X            
64867 X            // do the dynamic programming 
64868 X            
64869 X            // update E value
64870 X            E   = vec_subs(E,v_gapextend);
64871 X            tmp = vec_subs(H,v_gapopen);
64872 X            E   = vec_max(E,tmp);
64873 X            
64874 X            // update F value
64875 X            F   = vec_subs(Fup,v_gapextend);
64876 X            tmp = vec_subs(Hup1,v_gapopen);
64877 X            F   = vec_max(F,tmp);
64878 X            
64879 X            v_score_load1 = vec_perm(v_score_load1,v_score_load2,merge_score_load);
64880 X            
64881 X            // add score to H
64882 X            H   = vec_adds(Hup2,v_score);
64883 X            H   = vec_subs(H,v_bias);
64884 X            
64885 X            // set H to max of H,E,F
64886 X            H   = vec_max(H,E);
64887 X            H   = vec_max(H,F);
64888 X            
64889 X            // Update highest score encountered this far
64890 X            v_maxscore = vec_max(v_maxscore,H);
64891 X            
64892 X            // STEP 16
64893 X            
64894 X            // prefetch next residue
64895 X            k                = db_sequence[j+16];
64896 X            k8               = db_sequence[j+8];
64897 X            
64898 X            v_score     = vec_perm(v_score_q1,  v_score_load1,  queue1_to_score);
64899 X            v_score_q1  = vec_perm(v_score_q2,  v_score_load1,  queue2_to_queue1);
64900 X            v_score_q2  = vec_perm(v_score_q3,  v_score_load1,  queue3_to_queue2);
64901 X            v_score_q3  = vec_perm(v_score_q4,  v_score_load1,  queue4_to_queue3);
64902 X            v_score_q4  = vec_perm(v_score_q5,  v_score_load1,  queue5_to_queue4);
64903 X            v_score_q5  = vec_perm(v_score_q5,  v_score_load1,  queue5_with_load);
64904 X            
64905 X            
64906 X            // prefetch scores for next step
64907 X            v_score_load1 = vec_ld(16*k,query_profile_byte);
64908 X            v_score_load2 = vec_ld(16*k8,query_profile_byte);
64909 X            
64910 X            // load values of F and H from previous row (one unit up)
64911 X            Fup    = vec_ld(512, p);
64912 X            Hup2   = vec_ld(528, p);
64913 X            
64914 X            // save old values of F and H to use on next row
64915 X            vec_st(F, 0,  p);
64916 X            vec_st(H, 16, p);
64917 X            p += 32;
64918 X            
64919 X            // shift into place so we have complete F and H vectors
64920 X            // that refer to the values one unit up from each cell
64921 X            // that we are currently working on.
64922 X            Fup    = vec_sld(Fup,F,15);
64923 X            Hup2   = vec_sld(Hup2,H,15);            
64924 X            
64925 X            // do the dynamic programming 
64926 X            
64927 X            // update E value
64928 X            E   = vec_subs(E,v_gapextend);
64929 X            tmp = vec_subs(H,v_gapopen);
64930 X            E   = vec_max(E,tmp);
64931 X            
64932 X            // update F value
64933 X            F   = vec_subs(Fup,v_gapextend);
64934 X            tmp = vec_subs(Hup2,v_gapopen);
64935 X            F   = vec_max(F,tmp);
64936 X            
64937 X            v_score_load1 = vec_perm(v_score_load1,v_score_load2,merge_score_load);
64938 X            
64939 X            // add score to H
64940 X            H   = vec_adds(Hup1,v_score);
64941 X            H   = vec_subs(H,v_bias);
64942 X            
64943 X            // set H to max of H,E,F
64944 X            H   = vec_max(H,E);
64945 X            H   = vec_max(H,F);
64946 X            
64947 X            // Update highest score encountered this far
64948 X            v_maxscore = vec_max(v_maxscore,H);
64949 X            
64950 X        }
64951 X        
64952 X        for(;j<db_length+15;j++)
64953 X        {
64954 X            k8               = db_sequence[j-7];
64955 X
64956 X            v_score     = vec_perm(v_score_q1,  v_score_load1,  queue1_to_score);
64957 X            v_score_q1  = vec_perm(v_score_q2,  v_score_load1,  queue2_to_queue1);
64958 X            v_score_q2  = vec_perm(v_score_q3,  v_score_load1,  queue3_to_queue2);
64959 X            v_score_q3  = vec_perm(v_score_q4,  v_score_load1,  queue4_to_queue3);
64960 X            v_score_q4  = vec_perm(v_score_q5,  v_score_load1,  queue5_to_queue4);
64961 X            v_score_q5  = vec_perm(v_score_q5,  v_score_load1,  queue5_with_load);
64962 X            
64963 X            
64964 X            // prefetch scores for next step
64965 X            v_score_load2 = vec_ld(16*k8,query_profile_byte);
64966 X            v_score_load1 = vec_perm(v_zero,v_score_load2,merge_score_load);
64967 X
64968 X            // save old values of F and H to use on next row
64969 X            vec_st(F, 0,  p);
64970 X            vec_st(H, 16, p);
64971 X            p += 32; // move ahead 32 bytes
64972 X            
64973 X            Fup    = vec_sld(v_zero,F,15);
64974 X            Hup1   = vec_sld(v_zero,H,15);            
64975 X            
64976 X            // do the dynamic programming 
64977 X            
64978 X            // update E value
64979 X            E   = vec_subs(E,v_gapextend);
64980 X            tmp = vec_subs(H,v_gapopen);
64981 X            E   = vec_max(E,tmp);
64982 X            
64983 X            // update F value
64984 X            F   = vec_subs(Fup,v_gapextend);
64985 X            tmp = vec_subs(Hup1,v_gapopen);
64986 X            F   = vec_max(F,tmp);
64987 X            
64988 X            // add score to H
64989 X            H   = vec_adds(Hup2,v_score);
64990 X            H   = vec_subs(H,v_bias);
64991 X            
64992 X            // set H to max of H,E,F
64993 X            H   = vec_max(H,E);
64994 X            H   = vec_max(H,F);
64995 X            
64996 X            // Save value to use for next diagonal H 
64997 X            Hup2 = Hup1;
64998 X
64999 X            // Update highest score encountered this far
65000 X            v_maxscore = vec_max(v_maxscore,H);
65001 X        }
65002 X        vec_st(F, 512, p);
65003 X        vec_st(H, 528, p);
65004 X
65005 X        query_profile_byte += 16*alphabet_size;
65006 X
65007 X        // End of this row (actually 16 rows due to SIMD).
65008 X        // Before we continue, check for overflow.
65009 X        tmp      = vec_subs(vec_splat_u8(-1),v_bias);
65010 X        overflow = vec_any_ge(v_maxscore,tmp);
65011 X        
65012 X
65013 X    }
65014 X
65015 X    if(overflow)
65016 X    {
65017 X        return 255;
65018 X    }
65019 X    else
65020 X    {
65021 X        // find largest score in the v_maxscore vector
65022 X        tmp = vec_sld(v_maxscore,v_maxscore,8);
65023 X        v_maxscore = vec_max(v_maxscore,tmp);
65024 X        tmp = vec_sld(v_maxscore,v_maxscore,4);
65025 X        v_maxscore = vec_max(v_maxscore,tmp);
65026 X        tmp = vec_sld(v_maxscore,v_maxscore,2);
65027 X        v_maxscore = vec_max(v_maxscore,tmp);
65028 X        tmp = vec_sld(v_maxscore,v_maxscore,1);
65029 X        v_maxscore = vec_max(v_maxscore,tmp);
65030 X        
65031 X        // store in temporary variable
65032 X        vec_ste(v_maxscore,0,&score);
65033 X        
65034 X        // return largest score
65035 X        return score;
65036 X    }}
65037 X
65038 X
65039 #else
65040 X
65041 /* No Altivec support. Avoid compiler complaints about empty object */
65042 X
65043 int sw_dummy;
65044 X
65045 #endif
65046 SHAR_EOF
65047 chmod 0644 smith_waterman_altivec.c ||
65048 echo 'restore of smith_waterman_altivec.c failed'
65049 Wc_c="`wc -c < 'smith_waterman_altivec.c'`"
65050 test 113815 -eq "$Wc_c" ||
65051         echo 'smith_waterman_altivec.c: original size 113815, current size' "$Wc_c"
65052 fi
65053 # ============= smith_waterman_altivec.h ==============
65054 if test -f 'smith_waterman_altivec.h' -a X"$1" != X"-c"; then
65055         echo 'x - skipping smith_waterman_altivec.h (File already exists)'
65056 else
65057 echo 'x - extracting smith_waterman_altivec.h (Text)'
65058 sed 's/^X//' << 'SHAR_EOF' > 'smith_waterman_altivec.h' &&
65059 X
65060 int
65061 smith_waterman_altivec_word(const unsigned char *     query_sequence,
65062 X                            unsigned short *    query_profile_word,
65063 X                            const int                 query_length,
65064 X                            const unsigned char *     db_sequence,
65065 X                            const int                 db_length,
65066 X                            unsigned short      bias,
65067 X                            unsigned short      gap_open,
65068 X                            unsigned short      gap_extend,
65069 X                            struct f_struct *   f_str);
65070 X
65071 X
65072 int
65073 smith_waterman_altivec_byte(const unsigned char *     query_sequence,
65074 X                            unsigned char *     query_profile_byte,
65075 X                            const int                 query_length,
65076 X                            const unsigned char *     db_sequence,
65077 X                            const int                 db_length,
65078 X                            unsigned char       bias,
65079 X                            unsigned char       gap_open,
65080 X                            unsigned char       gap_extend,
65081 X                            struct f_struct *   f_str);
65082 X
65083 SHAR_EOF
65084 chmod 0644 smith_waterman_altivec.h ||
65085 echo 'restore of smith_waterman_altivec.h failed'
65086 Wc_c="`wc -c < 'smith_waterman_altivec.h'`"
65087 test 1144 -eq "$Wc_c" ||
65088         echo 'smith_waterman_altivec.h: original size 1144, current size' "$Wc_c"
65089 fi
65090 # ============= smith_waterman_sse2.c ==============
65091 if test -f 'smith_waterman_sse2.c' -a X"$1" != X"-c"; then
65092         echo 'x - skipping smith_waterman_sse2.c (File already exists)'
65093 else
65094 echo 'x - extracting smith_waterman_sse2.c (Text)'
65095 sed 's/^X//' << 'SHAR_EOF' > 'smith_waterman_sse2.c' &&
65096 /******************************************************************
65097 X  Copyright 2006 by Michael Farrar.  All rights reserved.
65098 X  This program may not be sold or incorporated into a commercial product,
65099 X  in whole or in part, without written consent of Michael Farrar.  For 
65100 X  further information regarding permission for use or reproduction, please 
65101 X  contact: Michael Farrar at farrar.michael@gmail.com.
65102 *******************************************************************/
65103 X
65104 /*
65105 X  Written by Michael Farrar, 2006.
65106 X  Please send bug reports and/or suggestions to farrar.michael@gmail.com.
65107 */
65108 X
65109 #include <stdio.h>
65110 X
65111 #include "defs.h"
65112 #include "param.h"
65113 #include "dropgsw.h"
65114 #include "smith_waterman_sse2.h"
65115 X
65116 #ifdef __SUNPRO_C
65117 #include <sunmedia_intrin.h>
65118 #else
65119 #include <emmintrin.h>
65120 #endif
65121 X
65122 #ifdef SW_SSE2
65123 X
65124 int
65125 smith_waterman_sse2_word(const unsigned char *     query_sequence,
65126 X                         unsigned short *    query_profile_word,
65127 X                         const int                 query_length,
65128 X                         const unsigned char *     db_sequence,
65129 X                         const int                 db_length,
65130 X                         unsigned short      gap_open,
65131 X                         unsigned short      gap_extend,
65132 X                         struct f_struct *   f_str)
65133 {
65134 X    int     i, j, k;
65135 X    short   score;
65136 X
65137 X    int     cmp;
65138 X    int     iter = (query_length + 7) / 8;
65139 X    
65140 X    __m128i *p;
65141 X    __m128i *workspace = (__m128i *) f_str->workspace;
65142 X
65143 X    __m128i E, F, H;
65144 X
65145 X    __m128i v_maxscore;
65146 X    __m128i v_gapopen;
65147 X    __m128i v_gapextend;
65148 X
65149 X    __m128i v_min;
65150 X    __m128i v_minimums;
65151 X    __m128i v_temp;
65152 X
65153 X    __m128i *pHLoad, *pHStore;
65154 X    __m128i *pE;
65155 X
65156 X    __m128i *pScore;
65157 X
65158 X    /* Load gap opening penalty to all elements of a constant */
65159 X    v_gapopen = _mm_insert_epi16 (v_gapopen, gap_open, 0);
65160 X    v_gapopen = _mm_shufflelo_epi16 (v_gapopen, 0);
65161 X    v_gapopen = _mm_shuffle_epi32 (v_gapopen, 0);
65162 X
65163 X    /* Load gap extension penalty to all elements of a constant */
65164 X    v_gapextend = _mm_insert_epi16 (v_gapextend, gap_extend, 0);
65165 X    v_gapextend = _mm_shufflelo_epi16 (v_gapextend, 0);
65166 X    v_gapextend = _mm_shuffle_epi32 (v_gapextend, 0);
65167 X
65168 X    /* load v_maxscore with the zeros.  since we are using signed */
65169 X    /*  math, we will bias the maxscore to -32768 so we have the */
65170 X    /*  full range of the short. */
65171 X    v_maxscore = _mm_cmpeq_epi16 (v_maxscore, v_maxscore);
65172 X    v_maxscore = _mm_slli_epi16 (v_maxscore, 15);
65173 X
65174 X    v_minimums = _mm_shuffle_epi32 (v_maxscore, 0);
65175 X
65176 X    v_min = _mm_shuffle_epi32 (v_maxscore, 0);
65177 X    v_min = _mm_srli_si128 (v_min, 14);
65178 X
65179 X    /* Zero out the storage vector */
65180 X    k = 2 * iter;
65181 X
65182 X    p = workspace;
65183 X    for (i = 0; i < k; i++)
65184 X    {
65185 X        _mm_store_si128 (p++, v_maxscore);
65186 X    }
65187 X
65188 X    pE = workspace;
65189 X    pHStore = pE + iter;
65190 X    pHLoad = pHStore + iter;
65191 X
65192 X    for (i = 0; i < db_length; ++i)
65193 X    {
65194 X        /* fetch first data asap. */
65195 X        pScore = (__m128i *) query_profile_word + db_sequence[i] * iter;
65196 X
65197 X        /* bias all elements in F to -32768 */
65198 X        F = _mm_cmpeq_epi16 (F, F);
65199 X        F = _mm_slli_epi16 (F, 15);
65200 X
65201 X        /* load the next h value */
65202 X        H = _mm_load_si128 (pHStore + iter - 1);
65203 X        H = _mm_slli_si128 (H, 2);
65204 X        H = _mm_or_si128 (H, v_min);
65205 X
65206 X        p = pHLoad;
65207 X        pHLoad = pHStore;
65208 X        pHStore = p;
65209 X
65210 X        for (j = 0; j < iter; j++)
65211 X        {
65212 X            /* load E values */
65213 X            E = _mm_load_si128 (pE + j);
65214 X
65215 X            /* add score to H */
65216 X            H = _mm_adds_epi16 (H, *pScore++);
65217 X
65218 X            /* Update highest score encountered this far */
65219 X            v_maxscore = _mm_max_epi16 (v_maxscore, H);
65220 X
65221 X            /* get max from H, E and F */
65222 X            H = _mm_max_epi16 (H, E);
65223 X            H = _mm_max_epi16 (H, F);
65224 X
65225 X            /* save H values */
65226 X            _mm_store_si128 (pHStore + j, H);
65227 X
65228 X            /* subtract the gap open penalty from H */
65229 X            H = _mm_subs_epi16 (H, v_gapopen);
65230 X
65231 X            /* update E value */
65232 X            E = _mm_subs_epi16 (E, v_gapextend);
65233 X            E = _mm_max_epi16 (E, H);
65234 X
65235 X            /* update F value */
65236 X            F = _mm_subs_epi16 (F, v_gapextend);
65237 X            F = _mm_max_epi16 (F, H);
65238 X
65239 X            /* save E values */
65240 X            _mm_store_si128 (pE + j, E);
65241 X
65242 X            /* load the next h value */
65243 X            H = _mm_load_si128 (pHLoad + j);
65244 X        }
65245 X
65246 X        /* reset pointers to the start of the saved data */
65247 X        j = 0;
65248 X        H = _mm_load_si128 (pHStore + j);
65249 X
65250 X        /*  the computed F value is for the given column.  since */
65251 X        /*  we are at the end, we need to shift the F value over */
65252 X        /*  to the next column. */
65253 X        F = _mm_slli_si128 (F, 2);
65254 X        F = _mm_or_si128 (F, v_min);
65255 X        v_temp = _mm_subs_epi16 (H, v_gapopen);
65256 X        v_temp = _mm_cmpgt_epi16 (F, v_temp);
65257 X        cmp  = _mm_movemask_epi8 (v_temp);
65258 X
65259 X        while (cmp != 0x0000) 
65260 X        {
65261 X            E = _mm_load_si128 (pE + j);
65262 X
65263 X            H = _mm_max_epi16 (H, F);
65264 X
65265 X            /* save H values */
65266 X            _mm_store_si128 (pHStore + j, H);
65267 X
65268 X            /* update E in case the new H value would change it */
65269 X            H = _mm_subs_epi16 (H, v_gapopen);
65270 X            E = _mm_max_epi16 (E, H);
65271 X            _mm_store_si128 (pE + j, E);
65272 X
65273 X            /* update F value */
65274 X            F = _mm_subs_epi16 (F, v_gapextend);
65275 X
65276 X            j++;
65277 X            if (j >= iter)
65278 X            {
65279 X                j = 0;
65280 X                F = _mm_slli_si128 (F, 2);
65281 X                F = _mm_or_si128 (F, v_min);
65282 X            }
65283 X            H = _mm_load_si128 (pHStore + j);
65284 X
65285 X            v_temp = _mm_subs_epi16 (H, v_gapopen);
65286 X            v_temp = _mm_cmpgt_epi16 (F, v_temp);
65287 X            cmp  = _mm_movemask_epi8 (v_temp);
65288 X        }
65289 X    }
65290 X
65291 X    /* find largest score in the v_maxscore vector */
65292 X    v_temp = _mm_srli_si128 (v_maxscore, 8);
65293 X    v_maxscore = _mm_max_epi16 (v_maxscore, v_temp);
65294 X    v_temp = _mm_srli_si128 (v_maxscore, 4);
65295 X    v_maxscore = _mm_max_epi16 (v_maxscore, v_temp);
65296 X    v_temp = _mm_srli_si128 (v_maxscore, 2);
65297 X    v_maxscore = _mm_max_epi16 (v_maxscore, v_temp);
65298 X
65299 X    /* extract the largest score */
65300 X    score = _mm_extract_epi16 (v_maxscore, 0);
65301 X
65302 X    /* return largest score biased by 32768 */
65303 X    return score + 32768;
65304 }
65305 X
65306 X
65307 X
65308 X
65309 int
65310 smith_waterman_sse2_byte(const unsigned char *     query_sequence,
65311 X                         unsigned char *     query_profile_byte,
65312 X                         const int                 query_length,
65313 X                         const unsigned char *     db_sequence,
65314 X                         const int                 db_length,
65315 X                         unsigned char       bias,
65316 X                         unsigned char       gap_open,
65317 X                         unsigned char       gap_extend,
65318 X                         struct f_struct *   f_str)
65319 {
65320 X    int     i, j, k;
65321 X    int     score;
65322 X
65323 X    int     dup;
65324 X    int     cmp;
65325 X    int     iter = (query_length + 15) / 16;
65326 X    
65327 X    __m128i *p;
65328 X    __m128i *workspace = (__m128i *) f_str->workspace;
65329 X
65330 X    __m128i E, F, H;
65331 X
65332 X    __m128i v_maxscore;
65333 X    __m128i v_bias;
65334 X    __m128i v_gapopen;
65335 X    __m128i v_gapextend;
65336 X
65337 X    __m128i v_temp;
65338 X    __m128i v_zero;
65339 X
65340 X    __m128i *pHLoad, *pHStore;
65341 X    __m128i *pE;
65342 X
65343 X    __m128i *pScore;
65344 X
65345 X    /* Load the bias to all elements of a constant */
65346 X    dup    = ((short) bias << 8) | bias;
65347 X    v_bias = _mm_insert_epi16 (v_bias, dup, 0);
65348 X    v_bias = _mm_shufflelo_epi16 (v_bias, 0);
65349 X    v_bias = _mm_shuffle_epi32 (v_bias, 0);
65350 X
65351 X    /* Load gap opening penalty to all elements of a constant */
65352 X    dup  = ((short) gap_open << 8) | gap_open;
65353 X    v_gapopen = _mm_insert_epi16 (v_gapopen, dup, 0);
65354 X    v_gapopen = _mm_shufflelo_epi16 (v_gapopen, 0);
65355 X    v_gapopen = _mm_shuffle_epi32 (v_gapopen, 0);
65356 X
65357 X    /* Load gap extension penalty to all elements of a constant */
65358 X    dup  = ((short) gap_extend << 8) | gap_extend;
65359 X    v_gapextend = _mm_insert_epi16 (v_gapextend, dup, 0);
65360 X    v_gapextend = _mm_shufflelo_epi16 (v_gapextend, 0);
65361 X    v_gapextend = _mm_shuffle_epi32 (v_gapextend, 0);
65362 X
65363 X    /* initialize the max score */
65364 X    v_maxscore = _mm_xor_si128 (v_maxscore, v_maxscore);
65365 X
65366 X    /* create a constant of all zeros for comparison */
65367 X    v_zero = _mm_xor_si128 (v_zero, v_zero);
65368 X
65369 X    /* Zero out the storage vector */
65370 X    k = iter * 2;
65371 X
65372 X    p = workspace;
65373 X    for (i = 0; i < k; i++)
65374 X    {
65375 X        _mm_store_si128 (p++, v_maxscore);
65376 X    }
65377 X
65378 X    pE = workspace;
65379 X    pHStore = pE + iter;
65380 X    pHLoad = pHStore + iter;
65381 X
65382 X    for (i = 0; i < db_length; ++i)
65383 X    {
65384 X        /* fetch first data asap. */
65385 X        pScore = (__m128i *) query_profile_byte + db_sequence[i] * iter;
65386 X
65387 X        /* zero out F value. */
65388 X        F = _mm_xor_si128 (F, F);
65389 X
65390 X        /* load the next h value */
65391 X        H = _mm_load_si128 (pHStore + iter - 1);
65392 X        H = _mm_slli_si128 (H, 1);
65393 X
65394 X        p = pHLoad;
65395 X        pHLoad = pHStore;
65396 X        pHStore = p;
65397 X
65398 X        for (j = 0; j < iter; j++)
65399 X        {
65400 X            /* load values E. */
65401 X            E = _mm_load_si128 (pE + j);
65402 X
65403 X            /* add score to H */
65404 X            H = _mm_adds_epu8 (H, *pScore++);
65405 X            H = _mm_subs_epu8 (H, v_bias);
65406 X
65407 X            /* Update highest score encountered this far */
65408 X            v_maxscore = _mm_max_epu8 (v_maxscore, H);
65409 X
65410 X            /* get max from H, E and F */
65411 X            H = _mm_max_epu8 (H, E);
65412 X            H = _mm_max_epu8 (H, F);
65413 X
65414 X            /* save H values */
65415 X            _mm_store_si128 (pHStore + j, H);
65416 X
65417 X            /* subtract the gap open penalty from H */
65418 X            H = _mm_subs_epu8 (H, v_gapopen);
65419 X
65420 X            /* update E value */
65421 X            E = _mm_subs_epu8 (E, v_gapextend);
65422 X            E = _mm_max_epu8 (E, H);
65423 X
65424 X            /* update F value */
65425 X            F = _mm_subs_epu8 (F, v_gapextend);
65426 X            F = _mm_max_epu8 (F, H);
65427 X
65428 X            /* save E values */
65429 X            _mm_store_si128 (pE + j, E);
65430 X
65431 X            /* load the next h value */
65432 X            H = _mm_load_si128 (pHLoad + j);
65433 X        }
65434 X
65435 X        /* reset pointers to the start of the saved data */
65436 X        j = 0;
65437 X        H = _mm_load_si128 (pHStore + j);
65438 X
65439 X        /*  the computed F value is for the given column.  since */
65440 X        /*  we are at the end, we need to shift the F value over */
65441 X        /*  to the next column. */
65442 X        F = _mm_slli_si128 (F, 1);
65443 X        v_temp = _mm_subs_epu8 (H, v_gapopen);
65444 X        v_temp = _mm_subs_epu8 (F, v_temp);
65445 X        v_temp = _mm_cmpeq_epi8 (v_temp, v_zero);
65446 X        cmp  = _mm_movemask_epi8 (v_temp);
65447 X
65448 X        while (cmp != 0xffff) 
65449 X        {
65450 X            E = _mm_load_si128 (pE + j);
65451 X
65452 X            H = _mm_max_epu8 (H, F);
65453 X
65454 X            /* save H values */
65455 X            _mm_store_si128 (pHStore + j, H);
65456 X
65457 X            /* update E in case the new H value would change it */
65458 X            H = _mm_subs_epu8 (H, v_gapopen);
65459 X            E = _mm_max_epu8 (E, H);
65460 X            _mm_store_si128 (pE + j, E);
65461 X
65462 X            /* update F value */
65463 X            F = _mm_subs_epu8 (F, v_gapextend);
65464 X
65465 X            j++;
65466 X            if (j >= iter)
65467 X            {
65468 X                j = 0;
65469 X                F = _mm_slli_si128 (F, 1);
65470 X            }
65471 X            H = _mm_load_si128 (pHStore + j);
65472 X
65473 X            v_temp = _mm_subs_epu8 (H, v_gapopen);
65474 X            v_temp = _mm_subs_epu8 (F, v_temp);
65475 X            v_temp = _mm_cmpeq_epi8 (v_temp, v_zero);
65476 X            cmp  = _mm_movemask_epi8 (v_temp);
65477 X        }
65478 X    }
65479 X
65480 X    /* find largest score in the v_maxscore vector */
65481 X    v_temp = _mm_srli_si128 (v_maxscore, 8);
65482 X    v_maxscore = _mm_max_epu8 (v_maxscore, v_temp);
65483 X    v_temp = _mm_srli_si128 (v_maxscore, 4);
65484 X    v_maxscore = _mm_max_epu8 (v_maxscore, v_temp);
65485 X    v_temp = _mm_srli_si128 (v_maxscore, 2);
65486 X    v_maxscore = _mm_max_epu8 (v_maxscore, v_temp);
65487 X    v_temp = _mm_srli_si128 (v_maxscore, 1);
65488 X    v_maxscore = _mm_max_epu8 (v_maxscore, v_temp);
65489 X
65490 X    /* store in temporary variable */
65491 X    score = _mm_extract_epi16 (v_maxscore, 0);
65492 X    score = score & 0x00ff;
65493 X
65494 X    /*  check if we might have overflowed */
65495 X    if (score + bias >= 255)
65496 X    {
65497 X        score = 255;
65498 X    }
65499 X
65500 X    /* return largest score */
65501 X    return score;
65502 }
65503 #else
65504 X
65505 /* No SSE2 support. Avoid compiler complaints about empty object */
65506 X
65507 int sw_dummy;
65508 X
65509 #endif
65510 SHAR_EOF
65511 chmod 0644 smith_waterman_sse2.c ||
65512 echo 'restore of smith_waterman_sse2.c failed'
65513 Wc_c="`wc -c < 'smith_waterman_sse2.c'`"
65514 test 12106 -eq "$Wc_c" ||
65515         echo 'smith_waterman_sse2.c: original size 12106, current size' "$Wc_c"
65516 fi
65517 # ============= smith_waterman_sse2.h ==============
65518 if test -f 'smith_waterman_sse2.h' -a X"$1" != X"-c"; then
65519         echo 'x - skipping smith_waterman_sse2.h (File already exists)'
65520 else
65521 echo 'x - extracting smith_waterman_sse2.h (Text)'
65522 sed 's/^X//' << 'SHAR_EOF' > 'smith_waterman_sse2.h' &&
65523 /******************************************************************
65524 X  Copyright 2006 by Michael Farrar.  All rights reserved.
65525 X  This program may not be sold or incorporated into a commercial product,
65526 X  in whole or in part, without written consent of Michael Farrar.  For 
65527 X  further information regarding permission for use or reproduction, please 
65528 X  contact: Michael Farrar at farrar.michael@gmail.com.
65529 *******************************************************************/
65530 X
65531 /*
65532 X  Written by Michael Farrar, 2006.
65533 X  Please send bug reports and/or suggestions to farrar.michael@gmail.com.
65534 */
65535 X
65536 #ifndef SMITH_WATERMAN_SSE2_H
65537 #define SMITH_WATERMAN_SSE2_H
65538 X
65539 int
65540 smith_waterman_sse2_word(const unsigned char *     query_sequence,
65541 X                         unsigned short *    query_profile_word,
65542 X                         const int                 query_length,
65543 X                         const unsigned char *     db_sequence,
65544 X                         const int                 db_length,
65545 X                         unsigned short      gap_open,
65546 X                         unsigned short      gap_extend,
65547 X                         struct f_struct *   f_str);
65548 X
65549 X
65550 int
65551 smith_waterman_sse2_byte(const unsigned char *     query_sequence,
65552 X                         unsigned char *     query_profile_byte,
65553 X                         const int                 query_length,
65554 X                         const unsigned char *     db_sequence,
65555 X                         const int                 db_length,
65556 X                         unsigned char       bias,
65557 X                         unsigned char       gap_open,
65558 X                         unsigned char       gap_extend,
65559 X                         struct f_struct *   f_str);
65560 X
65561 #endif /* SMITH_WATERMAN_SSE2_H */
65562 SHAR_EOF
65563 chmod 0755 smith_waterman_sse2.h ||
65564 echo 'restore of smith_waterman_sse2.h failed'
65565 Wc_c="`wc -c < 'smith_waterman_sse2.h'`"
65566 test 1723 -eq "$Wc_c" ||
65567         echo 'smith_waterman_sse2.h: original size 1723, current size' "$Wc_c"
65568 fi
65569 # ============= structs.h ==============
65570 if test -f 'structs.h' -a X"$1" != X"-c"; then
65571         echo 'x - skipping structs.h (File already exists)'
65572 else
65573 echo 'x - extracting structs.h (Text)'
65574 sed 's/^X//' << 'SHAR_EOF' > 'structs.h' &&
65575 X
65576 /* $Name: fa_34_26_5 $ - $Id: structs.h,v 1.36 2006/06/22 02:35:05 wrp Exp $ */
65577 X
65578 #include "aln_structs.h"
65579 X
65580 struct hist_str {
65581 X  int histflg;
65582 X  int *hist_a;
65583 X  int histint, min_hist, max_hist, maxh;
65584 X  long entries;
65585 X  int z_calls;
65586 X  char stat_info[MAX_STR];
65587 };
65588 X
65589 struct db_str {
65590 X  long entries;
65591 X  unsigned long length;
65592 X  int carry;
65593 };
65594 X
65595 struct mngmsg           /* Message from host to manager */
65596 {
65597 X  int n0;              /* Integer returned by hgetseq */
65598 X  int nm0;             /* number of segments */
65599 X  int nmoff;           /* length of fastf segment */
65600 X  unsigned char *aa0a; /* annotation array */
65601 X  char ann_arr[MAX_FN];        /* annotation characters */
65602 X  int ann_flg;         /* have annotation array, characters */
65603 X  char tname[MAX_FN];  /* Query sequence name */
65604 X  int tnamesize;       /* Query name size */
65605 X  int qsfnum[10];
65606 X  int nqsfnum;
65607 X  int qsfnum_n[10];
65608 X  int nqsfnum_n;
65609 X  char lname[MAX_FN];  /* Library  file  name */
65610 X  char *lbnames[MAX_LF]; /* list of library files */
65611 X  struct lmf_str *lb_mfd[MAX_LF];      /* list of opened file pointers */
65612 X
65613 X  int max_tot;         /* function defined total sequence area */
65614 X  int maxn;            /* longest library sequence chunk */
65615 X  int dupn;            /* overlap to use when segmenting sequence (p_comp) */
65616 X  int qoff;            /* overlap when segmenting long query sequence */
65617 X  int loff;            /* overlap when segmenting long library sequences */
65618 X  int maxt3;           /* overlap for tranlated sequences */
65619 X  int qdnaseq;         /* query is protein (0)/dna (1) */
65620 X  int ldnaseq;         /* library is protein (0)/dna (1) */
65621 X  int qframe;          /* number of possible query frames */
65622 X  int nframe;          /* frame for TFASTA */
65623 X  int nitt1;           /* nframe-1 */
65624 X  int thr_fact;                /* fudge factor for threads */
65625 X  int s_int;           /* sampling interval for statistics */
65626 X  int ql_start;                /* starting query sequence */
65627 X  int ql_stop;         /* ending query sequence */
65628 X  int nln;             /* number of library names */
65629 X  int pbuf_siz;                /* buffer size for sequences send in p2_complib */
65630 X  char qtitle[MAX_FN]; /* query title */
65631 X  char ltitle[MAX_FN]; /* library title */
65632 X  char flstr[MAX_FN];  /* FASTLIBS string */
65633 X  char outfile[MAX_FN];
65634 X  char label [MAXLN];  /* Output label */
65635 X  char f_id0[4];       /* function id for markx==10 */
65636 X  char f_id1[4];       /* function id for markx==10 */
65637 X  char sqnam[4];       /* "aa" or "nt" */ 
65638 X  char sqtype[10];     /* "DNA" or "protein" */
65639 X  int long_info;       /* long description flag*/
65640 X  long sq0off, sq1off; /* offset into aa0, aa1 */
65641 X  int markx;           /* alignment display type */
65642 X  int seqnm;           /* query sequence number */
65643 X  int nbr_seq;         /* number of library sequences */
65644 X  int term_code;       /* add termination codes to proteins if absent */
65645 X  int n1_high;         /* upper limit on sequence length */
65646 X  int n1_low;          /* lower limit on sequence length */
65647 X  double e_cut;                /* e_value for display */
65648 X  double e_low;                /* e_value for display */
65649 X  int e_cut_set;       /* e_value deliberately set */
65650 X  int pamd1;           /* 1st dimension of pam matrix */
65651 X  int pamd2;           /* 2nd dimension of pam matrix */
65652 X  int revcomp;         /* flag to do reverse complement */
65653 X  int quiet;           /* quiet option */
65654 X  int nrelv;           /* number of interesting scores */
65655 X  int srelv;           /* number of scores to show in showbest */
65656 X  int arelv;           /* number of scores to show at alignment */
65657 X  int z_bits;          /* z_bits==1: show bit score, ==0 show z-score */
65658 X  char alab[3][24];    /* labels for alignment scores */
65659 X  int nohist;          /* no histogram option */
65660 X  int nshow;
65661 X  int mshow;           /* number of scores to show */
65662 X  int mshow_flg;
65663 X  int ashow;           /* number of alignments to show */
65664 X  int nmlen;           /* length of name label */
65665 X  int show_code;       /* show alignment code in -m 9;  ==1 => identity only, ==2 alignment code*/
65666 X  int self;            /* self comparison */
65667 X  int thold;           /* threshold */
65668 X  int last_calc_flg;   /* needs a last calculation stage */
65669 X  int qshuffle;        /* shuffle the query and do additional comparisons */
65670 X  int shuff_max;       /* number of shuffles to perform */
65671 X  int shuff_node;      /* number of shuffles/worker node */
65672 X  int shuff_wid;
65673 X  int stages;          /* number of stages */
65674 X  double Lambda, K, H; /* Karlin-Altschul parameters */
65675 X  int escore_flg;      /* use escore calculated by do_work() */
65676 X  struct hist_str hist;
65677 X  struct db_str db;
65678 X  void *pstat_void;
65679 X  struct a_struct aln; /* has llen, llnctx, llnctx_flg, showall */
65680 X  struct a_res_str a_res; /* has individual alignment coordinates */
65681 X  char dfile [MAX_FN]; /* file for dumping scores to */
65682 };
65683 X
65684 X
65685 SHAR_EOF
65686 chmod 0644 structs.h ||
65687 echo 'restore of structs.h failed'
65688 Wc_c="`wc -c < 'structs.h'`"
65689 test 4279 -eq "$Wc_c" ||
65690         echo 'structs.h: original size 4279, current size' "$Wc_c"
65691 fi
65692 # ============= tatstats.c ==============
65693 if test -f 'tatstats.c' -a X"$1" != X"-c"; then
65694         echo 'x - skipping tatstats.c (File already exists)'
65695 else
65696 echo 'x - extracting tatstats.c (Text)'
65697 sed 's/^X//' << 'SHAR_EOF' > 'tatstats.c' &&
65698 #include <stdlib.h>
65699 #include <stdio.h>
65700 #include <math.h>
65701 #include <string.h>
65702 X
65703 #include "defs.h"
65704 #include "param.h"
65705 #include "tatstats.h"
65706 X
65707 #ifndef PCOMPLIB
65708 #include "mw.h"
65709 #else
65710 #include "p_mw.h"
65711 #endif
65712 X
65713 /* calc_priors() - calculate frequencies of amino-acids, possibly with counts */
65714 /* generate_tatprobs() - build the table of score probabilities if the
65715 X   sequences are not too long */
65716 X
65717 double
65718 det(double a11, double a12, double a13,
65719 X    double a21, double a22, double a23,
65720 X    double a31, double a32, double a33);
65721 X
65722 double power(double r, int p)
65723 {
65724 X  double tr;
65725 X  int neg;
65726 X
65727 X  if (r==0.0) return(p==0?1.0:0.0);
65728 X  if (neg = p<0) p = -p;
65729 X  tr = 1.0;
65730 X  while (p>0) {
65731 X    if (p & 1) tr *= r;
65732 X    p >>= 1;
65733 X    if (p) r *= r;
65734 X  }
65735 X  return((neg? 1.0/tr: tr));
65736 }
65737 X
65738 double
65739 factorial (int a, int b) {
65740 X
65741 X  double res = 1.0;
65742 X
65743 X  if(a == 0) { return 1.0; }
65744 X
65745 X  while(a > b) {
65746 X    res *= (double) a;
65747 X    a--;
65748 X  }
65749 X
65750 X  return res;
65751 }
65752 X
65753 void
65754 calc_priors(double *priors,
65755 X           struct pstruct *ppst,
65756 X           struct f_struct *f_str,
65757 X           const unsigned char *aa1, int n1,
65758 X           int pseudocts)
65759 {
65760 X  long counts[25], sum;
65761 X  int i;
65762 X
65763 X  if(n1 == 0 && f_str->priors[1] > 0.0) {
65764 X    for(i = 1 ; i <= ppst->nsq ; i++) {
65765 X      priors[i] = f_str->priors[i];
65766 X    }
65767 X    return;
65768 X  }
65769 X
65770 X  if(n1 == 0) {
65771 X    if (ppst->dnaseq==SEQT_PROT ) {
65772 X
65773 X      /* Robinson & Robinson residue counts from Stephen Altschul */
65774 X      counts[ 1] = 35155;    /*   A  */
65775 X      counts[ 2] = 23105;    /*   R  */  
65776 X      counts[ 3] = 20212;    /*   N  */  
65777 X      counts[ 4] = 24161;    /*   D  */  
65778 X      counts[ 5] =  8669;    /*   C  */  
65779 X      counts[ 6] = 19208;    /*   Q  */  
65780 X      counts[ 7] = 28354;    /*   E  */  
65781 X      counts[ 8] = 33229;    /*   G  */  
65782 X      counts[ 9] =  9906;    /*   H  */  
65783 X      counts[10] = 23161;    /*   I  */  
65784 X      counts[11] = 40625;    /*   L  */  
65785 X      counts[12] = 25872;    /*   K  */  
65786 X      counts[13] = 10101;    /*   M  */  
65787 X      counts[14] = 17367;    /*   F  */  
65788 X      counts[15] = 23435;    /*   P  */  
65789 X      counts[16] = 32070;    /*   S  */  
65790 X      counts[17] = 26311;    /*   T  */  
65791 X      counts[18] =  5990;    /*   W  */  
65792 X      counts[19] = 14488;    /*   Y  */  
65793 X      counts[20] = 29012;    /*   V  */  
65794 X      counts[21] =     0;    /*   B  */  
65795 X      counts[22] =     0;    /*   Z  */  
65796 X      counts[23] =     0;    /*   X   */ 
65797 X      counts[24] =     0;    /*   *   */
65798 X    }
65799 X    else { /* SEQT_DNA */
65800 X      counts[1] = 250;
65801 X      counts[2] = 250;
65802 X      counts[3] = 250;
65803 X      counts[4] = 250;
65804 X      for (i=5; i<=ppst->nsq; i++) counts[i]=0;
65805 X    }
65806 X  } else {
65807 X    memset(&counts[0], 0, sizeof(counts));
65808 X
65809 X    for(i = 0 ; i < n1 ; i++) {
65810 X      if(aa1[i] > ppst->nsq || aa1[i] < 1) continue;
65811 X      counts[aa1[i]]++;
65812 X    }
65813 X  }
65814 X
65815 X  sum = 0;
65816 X  for(i = 1 ; i <= ppst->nsq ; i++) sum += counts[i];
65817 X  
65818 X  for(i = 1 ; i <= ppst->nsq ; i++) {
65819 X    if(n1 == 0) {
65820 X      priors[i] = (double) counts[i] / (double) sum;
65821 X    } else {
65822 X      priors[i] = ( ((double) pseudocts * f_str->priors[i]) + (double) counts[i] ) / ( (double) sum + (double) pseudocts );
65823 X    }
65824 X  }
65825 X
65826 X  return;
65827
65828 X
65829 int
65830 max_score(int *scores, int nsq) {
65831 X
65832 X  int max, i;
65833 X
65834 X  max = -BIGNUM;
65835 X  for ( i = 1 ; i <= nsq ; i++ ) {
65836 X    if (scores[i] > max) max = scores[i];
65837 X  }
65838
65839 X  return max;
65840 }
65841 X
65842 int
65843 min_score(int *scores, int nsq) {
65844 X
65845 X  int min, i;
65846 X
65847 X  min = BIGNUM;
65848 X  for (i = 1 ; i <= nsq ; i++ ) {
65849 X    if (scores[i] < min) min = scores[i];
65850 X  }
65851 X
65852 X  return min;
65853 }
65854 X
65855 double
65856 calc_tatusov ( struct slink *last,
65857 X              struct slink *this,
65858 X              const unsigned char *aa0, int n0,
65859 X              const unsigned char *aa1, int n1,
65860 X              int **pam2, int nsq,
65861 X              struct f_struct *f_str,
65862 X              int pseudocts,
65863 X              int do_opt,
65864 X              int zsflag
65865 X              )
65866 {
65867 X  int i, is, j, k;
65868 X
65869 X  double *priors, my_priors[MAXSQ], tatprob, left_tatprob, right_tatprob;
65870 X  unsigned char *query = NULL;
65871 X  int length, maxlength, sumlength, sumscore, tmp, seg;
65872 X  int start, stop;
65873 X  struct slink *sl;
65874 X  int N;
65875 X  double *tatprobsptr;
65876 X
65877 #if defined(FASTS) || defined(FASTM)
65878 X  int index = 0;
65879 X  int notokay = 0;
65880 #endif
65881 X
65882 X  struct tat_str *oldtat = NULL, *newtat = NULL;
65883 X
65884 #if defined(FASTS) || defined(FASTM)
65885 X  start = this->vp->start - this->vp->dp + f_str->noff;
65886 X  stop = this->vp->stop - this->vp->dp + f_str->noff;
65887 X  tmp = stop - start + 1;
65888 #else
65889 X  /*
65890 X    FASTF alignments can also hang off the end of library sequences,
65891 X    but no query residues are used up in the process, but we have to
65892 X    keep track of which are
65893 X  */
65894 X  tmp = 0;
65895 X  for(i = 0, j = 0 ; i < n0 ; i++) {
65896 X    if (this->vp->used[i] == 1) {tmp++; }
65897 X  }
65898 #endif
65899 X
65900 X  sumlength = maxlength = length = tmp;
65901 X  seg = 1;
65902 X  sumscore = this->vp->score;
65903 X
65904 #if defined(FASTS) || defined(FASTM)
65905 X  if(f_str->aa0b[start] == start && f_str->aa0e[stop] == stop) {
65906 X    index |= (1 << f_str->aa0i[start]);
65907 X  } else {
65908 X    notokay |= (1 << f_str->aa0i[start]);
65909 X  }
65910 #endif
65911 X
65912 X  for(sl = last; sl != NULL ; sl = sl->prev) {
65913 X
65914 #if defined(FASTS) || defined(FASTM)
65915 X    start = sl->vp->start - sl->vp->dp + f_str->noff;
65916 X    stop = sl->vp->stop - sl->vp->dp + f_str->noff;
65917 X    tmp = stop - start + 1;
65918 #else
65919 X    tmp = 0;
65920 X    for(i = 0, j = 0 ; i < n0 ; i++) {
65921 X      if(sl->vp->used[i] == 1) {
65922 X       tmp++;
65923 X      }
65924 X    }
65925 #endif
65926 X    sumlength += tmp;
65927 X    maxlength = tmp > maxlength ? tmp : maxlength;
65928 X    seg++;
65929 X    sumscore += sl->vp->score;
65930 X
65931 #if defined(FASTS) || defined(FASTM)
65932 X    if(f_str->aa0b[start] == start && f_str->aa0e[stop] == stop) {
65933 X      index |= (1 << f_str->aa0i[start]);
65934 X    } else {
65935 X      notokay |= (1 << f_str->aa0i[start]);
65936 X    }
65937 #endif
65938 X
65939 X  }
65940 X
65941 X  tatprob = -1.0; 
65942 X    
65943 #if defined(FASTS) || defined(FASTM)
65944 X
65945 X  /* for T?FASTS, we try to use what we've precalculated: */
65946 X
65947 X  /* with z = 3, do_opt is true, but we can use precalculated - with
65948 X     all other z's we can use precalculated only if !do_opt */
65949 X  if(!notokay && f_str->tatprobs != NULL) {
65950 X    /* create our own newtat and copy f_str's tat into it */
65951 X    index--;
65952 X
65953 X    newtat = (struct tat_str *) malloc(sizeof(struct tat_str));
65954 X    if(newtat == NULL) {
65955 X      fprintf(stderr, "Couldn't calloc memory for newtat.\n");
65956 X      exit(1);
65957 X    }
65958 X    
65959 X    memcpy(newtat, f_str->tatprobs[index], sizeof(struct tat_str));
65960 X
65961 X    newtat->probs = (double *) calloc(f_str->tatprobs[index]->highscore - f_str->tatprobs[index]->lowscore + 1, sizeof(double));
65962 X    if(newtat->probs == NULL) {
65963 X      fprintf(stderr, "Coudln't calloc memory for newtat->probs.\n");
65964 X      exit(1);
65965 X    }
65966 X
65967 X    memcpy(newtat->probs, f_str->tatprobs[index]->probs,
65968 X          (f_str->tatprobs[index]->highscore - f_str->tatprobs[index]->lowscore + 1) * sizeof(double)); 
65969 X
65970 X
65971 X    tatprob = f_str->intprobs[index][sumscore - f_str->tatprobs[index]->lowscore];
65972 X
65973 X  } else { /* we need to recalculate from scratch */
65974 #endif
65975 X
65976 X    /* for T?FASTF, we're always recalculating from scratch: */
65977 X
65978 X    query = (unsigned char *) calloc(length, sizeof(unsigned char));
65979 X    if(query == NULL) {
65980 X      fprintf(stderr, "Couldn't calloc memory for query.\n");
65981 X      exit(1);
65982 X    }
65983 X    
65984 #if defined(FASTS) || defined(FASTM)
65985 X    start = this->vp->start - this->vp->dp + f_str->noff;
65986 X    for(i = 0, j = 0 ; i < length ; i++) {
65987 X      query[j++] = aa0[start + i];
65988 X    }
65989 #else
65990 X    for(i = 0, j = 0 ; i < n0 ; i++) {
65991 X      if (this->vp->used[i] == 1) {query[j++] = aa0[i];}
65992 X    }
65993 #endif
65994 X
65995 X    /*  calc_priors - not currently implemented for aa1 dependent */
65996 X    /* 
65997 X    if( (do_opt && zsflag == 2) || zsflag == 4 ) {    
65998 X      priors = &my_priors[0];
65999 X      calc_priors(priors, f_str, aa1, n1, pseudocts);
66000 X    } else {
66001 X      priors = f_str->priors;
66002 X    }
66003 X    */
66004 X
66005 X    priors = f_str->priors;
66006 X    oldtat = (last != NULL ? last->tat : NULL);
66007 X
66008 X    generate_tatprobs(query, 0, length - 1, priors, pam2, nsq, &newtat, oldtat);
66009 X
66010 X    free(query);
66011 #if defined(FASTS) || defined(FASTM)
66012 X  } /* close the FASTS-specific if-else from above */
66013 #endif
66014 X
66015 X  this->newtat = newtat;
66016 X  
66017 X  if(tatprob < 0.0) { /* hasn't been set by precalculated FASTS intprobs */
66018 X
66019 X    /* integrate probabilities >= sumscore */
66020 X    tatprobsptr = newtat->probs;
66021 X
66022 X    is = i = newtat->highscore - newtat->lowscore;
66023 X    N = sumscore - newtat->lowscore;
66024 X
66025 X    right_tatprob = 0;
66026 X    for ( ;  i >= N; i--) {
66027 X      right_tatprob += tatprobsptr[i];
66028 X    }
66029 X
66030 X    left_tatprob = tatprobsptr[0];
66031 X    for (i = 1 ; i < N ; i++ ) {
66032 X      left_tatprob += tatprobsptr[i];
66033 X    }
66034 X
66035 X    if (right_tatprob < left_tatprob) {tatprob = right_tatprob;}
66036 X    else {tatprob = 1.0 - left_tatprob;}
66037 X
66038 X    tatprob /= (right_tatprob+left_tatprob);
66039 X  }
66040 X
66041 X  if (maxlength > 0) {
66042 X    n1 += 2 * (maxlength - 1);
66043 X  }
66044 X
66045 #ifndef FASTM
66046 X  tatprob *= factorial(n1 - sumlength + seg, n1 - sumlength);
66047 #else
66048 X  tatprob *= power(n1 - sumlength,seg)/(1<<seg);
66049 #endif
66050 X
66051 X  if(tatprob > 0.01)
66052 X    tatprob = 1.0 - exp(-tatprob);
66053
66054 X  return tatprob;
66055 }
66056 X
66057 void
66058 generate_tatprobs(const unsigned char *query,
66059 X                 int begin,
66060 X                 int end,
66061 X                 double *priors,
66062 X                 int **pam2,
66063 X                 int nsq,
66064 X                 struct tat_str **tatarg,
66065 X                 struct tat_str *oldtat)
66066 {
66067 X
66068 X  int i, j, k, l, m, n, N, highscore, lowscore;
66069 X  int *lowrange = NULL, *highrange = NULL;
66070 X  double *probs = NULL, *newprobs = NULL, *priorptr, tmp;
66071 X  struct tat_str *tatprobs = NULL;
66072 X  int *pamptr, *pamptrsave;
66073 X
66074 X  if((tatprobs = (struct tat_str *) calloc(1, sizeof(struct tat_str)))==NULL) {
66075 X    fprintf(stderr, "Couldn't allocate individual tatprob struct.\n");
66076 X    exit(1);
66077 X  }
66078 X
66079 X  n = end - begin + 1;
66080 X
66081 X  if ( (lowrange = (int *) calloc(n, sizeof(int))) == NULL ) {
66082 X    fprintf(stderr, "Couldn't allocate memory for lowrange.\n");
66083 X    exit(1);
66084 X  }
66085 X  
66086 X  if ( (highrange = (int *) calloc(n, sizeof(int))) == NULL ) {
66087 X    fprintf(stderr, "Couldn't allocate memory for highrange.\n");
66088 X    exit(1);
66089 X  }
66090 X
66091 X  /* calculate the absolute highest and lowest score possible for this */
66092 X  /* segment.  Also, set the range we need to iterate over at each position */
66093 X  /* in the query: */
66094 X  if(oldtat == NULL) {
66095 X    highscore = lowscore = 0;
66096 X  } else {
66097 X    highscore = oldtat->highscore;
66098 X    lowscore = oldtat->lowscore;
66099 X  }
66100 X
66101 X  for ( i = 0 ; i < n ; i++ ) {
66102 X
66103 X    if (query[begin+i] == 0) break;
66104 X
66105 X    highscore =
66106 X      (highrange[i] = highscore + max_score(pam2[query[begin + i]], nsq));
66107 X
66108 X    lowscore =
66109 X      (lowrange[i] = lowscore + min_score(pam2[query[begin + i]], nsq));
66110 X
66111 X    /*
66112 X    fprintf(stderr, "i: %d, max: %d, min: %d, high[i]: %d, low[i]: %d, high: %d, low: %d, char: %d\n",
66113 X           i,
66114 X           max_score(pam2[query[begin + i]], nsq),
66115 X           min_score(pam2[query[begin + i]], nsq),
66116 X           highrange[i], lowrange[i],
66117 X           highscore, lowscore, query[begin + i]); 
66118 X    */
66119 X  }
66120 X
66121 X  /* allocate an array of probabilities for all possible scores */
66122 X  /* i.e. if highest score possible is 50 and lowest score possible */
66123 X  /* is -20, then there are 50 - (-20) + 1 = 71 possible different */
66124 X  /* scores (including 0): */
66125 X  N = highscore - lowscore;
66126 X  if ( (probs = (double *) calloc(N + 1, sizeof(double))) == NULL ) {
66127 X    fprintf(stderr, "Couldn't allocate probability matrix : %d.\n", N + 1);
66128 X    exit(1);
66129 X  }
66130 X
66131 X  if(oldtat == NULL) {
66132 X    /* for the first position, iterate over the only possible scores, */
66133 X    /* summing the priors for the amino acids that can yield each score. */
66134 X    pamptr = pam2[query[begin]];
66135 X    for ( i = 1 ; i <= nsq ; i++ ) {
66136 X      if(priors[i] > 0.0) {
66137 X       probs[(pamptr[i] - lowscore)] += priors[i];
66138 X      }
66139 X    }
66140 X  } else {
66141 X    /* Need to copy the data out of oldtat->probs into probs */
66142 X    memcpy( &probs[oldtat->lowscore - lowscore],
66143 X           oldtat->probs,
66144 X           (oldtat->highscore - oldtat->lowscore + 1) * sizeof(double));
66145 X  }
66146 X
66147 X  if ( (newprobs = (double *) calloc(N + 1, sizeof(double))) == NULL ) {
66148 X    fprintf(stderr, "Couldn't allocate newprobs matrix.\n");
66149 X    exit(1);
66150 X  }
66151 X
66152 X  /* now for each remaining residue in the segment ... */
66153 X  for ( i = (oldtat == NULL ? 1 : 0) ; i < n ; i++ ) {
66154 X
66155 X    pamptrsave = pam2[query[begin + i]];
66156 X
66157 X    /* ... calculate new probability distribution .... */
66158 X
66159 X    /* ... for each possible score (limited to current range) ... */
66160 X    for ( j = lowrange[i] - lowscore,
66161 X           k = highrange[i] - lowscore ;
66162 X         j <= k ;
66163 X         j++ ) {
66164 X      
66165 X      tmp = 0.0;
66166 X      pamptr = &pamptrsave[1];
66167 X      priorptr = &priors[1];
66168 X      /* ... for each of the possible alignment scores at this position ... */
66169 X      for ( l = 1 ;
66170 X           l <= nsq ;
66171 X           l++) {
66172 X
66173 X       /* make sure we don't go past highest possible score, or past
66174 X           the lowest possible score; not sure why this can happen */
66175 X       m = j - *pamptr++;
66176 X       if ( m <= N && m >= 0 ) {
66177 X         /* update the probability of getting score j: */
66178 X         tmp += probs[m] * *priorptr++;
66179 X       }
66180 X      }
66181 X      newprobs[j] += tmp;
66182 X    }
66183 X
66184 X    /* save the new set of probabilities, get rid of old; we don't
66185 X       necessarily have to copy/clear all N+1 slots, we could use
66186 X       high/low score boundaries -- not sure that's worth the
66187 X       effort. */
66188 X    memcpy(probs, newprobs, (N + 1) * sizeof(double));
66189 X    memset(newprobs, 0, (N + 1) * sizeof(double));
66190 X  }
66191 X
66192 X  free(newprobs);
66193 X  free(highrange);
66194 X  free(lowrange);
66195 X
66196 X  tatprobs->probs = probs;
66197 X  /*  tatprobs->intprobs = intprobs; */
66198 X  tatprobs->lowscore = lowscore;
66199 X  tatprobs->highscore = highscore;
66200 X
66201 X  *tatarg = tatprobs;
66202 }
66203 X
66204 SHAR_EOF
66205 chmod 0644 tatstats.c ||
66206 echo 'restore of tatstats.c failed'
66207 Wc_c="`wc -c < 'tatstats.c'`"
66208 test 12998 -eq "$Wc_c" ||
66209         echo 'tatstats.c: original size 12998, current size' "$Wc_c"
66210 fi
66211 # ============= tatstats.h ==============
66212 if test -f 'tatstats.h' -a X"$1" != X"-c"; then
66213         echo 'x - skipping tatstats.h (File already exists)'
66214 else
66215 echo 'x - extracting tatstats.h (Text)'
66216 sed 's/^X//' << 'SHAR_EOF' > 'tatstats.h' &&
66217 #ifndef MAXSQ
66218 #include "param.h"
66219 #endif
66220 X
66221 #ifndef MAXSAV
66222 #ifdef FASTS
66223 #define MAXSAV 25
66224 #else
66225 #define MAXSAV 10
66226 #endif
66227 #endif
66228 X
66229 #if defined(IBM_AIX) && defined(MAXSEG)
66230 #undef MAXSEG
66231 #endif
66232 #define MAXSEG 30
66233 X
66234 struct savestr {
66235 X  int     score;               /* pam score with segment optimization */
66236 X  int     score0;              /* pam score of best single segment */
66237 X  int     start0;              /* score from global match */
66238 X  int     dp;                  /* diagonal of match */
66239 X  int     start;               /* start of match in lib seq */
66240 X  int     stop;                 /* end of match in lib seq */
66241 X  int     exact;               /* exact match */
66242 #if defined(FASTF)
66243 X  int     *used;                /* array of positions in aa0 that were used */
66244 #endif
66245 };
66246 X
66247 struct dstruct  {       /* diagonal structure for saving current run */
66248 X   int     score;      /* hash score of current match */
66249 X   int     start;      /* start of current match */
66250 X   int     stop;       /* end of current match */
66251 X   struct savestr *dmax;   /* location in vmax[] where best score data saved */
66252 };
66253 X
66254 struct tat_str {
66255 X  double *probs;
66256 X  int lowscore;
66257 X  int highscore;
66258 };
66259 X
66260 struct f_struct {
66261 X  struct dstruct *diag;
66262 X  struct savestr *vmax;        /* best matches saved for one sequence */
66263 X  struct savestr **vptr;
66264 X  struct slink *sarr;
66265 X  struct savestr *lowmax;
66266 X  int maxsav;  /* max number of peptide alignments saved in search */
66267 X  int maxsav_w;        /* max number of peptide alignments saved in alignment */
66268 X  int shuff_cnt;
66269 X  int nsave;
66270 X  int ndo;
66271 X  int noff;
66272 X  int nm0;             /* number of fragments */
66273 #if defined(FASTS) || defined(FASTM)
66274 X  int *nmoff;          /* offset number, start */
66275 X  int *nm_u;
66276 X  int *aa0b;           /* beginning of each segment */
66277 X  int *aa0e;           /* end of each segment */
66278 X  int *aa0i;           /* index of each segment */
66279 X  int *aa0s;           /* max score of each segment */
66280 X  int *aa0l;           /* longest possible peptide match */
66281 #else
66282 X  int nmoff;           /* offset number, start */
66283 X  unsigned char *aa0;
66284 X  int aa0ix;
66285 #endif
66286 X  unsigned char *aa0t; /* temp location for peptides */
66287 X  int *aa0ti;          /* temp index for peptides */
66288 X  int hmask;                   /* hash constants */
66289 X  int *pamh1;                  /* pam based array */
66290 X  int *pamh2;                  /* pam based kfact array */
66291 #if defined(FASTS) || defined(FASTM)
66292 X  int *link, *harr, *l_end;            /* hash arrays */
66293 #else
66294 X  struct hlstr *link, *harr;            /* hash arrays */
66295 #endif
66296 X  int kshft;                   /* shift width */
66297 X  int nsav, lowscor;           /* number of saved runs, worst saved run */
66298 X  unsigned char *aa1x;         /* contains translated codons 111222333 */
66299 X  unsigned char *aa1y;         /* contains translated codons 123123123 */
66300 X  int n10;
66301 X  int *waa;
66302 X  int *res;
66303 X  int max_res;
66304 X  double *priors;
66305 #if defined(FASTS) || defined(FASTM)
66306 X  struct tat_str **tatprobs;          /* array of pointers to tat structs */
66307 X  double **intprobs;                  /* array of integrated tatprobs */
66308 #endif
66309 X  int dotat;
66310 X  double spacefactor;
66311 };
66312 X
66313 struct slink {
66314 X  int     score;
66315 X  double  tatprob;
66316 X  struct tat_str *tat;
66317 X  struct tat_str *newtat;
66318 X  struct savestr *vp;
66319 X  struct slink *next;
66320 X  struct slink *prev;
66321 };
66322 X
66323 struct segstr {
66324 X  double tatprob;
66325 X  int length;
66326 };
66327 X
66328 void generate_tatprobs(const unsigned char *query,
66329 X                      int begin,
66330 X                      int end,
66331 X                      double *priors,
66332 X                      int **pam2,
66333 X                      int nsq,
66334 X                      struct tat_str **tatarg, struct tat_str *oldtat);
66335 X
66336 double
66337 calc_tatusov ( struct slink *last,
66338 X              struct slink *this,
66339 X              const unsigned char *aa0, int n0,
66340 X              const unsigned char *aa1, int n1,
66341 X              int **pam2, int nsq,
66342 X              struct f_struct *f_str,
66343 X              int pseudocts,
66344 X              int do_opt,
66345 X              int zsflag
66346 X              );
66347 X
66348 double seg_tatprob(struct slink *start,
66349 X                  const unsigned char *aa0,
66350 X                  int n0,
66351 X                  const unsigned char *aa1,
66352 X                  int n1,
66353 X                  struct f_struct *f_str,
66354 X                  struct pstruct *ppst,
66355 X                  int do_opt);
66356 X
66357 void calc_priors(double *priors,
66358 X                struct pstruct *ppst,
66359 X                struct f_struct *f_str,
66360 X                const unsigned char *aa1,
66361 X                int n1, int pseudocts);
66362 X
66363 double factorial (int a, int b);
66364 X
66365 int max_score(int *scores, int nsq);
66366 X
66367 int min_score(int *scores, int nsq);
66368 X
66369 double calc_spacefactor(struct f_struct *f_str);
66370 X
66371 void linreg(double *lnx, double *x, double *lny,
66372 X           int n,
66373 X           double *a, double *b, double *c, int start);
66374 SHAR_EOF
66375 chmod 0644 tatstats.h ||
66376 echo 'restore of tatstats.h failed'
66377 Wc_c="`wc -c < 'tatstats.h'`"
66378 test 4126 -eq "$Wc_c" ||
66379         echo 'tatstats.h: original size 4126, current size' "$Wc_c"
66380 fi
66381 # ============= test.bat ==============
66382 if test -f 'test.bat' -a X"$1" != X"-c"; then
66383         echo 'x - skipping test.bat (File already exists)'
66384 else
66385 echo 'x - extracting test.bat (Text)'
66386 sed 's/^X//' << 'SHAR_EOF' > 'test.bat' &&
66387 rem ""
66388 rem "starting fasta34_t - protein on win32"
66389 rem ""
66390 fasta34_t -q -m 6 -Z 100000 mgstm1.aa:1-100 q > test_m1.ok2_t.html
66391 fasta34_t -S -q -z 11 -O test_m1.ok2_t_p25 -s P250 mgstm1.aa:100-218 q
66392 rem "done"
66393 rem "starting fastxy34_t"
66394 fastx34_t -m 9c -S -q mgtt2_x.seq q 1 > test_t2.xk1_t
66395 fasty34_t -S -q mgtt2_x.seq q > test_t2.yk2_t
66396 fastx34_t -m 9c -S -q -z 2 mgstm1.esq a > test_m1.xk2_tz2
66397 fasty34_t -S -q -z 2 mgstm1.esq a > test_m1.yk2_tz2
66398 rem "done"
66399 rem "starting fastxy34_t rev"
66400 fastx34_t -m 9c -q -m 5 mgstm1.rev q > test_m1.xk2r_t
66401 fasty34_t -q -m 5 -M 200-300 -z 2 mgstm1.rev q > test_m1.yk2r_tz2
66402 fasty34_t -q -m 5 -z 11 mgstm1.rev q > test_m1.yk2rz11_t
66403 rem "done"
66404 rem "starting ssearch34_t"
66405 ssearch34_t -m 9c -S -z 3 -q mgstm1.aa  q > test_m1.ss_tz3
66406 ssearch34_t -q -M 200-300 -z 2 -Z 100000 -s P250 mgstm1.aa q > test_m1.ss_t_p25
66407 rem "starting ssearch34_t"
66408 ssearch34sse2_t -m 9c -S -z 3 -q mgstm1.aa  q > test_m1.ss_tz3sse2
66409 ssearch34sse2_t -q -M 200-300 -z 2 -Z 100000 -s P250 mgstm1.aa q > test_m1.ss_t_p25sse2
66410 rem "done"
66411 rem "starting prss34"
66412 prss34_t -q -k 1000 -A mgstm1.aa xurt8c.aa  > test_m1.rss
66413 prfx34_t -q -k 1000 -A mgstm1.esq xurt8c.aa > test_m1.rfx
66414 rem "done"
66415 rem "starting fasta34_t - DNA"
66416 fasta34_t -S -q -z 2 mgstm1.seq %M 4 > test_m1.ok4_tz2
66417 fasta34_t -S -q mgstm1.rev %M 4 > test_m1.ok4r_t
66418 rem "done"
66419 rem "starting tfastxy34_t"
66420 tfastx34_t -m 9c -q -i -3 -m 6 mgstm1.aa m > test_m1.tx2_t.html
66421 tfasty34_t -q -i -3 -N 5000 mgstm1.aa m > test_m1.ty2_t
66422 rem "done"
66423 rem "starting fastf34_t"
66424 fastf34_t -q m1r.aa q > test_mf.ff_t
66425 fastf34 -q m1r.aa q > test_mf.ff_s
66426 rem "done"
66427 rem "starting tfastf34_t"
66428 tfastf34_t -q m1r.aa %m > test_mf.tf_tr
66429 rem "done"
66430 rem "starting fasts34_t"
66431 fasts34_t -q -V '*?@' ngts.aa q > test_m1.fs1_t
66432 fasts34_t -q ngt.aa q > test_m1.fs_t
66433 fasts34_t -q -n mgstm1.nts m > test_m1.nfs_t
66434 rem "done"
66435 rem "starting tfasts34_t"
66436 tfasts34_t -q n0.aa %m > test_m1.ts_r
66437 rem "done"
66438 rem "starting fasta34 - protein"
66439 fasta34 -q -z 2 mgstm1.aa q 1 > test_m1.ok1z2
66440 fasta34 -q -s P250 mgstm1.aa q > test_m1.ok2_p25 
66441 rem "done"
66442 rem "starting fastx3"
66443 fastx34 -m 9c -q mgstm1.esq q > test_m1.ok2x 
66444 rem "done"
66445 rem "starting fasty3"
66446 fasty34 -q mgstm1.esq q > test_m1.ok2y 
66447 rem "done"
66448 rem "starting fasta34 - DNA "
66449 fasta34 -m 9c -q mgstm1.seq M 4 > test_m1.ok4 
66450 rem "done"
66451 rem "starting ssearch3"
66452 ssearch34 -S -q -z 2 mgstm1.aa a > test_m1.ss_z2
66453 ssearch34 -q -s P250 mgstm1.aa a > test_m1.ss_p25 
66454 ssearch34 -S -q -s BL50  mgstm1.aa a > test_m1.ss_bl50
66455 ssearch34 -S -q -s blosum50.mat mgstm1.aa a > test_m1.ss_bl50f
66456 ssearch34sse2 -S -q -z 2 mgstm1.aa q > test_m1.ss_z2_sse2
66457 ssearch34sse2 -q -s P250 mgstm1.aa q > test_m1.ss_p25_sse2 
66458 rem "done"
66459 rem "starting tfastxy3"
66460 tfastx34 -q mgstm1.aa M > test_m1.tx2 
66461 tfasty34 -m 9c -q mgstm1.aa M > test_m1.ty2 
66462 rem "done"
66463 rem "starting fasts34"
66464 fasts34 -q -V '@?*' ngts.aa q > test_m1.fs1
66465 fasts34 -q ngt.aa q > test_m1.fs
66466 rem "done"
66467 SHAR_EOF
66468 chmod 0644 test.bat ||
66469 echo 'restore of test.bat failed'
66470 Wc_c="`wc -c < 'test.bat'`"
66471 test 2891 -eq "$Wc_c" ||
66472         echo 'test.bat: original size 2891, current size' "$Wc_c"
66473 fi
66474 # ============= test.sh ==============
66475 if test -f 'test.sh' -a X"$1" != X"-c"; then
66476         echo 'x - skipping test.sh (File already exists)'
66477 else
66478 echo 'x - extracting test.sh (Text)'
66479 sed 's/^X//' << 'SHAR_EOF' > 'test.sh' &&
66480 #!/bin/csh -f
66481 echo ""
66482 echo "starting fasta34_t - protein" `date` "on" `hostname`
66483 echo `uname -a`
66484 echo ""
66485 fasta34_t -q -m 6 -Z 100000 mgstm1.aa:1-100 q > test_m1.ok2_t.html
66486 fasta34_t -S -q -z 11 -O test_m1.ok2_t_p25 -s P250 mgstm1.aa:100-218 q
66487 echo "done"
66488 echo "starting fastxy34_t" `date`
66489 fastx34_t -m 9c -S -q mgtt2_x.seq q 1 > test_t2.xk1_t
66490 fasty34_t -S -q mgtt2_x.seq q > test_t2.yk2_t
66491 fastx34_t -m 9c -S -q -z 2 mgstm1.esq a > test_m1.xk2_tz2
66492 fasty34_t -S -q -z 2 mgstm1.esq a > test_m1.yk2_tz2
66493 echo "done"
66494 echo "starting fastxy34_t rev" `date`
66495 fastx34_t -m 9c -q -m 5 mgstm1.rev q > test_m1.xk2r_t
66496 fasty34_t -q -m 5 -M 200-300 -z 2 mgstm1.rev q > test_m1.yk2r_tz2
66497 fasty34_t -q -m 5 -z 11 mgstm1.rev q > test_m1.yk2rz11_t
66498 echo "done"
66499 echo "starting ssearch34_t" `date`
66500 ssearch34_t -m 9c -S -z 3 -q mgstm1.aa  q > test_m1.ss_tz3
66501 ssearch34_t -q -M 200-300 -z 2 -Z 100000 -s P250 mgstm1.aa q > test_m1.ss_t_p25
66502 echo "done"
66503 echo "starting prss34" `date`
66504 prss34_t -q -k 1000 -A mgstm1.aa xurt8c.aa  > test_m1.rss
66505 prfx34_t -q -k 1000 -A mgstm1.esq xurt8c.aa > test_m1.rfx
66506 echo "done"
66507 echo "starting fasta34_t - DNA" `date`
66508 fasta34_t -S -q -z 2 mgstm1.seq %RMB 4 > test_m1.ok4_tz2
66509 fasta34_t -S -q mgstm1.rev %RMB 4 > test_m1.ok4r_t
66510 echo "done"
66511 #echo "starting tfasta34_t" `date`
66512 #tfasta34_t -q mgstm1.aa %RMB > test_m1.tk2_t
66513 #echo "done"
66514 echo "starting tfastxy34_t" `date`
66515 tfastx34_t -m 9c -q -i -3 -m 6 mgstm1.aa %p > test_m1.tx2_t.html
66516 tfasty34_t -q -i -3 -N 5000 mgstm1.aa %p > test_m1.ty2_t
66517 echo "done"
66518 echo "starting fastf34_t" `date`
66519 fastf34_t -q m1r.aa q > test_mf.ff_t
66520 fastf34 -q m1r.aa q > test_mf.ff_s
66521 echo "done"
66522 echo "starting tfastf34_t" `date`
66523 tfastf34_t -q m1r.aa %r > test_mf.tf_tr
66524 echo "done"
66525 echo "starting fasts34_t" `date`
66526 fasts34_t -q -V '*?@' ngts.aa q > test_m1.fs1_t
66527 fasts34_t -q ngt.aa q > test_m1.fs_t
66528 fasts34_t -q -n mgstm1.nts m > test_m1.nfs_t
66529 echo "done"
66530 echo "starting tfasts34_t" `date`
66531 tfasts34_t -q n0.aa %r > test_m1.ts_r
66532 echo "done"
66533 echo "starting fasta34 - protein" `date`
66534 fasta34 -q -z 2 mgstm1.aa q 1 > test_m1.ok1z2
66535 fasta34 -q -s P250 mgstm1.aa q > test_m1.ok2_p25 
66536 echo "done"
66537 echo "starting fastx3" `date`
66538 fastx34 -m 9c -q mgstm1.esq q > test_m1.ok2x 
66539 echo "done"
66540 echo "starting fasty3" `date`
66541 fasty34 -q mgstm1.esq q > test_m1.ok2y 
66542 echo "done"
66543 echo "starting fasta34 - DNA " `date`
66544 fasta34 -m 9c -q mgstm1.seq %RMB 4 > test_m1.ok4 
66545 echo "done"
66546 echo "starting ssearch3" `date`
66547 ssearch34 -S -q -z 2 mgstm1.aa q > test_m1.ss_z2
66548 ssearch34 -S -q -s BL50  mgstm1.aa q > test_m1.ss_bl50
66549 ssearch34 -S -q -s blosum50.mat mgstm1.aa q > test_m1.ss_bl50f
66550 ssearch34 -q -s P250 mgstm1.aa q > test_m1.ss_p25 
66551 echo "done"
66552 #echo "starting tfasta3" `date`
66553 #tfasta34 -q mgstm1.aa %RMB > test_m1.tk2 
66554 #echo "done"
66555 echo "starting tfastxy3" `date`
66556 tfastx34 -q mgstm1.aa %RMB > test_m1.tx2 
66557 tfasty34 -m 9c -q mgstm1.aa %RMB > test_m1.ty2 
66558 echo "done"
66559 echo "starting fasts34" `date`
66560 fasts34 -q -V '@?*' ngts.aa q > test_m1.fs1
66561 fasts34 -q ngt.aa q > test_m1.fs
66562 echo "done" `date`
66563 SHAR_EOF
66564 chmod 0755 test.sh ||
66565 echo 'restore of test.sh failed'
66566 Wc_c="`wc -c < 'test.sh'`"
66567 test 2996 -eq "$Wc_c" ||
66568         echo 'test.sh: original size 2996, current size' "$Wc_c"
66569 fi
66570 # ============= test2.bat ==============
66571 if test -f 'test2.bat' -a X"$1" != X"-c"; then
66572         echo 'x - skipping test2.bat (File already exists)'
66573 else
66574 echo 'x - extracting test2.bat (Text)'
66575 sed 's/^X//' << 'SHAR_EOF' > 'test2.bat' &&
66576 rem ""
66577 rem "starting fasta34_t - protein on win32"
66578 rem ""
66579 fasta34_t -q -m 6 -Z 100000 mgstm1.aa:1-100 q > test_m1.ok2_t.html
66580 fasta34_t -S -q -z 11 -O test_m1.ok2_t_p25 -s P250 mgstm1.aa:100-218 q
66581 rem "done"
66582 rem "starting fastxy34_t"
66583 fastx34_t -m 9c -S -q mgtt2_x.seq q 1 > test_t2.xk1_t
66584 fasty34_t -S -q mgtt2_x.seq q > test_t2.yk2_t
66585 fastx34_t -m 9c -S -q -z 2 mgstm1.esq a > test_m1.xk2_tz2
66586 fasty34_t -S -q -z 2 mgstm1.esq a > test_m1.yk2_tz2
66587 rem "done"
66588 rem "starting fastxy34_t rev"
66589 fastx34_t -m 9c -q -m 5 mgstm1.rev q > test_m1.xk2r_t
66590 fasty34_t -q -m 5 -M 200-300 -z 2 mgstm1.rev q > test_m1.yk2r_tz2
66591 fasty34_t -q -m 5 -z 11 mgstm1.rev q > test_m1.yk2rz11_t
66592 rem "done"
66593 rem "starting ssearch34_t"
66594 ssearch34_t -m 9c -S -z 3 -q mgstm1.aa  q > test_m1.ss_tz3
66595 ssearch34_t -q -M 200-300 -z 2 -Z 100000 -s P250 mgstm1.aa q > test_m1.ss_t_p25
66596 rem "starting ssearch34_t"
66597 ssearch34sse2_t -m 9c -S -z 3 -q mgstm1.aa  q > test_m1.ss_tz3sse2
66598 ssearch34sse2_t -q -M 200-300 -z 2 -Z 100000 -s P250 mgstm1.aa q > test_m1.ss_t_p25sse2
66599 rem "done"
66600 rem "starting prss34"
66601 prss34_t -q -k 1000 -A mgstm1.aa xurt8c.aa  > test_m1.rss
66602 prfx34_t -q -k 1000 -A mgstm1.esq xurt8c.aa > test_m1.rfx
66603 rem "done"
66604 rem "starting fasta34_t - DNA"
66605 fasta34_t -S -q -z 2 mgstm1.seq %M 4 > test_m1.ok4_tz2
66606 fasta34_t -S -q mgstm1.rev %M 4 > test_m1.ok4r_t
66607 rem "done"
66608 rem "starting tfastxy34_t"
66609 tfastx34_t -m 9c -q -i -3 -m 6 mgstm1.aa %p > test_m1.tx2_t.html
66610 tfasty34_t -q -i -3 -N 5000 mgstm1.aa %p > test_m1.ty2_t
66611 rem "done"
66612 rem "starting fastf34_t"
66613 fastf34_t -q m1r.aa q > test_mf.ff_t
66614 fastf34 -q m1r.aa q > test_mf.ff_s
66615 rem "done"
66616 rem "starting tfastf34_t"
66617 tfastf34_t -q m1r.aa %r > test_mf.tf_tr
66618 rem "done"
66619 rem "starting fasts34_t"
66620 fasts34_t -q -V '*?@' ngts.aa q > test_m1.fs1_t
66621 fasts34_t -q ngt.aa q > test_m1.fs_t
66622 fasts34_t -q -n mgstm1.nts m > test_m1.nfs_t
66623 rem "done"
66624 rem "starting tfasts34_t"
66625 tfasts34_t -q n0.aa %r > test_m1.ts_r
66626 rem "done"
66627 rem "starting fasta34 - protein"
66628 fasta34 -q -z 2 mgstm1.aa q 1 > test_m1.ok1z2
66629 fasta34 -q -s P250 mgstm1.aa q > test_m1.ok2_p25 
66630 rem "done"
66631 rem "starting fastx3"
66632 fastx34 -m 9c -q mgstm1.esq q > test_m1.ok2x 
66633 rem "done"
66634 rem "starting fasty3"
66635 fasty34 -q mgstm1.esq q > test_m1.ok2y 
66636 rem "done"
66637 rem "starting fasta34 - DNA "
66638 fasta34 -m 9c -q mgstm1.seq M 4 > test_m1.ok4 
66639 rem "done"
66640 rem "starting ssearch3"
66641 ssearch34 -S -q -z 2 mgstm1.aa q > test_m1.ss_z2
66642 ssearch34 -q -s P250 mgstm1.aa q > test_m1.ss_p25 
66643 ssearch34sse2 -S -q -z 2 mgstm1.aa q > test_m1.ss_z2_sse2
66644 ssearch34sse2 -q -s P250 mgstm1.aa q > test_m1.ss_p25_sse2 
66645 rem "done"
66646 rem "starting tfastxy3"
66647 tfastx34 -q mgstm1.aa M > test_m1.tx2 
66648 tfasty34 -m 9c -q mgstm1.aa M > test_m1.ty2 
66649 rem "done"
66650 rem "starting fasts34"
66651 fasts34 -q -V '@?*' ngts.aa q > test_m1.fs1
66652 fasts34 -q ngt.aa q > test_m1.fs
66653 rem "done"
66654 SHAR_EOF
66655 chmod 0755 test2.bat ||
66656 echo 'restore of test2.bat failed'
66657 Wc_c="`wc -c < 'test2.bat'`"
66658 test 2775 -eq "$Wc_c" ||
66659         echo 'test2.bat: original size 2775, current size' "$Wc_c"
66660 fi
66661 # ============= test_osx.sh ==============
66662 if test -f 'test_osx.sh' -a X"$1" != X"-c"; then
66663         echo 'x - skipping test_osx.sh (File already exists)'
66664 else
66665 echo 'x - extracting test_osx.sh (Text)'
66666 sed 's/^X//' << 'SHAR_EOF' > 'test_osx.sh' &&
66667 #!/bin/csh -f
66668 echo ""
66669 echo "starting fasta34_t - protein" `date` "on" `hostname`
66670 echo `uname -a`
66671 echo ""
66672 fasta34_t -q -m 6 -Z 100000 mgstm1.aa:1-100 q > test_m1.ok2_t.html
66673 fasta34_t -S -q -z 11 -O test_m1.ok2_t_p25 -s P250 mgstm1.aa:100-218 q
66674 echo "done"
66675 echo "starting fastxy34_t" `date`
66676 fastx34_t -m 9 -S -q mgtt2_x.seq q > test_t2.xk2_t
66677 fasty34_t -S -q mgtt2_x.seq q > test_t2.yk2_t
66678 fastx34_t -m 9 -S -q -z 2 mgstm1.esq a > test_m1.xk2_tz2
66679 fasty34_t -S -q -z 2 mgstm1.esq a > test_m1.yk2_tz2
66680 echo "done"
66681 echo "starting fastxy34_t rev" `date`
66682 fastx34_t -m 9 -q -m 5 mgstm1.rev q > test_m1.xk2r_t
66683 fasty34_t -q -m 5 -M 200-300 -z 2 mgstm1.rev q > test_m1.yk2r_tz2
66684 fasty34_t -q -m 5 -z 11 mgstm1.rev q > test_m1.yk2rz11_t
66685 echo "done"
66686 echo "starting ssearch34_t" `date`
66687 ssearch34_t -m 9 -S -z 3 -q mgstm1.aa  q > test_m1.ss_tz3
66688 ssearch34_t -q -M 200-300 -z 2 -Z 100000 -s P250 mgstm1.aa q > test_m1.ss_t_p25
66689 echo "done"
66690 echo "starting fasta34_t - DNA" `date`
66691 fasta34_t -q -z 2 mgstm1.seq %M 4 > test_m1.ok4_tz2
66692 fasta34_t -q mgstm1.rev %M 4 > test_m1.ok4r_t
66693 echo "done"
66694 echo "starting tfasta34_t" `date`
66695 tfasta34_t -q mgstm1.aa %M > test_m1.tk2_t
66696 echo "done"
66697 echo "starting tfastxy34_t" `date`
66698 tfastx34_t -m 9 -q -i -3 -m 6 mgstm1.aa %m > test_m1.tx2_t.html
66699 tfasty34_t -q -3 -N 5000 mgstm1.aa %m > test_m1.ty2_t
66700 echo "done"
66701 echo "starting fastf34_t" `date`
66702 fastf34_t -q m1r.aa q > test_mf.ff_s
66703 echo "done"
66704 echo "starting tfastf34_t" `date`
66705 tfastf34_t -q m1r.aa %m > test_mf.tf_r
66706 echo "done"
66707 echo "starting fasts34_t" `date`
66708 fasts34_t -q n0.aa q > test_m1.fs_s
66709 echo "done"
66710 echo "starting tfasts34_t" `date`
66711 tfasts34_t -q n0.aa %m > test_m1.ts_r
66712 echo "done"
66713 echo "starting fasta34 - protein" `date`
66714 fasta34 -q -z 2 mgstm1.aa q > test_m1.ok2z2
66715 fasta34 -q -s P250 mgstm1.aa q > test_m1.ok2_p25 
66716 echo "done"
66717 echo "starting fastx3" `date`
66718 fastx34 -m 9 -q mgstm1.esq q > test_m1.ok2x 
66719 echo "done"
66720 echo "starting fasty3" `date`
66721 fasty34 -q mgstm1.esq q > test_m1.ok2y 
66722 echo "done"
66723 echo "starting fasta34 - DNA " `date`
66724 fasta34 -m 9 -q mgstm1.seq %m 4 > test_m1.ok4 
66725 echo "done"
66726 echo "starting ssearch3" `date`
66727 ssearch34 -S -q -z 2 mgstm1.aa q > test_m1.ss_z2
66728 ssearch34 -q -s P250 mgstm1.aa q > test_m1.ss_p25 
66729 echo "done"
66730 echo "starting tfasta3" `date`
66731 tfasta34 -q mgstm1.aa %m > test_m1.tk2 
66732 echo "done"
66733 echo "starting tfastxy3" `date`
66734 tfastx34 -q mgstm1.aa %m > test_m1.tx2 
66735 tfasty34 -m 9 -q mgstm1.aa %m > test_m1.ty2 
66736 echo "done" `date`
66737 SHAR_EOF
66738 chmod 0755 test_osx.sh ||
66739 echo 'restore of test_osx.sh failed'
66740 Wc_c="`wc -c < 'test_osx.sh'`"
66741 test 2429 -eq "$Wc_c" ||
66742         echo 'test_osx.sh: original size 2429, current size' "$Wc_c"
66743 fi
66744 # ============= test_s.sh ==============
66745 if test -f 'test_s.sh' -a X"$1" != X"-c"; then
66746         echo 'x - skipping test_s.sh (File already exists)'
66747 else
66748 echo 'x - extracting test_s.sh (Text)'
66749 sed 's/^X//' << 'SHAR_EOF' > 'test_s.sh' &&
66750 #!/bin/csh -f
66751 echo ""
66752 echo "starting fasta34 - protein" `date` "on" `hostname`
66753 echo `uname -a`
66754 echo ""
66755 fasta34 -q -m 6 -Z 100000 mgstm1.aa:1-100 q > test_m1.ok2.html
66756 fasta34 -S -q -z 11 -O test_m1.ok2_p25 -s P250 mgstm1.aa:100-218 q
66757 echo "done"
66758 echo "starting fastxy34" `date`
66759 fastx34 -m 9 -S -q mgtt2_x.seq q > test_t2.xk2
66760 fasty34 -S -q mgtt2_x.seq q > test_t2.yk2
66761 fastx34 -m 9 -S -q -z 2 mgstm1.esq a > test_m1.xk2z2
66762 fasty34 -S -q -z 2 mgstm1.esq a > test_m1.yk2z2
66763 echo "done"
66764 echo "starting fastxy34 rev" `date`
66765 fastx34 -m 9 -q -m 5 mgstm1.rev q > test_m1.xk2r
66766 fasty34 -q -m 5 -M 200-300 -z 2 mgstm1.rev q > test_m1.yk2rz2
66767 fasty34 -q -m 5 -z 11 mgstm1.rev q > test_m1.yk2rz11
66768 echo "done"
66769 echo "starting ssearch34" `date`
66770 ssearch34 -m 9 -S -z 3 -q mgstm1.aa  q > test_m1.ssz3
66771 ssearch34 -q -M 200-300 -z 2 -Z 100000 -s P250 mgstm1.aa q > test_m1.ss_p25
66772 echo "done"
66773 echo "starting fasta34 - DNA" `date`
66774 fasta34 -q -z 2 mgstm1.seq %RMB 4 > test_m1.ok4z2
66775 fasta34 -q mgstm1.rev %RMB 4 > test_m1.ok4r
66776 echo "done"
66777 echo "starting tfasta34" `date`
66778 tfasta34 -q mgstm1.aa %RMB > test_m1.tk2
66779 echo "done"
66780 echo "starting tfastxy34" `date`
66781 tfastx34 -m 9 -q -i -3 -m 6 mgstm1.aa %p > test_m1.tx2.html
66782 tfasty34 -q -i -3 -N 5000 mgstm1.aa %p > test_m1.ty2
66783 echo "done"
66784 echo "starting fastf34" `date`
66785 fastf34 -q m1r.aa q > test_mf.ff_s
66786 echo "done"
66787 echo "starting tfastf34" `date`
66788 tfastf34 -q -E 0.0001 m1r.aa %r > test_mf.tf_r
66789 echo "done"
66790 echo "starting fasts34" `date`
66791 fasts34 -q n0.aa q > test_m1.fs_s
66792 echo "done"
66793 echo "starting tfasts34" `date`
66794 tfasts34 -q n0.aa %r > test_m1.ts_r
66795 echo "done"
66796 echo "done" `date`
66797 SHAR_EOF
66798 chmod 0755 test_s.sh ||
66799 echo 'restore of test_s.sh failed'
66800 Wc_c="`wc -c < 'test_s.sh'`"
66801 test 1597 -eq "$Wc_c" ||
66802         echo 'test_s.sh: original size 1597, current size' "$Wc_c"
66803 fi
66804 # ============= test_z.sh ==============
66805 if test -f 'test_z.sh' -a X"$1" != X"-c"; then
66806         echo 'x - skipping test_z.sh (File already exists)'
66807 else
66808 echo 'x - extracting test_z.sh (Text)'
66809 sed 's/^X//' << 'SHAR_EOF' > 'test_z.sh' &&
66810 #!/bin/csh -f
66811 echo "starting fasta34_t - protein" `date`
66812 foreach z ( 1 2 3 6 11 )
66813 fasta34_t -q  -z $z mgstm1.aa a > test_m1_a.ok2_t_${z}
66814 fasta34_t -q  -z $z oohu.aa a > test_m1_b.ok2_t_${z}
66815 fasta34_t -q -S -z $z prio_atepa.aa a > test_m1_c.ok2S_t_${z}
66816 fasta34_t -q -S -z $z h10_human.aa a > test_m1_d.ok2S_t_${z}
66817 end
66818 echo "done"
66819 echo "starting ssearch34_t" `date`
66820 foreach z ( 1 2 3 6 11 )
66821 ssearch34_t -q  -z $z mgstm1.aa a > test_m1_a.ssS_t_${z}
66822 ssearch34_t -q  -z $z oohu.aa a > test_m1_b.ssS_t_${z}
66823 ssearch34_t -q -sBL62 -S -f -11 -z $z prio_atepa.aa a > test_m1_c.ssSbl62_t_${z}
66824 ssearch34_t -q -sBL62 -S -f -11 -z $z h10_human.aa a > test_m1_d.ssSbl62_t_${z}
66825 end
66826 echo "done"
66827 echo "starting fasta34 - protein" `date`
66828 foreach z ( 1 2 3 6 11 )
66829 fasta34 -q  -z $z mgstm1.aa a > test_m1_a.ok2_${z}
66830 fasta34 -q  -z $z oohu.aa a > test_m1_b.ok2_${z}
66831 fasta34 -q -S -sBL62 -f -11 -z $z prio_atepa.aa a > test_m1_c.ok2Sbl62_${z}
66832 fasta34 -q -S -sBL62 -f -11 -z $z h10_human.aa a > test_m1_d.ok2Sbl62_${z}
66833 end
66834 echo "done"
66835 echo "starting ssearch3" `date`
66836 foreach z ( 1 2 3 6 11 )
66837 ssearch34 -q  -z $z mgstm1.aa a > test_m1_a.ssS_${z}
66838 ssearch34 -q  -z $z oohu.aa a > test_m1_b.ssS_${z}
66839 ssearch34 -q -S -z $z prio_atepa.aa a > test_m1_c.ssS_${z}
66840 ssearch34 -q -S -z $z h10_human.aa a > test_m1_d.ssS_${z}
66841 end
66842 echo "done" `date`
66843 SHAR_EOF
66844 chmod 0755 test_z.sh ||
66845 echo 'restore of test_z.sh failed'
66846 Wc_c="`wc -c < 'test_z.sh'`"
66847 test 1312 -eq "$Wc_c" ||
66848         echo 'test_z.sh: original size 1312, current size' "$Wc_c"
66849 fi
66850 # ============= tfasts3.rsp ==============
66851 if test -f 'tfasts3.rsp' -a X"$1" != X"-c"; then
66852         echo 'x - skipping tfasts3.rsp (File already exists)'
66853 else
66854 echo 'x - extracting tfasts3.rsp (Text)'
66855 sed 's/^X//' << 'SHAR_EOF' > 'tfasts3.rsp' &&
66856 compacc.obj doinit.obj showbest.obj htime.obj apam.obj scaleswt.obj karlin.obj last_tat.obj tatsttfs.obj c_dispn.obj lib_sel.obj url_subs.obj nrand.obj getopt.obj regetlib.obj lgetlib.obj ncbl2_mlib.obj
66857 SHAR_EOF
66858 chmod 0644 tfasts3.rsp ||
66859 echo 'restore of tfasts3.rsp failed'
66860 Wc_c="`wc -c < 'tfasts3.rsp'`"
66861 test 203 -eq "$Wc_c" ||
66862         echo 'tfasts3.rsp: original size 203, current size' "$Wc_c"
66863 fi
66864 # ============= thr.h ==============
66865 if test -f 'thr.h' -a X"$1" != X"-c"; then
66866         echo 'x - skipping thr.h (File already exists)'
66867 else
66868 echo 'x - extracting thr.h (Text)'
66869 sed 's/^X//' << 'SHAR_EOF' > 'thr.h' &&
66870 X
66871 /***************************************/
66872 /* thread global variable declarations */
66873 /***************************************/
66874 X
66875 /* $Name: fa_34_26_5 $ - $Id: thr.h,v 1.2 1999/12/30 01:26:59 wrp Exp $ */
66876 X
66877 #ifndef MAX_WORKERS
66878 #define MAX_WORKERS 2
66879 #endif
66880 #define NUM_WORK_BUF 2*MAX_WORKERS
66881 X
66882 #ifndef XTERNAL
66883 struct buf_head *worker_buf[NUM_WORK_BUF];  /* pointers to full buffers */
66884 struct buf_head *reader_buf[NUM_WORK_BUF];  /* pointers to empty buffers */
66885 X
66886 /* protected by worker_mutex/woker_cond_var */
66887 int worker_buf_workp, worker_buf_readp; /* indices into full-buffers ptrs */
66888 int num_worker_bufs;
66889 int reader_done;
66890 X
66891 /* protected by reader_mutex/reader_cond var */
66892 int reader_buf_workp, reader_buf_readp; /* indices into empty-buffers ptrs */
66893 int num_reader_bufs;
66894 X
66895 /* protected by start_mutex/start_cont_var */
66896 int start_thread=1;        /* start-up predicate, 0 starts */
66897 #else
66898 extern struct buf_head *worker_buf[];
66899 extern struct buf_head *reader_buf[];
66900 extern int num_worker_bufs, reader_done, num_reader_bufs;
66901 extern int worker_buf_workp, worker_buf_readp;
66902 extern int reader_buf_workp, reader_buf_readp;
66903 X
66904 extern int start_thread;
66905 #endif
66906 X
66907 SHAR_EOF
66908 chmod 0644 thr.h ||
66909 echo 'restore of thr.h failed'
66910 Wc_c="`wc -c < 'thr.h'`"
66911 test 1144 -eq "$Wc_c" ||
66912         echo 'thr.h: original size 1144, current size' "$Wc_c"
66913 fi
66914 # ============= titin_hum.aa ==============
66915 if test -f 'titin_hum.aa' -a X"$1" != X"-c"; then
66916         echo 'x - skipping titin_hum.aa (File already exists)'
66917 else
66918 echo 'x - extracting titin_hum.aa (Text)'
66919 sed 's/^X//' << 'SHAR_EOF' > 'titin_hum.aa' &&
66920 >gi|20143914|ref|NP_003310.2| titin isoform N2-B [Homo sapiens]
66921 MTTQAPTFTQPLQSVVVLEGSTATFEAHISGFPVPEVSWFRDGQVISTSTLPGVQISFSDGRAKLTIPAV
66922 TKANSGRYSLKATNGSGQATSTAELLVKAETAPPNFVQRLQSMTVRQGSQVRLQVRVTGIPTPVVKFYRD
66923 GAEIQSSLDFQISQEGDLYSLLIAEAYPEDSGTYSVNATNSVGRATSTAELLVQGEEEVPAKKTKTIVST
66924 AQISESRQTRIEKKIEAHFDARSIATVEMVIDGAAGQQLPHKTPPRIPPKPKSRSPTPPSIAAKAQLARQ
66925 QSPSPIRHSPSPVRHVRAPTPSPVRSVSPAARISTSPIRSVRSPLLMRKTQASTVATGPEVPPPWKQEGY
66926 VASSSEAEMRETTLTTSTQIRTEERWEGRYGVQEQVTISGAAGAAASVSASASYAAEAVATGAKEVKQDA
66927 DKSAAVATVVAAVDMARVREPVISAVEQTAQRTTTTAVHIQPAQEQVRKEAEKTAVTKVVVAADKAKEQE
66928 LKSRTKEVITTKQEQMHVTHEQIRKETEKTFVPKVVISAAKAKEQETRISEEITKKQKQVTQEAIMKETR
66929 KTVVPKVIVATPKVKEQDLVSRGREGITTKREQVQITQEKMRKEAEKTALSTIAVATAKAKEQETILRTR
66930 ETMATRQEQIQVTHGKVDVGKKAEAVATVVAAVDQARVREPREPGHLEESYAQQTTLEYGYKERISAAKV
66931 AEPPQRPASEPHVVPKAVKPRVIQAPSETHIKTTDQKGMHISSQIKKTTDLTTERLVHVDKRPRTASPHF
66932 TVSKISVPKTEHGYEASIAGSAIATLQKELSATSSAQKITKSVKAPTVKPSETRVRAEPTPLPQFPFADT
66933 PDTYKSEAGVEVKKEVGVSITGTTVREERFEVLHGREAKVTETARVPAPVEIPVTPPTLVSGLKNVTVIE
66934 GESVTLECHISGYPSPTVTWYREDYQIESSIDFQITFQSGIARLMIREAFAEDSGRFTCSAVNEAGTVST
66935 SCYLAVQVSEEFEKETTAVTEKFTTEEKRFVESRDVVMTDTSLTEEQAGPGEPAAPYFITKPVVQKLVEG
66936 GSVVFGCQVGGNPKPHVYWKKSGVPLTTGYRYKVSYNKQTGECKLVISMTFADDAGEYTIVVRNKHGETS
66937 ASASLLEEADYELLMKSQQEMLYQTQVTAFVQEPKVGETAPGFVYSEYEKEYEKEQALIRKKMAKDTVVV
66938 RTYVEDQEFHISSFEERLIKEIEYRIIKTTLEELLEEDGEEKMAVDISESEAVESGFDLRIKNYRILEGM
66939 GVTFHCKMSGYPLPKIAWYKDGKRIKHGERYQMDFLQDGRASLRIPVVLPEDEGIYTAFASNIKGNAICS
66940 GKLYVEPAAPLGAPTYIPTLEPVSRIRSLSPRSVSRSPIRMSPARMSPARMSPARMSPARMSPGRRLEET
66941 DESQLERLYKPVFVLKPVSFKCLEGQTARFDLKVVGRPMPETFWFHDGQQIVNDYTHKVVIKEDGTQSLI
66942 IVPATPSDSGEWTVVAQNRAGRSSISVILTVEAVEHQVKPMFVEKLKNVNIKEGSRLEMKVRATGNPNPD
66943 IVWLKNSDIIVPHKYPKIRIEGTKGEAALKIDSTVSQDSAWYTATAINKAGRDTTRCKVNVEVEFAEPEP
66944 ERKLIIPRGTYRAKEIAAPELEPLHLRYGQEQWEEGDLYDKEKQQKPFFKKKLTSLRLKRFGPAHFECRL
66945 TPIGDPTMVVEWLHDGKPLEAANRLRMINEFGYCSLDYGVAYSRDSGIITCRATNKYGTDHTSATLIVKD
66946 EKSLVEESQLPEGRKGLQRIEELERMAHEGALTGVTTDQKEKQKPDIVLYPEPVRVLEGETARFRCRVTG
66947 YPQPKVNWYLNGQLIRKSKRFRVRYDGIHYLDIVDCKSYDTGEVKVTAENPEGVIEHKVKLEIQQREDFR
66948 SVLRRAPEPRPEFHVHEPGKLQFEVQKVDRPVDTTETKEVVKLKRAERITHEKVPEESEELRSKFKRRTE
66949 EGYYEAITAVELKSRKKDESYEELLRKTKDELLHWTKELTEEEKKALAEEGKITIPTFKPDKIELSPSME
66950 APKIFERIQSQTVGQGSDAHFRVRVVGKPDPECEWYKNGVKIERSDRIYWYWPEDNVCELVIRDVTAEDS
66951 ASIMVKAINIAGETSSHAFLLVQAKQLITFTQELQDVVAKEKDTMATFECETSEPFVKVKWYKDGMEVHE
66952 GDKYRMHSDRKVHFLSILTIDTSDAEDYSCVLVEDENVKTTAKLIVEGAVVEFVKELQDIEVPESYSGEL
66953 ECIVSPENIEGKWYHNDVELKSNGKYTITSRRGRQNLTVKDVTKEDQGEYSFVIDGKKTTCKLKMKPRPI
66954 AILQGLSDQKVCEGDIVQLEVKVSLESVEGVWMKDGQEVQPSDRVHIVIDKQSHMLLIEDMTKEDAGNYS
66955 FTIPALGLSTSGRVSVYSVDVITPLKDVNVIEGTKAVLECKVSVPDVTSVKWYLNDEQIKPDDRVQAIVK
66956 GTKQRLVINRTHASDEGPYKLIVGRVETNCNLSVEKIKIIRGLRDLTCTETQNVVFEVELSHSGIDVLWN
66957 FKDKEIKPSSKYKIEAHGKIYKLTVLNMMKDDEGKYTFYAGENITSGKLTVAGGAISKPLTDQTVAESQE
66958 AVFECEVANPDSKGEWLRDGKHLPLTNNIRSESDGHKRRLIIAATKLDDIGEYTYKVATSKTSAKLKVEA
66959 VKIKKTLKNLTVTETQDAVFTVELTHPNVKGVQWIKNGVVLESNEKYAISVKGTIYSLRIKNCAIVDESV
66960 YGFRLGRLGASARLHVETVKIIKKPKDVTALENATVAFEVSVSHDTVPVKWFHKSVEIKPSDKHRLVSER
66961 KVHKLMLQNISPSDAGEYTAVVGQLECKAKLFVETLHITKTMKNIEVPETKTASFECEVSHFNVPSMWLK
66962 NGVEIEMSEKFKIVVQGKLHQLIIMNTSTEDSAEYTFVCGNDQVSATLTVTPIMITSMLKDINAEEKDTI
66963 TFEVTVNYEGISYKWLKNGVEIKSTDKCQMRTKKLTHSLNIRNVHFGDAADYTFVAGKATSTATLYVEAR
66964 HIEFRKHIKDIKVLEKKRAMFECEVSEPDITVQWMKDDQELQITDRIKIQKEKYVHRLLIPSTRMSDAGK
66965 YTVVAGGNVSTAKLFVEGRDVRIRSIKKEVQVIEKQRAVVEFEVNEDDVDAHWYKDGIEINFQVQERHKY
66966 VVERRIHRMFISETRQSDAGEYTFVAGRNRSSVTLYVNAPEPPQVLQELQPVTVQSGKPARFCAVISGRP
66967 QPKISWYKEEQLLSTGFKCKFLHDGQEYTLLLIEAFPEDAAVYTCEAKNDYGVATTSASLSVEVPEVVSP
66968 DQEMPVYPPAIITPLQDTVTSEGQPARFQCRVSGTDLKVSWYSKDKKIKPSRFFRMTQFEDTYQLEIAEA
66969 YPEDEGTYTFVASNAVGQVSSTANLSLEAPESILHERIEQEIEMEMKEFSSSFLSAEEEGLHSAELQLSK
66970 INETLELLSESPVYSTKFDSEKEGTGPIFIKEVSNADISMGDVATLSVTVIGIPKPKIQWFFNGVLLTPS
66971 ADYKFVFDGDDHSLIILFTKLEDEGEYTCMASNDYGKTICSAYLKINSKGEGHKDTETESAVAKSLEKLG
66972 GPCPPHFLKELKPIRCAQGLPAIFEYTVVGEPAPTVTWFKENKQLCTSVYYTIIHNPNGSGTFIVNDPQR
66973 EDSGLYICKAENMLGESTCAAELLVLLEDTDMTDTPCKAKSTPEAPEDFPQTPLKGPAVEALDSEQEIAT
66974 FVKDTILKAALITEENQQLSYEHIAKANELSSQLPLGAQELQSILEQDKLTPESTREFLCINGSIHFQPL
66975 KEPSPNLQLQIVQSQKTFSKEGILMPEEPETQAVLSDTEKIFPSAMSIEQINSLTVEPLKTLLAEPEGNY
66976 PQSSIEPPMHSYLTSVAEEVLSPKEKTVSDTNREQRVTLQKQEAQSALILSQSLAEGHVESLQSPDVMIS
66977 QVNYEPLVPSEHSCTEGGKILIESANPLENAGQDSAVRIEEGKSLRFPLALEEKQVLLKEEHSDNVVMPP
66978 DQIIESKREPVAIKKVQEVQGRDLLSKESLLSGIPEEQRLNLKIQICRALQAAVASEQPGLFSEWLRNIE
66979 KVEVEAVNITQEPRHIMCMYLVTSAKSVTEEVTIIIEDVDPQMANLKMELRDALCAIIYEEIDILTAEGP
66980 RIQQGAKTSLQEEMDSFSGSQKVEPITEPEVESKYLISTEEVSYFNVQSRVKYLDATPVTKGVASAVVSD
66981 EKQDESLKPSEEKEESSSESGTEEVATVKIQEAEGGLIKEDGPMIHTPLVDTVSEEGDIVHLTTSITNAK
66982 EVNWYFENKLVPSDEKFKCLQDQNTYTLVIDKVNTEDHQGEYVCEALNDSGKTATSAKLTVVKRAAPVIK
66983 RKIEPLEVALGHLAKFTCEIQSAPNVRFQWFKAGREIYESDKCSIRSSKYISSLEILRTQVVDCGEYTCK
66984 ASNEYGSVSCTATLTVTVPGGEKKVRKLLPERKPEPKEEVVLKSVLRKRPEEEEPKVEPKKLEKVKKPAV
66985 PEPPPPKPVEEVEVPTVTKRERKIPEPTKVPEIKPAIPLPAPEPKPKPEAEVKTIKPPPVEPEPTPIAAP
66986 VTVPVVGKKAEAKAPKEEAAKPKGPIKGVPKKTPSPIEAERRKLRPGSGGEKPPDEAPFTYQLKAVPLKF
66987 VKEIKDIILTESEFVGSSAIFECLVSPSTAITTWMKDGSNIRESPKHRFIADGKDRKLHIIDVQLSDAGE
66988 YTCVLRLGNKEKTSTAKLVVEELPVRFVKTLEEEVTVVKGQPLYLSCELNKERDVVWRKDGKIVVEKPGR
66989 IVPGVIGLMRALTINDADDTDAGTYTVTVENANNLECSSCVKVVEVIRDWLVKPIRDQHVKPKGTAIFAC
66990 DIAKDTPNIKWFKGYDEIPAEPNDKTEILRDGNHLYLKIKNAMPEDIAEYAVEIEGKRYPAKLTLGEREV
66991 ELLKPIEDVTIYEKESASFDAEISEADIPGQWKLKGELLRPSPTCEIKAEGGKRFLTLHKVKLDQAGEVL
66992 YQALNAITTAILTVKEIELDFAVPLKDVTVPERRQARFECVLTREANVIWSKGPDIIKSSDKFDIIADGK
66993 KHILVINDSQFDDEGVYTAEVEGKKTSARLFVTGIRLKFMSPLEDQTVKEGETATFVCELSHEKMHVVWF
66994 KNDAKLHTSRTVLISSEGKTHKLEMKEVTLDDISQIKAQVKELSSTAQLKVLEADPYFTVKLHDKTAVEK
66995 DEITLKCEVSKDVPVKWFKDGEEIVPSPKYSIKADGLRRILKIKKADLKDKGEYVCDCGTDKTKANVTVE
66996 ARLIKVEKPLYGVEVFVGETAHFEIELSEPDVHGQWKLKGQPLTASPDCEIIEDGKKHILILHNCQLGMT
66997 GEVSFQAANAKSAANLKVKELPLIFITPLSDVKVFEKDEAKFECEVSREPKTFRWLKGTQEITGDDRFEL
66998 IKDGTKHSMVIKSAAFEDEAKYMFEAEDKHTSGKLIIEGIRLKFLTPLKDVTAKEKESAVFTVELSHDNI
66999 RVKWFKNDQRLHTTRSVSMQDEGKTHSITFKDLSIDDTSQIRVEAMGMSSEAKLTVLEGDPYFTGKLQDY
67000 TGVEKDEVILQCEISKADAPVKWFKDGKEIKPSKNAVIKADGKKRMLILKKALKSDIGQYTCDCGTDKTS
67001 GKLDIEDREIKLVRPLHSVEVMETETARFETEISEDDIHANWKLKGEALLQTPDCEIKEEGKIHSLVLHN
67002 CRLDQTGGVDFQAANVKSSAHLRVKPRVIGLLRPLKDVTVTAGETATFDCELSYEDIPVEWYLKGKKLEP
67003 SDKVVPRSEGKVHTLTLRDVKLEDAGEVQLTAKDFKTHANLFVKEPPVEFTKPLEDQTVEEGATAVLECE
67004 VSRENAKVKWFKNGTEILKSKKYEIVADGRVRKLVIHDCTPEDIKTYTCDAKDFKTSCNLNVVPPHVEFL
67005 RPLTDLQVREKEMARFECELSRENAKVKWFKDGAEIKKGKKYDIISKGAVRILVINKCLLDDEAEYSCEV
67006 RTARTSGMLTVLEEEAVFTKNLANIEVSETDTIKLVCEVSKPGAEVIWYKGDEEIIETGRYEILTEGRKR
67007 ILVIQNAHLEDAGNYNCRLPSSRTDGKVKVHELAAEFISKPQNLEILEGEKAEFVCSISKESFPVQWKRD
67008 DKTLESGDKYDVIADGKKRVLVVKDATLQDMGTYVVMVGAARAAAHLTVIEKLRIVVPLKDTRVKEQQEV
67009 VFNCEVNTEGAKAKWFRNEEAIFDSSKYIILQKDLVYTLRIRDAHLDDQANYNVSLTNHRGENVKSAANL
67010 IVEEEDLRIVEPLKDIETMEKKSVTFWCKVNRLNVTLKWTKNGEEVPFDNRVSYRVDKYKHMLTIKDCGF
67011 PDEGEYIVTAGQDKSVAELLIIEAPTEFVEHLEDQTVTEFDDAVFSCQLSREKANVKWYRNGREIKEGKK
67012 YKFEKDGSIHRLIIKDCRLDDECEYACGVEDRKSRARLFVEEIPVEIIRPPQDILEAPGADVVFLAELNK
67013 DKVEVQWLRNNMVVVQGDKHQMMSEGKIHRLQICDIKPRDQGEYRFIAKDKEARAKLELAAAPKIKTADQ
67014 DLVVDVGKPLTMVVPYDAYPKAEAEWFKENEPLSTKTIDTTAEQTSFRILEAKKGDKGRYKIVLQNKHGK
67015 AEGFINLKVIDVPGPVRNLEVTETFDGEVSLAWEEPLTDGGSKIIGYVVERRDIKRKTWVLATDRAESCE
67016 FTVTGLQKGGVEYLFRVSARNRVGTGEPVETDNPVEARSKYDVPGPPLNVTITDVNRFGVSLTWEPPEYD
67017 GGAEITNYVIELRDKTSIRWDTAMTVRAEDLSATVTDVVEGQEYSFRVRAQNRIGVGKPSAATPFVKVAD
67018 PIERPSPPVNLTSSDQTQSSVQLKWEPPLKDGGSPILGYIIERCEEGKDNWIRCNMKLVPELTYKVTGLE
67019 KGNKYLYRVSAENKAGVSDPSEILGPLTADDAFVEPTMDLSAFKDGLEVIVPNPITILVPSTGYPRPTAT
67020 WCFGDKVLETGDRVKMKTLSAYAELVISPSERSDKGIYTLKLENRVKTISGEIDVNVIARPSAPKELKFG
67021 DITKDSVHLTWEPPDDDGGSPLTGYVVEKREVSRKTWTKVMDFVTDLEFTVPDLVQGKEYLFKVCARNKC
67022 GPGEPAYVDEPVNMSTPATVPDPPENVKWRDRTANSIFLTWDPPKNDGGSRIKGYIVERCPRGSDKWVAC
67023 GEPVAETKMEVTGLEEGKWYAYRVKALNRQGASKPSRPTEEIQAVDTQEAPEIFLDVKLLAGLTVKAGTK
67024 IELPATVTGKPEPKITWTKADMILKQDKRITIENVPKKSTVTIVDSKRSDTGTYIIEAVNVCGRATAVVE
67025 VNVLDKPGPPAAFDITDVTNESCLLTWNPPRDDGGSKITNYVVERRATDSEVWHKLSSTVKDTNFKATKL
67026 IPNKEYIFRVAAENMYGVGEPVQASPITAKYQFDPPGPPTRLEPSDITKDAVTLTWCEPDDDGGSPITGY
67027 WVERLDPDTDKWVRCNKMPVKDTTYRVKGLTNKKKYRFRVLAENLAGPGKPSKSTEPILIKDPIDPPWPP
67028 GKPTVKDVGKTSVRLNWTKPEHDGGAKIESYVIEMLKTGTDEWVRVAEGVPTTQHLLPGLMEGQEYSFRV
67029 RAVNKAGESEPSEPSDPVLCREKLYPPSPPRWLEVINITKNTADLKWTVPEKDGGSPITNYIVEKRDVRR
67030 KGWQTVDTTVKDTKCTVTPLTEGSLYVFRVAAENAIGQSDYTEIEDSVLAKDTFTTPGPPYALAVVDVTK
67031 RHVDLKWEPPKNDGGRPIQRYVIEKKERLGTRWVKAGKTAGPDCNFRVTDVIEGTEVQFQVRAENEAGVG
67032 HPSEPTEILSIEDPTSPPSPPLDLHVTDAGRKHIAIAWKPPEKNGGSPIIGYHVEMCPVGTEKWMRVNSR
67033 PIKDLKFKVEEGVVPDKEYVLRVRAVNAIGVSEPSEISENVVAKDPDCKPTIDLETHDIIVIEGEKLSIP
67034 VPFRAVPVPTVSWHKDGKEVKASDRLTMKNDHISAHLEVPKSVRADAGIYTITLENKLGSATASINVKVI
67035 GLPGPCKDIKASDITKSSCKLTWEPPEFDGGTPILHYVLERREAGRRTYIPVMSGENKLSWTVKDLIPNG
67036 EYFFRVKAVNKVGGGEYIELKNPVIAQDPKQPPDPPVDVEVHNPTAEAMTITWKPPLYDGGSKIMGYIIE
67037 KIAKGEERWKRCNEHLVPILTYTAKGLEEGKEYQFRVRAENAAGISEPSRATPPTKAVDPIDAPKVILRT
67038 SLEVKRGDEIALDASISGSPYPTITWIKDENVIVPEEIKKRAAPLVRRRKGEVQEEEPFVLPLTQRLSID
67039 NSKKGESQLRVRDSLRPDHGLYMIKVENDHGIAKAPCTVSVLDTPGPPINFVFEDIRKTSVLCKWEPPLD
67040 DGGSEIINYTLEKKDKTKPDSEWIVVTSTLRHCKYSVTKLIEGKEYLFRVRAENRFGPGPPCVSKPLVAK
67041 DPFGPPDAPDKPIVEDVTSNSMLVKWNEPKDNGSPILGYWLEKREVNSTHWSRVNKSLLNALKANVDGLL
67042 EGLTYVFRVCAENAAGPGKFSPPSDPKTAHDPISPPGPPIPRVTDTSSTTIELEWEPPAFNGGGEIVGYF
67043 VDKQLVGTNEWSRCTEKMIKVRQYTVKEIREGADYKLRVSAVNAAGEGPPGETQPVTVAEPQEPPAVELD
67044 VSVKGGIQIMAGKTLRIPAVVTGRPVPTKVWTKEEGELDKDRVVIDNVGTKSELIIKDALRKDHGRYVIT
67045 ATNSCGSKFAAARVEVFDVPGPVLDLKPVVTNRKMCLLNWSDPEDDGGSEITGFIIERKDAKMHTWRQPI
67046 ETERSKCDITGLLEGQEYKFRVIAKNKFGCGPPVEIGPILAVDPLGPPTSPERLTYTERTKSTITLDWKE
67047 PRSNGGSPIQGYIIEKRRHDKPDFERVNKRLCPTTSFLVENLDEHQMYEFRVKAVNEIGESEPSLPLNVV
67048 IQDDEVPPTIKLRLSVRGDTIKVKAGEPVHIPADVTGLPMPKIEWSKNETVIEKPTDALQITKEEVSRSE
67049 AKTELSIPKAVREDKGTYTVTASNRLGSVFRNVHVEVYDRPSPPRNLAVTDIKAESCYLTWDAPLDNGGS
67050 EITHYVIDKRDASRKKAEWEEVTNTAVEKRYGIWKLIPNGQYEFRVRAVNKYGISDECKSDKVVIQDPYR
67051 LPGPPGKPKVLARTKGSMLVSWTPPLDNGGSPITGYWLEKREEGSPYWSRVSRAPITKVGLKGVEFNVPR
67052 LLEGVKYQFRAMAINAAGIGPPSEPSDPEVAGDPIFPPGPPSCPEVKDKTKSSISLGWKPPAKDGGSPIK
67053 GYIVEMQEEGTTDWKRVNEPDKLITTCECVVPNLKELRKYRFRVKAVNEAGESEPSDTTGEIPATDIQEE
67054 PEVFIDIGAQDCLVCKAGSQIRIPAVIKGRPTPKSSWEFDGKAKKAMKDGVHDIPEDAQLETAENSSVII
67055 IPECKRSHTGKYSITAKNKAGQKTANCRVKVMDVPGPPKDLKVSDITRGSCRLSWKMPDDDGGDRIKGYV
67056 IEKRTIDGKAWTKVNPDCGSTTFVVPDLLSEQQYFFRVRAENRFGIGPPVETIQRTTARDPIYPPDPPIK
67057 LKIGLITKNTVHLSWKPPKNDGGSPVTHYIVECLAWDPTGTKKEAWRQCNKRDVEELQFTVEDLVEGGEY
67058 EFRVKAVNAAGVSKPSATVGPCDCQRPDMPPSIDLKEFMEVEEGTNVNIVAKIKGVPFPTLTWFKAPPKK
67059 PDNKEPVLYDTHVNKLVVDDTCTLVIPQSRRSDTGLYTITAVNNLGTASKEMRLNVLGRPGPPVGPIKFE
67060 SVSADQMTLSWFPPKDDGGSKITNYVIEKREANRKTWVHVSSEPKECTYTIPKLLEGHEYVFRIMAQNKY
67061 GIGEPLDSEPETARNLFSVPGAPDKPTVSSVTRNSMTVNWEEPEYDGGSPVTGYWLEMKDTTSKRWKRVN
67062 RDPIKAMTLGVSYKVTGLIEGSDYQFRVYAINAAGVGPASLPSDPATARDPIAPPGPPFPKVTDWTKSSA
67063 DLEWSPPLKDGGSKVTGYIVEYKEEGKEEWEKGKDKEVRGTKLVVTGLKEGAFYKFRVSAVNIAGIGEPG
67064 EVTDVIEMKDRLVSPDLQLDASVRDRIVVHAGGVIRIIAYVSGKPPPTVTWNMNERTLPQEATIETTAIS
67065 SSMVIKNCQRSHQGVYSLLAKNEAGERKKTIIVDVLDVPGPVGTPFLAHNLTNESCKLTWFSPEDDGGSP
67066 ITNYVIEKRESDRRAWTPVTYTVTRQNATVQGLIQGKAYFFRIAAENSIGMGPFVETSEALVIREPITVP
67067 ERPEDLEVKEVTKNTVTLTWNPPKYDGGSEIINYVLESRLIGTEKFHKVTNDNLLSRKYTVKGLKEGDTY
67068 EYRVSAVNIVGQGKPSFCTKPITCKDELAPPTLHLDFRDKLTIRVGEAFALTGRYSGKPKPKVSWFKDEA
67069 DVLEDDRTHIKTTPATLALEKIKAKRSDSGKYCVVVENSTGSRKGFCQVNVVDRPGPPVGPVSFDEVTKD
67070 YMVISWKPPLDDGGSKITNYIIEKKEVGKDVWMPVTSASAKTTCKVSKLLEGKDYIFRIHAENLYGISDP
67071 LVSDSMKAKDRFRVPDAPDQPIVTEVTKDSALVTWNKPHDGGKPITNYILEKRETMSKRWARVTKDPIHP
67072 YTKFRVPDLLEGCQYEFRVSAENEIGIGDPSPPSKPVFAKDPIAKPSPPVNPEAIDTTCNSVDLTWQPPR
67073 HDGGSKILGYIVEYQKVGDEEWRRANHTPESCPETKYKVTGLRDGQTYKFRVLAVNAAGESDPAHVPEPV
67074 LVKDRLEPPELILDANMAREQHIKVGDTLRLSAIIKGVPFPKVTWKKEDRDAPTKARIDVTPVGSKLEIR
67075 NAAHEDGGIYSLTVENPAGSKTVSVKVLVLDKPGPPRDLEVSEIRKDSCYLTWKEPLDDGGSVITNYVVE
67076 RRDVASAQWSPLSATSKKKSHFAKHLNEGNQYLFRVAAENQYGRGPFVETPKPIKALDPLHPPGPPKDLH
67077 HVDVDKTEVSLVWNKPDRDGGSPITGYLVEYQEEGTQDWIKFKTVTNLECVVTGLQQGKTYRFRVKAENI
67078 VGLGLPDTTIPIECQEKLVPPSVELDVKLIEGLVVKAGTTVRFPAIIRGVPVPTAKWTTDGSEIKTDEHY
67079 TVETDNFSSVLTIKNCLRRDTGEYQITVSNAAGSKTVAVHLTVLDVPGPPTGPINILDVTPEHMTISWQP
67080 PKDDGGSPVINYIVEKQDTRKDTWGVVSSGSSKTKLKIPHLQKGCEYVFRVRAENKIGVGPPLDSTPTVA
67081 KHKFSPPSPPGKPVVTDITENAATVSWTLPKSDGGSPITGYYMERREVTGKWVRVNKTPIADLKFRVTGL
67082 YEGNTYEFRVFAENLAGLSKPSPSSDPIKACRPIKPPGPPINPKLKDKSRETADLVWTKPLSDGGSPILG
67083 YVVECQKPGTAQWNRINKDELIRQCAFRVPGLIEGNEYRFRIKAANIVGEGEPRELAESVIAKDILHPPE
67084 VELDVTCRDVITVRVGQTIRILARVKGRPEPDITWTKEGKVLVREKRVDLIQDLPRVELQIKEAVRADHG
67085 KYIISAKNSSGHAQGSAIVNVLDRPGPCQNLKVTNVTKENCTISWENPLDNGGSEITNFIVEYRKPNQKG
67086 WSIVASDVTKRLIKANLLANNEYYFRVCAENKVGVGPTIETKTPILAINPIDRPGEPENLHIADKGKTFV
67087 YLKWRRPDYDGGSPNLSYHVERRLKGSDDWERVHKGSIKETHYMVDRCVENQIYEFRVQTKNEGGESDWV
67088 KTEEVVVKEDLQKPVLDLKLSGVLTVKAGDTIRLEAGVRGKPFPEVAWTKDKDATDLTRSPRVKIDTRAD
67089 SSKFSLTKAKRSDGGKYVVTATNTAGSFVAYATVNVLDKPGPVRNLKIVDVSSDRCTVCWDPPEDDGGCE
67090 IQNYILEKCETKRMVWSTYSATVLTPGTTVTRLIEGNEYIFRVRAENKIGTGPPTESKPVIAKTKYDKPG
67091 RPDPPEVTKVSKEEMTVVWNPPEYDGGKSITGYFLEKKEKHSTRWVPVNKSAIPERRMKVQNLLPDHEYQ
67092 FRVKAENEIGIGEPSLPSRPVVAKDPIEPPGPPTNFRVVDTTKHSITLGWGKPVYDGGAPIIGYVVEMRP
67093 KIADASPDEGWKRCNAAAQLVRKEFTVTSLDENQEYEFRVCAQNQVGIGRPAELKEAIKPKEILEPPEID
67094 LDASMRKLVIVRAGCPIRLFAIVRGRPAPKVTWRKVGIDNVVRKGQVDLVDTMAFLVIPNSTRDDSGKYS
67095 LTLVNPAGEKAVFVNVRVLDTPGPVSDLKVSDVTKTSCHVSWAPPENDGGSQVTHYIVEKREADRKTWST
67096 VTPEVKKTSFHVTNLVPGNEYYFRVTAVNEYGPGVPTDVPKPVLASDPLSEPDPPRKLEVTEMTKNSATL
67097 AWLPPLRDGGAKIDGYITSYREEEQPADRWTEYSVVKDLSLVVTGLKEGKKYKFRVAARNAVGVSLPREA
67098 EGVYEAKEQLLPPKILMPEQITIKAGKKLRIEAHVYGKPHPTCKWKKGEDEVVTSSHLAVHKADSSSILI
67099 IKDVTRKDSGYYSLTAENSSGTDTQKIKVVVMDAPGPPQPPFDISDIDADACSLSWHIPLEDGGSNITNY
67100 IVEKCDVSRGDWVTALASVTKTSCRVGKLIPGQEYIFRVRAENRFGISEPLTSPKMVAQFPFGVPSEPKN
67101 ARVTKVNKDCIFVAWDRPDSDGGSPIIGYLIERKERNSLLWVKANDTLVRSTEYPCAGLVEGLEYSFRIY
67102 ALNKAGSSPPSKPTEYVTARMPVDPPGKPEVIDVTKSTVSLIWARPKHDGGSKIIGYFVEACKLPGDKWV
67103 RCNTAPHQIPQEEYTATGLEEKAQYQFRAIARTAVNISPPSEPSDPVTILAENVPPRIDLSVAMKSLLTV
67104 KAGTNVCLDATVFGKPMPTVSWKKDGTLLKPAEGIKMAMQRNLCTLELFSVNRKDSGDYTITAENSSGSK
67105 SATIKLKVLDKPGPPASVKINKMYSDRAMLSWEPPLEDGGSEITNYIVDKRETSRPNWAQVSATVPITSC
67106 SVEKLIEGHEYQFRICAENKYGVGDPVFTEPAIAKNPYDPPGRCDPPVISNITKDHMTVSWKPPADDGGS
67107 PITGYLLEKRETQAVNWTKVNRKPIIERTLKATGLQEGTEYEFRVTAINKAGPGKPSDASKAAYARDPQY
67108 PPAPPAFPKVYDTTRSSVSLSWGKPAYDGGSPIIGYLVEVKRADSDNWVRCNLPQNLQKTRFEVTGLMED
67109 TQYQFRVYAVNKIGYSDPSDVPDKHYPKDILIPPEGELDADLRKTLILRAGVTMRLYVPVKGRPPPKITW
67110 SKPNVNLRDRIGLDIKSTDFDTFLRCENVNKYDAGKYILTLENSCGKKEYTIVVKVLDTPGPPVNVTVKE
67111 ISKDSAYVTWEPPIIDGGSPIINYVVQKRDAERKSWSTVTTECSKTSFRVANLEEGKSYFFRVFAENEYG
67112 IGDPGETRDAVKASQTPGPVVDLKVRSVSKSSCSIGWKKPHSDGGSRIIGYVVDFLTEENKWQRVMKSLS
67113 LQYSAKDLTEGKEYTFRVSAENENGEGTPSEITVVARDDVVAPDLDLKGLPDLCYLAKENSNFRLKIPIK
67114 GKPAPSVSWKKGEDPLATDTRVSVESSAVNTTLIVYDCQKSDAGKYTITLKNVAGTKEGTISIKVVGKPG
67115 IPTGPIKFDEVTAEAMTLKWAPPKDDGGSEITNYILEKRDSVNNKWVTCASAVQKTTFRVTRLHEGMEYT
67116 FRVSAENKYGVGEGLKSEPIVARHPFDVPDAPPPPNIVDVRHDSVSLTWTDPKKTGGSPITGYHLEFKER
67117 NSLLWKRANKTPIRMRDFKVTGLTEGLEYEFRVMAINLAGVGKPSLPSEPVVALDPIDPPGKPEVINITR
67118 NSVTLIWTEPKYDGGHKLTGYIVEKRDLPSKSWMKANHVNVPECAFTVTDLVEGGKYEFRIRAKNTAGAI
67119 SAPSESTETIICKDEYEAPTIVLDPTIKDGLTIKAGDTIVLNAISILGKPLPKSSWSKAGKDIRPSDITQ
67120 ITSTPTSSMLTIKYATRKDAGEYTITATNPFGTKVEHVKVTVLDVPGPPGPVEISNVSAEKATLTWTPPL
67121 EDGGSPIKSYILEKRETSRLLWTVVSEDIQSCRHVATKLIQGNEYIFRVSAVNHYGKGEPVQSEPVKMVD
67122 RFGPPGPPEKPEVSNVTKNTATVSWKRPVDDGGSEITGYHVERREKKSLRWVRAIKTPVSDLRCKVTGLQ
67123 EGSTYEFRVSAENRAGIGPPSEASDSVLMKDAAYPPGPPSNPHVTDTTKKSASLAWGKPHYDGGLEITGY
67124 VVEHQKVGDEAWIKDTTGTALRITQFVVPDLQTKEKYNFRISAINDAGVGEPAVIPDVEIVEREMAPDFE
67125 LDAELRRTLVVRAGLSIRIFVPIKGRPAPEVTWTKDNINLKNRANIENTESFTLLIIPECNRYDTGKFVM
67126 TIENPAGKKSGFVNVRVLDTPGPVLNLRPTDITKDSVTLHWDLPLIDGGSRITNYIVEKREATRKSYSTA
67127 TTKCHKCTYKVTGLSEGCEYFFRVMAENEYGIGEPTETTEPVKASEAPSPPDSLNIMDITKSTVSLAWPK
67128 PKHDGGSKITGYVIEAQRKGSDQWTHITTVKGLECVVRNLTEGEEYTFQVMAVNSAGRSAPRESRPVIVK
67129 EQTMLPELDLRGIYQKLVIAKAGDNIKVEIPVLGRPKPTVTWKKGDQILKQTQRVNFETTATSTILNINE
67130 CVRSDSGPYPLTARNIVGEVGDVITIQVHDIPGPPTGPIKFDEVSSDFVTFSWDPPENDGGVPISNYVVE
67131 MRQTDSTTWVELATTVIRTTYKATRLTTGLEYQFRVKAQNRYGVGPGITSACIVANYPFKVPGPPGTPQV
67132 TAVTKDSMTISWHEPLSDGGSPILGYHVERKERNGILWQTVSKALVPGNIFKSSGLTDGIAYEFRVIAEN
67133 MAGKSKPSKPSEPMLALDPIDPPGKPVPLNITRHTVTLKWAKPEYTGGFKITSYIVEKRDLPNGRWLKAN
67134 FSNILENEFTVSGLTEDAAYEFRVIAKNAAGAISPPSEPSDAITCRDDVEAPKIKVDVKFKDTVILKAGE
67135 AFRLEADVSGRPPPTMEWSKDGKELEGTAKLEIKIADFSTNLVNKDSTRRDSGAYTLTATNPGGFAKHIF
67136 NVKVLDRPGPPEGPLAVTEVTSEKCVLSWFPPLDDGGAKIDHYIVQKRETSRLAWTNVASEVQVTKLKVT
67137 KLLKGNEYIFRVMAVNKYGVGEPLESEPVLAVNPYGPPDPPKNPEVTTITKDSMVVCWGHPDSDGGSEII
67138 NYIVERRDKAGQRWIKCNKKTLTDLRYKVSGLTEGHEYEFRIMAENAAGISAPSPTSPFYKACDTVFKPG
67139 PPGNPRVLDTSRSSISIAWNKPIYDGGSEITGYMVEIALPEEDEWQIVTPPAGLKATSYTITGLTENQEY
67140 KIRIYAMNSEGLGEPALVPGTPKAEDRMLPPEIELDADLRKVVTIRACCTLRLFVPIKGRPAPEVKWARD
67141 HGESLDKASIESTSSYTLLIVGNVNRFDSGKYILTVENSSGSKSAFVNVRVLDTPGPPQDLKVKEVTKTS
67142 VTLTWDPPLLDGGSKIKNYIVEKRESTRKAYSTVATNCHKTSWKVDQLQEGCSYYFRVLAENEYGIGLPA
67143 ETAESVKASERPLPPGKITLMDVTRNSVSLSWEKPEHDGGSRILGYIVEMQTKGSDKWATCATVKVTEAT
67144 ITGLIQGEEYSFRVSAQNEKGISDPRQLSVPVIAKDLVIPPAFKLLFNTFTVLAGEDLKVDVPFIGRPTP
67145 AVTWHKDNVPLKQTTRVNAESTENNSLLTIKDACREDVGHYVVKLTNSAGEAIETLNVIVLDKPGPPTGP
67146 VKMDEVTADSITLSWGPPKYDGGSSINNYIVEKRDTSTTTWQIVSATVARTTIKACRLKTGCEYQFRIAA
67147 ENRYGKSTYLNSEPTVAQYPFKVPGPPGTPVVTLSSRDSMEVQWNEPISDGGSRVIGYHLERKERNSILW
67148 VKLNKTPIPQTKFKTTGLEEGVEYEFRVSAENIVGIGKPSKVSECYVARDPCDPPGRPEAIIVTRNSVTL
67149 QWKKPTYDGGSKITGYIVEKKELPEGRWMKASFTNIIDTHFEVTGLVEDHRYEFRVIARNAAGVFSEPSE
67150 STGAITARDEVDPPRISMDPKYKDTIVVHAGESFKVDADIYGKPIPTIQWIKGDQELSNTARLEIKSTDF
67151 ATSLSVKDAVRVDSGNYILKAKNVAGERSVTVNVKVLDRPGPPEGPVVISGVTAEKCTLAWKPPLQDGGS
67152 DIINYIVERRETSRLVWTVVDANVQTLSCKVTKLLEGNEYTFRIMAVNKYGVGEPLESEPVVAKNPFVVP
67153 DAPKAPEVTTVTKDSMIVVWERPASDGGSEILGYVLEKRDKEGIRWTRCHKRLIGELRLRVTGLIENHDY
67154 EFRVSAENAAGLSEPSPPSAYQKACDPIYKPGPPNNPKVIDITRSSVFLSWSKPIYDGGCEIQGYIVEKC
67155 DVSVGEWTMCTPPTGINKTNIEVEKLLEKHEYNFRICAINKAGVGEHADVPGPIIVEEKLEAPDIDLDLE
67156 LRKIINIRAGGSLRLFVPIKGRPTPEVKWGKVDGEIRDAAIIDVTSSFTSLVLDNVNRYDSGKYTLTLEN
67157 SSGTKSAFVTVRVLDTPSPPVNLKVTEITKDSVSITWEPPLLDGGSKIKNYIVEKREATRKSYAAVVTNC
67158 HKNSWKIDQLQEGCSYYFRVTAENEYGIGLPAQTADPIKVAEVPQPPGKITVDDVTRNSVSLSWTKPEHD
67159 GGSKIIQYIVEMQAKHSEKWSECARVKSLQAVITNLTQGEEYLFRVVAVNEKGRSDPRSLAVPIVAKDLV
67160 IEPDVKPAFSSYSVQVGQDLKIEVPISGRPKPTITWTKDGLPLKQTTRINVTDSLDLTTLSIKETHKDDG
67161 GQYGITVANVVGQKTASIEIVTLDKPDPPKGPVKFDDVSAESITLSWNPPLYTGGCQITNYIVQKRDTTT
67162 TVWDVVSATVARTTLKVTKLKTGTEYQFRIFAENRYGQSFALESDPIVAQYPYKEPGPPGTPFATAISKD
67163 SMVIQWHEPVNNGGSPVIGYHLERKERNSILWTKVNKTIIHDTQFKAQNLEEGIEYEFRVYAENIVGVGK
67164 ASKNSECYVARDPCDPPGTPEPIMVKRNEITLQWTKPVYDGGSMITGYIVEKRDLPDGRWMKASFTNVIE
67165 TQFTVSGLTEDQRYEFRVIAKNAAGAISKPSDSTGPITAKDEVELPRISMDPKFRDTIVVNAGETFRLEA
67166 DVHGKPLPTIEWLRGDKEIEESARCEIKNTDFKALLIVKDAIRIDGGQYILRASNVAGSKSFPVNVKVLD
67167 RPGPPEGPVQVTGVTSEKCSLTWSPPLQDGGSDISHYVVEKRETSRLAWTVVASEVVTNSLKVTKLLEGN
67168 EYVFRIMAVNKYGVGEPLESAPVLMKNPFVLPGPPKSLEVTNIAKDSMTVCWNRPDSDGGSEIIGYIVEK
67169 RDRSGIRWIKCNKRRITDLRLRVTGLTEDHEYEFRVSAENAAGVGEPSPATVYYKACDPVFKPGPPTNAH
67170 IVDTTKNSITLAWGKPIYDGGSEILGYVVEICKADEEEWQIVTPQTGLRVTRFEISKLTEHQEYKIRVCA
67171 LNKVGLGEATSVPGTVKPEDKLEAPELDLDSELRKGIVVRAGGSARIHIPFKGRPTPEITWSREEGEFTD
67172 KVQIEKGVNYTQLSIDNCDRNDAGKYILKLENSSGSKSAFVTVKVLDTPGPPQNLAVKEVRKDSAFLVWE
67173 PPIIDGGAKVKNYVIDKRESTRKAYANVSSKCSKTSFKVENLTEGAIYYFRVMAENEFGVGVPVETVDAV
67174 KAAEPPSPPGKVTLTDVSQTSASLMWEKPEHDGGSRVLGYVVEMQPKGTEKWSIVAESKVCNAVVTGLSS
67175 GQEYQFRVKAYNEKGKSDPRVLGVPVIAKDLTIQPSLKLPFNTYSIQAGEDLKIEIPVIGRPRPNISWVK
67176 DGEPLKQTTRVNVEETATSTVLHIKEGNKDDFGKYTVTATNSAGTATENLSVIVLEKPGPPVGPVRFDEV
67177 SADFVVISWEPPAYTGGCQISNYIVEKRDTTTTTWHMVSATVARTTIKITKLKTGTEYQFRIFAENRYGK
67178 SAPLDSKAVIVQYPFKEPGPPGTPFVTSISKDQMLVQWHEPVNDGGTKIIGYHLEQKEKNSILWVKLNKT
67179 PIQDTKFKTTGLDEGLEYEFKVSAENIVGIGKPSKVSECFVARDPCDPPGRPEAIVITRNNVTLKWKKPA
67180 YDGGSKITGYIVEKKDLPDGRWMKASFTNVLETEFTVSGLVEDQRYEFRVIARNAAGNFSEPSDSSGAIT
67181 ARDEIDAPNASLDPKYKDVIVVHAGETFVLEADIRGKPIPDVVWSKDGKELEETAARMEIKSTIQKTTLV
67182 VKDCIRTDGGQYILKLSNVGGTKSIPITVKVLDRPGPPEGPLKVTGVTAEKCYLAWNPPLQDGGANISHY
67183 IIEKRETSRLSWTQVSTEVQALNYKVTKLLPGNEYIFRVMAVNKYGIGEPLESGPVTACNPYKPPGPPST
67184 PEVSAITKDSMVVTWARPVDDGGTEIEGYILEKRDKEGVRWTKCNKKTLTDLRLRVTGLTEGHSYEFRVA
67185 AENAAGVGEPSEPSVFYRACDALYPPGPPSNPKVTDTSRSSVSLAWSKPIYDGGAPVKGYVVEVKEAAAD
67186 EWTTCTPPTGLQGKQFTVTKLKENTEYNFRICAINSEGVGEPATLPGSVVAQERIEPPEIELDADLRKVV
67187 VLRASATLRLFVTIKGRPEPEVKWEKAEGILTDRAQIEVTSSFTMLVIDNVTRFDSGRYNLTLENNSGSK
67188 TAFVNVRVLDSPSAPVNLTIREVKKDSVTLSWEPPLIDGGAKITNYIVEKRETTRKAYATITNNCTKTTF
67189 RIENLQEGCSYYFRVLASNEYGIGLPAETTEPVKVSEPPLPPGRVTLVDVTRNTATIKWEKPESDGGSKI
67190 TGYVVEMQTKGSEKWSTCTQVKTLEATISGLTAGEEYVFRVAAVNEKGRSDPRQLGVPVIARDIEIKPSV
67191 ELPFHTFNVKAREQLKIDVPFKGRPQATVNWRKDGQTLKETTRVNVSSSKTVTSLSIKEASKEDVGTYEL
67192 CVSNSAGSITVPITIIVLDRPGPPGPIRIDEVSCDSITISWNPPEYDGGCQISNYIVEKKETTSTTWHIV
67193 SQAVARTSIKIVRLTTGSEYQFRVCAENRYGKSSYSESSAVVAEYPFSPPGPPGTPKVVHATKSTMLVTW
67194 QVPVNDGGSRVIGYHLEYKERSSILWSKANKILIADTQMKVSGLDEGLMYEYRVYAENIAGIGKCSKSCE
67195 PVPARDPCDPPGQPEVTNITRKSVSLKWSKPHYDGGAKITGYIVERRELPDGRWLKCNYTNIQETYFEVT
67196 ELTEDQRYEFRVFARNAADSVSEPSESTGPIIVKDDVEPPRVMMDVKFRDVIVVKAGEVLKINADIAGRP
67197 LPVISWAKDGIEIEERARTEIISTDNHTLLTVKDCIRRDTGQYVLTLKNVAGTRSVAVNCKVLDKPGPPA
67198 GPLEINGLTAEKCSLSWGRPQEDGGADIDYYIVEKRETSHLAWTICEGELQMTSCKVTKLLKGNEYIFRV
67199 TGVNKYGVGEPLESVAIKALDPFTVPSPPTSLEITSVTKESMTLCWSRPESDGGSEISGYIIERREKNSL
67200 RWVRVNKKPVYDLRVKSTGLREGCEYEYRVYAENAAGLSLPSETSPLIRAEDPVFLPSPPSKPKIVDSGK
67201 TTITIAWVKPLFDGGAPITGYTVEYKKSDDTDWKTSIQSLRGTEYTISGLTTGAEYVFRVKSVNKVGASD
67202 PSDSSDPQIAKEREEEPLFDIDSEMRKTLIVKAGASFTMTVPFRGRPVPNVLWSKPDTDLRTRAYVDTTD
67203 SRTSLTIENANRNDSGKYTLTIQNVLSAASLTLVVKVLDTPGPPTNITVQDVTKESAVLSWDVPENDGGA
67204 PVKNYHIEKREASKKAWVSVTNNCNRLSYKVTNLQEGAIYYFRVSGENEFGVGIPAETKEGVKITEKPSP
67205 PEKLGVTSISKDSVSLTWLKPEHDGGSRIVHYVVEALEKGQKNWVKCAVAKSTHHVVSGLRENSEYFFRV
67206 FAENQAGLSDPRELLLPVLIKEQLEPPEIDMKNFPSHTVYVRAGSNLKVDIPISGKPLPKVTLSRDGVPL
67207 KATMRFNTEITAENLTINLKESVTADAGRYEITAANSSGTTKAFINIVVLDRPGPPTGPVVISDITEESV
67208 TLKWEPPKYDGGSQVTNYILLKRETSTAVWTEVSATVARTMMKVMKLTTGEEYQFRIKAENRFGISDHID
67209 SACVTVKLPYTTPGPPSTPWVTNVTRESITVGWHEPVSNGGSAVVGYHLEMKDRNSILWQKANKLVIRTT
67210 HFKVTTISAGLIYEFRVYAENAAGVGKPSHPSEPVLAIDACEPPRNVRITDISKNSVSLSWQQPAFDGGS
67211 KITGYIVERRDLPDGRWTKASFTNVTETQFIISGLTQNSQYEFRVFARNAVGSISNPSEVVGPITCIDSY
67212 GGPVIDLPLEYTEVVKYRAGTSVKLRAGISGKPAPTIEWYKDDKELQTNALVCVENTTDLASILIKDADR
67213 LNSGCYELKLRNAMGSASATIRVQILDKPGPPGGPIEFKTVTAEKITLLWRPPADDGGAKITHYIVEKRE
67214 TSRVVWSMVSEHLEECIITTTKIIKGNEYIFRVRAVNKYGIGEPLESDSVVAKNAFVTPGPPGIPEVTKI
67215 TKNSMTVVWSRPIADGGSDISGYFLEKRDKKSLGWFKVLKETIRDTRQKVTGLTENSDYQYRVCAVNAAG
67216 QGPFSEPSEFYKAADPIDPPGPPAKIRIADSTKSSITLGWSKPVYDGGSAVTGYVVEIRQGEEEEWTTVS
67217 TKGEVRTTEYVVSNLKPGVNYYFRVSAVNCAGQGEPIEMNEPVQAKDILEAPEIDLDVALRTSVIAKAGE
67218 DVQVLIPFKGRPPPTVTWRKDEKNLGSDARYSIENTDSSSLLTIPQVTRNDTGKYILTIENGVGEPKSST
67219 VSVKVLDTPAACQKLQVKHVSRGTVTLLWDPPLIDGGSPIINYVIEKRDATKRTWSVVSHKCSSTSFKLI
67220 DLSEKTPFFFRVLAENEIGIGEPCETTEPVKAAEVPAPIRDLSMKDSTKTSVILSWTKPDFDGGSVITEY
67221 VVERKGKGEQTWSHAGISKTCEIEVSQLKEQSVLEFRVFAKNEKGLSDPVTIGPITVKELIITPEVDLSD
67222 IPGAQVTVRIGHNVHLELPYKGKPKPSISWLKDGLPLKESEFVRFSKTENKITLSIKNAKKEHGGKYTVI
67223 LDNAVCRIAVPITVITLGPPSKPKGPIRFDEIKADSVILSWDVPEDNGGGEITCYSIEKRETSQTNWRMV
67224 CSSVARTTFKVPNLVKDAEYQFRVRAENRYGVSQPLVSSIIVAKHQFRIPGPPGKPVIYNVTSDGMSLTW
67225 DAPVYDGGSEVTGFHVEKKERNSILWQKVNTSPISGREYRATGLVEGLDYQFRVYAENSAGLSSPSDPSK
67226 FTLAVSPVDPPGTPDYIDVTRETITLKWNPPLRDGGSKIVGYSIEKRQGNERWVRCNFTDVSECQYTVTG
67227 LSPGDRYEFRIIARNAVGTISPPSQSSGIIMTRDENVPPIVEFGPEYFDGLIIKSGESLRIKALVQGRPV
67228 PRVTWFKDGVEIEKRMNMEITDVLGSTSLFVRDATRDHRGVYTVEAKNASGSAKAEIKVKVQDTPGKVVG
67229 PIRFTNITGEKMTLWWDAPLNDGCAPITHYIIEKRETSRLAWALIEDKCEAQSYTAIKLINGNEYQFRVS
67230 AVNKFGVGRPLDSDPVVAQIQYTVPDAPGIPEPSNITGNSITLTWARPESDGGSEIQQYILERREKKSTR
67231 WVKVISKRPISETRFKVTGLTEGNEYEFHVMAENAAGVGPASGISRLIKCREPVNPPGPPTVVKVTDTSK
67232 TTVSLEWSKPVFDGGMEIIGYIIEMCKADLGDWHKVNAEACVKTRYTVTDLQAGEEYKFRVSAINGAGKG
67233 DSCEVTGTIKAVDRLTAPELDIDANFKQTHVVRAGASIRLFIAYQGRPTPTAVWSKPDSNLSLRADIHTT
67234 DSFSTLTVENCNRNDAGKYTLTVENNSGSKSITFTVKVLDTPGPPGPITFKDVTRGSATLMWDAPLLDGG
67235 ARIHHYVVEKREASRRSWQVISEKCTRQIFKVNDLAEGVPYYFRVSAVNEYGVGEPYEMPEPIVATEQPA
67236 PPRRLDVVDTSKSSAVLAWLKPDHDGGSRITGYLLEMRQKGSDFWVEAGHTKQLTFTVERLVEKTEYEFR
67237 VKAKNDAGYSEPREAFSSVIIKEPQIEPTADLTGITNQLITCKAGSPFTIDVPISGRPAPKVTWKLEEMR
67238 LKETDRVSITTTKDRTTLTVKDSMRGDSGRYFLTLENTAGVKTFSVTVVVIGRPGPVTGPIEVSSVSAES
67239 CVLSWGEPKDGGGTEITNYIVEKRESGTTAWQLVNSSVKRTQIKVTHLTKYMEYSFRVSSENRFGVSKPL
67240 ESAPIIAEHPFVPPSAPTRPEVYHVSANAMSIRWEEPYHDGGSKIIGYWVEKKERNTILWVKENKVPCLE
67241 CNYKVTGLVEGLEYQFRTYALNAAGVSKASEASRPIMAQNPVDAPGRPEVTDVTRSTVSLIWSAPAYDGG
67242 SKVVGYIIERKPVSEVGDGRWLKCNYTIVSDNFFTVTALSEGDTYEFRVLAKNAAGVISKGSESTGPVTC
67243 RDEYAPPKAELDARLHGDLVTIRAGSDLVLDAAVGGKPEPKIIWTKGDKELDLCEKVSLQYTGKRATAVI
67244 KFCDRSDSGKYTLTVKNASGTKAVSVMVKVLDSPGPCGKLTVSRVTQEKCTLAWSLPQEDGGAEITHYIV
67245 ERRETSRLNWVIVEGECPTLSYVVTRLIKNNEYIFRVRAVNKYGPGVPVESEPIVARNSFTIPSPPGIPE
67246 EVGTGKEHIIIQWTKPESDGGNEISNYLVDKREKKSLRWTRVNKDYVVYDTRLKVTSLMEGCDYQFRVTA
67247 VNAAGNSEPSEASNFISCREPSYTPGPPSAPRVVDTTKHSISLAWTKPMYDGGTDIVGYVLEMQEKDTDQ
67248 WYRVHTNATIRNTEFTVPDLKMGQKYSFRVAAVNVKGMSEYSESIAEIEPVERIEIPDLELADDLKKTVT
67249 IRAGASLRLMVSVSGRPPPVITWSKQGIDLASRAIIDTTESYSLLIVDKVNRYDAGKYTIEAENQSGKKS
67250 ATVLVKVYDTPGPCPSVKVKEVSRDSVTITWEIPTIDGGAPVNNYIVEKREAAMRAFKTVTTKCSKTLYR
67251 ISGLVEGTMYYFRVLPENIYGIGEPCETSDAVLVSEVPLVPAKLEVVDVTKSTVTLAWEKPLYDGGSRLT
67252 GYVLEACKAGTERWMKVVTLKPTVLEHTVTSLNEGEQYLFRIRAQNEKGVSEPRETVTAVTVQDLRVLPT
67253 IDLSTMPQKTIHVPAGRPVELVIPIAGRPPPAASWFFAGSKLRESERVTVETHTKVAKLTIRETTIRDTG
67254 EYTLELKNVTGTTSETIKVIILDKPGPPTGPIKIDEIDATSITISWEPPELDGGAPLSGYVVEQRDAHRP
67255 GWLPVSESVTRSTFKFTRLTEGNEYVFRVAATNRFGIGSYLQSEVIECRSSIRIPGPPETLQIFDVSRDG
67256 MTLTWYPPEDDGGSQVTGYIVERKEVRADRWVRVNKVPVTMTRYRSTGLTEGLEYEHRVTAINARGSGKP
67257 SRPSKPIVAMDPIAPPGKPQNPRVTDTTRTSVSLAWSVPEDEGGSKVTGYLIEMQKVDQHEWTKCNTTPT
67258 KIREYTLTHLPQGAEYRFRVLACNAGGPGEPAEVPGTVKVTEMLEYPDYELDERYQEGIFVRQGGVIRLT
67259 IPIKGKPFPICKWTKEGQDISKRAMIATSETHTELVIKEADRGDSGTYDLVLENKCGKKAVYIKVRVIGS
67260 PNSPEGPLEYDDIQVRSVRVSWRPPADDGGADILGYILERREVPKAAWYTIDSRVRGTSLVVKGLKENVE
67261 YHFRVSAENQFGISKPLKSEEPVTPKTPLNPPEPPSNPPEVLDVTKSSVSLSWSRPKDDGGSRVTGYYIE
67262 RKETSTDKWVRHNKTQITTTMYTVTGLVPDAEYQFRIIAQNDVGLSETSPASEPVVCKDPFDKPSQPGEL
67263 EILSISKDSVTLQWEKPECDGGKEILGYWVEYRQSGDSAWKKSNKERIKDKQFTIGGLLEATEYEFRVFA
67264 ENETGLSRPRRTAMSIKTKLTSGEAPGIRKEMKDVTTKLGEAAQLSCQIVGRPLPDIKWYRFGKELIQSR
67265 KYKMSSDGRTHTLTVMTEEQEDEGVYTCIATNEVGEVETSSKLLLQATPQFHPGYPLKEKYYGAVGSTLR
67266 LHVMYIGRPVPAMTWFHGQKLLQNSENITIENTEHYTHLVMKNVQRKTHAGKYKVQLSNVFGTVDAILDV
67267 EIQDKPDKPTGPIVIEALLKNSAVISWKPPADDGGSWITNYVVEKCEAKEGAEWQLVSSAISVTTCRIVN
67268 LTENAGYYFRVSAQNTFGISDPLEVSSVVIIKSPFEKPGAPGKPTITAVTKDSCVVAWKPPASDGGAKIR
67269 NYYLEKREKKQNKWISVTTEEIRETVFSVKNLIEGLEYEFRVKCENLGGESEWSEISEPITPKSDVPIQA
67270 PHFKEELRNLNVRYQSNATLVCKVTGHPKPIVKWYRQGKEIIADGLKYRIQEFKGGYHQLIIASVTDDDA
67271 TVYQVRATNQGGSVSGTASLEVEVPAKIHLPKTLEGMGAVHALRGEVVSIKIPFSGKPDPVITWQKGQDL
67272 IDNNGHYQVIVTRSFTSLVFPNGVERKDAGFYVVCAKNRFGIDQKTVELDVADVPDPPRGVKVSDVSRDS
67273 VNLTWTEPASDGGSKITNYIVEKCATTAERWLRVGQARETRYTVINLFGKTSYQFRVIAENKFGLSKPSE
67274 PSEPTITKEDKTRAMNYDEEVDETREVSMTKASHSSTKELYEKYMIAEDLGRGEFGIVHRCVETSSKKTY
67275 MAKFVKVKGTDQVLVKKEISILNIARHRNILHLHESFESMEELVMIFEFISGLDIFERINTSAFELNERE
67276 IVSYVHQVCEALQFLHSHNIGHFDIRPENIIYQTRRSSTIKIIEFGQARQLKPGDNFRLLFTAPEYYAPE
67277 VHQHDVVSTATDMWSLGTLVYVLLSGINPFLAETNQQIIENIMNAEYTFDEEAFKEISIEAMDFVDRLLV
67278 KERKSRMTASEALQHPWLKQKIERVSTKVIRTLKHRRYYHTLIKKDLNMVVSAARISCGGAIRSQKGVSV
67279 AKVKVASIEIGPVSGQIMHAVGEEGGHVKYVCKIENYDQSTQVTWYFGVRQLENSEKYEITYEDGVAILY
67280 VKDITKLDDGTYRCKVVNDYGEDSSYAELFVKGVREVYDYYCRRTMKKIKRRTDTMRLLERPPEFTLPLY
67281 NKTAYVGENVRFGVTITVHPEPHVTWYKSGQKIKPGDNDKKYTFESDKGLYQLTINSVTTDDDAEYTVVA
67282 RNKYGEDSCKAKLTVTLHPPPTDSTLRPMFKRLLANAECQEGQSVCFEIRVSGIPPPTLKWEKDGQPLSL
67283 GPNIEIIHEGLDYYALHIRDTLPEDTGYYRVTATNTAGSTSCQAHLQVERLRYKKQEFKSKEEHERHVQK
67284 QIDKTLRMAEILSGTESVPLTQVAKEALREAAVLYKPAVSTKTVKGEFRLEIEEKKEERKLRMPYDVPEP
67285 RKYKQTTIEEDQRIKQFVPMSDMKWYKKIRDQYEMPGKLDRVVQKRPKRIRLSRWEQFYVMPLPRITDQY
67286 RPKWRIPKLSQDDLEIVRPARRRTPSPDYDFYYRPRRRSLGDISDEELLLPIDDYLAMKRTEEERLRLEE
67287 ELELGFSASPPSRSPPHFELSSLRYSSPQAHVKVEETRKDFRYSTYHIPTKAEASTSYAELRERHAQAAY
67288 RQPKQRQRIMAEREDEELLRPVTTTQHLSEYKSELDFMSKEEKSRKKSRRQREVTEITEIEEEYEISKHA
67289 QRESSSSASRLLRRRRSLSPTYIELMRPVSELIRSRPQPAEEYEDDTERRSPTPERTRPRSPSPVSSERS
67290 LSRFERSARFDIFSRYESMKAALKTQKTSERKYEVLSQQPFTLDHAPRITLRMRSHRVPCGQNTRFILNV
67291 QSKPTAEVKWYHNGVELQESSKIHYTNTSGVLTLEILDCHTDDSGTYRAVCTNYKGEASDYATLDVTGGD
67292 YTTYASQRRDEEVPRSVFPELTRTEAYAVSSFKKTSEMEASSSVREVKSQMTETRESLSSYEHSASAEMK
67293 SAALEEKSLEEKSTTRKIKTTLAARILTKPRSMTVYEGESARFSCDTDGEPVPTVTWLRKGQVLSTSARH
67294 QVTTTKYKSTFEISSVQASDEGNYSVVVENSEGKQEAEFTLTIQKARVTEKAVTSPPRVKSPEPRVKSPE
67295 AVKSPKRVKSPEPSHPKAVSPTETKPTPTEKVQHLPVSAPPKITQFLKAEASKEIAKLTCVVESSVLRAK
67296 EVTWYKDGKKLKENGHFQFHYSADGTYELKINNLTESDQGEYVCEISGEGGTSKTNLQFMGQAFKSIHEK
67297 VSKISETKKSDQKTTESTVTRKTEPKAPEPISSKPVIVTGLQDTTVSSDSVAKFAVKATGEPRPTAIWTK
67298 DGKAITQGGKYKLSEDKGGFFLEIHKTDTSDSGLYTCTVKNSAGSVSSSCKLTIKAIKDTEAQKVSTQKT
67299 SEITPQKKAVVQEEISQKALRSEEIKMSEAKSQEKLALKEEASKVLISEEVKKSAATSLEKSIVHEEITK
67300 TSQASEEVRTHAEIKAFSTQMSINEGQRLVLKANIAGATDVKWVLNGVELTNSEEYRYGVSGSDQTLTIK
67301 QASHRDEGILTCISKTKEGIVKCQYDLTLSKELSDAPAFISQPRSQNINEGQNVLFTCEISGEPSPEIEW
67302 FKNNLPISISSNVSISRSRNVYSLEIRNASVSDSGKYTIKAKNFRGQCSATASLMVLPLVEEPSREVVLR
67303 TSGDTSLQGSFSSQSVQMSASKQEASFSSFSSSSASSMTEMKFASMSAQSMSSMQESFVEMSSSSFMGIS
67304 NMTQLESSTSKMLKAGIRGIPPKIEALPSDISIDEGKVLTVACAFTGEPTPEVTWSCGGRKIHSQEQGRF
67305 HIENTDDLTTLIIMDVQKQDGGLYTLSLGNEFGSDSATVNIHIRSI
67306 X
67307 SHAR_EOF
67308 chmod 0644 titin_hum.aa ||
67309 echo 'restore of titin_hum.aa failed'
67310 Wc_c="`wc -c < 'titin_hum.aa'`"
67311 test 27376 -eq "$Wc_c" ||
67312         echo 'titin_hum.aa: original size 27376, current size' "$Wc_c"
67313 fi
67314 # ============= titin_hum.seq ==============
67315 if test -f 'titin_hum.seq' -a X"$1" != X"-c"; then
67316         echo 'x - skipping titin_hum.seq (File already exists)'
67317 else
67318 echo 'x - extracting titin_hum.seq (Text)'
67319 sed 's/^X//' << 'SHAR_EOF' > 'titin_hum.seq' &&
67320 >gi|20143913|ref|NM_003319.2| Homo sapiens titin (TTN), transcript variant N2-B, mRNA
67321 AGCAGTCGTGCATTCCCAGCCTCGCCTCGGGTGTAGGGATTGCATAGAAAAGCAAAACTACACAGTCTTG
67322 ACTGTGTAGTTTTGTTTTTAGGATTAGAGGCTCACCGATTCATGTCGGAGATGGTCAGAAAAACCAACTC
67323 TCCATAGGACGTCGTTTCAGAAGCAACCTTGGGCTTAGTCCCACCCTTTTTAGGCACTCTTGAGAAATCA
67324 AGTGCCTAGAAAGATGACAACTCAAGCACCGACGTTTACGCAGCCGTTACAAAGCGTTGTGGTACTGGAG
67325 GGTAGTACCGCAACCTTTGAGGCTCACATTAGTGGTTTTCCAGTTCCTGAGGTGAGCTGGTTTAGGGATG
67326 GCCAGGTGATTTCCACTTCCACTCTGCCCGGCGTGCAGATCTCCTTTAGCGATGGCCGCGCTAAACTGAC
67327 GATCCCCGCCGTGACTAAAGCCAACAGTGGACGATATTCCCTGAAAGCCACCAATGGATCTGGACAAGCG
67328 ACTAGTACTGCTGAGCTTCTCGTGAAAGCTGAGACAGCACCACCCAACTTCGTTCAACGACTGCAGAGCA
67329 TGACCGTGAGACAAGGAAGCCAAGTGAGACTCCAAGTGAGAGTGACTGGAATCCCTACACCTGTGGTGAA
67330 GTTCTACCGGGATGGAGCCGAAATCCAGAGCTCCCTTGATTTCCAAATTTCACAAGAAGGCGACCTCTAC
67331 AGCTTACTGATTGCAGAAGCATACCCTGAGGACTCAGGGACCTATTCAGTAAATGCCACCAATAGCGTTG
67332 GAAGAGCTACTTCGACTGCTGAATTACTGGTTCAAGGTGAAGAAGAAGTACCTGCTAAAAAGACAAAGAC
67333 AATTGTTTCGACTGCTCAGATCTCAGAATCAAGACAAACCCGAATTGAAAAGAAGATTGAAGCCCACTTT
67334 GATGCCAGATCAATTGCAACAGTTGAGATGGTCATAGATGGTGCCGCTGGGCAACAGCTGCCACATAAAA
67335 CACCTCCCAGGATTCCTCCGAAGCCAAAGTCAAGATCCCCAACACCACCGTCTATTGCTGCCAAAGCACA
67336 GCTGGCTCGGCAGCAGTCCCCATCGCCCATAAGACACTCCCCTTCCCCGGTCAGACACGTGCGGGCACCG
67337 ACCCCATCTCCGGTCAGGTCCGTGTCTCCAGCAGCAAGAATCTCCACATCCCCCATCAGGTCTGTTAGGT
67338 CTCCATTGCTCATGCGTAAGACTCAGGCATCCACCGTGGCCACAGGTCCTGAAGTGCCTCCCCCTTGGAA
67339 GCAAGAGGGCTACGTGGCCTCCTCATCTGAGGCTGAGATGAGAGAGACAACGCTGACAACCTCTACTCAG
67340 ATCAGGACAGAAGAGAGATGGGAAGGGAGATACGGTGTCCAGGAGCAAGTGACCATCAGTGGTGCTGCGG
67341 GTGCTGCCGCCAGTGTGTCGGCCAGTGCTAGCTACGCAGCAGAGGCTGTTGCCACTGGTGCTAAAGAGGT
67342 GAAACAAGATGCTGACAAAAGTGCAGCTGTTGCGACTGTTGTTGCTGCCGTTGATATGGCCAGAGTGAGA
67343 GAACCAGTGATCAGCGCTGTAGAGCAGACTGCTCAGAGGACAACCACGACTGCTGTGCACATCCAACCTG
67344 CTCAAGAACAGGTAAGAAAGGAAGCGGAGAAGACTGCTGTAACTAAGGTAGTAGTGGCCGCCGATAAAGC
67345 CAAGGAACAAGAATTAAAATCAAGAACCAAAGAAGTAATTACCACAAAGCAAGAGCAGATGCACGTAACT
67346 CATGAGCAGATAAGAAAAGAAACTGAAAAAACATTTGTACCAAAGGTAGTAATTTCCGCAGCTAAAGCCA
67347 AAGAACAAGAAACTAGAATTTCTGAAGAAATTACTAAGAAACAGAAACAAGTAACTCAAGAAGCAATAAT
67348 GAAGGAAACTAGGAAAACAGTTGTACCTAAAGTCATAGTTGCCACACCCAAAGTCAAAGAACAAGATTTA
67349 GTATCAAGAGGTAGAGAAGGCATTACTACCAAAAGAGAACAAGTGCAAATAACTCAGGAGAAGATGAGAA
67350 AGGAAGCCGAGAAAACTGCCTTGTCTACAATAGCAGTTGCTACTGCTAAAGCCAAAGAACAAGAAACAAT
67351 ACTGAGAACTAGAGAAACTATGGCTACTAGACAAGAACAAATCCAAGTTACCCATGGAAAGGTGGACGTT
67352 GGAAAAAAGGCTGAAGCTGTAGCAACAGTTGTTGCTGCAGTAGACCAGGCCCGAGTCAGAGAGCCCAGAG
67353 AGCCTGGGCATCTTGAAGAATCCTATGCTCAGCAGACCACTTTGGAGTACGGATATAAGGAACGCATTTC
67354 CGCCGCAAAGGTAGCTGAGCCTCCCCAACGTCCAGCCTCAGAACCCCACGTTGTCCCTAAAGCAGTCAAG
67355 CCTAGAGTAATCCAGGCTCCTTCTGAGACTCATATCAAAACTACTGATCAAAAGGGAATGCACATATCAT
67356 CACAGATCAAGAAAACTACAGATCTAACAACGGAAAGATTAGTCCATGTGGATAAACGCCCCCGCACAGC
67357 TAGCCCTCACTTTACTGTTTCAAAAATTTCTGTTCCTAAGACAGAACATGGATATGAGGCATCAATAGCC
67358 GGTAGTGCTATTGCCACATTACAAAAAGAGTTGTCAGCCACATCTTCTGCTCAGAAGATCACCAAATCGG
67359 TGAAGGCTCCTACTGTGAAGCCCAGTGAGACTAGAGTAAGGGCAGAGCCCACACCCTTGCCACAGTTCCC
67360 CTTCGCTGACACACCAGATACTTACAAGAGTGAAGCTGGCGTTGAGGTGAAAAAGGAAGTAGGGGTGAGC
67361 ATCACTGGCACCACCGTCCGTGAAGAGCGCTTTGAAGTACTGCACGGACGCGAAGCCAAGGTAACAGAAA
67362 CAGCAAGAGTACCAGCACCTGTTGAAATTCCTGTTACTCCACCAACTTTGGTCTCGGGCTTAAAAAATGT
67363 GACTGTCATAGAAGGTGAATCTGTCACCTTGGAGTGCCACATCTCTGGATACCCATCCCCGACAGTGACA
67364 TGGTACAGGGAAGACTACCAAATCGAAAGTTCCATTGACTTCCAGATAACCTTCCAGAGTGGAATTGCTC
67365 GTCTTATGATTCGCGAAGCATTTGCGGAAGACAGCGGGCGATTTACTTGCAGTGCTGTAAATGAGGCTGG
67366 AACCGTCAGCACATCCTGCTATCTGGCTGTGCAGGTGTCAGAAGAATTTGAAAAGGAAACCACAGCCGTG
67367 ACTGAGAAATTTACTACAGAAGAGAAACGCTTTGTTGAGTCAAGAGATGTGGTTATGACTGATACTAGCC
67368 TCACAGAGGAACAAGCAGGGCCTGGAGAACCTGCCGCGCCTTACTTTATTACAAAACCAGTGGTCCAGAA
67369 ACTGGTGGAAGGTGGGAGCGTGGTGTTTGGATGCCAAGTTGGCGGCAACCCAAAGCCCCATGTATACTGG
67370 AAAAAATCTGGTGTTCCTCTAACCACTGGATACAGATACAAAGTGAGTTACAACAAACAAACCGGTGAAT
67371 GCAAGCTGGTGATTTCTATGACTTTTGCTGATGATGCTGGAGAATACACTATTGTTGTTCGCAATAAGCA
67372 TGGAGAAACTTCTGCATCTGCTTCCTTGCTTGAAGAAGCTGATTATGAGTTACTGATGAAGTCCCAGCAA
67373 GAAATGCTTTATCAGACACAAGTGACTGCATTTGTTCAAGAACCTAAAGTTGGAGAAACAGCACCTGGAT
67374 TTGTATACTCTGAGTATGAAAAAGAGTATGAAAAAGAACAAGCCTTAATTAGGAAGAAAATGGCCAAAGA
67375 TACTGTAGTGGTCAGAACTTATGTAGAAGATCAGGAATTCCATATTTCTTCCTTTGAAGAGAGACTTATT
67376 AAAGAAATTGAATATAGAATAATAAAGACTACATTAGAAGAACTTCTTGAAGAAGATGGAGAAGAAAAGA
67377 TGGCAGTTGACATTTCTGAATCTGAAGCTGTTGAATCAGGATTTGATTTAAGAATCAAGAATTATAGAAT
67378 TCTTGAGGGGATGGGTGTCACTTTTCATTGCAAGATGTCTGGATATCCATTACCAAAGATTGCTTGGTAC
67379 AAAGATGGCAAGCGCATCAAACATGGAGAAAGATACCAAATGGACTTTCTACAAGATGGCAGAGCTAGTC
67380 TGCGTATACCTGTTGTTCTTCCAGAAGATGAAGGAATCTACACTGCATTTGCCAGCAATATTAAAGGAAA
67381 TGCAATTTGCTCAGGGAAATTGTATGTGGAGCCTGCTGCACCACTTGGAGCTCCGACTTACATTCCCACA
67382 CTAGAGCCAGTGAGCAGAATCAGATCTCTCTCTCCACGTTCAGTGAGCAGGTCTCCTATACGCATGTCTC
67383 CTGCACGGATGTCACCTGCAAGGATGTCTCCTGCACGGATGTCCCCTGCAAGAATGTCCCCTGGACGTAG
67384 GCTGGAGGAGACAGATGAGTCACAACTTGAGAGACTATATAAACCAGTCTTTGTGTTAAAACCTGTTTCT
67385 TTCAAATGTTTAGAAGGGCAAACTGCCAGATTTGACTTAAAGGTTGTTGGTAGACCTATGCCAGAGACGT
67386 TCTGGTTTCATGATGGCCAGCAAATTGTCAATGACTATACCCATAAAGTAGTCATTAAAGAAGATGGTAC
67387 TCAATCACTAATTATTGTCCCTGCCACACCCAGTGATTCTGGGGAATGGACTGTGGTTGCCCAAAACAGG
67388 GCAGGCAGATCTTCAATTTCAGTGATTTTAACTGTGGAAGCTGTGGAACATCAGGTAAAACCGATGTTTG
67389 TAGAAAAACTGAAAAATGTCAATATAAAGGAAGGTTCCCGACTTGAAATGAAAGTCAGAGCTACGGGTAA
67390 CCCCAACCCTGACATTGTATGGTTGAAAAACAGTGACATCATTGTGCCTCATAAATATCCCAAAATCAGA
67391 ATTGAAGGAACCAAGGGAGAAGCTGCCCTTAAAATCGATTCCACTGTCAGCCAAGATTCTGCCTGGTATA
67392 CTGCGACTGCTATTAATAAAGCTGGCAGAGACACTACAAGATGCAAAGTAAATGTTGAAGTTGAGTTTGC
67393 AGAGCCTGAGCCAGAGAGAAAGTTAATCATCCCACGGGGGACATATAGAGCAAAGGAGATTGCAGCCCCA
67394 GAACTGGAGCCCCTCCATTTGCGATATGGCCAAGAGCAATGGGAAGAAGGTGATCTCTATGACAAAGAGA
67395 AACAACAGAAACCATTTTTCAAGAAAAAACTCACTTCCTTAAGACTTAAGCGCTTTGGGCCTGCCCACTT
67396 TGAATGCAGGCTAACACCCATTGGTGACCCAACGATGGTGGTGGAGTGGCTCCATGATGGAAAGCCACTT
67397 GAAGCAGCCAACAGGCTCCGTATGATCAATGAATTTGGGTACTGCAGCCTTGATTATGGCGTTGCATATT
67398 CTAGAGACAGTGGTATCATTACTTGCAGAGCCACTAACAAATATGGAACAGATCACACATCTGCTACCCT
67399 TATTGTTAAAGATGAGAAAAGTCTTGTGGAAGAATCCCAATTGCCTGAGGGGAGGAAAGGCTTACAGAGA
67400 ATTGAAGAATTAGAGAGAATGGCTCATGAAGGTGCACTTACAGGTGTAACAACAGATCAGAAAGAAAAGC
67401 AAAAGCCAGACATTGTCTTGTACCCAGAGCCAGTTAGAGTACTTGAAGGGGAGACTGCAAGGTTCCGCTG
67402 CAGGGTAACAGGCTACCCTCAGCCCAAAGTCAACTGGTACCTCAATGGACAGCTCATCCGCAAAAGCAAA
67403 AGGTTCAGAGTTCGCTATGATGGTATCCATTACCTGGACATCGTGGACTGCAAATCATATGACACAGGTG
67404 AAGTGAAGGTCACCGCGGAAAATCCTGAAGGTGTGATAGAGCATAAAGTGAAGCTTGAGATTCAACAGAG
67405 GGAAGATTTTAGGTCTGTCCTTAGGAGAGCTCCTGAACCAAGGCCTGAGTTTCACGTACATGAACCAGGA
67406 AAGCTTCAGTTTGAAGTACAAAAAGTGGATAGACCTGTTGACACCACTGAAACCAAAGAAGTTGTGAAGT
67407 TGAAAAGGGCTGAAAGAATTACCCATGAAAAAGTGCCTGAAGAGTCGGAAGAGCTGCGCAGTAAATTCAA
67408 GCGCAGAACAGAAGAGGGCTATTATGAAGCCATTACCGCTGTGGAGCTCAAGTCTCGAAAGAAGGATGAA
67409 TCCTATGAGGAACTCCTCAGGAAGACAAAAGATGAACTTCTCCACTGGACCAAAGAGTTAACTGAAGAGG
67410 AAAAGAAAGCTCTTGCCGAAGAAGGCAAAATCACGATTCCAACTTTTAAACCTGACAAGATTGAACTAAG
67411 TCCTAGTATGGAGGCTCCAAAAATCTTCGAAAGAATCCAGAGCCAAACAGTGGGCCAAGGATCTGATGCA
67412 CACTTCCGGGTCAGAGTCGTGGGGAAACCAGACCCCGAATGTGAATGGTACAAAAATGGTGTCAAAATTG
67413 AACGGTCTGACCGGATCTACTGGTACTGGCCCGAAGACAATGTTTGTGAATTGGTCATAAGAGATGTGAC
67414 TGCTGAGGACTCTGCCAGCATCATGGTAAAAGCCATCAACATAGCTGGAGAAACCTCCAGTCACGCATTC
67415 TTACTTGTCCAAGCCAAGCAATTGATCACTTTCACACAGGAATTACAAGATGTTGTTGCTAAGGAAAAAG
67416 ACACTATGGCAACCTTTGAATGTGAAACTTCAGAACCATTTGTCAAAGTGAAATGGTATAAAGATGGTAT
67417 GGAGGTTCATGAGGGAGATAAATACAGGATGCACTCTGACAGAAAGGTTCACTTCCTCTCCATACTGACC
67418 ATTGATACGTCTGATGCTGAAGATTACAGCTGTGTACTTGTGGAAGATGAAAATGTCAAAACGACTGCTA
67419 AACTTATTGTTGAAGGTGCAGTTGTTGAGTTTGTGAAAGAACTTCAGGACATAGAAGTTCCAGAATCATA
67420 TTCAGGAGAATTAGAGTGCATTGTATCCCCAGAAAATATAGAAGGAAAATGGTATCATAATGATGTGGAG
67421 CTTAAATCCAATGGCAAATATACAATTACATCTCGTCGTGGACGTCAGAACCTCACGGTCAAGGATGTAA
67422 CCAAGGAGGACCAGGGAGAATACAGCTTTGTCATCGACGGGAAAAAGACAACCTGTAAATTAAAGATGAA
67423 ACCCCGCCCCATTGCTATCCTACAAGGACTTAGTGACCAAAAAGTCTGTGAGGGTGACATTGTTCAGCTT
67424 GAAGTTAAAGTCTCCTTGGAAAGTGTGGAAGGCGTCTGGATGAAAGACGGCCAAGAAGTGCAGCCCAGTG
67425 ACAGGGTTCACATTGTGATAGACAAACAATCTCATATGCTGCTCATTGAAGACATGACTAAGGAAGATGC
67426 TGGAAATTACTCTTTCACCATTCCAGCCCTTGGCCTCTCCACCAGTGGGCGTGTCTCTGTCTATAGTGTG
67427 GACGTGATAACACCTCTAAAAGATGTTAATGTGATTGAAGGCACCAAGGCTGTGCTTGAATGTAAGGTGT
67428 CAGTCCCTGATGTGACTTCTGTTAAGTGGTACTTAAATGATGAACAAATCAAGCCTGATGACCGTGTACA
67429 GGCCATTGTGAAAGGTACTAAACAGCGACTAGTCATTAACCGAACTCATGCTTCAGACGAAGGACCTTAC
67430 AAGCTGATAGTTGGCAGAGTTGAAACCAACTGTAATCTCTCTGTAGAAAAAATTAAAATTATCAGAGGTC
67431 TTCGTGACCTTACCTGTACAGAAACTCAAAATGTGGTGTTTGAGGTTGAGCTGTCCCACTCTGGAATTGA
67432 TGTCCTGTGGAATTTTAAGGACAAGGAAATCAAGCCCAGTTCTAAATATAAAATTGAAGCACATGGAAAA
67433 ATATATAAATTGACAGTTCTAAATATGATGAAAGATGATGAAGGAAAATACACATTTTACGCGGGAGAAA
67434 ATATCACATCTGGAAAACTTACTGTGGCAGGTGGGGCCATCTCCAAGCCACTCACAGATCAGACCGTAGC
67435 TGAATCCCAGGAAGCTGTGTTTGAATGTGAAGTTGCCAACCCAGATTCCAAAGGCGAATGGTTGAGGGAT
67436 GGCAAACACCTACCACTGACTAACAACATCAGAAGTGAGTCTGATGGCCACAAAAGGAGACTTATCATTG
67437 CTGCCACCAAATTAGATGACATTGGAGAATATACCTACAAGGTGGCCACCTCCAAAACATCTGCCAAACT
67438 CAAAGTTGAAGCTGTCAAAATTAAGAAGACTCTGAAGAACCTCACAGTGACAGAAACACAGGATGCTGTT
67439 TTCACTGTCGAGCTTACACACCCTAATGTCAAAGGTGTCCAGTGGATCAAAAATGGAGTTGTGCTGGAAT
67440 CCAATGAAAAGTATGCTATCTCTGTCAAAGGAACAATTTACTCTCTGAGGATTAAAAACTGTGCCATCGT
67441 GGATGAGTCTGTTTATGGCTTCAGGCTTGGAAGGCTTGGAGCCAGTGCCAGACTGCACGTGGAGACTGTC
67442 AAGATCATTAAAAAGCCAAAGGATGTGACAGCCTTGGAAAATGCCACTGTTGCCTTTGAAGTTAGTGTTT
67443 CCCATGACACTGTTCCAGTAAAATGGTTCCATAAGAGTGTGGAAATTAAGCCAAGTGACAAACACAGACT
67444 GGTCTCAGAAAGGAAAGTCCACAAGCTGATGCTGCAGAACATCTCCCCCTCAGATGCTGGGGAATACACA
67445 GCTGTGGTCGGGCAATTGGAATGCAAAGCAAAACTGTTTGTGGAGACATTACATATTACAAAAACCATGA
67446 AAAATATCGAGGTGCCTGAGACCAAAACTGCCTCTTTTGAGTGTGAGGTGTCCCACTTCAATGTCCCTTC
67447 CATGTGGCTGAAGAATGGTGTGGAAATTGAGATGAGTGAAAAGTTCAAGATAGTTGTGCAGGGAAAACTC
67448 CATCAGCTGATCATCATGAACACCAGCACAGAGGACTCGGCAGAATACACATTTGTCTGTGGCAATGACC
67449 AAGTCAGTGCCACCCTGACAGTCACCCCAATCATGATTACTTCCATGCTGAAAGACATCAACGCTGAAGA
67450 AAAAGACACTATTACTTTTGAGGTGACAGTGAACTATGAAGGCATCTCTTACAAATGGTTAAAGAATGGT
67451 GTGGAAATCAAATCAACTGACAAGTGCCAGATGAGAACCAAAAAGCTCACACACTCACTGAACATCAGGA
67452 ATGTTCACTTTGGGGATGCTGCTGACTACACCTTTGTGGCTGGAAAAGCAACATCAACAGCCACACTTTA
67453 TGTGGAAGCTCGTCATATAGAATTTAGGAAACACATTAAGGACATTAAGGTACTGGAGAAGAAGCGAGCC
67454 ATGTTTGAATGTGAAGTTTCTGAACCTGACATCACTGTACAGTGGATGAAAGATGACCAGGAACTGCAGA
67455 TCACAGACAGAATAAAGATTCAGAAGGAGAAATATGTCCACCGCCTTCTGATCCCATCCACCCGGATGTC
67456 TGATGCTGGGAAGTACACAGTGGTGGCAGGAGGCAACGTGTCAACTGCAAAACTCTTTGTAGAAGGCAGA
67457 GATGTTCGCATCCGAAGTATTAAAAAGGAGGTTCAGGTCATTGAGAAACAGCGTGCTGTTGTTGAATTTG
67458 AGGTCAATGAAGACGATGTTGATGCCCACTGGTATAAAGATGGCATTGAAATCAATTTCCAAGTTCAAGA
67459 ACGACACAAATATGTAGTGGAAAGAAGAATCCACCGAATGTTTATCTCTGAGACCAGACAGAGCGATGCA
67460 GGAGAATACACCTTTGTGGCAGGAAGGAACAGGAGTTCTGTCACTCTCTATGTCAATGCTCCTGAACCGC
67461 CCCAAGTTCTGCAGGAGCTCCAGCCTGTCACTGTGCAGTCTGGCAAGCCTGCCCGCTTCTGTGCCGTGAT
67462 ATCCGGAAGACCACAGCCCAAAATTTCCTGGTACAAGGAAGAGCAGCTGCTTTCCACTGGCTTCAAGTGC
67463 AAATTTCTTCATGATGGGCAAGAGTACACGCTTTTGCTAATTGAAGCCTTCCCAGAGGATGCGGCAGTCT
67464 ATACCTGTGAAGCCAAGAATGACTATGGTGTTGCCACAACATCAGCTTCACTCTCAGTGGAAGTTCCAGA
67465 AGTTGTGTCTCCTGATCAGGAAATGCCTGTTTATCCACCTGCCATCATCACCCCGCTTCAGGACACTGTC
67466 ACTTCTGAAGGGCAGCCAGCCCGTTTTCAATGCCGGGTTTCTGGAACAGATCTAAAAGTGTCGTGGTACA
67467 GCAAAGACAAGAAAATCAAGCCATCTCGGTTCTTTAGAATGACTCAATTTGAAGACACTTATCAACTGGA
67468 AATTGCCGAAGCTTATCCAGAAGATGAAGGAACTTACACGTTTGTTGCTAGTAATGCTGTAGGCCAAGTA
67469 TCAAGCACAGCCAACCTGAGTCTGGAAGCTCCTGAATCAATTTTGCATGAGAGGATTGAACAAGAGATTG
67470 AGATGGAAATGAAAGAGTTTTCTAGTTCTTTTCTGTCTGCCGAGGAAGAAGGACTTCATAGCGCCGAACT
67471 TCAATTATCTAAAATAAATGAAACACTTGAACTTTTGTCTGAATCTCCAGTTTACTCAACTAAATTTGAT
67472 TCCGAAAAGGAAGGCACTGGCCCAATTTTCATCAAAGAAGTGTCAAATGCTGATATAAGCATGGGGGATG
67473 TGGCTACACTGTCTGTAACTGTCATTGGCATCCCCAAACCTAAAATTCAGTGGTTCTTTAATGGAGTGCT
67474 ATTAACCCCTTCTGCTGACTACAAATTTGTTTTTGACGGTGATGATCATAGCCTGATCATTCTGTTCACC
67475 AAATTGGAGGATGAGGGAGAGTATACATGTATGGCCAGTAATGACTATGGAAAGACAATATGTAGTGCCT
67476 ATCTAAAAATTAATTCCAAAGGAGAGGGTCACAAAGACACTGAAACAGAATCAGCAGTGGCAAAATCTCT
67477 GGAAAAGCTGGGAGGTCCTTGTCCTCCTCACTTCCTTAAGGAGTTAAAACCAATTCGCTGTGCTCAAGGG
67478 CTTCCTGCCATCTTTGAGTACACAGTGGTTGGAGAGCCTGCCCCTACTGTTACATGGTTCAAAGAAAACA
67479 AGCAGCTTTGCACCAGTGTTTATTACACTATCATTCATAACCCTAATGGCTCTGGAACTTTCATTGTCAA
67480 TGACCCTCAGAGGGAAGACAGTGGCCTCTATATCTGTAAAGCAGAGAATATGTTGGGTGAGTCCACCTGT
67481 GCAGCAGAGCTGCTTGTGCTTCTGGAAGACACAGACATGACTGATACCCCCTGCAAAGCAAAGTCCACAC
67482 CAGAGGCTCCTGAGGATTTTCCACAGACACCCTTAAAGGGTCCCGCAGTTGAAGCACTTGACTCAGAGCA
67483 GGAAATTGCAACGTTTGTAAAAGACACCATTTTGAAAGCTGCTTTAATTACAGAAGAAAACCAGCAACTA
67484 TCTTATGAGCATATTGCTAAAGCCAATGAATTGAGCAGTCAGCTTCCTTTGGGAGCTCAGGAATTGCAAT
67485 CCATTTTGGAGCAAGACAAGCTCACTCCTGAAAGCACCAGGGAATTTCTTTGCATCAATGGCAGTATTCA
67486 CTTTCAGCCTCTCAAGGAACCATCTCCCAACCTACAGCTGCAGATTGTACAGTCCCAGAAAACCTTCTCC
67487 AAAGAAGGTATTCTAATGCCTGAAGAGCCTGAGACACAGGCAGTTCTATCAGATACCGAGAAAATCTTCC
67488 CAAGTGCCATGTCCATAGAACAAATTAATTCATTAACAGTTGAGCCTCTGAAAACTTTATTAGCTGAACC
67489 TGAAGGGAATTATCCACAGTCTTCAATAGAACCTCCAATGCATTCTTATCTAACCTCTGTGGCTGAGGAA
67490 GTACTTTCACCAAAAGAAAAGACAGTATCTGACACCAACAGAGAGCAAAGAGTGACTCTTCAAAAGCAAG
67491 AGGCACAAAGTGCGCTCATCTTGAGTCAGAGCTTAGCTGAGGGACACGTGGAGAGTCTCCAGAGTCCTGA
67492 TGTCATGATCTCTCAGGTAAACTATGAGCCCCTAGTCCCTTCAGAACACTCATGCACAGAAGGAGGTAAA
67493 ATTTTGATAGAAAGTGCAAATCCACTGGAAAATGCAGGGCAAGATTCTGCGGTCAGAATTGAGGAAGGCA
67494 AGTCCTTAAGATTTCCACTAGCACTTGAAGAAAAGCAGGTACTGCTCAAAGAAGAGCATTCTGACAACGT
67495 GGTGATGCCCCCAGACCAAATCATTGAGTCTAAAAGAGAGCCCGTGGCAATAAAGAAAGTGCAGGAGGTA
67496 CAGGGAAGGGACCTTCTTTCTAAGGAAAGCTTGCTTTCTGGTATTCCAGAAGAGCAGAGATTAAACCTGA
67497 AAATTCAAATCTGCCGGGCTTTGCAAGCAGCCGTGGCCAGCGAGCAGCCAGGTCTTTTCTCTGAGTGGCT
67498 AAGAAATATTGAAAAGGTGGAGGTCGAGGCTGTAAACATCACCCAAGAGCCCAGACACATCATGTGCATG
67499 TACCTTGTTACTTCGGCAAAGTCTGTAACAGAAGAAGTAACCATCATTATTGAAGATGTTGATCCTCAAA
67500 TGGCTAACCTGAAAATGGAACTTAGGGATGCTTTGTGTGCTATTATATATGAGGAAATAGACATCCTAAC
67501 AGCTGAGGGTCCTAGAATTCAGCAAGGAGCCAAAACAAGTTTGCAAGAAGAAATGGATTCTTTTTCAGGT
67502 TCACAGAAGGTTGAACCCATTACTGAACCAGAAGTTGAATCTAAATATCTGATCTCAACTGAAGAGGTCA
67503 GTTATTTTAACGTGCAAAGTAGGGTTAAATATTTGGATGCCACACCTGTCACTAAAGGGGTTGCTTCAGC
67504 TGTTGTCTCTGACGAAAAACAAGATGAGAGTCTGAAACCATCAGAGGAAAAAGAGGAGTCTTCCTCTGAA
67505 AGTGGTACTGAGGAGGTTGCTACAGTAAAGATACAGGAAGCTGAGGGTGGCTTAATCAAAGAGGATGGCC
67506 CCATGATACATACACCTTTAGTGGACACTGTTTCTGAGGAAGGTGATATTGTACACCTCACAACATCCAT
67507 AACAAATGCTAAAGAGGTGAATTGGTATTTTGAGAATAAACTGGTGCCTTCAGATGAAAAGTTCAAGTGT
67508 TTACAAGATCAAAATACATATACGCTAGTCATCGACAAAGTAAATACCGAAGACCATCAAGGAGAGTATG
67509 TCTGTGAGGCCTTGAATGACAGCGGAAAAACAGCAACTTCAGCCAAACTCACTGTAGTAAAAAGAGCTGC
67510 CCCAGTGATCAAGAGGAAAATCGAACCCCTGGAAGTAGCACTGGGCCACCTAGCCAAATTCACCTGTGAG
67511 ATCCAAAGTGCTCCCAATGTCCGGTTCCAGTGGTTTAAAGCTGGCCGAGAAATTTATGAGAGTGACAAGT
67512 GTTCTATTCGATCTTCAAAGTATATCTCCAGCCTTGAAATCCTGAGAACCCAGGTGGTTGACTGCGGCGA
67513 GTATACATGCAAAGCTTCCAATGAGTATGGCAGTGTCAGCTGTACAGCCACACTAACTGTGACAGTGCCT
67514 GGAGGTGAAAAGAAAGTTCGCAAATTACTTCCGGAACGTAAACCTGAACCAAAGGAAGAAGTTGTTCTGA
67515 AAAGCGTTCTAAGAAAAAGACCTGAAGAAGAAGAACCTAAAGTAGAACCTAAAAAACTAGAAAAAGTTAA
67516 AAAACCTGCAGTACCAGAACCACCACCTCCAAAACCTGTTGAAGAGGTTGAAGTACCTACTGTTACAAAA
67517 AGGGAAAGGAAGATTCCTGAACCAACAAAAGTGCCTGAAATCAAGCCAGCAATACCTCTCCCTGCACCTG
67518 AACCGAAACCAAAGCCCGAAGCAGAAGTGAAAACAATCAAACCACCTCCTGTGGAACCTGAACCAACCCC
67519 CATCGCTGCCCCAGTAACAGTGCCAGTGGTTGGAAAGAAAGCAGAAGCCAAAGCACCTAAGGAAGAGGCT
67520 GCCAAGCCAAAAGGTCCTATCAAAGGTGTACCCAAAAAGACTCCTTCACCAATAGAAGCCGAAAGGAGAA
67521 AGTTAAGGCCAGGAAGTGGTGGAGAGAAACCTCCTGATGAAGCCCCGTTCACCTACCAGCTAAAGGCTGT
67522 GCCACTGAAGTTTGTGAAAGAAATCAAAGACATCATCTTGACAGAATCAGAGTTCGTTGGCTCTTCAGCA
67523 ATCTTTGAATGTTTGGTCTCCCCTTCCACTGCAATTACAACCTGGATGAAAGACGGTAGCAATATCCGTG
67524 AGAGTCCCAAGCACAGGTTTATTGCAGATGGTAAAGACAGAAAGCTGCACATCATTGATGTTCAACTTTC
67525 CGATGCTGGTGAATACACCTGTGTTTTACGTTTGGGAAACAAAGAAAAGACCTCCACGGCTAAACTTGTT
67526 GTAGAAGAACTTCCTGTGCGTTTTGTAAAAACACTGGAAGAGGAAGTCACAGTGGTCAAAGGACAGCCAT
67527 TGTACTTGAGCTGCGAGTTAAACAAAGAGCGTGACGTGGTCTGGAGGAAGGATGGCAAGATTGTGGTGGA
67528 GAAACCTGGCCGAATTGTGCCAGGCGTCATTGGCTTGATGCGGGCTCTGACCATCAACGATGCAGATGAC
67529 ACAGATGCTGGAACATACACAGTTACTGTGGAAAACGCCAACAACCTGGAGTGTTCATCTTGCGTAAAAG
67530 TAGTAGAAGTCATTAGAGATTGGCTGGTGAAACCTATACGAGACCAGCATGTGAAACCCAAGGGGACAGC
67531 TATTTTTGCCTGTGATATAGCAAAAGATACTCCAAACATTAAGTGGTTCAAAGGATATGATGAAATCCCT
67532 GCGGAACCAAATGATAAGACTGAAATACTGAGAGATGGAAATCATCTGTACCTCAAAATTAAGAATGCTA
67533 TGCCAGAAGATATTGCTGAGTATGCAGTGGAAATTGAAGGAAAAAGATACCCTGCAAAGCTGACACTTGG
67534 AGAGCGTGAAGTTGAACTGCTTAAACCAATAGAGGACGTTACCATTTATGAGAAAGAAAGTGCAAGCTTT
67535 GATGCAGAAATCTCAGAGGCAGACATTCCTGGACAATGGAAACTGAAAGGAGAACTTCTAAGGCCCTCAC
67536 CTACTTGTGAAATCAAAGCAGAAGGTGGAAAACGCTTCTTAACTTTGCACAAAGTCAAACTGGACCAAGC
67537 TGGTGAAGTCCTCTACCAGGCCCTTAATGCAATTACAACTGCCATTTTGACAGTAAAAGAAATCGAACTT
67538 GACTTTGCTGTGCCCCTGAAGGATGTCACTGTTCCAGAAAGGCGACAGGCTCGATTCGAATGTGTCCTCA
67539 CCCGAGAGGCAAATGTTATATGGTCCAAAGGACCTGATATAATTAAGTCATCTGACAAATTTGATATCAT
67540 CGCTGATGGAAAGAAACATATTCTTGTTATTAATGATTCTCAATTTGATGATGAAGGGGTCTATACTGCT
67541 GAGGTGGAGGGCAAGAAGACCTCAGCTCGGTTGTTTGTCACAGGTATAAGACTGAAATTCATGTCACCTC
67542 TTGAAGATCAAACAGTAAAAGAAGGTGAAACAGCAACTTTTGTTTGTGAACTTTCTCATGAAAAAATGCA
67543 TGTAGTCTGGTTCAAAAATGATGCCAAACTCCATACAAGCAGAACAGTACTCATCTCTTCTGAGGGCAAG
67544 ACTCACAAATTGGAAATGAAAGAAGTGACATTGGATGATATATCTCAGATAAAAGCTCAAGTCAAGGAGC
67545 TGAGCTCCACAGCACAGCTGAAGGTCTTAGAGGCCGATCCCTACTTCACTGTGAAATTACATGACAAAAC
67546 TGCAGTGGAGAAGGATGAGATTACTTTGAAGTGTGAAGTGAGCAAAGATGTACCAGTGAAATGGTTCAAA
67547 GATGGTGAAGAGATTGTCCCTTCACCCAAATATTCTATCAAGGCAGATGGCCTGCGCCGCATCTTAAAAA
67548 TCAAAAAGGCGGACCTTAAAGATAAAGGCGAATATGTGTGTGACTGTGGCACAGACAAGACCAAGGCAAA
67549 TGTTACTGTTGAGGCTCGACTAATAAAAGTGGAAAAGCCTCTGTACGGAGTAGAGGTGTTTGTTGGTGAA
67550 ACAGCCCACTTTGAAATTGAACTTTCTGAACCTGATGTTCACGGCCAGTGGAAGCTGAAAGGACAGCCTT
67551 TGACAGCTTCCCCTGACTGTGAAATCATTGAGGATGGAAAGAAGCATATTCTGATCCTTCATAACTGTCA
67552 GCTGGGTATGACAGGAGAGGTTTCCTTCCAGGCTGCTAATGCCAAATCTGCAGCCAATCTGAAAGTGAAA
67553 GAATTGCCTCTTATCTTCATCACACCTCTCAGTGATGTTAAAGTCTTCGAGAAAGATGAGGCTAAGTTTG
67554 AGTGTGAAGTATCCAGGGAGCCCAAAACATTCCGTTGGCTAAAAGGAACCCAGGAAATCACAGGTGATGA
67555 CAGATTTGAGCTTATAAAGGATGGCACTAAGCATTCAATGGTGATCAAGTCAGCTGCTTTTGAAGATGAA
67556 GCAAAATACATGTTTGAAGCTGAAGATAAGCACACAAGTGGCAAACTGATCATTGAAGGAATCCGGCTCA
67557 AATTCCTCACCCCTCTCAAAGATGTAACTGCCAAAGAGAAGGAAAGTGCTGTATTTACTGTGGAGTTATC
67558 TCATGATAACATCCGAGTTAAATGGTTCAAGAATGACCAGCGCCTACACACCACCAGGTCGGTCTCAATG
67559 CAAGACGAAGGGAAAACTCATTCGATCACATTCAAAGACCTGTCTATTGATGACACCTCCCAAATTAGAG
67560 TAGAAGCTATGGGGATGAGTTCAGAAGCTAAACTCACTGTGCTTGAGGGAGACCCATATTTTACAGGAAA
67561 ACTTCAAGATTATACTGGTGTAGAGAAAGATGAAGTTATTCTACAGTGTGAAATTAGCAAAGCAGATGCA
67562 CCAGTGAAATGGTTTAAGGATGGGAAGGAAATAAAGCCATCCAAAAATGCTGTTATTAAGGCAGATGGCA
67563 AGAAACGCATGCTAATCCTAAAGAAAGCCTTGAAATCAGATATTGGACAGTACACCTGTGACTGTGGGAC
67564 AGATAAGACCTCAGGAAAACTTGACATTGAGGATCGGGAAATTAAACTGGTGCGACCCCTGCACAGTGTG
67565 GAGGTGATGGAGACTGAGACAGCACGCTTTGAAACCGAAATCTCTGAAGATGATATCCACGCCAACTGGA
67566 AACTCAAGGGAGAGGCCCTACTCCAAACACCTGATTGTGAAATTAAGGAAGAAGGCAAAATACACTCCCT
67567 TGTTTTGCACAACTGTCGCCTGGACCAGACGGGTGGGGTGGATTTCCAAGCTGCCAATGTTAAATCTAGT
67568 GCCCACCTCCGAGTTAAGCCACGAGTAATTGGTCTTCTGAGGCCTTTAAAGGATGTCACCGTGACTGCAG
67569 GGGAAACAGCCACCTTCGACTGCGAGCTCTCCTACGAAGATATCCCAGTGGAATGGTATCTCAAAGGGAA
67570 GAAACTAGAGCCCAGCGATAAGGTGGTCCCACGTTCAGAAGGAAAAGTTCATACACTTACTCTGAGGGAT
67571 GTAAAGTTAGAAGATGCTGGGGAAGTCCAACTAACAGCAAAAGATTTCAAAACTCACGCCAACCTCTTTG
67572 TGAAAGAACCCCCAGTTGAATTCACTAAGCCTCTTGAGGACCAGACGGTCGAAGAGGGAGCCACTGCAGT
67573 GCTGGAGTGTGAAGTCTCCAGAGAAAATGCTAAGGTGAAATGGTTCAAAAATGGGACAGAAATCCTCAAA
67574 AGCAAGAAGTATGAAATTGTTGCTGATGGCAGGGTCAGAAAACTTGTTATACATGACTGTACCCCAGAGG
67575 ATATTAAAACATACACTTGTGATGCTAAGGATTTTAAGACTTCCTGTAACCTGAATGTCGTGCCTCCTCA
67576 TGTGGAATTCTTAAGACCACTCACCGACCTTCAAGTTAGAGAAAAAGAAATGGCTCGATTTGAGTGTGAA
67577 CTTTCCCGAGAAAATGCTAAGGTTAAGTGGTTTAAAGATGGTGCTGAAATTAAAAAGGGCAAAAAATATG
67578 ACATCATATCCAAGGGAGCAGTGCGCATTCTTGTCATCAACAAATGTCTACTGGATGATGAAGCTGAATA
67579 TTCCTGTGAAGTAAGGACAGCGAGAACTTCTGGCATGCTGACAGTTCTGGAAGAAGAAGCTGTCTTTACC
67580 AAAAATCTTGCCAACATTGAAGTTAGTGAAACAGACACTATAAAACTGGTTTGTGAAGTCTCCAAACCTG
67581 GCGCAGAAGTGATTTGGTATAAAGGGGATGAGGAGATCATTGAAACAGGAAGATATGAAATACTGACTGA
67582 AGGACGGAAGAGAATCCTGGTCATTCAGAACGCTCACCTTGAGGATGCTGGCAACTACAACTGTCGACTC
67583 CCAAGCTCTCGAACCGATGGCAAAGTCAAAGTACATGAACTGGCTGCTGAATTTATCTCAAAGCCTCAAA
67584 ACCTTGAAATACTTGAAGGAGAAAAGGCTGAATTTGTCTGCTCTATATCAAAAGAAAGCTTTCCAGTCCA
67585 GTGGAAGAGGGATGATAAGACACTTGAATCTGGAGATAAATATGACGTTATTGCTGATGGTAAAAAGAGG
67586 GTCCTAGTTGTGAAAGATGCCACATTACAAGATATGGGCACTTACGTTGTCATGGTAGGGGCCGCCAGAG
67587 CAGCAGCTCACTTGACAGTCATTGAAAAACTCAGGATCGTAGTTCCTCTTAAGGACACCCGGGTGAAGGA
67588 ACAACAGGAAGTTGTCTTCAACTGTGAAGTCAATACTGAAGGTGCCAAAGCCAAATGGTTCAGAAATGAA
67589 GAAGCTATATTTGATAGTTCAAAATACATCATTCTCCAAAAAGACCTAGTCTACACCCTCAGAATTAGAG
67590 ATGCACACTTAGATGACCAAGCCAACTATAATGTGTCTTTGACCAATCACAGAGGTGAAAATGTTAAAAG
67591 TGCAGCCAATCTAATAGTAGAAGAGGAAGACCTTAGGATTGTTGAGCCTCTTAAAGATATTGAAACAATG
67592 GAGAAGAAATCTGTCACATTCTGGTGCAAGGTGAATCGTCTCAATGTAACACTGAAGTGGACCAAAAATG
67593 GTGAAGAAGTGCCTTTTGACAACCGTGTCTCATACAGAGTTGATAAGTACAAGCACATGTTAACCATTAA
67594 AGACTGTGGCTTCCCAGATGAAGGTGAATACATTGTCACTGCTGGACAAGATAAATCTGTTGCTGAGCTT
67595 CTCATCATAGAAGCCCCGACAGAATTTGTGGAACACTTGGAAGATCAGACAGTCACTGAGTTCGATGACG
67596 CTGTCTTCTCCTGCCAGCTCTCCAGAGAGAAAGCCAATGTAAAATGGTACAGAAATGGGAGAGAAATCAA
67597 AGAAGGCAAAAAATACAAATTTGAAAAAGATGGAAGTATACACAGACTCATTATAAAAGATTGCAGGCTG
67598 GATGATGAGTGTGAATATGCTTGCGGGGTAGAAGACAGGAAGTCTCGTGCTAGACTTTTTGTGGAAGAAA
67599 TTCCTGTTGAGATCATCAGGCCTCCACAAGATATTCTTGAAGCCCCTGGTGCTGATGTTGTCTTTTTAGC
67600 AGAACTCAATAAAGATAAGGTGGAAGTCCAATGGCTAAGAAATAACATGGTTGTTGTCCAGGGTGATAAA
67601 CACCAGATGATGAGTGAAGGAAAGATACATCGACTACAGATTTGTGATATTAAGCCCCGTGACCAGGGTG
67602 AATACAGATTTATTGCCAAAGACAAAGAAGCCAGAGCTAAGCTTGAACTGGCAGCTGCACCAAAAATCAA
67603 GACAGCTGACCAAGACCTTGTGGTTGATGTTGGCAAGCCTCTGACAATGGTGGTGCCATATGATGCCTAC
67604 CCCAAAGCAGAAGCTGAATGGTTTAAAGAAAATGAACCTTTATCTACAAAAACCATTGATACTACGGCTG
67605 AACAAACTTCTTTCAGAATTTTAGAAGCCAAGAAAGGAGACAAAGGGAGGTATAAAATTGTGCTTCAGAA
67606 CAAACATGGAAAAGCAGAAGGATTCATCAATTTAAAAGTTATTGATGTTCCTGGGCCAGTACGTAACTTA
67607 GAAGTGACAGAAACATTTGATGGTGAAGTGAGCCTTGCTTGGGAAGAACCTTTAACTGATGGTGGAAGCA
67608 AAATCATAGGTTACGTTGTTGAAAGACGTGACATTAAGAGAAAGACCTGGGTTCTGGCCACAGACCGTGC
67609 AGAGAGTTGTGAGTTTACTGTCACTGGTCTACAGAAAGGAGGAGTTGAGTACCTATTCCGTGTGAGTGCA
67610 AGAAACAGAGTTGGCACTGGTGAGCCAGTAGAAACTGACAATCCTGTAGAAGCAAGGAGTAAATATGATG
67611 TTCCAGGCCCTCCTTTGAATGTAACCATCACTGATGTGAATCGATTTGGTGTCTCACTGACATGGGAACC
67612 ACCAGAGTATGATGGAGGTGCTGAGATCACAAACTACGTCATTGAATTAAGAGACAAGACTTCTATCAGG
67613 TGGGATACTGCCATGACTGTGAGAGCTGAAGACCTGTCTGCAACTGTTACTGATGTGGTAGAAGGACAGG
67614 AGTACAGTTTCCGAGTGAGAGCCCAAAATCGAATTGGAGTTGGAAAACCAAGTGCAGCCACACCCTTCGT
67615 CAAAGTTGCTGATCCAATTGAGAGACCAAGTCCTCCTGTAAACCTAACTTCCTCAGATCAGACTCAGTCA
67616 TCAGTTCAGCTCAAATGGGAACCTCCTCTGAAAGATGGAGGAAGCCCAATATTAGGCTATATAATTGAGC
67617 GATGCGAAGAAGGAAAAGATAATTGGATTCGTTGCAATATGAAACTTGTCCCTGAACTGACTTACAAGGT
67618 TACCGGATTGGAAAAAGGAAATAAATATTTATATAGAGTATCTGCAGAAAATAAAGCTGGTGTTTCAGAT
67619 CCATCTGAAATTCTTGGTCCTCTCACCGCTGACGATGCATTTGTTGAACCAACAATGGATTTAAGTGCAT
67620 TTAAAGATGGTCTGGAAGTTATTGTCCCAAATCCTATCACGATCCTGGTTCCAAGTACAGGCTATCCAAG
67621 GCCAACTGCAACCTGGTGTTTTGGAGATAAAGTACTAGAAACAGGGGACCGGGTGAAAATGAAGACCTTG
67622 TCTGCCTATGCCGAACTTGTCATTTCTCCAAGTGAACGTTCAGACAAGGGCATTTATACACTGAAATTAG
67623 AAAACCGTGTGAAAACAATTTCTGGGGAAATTGATGTCAATGTAATTGCTCGCCCAAGTGCACCCAAAGA
67624 ATTGAAATTTGGTGATATAACCAAGGACTCAGTACATTTGACTTGGGAACCACCTGATGATGATGGAGGA
67625 AGTCCGTTAACTGGATACGTTGTTGAAAAACGAGAAGTCAGCCGGAAAACATGGACTAAAGTTATGGACT
67626 TTGTGACTGATCTAGAATTCACAGTTCCTGATCTTGTTCAAGGAAAAGAGTACTTATTTAAAGTTTGTGC
67627 TCGTAACAAATGTGGCCCTGGAGAACCTGCATATGTTGATGAACCTGTAAATATGTCAACTCCTGCAACG
67628 GTACCTGACCCACCAGAGAATGTTAAATGGAGAGATCGAACAGCCAATAGCATCTTCTTAACATGGGATC
67629 CACCTAAAAATGATGGTGGTTCACGCATCAAAGGATATATAGTTGAAAGATGTCCACGTGGTTCTGATAA
67630 ATGGGTTGCCTGTGGAGAACCTGTTGCAGAAACAAAAATGGAAGTGACAGGTCTTGAGGAAGGCAAATGG
67631 TATGCCTACCGCGTGAAGGCCTTAAACAGGCAGGGTGCTAGCAAACCAAGCAGACCCACAGAGGAAATCC
67632 AGGCTGTGGACACACAAGAGGCCCCAGAAATCTTCCTCGATGTGAAGCTCCTTGCTGGTCTCACTGTAAA
67633 AGCTGGGACCAAGATTGAACTTCCTGCCACCGTAACCGGAAAACCTGAACCTAAAATAACTTGGACAAAG
67634 GCTGATATGATTCTGAAGCAGGACAAAAGAATTACCATTGAAAATGTCCCTAAGAAATCCACAGTGACTA
67635 TTGTTGATAGTAAGAGAAGTGACACTGGCACATATATCATTGAGGCTGTGAATGTGTGTGGCCGGGCCAC
67636 TGCTGTGGTGGAAGTGAACGTCTTAGATAAACCCGGACCACCAGCTGCCTTTGACATCACAGATGTAACC
67637 AATGAGTCATGTCTTCTAACATGGAACCCACCACGCGATGATGGTGGATCTAAGATCACAAACTATGTTG
67638 TGGAGAGACGAGCAACTGATAGTGAAGTGTGGCACAAGCTCTCATCCACCGTCAAGGATACAAACTTCAA
67639 GGCCACCAAATTAATCCCCAATAAAGAGTACATCTTCAGAGTTGCTGCAGAAAACATGTATGGTGTTGGT
67640 GAACCAGTTCAGGCCTCTCCAATAACAGCCAAATATCAGTTTGATCCACCTGGTCCTCCAACTCGCCTAG
67641 AACCTTCTGATATCACTAAAGACGCAGTGACTCTCACATGGTGTGAGCCAGATGATGATGGTGGCAGCCC
67642 AATCACAGGATACTGGGTTGAAAGACTGGATCCTGATACAGATAAATGGGTTAGATGCAATAAGATGCCA
67643 GTAAAGGACACAACATACAGAGTGAAAGGTCTCACTAATAAGAAAAAATACAGATTCCGTGTGTTGGCTG
67644 AAAATCTTGCTGGACCTGGAAAACCAAGCAAATCAACTGAACCAATCTTAATAAAGGATCCCATAGATCC
67645 TCCATGGCCCCCTGGAAAACCAACTGTAAAAGATGTAGGCAAAACATCAGTAAGGTTGAATTGGACAAAA
67646 CCAGAACATGATGGAGGTGCAAAGATTGAGTCTTATGTCATTGAAATGCTGAAGACTGGAACAGATGAGT
67647 GGGTCAGAGTGGCGGAAGGGGTTCCCACCACTCAGCACTTGCTCCCAGGGCTCATGGAAGGACAGGAATA
67648 CTCATTCCGAGTTAGAGCTGTGAATAAGGCTGGGGAAAGTGAACCCAGTGAACCCAGTGACCCTGTGCTT
67649 TGCCGGGAGAAGCTATATCCTCCATCACCACCACGCTGGCTTGAAGTTATTAATATCACAAAAAATACAG
67650 CAGACCTAAAATGGACAGTTCCTGAGAAAGATGGAGGGTCCCCCATCACCAACTACATTGTGGAAAAGAG
67651 AGACGTCAGGCGAAAAGGCTGGCAAACAGTGGATACCACTGTCAAGGACACCAAGTGCACAGTCACCCCA
67652 CTGACTGAGGGCTCTTTATATGTGTTCCGAGTTGCTGCAGAAAATGCTATAGGACAAAGCGACTACACCG
67653 AAATTGAGGACTCTGTGCTGGCCAAAGACACCTTTACCACTCCTGGACCACCCTACGCCCTGGCAGTGGT
67654 TGATGTGACAAAACGACATGTTGACCTAAAGTGGGAGCCACCTAAAAATGATGGTGGAAGACCAATACAG
67655 AGATATGTCATTGAGAAGAAAGAAAGGTTAGGTACCCGTTGGGTGAAAGCTGGAAAGACTGCAGGACCTG
67656 ACTGTAACTTCAGAGTAACTGATGTCATCGAAGGAACAGAGGTCCAGTTTCAGGTTCGGGCTGAAAATGA
67657 AGCTGGAGTTGGCCACCCAAGTGAACCCACAGAAATCCTATCCATTGAAGATCCAACAAGTCCTCCCTCA
67658 CCACCCCTTGACCTACATGTGACTGATGCTGGGAGAAAACACATTGCCATTGCTTGGAAGCCTCCAGAGA
67659 AAAATGGTGGAAGTCCTATCATAGGATACCATGTTGAAATGTGTCCAGTAGGCACTGAGAAATGGATGAG
67660 AGTTAATTCTCGCCCAATAAAGGACTTGAAATTCAAGGTTGAAGAAGGTGTTGTTCCTGACAAAGAATAT
67661 GTCCTGAGAGTGAGAGCAGTCAATGCTATTGGTGTCAGCGAGCCATCTGAAATCTCTGAAAATGTGGTTG
67662 CCAAAGACCCAGACTGCAAGCCAACAATTGACCTGGAGACTCATGACATTATTGTTATTGAAGGTGAAAA
67663 GTTAAGCATTCCTGTTCCCTTCAGAGCTGTCCCAGTTCCAACTGTTAGTTGGCATAAAGATGGCAAAGAA
67664 GTTAAAGCAAGTGATAGATTAACAATGAAGAATGATCACATCTCTGCACACCTTGAAGTTCCCAAGAGTG
67665 TCCGTGCAGATGCCGGAATTTATACCATTACACTGGAGAATAAGCTCGGCTCAGCAACAGCCTCAATCAA
67666 TGTCAAAGTCATAGGCCTACCTGGACCATGCAAAGATATTAAAGCAAGTGACATTACCAAGAGTTCTTGT
67667 AAGTTAACTTGGGAACCTCCAGAATTTGATGGTGGAACCCCAATTCTTCATTATGTCCTGGAGCGCAGAG
67668 AAGCTGGGAGGAGAACATATATACCAGTCATGTCTGGTGAGAACAAACTGTCATGGACTGTGAAGGATCT
67669 CATACCAAATGGTGAATACTTCTTCCGTGTTAAAGCAGTCAACAAGGTTGGTGGAGGAGAATATATTGAA
67670 CTGAAAAATCCAGTCATTGCTCAAGATCCAAAGCAACCCCCTGATCCACCTGTAGATGTAGAGGTTCATA
67671 ATCCTACAGCGGAGGCAATGACTATTACATGGAAGCCACCTTTGTATGATGGAGGGAGCAAGATAATGGG
67672 CTACATCATAGAGAAGATTGCTAAGGGTGAAGAAAGGTGGAAGAGATGCAATGAACACCTGGTACCAATC
67673 CTGACCTATACAGCAAAAGGACTTGAAGAGGGGAAAGAGTACCAATTCCGTGTGCGAGCAGAGAACGCCG
67674 CGGGTATTAGTGAACCTTCTCGGGCTACTCCTCCAACCAAAGCTGTAGATCCCATTGATGCCCCCAAAGT
67675 CATTCTGAGAACAAGCCTAGAAGTGAAACGAGGTGATGAAATAGCACTTGATGCAAGTATTTCTGGATCA
67676 CCTTACCCAACTATTACATGGATAAAGGATGAAAATGTTATTGTACCAGAGGAAATTAAGAAGCGTGCAG
67677 CACCCTTGGTTAGGAGAAGGAAGGGTGAAGTTCAAGAAGAAGAACCATTTGTCCTGCCTCTGACACAGCG
67678 TTTGAGTATTGACAACAGCAAAAAGGGAGAATCTCAGCTACGCGTCCGAGATTCTCTCCGACCTGACCAT
67679 GGTCTGTATATGATCAAAGTTGAAAATGACCACGGTATTGCAAAAGCTCCTTGTACTGTCAGTGTGTTAG
67680 ATACACCGGGACCACCAATCAACTTTGTATTTGAAGATATCAGAAAGACCTCAGTCCTTTGTAAATGGGA
67681 ACCACCCCTTGATGATGGTGGCAGTGAAATCATAAACTACACTTTGGAAAAGAAAGACAAGACAAAACCC
67682 GACTCAGAATGGATTGTTGTCACTTCAACACTTAGACATTGCAAATATTCAGTAACAAAACTGATTGAAG
67683 GAAAAGAGTACCTCTTCCGTGTAAGAGCTGAAAACAGATTTGGGCCAGGTCCACCATGTGTTTCAAAGCC
67684 ACTTGTGGCTAAAGATCCATTTGGACCACCTGATGCACCAGATAAGCCCATTGTGGAAGATGTTACCAGC
67685 AACAGTATGCTAGTGAAATGGAATGAACCAAAAGATAATGGAAGCCCCATTTTGGGTTACTGGCTTGAAA
67686 AACGTGAAGTTAACAGTACACATTGGTCTCGTGTCAACAAAAGCCTTCTGAATGCCTTGAAAGCCAATGT
67687 AGATGGCTTATTAGAAGGACTCACCTATGTCTTCAGAGTATGTGCTGAAAATGCAGCTGGACCTGGAAAG
67688 TTCAGTCCACCTTCAGATCCCAAAACAGCACATGATCCAATCTCTCCTCCTGGGCCACCTATCCCAAGAG
67689 TCACTGACACAAGCTCTACAACTATTGAACTAGAATGGGAACCCCCAGCTTTCAATGGTGGTGGGGAAAT
67690 TGTTGGCTATTTTGTTGATAAGCAGTTGGTTGGCACAAATGAATGGTCACGCTGCACAGAGAAGATGATC
67691 AAGGTCCGTCAGTACACCGTCAAAGAAATCCGAGAGGGTGCTGATTACAAACTTCGGGTGAGTGCTGTCA
67692 ATGCCGCAGGGGAAGGACCGCCTGGAGAAACACAACCTGTTACTGTGGCTGAACCACAAGAGCCTCCAGC
67693 TGTGGAACTGGATGTTTCTGTCAAGGGTGGAATACAAATAATGGCTGGGAAGACTCTTAGAATTCCAGCT
67694 GTGGTGACTGGTCGCCCTGTACCTACAAAAGTATGGACCAAAGAAGAAGGGGAGCTGGATAAAGACCGTG
67695 TTGTAATAGACAACGTTGGAACCAAATCTGAACTAATTATCAAGGATGCACTGCGAAAAGACCATGGCAG
67696 ATATGTGATTACAGCTACAAATAGCTGTGGTTCCAAATTTGCAGCAGCCAGGGTAGAAGTTTTTGATGTC
67697 CCTGGTCCAGTTCTTGACTTAAAACCTGTTGTAACAAACAGAAAAATGTGTCTACTTAACTGGTCTGATC
67698 CAGAAGATGATGGAGGAAGTGAAATAACAGGCTTTATCATTGAAAGAAAAGATGCCAAGATGCATACTTG
67699 GAGACAACCAATAGAGACTGAGAGATCTAAATGTGACATCACAGGTCTGCTTGAGGGACAAGAATATAAG
67700 TTCCGTGTTATTGCCAAGAACAAGTTTGGCTGTGGCCCTCCTGTTGAAATAGGACCAATTCTTGCAGTTG
67701 ATCCACTAGGTCCTCCAACATCTCCAGAGAGGCTCACATACACTGAAAGGACAAAGTCCACTATCACACT
67702 TGACTGGAAAGAGCCCCGCAGTAATGGTGGCAGTCCCATCCAAGGATATATCATTGAAAAACGGCGTCAT
67703 GACAAACCTGACTTTGAAAGAGTTAACAAGCGACTCTGCCCAACCACATCTTTTCTGGTTGAAAATCTTG
67704 ATGAACACCAAATGTATGAGTTCCGTGTCAAAGCTGTCAATGAAATTGGTGAAAGTGAACCATCCCTACC
67705 TCTTAATGTAGTCATACAAGATGATGAAGTGCCTCCAACTATTAAGTTGCGTCTGAGTGTTCGAGGAGAC
67706 ACTATCAAAGTTAAGGCAGGAGAGCCTGTCCACATCCCTGCAGATGTGACAGGCCTTCCAATGCCTAAGA
67707 TTGAATGGTCCAAAAATGAAACTGTAATTGAAAAACCCACTGATGCACTTCAGATAACCAAGGAAGAGGT
67708 ATCCCGAAGTGAGGCAAAAACTGAGCTTAGCATTCCCAAAGCGGTCCGGGAGGACAAAGGCACTTACACA
67709 GTTACTGCTTCCAATCGCCTTGGCTCAGTGTTCCGAAATGTTCACGTTGAAGTATATGACCGCCCATCCC
67710 CACCAAGAAATCTTGCTGTTACTGACATTAAAGCTGAATCTTGCTACTTGACATGGGATGCCCCTCTTGA
67711 TAATGGTGGCAGTGAAATCACCCATTATGTTATTGACAAACGTGATGCAAGTAGGAAGAAAGCAGAATGG
67712 GAGGAAGTCACCAACACTGCTGTAGAGAAAAGATATGGGATCTGGAAACTTATCCCCAATGGTCAGTATG
67713 AGTTCCGAGTCAGGGCAGTGAATAAATATGGAATCAGTGATGAGTGCAAATCAGATAAAGTAGTCATTCA
67714 AGATCCTTATCGCCTTCCTGGACCTCCAGGAAAACCAAAAGTTTTGGCACGCACCAAAGGATCAATGCTA
67715 GTGAGCTGGACTCCTCCTTTGGACAATGGTGGCTCTCCAATTACTGGCTACTGGCTGGAGAAAAGAGAAG
67716 AGGGAAGTCCTTATTGGTCACGTGTTAGCCGAGCACCAATAACCAAAGTGGGATTGAAAGGCGTGGAATT
67717 TAATGTTCCTCGTTTGCTTGAAGGCGTTAAATACCAGTTCAGAGCCATGGCAATAAATGCTGCAGGAATT
67718 GGTCCTCCCAGTGAACCATCAGATCCAGAGGTTGCAGGAGATCCCATATTTCCACCGGGGCCACCTTCTT
67719 GCCCAGAAGTTAAAGATAAAACGAAGTCAAGCATCTCACTAGGATGGAAACCTCCAGCCAAAGATGGTGG
67720 CAGCCCAATCAAAGGATACATTGTAGAAATGCAAGAAGAAGGTACTACTGACTGGAAAAGAGTAAATGAA
67721 CCAGACAAACTTATAACTACCTGTGAATGTGTGGTGCCTAATCTGAAAGAGCTCAGGAAGTACAGATTCA
67722 GAGTGAAAGCTGTCAATGAAGCTGGTGAATCTGAACCAAGTGATACAACTGGGGAGATCCCTGCCACTGA
67723 TATTCAAGAGGAACCAGAAGTTTTCATTGACATTGGAGCACAGGACTGTCTGGTTTGTAAAGCTGGCTCA
67724 CAGATTAGGATTCCTGCTGTCATCAAGGGACGCCCAACACCAAAATCATCTTGGGAATTTGATGGAAAGG
67725 CAAAGAAAGCAATGAAGGATGGAGTTCATGACATACCCGAAGATGCACAGCTGGAGACTGCTGAAAACTC
67726 CTCAGTAATTATTATTCCGGAGTGTAAACGATCTCATACAGGCAAATACAGCATCACAGCCAAGAATAAA
67727 GCAGGACAAAAGACTGCAAATTGCAGAGTTAAAGTCATGGATGTACCAGGCCCACCCAAAGATCTGAAAG
67728 TCAGTGATATCACAAGGGGTAGTTGCAGACTTTCATGGAAGATGCCAGACGACGATGGAGGAGACAGGAT
67729 CAAAGGCTATGTTATTGAGAAGAGGACTATTGATGGAAAAGCCTGGACCAAAGTCAATCCAGACTGTGGA
67730 AGCACCACATTTGTAGTGCCTGATCTCCTCTCTGAACAGCAATATTTCTTCCGTGTGCGAGCAGAAAACC
67731 GTTTTGGTATTGGCCCACCTGTGGAAACCATTCAGAGGACCACTGCCAGAGATCCGATATATCCTCCTGA
67732 TCCTCCTATTAAACTCAAGATTGGCCTCATCACAAAGAACACAGTGCATCTGTCATGGAAACCCCCGAAG
67733 AATGATGGGGGCTCCCCTGTTACCCACTATATTGTTGAGTGCCTTGCATGGGACCCTACTGGGACAAAGA
67734 AAGAAGCCTGGAGGCAGTGCAATAAGCGTGATGTGGAAGAACTGCAATTTACTGTTGAAGACCTAGTAGA
67735 AGGTGGGGAATATGAATTCCGAGTCAAAGCTGTCAATGCTGCAGGAGTCAGCAAGCCTTCAGCCACTGTT
67736 GGGCCCTGTGACTGTCAAAGACCAGACATGCCACCATCAATTGATCTAAAAGAATTCATGGAGGTTGAAG
67737 AAGGAACCAATGTTAACATTGTGGCCAAAATTAAAGGTGTGCCATTCCCGACACTAACCTGGTTTAAAGC
67738 TCCTCCAAAGAAGCCTGATAACAAAGAACCTGTTCTCTATGACACCCATGTCAACAAACTGGTGGTAGAT
67739 GATACTTGCACTTTAGTTATTCCGCAGTCTCGCAGGAGTGACACTGGCTTATATACCATCACAGCTGTAA
67740 ATAATCTGGGAACAGCATCAAAGGAGATGAGACTGAATGTCCTGGGTCGTCCTGGCCCTCCAGTGGGACC
67741 CATAAAATTTGAATCTGTTTCAGCAGATCAAATGACACTATCTTGGTTTCCACCTAAAGATGATGGTGGG
67742 TCTAAGATTACAAACTATGTAATTGAGAAAAGAGAAGCTAACAGGAAGACATGGGTCCATGTCTCCAGTG
67743 AACCTAAGGAGTGCACGTACACGATTCCCAAATTGCTAGAAGGCCATGAATATGTATTCCGAATCATGGC
67744 CCAGAATAAATATGGCATTGGAGAACCTCTTGACAGTGAACCTGAAACAGCAAGAAACCTCTTCTCTGTC
67745 CCTGGAGCACCAGATAAACCAACAGTTAGCAGCGTGACTCGTAACTCCATGACTGTCAACTGGGAAGAGC
67746 CAGAATATGATGGAGGCTCTCCTGTGACAGGGTACTGGCTGGAAATGAAAGACACCACTTCAAAGAGATG
67747 GAAGAGAGTTAACCGAGATCCTATCAAAGCCATGACTTTGGGTGTTTCTTATAAAGTGACTGGTCTTATT
67748 GAAGGTTCCGACTATCAATTCCGGGTATATGCAATCAATGCTGCTGGCGTGGGTCCAGCAAGTCTGCCAT
67749 CAGACCCAGCGACTGCTAGAGATCCAATTGCCCCTCCTGGTCCTCCATTTCCCAAAGTGACAGATTGGAC
67750 TAAATCATCTGCAGATCTGGAGTGGTCTCCCCCACTAAAAGATGGTGGATCCAAAGTAACTGGATACATC
67751 GTTGAATATAAAGAAGAAGGAAAAGAAGAATGGGAAAAGGGTAAAGATAAAGAAGTGAGAGGAACAAAGC
67752 TCGTTGTGACAGGATTAAAGGAAGGAGCATTCTACAAATTTAGAGTTAGTGCAGTCAACATTGCTGGCAT
67753 TGGAGAACCTGGAGAGGTCACAGATGTCATTGAAATGAAGGACAGACTTGTTTCACCTGACCTTCAGCTA
67754 GATGCCAGTGTCAGAGATAGAATTGTTGTCCATGCTGGAGGGGTGATCCGAATCATTGCCTATGTGTCTG
67755 GAAAGCCTCCTCCAACCGTCACCTGGAACATGAATGAAAGAACCTTACCTCAAGAAGCCACCATTGAGAC
67756 CACAGCCATTAGCTCATCCATGGTCATCAAGAACTGCCAGAGGAGCCATCAAGGCGTCTATTCTCTTCTT
67757 GCCAAAAATGAAGCCGGAGAAAGAAAGAAGACAATTATTGTTGATGTATTAGATGTTCCAGGTCCCGTTG
67758 GAACACCATTCCTAGCTCACAACCTAACCAATGAGTCCTGCAAACTGACATGGTTTTCTCCAGAAGATGA
67759 TGGAGGCTCTCCAATCACCAATTATGTCATTGAAAAGCGTGAATCTGACCGCAGAGCATGGACCCCAGTG
67760 ACATATACAGTTACCCGACAAAATGCTACTGTCCAGGGTCTCATTCAAGGAAAAGCCTACTTTTTCCGAA
67761 TTGCGGCTGAAAATAGTATTGGCATGGGTCCATTTGTTGAGACATCAGAGGCACTTGTTATCAGAGAGCC
67762 AATAACTGTACCAGAGCGTCCTGAAGACCTGGAAGTCAAAGAAGTTACTAAAAATACTGTAACTTTGACT
67763 TGGAATCCTCCTAAGTATGATGGTGGGTCAGAAATTATTAACTATGTCCTAGAAAGTCGGCTCATTGGGA
67764 CTGAGAAGTTCCACAAAGTTACAAATGACAACTTGCTTAGCAGAAAATACACTGTTAAAGGCTTAAAAGA
67765 AGGTGATACCTATGAGTACCGTGTCAGTGCTGTCAACATTGTTGGACAAGGCAAACCATCATTTTGCACC
67766 AAACCAATTACTTGCAAGGATGAGCTGGCACCCCCAACGCTTCACCTCGACTTCAGAGATAAGCTCACGA
67767 TTCGAGTTGGTGAAGCTTTTGCCCTCACTGGCCGTTACTCAGGCAAACCAAAGCCTAAGGTTTCCTGGTT
67768 CAAAGATGAAGCTGATGTGCTGGAAGATGATCGCACTCATATAAAGACTACACCAGCAACACTTGCTTTA
67769 GAGAAGATCAAGGCCAAACGTTCAGATTCCGGCAAATACTGTGTGGTTGTGGAGAACAGTACAGGCTCTA
67770 GGAAAGGTTTCTGTCAAGTTAATGTTGTTGACCGTCCTGGACCACCAGTAGGACCAGTTAGTTTTGATGA
67771 GGTGACCAAAGATTACATGGTTATCTCTTGGAAGCCTCCTTTAGATGATGGAGGCAGTAAAATCACCAAT
67772 TATATTATTGAGAAGAAGGAAGTGGGTAAAGACGTCTGGATGCCAGTGACATCTGCAAGTGCTAAAACAA
67773 CATGCAAAGTTTCTAAACTACTTGAAGGAAAAGATTATATTTTCCGGATACATGCTGAAAATCTGTATGG
67774 AATAAGTGATCCTCTGGTGTCTGATTCAATGAAAGCCAAAGATCGTTTCAGGGTTCCTGATGCACCTGAT
67775 CAGCCAATTGTTACAGAAGTTACCAAAGACTCTGCATTAGTAACCTGGAATAAGCCACATGATGGAGGAA
67776 AACCCATCACAAACTACATCCTGGAAAAGAGAGAAACTATGTCTAAACGATGGGCTAGAGTTACCAAAGA
67777 TCCTATTCATCCATACACTAAATTTAGGGTTCCTGATCTTCTAGAAGGATGTCAGTATGAATTCCGGGTT
67778 TCTGCAGAAAATGAAATTGGTATTGGAGATCCAAGCCCACCATCCAAACCAGTCTTTGCTAAAGATCCAA
67779 TTGCTAAACCAAGTCCACCTGTTAATCCTGAAGCAATAGATACAACATGCAATTCAGTCGATCTAACTTG
67780 GCAGCCACCACGTCATGATGGTGGGAGCAAGATTCTGGGTTATATTGTTGAGTACCAGAAAGTTGGAGAT
67781 GAAGAGTGGAGAAGAGCCAATCACACCCCTGAGTCATGTCCTGAAACTAAATATAAAGTCACCGGTCTTC
67782 GGGACGGTCAAACCTATAAGTTTAGAGTGTTAGCAGTCAATGCAGCTGGTGAATCAGATCCAGCTCATGT
67783 TCCGGAGCCAGTCCTAGTAAAAGACAGGCTTGAACCCCCTGAGTTGATTCTTGATGCCAACATGGCAAGA
67784 GAACAACACATTAAAGTTGGTGATACTCTAAGACTTAGTGCCATCATCAAAGGAGTGCCATTCCCAAAAG
67785 TAACTTGGAAAAAAGAAGACAGAGATGCTCCAACTAAAGCAAGAATTGATGTGACTCCAGTTGGTAGCAA
67786 GCTTGAAATTCGTAATGCTGCCCATGAAGATGGTGGAATTTATTCTTTAACAGTGGAGAATCCAGCTGGT
67787 TCAAAAACTGTCTCAGTAAAAGTACTTGTATTAGATAAACCTGGGCCACCTAGAGATCTGGAAGTCAGTG
67788 AAATTAGGAAAGATTCATGTTACCTTACTTGGAAAGAACCACTGGATGATGGTGGTTCTGTTATTACCAA
67789 TTATGTGGTTGAGAGGAGAGATGTTGCCAGCGCCCAGTGGTCACCTCTCTCAGCTACATCAAAGAAAAAG
67790 AGTCACTTCGCTAAGCATCTGAATGAAGGCAACCAGTACCTCTTCCGAGTAGCTGCGGAGAACCAGTATG
67791 GACGTGGTCCTTTTGTTGAAACACCAAAACCAATCAAGGCTTTGGATCCTCTCCATCCCCCAGGGCCACC
67792 CAAGGACCTGCACCATGTAGATGTTGACAAGACTGAAGTCTCCCTAGTCTGGAATAAGCCGGATCGTGAT
67793 GGTGGTTCTCCAATCACTGGATATTTGGTAGAATATCAAGAAGAAGGCACCCAGGACTGGATTAAATTTA
67794 AGACTGTGACAAACTTAGAGTGTGTGGTTACTGGACTACAACAAGGAAAGACCTATAGATTCCGTGTAAA
67795 AGCTGAAAACATTGTGGGTCTTGGTCTCCCTGACACAACTATCCCGATAGAATGTCAAGAAAAACTAGTG
67796 CCTCCATCCGTGGAGCTAGATGTGAAATTAATTGAAGGTCTTGTGGTAAAGGCTGGAACCACAGTCAGAT
67797 TCCCTGCTATTATAAGAGGTGTGCCTGTTCCTACTGCAAAGTGGACAACCGATGGGAGTGAGATTAAAAC
67798 CGATGAGCACTACACAGTTGAAACAGACAACTTCTCATCAGTACTTACCATTAAGAACTGCTTAAGGAGA
67799 GACACTGGGGAATATCAAATCACAGTTTCCAATGCAGCCGGTAGCAAAACAGTAGCCGTACATCTTACTG
67800 TTCTTGATGTTCCTGGGCCACCAACAGGTCCTATTAATATTCTGGATGTTACTCCTGAACACATGACTAT
67801 CTCATGGCAGCCACCTAAGGATGATGGAGGAAGCCCTGTGATAAATTATATTGTTGAGAAACAAGATACA
67802 AGGAAAGACACGTGGGGTGTTGTCTCTTCCGGAAGCAGTAAGACAAAGCTGAAAATCCCACATCTGCAGA
67803 AGGGCTGTGAATATGTTTTCCGAGTTAGAGCAGAGAATAAGATAGGTGTTGGTCCTCCCCTTGACTCCAC
67804 ACCTACTGTTGCTAAGCATAAATTTAGTCCTCCGTCTCCTCCTGGTAAACCAGTGGTTACTGACATTACT
67805 GAAAATGCAGCAACAGTGTCTTGGACCCTGCCAAAATCTGATGGTGGCAGTCCAATAACTGGCTACTATA
67806 TGGAACGTCGAGAAGTAACTGGCAAATGGGTGAGGGTCAACAAAACACCTATCGCTGACCTGAAGTTCAG
67807 AGTGACTGGACTCTATGAAGGAAATACATATGAGTTTAGAGTTTTTGCTGAAAATCTTGCAGGACTAAGC
67808 AAACCATCCCCAAGTTCTGATCCAATAAAAGCTTGCCGGCCCATCAAACCACCTGGACCACCTATTAATC
67809 CTAAACTGAAAGACAAGAGCAGAGAAACAGCTGATTTGGTGTGGACAAAGCCTCTCAGTGATGGTGGTAG
67810 CCCCATTCTAGGATATGTAGTGGAATGTCAGAAACCTGGCACGGCACAATGGAACAGGATTAATAAAGAT
67811 GAACTCATTAGGCAATGTGCCTTTAGGGTACCTGGACTAATTGAAGGAAATGAGTACAGATTCCGTATAA
67812 AGGCAGCTAATATTGTAGGAGAGGGTGAGCCAAGAGAACTAGCAGAATCTGTGATTGCAAAAGATATCCT
67813 TCATCCTCCAGAAGTAGAACTTGATGTTACTTGTCGTGATGTTATTACCGTGAGAGTAGGCCAAACTATC
67814 CGCATTCTAGCTCGAGTCAAAGGCAGACCTGAACCAGACATAACTTGGACTAAGGAAGGCAAAGTATTGG
67815 TCCGAGAAAAGAGGGTGGACCTTATTCAGGATCTACCTCGTGTTGAGTTACAAATTAAAGAAGCTGTTAG
67816 AGCTGATCATGGCAAGTATATCATCTCAGCTAAGAACAGCAGTGGACATGCCCAAGGTTCAGCCATCGTT
67817 AACGTCCTTGACAGACCTGGGCCTTGCCAGAATTTGAAGGTTACCAATGTAACCAAAGAGAACTGTACAA
67818 TTTCTTGGGAAAACCCACTAGATAATGGTGGCTCAGAAATAACAAACTTCATAGTAGAATATCGCAAACC
67819 AAACCAGAAAGGCTGGTCAATTGTTGCATCAGATGTCACTAAACGATTAATCAAGGCCAACCTTTTAGCC
67820 AACAATGAATACTATTTCCGAGTTTGTGCAGAGAATAAAGTAGGTGTTGGGCCAACCATCGAAACAAAAA
67821 CTCCCATTCTGGCTATTAACCCTATTGACAGACCAGGTGAGCCTGAAAACCTTCACATTGCAGATAAAGG
67822 AAAGACATTTGTCTATCTAAAGTGGCGGAGGCCTGACTATGATGGTGGCAGTCCAAATCTGTCATATCAT
67823 GTTGAGAGAAGGCTTAAGGGCTCCGATGACTGGGAAAGAGTGCATAAAGGAAGCATTAAAGAAACTCACT
67824 ACATGGTTGACAGATGTGTTGAAAACCAGATTTATGAGTTCAGAGTGCAAACAAAGAATGAAGGTGGGGA
67825 AAGTGACTGGGTGAAGACAGAGGAAGTTGTTGTGAAAGAAGACTTACAAAAACCAGTACTTGATCTGAAA
67826 TTAAGTGGGGTCCTAACTGTCAAAGCAGGGGACACCATTAGGCTTGAGGCAGGGGTTAGAGGCAAACCAT
67827 TCCCAGAAGTTGCATGGACCAAGGACAAAGACGCTACAGACTTAACAAGATCACCAAGGGTCAAGATTGA
67828 TACCCGTGCTGATTCATCTAAATTTTCTCTTACTAAAGCAAAGCGAAGTGATGGGGGTAAATATGTAGTT
67829 ACGGCAACTAACACGGCTGGCAGTTTTGTGGCCTATGCCACTGTCAATGTTTTAGATAAGCCTGGTCCTG
67830 TGAGAAATCTGAAAATTGTTGATGTGTCCAGTGATAGGTGTACTGTTTGCTGGGATCCACCAGAAGATGA
67831 TGGTGGCTGTGAAATCCAAAATTATATTCTAGAAAAATGTGAGACAAAGCGAATGGTTTGGTCTACCTAT
67832 TCTGCTACTGTCTTGACACCTGGTACTACAGTAACACGTCTCATAGAAGGAAATGAATATATTTTCAGAG
67833 TCCGTGCAGAAAATAAAATAGGCACAGGGCCTCCAACAGAAAGTAAACCAGTCATAGCCAAAACCAAGTA
67834 TGATAAACCTGGTCGCCCTGATCCCCCAGAAGTCACTAAAGTAAGCAAAGAAGAGATGACTGTGGTTTGG
67835 AATCCACCTGAATATGATGGTGGAAAGTCTATAACTGGATACTTTTTGGAGAAAAAGGAAAAGCATTCAA
67836 CACGATGGGTCCCTGTCAACAAGAGTGCAATCCCTGAGAGACGTATGAAAGTACAGAATCTCCTCCCAGA
67837 CCATGAATATCAGTTCCGTGTCAAGGCAGAAAATGAAATTGGAATTGGAGAACCAAGCTTGCCTTCAAGA
67838 CCGGTGGTGGCAAAAGACCCCATAGAGCCACCTGGTCCACCAACCAATTTCAGAGTGGTTGATACAACCA
67839 AACATTCCATAACTCTTGGGTGGGGAAAACCAGTCTATGATGGTGGTGCACCGATCATTGGATATGTTGT
67840 GGAAATGAGACCAAAAATAGCAGATGCGTCTCCTGATGAAGGCTGGAAACGGTGTAATGCTGCAGCACAG
67841 CTTGTACGCAAGGAATTCACTGTTACCAGCTTGGATGAAAACCAGGAATATGAGTTCAGGGTGTGTGCCC
67842 AAAACCAAGTTGGTATTGGGCGCCCTGCAGAGCTAAAGGAAGCTATCAAACCTAAAGAAATACTAGAACC
67843 TCCGGAGATTGATTTGGATGCCAGCATGAGGAAACTGGTCATAGTGAGAGCAGGATGCCCTATTCGTCTC
67844 TTTGCTATAGTGAGAGGACGACCAGCCCCTAAAGTCACTTGGCGAAAAGTTGGCATTGATAATGTGGTCA
67845 GAAAAGGACAAGTTGATCTGGTTGACACTATGGCCTTCCTTGTCATCCCCAATTCTACCCGTGATGACTC
67846 AGGAAAATATTCCTTAACACTTGTGAACCCAGCAGGAGAAAAGGCTGTATTCGTAAATGTCAGAGTATTA
67847 GACACTCCTGGGCCTGTGTCTGATTTAAAAGTTTCAGATGTCACTAAAACATCATGCCATGTGTCCTGGG
67848 CCCCTCCTGAAAACGACGGTGGGAGCCAAGTGACACATTATATCGTGGAGAAACGTGAGGCAGACAGAAA
67849 GACATGGTCGACCGTTACCCCAGAAGTTAAGAAAACAAGCTTCCATGTAACCAATCTTGTCCCTGGGAAT
67850 GAGTATTACTTCAGAGTAACTGCTGTCAACGAATATGGCCCTGGCGTCCCAACAGATGTCCCAAAACCAG
67851 TGCTTGCATCAGATCCTCTAAGTGAGCCGGATCCCCCAAGGAAATTAGAAGTGACTGAAATGACCAAGAA
67852 CAGTGCCACCTTAGCCTGGTTACCTCCCCTACGTGATGGAGGTGCTAAAATCGATGGCTACATCACTAGT
67853 TACAGAGAAGAAGAGCAGCCTGCAGATCGCTGGACAGAGTACTCAGTGGTAAAAGATCTGAGCCTTGTTG
67854 TCACTGGCCTAAAGGAAGGAAAGAAATACAAATTTAGAGTAGCGGCCAGAAATGCTGTTGGAGTCAGTTT
67855 GCCAAGAGAAGCTGAAGGAGTGTATGAAGCCAAAGAACAACTGTTGCCACCAAAGATCCTTATGCCAGAG
67856 CAAATAACTATCAAAGCTGGGAAAAAACTCCGAATTGAAGCCCATGTGTATGGAAAGCCTCATCCCACCT
67857 GTAAATGGAAAAAAGGAGAAGATGAAGTTGTCACATCCAGCCACCTGGCAGTGCATAAAGCAGACAGCTC
67858 TTCAATTCTGATCATAAAAGATGTGACTAGGAAAGACAGTGGTTACTACAGCCTCACAGCAGAGAACAGT
67859 TCTGGGACAGACACTCAGAAAATCAAAGTTGTAGTCATGGATGCCCCCGGCCCCCCTCAGCCTCCATTTG
67860 ACATTTCTGATATAGACGCTGATGCTTGCTCCCTGTCATGGCACATCCCTCTGGAGGACGGAGGCAGTAA
67861 CATCACCAATTATATAGTGGAGAAGTGTGATGTAAGCCGAGGTGACTGGGTCACGGCTCTAGCTTCAGTC
67862 ACAAAAACTTCCTGCAGGGTTGGAAAGCTGATCCCAGGCCAGGAGTACATCTTCCGGGTCCGTGCTGAAA
67863 ACCGATTTGGCATTTCAGAGCCTCTCACATCTCCAAAGATGGTTGCGCAGTTCCCATTTGGTGTTCCTAG
67864 TGAACCAAAGAATGCACGAGTCACCAAAGTCAACAAGGACTGTATTTTTGTTGCTTGGGACAGACCAGAT
67865 AGTGATGGAGGGAGCCCCATTATTGGTTATCTGATTGAACGCAAGGAAAGAAACAGTTTGCTGTGGGTGA
67866 AAGCCAATGATACTCTTGTCCGGTCAACTGAATATCCTTGTGCTGGCCTTGTAGAAGGTCTTGAGTATTC
67867 ATTCAGAATCTATGCCCTAAACAAAGCTGGATCCAGCCCACCCAGCAAACCCACAGAATATGTAACTGCA
67868 AGAATGCCAGTTGATCCTCCTGGGAAACCTGAGGTTATTGATGTCACCAAGAGTACTGTATCTCTGATCT
67869 GGGCTCGTCCAAAGCATGATGGAGGCAGTAAAATTATTGGCTATTTCGTAGAAGCTTGCAAACTTCCTGG
67870 TGATAAATGGGTACGGTGCAATACTGCACCTCACCAGATTCCCCAGGAAGAGTACACAGCTACTGGCCTA
67871 GAAGAGAAAGCTCAGTATCAATTTAGAGCTATTGCCAGGACCGCGGTAAACATTAGCCCACCTTCTGAAC
67872 CTTCTGATCCAGTGACTATCCTCGCAGAAAATGTCCCTCCCAGGATAGACCTGAGTGTGGCTATGAAATC
67873 TTTGCTTACTGTGAAAGCTGGAACTAATGTCTGCTTGGATGCTACTGTTTTTGGTAAACCGATGCCAACA
67874 GTTTCTTGGAAAAAAGATGGCACACTGCTAAAACCAGCAGAAGGCATAAAGATGGCCATGCAGCGGAATC
67875 TGTGCACCTTGGAGCTATTCAGCGTGAACCGGAAGGACTCAGGAGACTATACCATTACTGCTGAAAATTC
67876 AAGTGGTTCTAAATCAGCCACCATTAAGCTTAAAGTGTTAGATAAACCGGGTCCTCCAGCATCTGTTAAA
67877 ATCAACAAAATGTATTCAGATCGTGCTATGCTTTCTTGGGAACCGCCTCTTGAAGATGGAGGCTCAGAAA
67878 TCACCAACTATATTGTTGACAAACGTGAAACAAGCAGGCCCAACTGGGCTCAAGTCTCTGCAACTGTGCC
67879 TATCACCAGCTGCAGCGTGGAGAAACTTATAGAGGGCCATGAGTATCAGTTCCGTATTTGTGCTGAAAAT
67880 AAATATGGAGTAGGCGATCCAGTCTTCACTGAACCAGCAATTGCCAAAAACCCATATGACCCACCAGGAC
67881 GCTGTGATCCTCCTGTTATTAGCAACATAACCAAAGATCACATGACAGTCAGCTGGAAGCCACCAGCAGA
67882 TGATGGGGGCTCACCCATCACTGGCTATTTGCTTGAAAAGCGGGAAACCCAGGCTGTTAACTGGACTAAG
67883 GTCAACAGAAAACCTATTATAGAAAGAACATTAAAAGCAACAGGTCTTCAAGAAGGTACCGAATATGAGT
67884 TCCGTGTTACAGCTATAAATAAAGCTGGACCAGGCAAACCCAGTGACGCATCCAAGGCCGCTTATGCTCG
67885 GGACCCTCAGTATCCTCCTGCGCCACCGGCTTTCCCTAAAGTATATGATACAACTCGCAGCTCTGTGAGT
67886 CTATCTTGGGGCAAGCCAGCCTATGACGGCGGCAGCCCTATCATTGGTTATCTCGTTGAAGTAAAACGGG
67887 CTGACTCCGATAACTGGGTGAGGTGCAACTTACCACAGAATCTACAGAAAACCCGCTTTGAGGTTACTGG
67888 CCTGATGGAAGACACACAATATCAATTCCGTGTGTATGCCGTTAATAAGATTGGATACAGTGACCCCAGT
67889 GATGTGCCAGATAAACACTATCCCAAGGACATCTTAATTCCACCTGAGGGAGAACTTGATGCGGACTTAA
67890 GGAAGACACTCATATTACGTGCTGGAGTTACTATGAGACTATATGTACCAGTAAAAGGACGCCCACCTCC
67891 AAAGATTACTTGGTCTAAACCAAATGTCAATCTAAGAGACAGGATTGGACTGGACATAAAGTCAACTGAC
67892 TTTGACACTTTCTTGCGCTGTGAAAATGTGAACAAATATGATGCAGGAAAATATATCTTAACCCTGGAGA
67893 ACAGCTGTGGTAAAAAGGAATATACCATTGTTGTGAAAGTGCTTGATACTCCTGGGCCACCTGTCAATGT
67894 GACTGTTAAGGAAATATCCAAAGACTCTGCTTATGTTACCTGGGAGCCTCCCATTATTGATGGCGGAAGC
67895 CCCATCATAAACTATGTGGTACAAAAACGTGATGCAGAGAGGAAATCCTGGTCTACAGTGACAACTGAGT
67896 GCTCCAAAACAAGCTTCAGAGTAGCTAATTTGGAGGAGGGAAAATCCTACTTCTTCCGAGTGTTTGCTGA
67897 AAATGAGTATGGCATTGGTGATCCCGGTGAAACTCGTGATGCTGTCAAAGCTTCCCAAACTCCTGGACCA
67898 GTTGTGGACCTGAAAGTGAGGTCTGTATCTAAGTCATCCTGTAGCATTGGCTGGAAAAAGCCTCACAGTG
67899 ATGGTGGAAGTCGGATTATTGGATATGTAGTTGATTTCCTGACTGAAGAAAATAAGTGGCAACGAGTTAT
67900 GAAATCCTTAAGCCTACAGTACTCTGCAAAAGATTTGACTGAAGGGAAGGAATATACCTTCAGAGTGAGT
67901 GCTGAGAATGAAAATGGAGAAGGAACCCCAAGCGAAATCACTGTTGTGGCAAGGGATGATGTTGTGGCTC
67902 CTGATCTTGACTTAAAGGGTCTACCTGATTTGTGCTACTTGGCTAAAGAAAACAGCAACTTCCGGCTTAA
67903 GATCCCCATAAAAGGCAAGCCAGCTCCATCAGTCTCCTGGAAGAAAGGGGAAGATCCTCTAGCAACTGAC
67904 ACTAGAGTCAGTGTTGAGTCATCTGCGGTTAACACAACTCTTATAGTGTACGATTGCCAAAAATCTGATG
67905 CTGGAAAATACACAATCACACTTAAGAATGTTGCTGGCACCAAGGAAGGAACTATCTCCATAAAGGTTGT
67906 TGGCAAGCCTGGCATCCCCACTGGACCAATCAAATTTGATGAAGTCACAGCAGAAGCCATGACCTTAAAG
67907 TGGGCTCCTCCAAAGGATGATGGAGGTTCTGAAATCACCAACTATATCCTAGAGAAGAGGGATTCTGTGA
67908 ACAACAAGTGGGTGACGTGCGCCTCAGCTGTCCAGAAAACCACCTTTAGAGTAACCAGACTTCATGAGGG
67909 CATGGAATATACCTTCAGGGTCAGTGCCGAAAATAAATATGGTGTAGGGGAAGGCCTGAAATCGGAGCCA
67910 ATTGTTGCGAGACATCCATTTGATGTGCCTGATGCTCCCCCACCTCCCAATATTGTGGATGTCAGACACG
67911 ATTCAGTATCTCTAACTTGGACTGACCCCAAGAAAACTGGTGGTTCTCCAATTACAGGGTATCATCTCGA
67912 GTTCAAGGAAAGAAACAGCCTTTTGTGGAAGAGAGCTAACAAGACTCCGATAAGGATGAGAGACTTTAAA
67913 GTGACAGGATTAACTGAAGGTCTTGAATATGAATTCCGAGTTATGGCAATCAATTTAGCAGGTGTGGGCA
67914 AGCCAAGCCTACCATCAGAGCCTGTTGTGGCACTGGACCCAATTGATCCTCCTGGAAAACCTGAGGTTAT
67915 TAACATAACAAGGAATTCAGTGACTCTCATTTGGACTGAACCTAAATATGACGGTGGTCATAAGTTAACT
67916 GGATATATAGTGGAGAAGCGAGATCTACCTTCGAAGTCTTGGATGAAAGCCAACCATGTTAATGTCCCAG
67917 AATGTGCCTTTACTGTAACTGACCTTGTTGAGGGTGGAAAATATGAATTCAGAATTAGAGCAAAGAATAC
67918 AGCAGGTGCTATCAGTGCTCCATCAGAAAGTACAGAAACCATTATTTGCAAGGATGAATACGAGGCACCA
67919 ACAATTGTCCTTGATCCCACAATAAAAGATGGGCTAACAATTAAAGCAGGGGATACCATTGTTTTGAATG
67920 CCATTAGCATTCTTGGCAAACCCCTTCCAAAATCAAGTTGGTCCAAGGCAGGAAAAGACATTAGACCATC
67921 AGATATCACTCAGATAACTTCAACCCCAACATCTTCCATGCTTACTATCAAGTATGCCACTAGAAAAGAT
67922 GCGGGTGAATATACCATCACTGCTACCAATCCTTTTGGCACGAAGGTGGAACATGTGAAGGTAACAGTCC
67923 TTGATGTACCTGGTCCCCCAGGTCCTGTTGAAATCAGTAATGTTTCTGCTGAAAAAGCAACACTTACATG
67924 GACACCTCCCTTGGAAGATGGCGGCTCACCAATTAAGTCCTATATACTTGAAAAGAGAGAAACCAGCCGA
67925 CTTTTGTGGACAGTGGTTTCTGAAGATATTCAGTCTTGCAGGCATGTGGCAACCAAACTTATCCAAGGAA
67926 ATGAGTACATCTTCCGGGTCTCAGCTGTAAACCACTATGGCAAAGGAGAACCTGTACAGTCTGAACCTGT
67927 CAAAATGGTAGACAGATTTGGTCCCCCTGGCCCTCCTGAAAAACCAGAGGTATCAAATGTCACTAAGAAC
67928 ACTGCCACTGTCAGCTGGAAAAGGCCAGTGGATGATGGTGGCAGCGAAATTACAGGATATCATGTAGAAA
67929 GGAGAGAAAAGAAAAGCCTGCGATGGGTGAGAGCAATAAAAACACCAGTTTCCGATCTCAGGTGCAAAGT
67930 AACAGGACTGCAAGAAGGAAGCACCTACGAATTCCGTGTCAGTGCAGAAAACAGAGCAGGAATTGGTCCA
67931 CCCAGTGAGGCTTCAGATTCTGTTCTGATGAAAGATGCAGCATATCCTCCAGGACCACCTTCAAATCCGC
67932 ATGTCACTGATACTACCAAGAAATCTGCTTCTTTGGCATGGGGCAAGCCTCATTATGATGGTGGACTTGA
67933 AATCACTGGCTATGTCGTGGAGCATCAAAAAGTAGGAGACGAGGCCTGGATAAAAGATACCACAGGAACC
67934 GCCCTCAGAATCACTCAGTTCGTTGTTCCTGATCTTCAGACTAAAGAAAAATACAACTTCAGAATCAGTG
67935 CCATCAACGATGCAGGTGTTGGGGAGCCAGCGGTGATTCCAGATGTTGAAATCGTAGAACGGGAGATGGC
67936 TCCTGATTTTGAACTAGATGCCGAGCTTCGAAGAACACTTGTTGTTAGAGCAGGACTCAGTATTAGGATA
67937 TTTGTGCCAATTAAAGGTCGTCCTGCTCCTGAAGTGACATGGACCAAAGATAACATCAACCTGAAAAACC
67938 GAGCCAACATTGAAAATACGGAATCATTTACTCTTCTGATTATCCCAGAATGTAACAGATATGATACCGG
67939 TAAATTTGTCATGACCATTGAAAACCCGGCTGGGAAGAAAAGTGGCTTTGTGAACGTCAGAGTCTTGGAC
67940 ACGCCAGGCCCAGTCCTCAACCTGCGGCCTACAGACATCACAAAGGACAGTGTCACCCTGCACTGGGACC
67941 TCCCTCTGATAGATGGAGGCTCACGTATAACAAACTACATTGTAGAGAAACGTGAAGCAACACGGAAATC
67942 TTATTCCACAGCCACCACTAAGTGCCATAAATGCACATATAAAGTTACCGGCTTGTCTGAAGGGTGTGAA
67943 TATTTCTTCAGAGTGATGGCAGAGAATGAATATGGAATTGGTGAGCCAACAGAAACTACAGAGCCCGTAA
67944 AAGCCTCTGAAGCACCATCTCCACCAGACAGCCTTAACATCATGGACATAACTAAGAGCACCGTCAGCCT
67945 GGCATGGCCTAAGCCCAAACACGATGGTGGCAGCAAGATCACTGGCTATGTGATTGAAGCCCAAAGAAAA
67946 GGCTCTGACCAGTGGACCCACATCACAACCGTGAAAGGGTTAGAATGTGTTGTGAGGAATCTAACTGAAG
67947 GAGAGGAATATACCTTCCAAGTGATGGCAGTGAACAGCGCGGGGAGAAGTGCCCCTAGAGAAAGCAGACC
67948 CGTCATTGTCAAGGAGCAGACAATGCTTCCAGAGCTGGATCTCCGTGGCATCTATCAGAAACTGGTCATT
67949 GCCAAAGCTGGTGACAACATCAAAGTTGAAATTCCAGTGCTCGGTCGACCGAAGCCCACAGTGACATGGA
67950 AAAAAGGAGACCAAATTCTTAAACAGACACAGAGAGTTAATTTTGAAACCACAGCGACTTCAACCATTTT
67951 AAATATCAATGAGTGTGTCAGAAGTGATAGTGGGCCCTATCCATTAACAGCAAGGAACATTGTAGGAGAG
67952 GTTGGTGATGTCATCACCATTCAAGTCCATGATATCCCAGGGCCACCTACTGGACCAATCAAATTTGATG
67953 AAGTTTCATCTGATTTTGTAACCTTCTCTTGGGACCCACCTGAGAACGATGGTGGTGTACCAATAAGCAA
67954 CTATGTAGTGGAAATGCGGCAGACTGACAGTACTACCTGGGTTGAGTTAGCAACCACCGTTATACGTACT
67955 ACCTATAAAGCCACCCGCCTTACTACTGGATTAGAGTATCAGTTCCGTGTAAAAGCTCAGAATAGATATG
67956 GAGTTGGACCAGGCATCACATCAGCATGCATAGTTGCCAACTATCCATTTAAGGTTCCTGGACCTCCTGG
67957 TACCCCTCAGGTAACTGCAGTTACCAAGGATTCAATGACAATTAGCTGGCATGAGCCACTTTCTGATGGT
67958 GGAAGCCCCATTTTAGGATATCATGTTGAAAGAAAAGAACGAAATGGTATTCTCTGGCAGACTGTGAGCA
67959 AAGCTTTAGTACCAGGCAACATTTTCAAATCAAGTGGACTTACAGATGGTATTGCTTATGAGTTCCGGGT
67960 GATTGCAGAAAACATGGCAGGCAAAAGTAAGCCAAGCAAGCCATCAGAACCTATGTTGGCTCTGGATCCC
67961 ATTGACCCACCTGGAAAACCAGTACCTCTAAATATTACAAGACACACAGTAACACTTAAATGGGCTAAGC
67962 CTGAATATACTGGGGGCTTTAAAATTACCAGTTATATCGTTGAAAAGAGAGACCTTCCTAATGGACGGTG
67963 GCTGAAGGCCAACTTCAGCAACATTTTGGAGAATGAATTTACAGTCAGTGGCCTAACAGAAGATGCTGCA
67964 TATGAATTCCGTGTGATCGCCAAAAATGCTGCAGGTGCCATCAGTCCACCATCTGAGCCATCTGATGCTA
67965 TCACTTGCAGGGATGATGTTGAGGCACCAAAGATAAAGGTGGATGTTAAATTTAAGGACACGGTTATATT
67966 AAAAGCAGGTGAAGCATTCAGACTGGAAGCTGATGTTTCAGGCCGCCCACCTCCAACAATGGAATGGAGC
67967 AAAGATGGAAAAGAGCTGGAAGGCACAGCAAAGTTAGAAATAAAAATTGCAGATTTCTCTACTAATCTGG
67968 TAAACAAAGATTCAACAAGAAGGGATAGTGGTGCCTATACCCTTACAGCGACTAATCCTGGTGGCTTTGC
67969 TAAACACATTTTCAATGTCAAAGTTCTTGACAGACCAGGCCCACCTGAAGGACCTTTGGCTGTAACTGAA
67970 GTGACATCAGAAAAGTGTGTACTATCATGGTTCCCTCCACTGGATGATGGAGGTGCCAAAATTGATCATT
67971 ACATAGTACAGAAACGTGAAACCAGCAGATTGGCATGGACAAATGTAGCCTCAGAAGTCCAAGTAACAAA
67972 GCTAAAGGTCACTAAACTCTTGAAAGGCAATGAATACATATTCCGTGTCATGGCTGTAAATAAATATGGA
67973 GTGGGAGAGCCACTGGAATCAGAGCCTGTGCTTGCAGTGAATCCTTATGGACCCCCTGATCCGCCCAAAA
67974 ACCCTGAAGTGACAACTATTACTAAAGATTCGATGGTTGTCTGCTGGGGACATCCTGATTCTGATGGTGG
67975 AAGTGAAATCATCAATTATATTGTGGAACGGCGTGATAAAGCTGGCCAACGCTGGATTAAATGCAACAAA
67976 AAAACTCTTACTGATTTAAGATATAAAGTGTCTGGACTGACAGAAGGACATGAATATGAGTTCAGGATTA
67977 TGGCTGAAAATGCTGCTGGAATTAGTGCACCAAGTCCTACCAGTCCATTTTACAAGGCTTGTGACACTGT
67978 GTTTAAACCTGGACCACCAGGTAACCCACGTGTTCTGGATACAAGCAGATCATCCATTTCAATCGCTTGG
67979 AATAAACCTATCTATGATGGTGGTTCAGAAATCACTGGGTATATGGTTGAGATTGCCCTGCCAGAGGAAG
67980 ATGAATGGCAGATTGTCACTCCACCAGCAGGACTCAAGGCAACTTCGTATACTATCACTGGCCTCACAGA
67981 GAATCAGGAATATAAGATCCGCATCTATGCCATGAATTCCGAAGGACTTGGGGAACCTGCCCTTGTTCCT
67982 GGAACTCCAAAGGCTGAAGACAGAATGCTGCCTCCAGAAATTGAACTGGATGCTGACCTGCGCAAAGTTG
67983 TTACTATAAGGGCCTGCTGCACCCTGAGACTTTTTGTTCCCATCAAAGGAAGGCCTGCACCTGAGGTGAA
67984 GTGGGCCCGGGACCATGGAGAATCTTTAGATAAAGCTAGCATCGAATCCACAAGCTCTTACACCCTGCTT
67985 ATTGTTGGAAATGTAAACAGATTTGACAGTGGCAAATATATACTAACTGTAGAAAATAGTTCAGGCAGCA
67986 AGTCTGCATTTGTCAATGTTAGAGTTCTCGATACACCAGGCCCCCCACAGGATCTGAAGGTAAAAGAGGT
67987 CACTAAGACATCTGTCACACTCACATGGGACCCACCTCTCCTTGATGGAGGTTCAAAAATCAAGAACTAT
67988 ATTGTTGAAAAGCGGGAATCAACAAGAAAAGCATATTCAACTGTTGCAACAAACTGCCACAAGACTTCCT
67989 GGAAGGTAGACCAGCTTCAAGAAGGCTGTAGCTACTATTTCAGGGTTCTCGCAGAAAATGAATATGGCAT
67990 TGGGCTGCCTGCTGAAACCGCAGAATCTGTGAAAGCATCAGAACGACCTCTTCCTCCAGGAAAAATAACT
67991 TTGATGGATGTCACAAGAAATAGTGTGTCACTCTCTTGGGAGAAACCAGAGCATGATGGAGGCAGCCGAA
67992 TTCTAGGCTACATTGTGGAGATGCAGACCAAAGGCAGTGACAAATGGGCCACGTGTGCCACAGTCAAGGT
67993 CACTGAAGCCACTATCACTGGATTAATTCAGGGTGAAGAATACTCTTTCCGTGTTTCAGCTCAGAATGAA
67994 AAGGGCATCAGTGATCCTAGACAACTGAGTGTGCCAGTGATCGCCAAAGATCTTGTCATTCCACCAGCCT
67995 TCAAACTCCTGTTCAATACTTTCACTGTACTGGCAGGTGAAGACCTAAAAGTTGATGTTCCATTCATTGG
67996 CCGCCCTACCCCAGCTGTAACCTGGCATAAAGATAATGTACCACTGAAGCAGACAACTAGAGTAAATGCA
67997 GAGAGCACAGAAAATAATTCACTACTGACAATAAAGGACGCCTGCCGAGAAGATGTTGGCCATTATGTGG
67998 TTAAACTGACTAACTCAGCTGGTGAAGCTATTGAAACCCTTAATGTTATCGTTCTTGACAAACCAGGGCC
67999 TCCAACTGGACCAGTTAAAATGGATGAAGTGACAGCTGATAGTATTACTCTTTCCTGGGGCCCACCCAAG
68000 TATGATGGTGGAAGTTCTATCAATAATTACATTGTTGAGAAACGGGACACTTCCACAACCACCTGGCAAA
68001 TTGTATCAGCTACAGTTGCAAGGACAACAATAAAGGCTTGCAGACTGAAGACTGGATGTGAATATCAGTT
68002 TAGAATTGCAGCTGAAAACAGATATGGGAAGAGTACCTACCTCAATTCAGAGCCTACTGTAGCCCAATAT
68003 CCATTCAAAGTTCCTGGTCCTCCTGGCACTCCAGTTGTCACACTGTCCTCCAGGGACAGCATGGAAGTAC
68004 AATGGAATGAGCCAATCAGTGATGGAGGAAGTAGAGTCATTGGCTATCATCTAGAACGCAAGGAAAGAAA
68005 TAGCATCCTCTGGGTTAAGTTGAATAAAACACCTATTCCTCAAACCAAGTTTAAGACAACTGGCCTTGAA
68006 GAAGGTGTTGAATATGAATTTAGAGTCTCTGCAGAGAACATCGTGGGCATTGGCAAGCCGAGTAAAGTAT
68007 CAGAATGTTATGTGGCTCGTGACCCATGTGATCCACCAGGACGGCCAGAGGCAATCATTGTCACAAGGAA
68008 TTCTGTGACTCTTCAGTGGAAGAAACCCACCTATGACGGTGGAAGCAAGATCACTGGTTATATTGTTGAG
68009 AAGAAAGAATTACCTGAGGGCCGTTGGATGAAAGCCAGTTTTACAAATATTATTGACACTCATTTTGAAG
68010 TAACTGGCCTAGTTGAAGATCACAGATATGAGTTCCGGGTTATAGCCCGAAATGCCGCAGGAGTGTTTAG
68011 TGAGCCTTCAGAAAGCACAGGAGCAATAACAGCTAGAGATGAGGTAGATCCACCACGAATAAGTATGGAT
68012 CCAAAATACAAAGACACAATCGTGGTTCATGCTGGTGAATCATTCAAGGTTGATGCAGATATTTATGGCA
68013 AACCAATACCAACCATTCAGTGGATAAAAGGTGATCAGGAGCTTTCAAACACAGCTCGATTAGAAATAAA
68014 GAGCACCGACTTTGCCACCAGTCTCAGTGTAAAAGATGCAGTACGTGTCGACAGTGGAAATTACATACTG
68015 AAGGCCAAAAATGTTGCAGGAGAAAGATCAGTTACTGTGAATGTCAAGGTTCTTGACAGACCAGGGCCAC
68016 CTGAAGGACCTGTTGTTATCTCAGGAGTTACAGCAGAAAAATGCACACTAGCTTGGAAACCCCCACTTCA
68017 GGATGGTGGGAGTGACATCATAAATTATATTGTGGAAAGGAGAGAAACCAGCCGCTTAGTTTGGACTGTG
68018 GTTGATGCCAATGTGCAGACTCTCAGCTGCAAGGTTACTAAGCTTCTTGAAGGCAATGAATATACTTTCC
68019 GTATAATGGCAGTAAACAAATATGGTGTTGGTGAACCTCTTGAATCTGAGCCAGTAGTTGCCAAGAATCC
68020 ATTTGTAGTACCAGATGCACCAAAAGCTCCAGAAGTCACAACAGTGACCAAGGACTCAATGATTGTTGTA
68021 TGGGAAAGACCAGCATCTGATGGTGGTAGTGAAATTCTTGGATATGTTCTTGAGAAACGGGATAAAGAAG
68022 GCATTAGATGGACAAGATGCCATAAGCGTCTGATTGGAGAGTTGCGCCTGAGAGTAACTGGACTCATAGA
68023 AAATCACGATTATGAGTTCAGAGTTTCTGCTGAGAATGCTGCTGGACTTAGTGAACCAAGCCCTCCTTCT
68024 GCTTACCAAAAGGCTTGTGATCCTATTTATAAACCAGGACCCCCAAACAACCCCAAAGTCATAGACATAA
68025 CCAGATCTTCAGTATTCCTTTCTTGGAGCAAACCAATATATGATGGTGGCTGTGAAATTCAAGGATACAT
68026 TGTTGAAAAATGTGATGTGAGTGTTGGTGAATGGACAATGTGCACTCCACCAACAGGAATTAATAAAACA
68027 AACATAGAAGTAGAGAAGCTGTTGGAAAAGCATGAATACAACTTCCGTATCTGTGCTATTAATAAAGCTG
68028 GAGTTGGAGAACATGCTGACGTCCCTGGACCTATTATAGTTGAAGAAAAATTAGAAGCACCAGACATTGA
68029 TCTTGACCTAGAACTAAGGAAAATCATAAATATAAGGGCAGGTGGCTCCTTAAGGTTATTTGTTCCTATA
68030 AAAGGTCGTCCTACACCAGAAGTTAAATGGGGAAAGGTGGATGGTGAAATCCGAGATGCAGCTATAATTG
68031 ATGTCACTAGCAGTTTCACCTCTCTTGTTCTTGACAATGTCAACCGATATGATAGTGGAAAATATACGCT
68032 TACATTAGAAAACAGCAGTGGAACAAAGTCTGCCTTTGTTACTGTGAGAGTTCTGGACACGCCAAGTCCA
68033 CCTGTTAACCTGAAAGTCACAGAAATCACCAAAGACTCAGTATCAATTACATGGGAACCTCCTTTGTTGG
68034 ATGGGGGATCCAAAATAAAAAATTACATTGTTGAGAAACGTGAAGCCACAAGAAAATCATATGCTGCTGT
68035 TGTAACTAACTGCCATAAGAATTCTTGGAAAATCGATCAGCTCCAAGAAGGTTGCAGTTATTACTTTAGA
68036 GTCACAGCTGAGAATGAGTATGGTATTGGCCTTCCTGCCCAGACTGCTGATCCAATTAAGGTTGCAGAAG
68037 TGCCACAACCTCCTGGAAAAATAACTGTGGATGATGTCACCAGAAACAGTGTCTCTCTGAGTTGGACAAA
68038 ACCTGAACATGATGGTGGCAGTAAAATCATTCAGTATATTGTGGAAATGCAAGCTAAACACAGTGAGAAA
68039 TGGTCAGAGTGTGCTCGAGTAAAGTCTCTTCAGGCAGTAATTACCAACCTAACTCAAGGGGAAGAATATC
68040 TTTTTAGAGTTGTTGCTGTAAATGAAAAGGGGAGAAGTGATCCTCGGTCCCTTGCAGTTCCAATAGTTGC
68041 CAAAGATCTGGTAATTGAGCCAGATGTAAAACCTGCATTCAGTAGTTACAGTGTACAGGTTGGCCAAGAT
68042 TTGAAAATAGAAGTGCCAATTTCTGGACGTCCTAAGCCAACCATTACCTGGACTAAAGATGGTCTCCCAC
68043 TGAAGCAGACCACAAGAATCAATGTTACCGATTCACTGGATCTCACCACACTCAGTATTAAAGAAACTCA
68044 TAAGGATGATGGTGGACAATATGGAATCACAGTTGCCAATGTTGTTGGTCAGAAGACAGCATCCATCGAA
68045 ATTGTAACTCTAGATAAACCTGATCCTCCAAAAGGACCTGTTAAATTTGATGACGTCAGTGCTGAAAGTA
68046 TTACATTATCTTGGAACCCTCCATTATATACAGGGGGCTGCCAAATCACCAACTACATTGTTCAGAAAAG
68047 AGATACAACCACCACAGTATGGGATGTTGTTTCTGCTACTGTTGCTAGAACTACACTCAAAGTGACCAAA
68048 CTGAAAACTGGTACAGAATACCAATTTAGAATATTTGCCGAAAACAGATATGGACAAAGCTTTGCCTTAG
68049 AGTCTGATCCAATTGTAGCTCAATATCCCTACAAAGAACCAGGCCCTCCAGGTACACCATTTGCCACAGC
68050 CATTTCCAAAGACTCCATGGTCATACAGTGGCATGAACCAGTCAACAATGGTGGAAGCCCCGTCATAGGT
68051 TACCACCTGGAGAGAAAAGAAAGAAACAGTATTTTGTGGACAAAGGTCAACAAAACTATTATTCATGACA
68052 CCCAATTCAAAGCACAGAATCTTGAAGAAGGCATTGAATATGAATTCAGAGTGTATGCTGAAAATATTGT
68053 TGGTGTAGGCAAAGCAAGCAAGAATTCTGAATGCTATGTAGCCAGAGATCCCTGTGACCCACCAGGAACC
68054 CCAGAACCAATAATGGTTAAAAGAAATGAAATCACTTTACAGTGGACCAAACCTGTGTATGATGGTGGAA
68055 GTATGATTACAGGCTACATTGTAGAGAAACGTGATTTGCCTGATGGTCGTTGGATGAAAGCTAGCTTTAC
68056 AAATGTCATTGAAACTCAATTTACTGTGTCAGGTCTTACTGAAGATCAAAGATATGAATTCAGAGTCATT
68057 GCAAAGAATGCAGCTGGTGCAATAAGTAAACCCTCTGACAGTACTGGACCAATAACTGCCAAGGATGAGG
68058 TTGAACTCCCAAGAATTTCAATGGATCCAAAATTCAGAGACACAATTGTGGTAAATGCTGGAGAAACATT
68059 CAGACTTGAGGCTGATGTCCATGGAAAGCCCCTACCTACCATTGAGTGGTTAAGAGGAGATAAGGAAATT
68060 GAAGAATCTGCTAGATGTGAAATAAAGAACACAGATTTCAAGGCTTTACTTATTGTAAAAGATGCAATTA
68061 GAATTGATGGTGGGCAGTATATTTTAAGAGCTTCCAATGTTGCAGGTTCTAAGTCATTCCCAGTAAATGT
68062 AAAAGTATTAGATAGACCAGGACCTCCAGAAGGGCCAGTCCAGGTTACTGGAGTCACTTCTGAAAAATGC
68063 TCTTTAACATGGTCTCCACCACTTCAAGATGGTGGCAGTGACATTTCTCACTATGTTGTTGAAAAGCGAG
68064 AAACCAGTCGACTTGCCTGGACTGTTGTTGCTTCAGAAGTTGTGACCAATTCTCTGAAAGTTACCAAACT
68065 CTTAGAAGGTAATGAATATGTTTTCCGTATAATGGCTGTCAACAAATATGGTGTTGGAGAGCCTTTGGAA
68066 TCTGCACCAGTACTAATGAAAAATCCATTTGTGCTTCCTGGACCACCAAAAAGCTTGGAAGTCACAAATA
68067 TTGCCAAAGACTCCATGACCGTCTGTTGGAACCGTCCAGATAGTGATGGTGGAAGTGAGATTATTGGTTA
68068 CATTGTAGAGAAAAGAGACAGAAGTGGCATTCGATGGATAAAATGTAATAAACGCCGCATTACAGATTTG
68069 CGTCTAAGAGTGACAGGATTAACAGAAGATCATGAGTATGAATTCAGGGTCTCTGCAGAAAATGCTGCTG
68070 GAGTTGGGGAACCAAGTCCAGCTACAGTTTATTATAAAGCCTGTGATCCTGTGTTCAAACCTGGCCCACC
68071 TACCAATGCACACATTGTAGACACCACTAAAAATTCAATCACACTTGCCTGGGGTAAACCCATCTATGAT
68072 GGCGGCAGTGAGATCTTGGGATATGTAGTAGAAATCTGTAAAGCAGATGAAGAAGAATGGCAAATAGTTA
68073 CTCCACAGACTGGCCTGAGAGTCACTCGATTTGAAATTTCAAAACTCACTGAACACCAAGAGTATAAAAT
68074 ACGAGTCTGTGCCCTCAACAAAGTTGGTTTAGGTGAGGCTACATCAGTTCCTGGTACTGTGAAACCAGAA
68075 GATAAACTTGAAGCACCTGAACTTGACCTTGACTCCGAATTAAGAAAAGGAATTGTTGTAAGAGCTGGTG
68076 GATCTGCCAGAATTCACATTCCATTCAAAGGTCGTCCAACGCCTGAGATCACTTGGTCTCGAGAGGAAGG
68077 TGAATTCACAGATAAGGTCCAAATTGAAAAGGGAGTAAACTATACCCAACTATCAATAGATAACTGTGAT
68078 AGAAATGATGCTGGAAAATACATTCTTAAGTTGGAAAACAGCAGTGGATCAAAGTCTGCTTTTGTAACTG
68079 TGAAAGTTCTTGACACTCCAGGACCACCACAGAATTTGGCAGTCAAAGAAGTGAGAAAAGATTCTGCCTT
68080 CCTGGTATGGGAGCCACCCATCATTGATGGAGGGGCAAAGGTCAAGAACTATGTGATTGACAAACGTGAG
68081 TCAACCAGAAAAGCGTATGCTAATGTGAGTAGTAAATGCAGCAAAACAAGTTTTAAAGTGGAAAACCTTA
68082 CAGAAGGAGCCATTTATTACTTCAGAGTCATGGCTGAAAATGAATTTGGAGTTGGTGTTCCAGTGGAAAC
68083 TGTTGATGCCGTGAAAGCTGCTGAACCTCCTTCCCCACCAGGAAAGGTTACACTCACTGATGTGTCCCAG
68084 ACCAGTGCATCACTTATGTGGGAGAAACCTGAACATGATGGCGGTAGCAGAGTCCTGGGGTACGTTGTTG
68085 AAATGCAGCCCAAAGGAACTGAAAAATGGAGCATTGTGGCTGAATCCAAAGTCTGTAATGCAGTTGTTAC
68086 TGGTTTGAGTTCTGGACAAGAATATCAGTTCCGTGTCAAGGCTTATAATGAGAAAGGAAAAAGCGATCCA
68087 AGAGTGTTGGGTGTTCCTGTCATAGCCAAGGACTTGACTATACAGCCTAGTTTAAAGTTACCATTTAACA
68088 CATATAGTATCCAAGCTGGAGAAGATCTTAAAATAGAAATTCCAGTTATAGGCCGACCAAGACCTAACAT
68089 TTCTTGGGTCAAAGATGGTGAGCCTCTTAAACAGACAACAAGAGTAAACGTTGAAGAAACAGCTACCTCA
68090 ACTGTTTTGCACATTAAAGAAGGTAACAAAGATGACTTTGGAAAATACACCGTAACGGCAACAAATAGTG
68091 CAGGCACAGCAACAGAAAATCTCAGTGTTATCGTTTTAGAAAAGCCTGGACCTCCAGTTGGCCCAGTTCG
68092 GTTTGATGAAGTTAGTGCAGACTTTGTAGTCATATCTTGGGAACCTCCAGCCTATACTGGTGGCTGCCAA
68093 ATAAGCAACTACATTGTAGAGAAGCGAGATACAACCACCACCACTTGGCACATGGTATCAGCAACAGTTG
68094 CAAGAACAACAATTAAAATAACCAAACTGAAAACAGGCACGGAGTACCAGTTTAGAATTTTTGCTGAAAA
68095 CAGGTATGGAAAAAGTGCCCCACTGGATTCTAAGGCAGTTATTGTACAATATCCATTTAAAGAACCTGGA
68096 CCACCTGGAACTCCTTTTGTGACATCAATCTCAAAAGATCAGATGCTTGTGCAATGGCATGAGCCAGTGA
68097 ATGATGGAGGCACCAAAATTATTGGCTACCATCTTGAACAGAAAGAAAAGAACAGTATTTTATGGGTCAA
68098 GTTAAATAAGACCCCCATTCAGGACACCAAATTCAAAACAACTGGGCTTGATGAGGGCCTTGAGTATGAG
68099 TTCAAAGTTTCTGCTGAAAATATTGTTGGCATTGGCAAGCCTAGCAAAGTGTCAGAATGCTTTGTTGCTC
68100 GTGATCCATGTGACCCACCTGGTCGCCCTGAAGCCATTGTTATTACAAGAAACAATGTCACACTGAAATG
68101 GAAGAAACCTGCCTATGATGGTGGTAGCAAAATAACAGGTTATATTGTAGAAAAGAAAGATCTACCTGAT
68102 GGCCGCTGGATGAAAGCCAGCTTTACCAACGTATTAGAAACTGAATTTACAGTGAGTGGACTTGTAGAAG
68103 ACCAAAGATATGAATTTAGAGTAATTGCAAGAAATGCAGCTGGAAACTTTAGTGAACCATCTGATAGTAG
68104 TGGTGCCATTACTGCAAGAGATGAAATTGATGCACCAAATGCCTCTCTGGATCCAAAATATAAAGATGTC
68105 ATCGTTGTTCATGCAGGAGAGACTTTTGTTCTTGAAGCCGACATCCGTGGCAAACCTATACCTGATGTTG
68106 TTTGGTCAAAAGATGGAAAAGAACTTGAAGAAACAGCTGCTAGAATGGAAATTAAATCTACTATTCAGAA
68107 AACAACTCTTGTTGTCAAAGACTGTATACGGACTGATGGAGGACAATATATTCTGAAACTCAGCAATGTT
68108 GGTGGTACAAAGTCTATACCCATCACTGTAAAGGTACTTGACAGGCCAGGGCCTCCTGAAGGGCCTCTGA
68109 AAGTTACTGGAGTTACTGCGGAAAAATGTTACCTGGCATGGAACCCACCTTTGCAAGATGGTGGTGCTAA
68110 TATTTCACATTACATCATTGAAAAGAGGGAGACAAGCCGACTCTCTTGGACCCAGGTTTCAACTGAGGTA
68111 CAGGCCCTTAACTACAAAGTTACTAAACTTCTTCCTGGTAATGAGTACATTTTCCGTGTCATGGCTGTGA
68112 ATAAATATGGAATTGGAGAGCCCTTGGAATCTGGGCCTGTTACGGCCTGTAATCCTTATAAGCCACCAGG
68113 TCCTCCCTCAACACCTGAAGTCTCAGCAATCACCAAAGATTCTATGGTAGTAACATGGGCACGCCCAGTA
68114 GACGACGGAGGTACCGAAATTGAGGGCTACATTCTTGAAAAACGAGATAAGGAAGGCGTTAGATGGACCA
68115 AGTGCAACAAGAAAACATTAACGGATCTGCGGCTCAGGGTAACTGGTCTTACCGAAGGCCATTCCTATGA
68116 ATTCAGAGTTGCTGCTGAAAATGCAGCTGGTGTGGGAGAACCTAGTGAGCCATCTGTTTTCTACCGTGCG
68117 TGTGATGCCTTGTATCCACCAGGTCCCCCAAGCAATCCAAAAGTGACGGACACTTCCAGATCTTCTGTCT
68118 CCCTGGCATGGAGTAAGCCAATTTATGATGGTGGCGCACCTGTTAAAGGCTATGTTGTAGAGGTCAAAGA
68119 AGCTGCTGCGGATGAATGGACAACCTGCACTCCACCAACAGGATTACAAGGAAAGCAGTTCACAGTGACC
68120 AAGCTTAAAGAAAACACTGAATATAACTTCCGTATTTGTGCCATCAATTCTGAAGGTGTAGGTGAACCTG
68121 CAACTCTACCTGGCTCAGTGGTTGCTCAGGAGAGGATAGAGCCACCAGAAATAGAACTCGATGCTGATCT
68122 CAGAAAGGTGGTCGTTCTGCGTGCAAGTGCTACTTTACGCTTATTTGTCACTATCAAAGGTCGACCAGAA
68123 CCCGAAGTTAAATGGGAAAAGGCAGAAGGCATTCTCACTGACAGGGCTCAGATAGAGGTGACCAGCTCAT
68124 TTACAATGTTGGTGATTGATAATGTTACCAGATTTGACAGTGGTCGGTATAATCTGACATTAGAAAATAA
68125 TAGTGGCTCCAAAACAGCTTTTGTTAACGTCAGAGTTCTTGACTCACCAAGTGCCCCTGTGAATTTGACC
68126 ATAAGAGAAGTGAAGAAAGACTCAGTGACGTTGTCCTGGGAACCACCACTTATTGATGGTGGAGCTAAGA
68127 TTACAAACTACATTGTCGAAAAACGAGAAACTACAAGAAAAGCCTATGCTACCATTACAAATAATTGCAC
68128 TAAAACTACTTTCAGAATTGAAAATCTACAAGAAGGATGTTCTTACTACTTCCGAGTCTTGGCTTCCAAT
68129 GAATATGGGATTGGTTTGCCAGCTGAAACAACAGAACCCGTTAAAGTGTCTGAACCACCCCTCCCACCTG
68130 GAAGAGTAACTCTTGTTGATGTGACCCGTAATACAGCTACAATTAAGTGGGAGAAACCAGAAAGTGATGG
68131 TGGCAGCAAAATTACTGGTTATGTGGTTGAAATGCAGACTAAAGGGAGTGAAAAGTGGAGCACCTGCACA
68132 CAAGTTAAGACTCTAGAAGCAACTATATCTGGCTTAACTGCAGGAGAAGAGTATGTCTTCAGGGTAGCTG
68133 CAGTTAACGAAAAGGGAAGAAGTGATCCAAGACAACTTGGAGTGCCAGTAATTGCAAGGGATATTGAAAT
68134 AAAGCCTTCAGTTGAGCTTCCTTTCCATACTTTCAATGTAAAGGCTAGAGAACAACTTAAGATTGATGTG
68135 CCATTCAAAGGAAGACCTCAAGCTACTGTGAACTGGAGAAAAGATGGTCAGACTCTTAAAGAGACAACTA
68136 GAGTCAATGTTTCTTCTTCAAAGACTGTAACATCACTATCTATTAAGGAAGCTTCAAAGGAAGATGTTGG
68137 AACTTATGAATTATGTGTTTCAAACAGTGCTGGATCCATAACAGTTCCTATTACTATAATTGTCCTTGAC
68138 AGACCAGGACCTCCAGGTCCTATACGTATTGATGAGGTTAGTTGTGACAGCATAACCATTTCTTGGAATC
68139 CTCCAGAATATGATGGTGGCTGCCAAATTAGCAATTACATTGTTGAAAAGAAAGAAACCACCTCTACAAC
68140 ATGGCACATAGTTTCACAAGCAGTTGCAAGAACATCCATTAAAATAGTTCGCCTGACAACAGGAAGTGAG
68141 TATCAGTTCCGTGTTTGTGCAGAAAACCGCTATGGAAAGAGCTCCTACAGTGAATCTTCAGCTGTTGTTG
68142 CAGAGTATCCATTCAGTCCCCCAGGTCCTCCTGGTACTCCTAAAGTTGTGCATGCCACAAAATCTACCAT
68143 GCTTGTAACCTGGCAAGTGCCAGTTAATGATGGAGGAAGTCGAGTAATTGGCTATCATCTTGAGTATAAA
68144 GAAAGAAGCAGCATTCTTTGGTCAAAAGCAAATAAAATCCTCATTGCTGATACTCAAATGAAAGTCTCCG
68145 GCCTTGATGAAGGACTGATGTATGAGTATCGTGTATATGCTGAAAATATTGCTGGAATTGGTAAATGCAG
68146 TAAATCTTGTGAACCAGTCCCTGCAAGAGATCCTTGTGACCCTCCTGGACAACCTGAAGTCACAAATATC
68147 ACAAGAAAATCAGTGTCACTTAAATGGTCTAAACCACATTATGATGGTGGAGCTAAGATCACAGGATACA
68148 TTGTTGAACGCAGAGAACTACCAGATGGCCGGTGGCTGAAGTGCAATTATACTAATATACAAGAAACATA
68149 CTTTGAAGTAACTGAACTTACTGAAGATCAGCGTTATGAATTCCGGGTTTTTGCAAGGAATGCTGCTGAC
68150 TCAGTTAGTGAGCCATCTGAATCCACTGGGCCTATTATAGTTAAAGATGATGTTGAGCCTCCAAGAGTTA
68151 TGATGGATGTCAAGTTCCGAGACGTTATTGTTGTCAAAGCTGGAGAGGTCCTTAAGATAAATGCAGACAT
68152 TGCAGGGCGACCTCTGCCAGTAATTTCCTGGGCCAAGGATGGTATAGAAATTGAAGAAAGAGCAAGAACA
68153 GAAATCATCTCAACAGACAATCATACTTTGTTAACAGTTAAAGACTGTATAAGACGAGACACTGGGCAAT
68154 ATGTACTAACACTGAAGAATGTTGCCGGCACTCGGTCTGTGGCCGTTAATTGCAAAGTACTTGATAAGCC
68155 TGGTCCACCAGCAGGACCACTTGAAATAAATGGCCTCACTGCTGAGAAATGCTCTCTTTCCTGGGGACGT
68156 CCCCAAGAAGATGGTGGTGCAGATATCGACTATTACATCGTAGAAAAACGTGAAACAAGCCACCTTGCAT
68157 GGACAATATGTGAAGGAGAGTTACAGATGACATCCTGTAAAGTAACCAAGTTACTCAAAGGCAATGAATA
68158 TATATTTAGAGTAACTGGTGTTAATAAATATGGTGTTGGTGAGCCCCTAGAGAGTGTAGCTATAAAGGCA
68159 CTAGATCCATTTACAGTTCCAAGTCCACCCACGTCTTTGGAAATTACTTCTGTGACCAAAGAATCTATGA
68160 CACTTTGCTGGTCAAGACCCGAGAGTGATGGAGGTAGTGAAATATCTGGATATATAATTGAAAGGCGAGA
68161 GAAAAATAGCCTAAGATGGGTGCGTGTAAACAAAAAACCAGTTTATGATCTAAGAGTGAAATCAACAGGA
68162 CTTCGGGAAGGATGTGAATATGAATATCGTGTTTATGCAGAAAATGCTGCTGGCCTAAGTCTTCCAAGTG
68163 AAACCTCTCCCTTAATTAGGGCAGAAGATCCAGTGTTCCTACCATCTCCTCCATCCAAACCCAAAATTGT
68164 GGACTCAGGCAAGACAACTATAACTATTGCCTGGGTTAAGCCGCTGTTTGATGGTGGGGCCCCGATAACT
68165 GGATATACTGTAGAATACAAAAAATCTGATGACACTGACTGGAAAACTTCCATTCAGAGCTTACGAGGGA
68166 CAGAATATACAATAAGCGGACTAACAACAGGAGCTGAATATGTTTTCAGAGTAAAATCTGTCAATAAGGT
68167 TGGTGCTAGTGACCCCAGTGATAGCTCTGACCCTCAGATAGCAAAGGAAAGAGAAGAAGAACCTTTATTT
68168 GATATTGACAGTGAAATGAGGAAGACCTTGATTGTCAAGGCTGGTGCCTCATTTACCATGACTGTGCCTT
68169 TCCGAGGAAGACCAGTACCCAATGTCTTGTGGAGTAAGCCAGACACTGACCTCCGTACTAGAGCTTATGT
68170 TGATACCACAGACTCCCGTACATCACTGACCATTGAAAATGCCAACAGAAATGACTCTGGAAAGTACACA
68171 TTAACAATTCAGAATGTTTTGAGTGCTGCTTCACTGACCTTAGTTGTCAAAGTTTTAGATACCCCAGGTC
68172 CTCCAACCAACATTACTGTGCAAGATGTAACCAAAGAGTCTGCAGTGTTATCCTGGGATGTTCCTGAAAA
68173 CGATGGTGGAGCACCAGTGAAGAATTACCACATAGAAAAACGTGAGGCCAGCAAGAAAGCATGGGTCTCT
68174 GTGACCAACAACTGTAACCGCCTCTCCTACAAAGTTACCAATTTACAAGAAGGAGCTATCTATTACTTCA
68175 GAGTCTCTGGAGAAAATGAGTTTGGTGTTGGTATACCAGCTGAAACAAAGGAAGGAGTAAAAATAACAGA
68176 AAAACCAAGCCCACCTGAAAAACTTGGAGTAACAAGTATATCCAAAGACAGTGTTTCCCTGACCTGGCTG
68177 AAGCCTGAACATGATGGCGGAAGCAGAATTGTACACTATGTCGTTGAAGCACTAGAAAAAGGACAGAAAA
68178 ACTGGGTTAAATGTGCAGTGGCAAAGTCAACCCATCACGTTGTTTCCGGTCTGAGAGAGAATTCTGAATA
68179 CTTTTTCCGAGTGTTTGCTGAAAATCAAGCTGGCCTGAGTGACCCGAGAGAGCTTCTGCTTCCTGTTCTT
68180 ATTAAGGAGCAACTAGAACCACCTGAAATTGATATGAAGAATTTCCCAAGTCACACTGTATATGTTAGAG
68181 CTGGTTCAAACCTTAAAGTTGACATTCCAATCTCTGGAAAACCACTTCCCAAAGTGACCTTATCAAGAGA
68182 TGGTGTCCCCCTTAAGGCAACCATGAGATTTAATACCGAAATTACTGCTGAGAACCTGACCATCAATCTC
68183 AAAGAAAGTGTTACAGCTGACGCTGGGAGATATGAAATCACTGCTGCCAACTCCAGTGGTACAACCAAAG
68184 CTTTCATTAACATTGTTGTGCTAGACAGGCCTGGTCCTCCAACTGGCCCTGTTGTTATTAGTGATATAAC
68185 TGAAGAAAGTGTGACTCTCAAATGGGAGCCACCTAAGTATGACGGTGGAAGTCAAGTTACCAACTACATT
68186 CTACTCAAAAGAGAAACAAGTACTGCAGTGTGGACTGAAGTGTCTGCAACAGTTGCAAGAACCATGATGA
68187 AAGTCATGAAACTGACCACAGGAGAAGAATACCAATTCCGCATCAAGGCAGAAAACCGCTTTGGCATCAG
68188 TGATCATATAGATTCAGCTTGTGTGACTGTCAAACTACCATACACAACACCTGGACCACCATCTACACCA
68189 TGGGTCACTAATGTTACTCGAGAAAGCATCACTGTGGGCTGGCATGAACCAGTGTCAAATGGAGGCAGTG
68190 CAGTCGTAGGCTATCACCTGGAAATGAAAGACAGAAACAGTATTTTATGGCAAAAAGCCAACAAACTGGT
68191 CATCCGCACAACTCACTTCAAAGTCACAACAATCAGTGCTGGACTTATTTATGAATTCAGGGTGTATGCA
68192 GAAAATGCTGCTGGAGTTGGAAAACCTAGCCATCCTTCTGAACCAGTCTTGGCAATTGATGCTTGTGAAC
68193 CCCCAAGAAATGTTCGTATCACTGATATTTCAAAGAACTCTGTCAGCCTTTCATGGCAACAACCAGCTTT
68194 CGATGGAGGTAGCAAGATTACAGGCTACATTGTTGAGAGACGTGACCTTCCAGATGGCAGATGGACCAAG
68195 GCCAGCTTCACCAATGTTACTGAAACTCAATTCATCATCTCTGGCTTGACTCAGAATTCCCAGTATGAAT
68196 TCCGTGTCTTTGCTAGGAATGCTGTTGGTTCCATTAGCAATCCATCTGAGGTTGTAGGGCCCATTACTTG
68197 CATCGATTCTTATGGTGGTCCTGTAATTGATTTGCCTCTAGAATATACAGAAGTTGTCAAATACAGAGCA
68198 GGTACATCTGTGAAGCTCAGAGCTGGCATTTCTGGCAAACCTGCGCCTACTATTGAGTGGTATAAAGATG
68199 ATAAAGAATTACAAACCAATGCACTGGTGTGTGTTGAAAATACCACGGACCTCGCATCTATACTCATCAA
68200 AGATGCCGATCGCCTTAATAGTGGATGCTATGAATTAAAACTAAGGAATGCCATGGGCTCAGCCTCAGCC
68201 ACCATCAGAGTACAGATCCTTGACAAACCAGGCCCACCTGGTGGACCAATTGAATTTAAGACTGTAACTG
68202 CTGAGAAGATCACCCTTCTCTGGCGGCCTCCAGCTGATGATGGTGGTGCAAAAATCACTCACTACATTGT
68203 GGAAAAGCGTGAGACAAGCCGCGTTGTGTGGTCTATGGTGTCTGAACATTTGGAAGAGTGCATCATTACA
68204 ACCACCAAAATTATCAAAGGAAATGAATACATCTTCCGGGTCCGAGCCGTGAACAAATATGGAATTGGCG
68205 AGCCACTGGAATCTGATTCCGTTGTAGCCAAGAACGCATTTGTTACACCTGGGCCACCAGGCATACCAGA
68206 AGTGACAAAGATTACCAAGAATTCGATGACTGTTGTATGGAGCAGGCCAATTGCAGATGGCGGTAGTGAT
68207 ATAAGTGGCTATTTCCTTGAAAAACGAGACAAGAAGAGCCTAGGATGGTTTAAAGTACTAAAAGAGACTA
68208 TCCGTGACACCAGACAAAAAGTAACAGGACTCACAGAAAACAGTGACTATCAATACAGAGTTTGTGCTGT
68209 AAACGCTGCTGGACAGGGTCCATTTTCTGAACCATCTGAATTCTACAAAGCTGCTGATCCTATTGATCCT
68210 CCAGGTCCACCTGCTAAGATAAGAATCGCAGATTCAACCAAGTCATCCATCACCCTTGGCTGGAGTAAGC
68211 CTGTCTATGATGGGGGCAGTGCTGTTACTGGGTATGTTGTCGAGATAAGACAAGGAGAGGAAGAGGAATG
68212 GACTACTGTCTCTACCAAAGGAGAGGTCAGAACTACAGAATATGTGGTATCCAACCTGAAACCTGGAGTC
68213 AATTACTACTTCCGGGTATCTGCTGTAAACTGTGCTGGACAAGGAGAACCTATAGAAATGAATGAACCTG
68214 TACAAGCTAAAGATATACTTGAGGCACCAGAGATTGACCTGGATGTGGCTCTCAGAACTTCTGTTATTGC
68215 CAAAGCTGGTGAAGATGTACAAGTGTTGATTCCCTTTAAAGGCAGACCTCCACCTACTGTCACATGGAGA
68216 AAAGATGAGAAGAATCTTGGCAGTGATGCCAGATACAGCATTGAAAACACTGATTCATCCTCATTACTCA
68217 CCATTCCTCAAGTTACTCGCAATGATACAGGAAAATATATTCTCACAATAGAAAATGGAGTTGGTGAACC
68218 TAAGTCTTCAACTGTGAGTGTTAAAGTGCTTGACACACCAGCTGCCTGCCAGAAACTACAGGTTAAACAT
68219 GTTTCTCGAGGCACAGTCACTTTGCTCTGGGATCCTCCTCTCATTGATGGAGGATCTCCAATAATTAATT
68220 ATGTCATTGAAAAGAGAGATGCCACCAAGAGAACATGGTCTGTCGTGTCACACAAATGTTCTAGCACATC
68221 CTTCAAGCTAATAGATTTGTCGGAGAAGACTCCATTCTTCTTCAGAGTTCTTGCAGAAAATGAAATTGGA
68222 ATTGGGGAACCCTGTGAAACTACAGAGCCAGTGAAGGCTGCTGAAGTACCAGCTCCTATACGTGATCTCT
68223 CAATGAAAGACTCAACAAAGACATCTGTCATCCTCAGCTGGACCAAACCTGACTTTGATGGTGGTAGCGT
68224 CATCACAGAATATGTTGTAGAAAGGAAAGGTAAAGGTGAACAGACGTGGTCCCACGCTGGCATAAGTAAG
68225 ACATGTGAAATTGAGGTTAGCCAACTTAAGGAGCAGTCAGTCCTGGAGTTCAGAGTGTTTGCCAAAAATG
68226 AGAAAGGACTGAGTGATCCTGTCACTATTGGGCCAATTACAGTGAAAGAACTTATTATTACACCTGAAGT
68227 TGACCTGTCAGATATCCCTGGGGCACAAGTCACTGTGAGAATTGGGCACAATGTGCACCTTGAATTACCT
68228 TATAAGGGAAAACCCAAACCATCCATCAGTTGGCTGAAAGATGGCTTGCCACTGAAAGAAAGTGAATTTG
68229 TTCGCTTCAGTAAAACTGAAAACAAAATTACTTTGAGTATTAAGAATGCCAAGAAGGAGCATGGAGGAAA
68230 ATACACTGTTATTCTTGATAATGCAGTGTGTAGAATTGCAGTCCCCATTACAGTCATCACCCTTGGCCCA
68231 CCATCAAAGCCCAAAGGACCCATTCGATTTGATGAAATCAAGGCTGATAGTGTCATCCTGTCATGGGATG
68232 TACCTGAAGATAATGGAGGAGGAGAAATTACTTGTTACAGCATCGAGAAGCGGGAAACTTCACAAACTAA
68233 CTGGAGGATGGTGTGTTCAAGTGTTGCCAGAACGACTTTCAAAGTTCCTAATCTAGTCAAAGATGCTGAG
68234 TACCAGTTTAGAGTGAGAGCAGAAAACAGATACGGAGTCAGCCAACCACTTGTCTCAAGCATTATTGTGG
68235 CAAAACACCAGTTCAGGATTCCTGGTCCCCCAGGAAAGCCAGTTATATACAATGTGACTTCTGATGGCAT
68236 GTCACTAACTTGGGATGCTCCAGTTTATGATGGTGGTTCAGAAGTTACTGGATTCCATGTTGAAAAGAAA
68237 GAAAGAAATAGCATCCTCTGGCAAAAAGTTAATACATCACCAATCTCTGGAAGAGAATATAGAGCCACTG
68238 GACTGGTAGAAGGTCTGGATTACCAATTCCGTGTATATGCTGAAAATTCTGCTGGCCTAAGCTCACCTAG
68239 TGACCCAAGCAAATTTACCTTAGCTGTTTCTCCAGTAGACCCACCTGGCACTCCTGACTACATTGATGTC
68240 ACCCGGGAAACCATCACACTTAAATGGAACCCACCATTGCGTGATGGAGGCAGTAAGATTGTGGGCTATA
68241 GCATTGAGAAACGGCAAGGAAATGAACGCTGGGTGAGATGCAACTTTACTGACGTCAGTGAATGTCAGTA
68242 CACAGTTACAGGACTCAGTCCTGGGGATCGCTATGAGTTCAGAATAATTGCAAGAAATGCTGTTGGAACT
68243 ATAAGCCCGCCCTCACAGTCTTCTGGCATTATTATGACAAGAGATGAAAATGTTCCACCAATAGTAGAGT
68244 TTGGCCCTGAATACTTTGATGGTCTCATTATTAAGTCCGGAGAGAGCCTTAGAATTAAAGCTTTGGTACA
68245 AGGAAGACCAGTGCCTCGAGTAACTTGGTTCAAAGATGGAGTGGAAATCGAAAAGAGGATGAATATGGAA
68246 ATAACCGACGTACTTGGATCCACCAGCCTATTTGTTAGAGATGCTACTCGGGACCATCGTGGTGTATACA
68247 CAGTGGAAGCCAAAAATGCATCTGGTTCTGCAAAAGCAGAAATTAAAGTGAAAGTACAAGATACACCAGG
68248 AAAAGTAGTTGGGCCAATAAGATTCACCAATATTACTGGGGAGAAGATGACTCTGTGGTGGGATGCCCCA
68249 CTCAATGACGGTTGTGCTCCCATAACCCACTACATCATTGAAAAACGGGAAACCAGCAGACTTGCCTGGG
68250 CACTAATTGAGGATAAATGTGAAGCCCAAAGTTACACTGCCATTAAACTAATAAACGGCAATGAATACCA
68251 ATTCCGTGTTTCTGCAGTTAACAAGTTTGGTGTTGGCAGGCCACTTGATTCTGATCCAGTGGTTGCTCAA
68252 ATACAATATACTGTTCCTGATGCCCCTGGCATTCCAGAACCTAGCAACATAACAGGCAACAGCATTACCC
68253 TGACATGGGCAAGGCCAGAATCAGATGGTGGCAGTGAAATTCAACAGTATATCCTTGAAAGAAGAGAAAA
68254 GAAAAGCACAAGATGGGTAAAAGTGATCAGCAAACGACCAATCTCTGAAACAAGATTCAAAGTCACTGGT
68255 CTGACAGAAGGCAATGAGTATGAATTCCATGTCATGGCTGAAAATGCTGCAGGAGTTGGACCTGCAAGTG
68256 GCATCTCAAGACTCATTAAATGTAGAGAGCCCGTCAACCCACCAGGTCCTCCCACAGTGGTCAAAGTAAC
68257 AGACACATCAAAGACAACTGTGAGCTTAGAATGGTCCAAACCAGTGTTTGATGGTGGCATGGAAATAATT
68258 GGGTATATTATTGAAATGTGTAAGGCCGACTTAGGAGACTGGCACAAGGTGAATGCAGAGGCATGTGTGA
68259 AAACAAGATATACAGTCACTGATCTACAAGCAGGTGAAGAATACAAATTCCGAGTTAGTGCTATCAATGG
68260 TGCTGGAAAAGGCGACAGCTGTGAAGTGACTGGCACAATTAAAGCAGTTGACCGGTTAACAGCTCCTGAG
68261 TTAGACATAGATGCAAACTTCAAACAGACTCATGTTGTTAGAGCTGGGGCCAGTATTCGCCTCTTCATTG
68262 CCTACCAAGGTAGACCTACTCCTACAGCTGTGTGGAGCAAACCAGACTCTAACCTTAGCCTTCGGGCTGA
68263 TATCCATACAACAGATTCCTTCAGCACCCTCACTGTGGAAAACTGCAACAGAAATGATGCAGGGAAATAT
68264 ACCCTTACTGTGGAAAACAACAGTGGTAGTAAGTCAATCACATTCACCGTGAAAGTGCTAGACACTCCAG
68265 GCCCACCTGGCCCAATTACCTTCAAAGATGTGACCCGGGGATCTGCTACATTGATGTGGGATGCCCCTCT
68266 TCTTGACGGTGGTGCCCGAATCCATCATTATGTGGTAGAGAAACGAGAGGCAAGTCGCCGTAGTTGGCAG
68267 GTTATCAGTGAAAAATGCACTCGTCAGATCTTCAAGGTCAATGACCTGGCCGAAGGTGTTCCGTACTATT
68268 TCCGTGTTTCTGCAGTAAATGAGTATGGTGTTGGTGAGCCCTATGAAATGCCAGAACCAATTGTAGCCAC
68269 AGAACAGCCTGCTCCACCTAGGAGACTTGATGTTGTTGATACTAGCAAATCCTCCGCAGTCTTAGCTTGG
68270 CTTAAACCTGACCACGATGGAGGCAGCCGGATCACTGGCTACCTGCTTGAAATGAGACAAAAGGGATCTG
68271 ACTTCTGGGTTGAAGCTGGTCACACCAAACAGCTAACTTTCACAGTAGAGCGTCTTGTTGAGAAAACTGA
68272 ATATGAATTCCGTGTGAAGGCCAAGAATGATGCTGGCTATAGTGAACCCAGAGAAGCCTTCTCTTCTGTC
68273 ATCATTAAGGAGCCTCAAATCGAGCCCACTGCTGACCTCACTGGAATTACCAATCAGCTTATAACTTGCA
68274 AAGCAGGAAGCCCATTTACCATTGACGTACCAATCAGTGGTCGTCCTGCCCCCAAAGTAACATGGAAACT
68275 GGAAGAAATGAGACTTAAAGAGACAGATCGAGTGAGCATTACAACAACAAAAGACAGAACCACACTGACT
68276 GTAAAGGACAGCATGAGAGGTGACTCTGGAAGATACTTCTTGACCCTGGAAAATACAGCTGGTGTTAAAA
68277 CATTTAGCGTCACAGTTGTGGTCATTGGAAGGCCAGGTCCAGTAACCGGCCCCATTGAGGTCTCATCTGT
68278 CTCAGCTGAATCGTGTGTCCTGTCATGGGGAGAACCTAAAGATGGAGGAGGCACTGAAATTACTAATTAC
68279 ATAGTTGAAAAGCGTGAATCGGGTACAACAGCTTGGCAGCTTGTCAATTCCAGTGTCAAGCGCACTCAAA
68280 TTAAAGTCACTCATCTCACAAAATACATGGAATATTCTTTCCGTGTCAGTTCAGAGAACAGATTTGGTGT
68281 CAGCAAACCTCTAGAATCAGCACCAATAATTGCTGAACATCCATTTGTCCCACCAAGCGCTCCTACCAGA
68282 CCTGAGGTCTACCATGTGTCTGCCAATGCCATGTCTATTCGTTGGGAAGAACCCTACCACGATGGTGGCA
68283 GTAAAATCATTGGCTACTGGGTTGAGAAGAAAGAACGTAATACAATTCTTTGGGTGAAAGAAAACAAAGT
68284 GCCATGCTTAGAGTGCAACTACAAAGTAACTGGTTTAGTAGAAGGACTGGAATATCAGTTCAGAACTTAT
68285 GCACTCAATGCTGCAGGTGTTAGCAAGGCCAGCGAAGCTTCAAGACCTATAATGGCTCAAAATCCAGTTG
68286 ATGCACCAGGCAGACCAGAGGTGACAGATGTCACAAGATCAACAGTATCACTGATTTGGTCTGCCCCAGC
68287 GTATGATGGAGGCAGCAAGGTTGTGGGCTACATCATAGAGCGTAAGCCAGTCAGTGAGGTAGGAGATGGT
68288 CGCTGGCTGAAGTGCAACTACACCATTGTATCTGACAATTTCTTCACCGTGACTGCTCTCAGTGAAGGAG
68289 ACACTTATGAGTTCCGTGTGTTAGCCAAGAATGCAGCAGGCGTAATTAGCAAAGGGTCTGAATCTACAGG
68290 CCCTGTCACTTGCCGAGATGAATACGCTCCACCCAAAGCCGAACTGGATGCCCGATTACACGGTGATCTG
68291 GTTACCATCAGAGCAGGTTCTGATCTTGTTCTGGATGCTGCAGTTGGTGGCAAACCTGAACCCAAAATTA
68292 TCTGGACCAAAGGAGACAAGGAGCTAGATCTCTGTGAAAAAGTCTCTTTGCAGTATACTGGCAAACGAGC
68293 AACTGCTGTGATCAAGTTCTGTGACAGAAGTGACAGTGGAAAATACACTTTAACAGTGAAAAATGCCAGC
68294 GGGACCAAGGCCGTGTCTGTCATGGTCAAAGTGCTTGATTCCCCTGGCCCATGTGGAAAGCTCACCGTCA
68295 GCAGAGTAACACAGGAGAAGTGCACTTTAGCCTGGAGCCTTCCGCAGGAAGACGGAGGAGCAGAAATCAC
68296 TCACTACATCGTGGAAAGACGCGAGACTAGCAGGCTCAACTGGGTGATTGTTGAAGGCGAATGCCCAACC
68297 CTATCCTATGTCGTTACCAGGCTCATCAAGAACAATGAGTACATATTCCGAGTGAGGGCAGTAAACAAAT
68298 ATGGCCCTGGTGTGCCTGTTGAATCAGAGCCAATTGTAGCCAGAAACTCATTCACTATTCCATCACCACC
68299 CGGCATACCTGAAGAAGTTGGGACTGGCAAAGAGCATATCATCATTCAGTGGACAAAACCTGAATCTGAT
68300 GGTGGCAATGAAATCAGCAACTACCTAGTAGACAAACGTGAGAAGAAGAGCCTGCGCTGGACACGTGTCA
68301 ACAAAGACTATGTGGTGTATGATACCAGGCTGAAGGTGACCAGCCTGATGGAGGGTTGTGATTACCAGTT
68302 CCGGGTGACCGCAGTGAATGCAGCTGGTAACAGTGAGCCCAGCGAAGCTTCCAACTTCATCTCATGCAGA
68303 GAACCATCATATACCCCTGGACCACCTTCTGCTCCAAGAGTTGTGGATACCACCAAACACAGCATTAGTT
68304 TGGCATGGACCAAACCCATGTACGATGGTGGTACTGACATTGTAGGATATGTTCTGGAAATGCAAGAGAA
68305 GGACACTGATCAGTGGTACCGAGTGCATACCAATGCCACAATAAGAAATACTGAATTCACTGTGCCAGAC
68306 CTTAAAATGGGCCAGAAATATTCCTTCAGAGTTGCTGCCGTGAACGTGAAGGGTATGAGCGAATACAGCG
68307 AATCAATTGCTGAAATTGAGCCCGTGGAAAGAATAGAAATACCAGATCTTGAGCTTGCAGATGATCTAAA
68308 GAAGACTGTGACCATCAGGGCTGGGGCCTCCTTGCGCTTGATGGTGTCTGTATCTGGAAGACCACCTCCT
68309 GTCATAACGTGGAGCAAGCAGGGCATTGACCTTGCAAGCCGGGCAATTATTGACACCACTGAGAGCTACT
68310 CATTGCTAATAGTGGACAAAGTTAATCGGTACGATGCTGGAAAATACACAATTGAAGCTGAAAACCAATC
68311 TGGCAAGAAATCAGCAACAGTCCTTGTTAAAGTCTATGATACTCCTGGTCCCTGTCCTTCAGTGAAAGTT
68312 AAGGAAGTATCAAGAGATTCTGTGACTATAACTTGGGAAATTCCCACGATTGATGGTGGAGCTCCAGTCA
68313 ACAATTACATCGTTGAGAAGCGTGAAGCTGCTATGAGAGCATTCAAAACAGTAACTACCAAATGCAGCAA
68314 GACACTTTACAGAATTTCTGGACTTGTAGAAGGAACCATGTACTATTTCAGAGTGCTGCCAGAAAATATT
68315 TATGGCATTGGAGAACCTTGTGAAACATCTGATGCAGTACTGGTCTCAGAAGTGCCTTTGGTGCCTGCAA
68316 AGCTAGAAGTGGTCGATGTCACCAAATCCACTGTTACCCTTGCCTGGGAAAAACCACTCTACGATGGTGG
68317 TAGCCGACTCACTGGATATGTTCTCGAGGCCTGCAAAGCTGGCACAGAGAGATGGATGAAGGTTGTCACC
68318 TTAAAACCCACAGTCCTAGAGCACACTGTTACTTCCTTAAATGAAGGTGAACAATACTTATTTAGAATAA
68319 GGGCACAAAATGAGAAAGGTGTGTCAGAACCAAGAGAGACTGTCACAGCCGTGACTGTACAAGACCTCAG
68320 AGTGTTGCCAACAATCGATCTTTCTACAATGCCTCAGAAGACCATCCATGTCCCAGCTGGCAGACCAGTA
68321 GAGCTGGTGATACCTATTGCTGGCCGTCCACCTCCTGCTGCTTCCTGGTTCTTTGCTGGTTCTAAACTGA
68322 GAGAATCAGAGCGTGTCACAGTTGAAACTCACACTAAAGTAGCTAAATTAACCATCCGTGAAACCACTAT
68323 CAGAGATACTGGAGAATACACACTTGAATTGAAGAATGTTACCGGAACTACTTCAGAAACCATTAAAGTT
68324 ATCATTCTTGACAAGCCTGGTCCACCAACAGGACCTATTAAGATTGATGAAATTGATGCTACATCAATTA
68325 CCATTTCCTGGGAACCACCTGAATTGGACGGTGGTGCTCCACTGAGTGGTTATGTGGTAGAACAACGTGA
68326 CGCTCATCGTCCAGGATGGCTGCCCGTTTCTGAATCAGTGACTAGGTCCACGTTTAAGTTTACCAGACTC
68327 ACCGAAGGAAATGAGTATGTGTTCCGTGTGGCTGCAACAAACCGCTTCGGGATTGGCTCTTACTTGCAGT
68328 CTGAGGTCATAGAGTGTCGCAGCAGCATCCGTATTCCTGGACCCCCAGAAACATTACAGATATTTGATGT
68329 TTCCCGTGATGGCATGACACTTACTTGGTACCCACCAGAGGATGACGGTGGCTCCCAAGTGACTGGATAT
68330 ATTGTGGAGCGCAAAGAAGTGAGAGCAGATCGATGGGTCCGTGTAAATAAAGTACCTGTGACAATGACAC
68331 GGTACCGCTCCACTGGCCTTACTGAAGGCTTAGAATATGAACACCGTGTCACAGCCATTAATGCAAGAGG
68332 GTCTGGGAAACCAAGTCGTCCTTCCAAACCCATCGTTGCCATGGATCCAATTGCTCCTCCAGGAAAGCCA
68333 CAAAACCCAAGAGTTACTGATACAACAAGGACATCAGTCTCCCTGGCCTGGAGTGTTCCAGAAGATGAAG
68334 GAGGATCTAAAGTCACAGGCTACTTGATTGAAATGCAAAAAGTAGATCAACATGAATGGACCAAGTGTAA
68335 CACCACTCCAACCAAGATTCGAGAGTATACTCTAACACACCTACCTCAGGGTGCAGAATACAGGTTCCGC
68336 GTCCTAGCTTGTAATGCTGGTGGACCTGGTGAGCCTGCTGAGGTACCAGGAACAGTCAAAGTCACTGAAA
68337 TGCTTGAATATCCTGATTATGAACTTGATGAAAGATACCAAGAAGGTATCTTTGTAAGGCAAGGTGGCGT
68338 CATCAGACTTACCATACCAATCAAAGGAAAACCATTCCCAATATGTAAATGGACCAAGGAAGGCCAGGAT
68339 ATTAGTAAGCGTGCCATGATTGCAACATCTGAAACACACACTGAGCTTGTGATCAAAGAAGCAGACAGGG
68340 GTGATTCTGGCACTTATGACCTGGTTCTGGAAAATAAATGTGGCAAGAAGGCTGTCTACATCAAGGTCAG
68341 GGTGATAGGAAGTCCCAACAGTCCAGAAGGGCCACTGGAATATGATGACATCCAAGTCCGCTCTGTGAGG
68342 GTCAGCTGGAGACCTCCTGCTGATGATGGTGGTGCTGACATCTTAGGCTACATCCTCGAGAGACGAGAAG
68343 TGCCTAAAGCCGCCTGGTATACCATTGATTCCAGAGTCCGAGGTACATCTCTGGTGGTAAAAGGCCTCAA
68344 AGAGAATGTAGAATACCATTTCCGTGTTTCAGCAGAAAACCAGTTTGGCATAAGCAAACCCTTGAAATCT
68345 GAGGAACCAGTCACACCAAAAACACCATTGAATCCTCCAGAACCTCCAAGCAATCCTCCAGAAGTACTCG
68346 ATGTAACCAAGAGTTCTGTTAGCTTGTCCTGGTCCCGGCCCAAAGATGATGGTGGTTCTAGAGTCACAGG
68347 CTACTACATCGAACGCAAAGAGACATCCACTGACAAGTGGGTCAGACACAACAAGACTCAGATCACCACC
68348 ACAATGTACACTGTCACAGGGCTTGTTCCCGATGCTGAGTATCAGTTCCGCATCATCGCACAGAATGATG
68349 TTGGCCTGAGTGAGACCAGCCCTGCTTCTGAACCAGTTGTTTGCAAAGATCCATTTGATAAACCAAGCCA
68350 ACCAGGAGAACTTGAGATTCTTTCAATATCCAAAGATAGTGTCACTCTACAGTGGGAGAAACCTGAATGT
68351 GATGGTGGTAAAGAAATTCTTGGATACTGGGTTGAATATAGACAGTCTGGAGACAGTGCCTGGAAGAAGA
68352 GCAATAAGGAACGTATTAAGGACAAGCAATTCACAATAGGAGGTTTGCTGGAAGCTACTGAGTATGAATT
68353 CAGGGTTTTTGCTGAGAATGAGACTGGGCTGAGCAGACCTCGCAGAACTGCTATGTCTATAAAGACTAAA
68354 CTCACATCTGGAGAGGCCCCAGGAATACGCAAAGAAATGAAGGATGTTACCACAAAATTGGGTGAAGCTG
68355 CTCAACTCTCATGCCAGATTGTTGGAAGGCCTCTTCCTGACATTAAATGGTACAGATTTGGTAAAGAGCT
68356 CATACAAAGCCGGAAATACAAAATGTCTTCAGATGGACGCACACACACTCTTACAGTAATGACAGAGGAA
68357 CAGGAAGATGAAGGTGTTTATACCTGCATAGCCACCAATGAGGTTGGAGAAGTAGAAACCAGTAGTAAGC
68358 TTCTCCTGCAAGCAACACCGCAGTTCCATCCTGGTTACCCACTGAAAGAGAAATATTATGGAGCTGTGGG
68359 TTCCACACTTCGGCTTCATGTTATGTACATTGGTCGTCCAGTACCTGCCATGACTTGGTTCCATGGTCAG
68360 AAACTTTTGCAAAACTCAGAAAACATTACTATTGAAAACACTGAGCACTATACTCATCTTGTCATGAAGA
68361 ATGTCCAACGTAAGACTCATGCTGGGAAATACAAAGTCCAGCTCAGCAATGTTTTTGGAACAGTTGATGC
68362 CATCCTTGATGTGGAAATACAAGATAAACCAGACAAACCTACAGGACCAATTGTGATCGAAGCTCTATTG
68363 AAGAACTCCGCAGTGATCAGCTGGAAACCACCCGCAGATGACGGAGGCTCCTGGATCACCAACTATGTGG
68364 TGGAAAAATGTGAGGCCAAGGAGGGGGCTGAATGGCAATTGGTGTCTTCAGCCATCTCAGTGACAACCTG
68365 TAGAATTGTGAACCTCACAGAAAATGCTGGCTATTACTTCCGGGTTTCAGCTCAGAACACTTTCGGCATC
68366 AGTGACCCTCTAGAAGTGTCCTCAGTTGTGATCATTAAGAGTCCATTTGAAAAGCCAGGTGCTCCTGGCA
68367 AACCAACTATTACTGCTGTCACAAAAGATTCTTGTGTTGTGGCCTGGAAGCCACCTGCCAGTGATGGAGG
68368 TGCAAAGATTAGAAATTACTACCTTGAGAAGCGTGAGAAGAAGCAGAATAAATGGATTTCTGTGACAACA
68369 GAAGAAATTCGAGAAACTGTCTTTTCAGTGAAAAACCTTATTGAAGGTCTTGAATACGAGTTTCGTGTGA
68370 AATGTGAAAATCTAGGTGGGGAAAGTGAATGGAGTGAAATATCAGAACCCATCACTCCCAAATCTGATGT
68371 CCCAATTCAGGCACCACACTTTAAAGAGGAACTGAGAAATCTAAATGTCAGATATCAGAGCAATGCTACC
68372 TTGGTCTGCAAAGTGACTGGTCATCCAAAACCTATCGTCAAATGGTACAGACAAGGCAAAGAAATCATTG
68373 CAGATGGATTAAAATATAGGATTCAAGAATTTAAGGGTGGCTACCACCAGCTCATCATTGCAAGTGTCAC
68374 AGATGATGATGCCACAGTTTACCAAGTCAGAGCTACCAACCAAGGGGGATCTGTGTCTGGCACTGCCTCC
68375 TTGGAAGTGGAAGTTCCAGCTAAGATACACTTACCTAAAACTCTTGAAGGCATGGGAGCAGTTCATGCTC
68376 TCCGAGGTGAAGTGGTCAGCATCAAGATTCCTTTCAGTGGCAAACCAGATCCTGTGATCACCTGGCAGAA
68377 AGGACAAGATCTCATTGACAATAATGGCCACTACCAAGTTATTGTCACAAGATCCTTCACATCACTTGTT
68378 TTCCCCAATGGGGTAGAGAGAAAAGATGCTGGTTTCTATGTGGTCTGTGCTAAAAACAGATTTGGAATTG
68379 ATCAGAAGACAGTTGAACTGGATGTGGCTGATGTTCCTGACCCACCCAGAGGAGTCAAAGTTAGTGATGT
68380 CTCACGAGATTCTGTCAACTTAACATGGACTGAGCCAGCCTCTGATGGTGGCAGCAAAATCACCAACTAC
68381 ATTGTTGAAAAATGTGCAACTACTGCAGAAAGATGGCTCCGTGTAGGACAGGCCCGAGAAACACGTTATA
68382 CCGTGATCAACTTATTTGGAAAAACAAGTTACCAGTTCCGGGTAATAGCTGAAAATAAATTTGGTCTGAG
68383 CAAGCCTTCAGAGCCTTCAGAACCAACCATAACCAAAGAAGATAAGACCAGAGCTATGAACTATGATGAA
68384 GAGGTAGATGAAACCAGGGAAGTCTCCATGACTAAAGCATCTCACTCTTCAACCAAGGAACTCTATGAGA
68385 AATATATGATTGCTGAAGATCTTGGGCGTGGTGAGTTTGGAATTGTCCATCGTTGTGTTGAAACATCCTC
68386 AAAGAAGACATACATGGCCAAATTTGTTAAAGTCAAAGGGACTGATCAGGTTTTGGTAAAGAAGGAAATT
68387 TCCATTCTGAATATTGCTAGGCATAGAAACATCTTACACCTCCATGAATCATTTGAAAGCATGGAAGAAT
68388 TAGTTATGATCTTTGAGTTTATATCAGGACTTGACATATTTGAGCGCATTAACACAAGTGCTTTTGAACT
68389 TAATGAAAGAGAAATTGTAAGTTATGTTCACCAGGTCTGTGAAGCACTTCAGTTTTTACACAGTCATAAT
68390 ATTGGACACTTTGACATTAGACCAGAAAATATCATTTACCAAACCAGAAGAAGCTCTACCATTAAAATCA
68391 TAGAATTTGGTCAAGCCCGTCAGCTGAAACCAGGGGACAACTTCAGGCTTCTATTCACTGCCCCAGAATA
68392 CTATGCACCTGAAGTCCACCAGCATGATGTTGTCAGCACAGCCACAGACATGTGGTCACTTGGAACACTG
68393 GTATATGTGCTATTGAGTGGTATCAACCCATTCCTGGCTGAAACTAACCAACAGATCATTGAGAATATCA
68394 TGAATGCTGAATATACTTTCGATGAGGAAGCATTCAAAGAGATTAGCATTGAAGCCATGGATTTTGTTGA
68395 CCGGTTGTTAGTGAAAGAGAGGAAATCTCGCATGACAGCATCGGAGGCTCTCCAGCACCCATGGTTGAAG
68396 CAGAAGATAGAAAGAGTCAGTACTAAAGTTATCAGAACATTAAAACACCGGCGTTATTACCACACCCTGA
68397 TCAAGAAAGACCTCAACATGGTTGTGTCAGCAGCCCGGATCTCCTGTGGTGGTGCAATTCGATCTCAGAA
68398 GGGAGTGAGTGTTGCTAAAGTTAAAGTGGCATCCATTGAAATTGGCCCAGTTTCTGGGCAGATAATGCAT
68399 GCAGTTGGTGAAGAAGGAGGACATGTCAAATATGTATGCAAAATTGAAAATTATGATCAGTCTACCCAAG
68400 TGACTTGGTACTTTGGCGTCCGACAGCTGGAGAACAGTGAGAAATACGAAATCACCTACGAAGATGGAGT
68401 GGCCATCCTCTATGTCAAAGACATTACCAAATTAGATGATGGTACCTACAGATGCAAAGTAGTCAATGAC
68402 TATGGTGAAGACAGTTCTTATGCAGAGCTATTTGTTAAAGGTGTGAGAGAAGTCTATGACTATTACTGCC
68403 GTAGAACCATGAAGAAAATTAAGCGCAGAACAGACACAATGAGACTCCTGGAAAGGCCACCAGAATTTAC
68404 CCTGCCTCTCTATAATAAGACAGCTTATGTAGGTGAAAATGTCCGGTTTGGAGTAACTATAACTGTCCAC
68405 CCAGAGCCTCATGTAACATGGTATAAATCAGGTCAGAAAATCAAACCAGGTGACAATGACAAGAAGTACA
68406 CATTTGAGTCAGACAAGGGTCTTTACCAATTAACAATCAACAGTGTCACTACAGATGATGACGCTGAATA
68407 TACTGTTGTGGCAAGGAACAAATATGGTGAAGACAGCTGTAAAGCAAAGCTGACAGTAACCCTACACCCA
68408 CCTCCAACAGATAGTACCTTAAGACCCATGTTCAAAAGGTTACTGGCAAATGCAGAATGCCAAGAAGGCC
68409 AAAGTGTCTGCTTTGAGATCAGAGTGTCTGGCATCCCCCCACCAACATTAAAATGGGAGAAAGATGGTCA
68410 GCCACTGTCCCTCGGGCCTAACATTGAAATTATCCATGAAGGCTTGGATTATTATGCTCTGCACATCAGG
68411 GACACTTTGCCTGAAGACACGGGTTATTATAGAGTCACAGCCACTAACACAGCTGGGTCCACCAGCTGCC
68412 AGGCTCACCTACAAGTGGAACGCCTGAGGTACAAGAAACAGGAATTCAAGAGTAAGGAGGAGCATGAGCG
68413 ACACGTACAAAAACAAATTGACAAAACCCTCAGAATGGCTGAAATTCTTTCTGGAACTGAAAGTGTACCA
68414 CTGACACAGGTAGCTAAAGAGGCTCTGAGAGAAGCTGCTGTCCTTTATAAACCGGCTGTAAGCACCAAGA
68415 CTGTAAAAGGGGAATTCAGACTTGAGATAGAAGAAAAGAAGGAGGAGAGAAAACTCCGGATGCCTTATGA
68416 TGTACCAGAGCCACGCAAGTATAAGCAGACTACCATAGAAGAAGACCAACGCATCAAGCAGTTCGTGCCC
68417 ATGTCTGACATGAAGTGGTATAAAAAGATACGTGATCAGTATGAAATGCCTGGGAAACTTGACAGAGTTG
68418 TACAGAAACGACCCAAGCGCATCCGCCTTTCAAGATGGGAACAGTTCTATGTGATGCCTCTTCCACGCAT
68419 TACAGATCAATACAGACCTAAATGGCGTATTCCTAAACTGTCCCAAGATGATCTTGAGATAGTGAGACCA
68420 GCCCGCCGGCGTACACCTTCTCCTGATTATGACTTTTACTACCGACCTAGAAGACGTTCTCTTGGGGACA
68421 TCTCTGATGAAGAATTACTCCTCCCCATTGATGACTACTTAGCAATGAAAAGAACAGAGGAAGAGAGGCT
68422 GCGTCTTGAAGAAGAGCTTGAGTTAGGTTTTTCAGCTTCACCCCCAAGTCGAAGCCCTCCACACTTTGAG
68423 CTTTCTAGCCTACGTTACTCTTCACCACAAGCTCATGTCAAGGTGGAGGAAACAAGAAAAGACTTCAGGT
68424 ATTCAACCTATCACATCCCAACGAAGGCTGAAGCTAGTACAAGTTATGCAGAACTGAGGGAACGGCATGC
68425 CCAGGCTGCGTACAGACAGCCAAAGCAACGGCAAAGAATCATGGCTGAGAGGGAGGATGAAGAGTTGCTT
68426 CGCCCAGTTACGACCACCCAGCATCTCTCAGAATACAAAAGCGAACTTGACTTCATGTCAAAGGAGGAAA
68427 AGTCTAGAAAGAAATCAAGGCGACAAAGAGAAGTGACAGAAATAACAGAAATTGAGGAAGAATACGAAAT
68428 CTCAAAACATGCTCAAAGAGAATCATCCTCATCTGCGTCTAGACTACTGAGACGACGGCGCTCCCTGTCT
68429 CCAACTTATATTGAGTTAATGAGGCCAGTGTCTGAGCTGATCCGGTCACGTCCACAACCGGCTGAGGAAT
68430 ACGAAGATGACACAGAAAGAAGGTCACCTACTCCAGAGAGAACTCGCCCACGATCCCCCAGCCCTGTGTC
68431 TAGTGAGAGATCACTCTCGAGATTTGAGAGGTCTGCAAGATTTGATATCTTTTCCAGGTATGAGTCCATG
68432 AAAGCTGCTTTAAAAACTCAGAAGACATCAGAAAGGAAGTATGAAGTTTTGAGTCAGCAGCCTTTCACAC
68433 TGGACCATGCCCCTCGAATCACACTGAGAATGCGCTCGCACAGGGTACCATGTGGCCAAAATACACGTTT
68434 TATTTTAAATGTTCAGTCTAAGCCAACTGCCGAGGTTAAATGGTACCACAATGGTGTGGAACTCCAAGAA
68435 AGCAGTAAGATTCATTACACCAACACGAGTGGAGTCCTCACCCTGGAAATTCTGGACTGTCATACTGATG
68436 ACAGTGGAACCTACCGTGCTGTGTGCACCAACTACAAGGGCGAAGCTTCTGACTATGCAACGTTGGACGT
68437 GACAGGAGGGGATTATACCACCTATGCTTCCCAACGCAGAGATGAAGAGGTCCCCAGATCTGTTTTCCCT
68438 GAGCTGACAAGAACAGAGGCGTATGCTGTTTCATCATTTAAGAAAACATCTGAGATGGAAGCTTCGTCTT
68439 CTGTCAGGGAAGTGAAATCACAGATGACGGAGACAAGGGAAAGTCTCTCCTCATATGAACACTCTGCATC
68440 TGCAGAAATGAAAAGTGCTGCATTAGAAGAAAAGTCACTGGAAGAAAAATCCACAACCAGAAAGATCAAG
68441 ACGACTTTGGCAGCAAGAATTCTAACAAAGCCACGGTCCATGACCGTCTACGAGGGCGAGTCTGCAAGGT
68442 TTTCTTGTGACACCGATGGTGAGCCGGTACCAACTGTGACCTGGCTGCGTAAAGGACAAGTGCTAAGTAC
68443 TTCTGCCCGCCACCAAGTGACCACCACAAAGTACAAATCAACCTTTGAGATCTCTTCAGTCCAGGCTTCC
68444 GATGAGGGCAATTACAGCGTGGTGGTAGAAAACAGTGAAGGGAAACAAGAAGCAGAGTTCACTCTGACTA
68445 TTCAAAAGGCCAGGGTAACTGAAAAGGCTGTGACATCACCACCAAGAGTCAAATCCCCAGAGCCTCGGGT
68446 GAAATCCCCAGAAGCAGTTAAGTCTCCAAAACGAGTGAAATCTCCAGAACCTTCTCACCCGAAAGCCGTA
68447 TCACCCACAGAGACAAAACCAACACCAACAGAGAAAGTTCAGCACCTCCCAGTCTCTGCCCCACCAAAGA
68448 TTACTCAGTTCCTGAAAGCAGAAGCTTCTAAAGAGATTGCAAAACTGACCTGTGTGGTTGAAAGCAGTGT
68449 ATTAAGGGCAAAAGAGGTCACCTGGTATAAAGATGGCAAGAAACTGAAGGAAAATGGGCATTTCCAGTTT
68450 CATTATTCAGCAGATGGTACCTATGAGCTCAAAATCAATAACCTCACTGAATCTGATCAAGGAGAATATG
68451 TTTGTGAGATTTCTGGTGAAGGTGGAACGTCTAAAACCAACTTACAATTTATGGGGCAAGCCTTTAAGAG
68452 TATCCATGAGAAGGTATCAAAAATATCAGAAACTAAGAAATCAGATCAGAAAACCACTGAGTCAACAGTA
68453 ACCAGAAAAACTGAACCAAAAGCTCCTGAACCAATTTCCTCAAAACCAGTAATTGTTACTGGGTTGCAGG
68454 ATACAACTGTTTCTTCAGACAGTGTTGCTAAATTTGCAGTTAAGGCTACTGGAGAACCCCGGCCAACTGC
68455 CATCTGGACAAAAGATGGAAAGGCCATTACACAAGGAGGTAAATATAAACTCTCTGAAGACAAGGGAGGG
68456 TTCTTCTTAGAAATTCATAAGACTGATACTTCTGACAGTGGACTTTATACTTGTACAGTAAAAAATTCAG
68457 CTGGATCTGTGTCCTCTAGCTGCAAATTAACAATAAAAGCTATAAAAGATACTGAGGCACAGAAAGTCTC
68458 TACACAAAAGACTTCTGAAATTACACCTCAGAAGAAAGCTGTTGTCCAAGAGGAAATTTCCCAAAAAGCC
68459 CTAAGGTCTGAAGAAATTAAGATGTCAGAGGCAAAATCTCAAGAAAAGTTAGCCCTCAAAGAGGAAGCTT
68460 CAAAGGTTCTGATTTCTGAAGAAGTCAAGAAATCAGCAGCAACCTCCCTGGAAAAATCCATTGTCCATGA
68461 GGAAATCACTAAAACATCACAGGCATCAGAAGAAGTCAGAACTCATGCTGAGATTAAAGCATTTTCTACT
68462 CAGATGAGCATAAACGAAGGTCAAAGACTGGTTTTAAAAGCCAACATTGCTGGTGCCACTGATGTGAAAT
68463 GGGTACTGAATGGCGTAGAGCTTACCAACTCTGAGGAGTACCGATATGGTGTCTCAGGCAGCGATCAGAC
68464 CCTAACCATCAAGCAAGCCAGTCACAGAGATGAAGGAATCCTCACCTGCATAAGCAAAACCAAGGAAGGA
68465 ATCGTCAAGTGTCAGTATGATTTGACACTGAGCAAAGAACTCTCAGATGCTCCAGCCTTCATCTCACAGC
68466 CTAGATCTCAAAATATTAATGAAGGACAAAATGTTCTCTTTACTTGTGAAATCAGTGGCGAGCCATCCCC
68467 TGAAATCGAATGGTTTAAAAACAACCTGCCAATTTCTATTTCTTCAAATGTCAGCATAAGCCGCTCCAGA
68468 AATGTATACTCCCTTGAAATCCGAAATGCATCAGTCAGCGACAGTGGAAAGTACACAATTAAGGCCAAAA
68469 ATTTCCGTGGCCAGTGTTCAGCTACAGCTTCCTTAATGGTCCTTCCTCTAGTTGAAGAACCTTCCAGAGA
68470 GGTAGTATTGAGAACAAGTGGTGACACAAGCTTGCAAGGAAGCTTCTCGTCTCAGTCAGTCCAAATGTCT
68471 GCCTCCAAGCAGGAGGCCTCCTTCAGCAGTTTCAGCAGCAGCAGTGCTAGCAGCATGACTGAGATGAAAT
68472 TTGCAAGCATGTCTGCCCAAAGCATGTCCTCCATGCAAGAGTCCTTTGTAGAAATGAGTTCCAGCAGCTT
68473 TATGGGAATATCTAATATGACACAACTGGAAAGCTCAACTAGTAAAATGCTTAAAGCAGGCATAAGAGGA
68474 ATTCCGCCTAAAATTGAAGCTCTTCCATCTGATATCAGCATTGATGAAGGCAAAGTTCTAACAGTAGCCT
68475 GTGCTTTCACGGGTGAGCCTACCCCAGAAGTAACATGGTCCTGTGGTGGAAGAAAAATCCACAGTCAAGA
68476 ACAGGGGAGGTTCCACATTGAAAACACAGATGACCTGACAACCCTGATCATCATGGACGTACAGAAACAA
68477 GATGGTGGACTTTATACCCTGAGTTTAGGGAATGAATTTGGATCTGACTCTGCCACTGTGAATATACATA
68478 TTCGATCCATTTAAGAGGGCCTGTGCCCTTATACTCTACACTCATTCTTAACTTTTCGCAAACGTTTCAC
68479 ACGGACTAATCTTTCTGAACTGTAAATATTTAAAGAAAAAAAAGTAGTTTTGTATCAACCTAAATGAGTC
68480 AAAGTTCAAAAATATTCATTTCAATCTTTTCATAATTGTTGACCTAAGAATATAATACATTTGCTAGTGA
68481 CATGTACATACTGTATATAGCCGGATTAACGGTTATAAAGTTTTGTACCATTTATTTTATGACATTTTAC
68482 AATGTAAGTTTTGAAACTAACTGTTGGTAGGAGAAAGTTTCTTATGGAACGAATACCCTGCTCAACATTT
68483 AATCAATCTTTGTGCCTCAACATACTGTTGATGTCTAAGTATGCCTCAGTGGGTTGAGAAAATCCCCATT
68484 GAAGATGTCCTGTCCACCTAAAAGAGAATGATGCTGTGCATATCACTTGATATGTGCACCAATACCTACT
68485 GAATCAGAAATGTAAGGCATTGGTGATGTTTGCATTTACCCTCCTGTAAGCAACACTTTAACGTCTTACA
68486 TTTTCTCTGATGATGTCACACAAAATTATCATGACAAATATTACCAGAGCAAAGTGTAACGGCCAACACT
68487 TTGTTCGCTCATTTTACGCTGTCTCTGACATAAGGAGTGCCTGAATAGCTTGGAAAAGTAACATCTCCTG
68488 GCCATCCCTTCATTTAACCAAGCTATTCAAGTATTCCTATGCCAGAGCAGTGCCAACTCTTGGAGGTCCC
68489 AGAGTGCAGCCAATGCCTTTGTGTGGTAGTTCTAAATTTTAATTGCACCTGAAAAACCTGGGCACCTAAG
68490 CAATGAGCCACAGCAAAAAGTAAAGAACAACAACAAAATAAAGCTGTTGTTAAATTTTAAACAATATTAC
68491 TAATTGCCCAAAATGTCAATTTGATGTAGTTCTTTTCATGCAAGTATAAATTCAATTGTTAGTTATAATT
68492 GTTGGACCTCCTTGAGATAGTAACAACAAAATAAAGCAAGCTATCTGCACCTCAAAA
68493 X
68494 SHAR_EOF
68495 chmod 0644 titin_hum.seq ||
68496 echo 'restore of titin_hum.seq failed'
68497 Wc_c="`wc -c < 'titin_hum.seq'`"
68498 test 83286 -eq "$Wc_c" ||
68499         echo 'titin_hum.seq: original size 83286, current size' "$Wc_c"
68500 fi
68501 # ============= uascii.h ==============
68502 if test -f 'uascii.h' -a X"$1" != X"-c"; then
68503         echo 'x - skipping uascii.h (File already exists)'
68504 else
68505 echo 'x - extracting uascii.h (Text)'
68506 sed 's/^X//' << 'SHAR_EOF' > 'uascii.h' &&
68507 /* Concurrent read version */
68508 /*      ascii.gbl       ascii translation to amino acids */
68509 /*      modified 10-Mar-1987 for B, Z   */
68510 X
68511 /* $Name: fa_34_26_5 $ - $Id: uascii.h,v 1.6 2004/12/30 16:45:01 wrp Exp $ */
68512 X
68513 #define NA 123
68514 #define NANN 50
68515 #define ESS 49  /* code for ',' in FASTS,FASTF, FASTM */
68516 #define EL 125
68517 #define ES 126
68518 #define AAMASK 127
68519 X
68520 #ifndef XTERNAL
68521 /*       0  1  2  3  4  5  6  7  8  9  10 11 12 13 14 15        */
68522 /* 32       !  "  #  $  %  &  '  (  )  *  +  ,  -  .  /         */
68523 /* 48    0  1  2  3  4  5  6  7  8  9  :  ;  <  =  >  ?         */
68524 /* 64    @  A  B  C  D  E  F  G  H  I  J  K  L  M  N  O         */ 
68525 /* 80    P  Q  R  S  T  U  V  W  X  Y  Z  [  \  ]  ^  _         */ 
68526 /* 96    `  a  b  c  d  e  f  g  h  i  j  k  l  m  n  o         */
68527 /*112    p  q  r  s  t  u  v  w  x  y  z  {  |  }  ~  ^?        */ 
68528 X
68529 int aascii[128]={
68530 X       EL,NA,NA,NA,NA,NA,NA,NA,NA,NA,EL,NA,NA,EL,NA,NA,        /* 15 */
68531 X       NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,        /* 31 */
68532 X       NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,24,NA,NA,NA,NA,NA,        /* 47 */
68533 X       NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,        /* 63 */
68534 X       NA, 1,21, 5, 4, 7,14, 8, 9,10,NA,12,11,13, 3,NA,        /* 79 */
68535 X       15, 6, 2,16,17,23,20,18,23,19,22,NA,NA,NA,NA,NA,        /* 95 */
68536 X       NA, 1,21, 5, 4, 7,14, 8, 9,10,NA,12,11,13, 3,NA,        /*111 */
68537 X       15, 6, 2,16,17,23,20,18,23,19,22,NA,NA,NA,NA,NA};       /*127 */
68538 X
68539 int nascii[128]={
68540 /*       0  1  2  3  5  6  7  8  9 10 11 12 13 14 15 15
68541 X        @  A  B  C  D  E  F  G  H  I  J  K  L  M  N  O
68542 X        P  Q  R  S  T  U  V  W  X  Y  Z                */
68543 X       EL,NA,NA,NA,NA,NA,NA,NA,NA,NA,EL,NA,NA,EL,NA,NA,
68544 X       NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,
68545 X       NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,ES,NA,NA,16,NA,NA,
68546 X       NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,ES,NA,NA,ES,NA,
68547 X       NA, 1,15, 2,12,NA,NA, 3,13,NA,NA,11,NA, 8,16,NA,
68548 X        6, 7, 6,10, 4, 5,14, 9,17, 7,NA,NA,NA,NA,NA,NA,
68549 X       NA, 1,15, 2,12,NA,NA, 3,13,NA,NA,11,NA, 8,16,NA,
68550 X        6, 7, 6,10, 4, 5,14, 9,17, 7,NA,NA,NA,NA,NA,NA};
68551 X
68552 int *pascii;
68553 int qascii[128];
68554 int lascii[128];
68555 #else
68556 #define AAMASK 127
68557 extern int aascii[128];
68558 extern int nascii[128];
68559 X
68560 extern int *pascii;
68561 extern int qascii[128];
68562 extern int lascii[128];
68563 #endif
68564 SHAR_EOF
68565 chmod 0644 uascii.h ||
68566 echo 'restore of uascii.h failed'
68567 Wc_c="`wc -c < 'uascii.h'`"
68568 test 2006 -eq "$Wc_c" ||
68569         echo 'uascii.h: original size 2006, current size' "$Wc_c"
68570 fi
68571 # ============= upam.h ==============
68572 if test -f 'upam.h' -a X"$1" != X"-c"; then
68573         echo 'x - skipping upam.h (File already exists)'
68574 else
68575 echo 'x - extracting upam.h (Text)'
68576 sed 's/^X//' << 'SHAR_EOF' > 'upam.h' &&
68577 /* Concurrent read version */
68578 /*      20-June-1986    universal pam file */
68579 X
68580 /* $Name: fa_34_26_5 $ - $Id: upam.h,v 1.19 2006/02/07 17:58:19 wrp Exp $ */
68581 X
68582 /* modified to accomodate both lower and upper case amino acid numbers
68583 X   as a result MAXSQ = 50
68584 */
68585 X
68586 #ifndef UPAM_GBL_DEF
68587 #define UPAM_GBL_DEF
68588 X
68589 #define EOSEQ 0
68590 #define MAXSQ 50
68591 #define MAXUC 24
68592 #define MAXLC 48
68593 X
68594 #define MAXHASH 32
68595 #define NMAP MAXHASH+1
68596 X
68597 #ifndef XTERNAL
68598 X
68599 int pamoff=0;
68600 X
68601 /*extern int gdelval, ggapval;*/
68602 X
68603 /* char sqnam[]="aa"; */
68604 /* char sqtype[]="protein"; */
68605 X
68606 char aa[MAXSQ+1]  = {"\0ARNDCQEGHILKMFPSTWYVBZX*ARNDCQEGHILKMFPSTWYVBZX*\0"};
68607 char aax[MAXSQ+1] = {"\0ARNDCQEGHILKMFPSTWYVBZX*arndcqeghilkmfpstwyvbzx*\0"};
68608 X
68609 int naa = 24;   /* this should be calculated from aa[] */
68610 int naax = 48;
68611 X
68612 /* haa[] used to map all valid amino acid codes into a hash value;
68613 X   now, there is an additional hash value - not-mapped - NM */
68614 X
68615 /* this has been expanded to accomodate '*' */
68616 int haa[MAXSQ+1] = {
68617 X  NMAP,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,3,7,NMAP,NMAP,
68618 X       1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,3,7,NMAP,NMAP};
68619 X
68620 int haax[MAXSQ+1] = {
68621 X  NMAP,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,3,7,NMAP,
68622 X  NMAP,NMAP,NMAP,NMAP,NMAP,NMAP,NMAP,NMAP,NMAP,NMAP,NMAP,NMAP,NMAP,
68623 X  NMAP,NMAP,NMAP,NMAP,NMAP,NMAP,NMAP,NMAP,NMAP,NMAP,NMAP,NMAP,NMAP,
68624 X  NMAP};
68625 X
68626 /*
68627 X  PAM 250 substitution matrix, scale = ln(2)/3 = 0.231049
68628 X  Expected score = -0.844, Entropy = 0.354 bits
68629 X  Lowest score = -8, Highest score = 17
68630 */
68631 int apam250[450] = {
68632 X 2,
68633 -2, 6,
68634 X 0, 0, 2,
68635 X 0,-1, 2, 4,
68636 -2,-4,-4,-5,12,
68637 X 0, 1, 1, 2,-5, 4,
68638 X 0,-1, 1, 3,-5, 2, 4,
68639 X 1,-3, 0, 1,-3,-1, 0, 5,
68640 -1, 2, 2, 1,-3, 3, 1,-2, 6,
68641 -1,-2,-2,-2,-2,-2,-2,-3,-2, 5,
68642 -2,-3,-3,-4,-6,-2,-3,-4,-2, 2, 6,
68643 -1, 3, 1, 0,-5, 1, 0,-2, 0,-2,-3, 5,
68644 -1, 0,-2,-3,-5,-1,-2,-3,-2, 2, 4, 0, 6,
68645 -4,-4,-4,-6,-4,-5,-5,-5,-2, 1, 2,-5, 0, 9,
68646 X 1, 0,-1,-1,-3, 0,-1,-1, 0,-2,-3,-1,-2,-5, 6,
68647 X 1, 0, 1, 0, 0,-1, 0, 1,-1,-1,-3, 0,-2,-3, 1, 2,
68648 X 1,-1, 0, 0,-2,-1, 0, 0,-1, 0,-2, 0,-1,-3, 0, 1, 3,
68649 -6, 2,-4,-7,-8,-5,-7,-7,-3,-5,-2,-3,-4, 0,-6,-2,-5,17,
68650 -3,-4,-2,-4, 0,-4,-4,-5, 0,-1,-1,-4,-2, 7,-5,-3,-3, 0,10,
68651 X 0,-2,-2,-2,-2,-2,-2,-1,-2, 4, 2,-2, 2,-1,-1,-1, 0,-6,-2, 4,
68652 X 0,-1, 2, 3,-4, 1, 2, 0, 1,-2,-3, 1,-2,-5,-1, 0, 0,-5,-3,-2, 2,
68653 X 0, 0, 1, 3,-5, 3, 3,-1, 2,-2,-3, 0,-2,-5, 0, 0,-1,-6,-4,-2, 2, 3,
68654 X 0,-1, 0,-1,-3,-1,-1,-1,-1,-1,-1,-1,-1,-2,-1, 0, 0,-4,-2,-1,-1,-1,-1,
68655 X 0,-1, 0,-1,-3,-1,-1,-1,-1,-1,-1,-1,-1,-2,-1, 0, 0,-4,-2,-1,-1,-1,-1, 8};
68656 X
68657 /*
68658 X This matrix was produced by "pam" Version 1.0.6 [28-Jul-93]
68659 X PAM 120 substitution matrix, scale = ln(2)/2 = 0.346574
68660 X Expected score = -1.64, Entropy = 0.979 bits
68661 X Lowest score = -8, Highest score = 12
68662 */
68663 int apam120[450] = {
68664 X  3,
68665 X -3, 6,
68666 X  0,-1, 4,
68667 X  0,-3, 2, 5,
68668 X -3,-4,-5,-7, 9,
68669 X -1, 1, 0, 1,-7, 6,
68670 X  0,-3, 1, 3,-7, 2, 5,
68671 X  1,-4, 0, 0,-5,-3,-1, 5,
68672 X -3, 1, 2, 0,-4, 3,-1,-4, 7,
68673 X -1,-2,-2,-3,-3,-3,-3,-4,-4, 6,
68674 X -3,-4,-4,-5,-7,-2,-4,-5,-3, 1, 5,
68675 X -2, 2, 1,-1,-7, 0,-1,-3,-2,-2,-4, 5,
68676 X -2,-1,-3,-4,-6,-1,-4,-4,-4, 1, 3, 0, 8,
68677 X -4,-4,-4,-7,-6,-6,-6,-5,-2, 0, 0,-6,-1, 8,
68678 X  1,-1,-2,-2,-3, 0,-1,-2,-1,-3,-3,-2,-3,-5, 6,
68679 X  1,-1, 1, 0,-1,-2,-1, 1,-2,-2,-4,-1,-2,-3, 1, 3,
68680 X  1,-2, 0,-1,-3,-2,-2,-1,-3, 0,-3,-1,-1,-4,-1, 2, 4,
68681 X -7, 1,-5,-8,-8,-6,-8,-8,-5,-7,-5,-5,-7,-1,-7,-2,-6, 12,
68682 X -4,-6,-2,-5,-1,-5,-4,-6,-1,-2,-3,-6,-4, 4,-6,-3,-3,-1, 8,
68683 X  0,-3,-3,-3,-2,-3,-3,-2,-3, 3, 1,-4, 1,-3,-2,-2, 0,-8,-3, 5,
68684 X  0,-2, 3, 4,-6, 0, 3, 0, 1,-3,-4, 0,-4,-5,-2, 0, 0,-6,-3,-3, 4,
68685 X -1,-1, 0, 3,-7, 4, 4,-2, 1,-3,-3,-1,-2,-6,-1,-1,-2,-7,-5,-3, 2, 4,
68686 X -1,-2,-1,-2,-4,-1,-1,-2,-2,-1,-2,-2,-2,-3,-2,-1,-1,-5,-3,-1,-1,-1,-2,
68687 X -1,-2,-1,-2,-4,-1,-1,-2,-2,-1,-2,-2,-2,-3,-2,-1,-1,-5,-3,-1,-1,-1,-2, 6};
68688 X
68689 /*
68690 #     VTML160
68691 #
68692 # This matrix was produced with scripts written by
68693 # Tobias Mueller and Sven Rahmann [June-2001]. 
68694 #
68695 # VTML160 substitution matrix, Units = Third-Bits
68696 # Expected Score = -1.297840 Third-Bits
68697 # Lowest Score = -7, Highest Score = 16
68698 #
68699 # Entropy H = 0.562489 Bits
68700 #
68701 # 30-Jun-2001 
68702 */
68703 int avt160[450] = {
68704 X  5,
68705 X  -2,  7,
68706 X  -1,  0,  7,
68707 X  -1, -3,  3,  7,
68708 X  1, -3, -3, -5, 13,
68709 X  -1,  2,  0,  1, -4,  6,
68710 X  -1, -1,  0,  3, -5,  2,  6,
68711 X  0, -3,  0, -1, -2, -3, -2,  8,
68712 X  -2,  1,  1,  0, -2,  2, -1, -3,  9,
68713 X  -1, -4, -4, -6, -1, -4, -5, -7, -4,  6,
68714 X  -2, -3, -4, -6, -4, -2, -4, -6, -3,  3,  6,
68715 X  -1,  4,  0,  0, -4,  2,  1, -2,  0, -4, -3,  5,
68716 X  -1, -2, -3, -5, -1, -1, -3, -5, -3,  2,  4, -2,  8,
68717 X  -3, -5, -5, -7, -4, -4, -6, -6,  0,  0,  2, -5,  1,  9,
68718 X  0, -2, -2, -1, -3, -1, -1, -3, -2, -4, -3, -1, -4, -5,  9,
68719 X  1, -1,  1,  0,  1,  0,  0,  0, -1, -3, -3, -1, -3, -3,  0,  4,
68720 X  1, -1,  0, -1,  0, -1, -1, -2, -1, -1, -2, -1, -1, -3, -1,  2,  5,
68721 X  -5, -4, -5, -7, -7, -6, -7, -5, -1, -2, -1, -5, -4,  3, -5, -4, -6, 16,
68722 X  -3, -3, -2, -5, -1, -4, -3, -5,  3, -2, -1, -3, -2,  6, -6, -2, -3,  4, 10,
68723 X  0, -4, -4, -4,  1, -3, -3, -5, -3,  4,  2, -3,  1, -1, -3, -2,  0, -5, -3,  5,
68724 X  -1, -2,  5,  6, -4,  0,  2, -1,  0, -5, -5,  0, -4, -6, -2,  1,  0, -6, -3, -4,  5,
68725 X  -1,  0,  0,  3, -5,  4,  5, -2,  0, -4, -3,  2, -3, -5, -1,  0, -1, -7, -4, -3,  2,  5,
68726 X  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
68727 X  -7, -7, -7, -7, -7, -7, -7, -7, -7, -7, -7, -7, -7, -7, -7, -7, -7, -7, -7, -7, -7, -7, -7,  6};
68728 X
68729 /*
68730 X  Matrix made by matblas from blosum50.iij
68731 X  BLOSUM Clustered Scoring Matrix in 1/3 Bit Units
68732 X  Blocks Database = /data/blocks_5.0/blocks.dat
68733 X  Cluster Percentage: >= 50
68734 X  Entropy =   0.4808, Expected =  -0.3573
68735 */
68736 int abl50[450] = {
68737 X  5,
68738 X -2, 7,
68739 X -1,-1, 7,
68740 X -2,-2, 2, 8,
68741 X -1,-4,-2,-4,13,
68742 X -1, 1, 0, 0,-3, 7,
68743 X -1, 0, 0, 2,-3, 2, 6,
68744 X  0,-3, 0,-1,-3,-2,-3, 8,
68745 X -2, 0, 1,-1,-3, 1, 0,-2,10,
68746 X -1,-4,-3,-4,-2,-3,-4,-4,-4, 5,
68747 X -2,-3,-4,-4,-2,-2,-3,-4,-3, 2, 5,
68748 X -1, 3, 0,-1,-3, 2, 1,-2, 0,-3,-3, 6,
68749 X -1,-2,-2,-4,-2, 0,-2,-3,-1, 2, 3,-2, 7,
68750 X -3,-3,-4,-5,-2,-4,-3,-4,-1, 0, 1,-4, 0, 8,
68751 X -1,-3,-2,-1,-4,-1,-1,-2,-2,-3,-4,-1,-3,-4,10,
68752 X  1,-1, 1, 0,-1, 0,-1, 0,-1,-3,-3, 0,-2,-3,-1, 5,
68753 X  0,-1, 0,-1,-1,-1,-1,-2,-2,-1,-1,-1,-1,-2,-1, 2, 5,
68754 X -3,-3,-4,-5,-5,-1,-3,-3,-3,-3,-2,-3,-1, 1,-4,-4,-3,15,
68755 X -2,-1,-2,-3,-3,-1,-2,-3, 2,-1,-1,-2, 0, 4,-3,-2,-2, 2, 8,
68756 X  0,-3,-3,-4,-1,-3,-3,-4,-4, 4, 1,-3, 1,-1,-3,-2, 0,-3,-1, 5,
68757 X -2,-1, 4, 5,-3, 0, 1,-1, 0,-4,-4, 0,-3,-4,-2, 0, 0,-5,-3,-4, 5,
68758 X -1, 0, 0, 1,-3, 4, 5,-2, 0,-3,-3, 1,-1,-4,-1, 0,-1,-2,-2,-3, 2, 5,
68759 X -1,-1,-1,-1,-2,-1,-1,-2,-1,-1,-1,-1,-1,-2,-2,-1, 0,-3,-1,-1,-1,-1,-1,
68760 X -1,-1,-1,-1,-2,-1,-1,-2,-1,-1,-1,-1,-1,-2,-2,-1, 0,-3,-1,-1,-1,-1,-1, 7};
68761 X
68762 /*
68763 X  A   R   N   D   C   Q   E   G   H   I   L   K   M   F   P   S   T   W   Y   V   B   Z   X   * */
68764 int a_md10[450]= {
68765 X 11,   /* A */
68766 -12, 12,        /* R */
68767 -12,-13, 13,    /* N */
68768 -11,-18, -3, 12,        /* D */
68769 -13,-10,-14,-20, 17,    /* C */
68770 -13, -5,-11,-13,-19, 13,        /* Q */
68771 -10,-15,-12, -2,-22, -5, 12,    /* E */
68772 X -8, -9,-11, -9,-12,-16, -9, 11,       /* G */
68773 -16, -5, -5,-10,-12, -3,-15,-16, 16,    /* H */
68774 -13,-17,-14,-19,-17,-20,-19,-21,-18, 12,        /* I */
68775 -15,-14,-19,-21,-16,-12,-20,-21,-13, -7, 10,    /* L */
68776 -14, -2, -6,-15,-21, -6, -8,-15,-13,-17,-18, 12,        /* K */
68777 -13,-14,-15,-18,-15,-14,-18,-19,-15, -4, -4,-12, 16,    /* M */
68778 -18,-22,-19,-22,-11,-22,-23,-22,-14,-11, -6,-23,-14, 14,        /* F */
68779 X -7,-12,-17,-18,-18, -8,-17,-16,-10,-19,-10,-16,-17,-17, 13,   /* P */
68780 X -5,-10, -4,-12, -7,-13,-15, -7,-11,-14,-13,-13,-15,-11, -6, 11,       /* S */
68781 X -4,-12, -7,-14,-14,-13,-15,-14,-13, -7,-16,-10, -7,-19, -9, -4, 12,   /* T */
68782 -21, -9,-21,-21,-10,-17,-21,-13,-21,-21,-13,-21,-17,-13,-21,-15,-18, 18,        /* W */
68783 -20,-17,-12,-13, -7,-16,-21,-20, -3,-15,-16,-20,-17, -3,-20,-12,-17,-12, 15,    /* Y */
68784 X -6,-17,-17,-15,-12,-17,-14,-13,-19, -1, -8,-18, -5,-12,-16,-14,-10,-16,-18, 11,       /* V */
68785 -12,-15,  5,  5,-17,-12, -7,-10, -7,-16,-20,-11,-17,-21,-17, -8,-10,-22,-13,-16, 13,    /* B */
68786 -16,-18,-17, -8,-32,  1,  9,-17,-17,-29,-26,-11,-24,-34,-21,-21,-21,-29,-29,-22, -9, 13, /* Z */
68787 X -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
68788 X -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 9};
68789 X
68790 int a_md20[450] = {
68791 X 10,
68792 -10, 12,
68793 X -9,-10, 13,
68794 X -8,-14, -1, 12,
68795 -10, -7,-11,-16, 17,
68796 -10, -3, -8, -9,-16, 13,
68797 X -7,-11, -9,  1,-19, -3, 11,
68798 X -5, -6, -8, -6, -9,-12, -7, 11,
68799 -12, -3, -2, -7, -9,  0,-12,-13, 15,
68800 -10,-14,-11,-16,-14,-16,-16,-17,-14, 12,
68801 -12,-11,-15,-18,-13, -9,-17,-18,-10, -4, 10,
68802 -11,  0, -4,-12,-17, -3, -5,-12, -9,-14,-15, 12,
68803 X -9,-11,-12,-15,-12,-11,-15,-16,-12, -1, -2, -9, 15,
68804 -15,-19,-16,-19, -8,-18,-20,-19,-11, -8, -4,-19,-10, 13,
68805 X -5, -9,-13,-15,-14, -5,-14,-12, -7,-15, -7,-13,-14,-14, 12,
68806 X -2, -8, -1, -9, -4,-10,-12, -5, -8,-11,-10,-10,-12, -8, -3, 10,
68807 X -1, -9, -4,-11,-10,-10,-12,-11,-10, -4,-12, -7, -4,-15, -7, -1, 11,
68808 -17, -6,-18,-18, -7,-14,-18,-10,-17,-17,-10,-17,-14,-10,-18,-12,-15, 18,
68809 -16,-14, -9,-11, -4,-12,-18,-17,  0,-12,-12,-17,-14,  0,-16, -9,-13, -9, 14,
68810 X -3,-14,-14,-12, -9,-14,-11,-11,-15,  2, -5,-15, -2, -9,-13,-11, -7,-13,-14, 11,
68811 X -9,-12,  6,  6,-14, -9, -4, -7, -4,-13,-17, -8,-13,-18,-14, -5, -7,-19,-10,-13, 12,
68812 -12,-13,-13, -4,-27,  4, 10,-13,-12,-24,-21, -6,-20,-29,-17,-17,-17,-24,-24,-18, -6, 12,
68813 X -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
68814 X -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 9 };
68815 X
68816 int a_md40[450] = {
68817 X  9,
68818 X -7, 11,
68819 X -6, -6, 12,
68820 X -6,-10,  1, 11,
68821 X -7, -5, -8,-13, 16,
68822 X -7,  0, -5, -6,-12, 12,
68823 X -5, -8, -5,  3,-15,  0, 11,
68824 X -3, -4, -5, -4, -7, -9, -4, 10,
68825 X -9,  0,  0, -4, -6,  2, -8,-10, 14,
68826 X -6,-10, -8,-12,-11,-12,-12,-13,-11, 11,
68827 X -9, -9,-12,-14,-10, -6,-13,-14, -7, -1,  9,
68828 X -8,  3, -1, -8,-12, -1, -3, -9, -6,-11,-12, 11,
68829 X -6, -8, -9,-12, -9, -8,-11,-12, -9,  1,  1, -7, 14,
68830 -11,-15,-12,-15, -5,-14,-16,-15, -7, -5, -1,-16, -7, 13,
68831 X -2, -6, -9,-11,-11, -3,-11, -9, -4,-11, -5,-10,-10,-11, 12,
68832 X  0, -5,  1, -6, -2, -7, -8, -2, -6, -8, -7, -7, -8, -6, -1,  9,
68833 X  1, -6, -2, -8, -7, -7, -8, -7, -7, -2, -9, -5, -2,-11, -4,  1, 10,
68834 -14, -4,-14,-15, -4,-11,-15, -7,-13,-13, -8,-13,-11, -7,-14, -9,-12, 18,
68835 -13,-10, -6, -8, -2, -9,-14,-13,  2, -9, -9,-13,-11,  2,-13, -7,-10, -6, 14,
68836 X -1,-11,-10, -9, -7,-11, -8, -8,-12,  4, -2,-12,  0, -6, -9, -7, -4,-10,-11, 10,
68837 X -6, -8,  6,  6,-10, -6, -1, -4, -2,-10,-13, -5,-10,-14,-10, -3, -5,-15, -7,-10, 11,
68838 X -8, -8, -8,  0,-21,  6, 10, -8, -7,-18,-16, -3,-15,-23,-12,-12,-12,-19,-18,-14, -3, 11,
68839 X -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
68840 X -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 9};
68841 X
68842 /* 
68843 X  Matrix made by matblas from blosum62.iij
68844 X  * column uses minimum score
68845 X  BLOSUM Clustered Scoring Matrix in 1/2 Bit Units
68846 X  Blocks Database = /data/blocks_5.0/blocks.dat
68847 X  Cluster Percentage: >= 62
68848 X  Entropy =   0.6979, Expected =  -0.5209
68849 */
68850 X
68851 int abl62[450] = {
68852 X  4,
68853 X -1, 5,
68854 X -2, 0, 6,
68855 X -2,-2, 1, 6,
68856 X  0,-3,-3,-3, 9,
68857 X -1, 1, 0, 0,-3, 5,
68858 X -1, 0, 0, 2,-4, 2, 5,
68859 X  0,-2, 0,-1,-3,-2,-2, 6,
68860 X -2, 0, 1,-1,-3, 0, 0,-2, 8,
68861 X -1,-3,-3,-3,-1,-3,-3,-4,-3, 4,
68862 X -1,-2,-3,-4,-1,-2,-3,-4,-3, 2, 4,
68863 X -1, 2, 0,-1,-3, 1, 1,-2,-1,-3,-2, 5,
68864 X -1,-1,-2,-3,-1, 0,-2,-3,-2, 1, 2,-1, 5,
68865 X -2,-3,-3,-3,-2,-3,-3,-3,-1, 0, 0,-3, 0, 6,
68866 X -1,-2,-2,-1,-3,-1,-1,-2,-2,-3,-3,-1,-2,-4, 7,
68867 X  1,-1, 1, 0,-1, 0, 0, 0,-1,-2,-2, 0,-1,-2,-1, 4,
68868 X  0,-1, 0,-1,-1,-1,-1,-2,-2,-1,-1,-1,-1,-2,-1, 1, 5,
68869 X -3,-3,-4,-4,-2,-2,-3,-2,-2,-3,-2,-3,-1, 1,-4,-3,-2,11,
68870 X -2,-2,-2,-3,-2,-1,-2,-3, 2,-1,-1,-2,-1, 3,-3,-2,-2, 2, 7,
68871 X  0,-3,-3,-3,-1,-2,-2,-3,-3, 3, 1,-2, 1,-1,-2,-2, 0,-3,-1, 4,
68872 X -2,-1, 3, 4,-3, 0, 1,-1, 0,-3,-4, 0,-3,-3,-2, 0,-1,-4,-3,-3, 4,
68873 X -1, 0, 0, 1,-3, 3, 4,-2, 0,-3,-3, 1,-1,-3,-1, 0,-1,-3,-2,-2, 1, 4,
68874 X  0,-1,-1,-1,-2,-1,-1,-1,-1,-1,-1,-1,-1,-1,-2, 0, 0,-2,-1,-1,-1,-1,-1,
68875 X  0,-1,-1,-1,-2,-1,-1,-1,-1,-1,-1,-1,-1,-1,-2, 0, 0,-2,-1,-1,-1,-1,-1, 6};
68876 X
68877 /* blosum80 in 1/2 bit units (previous versions had 1/3 bit units) */
68878 /*
68879 X  Matrix made by matblas from blosum80.iij
68880 X  * column uses minimum score
68881 X  BLOSUM Clustered Scoring Matrix in 1/2 Bit Units
68882 X  Blocks Database = /data/blocks_5.0/blocks.dat
68883 X  Cluster Percentage: >= 80
68884 X  Entropy =   0.9868, Expected =  -0.7442
68885 */
68886 X
68887 int abl80[450] = {
68888 X  5,
68889 X -2, 6,
68890 X -2,-1, 6,
68891 X -2,-2, 1, 6,
68892 X -1,-4,-3,-4, 9,
68893 X -1, 1, 0,-1,-4, 6,
68894 X -1,-1,-1, 1,-5, 2, 6,
68895 X  0,-3,-1,-2,-4,-2,-3, 6,
68896 X -2, 0, 0,-2,-4, 1, 0,-3, 8,
68897 X -2,-3,-4,-4,-2,-3,-4,-5,-4, 5,
68898 X -2,-3,-4,-5,-2,-3,-4,-4,-3, 1, 4,
68899 X -1, 2, 0,-1,-4, 1, 1,-2,-1,-3,-3, 5,
68900 X -1,-2,-3,-4,-2, 0,-2,-4,-2, 1, 2,-2, 6,
68901 X -3,-4,-4,-4,-3,-4,-4,-4,-2,-1, 0,-4, 0, 6,
68902 X -1,-2,-3,-2,-4,-2,-2,-3,-3,-4,-3,-1,-3,-4, 8,
68903 X  1,-1, 0,-1,-2, 0, 0,-1,-1,-3,-3,-1,-2,-3,-1, 5,
68904 X  0,-1, 0,-1,-1,-1,-1,-2,-2,-1,-2,-1,-1,-2,-2, 1, 5,
68905 X -3,-4,-4,-6,-3,-3,-4,-4,-3,-3,-2,-4,-2, 0,-5,-4,-4,11,
68906 X -2,-3,-3,-4,-3,-2,-3,-4, 2,-2,-2,-3,-2, 3,-4,-2,-2, 2, 7,
68907 X  0,-3,-4,-4,-1,-3,-3,-4,-4, 3, 1,-3, 1,-1,-3,-2, 0,-3,-2, 4,
68908 X -2,-2, 4, 4,-4, 0, 1,-1,-1,-4,-4,-1,-3,-4,-2, 0,-1,-5,-3,-4, 4,
68909 X -1, 0, 0, 1,-4, 3, 4,-3, 0,-4,-3, 1,-2,-4,-2, 0,-1,-4,-3,-3, 0, 4,
68910 X -1,-1,-1,-2,-3,-1,-1,-2,-2,-2,-2,-1,-1,-2,-2,-1,-1,-3,-2,-1,-2,-1,-1,
68911 X -1,-1,-1,-2,-3,-1,-1,-2,-2,-2,-2,-1,-1,-2,-2,-1,-1,-3,-2,-1,-2,-1,-1, 6};
68912 X
68913 /*      DNA alphabet
68914 X
68915 X       A, C, G, T, U   1-4, 5
68916 X       R, Y            6, 7
68917 X       M (A or C)      8
68918 X       W (A or T)      9
68919 X       S (C or G)      10
68920 X       K (G or T)      11
68921 X       D (not C)       12
68922 X       H (not G)       13
68923 X       V (not T)       14
68924 X       B (not A)       15
68925 X       N               16
68926 X       X               17
68927 */
68928 X
68929 char nt[MAXSQ+1] ={"\0ACGTURYMWSKDHVBNXACGTURYMWSKDHVBNX\0"};
68930 char ntx[MAXSQ+1]={"\0ACGTURYMWSKDHVBNXacgturymwskdhvbnx\0"};
68931 char ntc[MAXSQ+1]={"\0TGCAAYRKWSMHDBVNXtgcaayrkwsmhdbvnx\0"};
68932 X
68933 /* nt complement to encoding */
68934 X                     /* A:T C:G G:C T:A U:A */
68935 int gc_nt[MAXSQ+1]={ 0,  4,  3,  2,  1,  1, 
68936 X                     /* R:Y Y:R M:K W:W */
68937 X                        7,  6, 11,  9,
68938 X                     /* S:S K:M D:H H:D */
68939 X                       10,  8, 13, 12,
68940 X                     /* B:V V:B N:N X:X */
68941 X                       15, 14, 16, 16};
68942 X
68943 int nnt = 17;
68944 int nntx = 34;
68945 X
68946 int hnt[MAXSQ+1] = {
68947 X  NMAP,0,1,2,3,3,0,1,0,0,1,2,0,0,0,1,NMAP,
68948 X  NMAP,0,1,2,3,3,0,1,0,0,1,2,0,0,0,1,NMAP,NMAP};
68949 int hntx[MAXSQ+1] = {
68950 X  NMAP,0,1,2,3,3,0,1,0,0,1,2,0,0,0,1,NMAP,
68951 X  NMAP,NMAP,NMAP,NMAP,NMAP,NMAP,NMAP,NMAP,NMAP,
68952 X  NMAP,NMAP,NMAP,NMAP,NMAP,NMAP,NMAP,NMAP,NMAP};
68953 X
68954 int npam[450] = {
68955 /*       A  C  G  T  U  R  Y  M  W  S  K  D  H  V  B  N  X  */
68956 X        5,                                             /* A */
68957 X       -4, 5,                                          /* C */
68958 X       -4,-4, 5,                                       /* G */
68959 X       -4,-4,-4, 5,                                    /* T */
68960 X       -4,-4,-4, 5, 5,                                 /* U */
68961 X        2,-1, 2,-1,-1, 2,                              /* R (A G)*/
68962 X       -1, 2,-1, 2, 2,-2, 2,                           /* Y (C T)*/
68963 X        2, 2,-1,-1,-1,-1,-1, 2,                        /* M (A C)*/
68964 X        2,-1,-1, 2, 2, 1, 1, 1, 2,                     /* W (A T)*/
68965 X       -1, 2, 2,-1,-1, 1, 1, 1,-1, 2,                  /* S (C G)*/
68966 X       -1,-1, 2, 2, 2, 1, 1,-1, 1, 1, 2,               /* K (G T)*/
68967 X        1,-2, 1, 1, 1, 1,-1,-1, 1,-1, 1, 1,            /* D (!C) */
68968 X        1, 1,-2, 1, 1,-1, 1, 1, 1,-1,-1,-1, 1,         /* H (!G) */
68969 X        1, 1, 1,-2,-2, 1,-1, 1,-1, 1,-1,-1,-1, 1,      /* V (!T) */
68970 X       -2, 1, 1, 1, 1,-1, 1,-1,-1, 1, 1,-1,-1,-1, 1,   /* B (!A) */
68971 X       -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, /* N */
68972 X       -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1}; /* X */
68973 /*       A  C  G  T  U  R  Y  M  W  S  K  D  H  V  B  N  */
68974 X
68975 int *pam;                       /* Pam matrix- 1D */
68976 int *pam12;
68977 int *pam12x;
68978 int pamh1[MAXSQ+1];             /* used for kfact replacement */
68979 X
68980 /* Robinson & Robinson counts */
68981 long rrcounts[25] = {
68982 X  0,
68983 X  35155,
68984 X  23105,
68985 X  20212,
68986 X  24161,
68987 X  8669,
68988 X  19208,
68989 X  28354,
68990 X  33229,
68991 X  9906,
68992 X  23161,
68993 X  40625,
68994 X  25872,
68995 X  10101,
68996 X  17367,
68997 X  23435,
68998 X  32070,
68999 X  26311,
69000 X  5990,
69001 X  14488,
69002 X  29012,
69003 X  0, 0, 0, 0 };
69004 X
69005 long rrtotal = 450431;
69006 #else
69007 X
69008 /* extern char sqnam[]; */
69009 /* extern char sqtype[]; */
69010 /* extern int gdelval, ggapval; */
69011 extern int pamoff;
69012 extern char aa[MAXSQ+1];
69013 extern char aax[MAXSQ+1];
69014 extern char nt[MAXSQ+1];
69015 extern char ntx[MAXSQ+1];
69016 extern char ntc[MAXSQ+1];
69017 extern int gc_nt[MAXSQ+1];
69018 X
69019 extern  int naa;
69020 extern  int naax;
69021 extern  int nnt;
69022 extern  int nntx;
69023 X
69024 extern  int haa[MAXSQ+1];
69025 extern  int haax[MAXSQ+1];
69026 extern  int hnt[MAXSQ+1];
69027 extern  int hntx[MAXSQ+1];
69028 /* extern  int had[MAXSQ+1]; */
69029 X
69030 extern  int apam250[450];
69031 extern  int apam120[450];
69032 extern  int a_md10[450];
69033 extern  int a_md20[450];
69034 extern  int a_md40[450];
69035 extern  int abl50[450];
69036 extern  int abl62[450];
69037 extern  int abl80[450];
69038 extern  int npam[450];
69039 extern  int *pam;
69040 extern  int *pam12;
69041 extern  int *pam12x;
69042 extern  int pamh1[MAXSQ+1];
69043 extern  long rrcounts[25];
69044 extern  long rrtotal;
69045 #endif
69046 #endif
69047 SHAR_EOF
69048 chmod 0644 upam.h ||
69049 echo 'restore of upam.h failed'
69050 Wc_c="`wc -c < 'upam.h'`"
69051 test 16008 -eq "$Wc_c" ||
69052         echo 'upam.h: original size 16008, current size' "$Wc_c"
69053 fi
69054 # ============= url_subs.c ==============
69055 if test -f 'url_subs.c' -a X"$1" != X"-c"; then
69056         echo 'x - skipping url_subs.c (File already exists)'
69057 else
69058 echo 'x - extracting url_subs.c (Text)'
69059 sed 's/^X//' << 'SHAR_EOF' > 'url_subs.c' &&
69060 X
69061 /* copyright (c) 1998, 1999 William R. Pearson and the
69062 X   U. of Virginia */
69063 X
69064 /* $Name: fa_34_26_5 $ - $Id: url_subs.c,v 1.9 2006/08/20 18:18:33 wrp Exp $ */
69065 X
69066 /* 30 Dec 2004 - modify REF_URL to accomodate current Entrez */
69067 X
69068 #include <stdio.h>
69069 #include <stdlib.h>
69070 #include <string.h>
69071 X
69072 #include "defs.h"
69073 #include "structs.h"
69074 #include "param.h"
69075 X
69076 #ifndef DEF_PROT_LIB
69077 #define DEF_PROT_LIB "q"
69078 #endif
69079 X
69080 #ifndef FASTA_HOST
69081 #define FASTA_HOST "your.fasta.host.here/fasta/cgi"
69082 #endif
69083 X
69084 void do_url1(FILE *fp, struct mngmsg m_msg, struct pstruct pst,
69085 X            char *l_name, int n1, struct a_struct aln, long loffset)
69086 {
69087 X  char my_l_name[200];
69088 X  char *db;
69089 X  char pgm[10], lib[MAX_FN];
69090 X  char *ref_url, *lbp=NULL;
69091 X  char *srch_url, *srch_url1;
69092 X
69093 X  if (m_msg.ldnaseq==SEQT_DNA) db="nucleotide";
69094 X  else db="Protein";
69095 X
69096 X  if (strncmp(m_msg.f_id0,"rss",3)==0) {
69097 X    strncpy(pgm,"fa",sizeof(pgm));
69098 X  }
69099 X  else if (strncmp(m_msg.f_id0,"rfx",3)==0) {
69100 X    strncpy(pgm,"fx",sizeof(pgm));
69101 X  }
69102 X  else { strncpy(pgm,m_msg.f_id0,sizeof(pgm)); }
69103 X
69104 X  if (m_msg.lname[0]!='%') {
69105 X    strncpy(lib,m_msg.lname,sizeof(lib));
69106 X  }
69107 X  else {
69108 X    strncpy(lib,"%25",sizeof(lib));
69109 X    strncat(lib,&m_msg.lname[1],sizeof(lib));
69110 X  }
69111 X  lib[sizeof(lib)-1]='\0';
69112 X
69113 X  strncpy(my_l_name,l_name,sizeof(my_l_name));
69114 X  my_l_name[sizeof(my_l_name)-1]='\0';
69115 X
69116 X  if (pgm[0]=='t' || strcmp(pgm,"fx") || strcmp(pgm,"fy")==0 ) {
69117 X    if ((lbp=strchr(my_l_name,':'))!=NULL) *lbp='\0';
69118 X    lbp = &my_l_name[strlen(my_l_name)-2];
69119 X    if ( *lbp == '_' ) *lbp = '\0';
69120 X  }
69121 X
69122 X  /* change the program name for fastx, tfastx, tfasta */
69123 X  /* fastx returns proteins */
69124 X  if (strcmp(pgm,"fx")==0 || strcmp(pgm,"fy")==0) strncpy(pgm,"fa",sizeof(pgm));
69125 X  else if (strcmp(pgm,"ff")==0) strncpy(pgm,"fa",sizeof(pgm));
69126 X  else if (pgm[0]=='t') {
69127 X    strncpy(pgm,"fx",sizeof(pgm));
69128 X    strncpy(lib,DEF_PROT_LIB,sizeof(lib));
69129 X  }
69130 X
69131 X  fflush(fp);
69132 X  if ((ref_url = getenv("REF_URL"))==NULL)
69133 X    fprintf(fp,"<A HREF=\"http://www.ncbi.nlm.nih.gov/entrez/query.fcgi?db=%s&fcmd=Search&doptcmd1=DocSum&term=%s\">Entrez lookup</A>&nbsp;&nbsp;",
69134 X           db,my_l_name);
69135 X  else
69136 X    fprintf(fp,ref_url,db,my_l_name);
69137 X
69138 X  if ((srch_url = getenv("SRCH_URL"))==NULL)
69139 X    fprintf(fp,"<A HREF=\"http://%s/searchfa.cgi?query=%s&db=%s&lib=%s&pgm=%s&start=%ld&stop=%ld&n1=%d\">Re-search database</A>&nbsp;&nbsp;",
69140 X           FASTA_HOST,my_l_name,db,lib,pgm,
69141 X           loffset+aln.amin1+1,loffset+aln.amax1,n1);
69142 X  else 
69143 X    fprintf(fp,srch_url,my_l_name,db,lib,pgm,
69144 X           loffset+aln.amin1+1,loffset+aln.amax1,n1);
69145 X
69146 X  if ((srch_url1 = getenv("SRCH_URL1"))==NULL)
69147 X    fprintf(fp,"<A HREF=\"http://%s/searchxf.cgi?query=%s&db=%s&lib=%s&pgm=%s&start=%ld&stop=%ld&n1=%d\">General re-search</A>\n<p>\n",
69148 X           FASTA_HOST,my_l_name,db,lib,pgm,
69149 X           loffset+aln.amin1+1,loffset+aln.amax1,n1);
69150 X  else 
69151 X    fprintf(fp,srch_url1,my_l_name,db,lib,pgm,
69152 X           loffset+aln.amin1+1,loffset+aln.amax1,n1);
69153 X
69154 X  /* put back "_r"  */
69155 X  if (lbp!=NULL) *lbp = '_';
69156 X
69157 X  /*
69158 X  if ((srch_url2 = getenv("SRCH_URL2"))==NULL)
69159 X    fprintf(fp,"<A HREF=\"http://fasta.bioch.virginia.edu/fasta/cgi/lalignx.cgi?seq1=\"%s\"&in_seq1=\"FASTA\"&seq2=\"%s\"&in_seq2=\"Accession\"&ssr2=%ld:%ld\">lalign</A>\n<p>\n",my_l_name,db,lib,pgm,loffset+aln.amin1+1,loffset+aln.amax1,n1);
69160 X  else 
69161 X    fprintf(fp,srch_url1,my_l_name,db,lib,pgm,
69162 X           loffset+aln.amin1+1,loffset+aln.amax1,n1);
69163 X  */
69164 X  fflush(fp);
69165 X
69166 }
69167 SHAR_EOF
69168 chmod 0644 url_subs.c ||
69169 echo 'restore of url_subs.c failed'
69170 Wc_c="`wc -c < 'url_subs.c'`"
69171 test 3335 -eq "$Wc_c" ||
69172         echo 'url_subs.c: original size 3335, current size' "$Wc_c"
69173 fi
69174 # ============= uthr_subs.h ==============
69175 if test -f 'uthr_subs.h' -a X"$1" != X"-c"; then
69176         echo 'x - skipping uthr_subs.h (File already exists)'
69177 else
69178 echo 'x - extracting uthr_subs.h (Text)'
69179 sed 's/^X//' << 'SHAR_EOF' > 'uthr_subs.h' &&
69180 X
69181 /***************************************/
69182 /* thread global variable declarations */
69183 /***************************************/
69184 X
69185 X
69186 /* $Name: fa_34_26_5 $ - $Id: uthr_subs.h,v 1.1.1.1 1999/10/22 20:56:02 wrp Exp $ */
69187 X
69188 X
69189 #ifndef MAX_WORKERS
69190 #define MAX_WORKERS 2
69191 #endif
69192 #define NUM_WORK_BUF 2*MAX_WORKERS
69193 X
69194 #include <synch.h>
69195 #include <thread.h>
69196 X
69197 #define check(status,string) \
69198 X     if (status == -1) perror(string)   /* error macro for thread calls */
69199 X
69200 #ifndef XTERNAL
69201 X
69202 thread_t threads[MAX_WORKERS];
69203 X
69204 /* mutex stuff */
69205 X
69206 mutex_t reader_mutex;      /* empty buffer pointer structure lock */
69207 mutex_t worker_mutex;      /* full buffer pointer structure lock */
69208 X
69209 /* condition variable stuff */
69210 X
69211 cond_t reader_cond_var;    /* condition variable for reader */
69212 cond_t worker_cond_var;    /* condition variable for workers */
69213 X
69214 mutex_t start_mutex;       /* start-up synchronisation lock */
69215 cond_t start_cond_var;     /* start-up synchronisation condition variable */
69216 X
69217 #else
69218 X
69219 extern thread_t threads[];
69220 X
69221 /* mutex stuff */
69222 X
69223 extern mutex_t reader_mutex;
69224 extern mutex_t worker_mutex;
69225 X
69226 /* condition variable stuff */
69227 X
69228 extern cond_t reader_cond_var;
69229 extern cond_t worker_cond_var;
69230 X
69231 extern mutex_t start_mutex;
69232 extern cond_t start_cond_var;
69233 X
69234 #endif
69235 SHAR_EOF
69236 chmod 0644 uthr_subs.h ||
69237 echo 'restore of uthr_subs.h failed'
69238 Wc_c="`wc -c < 'uthr_subs.h'`"
69239 test 1229 -eq "$Wc_c" ||
69240         echo 'uthr_subs.h: original size 1229, current size' "$Wc_c"
69241 fi
69242 # ============= vtml160.mat ==============
69243 if test -f 'vtml160.mat' -a X"$1" != X"-c"; then
69244         echo 'x - skipping vtml160.mat (File already exists)'
69245 else
69246 echo 'x - extracting vtml160.mat (Text)'
69247 sed 's/^X//' << 'SHAR_EOF' > 'vtml160.mat' &&
69248 #
69249 #     VTML160
69250 #
69251 # This matrix was produced with scripts written by
69252 # Tobias Mueller and Sven Rahmann [June-2001]. 
69253 #
69254 # VTML160 substitution matrix, Units = Third-Bits
69255 # Expected Score = -1.297840 Third-Bits
69256 # Lowest Score = -7, Highest Score = 16
69257 #
69258 # Entropy H = 0.562489 Bits
69259 #
69260 # 30-Jun-2001 
69261 X    A   R   N   D   C   Q   E   G   H   I   L   K   M   F   P   S   T   W   Y   V   B   Z   X   * 
69262 A   5  -2  -1  -1   1  -1  -1   0  -2  -1  -2  -1  -1  -3   0   1   1  -5  -3   0  -1  -1   0  -7 
69263 R  -2   7   0  -3  -3   2  -1  -3   1  -4  -3   4  -2  -5  -2  -1  -1  -4  -3  -4  -2   0   0  -7 
69264 N  -1   0   7   3  -3   0   0   0   1  -4  -4   0  -3  -5  -2   1   0  -5  -2  -4   5   0   0  -7 
69265 D  -1  -3   3   7  -5   1   3  -1   0  -6  -6   0  -5  -7  -1   0  -1  -7  -5  -4   6   3   0  -7 
69266 C   1  -3  -3  -5  13  -4  -5  -2  -2  -1  -4  -4  -1  -4  -3   1   0  -7  -1   1  -4  -5   0  -7 
69267 Q  -1   2   0   1  -4   6   2  -3   2  -4  -2   2  -1  -4  -1   0  -1  -6  -4  -3   0   4   0  -7 
69268 E  -1  -1   0   3  -5   2   6  -2  -1  -5  -4   1  -3  -6  -1   0  -1  -7  -3  -3   2   5   0  -7 
69269 G   0  -3   0  -1  -2  -3  -2   8  -3  -7  -6  -2  -5  -6  -3   0  -2  -5  -5  -5  -1  -2   0  -7 
69270 H  -2   1   1   0  -2   2  -1  -3   9  -4  -3   0  -3   0  -2  -1  -1  -1   3  -3   0   0   0  -7 
69271 I  -1  -4  -4  -6  -1  -4  -5  -7  -4   6   3  -4   2   0  -4  -3  -1  -2  -2   4  -5  -4   0  -7 
69272 L  -2  -3  -4  -6  -4  -2  -4  -6  -3   3   6  -3   4   2  -3  -3  -2  -1  -1   2  -5  -3   0  -7 
69273 K  -1   4   0   0  -4   2   1  -2   0  -4  -3   5  -2  -5  -1  -1  -1  -5  -3  -3   0   2   0  -7 
69274 M  -1  -2  -3  -5  -1  -1  -3  -5  -3   2   4  -2   8   1  -4  -3  -1  -4  -2   1  -4  -3   0  -7 
69275 F  -3  -5  -5  -7  -4  -4  -6  -6   0   0   2  -5   1   9  -5  -3  -3   3   6  -1  -6  -5   0  -7 
69276 P   0  -2  -2  -1  -3  -1  -1  -3  -2  -4  -3  -1  -4  -5   9   0  -1  -5  -6  -3  -2  -1   0  -7 
69277 S   1  -1   1   0   1   0   0   0  -1  -3  -3  -1  -3  -3   0   4   2  -4  -2  -2   1   0   0  -7 
69278 T   1  -1   0  -1   0  -1  -1  -2  -1  -1  -2  -1  -1  -3  -1   2   5  -6  -3   0   0  -1   0  -7 
69279 W  -5  -4  -5  -7  -7  -6  -7  -5  -1  -2  -1  -5  -4   3  -5  -4  -6  16   4  -5  -6  -7   0  -7 
69280 Y  -3  -3  -2  -5  -1  -4  -3  -5   3  -2  -1  -3  -2   6  -6  -2  -3   4  10  -3  -3  -4   0  -7 
69281 V   0  -4  -4  -4   1  -3  -3  -5  -3   4   2  -3   1  -1  -3  -2   0  -5  -3   5  -4  -3   0  -7 
69282 B  -1  -2   5   6  -4   0   2  -1   0  -5  -5   0  -4  -6  -2   1   0  -6  -3  -4   5   2   0  -7 
69283 Z  -1   0   0   3  -5   4   5  -2   0  -4  -3   2  -3  -5  -1   0  -1  -7  -4  -3   2   5   0  -7 
69284 XX   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0  -7 
69285 *  -7  -7  -7  -7  -7  -7  -7  -7  -7  -7  -7  -7  -7  -7  -7  -7  -7  -7  -7  -7  -7  -7  -7   1 
69286 SHAR_EOF
69287 chmod 0644 vtml160.mat ||
69288 echo 'restore of vtml160.mat failed'
69289 Wc_c="`wc -c < 'vtml160.mat'`"
69290 test 2771 -eq "$Wc_c" ||
69291         echo 'vtml160.mat: original size 2771, current size' "$Wc_c"
69292 fi
69293 # ============= w_mw.h ==============
69294 if test -f 'w_mw.h' -a X"$1" != X"-c"; then
69295         echo 'x - skipping w_mw.h (File already exists)'
69296 else
69297 echo 'x - extracting w_mw.h (Text)'
69298 sed 's/^X//' << 'SHAR_EOF' > 'w_mw.h' &&
69299 X
69300 /* $Name: fa_34_26_5 $ - $Id: w_mw.h,v 1.17 2006/04/12 18:00:02 wrp Exp $ */
69301 X
69302 /* 21-July-2000 - changes for p2_complib/p2_workcomp:
69303 X   there are now two sequence numbers; the old (worker) seqnm,
69304 X   and a new manager (master) sequence number, m_seqnm
69305 */
69306 X
69307 #ifndef BFR
69308 #define BFR     300
69309 #endif
69310 #ifndef BFR2
69311 #define BFR2    100
69312 #endif
69313 X
69314 #define MAXSQL  125000
69315 #define MMAXSQL 2000000
69316 #ifndef MAXWRKR
69317 #define MAXWRKR 64
69318 #endif
69319 #define MAXLSEQ 50000
69320 #define DESLIN  60
69321 #define NDES    100
69322 X
69323 struct qmng_str
69324 {
69325 X  int n0;      /* query sequence length */
69326 X  int nm0;     /* number of segments */
69327 X  int escore_flg;      /* use escores */
69328 X  int qshuffle;                /* query shuffle */
69329 X  int pam_pssm;        /* flag for pssm/profile search */
69330 X  int s_func;  /* for p_workcomp: func==0>simple comparison, ==1>alignments */
69331 X  int slist;   /* number of alignments to do */
69332 X  int seqnm;   /* query sequence number - used for identity searches */
69333 X  char libstr[MAX_FN];
69334 };
69335 X
69336 struct comstr
69337 {
69338 X  int m_seqnm;         /* sequence number */
69339 X  int seqnm;           /* sequence number */
69340 X  int score[3];                /* score */
69341 X  double escore;
69342 X  float comp;
69343 X  float H;
69344 X  int segnum;
69345 X  int seglen;
69346 X  int frame;
69347 X  int r_score, qr_score;
69348 X  double r_escore, qr_escore;
69349 };
69350 X
69351 struct comstr2
69352 {
69353 X  int m_seqnm;         /* sequence number */
69354 X  int seqnm;           /* sequence number */
69355 X  int score[3];                /* score */
69356 X  double escore;
69357 X  int segnum;
69358 X  int seglen;
69359 X  int sw_score;
69360 X
69361 X  /* int a_len; */     /* consensus alignment length */
69362 X  /* int min0, max0, min1, max1;
69363 X  int nident, ngap_q, ngap_l; */ /* number of identities, gaps in q, l */
69364 X  
69365 X  struct a_struct aln_d;
69366 X  float percent, gpercent;
69367 X  int aln_code_n;
69368 };
69369 X
69370 /* The message structure */
69371 X
69372 struct wrkmsg
69373 {
69374 X    char lname [80];   /* name of the library */
69375 X    char libenv[80];   /* directory in which library resides */
69376 X    int lb_off;                /* offset in the library */
69377 X    int lb_stop;       /* stop position in library */
69378 X    int lb_code;       /* continue code */
69379 X    int lb_size;       /* library size */
69380 X    int p_size;                /* parcel size */
69381 X    int libfn;         /* current library being searched */
69382 X    int stage;         /* current stage number */
69383 };
69384 X
69385 struct sql
69386 {
69387 X  int n1;
69388 X  int *n1tot_p;
69389 X  int sfnum[10];       /* superfamily number */
69390 X  int nsfnum;
69391 #ifndef USE_FSEEKO
69392 X  long lseek;          /* location of sequence in file */
69393 #else
69394 X  off_t lseek;
69395 #endif
69396 X  long loffset;                /* offset from the beginning of the sequence */
69397 X  int wrkr;            /* worker that has sequence */
69398 X  int cont;
69399 X  char *bline; /* descriptive line */
69400 };
69401 X
69402 struct sqs
69403 {
69404 X  int n1;              /* size of library sequence */
69405 X  unsigned char *aa1;  /* sequence data */
69406 };
69407 X
69408 #include "aln_structs.h"
69409 X
69410 struct sqs2
69411 {
69412 X  int n1;              /* size of library sequence */
69413 X  int m_seqnm;         /* location in master list */
69414 X  unsigned char *aa1;
69415 X  int walign_dflg[2];
69416 X  int sw_score[2];
69417 X  struct a_res_str a_res[2];   /* need a_res for each frame */
69418 };
69419 X
69420 struct stage2_str {
69421 X  int m_seqnm; /* manager sequence number */
69422 X  int seqnm;   /* worker sequence number */
69423 X  int frame;   /* query frame */
69424 };
69425 SHAR_EOF
69426 chmod 0644 w_mw.h ||
69427 echo 'restore of w_mw.h failed'
69428 Wc_c="`wc -c < 'w_mw.h'`"
69429 test 2899 -eq "$Wc_c" ||
69430         echo 'w_mw.h: original size 2899, current size' "$Wc_c"
69431 fi
69432 # ============= work_thr.c ==============
69433 if test -f 'work_thr.c' -a X"$1" != X"-c"; then
69434         echo 'x - skipping work_thr.c (File already exists)'
69435 else
69436 echo 'x - extracting work_thr.c (Text)'
69437 sed 's/^X//' << 'SHAR_EOF' > 'work_thr.c' &&
69438 /* copyright (c) 1996, 1997, 1998, 1999 William R. Pearson and the
69439 X   U. of Virginia */
69440 X
69441 /* $Name: fa_34_26_5 $ - $Id: work_thr.c,v 1.23 2007/04/26 18:33:20 wrp Exp $ */
69442 X
69443 /* work_thr.c - threaded worker */
69444 X
69445 /* modified 21-Oct-1998 to work with reverse complement for DNA */
69446 X
69447 #include <stdio.h>
69448 #include <stdlib.h>
69449 #include <string.h>
69450 #include <time.h>
69451 #include <sys/types.h>
69452 #include <signal.h>
69453 X
69454 #include "defs.h"               /* various constants */
69455 #include "mw.h"                 /* defines beststr */
69456 #include "structs.h"
69457 #include "param.h"              /* pstruct, thr_str, buf_head, rstruct */
69458 X
69459 /***************************************/
69460 /* thread global variable declarations */
69461 /***************************************/
69462 X
69463 #define XTERNAL
69464 #include "thr.h"
69465 #undef XTERNAL
69466 X
69467 void alloc_pam (int, int, struct pstruct *);
69468 int **alloc_pam2p(int, int);
69469 void revcomp(unsigned char *seq, int n, int *c_nt);
69470 #ifdef WIN32
69471 void pthread_exit(void *);
69472 #else
69473 void THR_EXIT(void *);
69474 #endif
69475 X
69476 /* functions getting/sending buffers to threads (thr_sub.c) */
69477 extern void wait_thr(void);
69478 extern int get_wbuf(struct buf_head **cur_buf, int max_work_buf);
69479 extern void put_wbuf(struct buf_head *cur_buf, int max_work_buf);
69480 X
69481 /* dropxx.c functions */
69482 extern void init_work (unsigned char *aa0, int n0,
69483 X                      struct pstruct *ppst, void **f_arg);
69484 X
69485 extern void do_work (unsigned char *aa0, int n0, unsigned char *aa1, int n1,
69486 X                    int frame,
69487 X                    struct pstruct *ppst, void *f_str, int qr_flg,
69488 X                    struct rstruct *rst);
69489 X
69490 extern void close_work (unsigned char *, int, struct pstruct *, void **);
69491 X
69492 extern void irand(int);
69493 extern int shuffle(unsigned char *, unsigned char *, int);
69494 extern int wshuffle(unsigned char *, unsigned char *, int, int, int *);
69495 extern void qshuffle(unsigned char *aa0, int n0, int nm0);
69496 extern void free_pam2p(int **);
69497 X
69498 void
69499 work_thread (struct thr_str *work_info)
69500 {
69501 X  struct buf_head *cur_buf;
69502 X  struct buf_str *cur_buf_p;
69503 X  struct buf_str *p_rbuf;
69504 X  unsigned char *aa1s;
69505 X  int cur_cnt;
69506 X  int my_worker;
69507 X  int i, j, npam, n0, nm0;
69508 X  int ix_score, debug_lib, zsflag, zs_win, do_shuffle, ieven=0;
69509 X  int frame;
69510 X
69511 X  struct rstruct rrst;
69512 X  struct pstruct my_pst, *my_ppst;
69513 X  unsigned char *aa0[6], *aa0s;
69514 X  void *f_str[6], *qf_str;
69515 X
69516 X  my_worker = work_info->worker;
69517 X
69518 X  wait_thr();  /* wait for start_thread predicate to drop to  0 */
69519 X
69520 X  /* do init_work */
69521 X
69522 X  /* let each thread have its own copy of the query */
69523 X  n0 = work_info->n0;
69524 X  nm0 = work_info->nm0;
69525 X
69526 X  if ((aa0[0]=(unsigned char *)calloc((size_t)n0+2,sizeof(unsigned char)))
69527 X      ==NULL) {
69528 X    fprintf(stderr," cannot allocate aa00[%d] for worker %d\n",
69529 X           n0, my_worker);
69530 X    exit(1);
69531 X  }
69532 X  *aa0[0]='\0';
69533 X  aa0[0]++;
69534 X  memcpy(aa0[0],work_info->aa0,n0+1);
69535 X
69536 X  /* make certain that all but 0 have their own copy of pst */
69537 X  if (my_worker) {
69538 X    my_ppst = &my_pst;
69539 X    memcpy(my_ppst,work_info->ppst,sizeof(struct pstruct));
69540 X
69541 X    alloc_pam(MAXSQ, MAXSQ, my_ppst);
69542 X
69543 X    npam = (my_pst.ext_sq_set) ? my_pst.nsqx : my_pst.nsq;
69544 X
69545 X    for (i=0; i<=npam; i++) {
69546 X      for (j=0; j<=npam; j++) {
69547 X       my_pst.pam2[0][i][j] = work_info->ppst->pam2[0][i][j];
69548 X       my_pst.pam2[1][i][j] = work_info->ppst->pam2[1][i][j];
69549 X      }
69550 X    }
69551 X
69552 X    if (work_info->ppst->pam_pssm && work_info->ppst->pam2p[0]) {
69553 X      my_ppst->pam2p[0] = alloc_pam2p(n0,npam);
69554 X      my_ppst->pam2p[1] = alloc_pam2p(n0,npam);
69555 X      for (i=0; i<n0; i++) {
69556 X       for (j=0; j <= npam; j++) {
69557 X         my_pst.pam2p[0][i][j] = work_info->ppst->pam2p[0][i][j];
69558 X         my_pst.pam2p[1][i][j] = work_info->ppst->pam2p[1][i][j];
69559 X       }
69560 X      }
69561 X    }
69562 X  }
69563 X  else my_ppst=work_info->ppst;
69564 X
69565 X  /* note that aa[5,4,3,2] are never used, but are provided so that frame
69566 X     can range from 0 .. 5; likewise for f_str[5..2] */
69567 X
69568 X  aa0[5] = aa0[4] = aa0[3] = aa0[2] = aa0[1] = aa0[0];
69569 X  init_work (aa0[0], n0, my_ppst, &f_str[0]);
69570 X
69571 X  f_str[5] = f_str[4] = f_str[3] = f_str[2] = f_str[1] = f_str[0];
69572 X
69573 X  if (work_info->qframe == 2) {
69574 X    if ((aa0[1]=(unsigned char *)calloc((size_t)n0+2,sizeof(unsigned char)))==NULL) {
69575 X      fprintf(stderr," cannot allocate aa01[%d] for worker %d\n",
69576 X           n0, my_worker);
69577 X    }
69578 X    *aa0[1]='\0';
69579 X    aa0[1]++;
69580 X    memcpy(aa0[1],work_info->aa0,n0+1);
69581 X    revcomp(aa0[1],n0,my_ppst->c_nt);
69582 X    init_work (aa0[1], n0, my_ppst, &f_str[1]);
69583 X  }
69584 X
69585 X  if (work_info->qshuffle) {
69586 X    if ((aa0s=(unsigned char *)calloc(n0+2,sizeof(char)))==NULL) {
69587 X      fprintf(stderr,"cannot allocate aa0s[%d]\n",n0+2);
69588 X      exit(1);
69589 X    }
69590 X    *aa0s='\0';
69591 X    aa0s++;
69592 X    memcpy(aa0s,aa0[0],n0);
69593 X    qshuffle(aa0s,n0,nm0);
69594 X    init_work (aa0s, n0, my_ppst, &qf_str);
69595 X  }
69596 X
69597 X  ix_score = my_ppst->score_ix;
69598 X  debug_lib = my_ppst->debug_lib;
69599 X  zsflag = my_ppst->zsflag;
69600 X  zs_win = my_ppst->zs_win;
69601 X
69602 X  if (zsflag >= 10) {
69603 X    if((aa1s=calloc(work_info->max_tot+1,sizeof(char))) == NULL) {
69604 X      fprintf(stderr,"unable to allocate shuffled library sequence\n");
69605 X    }
69606 X    else {
69607 X      *aa1s=0;
69608 X      aa1s++;
69609 X      do_shuffle =1;
69610 X      irand(0);
69611 X    }
69612 X  }
69613 X  else {do_shuffle = 0;}
69614 X
69615 X  /* main work loop */
69616 X  while (get_wbuf(&cur_buf,work_info->max_work_buf)) {
69617 X
69618 X    cur_cnt = cur_buf->buf_cnt;
69619 X    if (cur_cnt == -1) break;
69620 X    cur_buf_p = cur_buf->buf;
69621 X
69622 X    while (cur_cnt--) { /* count down the number of sequences */
69623 X      p_rbuf = cur_buf_p++;   /* step through each sequence */
69624 X      p_rbuf->rst.score[0] = p_rbuf->rst.score[1] = p_rbuf->rst.score[2] = 0;
69625 X      frame = p_rbuf->frame;
69626 X
69627 #ifdef DEBUG
69628 X      if (debug_lib) {
69629 X       if (frame >= 2) fprintf(stderr,"* frame: %d\n",frame);
69630 X       for (i=0; i<p_rbuf->n1; i++)
69631 X         if (p_rbuf->aa1b[i]>=my_ppst->nsqx) {
69632 X           fprintf(stderr,
69633 X                   "%s residue[%d/%d] %d range (%d)\n",
69634 X                   p_rbuf->libstr,i,p_rbuf->n1,p_rbuf->aa1b[i],my_ppst->nsqx);
69635 X           p_rbuf->aa1b[i]=0;
69636 X           p_rbuf->n1=i-1;
69637 X           break;
69638 X         }
69639 X      }
69640 #endif
69641 X
69642 X      do_work (aa0[frame], n0, p_rbuf->aa1b, p_rbuf->n1, frame,
69643 X              my_ppst, f_str[frame], 0, &p_rbuf->rst);
69644 X      
69645 X      if (work_info->qshuffle) {
69646 X       do_work(aa0s,n0,p_rbuf->aa1b, p_rbuf->n1, frame,
69647 X               my_ppst, qf_str, 1, &rrst);
69648 X       p_rbuf->qr_score = rrst.score[ix_score];
69649 X       p_rbuf->qr_escore = rrst.escore;
69650 X      }
69651 X
69652 X      if (do_shuffle) {
69653 X       if (zs_win > 0) wshuffle(p_rbuf->aa1b,aa1s,p_rbuf->n1,zs_win,&ieven);
69654 X       else shuffle(p_rbuf->aa1b,aa1s,p_rbuf->n1);
69655 X
69656 X       do_work (aa0[frame], n0, aa1s, p_rbuf->n1, frame,
69657 X                my_ppst, f_str[frame], 0, &rrst);
69658 X       p_rbuf->r_score = rrst.score[ix_score];
69659 X       p_rbuf->r_escore = rrst.escore;
69660 X      }
69661 X    }
69662 X
69663 X    cur_buf->have_results = 1;
69664 X
69665 X    put_wbuf(cur_buf,work_info->max_work_buf);
69666 X
69667 X  } /* end main while */
69668 X
69669 X  close_work(aa0[0], n0, my_ppst, &f_str[0]);
69670 X  free(aa0[0]-1);
69671 X  if (work_info->qframe == 2) {
69672 X    close_work(aa0[1], n0, my_ppst, &f_str[1]);
69673 X    free(aa0[1]-1);
69674 X  }
69675 X
69676 X  if (do_shuffle) free(aa1s-1);
69677 X
69678 X  if (my_worker) {
69679 X    free(my_pst.pam2[1][0]);
69680 X    free(my_pst.pam2[0][0]);
69681 X    free(my_pst.pam2[1]);
69682 X    free(my_pst.pam2[0]);
69683 X    
69684 X    if (my_pst.pam_pssm) {
69685 X      free_pam2p(my_pst.pam2p[0]);
69686 X      free_pam2p(my_pst.pam2p[1]);
69687 X    }
69688 X  }
69689 X
69690 #ifdef WIN32
69691 X  pthread_exit(&work_info->status);
69692 #else
69693 X  THR_EXIT(&work_info->status);
69694 #endif
69695 X
69696 }  /* end work_thread */
69697 X
69698 SHAR_EOF
69699 chmod 0644 work_thr.c ||
69700 echo 'restore of work_thr.c failed'
69701 Wc_c="`wc -c < 'work_thr.c'`"
69702 test 7001 -eq "$Wc_c" ||
69703         echo 'work_thr.c: original size 7001, current size' "$Wc_c"
69704 fi
69705 # ============= workacc.c ==============
69706 if test -f 'workacc.c' -a X"$1" != X"-c"; then
69707         echo 'x - skipping workacc.c (File already exists)'
69708 else
69709 echo 'x - extracting workacc.c (Text)'
69710 sed 's/^X//' << 'SHAR_EOF' > 'workacc.c' &&
69711 X
69712 /* copyright (c) 1996, 1997, 1998, 1999 William R. Pearson and the
69713 X   U. of Virginia */
69714 X
69715 /* $Name: fa_34_26_5 $ - $Id: workacc.c,v 1.19 2006/02/07 17:58:19 wrp Exp $ */
69716 X
69717 /* Concurrent read version */
69718 X
69719 #include <stdio.h>
69720 #include <stdlib.h>
69721 #include <string.h>
69722 X
69723 #include "param.h"
69724 X
69725 #define XTERNAL
69726 #include "uascii.h"
69727 #include "upam.h"
69728 #undef XTERNAL
69729 X
69730 char err_str[128];
69731 X
69732 /* Initialization - set up defaults - assume protein sequence */
69733 void w_init ()
69734 {
69735 X  pascii=aascii;
69736 }
69737 X
69738 #ifndef MPI_SRC
69739 /* allocate memory for pam matrix - identical to version in initfa/sw.c */
69740 alloc_pam (int d1, int d2, struct pstruct *ppst)
69741 {
69742 X  int     i, *d2p;
69743 X  char err_str[128];
69744 X
69745 X  if ((ppst->pam2[0] = (int **) malloc (d1 * sizeof (int *))) == NULL) {
69746 X     sprintf(err_str,"Cannot allocate 2D pam matrix: %d",d1);
69747 X     return -1;
69748 X  }
69749 X
69750 X  if ((ppst->pam2[1] = (int **) malloc (d1 * sizeof (int *))) == NULL) {
69751 X     sprintf(err_str,"Cannot allocate 2D pam matrix: %d",d1);
69752 X     return -1;
69753 X  }
69754 X
69755 X  if ((d2p = pam12 = (int *) malloc (d1 * d2 * sizeof (int))) == NULL) {
69756 X     sprintf(err_str,"Cannot allocate 2D pam matrix: %d",d1);
69757 X     return -1;
69758 X   }
69759 X   for (i = 0; i < d1; i++, d2p += d2) ppst->pam2[0][i] = d2p;
69760 X
69761 X   if ((d2p=pam12x= (int *) malloc (d1 * d2 * sizeof (int))) == NULL) {
69762 X     sprintf(err_str,"Cannot allocate 2d pam matrix: %d",d2);
69763 X     return -1;
69764 X   }
69765 X   for (i = 0;  i < d1; i++, d2p += d2) ppst->pam2[1][i] = d2p;
69766 X
69767 X   return 1;
69768 }
69769 X
69770 int **
69771 alloc_pam2p(int len, int nsq) {
69772 X  int i;
69773 X  int **pam2p;
69774 X
69775 X  if ((pam2p = (int **)calloc(len,sizeof(int *)))==NULL) {
69776 X    fprintf(stderr," Cannot allocate pam2p: %d\n",len);
69777 X    return NULL;
69778 X  }
69779 X
69780 X  if((pam2p[0] = (int *)calloc((nsq+1)*len,sizeof(int)))==NULL) {
69781 X    fprintf(stderr, "Cannot allocate pam2p[0]: %d\n", (nsq+1)*len);
69782 X    free(pam2p);
69783 X    return NULL;
69784 X  }
69785 X
69786 X  for (i=1; i<len; i++) {
69787 X    pam2p[i] = pam2p[0] + (i*(nsq+1));
69788 X  }
69789 X
69790 X  return pam2p;
69791 }
69792 X
69793 void free_pam2p(int **pam2p) {
69794 X  if (pam2p) {
69795 X    free(pam2p[0]);
69796 X    free(pam2p);
69797 X  }
69798 }
69799 X
69800 void
69801 aancpy(char *to, char *from, int count, struct pstruct pst)
69802 {
69803 X  char *tp, *sq;
69804 X  int nsq;
69805 X
69806 X  tp=to;
69807 X
69808 X  if (pst.ext_sq_set) {
69809 X    nsq = pst.nsqx;
69810 X    sq = pst.sqx;
69811 X  }
69812 X  else {
69813 X    nsq = pst.nsq;
69814 X    sq = pst.sq;
69815 X  }
69816 X
69817 X  while (count-- && *from) {
69818 X    if (*from <= nsq) *tp++ = sq[*(from++)];
69819 X    else *tp++ = *from++;
69820 X  }
69821 X  *tp='\0';
69822 }
69823 #endif
69824 X
69825 /* copies from from to to shuffling */
69826 X
69827 void
69828 shuffle(unsigned char *from, unsigned char *to, int n)
69829 {
69830 X  int i,j; unsigned char tmp;
69831 X
69832 X  if (from != to) memcpy((void *)to,(void *)from,(size_t)n);
69833 X
69834 X  for (i=n; i>0; i--) {
69835 X    j = nrand(i);
69836 X    tmp = to[j];
69837 X    to[j] = to[i-1];
69838 X    to[i-1] = tmp;
69839 X  }
69840 X  to[n] = 0;
69841 }
69842 X
69843 /* this shuffle is for FASTS */
69844 /* convert ',' -> '\0', shuffle each of the substrings */
69845 qshuffle(unsigned char *aa0, int n0, int nm0)
69846 {
69847 X  unsigned char **aa0start, *aap, tmp;
69848 X  int i,j,k, ns;
69849 X
69850 X  if ((aa0start=(unsigned char **)calloc(nm0+1,
69851 X                                        sizeof(unsigned char *)))==NULL) {
69852 X    fprintf(stderr,"cannot calloc for qshuffle %d\n",nm0);
69853 X    exit(1);
69854 X  }
69855 X  aa0start[0]=aa0;
69856 X  for (k=1,i=0; i<n0; i++) {
69857 X    if (aa0[i]==EOSEQ || aa0[i]==ESS) {
69858 X      aa0[i]='\0';
69859 X      aa0start[k++] = &aa0[i+1];
69860 X    }
69861 X  }  
69862 X
69863 X  /* aa0start has the beginning of each substring */
69864 X  for (k=0; k<nm0; k++) {
69865 X    aap=aa0start[k];
69866 X    ns = strlen((char *)aap);
69867 X    for (i=ns; i>1; i--) {
69868 X      j = nrand(i);
69869 X      tmp = aap[j];
69870 X      aap[j] = aap[i-1];
69871 X      aap[i-1] = tmp;
69872 X    }
69873 X    aap[ns] = 0;
69874 X  }
69875 X
69876 X  for (k=1; k<nm0; k++) {
69877 /*  aap = aa0start[k];
69878 X    while (*aap) fputc(pst.sq[*aap++],stderr);
69879 X    fputc('\n',stderr);
69880 */
69881 X    aa0start[k][-1]=ESS;
69882 X  }
69883 X
69884 X  free(aa0start);
69885 }
69886 X
69887 /* copies from from to from shuffling */
69888 void
69889 wshuffle(unsigned char *from, unsigned char *to, int n, int wsiz, int *ieven)
69890 {
69891 X  int i,j, k, mm; 
69892 X  unsigned char tmp, *top;
69893 X
69894 X  memcpy((void *)to,(void *)from,n);
69895 X       
69896 X  mm = n%wsiz;
69897 X
69898 X  if (*ieven) {
69899 X    for (k=0; k<(n-wsiz); k += wsiz) {
69900 X      top = &to[k];
69901 X      for (i=wsiz; i>0; i--) {
69902 X       j = nrand(i);
69903 X       tmp = top[j];
69904 X       top[j] = top[i-1];
69905 X       top[i-1] = tmp;
69906 X      }
69907 X    }
69908 X    top = &to[n-mm];
69909 X    for (i=mm; i>0; i--) {
69910 X      j = nrand(i);
69911 X      tmp = top[j];
69912 X      top[j] = top[i-1];
69913 X      top[i-1] = tmp;
69914 X    }
69915 X    *ieven = 0;
69916 X  }
69917 X  else {
69918 X    for (k=n; k>=wsiz; k -= wsiz) {
69919 X      top = &to[k-wsiz];
69920 X      for (i=wsiz; i>0; i--) {
69921 X       j = nrand(i);
69922 X       tmp = top[j];
69923 X       top[j] = top[i-1];
69924 X       top[i-1] = tmp;
69925 X      }
69926 X    }
69927 X    top = &to[0];
69928 X    for (i=mm; i>0; i--) {
69929 X      j = nrand(i);
69930 X      tmp = top[j];
69931 X      top[j] = top[i-1];
69932 X      top[i-1] = tmp;
69933 X    }
69934 X    *ieven = 1;
69935 X  }
69936 X  to[n] = 0;
69937 }
69938 X
69939 void initseq(char **seqc0, char **seqc0a, char **seqc1, char **seqca, int seqsiz)       /* initialize arrays */
69940 {
69941 X  *seqc0=(char *)calloc((size_t)(seqsiz+1)*4,sizeof(char));
69942 X  *seqc0a= *seqc0+seqsiz+1;
69943 X  *seqc1= *seqc0a+seqsiz+1;
69944 X  *seqca= *seqc1+seqsiz+1;
69945 X  if (*seqc0==NULL)
69946 X    {fprintf(stderr,"cannot allocate consensus arrays %d\n",seqsiz);
69947 X     exit(1);}
69948 }
69949 X
69950 void freeseq(char **seqc0, char **seqc1, char **seqca)
69951 {
69952 X  free(*seqc0);
69953 }
69954 X
69955 #define ESS 49
69956 X
69957 void
69958 revcomp(unsigned char *seq, int n, int *c_nt)
69959 {
69960 X  unsigned char tmp;
69961 X  int i, ni;
69962 X
69963 X  for (i=0, ni = n-1; i< n/2; i++,ni--) {
69964 X    tmp = c_nt[seq[i]];
69965 X    seq[i] = c_nt[seq[ni]];
69966 X    seq[ni] = tmp;
69967 X  }
69968 X  if ((n%2)==1) {
69969 X    i = n/2;
69970 X    seq[i] = c_nt[seq[i]];
69971 X  }
69972 X  seq[n]=0;
69973 }
69974 SHAR_EOF
69975 chmod 0644 workacc.c ||
69976 echo 'restore of workacc.c failed'
69977 Wc_c="`wc -c < 'workacc.c'`"
69978 test 5262 -eq "$Wc_c" ||
69979         echo 'workacc.c: original size 5262, current size' "$Wc_c"
69980 fi
69981 # ============= xurt8c.aa ==============
69982 if test -f 'xurt8c.aa' -a X"$1" != X"-c"; then
69983         echo 'x - skipping xurt8c.aa (File already exists)'
69984 else
69985 echo 'x - extracting xurt8c.aa (Text)'
69986 sed 's/^X//' << 'SHAR_EOF' > 'xurt8c.aa' &&
69987 >XURT8C | 40001 | glutathione transferase (EC 2.5.1.18) 8, cytosolic - rat
69988 MEVKPKLYYFQGRGRMEVIRWLLATAGVEFEEEFLETREQYEKLQKDDCLLFGQVPLVEIDGMLLTQTRA
69989 ILSYLAAKYNLYGKDLKERVRIDMYADGTQDLMMMIIGAPFKAPQEKEESLALAVKRAKNRYFPVFEKIL
69990 KDHGEAFLVGNQLSWADIQLLEAILMVEEVSAPVLSDFPLLQAFKTRISNIPTIKKFLQPGSQRKPPPDG
69991 HYVDVVRTVLKF 
69992 SHAR_EOF
69993 chmod 0644 xurt8c.aa ||
69994 echo 'restore of xurt8c.aa failed'
69995 Wc_c="`wc -c < 'xurt8c.aa'`"
69996 test 302 -eq "$Wc_c" ||
69997         echo 'xurt8c.aa: original size 302, current size' "$Wc_c"
69998 fi
69999 # ============= xurt8c.lc ==============
70000 if test -f 'xurt8c.lc' -a X"$1" != X"-c"; then
70001         echo 'x - skipping xurt8c.lc (File already exists)'
70002 else
70003 echo 'x - extracting xurt8c.lc (Text)'
70004 sed 's/^X//' << 'SHAR_EOF' > 'xurt8c.lc' &&
70005 >XURT8C | 40001 | glutathione transferase (EC 2.5.1.18) 8, cytosolic - rat
70006 MEVKPKLYYFQGRGRMEVIRWLLATAGVEFEEEFLETREQYEKLQKDDCLLFGQVPLVEIDGMLLTQTRA
70007 ilsylaakynlygkdlkervridmyadgtqdlmmmiigapfkapqekeeslalavkraknryfpvfekil
70008 KDHGEAFLVGNQLSWADIQLLEAILMVEEVSAPVLSDFPLLQAFKTRISNIPTIKKFLQPGSQRKPPPDG
70009 HYVDVVRTVLKF 
70010 SHAR_EOF
70011 chmod 0644 xurt8c.lc ||
70012 echo 'restore of xurt8c.lc failed'
70013 Wc_c="`wc -c < 'xurt8c.lc'`"
70014 test 302 -eq "$Wc_c" ||
70015         echo 'xurt8c.lc: original size 302, current size' "$Wc_c"
70016 fi
70017 # ============= xurtg.aa ==============
70018 if test -f 'xurtg.aa' -a X"$1" != X"-c"; then
70019         echo 'x - skipping xurtg.aa (File already exists)'
70020 else
70021 echo 'x - extracting xurtg.aa (Text)'
70022 sed 's/^X//' << 'SHAR_EOF' > 'xurtg.aa' &&
70023 >XURTG glutathione transferase (EC 2.5.1.18) Ya - rat
70024 MSGKPVLHYFNARGRMECIRWLLAAAGVEFDEKFIQSPEDLEKLKKDGNLMFDQVPMVEIDGMKLAQTRA
70025 ILNYIATKYDLYGKDMKERALIDMYTEGILDLTEMIMQLVICPPDQKEAKTALAKDRTKNRYLPAFEKVL
70026 KSHGQDYLVGNRLTRVDIHLLELLLYVEEFDASLLTSFPLLKAFKSRISSLPNVKKFLQPGSQRKLPMDA
70027 KQIEEARKIFKF 
70028 SHAR_EOF
70029 chmod 0644 xurtg.aa ||
70030 echo 'restore of xurtg.aa failed'
70031 Wc_c="`wc -c < 'xurtg.aa'`"
70032 test 281 -eq "$Wc_c" ||
70033         echo 'xurtg.aa: original size 281, current size' "$Wc_c"
70034 fi
70035 exit 0