~ubuntu-branches/debian/experimental/ncbi-tools6/experimental

« back to all changes in this revision

Viewing changes to demo/blastall.c

  • Committer: Bazaar Package Importer
  • Author(s): Aaron M. Ucko
  • Date: 2005-03-27 12:00:15 UTC
  • mfrom: (2.1.2 hoary)
  • Revision ID: james.westby@ubuntu.com-20050327120015-embhesp32nj73p9r
Tags: 6.1.20041020-3
* Fix FTBFS under GCC 4.0 caused by inconsistent use of "static" on
  functions.  (Closes: #295110.)
* Add a watch file, now that we can.  (Upstream's layout needs version=3.)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $Id: blastall.c,v 6.105 2001/12/17 20:23:44 madden Exp $
 
1
static char const rcsid[] = "$Id: blastall.c,v 6.148 2004/09/28 16:06:38 papadopo Exp $";
 
2
 
 
3
/* $Id: blastall.c,v 6.148 2004/09/28 16:06:38 papadopo Exp $
2
4
**************************************************************************
3
5
*                                                                         *
4
6
*                             COPYRIGHT NOTICE                            *
26
28
************************************************************************** 
27
29
 * 
28
30
 * $Log: blastall.c,v $
 
31
 * Revision 6.148  2004/09/28 16:06:38  papadopo
 
32
 * From Michael Gertz:
 
33
 * 1. Disabled ungapped psitblastn.
 
34
 * 2. The longest_intron parameter no longer has a minimum value of 4000.
 
35
 * 3. Changed the command line help for the longest_intron parameter.
 
36
 *
 
37
 * Revision 6.147  2004/08/17 17:22:33  madden
 
38
 * Add BlastArguments enum for command-line arguments
 
39
 *
 
40
 * Revision 6.146  2004/07/29 00:05:57  coulouri
 
41
 * fix blastcl3 umr
 
42
 *
 
43
 * Revision 6.145  2004/07/28 18:49:56  coulouri
 
44
 * fix printf specifier
 
45
 *
 
46
 * Revision 6.144  2004/06/30 12:33:30  madden
 
47
 * Add include for blfmtutl.h
 
48
 *
 
49
 * Revision 6.143  2004/05/13 18:42:44  coulouri
 
50
 * disable -B for blastcl3
 
51
 *
 
52
 * Revision 6.142  2004/04/29 19:56:00  dondosha
 
53
 * Mask filtered locations in query sequence lines in XML output
 
54
 *
 
55
 * Revision 6.141  2004/04/20 14:55:47  morgulis
 
56
 * 1. Fixed query offsets in results when -B option is used.
 
57
 * 2. Fixes for lower case masking handling with -B option.
 
58
 *
 
59
 * Revision 6.140  2004/03/26 21:42:19  coulouri
 
60
 * remove unused variables
 
61
 *
 
62
 * Revision 6.139  2004/03/18 15:14:21  coulouri
 
63
 * do not dereference null seqalignptr
 
64
 *
 
65
 * Revision 6.138  2004/02/27 14:22:47  coulouri
 
66
 * Correct typo
 
67
 *
 
68
 * Revision 6.137  2004/02/10 18:49:06  coulouri
 
69
 * do not allow 1-hit blastn searches
 
70
 *
 
71
 * Revision 6.136  2003/11/05 22:28:06  dondosha
 
72
 * No need to shift subsequence coordinates in tabular output, since they are already shifted in the seqalign
 
73
 *
 
74
 * Revision 6.135  2003/08/21 15:37:54  dondosha
 
75
 * Corrections for out-of-frame tabular output and megablast XML output
 
76
 *
 
77
 * Revision 6.134  2003/05/30 17:31:09  coulouri
 
78
 * add rcsid
 
79
 *
 
80
 * Revision 6.133  2003/05/09 18:44:49  coulouri
 
81
 * make ErrPostEx(SEV_FATAL, ...) exit with nonzero status
 
82
 *
 
83
 * Revision 6.132  2003/05/06 18:57:46  dondosha
 
84
 * Do not set cutoff_s for megablast, it is not needed
 
85
 *
 
86
 * Revision 6.131  2003/04/08 17:33:42  dondosha
 
87
 * Scale the default values of gap costs if match reward is > 1
 
88
 *
 
89
 * Revision 6.130  2003/04/07 14:46:25  madden
 
90
 * Disallow query concatenation if XML, tabular, or ASN.1
 
91
 *
 
92
 * Revision 6.129  2003/04/01 22:40:09  dondosha
 
93
 * Check lower case masking option if megablast option is on
 
94
 *
 
95
 * Revision 6.128  2003/03/25 15:28:08  dondosha
 
96
 * Print tabular output header before checking if seqalign is NULL
 
97
 *
 
98
 * Revision 6.127  2003/03/24 21:17:08  madden
 
99
 * XML fix, remove random printf statements
 
100
 *
 
101
 * Revision 6.126  2003/03/24 19:43:05  madden
 
102
 * Changes to support query concatenation for blastn and tblastn
 
103
 *
 
104
 * Revision 6.125  2003/03/20 13:44:23  madden
 
105
 * Fix -m 10/11 output to make them SeqAnnots
 
106
 *
 
107
 * Revision 6.124  2002/12/31 22:47:16  boemker
 
108
 * Added support for printing output as ASN (text, with -m 10, or binary, with
 
109
 * -m 11).
 
110
 *
 
111
 * Revision 6.123  2002/09/18 20:34:30  camacho
 
112
 * Restored -P option
 
113
 *
 
114
 * Revision 6.122  2002/08/23 16:45:36  madden
 
115
 * Issue WARNING for out-of-frame alignments
 
116
 *
 
117
 * Revision 6.121  2002/08/14 15:09:59  camacho
 
118
 * Only change default window size if its command-line value is non-zero
 
119
 *
 
120
 * Revision 6.120  2002/08/09 19:41:25  camacho
 
121
 * 1) Added blast version number to command-line options
 
122
 * 2) Added explanations for some default parameters
 
123
 *
 
124
 * Revision 6.119  2002/06/19 22:50:17  dondosha
 
125
 * Added all queries information for tabular output with multiple queries
 
126
 *
 
127
 * Revision 6.118  2002/05/09 15:37:52  dondosha
 
128
 * Call BLASTOptionNewEx instead of BLASTOptionNew, so megablast defaults are set in a central place
 
129
 *
 
130
 * Revision 6.117  2002/05/04 13:04:43  madden
 
131
 * Unsuppress options
 
132
 *
 
133
 * Revision 6.116  2002/04/29 19:55:26  madden
 
134
 * Use ARG_FLOAT for db length
 
135
 *
 
136
 * Revision 6.115  2002/04/25 21:57:45  madden
 
137
 * Strip options for release
 
138
 *
 
139
 * Revision 6.114  2002/04/25 21:49:28  madden
 
140
 * Reset mask_loc_start to NULL for every query
 
141
 *
 
142
 * Revision 6.113  2002/04/24 19:55:13  madden
 
143
 * Rolled back last change
 
144
 *
 
145
 * Revision 6.112  2002/04/23 20:58:52  madden
 
146
 * Suppress options for release
 
147
 *
 
148
 * Revision 6.111  2002/04/18 20:18:22  dondosha
 
149
 * Separate mask locations when formatting results for multiple queries
 
150
 *
 
151
 * Revision 6.110  2002/04/16 21:10:58  madden
 
152
 * Change placement of ReadDBBioseqFetchEnable so db open only once (for HPUX)
 
153
 *
 
154
 * Revision 6.109  2002/04/16 14:06:00  madden
 
155
 * Do not print headers for XML or tabular output
 
156
 *
 
157
 * Revision 6.108  2002/03/19 23:29:38  dondosha
 
158
 * Do not increment options->wordsize by 4 for megablast any more
 
159
 *
 
160
 * Revision 6.107  2002/02/19 23:21:45  dondosha
 
161
 * Fix for XML output if megablast option is used
 
162
 *
 
163
 * Revision 6.106  2001/12/20 21:51:06  madden
 
164
 * Uncomment DO_NOT_SUPPRESS_BLAST_OP
 
165
 *
29
166
 * Revision 6.105  2001/12/17 20:23:44  madden
30
167
 * comment out DO_NOT_SUPPRESS_BLAST_OP
31
168
 *
383
520
#include <sqnutils.h>
384
521
#include <xmlblast.h>
385
522
#include <mblast.h>
 
523
#include <blfmtutl.h>
386
524
#ifdef BLAST_CS_API
387
525
#include <objblst3.h>
388
526
#include <netblap3.h>
444
582
 
445
583
                if (bsp == NULL)
446
584
                {
447
 
                        ErrPostEx(SEV_FATAL, 0, 0, "Unable to obtain bioseq\n");
 
585
                        ErrPostEx(SEV_FATAL, 1, 0, "Unable to obtain bioseq\n");
448
586
                        return 2;
449
587
                }
450
588
                SeqIdWrite(bsp->id, buffer, PRINTID_FASTA_LONG, 50);
535
673
        return 0;
536
674
}
537
675
 
538
 
/*
539
 
#define DO_NOT_SUPPRESS_BLAST_OP
540
 
*/
 
676
typedef enum {
 
677
ARG_PROGRAM = 0,
 
678
ARG_DB,
 
679
ARG_QUERY,
 
680
ARG_EVALUE,
 
681
ARG_FORMAT,
 
682
ARG_OUT,
 
683
ARG_FILTER,
 
684
ARG_GAPOPEN,
 
685
ARG_GAPEXT,
 
686
ARG_XDROP,
 
687
ARG_SHOWGIS,
 
688
ARG_MISMATCH,
 
689
ARG_MATCH,
 
690
ARG_DESCRIPTIONS,
 
691
ARG_ALIGNMENTS,
 
692
ARG_THRESHOLD,
 
693
ARG_GAPPED,
 
694
ARG_QGENETIC_CODE,
 
695
ARG_DBGENETIC_CODE,
 
696
ARG_THREADS, 
 
697
ARG_ASNOUT,
 
698
ARG_BELIEVEQUERY,
 
699
ARG_MATRIX,
 
700
ARG_WORDSIZE,
 
701
ARG_DBSIZE,
 
702
ARG_BESTHITS,
 
703
ARG_MULTIPLEHITS,
 
704
ARG_SEARCHSP,
 
705
ARG_STRAND,
 
706
ARG_HTML,
 
707
#ifdef BLAST_CS_API
 
708
ARG_ENTREZQ,
 
709
#else
 
710
ARG_GILIST,
 
711
#endif
 
712
ARG_LCASE,
 
713
ARG_XDROP_UNGAPPED,
 
714
ARG_XDROP_FINAL,
 
715
#ifdef BLAST_CS_API
 
716
ARG_RPSBLAST,
 
717
#else
 
718
ARG_PSITCHKPNT,
 
719
#endif
 
720
ARG_USEMEGABLAST,
 
721
ARG_QUERYLOC,
 
722
ARG_WINDOW,
 
723
ARG_FRAMESHIFT,
 
724
ARG_INTRON,
 
725
ARG_NUMQUERIES
 
726
} BlastArguments;
541
727
 
542
728
#define NUMARG (sizeof(myargs)/sizeof(myargs[0]))
543
729
 
544
 
static Args myargs [] = {
545
 
    { "Program Name",           /* 0 */
546
 
      NULL, NULL, NULL, FALSE, 'p', ARG_STRING, 0.0, 0, NULL},
547
 
    { "Database",               /* 1 */
548
 
      "nr", NULL, NULL, FALSE, 'd', ARG_STRING, 0.0, 0, NULL},
549
 
    { "Query File",             /* 2 */
550
 
      "stdin", NULL, NULL, FALSE, 'i', ARG_FILE_IN, 0.0, 0, NULL},
551
 
    { "Expectation value (E)",  /* 3 */
552
 
      "10.0", NULL, NULL, FALSE, 'e', ARG_FLOAT, 0.0, 0, NULL},
553
 
    { "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, \n9 tabular with comment lines", /* 4 */
554
 
      "0", NULL, NULL, FALSE, 'm', ARG_INT, 0.0, 0, NULL},
555
 
    { "BLAST report Output File", /* 5 */
556
 
      "stdout", NULL, NULL, TRUE, 'o', ARG_FILE_OUT, 0.0, 0, NULL},
557
 
    { "Filter query sequence (DUST with blastn, SEG with others)", /* 6 */
558
 
      "T", NULL, NULL, FALSE, 'F', ARG_STRING, 0.0, 0, NULL},
559
 
    { "Cost to open a gap (zero invokes default behavior)", /* 7 */
560
 
      "0", NULL, NULL, FALSE, 'G', ARG_INT, 0.0, 0, NULL},
561
 
    { "Cost to extend a gap (zero invokes default behavior)", /* 8 */
562
 
      "0", NULL, NULL, FALSE, 'E', ARG_INT, 0.0, 0, NULL},
563
 
    { "X dropoff value for gapped alignment (in bits) (zero invokes default behavior)", /* 9 */
564
 
      "0", NULL, NULL, FALSE, 'X', ARG_INT, 0.0, 0, NULL},
 
730
static Args myargs[] = {
 
731
    { "Program Name",           
 
732
      NULL, NULL, NULL, FALSE, 'p', ARG_STRING, 0.0, 0, NULL},    /* ARG_PROGRAM */
 
733
    { "Database",               
 
734
      "nr", NULL, NULL, FALSE, 'd', ARG_STRING, 0.0, 0, NULL},    /* ARG_DB */
 
735
    { "Query File",            
 
736
      "stdin", NULL, NULL, FALSE, 'i', ARG_FILE_IN, 0.0, 0, NULL}, /* ARG_QUERY */
 
737
    { "Expectation value (E)",  
 
738
      "10.0", NULL, NULL, FALSE, 'e', ARG_FLOAT, 0.0, 0, NULL},    /* ARG_EVALUE */
 
739
    { "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, \n9 tabular with comment lines\n10 ASN, text\n11 ASN, binary", /* 4 */
 
740
      "0", NULL, NULL, FALSE, 'm', ARG_INT, 0.0, 0, NULL},         /* ARG_FORMAT */
 
741
    { "BLAST report Output File", 
 
742
      "stdout", NULL, NULL, TRUE, 'o', ARG_FILE_OUT, 0.0, 0, NULL}, /* ARG_OUT */
 
743
    { "Filter query sequence (DUST with blastn, SEG with others)", 
 
744
      "T", NULL, NULL, FALSE, 'F', ARG_STRING, 0.0, 0, NULL},       /* ARG_FILTER */
 
745
    { "Cost to open a gap (zero invokes default behavior)", 
 
746
      "0", NULL, NULL, FALSE, 'G', ARG_INT, 0.0, 0, NULL},          /* ARG_GAPOPEN */
 
747
    { "Cost to extend a gap (zero invokes default behavior)", 
 
748
      "0", NULL, NULL, FALSE, 'E', ARG_INT, 0.0, 0, NULL},          /* ARG_GAPEXT */
 
749
    { "X dropoff value for gapped alignment (in bits) (zero invokes default "
 
750
      "behavior)\n      blastn 30, megablast 20, tblastx 0, all others 15", 
 
751
      "0", NULL, NULL, FALSE, 'X', ARG_INT, 0.0, 0, NULL},          /* ARG_XDROP */
565
752
    { "Show GI's in deflines",  /* 10 */
566
 
      "F", NULL, NULL, FALSE, 'I', ARG_BOOLEAN, 0.0, 0, NULL},
567
 
    { "Penalty for a nucleotide mismatch (blastn only)", /* 11 */
568
 
      "-3", NULL, NULL, FALSE, 'q', ARG_INT, 0.0, 0, NULL},
569
 
    { "Reward for a nucleotide match (blastn only)", /* 12 */
570
 
      "1", NULL, NULL, FALSE, 'r', ARG_INT, 0.0, 0, NULL},
571
 
    { "Number of database sequences to show one-line descriptions for (V)", /* 13 */
572
 
      "500", NULL, NULL, FALSE, 'v', ARG_INT, 0.0, 0, NULL},
573
 
    { "Number of database sequence to show alignments for (B)", /* 14 */
574
 
      "250", NULL, NULL, FALSE, 'b', ARG_INT, 0.0, 0, NULL},
575
 
    { "Threshold for extending hits, default if zero", /* 15 */
576
 
      "0", NULL, NULL, FALSE, 'f', ARG_INT, 0.0, 0, NULL},
577
 
    { "Perfom gapped alignment (not available with tblastx)", /* 16 */
578
 
        "T", NULL, NULL, FALSE, 'g', ARG_BOOLEAN, 0.0, 0, NULL},
 
753
      "F", NULL, NULL, FALSE, 'I', ARG_BOOLEAN, 0.0, 0, NULL},      /* ARG_SHOWGIS */
 
754
    { "Penalty for a nucleotide mismatch (blastn only)", 
 
755
      "-3", NULL, NULL, FALSE, 'q', ARG_INT, 0.0, 0, NULL},         /* ARG_MISMATCH */
 
756
    { "Reward for a nucleotide match (blastn only)", 
 
757
      "1", NULL, NULL, FALSE, 'r', ARG_INT, 0.0, 0, NULL},          /* ARG_MATCH */
 
758
    { "Number of database sequences to show one-line descriptions for (V)", 
 
759
      "500", NULL, NULL, FALSE, 'v', ARG_INT, 0.0, 0, NULL},         /*  ARG_DESCRIPTIONS */
 
760
    { "Number of database sequence to show alignments for (B)", 
 
761
      "250", NULL, NULL, FALSE, 'b', ARG_INT, 0.0, 0, NULL},        /* ARG_ALIGNMENTS */
 
762
    { "Threshold for extending hits, default if zero\n" 
 
763
      "      blastp 11, blastn 0, blastx 12, tblastn 13\n"
 
764
      "      tblastx 13, megablast 0",
 
765
      "0", NULL, NULL, FALSE, 'f', ARG_INT, 0.0, 0, NULL},           /* ARG_THRESHOLD */
 
766
    { "Perform gapped alignment (not available with tblastx)", 
 
767
        "T", NULL, NULL, FALSE, 'g', ARG_BOOLEAN, 0.0, 0, NULL},     /* ARG_GAPPED */
579
768
    { "Query Genetic code to use", /* 17 */
580
 
      "1", NULL, NULL, FALSE, 'Q', ARG_INT, 0.0, 0, NULL},
 
769
      "1", NULL, NULL, FALSE, 'Q', ARG_INT, 0.0, 0, NULL},           /* ARG_QGENETIC_CODE */
581
770
    { "DB Genetic code (for tblast[nx] only)", /* 18 */
582
 
      "1", NULL, NULL, FALSE, 'D', ARG_INT, 0.0, 0, NULL},
 
771
      "1", NULL, NULL, FALSE, 'D', ARG_INT, 0.0, 0, NULL},           /* ARG_DBGENETIC_CODE */
583
772
    { "Number of processors to use", /* 19 */
584
 
      "1", NULL, NULL, FALSE, 'a', ARG_INT, 0.0, 0, NULL},
 
773
      "1", NULL, NULL, FALSE, 'a', ARG_INT, 0.0, 0, NULL},           /* ARG_THREADS */
