~ubuntu-branches/ubuntu/warty/ncbi-tools6/warty

« back to all changes in this revision

Viewing changes to demo/blastpgp.c

  • Committer: Bazaar Package Importer
  • Author(s): Aaron M. Ucko
  • Date: 2002-04-04 22:13:09 UTC
  • Revision ID: james.westby@ubuntu.com-20020404221309-vfze028rfnlrldct
Tags: upstream-6.1.20011220a
ImportĀ upstreamĀ versionĀ 6.1.20011220a

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $Id: blastpgp.c,v 6.104 2001/10/12 14:55:41 dondosha Exp $ */
 
2
/**************************************************************************
 
3
*                                                                         *
 
4
*                             COPYRIGHT NOTICE                            *
 
5
*                                                                         *
 
6
* This software/database is categorized as "United States Government      *
 
7
* Work" under the terms of the United States Copyright Act.  It was       *
 
8
* produced as part of the author's official duties as a Government        *
 
9
* employee and thus can not be copyrighted.  This software/database is    *
 
10
* freely available to the public for use without a copyright notice.      *
 
11
* Restrictions can not be placed on its present or future use.            *
 
12
*                                                                         *
 
13
* Although all reasonable efforts have been taken to ensure the accuracy  *
 
14
* and reliability of the software and data, the National Library of       *
 
15
* Medicine (NLM) and the U.S. Government do not and can not warrant the   *
 
16
* performance or results that may be obtained by using this software,     *
 
17
* data, or derivative works thereof.  The NLM and the U.S. Government     *
 
18
* disclaim any and all warranties, expressed or implied, as to the        *
 
19
* performance, merchantability or fitness for any particular purpose or   *
 
20
* use.                                                                    *
 
21
*                                                                         *
 
22
* In any work or product derived from this material, proper attribution   *
 
23
* of the author(s) as the source of the software or data would be         *
 
24
* appreciated.                                                            *
 
25
*                                                                         *
 
26
**************************************************************************
 
27
 * $Revision: 6.104 $ 
 
28
 * $Log: blastpgp.c,v $
 
29
 * Revision 6.104  2001/10/12 14:55:41  dondosha
 
30
 * Changed description of the -t option
 
31
 *
 
32
 * Revision 6.103  2001/08/29 19:06:37  madden
 
33
 * added variable posComputationcalled in Main, added parameter posComputationCalled to PGPrintPosMatrix
 
34
 *
 
35
 * Revision 6.102  2001/08/28 17:34:35  madden
 
36
 * Add -m 9 as tabular output with comments
 
37
 *
 
38
 * Revision 6.101  2001/07/30 16:27:42  dondosha
 
39
 * Do not call PGPOutTextMessages with XML output option
 
40
 *
 
41
 * Revision 6.100  2001/07/25 19:40:15  dondosha
 
42
 * Multiply hitlist_size by 2 when going to next query if when tweak_parameters set
 
43
 *
 
44
 * Revision 6.99  2001/07/24 18:16:55  madden
 
45
 * Set error_return when freeing
 
46
 *
 
47
 * Revision 6.98  2001/07/09 19:37:31  kans
 
48
 * return 0 instead of NULL to fix Mac compiler error
 
49
 *
 
50
 * Revision 6.97  2001/07/03 20:50:33  madden
 
51
 * Commented out call to PrintTabularOutputHeader
 
52
 *
 
53
 * Revision 6.96  2001/06/22 13:48:39  dondosha
 
54
 * Declare variable vnp
 
55
 *
 
56
 * Revision 6.95  2001/06/21 21:56:37  dondosha
 
57
 * Fixed memory leak: destroy all error returns; uncommented ObjMgrFreeCache
 
58
 *
 
59
 * Revision 6.94  2001/06/15 21:19:28  dondosha
 
60
 * Added tabular output option -m 8
 
61
 *
 
62
 * Revision 6.93  2001/06/11 20:31:19  shavirin
 
63
 * Added possibility to make Batch searches in iteractive mode.
 
64
 *
 
65
 * Revision 6.92  2001/04/13 20:46:01  madden
 
66
 * Changed default e-value threshold for inclusion in multipass model from 0.002 to 0.005, Changed default constant in pseudocounts for multipass version from 7 to 9
 
67
 *
 
68
 * Revision 6.91  2001/04/10 19:20:52  madden
 
69
 * Unsuppress some options suppressed for the release
 
70
 *
 
71
 * Revision 6.90  2001/03/30 22:02:04  madden
 
72
 * Suppress options not yet ready for prime-time
 
73
 *
 
74
 * Revision 6.89  2000/11/30 17:10:13  shavirin
 
75
 * Initialized to NULL xml pointer.
 
76
 *
 
77
 * Revision 6.88  2000/11/28 20:48:49  shavirin
 
78
 * Adopted for usage with many-iterations XML.
 
79
 *
 
80
 * Revision 6.87  2000/11/22 21:57:08  shavirin
 
81
 * Added passing of iteration number into XML output.
 
82
 *
 
83
 * Revision 6.86  2000/11/22 21:41:52  shavirin
 
84
 * Removed problem with mutiple iteration XML output.
 
85
 *
 
86
 * Revision 6.85  2000/11/22 17:34:32  madden
 
87
 * Change NULL to 0 for an intvalue
 
88
 *
 
89
 * Revision 6.84  2000/11/22 17:28:31  madden
 
90
 * Enable decline-to-align
 
91
 *
 
92
 * Revision 6.83  2000/10/27 21:26:50  shavirin
 
93
 * Produce valid XML output if no hits found.
 
94
 *
 
95
 * Revision 6.82  2000/10/27 19:14:41  madden
 
96
 * Change description of -b option
 
97
 *
 
98
 * Revision 6.81  2000/10/24 13:51:33  shavirin
 
99
 * Removed unused parameter from the function BXMLPrintOutput().
 
100
 *
 
101
 * Revision 6.80  2000/10/23 19:58:22  dondosha
 
102
 * Open and close AsnIo outside of call(s) to BXMLPrintOutput
 
103
 *
 
104
 * Revision 6.79  2000/10/17 19:39:20  shavirin
 
105
 * Fixed compilation problems on Mac.
 
106
 *
 
107
 * Revision 6.78  2000/10/13 20:58:01  madden
 
108
 * Add YES_TO_DECLINE_TO_ALIGN define and disable same
 
109
 *
 
110
 * Revision 6.77  2000/09/28 15:48:30  dondosha
 
111
 * Open <PRE> block in PGPFormatFooter
 
112
 *
 
113
 * Revision 6.76  2000/09/27 19:31:44  dondosha
 
114
 * Use original square substitution matrix to pass to txalign on all iterations
 
115
 *
 
116
 * Revision 6.75  2000/09/21 17:54:46  dondosha
 
117
 * Do not pass matrix to txalign in case of query-anchored formatting
 
118
 *
 
119
 * Revision 6.74  2000/09/13 18:34:35  dondosha
 
120
 * Create BLAST_Matrix from ScoreBlk before converting it to txalign-style matrix
 
121
 *
 
122
 * Revision 6.73  2000/09/12 21:51:38  dondosha
 
123
 * Pass the correct scoring matrix to ShowTextAlignFromAnnot
 
124
 *
 
125
 * Revision 6.72  2000/08/28 21:55:01  shavirin
 
126
 * Added option (m = 7) to print XML output.
 
127
 *
 
128
 * Revision 6.71  2000/08/22 20:18:21  shavirin
 
129
 * Added support for HTML output if decline-to-align parameter is set.
 
130
 *
 
131
 * Revision 6.70  2000/08/18 21:31:12  madden
 
132
 * no longer need to raise E-value threshold for composition-based statistics
 
133
 *
 
134
 * Revision 6.69  2000/08/08 21:47:55  shavirin
 
135
 * Added parameter decline_align and possibility to print then
 
136
 * discontinuous alignment.
 
137
 *
 
138
 * Revision 6.68  2000/07/26 19:04:14  shavirin
 
139
 * Set overriding default threshold only if input value != 0.
 
140
 *
 
141
 * Revision 6.67  2000/07/25 18:14:06  shavirin
 
142
 * WARNING: This is no-turning-back changed related to S&W Blast from
 
143
 * Alejandro Schaffer
 
144
 *
 
145
 * Revision 6.66  2000/07/21 20:46:40  madden
 
146
 * Threshold set to default if arg is zero
 
147
 *
 
148
 * Revision 6.65  2000/06/27 15:25:19  madden
 
149
 * Changed master-slave to query-anchored
 
150
 *
 
151
 * Revision 6.64  2000/03/29 17:32:55  madden
 
152
 * Commented out yet another call to ObjMgrFreeCache
 
153
 *
 
154
 * Revision 6.63  2000/03/27 21:32:00  shavirin
 
155
 * Use function ShowTextAlignFromAnnot2 instead of ShowTextAlignFromAnnot3
 
156
 *
 
157
 * Revision 6.62  2000/03/23 15:30:22  shavirin
 
158
 * Removed call to ObjMgrFreeCache()
 
159
 *
 
160
 * Revision 6.61  2000/03/07 21:59:07  shavirin
 
161
 * Now will use PSSM Matrix to show positives in PSI Blast
 
162
 *
 
163
 * Revision 6.60  2000/03/02 21:06:09  shavirin
 
164
 * Added -U option, that allows to consider low characters in FASTA files
 
165
 * as filtered regions (for blastn, blastp and tblastn).
 
166
 *
 
167
 * Revision 6.58  2000/01/07 22:01:04  shavirin
 
168
 * Fixed problem with printing alignment.
 
169
 *
 
170
 * Revision 6.57  1999/12/21 21:34:05  shavirin
 
171
 * Fixed some memory leaks.
 
172
 *
 
173
 * Revision 6.56  1999/11/08 19:12:41  shavirin
 
174
 * Fixed minor SGI warning.
 
175
 *
 
176
 * Revision 6.55  1999/10/21 20:27:52  shavirin
 
177
 * Fixed bug resulted in failue to print out seqannot. (-O)
 
178
 *
 
179
 * Revision 6.53  1999/10/14 15:52:51  shavirin
 
180
 * Added possibility to make search by list of gis. Fixed some bugs.
 
181
 *
 
182
 * Revision 6.52  1999/10/05 17:41:08  shavirin
 
183
 * Corrected in accordance to blast.c changes.
 
184
 *
 
185
 * Revision 6.51  1999/09/24 16:06:15  shavirin
 
186
 * Matrix is set to NULL if no matrix calculation produced.
 
187
 *
 
188
 * Revision 6.50  1999/09/22 17:53:25  shavirin
 
189
 * Now functions will collect messages in ValNodePtr before printing out.
 
190
 *
 
191
 * Revision 6.49  1999/09/21 16:01:46  shavirin
 
192
 * Rearanged all file. Main function was disintegrated into few small
 
193
 * functions.
 
194
 *
 
195
 * Revision 6.48  1999/08/27 18:17:42  shavirin
 
196
 * Added new parameter to command line - decline_align.
 
197
 *
 
198
 * Revision 6.47  1999/08/26 14:58:06  madden
 
199
 * Use float for db length
 
200
 *
 
201
 * Revision 6.46  1999/08/04 13:26:49  madden
 
202
 * Added -B option
 
203
 *
 
204
 * Revision 6.45  1999/03/31 16:58:04  madden
 
205
 * Removed static FindProt and FindNuc
 
206
 *
 
207
 * Revision 6.44  1999/03/24 18:16:33  madden
 
208
 * zero-out groupOrder and featureOrder
 
209
 *
 
210
 * Revision 6.43  1999/03/21 19:43:23  madden
 
211
 * Added -Q option to store ASCII version of last position-specific matrix in a file
 
212
 *
 
213
 * Revision 6.42  1999/03/04 14:17:20  egorov
 
214
 * Added new parameter to BlastMaskTheResidues() function for correct masking
 
215
 * when query is seqloc.  The paramter is not used in this file and is 0.
 
216
 *
 
217
 * Revision 6.41  1999/02/18 21:13:11  madden
 
218
 * Check for non-pattern search before call to BlastPruneSapStructDestruct
 
219
 *
 
220
 * Revision 6.40  1999/02/10 21:12:27  madden
 
221
 * Added HTML and GI list option, fixed filtering
 
222
 *
 
223
 * Revision 6.39  1999/01/22 17:24:51  madden
 
224
 * added line breaks for alignment views
 
225
 *
 
226
 * Revision 6.38  1998/12/29 20:03:14  kans
 
227
 * calls UseLocalAsnloadDataAndErrMsg at startup
 
228
 *
 
229
 * Revision 6.37  1998/12/17 21:54:39  madden
 
230
 * Added call to BlastPruneHitsFromSeqAlign for other than first round
 
231
 *
 
232
 * Revision 6.36  1998/12/16 14:13:36  madden
 
233
 * Fix for more than one pattern in query
 
234
 *
 
235
 * Revision 6.35  1998/11/19 14:04:34  madden
 
236
 * Changed message level to SEV_WARNING
 
237
 *
 
238
 * Revision 6.34  1998/11/16 16:29:41  madden
 
239
 * Added ErrSetMessageLevel(SEV_INFO) and fixed call to PrintKAParametersExtra
 
240
 *
 
241
 * Revision 6.33  1998/09/28 12:33:02  madden
 
242
 * Used BlastErrorPrint
 
243
 *
 
244
 * Revision 6.31  1998/09/17 19:54:31  madden
 
245
 * Removed fillCandLambda
 
246
 *
 
247
 * Revision 6.29  1998/09/10 22:38:24  madden
 
248
 * Moved convertSeqAlignListToValNodeList and convertValNodeListToSeqAlignList
 
249
 *
 
250
 * Revision 6.28  1998/09/09 21:20:02  madden
 
251
 * AS fixed warnings, removed stderr fprintf, added call to PrintKAParametersExtra
 
252
 *
 
253
 * Revision 6.27  1998/09/09 16:10:49  madden
 
254
 * PHI-BLAST changes
 
255
 *
 
256
 * Revision 6.26  1998/07/17 15:41:36  madden
 
257
 * Added effective search space flag
 
258
 *
 
259
 * Revision 6.24  1998/06/14 19:44:46  madden
 
260
 * Checkpointing fix
 
261
 *
 
262
 * Revision 6.23  1998/06/12 21:32:27  madden
 
263
 * Removed extra FnPtr cast
 
264
 *
 
265
 * Revision 6.22  1998/06/10 13:33:39  madden
 
266
 * change -h from 0.01 to 0.001
 
267
 *
 
268
 * Revision 6.21  1998/06/05 21:48:43  madden
 
269
 * Added -K and -L options
 
270
 *
 
271
 * Revision 6.20  1998/05/18 18:01:05  madden
 
272
 * Changed args to allow filter options to be changed
 
273
 *
 
274
 * Revision 6.19  1998/05/01 18:31:03  egorov
 
275
 * Add new parametes to BLASTOptionSetGapParam()
 
276
 *
 
277
 * Revision 6.18  1998/04/30 14:32:33  madden
 
278
 * init_buff_ex arg changed to 90 for reference
 
279
 *
 
280
 * Revision 6.17  1998/04/29 14:29:31  madden
 
281
 * Made reference line longer
 
282
 *
 
283
 * Revision 6.16  1998/04/01 22:49:13  madden
 
284
 * Print No hits found message
 
285
 *
 
286
 * Revision 6.15  1998/02/25 20:50:50  madden
 
287
 * Added arg for db length
 
288
 *
 
289
 * Revision 6.14  1998/02/24 22:48:36  madden
 
290
 * Removed options for culling
 
291
 *
 
292
 * Revision 6.13  1998/01/02 14:33:37  madden
 
293
 * Added comma
 
294
 *
 
295
 * Revision 6.12  1997/12/31 17:48:56  madden
 
296
 * Added wordsize option
 
297
 *
 
298
 * Revision 6.11  1997/12/23 21:09:44  madden
 
299
 * Added -K and -L for range-dependent blast
 
300
 *
 
301
 * Revision 6.10  1997/12/23 20:57:44  madden
 
302
 * Changes for checkpointing
 
303
 *
 
304
 * Revision 6.9  1997/11/19 14:26:46  madden
 
305
 * Removed extra break statement
 
306
 *
 
307
 * Revision 6.8  1997/11/18 22:24:24  madden
 
308
 * Added call to BLASTOptionSetGapParams
 
309
 *
 
310
 * Revision 6.7  1997/11/08 22:04:43  madden
 
311
 * Called BlastOtherReturnsPrepare earlier to before posMatrix is deleted
 
312
 *
 
313
 * Revision 6.6  1997/10/27 22:26:49  madden
 
314
 * Added call to ObjMgrFreeCache(0)
 
315
 *
 
316
 * Revision 6.5  1997/10/23 20:26:15  madden
 
317
 * Use of init_buff_ex rather than init_buff
 
318
 *
 
319
 * Revision 6.4  1997/10/22 21:56:49  madden
 
320
 * Changed default values
 
321
 *
 
322
 * Revision 6.3  1997/10/07 21:33:34  madden
 
323
 * Added BLUNT option
 
324
 *
 
325
 * Revision 6.2  1997/09/18 22:25:02  madden
 
326
 * b and v options now work
 
327
 *
 
328
 * Revision 6.1  1997/09/16 16:40:50  madden
 
329
 * Dbinfo printing changed for multiple db searches
 
330
 *
 
331
 * Revision 6.0  1997/08/25 18:19:19  madden
 
332
 * Revision changed to 6.0
 
333
 *
 
334
 * Revision 1.24  1997/08/24 19:38:23  madden
 
335
 * Used function BlastOtherReturnsPrepare
 
336
 *
 
337
 * Revision 1.23  1997/08/14 21:48:57  madden
 
338
 * Added descriptions and alignments options
 
339
 *
 
340
 * Revision 1.22  1997/07/29 19:33:05  madden
 
341
 * Added TXALIGN_SHOW_QS flag
 
342
 *
 
343
 * Revision 1.21  1997/07/28 18:36:45  madden
 
344
 * Replaced printf with ErrPostEx and fprintf
 
345
 *
 
346
 * Revision 1.20  1997/07/28 16:59:21  madden
 
347
 * Added include for simutil.h
 
348
 *
 
349
 * Revision 1.19  1997/07/28 16:50:51  madden
 
350
 * Changed call to ShowTextAlignFromAnnot
 
351
 *
 
352
 * Revision 1.18  1997/07/22 19:18:40  madden
 
353
 * printing version, etc.
 
354
 *
 
355
 * Revision 1.17  1997/06/25 14:06:21  madden
 
356
 * minor changes to check convergence
 
357
 *
 
358
 * Revision 1.16  1997/06/23 20:51:29  madden
 
359
 * Added matrix option
 
360
 *
 
361
 * Revision 1.15  1997/06/20 19:30:00  madden
 
362
 * Added align_type info, support for SeqAligns
 
363
 *
 
364
 * Revision 1.14  1997/05/23 20:54:48  madden
 
365
 * Added -Z option for final gapped alignment
 
366
 *
 
367
 * Revision 1.13  1997/05/07 15:06:01  madden
 
368
 * replacement of search by compactSearch
 
369
 *
 
370
 * Revision 1.12  1997/04/21  14:09:27  madden
 
371
 * Added four new master-slave alignment types.
 
372
 *
 
373
 * Revision 1.11  1997/04/11  19:03:47  madden
 
374
 * Changes to ignore query ID and show master-slave alignments.
 
375
 *
 
376
 * Revision 1.10  1997/04/10  19:28:28  madden
 
377
 * COMMAND_LINE replaced by ALL_ROUNDS.
 
378
 *
 
379
 * Revision 1.9  1997/04/10  13:27:32  madden
 
380
 * Added COMMAND_LINE define, option for multiple alignments.
 
381
 *
 
382
 * Revision 1.8  1997/04/07  21:44:50  madden
 
383
 * Removed unused variable stats.
 
384
 *
 
385
 * Revision 1.7  1997/04/04  21:13:33  madden
 
386
 * Used function BioseqBlastEngineCore, remove PrivateScoreFunc.
 
387
 *
 
388
 * Revision 1.6  1997/04/04  16:38:04  madden
 
389
 * Changed filtering option, ObjMgrHold.
 
390
 *
 
391
 * Revision 1.5  1997/03/21  20:30:02  madden
 
392
 * Expect value arg made a float.
 
393
 *
 
394
 * Revision 1.4  1997/03/13  21:18:51  madden
 
395
 * Changed default extension value to 1 from 2.
 
396
 *
 
397
 * Revision 1.3  1997/02/19  21:43:04  madden
 
398
 * Extensive changes for psi-blast.  blastp runs now occur multiple times.
 
399
 *
 
400
 * Revision 1.2  1997/02/12  15:16:58  madden
 
401
 * Changed from blast2 to new formatting.
 
402
 *
 
403
 * Revision 1.1  1997/01/16  21:35:42  madden
 
404
 * Initial revision
 
405
 *
 
406
 * Revision 1.1  1997/01/16  21:34:23  madden
 
407
 * Initial revision
 
408
 *
 
409
*/
 
