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: vastsrv.c
26 *
27 * Author: Christopher Hogue, Tom Madej
28 *
29 * Version Creation Date: 10 March 1998
30 *
31 * $Log: vastsrv.c,v $
32 * Revision 6.26 2000/12/06 20:58:53 lewisg
33 * change cn3d 2.5 string
34 *
35 * Revision 6.25 2000/06/23 22:35:58 lewisg
36 * get rid of hardcoded urls
37 *
38 * Revision 6.24 1999/10/14 14:03:27 zimmerma
39 * DZ: changed exit status to 0 when WWWargs is empty - see line 1402
40 * This was done to prevent error reports being generated by wrapper script.
41 *
42 * Revision 6.23 1999/10/13 20:15:56 zimmerma
43 * DZ: Removed use of temporary files - html output redirected to stdout
44 *
45 * Revision 6.22 1999/07/30 19:46:27 addess
46 * more changes to ValidateMMDBID by Diane and Ken
47 *
48 * Revision 6.21 1999/07/29 20:56:02 addess
49 * added ValidateMMDBID() to determine if MMDBID from neighbor is live
50 *
51 * Revision 6.20 1999/07/21 17:25:36 addess
52 * changed printout from Cn3D v2.0 to Cn3D v2.5
53 *
54 * Revision 6.19 1999/05/13 16:31:58 kimelman
55 * - extra spaces
56 *
57 * Revision 6.18 1999/05/11 20:34:14 kimelman
58 * style fixes
59 *
60 * Revision 6.17 1999/05/07 14:02:13 zimmerma
61 * Removed local copy of MMDBBiostrucGet
62 *
63 * Revision 6.16 1999/02/09 15:14:00 addess
64 * Modified by DZ to extract html path dependencies:
65 * - created two new static Char vars: DATApath and VASTpath - read by GetAppParam -
66 * and modified .vastrc to include these new vars.
67 * - created text file getCn3D.txt in data directory - used by WWWPrintFileData
68 *
69 * Revision 6.15 1998/12/22 18:01:51 addess
70 * changes relevant to reading new type of annot-set data
71 *
72 * Revision 6.14 1998/12/01 15:12:56 addess
73 * removed unused variable pbsaShort
74 *
75 * Revision 6.13 1998/11/20 20:03:08 addess
76 * related to platform independence of VAST Search
77 *
78 * Revision 6.12 1998/10/23 19:48:50 addess
79 * fix pagination bug
80 *
81 * Revision 6.11 1998/10/21 14:07:13 addess
82 * add error statement related to NR subset filtering
83 *
84 * Revision 6.10 1998/10/14 17:12:54 addess
85 * pagination and aligned chain
86 *
87 * Revision 6.9 1998/08/06 17:48:52 madej
88 * Fix Display/Show hits button for Vast Search.
89 *
90 * Revision 6.8 1998/07/27 16:08:15 madej
91 * Minor change having to do with gifs.
92 *
93 * Revision 6.7 1998/07/17 18:48:14 madej
94 * Miscellaneous changes.
95 *
96 * Revision 6.6 1998/06/11 19:13:57 madej
97 * Modifications to html.
98 *
99 * Revision 6.5 1998/05/19 20:26:13 madej
100 * Comment out VastViewAlign feature.
101 *
102 * Revision 6.4 1998/05/19 20:17:12 madej
103 * Add general WWW routines for running on Sun servers.
104 *
105 * Revision 6.3 1998/03/30 19:11:50 madej
106 * Added subset filtering, changes to neighbor page layout.
107 *
108 * Revision 6.2 1998/03/16 17:59:59 lewisg
109 * added temporary hooks to communicate to cn3d
110 *
111 * Revision 6.1 1998/03/10 16:29:12 madej
112 * First official version of vastsrv.c
113 *
114 */
115
116
117
118 /* Main program for VAST structure neighbor server. */
119
120 /* define DEBUG_1 1 */
121
122 #include <stdio.h>
123 #include <ncbi.h>
124 #include <accentr.h>
125 #include <netentr.h>
126 #include <www.h>
127 #include <sys/resource.h>
128 #include <asn.h>
129 #include <accutils.h>
130 #include <mmdbapi.h>
131 #include "vastlocl.h"
132 #include "mmdblocl.h"
133 #include "mmdbdata.h"
134 #include "vastsrv.h"
135
136
137
138 #define CPUTIME_MAX 120
139 #define DOMID_SIZE 6
140 #define MAX_MMDBIDS 4096
141 #define DEFAULT_SUBSET_NUM 2 /* default to the NR set BLAST 10e-7 */
142 #define ABRIDGED_DISPLAY 0 /* display only Rmsd, Nres, %Id */
143 #define FULL_DISPLAY 1 /* display all columns in table */
144 #define SORT_BY_SCORE 1 /* sort table by Score */
145 #define SORT_BY_PVAL 2 /* sort table by P-value */
146 #define SORT_BY_RMSD 3 /* sort table by Rmsd */
147 #define SORT_BY_NRES 4 /* sort table by Nres */
148 #define SORT_BY_ID 5 /* sort table by %Id */
149 #define VIEW_ALIGNMENT 4 /* selects action "View Alignment" */
150 #define LOG10_500 2.69897 /* -log10(500); database size correction */
151 #define LOG_10 2.302585 /* log(10.0) */
152 #define NUM_HITS_PER_PAGE 20
153 #define DEFAULT_PAGE 1
154
155 static Char URLBase[PATH_MAX];
156 static Char URLcgi[PATH_MAX];
157 static Char DATApath[PATH_MAX];
158 static Char VASTpath[PATH_MAX];
159 static Char ENTREZurl[PATH_MAX];
160 static Char DOCSUMurl[PATH_MAX];
161 static Char MAILto[PATH_MAX];
162 static FILE *OutputFile = NULL;
163 static char OutputName[200];
164 static Char gunzip[PATH_MAX];
165 static Char MMDBpath[PATH_MAX];
166 static Char CGIname[PATH_MAX];
167 static Char MMDBCGIname[PATH_MAX];
168 static Int2 SortOn = 0;
169 static Int4 cnt_MMDBid;
170 static long save_MMDBid[MAX_MMDBIDS];
171 Boolean Chain;
172 Char VSPATH[PATH_MAX];
173 Char SlaveChain[2];
174 Char MasterChain[2];
175
176 static void
VnpHeapSort(ValNodePtr PNTR vnp,int (LIBCALLBACK * compar)PROTO ((Nlm_VoidPtr,Nlm_VoidPtr)))177 VnpHeapSort (ValNodePtr PNTR vnp, int (LIBCALLBACK *compar )PROTO ((Nlm_VoidPtr, Nlm_VoidPtr )))
178 {
179 Int2 index, total;
180 ValNodePtr vnp1;
181 ValNodePtr PNTR temp;
182
183 total=0;
184 for (vnp1 = *vnp; vnp1; vnp1=vnp1->next)
185 total++;
186
187 temp = (ValNodePtr PNTR) MemNew(total*sizeof(ValNodePtr));
188
189 index=0;
190 for (vnp1 = *vnp; vnp1; vnp1=vnp1->next)
191 {
192 temp[index] = vnp1;
193 index++;
194 }
195
196 HeapSort ((VoidPtr) temp, (size_t) index, sizeof(ValNodePtr), compar);
197
198 *vnp = temp[0];
199 for (vnp1 = *vnp, index=0; index<(total-1); vnp1=vnp1->next, index++)
200 {
201 vnp1->next = temp[index+1];
202 }
203 vnp1 = temp[total-1];
204 vnp1->next = NULL;
205
206 temp = MemFree(temp);
207 }
208
209
210
211 /* Common code for the vastsrv page header is collected here. This generates the html for
212 * the title bar, the domain name, and the defline.
213 */
214
215 static void
VastPageHeader(FILE * table,CharPtr pcPDB,Char cChain,int iDomain,Int4 iMMDBid,CharPtr JobID)216 VastPageHeader(FILE *table, CharPtr pcPDB, Char cChain, int iDomain, Int4 iMMDBid, CharPtr JobID)
217 {
218 DocSumPtr dsp;
219
220 fprintf(table, "Content-type: text/html\n\n");
221 fprintf(table, "<html><title>Vast Results</title>\n");
222 fprintf(table, "<body bgcolor = \"ffffff\">\n");
223 fprintf(table, "<img src=\"%s/vast2.gif\" alt=\"VAST Structure Neighbors\" usemap=#map ISMAP>\n", VASTpath);
224 fprintf(table, "<map name=map>\n");
225 fprintf(table, "<area shape=rect coords=4,5,42,18 href=\"http://www.ncbi.nlm.nih.gov\">\n");
226 fprintf(table, "<area shape=rect coords=43,3,438,18 href=\"%s/vast.html\">\n", VASTpath);
227 fprintf(table, "<area shape=rect coords=439,3,485,18 href=\"%s\">\n", ENTREZurl);
228 fprintf(table, "<area shape=rect coords=490,3,507,18 href=\"%s/vasthelp.html\">\n", VASTpath);
229 fprintf(table, "</map><p>\n");
230 fprintf(table, "\n\n<HR SIZE=5 NOSHADE>\n");
231 if (JobID == NULL)
232 {
233 fprintf(table, "<h1>Structures similar to MMDB\n");
234 fprintf(table, "<a href=\"%s%s?uid=%s", URLcgi, MMDBCGIname, pcPDB);
235 fprintf(table, "&form=6&db=t&Dopt=s\">\n%d</a>", (long)iMMDBid);
236 fprintf(table, ", \n");
237 }
238 else
239 {
240 fprintf(table, "<h1>Structures similar to VAST Search\n");
241 fprintf(table, " %s\n", JobID);
242 fprintf(table, ", \n");
243 }
244 fprintf(table, "%s", pcPDB);
245
246 if (cChain != ' ')
247 fprintf(table, " chain %c", cChain);
248
249 if (iDomain > 0)
250 fprintf(table, " domain %d", (int) iDomain);
251
252 fprintf(table, "</h1>\n");
253 dsp = NetDocSum(TYP_ST, (DocUid) iMMDBid);
254
255 if (dsp) {
256 if (dsp->title)
257 fprintf(table, "%s\n", dsp->title);
258
259 DocSumFree(dsp);
260 }
261
262 } /* end VastPageHeader */
263
264
265 /************************** DZ: extracted from mmdbsrv.c ************************
266 * WWWPrintFileData looks in the current CGI-BIN directory
267 * or the "data" subdirectory for the data file.
268 * and prints it out to pFile
269 */
270
WWWPrintFileData(CharPtr FName,FILE * pFile)271 static void WWWPrintFileData(CharPtr FName, FILE *pFile)
272 {
273
274 FILE *f = NULL;
275 Char fullpath [PATH_MAX];
276 CharPtr ptr;
277 Char pcBuf[1024];
278
279 fullpath[0] = '\0';
280 StringCpy(fullpath, DATApath); /* look in DATApath */
281 StringCat(fullpath, FName);
282 f = FileOpen (fullpath, "r");
283 if (f == NULL) {
284 f = FileOpen (FName, "r"); /* look in curent */
285 if (f == NULL) { /* look in ./data/ */
286 ProgramPath (fullpath, sizeof (fullpath) - 1);
287 ptr = StringRChr (fullpath, DIRDELIMCHR);
288 if (ptr != NULL) {
289 *ptr = '\0';
290 }
291 FileBuildPath (fullpath, "data", FName);
292 f = FileOpen (fullpath, "r");
293 if (f == NULL) {
294 return;
295 }
296 }
297 }
298
299 do {
300 pcBuf[0] = '\0';
301 ptr = fgets(pcBuf, (size_t)1024, f);
302 if (ptr) fprintf(pFile, ptr);
303 } while (ptr);
304
305 FileClose(f);
306 return;
307 }
308
309
310 /* Note: A lot of this common html text could be put into a header file, read in, and then
311 * spewed out. Cf. the way this is done in mmdbsrv with WWWPrintFile. Sometime I'll take
312 * the time to write a more general version of the latter function that can be used for this
313 * purpose. T.M.
314 */
315
316 /*
317 DZ: most of the HTML file URLs are inside the new VAST subdirectory, and references to these
318 are interwoven with many query-specific references. Becasue of this interleaving, using
319 WWWPrintFileData would require several invocations and corresponding text files. Instead.
320 WWWPrintFileData is only used to define the new path to CN3D, and all vast html references
321 are now prefixed with the VASTpath string. This variable has been added to .vastrc and to
322 the list of parameters to be extracted using GetVastParams.
323 */
324
325 static void
VastTableBegin(FILE * table,CharPtr pcPDB,CharPtr JobID,CharPtr pcPass,Char cChain,int iDomain,Int4 iMMDBid,Int4 iFSID,Int2 iFull,Int4 numhits,Int4 upper,Int4 lower,Int4 numpages,Int4 HitsPerPage,Int4 pagenum)326 VastTableBegin (FILE *table, CharPtr pcPDB, CharPtr JobID, CharPtr pcPass,
327 Char cChain, int iDomain, Int4 iMMDBid, Int4 iFSID,
328 Int2 iFull, Int4 numhits, Int4 upper, Int4 lower, Int4 numpages, Int4 HitsPerPage, Int4 pagenum)
329 {
330 Int4 DisplayOpt;
331
332 VastPageHeader(table, pcPDB, cChain, iDomain, iMMDBid, JobID);
333 fprintf(table,"<FORM METHOD=\"POST\" ACTION=\"%s%s\">\n", URLcgi, CGIname);
334 fprintf(table,"<INPUT TYPE=\"hidden\" NAME=\"uid\" VALUE=\"%ld\">\n", (long)iMMDBid);
335 fprintf(table,"<INPUT TYPE=\"hidden\" NAME=\"chaindom\" VALUE=\"%ld\">\n", (long) iFSID);
336 if (JobID)
337 {
338 fprintf(table,"<INPUT TYPE=\"hidden\" NAME=\"vsid\" VALUE=\"%s\">\n", JobID);
339 fprintf(table,"<INPUT TYPE=\"hidden\" NAME=\"pass\" VALUE=\"%s\">\n", pcPass);
340 }
341
342 fprintf(table, "<TABLE CELLPADDING=0 CELLSPACING=4>\n");
343 fprintf(table, "<TR><TH COLSPAN=2 ALIGN=LEFT>\n");
344 fprintf(table, "<strong><INPUT TYPE=SUBMIT VALUE=\"View / Save Alignments\"></strong>\n");
345 fprintf(table, " <img src=\"%s/new.gif\" alt=\"New\">\n", VASTpath);
346 WWWPrintFileData("getCn3D.txt", table);
347 fprintf(table, "</TH></TR>");
348 fprintf(table, "<tr><td colspan = 1><strong>Options:</strong></td>\n");
349 fprintf(table, "<td colspan = 1><strong>Viewer:</strong></td>\n");
350 fprintf(table, "<td colspan = 2><strong>Complexity:</strong></td></tr>\n");
351 /*fprintf(table, "<td colspan = 1><strong>Cn3D Atom Complexity:</strong></td></tr>\n");*/
352 fprintf(table,"<TD VALIGN=TOP NOWRAP>\n");
353 fprintf(table,"<INPUT TYPE=\"radio\" NAME=\"action\" value=\"0\"CHECKED> Launch Viewer<BR>\n");
354 fprintf(table,"<INPUT TYPE=\"radio\" NAME=\"action\" value=\"1\"> See File<BR>\n");
355 fprintf(table,"<INPUT TYPE=\"radio\" NAME=\"action\" value=\"2\"> Save File<BR></TD>\n");
356 fprintf(table,"<TD VALIGN=TOP NOWRAP>\n");
357 fprintf(table,"<INPUT TYPE=\"radio\" NAME=\"calltype\" value=\"a\"CHECKED> Cn3D (asn.1)<BR>\n");
358 fprintf(table,"<INPUT TYPE=\"radio\" NAME=\"calltype\" value=\"m\"> Mage (Kinemage)<BR>\n");
359 fprintf(table,"<INPUT TYPE=\"radio\" NAME=\"calltype\" value=\"p\"> (PDB)<BR></TD>\n");
360 fprintf(table, "<TD VALIGN=TOP NOWRAP>\n");
361 fprintf(table, "<INPUT TYPE=\"radio\" NAME=\"chn_complexity\" value=\"1\"CHECKED> Aligned Chains only<BR>\n");
362 fprintf(table, "<INPUT TYPE=\"radio\" NAME=\"chn_complexity\" value=\"0\"> All Chains<BR></TD>\n");
363 fprintf(table, "<TD VALIGN=TOP NOWRAP>\n");
364 fprintf(table, "<INPUT TYPE=\"radio\" NAME=\"atm_complexity\" value=\"1\"CHECKED> Alpha Carbons only<BR>\n");
365 fprintf(table, "<INPUT TYPE=\"radio\" NAME=\"atm_complexity\" value=\"0\"> All Atoms<BR></TD>\n");
366 fprintf(table, "</TR>\n</TABLE>\n");
367
368 DisplayOpt = upper - lower;
369
370 if (!DisplayOpt)
371 fprintf(table, "<H4>Structure neighbor %d out of %d displayed. ", lower, numhits);
372 else
373 fprintf(table, "<H4>Structure neighbors %d-%d out of %d displayed. ", lower, upper, numhits);
374 fprintf(table, "Page %d of %d.</H4>\n", pagenum, numpages);
375
376 /* VAST data table begins here */
377 if (numhits > 0) {
378 fprintf(table,"<table cellspacing=3 cellpadding=2 width=100%% border=1>\n");
379 fprintf(table,"<tr valign=middle>\n");
380 fprintf(table,"<th> </th>\n");
381 fprintf(table,"<th align=left><pre> <a href=\"%s/vasthelp.html#Structure\">PDB</a>", VASTpath);
382 fprintf(table," <a href=\"%s/vasthelp.html#C\">C</a>", VASTpath);
383 fprintf(table," <a href=\"%s/vasthelp.html#D\">D</a></pre></th>\n", VASTpath);
384
385 if (iFull) {
386 fprintf(table,"<th align=right><pre><a href=\"%s/vasthelp.html#SCORE\">SCO</a></pre></th>\n", VASTpath);
387 fprintf(table,"<th align=right><pre><a href=\"%s/vasthelp.html#P-VAL\">P-VAL</a></pre></th>\n", VASTpath);
388 }
389
390 fprintf(table,"<th align=right><pre><a href=\"%s/vasthelp.html#RMSD\">RMSD</a></pre></th>\n", VASTpath);
391 fprintf(table,"<th align=right><pre><a href=\"%s/vasthelp.html#NRES\">NRES</a></pre></th>\n",VASTpath);
392 fprintf(table,"<th align=right><pre><a href=\"%s/vasthelp.html#Id\">%s</a></pre></th>\n", VASTpath, "%Id");
393 fprintf(table,"<th align=left><pre><a href=\"%s/vasthelp.html#Contents\">Description</pre></th>\n",VASTpath);
394 fprintf(table,"</tr><br>\n");
395 fflush(table);
396 }
397 } /* end of VastTableBegin */
398
399
ValidateMMDBID(CharPtr pcAccession,Int4 iMMDBid)400 static Boolean ValidateMMDBID(CharPtr pcAccession, Int4 iMMDBid)
401 {
402 DocUid uid;
403
404 uid = MMDBEvalPDB(pcAccession);
405 if ((Int4)uid == iMMDBid) return TRUE;
406 else return FALSE;
407
408 }
409
410
411 static void
VastTableRows(FILE * table,BiostrucFeatureSetPtr pbsfs,Int4 iMMDBid1,Int4 iFSID,Int2 iFull,ValNodePtr pvnBools)412 VastTableRows(FILE *table, BiostrucFeatureSetPtr pbsfs, Int4 iMMDBid1, Int4 iFSID, Int2 iFull, ValNodePtr pvnBools)
413 {
414 BiostrucFeaturePtr pbsf = NULL;
415 ChemGraphAlignmentPtr pcga = NULL;
416 BiostrucIdPtr pbsidThis = NULL;
417 AlignStatsPtr pasp = NULL;
418 ValNodePtr pvn = NULL;
419 DocSumPtr dsp = NULL;
420 CharPtr pcPDB;
421 CharPtr pcSlaveName;
422 Int4 iMMDBid;
423 Char cChain;
424 int iDomain;
425 Int4 iAlign;
426 float f;
427 Boolean page;
428
429 /* use cnt_MMDBid and save_MMDBid[] for docsum display of the correct subset hits */
430 cnt_MMDBid = 0;
431
432 for (pbsf = pbsfs->features; pbsf != NULL || pvnBools != NULL ; pbsf = pbsf->next, pvnBools = pvnBools->next) {
433 /* Filter Hits By Page*/
434 page = pvnBools->data.boolvalue;
435 if (page == FALSE) continue;
436
437 /* get the embedded PDB code of the hit */
438 pcPDB = StringSave(PDBNAME_DEFAULT);
439 pcSlaveName = NULL;
440 if (pbsf->name[14] != '\0') pcSlaveName = StringSave(&pbsf->name[14]);
441 iDomain = 0;
442 cChain = '-';
443 if (StringLen(pbsf->name) >= 13)
444 {
445 pcPDB[0] = pbsf->name[7];
446 pcPDB[1] = pbsf->name[8];
447 pcPDB[2] = pbsf->name[9];
448 pcPDB[3] = pbsf->name[10];
449 cChain = pbsf->name[11];
450 iDomain = atoi((char *) &pbsf->name[12]);
451 }
452
453 pvn = ValNodeFindNext(pbsf->Location_location,NULL,Location_location_alignment);
454 if (pvn) pcga = (ChemGraphAlignmentPtr) pvn->data.ptrvalue;
455 iMMDBid = 0;
456 if (pcga)
457 {
458
459 pbsidThis = ValNodeFindNext(pcga->biostruc_ids,NULL,BiostrucId_mmdb_id);
460 if (pbsidThis)
461 {
462 if (pbsidThis->next) /* want only the second one - the slave */
463 iMMDBid = (long) pbsidThis->next->data.intvalue;
464 }
465 }
466
467 /* save the MMDB id for later output for the docsum format */
468 if (cnt_MMDBid < MAX_MMDBIDS)
469 save_MMDBid[cnt_MMDBid++] = (long) iMMDBid;
470
471 /* PDB and Kinemage file generators */
472 /*****
473 fprintf(table, "(<a href=\"%s%s?calltype=p&uid=%ld&fid=%ld&fsid=%ld&pdb=1\">P</a>) ",
474 URLcgi, CGIname, (long) iMMDBid1, pbsf->id, iFSID);
475 fprintf(table, "(<a href=\"%s%s?calltype=m&uid=%ld&fid=%ld&fsid=%ld&pdb=1\">K</a>) ",
476 URLcgi, CGIname, (long) iMMDBid1, pbsf->id, iFSID);
477 *****/
478 /* Please do not delete. for testing. lyg */
479 /*****
480 fprintf(table, "(<a href=\"%s%s?calltype=c&uid=%ld&fid=%ld&fsid=%ld&pdb=1\">C</a>) ",
481 URLcgi, CGIname, (long) iMMDBid1, pbsf->id, iFSID);
482 *****/
483
484 /*****
485 fprintf(table,"<a href=\"%s%s?uid=%ld&form=6&db=t&Dopt=s\">%ld</a></pre></td>\n",
486 MMDBCGIname, URLcgi, (long) iMMDBid, iMMDBid);
487 *****/
488 fprintf(table, "<tr>\n");
489 fprintf(table, "<td VALIGN=TOP><INPUT TYPE=\"checkbox\" NAME=\"hit\"");
490 fprintf(table, "VALUE=\"%ld\"></td>\n", (long) pbsf->id);
491 fprintf(table,"<td VALIGN=TOP><pre>");
492 fprintf(table, "<a href=\"%s%s?uid=%ld&form=6&db=t&Dopt=s\">%s</a>",
493 URLcgi, MMDBCGIname,
494 (long) iMMDBid, pcPDB);
495
496 if (cChain == ' ')
497 fprintf(table, "  ");
498 else
499 fprintf(table, " <a href=\"%s%s?uid=%ld&form=6&db=t&Dopt=s\">%c</a>",
500 URLcgi, MMDBCGIname, (long) iMMDBid, cChain);
501
502 /* get the alignment number from the id */
503 iDomain = (int) (pbsf->id/10) % 100;
504
505 if (iDomain > 0)
506 fprintf(table, " <a href=\"%s%s?uid=%ld&form=6&db=t&Dopt=s\">%d</a></pre></td>\n",
507 URLcgi, MMDBCGIname, (long) iMMDBid, iDomain);
508 else
509 fprintf(table, " </pre></td>\n");
510
511 /* dig into aligndata */
512 if (pcga)
513 {
514 pasp = pcga->aligndata;
515 if (iFull)
516 {
517 if (pasp->vast_score)
518 {
519 f = (FloatLo) pasp->vast_score;
520 f = f/(FloatLo) pasp->scale_factor;
521 fprintf(table,"<td VALIGN=top ALIGN=right>%.1f</td>\n",(float)f);
522 }
523 else
524 fprintf(table,"<td> </td>\n");
525 if (pasp->vast_mlogp)
526 {
527 f = (float) pasp->vast_mlogp;
528 f = f/(float) pasp->scale_factor;
529
530 /* adjust for database size */
531 f -= LOG10_500;
532
533 if (f <= 4.0) {
534 f = (float) exp(-LOG_10*f);
535 fprintf(table, "<td VALIGN=top ALIGN=right>%.4f</td>\n", f);
536 }
537 else
538 fprintf(table,"<td VALIGN=top ALIGN=right>10e-%.1f</td>\n", f);
539 }
540 else
541 fprintf(table,"<td> </td>\n");
542 }
543 if (pasp->rmsd)
544 {
545 f = (FloatLo) pasp->rmsd;
546 f = f/(FloatLo) pasp->scale_factor;
547 fprintf(table,"<td VALIGN=top ALIGN=right>%.1f</td>\n",(float)f);
548 }
549 else
550 fprintf(table,"<td> </td>\n");
551 if (pasp->align_res)
552 {
553 fprintf(table,"<td VALIGN=top ALIGN=center>%d</td>\n",(int) pasp->align_res);
554 }
555 else
556 fprintf(table,"<td> </td>\n");
557 if (pasp->other_score)
558 {
559 f = (FloatLo) pasp->other_score;
560 f = f/(FloatLo) pasp->scale_factor;
561 fprintf(table,"<td VALIGN=top ALIGN=right>%.1f</td>\n",(float)f * 100.0);
562 }
563 else
564 fprintf(table,"<td VALIGN=top ALIGN=right>0.0</td>\n");
565 }
566 else
567 {
568 fprintf(table, "<td> </td><td> </td><td> </td><td> </td><td> </td>\n");
569 }
570
571 /* get the Entrez docsum */
572 fprintf(table,"<td VALIGN=top>\n");
573 /* Names are read directly from Annot-set. DocSums are used no longer */
574 if(StringLen(pbsf->name) <= 13)
575 {
576 dsp = NULL;
577 dsp = NetDocSum(TYP_ST, (DocUid) iMMDBid);
578 if (dsp)
579 {
580 if (dsp->title)
581 {
582 fprintf(table,"%s" , dsp->title);
583 }
584 else
585 {
586 fprintf(table," ");
587 }
588 DocSumFree(dsp);
589 }
590 else
591 fprintf(table, " ");
592 }
593 else
594 {
595 if (pcSlaveName)
596 fprintf(table,"%s" , pcSlaveName);
597 else
598 fprintf(table, " ");
599 }
600 fprintf(table,"<BR>\n");
601 fprintf(table,"</td>\n</tr>\n");
602 fflush(table);
603 MemFree(pcPDB);
604 MemFree(pcSlaveName);
605
606 } /* end of for */
607
608 } /* end of VastTableRows */
609
610
611
612 static void
VastTableEnd(FILE * table,Int4 iMMDBid,Int4 FSID,BiostrucAnnotSetPtr pbsas,Int4 subsetnum,Int4 iSort,Int2 iFull,CharPtr JobID,CharPtr pcPass,Int4 numpages,Int4 pagenum,Int4 HitsPerPage)613 VastTableEnd(FILE *table, Int4 iMMDBid, Int4 FSID, BiostrucAnnotSetPtr pbsas, Int4 subsetnum,
614 Int4 iSort, Int2 iFull, CharPtr JobID, CharPtr pcPass, Int4 numpages, Int4 pagenum, Int4 HitsPerPage)
615 {
616 BiostrucFeatureSetPtr pbsfs = NULL;
617 BiostrucFeaturePtr pbsf = NULL;
618 ChemGraphAlignmentPtr pcga = NULL;
619 BiostrucIdPtr pbsidThis = NULL;
620 ValNodePtr pvn = NULL;
621 Int4 i, n;
622
623 fprintf(table,"</table><hr>\n");
624 fprintf(table,"</form>\n\n");
625 fprintf(table,"<FORM METHOD=\"POST\" ACTION=\"%s%s\">\n", URLcgi, CGIname);
626 fprintf(table,"<INPUT TYPE=\"hidden\" NAME=\"uid\" VALUE=\"%ld\">\n", (long) iMMDBid);
627 fprintf(table,"<INPUT TYPE=\"hidden\" NAME=\"chaindom\" VALUE=\"%ld\">\n",(long) FSID);
628 if (JobID)
629 {
630 fprintf(table,"<INPUT TYPE=\"hidden\" NAME=\"vsid\" VALUE=\"%s\">\n", JobID);
631 fprintf(table,"<INPUT TYPE=\"hidden\" NAME=\"pass\" VALUE=\"%s\">\n", pcPass);
632 }
633 fprintf(table, "<TABLE CELLPADDING=0 CELLSPACING=4>\n");
634 fprintf(table, "<TR><TD COLSPAN=3 ALIGN=LEFT> <strong><INPUT TYPE=SUBMIT VALUE=\"Display / Sort Hits\"></strong>\n");
635 fprintf(table, "     page number:\n");
636 fprintf(table, "<SELECT name=\"doclistpage\">\n");
637 pagenum++;
638 for (i = 1; i<= numpages; i++) {
639 if (pagenum < numpages) {
640 if (i == pagenum)
641 fprintf(table,"<OPTION VALUE = \"%d\" SELECTED>%d\n", i, i);
642 else
643 fprintf(table,"<OPTION VALUE = \"%d\">%d\n", i, i);
644 }
645 else {
646 if (i == numpages)
647 fprintf(table,"<OPTION VALUE = \"%d\" SELECTED>%d\n", i, i);
648 else
649 fprintf(table,"<OPTION VALUE = \"%d\">%d\n", i, i);
650 }
651 }
652
653 fprintf(table, "</SELECT>\n");
654 fprintf(table, "  <small>Hits to display per page:\n");
655 fprintf(table, "<INPUT name = \"dispmax\" size=6 Value=%d> choose between 20-100 neighbors per page.</small></TD></TR>\n", HitsPerPage);
656 fprintf(table, "<TR>\n");
657 fprintf(table, "<TD><a href=\"%s/vasthelp.html#NRSet\"><strong>Display Subset:</strong></a></TD>\n", VASTpath);
658 fprintf(table, "<TD COLSPAN=1><strong>Sorted by:</strong></TD>\n");
659 fprintf(table, "<TD COLSPAN=1><strong>Column Format:</strong></TD>\n");
660 fprintf(table, "</TR>\n");
661 fprintf(table, "<TR><TD VALIGN=TOP NOWRAP>\n");
662 n = GetNumberOfSubsets();
663
664 /* subset 1 should be "All of PDB"; put it last */
665 for (i = 2; i <= n; i++) {
666 fprintf(table, "<INPUT TYPE=radio NAME=subset VALUE=\"%s\"", GetSubsetName(i));
667
668 if (i == subsetnum)
669 fprintf(table, " CHECKED");
670
671 fprintf(table, "> %s<BR>\n", GetSubsetName(i));
672 }
673
674 fprintf(table, "<INPUT TYPE=radio NAME=subset VALUE=\"%s\"", GetSubsetName(1));
675
676 if (subsetnum == 1)
677 fprintf(table, " CHECKED");
678
679 fprintf(table, "> %s<BR>\n", GetSubsetName(1));
680 fprintf(table, "<TD VALIGN=TOP NOWRAP>\n");
681 fprintf(table, "<INPUT TYPE=radio NAME=sort VALUE=\"1\"");
682 if ((iSort == SORT_BY_SCORE) || (iSort == 0)) fprintf(table, " CHECKED");
683 fprintf(table, "> VAST Score<BR>\n");
684 fprintf(table, "<INPUT TYPE=radio NAME=sort VALUE=\"2\"");
685 if (iSort == SORT_BY_PVAL) fprintf(table, " CHECKED");
686 fprintf(table, "> VAST P-value<BR>\n");
687 fprintf(table, "<INPUT TYPE=radio NAME=sort VALUE=\"3\"");
688 if (iSort == SORT_BY_RMSD) fprintf(table, " CHECKED");
689 fprintf(table, "> Rmsd<BR>\n");
690 /*****
691 fprintf(table, "<TD VALIGN=TOP NOWRAP>\n");
692 *****/
693 fprintf(table, "<INPUT TYPE=radio NAME=sort VALUE=\"4\"");
694 if (iSort == SORT_BY_NRES) fprintf(table, " CHECKED");
695 fprintf(table, "> Aligned residues<BR>\n");
696 fprintf(table, "<INPUT TYPE=radio NAME=sort VALUE=\"5\"");
697 if (iSort == SORT_BY_ID) fprintf(table, " CHECKED");
698 fprintf(table, "> Identities<BR>\n");
699 fprintf(table, "<TD VALIGN=TOP NOWRAP>\n");
700 fprintf(table, "<INPUT TYPE=radio NAME=version VALUE=\"0\"");
701 if (iFull == ABRIDGED_DISPLAY) fprintf(table, " CHECKED");
702 fprintf(table, "> RMSD, NRES, %s<BR>\n", "%Id");
703 fprintf(table, "<INPUT TYPE=radio NAME=version VALUE=\"1\"");
704 if (iFull == FULL_DISPLAY) fprintf(table, " CHECKED");
705 fprintf(table, "> All values<BR>\n");
706 fprintf(table, "</TR>\n");
707 fprintf(table, "</TABLE>\n");
708 fprintf(table, "</FORM>\n");
709
710 /***** Removing docsum button:
711 fprintf(table,"<FORM METHOD=\"POST\" ACTION=\"%s/query\">\n", DOCSUMurl);
712 fprintf(table,"<INPUT TYPE=\"hidden\" NAME=\"form\" VALUE=\"6\">\n");
713 fprintf(table,"<INPUT TYPE=\"hidden\" NAME=\"db\" VALUE=\"t\">\n");
714 fprintf(table,"<INPUT TYPE=\"hidden\" NAME=\"uid\" VALUE=\"%ld,", (long) iMMDBid);
715 *****/
716
717 /* output the MMDB id's for the slaves */
718 /***** Removing docsum button:
719 if (cnt_MMDBid > 0) {
720 for (i = 0; i < cnt_MMDBid - 1; i++)
721 fprintf(table, "%ld,", save_MMDBid[i]);
722
723 fprintf(table, "%ld ", save_MMDBid[cnt_MMDBid - 1]);
724 }
725
726 fprintf(table,"\">\n");
727 fprintf(table,"<INPUT TYPE=\"submit\" VALUE=\"Display\"> table as an Entrez Document Summary form.</form>\n");
728 *****/
729 fprintf(table, "\n<HR SIZE=5 NOSHADE>\n");
730 fprintf(table,"</body></html>\n");
731
732 } /* end of VastTableEnd */
733
734 /* I decided to filter by domain subset first because it make writing the pagination code much easier Ken */
735
FilterHitsByDomainSubset(BiostrucFeaturePtr pbsf,Int4 subsetnum)736 static BiostrucFeaturePtr FilterHitsByDomainSubset(BiostrucFeaturePtr pbsf, Int4 subsetnum)
737 {
738 BiostrucFeaturePtr current, pbsfHead = NULL, pbsfTail;
739 Int4 h, i, n;
740 Int4 gn, gr, hcnt, *min_ranks, *group_num, *group_rank;
741 Char domid[DOMID_SIZE + 1], pdbcode[4+1];
742
743 /* The next bit of code is used for filtering the hit lists. When we go through a hit
744 * list we skip domains that do not belong to the subset of interest, or which belong to
745 * the subset but for which a group representative has already been encountered.
746 */
747 for (i = 0; i <= DOMID_SIZE; i++)
748 domid[i] = '\0';
749
750 n = GetNumberOfDomains();
751 min_ranks = (Int4 *) MemNew(n*sizeof(Int4));
752 group_num = (Int4 *) MemNew(n*sizeof(Int4));
753 group_rank = (Int4 *) MemNew(n*sizeof(Int4));
754
755 /* use a first pass to "flag" the selected hits in the specified subset
756 If group_num[i] = 0 or group_rank[i] is larger than min_ranks[i],
757 then the ith neighbor should not be included in summary page */
758
759 if (group_rank != NULL) { /* check mem alloc */
760
761 for (i = 0; i < n; i++) { /* initializations */
762 group_num[i] = 0;
763 min_ranks[i] = n + 1;
764 group_rank[i] = n + 1;
765 }
766
767 for (current = pbsf, hcnt = 0; current != NULL; current = current->next, hcnt++) {
768 /* copy domain identifier into domid[] */
769 domid[0] = current->name[7];
770 domid[1] = current->name[8];
771 domid[2] = current->name[9];
772 domid[3] = current->name[10];
773 domid[4] = current->name[11];
774 domid[5] = current->name[12];
775
776 if (domid[5] == '0') domid[5] = ' ';
777
778 /* if not in subset then skip over this domain */
779 if (BelongsToSubset(domid, subsetnum, &gn, &gr) <= 0) {
780 continue;
781 }
782
783 /* otherwise record group data for this hit */
784 group_num[hcnt] = gn;
785 group_rank[hcnt] = gr;
786
787 /* and reset minimum rank for this group */
788 if (gr < min_ranks[gn - 1])
789 min_ranks[gn - 1] = gr;
790 }
791 }
792
793 /* Now use the values just set in group_num, group_rank, and min_ranks
794 to decide whether or not the current neighbor should be linked
795 into the new feature list */
796
797 current = pbsf;
798 hcnt = 0;
799 while (current) {
800 if (group_rank != NULL) /* check mem alloc */
801 {
802 if (group_num[hcnt] == 0) /* group_num not set so NOT in subset */
803 { /* incr hcnt and do NOT link */
804 hcnt++;
805 current = current->next;
806 continue;
807 }
808
809 gn = group_num[hcnt];
810
811 if (group_rank[hcnt] != min_ranks[gn - 1]) /* neighbor is in subset but of lower rank */
812 {
813 hcnt++; /* incr hcnt and do NOT link */
814 current = current->next;
815 continue;
816 }
817 }
818
819 /* With the new rcsb depositions we now need to validate mmdbids
820 in the .bas files. Extract pdbcode and use it with mmdbID to validate */
821
822 pdbcode[0] = current->name[7];
823 pdbcode[1] = current->name[8];
824 pdbcode[2] = current->name[9];
825 pdbcode[3] = current->name[10];
826 pdbcode[4]= '\0';
827
828 if (!ValidateMMDBID(pdbcode, (current->id)/100000)) {
829 hcnt++;
830 current = current->next; /* incr hcnt and do NOT link */
831 continue;
832 }
833
834 if (pbsfHead == NULL) /* neighbor has passed all tests - include it! */
835 {
836 pbsfHead = BiostrucFeatureNew();
837 pbsfHead = current;
838 pbsfTail = pbsfHead;
839 hcnt++;
840 current = current->next;
841 pbsfTail->next = NULL;
842 }
843 else
844 {
845 pbsfTail->next = current;
846 pbsfTail = current;
847 hcnt++;
848 current = current->next;
849 pbsfTail->next = NULL;
850 }
851 }
852
853 MemFree(min_ranks);
854 MemFree(group_num);
855 MemFree(group_rank);
856 return pbsfHead;
857 }
858
FilterHitsByPage(BiostrucFeatureSetPtr pbsfs,Int4 PageNum,Int4 HitsPerPage,Int4 * numhits,Int4 * numpages,Int4 * upper,Int4 * lower)859 static ValNodePtr FilterHitsByPage(BiostrucFeatureSetPtr pbsfs, Int4 PageNum, Int4 HitsPerPage, Int4 *numhits, Int4 *numpages, Int4 *upper, Int4 *lower)
860 {
861
862 BiostrucFeaturePtr pbsf;
863 Int4 index, FidCount, RemainFids, CompleteFidSet;
864 Int4 UpperLimit, LowerLimit;
865 ValNodePtr pvnBools = NULL;
866 float n;
867
868
869
870 pbsf = pbsfs->features;
871 if (pbsf == NULL) {
872 *numpages = 1;
873 *numhits = 0;
874 *lower = 0;
875 *upper = 0;
876 return pvnBools;
877 }
878
879 FidCount = 0;
880
881 while (pbsf)
882 {
883 FidCount++;
884 pbsf = pbsf->next;
885 }
886 *numhits = FidCount;
887
888 if (FidCount <= HitsPerPage)
889 *numpages = 1;
890 else
891 {
892 RemainFids = FidCount % HitsPerPage;
893
894 if (RemainFids)
895 {
896 CompleteFidSet = FidCount - RemainFids;
897 *numpages = (CompleteFidSet/HitsPerPage) + 1;
898 }
899 else *numpages = FidCount/HitsPerPage;
900 }
901
902 UpperLimit = HitsPerPage * PageNum;
903 LowerLimit = UpperLimit - HitsPerPage + 1;
904
905 if ((FidCount < HitsPerPage ) || (LowerLimit > FidCount)) {
906 UpperLimit = FidCount;
907 LowerLimit = 1;
908 }
909
910 if (UpperLimit > FidCount) UpperLimit = FidCount;
911
912 *lower = LowerLimit;
913 *upper = UpperLimit;
914
915 for (index = 1; index <= FidCount; index++)
916 {
917 if ((index >= LowerLimit) && (index <= UpperLimit)) ValNodeAddBoolean(&pvnBools, 0, TRUE);
918 else ValNodeAddBoolean(&pvnBools, 0, FALSE);
919 }
920
921 return pvnBools;
922 }
923
924 static void
MakeVastTable(Int4 FSID,BiostrucAnnotSetPtr pbsas,Int2 iSort,Int4 subsetnum,Int4 pagenum,Int4 HitsPerPage,Int2 iFull,CharPtr JobID,CharPtr pcPass)925 MakeVastTable(Int4 FSID, BiostrucAnnotSetPtr pbsas, Int2 iSort, Int4 subsetnum, Int4 pagenum, Int4 HitsPerPage, Int2 iFull, CharPtr JobID, CharPtr pcPass)
926 {
927 BiostrucFeatureSetPtr pbsfs = NULL, pbsfs2 = NULL;
928 FILE *table = NULL;
929 CharPtr pcPDB = NULL;
930 char cChain = '-';
931 int iDomain = 0;
932 Int4 iMMDBid = 0;
933 Int4 numhits, numpages, upper, lower;
934 BiostrucIdPtr pbsidThis = NULL;
935 BiostrucDescrPtr pbsdrThis = NULL;
936 CharPtr pcVast = NULL;
937 ValNodePtr pvnBools = NULL;
938
939 if ((!pbsas) || (!FSID) ) return;
940
941 /* pull values out of BiostrucAnnotSet */
942 pbsidThis = ValNodeFindNext(pbsas->id,NULL,BiostrucId_mmdb_id);
943 if (pbsidThis)
944 {
945 iMMDBid = (Int4) pbsidThis->data.intvalue; /* Get MMDB id no (only the first one) */
946 }
947 else
948 {
949 printf("Content-type: text/html\n\n");
950 printf("<h2>Error</h2>\n");
951 printf("Internal VASTSERV Error. No MMDB-ID in Data on Server.<p>\n");
952 return;
953 }
954
955 pbsfs = pbsas->features;
956 while (pbsfs)
957 {
958 if (pbsfs->id == FSID)
959 {
960 /* got the right one - make the table */
961
962 /* pull out the PDB chain code and domain number from the name string */
963 pbsidThis = ValNodeFindNext(pbsfs->descr,NULL,BiostrucFeatureSetDescr_name);
964 if (pbsidThis)
965 {
966 pcVast = (CharPtr) pbsidThis->data.ptrvalue;
967 pcPDB = StringSave(PDBNAME_DEFAULT);
968 iDomain = 0;
969 cChain = '-';
970 if (StringLen(pcVast) >= 6)
971 {
972 pcPDB[0] = pcVast[0];
973 pcPDB[1] = pcVast[1];
974 pcPDB[2] = pcVast[2];
975 pcPDB[3] = pcVast[3];
976 cChain = pcVast[4];
977 iDomain = (Int4) FSID % 100;
978 }
979 }
980
981 if (EntrezInit("vastsrv", NULL, FALSE) == FALSE)
982 {
983 printf("Content-type: text/html\n\n");
984 printf("<h2>Error</h2>\n");
985 printf("VASTSERV: EntrezInit Failed.<p>\n");
986 if (pcPDB) MemFree(pcPDB);
987 return;
988 }
989
990 if (pbsfs->features != NULL) {
991 pbsfs2 = BiostrucFeatureSetNew();
992 pbsfs2->id = pbsfs->id;
993 pbsfs->id = NULL;
994 pbsfs2->descr = pbsfs->descr;
995 pbsfs->descr = NULL;
996 pbsfs2->features = FilterHitsByDomainSubset(pbsfs->features, subsetnum);
997 pbsfs->features = NULL;
998 pvnBools = FilterHitsByPage(pbsfs2, pagenum, HitsPerPage, &numhits, &numpages, &upper, &lower);
999 if (numhits < HitsPerPage || lower > numhits) pagenum = DEFAULT_PAGE;
1000 if (pbsfs2->features != NULL) VastTableSort(pbsfs2, iSort);
1001 VastTableBegin(stdout, pcPDB, JobID, pcPass, cChain, iDomain, iMMDBid, FSID, iFull,
1002 numhits, upper, lower, numpages, HitsPerPage, pagenum);
1003 if (pbsfs2->features != NULL || pvnBools != NULL)
1004 VastTableRows(stdout, pbsfs2, iMMDBid, FSID, iFull, pvnBools);
1005 else
1006 fprintf(stdout,"<h2><p>Hits are not present in the selected subset</p></h2>\n");
1007 VastTableEnd(stdout, iMMDBid, FSID, pbsas, subsetnum, iSort, iFull, JobID, pcPass, numpages, pagenum, HitsPerPage);
1008 }
1009 else {
1010 VastPageHeader(stdout, pcPDB, cChain, iDomain, iMMDBid, JobID);
1011 fprintf(stdout, "<h1><a href=\"%s/vasthelp.html#NoNeighbor\">%s</a></h1>\n", VASTpath,
1012 "VAST did not find any structure neighbors.");
1013 fprintf(stdout, "<HR SIZE=5 NOSHADE>\n");
1014 fprintf(stdout, "</body></html>\n");
1015 }
1016
1017 oot:
1018 EntrezFini();
1019 RemoveTempFiles();
1020 if (pcPDB) MemFree(pcPDB);
1021 return;
1022 }
1023 pbsfs = pbsfs->next;
1024 }
1025 printf("Content-type: text/html\n\n");
1026 printf("<h2>Error</h2>\n");
1027 printf("VASTSERV: Could Not Create VAST Table because Data Not Found.<p>\n");
1028 if (pcPDB) MemFree(pcPDB);
1029 return;
1030 }
1031
1032 /* Used ONLY by vastsearch - to retrieve from local file rather than .bas or dbase */
1033
LocalGetBiostrucAnnotSet(Int4 mmdbid,CharPtr JobID)1034 BiostrucAnnotSetPtr LIBCALL LocalGetBiostrucAnnotSet(Int4 mmdbid, CharPtr JobID)
1035 {
1036 FILE *pFile;
1037 AsnIoPtr aip = NULL;
1038 AsnTypePtr atp = NULL;
1039 BiostrucAnnotSetPtr pbsa = NULL;
1040 Char path[PATH_MAX];
1041 Char pcId[20];
1042 Int2 iFileExists = 0;
1043
1044 sprintf(pcId, "/%ld", (long) mmdbid);
1045 pFile = NULL;
1046 StringCpy(path, VSPATH);
1047 StringCat(path, JobID);
1048 StringCat(path, pcId);
1049 StringCat(path, ".bas");
1050 iFileExists = FileLength(path);
1051 if (iFileExists == 0)
1052 {
1053 return NULL;
1054 }
1055
1056 aip = AsnIoOpen(path, "r");
1057 pbsa = BiostrucAnnotSetAsnRead(aip, NULL);
1058 AsnIoClose (aip);
1059 if (!pbsa) return NULL;
1060 return pbsa;
1061 }
1062
1063
1064
1065 BiostrucAnnotSetPtr LIBCALL
LocalGetFeatureSet(Int4 mmdbid,Int4 feature_set_id,CharPtr JobID)1066 LocalGetFeatureSet(Int4 mmdbid, Int4 feature_set_id, CharPtr JobID)
1067 {
1068 BiostrucAnnotSetPtr basp2 = NULL;
1069 BiostrucFeatureSetPtr pbsfs = NULL;
1070 BiostrucAnnotSetPtr basp = NULL;
1071 BiostrucFeatureSetPtr pbsfsLast = NULL;
1072
1073 if (IsVASTData(mmdbid))
1074 basp = VASTBsAnnotSetGet(mmdbid);
1075 else if (IsVASTData(feature_set_id)) {
1076 basp = VASTBsAnnotSetGet(feature_set_id);
1077 if (basp != NULL) return basp;
1078 }
1079 else if (JobID)
1080 basp = LocalGetBiostrucAnnotSet(mmdbid, JobID);
1081
1082 if (basp == NULL)
1083 return NULL;
1084
1085 pbsfs = basp->features;
1086 pbsfsLast = NULL;
1087 basp2 = NULL;
1088 while (pbsfs)
1089 {
1090 if (pbsfs->id == feature_set_id)
1091 {
1092 basp2 = BiostrucAnnotSetNew();
1093 basp2->id = basp->id;
1094 basp->id = NULL; /* unlink the id valnode from basp object */
1095 basp2->descr = basp->descr;
1096 basp->descr = NULL; /* unlink the descr from basp object */
1097 basp2->features = pbsfs;
1098 if (pbsfsLast) /* relink next to prev */
1099 pbsfsLast->next = pbsfs->next;
1100 else
1101 basp->features = pbsfs->next;
1102 basp2->features->next = NULL;
1103 BiostrucAnnotSetFree(basp);
1104 return basp2;
1105 }
1106 pbsfsLast = pbsfs;
1107 pbsfs = pbsfs->next;
1108 }
1109 BiostrucAnnotSetFree(basp);
1110 return basp2;
1111 }
1112
1113
1114
PruneBiostrucAnnotHits(BiostrucAnnotSetPtr basp,Int4 FSID,ValNodePtr pvnFids)1115 BiostrucAnnotSetPtr PruneBiostrucAnnotHits(
1116 BiostrucAnnotSetPtr basp, Int4 FSID, ValNodePtr pvnFids)
1117 {
1118 BiostrucAnnotSetPtr basp2 = NULL;
1119 BiostrucFeatureSetPtr pbsfs = NULL;
1120 BiostrucFeaturePtr pbsf = NULL;
1121 BiostrucFeaturePtr pbsfHold = NULL;
1122 BiostrucFeaturePtr pbsf2 = NULL;
1123 BiostrucFeaturePtr pbsfDie = NULL;
1124
1125 ValNodePtr pvnFid = NULL;
1126 Boolean found = FALSE;
1127
1128 if ((basp == NULL) || (pvnFids == NULL) || (FSID == 0))
1129 return NULL;
1130
1131 pbsfs = basp->features;
1132 while (pbsfs)
1133 {
1134 if (pbsfs->id == FSID)
1135 {
1136 basp2 = BiostrucAnnotSetNew();
1137 basp2->id = basp->id;
1138 basp->id = NULL; /* unlink the id valnode from basp object */
1139 basp2->descr = basp->descr;
1140 basp->descr = NULL; /* unlink the descr from basp object */
1141 basp2->features = BiostrucFeatureSetNew();
1142 basp2->features->id = pbsfs->id;
1143 pbsfs->id = NULL;
1144 basp2->features->descr = pbsfs->descr;
1145 pbsfs->descr = NULL; /* unlink the feature-set descr from basp object */
1146 pbsfHold = pbsfs->features;
1147 pbsfs->features = NULL;
1148 BiostrucAnnotSetFree(basp);
1149 pbsfs = NULL;
1150 pbsf = pbsfHold;
1151 while (pbsf)
1152 {
1153 found = FALSE;
1154 pvnFid = pvnFids;
1155 while (pvnFid)
1156 {
1157 if (pbsf->id == (Int4) pvnFid->data.intvalue)
1158 {
1159 found = TRUE;
1160 break;
1161 }
1162 pvnFid = pvnFid->next;
1163 }
1164 if (!found)
1165 {
1166 pbsfDie = pbsf;
1167 pbsf = pbsf->next;
1168 pbsfDie->next = NULL;
1169 }
1170 else
1171 {
1172 if (!basp2->features->features)
1173 {
1174 basp2->features->features = pbsf;
1175 pbsf2 = basp2->features->features;
1176 pbsf = pbsf->next; /* keep next for loop */
1177 pbsf2->next = NULL; /* chop it */
1178 }
1179 else
1180 {
1181 pbsf2->next = pbsf;
1182 pbsf2 = pbsf;
1183 pbsf = pbsf->next; /* keep next for loop */
1184 pbsf2->next = NULL; /* chop it */
1185 }
1186 }
1187 } /* while pbsf */
1188 }
1189 if(pbsfs) pbsfs = pbsfs->next;
1190 }
1191 return basp2;
1192 }
1193
1194
1195
BiostrucAnnotSetGetByFid(BiostrucAnnotSetPtr basp,Int4 feature_id,Int4 feature_set_id)1196 BiostrucAnnotSetPtr LIBCALL BiostrucAnnotSetGetByFid (
1197 BiostrucAnnotSetPtr basp, Int4 feature_id, Int4 feature_set_id)
1198 {
1199 BiostrucAnnotSetPtr basp2 = NULL;
1200 BiostrucFeatureSetPtr pbsfs = NULL;
1201 BiostrucFeaturePtr pbsf = NULL;
1202
1203 if (basp == NULL)
1204 return NULL;
1205
1206 pbsfs = basp->features;
1207 while (pbsfs)
1208 {
1209 if (pbsfs->id == feature_set_id)
1210 {
1211 pbsf = pbsfs->features;
1212 while(pbsf)
1213 {
1214 if (pbsf->id == feature_id)
1215 { /* found it */
1216 basp2 = BiostrucAnnotSetNew();
1217 basp2->id = basp->id;
1218 basp->id = NULL; /* unlink the id valnode from basp object */
1219 basp2->descr = basp->descr;
1220 basp->descr = NULL; /* unlink the descr from basp object */
1221 basp2->features = BiostrucFeatureSetNew();
1222 basp2->features->id = pbsfs->id;
1223 basp2->features->descr = pbsfs->descr;
1224 pbsfs->descr = NULL; /* unlink the feature-set descr from basp object */
1225 basp2->features->features = BiostrucFeatureNew();
1226 basp2->features->features->id = pbsf->id;
1227 basp2->features->features->name = StringSave(pbsf->name);
1228 basp2->features->features->type = pbsf->type;
1229 basp2->features->features->Property_property = pbsf->Property_property;
1230 pbsf->Property_property = NULL; /* unlink the property from basp object */
1231 basp2->features->features->Location_location = pbsf->Location_location;
1232 pbsf->Location_location = NULL; /* unlink the location from basp object */
1233 BiostrucAnnotSetFree(basp);
1234 return basp2;
1235 }
1236 pbsf = pbsf->next;
1237 }
1238 }
1239 pbsfs = pbsfs->next;
1240 }
1241
1242 BiostrucAnnotSetFree(basp);
1243 return basp2;
1244 }
1245
1246
1247
Check_VastSearch_Password(CharPtr pcPassNew,CharPtr JobID)1248 Int2 LIBCALL Check_VastSearch_Password(CharPtr pcPassNew, CharPtr JobID)
1249 {
1250
1251 Char pcPassFile[24];
1252 Char PassPath[PATH_MAX];
1253 FILE *passwdfile;
1254 CharPtr pcPassOld;
1255 Int4 iPassLen;
1256
1257 iPassLen = StringLen(pcPassNew);
1258 pcPassOld = StringSave(pcPassNew);
1259
1260 sprintf(pcPassFile, "/%s.passwd", JobID);
1261 PassPath[0]='\0';
1262 StringCpy(PassPath, VSPATH);
1263 StringCat(PassPath, JobID);
1264 StringCat(PassPath, pcPassFile);
1265
1266 if ((passwdfile = FileOpen(PassPath, "r")) == NULL)
1267 {
1268
1269 printf("Content-type: text/html\n\n");
1270 printf("<h2>Error</h2>\n");
1271 printf("<body><h2>Cannot examine password</h2>\n");
1272 printf("Please alert info@ncbi.nlm.nih.gov\n");
1273 printf("of this problem\n");
1274 printf("</BODY>\n</HTML>\n");
1275 return 2;
1276 }
1277
1278 fscanf(passwdfile, "%s", pcPassOld);
1279 FileClose(passwdfile);
1280
1281 if (!StringNCmp(pcPassOld, pcPassNew, iPassLen))
1282 return 1;
1283 else
1284 return 0;
1285 }
1286
1287 /* Extract vastsrv parameters from the config file. */
1288
1289 static Boolean
GetVastParams()1290 GetVastParams()
1291 {
1292 URLBase[0] = URLcgi[0] = ENTREZurl[0] = DOCSUMurl[0] = MAILto[0] = '\0';
1293 MMDBpath[0] = gunzip[0] = CGIname[0] = MMDBCGIname[0] = '\0';
1294
1295 GetAppParam("vast", "VASTSRV", "URLBase", "", URLBase, PATH_MAX);
1296
1297 if (URLBase[0] == '\0') {
1298 ErrPostEx(SEV_FATAL, 0, 0, "VAST config file\nVASTSRV section has no URLBase...\n");
1299 return FALSE;
1300 }
1301
1302 GetAppParam("vast", "VASTSRV", "URLcgi", "", URLcgi, PATH_MAX);
1303
1304 if (URLcgi[0] == '\0') {
1305 ErrPostEx(SEV_FATAL, 0, 0, "VAST config file\nVASTSRV section has no URLcgi...\n");
1306 return FALSE;
1307 }
1308
1309 GetAppParam("vast", "VASTSRV", "ENTREZurl", "", ENTREZurl, PATH_MAX);
1310
1311 if (ENTREZurl[0] == '\0') {
1312 ErrPostEx(SEV_FATAL, 0, 0, "VAST config file\nVASTSRV section has no ENTREZurl...\n");
1313 return FALSE;
1314 }
1315
1316 GetAppParam("vast", "VASTSRV", "DOCSUMurl", "", DOCSUMurl, PATH_MAX);
1317
1318 if (DOCSUMurl[0] == '\0') {
1319 ErrPostEx(SEV_FATAL, 0, 0, "VAST config file\nVASTSRV section has no DOCSUMurl...\n");
1320 return FALSE;
1321 }
1322
1323 GetAppParam("vast", "VASTSRV", "Gunzip", "", gunzip, (size_t) 256*(sizeof(char)));
1324
1325 if (gunzip[0] == '\0') {
1326 ErrPostEx(SEV_FATAL, 0, 0, "VAST config file\nVASTSRV section has no Gunzip...\n");
1327 return FALSE;
1328 }
1329
1330 GetAppParam("vast", "VASTSRV", "CGIname", "", CGIname, PATH_MAX);
1331
1332 if (CGIname[0] == '\0') {
1333 ErrPostEx(SEV_FATAL, 0, 0, "VAST config file\nVASTSRV section has no CGIname...\n");
1334 return FALSE;
1335 }
1336
1337 GetAppParam("vast", "VASTSRV", "MMDBCGIname", "", MMDBCGIname, PATH_MAX);
1338
1339 if (MMDBCGIname[0] == '\0') {
1340 ErrPostEx(SEV_FATAL, 0, 0, "VAST config file\nVASTSRV section has no MMDBCGIname...\n");
1341 return FALSE;
1342 }
1343
1344 GetAppParam("mmdb", "MMDB", "Database", "", MMDBpath, PATH_MAX);
1345
1346 if (MMDBpath[0] == '\0') {
1347 ErrPostEx(SEV_FATAL, 0, 0, "MMDB config file\nMMDBSRV section has no Database...\n");
1348 return FALSE;
1349 }
1350
1351 GetAppParam("vast", "VASTSRV", "MAILto", "", MAILto, PATH_MAX);
1352
1353 if (MAILto[0] == '\0') {
1354 ErrPostEx(SEV_FATAL, 0, 0, "VAST config file\nVASTSRV section has no MAILto...\n");
1355 return FALSE;
1356 }
1357
1358 GetAppParam("vast", "VASTSRV", "VSPATH", "", VSPATH, PATH_MAX);
1359
1360 if (VSPATH[0] == '\0') {
1361 ErrPostEx(SEV_FATAL, 0, 0, "VAST config file\nVASTSRV section has no VAST Search path...\n");
1362 return FALSE;
1363 }
1364
1365 GetAppParam("vast", "VASTSRV", "DATApath", "", DATApath, PATH_MAX);
1366 if (DATApath[0] == '\0') {
1367 ErrPostEx(SEV_FATAL, 0, 0, "VAST config file\nVASTSRV section has no VAST Data path...\n");
1368 return FALSE;
1369 }
1370
1371 GetAppParam("vast", "VASTSRV", "VASTpath", "", VASTpath, PATH_MAX);
1372 if (DATApath[0] == '\0') {
1373 ErrPostEx(SEV_FATAL, 0, 0, "VAST config file\nVASTSRV section has no VAST html path...\n");
1374 return FALSE;
1375 }
1376
1377 return TRUE;
1378
1379 } /* end GetVastParams */
1380
1381
1382
1383 Int2
Main()1384 Main()
1385 {
1386 FILE *pFile = NULL, *pIn = NULL;
1387 Char pcBuf[100];
1388 CharPtr pcTest, pcL1 = NULL;
1389 Int4 GetGi, Fid, Fsid, iFileExists = 0, NumLabels = 0;
1390 BiostrucAnnotSetPtr pbsa = NULL;
1391 PDNMS pdnmsMaster = NULL, pdnmsSlave = NULL;
1392 AsnIoPtr aip = NULL;
1393 Int2 iTest = 0, iPDB = 0, iSort = 0, action = 0, viewer = 0, level = 0;
1394 CharPtr Name, Value, IPAddress = getenv("REMOTE_HOST");
1395 struct rlimit rl;
1396 ValNodePtr pvnFid = NULL, pvnFids = NULL;
1397 Int4 iFidCount = 0, count = 0, subsetnum, pagenum, HitsPerPage, indx;
1398 Char subsetname[256];
1399 CharPtr JobID = NULL, pcPass, www_arg;
1400 Int2 ret, iFull = 0;
1401 WWWInfoPtr www_info;
1402
1403
1404
1405 /* this sets up the unix time limit */
1406 getrlimit(RLIMIT_CPU, &rl);
1407 rl.rlim_max = rl.rlim_cur = CPUTIME_MAX;
1408 setrlimit(RLIMIT_CPU, &rl);
1409
1410 if (!GetVastParams()) {
1411 printf("Content-type: text/html\n\n");
1412 printf("<h2>VASTSERV Error</h2>\n");
1413 printf("<h3>Couldn't read from config file...</h3>\n");
1414 exit(1);
1415 }
1416
1417 if (WWWGetArgs(&www_info) != WWWErrOk) {
1418 printf("Content-type: text/html\n\n");
1419 printf("<h2>VASTSERV</h2>\n");
1420 printf("<h3>Failed to process posting - check your get/post syntax.</h3>\n");
1421 exit(1);
1422 }
1423
1424 if ((NumLabels = WWWGetNumEntries(www_info)) == 0) {
1425 printf("Content-type: text/html\n\n");
1426 printf("<h2>VASTSERV</h2>\n");
1427 printf("<h3>No input - nothing to report.</h3>\n");
1428 exit(0);
1429 }
1430
1431 if ((indx = WWWFindName(www_info, "action")) >= 0) {
1432 www_arg = WWWGetValueByIndex(www_info, indx);
1433
1434 if (isdigit(www_arg[0]))
1435 action = (Int2) atoi(www_arg);
1436 else
1437 /* default to asn.1 text */
1438 action = 3;
1439 }
1440 else
1441 action = 3;
1442
1443 /***** We may not add this feature, comment it out for now.
1444 if (action == VIEW_ALIGNMENT) {
1445 (void) VastViewAlign(www_info);
1446 exit(0);
1447 }
1448 *****/
1449
1450 /* check whether or not to launch a viewer */
1451 if ((indx = WWWFindName(www_info, "calltype")) >= 0) {
1452 www_arg = WWWGetValueByIndex(www_info, indx);
1453
1454 switch (www_arg[0]) {
1455 case 'm':
1456 (void) VastToMage(www_info);
1457 exit(0);
1458 case 'p':
1459 (void) VastToPDB(www_info);
1460 exit(0);
1461 case 'a':
1462 (void) VastToCn3D(www_info);
1463 exit(0);
1464 default:
1465 printf("Content-type: text/html\n\n");
1466 printf("<h2>VASTSERV Error</h2>\n");
1467 printf("<h3>Internal failure (bad calltype).\nContact %s</h3>\n", MAILto);
1468 exit(1);
1469 }
1470 }
1471
1472 if (!VASTInit()) {
1473 printf("Content-type: text/html\n\n");
1474 printf("<h2>VASTSERV Error</h2>\n");
1475 printf("<h3>Cannot find VAST data on server.\nContact %s</h3>\n", MAILto);
1476 exit(1);
1477 }
1478
1479 if (!MMDBInit()) {
1480 printf("Content-type: text/html\n\n");
1481 printf("<h2>VASTSERV Error</h2>\n");
1482 printf("<h3>Cannot find MMDB data on server.\nContact %s</h3>\n", MAILto);
1483 exit(1);
1484 }
1485
1486 if ((indx = WWWFindName(www_info, "chaindom")) < 0) {
1487 printf("Content-type: text/html\n\n");
1488 printf("<h2>VASTSERV Error</h2>\n");
1489 printf("<h3>Internal failure (no chaindom).\nContact %s</h3>\n", MAILto);
1490 exit(1);
1491 }
1492
1493 www_arg = WWWGetValueByIndex(www_info, indx);
1494
1495 if (isdigit(www_arg[0]))
1496 Fsid = (Int4) atol(www_arg);
1497 else {
1498 printf("Content-type: text/html\n\n");
1499 printf("<h2>VASTSERV Error</h2>\n");
1500 printf("<h3>Invalid feature set id input; no results.</h3>\n");
1501 exit(1);
1502 }
1503
1504 GetGi = Fsid/10000;
1505
1506 if ((indx = WWWFindName(www_info, "vsid")) >= 0) {
1507 /* we have a VAST Search job */
1508 www_arg = WWWGetValueByIndex(www_info, indx);
1509 JobID = StringSave(www_arg);
1510
1511 if ((indx = WWWFindName(www_info, "pass")) < 0) {
1512 printf("Content-type: text/html\n\n");
1513 printf("<body bgcolor = \"#f0f0f0\"\n");
1514 printf("<h2>VAST SEARCH</h2>\n");
1515 printf("<h3>Password required.</h3>\n");
1516 exit(0);
1517 }
1518
1519 www_arg = WWWGetValueByIndex(www_info, indx);
1520 pcPass = StringSave(www_arg);
1521
1522 if ((ret = Check_VastSearch_Password(pcPass, JobID)) != 1) {
1523 if (ret == 2) exit(0);
1524 printf("Content-type: text/html\n\n");
1525 printf("<body bgcolor = \"#f0f0f0\"\n");
1526 printf("<h2>VAST SEARCH</h2>\n");
1527 printf("<h3>Incorrect password.</h3>\n");
1528 exit(0);
1529 }
1530 }
1531
1532 /* load in the chaindom into memory */
1533 objmmdb1AsnLoad();
1534 objmmdb2AsnLoad();
1535 objmmdb3AsnLoad();
1536 pbsa = LocalGetFeatureSet(GetGi, Fsid, JobID);
1537
1538 if (pbsa == NULL) {
1539 printf("Content-type: text/html\n\n");
1540 printf("<body bgcolor = \"#f0f0f0\">\n");
1541 printf("<br>\n<h2>VAST structure neighbor calculations for this entry are in progress.</h2>\n");
1542 exit(0);
1543 }
1544
1545 /* at this point, there is a valid feature set id and pbsa in memory */
1546
1547 /* subset filtering; identify which subset we're working with */
1548 if ((indx = WWWFindName(www_info, "subset")) < 0)
1549 subsetnum = DEFAULT_SUBSET_NUM;
1550 else {
1551 www_arg = WWWGetValueByIndex(www_info, indx);
1552 StringCpy(subsetname, www_arg);
1553 subsetnum = GetSubsetNum(subsetname);
1554 }
1555
1556 if ((indx = WWWFindName(www_info, "doclistpage")) < 0)
1557 pagenum = DEFAULT_PAGE;
1558 else {
1559 www_arg = WWWGetValueByIndex(www_info, indx);
1560 if (isdigit(www_arg[0]))
1561 pagenum = (Int4) atoi(www_arg);
1562 else
1563 pagenum = DEFAULT_PAGE;
1564 }
1565
1566 if ((indx = WWWFindName(www_info, "dispmax")) < 0)
1567 HitsPerPage = NUM_HITS_PER_PAGE;
1568 else {
1569 www_arg = WWWGetValueByIndex(www_info, indx);
1570 if (isdigit(www_arg[0])) {
1571 HitsPerPage = (Int4) atoi(www_arg);
1572 if ((HitsPerPage < NUM_HITS_PER_PAGE) || (HitsPerPage > 100)) {
1573 printf("Content-type: text/html\n\n");
1574 printf("<h2>VASTSERV Error</h2>\n");
1575 printf("<h3>Can only display between 20 and 100 neighbors per page!</h3>");
1576 exit(1);
1577 }
1578 }
1579 else
1580 HitsPerPage = NUM_HITS_PER_PAGE;
1581 }
1582
1583 if ((indx = WWWFindName(www_info, "sort")) < 0)
1584 iSort = 0;
1585 else {
1586 www_arg = WWWGetValueByIndex(www_info, indx);
1587
1588 if (isdigit(www_arg[0]))
1589 iSort = (Int2) atoi(www_arg);
1590 else
1591 iSort = 0;
1592 }
1593
1594 if ((indx = WWWFindName(www_info, "version")) < 0)
1595 iFull = ABRIDGED_DISPLAY;
1596 else {
1597 www_arg = WWWGetValueByIndex(www_info, indx);
1598
1599 if (isdigit(www_arg[0]))
1600 iFull = (Int2) atoi(www_arg);
1601 else
1602 iFull = ABRIDGED_DISPLAY;
1603 }
1604
1605 /* only two possibilities (so far)! */
1606 if ((iFull != FULL_DISPLAY) && (iFull != ABRIDGED_DISPLAY))
1607 iFull = ABRIDGED_DISPLAY;
1608
1609 if ((indx = WWWFindName(www_info, "hit")) < 0) {
1610 MakeVastTable(Fsid, pbsa, iSort, subsetnum, pagenum, HitsPerPage, iFull, JobID, pcPass);
1611 BiostrucAnnotSetFree(pbsa);
1612 MMDBFini();
1613 exit(0);
1614 }
1615
1616 /* if we get to here then something's wrong! */
1617 exit(1);
1618
1619 } /* end Main */
1620
1621