585
774
    { "SeqAlign file",          /* 20 */
586
 
      NULL, NULL, NULL, TRUE, 'O', ARG_FILE_OUT, 0.0, 0, NULL},
 
775
      NULL, NULL, NULL, TRUE, 'O', ARG_FILE_OUT, 0.0, 0, NULL},      /* ARG_ASNOUT */
587
776
    { "Believe the query defline", /* 21 */
588
 
      "F", NULL, NULL, FALSE, 'J', ARG_BOOLEAN, 0.0, 0, NULL},
 
777
      "F", NULL, NULL, FALSE, 'J', ARG_BOOLEAN, 0.0, 0, NULL},        /* ARG_BELIEVEQUERY */
589
778
    { "Matrix",                 /* 22 */
590
 
      "BLOSUM62", NULL, NULL, FALSE, 'M', ARG_STRING, 0.0, 0, NULL},
591
 
    { "Word size, default if zero", /* 23 */
592
 
      "0", NULL, NULL, FALSE, 'W', ARG_INT, 0.0, 0, NULL},
593
 
    { "Effective length of the database (use zero for the real size)", /* 24 */
594
 
      "0", NULL, NULL, FALSE, 'z', ARG_STRING, 0.0, 0, NULL},
595
 
    { "Number of best hits from a region to keep (off by default, if used a value of 100 is recommended)", /* 25 */
596
 
      "0", NULL, NULL, FALSE, 'K', ARG_INT, 0.0, 0, NULL},
597
 
    { "0 for multiple hits 1-pass, 1 for single hit 1-pass, 2 for 2-pass", /* 26 */
598
 
      "0", NULL, NULL, FALSE, 'P', ARG_INT, 0.0, 0, NULL},
599
 
    { "Effective length of the search space (use zero for the real size)", /* 27 */
600
 
      "0", NULL, NULL, FALSE, 'Y', ARG_FLOAT, 0.0, 0, NULL},
601
 
    { "Query strands to search against database (for blast[nx], and tblastx).  3 is both, 1 is top, 2 is bottom", /* 28 */
602
 
      "3", NULL, NULL, FALSE, 'S', ARG_INT, 0.0, 0, NULL},
 
779
      "BLOSUM62", NULL, NULL, FALSE, 'M', ARG_STRING, 0.0, 0, NULL},  /* ARG_MATRIX */
 
780
    { "Word size, default if zero (blastn 11, megablast 28, "
 
781
        "all others 3)", /* 23 */
 
782
      "0", NULL, NULL, FALSE, 'W', ARG_INT, 0.0, 0, NULL},            /* ARG_WORDSIZE */
 
783
    { "Effective length of the database (use zero for the real size)", 
 
784
      "0", NULL, NULL, FALSE, 'z', ARG_FLOAT, 0.0, 0, NULL},          /* ARG_DBSIZE */
 
785
    { "Number of best hits from a region to keep (off by default, if used a value of 100 is recommended)", 
 
786
      "0", NULL, NULL, FALSE, 'K', ARG_INT, 0.0, 0, NULL},            /* ARG_BESTHITS */
 
787
    { "0 for multiple hit, 1 for single hit (does not apply to blastn)",
 
788
       "0",  NULL, NULL, FALSE, 'P', ARG_INT, 0.0, 0, NULL},           /* ARG_MULTIPLEHITS */
 