410
#include <ncbi.h>
 
411
#include <objseq.h>
 
412
#include <objsset.h>
 
413
#include <sequtil.h>
 
414
#include <seqport.h>
 
415
#include <tofasta.h>
 
416
#include <blast.h>
 
417
#include <blastpri.h>
 
418
#include <txalign.h>
 
419
#include <simutil.h>
 
420
#include <gapxdrop.h>
 
421
#include <posit.h>
 
422
#include <seed.h>
 
423
#include <sqnutils.h>
 
424
#include <xmlblast.h>
 
425
#include <ddvcreate.h>
 
426
 
 
427
/* Used by the callback function. */
 
428
FILE *global_fp=NULL;
 
429
/*
 
430
  Callback to print out ticks, in UNIX only due to file systems
 
431
  portability issues.
 
432
  */
 
433
 
 
434
static int LIBCALLBACK
 
435
tick_callback(Int4 sequence_number, Int4 number_of_positive_hits)
 
436
{
 
437
    
 
438
#ifdef OS_UNIX
 
439
    
 
440
    fprintf(global_fp, "%s", ".");
 
441
    fflush(global_fp);
 
442
#endif
 
443
    return 0;
 
444
}
 
445
 
 
446
static int LIBCALLBACK
 
447
star_callback(Int4 sequence_number, Int4 number_of_positive_hits)
 
