1 /*===========================================================================
2 *
3 *                            PUBLIC DOMAIN NOTICE
4 *               National Center for Biotechnology Information
5 *
6 *  This software/database is a "United States Government Work" under the
7 *  terms of the United States Copyright Act.  It was written as part of
8 *  the author's official duties as a United States Government employee and
9 *  thus cannot be copyrighted.  This software/database is freely available
10 *  to the public for use. The National Library of Medicine and the U.S.
11 *  Government have not placed any restriction on its use or reproduction.
12 *
13 *  Although all reasonable efforts have been taken to ensure the accuracy
14 *  and reliability of the software and data, the NLM and the U.S.
15 *  Government do not and cannot warrant the performance or results that
16 *  may be obtained by using this software or data. The NLM and the U.S.
17 *  Government disclaim all warranties, express or implied, including
18 *  warranties of performance, merchantability or fitness for any particular
19 *  purpose.
20 *
21 *  Please cite the author in any work or product based on this material.
22 *
23 * ===========================================================================
24 *
25 * File Name:  cblast.c
26 *
27 * Author:  Yanli Wang
28 *
29 * Initial Version Creation Date: 6/19/2002
30 *
31 * File Description:
32 *         WWW-Server for visualizing sequence-structure alignment
33 *
34 *
35 * Modifications:
36 * --------------------------------------------------------------------------
37 * $Log: cblast.c,v $
38 * Revision 1.9  2002/12/31 21:00:32  ywang
39 * read environment variables from config file
40 *
41 * Revision 1.8  2002/12/20 21:44:09  ywang
42 * update CDart_Init2
43 *
44 * Revision 1.7  2002/12/18 16:58:35  ywang
45 * get defline from blast DB now
46 *
47 * Revision 1.6  2002/12/18 15:29:56  ywang
48 * improve query id label
49 *
50 * Revision 1.5  2002/12/12 15:59:45  ywang
51 * wording improvement
52 *
53 *
54 * ==========================================================================
55 */
56 
57 #include <stdio.h>
58 #include <ncbi.h>
59 #include <accentr.h>
60 #include <lsqfetch.h>
61 #include <netentr.h>
62 #include <www.h>
63 #include <sys/resource.h>
64 #include <asn.h>
65 #include <accutils.h>
66 #include <mmdbapi.h>
67 #include <mmdbapi1.h>
68 #include <asnmime.h>
69 #include <objmime.h>
70 #include <strimprt.h>
71 #include <objcdd.h>
72 #include "cddsrv.h"
73 #include <pgppop.h>
74 #include <alignmgr.h>
75 #include <taxutil.h>
76 #include <txcommon.h>
77 #include <taxinc.h>
78 #include <ctlibutils.h>
79 
80 #include "CAV_lib/cddalignview.h"
81 #include "/netopt/structure/include/dbinfo.h"
82 #include "/netopt/structure/include/dart.h"
83 #include "/netopt/structure/include/dartutil.h"
84 
85 #include <objcn3d.h>
86 #include <cddutil.h>
87 #include "cdd_seedutil.h"
88 #include "cblast.h"
89 #include "cblastutil.h"
90 #include "cblastgraph.h"
91 #include <PubVastApi.h>
92 #include <PubStructApi.h>
93 #include <txalign.h>
94 
95 #define MMDBDirPath "/net/vaster/mmdb/mmdb/data/"
96 #define HEADFILE "sshead.txt"
97 /* Structure Summary Header File */
98 
99 #define MaxModels 1
100 
101 #define BLAST_OVERVIEW 1
102 #define BLAST_ONEGROUP 2
103 #define BLAST_ONEPAIR 3
104 
105 Dart_Connect    *dartcon;
106 Boolean psfailed = FALSE;
107 WWWInfoPtr  info = NULL;
108 Int2 DispOptChoice = 0;
109 
110 CharPtr queryrid;
111 extern FILE *logFilePtr;
112 Int2 entry_page = 3;
113 Char subset_name[5][20] = {"All MMDB", "Non-identical seq.", "NR,Blast_p<10e-80", "NR,Blast_p<10e-40", "NR,Blast_p<10e-7"};
114 Char sortpara_name[4][20] = {"Blast e_value", "Blast bit_score", "Aligned length", "Seq. Identity"};
115 Char dispform_name[2][20] = {"Graphics", "Table"};
116 /*------------------------------*/
WWWPrintFileData(CharPtr FName,FILE * pFile)117 static void WWWPrintFileData(CharPtr FName,  FILE *pFile)
118 {
119 
120    FILE *f = NULL;
121    Char fullpath [PATH_MAX];
122    CharPtr ptr;
123    Char pcBuf[1024];
124 
125    fullpath[0] = '\0';
126    StringCpy(fullpath,  DATApath); /* look in DATApath */
127    StringCat(fullpath,  FName);
128    f = FileOpen (fullpath, "r");
129    if (f == NULL) {
130        f = FileOpen (FName, "r");  /* look in curent */
131        if (f == NULL)  {  /* look in ./data/ */
132          ProgramPath (fullpath, sizeof (fullpath) - 1);
133          ptr = StringRChr (fullpath, DIRDELIMCHR);
134          if (ptr != NULL) {
135       *ptr = '\0';
136          }
137          FileBuildPath (fullpath, "data", FName);
138          f = FileOpen (fullpath, "r");
139          if (f == NULL)  {
140            return;
141          }
142        }
143    }
144 
145    do {
146      pcBuf[0] = '\0';
147      ptr = fgets(pcBuf, (size_t)1024, f);
148      if (ptr) fprintf(pFile, ptr);
149    } while (ptr);
150 
151    FileClose(f);
152    return;
153 }
154 /*---------------------------------------------------------------------------*/
155 /* read parameters from configuration file                                   */
156 /*---------------------------------------------------------------------------*/
CblastSrvGetParams()157 static Boolean CblastSrvGetParams()
158 {
159   URLBase[0] = URLcgi[0] = ENTREZurl[0] = DOCSUMurl[0] = MAILto[0] = '\0';
160 
161   GetAppParam("cblast", "CBLAST", "ENTREZurl", "", ENTREZurl, PATH_MAX);
162   if (ENTREZurl[0] == '\0') {
163     ErrPostEx(SEV_FATAL,0,0,"CBLAST config file\nCBLAST section has no ENTREZurl...\n");
164     return FALSE;
165   }
166   GetAppParam("cblast", "CBLAST", "DOCSUMurl", "", DOCSUMurl, PATH_MAX);
167   if (DOCSUMurl[0] == '\0') {
168     ErrPostEx(SEV_FATAL,0,0,"CBLAST config file\nCBLAST section has no DOCSUMurl...\n");
169     return FALSE;
170   }
171 
172   GetAppParam("cblast", "CBLAST", "TAXcgi", "", TAXcgi, PATH_MAX);
173   if (TAXcgi[0] == '\0') {
174     ErrPostEx(SEV_FATAL,0,0,"CBLAST config file\nCBLAST section has no TAXcgi ...\n");
175     return FALSE;
176   }
177 
178   GetAppParam("cblast", "CBLAST", "MMDBcgi", "", MMDBcgi, PATH_MAX);
179   if (MMDBcgi[0] == '\0') {
180     ErrPostEx(SEV_FATAL,0,0,"CBLAST config file\nCBLAST section has no MMDBcgi ...\n");
181     return FALSE;
182   }
183 
184   GetAppParam("cblast", "CBLAST", "MMDBurl", "", MMDBurl, PATH_MAX);
185   if (MMDBurl[0] == '\0') {
186     ErrPostEx(SEV_FATAL,0,0,"CBLAST config file\nCBLAST section has no MMDBurl ...\n");
187     return FALSE;
188   }
189 
190   GetAppParam("cblast", "CBLAST", "DARTcgi", "", DARTcgi, PATH_MAX);
191   if (DARTcgi[0] == '\0') {
192     ErrPostEx(SEV_FATAL,0,0,"CBLAST config file\nCBLAST section has no DARTcgi ...\n");
193     return FALSE;
194   }
195 
196   GetAppParam("cblast", "CBLAST", "CGIurl", "", CGIurl, PATH_MAX);
197   if (CGIurl[0] == '\0') {
198     ErrPostEx(SEV_FATAL,0,0,"CBLAST config file\nCBLAST section has no CGIurl ...\n");
199     return FALSE;
200   }
201 
202   GetAppParam("cblast", "CBLAST", "CDDhome", "", CDDhome, PATH_MAX);
203   if (CDDhome[0] == '\0') {
204     ErrPostEx(SEV_FATAL,0,0,"CBLAST config file\nCBLAST section has no CDDhome ...\n");
205     return FALSE;
206   }
207 
208   GetAppParam("cblast", "CBLAST", "CDSRVurl", "", CDSRVurl, PATH_MAX);
209   if (CDSRVurl[0] == '\0') {
210     ErrPostEx(SEV_FATAL,0,0,"CBLAST config file\nCBLAST section has no CDSRVurl ...\n");
211     return FALSE;
212   }
213 
214   GetAppParam("cblast", "CBLAST", "CGIName", "", CGIName, PATH_MAX);
215   if (CGIName[0] == '\0') {
216     ErrPostEx(SEV_FATAL,0,0,"CBLAST config file\nCBLAST section has no CGIName ...\n");
217     return FALSE;
218   }
219 
220   GetAppParam("cblast", "CBLAST", "LOGpath", "", LOGpath, PATH_MAX);
221   if (LOGpath[0] == '\0') {
222     ErrPostEx(SEV_FATAL,0,0,"CBLAST config file\nCBLAST section has no LOGpath ...\n");
223     return FALSE;
224   }
225 
226   GetAppParam("cblast", "CBLAST", "NRPDB", "", NRPDB, PATH_MAX);
227   if (NRPDB[0] == '\0') {
228     ErrPostEx(SEV_FATAL,0,0,"CBLAST config file\nCBLAST section has no NRPDB ...\n");
229     return FALSE;
230   }
231 
232   GetAppParam("cblast", "CBLAST", "ODBCINI", "", ODBCINI, PATH_MAX);
233   if (ODBCINI[0] == '\0') {
234     ErrPostEx(SEV_FATAL,0,0,"CBLAST config file\nCBLAST section has no ODBCINI ...\n");
235     return FALSE;
236   }
237 
238   GetAppParam("cblast", "CBLAST", "DARTUSER", "", DARTUSER, PATH_MAX);
239   if (DARTUSER[0] == '\0') {
240     ErrPostEx(SEV_FATAL,0,0,"CBLAST config file\nCBLAST section has no DARTUSER ...\n");
241     return FALSE;
242   }
243 
244   GetAppParam("cblast", "CBLAST", "DARTPASS", "", DARTPASS, PATH_MAX);
245   if (DARTPASS[0] == '\0') {
246     ErrPostEx(SEV_FATAL,0,0,"CBLAST config file\nCBLAST section has no DARTPASS ...\n");
247     return FALSE;
248   }
249 
250   GetAppParam("cblast", "CBLAST", "DARTLIB", "", DARTLIB, PATH_MAX);
251   if (DARTLIB[0] == '\0') {
252     ErrPostEx(SEV_FATAL,0,0,"CBLAST config file\nCBLAST section has no NRPDB ...\n");
253     return FALSE;
254   }
255 
256   GetAppParam("cblast", "CBLAST", "LDLIBRARYPATH", "", LDLIBRARYPATH, PATH_MAX);
257   if (LDLIBRARYPATH[0] == '\0') {
258     ErrPostEx(SEV_FATAL,0,0,"CBLAST config file\nCBLAST section has no LDLIBRARYPATH ...\n");
259     return FALSE;
260   }
261 
262   GetAppParam("cblast", "CBLAST", "SYBASE", "", SYBASE, PATH_MAX);
263   if (SYBASE[0] == '\0') {
264     ErrPostEx(SEV_FATAL,0,0,"CBLAST config file\nCBLAST section has no NRPDB ...\n");
265     return FALSE;
266   }
267 
268   GetAppParam("cblast", "CBLAST", "BLASTDB", "", BLASTDB, PATH_MAX);
269   if (BLASTDB[0] == '\0') {
270     ErrPostEx(SEV_FATAL,0,0,"CBLAST config file\nCBLAST section has no NRPDB ...\n");
271     return FALSE;
272   }
273 
274   GetAppParam("cblast", "CBLAST", "NCBI", "", NCBI, PATH_MAX);
275   if (NCBI[0] == '\0') {
276     ErrPostEx(SEV_FATAL,0,0,"CBLAST config file\nCBLAST section has no NRPDB ...\n");
277     return FALSE;
278   }
279 
280   return TRUE;
281 }                                                    /* end CddGetParams */
282 /*---------------------------*/
CblastSrvInit()283 void CblastSrvInit()
284 {
285 
286   Char str[1024];
287 
288   if((! VastSrvInitialize()) || (! MmdbSrvInitialize()))
289   {
290     printf("Error: VastSrvInitialize() or MmdbSrvInitialize() failed.\n");
291     exit(0);
292   }
293 
294   sprintf(str, "ODBCINI=%s", ODBCINI); putenv(str);
295   putenv("LD_LIBRARY_PATH=/opt/machine/merant/lib");
296 
297   dartcon = Dart_Init2(DARTLIB, DARTUSER, DARTPASS);
298 
299   StringCat(LOGpath, "cblast.log");
300   if( !ErrSetLogfile (LOGpath, ELOG_APPEND) ) {
301       printf("Content-type: text/html\r\n\r\n");
302       printf("<H2>CBLAST Error</H2>\n - Unable to Open Log.<p>\n");
303       printf("LOGpath %s<br>\n", LOGpath);
304         printf("Contact CBLAST administrator for this site: %s<p>\n",  MAILto);
305     exit(1);
306   }
307 
308   ErrSetLogLevel(SEV_MAX);
309   ErrSetOpts (ERR_CONTINUE, ERR_LOG_ON);
310 
311   psfailed = FALSE;
312   if (!MMDBInit_PS()) {
313     psfailed = TRUE;
314     if (!MMDBInit_FF()) {
315       ErrLogPrintf("#MMDB Database Access Failed to Initialize.\n");
316       printf("Content-type: text/html\r\n\r\n");
317       printf("<H2>CBLAST Error</H2>\n - Unable to Open MMDB Database on Server.<p>");
318       printf("Contact CBLAST administrator for this site: %s<p>\n",  MAILto);
319 
320       exit(1);
321     }
322   }
323 
324   SeqAsnLoad();
325   if(!objmimeAsnLoad()) printf("objmimeAsnLoad failed!\n");
326   AllObjLoad ();
327   objcn3dAsnLoad();
328 
329 /*
330   ID1BioseqFetchEnable ("CBLAST", FALSE);
331 */
332 
333 /*
334   if (EntrezInit("CBLAST", NULL, FALSE) == FALSE)
335   {
336     printf("Content-type: text/html\n\n");
337     printf("<h2>Error</h2>\n");
338     printf("CBLAST: EntrezInit Failed.<p>\n");
339     return;
340   }
341 */
342 
343 }
344 /*----------*/
CblastDumpQuery(BioseqPtr bsp,FILE * File)345 static CblastDumpQuery(BioseqPtr bsp, FILE *File)
346 {
347 
348   printf("Content-type: text/html\n\n");
349   WWWPrintFileData(HEADFILE,  File);
350 
351   fprintf(File, "\n\n");
352 
353   fprintf(File, "\n\n");
354   fprintf(File, "<small>\n");
355   BioseqToFastaDump(bsp, File, FALSE);
356   fprintf(File, "</small>\n");
357 
358   printf ("</body>\n");
359   printf ("</html>");
360 
361   return 0;
362 }
363 /*----------*/
PrintPageView(FILE * File,WWWQueryPtr wqp,BlastPDBNbPtr bpnp)364 static PrintPageView(FILE *File, WWWQueryPtr wqp, BlastPDBNbPtr bpnp)
365 {
366     WWWQueryDataPtr wqdp = NULL;
367     ValNodePtr csip = NULL;
368     CblastSeqInfoDataPtr csidp = NULL;
369     long mmdb_id = 0;
370     PDBSeqIdPtr pdbid = NULL;
371 
372     csip = bpnp->csip;
373     csidp = csip->data.ptrvalue;
374 
375     mmdb_id = constructMmdbIdForGi(csidp->PDBgi);
376     pdbid = csidp->pdbid->data.ptrvalue;
377 
378     fprintf(File, "<TABLE width=800 BORDER=0 CELLPADDING=3 CELLSPACING=0 bgcolor=#FFFFCC>\n\n");
379     fprintf(File, "<TR>\n");
380     fprintf(File, "<TD>\n");
381     fprintf(File, "<table>   <!-- 1st subtable, in the first layer -->\n\n");
382     /* insert a blank row in the table, for spacing */
383     fprintf(File, "<tr>\n<td VALIGN=TOP NOWRAP> </td>\n</tr>\n\n");
384 
385     if(bpnp->query_title){
386       fprintf(File, "<tr>\n");
387       fprintf(File, "<td VALIGN=TOP NOWRAP class=H4>\n");
388       fprintf(File, "<strong>Query:</strong></td>\n");
389       fprintf(File, "<td class=\"TEXT\">%s", bpnp->query_title);
390       fprintf(File, "</td>\n</tr>\n\n");
391     }
392 
393     fprintf(File, "<tr>\n");
394     fprintf(File, "<td VALIGN=TOP NOWRAP class=H4>\n");
395     fprintf(File, "<strong>Structure:</strong></td>\n");
396     fprintf(File, "<td class=\"TEXT\">%s %s.", pdbid->mol, csidp->doc);
397     fprintf(File, "</td>\n</tr>\n\n");
398 
399     fprintf(File, "<tr>\n");
400     fprintf(File, "<td VALIGN=TOP NOWRAP ALIGN=LEFT class=H4>");
401     fprintf(File, "MMDB: <A HREF=\"%s%d\">%s_%c</A>", MMDBcgi, mmdb_id, pdbid->mol, pdbid->chain);
402     fprintf(File, "&nbsp;&nbsp;\n<font class=H4>");
403     fprintf(File, "</td>\n");
404     fprintf(File, "<td VALIGN=TOP NOWRAP ALIGN=LEFT class=H4>");
405     fprintf(File, "Reference: <A HREF=\"%sdb=structure&cmd=Display&dopt=structure_pubmed&from_uid=%ld\">PubMed</A>\n",ENTREZurl, (long) mmdb_id );
406     fprintf(File, "</td>\n</tr>\n");
407 
408   /* insert a blank row in the table, for spacing */
409     fprintf(File, "\n<tr>\n");
410     fprintf(File, "<td VALIGN=TOP NOWRAP><BR></td>\n");
411     fprintf(File, "</tr>\n");
412     fprintf(File, "</table>  <!-- end of first subtable -->\n");
413 
414     fprintf(File, "</TD>\n");
415     fprintf(File, "</TR>\n");
416     fprintf(File, "</TABLE>\n");
417 
418 
419     fprintf(File, "<FORM METHOD=POST ACTION=\"%s%s\">\n", CGIurl, CGIName);
420 
421     while(wqp){
422       wqdp = wqp->data.ptrvalue;
423       fprintf(File, "<INPUT TYPE=HIDDEN NAME=%s VALUE=%s>\n", wqdp->name, wqdp->value);
424       wqp = wqp->next;
425     }
426 
427 /*
428     fprintf(File, "<table border=0 cellpadding=0 cellspacing=0>\n");
429     fprintf(File, "<tr>\n");
430     fprintf(File, "<TD class=SMALL1>\n");
431 
432     fprintf(File, "<strong><INPUT TYPE=submit NAME=viewmethod VALUE=\"View Alignment\"></strong>");
433     fprintf(File, "&nbsp;\n");
434 
435     fprintf(File, "<strong>using</strong>\n");
436     fprintf(File, "<SELECT NAME=viewmethod_option>\n");
437     if(DispOptChoice == 1) fprintf(File, "<OPTION SELECTED VALUE=HTML>HTML\n");
438     else fprintf(File, "<OPTION VALUE=HTML>HTML\n");
439     if(DispOptChoice == 2) fprintf(File, "<OPTION SELECTED VALUE=Graphic>Graphic\n");
440     else fprintf(File, "<OPTION VALUE=Graphic>Graphic\n");
441     fprintf(File, "</SELECT>\n");
442     fprintf(File, "</TD>\n");
443 
444     fprintf(File, "</TR>\n");
445     fprintf(File, "</table>\n");
446 */
447 
448     fprintf(File, "<table border=0 cellpadding=0 cellspacing=0>\n");
449     fprintf(File, "<tr>\n");
450     fprintf(File, "<TD class=SMALL1>\n");
451 
452     fprintf(File, "<strong><INPUT TYPE=submit NAME=3d_viewmethod VALUE=\"View 3D Structure\"></strong>");
453     fprintf(File, "&nbsp;\n");
454 
455     fprintf(File, "<strong>with</strong>\n");
456     fprintf(File, "<SELECT NAME=3d_viewmethod_option>\n");
457     if(DispOptChoice == 3)fprintf(File, "<OPTION SELECTED VALUE=Cn3D>Cn3D Display\n");
458     else fprintf(File, "<OPTION VALUE=Cn3D>Cn3D Display\n");
459     if(DispOptChoice == 4)fprintf(File, "<OPTION SELECTED VALUE=SAVE_ASN1>Save File\n");
460     else fprintf(File, "<OPTION VALUE=SAVE_ASN1>Save File\n");
461     if(DispOptChoice == 5)fprintf(File, "<OPTION SELECTED VALUE=PRINT_ASN1>See File\n");
462     else fprintf(File, "<OPTION VALUE=PRINT_ASN1>See File\n");
463     fprintf(File, "</SELECT>\n");
464     fprintf(File, "</TD>\n");
465 
466     fprintf(File, "<TD>&nbsp;</TD>\n");
467     fprintf(File, "<TD><small>(To display structure, download <A HREF = \"http://www.ncbi.nlm.nih.gov/Structure/CN3D/cn3d.shtml\"><STRONG><i>Cn3D</i></STRONG></A>)</small></TD>\n");
468 
469     fprintf(File, "</TR>\n");
470     fprintf(File, "</table>\n");
471 
472     fprintf(File, "</FORM>\n");
473 
474     return;
475 }
476 /*-------------*/
PrintNeighborTable(NeighborInfoPtr nip,Int4 subject_str_gi,Int2 pagenum,Int2 numpages)477 PrintNeighborTable(NeighborInfoPtr nip, Int4 subject_str_gi, Int2 pagenum, Int2 numpages)
478 {
479   NeighborInfoDataPtr nidp = NULL;
480   Int2 i = 0;
481 
482   printf("<strong><INPUT TYPE=SUBMIT NAME=dispsub VALUE=List></strong>\n");
483   printf("<strong> Structures with identical sequence on page</strong>\n");
484   printf("<select name=doclistpage>\n");
485   for(i = 1; i <= numpages; i++){
486     if(i == pagenum) printf("<option value=%d selected>%d\n", i, i);
487     else printf("<option value=%d>%d\n", i, i);
488   }
489   printf("</select>\n");
490 
491   printf("<table cellspacing=3 cellpadding=2 width=800 border=1>\n");
492   printf("<tr valign=middle>\n");
493   printf("<th>&nbsp;</th>\n");
494   printf("<th align=middle>Id</th>\n");
495   printf("<th align=middle>Description</th>\n");
496   printf("</tr>\n");
497 
498   while(nip){
499     nidp = nip->data.ptrvalue;
500     if(nidp->pagenum != pagenum){
501       nip = nip->next;
502       continue;
503     }
504     printf("<tr>\n");
505     if(nidp->gi==subject_str_gi) printf("<td VALIGN=TOP><INPUT TYPE=\"radio\" checked NAME=\"hit\" ");
506     else printf("<td VALIGN=TOP><INPUT TYPE=\"radio\" NAME=\"hit\" ");
507     printf("VALUE=\"%d\"></td>\n", nidp->gi);
508     printf("<td valign=top>"); printf("<A HREF=\"%s%s\">%s_%c</A>", MMDBcgi, nidp->mol, nidp->mol, nidp->chain); printf("</td>\n");
509     printf("<td valign=top>"); printf("%s", nidp->docsum); printf("</td>\n");
510     printf("</tr>\n");
511     nip = nip->next;
512   }
513 
514   printf("</table>\n");
515 }
516 /*--------------------------*/
PrintPDBNeighborTable(FILE * File,BlastPDBNbPtr bpnp,Int2 pagenum)517 void PrintPDBNeighborTable(FILE *File, BlastPDBNbPtr bpnp, Int2 pagenum)
518 {
519   ValNodePtr csp = NULL, csip = NULL;
520   CblastSeqInfoDataPtr csidp = NULL;
521   CblastScoreDataPtr csdp = NULL;
522   PDBSeqIdPtr pdbid = NULL;
523   char str_score[1024];
524   Int4 count_onpage = 0, count = 0;
525 
526   csip = bpnp->csip;
527   while(csip){
528     csidp = csip->data.ptrvalue;
529     if(csidp->pagenum == pagenum) count_onpage++;
530     count++;
531     csip = csip->next;
532   }
533 
534   if(count_onpage < count) fprintf(File, "<strong>%d out of %d hits with known structures displayed.</strong>\n", count_onpage, count);
535   else fprintf(File, "<strong>%d hits with known structures displayed.</strong>\n", count);
536 
537   fprintf(File, "<table cellspacing=3 cellpadding=2 width=800 border=1>\n");
538   printf("<tr valign=middle>\n");
539   printf("<th align=middle>Structure</th>\n");
540   printf("<th align=middle>E_value</th>\n");
541   printf("<th align=middle>Bit_score</th>\n");
542   printf("<th align=middle>Alg. Len</th>\n");
543   printf("<th align=middle>Seq %Id</th>\n");
544   printf("<th align=middle>Description</th>\n");
545   printf("</tr>\n");
546 
547   csp = bpnp->csp;
548   csip = bpnp->csip;
549   while(csip){
550 
551     csdp = csp->data.ptrvalue;
552     csidp = csip->data.ptrvalue;
553     pdbid = csidp->pdbid->data.ptrvalue;
554 
555     if(csidp->pagenum == pagenum){
556       fprintf(File, "<tr>\n");
557       fprintf(File, "<td valign=top>"); printf("<A HREF=\"%s%s\">%s_%c</A>", MMDBcgi, pdbid->mol, pdbid->mol, pdbid->chain); printf("</td>\n");
558       print_evalue(csdp->evalue, str_score);
559       fprintf(File, "<td valign=top>"); printf("%s\n", str_score); printf("</td>\n");
560       print_bitscore(csdp->bit_score, str_score);
561       fprintf(File, "<td valign=top>"); printf("%s\n", str_score); printf("</td>\n");
562       fprintf(File, "<td valign=top>"); printf("%d\n",  csdp->length); printf("</td>\n");
563       fprintf(File, "<td valign=top>"); printf("%d\n", (int) (csdp->seq_identity*100)); printf("</td>\n");
564       fprintf(File, "<td valign=top>"); printf("%s\n", csidp->doc); printf("</td>\n");
565       fprintf(File, "</tr>\n");
566     }
567 
568     csip = csip->next;
569     csp = csp->next;
570   }
571 
572   fprintf(File, "</table>\n");
573 }
574 /*--------------------------*/
SendAlgSummaryGraphPage(BioseqPtr query_bsp,CdInfoPtr cip,BlastPDBNbPtr bpnp,Int2 imgsize,Int2 ScoreLabel,Boolean DrawMap,Boolean AlgGraph,Int2 subset,Int2 sortpara,Int2 dispform,Int2 pagenum,WWWQueryPtr wqp_head,FILE * File,Int2 blastview)575 static Int4 SendAlgSummaryGraphPage(BioseqPtr query_bsp, CdInfoPtr cip, BlastPDBNbPtr bpnp, Int2 imgsize, Int2 ScoreLabel, Boolean DrawMap, Boolean AlgGraph,  Int2 subset, Int2 sortpara, Int2 dispform, Int2 pagenum, WWWQueryPtr wqp_head, FILE *File, Int2 blastview)
576 {
577   Int2 i = 0;
578   Int4 count = 0, count_onpage = 0;
579   ValNodePtr csip = NULL;
580   CblastSeqInfoDataPtr csidp = NULL;
581   ValNodePtr query = NULL;
582   WWWQueryPtr wqp = NULL;
583   WWWQueryDataPtr wqdp = NULL;
584   CharPtr str_query = NULL;
585 
586   csip = bpnp->csip;
587   while(csip){
588     csidp = csip->data.ptrvalue;
589     if(csidp->pagenum == pagenum)count_onpage++;
590     count++;
591     csip = csip->next;
592   }
593 
594   if(DrawMap){
595     printf("Content-type: text/html\n\n");
596     WWWPrintFileData(HEADFILE,  stdout);
597 
598     fprintf(File, "<TABLE width=800 BORDER=0 CELLPADDING=3 CELLSPACING=0 bgcolor=#FFFFCC>\n\n");
599     fprintf(File, "<TR>\n");
600     fprintf(File, "<TD>\n");
601 
602     fprintf(File, "<table>");
603     fprintf(File, "<tr>\n<td VALIGN=TOP NOWRAP> </td>\n</tr>\n\n");
604 
605     if(bpnp->query_title){
606       fprintf(File, "<tr>\n");
607       fprintf(File, "<td VALIGN=TOP NOWRAP class=H4>\n");
608       fprintf(File, "<strong>Query:</strong></td>\n");
609       fprintf(File, "<td class=\"TEXT\">%s", bpnp->query_title);
610       fprintf(File, "</td>\n</tr>\n\n");
611     }
612 
613     fprintf(File, "<tr>\n");
614     wqp = wqp_head;
615     while(wqp){
616       wqdp = wqp->data.ptrvalue;
617       if(strcmp(wqdp->name, "blast_RID")==0) {
618         fprintf(File, "<td>BLAST RID: </td>\n");
619         fprintf(File, "<td>%s</td>\n", wqdp->value);
620         break;
621       }
622       wqp = wqp->next;
623     }
624     fprintf(File, "</tr>\n");
625     fprintf(File, "</table>\n");
626     fprintf(File, "</TD>\n");
627     fprintf(File, "</TR>\n");
628     fprintf(File, "</TABLE>");
629 
630     fprintf(File, "<FORM METHOD=POST ACTION=\"%s%s\">\n", CGIurl, CGIName);
631     wqp = wqp_head;
632     while(wqp){
633       wqdp = wqp->data.ptrvalue;
634       fprintf(File, "<INPUT TYPE=HIDDEN NAME=%s VALUE=%s>\n", wqdp->name, wqdp->value);
635       wqp = wqp->next;
636     }
637 
638     fprintf(File, "<table>\n");
639     fprintf(File, "<tr><td>\n");
640     fprintf(File, "</td></tr>\n");
641 
642     fprintf(File, "<tr><td>\n");
643     fprintf(File, "<strong><INPUT TYPE=SUBMIT NAME=dispsub VALUE=List></strong>\n");
644     fprintf(File, "<strong>subset grouped by</strong>\n");
645     fprintf(File, "<select name=subset>\n");
646     for(i = 1; i<=5; i++){
647       if(subset == i)fprintf(File, "<option value=%d selected>%s\n", i, subset_name[i-1]);
648       else fprintf(File, "<option value=%d>%s\n", i, subset_name[i-1]);
649     }
650     fprintf(File, "</select>\n");
651     fprintf(File, "</td>\n");
652 
653     fprintf(File, "<td>\n");
654     fprintf(File, "<strong>sorted by </strong>\n");
655     fprintf(File, "<select name=sortpara>\n");
656     for(i = 1; i <= 4; i++){
657       if(sortpara == i)fprintf(File, "<option value=%d selected>%s\n", i, sortpara_name[i-1]);
658       else fprintf(File, "<option value=%d>%s\n", i, sortpara_name[i-1]);
659     }
660     fprintf(File, "</select>\n");
661     fprintf(File, "</td>\n");
662 
663     if(bpnp->numpages > 1){
664       fprintf(File, "<td>\n");
665       fprintf(File, "<strong>page </strong>\n");
666       fprintf(File, "<select name=doclistpage>\n");
667       for(i = 1; i <= bpnp->numpages; i++){
668         if(pagenum == i)fprintf(File, "<option value=%d selected>%d\n", i, i);
669         else fprintf(File, "<option value=%d>%d\n", i, i);
670       }
671       fprintf(File, "</select>\n");
672       fprintf(File, "</td>\n");
673     }
674 
675     fprintf(File, "<td>\n");
676     fprintf(File, "<strong>in </strong>\n");
677     fprintf(File, "<select name=dispform>\n");
678     for(i = 1; i <= 2; i++){
679       if(dispform == i)fprintf(File, "<option value=%d selected>%s\n", i, dispform_name[i-1]);
680       else fprintf(File, "<option value=%d>%s\n", i, dispform_name[i-1]);
681     }
682     fprintf(File, "</select>\n");
683     fprintf(File, "</td></tr>\n");
684 
685     fprintf(File, "<tr><td>\n");
686     fprintf(File, "</td></tr>\n");
687     fprintf(File, "</table>\n");
688     fprintf(File, "</FORM>\n");
689 
690     if(dispform == 1){
691           /* &nbsp */
692       fprintf(File, "<table>\n");
693       fprintf(File, "<TR><TD>\n");
694       if(blastview == BLAST_OVERVIEW) fprintf(File, "BLAST found %d related structures. Click on the alignment figure to see alignments and 3D structure.", count);
695       else if(blastview == BLAST_ONEGROUP) fprintf(File, "BLAST found %d related structures with identical sequence. Click on the alignment figure to see alignments and 3D structure.", count);
696       if(blastview == BLAST_ONEPAIR) fprintf(File, "Click on the alignment figure to see alignments and 3D structure.");
697       fprintf(File, "</TD></TR>\n");
698       fprintf(File, "<TR><TD>&nbsp;\n");
699       fprintf(File, "</TD></TR>\n");
700       fprintf(File, "</table>\n");
701 
702       fprintf(File, "<img src=\"%scblast.cgi?summary_graph=TRUE", CGIurl);
703       fprintf(File, "&subset=%d",subset);
704       fprintf(File, "&sortpara=%d",sortpara);
705       fprintf(File, "&doclistpage=%d",pagenum);
706       fprintf(File, "&dispform=%d",dispform);
707 
708       str_query = StringSave("summary_graph");
709       ValNodeAddStr(&query, 0, str_query);
710       str_query = StringSave("subset");
711       ValNodeAddStr(&query, 0, str_query);
712       str_query = StringSave("sortpara");
713       ValNodeAddStr(&query, 0, str_query);
714       str_query = StringSave("doclistpage");
715       ValNodeAddStr(&query, 0, str_query);
716       str_query = StringSave("dispform");
717       ValNodeAddStr(&query, 0, str_query);
718 
719       print_query_args(File, wqp_head, query);
720       ValNodeFreeData(query);
721 
722       fprintf(File, "\" usemap=#img_map border=0 ISMAP>\n");
723       fprintf(File, "\n");
724 
725       fprintf(File,"<map name=img_map>\n");
726     }
727     else if(dispform == 2){
728       PrintPDBNeighborTable(File, bpnp, pagenum);
729     }
730   }
731 
732   /* SetMMDBSubsetRep(bpnp, subset); */ /* ? */
733 
734   if(dispform == 1) DrawSummaryImgAndMap(query_bsp, cip, bpnp, imgsize, pagenum, ScoreLabel, DrawMap, AlgGraph, wqp_head, File);
735 
736   if(DrawMap){
737     if(dispform == 1 ){
738       fprintf(File, "</map>\n");
739       fprintf(File, "</body>\n");
740       fprintf(File, "</html>");
741     }
742     else if(dispform == 2){
743       fprintf(File, "</body>\n");
744       fprintf(File, "</html>");
745     }
746   }
747 
748 }
749 /*--------------------------*/
SendAlgGraphPage(BioseqPtr query_bsp,CdInfoPtr cip,BlastPDBNbPtr bpnp,Int2 imgsize,Int2 sortpara,Int2 ScoreLabel,Boolean DrawMap,Boolean AlgGraph,WWWQueryPtr wqp_head,FILE * File,NeighborInfoPtr nip,Int4 subject_str_gi,Int4 subject_sel_gi,Int2 pagenum,Int2 numpages)750 static Int4 SendAlgGraphPage(BioseqPtr query_bsp, CdInfoPtr cip, BlastPDBNbPtr bpnp, Int2 imgsize, Int2 sortpara, Int2 ScoreLabel, Boolean DrawMap, Boolean AlgGraph, WWWQueryPtr wqp_head, FILE *File, NeighborInfoPtr nip, Int4 subject_str_gi, Int4 subject_sel_gi, Int2 pagenum, Int2 numpages)
751 {
752   ValNodePtr query = NULL;
753   CharPtr str_query = NULL;
754   ValNodePtr csp = NULL;
755   CblastScoreDataPtr csdp = NULL;
756 
757   csp = bpnp->csp;
758   csdp = csp->data.ptrvalue;
759 
760   if(DrawMap){
761     printf("Content-type: text/html\n\n");
762     WWWPrintFileData(HEADFILE,  stdout);
763     PrintPageView(File, wqp_head, bpnp);
764 
765     fprintf(File, "<img src=\"%scblast.cgi?alg_graph=TRUE&viewmethod=1&viewmethod_option=HTML&hit=%d", CGIurl, subject_sel_gi);
766     str_query = StringSave("alg_graph");
767     ValNodeAddStr(&query, 0, str_query);
768     str_query = StringSave("viewmethod");
769     ValNodeAddStr(&query, 0, str_query);
770     str_query = StringSave("viewmethod_option");
771     ValNodeAddStr(&query, 0, str_query);
772     str_query = StringSave("hit");
773     ValNodeAddStr(&query, 0, str_query);
774     print_query_args(File, wqp_head, query);
775     ValNodeFreeData(query);
776     fprintf(File, "\" usemap=#img_map border=0 ISMAP>\n");
777     fprintf(File, "\n");
778 
779     fprintf(File,"<map name=img_map>\n");
780   }
781 
782   DrawSummaryImgAndMap(query_bsp, cip, bpnp, imgsize, pagenum, ScoreLabel, DrawMap, AlgGraph, wqp_head, File);
783 
784   if(DrawMap){
785     fprintf(File, "</map>\n");
786 /*  PrintNeighborTable(nip, subject_str_gi, pagenum, numpages); */
787     printscore(csdp, stdout);
788 /*  printf("</FORM>\n"); */
789 
790     printf ("</body>\n");
791     printf ("</html>");
792   }
793 
794 }
795 /*--------------------------*/
SendAlgInHtmlPage(SeqAnnotPtr sap,SeqEntryPtr sep,BlastPDBNbPtr bpnp,NeighborInfoPtr nip,Int4 subject_str_gi,WWWQueryPtr wqp,Int2 pagenum,Int2 numpages)796 static Int4 SendAlgInHtmlPage(SeqAnnotPtr sap, SeqEntryPtr sep, BlastPDBNbPtr bpnp, NeighborInfoPtr nip, Int4 subject_str_gi, WWWQueryPtr wqp, Int2 pagenum, Int2 numpages)
797 {
798   NcbiMimeAsn1Ptr   pvnNcbi = NULL;
799   BiostrucAlignSeqPtr basp = NULL;
800 
801   Uint4       size = 0;
802   BytePtr     buf = NULL;
803   Nlm_ByteStorePtr bsp = NULL;
804   AsnIoBSPtr  aibp = NULL;
805 
806 /*
807   FloatHi      evalue;
808   Int4         number;
809   FloatHi      bit_score;
810   Int4         score;
811 */
812   Uint4                 uCAVoptions = 0;
813   Uint4  CAV_return = 0;
814 
815   ValNodePtr csp = NULL;
816   CblastScoreDataPtr csdp = NULL;
817 
818   csp = bpnp->csp;
819   csdp = csp->data.ptrvalue;
820 
821   basp = BiostrucAlignSeqNew();
822   basp->sequences = sep;
823   basp->seqalign = sap;
824 
825   pvnNcbi = ValNodeNew(NULL);
826   pvnNcbi->choice = NcbiMimeAsn1_alignseq;
827   pvnNcbi->data.ptrvalue = basp;
828 
829   bsp = Nlm_BSNew(1024);
830   aibp = AsnIoBSOpen("wb", bsp);
831   if (!bsp || !aibp) {
832       printf("Cblast Error:AsnIoBS creation failed.\n"); return 0;
833   }
834 
835   if (!(NcbiMimeAsn1AsnWrite(pvnNcbi, aibp->aip, NULL)))  {
836       printf("Cblast Error:C object -> AsnInBS failed.\n");
837   }
838 
839   AsnIoFlush(aibp->aip);
840   AsnIoBSClose(aibp); aibp = NULL;
841 
842   size = Nlm_BSLen(bsp);
843   buf = MemNew(size);
844   if (!buf) {
845       printf("Cblast Error: buf allocation failed\n"); return 0;
846   }
847 
848   Nlm_BSSeek(bsp, 0, 0);
849   if (Nlm_BSRead(bsp, buf, size) != size) {
850       printf("Cblast Error: AsnIoBS -> buf failed\n"); return 0;
851   }
852 
853   Nlm_BSFree(bsp); bsp = NULL;
854 
855   printf("Content-type: text/html\n\n");
856 
857   WWWPrintFileData(HEADFILE,  stdout);
858 
859   PrintPageView(stdout, wqp, bpnp);
860 
861   uCAVoptions = CAV_HTML;
862   uCAVoptions |= CAV_SHOW_IDENTITY;
863   CAV_return = CAV_DisplayMultiple(buf, uCAVoptions, 60, 0.0, NULL, 0, NULL);
864 
865 /*
866   GetScoreAndEvalue(sap->data, &score, &bit_score, &evalue, &number);
867 */
868   printscore(csdp, stdout);
869 
870 /*PrintNeighborTable(nip, subject_str_gi, pagenum, numpages); */
871 
872   printf ("</body>\n");
873   printf ("</html>");
874 
875   MemFree(buf);
876   pvnNcbi->data.ptrvalue = NULL;
877   NcbiMimeAsn1Free(pvnNcbi);
878 
879   return 0;
880 }
881 /*---------------*/
SendMimePage(SeqAnnotPtr sap,SeqEntryPtr sep,Int4 gi,ValNodePtr sfp)882 int SendMimePage(SeqAnnotPtr sap, SeqEntryPtr sep, Int4 gi, ValNodePtr sfp)
883 {
884   char sql[128];
885   Boolean     isFromDatabase = TRUE;
886   unsigned mmdb_id = 0;
887   Int4 mol_id = 0;
888   MoleculeGraphPtr mgp = NULL;
889   SeqIdPtr sip = NULL;
890 
891   AsnIoPtr aip = NULL;
892   NcbiMimeAsn1Ptr mime;
893   BiostrucSeqsPtr bssp = NULL;
894   BiostrucPtr bsp = NULL;
895   Boolean success = FALSE;
896 
897   SnpFeatureInfoPtr sfipThis = NULL;
898   Cn3dUserAnnotationsPtr cuasp =NULL;
899   Cn3dStyleDictionaryPtr csdp = NULL;
900 
901 /*
902   sprintf(sql,"select max(mmdbId) from GiDomMap where gi = %d",gi);
903   mmdb_id = constructSingleVastIntValue(sql);
904 */
905   mmdb_id = constructMmdbIdForGi(gi);
906 
907   if(mmdb_id <=0)
908   {
909     printf("Error: mmdb_id = %d after calling \"%s\".",mmdb_id,sql);
910     exit(0);
911   }
912   bsp = (BiostrucPtr) openBSP(mmdb_id, ONECOORDATOM, MaxModels, FALSE, FALSE, FALSE, &isFromDatabase, MMDBDirPath);
913   if (bsp == NULL) {
914     printf("Content-type: text/html\r\n\r\n");
915     printf("<h2>Error</h2>\n");
916     printf("Structure with UID = %ld failed to fetch on Server<p>\n", (long)mmdb_id);
917     exit(0);
918   }
919 
920   bssp = BiostrucSeqsNew();
921   bssp->structure = bsp;
922   ValNodeLink(&(bssp->sequences), sep);
923 
924   SapMSInvert(sap);
925   bssp->seqalign = sap;
926 
927   if(sfp){
928     mgp = bsp->chemical_graph->molecule_graphs;
929     while(mgp){
930       sip = mgp->seq_id;
931       while(sip){
932         if(sip->choice = SEQID_GI){
933           if(sip->data.intvalue == gi) {
934             mol_id = mgp->id;
935             break;
936           }
937         }
938         sip = sip->next;
939       }
940       mgp = mgp->next;
941     }
942 
943     csdp = (Cn3dStyleDictionaryPtr) MakeCn3dStyleDicForSNP(sfp);
944     bssp->style_dictionary = csdp;
945 
946     cuasp = (Cn3dUserAnnotationsPtr) MakeUserAnnotForSNP(sfp, mmdb_id, mol_id);
947     bssp->user_annotations = cuasp;
948   }
949   else {
950     csdp = Cn3dStyleDictionaryNew();
951     csdp->global_style = (Cn3dStyleSettingsPtr) GetDefaultCn3DStyleSettings();
952     csdp->style_table = NULL;
953     bssp->style_dictionary = csdp;
954   }
955 
956   mime = (NcbiMimeAsn1Ptr) ValNodeNew(NULL);
957   mime->choice = NcbiMimeAsn1_strucseqs;
958   mime->data.ptrvalue=bssp;
959 
960   printf ("Content-type: chemical/ncbi-asn1-binary\r\n\r\n");
961 /*aip = AsnIoNew(ASNIO_BIN_OUT, stdout, NULL, NULL, NULL);     */
962   aip = AsnIoNew(ASNIO_TEXT_OUT, stdout, NULL, NULL, NULL);
963   if(!NcbiMimeAsn1AsnWrite(mime, aip, NULL)) printf("NcbiMimeAsn1AsnWrite failed!\n");
964   AsnIoFlush(aip);
965   aip = AsnIoClose(aip);
966 
967   mime->data.ptrvalue=NULL ;
968   NcbiMimeAsn1Free(mime);
969 
970   return 1;
971 }
972 /*--------------------*/
SendAsnPage(SeqAnnotPtr sap,SeqEntryPtr sep,Int4 gi,ValNodePtr sfp,Char DispOpt)973 int SendAsnPage(SeqAnnotPtr sap, SeqEntryPtr sep, Int4 gi, ValNodePtr sfp, Char DispOpt)
974 {
975 
976   char sql[128];
977   Boolean     isFromDatabase = TRUE;
978   long mmdb_id = 0;
979   Int4 mol_id = 0;
980   MoleculeGraphPtr mgp = NULL;
981   SeqIdPtr sip = NULL;
982 
983   AsnIoPtr aip = NULL;
984   NcbiMimeAsn1Ptr mime;
985   BiostrucSeqsPtr bssp = NULL;
986   BiostrucPtr bsp = NULL;
987   Boolean success = FALSE;
988 
989   SnpFeatureInfoPtr sfipThis = NULL;
990   Cn3dUserAnnotationsPtr cuasp =NULL;
991   Cn3dStyleDictionaryPtr csdp = NULL;
992 
993 /*
994   sprintf(sql,"select max(mmdbId) from GiDomMap where gi = %d",gi);
995   mmdb_id = constructSingleVastIntValue(sql);
996 */
997   mmdb_id = constructMmdbIdForGi(gi);
998 
999   if(mmdb_id <=0)
1000   {
1001     printf("Error: mmdb_id = %d after calling \"%s\".",mmdb_id,sql);
1002     exit(0);
1003   }
1004   bsp = (BiostrucPtr) openBSP(mmdb_id, ONECOORDATOM, MaxModels, TRUE, FALSE, FALSE, &isFromDatabase, MMDBDirPath);
1005   if (bsp == NULL) {
1006     printf("Content-type: text/html\r\n\r\n");
1007     printf("<h2>Error</h2>\n");
1008     printf("Structure with UID = %ld failed to fetch on Server<p>\n", (long) mmdb_id);
1009     exit(0);
1010   }
1011 
1012   bssp = BiostrucSeqsNew();
1013   bssp->structure = bsp;
1014   ValNodeLink(&(bssp->sequences), sep);
1015 
1016   SapMSInvert(sap);
1017   bssp->seqalign = sap;
1018 
1019   if(sfp){
1020     mgp = bsp->chemical_graph->molecule_graphs;
1021     while(mgp){
1022       sip = mgp->seq_id;
1023       while(sip){
1024         if(sip->choice = SEQID_GI){
1025           if(sip->data.intvalue == gi) {
1026             mol_id = mgp->id;
1027             break;
1028           }
1029         }
1030         sip = sip->next;
1031       }
1032       mgp = mgp->next;
1033     }
1034 
1035     csdp = (Cn3dStyleDictionaryPtr) MakeCn3dStyleDicForSNP(sfp);
1036     bssp->style_dictionary = csdp;
1037 
1038     cuasp = (Cn3dUserAnnotationsPtr) MakeUserAnnotForSNP(sfp, mmdb_id, mol_id);
1039     bssp->user_annotations = cuasp;
1040   }
1041   else {
1042 /*
1043     csdp = Cn3dStyleDictionaryNew();
1044     csdp->global_style = (Cn3dStyleSettingsPtr) GetDefaultCn3DStyleSettings();
1045     csdp->style_table = NULL;
1046     bssp->style_dictionary = csdp;
1047 */
1048   }
1049 
1050   mime = (NcbiMimeAsn1Ptr) ValNodeNew(NULL);
1051   mime->choice = NcbiMimeAsn1_strucseqs;
1052   mime->data.ptrvalue=bssp;
1053 
1054   if(DispOpt == 'c'){
1055      printf ("Content-type: chemical/ncbi-asn1-binary\r\n\r\n");
1056      aip = AsnIoNew(ASNIO_BIN_OUT, stdout, NULL, NULL, NULL);
1057   }
1058   else if(DispOpt == 'a') {
1059      printf("Content-type: application/octet-stream\r\n\r\n");
1060      aip = AsnIoNew(ASNIO_BIN_OUT, stdout, NULL, NULL, NULL);
1061   }
1062   else if(DispOpt == 'p') {
1063     aip = AsnIoNew(ASNIO_TEXT_OUT, stdout, NULL, NULL, NULL);
1064     printf ("Content-type: text/html\r\n\r\n");
1065     printf ("<HTML><pre>\n");
1066   }
1067 
1068   NcbiMimeAsn1AsnWrite(mime, aip, NULL);
1069   AsnIoFlush(aip);
1070   AsnIoReset(aip);
1071   aip = AsnIoClose(aip);
1072 
1073   if(DispOpt == 'p')printf ("</PRE></HTML>\r\n");
1074   mime->data.ptrvalue=NULL ;
1075   NcbiMimeAsn1Free(mime);
1076 
1077   return 1;
1078 }
1079 /*-----------------*/
Main()1080 Int2 Main()
1081 {
1082 
1083   Boolean       Netscape2_OK = FALSE;
1084   WWWErrorCode      error;
1085 
1086   Int4    IndexArgs = -1, indx = 0, NumEntries = 0;
1087   Int4    iBytes = 0;
1088   Int2    imagsize = 0;
1089   int     algseq = 0;
1090 
1091   Char DispOpt;
1092   CharPtr Cmd;
1093   CharPtr pcName = NULL, pcThis = NULL;
1094 
1095   CdInfoPtr cip = NULL;
1096   SeqAnnotPtr sap_dart = NULL;
1097   SeqAnnotPtr sap_set = NULL, sap_subject_pair, sap_pdb_pair = NULL;
1098   SeqAlignPtr salp = NULL;
1099   DenseSegPtr dsp = NULL;
1100   BioseqPtr query_bsp = NULL, cdquery_bsp = NULL, subject_bsp = NULL;
1101   SeqIdPtr sipQuery=NULL, sip=NULL;
1102   ObjectIdPtr              oidp;
1103   SeqEntryPtr sep = NULL;
1104   Int4 query_gi = 0, subject_rep_gi = 0, subject_sel_gi = 0, subject_str_gi = 0;
1105   Int2 status = -3;
1106 
1107   BLAST_OptionsBlkPtr option = NULL;
1108   Int4 db_length = 90077593;    /* default */
1109   Int4 expect_value = 10;   /* default */
1110   Char blastinfo[PATH_MAX];
1111 
1112   BlastPDBNbPtr bpnp = NULL;
1113   Boolean ForGenome = FALSE, ForSNP = FALSE, DrawMap = FALSE, QueryDump = FALSE, DrawCdMap = TRUE;
1114 
1115   Boolean DrawBlastPDBNbSummary = FALSE, DrawBlastPDBNbSummaryOneGroup = FALSE, DrawBlastPDBNbSummaryOnePairOneHSP = FALSE, DrawBlastPDBNbSummaryOnePairMultiHSP = FALSE;
1116   Boolean NoHspArg = FALSE;
1117 
1118   NeighborInfoPtr nip = NULL;
1119   NeighborInfoDataPtr nidp_sel= NULL;
1120   ReadDBFILEPtr   rdfp=NULL;
1121   FILE *fp_nrpdb;
1122 
1123   WWWQueryPtr wqp_head = NULL;
1124   WWWQueryDataPtr wqdp = NULL;
1125   Char str[1024];
1126   Int2 query_num = 0;
1127 
1128   Int4 snp_pos = 0, snp_count = 0;
1129   ValNodePtr sfp = NULL, sfpThis = NULL; /*data.ptrvalue is snp feature pointer*/
1130   SnpFeatureInfoPtr sfipThis = NULL;
1131 
1132   Int2 ScoreLabel = 1;
1133   Int2 pagenum = 1, numpages = 0, subset = 1, sortpara = 1, dispform = 1, blastview=0;
1134   Int2 hsp = 0;
1135   SeqIdPtr subject_pdbid = NULL;
1136   ValNodePtr descr = NULL;
1137 
1138   logFilePtr = fopen("mylog","w");
1139 
1140   CblastSrvGetParams();
1141   CblastSrvInit();
1142 
1143   putenv("NCBI=/netopt/ncbi_tools");
1144   putenv("SYBASE=/netopt/Sybase/clients/current");
1145 /*    putenv("BLASTDB=/net/fridge/vol/export/blast/db/blast"); */
1146   putenv("BLASTDB=/blast/db/blast");
1147   if(!(rdfp = readdb_new("nr", TRUE))){
1148     printf("Content-type: text/html\r\n\r\n");
1149     printf("<h2>Error</h2>\n");
1150     printf("readdb failed!\n");
1151     return;
1152   }
1153 
1154   if((error = WWWGetArgs(&info)) != WWWErrOk) {
1155       printf("Content-type: text/html\r\n\r\n");
1156       printf("<H2>CBLAST Error</H2>\n Failed to Process Posting - Check your GET/POST syntax\n");
1157       exit(0);
1158   }
1159 
1160    IndexArgs = -1;
1161    if((IndexArgs = WWWFindName(info, "blast_RID")) >= 0){
1162      pcThis = WWWGetValueByIndex(info,IndexArgs);
1163      CblastAddWWWQueryData("blast_RID", pcThis, &query_num, &wqp_head);
1164      status = QBlastGetResults(pcThis, &sap_set, &query_bsp, NULL, NULL, NULL, NULL);
1165      sip=query_bsp->id;
1166      sipQuery=(SeqIdPtr) ValNodeNew(NULL);
1167      sipQuery->choice = SEQID_LOCAL;
1168      oidp = ObjectIdNew();
1169      oidp->str = StringSave("query");
1170      sipQuery->data.ptrvalue = oidp;
1171      sipQuery->next=NULL;
1172      query_bsp->id = SeqIdDup(sipQuery);
1173      sip = SeqIdFree(sip);
1174      if(!sap_set){
1175         printf("Content-type: text/html\r\n\r\n");
1176         printf("<h2>Error</h2>\n");
1177         printf("Can not retrieve data with RID: %s!\n", pcThis);
1178         exit(0);
1179      }
1180      salp=sap_set->data;
1181      while(salp){
1182        dsp = salp->segs;
1183        sip=dsp->ids;
1184        dsp->ids = SeqIdDup(sipQuery);
1185        dsp->ids->next=sip->next;
1186        sip->next=NULL;
1187        sip = SeqIdFree(sip);
1188 
1189        salp = salp->next;
1190      }
1191      sipQuery=SeqIdFree(sipQuery);
1192 /*
1193 {
1194 AsnIoPtr aip = NULL;
1195 aip = AsnIoOpen("test4.sap", "w");
1196 SeqAnnotAsnWrite(sap_set, aip, NULL);
1197 aip = AsnIoClose(aip);
1198 aip = AsnIoOpen("test4.bsp", "w");
1199 BioseqAsnWrite(query_bsp, aip, NULL);
1200 aip = AsnIoClose(aip);
1201 }
1202 */
1203 
1204      IndexArgs = -1;
1205      if((IndexArgs = WWWFindName(info, "blast_CD_RID")) >= 0){
1206        pcThis = WWWGetValueByIndex(info,IndexArgs);
1207        if(strcmp(pcThis, "0")==0) DrawCdMap = FALSE;
1208        else {
1209          queryrid = StringSave(pcThis);
1210          CblastAddWWWQueryData("blast_CD_RID", pcThis, &query_num, &wqp_head);
1211          status = QBlastGetResults(pcThis, &sap_dart, &cdquery_bsp, NULL, NULL, NULL, NULL);
1212          if(sap_dart != NULL) DrawCdMap = TRUE;
1213          else DrawCdMap = FALSE;
1214        }
1215      }
1216      else DrawCdMap = FALSE;
1217 
1218 /*
1219 {
1220 AsnIoPtr aip = NULL;
1221 aip = AsnIoOpen("test_bacteria.sap", "w");
1222 SeqAnnotAsnWrite(sap_set, aip, NULL);
1223 aip = AsnIoClose(aip);
1224 }
1225 */
1226 
1227 /*
1228 {
1229 SeqAnnotPtr sap_dart = NULL;
1230 AsnIoPtr aip = NULL;
1231 aip = AsnIoOpen("test3.sap", "w");
1232 status = QBlastGetResults("1035554681-021776-25378", &sap_set, &query_bsp, NULL, NULL, NULL, NULL);
1233 SeqAnnotAsnWrite(sap_set, aip, NULL);
1234 aip = AsnIoClose(aip);
1235 aip = AsnIoOpen("test2.bsp", "w");
1236 BioseqAsnWrite(query_bsp, aip, NULL);
1237 aip = AsnIoClose(aip);
1238 
1239 if(Dart_Gi2Sap(dartcon, 10728126, &sap_dart, NULL)&&(sap_dart != NULL)){
1240   aip = AsnIoOpen("dart.sap", "w");
1241   SeqAnnotAsnWrite(sap_dart, aip, NULL);
1242   aip = AsnIoClose(aip);
1243 }
1244 
1245 }
1246 */
1247 /*
1248 {
1249 AsnIoPtr aip = NULL;
1250 aip = AsnIoOpen("test2.sap", "r");
1251 sap_set = SeqAnnotAsnRead(aip, NULL);
1252 aip = AsnIoClose(aip);
1253 aip = AsnIoOpen("test2.bsp", "r");
1254 query_bsp = BioseqAsnRead(aip, NULL);
1255 aip = AsnIoClose(aip);
1256 aip = AsnIoOpen("dart.sap", "r");
1257 sap_dart = SeqAnnotAsnRead(aip, NULL);
1258 aip = AsnIoClose(aip);
1259 }
1260 */
1261      IndexArgs = -1;
1262      if((IndexArgs = WWWFindName(info, "blast_rep_gi")) >= 0){
1263        pcThis = WWWGetValueByIndex(info,IndexArgs);
1264        subject_rep_gi = atoi(pcThis);
1265 
1266        sprintf(str, "%d", subject_rep_gi);
1267        CblastAddWWWQueryData("blast_rep_gi", str, &query_num, &wqp_head);
1268      }
1269 
1270      IndexArgs = -1;
1271      if((IndexArgs = WWWFindName(info, "hsp")) >= 0){
1272        pcThis = WWWGetValueByIndex(info,IndexArgs);
1273        CblastAddWWWQueryData("hsp", pcThis, &query_num, &wqp_head);
1274        hsp = atoi(pcThis);
1275           /* blast service sends hsp=0 */
1276      }
1277      else {
1278        hsp = 1;
1279      }
1280 
1281      IndexArgs = -1;
1282      if((IndexArgs = WWWFindName(info, "blast_view")) >= 0){
1283        pcThis = WWWGetValueByIndex(info,IndexArgs);
1284        if(strcmp(pcThis, "overview")==0) {
1285          blastview = 1;
1286          DrawBlastPDBNbSummary = TRUE;
1287          if(hsp == 0) hsp = 1;
1288        }
1289        else if(strcmp(pcThis, "onegroup")==0) {
1290          blastview = 2;
1291          DrawBlastPDBNbSummaryOneGroup = TRUE;
1292          if(hsp == 0) hsp = 1;
1293        }
1294        else if(strcmp(pcThis, "onepair")==0) {
1295          blastview = 3;
1296          if(hsp == 0){
1297            if(MultiHSP(sap_set, subject_rep_gi)) DrawBlastPDBNbSummaryOnePairMultiHSP = TRUE;
1298            else {
1299              DrawBlastPDBNbSummaryOnePairOneHSP = TRUE;
1300              hsp = 1;
1301            }
1302          }
1303          else DrawBlastPDBNbSummaryOnePairOneHSP = TRUE;
1304        }
1305        CblastAddWWWQueryData("blast_view", pcThis, &query_num, &wqp_head);
1306      }
1307      else DrawBlastPDBNbSummary = TRUE;
1308 
1309      IndexArgs = -1;
1310      if((IndexArgs = WWWFindName(info, "hit")) >= 0){
1311        pcThis = WWWGetValueByIndex(info,IndexArgs);
1312        subject_sel_gi = atoi(pcThis);
1313        CblastAddWWWQueryData("hit", pcThis, &query_num, &wqp_head);
1314        if(subject_sel_gi == 0) subject_sel_gi = subject_rep_gi;
1315      }
1316      else subject_sel_gi = subject_rep_gi;
1317      subject_str_gi = subject_sel_gi;
1318 
1319      if(subject_sel_gi > 0) {
1320        subject_bsp = CblastGetBioseqWithGi(subject_sel_gi, rdfp);
1321      }
1322 
1323      if(subject_sel_gi > 0) {
1324        sap_subject_pair = (SeqAnnotPtr)GetAlgForSubjectPairPerHSP(sap_set, subject_rep_gi, hsp);
1325 /*     sap_subject_pair = (SeqAnnotPtr)GetAlgForSubjectPair(sap_set, subject_rep_gi);  */
1326        if(sap_subject_pair) sap_pdb_pair = (SeqAnnotPtr) CblastGetSapPdbPair(sap_subject_pair, subject_bsp);
1327      }
1328 
1329    }
1330 
1331    IndexArgs = -1;
1332    if((IndexArgs = WWWFindName(info, "master_gi")) >= 0){
1333      ForGenome = TRUE;
1334      pcThis = WWWGetValueByIndex(info,IndexArgs);
1335      query_gi = atoi(pcThis);
1336      sprintf(str, "%d", query_gi);
1337      CblastAddWWWQueryData("master_gi", str, &query_num, &wqp_head);
1338 
1339      IndexArgs = -1;
1340      if((IndexArgs = WWWFindName(info, "neighbor_gi")) >= 0){
1341        pcThis = WWWGetValueByIndex(info,IndexArgs);
1342        subject_rep_gi = atoi(pcThis);
1343        subject_str_gi = subject_rep_gi;
1344        sprintf(str, "%d", subject_rep_gi);
1345        CblastAddWWWQueryData("neighbor_gi", str, &query_num, &wqp_head);
1346      }
1347      else {
1348        printf("Content-type: text/html\r\n\r\n");
1349        printf("<h2>Error</h2>\n");
1350        printf("CBLAST: neighbor GI should be given to identify the pairwise seqalign!\n");
1351        return;
1352      }
1353 
1354      IndexArgs = -1;
1355      if((IndexArgs = WWWFindName(info, "hit")) >= 0){
1356        pcThis = WWWGetValueByIndex(info,IndexArgs);
1357        subject_sel_gi = atoi(pcThis);
1358      }
1359      else subject_sel_gi = subject_rep_gi;
1360 
1361      option = BLASTOptionNew("blastp", TRUE);
1362      GetAppParam("cblast", "BLASTOPTION", "NRSize", "", blastinfo, PATH_MAX);
1363      if(blastinfo[0] == '\0') {
1364         ErrPostEx(SEV_ERROR, 0, 0, "CBLAST config file \n BLASTOPTION section has no NRSize ...\n Default databasesize will be used\n");
1365      }
1366      else {
1367         sscanf(blastinfo, "%d", &db_length);
1368         option->db_length = db_length;
1369      }
1370      GetAppParam("cblast", "BLASTOPTION", "CutOff", "", blastinfo, PATH_MAX);
1371      if(blastinfo[0] != '\0') {
1372         sscanf(blastinfo, "%d", &expect_value);
1373         option->expect_value = (FloatHi) expect_value;     /* default e-value 10 */
1374      }
1375                        /* one-pass non-multiple hits search with low threshold */
1376 
1377      option->two_pass_method  = FALSE;
1378      option->multiple_hits_only  = FALSE;
1379      option->threshold_second = 9;
1380 
1381      query_bsp = CblastGetBioseqWithGi(query_gi, rdfp);
1382      if(!query_bsp) {
1383         printf("Content-type: text/html\n\n");
1384         printf("<h2>CBLAST Error</h2>\n");
1385         printf("<h3>query sequence with gi number %d is not populated.\nContact %s</h3>\n", query_gi, MAILto);
1386      }
1387 
1388      subject_bsp = CblastGetBioseqWithGi(subject_sel_gi, rdfp);
1389      if(!subject_bsp) {
1390         printf("Content-type: text/html\n\n");
1391         printf("<h2>CBLAST Error</h2>\n");
1392         printf("<h3>subject sequence with gi number %d is not populated.\nContact %s</h3>\n", subject_rep_gi, MAILto);
1393      }
1394 
1395      salp = BlastTwoSequences(query_bsp, subject_bsp, "blastp", option);
1396      if(!salp) {
1397         printf("Content-type: text/html\n\n");
1398         printf("<h2>CBLAST Error</h2>\n");
1399         printf("<h3>Blast sequences with gi number %d and %d failed, no significant similarity found. \nContact %s</h3>\n", query_gi, subject_rep_gi, MAILto);
1400         return;
1401      }
1402      sap_subject_pair = SeqAnnotNew();
1403      sap_subject_pair->type = 2;
1404      sap_subject_pair->data = salp;
1405      sap_pdb_pair = (SeqAnnotPtr) CblastGetSapPdbPair(sap_subject_pair, subject_bsp);
1406           /* do pdb-id replacement ? */
1407 
1408 /*******************************/
1409          /* to check SNP feature request */
1410      snp_count = 0;
1411      ForSNP = FALSE;
1412      if((indx = WWWFindName(info, "snp_pos")) >= 0) {
1413        ForSNP = TRUE;
1414        NumEntries = WWWGetNumEntries(info);
1415        for(IndexArgs = 0; IndexArgs < NumEntries; IndexArgs++){
1416          pcName = WWWGetNameByIndex(info,  IndexArgs);
1417          pcThis = WWWGetValueByIndex(info, IndexArgs);
1418          if(StrICmp(pcName, "snp_pos") == 0){
1419            if(isdigit(pcThis[0])){
1420              snp_pos = (Int4) atoi(pcThis);
1421              snp_count++;
1422              sfipThis = (SnpFeatureInfoPtr) MemNew(sizeof(SnpFeatureInfo));
1423              sfipThis->pos = snp_pos;
1424              sfipThis->feature_id = snp_count;
1425              sfipThis->color = 1;
1426              sfipThis->id = 0;
1427              ValNodeAddPointer(&sfp, snp_count, (SnpFeatureInfoPtr) sfipThis);
1428            }
1429          }
1430        }
1431 
1432        sfpThis = sfp;
1433        for(IndexArgs = 0; IndexArgs < NumEntries; IndexArgs++){
1434          pcName = WWWGetNameByIndex(info,  IndexArgs);
1435          pcThis = WWWGetValueByIndex(info, IndexArgs);
1436          if(StrICmp(pcName, "snp_title") == 0){
1437            if(sfpThis != NULL){
1438              sfipThis = sfpThis->data.ptrvalue;
1439              sfipThis->title = StringSave(pcThis);
1440              sfpThis = sfpThis->next;
1441            }
1442          }
1443        }
1444 
1445        sfpThis = sfp;
1446        for(IndexArgs = 0; IndexArgs < NumEntries; IndexArgs++){
1447          pcName = WWWGetNameByIndex(info,  IndexArgs);
1448          pcThis = WWWGetValueByIndex(info, IndexArgs);
1449          if(StrICmp(pcName, "snp_descr") == 0){
1450            if(sfpThis != NULL){
1451              sfipThis = sfpThis->data.ptrvalue;
1452              sfipThis->descr = StringSave(pcThis);
1453              sfpThis = sfpThis->next;
1454            }
1455          }
1456        }
1457        sfpThis = sfp;
1458        for(IndexArgs = 0; IndexArgs < NumEntries; IndexArgs++){
1459          pcName = WWWGetNameByIndex(info,  IndexArgs);
1460          pcThis = WWWGetValueByIndex(info, IndexArgs);
1461          if(StrICmp(pcName, "snp_color") == 0){
1462            if(sfpThis != NULL){
1463              sfipThis = sfpThis->data.ptrvalue;
1464              sfipThis->color = (Int4) atoi(pcThis);
1465              sfpThis = sfpThis->next;
1466            }
1467          }
1468        }
1469 
1470        sfpThis = sfp;
1471        for(IndexArgs = 0; IndexArgs < NumEntries; IndexArgs++){
1472          pcName = WWWGetNameByIndex(info,  IndexArgs);
1473          pcThis = WWWGetValueByIndex(info, IndexArgs);
1474          if(StrICmp(pcName, "snp_id") == 0){
1475            if(sfpThis != NULL){
1476              sfipThis = sfpThis->data.ptrvalue;
1477              sfipThis->id = (Int4) atoi(pcThis);
1478              sfpThis = sfpThis->next;
1479            }
1480          }
1481        }
1482 
1483      }
1484 
1485 /* done with SNP features add */
1486 
1487 /*******************************/
1488    }
1489 
1490      /* to be modified */
1491 /*
1492    if(subject_rep_gi > 0 && DrawBlastPDBNbSummaryOnePairOneHSP){
1493      nip = GetRedundantPDBNeighborInfo(subject_rep_gi, rdfp);
1494      {  NeighborInfoPtr nipThis = NULL;
1495         Int2 count = 0;
1496         nipThis = nip;
1497         while(nipThis){
1498           count++;
1499           nipThis = nipThis->next;
1500         }
1501         count = count-1;
1502         numpages = (Int2) ((count - count%entry_page)/entry_page) + 1;
1503      }
1504 
1505      if(nip == NULL){
1506        printf("Content-type: text/html\r\n\r\n");
1507        printf("<h2>Error</h2>\n");
1508        printf("CBLAST: No PDB Neighbor Identified for gi %d!\n", subject_rep_gi);
1509        return;
1510      }
1511 
1512      nidp_sel = (NeighborInfoDataPtr)GetNIForSel(subject_sel_gi, nip);
1513      if(nidp_sel){
1514        sap_pdb_pair = ReplaceSeqIdForSeqAnnot(sap_subject_pair, nidp_sel->pdbid);
1515      }
1516      else {
1517        printf("Content-type: text/html\r\n\r\n");
1518        printf("<h2>Error</h2>\n");
1519        printf("CBLAST: No Representative info available!\n");
1520        return;
1521      }
1522 
1523      nip = (NeighborInfoPtr)GetRankedNeighborInfoFD(nip);
1524    }
1525 */
1526 
1527 /*
1528 {
1529 int i = 0;
1530 MapRowInfoPtr mrip = NULL;
1531 ValNodePtr mapinfo=NULL, maprow = NULL;
1532 CdNbInfoPtr *cnip = NULL;
1533 
1534 mapinfo = cip->mapinfo;
1535 while(mapinfo){
1536 printf("mapinfo->choice: %d\n", mapinfo->choice);
1537   maprow = mapinfo->data.ptrvalue;
1538   while(maprow){
1539     mrip = maprow->data.ptrvalue;
1540     printf("mrip: from %d to %d iColor: %d CdName %s PssmId %d\n", mrip->from, mrip->to, mrip->iColor, mrip->CdName, mrip->PssmId);
1541     maprow = maprow->next;
1542   }
1543   mapinfo = mapinfo->next;
1544 }
1545 
1546 cnip = cip->cnip;
1547 for(i=0; i<cip->cd_num; i++){
1548 printf("%s\n", cnip[i]->CdName);
1549 printf("CdName: %s bRep: %d iClust: %d iMaprow: %d from: %d to: %d\n", cnip[i]->CdName, cnip[i]->bRep, cnip[i]->iClust, cnip[i]->iMaprow, cnip[i]->from, cnip[i]->to);
1550 }
1551 
1552 }
1553 */
1554 
1555    IndexArgs = -1;
1556    if((IndexArgs = WWWFindName(info, "viewmethod")) >= 0){
1557      if((IndexArgs = WWWFindName(info, "viewmethod_option")) >= 0){
1558        pcThis = WWWGetValueByIndex(info,IndexArgs);
1559        if(!StrICmp(pcThis, "HTML")) {DispOpt = 'h'; DispOptChoice = 1;}
1560        else if(!StrICmp(pcThis, "Graphic")) {DispOpt = 'g'; DispOptChoice = 2;}
1561      }
1562      else {
1563        DispOpt = 'h'; DispOptChoice = 1;
1564      }
1565    }
1566    else if((IndexArgs = WWWFindName(info, "3d_viewmethod")) >= 0){
1567      if((IndexArgs = WWWFindName(info, "3d_viewmethod_option")) >= 0){
1568        pcThis = WWWGetValueByIndex(info,IndexArgs);
1569        if(!StrICmp(pcThis, "Cn3D")) {DispOpt = 'c'; DispOptChoice = 3;}
1570        else if(!StrICmp(pcThis, "SAVE_ASN1")) {DispOpt = 'a'; DispOptChoice = 4;}
1571        else if(!StrICmp(pcThis, "PRINT_ASN1")) {DispOpt = 'p'; DispOptChoice = 5;}
1572      }
1573      else {
1574        DispOpt = 'c'; DispOptChoice = 3;
1575      }
1576    }
1577    else if(ForSNP || ForGenome){
1578      DispOpt = 'c';
1579      DispOptChoice = 3;
1580    }
1581    else {
1582      DispOpt = 'g';
1583      DispOptChoice = 2;
1584    }
1585 
1586 
1587    IndexArgs = -1;
1588    if((IndexArgs = WWWFindName(info, "cmd")) >= 0){
1589      pcThis = WWWGetValueByIndex(info,IndexArgs);
1590      Cmd = StringSave(pcThis);
1591    }
1592 
1593    IndexArgs = -1;
1594    if((IndexArgs = WWWFindName(info, "query_dump")) >= 0){
1595      QueryDump = TRUE;
1596    }
1597    else QueryDump = FALSE;
1598 
1599    IndexArgs = -1;
1600    if((IndexArgs = WWWFindName(info, "doclistpage")) >= 0){
1601      pcThis = WWWGetValueByIndex(info,IndexArgs);
1602      pagenum = (Int2) atoi(pcThis);
1603    }
1604    else pagenum = 1;
1605 
1606    IndexArgs = -1;
1607    if((IndexArgs = WWWFindName(info, "summary_graph")) >= 0){
1608      DrawMap = FALSE;
1609    } else DrawMap = TRUE;
1610 
1611    IndexArgs = -1;
1612    if((IndexArgs = WWWFindName(info, "subset")) >= 0){
1613      pcThis = WWWGetValueByIndex(info,IndexArgs);
1614      subset = (Int2) atoi(pcThis);
1615    } else subset = 1;
1616 
1617    IndexArgs = -1;
1618    if((IndexArgs = WWWFindName(info, "sortpara")) >= 0){
1619      pcThis = WWWGetValueByIndex(info,IndexArgs);
1620      sortpara = (Int2) atoi(pcThis);
1621    } else sortpara = 1;
1622    ScoreLabel = sortpara;
1623 
1624    IndexArgs = -1;
1625    if((IndexArgs = WWWFindName(info, "dispform")) >= 0){
1626      pcThis = WWWGetValueByIndex(info,IndexArgs);
1627      dispform = (Int2) atoi(pcThis);
1628    } else dispform = 1;
1629 
1630    if(DrawBlastPDBNbSummary){
1631      bpnp = (BlastPDBNbPtr)GetBlastPDBNbInfo(sap_set, 0, 0, rdfp, "ALL_PDB");
1632 /*     bpnp = (BlastPDBNbPtr)GetBlastPDBNbInfo(sap_set, 0, 0, rdfp, "OneEachGroup", "DrawBlastPDBNbSummary");*/
1633    }
1634    else if(DrawBlastPDBNbSummaryOneGroup){
1635      bpnp = (BlastPDBNbPtr)GetBlastPDBNbInfo(sap_set, subject_rep_gi, 0, rdfp, "ALLOneGroup");
1636    }
1637    else if(DrawBlastPDBNbSummaryOnePairMultiHSP){
1638      bpnp = (BlastPDBNbPtr)GetBlastPDBNbInfo(sap_set, subject_rep_gi, subject_sel_gi, rdfp, "OnePairMultiHSP");
1639    }
1640    else if(DrawBlastPDBNbSummaryOnePairOneHSP){
1641         /* case blastview assuming subject_sel_gi > 0*/
1642      subject_pdbid = (SeqIdPtr) CblastGetPDBIdFromBioseq(subject_bsp);
1643      bpnp = (BlastPDBNbPtr)BlastPDBNbInfoBuild(sap_subject_pair, subject_rep_gi, subject_sel_gi, subject_pdbid, rdfp);
1644      subject_pdbid = SeqIdFree(subject_pdbid);
1645    }
1646    if(bpnp) {
1647      bpnp->query_length = query_bsp->length;
1648      if(query_bsp->descr){
1649        descr = query_bsp->descr;
1650        while(descr){
1651          if(descr->choice == Seq_descr_title) {
1652            bpnp->query_title = StringSave(descr->data.ptrvalue);
1653            break;
1654          }
1655          descr = descr->next;
1656        }
1657      }
1658      SetMMDBSubsetRep(bpnp, subset); /* ? */
1659      bpnp = (BlastPDBNbPtr)CblastIndexHSP(bpnp);
1660 
1661      EntrezFini();
1662      ReadDBBioseqFetchEnable("cblast", "nr", FALSE, TRUE);
1663      bpnp = (BlastPDBNbPtr)CblastGetAlignScoreParam(bpnp);
1664      ReadDBBioseqFetchDisable();
1665 
1666      bpnp = (BlastPDBNbPtr)SortBlastPDBNb(bpnp, sortpara);
1667      bpnp = (BlastPDBNbPtr)CblastIndexPage(bpnp);
1668    }
1669 
1670 /*
1671 {
1672 ValNodePtr csp = NULL, csip = NULL;
1673 CblastSeqInfoDataPtr csidp = NULL;
1674 CblastScoreDataPtr csdp = NULL;
1675 PDBSeqIdPtr pdb_sip = NULL;
1676 Char str_score[120];
1677 
1678 csip = bpnp->csip;
1679 csp = bpnp->csp;
1680 while(csip){
1681   csidp = csip->data.ptrvalue;
1682   csdp = csp->data.ptrvalue;
1683   pdb_sip = csidp->pdbid->data.ptrvalue;
1684 printf("rep_gi: %d mol: %s chain: %c\n", csidp->gi, pdb_sip->mol, pdb_sip->chain);
1685   print_bitscore(csdp->bit_score, str_score);
1686 printf("bit_score: %s\n", str_score);
1687   print_evalue(csdp->evalue, str_score);
1688 printf("evalue: %s\n", str_score);
1689 printf("length: %d\n", csdp->length);
1690   csip = csip->next;
1691   csp = csp->next;
1692 }
1693 }
1694 */
1695 
1696 
1697    if(DrawBlastPDBNbSummary || DrawBlastPDBNbSummaryOneGroup || DrawBlastPDBNbSummaryOnePairMultiHSP || DrawBlastPDBNbSummaryOnePairOneHSP || DispOpt == 'g'){
1698      if(DrawCdMap){
1699        cip = (CdInfoPtr) CdInfoNew();
1700        cip->sap = AsnIoMemCopy(sap_dart, (AsnReadFunc)SeqAnnotAsnRead, (AsnWriteFunc)SeqAnnotAsnWrite);
1701        cip->query_length = query_bsp->length;
1702        cip = (CdInfoPtr) FillCdInfo(cip, dartcon);
1703      }
1704      else cip = NULL;
1705 
1706      maxseqlen = query_bsp->length;
1707 
1708      algseq = GetSelectedAlgSeqNum(bpnp, pagenum);
1709        /* if the pagenum out of sinchronization due to change of subdataset, set it back as 1 */
1710      if(algseq == 0){
1711        pagenum = 1;
1712        algseq = GetSelectedAlgSeqNum(bpnp, pagenum);
1713      }
1714 
1715      if(DrawCdMap) imagsize = ConsDomStartY + cip->maprow_num*(CdMapRowSpace+FontBH) + algseq*(MapRowSpace + MapRowHeight) + 2*MapRowSpace + 2*FontBH + 20;
1716      else imagsize = ConsDomStartY + algseq*(MapRowSpace + MapRowHeight) + 2*MapRowSpace + 2*FontBH + 20;
1717    }
1718 
1719    if(QueryDump){
1720      CblastDumpQuery(query_bsp, stdout);
1721    }
1722 /*
1723    else if(DispOpt == 'g') {
1724 
1725      IndexArgs = -1;
1726      if((IndexArgs = WWWFindName(info, "alg_graph")) >= 0){
1727        DrawMap = FALSE;
1728      } else DrawMap = TRUE;
1729 
1730      SendAlgGraphPage(query_bsp, cip, bpnp, imagsize, sortpara, ScoreLabel, DrawMap, TRUE, wqp_head, stdout, nip, subject_str_gi, subject_sel_gi, pagenum, numpages);
1731 
1732    }
1733 */
1734    else if(DispOpt == 'h') {
1735      sep = GetSeqEntry(query_bsp, subject_bsp);
1736      iBytes = SendAlgInHtmlPage(sap_pdb_pair, sep, bpnp, nip, subject_str_gi, wqp_head, pagenum, numpages);
1737    }
1738    else if(DispOpt == 'c' || DispOpt == 'a' || DispOpt == 'p') {
1739      sep = GetSeqEntry(subject_bsp, query_bsp);
1740      iBytes = SendAsnPage(sap_pdb_pair, sep, subject_str_gi, sfp, DispOpt);
1741    }
1742    else if(DrawBlastPDBNbSummary || DrawBlastPDBNbSummaryOneGroup || DrawBlastPDBNbSummaryOnePairMultiHSP || DrawBlastPDBNbSummaryOnePairOneHSP){
1743      SendAlgSummaryGraphPage(query_bsp, cip, bpnp, imagsize, ScoreLabel, DrawMap, FALSE, subset, sortpara, dispform, pagenum, wqp_head, stdout, blastview);
1744 
1745    }
1746 
1747   if(bpnp) bpnp = (BlastPDBNbPtr) BlastPDBNbFree(bpnp);
1748   if(nip) nip = NeighborInfoFree(nip);
1749   if(cip) cip = (CdInfoPtr) CdInfoFree(cip);
1750 
1751   if(sep) sep = SeqEntryFree(sep);
1752   if(subject_bsp) subject_bsp = BioseqFree(subject_bsp);
1753   if(query_bsp) query_bsp = BioseqFree(query_bsp);
1754   if(cdquery_bsp) cdquery_bsp = BioseqFree(cdquery_bsp);
1755   if(sap_set) sap_set = SeqAnnotFree(sap_set);
1756   if(sap_dart) sap_dart = SeqAnnotFree(sap_dart);
1757   if(sap_pdb_pair) sap_pdb_pair = SeqAnnotFree(sap_pdb_pair);
1758   if(sap_subject_pair) sap_subject_pair = SeqAnnotFree(sap_subject_pair);
1759 
1760   CloseMMDBAPI();
1761   if (psfailed == TRUE) MMDBFini_FF();
1762   else MMDBFini_PS();
1763   Dart_Fini(dartcon);
1764   fflush(stdout);
1765   rdfp = readdb_destruct(rdfp);
1766 
1767   VastSrvFinish();
1768   MmdbSrvFinish();
1769   exit(0);
1770 
1771 }
1772