789
    { "Effective length of the search space (use zero for the real size)", 
 
790
      "0", NULL, NULL, FALSE, 'Y', ARG_FLOAT, 0.0, 0, NULL},           /* ARG_SEARCHSP */
 
791
    { "Query strands to search against database (for blast[nx], and tblastx)\n"
 
792
      "       3 is both, 1 is top, 2 is bottom", 
 
793
      "3", NULL, NULL, FALSE, 'S', ARG_INT, 0.0, 0, NULL},             /* ARG_STRAND */
603
794
    { "Produce HTML output",    /* 29 */
604
 
      "F", NULL, NULL, FALSE, 'T', ARG_BOOLEAN, 0.0, 0, NULL},
 
795
      "F", NULL, NULL, FALSE, 'T', ARG_BOOLEAN, 0.0, 0, NULL},         /* ARG_HTML */
605
796
#ifdef BLAST_CS_API
606
 
    { "Restrict search of database to results of Entrez2 lookup", /* 30 */
607
 
      NULL, NULL, NULL, TRUE, 'u', ARG_STRING, 0.0, 0, NULL},
 
797
    { "Restrict search of database to results of Entrez2 lookup", 
 
798
      NULL, NULL, NULL, TRUE, 'u', ARG_STRING, 0.0, 0, NULL},          /* ARG_ENTREZQ */
608
799
#else
609
 
    { "Restrict search of database to list of GI's",              /* 30 */
610
 
      NULL, NULL, NULL, TRUE, 'l', ARG_STRING, 0.0, 0, NULL},
 
800
    { "Restrict search of database to list of GI's",             
 
801
      NULL, NULL, NULL, TRUE, 'l', ARG_STRING, 0.0, 0, NULL},          /* ARG_GILIST */
611
802
#endif
612
 
    {"Use lower case filtering of FASTA sequence", /* 31 */
613
 
     "F", NULL,NULL,TRUE,'U',ARG_BOOLEAN, 0.0,0,NULL},
614
 
    { "Dropoff (X) for blast extensions in bits (0.0 invokes default behavior)", /* 32 */
615
 
      "0.0", NULL, NULL, FALSE, 'y', ARG_FLOAT, 0.0, 0, NULL},
616
 
    { "X dropoff value for final gapped alignment (in bits)", /* 33 */
617
 
      "0", NULL, NULL, FALSE, 'Z', ARG_INT, 0.0, 0, NULL},
 
803
    {"Use lower case filtering of FASTA sequence", 
 
804
     NULL, NULL, NULL, TRUE, 'U', ARG_BOOLEAN, 0.0, 0, NULL},          /* ARG_LCASE */
 
805
    { "X dropoff value for ungapped extensions in bits (0.0 invokes default "
 
806
      "behavior)\n      blastn 20, megablast 10, all others 7", 
 
807
      "0.0", NULL, NULL, FALSE, 'y', ARG_FLOAT, 0.0, 0, NULL},         /* ARG_XDROP_UNGAPPED */       
 
808
    { "X dropoff value for final gapped alignment in bits " 
 
809
      "(0.0 invokes default behavior)\n"
 
810
      "      blastn/megablast 50, tblastx 0, all others 25",
 
811
      "0", NULL, NULL, FALSE, 'Z', ARG_INT, 0.0, 0, NULL},             /* ARG_XDROP_FINAL */
618
812
#ifdef BLAST_CS_API
619
813
    { "RPS Blast search",            /* 34 */
620
 
      "F", NULL, NULL, FALSE, 'R', ARG_BOOLEAN, 0.0, 0, NULL},
 
814
      "F", NULL, NULL, FALSE, 'R', ARG_BOOLEAN, 0.0, 0, NULL},          /* ARG_RPSBLAST */
621
815
#else
622
816
    { "PSI-TBLASTN checkpoint file", /* 34 */
623
 
      NULL, NULL, NULL, TRUE, 'R', ARG_FILE_IN, 0.0, 0, NULL},
 
817
      NULL, NULL, NULL, TRUE, 'R', ARG_FILE_IN, 0.0, 0, NULL},         /* ARG_PSITCHKPNT */
624
818
#endif
625
819
    { "MegaBlast search",       /* 35 */
626
 
      "F", NULL, NULL, FALSE, 'n', ARG_BOOLEAN, 0.0, 0, NULL},
 
820
      "F", NULL, NULL, FALSE, 'n', ARG_BOOLEAN, 0.0, 0, NULL},         /* ARG_USEMEGABLAST */
627
821
    { "Location on query sequence",/* 36 */
628
 
      NULL, NULL, NULL, TRUE, 'L', ARG_STRING, 0.0, 0, NULL},
629
 
    { "Multiple Hits window size (zero for single hit algorithm)", /* 37 */
630
 
      "40", NULL, NULL, FALSE, 'A', ARG_INT, 0.0, 0, NULL},
631
 
#ifdef DO_NOT_SUPPRESS_BLAST_OP
632
 
    { "Frame shift penalty (OOF algorithm for blastx)", /* 38 */
633
 
      "0", NULL, NULL, FALSE, 'w', ARG_INT, 0.0, 0, NULL},
634
 
    { "Length of the largest intron allowed in tblastn for linking HSPs (0 disables linking)", /* 39 */
635
 
      "0", NULL, NULL, FALSE, 't', ARG_INT, 0.0, 0, NULL} 
 
822
      NULL, NULL, NULL, TRUE, 'L', ARG_STRING, 0.0, 0, NULL},          /* ARG_QUERYLOC */
 
823
    { "Multiple Hits window size, default if zero (blastn/megablast 0, "
 
824
        "all others 40", /* 37 */
 
825
      "0", NULL, NULL, FALSE, 'A', ARG_INT, 0.0, 0, NULL},             /* ARG_WINDOW */
 
826
    { "Frame shift penalty (OOF algorithm for blastx)", 
 
827
      "0", NULL, NULL, FALSE, 'w', ARG_INT, 0.0, 0, NULL},             /* ARG_FRAMESHIFT */
 
828
    { "Length of the largest intron allowed in a translated nucleotide "
 
829
      "sequence when "
 
830
      "linking multiple distinct alignments. (0 invokes default behavior; a "
 
831
      "negative value disables linking.)", 
 
832
      "0", NULL, NULL, FALSE, 't', ARG_INT, 0.0, 0, NULL},             /* ARG_INTRON */
 
833
/*--KM
 
834
   seems ok to add another param b/c NUMARG is defined based on 
 
835
    sizeof(myargs) itself
 
836
   made optional=TRUE but this may change?
 
837
*/
 
838
#ifndef BLAST_CS_API
 
839
    { "Number of concatenated queries, for blastn and tblastn", 
 
840
      "0", NULL, NULL, TRUE, 'B', ARG_INT, 0.0, 0, NULL}               /* ARG_NUMQUERIES */
636
841
#endif
637
842
};
638
843
 
639
844
#ifdef BLAST_CS_API
640
 
BlastNet3Hptr BNETInitializeBlast(CharPtr database, CharPtr program, 
 
845
static BlastNet3Hptr BNETInitializeBlast(CharPtr database, CharPtr program, 
641
846
                                  FILE *outfp, Boolean db_is_na,
642
 
                                  Boolean is_rps_blast, Boolean html)
 
847
                                  Boolean is_rps_blast, Boolean html, Boolean header)