448
{
 
449
#ifdef OS_UNIX
 
450
    fprintf(global_fp, "%s", "*");
 
451
    fflush(global_fp);
 
452
#endif
 
453
    return 0;
 
454
}
 
455
 
 
456
#define YES_TO_DECLINE_TO_ALIGN
 
457
 
 
458
#define NUMARG (sizeof(myargs)/sizeof(myargs[0]))
 
459
 
 
460
static Args myargs [] = {
 
461
    { "Database",               /* 0 */
 
462
      "nr", NULL, NULL, FALSE, 'd', ARG_STRING, 0.0, 0, NULL},
 
463
    { "Query File",             /* 1 */
 
464
      "stdin", NULL, NULL, FALSE, 'i', ARG_FILE_IN, 0.0, 0, NULL},
 
465
    { "Multiple Hits window size (zero for single hit algorithm)", /* 2 */
 
466
      "40", NULL, NULL, FALSE, 'A', ARG_INT, 0.0, 0, NULL},
 
467
    { "Threshold for extending hits", /* 3 */
 
468
      "0", NULL, NULL, FALSE, 'f', ARG_INT, 0.0, 0, NULL},
 
469
    { "Expectation value (E)",  /* 4 */
 
470
      "10.0", NULL, NULL, FALSE, 'e', ARG_FLOAT, 0.0, 0, NULL},
 
471
    { "alignment view options:\n0 = pairwise,\n1 = query-anchored showing identities,\n2 = query-anchored no identities,\n3 = flat query-anchored, show identities,\n4 = flat query-anchored, no identities,\n5 = query-anchored no identities and blunt ends,\n6 = flat query-anchored, no identities and blunt ends,\n7 = XML Blast output,\n8 = Tabular output, \n9 = Tabular output with comments", /* 5 */
 
472
      "0", NULL, NULL, FALSE, 'm', ARG_INT, 0.0, 0, NULL},
 
473
    { "Output File for Alignment", /* 6 */
 
474
      "stdout", NULL, NULL, TRUE, 'o', ARG_FILE_OUT, 0.0, 0, NULL},
 
475
    { "Dropoff (X) for blast extensions in bits (default if zero)", /* 7 */
 
476
      "7.0", NULL, NULL, FALSE, 'y', ARG_FLOAT, 0.0, 0, NULL},
 
477
    { "0 for multiple hits 1-pass, 1 for single hit 1-pass, 2 for 2-pass", /* 8 */
 
478
      "0", NULL, NULL, FALSE, 'P', ARG_INT, 0.0, 0, NULL},
 
479
    { "Filter query sequence with SEG", /* 9 */
 
480
      "F", NULL, NULL, FALSE, 'F', ARG_STRING, 0.0, 0, NULL},
 
481
    { "Cost to open a gap",     /* 10 */
 
482
      "11", NULL, NULL, FALSE, 'G', ARG_INT, 0.0, 0, NULL},
 
483
    { "Cost to extend a gap",   /* 11 */
 
484
      "1", NULL, NULL, FALSE, 'E', ARG_INT, 0.0, 0, NULL},
 
485
    { "X dropoff value for gapped alignment (in bits)", /* 12 */
 
486
      "15", NULL, NULL, FALSE, 'X', ARG_INT, 0.0, 0, NULL},
 
487
    { "Number of bits to trigger gapping", /* 13 */
 
488
      "22.0", NULL, NULL, FALSE, 'N', ARG_FLOAT, 0.0, 0, NULL},
 
489
    { "Gapped",                 /* 14 */
 
490
      "T", NULL, NULL, FALSE, 'g', ARG_BOOLEAN, 0.0, 0, NULL},
 
491
    { "Start of required region in query", /* 15 */
 
492
      "1", NULL, NULL, FALSE, 'S', ARG_INT, 0.0, 0, NULL},
 
493
    { "End of required region in query (-1 indicates end of query)", /* 16 */
 
494
      "-1", NULL, NULL, FALSE, 'H', ARG_INT, 0.0, 0, NULL},
 
495
    { "Number of processors to use", /* 17 */
 
496
      "1", NULL, NULL, FALSE, 'a', ARG_INT, 0.0, 0, NULL},
 
497
    { "Show GI's in deflines",  /* 18 */
 
498
      "F", NULL, NULL, FALSE, 'I', ARG_BOOLEAN, 0.0, 0, NULL},
 
499
    { "e-value threshold for inclusion in multipass model", /* 19 */
 
500
      "0.005", NULL, NULL, FALSE, 'h', ARG_FLOAT, 0.0, 0, NULL},
 
501
    { "Constant in pseudocounts for multipass version", /* 20 */
 
502
      "9", NULL, NULL, FALSE, 'c', ARG_INT, 0.0, 0, NULL},
 
503
    { "Maximum number of passes to use in  multipass version", /* 21 */
 
504
      "1", NULL, NULL, FALSE, 'j', ARG_INT, 0.0, 0, NULL},
 
505
    { "Believe the query defline", /* 22 */
 
506
      "F", NULL, NULL, FALSE, 'J', ARG_BOOLEAN, 0.0, 0, NULL},
 
507
    { "X dropoff value for final gapped alignment (in bits)", /* 23 */
 
508
      "25", NULL, NULL, FALSE, 'Z', ARG_INT, 0.0, 0, NULL},
 
509
    { "SeqAlign file ('Believe the query defline' must be TRUE)", /* 24 */
 
510
      NULL, NULL, NULL, TRUE, 'O', ARG_FILE_OUT, 0.0, 0, NULL},
 
511
    { "Matrix",                 /* 25 */
 
512
      "BLOSUM62", NULL, NULL, FALSE, 'M', ARG_STRING, 0.0, 0, NULL},
 
513
    { "Number of database sequences to show one-line descriptions for (V)", /* 26 */
 
514
      "500", NULL, NULL, FALSE, 'v', ARG_INT, 0.0, 0, NULL},
 
515
    { "Number of database sequence to show alignments for (B)", /* 27 */
 
516
      "250", NULL, NULL, FALSE, 'b', ARG_INT, 0.0, 0, NULL},
 
517
    { "Output File for PSI-BLAST Checkpointing", /* 28 */
 
518
      NULL, NULL, NULL, TRUE, 'C', ARG_FILE_OUT, 0.0, 0, NULL},
 
519
    { "Input File for PSI-BLAST Restart", /* 29 */
 
520
      NULL, NULL, NULL, TRUE, 'R', ARG_FILE_IN, 0.0, 0, NULL},
 
521
    { "Word size, default if zero", /* 30 */
 
522
      "0", NULL, NULL, FALSE, 'W', ARG_INT, 0.0, 0, NULL},
 
523
    { "Effective length of the database (use zero for the real size)", /* 31 */
 
524
      "0", NULL, NULL, FALSE, 'z', ARG_INT, 0.0, 0, NULL},
 
525
    { "Number of best hits from a region to keep", /* 32 */
 
526
      "0", NULL, NULL, FALSE, 'K', ARG_INT, 0.0, 0, NULL},
 
527
    { "Compute locally optimal Smith-Waterman alignments", /*33*/
 
528
      "F", NULL, NULL, FALSE, 's', ARG_BOOLEAN, 0.0, 0, NULL},
 
529
    { "Effective length of the search space (use zero for the real size)", /* 34 */
 
530
      "0", NULL, NULL, FALSE, 'Y', ARG_FLOAT, 0.0, 0, NULL},
 
531
    { "program option for PHI-BLAST", /* 35 */
 
532
      "blastpgp", NULL, NULL, FALSE, 'p', ARG_STRING, 0.0, 0, NULL},
 
533
    { "Hit File for PHI-BLAST", /* 36 */
 
534
      "hit_file", NULL, NULL, FALSE, 'k', ARG_FILE_IN, 0.0, 0, NULL},
 
535
    { "Produce HTML output",    /* 37 */
 
536
      "F", NULL, NULL, FALSE, 'T', ARG_BOOLEAN, 0.0, 0, NULL},
 
537
    { "Output File for PSI-BLAST Matrix in ASCII", /* 38 */
 
538
      NULL, NULL, NULL, TRUE, 'Q', ARG_FILE_OUT, 0.0, 0, NULL},
 
539
    { "Input Alignment File for PSI-BLAST Restart", /* 39 */
 
540
      NULL, NULL, NULL, TRUE, 'B', ARG_FILE_IN, 0.0, 0, NULL},
 
541
    { "Restrict search of database to list of GI's", /* 40 */
 
542
      NULL, NULL, NULL, TRUE, 'l', ARG_STRING, 0.0, 0, NULL},
 
543
    {"Use lower case filtering of FASTA sequence",    /* 41 */
 
544
     "F", NULL,NULL,TRUE,'U',ARG_BOOLEAN, 0.0,0,NULL},
 
545
    { "Use composition based statistics", /*42*/
 
546
      "T", NULL, NULL, FALSE, 't', ARG_BOOLEAN, 0.0, 0, NULL},
 
547
#ifdef YES_TO_DECLINE_TO_ALIGN
 
548
    { "Cost to decline alignment (disabled when 0)", /* 43 */
 
549
      "0", NULL, NULL, FALSE, 'L', ARG_INT, 0.0, 0, NULL},
 
550
#endif
 
551
};
 
552
 
 
553
typedef struct _pgp_blast_options {
 
554
    BLAST_OptionsBlkPtr options;
 
555
    CharPtr blast_database;
 
556
    BioseqPtr query_bsp, fake_bsp;
 
557
    Int4 number_of_descriptions, number_of_alignments;
 
558
    FILE *infp, *outfp;
 
559
    AsnIoPtr aip_out;
 
560
    Boolean html;
 
561
    Boolean believe_query;
 
562
    Uint4 align_options, print_options;
 
563
    /* PHI-PSI Blast variables */
 
564
    Uint1 featureOrder[FEATDEF_ANY];
 
565
    Uint1 groupOrder[FEATDEF_ANY];
 
566
    Int4 program_flag;
 
567
    CharPtr patfile;
 
568
    FILE *patfp; 
 
569
    seedSearchItems *seedSearch;
 
570
    Boolean is_xml_output;
 
571
} PGPBlastOptions, PNTR PGPBlastOptionsPtr;
 