643
848
{
644
849
    BlastNet3Hptr    bl3hp;
645
850
    BlastResponsePtr response = NULL;
646
851
    BlastVersionPtr     blast_version;
647
852
 
648
853
    if (! BlastInit("blastcl3", &bl3hp, &response)) {
649
 
        ErrPostEx(SEV_FATAL, 0, 0, "Unable to initialize BLAST service");
 
854
        ErrPostEx(SEV_FATAL, 1, 0, "Unable to initialize BLAST service");
650
855
        return NULL;
651
856
    }
652
857
    if (response && response->choice == BlastResponse_init) {
653
858
        blast_version = response->data.ptrvalue;
654
859
    } else {
655
 
        ErrPostEx(SEV_FATAL, 0, 0, "Unable to connect to the BLAST service");
 
860
        ErrPostEx(SEV_FATAL, 1, 0, "Unable to connect to the BLAST service");
656
861
        return NULL;
657
862
    }
658
863
    
659
864
    BlastNetBioseqFetchEnable(bl3hp, database, db_is_na, TRUE);
660
865
    
661
 
    if(is_rps_blast == TRUE)
 
866
    if(is_rps_blast == TRUE && header)
 
867
    {
662
868
        BlastPrintVersionInfoEx("RPS-BLAST", html, blast_version->version, 
663
869
                                blast_version->date, outfp);
664
 
    
665
 
    else {
 
870
    }
 
871
    else if (header) 
 
872
    {
666
873
        init_buff_ex(90);
667
874
        BlastPrintVersionInfoEx(program, html, blast_version->version, 
668
875
                                blast_version->date, outfp);
684
891
 
685
892
{
686
893
    AsnIoPtr aip, xml_aip;
687
 
    BioseqPtr fake_bsp = NULL, query_bsp;
 
894
    BioseqPtr fake_bsp = NULL, query_bsp, bsp;
688
895
    BioSourcePtr source;
689
896
    BLAST_MatrixPtr matrix;
690
897
    Int4Ptr PNTR txmatrix;
701
908
    TxDfDbInfoPtr dbinfo=NULL, dbinfo_head;
702
909
    Uint1 align_type, align_view, err_ticket;
703
910
    Uint4 align_options, print_options;
704
 
    ValNodePtr  mask_loc, mask_loc_start, vnp, other_returns, error_returns;
 
911
    ValNodePtr mask_loc, mask_loc_start = NULL, vnp, next_mask_loc = NULL;
 
912
    ValNodePtr other_returns, error_returns;
705
913
    CharPtr blast_program, blast_database, blast_inputfile, blast_outputfile;
706
914
    FILE *infp, *outfp;
 
915
    Char buf[256] = { '\0' } ;
707
916
    /* Mega BLAST related variables */
708
917
    SeqAlignPtr sap, next_seqalign, PNTR seqalignp;
709
918
    Int4 num_bsps, index;
713
922
    Boolean done = TRUE;
714
923
    int (LIBCALLBACK *handle_results)(VoidPtr srch);       
715
924
    Int4 from = 0, to = -1;
716
 
    const char *dummystr;
 
925
    Uint1 num_queries;          /*--KM for concatenated queries in blastn, tblastn */
 
926
    Uint1 num_iters;
 
927
    Uint1 sap_iter;
 
928
    SeqAlignPtr curr_seqalign;
 
929
    SeqAlignPtrArray sap_array;         /*--KM for separating seqaligns to test concat printing, temporary?*/
 
930
    SeqAnnotPtr curr_seqannot;
 
931
    SeqAnnotPtrArray seq_annot_arr;
 
932
    Uint1 bsp_iter;
 
933
    BspArray fake_bsp_arr;      /*--KM the array of fake_bsps for indiv. queries */ 
 
934
    SeqLocPtr PNTR lcase_mask_arr = NULL;       /* AM: information about lower case masked parts of queries */
 
935
    Boolean concat_done, nuc_concat;
 
936
    QueriesPtr mult_queries = NULL;     /*--KM, AM: stores information related to 
 
937
                                                    query multipolexing, to put in search */
 
938
    BioseqPtr curr_bsp;
 
939
 
 
940
    /* AM: Support for query multiplexing. */
 
941
    Uint4 num_spacers;
 
942
    ValNodePtr orig_mask_loc = NULL;
717
943
 
718
944
#ifdef BLAST_CS_API
719
945
    BlastNet3Hptr    bl3hp;
721
947
#endif
722
948
    
723
949
#ifdef BLAST_CS_API
724
 
    if (! GetArgs ("blastcl3", NUMARG, myargs)) {
 
950
    StringCpy(buf, "blastcl3 ");
 
951
    StringNCat(buf, BlastGetVersionNumber(), sizeof(buf)-StringLen(buf)-1);
 
952
    if (! GetArgs (buf, NUMARG, myargs)) {
725
953
        return (1);
726
954
    }
727
955
#else    
728
 
    if (! GetArgs ("blastall", NUMARG, myargs)) {
 
956
    StringCpy(buf, "blastall ");
 
957
    StringNCat(buf, BlastGetVersionNumber(), sizeof(buf)-StringLen(buf));
 
958
    if (! GetArgs (buf, NUMARG, myargs)) {
729
959
        return (1);
730
960
    }
731
961
#endif
737
967
    
738
968
    ErrSetMessageLevel(SEV_WARNING);
739
969
    
740
 
    blast_program = myargs [0].strvalue;
 
970
    blast_program = myargs[ARG_PROGRAM].strvalue;
741
971
 
742
972
#ifdef BLAST_CS_API
743
973
    /* For RPS Blast - anything not "blastp" - is "tblastn" */    
744
 
    if(myargs[34].intvalue) {
 
974
    if(myargs[ARG_RPSBLAST].intvalue) {
745
975
        if(StringICmp(blast_program, "blastp")) {
746
976
            StringCpy(blast_program, "blastx");
747
977
        }
748
978
    }
749
979
#endif
750
980
 
751
 
    blast_database = myargs [1].strvalue;
752
 
    blast_inputfile = myargs [2].strvalue;
753
 
    blast_outputfile = myargs [5].strvalue;
 
981
    blast_database = myargs[ARG_DB].strvalue;
 
982
    blast_inputfile = myargs[ARG_QUERY].strvalue;
 
983
    blast_outputfile = myargs[ARG_OUT].strvalue;
754
984
 
755
 
    if (myargs[29].intvalue)
 
985
    if (myargs[ARG_HTML].intvalue)
756
986
        html = TRUE;
757
987
    
758
988
    if ((infp = FileOpen(blast_inputfile, "r")) == NULL) {
759
 
        ErrPostEx(SEV_FATAL, 0, 0, "blast: Unable to open input file %s\n", blast_inputfile);
 
989
        ErrPostEx(SEV_FATAL, 1, 0, "blast: Unable to open input file %s\n", blast_inputfile);
760
990
        return (1);
761
991
    }
762
992
 
 
993
    align_view = (Int1) myargs[ARG_FORMAT].intvalue;
763
994
    outfp = NULL;
764
 
    if (blast_outputfile != NULL) {
 
995
    if (align_view != 7 && align_view != 10 && align_view != 11 && blast_outputfile != NULL) {
765
996
        if ((outfp = FileOpen(blast_outputfile, "w")) == NULL) {
766
 
            ErrPostEx(SEV_FATAL, 0, 0, "blast: Unable to open output file %s\n", blast_outputfile);
 
997
            ErrPostEx(SEV_FATAL, 1, 0, "blast: Unable to open output file %s\n", blast_outputfile);
767
998
            return (1);
768
999
        }
769
1000
    }
770
1001
    
771
1002
    if (StringCmp("filter", blast_program) == 0) {
772
 
        BlastGetMaskingLoc(infp, outfp, myargs[6].strvalue);
 
1003
        BlastGetMaskingLoc(infp, outfp, myargs[ARG_FILTER].strvalue);
773
1004
        FileClose(outfp);
774
1005
        FileClose(infp);        
775
1006
        return 0;
776
1007
    }
777
 
    align_view = (Int1) myargs[4].intvalue;
778
1008
    
779
1009
    align_type = BlastGetTypes(blast_program, &query_is_na, &db_is_na);
780
1010
 
781
1011
    if(align_view < 7) {
782
1012
        if (StringICmp("blastx", blast_program) == 0) {
783
1013
            if (align_view != 0) {
784
 
                ErrPostEx(SEV_FATAL, 0, 0, "This option is not available with blastx");
 
1014
                ErrPostEx(SEV_FATAL, 1, 0, "This option is not available with blastx");
785
1015
                return 1;
786
1016
            }
787
1017
        } else if (StringICmp("tblastx", blast_program) == 0) {
788
1018
            if (align_view != 0) {
789
 
                ErrPostEx(SEV_FATAL, 0, 0, "This option is not available with tblastx");
 
1019
                ErrPostEx(SEV_FATAL, 1, 0, "This option is not available with tblastx");
790
1020
                return 1;
791
1021
            }
792
1022
        }
793
1023
    }
794
1024
    
795
1025
    believe_query = FALSE;
796
 
    if (myargs[21].intvalue != 0)
 
1026
    if (myargs[ARG_BELIEVEQUERY].intvalue != 0)
797
1027
        believe_query = TRUE;
798
1028
    
799
 
    if (believe_query == FALSE && myargs[20].strvalue) {
800
 
        ErrPostEx(SEV_FATAL, 0, 0, "-J option must be TRUE to produce a SeqAlign file");
 
1029
    if (believe_query == FALSE && (myargs[ARG_ASNOUT].strvalue || align_view == 10 || align_view ==11)) {
 
1030
        ErrPostEx(SEV_FATAL, 1, 0, "-J option must be TRUE to produce a SeqAlign file");
801
1031
    }
802
1032
    
803
 
    options = BLASTOptionNew(blast_program, (Boolean) myargs [16].intvalue);
 
1033
    options = BLASTOptionNewEx(blast_program, (Boolean) myargs[ARG_GAPPED].intvalue, (Boolean) myargs[ARG_USEMEGABLAST].intvalue);
804
1034
    if (options == NULL)
805
1035
        return 3;
806
1036
 
807
1037
#ifdef BLAST_CS_API
808
 
    if(myargs[34].intvalue) 
 
1038
    if(myargs[ARG_RPSBLAST].intvalue) 
809
1039
        options->is_rps_blast = TRUE;
810
1040
#endif
811
 
    options->is_megablast_search = (Boolean) myargs[35].intvalue;
812
 
    
813
 
    if (options->is_megablast_search) {
814
 
       options->wordsize = 28;
815
 
       options->block_width = 0;
816
 
    }
817
1041
    
818
1042
    if (align_view == 8 && options->is_megablast_search) {
819
1043
       options->output = (VoidPtr) outfp;
821
1045
    } else 
822
1046
       handle_results = NULL;
823
1047
 
824
 
    BLASTOptionSetGapParams(options, myargs[22].strvalue, 0, 0); 
825
 
    options->expect_value  = (Nlm_FloatHi) myargs [3].floatvalue;
826
 
    number_of_descriptions = myargs[13].intvalue;       
827
 
    number_of_alignments = myargs[14].intvalue; 
 
1048
    BLASTOptionSetGapParams(options, myargs[ARG_MATRIX].strvalue, 0, 0); 
 
1049
    options->expect_value  = (Nlm_FloatHi) myargs[ARG_EVALUE].floatvalue;
 
1050
    number_of_descriptions = myargs[ARG_DESCRIPTIONS].intvalue; 
 
1051
    number_of_alignments = myargs[ARG_ALIGNMENTS].intvalue;     
828
1052
    options->hitlist_size = MAX(number_of_descriptions, number_of_alignments);
829
 
    if (myargs[7].intvalue != 0)
830
 
        options->gap_open = myargs[7].intvalue;
831
 
    if (myargs[8].intvalue != 0)
832
 
        options->gap_extend = myargs[8].intvalue;
833
 
    if (myargs[9].intvalue != 0)
834
 
        options->gap_x_dropoff = myargs[9].intvalue;
835
1053
 
836
 
        /* Multiple hits does not apply to blastn. */
837
 
    if (StringICmp("blastn", blast_program)) {
838
 
        if (myargs[26].intvalue == 0) {
839
 
            options->two_pass_method  = FALSE;
840
 
            options->multiple_hits_only  = TRUE;
841
 
        } else if (myargs[26].intvalue == 1) {
842
 
            options->two_pass_method  = FALSE;
843
 
            options->multiple_hits_only  = FALSE;
844
 
        } else {
845
 
            options->two_pass_method  = TRUE;
846
 
            options->multiple_hits_only  = FALSE;
847
 
        }
 
1054
    if (StringICmp("blastn", blast_program) == 0) {
 
1055
        options->penalty = myargs[ARG_MISMATCH].intvalue;
 
1056
        options->reward = myargs[ARG_MATCH].intvalue;
 
1057
        if (options->reward > 1) {
 
1058
           /* Scale the default values for gap costs; will be overridden
 
1059
              later, if command line values are non-zero */
 
1060
           options->gap_open *= options->reward;
 
1061
           options->gap_extend *= options->reward;
 
1062
        }
 
1063
    } else {
 
1064
        if (myargs[ARG_THRESHOLD].intvalue != 0) {
 
1065
            options->threshold_second = myargs[ARG_THRESHOLD].intvalue;
 
1066
        }
848
1067
    }
 
1068
    
 
1069
    if (myargs[ARG_GAPOPEN].intvalue != 0)
 
1070
        options->gap_open = myargs[ARG_GAPOPEN].intvalue;
 
1071
    if (myargs[ARG_GAPEXT].intvalue != 0)
 
1072
        options->gap_extend = myargs[ARG_GAPEXT].intvalue;
 
1073
    if (myargs[ARG_XDROP].intvalue != 0)
 
1074
        options->gap_x_dropoff = myargs[ARG_XDROP].intvalue;
 
1075
 
 
1076
    /* use one-hit if specified or it's a blastn search */
 
1077
    if ( (myargs[ARG_MULTIPLEHITS].intvalue == 1) || (StringICmp("blastn", blast_program) == 0 ) )
 
1078
      {
 
1079
        options->two_pass_method  = FALSE;
 
1080
        options->multiple_hits_only  = FALSE;
 
1081
      }
 
1082
    /* otherwise, use two-hit */
849
1083
    else
850
 
    { /* Reverse these for blastn for now. */
851
 
        if (myargs[26].intvalue == 1) {
852
 
            options->two_pass_method  = FALSE;
853
 
            options->multiple_hits_only  = TRUE;
854
 
        } else if (myargs[26].intvalue == 0) {
855
 
            options->two_pass_method  = FALSE;
856
 
            options->multiple_hits_only  = FALSE;
857
 
        }
858
 
    }
859
 
 
860
 
    if(myargs[33].intvalue != 0) 
861
 
        options->gap_x_dropoff_final = myargs[33].intvalue;
862
 
 
863
 
    if (StringICmp(myargs[6].strvalue, "T") == 0) {
 
1084
      { 
 
1085
        /* all other inputs, including the default 0 use 2-hit method */
 
1086
        options->two_pass_method  = FALSE;
 
1087
        options->multiple_hits_only  = TRUE;
 
1088
      }
 
1089
    
 
1090
    if(myargs[ARG_XDROP_FINAL].intvalue != 0) 
 
1091
        options->gap_x_dropoff_final = myargs[ARG_XDROP_FINAL].intvalue;
 
1092
 
 
1093
    if (StringICmp(myargs[ARG_FILTER].strvalue, "T") == 0) {
864
1094
        if (StringICmp("blastn", blast_program) == 0)
865
1095
            options->filter_string = StringSave("D");
866
1096
        else
867
1097
            options->filter_string = StringSave("S");
868
1098
    } else {
869
 
        options->filter_string = StringSave(myargs[6].strvalue);
870
 
    }
871
 
    
872
 
    show_gi = (Boolean) myargs[10].intvalue;
873
 
    if (StringICmp("blastn", blast_program) == 0) {
874
 
        options->penalty = myargs[11].intvalue;
875
 
        options->reward = myargs[12].intvalue;
876
 
    } else {
877
 
        if (myargs[15].intvalue != 0) {
878
 
            options->threshold_second = myargs[15].intvalue;
879
 
        }
880
 
    }
881
 
    
882
 
    options->genetic_code = myargs[17].intvalue;
883
 
    options->db_genetic_code = myargs[18].intvalue;
884
 
    options->number_of_cpus = myargs[19].intvalue;
885
 
    if (myargs[23].intvalue != 0) {
886
 
        options->wordsize = myargs[23].intvalue;
 
1099
        options->filter_string = StringSave(myargs[ARG_FILTER].strvalue);
 
1100
    }
 
1101
    
 
1102
    show_gi = (Boolean) myargs[ARG_SHOWGIS].intvalue;
 
1103
 
 
1104
    options->genetic_code = myargs[ARG_QGENETIC_CODE].intvalue;
 
1105
    options->db_genetic_code = myargs[ARG_DBGENETIC_CODE].intvalue;
 
1106
    options->number_of_cpus = myargs[ARG_THREADS].intvalue;
 
1107
    if (myargs[ARG_WORDSIZE].intvalue != 0) {
 
1108
        options->wordsize = myargs[ARG_WORDSIZE].intvalue;
887
1109
    }
888
1110
    
889
1111
    if (options->is_megablast_search) {
890
 
       options->cutoff_s2 = options->wordsize;
891
 
       options->wordsize += 4;
892
 
       options->cutoff_s = options->wordsize;
 
1112
       options->cutoff_s2 = options->wordsize*options->reward;
893
1113
    }
894
1114
 
895
 
    options->db_length = StringToInt8(myargs[24].strvalue, &dummystr);
 
1115
    options->db_length = (Int8) myargs[ARG_DBSIZE].floatvalue;
896
1116
    
897
 
    options->hsp_range_max  = myargs[25].intvalue;
 
1117
    options->hsp_range_max  = myargs[ARG_BESTHITS].intvalue;
898
1118
    if (options->hsp_range_max != 0)
899
1119
        options->perform_culling = TRUE;
900
 
    if (myargs[27].floatvalue)
901
 
        options->searchsp_eff = (Nlm_FloatHi) myargs[27].floatvalue;
 
1120
    if (myargs[ARG_SEARCHSP].floatvalue)
 
1121
        options->searchsp_eff = (Nlm_FloatHi) myargs[ARG_SEARCHSP].floatvalue;
902
1122
    
903
 
    options->strand_option = myargs[28].intvalue;
 
1123
    options->strand_option = myargs[ARG_STRAND].intvalue;
904
1124
 
905
 
    if(myargs [32].floatvalue != 0.0) {
906
 
        options->dropoff_2nd_pass  = myargs [32].floatvalue;
 
1125
    if(myargs[ARG_XDROP_UNGAPPED].floatvalue != 0.0) {
 
1126
        options->dropoff_2nd_pass  = myargs[ARG_XDROP_UNGAPPED].floatvalue;
907
1127
        if(options->dropoff_1st_pass > options->dropoff_2nd_pass)
908
1128
            options->dropoff_1st_pass = options->dropoff_2nd_pass;
909
1129
    }
910
1130
 
911
 
    options->window_size = myargs [37].intvalue;
 
1131
    if (myargs[ARG_WINDOW].intvalue != 0)
 
1132
        options->window_size = myargs[ARG_WINDOW].intvalue;
912
1133
 
913
1134
    print_options = 0;
914
1135
    align_options = 0;
921
1142
        align_options += TXALIGN_SHOW_GI;
922
1143
        print_options += TXALIGN_SHOW_GI;
923
1144
    }
924
 
    if (myargs[16].intvalue == 0)
 
1145
    if (myargs[ARG_GAPPED].intvalue == 0)
925
1146
        print_options += TXALIGN_SHOW_NO_OF_SEGS;
926
1147
    
927
1148
    if (align_view) {
943
1164
    }
944
1165
 
945
1166
#ifdef BLAST_CS_API
946
 
    if(myargs[30].strvalue)
947
 
        options->entrez_query = StringSave(myargs[30].strvalue);
 
1167
    if(myargs[ARG_ENTREZQ].strvalue)
 
1168
        options->entrez_query = StringSave(myargs[ARG_ENTREZQ].strvalue);
948
1169
#else    
949
 
    if (myargs[30].strvalue) {
950
 
        options->gifile = StringSave(myargs[30].strvalue);
 
1170
    if (myargs[ARG_GILIST].strvalue) {
 
1171
        options->gifile = StringSave(myargs[ARG_GILIST].strvalue);
951
1172
    }
952
1173
#endif
953
1174
    
956
1177
       psitblastnsearches
957
1178
    */
958
1179
 
959
 
#ifdef DO_NOT_SUPPRESS_BLAST_OP
960
 
    if(myargs[38].intvalue > 0) {
 
1180
    if(myargs[ARG_FRAMESHIFT].intvalue > 0) {
961
1181
        if (!StringICmp("blastx", blast_program) || 
962
1182
            !StringICmp("tblastn", blast_program)||
963
1183
            !StringICmp("psitblastn", blast_program)) {
964
1184
           if (!StringICmp("blastx", blast_program)) {
965
1185
              options->is_ooframe = TRUE;
966
 
              options->shift_pen = myargs[38].intvalue;
 
1186
              options->shift_pen = myargs[ARG_FRAMESHIFT].intvalue;
967
1187
           }
968
1188
        }
969
1189
    }
970
 
#endif
971
1190
        
972
 
#ifdef DO_NOT_SUPPRESS_BLAST_OP
973
1191
    /* Input longest intron length is in nucleotide scale; in the lower level
974
1192
       code it will be used in protein scale */
975
 
    if (myargs[39].intvalue > 0) 
976
 
       options->longest_intron = MAX(myargs[39].intvalue, MAX_INTRON_LENGTH);
977
 
#endif
 
1193
    options->longest_intron =
 
1194
      MIN(myargs[ARG_INTRON].intvalue, MAX_INTRON_LENGTH);
978
1195
 
979
1196
    aip = NULL;
980
 
    if (myargs[20].strvalue != NULL) {
981
 
        if ((aip = AsnIoOpen (myargs[20].strvalue,"w")) == NULL) {
982
 
                ErrPostEx(SEV_FATAL, 0, 0, "blast: Unable to open output file %s\n", myargs[20].strvalue);
 
1197
    if (myargs[ARG_ASNOUT].strvalue != NULL) {
 
1198
        if ((aip = AsnIoOpen (myargs[ARG_ASNOUT].strvalue,"w")) == NULL) {
 
1199
                ErrPostEx(SEV_FATAL, 1, 0, "blast: Unable to open output file %s\n", myargs[ARG_ASNOUT].strvalue);
 
1200
                return 1;
 
1201
        }
 
1202
    }
 
1203
    else if (align_view == 10 || align_view == 11) 
 
1204
    {
 
1205
        const char* mode = (align_view == 10) ? "w" : "wb";
 
1206
        if ((aip = AsnIoOpen (blast_outputfile, (char*) mode)) == NULL) {
 
1207
                ErrPostEx(SEV_FATAL, 1, 0, "blast: Unable to open output file %s\n", myargs[ARG_ASNOUT].strvalue);
983
1208
                return 1;
984
1209
        }
985
1210
    }
991
1216
                  "VLINK=\"#660099\" ALINK=\"#660099\">\n");
992
1217
          fprintf(outfp, "<PRE>\n");
993
1218
       }
994
 
    } else if (align_view == 7)     
995
 
       xml_aip = AsnIoOpen(blast_outputfile, "wx");
 
1219
    } else if (align_view == 7 ) {
 
1220
        xml_aip = AsnIoOpen(blast_outputfile, "wx");
 
1221
    }
 
1222
 
 
1223
#ifndef BLAST_CS_API
 
1224
    if(align_view >= 7 && myargs[ARG_NUMQUERIES].intvalue > 1)
 
1225
    {
 
1226
      ErrPostEx(SEV_FATAL, 1, 0, 
 
1227
                 "blast: Query concatenation is currently not supported with -m > 7");
 
1228
      return 1;
 
1229
    }
 
1230
#endif
996
1231
 
997
1232
 
998
1233
                  /* Futamura: Setting up the psitblastn options */
999
1234
#ifndef BLAST_CS_API
1000
 
    if (NULL != myargs[34].strvalue) {
 
1235
    if (NULL != myargs[ARG_PSITCHKPNT].strvalue) {
1001
1236
          options->recoverCheckpoint = TRUE;
1002
1237
          options->freqCheckpoint = TRUE;
1003
1238
    }
1004
 
    options->CheckpointFileName=myargs[34].strvalue;
 
1239
    options->CheckpointFileName=myargs[ARG_PSITCHKPNT].strvalue;
1005
1240
#endif
1006
1241
 
1007
1242
#ifdef BLAST_CS_API
1008
 
    bl3hp = BNETInitializeBlast(blast_database, blast_program, outfp, 
1009
 
                                db_is_na, options->is_rps_blast, html);
1010
 
#else
1011
 
    ReadDBBioseqFetchEnable ("blastall", blast_database, db_is_na, TRUE);
1012
 
#endif
 
1243
    if (align_view < 7)
 
1244
        bl3hp = BNETInitializeBlast(blast_database, blast_program, outfp, 
 
1245
                                db_is_na, options->is_rps_blast, html, TRUE);
 
1246
    else
 
1247
        bl3hp = BNETInitializeBlast(blast_database, blast_program, outfp, 
 
1248
                                db_is_na, options->is_rps_blast, html, FALSE);
 
1249
#endif
 
1250
 
 
1251
    /*--KM get number of queries for concatenated blastn/tblastn queries */
 
1252
 
 
1253
#ifndef BLAST_CS_API
 
1254
    options->NumQueries=myargs[ARG_NUMQUERIES].intvalue;  
 
1255
#endif
 
1256
 
 
1257
    num_queries = options->NumQueries;
 
1258
    if (num_queries>0 && 
 
1259
        !( (StringICmp("blastn",  blast_program) == 0) || 
 
1260
           (StringICmp("tblastn", blast_program) == 0)   ) ) {
 
1261
 
 
1262
        ErrPostEx(SEV_FATAL, 1, 0, "blast: Can't concat with program %s\n", myargs[ARG_PROGRAM].strvalue);
 
1263
       return 1;
 
1264
    }
1013
1265
    
 
1266
    /* AM: Query concatenation is not consistent with ungapped search */
 
1267
    if( num_queries > 0 && !myargs[ARG_GAPPED].intvalue )
 
1268
    {
 
1269
      ErrPostEx(SEV_FATAL, 1, 0, 
 
1270
                 "blast: Query concatenation is inconsistent with ungapped search\n" );
 
1271
      return 1;
 
1272
    }
 
1273
    if( !myargs[ARG_GAPPED].intvalue &&
 
1274
        0 == StringCmp("psitblastn", blast_program ) ) {
 
1275
      ErrPostEx(SEV_FATAL, 1, 0,"blast: Ungapped alignment is not appropriate "
 
1276
                "for PSI-tBLASTn.\n" );
 
1277
    }
 
1278
 
 
1279
    /* --KM set bool value if DNA and concat needed, need for Fasta->seq functions */
 
1280
    if (num_queries>0 && query_is_na == TRUE) {
 
1281
        nuc_concat = TRUE;
 
1282
    } else {
 
1283
        nuc_concat = FALSE;
 
1284
    }
 
1285
 
1014
1286
    /* --- Main loop over all FASTA entries in the input file ---- */
1015
1287
 
1016
 
    if (myargs[36].strvalue) {       
 
1288
    concat_done = FALSE;        /*--KM */
 
1289
 
 
1290
    if (myargs[ARG_QUERYLOC].strvalue) {       
1017
1291
        CharPtr delimiters = " ,;";
1018
1292
        CharPtr location;
1019
 
        location = myargs[36].strvalue;
 
1293
        location = myargs[ARG_QUERYLOC].strvalue;
1020
1294
        from = atoi(StringTokMT(location, delimiters, &location)) - 1;
1021
1295
        to = atoi(location) - 1;
1022
1296
        from = MAX(from, 0);
1033
1307
          while ((sep=FastaToSeqEntryForDb(infp, query_is_na, NULL,
1034
1308
                                           believe_query, prefix, &ctr, 
1035
1309
                                           &mask_slp)) != NULL) {
1036
 
             
1037
 
             if (mask_slp) {
1038
 
                if (!last_mask)
1039
 
                   options->query_lcase_mask = last_mask = mask_slp;
1040
 
                else {
1041
 
                   last_mask->next = mask_slp;
1042
 
                   last_mask = last_mask->next;
1043
 
                }
1044
 
                mask_slp = NULL;
1045
 
             }
 
1310
             if ((Boolean)myargs[ARG_LCASE].intvalue) {
 
1311
                if (mask_slp) {
 
1312
                   if (!last_mask)
 
1313
                      options->query_lcase_mask = last_mask = mask_slp;
 
1314
                   else {
 
1315
                      last_mask->next = mask_slp;
 
1316
                      last_mask = last_mask->next;
 
1317
                   }
 
1318
                   mask_slp = NULL;
 
1319
                }
 
1320
             } else {
 
1321
                mask_slp = SeqLocSetFree(mask_slp);
 
1322
             }
1046
1323
             query_bsp = NULL;
1047
1324
             if (query_is_na) 
1048
1325
                SeqEntryExplore(sep, &query_bsp, FindNuc);
1050
1327
                SeqEntryExplore(sep, &query_bsp, FindProt);
1051
1328
             
1052
1329
             if (query_bsp == NULL) {
1053
 
                ErrPostEx(SEV_FATAL, 0, 0, "Unable to obtain bioseq\n");
 
1330
                ErrPostEx(SEV_FATAL, 1, 0, "Unable to obtain bioseq\n");
1054
1331
                return 2;
1055
1332
             }
1056
1333
             
1062
1339
                 if (to < 0)
1063
1340
                     to = query_bsp->length - 1;
1064
1341
                 if (from >= query_bsp->length || to < 0) {
1065
 
                     ErrPostEx(SEV_FATAL, 0, 0, 
 
1342
                     ErrPostEx(SEV_FATAL, 1, 0, 
1066
1343
                               "Location outside of the query sequence range\n");
1067
1344
                     return 3;
1068
1345
                 }
1083
1360
          if (num_bsps == 0) 
1084
1361
             break;
1085
1362
       } else {
1086
 
          if(myargs[31].intvalue) {
1087
 
             sep = FastaToSeqEntryForDb (infp, query_is_na, NULL, believe_query, NULL, NULL, &options->query_lcase_mask);
 
1363
          /* not megablast */
 
1364
 
 
1365
          /*--KM make array of fake_bsp's if concat. query */
 
1366
          if (concat_done)
 
1367
             break;
 
1368
          if (num_queries > 0)  {
 
1369
             fake_bsp_arr = (BspArray) MemNew(sizeof(BioseqPtr)*num_queries); 
 
1370
 
 
1371
             if( myargs[ARG_LCASE].intvalue )
 
1372
               lcase_mask_arr = (SeqLocPtr PNTR)MemNew( sizeof( SeqLocPtr )*num_queries );
 
1373
          }
 
1374
          num_iters = (num_queries>0) ? num_queries : 1; 
 
1375
          for (bsp_iter=0; bsp_iter<num_iters; bsp_iter++) {
 
1376
 
 
1377
             if(myargs[ARG_LCASE].intvalue) {
 
1378
                /* AM: query multiplexing */
 
1379
                if( !num_queries )
 
1380
                  sep = FastaToSeqEntryForDb (infp, query_is_na, NULL, believe_query, NULL, NULL, &options->query_lcase_mask);
 
1381
                else
 
1382
                  sep = FastaToSeqEntryInternalEx( infp, FASTA_FILE_IO, NULL, query_is_na, NULL, believe_query,
 
1383
                                                   NULL, NULL, NULL, lcase_mask_arr + bsp_iter );
 
1384
                
 
1385
             } else {
 
1386
                sep = FastaToSeqEntryEx(infp, query_is_na, NULL, believe_query);
 
1387
             }
 
1388
          
 
1389
             /* if concat and num_queries has not been reached and sep is NULL, crap out */
 
1390
             if (sep == NULL && bsp_iter < num_queries) {   /* implies num_queries>0 */
 
1391
                ErrPostEx(SEV_FATAL, 1, 0, "blast: Only %d queries found!\n", bsp_iter); 
 
1392
                return (1);
 
1393
             }
 
1394
               
 
1395
             if(sep == NULL)
 
1396
                break;  /* no more queries, can go to finish with next break */
 
1397
          
 
1398
             query_bsp = NULL;
 
1399
             if (query_is_na) {
 
1400
                SeqEntryExplore(sep, &query_bsp, FindNuc);
 
1401
             } else {
 
1402
                SeqEntryExplore(sep, &query_bsp, FindProt);
 
1403
             }
 
1404
          
 
1405
             if (query_bsp == NULL) {
 
1406
                ErrPostEx(SEV_FATAL, 1, 0, "Unable to obtain bioseq\n");
 
1407
                return 2;
 
1408
             }
 
1409
 
 
1410
             if (num_queries>0) {
 
1411
                *(fake_bsp_arr + bsp_iter) = query_bsp;
 
1412
             }
 
1413
          }
 
1414
          if ( (sep == NULL && num_queries ==0) || (num_queries>0 && concat_done) )
 
1415
             break;  /* go to finish */
 
1416
 
 
1417
          /* --KM */
 
1418
          
 
1419
          if (num_queries>0) {
 
1420
             concat_done = TRUE;   /* --KM to prevent futher looping */
 
1421
 
 
1422
             /* AM: Determine the number of query separators. */
 
1423
             num_spacers = GetNumSpacers( options, believe_query, fake_bsp_arr ); 
 
1424
 
 
1425
             if( num_spacers%2 ) ++num_spacers;
 
1426
 
 
1427
             /* --KM make the concatenated fake_bsp */
 
1428
             /* AM: Added num_spacers. */
 
1429
             if( query_is_na )
 
1430
               fake_bsp = (BioseqPtr) 
 
1431
                          BlastMakeFakeBspConcat(fake_bsp_arr, num_queries, query_is_na, num_spacers); 
 
1432
             else
 
1433
               fake_bsp = (BioseqPtr) 
 
1434
                          BlastMakeFakeBspConcat(fake_bsp_arr, num_queries, query_is_na, num_spacers); 
1088
1435
             
1089
 
          } else {
1090
 
             sep = FastaToSeqEntryEx(infp, query_is_na, NULL, believe_query);
1091
 
          }
1092
 
          
1093
 
          if(sep == NULL)
1094
 
             break;
1095
 
          
1096
 
          query_bsp = NULL;
1097
 
          if (query_is_na) {
1098
 
             SeqEntryExplore(sep, &query_bsp, FindNuc);
1099
 
          } else {
1100
 
             SeqEntryExplore(sep, &query_bsp, FindProt);
1101
 
          }
1102
 
          
1103
 
          if (query_bsp == NULL) {
1104
 
             ErrPostEx(SEV_FATAL, 0, 0, "Unable to obtain bioseq\n");
1105
 
             return 2;
1106
 
          }
1107
 
        
1108
 
          if(believe_query)
1109
 
             fake_bsp = query_bsp;
1110
 
          else 
1111
 
             fake_bsp = BlastMakeFakeBioseq(query_bsp, NULL);
 
1436
             /* construct the MultQueries struct here*/
 
1437
             mult_queries = (QueriesPtr) BlastMakeMultQueries(fake_bsp_arr, num_queries, query_is_na, num_spacers,
 
1438
                                                              lcase_mask_arr);
 
1439
          } else {
 
1440
             if(believe_query)
 
1441
                fake_bsp = query_bsp;
 
1442
             else 
 
1443
                fake_bsp = BlastMakeFakeBioseq(query_bsp, NULL);
 
1444
          }
1112
1445
 
1113
1446
          err_ticket = BlastSetUserErrorString(NULL, query_bsp->id, believe_query);
1114
1447
        
1115
1448
          /* If fake_bsp created mask should be updated to use it's id */
1116
 
          BLASTUpdateSeqIdInSeqInt(options->query_lcase_mask, fake_bsp->id);
 
1449
          /* AM: query multiplexing */
 
1450
          if( !mult_queries )
 
1451
            BLASTUpdateSeqIdInSeqInt(options->query_lcase_mask, fake_bsp->id);
 
1452
          else for( bsp_iter = 0; bsp_iter < num_iters; ++bsp_iter )
 
1453
                 if( mult_queries->LCaseMasks )
 
1454
                   BLASTUpdateSeqIdInSeqInt( mult_queries->LCaseMasks[bsp_iter],
 
1455
                                             mult_queries->FakeBsps[bsp_iter]->id );
1117
1456
        
1118
1457
          source = BioSourceNew();
1119
1458
          source->org = OrgRefNew();
1120
1459
          source->org->orgname = OrgNameNew();
1121
1460
          source->org->orgname->gcode = options->genetic_code;
1122
1461
          ValNodeAddPointer(&(query_bsp->descr), Seq_descr_source, source);
 
1462
 
 
1463
       /* free sep later when done. --KM remember to free all if array*/
1123
1464
       }
1124
1465
 
1125
1466
       global_fp = outfp;
1134
1475
#else
1135
1476
           fprintf(outfp, "\n");
1136
1477
#endif            
1137
 
           if (!options->is_megablast_search)
1138
 
              AcknowledgeBlastQuery(query_bsp, 70, outfp, believe_query, html);
 
1478
           if (!options->is_megablast_search) {
 
1479
              /* KM added loop here for concat case */
 
1480
              num_iters = (num_queries>0) ? num_queries : 1;
 
1481
              for (bsp_iter=0; bsp_iter<num_iters; bsp_iter++) {
 
1482
                 curr_bsp = (num_queries>0) ? *(fake_bsp_arr + bsp_iter) : query_bsp; 
 
1483
                 AcknowledgeBlastQuery(curr_bsp, 70, outfp, believe_query, html);
 
1484
              }
 
1485
           }
1139
1486
 
1140
1487
            /* Here we first check, that database do no exists */
1141
1488
 
1161
1508
            }}
1162
1509
#endif    /* BLAST_CS_API */        
1163
1510
            free_buff();
 
1511
                if (options->is_ooframe)
 
1512
                        ErrPostEx(SEV_WARNING, 0, 0, "Out-of-frame option selected, Expect values are only approximate and calculated not assuming out-of-frame alignments");
1164
1513
        }
1165
1514
#ifdef OS_UNIX
1166
 
        if(align_view < 7) {
 
1515
        if(align_view < 7) { /*--KM why not fold into previous if statement? */
1167
1516
#ifdef BLAST_CS_API
1168
1517
            fprintf(global_fp, "%s", "Searching... please wait.. ");
1169
1518
#else
1189
1538
                                   NULL, NULL, 0, handle_results);
1190
1539
           seqalign = NULL;
1191
1540
           for (index=0; index<num_bsps; index++) { 
1192
 
              if (seqalignp[index]) {
 
1541
              if (seqalignp && seqalignp[index]) {
1193
1542
                 if (seqalign == NULL) 
1194
1543
                    sap = seqalign = seqalignp[index];
1195
1544
                 else
1200
1549
           }
1201
1550
           seqalignp = MemFree(seqalignp);
1202
1551
#endif
1203
 
        } else if (!myargs[36].strvalue) {       
 
1552
        } else if (!myargs[ARG_QUERYLOC].strvalue) {       
1204
1553
#ifdef BLAST_CS_API
1205
1554
           seqalign = BlastBioseqNetCore(bl3hp, fake_bsp, blast_program, 
1206
1555
                                      blast_database, options,
1208
1557
                                      align_view < 7 ? tick_callback : NULL,
1209
1558
                                      NULL, &status);
1210
1559
#else
1211
 
           seqalign = BioseqBlastEngineWithCallback(fake_bsp, blast_program, blast_database, options, &other_returns, &error_returns, align_view < 7 ? tick_callback : NULL, handle_results);
 
1560
           /* KM added mult_queries param */
 
1561
           seqalign = BioseqBlastEngineWithCallbackMult(fake_bsp, blast_program, blast_database, options, &other_returns, &error_returns, align_view < 7 ? tick_callback : NULL, handle_results, mult_queries);
1212
1562
#endif
1213
1563
        } else { /* Location on query provided */
1214
1564
           to = MIN(to, fake_bsp->length - 1);
1217
1567
           if (to < 0)
1218
1568
              to = fake_bsp->length - 1;
1219
1569
           if (from >= fake_bsp->length || to < 0) {
1220
 
              ErrPostEx(SEV_FATAL, 0, 0, 
 
1570
              ErrPostEx(SEV_FATAL, 1, 0, 
1221
1571
                        "Location outside of the query sequence range\n");
1222
1572
              return 3;
1223
1573
           }
1230
1580
                                         align_view < 7 ? tick_callback : NULL,
1231
1581
                                         NULL, &status);
1232
1582
#else
1233
 
           seqalign = BioseqBlastEngineByLocWithCallback(slp, blast_program, blast_database, options, &other_returns, &error_returns, align_view < 7 ? tick_callback : NULL, NULL, NULL, 0, handle_results);
 
1583
           seqalign = BioseqBlastEngineByLocWithCallbackMult(slp, blast_program, blast_database, options, &other_returns, &error_returns, align_view < 7 ? tick_callback : NULL, NULL, NULL, 0, handle_results, mult_queries);
1234
1584
#endif
1235
1585
           
1236
1586
        }
1280
1630
                break;
1281
1631
            }
1282
1632
        }       
1283
 
        
1284
 
        
 
1633
 
1285
1634
#ifdef OS_UNIX
1286
1635
        fflush(global_fp);
1287
1636
#endif
1292
1641
        }
1293
1642
#endif
1294
1643
        
 
1644
#ifndef BLAST_CS_API
 
1645
    ReadDBBioseqFetchEnable ("blastall", blast_database, db_is_na, TRUE);
 
1646
#endif
1295
1647
        ReadDBBioseqSetDbGeneticCode(options->db_genetic_code);
1296
1648
 
1297
1649
        tmp_slp = slp;
1302
1654
           BlastClusterHitsFromSeqAlign(seqalign, blast_program, blast_database, 
1303
1655
                                        options, 0.9, 1.6, 0.5, TRUE);
1304
1656
 
 
1657
        if (mask_loc) {
 
1658
           mask_loc_start = mask_loc;
 
1659
        }
 
1660
        else
 
1661
        {       /* Could have become non-NUll for last query. */
 
1662
           mask_loc_start = NULL;
 
1663
        }
 
1664
        /* Print header in any case */
 
1665
        if (align_view == 9) {
 
1666
           PrintTabularOutputHeader(blast_database, query_bsp, slp, 
 
1667
              blast_program, 0, believe_query, global_fp);
 
1668
        }
 
1669
 
1305
1670
        if (seqalign) {
1306
 
           if (align_view == 8 || align_view == 9) {
1307
 
              if (align_view == 9)
1308
 
                PrintTabularOutputHeader(blast_database, query_bsp, slp, 
1309
 
                                       blast_program, 0, believe_query,
1310
 
                                       global_fp);
 
1671
           if (num_queries > 0) { /* AM: Support for query multiplexing. */
 
1672
              sap_array = mult_queries->sap_array_data->sap_array;
 
1673
           }   
 
1674
        
 
1675
           if (align_view == 8 || align_view == 9) {
 
1676
/* --KM need to put a loop around this. seqaligns already broken up
 
1677
   note the method for looping if num_aligns > 0 - reuse this method everywhere */
 
1678
              num_iters = (num_queries>0) ? num_queries : 1;
 
1679
              for (sap_iter=0; sap_iter < num_iters; sap_iter++) {
 
1680
                 curr_seqalign = (num_queries>0) ? *(sap_array + sap_iter) : seqalign;
 
1681
                 BlastPrintTabularResults(curr_seqalign, query_bsp, slp, 
 
1682
               number_of_alignments, blast_program, 
 
1683
               !options->gapped_calculation, options->is_ooframe,
 
1684
               believe_query, 0, 0, global_fp, NULL, (align_view == 9));
1311
1685
 
1312
 
              BlastPrintTabulatedResults(seqalign, query_bsp, slp, 
1313
 
                                         number_of_alignments,
1314
 
                                         blast_program, 
1315
 
                                         !options->gapped_calculation,
1316
 
                                         believe_query, from, 0, global_fp);
1317
 
              SeqAlignSetFree(seqalign);
 
1686
                 SeqAlignSetFree(curr_seqalign);
 
1687
              }
1318
1688
           } else {
1319
1689
           while (seqalign) {
1320
 
              if (!options->is_megablast_search)
 
1690
                        
 
1691
              if (!options->is_megablast_search){
1321
1692
                 next_seqalign = NULL;
1322
 
              else {
1323
 
                 DenseSegPtr dsp, next_dsp;
1324
 
                 BioseqPtr bsp;
 
1693
              } else {
 
1694
                 SeqIdPtr sip, next_sip = NULL;
1325
1695
                 
1326
1696
                 sap = seqalign;
 
1697
                 sip = TxGetQueryIdFromSeqAlign(seqalign);
1327
1698
                 while (sap != NULL) { 
1328
1699
                    if (sap->next != NULL) {
1329
 
                       dsp = (DenseSegPtr) (sap->segs);
1330
 
                       next_dsp = (DenseSegPtr) (sap->next->segs);
1331
 
                       
1332
 
                       if (SeqIdComp(dsp->ids, next_dsp->ids) != SIC_YES) {
 
1700
                       next_sip = TxGetQueryIdFromSeqAlign(sap->next);
 
1701
 
 
1702
                       if (SeqIdComp(sip, next_sip) != SIC_YES) {
1333
1703
                          next_seqalign = sap->next;
1334
1704
                          sap->next = NULL;
1335
1705
                       }
1338
1708
                    sap = sap->next;
1339
1709
                 }
1340
1710
                 
1341
 
                 dsp = (DenseSegPtr) (seqalign->segs);
1342
 
                 while (tmp_slp && SeqIdComp(dsp->ids, SeqLocId(tmp_slp)) != SIC_YES)
 
1711
                 while (tmp_slp && SeqIdComp(sip, SeqLocId(tmp_slp)) != SIC_YES)
1343
1712
                    tmp_slp = tmp_slp->next;
1344
1713
                 if (tmp_slp == NULL) /* Should never happen */
1345
1714
                    break;
1346
 
                 bsp = BioseqLockById(SeqLocId(tmp_slp));
1347
 
                 init_buff_ex(85);
1348
 
                 fprintf(outfp, "\n");
1349
 
                 AcknowledgeBlastQuery(bsp, 70, outfp, believe_query, html);
1350
 
                 free_buff();
1351
 
                 BioseqUnlock(bsp);
 
1715
                 /* Separate the mask locations list for this query */
 
1716
                 if (!mask_loc && next_mask_loc) {
 
1717
                    mask_loc = next_mask_loc;
 
1718
                    next_mask_loc = NULL;
 
1719
                 }
 
1720
                 if (mask_loc) {
 
1721
                    if (next_mask_loc) {
 
1722
                       mask_loc->next = next_mask_loc;
 
1723
                       mask_loc = next_mask_loc;
 
1724
                    }
 
1725
                    mask_slp = (SeqLocPtr) mask_loc->data.ptrvalue;
 
1726
                    next_mask_loc = mask_loc;
 
1727
                    while (SeqIdComp(SeqLocId(mask_slp), sip) != SIC_YES) {
 
1728
                       mask_loc = mask_loc->next;
 
1729
                       if (!mask_loc)
 
1730
                          break;
 
1731
                       mask_slp = (SeqLocPtr) mask_loc->data.ptrvalue;
 
1732
                    }
 
1733
                    if (mask_loc) {
 
1734
                       next_mask_loc = mask_loc->next;
 
1735
                       mask_loc->next = NULL;
 
1736
                    }
 
1737
                 }
 
1738
                 if (align_view < 7) {
 
1739
                     bsp = BioseqLockById(SeqLocId(tmp_slp));
 
1740
                     init_buff_ex(85);
 
1741
                     fprintf(outfp, "\n");
 
1742
                     AcknowledgeBlastQuery(bsp, 70, outfp, believe_query, 
 
1743
                                           html);
 
1744
                     free_buff();
 
1745
                     BioseqUnlock(bsp);
 
1746
                 }
1352
1747
              }
1353
 
              if(align_view == 7 && !options->is_ooframe) {
1354
 
                 BXMLPrintOutput(xml_aip, seqalign, 
1355
 
                                 options, blast_program, blast_database, 
1356
 
                                 fake_bsp, other_returns, 0, NULL);
1357
 
                 AsnIoReset(xml_aip);
1358
 
                 SeqAlignSetFree(seqalign);
 
1748
              if((align_view == 7) && !options->is_ooframe) {
 
1749
                 if (options->is_megablast_search) {
 
1750
                    bsp = BioseqLockById(SeqLocId(tmp_slp));
 
1751
                    BXMLPrintOutput(xml_aip, seqalign, 
 
1752
                                    options, blast_program, blast_database, 
 
1753
                                    bsp, other_returns, 0, NULL, mask_loc);
 
1754
                    BioseqUnlock(bsp);
 
1755
                    AsnIoReset(xml_aip);
 
1756
                    SeqAlignSetFree(seqalign);
 
1757
                 } else {
 
1758
                    num_iters = (num_queries>0) ? num_queries : 1;
 
1759
                    for (sap_iter=0; sap_iter < num_iters; sap_iter++) {
 
1760
                       curr_seqalign = (num_queries > 0) ? *(sap_array + sap_iter) : seqalign;
 
1761
                       BXMLPrintOutput(xml_aip, curr_seqalign, 
 
1762
                                    options, blast_program, blast_database, 
 
1763
                                    fake_bsp, other_returns, 0, NULL, mask_loc);
 
1764
                       AsnIoReset(xml_aip);
 
1765
                       SeqAlignSetFree(curr_seqalign);
 
1766
                    } /* for loop over sap-array (concat) */
 
1767
                 } /* not MBlast case */
1359
1768
              } else {
1360
 
                 seqannot = SeqAnnotNew();
1361
 
                 seqannot->type = 2;
1362
 
                 AddAlignInfoToSeqAnnot(seqannot, align_type);
1363
 
                 seqannot->data = seqalign;
1364
 
                 if (aip) {
1365
 
                    SeqAnnotAsnWrite((SeqAnnotPtr) seqannot, aip, NULL);
1366
 
                    AsnIoReset(aip);
1367
 
                 }
 
1769
                 /* create the array of SeqAnnotPtrs, if necessary */
 
1770
 
 
1771
                 num_iters = (num_queries > 0) ? num_queries : 1; 
 
1772
                 for (sap_iter=0; sap_iter < num_iters; sap_iter++) {
 
1773
                    curr_seqalign = (num_queries > 0) ? *(sap_array + sap_iter) : seqalign;
 
1774
                    if ( (num_queries > 0) && (sap_iter == 0) ) {
 
1775
                       seq_annot_arr = (SeqAnnotPtrArray) MemNew(sizeof(SeqAnnotPtr)*num_queries);
 
1776
                    }
 
1777
                    seqannot = SeqAnnotNew();
 
1778
                    seqannot->type = 2;
 
1779
                    AddAlignInfoToSeqAnnot(seqannot, align_type);
 
1780
                    seqannot->data = curr_seqalign;
 
1781
                    if (aip) {
 
1782
                       SeqAnnotAsnWrite((SeqAnnotPtr) seqannot, aip, NULL);
 
1783
                       AsnIoReset(aip);
 
1784
                    }
 
1785
                    if (num_queries > 0) {
 
1786
                       *(seq_annot_arr + sap_iter) = seqannot;
 
1787
                    }
 
1788
                 } /* make seqannots over the sap_iters from concat, or the single seqalign */
 
1789
                    
1368
1790
                 if (outfp) { /* Uncacheing causes problems with ordinal nos. vs. gi's. */
1369
1791
                    ObjMgrSetHold();
1370
 
                    init_buff_ex(85);
1371
 
                    PrintDefLinesFromSeqAlignEx2(seqalign, 80, outfp, print_options, FIRST_PASS, 
1372
 
                        NULL, number_of_descriptions, NULL, NULL);
1373
 
                    free_buff();
1374
 
                    
1375
 
                    prune = BlastPruneHitsFromSeqAlign(seqalign, number_of_alignments, NULL);
1376
 
                    seqannot->data = prune->sap;
1377
 
 
1378
 
                    if(options->is_ooframe) {
1379
 
                        OOFShowBlastAlignment(seqalign, /*mask*/ NULL,
1380
 
                                              outfp, align_options, txmatrix);
1381
 
                    } else {
1382
 
                        if (align_view != 0)
1383
 
                            ShowTextAlignFromAnnot(seqannot, 60, outfp, NULL, NULL, align_options, txmatrix, mask_loc, NULL);
1384
 
                        else
1385
 
                            ShowTextAlignFromAnnot(seqannot, 60, outfp, NULL, NULL, align_options, txmatrix, mask_loc, FormatScoreFunc);
1386
 
                    }
1387
 
                    
1388
 
                    seqannot->data = seqalign;
1389
 
                    prune = BlastPruneSapStructDestruct(prune);
 
1792
                    /* print deflines */
 
1793
                    for (sap_iter=0; sap_iter < num_iters; sap_iter++) {
 
1794
                       curr_seqalign = (num_queries > 0) ? *(sap_array + sap_iter) : seqalign;
 
1795
 
 
1796
                       init_buff_ex(85);
 
1797
 
 
1798
                       PrintDefLinesFromSeqAlignEx2(curr_seqalign, 80, outfp, 
 
1799
                                        print_options, FIRST_PASS, NULL, 
 
1800
                                        number_of_descriptions, NULL, NULL);
 
1801
                       free_buff();
 
1802
                    } /* print deflines, looped if concat */
 
1803
 
 
1804
                    for (sap_iter=0; sap_iter < num_iters; sap_iter++) {
 
1805
                       /* AM: Query concatenation. */
 
1806
                       if( mult_queries && mask_loc )
 
1807
                       {
 
1808
                         orig_mask_loc = mask_loc;
 
1809
                         
 
1810
                         if( !mask_loc->data.ptrvalue ) mask_loc = NULL;
 
1811
                       }
 
1812
 
 
1813
                       curr_seqalign = (num_queries > 0) ? *(sap_array + sap_iter) : seqalign;
 
1814
                       curr_seqannot = (num_queries > 0) ? *(seq_annot_arr + sap_iter) : seqannot;
 
1815
 
 
1816
                       prune = BlastPruneHitsFromSeqAlign(curr_seqalign,
 
1817
                                        number_of_alignments, NULL);
 
1818
                       curr_seqannot->data = prune->sap;
 
1819
 
 
1820
                       if(options->is_ooframe) {
 
1821
                          OOFShowBlastAlignment(curr_seqalign, /*mask*/ NULL,
 
1822
                                        outfp, align_options, txmatrix);
 
1823
                       } else {
 
1824
                          if (align_view != 0)
 
1825
                             ShowTextAlignFromAnnot(curr_seqannot, 60, outfp, NULL, NULL, 
 
1826
                                        align_options, txmatrix, mask_loc, NULL);
 
1827
                          else
 
1828
                             ShowTextAlignFromAnnot(curr_seqannot, 60, outfp, NULL, NULL,
 
1829
                                        align_options, txmatrix, mask_loc, 
 
1830
                                        FormatScoreFunc);
 
1831
                       }
 
1832
                    
 
1833
                       curr_seqannot->data = curr_seqalign;
 
1834
                       prune = BlastPruneSapStructDestruct(prune);
 
1835
 
 
1836
                       /* AM: Query concatenation. */
 
1837
                       if( mult_queries && orig_mask_loc ) 
 
1838
                       {
 
1839
                         mask_loc = orig_mask_loc;
 
1840
                         mask_loc = mask_loc->next;
 
1841
                       }
 
1842
                    } /* show text align, loop over seqalign/seqannots for concat */
1390
1843
                    ObjMgrClearHold();
1391
1844
                    
1392
1845
                    ObjMgrFreeCache(0);
1393
 
                    
 
1846
                 } /* if outfp */
 
1847
                 for (sap_iter=0; sap_iter < num_queries; sap_iter++) {
 
1848
                    /* upper bound is num_queries, take care not to do this unless concat */
 
1849
                    *(seq_annot_arr + sap_iter) = SeqAnnotFree(*(seq_annot_arr + sap_iter)); 
1394
1850
                 }
1395
 
                 seqannot = SeqAnnotFree(seqannot);
1396
 
              } /* if XML Printing */
 
1851
        /*--KM free seqalign array and all seqaligns?? */
 
1852
 
 
1853
              } /* end of else (not XML Printing) */
1397
1854
              if (options->is_megablast_search)
1398
1855
                 tmp_slp = tmp_slp->next;
1399
 
              if (seqannot)
 
1856
        /* --KM watch for memory leaks */
 
1857
              if (seqannot && num_queries == 0)   
1400
1858
                 seqannot = SeqAnnotFree(seqannot);
1401
1859
              seqalign = next_seqalign;
1402
 
           }
1403
 
           }
 
1860
           } /* End of loop on all seqaligns */
 
1861
           if (mask_loc && next_mask_loc)
 
1862
              mask_loc->next = next_mask_loc;
 
1863
 
 
1864
           } /* end of align_view not tabular case */
1404
1865
        } else {         /* seqalign is NULL */
1405
 
           if(align_view == 7 && !options->is_ooframe) {
 
1866
           if((align_view == 7) && !options->is_ooframe) {
1406
1867
              BlastErrorMsgPtr error_msg;
1407
1868
              CharPtr message;
1408
1869
              
1412
1873
                 error_msg = error_returns->data.ptrvalue;
1413
1874
                 message = error_msg->msg;
1414
1875
              }
1415
 
           
1416
 
              BXMLPrintOutput(xml_aip, NULL, 
1417
 
                              options, blast_program, blast_database, 
1418
 
                              fake_bsp, other_returns, 0, message);
1419
 
              
 
1876
              if (options->is_megablast_search) {
 
1877
                 bsp = BioseqLockById(SeqLocId(tmp_slp));
 
1878
                 BXMLPrintOutput(xml_aip, seqalign, 
 
1879
                                 options, blast_program, blast_database, 
 
1880
                                 bsp, other_returns, 0, NULL, mask_loc);
 
1881
                 BioseqUnlock(bsp);
 
1882
              } else {
 
1883
                 BXMLPrintOutput(xml_aip, NULL, options, blast_program, 
 
1884
                                 blast_database, fake_bsp, other_returns, 0, 
 
1885
                                 message, mask_loc);
 
1886
              }
1420
1887
              AsnIoReset(xml_aip);
1421
1888
           } else if (align_view < 8) {
1422
1889
              fprintf(outfp, "\n\n ***** No hits found ******\n\n");
1469
1936
        
1470
1937
        MemFree(params_buffer);
1471
1938
        free_buff();
1472
 
        mask_loc_start = mask_loc;
 
1939
        mask_loc = mask_loc_start;
1473
1940
        while (mask_loc) {
1474
1941
           SeqLocSetFree(mask_loc->data.ptrvalue);
1475
1942
           mask_loc = mask_loc->next;
1485
1952
#ifndef BLAST_CS_API
1486
1953
        /* This is freed earlier in client-server case */
1487
1954
        options->query_lcase_mask = SeqLocSetFree(options->query_lcase_mask);
 
1955
        ReadDBBioseqFetchDisable();
1488
1956
#endif
1489
1957
        if (html)
1490
1958
           fprintf(outfp, "</PRE>\n<P><HR><BR>\n<PRE>");
1496
1964
#ifdef BLAST_CS_API
1497
1965
    BlastNetBioseqFetchDisable(bl3hp, blast_database, db_is_na);
1498
1966
    BlastFini(bl3hp);
1499
 
#else
1500
 
    ReadDBBioseqFetchDisable();
1501
1967
#endif
1502
1968
    
1503
1969
    aip = AsnIoClose(aip);