572
 
 
573
void PGPGetPrintOptions(Boolean gapped, Uint4Ptr align_options_out, 
 
574
                        Uint4Ptr print_options_out)
 
575
{
 
576
    Uint4 print_options, align_options;
 
577
 
 
578
    print_options = 0;
 
579
    if (gapped == FALSE)
 
580
        print_options += TXALIGN_SHOW_NO_OF_SEGS;
 
581
    
 
582
    align_options = 0;
 
583
    align_options += TXALIGN_COMPRESS;
 
584
    align_options += TXALIGN_END_NUM;
 
585
 
 
586
    if (myargs[18].intvalue) {
 
587
        align_options += TXALIGN_SHOW_GI;
 
588
        print_options += TXALIGN_SHOW_GI;
 
589
    } 
 
590
    
 
591
    if (myargs[37].intvalue) {
 
592
        align_options += TXALIGN_HTML;
 
593
        print_options += TXALIGN_HTML;
 
594
    }
 
595
    
 
596
    if (myargs[5].intvalue != 0) {
 
597
        align_options += TXALIGN_MASTER;
 
598
        if (myargs[5].intvalue == 1 || myargs[5].intvalue == 3)
 
599
            align_options += TXALIGN_MISMATCH;
 
600
        if (myargs[5].intvalue == 3 || myargs[5].intvalue == 4 || myargs[5].intvalue == 6)
 
601
            align_options += TXALIGN_FLAT_INS;
 
602
        if (myargs[5].intvalue == 5 || myargs[5].intvalue == 6)
 
603
            align_options += TXALIGN_BLUNT_END;
 
604
    } else {
 
605
        align_options += TXALIGN_MATRIX_VAL;
 
606
        align_options += TXALIGN_SHOW_QS;
 
607
    }
 
608
 
 
609
    *align_options_out = align_options;
 
610
    *print_options_out = print_options;
 
611
 
 
612
    return;
 
613
}
 
614
void PGPFreeBlastOptions(PGPBlastOptionsPtr bop)
 
615
{
 
616
 
 
617
    bop->options = BLASTOptionDelete(bop->options);
 
618
    
 
619
    FileClose(bop->infp);
 
620
    FileClose(bop->outfp);
 
621
    
 
622
    MemFree(bop->blast_database);
 
623
    MemFree(bop->patfile);
 
624
    MemFree(bop->seedSearch);
 
625
 
 
626
    MemFree(bop);
 
627
 
 
628
    return;
 
629
 
630
    
 
631
PGPBlastOptionsPtr PGPReadBlastOptions(void)
 
632
{
 
633
    PGPBlastOptionsPtr bop;
 
634
    BLAST_OptionsBlkPtr options;
 
635
    SeqEntryPtr sep;
 
636
    Boolean is_dna;
 
637
    ObjectIdPtr obidp;
 
638
 
 
639
    bop = MemNew(sizeof(PGPBlastOptions));
 
640
    
 
641
    bop->blast_database   = StringSave(myargs [0].strvalue);
 
642
 
 
643
    if ((bop->infp = FileOpen(myargs [1].strvalue, "r")) == NULL) {
 
644
        ErrPostEx(SEV_FATAL, 0, 0, "blast: Unable to open input file %s\n", 
 
645
                  myargs [1].strvalue);
 
646
        return NULL;
 
647
    }
 
648
    
 
649
    if (myargs [6].strvalue != NULL) {
 
650
        if ((bop->outfp = FileOpen(myargs [6].strvalue, "w")) == NULL) {
 
651
            ErrPostEx(SEV_FATAL, 0, 0, "blast: Unable to open output "
 
652
                      "file %s\n", myargs [6].strvalue);
 
653
            return NULL;
 
654
        }
 
655
    }
 
656
    
 
657
    bop->number_of_descriptions = myargs[26].intvalue;
 
658
    bop->number_of_alignments = myargs[27].intvalue;
 
659
    
 
660
    if (myargs[22].intvalue != 0)
 
661
        bop->believe_query = TRUE;
 
662
    
 
663
    if (myargs[24].strvalue != NULL) {
 
664
        
 
665
        if (bop->believe_query == FALSE) {
 
666
            ErrPostEx(SEV_FATAL, 0, 0, 
 
667
                      "-J option must be TRUE to use this option");
 
668
            return NULL;
 
669
        }
 
670
        
 
671
        if ((bop->aip_out = AsnIoOpen (myargs[24].strvalue,"w")) == NULL) {
 
672
            ErrPostEx(SEV_FATAL, 0, 0, "blast: Unable to open output "
 
673
                      "file %s\n", myargs[24].strvalue);
 
674
            return NULL;
 
675
        }
 
676
    }
 
677
 
 
678
    options = BLASTOptionNew("blastp", (Boolean)myargs[14].intvalue);
 
679
    bop->options = options;
 
680
 
 
681
    if(myargs[41].intvalue) {
 
682
        if((sep = FastaToSeqEntryForDb (bop->infp, FALSE, NULL, bop->believe_query, NULL, NULL, &options->query_lcase_mask)) == NULL) {
 
683
            ErrPostEx(SEV_FATAL, 0, 0, "Unable to read input FASTA file\n");
 
684
            return NULL;
 
685
        }
 
686
    } else {
 
687
        if((sep = FastaToSeqEntryEx(bop->infp, FALSE, NULL, bop->believe_query)) == NULL) {
 
688
            ErrPostEx(SEV_FATAL, 0, 0, "Unable to read input FASTA file\n");
 
689
            return NULL;
 
690
        }
 
691
    }
 
692
    
 
693
    SeqEntryExplore(sep, &bop->query_bsp, FindProt);    
 
694
    /*    sep->data.ptrvalue = NULL;
 
695
          SeqEntryFree(sep); */
 
696
    
 
697
    if (bop->query_bsp == NULL) {
 
698
        ErrPostEx(SEV_FATAL, 0, 0, "Unable to obtain bioseq\n");
 
699
        return NULL;
 
700
    }    
 
701
    
 
702
    /* Set default gap params for matrix. */
 
703
    BLASTOptionSetGapParams(options, myargs[25].strvalue, 0, 0);
 
704
 
 
705
    if(myargs[5].intvalue == 7) {
 
706
        bop->is_xml_output = TRUE;
 
707
    } else if (myargs[5].intvalue != 8 && myargs[5].intvalue != 9) {
 
708
        PGPGetPrintOptions(options->gapped_calculation, &bop->align_options, 
 
709
                           &bop->print_options);
 
710
    }
 
711
 
 
712
    /* decrement by one to agree with program values. */
 
713
    options->required_start = myargs[15].intvalue - 1;
 
714
    options->required_end = myargs[16].intvalue;
 
715
    if (options->required_end != -1) {
 
716
        options->required_end--;
 
717
    }
 
718
    
 
719
    options->window_size = myargs [2].intvalue;
 
720
 
 
721
    if(myargs [3].intvalue)    
 
722
        options->threshold_second = (Int4) myargs [3].intvalue;
 
723
    
 
724
    options->dropoff_2nd_pass  = myargs [7].floatvalue;
 
725
    options->expect_value  = (Nlm_FloatHi) myargs [4].floatvalue;
 
726
    options->hitlist_size = MAX(bop->number_of_descriptions, 
 
727
                                bop->number_of_alignments);
 
728
    
 
729
    if (myargs[14].intvalue != 0) {
 
730
        if (myargs[8].intvalue == 0) {
 
731
            options->two_pass_method  = FALSE;
 
732
            options->multiple_hits_only  = TRUE;
 
733
        } else if (myargs[8].intvalue == 1) {
 
734
            options->two_pass_method  = FALSE;
 
735
            options->multiple_hits_only  = FALSE;
 
736
        } else {
 
737
            options->two_pass_method  = TRUE;
 
738
            options->multiple_hits_only  = FALSE;
 
739
        }
 
740
        options->gap_open = myargs[10].intvalue;
 
741
        options->gap_extend = myargs[11].intvalue;
 
742
        
 
743
#ifdef YES_TO_DECLINE_TO_ALIGN
 
744
        if(myargs[43].intvalue != 0) {
 
745
            options->discontinuous = TRUE;
 
746
            options->decline_align = myargs[43].intvalue;
 
747
        } else {
 
748
            options->discontinuous = FALSE;
 
749
            options->decline_align = INT2_MAX;
 
750
        }
 
751
#endif
 
752
 
 
753
        options->gap_x_dropoff = myargs[12].intvalue;
 
754
        options->gap_x_dropoff_final = myargs[23].intvalue;
 
755
        options->gap_trigger = myargs[13].floatvalue;
 
756
    }
 
757
    
 
758
    if (StringICmp(myargs[9].strvalue, "T") == 0) {
 
759
        options->filter_string = StringSave("S");
 
760
    } else {
 
761
        options->filter_string = StringSave(myargs[9].strvalue);
 
762
    }
 
763
    
 
764
    options->number_of_cpus = (Int2) myargs[17].intvalue;
 
765
    
 
766
    
 
767
    options->isPatternSearch = FALSE;
 
768
    
 
769
    if (0 != (StringCmp("blastpgp",myargs[35].strvalue))) {
 
770
        options->isPatternSearch = TRUE;
 
771
        options->discontinuous = FALSE;
 
772
        options->decline_align = INT2_MAX;    
 
773
        bop->program_flag = convertProgramToFlag(myargs[35].strvalue, 
 
774
                                                 &is_dna);
 
775
    }
 
776
    
 
777
    if (options->isPatternSearch) {
 
778
        bop->patfile = StringSave(myargs[36].strvalue);
 
779
        if ((bop->patfp = FileOpen(bop->patfile, "r")) == NULL) {
 
780
            ErrPostEx(SEV_FATAL, 0, 0, "blast: Unable to open pattern "
 
781
                      "file %s\n", bop->patfile);
 
782
            return NULL;
 
783
        }
 
784
        
 
785
        bop->seedSearch = (seedSearchItems *) 
 
786
            ckalloc(sizeof(seedSearchItems));
 
787
    }
 
788
    
 
789
    if(options->isPatternSearch)
 
790
        fillCandLambda(bop->seedSearch, myargs[25].strvalue, options);
 
791
    
 
792
    options->ethresh = (Nlm_FloatHi) myargs[19].floatvalue;
 
793
    options->pseudoCountConst = myargs[20].intvalue;
 
794
    options->maxNumPasses = myargs[21].intvalue;
 
795
    /*zero out e-value threshold if it will not be used*/
 
796
    if (options->maxNumPasses == 1)
 
797
        options->ethresh = 0.0;
 
798
    if (myargs[30].intvalue)
 
799
        options->wordsize = myargs[30].intvalue;
 
800
    if (myargs[31].intvalue)
 
801
        options->db_length = (Int8) myargs[31].intvalue;
 
802
    
 
803
    options->hsp_range_max  = myargs[32].intvalue;
 
804
    if (options->hsp_range_max != 0)
 
805
        options->perform_culling = TRUE;
 
806
 
 
807
    options->block_width  = 20; /* Default value - previously '-L' parameter */
 
808
    
 
809
    if (myargs[34].floatvalue)
 
810
        options->searchsp_eff = (Nlm_FloatHi) myargs[34].floatvalue;
 
811
 
 
812
    options->tweak_parameters = (Boolean) myargs[42].intvalue;
 
813
    options->smith_waterman = (Boolean) myargs[33].intvalue;
 
814
 
 
815
    if (bop->options->tweak_parameters) {
 
816
      /*allows for extra matches in first pass of screening,
 
817
        hitlist_size */
 
818
      bop->options->original_expect_value = bop->options->expect_value;
 
819
      bop->options->hitlist_size *= 2; 
 
820
    }
 
821
 
 
822
 
 
823
    /* Seting list of gis to restrict search */
 
824
    
 
825
    if (myargs[40].strvalue) {
 
826
        options->gifile = StringSave(myargs[40].strvalue);
 
827
    }
 
828
    
 
829
    options = BLASTOptionValidate(options, "blastp");
 
830
    
 
831
    if (options == NULL)
 
832
        return NULL;
 
833
 
 
834
    if(bop->believe_query) {
 
835
        bop->fake_bsp = bop->query_bsp;
 
836
    } else {
 
837
        bop->fake_bsp = BlastMakeFakeBioseq(bop->query_bsp, NULL);
 
838
        
 
839
        BLASTUpdateSeqIdInSeqInt(bop->options->query_lcase_mask, 
 
840
                                 bop->fake_bsp->id);
 
841
    }
 
842
 
 
843
    return bop;
 
844
}
 
845
 
 
846
Boolean PGPReadNextQuerySequence(PGPBlastOptionsPtr bop)
 
847
{
 
848
    SeqEntryPtr sep;
 
849
 
 
850
    /* Cleaning up stuff from previous query run */
 
851
 
 
852
    bop->options->query_lcase_mask = SeqLocSetFree(bop->options->query_lcase_mask);
 
853
 
 
854
    if (bop->believe_query == TRUE) { /* Not corect - to be fixed */
 
855
        BioseqFree(bop->query_bsp);
 
856
    } else {
 
857
        BioseqFree(bop->fake_bsp);
 
858
    }
 
859
 
 
860
    if(myargs[41].intvalue) {
 
861
        if((sep = FastaToSeqEntryForDb (bop->infp, FALSE, NULL, bop->believe_query, NULL, NULL, &bop->options->query_lcase_mask)) == NULL) {
 
862
            return FALSE;
 
863
        }
 
864
    } else {
 
865
        if((sep = FastaToSeqEntryEx(bop->infp, FALSE, NULL, 
 
866
                                    bop->believe_query)) == NULL) {
 
867
            return FALSE;
 
868
        }
 
869
    }
 
870
 
 
871
    bop->query_bsp = NULL;
 
872
    SeqEntryExplore(sep, &bop->query_bsp, FindProt);    
 
873
    
 
874
    if (bop->query_bsp == NULL) {
 
875
        ErrPostEx(SEV_FATAL, 0, 0, "Unable to obtain bioseq\n");
 
876
        return 0;
 
877
    }    
 
878
    
 
879
    if(bop->believe_query) {
 
880
        bop->fake_bsp = bop->query_bsp;
 
881
    } else {
 
882
        bop->fake_bsp = BlastMakeFakeBioseq(bop->query_bsp, NULL);
 
883
        
 
884
        BLASTUpdateSeqIdInSeqInt(bop->options->query_lcase_mask, 
 
885
                                 bop->fake_bsp->id);
 
886
    }
 
887
 
 
888
    return TRUE;
 
889
}
 
890
 
 
891
Boolean PGPFormatHeader(PGPBlastOptionsPtr bop)
 
892
{
 
893
    Boolean html = myargs[37].intvalue;
 
894
 
 
895
    if (html)
 
896
        fprintf(bop->outfp, "<PRE>\n");
 
897
    
 
898
    init_buff_ex(90);
 
899
    BlastPrintVersionInfo("blastp", html, bop->outfp);
 
900
    fprintf(bop->outfp, "\n");
 
901
    BlastPrintReference(html, 90, bop->outfp);
 
902
    fprintf(bop->outfp, "\n");
 
903
    AcknowledgeBlastQuery(bop->query_bsp, 70, 
 
904
                          bop->outfp, bop->believe_query, html);
 
905
    PrintDbInformation(bop->blast_database, TRUE, 70, bop->outfp, html);
 
906
    free_buff();
 
907
 
 
908
    return TRUE;
 
909
}
 
910
Boolean  PGPFormatFooter(PGPBlastOptionsPtr bop, BlastSearchBlkPtr search)
 
911
{
 
912
    
 
913
    ValNodePtr  mask_loc, vnp;
 
914
    BLAST_KarlinBlkPtr ka_params=NULL, ka_params_gap=NULL;
 
915
    TxDfDbInfoPtr dbinfo=NULL, dbinfo_head;
 
916
    CharPtr params_buffer=NULL;
 
917
    ValNodePtr other_returns;
 
918
    BLAST_MatrixPtr blast_matrix;
 
919
    Boolean html = myargs[37].intvalue;
 
920
 
 
921
    if (html)
 
922
        fprintf(bop->outfp, "<PRE>\n");
 
923
 
 
924
    other_returns = BlastOtherReturnsPrepare(search);
 
925
 
 
926
    mask_loc = NULL;
 
927
    for (vnp=other_returns; vnp; vnp = vnp->next) {
 
928
        switch (vnp->choice) {
 
929
        case TXDBINFO:
 
930
            dbinfo = vnp->data.ptrvalue;
 
931
            break;
 
932
        case TXKABLK_NOGAP:
 
933
            ka_params = vnp->data.ptrvalue;
 
934
            break;
 
935
        case TXKABLK_GAP:
 
936
            ka_params_gap = vnp->data.ptrvalue;
 
937
            break;
 
938
        case TXPARAMETERS:
 
939
            params_buffer = vnp->data.ptrvalue;
 
940
            break;
 
941
        case TXMATRIX:
 
942
            blast_matrix = vnp->data.ptrvalue;
 
943
            BLAST_MatrixDestruct(blast_matrix);
 
944
            break;
 
945
        case SEQLOC_MASKING_NOTSET:
 
946
        case SEQLOC_MASKING_PLUS1:
 
947
        case SEQLOC_MASKING_PLUS2:
 
948
        case SEQLOC_MASKING_PLUS3:
 
949
        case SEQLOC_MASKING_MINUS1:
 
950
        case SEQLOC_MASKING_MINUS2:
 
951
        case SEQLOC_MASKING_MINUS3:
 
952
            ValNodeAddPointer(&mask_loc, vnp->choice, vnp->data.ptrvalue);
 
953
            break;
 
954
        default:
 
955
            break;
 
956
        }
 
957
    }   
 
958
    
 
959
    init_buff_ex(85);
 
960
    dbinfo_head = dbinfo;
 
961
    while (dbinfo) {
 
962
        PrintDbReport(dbinfo, 70, bop->outfp);
 
963
        dbinfo = dbinfo->next;
 
964
    }
 
965
    dbinfo_head = TxDfDbInfoDestruct(dbinfo_head);
 
966
    
 
967
    if (ka_params && !bop->options->isPatternSearch) {
 
968
        PrintKAParameters(ka_params->Lambda, ka_params->K, ka_params->H, 70, bop->outfp, FALSE);
 
969
    }
 
970
    
 
971
    if (ka_params_gap) {
 
972
        if (bop->options->isPatternSearch)
 
973
            PrintKAParametersExtra(ka_params_gap->Lambda, ka_params_gap->K, ka_params_gap->H, bop->seedSearch->paramC, 70, bop->outfp, FALSE);
 
974
        else
 
975
            PrintKAParameters(ka_params_gap->Lambda, ka_params_gap->K, ka_params_gap->H, 70, bop->outfp, FALSE);
 
976
    }
 
977
    
 
978
    MemFree(ka_params);
 
979
    MemFree(ka_params_gap);
 
980
 
 
981
    PrintTildeSepLines(params_buffer, 70, bop->outfp);
 
982
    MemFree(params_buffer);
 
983
    free_buff();
 
984
 
 
985
    return TRUE;
 
986
}
 
987
 
 
988
Boolean PGPrintPosMatrix(CharPtr filename, posSearchItems *posSearch, 
 
989
                         compactSearchItems *compactSearch, 
 
990
                         Boolean posComputationCalled)
 
991
{
 
992
    FILE *fp;
 
993
    
 
994
    if ((fp = FileOpen(filename, "w")) == NULL) {
 
995
        ErrPostEx(SEV_FATAL, 0, 0, "Unable to open matrix output file %s\n", 
 
996
                  filename);
 
997
        return FALSE;
 
998
    }
 
999
 
 
1000
    /* a diagnostic, partly an option with -Q. */
 
1001
    outputPosMatrix(posSearch, compactSearch, fp, posComputationCalled); 
 
1002
    FileClose(fp);
 
1003
 
 
1004
    return TRUE;
 
1005
}
 
1006
 
 
1007
SeqAlignPtr PGPSeedSearch(PGPBlastOptionsPtr bop, BlastSearchBlkPtr search,
 
1008
                          posSearchItems *posSearch, 
 
1009
                          SeqLocPtr PNTR seqloc_duplicate,
 
1010
                          SeqAlignPtr PNTR PNTR lastSeqAligns,
 
1011
                          Int4Ptr numLastSeqAligns)
 
1012
{
 
1013
    Uint1Ptr query = NULL; /*query sequence read in*/
 
1014
    Uint1Ptr unfilter_query = NULL; /*needed if seg will filter query*/
 
1015
    SeqLocPtr seg_slp;  /*pointer to structure for seg filtering*/
 
1016
    Int4 i, queryLength;   /*length of query sequence*/
 
1017
    SeqAlignPtr head;
 
1018
    SeqAnnotPtr annot;
 
1019
    SeqFeatPtr sfp;
 
1020
    SeqLocPtr seqloc, next;
 
1021
    ValNodePtr seedReturn; /*return value from seedEngineCore, which
 
1022
                             is a list of lists of SeqAligns, one
 
1023
                             list of SeqAligns per pattern occurrence*/
 
1024
    
 
1025
    ValNodePtr vnp, info_vnp;  /* Output text messages from seedEngineCore() */
 
1026
    
 
1027
    query = BlastGetSequenceFromBioseq(bop->fake_bsp, &queryLength);
 
1028
    seg_slp = BlastBioseqFilter(bop->fake_bsp, 
 
1029
                                bop->options->filter_string);
 
1030
    if (seg_slp) {
 
1031
        unfilter_query = MemNew((queryLength + 1) * sizeof(Uint1));
 
1032
        for (i = 0; i < queryLength; i++)
 
1033
            unfilter_query[i] = query[i];
 
1034
        BlastMaskTheResidues(query,queryLength,21,seg_slp,FALSE, 0);
 
1035
    }
 
1036
    
 
1037
    search->gap_align = GapAlignBlkNew(1,1);
 
1038
    search->gap_align->gap_open = bop->options->gap_open;
 
1039
    search->gap_align->gap_extend = bop->options->gap_extend;
 
1040
 
 
1041
 
 
1042
    search->gap_align->decline_align = INT2_MAX;
 
1043
 
 
1044
#ifdef YES_TO_DECLINE_TO_ALIGN
 
1045
    if(myargs[43].intvalue != 0) {
 
1046
        search->gap_align->decline_align = myargs[43].intvalue;
 
1047
    } else {
 
1048
        search->gap_align->decline_align = INT2_MAX;
 
1049
    }
 
1050
#endif
 
1051
    
 
1052
    /* search->gap_align->decline_align = (-(BLAST_SCORE_MIN)); */
 
1053
    /* search->gap_align->decline_align = myargs[41].intvalue; */
 
1054
 
 
1055
    search->gap_align->x_parameter = bop->options->gap_x_dropoff
 
1056
        *NCBIMATH_LN2/bop->seedSearch->paramLambda;
 
1057
    search->gap_align->matrix = search->sbp->matrix;
 
1058
    initProbs(bop->seedSearch);
 
1059
    init_order(search->gap_align->matrix, bop->program_flag, 
 
1060
               FALSE, bop->seedSearch);
 
1061
    
 
1062
    for(i = 0; i < queryLength; i++)
 
1063
        query[i] = bop->seedSearch->order[query[i]];
 
1064
    
 
1065
    if (unfilter_query) {
 
1066
        for(i = 0; i < queryLength; i++)
 
1067
            unfilter_query[i] = bop->seedSearch->order[unfilter_query[i]];
 
1068
    }
 
1069
            
 
1070
    seqloc = NULL;
 
1071
    seedReturn = seedEngineCore(search, bop->options, query, 
 
1072
                                unfilter_query,
 
1073
                                bop->blast_database, bop->patfile, 
 
1074
                                bop->program_flag, 
 
1075
                                bop->patfp, FALSE, FALSE, 
 
1076
                                bop->seedSearch, bop->options->ethresh, 
 
1077
                                myargs[34].floatvalue, posSearch, 
 
1078
                                &seqloc, TRUE, &info_vnp);
 
1079
    if (!bop->is_xml_output)
 
1080
       PGPOutTextMessages(info_vnp, bop->outfp);
 
1081
    ValNodeFreeData(info_vnp);
 
1082
    
 
1083
    if (search->error_return) {
 
1084
       BlastErrorPrint(search->error_return);
 
1085
       for (vnp = search->error_return; vnp; vnp = vnp->next) {
 
1086
          BlastDestroyErrorMessage((BlastErrorMsgPtr)vnp->data.ptrvalue);
 
1087
       }
 
1088
       search->error_return = ValNodeFree(search->error_return);
 
1089
    }
 
1090
    *seqloc_duplicate = seqloc;
 
1091
    head = convertValNodeListToSeqAlignList(seedReturn, lastSeqAligns, 
 
1092
                                            numLastSeqAligns);
 
1093
 
 
1094
    bop->featureOrder[FEATDEF_REGION] = 1;
 
1095
    bop->groupOrder[FEATDEF_REGION] = 1;
 
1096
    annot = bop->fake_bsp->annot = SeqAnnotNew();
 
1097
    bop->fake_bsp->annot->type = 1;     /* ftable. */
 
1098
    while (seqloc) {
 
1099
        next = seqloc->next;
 
1100
        sfp = SeqFeatNew();
 
1101
        sfp->location = seqloc;
 
1102
        sfp->data.choice = SEQFEAT_REGION;
 
1103
        sfp->data.value.ptrvalue = StringSave("pattern");
 
1104
        annot->data = sfp;
 
1105
        if (next) {
 
1106
            annot->next = SeqAnnotNew();
 
1107
            annot = annot->next;
 
1108
            annot->type = 1;
 
1109
        }
 
1110
        seqloc = next;
 
1111
    }
 
1112
 
 
1113
    if (query != NULL)
 
1114
        MemFree(query);
 
1115
    if (unfilter_query != NULL)
 
1116
        unfilter_query = MemFree(unfilter_query);
 
1117
    
 
1118
    return head;
 
1119
}
 
1120
 
 
1121
void PGPFormatMainOutput(SeqAlignPtr head, PGPBlastOptionsPtr bop,
 
1122
                         BlastSearchBlkPtr search, Int4 thisPassNum,
 
1123
                         SeqAlignPtr PNTR lastSeqAligns, 
 
1124
                         Int4 numLastSeqAligns, SeqLocPtr seed_seqloc,
 
1125
                         Int2Ptr posRepeatSequences)
 
1126
{
 
1127
    SeqAnnotPtr seqannot;
 
1128
    ValNodePtr pruneSeed, seedReturn;  
 
1129
    BlastPruneSapStructPtr prune;
 
1130
    BLAST_MatrixPtr matrix;
 
1131
    Int4Ptr PNTR txmatrix;
 
1132
    BioseqPtr query_bsp;
 
1133
 
 
1134
    if(head == NULL) {
 
1135
        fprintf(bop->outfp, "\n\n ***** No hits found ******\n\n");
 
1136
        return;
 
1137
    }
 
1138
    
 
1139
    if (myargs[5].intvalue == 8 || myargs[5].intvalue == 9) {
 
1140
       query_bsp = (bop->believe_query) ? bop->query_bsp : bop->fake_bsp;
 
1141
        if (myargs[5].intvalue == 9)
 
1142
                PrintTabularOutputHeader(bop->blast_database, query_bsp, NULL, 
 
1143
                                "blastp", thisPassNum, bop->believe_query,
 
1144
                                bop->outfp);
 
1145
       BlastPrintTabulatedResults(head, query_bsp, NULL, 
 
1146
                                  bop->number_of_alignments,
 
1147
                                  "blastp", FALSE,
 
1148
                                  bop->believe_query, 0, 0, bop->outfp);
 
1149
       return;
 
1150
    }
 
1151
 
 
1152
    seqannot = SeqAnnotNew();
 
1153
    seqannot->type = 2;
 
1154
    AddAlignInfoToSeqAnnot(seqannot, 2);
 
1155
    seqannot->data = head;
 
1156
 
 
1157
    if (search->pbp->maxNumPasses != 1) {
 
1158
        fprintf(bop->outfp, "\nResults from round %d\n", 
 
1159
                thisPassNum);
 
1160
    }
 
1161
    
 
1162
    ObjMgrSetHold();
 
1163
    init_buff_ex(85);
 
1164
 
 
1165
    /* ------- Printing deflines for the BLAST output ------- */
 
1166
 
 
1167
    if (thisPassNum == 1) {
 
1168
        search->positionBased = FALSE;
 
1169
        if (!bop->options->isPatternSearch) {
 
1170
            prune = BlastPruneHitsFromSeqAlign(head, 
 
1171
                             bop->number_of_descriptions, NULL);
 
1172
            PrintDefLinesFromSeqAlign(prune->sap, 80, bop->outfp, 
 
1173
                                      bop->print_options, FIRST_PASS, NULL);
 
1174
        } else {
 
1175
            seedReturn = convertSeqAlignListToValNodeList(head,lastSeqAligns, 
 
1176
                                                          numLastSeqAligns);
 
1177
                        
 
1178
            pruneSeed = SeedPruneHitsFromSeedReturn(seedReturn, 
 
1179
                                      bop->number_of_descriptions);
 
1180
            PrintDefLinesExtra(pruneSeed, 80, bop->outfp, bop->print_options, 
 
1181
                               FIRST_PASS, NULL, seed_seqloc);
 
1182
        }
 
1183
    } else {
 
1184
        prune = BlastPruneHitsFromSeqAlign(head, 
 
1185
                              bop->number_of_descriptions, NULL);
 
1186
        if (ALL_ROUNDS) {
 
1187
            PrintDefLinesFromSeqAlign(prune->sap, 80, bop->outfp, 
 
1188
                                      bop->print_options, 
 
1189
                                      NOT_FIRST_PASS_REPEATS, 
 
1190
                                      posRepeatSequences);
 
1191
            PrintDefLinesFromSeqAlign(prune->sap, 80, bop->outfp, 
 
1192
                                      bop->print_options, NOT_FIRST_PASS_NEW, 
 
1193
                                      posRepeatSequences);
 
1194
        } else
 
1195
            PrintDefLinesFromSeqAlign(prune->sap, 80, bop->outfp, 
 
1196
                                      bop->print_options, FIRST_PASS, NULL);
 
1197
    } /*thisPassNum == 1 */
 
1198
 
 
1199
    /* ------- --------------------------------------- ------- */
 
1200
 
 
1201
    if (ALL_ROUNDS && search->posConverged) {
 
1202
        fprintf(bop->outfp, "\nCONVERGED!\n");
 
1203
    }
 
1204
 
 
1205
    free_buff();
 
1206
    
 
1207
    matrix = NULL;
 
1208
    txmatrix = NULL;
 
1209
    if (search->sbp->matrix) {
 
1210
       matrix = BLAST_MatrixFill(search->sbp, FALSE);
 
1211
       txmatrix = BlastMatrixToTxMatrix(matrix);
 
1212
    }
 
1213
 
 
1214
    if (!(bop->options->isPatternSearch)) {
 
1215
        prune = BlastPruneHitsFromSeqAlign(head, bop->number_of_alignments, 
 
1216
                                           prune);
 
1217
        seqannot->data = prune->sap;
 
1218
 
 
1219
        if(bop->options->discontinuous) {
 
1220
            if(!DDV_DisplayBlastPairList(prune->sap, search->mask, 
 
1221
                                         bop->outfp, FALSE, 
 
1222
                                         bop->align_options,
 
1223
                                         bop->align_options & TXALIGN_HTML ? 6 : 1)) { 
 
1224
                fprintf(stdout, 
 
1225
                        "\n\n!!!\n   "
 
1226
                        "    --------  Failure to print alignment...  --------"
 
1227
                        "\n!!!\n\n");
 
1228
                fflush(stdout);
 
1229
            }
 
1230
        } else {   /* Old type formating */
 
1231
            if (myargs[5].intvalue != 0) {
 
1232
                ShowTextAlignFromAnnot2(seqannot, 60, bop->outfp, 
 
1233
                                        bop->featureOrder, bop->groupOrder, 
 
1234
                                        bop->align_options, NULL, 
 
1235
                                        search->mask, NULL, 
 
1236
                                        NULL, NULL);
 
1237
            } else {
 
1238
                ShowTextAlignFromAnnot2(seqannot, 60, bop->outfp, 
 
1239
                                        bop->featureOrder, bop->groupOrder, 
 
1240
                                        bop->align_options, txmatrix, 
 
1241
                                        search->mask, FormatScoreFunc, 
 
1242
                                        NULL, NULL);
 
1243
            }
 
1244
        }
 
1245
 
 
1246
        /* seqannot->data = head; */
 
1247
 
 
1248
    } else {
 
1249
        if (bop->number_of_alignments < bop->number_of_descriptions) {
 
1250
            pruneSeed = SeedPruneHitsFromSeedReturn(pruneSeed, 
 
1251
                                                    bop->number_of_alignments);
 
1252
        }
 
1253
 
 
1254
 
 
1255
        if (myargs[5].intvalue != 0) {
 
1256
            ShowTextAlignFromAnnotExtra(bop->query_bsp, pruneSeed, 
 
1257
                                        seed_seqloc, 60, bop->outfp, 
 
1258
                                        bop->featureOrder, bop->groupOrder, 
 
1259
                                        bop->align_options, NULL, 
 
1260
                                        search->mask, NULL);
 
1261
        } else {
 
1262
            ShowTextAlignFromAnnotExtra(bop->query_bsp, pruneSeed, 
 
1263
                                        seed_seqloc, 60, bop->outfp, 
 
1264
                                        bop->featureOrder, bop->groupOrder, 
 
1265
                                        bop->align_options, txmatrix, 
 
1266
                                        search->mask, FormatScoreFunc);
 
1267
        }
 
1268
    }
 
1269
 
 
1270
    if (!(bop->options->isPatternSearch)) {
 
1271
        prune = BlastPruneSapStructDestruct(prune);
 
1272
    }
 
1273
 
 
1274
    search->positionBased = TRUE;
 
1275
    ObjMgrClearHold();
 
1276
    ObjMgrFreeCache(0);
 
1277
 
 
1278
    matrix = BLAST_MatrixDestruct(matrix);
 
1279
    if (txmatrix)
 
1280
       txmatrix = TxMatrixDestruct(txmatrix);
 
1281
 
 
1282
    seqannot->data = NULL;
 
1283
    seqannot = SeqAnnotFree(seqannot);
 
1284
 
 
1285
    return;
 
1286
}
 
1287
 
 
1288
void PGPSeqAlignOut(PGPBlastOptionsPtr bop, SeqAlignPtr head)
 
1289
{
 
1290
    SeqAnnotPtr seqannot;
 
1291
 
 
1292
    if (!bop->aip_out || !head)
 
1293
        return;
 
1294
    
 
1295
    seqannot = SeqAnnotNew();
 
1296
    seqannot->type = 2;
 
1297
    AddAlignInfoToSeqAnnot(seqannot, 2);
 
1298
    seqannot->data = head;
 
1299
    SeqAnnotAsnWrite((SeqAnnotPtr) seqannot, bop->aip_out, NULL);
 
1300
    AsnIoReset(bop->aip_out);
 
1301
    bop->aip_out = AsnIoClose(bop->aip_out);
 
1302
    seqannot->data = NULL;
 
1303
    seqannot = SeqAnnotFree(seqannot);
 
1304
}
 
1305
 
 
1306
Int2 Main (void)
 
1307
     
 
1308
{
 
1309
    PGPBlastOptionsPtr bop;
 
1310
    BlastSearchBlkPtr search;
 
1311
    SeqAlignPtr  head = NULL;
 
1312
    SeqLocPtr seed_seqloc = NULL;
 
1313
    
 
1314
    /* used for psi-blast */
 
1315
    Int4 thisPassNum;       
 
1316
    posSearchItems *posSearch;
 
1317
    compactSearchItems *compactSearch;
 
1318
    Boolean  recoverCheckpoint = FALSE;
 
1319
    Boolean  alreadyRecovered = FALSE;
 
1320
    Boolean  freqCheckpoint = FALSE;
 
1321
    Boolean  alignCheckpoint = FALSE;
 
1322
    Boolean  posComputationCalled = FALSE;
 
1323
    Boolean  checkReturn = FALSE;
 
1324
    Boolean  next_query = FALSE;
 
1325
    Boolean tabular_output;
 
1326
 
 
1327
    SeqAlignPtr PNTR lastSeqAligns = NULL; 
 
1328
                                /*keeps track of the last SeqAlign in
 
1329
                                  each list of seedReturn so that the
 
1330
                                  2-level list can be converted to a 1-level
 
1331
                                  list and then back to 2-level*/
 
1332
    Int4 numLastSeqAligns = 0;
 
1333
 
 
1334
    PSIXmlPtr psixp = NULL;
 
1335
    ValNodePtr vnp;
 
1336
 
 
1337
    /* ----- End of definitions ----- */
 
1338
    
 
1339
    if (! GetArgs ("blastpgp", NUMARG, myargs))
 
1340
        return (1);
 
1341
    ErrSetMessageLevel(SEV_WARNING);
 
1342
    
 
1343
    UseLocalAsnloadDataAndErrMsg ();
 
1344
 
 
1345
    if (! SeqEntryLoad())
 
1346
        return 1;    
 
1347
    
 
1348
    bop = PGPReadBlastOptions();
 
1349
 
 
1350
    /* Here we will start main do/while loop over many query entries in 
 
1351
       the input file. If there is an option for checkpoint recover or
 
1352
       Output File for PSI-BLAST Checkpointing all but first entries in
 
1353
       the input file will be discarded */
 
1354
 
 
1355
    do {    
 
1356
        search = BLASTSetUpSearchWithReadDb(bop->fake_bsp, "blastp", 
 
1357
                                            bop->query_bsp->length, 
 
1358
                                            bop->blast_database,
 
1359
                                            bop->options, NULL);
 
1360
    
 
1361
        if (search == NULL)
 
1362
            return 1;
 
1363
    
 
1364
        if(bop->is_xml_output) {
 
1365
            AsnIoPtr aip;
 
1366
            if((aip = AsnIoOpen(myargs[6].strvalue, "wx")) == NULL)
 
1367
                return 1;
 
1368
        
 
1369
            psixp = PSIXmlInit(aip, "blastp", bop->blast_database, 
 
1370
                               bop->options, 
 
1371
                               bop->fake_bsp, 0);
 
1372
        }
 
1373
    
 
1374
        /*AAS*/
 
1375
        if ((NULL != myargs[29].strvalue) || (NULL != myargs[39].strvalue)) {
 
1376
            recoverCheckpoint = TRUE;
 
1377
            if (NULL != myargs[29].strvalue) {
 
1378
                freqCheckpoint = TRUE;
 
1379
                alignCheckpoint = FALSE;
 
1380
            } else {
 
1381
                freqCheckpoint = FALSE;
 
1382
                alignCheckpoint = TRUE;
 
1383
            }
 
1384
        }
 
1385
        
 
1386
        if (recoverCheckpoint)
 
1387
            search->positionBased = TRUE;
 
1388
        else
 
1389
            search->positionBased = FALSE;
 
1390
        
 
1391
        global_fp = bop->outfp;
 
1392
        tabular_output = (myargs[5].intvalue == 8 || myargs[5].intvalue == 9);
 
1393
 
 
1394
        if(!bop->is_xml_output && !tabular_output) {   
 
1395
            PGPFormatHeader(bop);
 
1396
        }
 
1397
        
 
1398
        posSearch = NULL;
 
1399
        thisPassNum = 0;
 
1400
        compactSearch = NULL;
 
1401
        search->posConverged = FALSE;
 
1402
        global_fp = bop->outfp;
 
1403
        search->error_return = NULL;
 
1404
        /*AAS*/
 
1405
        if (recoverCheckpoint) {
 
1406
            posSearch = (posSearchItems *) MemNew(1 * sizeof(posSearchItems));
 
1407
            compactSearch = compactSearchNew(compactSearch);
 
1408
            copySearchItems(compactSearch, search, bop->options->matrix);
 
1409
            posInitializeInformation(posSearch,search);
 
1410
            /*AAS*/
 
1411
            if (freqCheckpoint) {
 
1412
                checkReturn = posReadCheckpoint(posSearch, compactSearch, myargs[29].strvalue, &(search->error_return));
 
1413
                search->sbp->posMatrix = posSearch->posMatrix;
 
1414
                if (NULL == search->sbp->posFreqs)
 
1415
                    search->sbp->posFreqs =  allocatePosFreqs(compactSearch->qlength, compactSearch->alphabetSize);
 
1416
                copyPosFreqs(posSearch->posFreqs,search->sbp->posFreqs, compactSearch->qlength, compactSearch->alphabetSize);
 
1417
            } else {
 
1418
                search->sbp->posMatrix = BposComputation(posSearch, search, compactSearch, myargs[39].strvalue, myargs[28].strvalue, &(search->error_return)); 
 
1419
                posComputationCalled = TRUE;
 
1420
                if (NULL == search->sbp->posMatrix)
 
1421
                    checkReturn = FALSE;
 
1422
                else
 
1423
                    checkReturn = TRUE;
 
1424
            }
 
1425
            
 
1426
 
 
1427
            if (search->error_return) {
 
1428
               BlastErrorPrint(search->error_return);
 
1429
               for (vnp = search->error_return; vnp; vnp = vnp->next) {
 
1430
                  BlastDestroyErrorMessage((BlastErrorMsgPtr)vnp->data.ptrvalue);
 
1431
               }
 
1432
               search->error_return = ValNodeFree(search->error_return);
 
1433
            }
 
1434
            if (!checkReturn) {
 
1435
                ErrPostEx(SEV_FATAL, 0, 0, "blast: Error recovering from checkpoint");
 
1436
                return 1;
 
1437
            }
 
1438
        
 
1439
            /* Print out Pos matrix if necessary */
 
1440
            if (myargs[38].strvalue != NULL)
 
1441
                PGPrintPosMatrix(myargs[38].strvalue, posSearch, compactSearch, posComputationCalled);
 
1442
        }
 
1443
        
 
1444
        do {  /*AAS*/
 
1445
            thisPassNum++;
 
1446
            if (thisPassNum > 1)
 
1447
                bop->options->isPatternSearch = FALSE;
 
1448
            
 
1449
            if(head != NULL)
 
1450
                head = SeqAlignSetFree(head);
 
1451
            
 
1452
#ifdef OS_UNIX
 
1453
            if(!bop->is_xml_output && !tabular_output) {
 
1454
                search->thr_info->tick_callback =  tick_callback;
 
1455
                fprintf(global_fp, "%s", "Searching");
 
1456
                fflush(global_fp);
 
1457
            }
 
1458
#endif
 
1459
            if (1 == thisPassNum && (!recoverCheckpoint)) {
 
1460
                
 
1461
                posSearch = (posSearchItems *) 
 
1462
                    MemNew(1 * sizeof(posSearchItems));
 
1463
            }
 
1464
            
 
1465
            /* ----- Here is real BLAST search done ------- */
 
1466
            
 
1467
            if (bop->options->isPatternSearch && 
 
1468
                (1 == thisPassNum && (!recoverCheckpoint))) {
 
1469
                head = PGPSeedSearch(bop, search, posSearch, 
 
1470
                                     &seed_seqloc,
 
1471
                                     &lastSeqAligns, &numLastSeqAligns);
 
1472
            } else {
 
1473
                if ((bop->options->tweak_parameters) && (thisPassNum > 1)) {
 
1474
                    /*allows for extra matches in first pass of screening,
 
1475
                      hitlist_size will be restored in
 
1476
                      BioseqBlastEngineCore for the second pass. */
 
1477
                    bop->options->original_expect_value = 
 
1478
                        bop->options->expect_value;
 
1479
                    bop->options->hitlist_size *= 2; 
 
1480
                }
 
1481
                
 
1482
                if ((1 == thisPassNum) && (!recoverCheckpoint))
 
1483
                    head = BioseqBlastEngineCore(search, bop->options, NULL);
 
1484
                else
 
1485
                    head = BioseqBlastEngineCore(search, bop->options, 
 
1486
                                                 search->sbp->posMatrix);  
 
1487
            }
 
1488
            /* ---------------------------------------------- */
 
1489
            
 
1490
            if (recoverCheckpoint) {
 
1491
                compactSearchDestruct(compactSearch);
 
1492
                recoverCheckpoint = FALSE;
 
1493
                alreadyRecovered = TRUE;
 
1494
            }
 
1495
            
 
1496
            if (thisPassNum == 1) {
 
1497
                compactSearch = compactSearchNew(compactSearch);
 
1498
            } else {
 
1499
                MemFree(compactSearch->standardProb);
 
1500
            }
 
1501
            
 
1502
            copySearchItems(compactSearch, search, bop->options->matrix);
 
1503
            
 
1504
            
 
1505
            /* The next two calls (after the "if") are diagnostics 
 
1506
               for Stephen. Don't perform this if only one pass will 
 
1507
               be made (i.e., standard BLAST) */
 
1508
            
 
1509
            if (ALL_ROUNDS && 1 != search->pbp->maxNumPasses) {
 
1510
                if ((1 == thisPassNum)  && (!alreadyRecovered))
 
1511
                    posInitializeInformation(posSearch, search);
 
1512
                posPrintInformation(posSearch, search, thisPassNum);
 
1513
            }
 
1514
            
 
1515
#ifdef OS_UNIX
 
1516
            if(!bop->is_xml_output && !tabular_output) {
 
1517
                fprintf(global_fp, "%s", "done\n\n");
 
1518
            }
 
1519
#endif
 
1520
            
 
1521
            /* AAS */
 
1522
            if (thisPassNum == 1) {
 
1523
                ReadDBBioseqFetchEnable ("blastpgp", bop->blast_database, 
 
1524
                                         FALSE, TRUE);
 
1525
            } else {
 
1526
                
 
1527
                /* Have things converged? */
 
1528
                if (ALL_ROUNDS && search->pbp->maxNumPasses != 1) {
 
1529
                    posConvergenceTest(posSearch, search, head, thisPassNum);
 
1530
                }
 
1531
            }
 
1532
 
 
1533
            /*AAS*/
 
1534
            search->positionBased = TRUE;
 
1535
            
 
1536
            /* Here is all BLAST formating of the main output done */
 
1537
            
 
1538
            if(bop->is_xml_output) {
 
1539
                
 
1540
                ValNodePtr other_returns;
 
1541
                IterationPtr iterp;
 
1542
 
 
1543
                other_returns = BlastOtherReturnsPrepare(search);
 
1544
 
 
1545
                if (head == NULL) {                
 
1546
                    iterp = BXMLBuildOneIteration(head, other_returns, bop->options->is_ooframe, !bop->options->gapped_calculation, thisPassNum, "No hits found");
 
1547
                } else {
 
1548
                    iterp = BXMLBuildOneIteration(head, other_returns, bop->options->is_ooframe, !bop->options->gapped_calculation, thisPassNum, search->posConverged ? "CONVERGED" : NULL);
 
1549
                }
 
1550
                
 
1551
                IterationAsnWrite(iterp, psixp->aip, psixp->atp);
 
1552
                AsnIoFlush(psixp->aip);
 
1553
                
 
1554
                IterationFree(iterp);
 
1555
                BlastOtherReturnsFree(other_returns);
 
1556
            } else {
 
1557
                PGPFormatMainOutput(head, bop, search, thisPassNum,
 
1558
                                    lastSeqAligns, numLastSeqAligns, 
 
1559
                                    seed_seqloc, posSearch->posRepeatSequences);
 
1560
            }
 
1561
            
 
1562
            if (alreadyRecovered) {
 
1563
                posCheckpointFreeMemory(posSearch, compactSearch->qlength);
 
1564
                alreadyRecovered = FALSE;
 
1565
            }
 
1566
            
 
1567
            if (ALL_ROUNDS && thisPassNum > 1) {
 
1568
                posCleanup(posSearch, compactSearch);
 
1569
            }
 
1570
        
 
1571
            if (!search->posConverged && (search->pbp->maxNumPasses == 0 || 
 
1572
                                          (thisPassNum < search->pbp->maxNumPasses))) {
 
1573
                if (ALL_ROUNDS) {
 
1574
                    search->sbp->posMatrix = 
 
1575
                        CposComputation(posSearch, search, compactSearch, 
 
1576
                                        head, myargs[28].strvalue, 
 
1577
                                        (bop->options->isPatternSearch && 
 
1578
                                         (1== thisPassNum)), 
 
1579
                                        &(search->error_return), 1.0); /*AAS*/
 
1580
                    posComputationCalled = TRUE;
 
1581
                    if (search->error_return) {
 
1582
                       BlastErrorPrint(search->error_return);
 
1583
                       for (vnp = search->error_return; vnp; vnp = vnp->next) {
 
1584
                          BlastDestroyErrorMessage((BlastErrorMsgPtr)vnp->data.ptrvalue);
 
1585
                       }
 
1586
                       search->error_return = ValNodeFree(search->error_return);
 
1587
                    }
 
1588
                } else {
 
1589
                    search->sbp->posMatrix = 
 
1590
                        WposComputation(compactSearch, head, search->sbp->posFreqs); 
 
1591
                    posComputationCalled = TRUE;
 
1592
                }
 
1593
#if 0
 
1594
                /* DEBUG Printing of the matrix */
 
1595
                {{
 
1596
                    Int4 i, j;
 
1597
                    FILE *fd;
 
1598
                    
 
1599
                    fd = FileOpen("omatrix.out", "w");
 
1600
                    for(i = 0; i < bop->query_bsp->length; i++) {
 
1601
                        for(j = 0; j < 26; j++) {
 
1602
                            fprintf(fd, "%d ", search->sbp->posMatrix[i][j]);
 
1603
                        } 
 
1604
                        fprintf(fd, "\n");
 
1605
                    } 
 
1606
                    FileClose(fd);
 
1607
                }}
 
1608
#endif
 
1609
            } else {
 
1610
                search->sbp->posMatrix = NULL;
 
1611
            }
 
1612
            
 
1613
            if (ALL_ROUNDS && thisPassNum > 1) {
 
1614
                MemFree(posSearch->posRepeatSequences);
 
1615
            }
 
1616
            
 
1617
            if (!search->posConverged && (0 == search->pbp->maxNumPasses || 
 
1618
                                          thisPassNum < search->pbp->maxNumPasses)) {
 
1619
                
 
1620
                /* Print out pos matrix if necessary */
 
1621
                if (ALL_ROUNDS && (myargs[38].strvalue != NULL))
 
1622
                    PGPrintPosMatrix(myargs[38].strvalue, posSearch, 
 
1623
                                     compactSearch, posComputationCalled);
 
1624
            }
 
1625
            
 
1626
        } while (( 0 == search->pbp->maxNumPasses || thisPassNum < (search->pbp->maxNumPasses)) && (! (search->posConverged)));
 
1627
 
 
1628
        if (bop->aip_out != NULL && head != NULL)
 
1629
            PGPSeqAlignOut(bop, head);
 
1630
        
 
1631
        head = SeqAlignSetFree(head);
 
1632
        
 
1633
        /* Here we will print out footer of BLAST output */
 
1634
        
 
1635
        if(!bop->is_xml_output && !tabular_output) {
 
1636
            PGPFormatFooter(bop, search);
 
1637
        }
 
1638
 
 
1639
        /* PGPOneQueryCleanup */
 
1640
 
 
1641
        if (bop->options->isPatternSearch) {
 
1642
            bop->seedSearch = MemFree(bop->seedSearch);
 
1643
            FileClose(bop->patfp);
 
1644
        }
 
1645
        
 
1646
        if (ALL_ROUNDS) {
 
1647
            posFreeInformation(posSearch);
 
1648
            MemFree(posSearch);
 
1649
        }    
 
1650
        compactSearchDestruct(compactSearch);
 
1651
        search = BlastSearchBlkDestruct(search);
 
1652
 
 
1653
        /* If these options are set we are not going to proceed with another
 
1654
           queryes in the input file if any */
 
1655
        
 
1656
        if(recoverCheckpoint || myargs[38].strvalue != NULL)
 
1657
            break;
 
1658
        
 
1659
        next_query = FALSE;
 
1660
        next_query = PGPReadNextQuerySequence(bop);
 
1661
        if (bop->options->tweak_parameters)
 
1662
           bop->options->hitlist_size *= 2;   
 
1663
    } while (next_query);       /* End of main do {} while (); loop */
 
1664
 
 
1665
    ReadDBBioseqFetchDisable();
 
1666
 
 
1667
    
 
1668
    if(psixp != NULL) {
 
1669
        PSIXmlClose(psixp);
 
1670
    }
 
1671
    
 
1672
    PGPFreeBlastOptions(bop);
 
1673
    
 
1674
    return 0;
 
1675
}
 
1676
        
 
1677
 
 
1678
/* Nothing below this line is executable code */
 
1679
 
 
1680
#ifdef PRINT_ONLY_ALIGNMENT
 
1681
        {{
 
1682
            AsnIoPtr aip;
 
1683
            
 
1684
            if (seqannot)
 
1685
                seqannot = SeqAnnotFree(seqannot);
 
1686
            
 
1687
            seqannot = SeqAnnotNew();
 
1688
            seqannot->type = 2;
 
1689
            AddAlignInfoToSeqAnnot(seqannot, 2);
 
1690
            seqannot->data = head;
 
1691
            aip = AsnIoOpen("stdout", "w");
 
1692
            SeqAnnotAsnWrite(seqannot, aip, NULL);
 
1693
            AsnIoReset(aip);
 
1694
            AsnIoClose(aip);
 
1695
            
 
1696
            seqannot->data = NULL;
 
1697
            seqannot = SeqAnnotFree(seqannot);
 
1698
            
 
1699
            return 0;
 
1700
        }}
 
1701
#endif