1
/* $Id: mmdbsrv.c,v 6.28 2001/12/12 20:43:38 beloslyu Exp $
2
* ===========================================================================
5
* National Center for Biotechnology Information
7
* This software/database is a "United States Government Work" under the
8
* terms of the United States Copyright Act. It was written as part of
9
* the author's official duties as a United States Government employee and
10
* thus cannot be copyrighted. This software/database is freely available
11
* to the public for use. The National Library of Medicine and the U.S.
12
* Government have not placed any restriction on its use or reproduction.
14
* Although all reasonable efforts have been taken to ensure the accuracy
15
* and reliability of the software and data, the NLM and the U.S.
16
* Government do not and cannot warrant the performance or results that
17
* may be obtained by using this software or data. The NLM and the U.S.
18
* Government disclaim all warranties, express or implied, including
19
* warranties of performance, merchantability or fitness for any particular
22
* Please cite the author in any work or product based on this material.
24
* ===========================================================================
26
* File Name: $RCSfile: mmdbsrv.c,v $
28
* Author: Christopher Hogue
30
* Version Creation Date: 6 January 1997
38
* Revision 6.28 2001/12/12 20:43:38 beloslyu
39
* change the name of ftp site to ftp.ncbi.nih.gov
41
* Revision 6.27 2001/01/25 23:02:56 lewisg
42
* get rid of content-disp, add mdlLvl and maxModels args
44
* Revision 6.26 2000/08/21 16:12:42 lewisg
45
* add save=asntext option
47
* Revision 6.25 2000/06/26 18:05:26 lewisg
48
* fix another hardcoded url
50
* Revision 6.24 2000/06/23 22:35:58 lewisg
51
* get rid of hardcoded urls
53
* Revision 6.23 2000/01/31 19:59:12 lewisg
54
* fix output of date in pdb header
56
* Revision 6.22 1999/10/13 20:13:18 zimmerma
57
* DZ: Removed use of temporary files - html ouput redirected to stdout
59
* Revision 6.21 1999/06/17 14:44:09 zimmerma
60
* Added static char variable for cvsId in order to use unix "what"
62
* Revision 6.20 1999/06/15 18:15:34 addess
63
* Initialized this_uid to 0 on line 1286
65
* Revision 6.19 1999/05/13 15:51:33 kimelman
66
* bugfix: memory deallocation fixed
68
* Revision 6.19 1999/05/13 15:51:33 kimelman
69
* bugfix: memory deallocation fixed
71
* Revision 6.18 1999/05/11 23:36:34 kimelman
72
* make StrToInt4 static
74
* Revision 6.17 1999/05/11 17:50:23 kimelman
77
* Revision 6.16 1999/04/28 21:08:30 lewisg
78
* fixed double freeing of Biostruc
80
* Revision 6.15 1999/04/28 18:26:15 kimelman
81
* exit codes changed to 0
83
* Revision 6.14 1999/04/22 01:56:44 kimelman
84
* 1. pdb reference read completely from configurstion files
86
* 3. NcbiMimeAsn1Free(mime) commented out <-- lead to core
87
* dump AFTER sending MIME (quick & dirty fix)
89
* Revision 6.13 1999/04/19 16:52:57 kimelman
92
* Revision 6.12 1999/03/05 19:18:47 addess
93
* changed URL to link to RCSB structure explorer
95
* Revision 6.11 1998/11/06 16:25:31 addess
96
* added features for layer-1 and PDB TITLE records
98
* Revision 6.10 1998/07/17 18:45:53 madej
99
* Got rid of some unused URLs.
101
* Revision 6.9 1998/06/11 19:12:53 madej
102
* Changes in a message type for Cn3D by Yanli.
104
* Revision 6.8 1998/04/16 17:51:38 madej
105
* Tweak to print out author names in new/old format.
107
* Revision 6.7 1998/04/15 14:54:05 kimelman
108
* 1. Make retrieval unifirm from open server and sql server.
109
* 2. mmdbsrv retrival performance tuning:
110
* - size of read-in buffers
111
* - direct pdb2mmdb DB lookup instead of full loading pdb to mmdb translataion
113
* 3. cleaning mmdblocl.* and make.mmdbsrv in order to remove obsolete code
115
* Revision 6.6 1998/04/03 20:25:24 kimelman
116
* PubStruct access code added to mmdbsrv
118
* Revision 6.5 1998/02/20 18:25:26 madej
119
* Fix using unlink to stop file dumps into /var/tmp.
121
* Revision 6.4 1997/11/25 18:27:45 madej
122
* Fix to save asn.1 files in binary.
124
* Revision 6.3 1997/11/05 19:05:16 madej
125
* Updated comments for config file.
127
* Revision 6.2 1997/11/05 15:58:57 madej
128
* Bug fix for tax names in multiple listings
130
* Revision 6.1 1997/10/31 15:29:57 madej
131
* Major reformat of structure summary page, including taxonomy links.
133
* Revision 6.0 1997/08/25 18:11:28 madden
134
* Revision changed to 6.0
136
* Revision 1.2 1997/05/16 21:25:41 hogue
137
* Added checks with vast database entries before showing vast links.
139
* Revision 1.1 1997/02/18 18:03:30 hogue
143
* ==========================================================================
149
*db=t&form=6&uid=1OMD&dopt=s - PDB or MMDB-ids allowed
150
*db=t&form=6&uid=1OMD&Dopt=i - launch Cn3D Mime-type - first UID only.
151
*db=t&uid=1234,2345,1254,1232&dopt=s - multiple structure summaries
152
*db=t&uid=3INS,1234,1OMD&dopt=s - mixed id types OK
154
*Optional, but if wrong, error:
155
* db=t any other is an error message
156
* form=6 4 is an error message - any other ignored
159
* uid=(list of MMDB ids or PDB ids)
162
* 's' Structure summary
166
* Others - error; None assumes 's'
168
*Optional - Interpreted in Context:
169
* complexity="Cn3D+Subset" ONECOORDATOM, 1
170
* "Virtual+Bond+Model" ONECOORDRES, 1
171
* "Up+to+5+Models" ALLMDL, 5
172
* "Up+to+10+Models" ALLMDL, 10
173
* "All+Models" ALLMDL, 100
175
* KinemageColor="Molecule+Number" KIN_COLOR_NUMBER
176
* "Secondary+Structure" KIN_COLOR_TYPE
177
* "Thermal+Factor" KIN_COLOR_TEMP
178
* "Element" KIN_COLOR_ATOM
179
* KinemageRender=(integer) - not seen on Struc Summary
183
* header="no" same as save="s"
184
* title="no" - omit title bar and bottom options
189
/*******************************************
190
MMDBSRV MIRROR installation:
192
This describes what you need to run MMDBSRV:
194
1] YOUR MMDB DATA DIRECTORIES, e.g.:
198
These contain the MMDB data on your local filesystem,
199
as obtained from ftp://ftp.ncbi.nih.gov/mmdb/mmdbdata
200
and updated regularly by MIRROR. You can
201
put them in the CGI-BIN or HTTP (HTML) directories
202
if you prefer. If you wish to implement a local
203
decompression/compression scheme see the source code mmdblocl.c.
205
2] YOUR CGI-BIN directory & URL, e.g.:
207
...cgi-bin/mmdb/logs/
208
...cgi-bin/mmdb/data/
209
http://123.456.789.10/cgi-bin/mmdb/
211
The first contains the compiled mmdbsrv program and the
212
config file, obtained from
213
ftp://ftp.ncbi.nih.gov/mmdb/www/mmdbsrv
214
The second will contain the log files written out.
215
The third needs sshead.txt, sscode.txt, sstail.txt
216
NOTE - you must edit "sstail.txt"
217
in order to get the proper links to your local
218
copy of help documentation & server.
220
3] YOUR HTTP (HTML) directory & URL, e.g.:
222
...html/mmdb/mmdbgifs
223
http://123.456.789.10/mmdb/
225
The first contains the html files to launch mmdbsrv,
226
arrow.gif, strucsum.gif and any other gif files, and the
227
associated MMDB help files struchelp.html, cn3d.html,
228
strucinstall.html, vast.html, etc. Master copies are kept
229
at ftp://ftp.ncbi.nih.gov/mmdb/www/http
230
You must hand edit or use scripts or SED to change links from
231
NCBI's to your own in all these HTML files.
233
The second contains the GIF library as obtained from
234
the NCBI ftp site ftp://ftp.ncbi.nih.gov/mmdb/mmdbgifs
236
6] Your WWW-Server - make it aware of the following
238
chemical/ncbi-asn1-binary *.val
239
chemical/x-pdb *.ent; *.pdb
240
chemical/x-kinemage *.kin
243
-----------------------------
245
MMDBSRV gets its directory structure; link URLS and CGI call names
247
Change these as required and make a config file.
248
Unix ".mmdbrc" or Win "mmdb.ini" from this example:
251
URLHelp, ENTREZurl, MMDBurl, PDBurl, 3DBurl
252
unless there are broken external links to these.
254
-------------------- cut here --------------------
256
;Database and Index required when local MMDB database is used.
258
Database = /net/dorothy/cbb3/mmdb/data/
262
; File for configuring the MMDB server.
263
; Base Directory & URLs for HTML documents.
264
HTMLPath = /net/vaster/usr/attic/httpd.local/htdocs/Structure/
265
URLBase = http://inhouse.ncbi.nlm.nih.gov:6224/Structure/
266
URLHelp = http://www.ncbi.nlm.nih.gov/Entrez/
269
; Base Directory for CGI-BIN code, data (gifs, html text) and logs.
270
CGIPath = /net/vaster/usr/attic/httpd.local/cgi-bin/Structure/
271
URLcgi = http://inhouse.ncbi.nlm.nih.gov:6224/cgi-bin/Structure/
277
; Base Directory for MMDB-gif set
278
GIFpath = /net/vaster/usr/attic/httpd.public/htdocs/Structure/mmdbgifs/
279
GIFurl = http://www.ncbi.nlm.nih.gov/Structure/mmdbgifs/
282
; URL's for links to Entrez, VAST.
283
ENTREZurl = http://www.ncbi.nlm.nih.gov/htbin-post/Entrez/query
284
VASTurl = http://inhouse.ncbi.nlm.nih.gov:6224/cgi-bin/Structure/vastsrv
285
MMDBurl = http://www.ncbi.nlm.nih.gov/Structure/
286
PDBurl = http://www.pdb.bnl.gov/index.html
287
TDBurl = http://www.pdb.bnl.gov/cgi-bin/opdbshort
289
; Location of gunzip function.
290
Gunzip = /usr/sbin/gunzip
293
MAILto = info@ncbi.nlm.nih.gov
296
;Database required for local VAST fetches.
297
;Database = /net/vaster/usr/people6/madej/vastdata.binary/
298
Database = /net/dorothy/cbb3/vast/data/
300
; URL for link to taxonomy database (wgetorg for retrieval)
302
TAXurl = http://www.ncbi.nlm.nih.gov/htbin-post/Taxonomy/wgetorg
304
-------------------- cut here --------------------
305
********************************************/
311
#include <miscutils.h>
312
#include <sys/resource.h>
314
#include <mmdbdata.h>
316
#include <sys/resource.h>
318
#include <lsqfetch.h>
326
#define CPUTIME_MAX 120
331
#define NUM_COMPLEXITY_TYPES 6
332
static char *ComplexityDescriptions[] =
333
{"Virtual Bond Model","All Atom Model","Up to 5 Models",
334
"Up to 10 Models","All Models","Cn3D Subset"};
336
#define NUM_COLOR_TYPES 5
337
static char *ColorDescriptions[] =
338
{"","Molecule Number","Secondary Structure","Thermal Factor","Element"};
340
/* the config file DATApath is used for the location of these files */
342
#define HEADFILE "sshead.txt"
343
/* Structure Summary Header File */
345
#define TAILFILE "sstail.txt"
346
/* Structure Summary Tail File */
348
#define CODEFILE "sscode.txt"
349
/* Structure Summary View Code */
351
#define CHAIN_CHOICE_NUM 1
352
#define ORG_CHOICE_NUM 6
354
/* some defines needed for the taxonomy code */
356
#define TAX_ID_CHOICE_NUM 0
357
#define MAX_CHAINS 128
358
#define MAX_TBUFF 8192
360
WWWInfoPtr info = NULL;
362
static Boolean GlobalTitles = TRUE;
363
static Boolean GlobalNonHtmlOutput = FALSE;
365
static Char HTMLPath[PATH_MAX];
366
static Char URLBase[PATH_MAX];
367
static Char URLHelp[PATH_MAX];
369
static Char CGIPath[PATH_MAX];
370
static Char URLcgi[PATH_MAX];
371
static Char CGIName[256];
372
static Char DATApath[PATH_MAX];
373
static Char LOGpath[PATH_MAX];
375
static Char ENTREZurl[PATH_MAX];
376
static Char VASTurl[PATH_MAX];
377
static Char MMDBurl[PATH_MAX];
378
static Char PDBurl[PATH_MAX];
379
static Char TDBurl[PATH_MAX];
380
static Char TAXurl[PATH_MAX];
381
static Char MAILto[256];
382
static Char MAILTO[PATH_MAX];
383
static Char ARROW[PATH_MAX];
385
static char* cvsId_ = "@(#)$Id: mmdbsrv.c,v 6.28 2001/12/12 20:43:38 beloslyu Exp $";
387
/*****************************************************
388
* WWWPrintFileData looks in the current CGI-BIN directory
389
* or the "data" subdirectory for the data file.
390
* and prints it out to pFile
393
static void WWWPrintFileData(CharPtr FName, FILE *pFile)
397
Char fullpath [PATH_MAX];
402
StringCpy(fullpath, DATApath); /* look in DATApath */
403
StringCat(fullpath, FName);
404
f = FileOpen (fullpath, "r");
406
f = FileOpen (FName, "r"); /* look in curent */
407
if (f == NULL) { /* look in ./data/ */
408
ProgramPath (fullpath, sizeof (fullpath) - 1);
409
ptr = StringRChr (fullpath, DIRDELIMCHR);
413
FileBuildPath (fullpath, "data", FName);
414
f = FileOpen (fullpath, "r");
423
ptr = fgets(pcBuf, (size_t)1024, f);
424
if (ptr) fprintf(pFile, ptr);
433
StrToInt4 (CharPtr str, Int4Ptr longval)
438
Nlm_Boolean nodigits;
441
if (longval != NULL) {
442
*longval = (Nlm_Int4) 0;
444
len = (Nlm_Int2) Nlm_StringLen (str);
449
for (i = 0; i < len; i++)
454
if ('0' <= ch && ch <= '9')
456
else if ( !/*!!*/ (ch == ' ' || ch == '+' || ch == '-') || nodigits==FALSE)
463
Nlm_StringNCpy (local, str, sizeof (local));
464
if (sscanf (local, "%ld", &val) == 1)
471
static Int4 CountUIDs(char *String)
477
String = SkipSet(String,", ");
478
if (*String == NULLB)
481
String = SkipToSet(String,", ");
487
static Int4 ConvertMMDBUID(CharPtr pcString)
490
CharPtr pcTemp = NULL;
492
if (pcString == NULL)
496
pcTemp = StringSave(pcString);
498
if (!StrToInt4(pcTemp, &iUID))
500
iUID = MMDBEvalPDB(pcTemp);
509
static void MakeUIDList(CharPtr pcString, ValNodePtr PNTR ppvnUIDS)
513
Char SavedChar = NULL;
518
Ptr = SkipSpaces(pcString);
524
Ptr2 = SkipToSet(Ptr," ,");
528
Uid = ConvertMMDBUID(Ptr);
529
/* printf("{%s}[%ld]\n", Ptr, Uid); */
532
ValNodeAddInt(ppvnUIDS, 0, Uid);
535
Ptr = SkipSet(Ptr2," ,");
542
static Int4 GetOptionValue(CharPtr Value, Int4 NumElements, CharPtr *ElementText)
547
if (StrToInt4(Value, &valnum))
550
Len = StringLen(Value);
551
for (count = 0; count < NumElements; count++)
552
if (StrNICmp(ElementText[count],Value, Len) == 0)
555
if (count == NumElements)
563
/* Output links from the protein and nucleotide chains to GenPept reports. */
565
#define EntrezLink "<A HREF=\"%s?uid=%ld&form=6&db=%c&dopt=%c\">%s</A>"
567
/************ Added by Ken for Layer One PDB releases ************/
569
static void My_StringNCpy(CharPtr str1, CharPtr str2, Int4 len)
571
StringNCpy(str1,str2,len);
575
static Boolean IsLayerOne(ValNodePtr pvn)
577
Boolean Layer = FALSE;
579
CharPtr LayerOne = {"This is Layer 1 Release"};
585
if (pvn->choice == BiostrucDescr_pdb_comment)
587
comment_txt = (CharPtr)pvn->data.ptrvalue;
588
temp_string = StringSave(LayerOne);
589
len = StringLen(LayerOne);
590
My_StringNCpy(temp_string, &comment_txt[18], len);
591
if (!StringICmp(temp_string, LayerOne))
602
/***** End of functions added by Ken ********************/
604
PrintMolecularContents(PDNMS ModelStruc, FILE *gdf)
613
if (ModelStruc == NULL)
617
pmsd = (PMSD) ModelStruc->data.ptrvalue;
619
for (pdnmm = pmsd->pdnmmHead, cnt = 0; pdnmm != NULL; pdnmm = pdnmm->next) {
620
pmmd = (PMMD) pdnmm->data.ptrvalue;
622
if ((pmmd->bWhat) & AM_PROT) {
624
fprintf(gdf, "<TR>\n<TD VALIGN=TOP NOWRAP>");
625
fprintf(gdf, "<strong>Protein Chains:</strong></TD>\n<TD>");
627
if (pmmd->pcMolName[0] == ' ')
628
fprintf(gdf, EntrezLink, ENTREZurl, (long) pmmd->iGi, 'p', 'g',
631
fprintf(gdf, EntrezLink, ENTREZurl, (long) pmmd->iGi, 'p', 'g',
636
fprintf(gdf, EntrezLink, ENTREZurl, (long) pmmd->iGi, 'p', 'g',
643
fprintf(gdf, "</TD>\n</TR>\n");
645
/* nucleotide chains */
646
for (pdnmm = pmsd->pdnmmHead, cnt = 0; pdnmm != NULL; pdnmm = pdnmm->next) {
647
pmmd = (PMMD) pdnmm->data.ptrvalue;
649
if ((pmmd->bWhat) & (AM_DNA | AM_RNA)) {
651
fprintf(gdf, "<TR>\n<TD VALIGN=TOP NOWRAP>");
652
fprintf(gdf, "<strong>Nucleotide chains:</strong></TD>\n<TD>");
654
if (pmmd->pcMolName[0] == ' ')
655
fprintf(gdf, EntrezLink, ENTREZurl, (long) pmmd->iGi, 'n', 'g',
658
fprintf(gdf, EntrezLink, ENTREZurl, (long) pmmd->iGi, 'n', 'g',
663
fprintf(gdf, EntrezLink, ENTREZurl, (long) pmmd->iGi, 'n', 'g',
670
fprintf(gdf, "</TD>\n</TR>\n");
672
} /* end PrintMolecularContents */
677
PrintStructureInfo(PDNMS ModelStruc, FILE *File, CharPtr tax_save)
680
Int4 depyear, depday;
681
PMSD pmsdThis = NULL;
682
BiostrucSourcePtr pbssThis = NULL;
683
ValNodePtr pvnThis = NULL;
684
BiostrucHistoryPtr pbshThis = NULL;
685
CharPtr pcAuthors = NULL;
691
pmsdThis = (PMSD) ModelStruc->data.ptrvalue;
692
pvnThis = ValNodeFindNext(pmsdThis->pbsBS->descr,NULL,BiostrucDescr_history);
695
pbshThis = (BiostrucHistoryPtr) pvnThis->data.ptrvalue;
696
pbssThis = pbshThis->data_source;
700
fprintf(File, "<font size=+2>MMDB Id: %ld  ", (long) pmsdThis->iMMDBid);
702
fprintf(File, "<font size=+2>");
703
fprintf(File, "MMDB Id: <A HREF=\"%s%s?uid=%ld&form=6&db=t&Dopt=s\">%ld</A>  ",
704
URLcgi, CGIName, (long) pmsdThis->iMMDBid, (long) pmsdThis->iMMDBid);
705
fprintf(File, "PDB Id: <A HREF=\"%s=%s\">%s</a>\n", TDBurl,pmsdThis->pcPDBName, pmsdThis->pcPDBName);
706
if (IsLayerOne(pmsdThis->pbsBS->descr))
707
fprintf(File, " - Warning: <A HREF=\"http://www.pdb.bnl.gov/pdb-docs/what_is_LR.html\">Not validated!</A>\n");
708
fprintf(File, "</font>");
709
fprintf(File, "<BR>\n<BR>\n");
710
fprintf(File, "<TABLE>\n");
711
PrintMolecularContents(ModelStruc, File);
712
fprintf(File, "<TR>\n<TD VALIGN=TOP NOWRAP>");
713
fprintf(File, "<strong>MEDLINE</strong>:</TD>\n<TD><A HREF=\"%s?db=t&form=6&uid=", ENTREZurl);
714
fprintf(File, "%ld&Dopt=m\">PubMed</A></TD>\n</TR>\n", (long) pmsdThis->iMMDBid );
716
if (tax_save != NULL)
717
fprintf(File, "%s\n", tax_save);
718
else if (pmsdThis->pcPdbSource) {
719
fprintf(File, "<TR>\n<TD VALIGN=TOP NOWRAP>");
720
fprintf(File, "<strong>Source</strong>:</TD>\n<TD>%s</TD>\n</TR>\n", pmsdThis->pcPdbSource);
723
/* insert a blank row in the table, for spacing */
724
fprintf(File, "<TR>\n<TD VALIGN=TOP NOWRAP> </TD>\n<TD><BR></TD>\n</TR>\n");
725
pcAuthors = AuthorListPDB(pmsdThis->pbsBS);
728
fprintf(File, "<TR>\n<TD VALIGN=TOP NOWRAP>");
729
fprintf(File, "<strong>PDB Authors</strong>:</TD>\n<TD>%s</TD>\n</TR>\n", pcAuthors);
735
depyear = pbssThis->database_entry_date->data[1];
736
depday = pbssThis->database_entry_date->data[3];
737
fprintf(File, "<TR>\n<TD VALIGN=TOP NOWRAP>");
738
fprintf(File, "<strong>PDB Deposition</strong>:</TD>\n<TD>%2d-%3s-%02d</TD>\n</TR>\n",
739
(int) depday, NCBI_months[pbssThis->database_entry_date->data[2] - 1], (int) depyear%100);
742
if (pmsdThis->pcPdbClass) {
743
fprintf(File, "<TR>\n<TD VALIGN=TOP NOWRAP>");
744
fprintf(File, "<strong>PDB Class</strong>:</TD>\n<TD>%s</TD>\n</TR>\n", pmsdThis->pcPdbClass);
747
fprintf(File, "<TR>\n<TD VALIGN=TOP NOWRAP>");
748
pvnThis = ValNodeFindNext(pmsdThis->pGraphDescr,NULL,BiomolDescr_pdb_comment);
750
fprintf(File, "<strong>PDB Title</strong>:</TD>\n<TD>%s</TD>\n</TR>\n", pmsdThis->pcChemName);
752
fprintf(File, "<strong>PDB Compound</strong>:</TD>\n<TD>%s</TD>\n</TR>\n", pmsdThis->pcChemName);
753
/* insert a blank row in the table, for spacing */
754
fprintf(File, "<TR>\n<TD VALIGN=TOP NOWRAP> </TD>\n<TD><BR></TD>\n</TR>\n");
756
/* Note: The table continues with "Sequence Neighbors" and "Structure Neighbors". */
764
PrintStructureView(PDNMS ModelStruc, FILE *File)
768
if (ModelStruc == NULL) return;
770
pmsd = (PMSD) ModelStruc->data.ptrvalue;
771
fprintf(File, "<FORM METHOD=POST ACTION=\"%s%s\">\n", URLcgi, CGIName);
772
fprintf(File, "<INPUT TYPE=HIDDEN NAME=uid VALUE=%ld>\n", (long) pmsd->iMMDBid);
773
WWWPrintFileData(CODEFILE, File);
778
/* This routine creates the last two rows of the table started by PrintStructureInfo.
779
* These last two rows contain the links for the "Sequence Neighbors" of the chains of
780
* the structure, and for "Structure Neighbors" of the chains and domains of the
781
* structure. The first part of the code is very similar to PrintMolecularContents.
782
* The 2nd part creates the links for the VAST structure neighbors.
784
* Note there are 3 different formats for Vast neighbor links, purely for cosmetics.
787
#define VastLink1 "<A HREF=\"%s?uid=%ld&chaindom=%ld\">%s</A>"
788
#define VastLink2 "<A HREF=\"%s?uid=%ld&chaindom=%ld\">%s.%d</A>"
789
#define VastLink3 "<A HREF=\"%s?uid=%ld&chaindom=%ld\">%d</A>"
792
PrintStructureLinks(PDNMS ModelStruc, FILE *gdf)
800
Int4 uid, ichn, idom, chndom, chndom0;
804
if (ModelStruc == NULL)
807
/* insert a blank row in the table, for spacing */
808
fprintf(gdf, "<TR>\n<TD VALIGN=TOP NOWRAP> </TD>\n<TD> </TD>\n</TR>\n");
811
pmsd = (PMSD) ModelStruc->data.ptrvalue;
813
for (pdnmm = pmsd->pdnmmHead, cnt = pflg = 0; pdnmm != NULL; pdnmm = pdnmm->next) {
814
pmmd = (PMMD) pdnmm->data.ptrvalue;
816
if ((pmmd->bWhat) & AM_PROT) {
817
if ((pmmd->iResCount <= 1) || (pmmd->iGi <= 0))
822
fprintf(gdf, "<TR>\n<TD VALIGN=TOP NOWRAP>");
823
fprintf(gdf, "<strong>Sequence Neighbors:</strong></TD>\n<TD>");
825
if (pmmd->pcMolName[0] == ' ')
826
fprintf(gdf, EntrezLink, ENTREZurl, (long) pmmd->iGi, 'p', 'p',
829
fprintf(gdf, EntrezLink, ENTREZurl, (long) pmmd->iGi, 'p', 'p',
834
fprintf(gdf, EntrezLink, ENTREZurl, (long) pmmd->iGi, 'p', 'p',
840
/* nucleotide chains */
841
for (pdnmm = pmsd->pdnmmHead; pdnmm != NULL; pdnmm = pdnmm->next) {
842
pmmd = (PMMD) pdnmm->data.ptrvalue;
844
if ((pmmd->bWhat) & (AM_DNA | AM_RNA)) {
845
if ((pmmd->iResCount <= 1) || (pmmd->iGi <= 0))
849
fprintf(gdf, "<TR>\n<TD VALIGN=TOP NOWRAP>");
850
fprintf(gdf, "<strong>Sequence Neighbors:</strong></TD>\n<TD>");
852
if (pmmd->pcMolName[0] == ' ')
853
fprintf(gdf, EntrezLink, ENTREZurl, (long) pmmd->iGi, 'n', 'n',
856
fprintf(gdf, EntrezLink, ENTREZurl, (long) pmmd->iGi, 'n', 'n',
861
fprintf(gdf, EntrezLink, ENTREZurl, (long) pmmd->iGi, 'n', 'n',
868
fprintf(gdf, "</TD>\n</TR>\n");
870
if (pmsd->pdnmlModels == NULL) {
872
fprintf(gdf, "</TABLE>\n<BR>\n");
876
/* VAST neighbors: loop over protein chains */
877
uid = (Int4) pmsd->iMMDBid;
879
for (pdnmm = pmsd->pdnmmHead, cnt = ichn = 0; pdnmm != NULL; pdnmm = pdnmm->next) {
880
pmmd = (PMMD) pdnmm->data.ptrvalue;
883
if ((pmmd->bWhat) & AM_PROT) {
884
if ((pmmd->iResCount <= 1) || (pmmd->iGi <= 0))
887
chndom0 = 10000*uid + 100*(Int4) ichn;
890
fprintf(gdf, "<TR>\n<TD VALIGN=TOP NOWRAP>");
891
fprintf(gdf, "<strong>Structure Neighbors:</strong></TD>\n<TD>");
893
if (pmmd->pcMolName[0] == ' ')
894
fprintf(gdf, VastLink1, VASTurl, (long) uid, (long) chndom0,
897
fprintf(gdf, VastLink1, VASTurl, (long) uid, (long) chndom0,
902
fprintf(gdf, VastLink1, VASTurl, (long) uid, (long) chndom0,
906
/* now loop over domains */
909
for (pdnmg = pmmd->pdnmgHead; pdnmg != NULL; pdnmg = pdnmg->next) {
910
pmgd = (PMGD) pdnmg->data.ptrvalue;
912
if (pmgd->iDomain > idom) {
913
idom = (Int4) pmgd->iDomain;
914
chndom = chndom0 + idom;
917
if (pmmd->pcMolName[0] == ' ')
918
fprintf(gdf, VastLink3, VASTurl, (long) uid,
919
(long) chndom, (int) idom);
921
fprintf(gdf, VastLink2, VASTurl, (long) uid,
922
(long) chndom, pmmd->pcMolName, (int) idom);
929
fprintf(gdf, "</TD>\n</TR>\n</TABLE>\n");
931
} /* end PrintStructureLinks */
935
/* Utility routine needed below. Return a vector marking the distinct integers
936
* appearing in the input array. A naive algorithm is used since we never expect
937
* the array size 'n' to be large. If an entry vec[i] is 0, this means it is
938
* a duplicate. If vec[i] > 0 then this is the first occurrence of the number,
939
* and the value vec[i] is the number of times the corresponding number nums[i]
944
mark_distinct(Int4Ptr nums, Int2Ptr vec, Int2 n)
951
/* initialize the vector */
952
for (i = 0; i < n; i++)
955
for (i = 1; i < n; i++) {
956
for (j = 0; j < i; j++) {
957
if (nums[i] == nums[j]) {
965
} /* end mark_distinct */
969
/* Output the taxonomy data, per chain, and also links to the taxonomy database.
970
* Return '1' in case there was a non-trivial taxonomy assignment, '0' if there
971
* was no taxonomy data found. The success or failure is passed ultimately to
972
* PrintStructureInfo, where the PDB source is displayed in case no taxonomy data
977
SaveTaxonomyInfo(BiostrucPtr bsp, CharPtr save, Int2 n, CharPtr pname)
979
MoleculeGraphPtr mgp;
980
Int4 i, j, k, cnt, txcnt, uacnt;
981
ValNodePtr descr, db;
982
CharPtr chainp, name, names[MAX_CHAINS];
983
Char chn, chns[MAX_CHAINS], org_names[MAX_TBUFF];
984
Int2 flg, name_here, cnt_vec[MAX_CHAINS];
987
Int4 molecule_type, tax_id, tax_ids[MAX_CHAINS];
991
if ((bsp == NULL) || (save == NULL))
994
for (i = 0; i < MAX_TBUFF; i++)
998
mgp = bsp->chemical_graph->molecule_graphs;
1000
for (cnt = uacnt = 0; (mgp != NULL) && (cnt < MAX_CHAINS); mgp = mgp->next) {
1001
/* zap the OrgRefPtr, there may be no taxonomy for this chain! */
1004
for (descr = mgp->descr; descr != NULL; descr = descr->next) {
1005
if (descr->choice == BiomolDescr_molecule_type)
1006
molecule_type = descr->data.intvalue;
1008
if (descr->choice == BiomolDescr_name) {
1009
chainp = descr->data.ptrvalue;
1013
if (descr->choice == BiomolDescr_organism) {
1014
bios = descr->data.ptrvalue;
1015
org = (OrgRefPtr) bios->org;
1019
if ((molecule_type == Molecule_type_protein) ||
1020
(molecule_type == Molecule_type_dna) ||
1021
(molecule_type == Molecule_type_rna)) {
1023
/* save the chain and get the taxonomy data */
1024
chns[cnt] = (chn == ' ') ? '\n' : chn;
1028
ObjectIdPtr object_id;
1030
for (db = org->db, tax_id = -1; db != NULL; db = db->next) {
1031
if (db->choice == TAX_ID_CHOICE_NUM) {
1032
dbtag = db->data.ptrvalue;
1033
tax_id = dbtag->tag->id;
1038
names[cnt] = &org_names[name_here];
1040
if (org->taxname != NULL) {
1041
StringCat(names[cnt], org->taxname);
1042
name_here += StrLen(org->taxname) + 1;
1044
else if (org->common != NULL) {
1045
StringCat(names[cnt], org->common);
1046
name_here += StrLen(org->common) + 1;
1049
StringCat(names[cnt], "(unassigned)");
1053
tax_ids[cnt++] = tax_id;
1056
/* track the number of unassigned chains */
1058
names[cnt] = &org_names[name_here];
1059
StringCat(names[cnt], "(unassigned)");
1061
tax_ids[cnt++] = -1;
1066
/* zap the save area */
1067
for (i = 0; i < n; i++)
1070
/* flag the taxonomy section */
1071
sprintf(save, "<TR>\n<TD VALIGN=TOP NOWRAP><strong>Taxonomy</strong>:</TD>\n");
1075
sprintf(&save[k], "<TD>(unassigned)</TD>\n");
1079
/* group chains by organism type, i.e. tax id */
1080
mark_distinct(tax_ids, cnt_vec, cnt);
1082
for (i = flg = 0; i < cnt; i++) {
1083
if (cnt_vec[i] == 0)
1086
tax_id = tax_ids[i];
1090
sprintf(&save[k], "; ");
1092
sprintf(&save[k], "<TD>");
1096
/* collect chains with the same tax id */
1102
sprintf(&save[k], "chains ");
1103
else if (chns[i] != '\n')
1104
sprintf(&save[k], "chain ");
1107
for (j = i; (j < cnt) && (txcnt > 0); j++) {
1108
if (tax_ids[j] != tax_id)
1114
sprintf(&save[k], "%c, ", chns[j]);
1116
sprintf(&save[k], "%c", chns[j]);
1122
if (chns[i] != '\n')
1123
sprintf(&save[k], "  <A HREF=\"");
1125
sprintf(&save[k], "<A HREF=\"");
1128
sprintf(&save[k], TAXurl, tax_id);
1130
sprintf(&save[k], "\">%s</A> ", names[i]);
1133
sprintf(&save[k], " (unassigned)");
1137
sprintf(&save[k], "</TD>\n</TR>\n");
1140
} /* end SaveTaxonomyInfo */
1144
/* Old version of DumpMime, preserved for compatibility with Cn3D v1.0. */
1146
static void DumpMime_v1(AsnIoPtr aip, CharPtr title, Int2 style, Int2 choice, VoidPtr datum)
1148
NcbiMimeAsn1Ptr mime;
1149
EntrezGeneralPtr egp;
1151
mime = (NcbiMimeAsn1Ptr) ValNodeNew(NULL);
1152
mime->choice = NcbiMimeAsn1_entrez;
1153
egp = EntrezGeneralNew();
1154
mime->data.ptrvalue = (VoidPtr) egp;
1155
egp->Data_data = ValNodeNew(NULL);
1156
egp->title = StringSave(title);
1158
egp->Data_data->choice = choice;
1159
egp->Data_data->data.ptrvalue = datum;
1161
NcbiMimeAsn1AsnWrite(mime, aip, NULL);
1164
egp->Data_data->data.ptrvalue = NULL; /* for clean free */
1165
NcbiMimeAsn1Free(mime);
1167
} /* end DumpMime_v1 */
1172
static void DumpMime(AsnIoPtr aip, CharPtr title, VoidPtr datum)
1174
NcbiMimeAsn1Ptr mime;
1175
EntrezGeneralPtr egp;
1177
mime = (NcbiMimeAsn1Ptr) ValNodeNew(NULL);
1178
mime->choice = NcbiMimeAsn1_strucseq;
1179
mime->data.ptrvalue= datum;
1181
NcbiMimeAsn1AsnWrite(mime, aip, NULL);
1184
mime->data.ptrvalue=NULL ; /* for clean free */
1185
NcbiMimeAsn1Free(mime);
1190
#define LAUNCH_VIEWER 0
1195
/* Handle the various View/See/Save file options. */
1198
SendStructureMIME(Char Filetype, Int4 uid, Int4 Mime, Int4 Complexity,
1199
Int4 Models, Int4 Color, Int4 Render)
1203
Int4 count, i4Sent = 0, error_flag = 0;
1207
NcbiMimeAsn1Ptr mime;
1208
BiostrucSeqPtr bssp;
1209
BiostrucGraphPtr bsgp;
1210
MoleculeGraphPtr mgp;
1216
if ((bsp = MMDBBiostrucGet((DocUid) uid, Complexity, Models)) == NULL) {
1217
printf("Content-type: text/html\r\n\r\n");
1218
printf("<h2>Error</h2>\n");
1219
printf("Structure with UID = %ld failed to fetch on Server<p>\n", (long) uid);
1220
printf("No such structure available on this MMDB server.\n");
1225
bsgp = bsp->chemical_graph;
1226
mgp = bsgp->molecule_graphs;
1228
/* This_uid = EntrezFindSeqId(sip); */
1230
if(sip->choice == 12) This_uid = sip->data.intvalue;
1233
sep = EntrezSeqEntryGet(This_uid, retcode);
1235
bssp = BiostrucSeqNew();
1236
bssp->structure = bsp;
1237
ValNodeLink(&(bssp->sequences), sep);
1239
mime = (NcbiMimeAsn1Ptr) ValNodeNew(NULL); /* yanli */
1240
mime->choice = NcbiMimeAsn1_strucseq;
1241
mime->data.ptrvalue = bssp;
1244
/* the following headers are format-independent */
1247
printf("Content-type: application/octet-stream\r\n\r\n");
1250
printf ("Content-type: text/html\r\n\r\n");
1251
printf ("<HTML><PRE>\r\n");
1254
printf ("Content-type: text/html\r\n\r\n");
1258
if (Filetype == 'j') {
1259
/* Cn3D v2.0 asn.1 format */
1262
printf ("Content-type: chemical/ncbi-asn1-binary\r\n\r\n");
1263
aip = AsnIoNew(ASNIO_BIN_OUT, stdout, NULL, NULL, NULL);
1264
DumpMime(aip, "MIME", bssp);
1267
aip = AsnIoNew(ASNIO_BIN_OUT, stdout, NULL, NULL, NULL);
1268
NcbiMimeAsn1AsnWrite(mime, aip, NULL);
1271
aip = AsnIoNew(ASNIO_TEXT_OUT, stdout, NULL, NULL, NULL);
1272
NcbiMimeAsn1AsnWrite(mime, aip, NULL);
1275
aip = AsnIoNew(ASNIO_TEXT_OUT, stdout, NULL, NULL, NULL);
1276
NcbiMimeAsn1AsnWrite(mime, aip, NULL);
1283
else if (Filetype == 'i') {
1284
/* Cn3D v1.0 asn.1 format. Included for backwards compatibility, in case users
1285
* want to stick with their old Cn3D for some reason.
1289
printf ("Content-type: chemical/ncbi-asn1-binary\r\n\r\n");
1290
/* printf ("Content-disposition: filename=\"%d.val\"\r\n\r\n", uid);*/
1291
aip = AsnIoNew(ASNIO_BIN_OUT, stdout, NULL, NULL, NULL);
1292
DumpMime_v1(aip, "MIME", Entrez_style_report, Data_data_structure, bsp);
1295
aip = AsnIoNew(ASNIO_BIN_OUT, stdout, NULL, NULL, NULL);
1296
BiostrucAsnWrite(bsp, aip, NULL);
1299
aip = AsnIoNew(ASNIO_TEXT_OUT, stdout, NULL, NULL, NULL);
1300
BiostrucAsnWrite(bsp, aip, NULL);
1303
aip = AsnIoNew(ASNIO_TEXT_OUT, stdout, NULL, NULL, NULL);
1304
BiostrucAsnWrite(bsp, aip, NULL);
1311
else if (Filetype == 'r') {
1313
if (Mime == LAUNCH_VIEWER)
1314
printf ("Content-type: chemical/x-pdb\r\n\r\n");
1315
/* printf ("Content-disposition: filename=\"%d.pdb\"\r\n\r\n", uid);*/
1317
ModelStruc = MakeAModelstruc(bsp);
1318
bssp->structure = NULL; /* already linked into modelstruc */
1319
WritePDBAllModel(ModelStruc, stdout);
1322
else if (Filetype == 'k') {
1324
if (Mime == LAUNCH_VIEWER)
1325
printf ("Content-type: chemical/x-kinemage\r\n\r\n");
1326
/* printf ("Content-disposition: filename=\"%d.kin\"\r\n\r\n", uid);*/
1328
ModelStruc = MakeAModelstruc(bsp);
1329
bssp->structure = NULL; /* already linked into modelstruc */
1330
WriteKinAllModel(ModelStruc, stdout, Color, Render);
1335
printf("Content-type: text/html\r\n\r\n");
1336
printf("<h2>Error</h2>\n");
1337
printf("Unknown file type on structure fetch.<p>\n");
1338
printf("Contact %s\n", MAILTO);
1341
if ((Mime == SEE_FILE) && (!error_flag))
1342
printf ("</PRE></HTML>\r\n");
1344
NcbiMimeAsn1Free(mime); /* yanli */
1347
} /* end SendStructureMIME */
1350
static Int4 SendSummaryPage(Int4Ptr Uids, Int4 NumToDisplay, Int4 Save)
1355
Int4 uid, count, i4Sent = 0;
1357
Char tax_save[MAX_TBUFF];
1361
printf ("Content-type: application/octet-stream\n\n");
1363
printf ("Content-type: text/html\n\n");
1365
if (!GlobalNonHtmlOutput) {
1367
WWWPrintFileData(HEADFILE, stdout);
1369
printf ( "<html>\n<title>MMDB Structure Summary</title><body>");
1371
for (count = 0; count < NumToDisplay; count++)
1374
bsp = MMDBBiostrucGet((DocUid) uid,3,0);
1377
printf ("%sNo structure found for UID %ld.%s\n",
1378
GlobalNonHtmlOutput ? "\n" : "<P><h4>",uid,
1379
GlobalNonHtmlOutput ? "\n" : "</h4><P>");
1380
if (!GlobalNonHtmlOutput)
1381
printf ("<HR SIZE=5 NOSHADE><BR>\n");
1385
if (!GlobalNonHtmlOutput) {
1388
for (descr = bsp->descr, name = NULL; descr != NULL; descr = descr->next) {
1389
if (descr->choice == BiomolDescr_name) {
1390
name = descr->data.ptrvalue;
1394
taxret = SaveTaxonomyInfo(bsp, tax_save, MAX_TBUFF, name);
1397
ModelStruc = MakeAModelstruc(bsp);
1398
PrintStructureInfo(ModelStruc, stdout, (taxret) ? tax_save : NULL);
1400
if (!GlobalNonHtmlOutput) /* Rest of View/Save stuff */
1402
PrintStructureLinks(ModelStruc, stdout);
1403
PrintStructureView(ModelStruc, stdout);
1404
printf ("<HR SIZE=5 NOSHADE><BR>\n");
1409
if (!GlobalNonHtmlOutput)
1411
WWWPrintFileData(TAILFILE, stdout);
1416
} /* SendSummaryPage() */
1419
static void SendGetNetscape(void) {
1421
printf("HTTP/1.0 200 OK\r\n");
1422
printf("MIME-Version: 1.0\r\n");
1423
printf("Content-type: text/html\r\n\r\n");
1424
printf("<BR><BR><B>Sorry, you need a <a href=\"http://home.netscape.com/\">",
1425
"Netscape</a> version 2 or higher WWW-browser "
1426
"to be able to enter this page</B><BR>\n\n");
1427
} /* SendGetNetscape */
1432
static Boolean InitMMDBSrv(void)
1444
ENTREZurl[0] = '\0';
1451
for (i = 0; i < PATH_MAX; i++)
1454
FindPath("mmdb", "MMDBSRV", "HTMLPath", HTMLPath, PATH_MAX);
1455
if (HTMLPath[0] == '\0')
1457
ErrPostEx(SEV_FATAL,0,0, "MMDB config file \nMMDBSRV section no HTMLPath...\n");
1460
GetAppParam("mmdb", "MMDBSRV", "URLBase", "", URLBase, PATH_MAX);
1461
if (URLBase[0] == '\0')
1463
ErrPostEx(SEV_FATAL,0,0, "MMDB config file \nMMDBSRV section no URLBase...\n");
1466
GetAppParam("mmdb", "MMDBSRV", "URLHelp", "", URLHelp, PATH_MAX);
1467
if (URLHelp[0] == '\0')
1469
ErrPostEx(SEV_FATAL,0,0, "MMDB config file \nMMDBSRV section no URLHelp...\n");
1472
FindPath("mmdb", "MMDBSRV", "CGIPath", CGIPath, PATH_MAX);
1473
if (CGIPath[0] == '\0')
1475
ErrPostEx(SEV_FATAL,0,0, "MMDB config file \nMMDBSRV section no CGIPath...\n");
1479
GetAppParam("mmdb", "MMDBSRV", "URLcgi", "", URLcgi, PATH_MAX);
1480
if (URLcgi[0] == '\0')
1482
ErrPostEx(SEV_FATAL,0,0, "MMDB config file \nMMDBSRV section no URLcgi...\n");
1485
GetAppParam("mmdb", "MMDBSRV", "CGIName", "", CGIName, (size_t) 256 * sizeof(char));
1486
if (CGIName[0] == '\0')
1488
ErrPostEx(SEV_FATAL,0,0, "MMDB config file \nMMDBSRV section no CGIName...\n");
1491
FindPath("mmdb", "MMDBSRV", "DATApath", DATApath, PATH_MAX);
1492
if (DATApath[0] == '\0')
1494
ErrPostEx(SEV_FATAL,0,0, "MMDB config file \nMMDBSRV section no DATApath...\n");
1498
sprintf(ARROW, "<IMG alt=\"o\" SRC=\"%sarrow.gif\" ALT=\"o\" BORDER=0>\n", URLBase);
1500
FindPath("mmdb", "MMDBSRV", "LOGpath", LOGpath, PATH_MAX);
1501
if (LOGpath[0] == '\0')
1503
ErrPostEx(SEV_FATAL,0,0, "MMDB config file \nMMDBSRV section no LOGpath...\n");
1506
GetAppParam("mmdb", "MMDBSRV", "ENTREZurl", "", ENTREZurl, PATH_MAX);
1507
if (ENTREZurl[0] == '\0')
1509
ErrPostEx(SEV_FATAL,0,0, "MMDB config file \nMMDBSRV section no ENTREZurl...\n");
1512
GetAppParam("mmdb", "MMDBSRV", "VASTurl", "", VASTurl, PATH_MAX);
1513
if (VASTurl[0] == '\0')
1515
ErrPostEx(SEV_FATAL,0,0, "MMDB config file \nMMDBSRV section no VASTurl...\n");
1518
GetAppParam("mmdb", "MMDBSRV", "MMDBurl", "", MMDBurl, PATH_MAX);
1519
if (MMDBurl[0] == '\0')
1521
ErrPostEx(SEV_FATAL,0,0, "MMDB config file \nMMDBSRV section no MMDBurl...\n");
1524
GetAppParam("mmdb", "MMDBSRV", "PDBurl", "", PDBurl, PATH_MAX);
1525
if (PDBurl[0] == '\0')
1527
ErrPostEx(SEV_FATAL,0,0, "MMDB config file \nMMDBSRV section no PDBurl...\n");
1530
GetAppParam("mmdb", "MMDBSRV", "TDBurl", "", TDBurl, PATH_MAX);
1531
if (TDBurl[0] == '\0')
1533
ErrPostEx(SEV_FATAL,0,0, "MMDB config file \nMMDBSRV section no TDBurl...\n");
1536
GetAppParam("mmdb", "TAXLINK", "TAXurl", "", TAXurl, PATH_MAX);
1537
if (TAXurl[0] == '\0')
1539
ErrPostEx(SEV_FATAL,0,0, "MMDB config file \nTAXLINK section no TAXurl...\n");
1542
StringCat(TAXurl, "?id=%d&lvl=0");
1543
GetAppParam("mmdb", "MMDBSRV", "MAILto", "", MAILto, PATH_MAX);
1544
if (MAILto[0] == '\0')
1546
ErrPostEx(SEV_FATAL,0,0, "MMDB config file \nMMDBSRV section no Mailto...\n");
1551
sprintf(MAILTO, "< <a href=\"%s\">%s</a> >", MAILto, MAILto);
1558
/************************************************************************
1560
* Int2 Main() - main function
1562
***********************************************************************/
1568
Boolean Netscape2_OK = FALSE;
1570
CharPtr TimeNowStr = NULL;
1572
Int4 IndexArgs = -1;
1578
Char DispOpt = '\0';
1580
CharPtr pcThis = NULL, pcName = NULL;
1581
CharPtr Uids; /* (list of MMDB ids or PDB ids) */
1582
Int4Ptr MMDBids = NULL; /* (list of MMDB ids ) */
1586
Int4 NumEntries = 0;
1587
ValNodePtr pvnUIDS = NULL, pvnThis = NULL;
1589
/* this sets up the unix time limit */
1594
getrlimit(RLIMIT_CPU, &rl);
1595
rl.rlim_max = rl.rlim_cur = CPUTIME_MAX;
1596
setrlimit(RLIMIT_CPU, &rl);
1600
if (!InitMMDBSrv()) {
1601
printf("Content-type: text/html\r\n\r\n");
1602
printf("<H2>MMDBSRV Error</H2>\n - Unable to Open Server Configuration File.<p>\n");
1603
printf("Contact the MMDBSRV administrator for this site.<p>\n");
1607
StringCat(LOGpath, "mmdbsrv.log");
1608
if( !ErrSetLogfile (LOGpath, ELOG_APPEND) ) {
1609
printf("Content-type: text/html\r\n\r\n");
1610
printf("<H2>MMDBSRV Error</H2>\n - Unable to Open Log.<p>\n");
1611
printf("Contact MMDBSRV administrator for this site: %s<p>\n", MAILTO);
1615
ErrSetLogLevel(SEV_MAX);
1616
ErrSetOpts (ERR_CONTINUE, ERR_LOG_ON);
1620
if((error = WWWGetArgs(&info)) != WWWErrOk) {
1621
printf("Content-type: text/html\r\n\r\n");
1622
printf("<H2>MMDBSRV Error</H2>\n Failed to Process Posting - Check your GET/POST syntax\n");
1627
/* if(WWWGetBrowser(info) != NETSCAPE) {
1632
if ((!OpenMMDBAPI(0, NULL)) || (!MMDBInit()))
1634
ErrLogPrintf("#MMDB Database Access Failed to Initialize.\n");
1635
printf("Content-type: text/html\r\n\r\n");
1636
printf("<H2>MMDBSRV Error</H2>\n - Unable to Open MMDB Database on Server.<p>");
1637
printf("Contact MMDBSRV administrator for this site: %s<p>\n", MAILTO);
1641
if (EntrezInit("mmdbsrv", NULL, FALSE) == FALSE)
1643
printf("Content-type: text/html\n\n");
1644
printf("<h2>Error</h2>\n");
1645
printf("MMDBSERV: EntrezInit Failed.<p>\n");
1649
/*if( !BioseqFetchInit(TRUE))
1651
ErrLogPrintf("BioseqFetchInit failed! \n");
1652
printf("Content-type: text/html\r\n\r\n");
1653
printf("<H2>MMDBSRV Error</H2>\n - BioseqFetchInit failed! <p>");
1654
printf("Contact MMDBSRV administrator for this site: %s<p>\n", MAILTO);
1662
if ((IndexArgs = WWWFindName(info,"db")) >= 0)
1664
pcThis = WWWGetValueByIndex(info,IndexArgs);
1665
DispOpt = pcThis[0];
1666
if ((DispOpt != 't') && (DispOpt != 'T'))
1668
printf("Content-type: text/html\r\n\r\n");
1669
printf("<H2>MMDBSRV Error</H2>\n - Wrong Database Type db=%c.<p>\n", DispOpt );
1670
printf("Try <a href=\"%s\">WWW-Entrez</a> for this<p>\n", URLHelp);
1676
if ((IndexArgs = WWWFindName(info, "form")) >= 0)
1678
pcThis = WWWGetValueByIndex(info,IndexArgs);
1679
if ((!StrToInt4(pcThis,&Form)) || (Form != 6))
1681
printf("Content-type: text/html\r\n\r\n");
1682
printf("<H2>MMDBSRV Error</H2>\n - Wrong Form Type form=%s.<p>\n", pcThis );
1683
printf("<pre>Only supports form=6</pre><p>\n");
1684
printf("Try <a href=\"%s\">WWW-Entrez</a> for this<p>\n", URLHelp);
1693
if ((IndexArgs = WWWFindName(info, "uid")) < 0)
1695
printf("Content-type: text/html\r\n\r\n");
1696
printf("<H2>MMDBSRV Error</H2>\n - No Identifier specified:<p>\n<pre>Missing uid=</pre><p>\n");
1701
/* loop over entire set of tag=value entries and add all the UID's found together */
1702
/* must handle uid=1234&uid=1OMD&uid=1234,2345,2134&dopt=s&uid=3INS */
1703
NumEntries = WWWGetNumEntries(info);
1704
for (IndexArgs = 0; IndexArgs < NumEntries; IndexArgs++)
1706
pcName = WWWGetNameByIndex(info, IndexArgs);
1707
pcThis = WWWGetValueByIndex(info, IndexArgs);
1709
if (StrICmp(pcName, "uid") == 0)
1711
/* printf("[%s][%s]\n", pcThis, pcName); */
1712
MakeUIDList(pcThis, &pvnUIDS);
1715
if (pvnUIDS == NULL)
1717
printf("Content-type: text/html\r\n\r\n");
1718
printf("<H2>MMDBSRV Error</H2>\n - UID specified does not match an MMDB-ID or PDB-Code:<p>\n");
1725
pvnThis = pvnThis->next;
1727
MMDBids = (Int4Ptr) MemNew((size_t) (sizeof(Int4) * iMMDBids));
1732
MMDBids[iCount] = (Int4) pvnThis->data.intvalue;
1733
/* printf("%ld \n",(long) MMDBids[iCount]); */
1734
pvnThis = pvnThis->next;
1741
if ((IndexArgs = WWWFindName(info, "dopt")) >= 0)
1743
pcThis = WWWGetValueByIndex(info,IndexArgs);
1773
printf("Content-type: text/html\r\n\r\n");
1774
printf("<H2>MMDBSRV Error</H2>\n - Wrong Display Option Type: dopt=%s.<p>\n", pcThis);
1775
printf("<pre>dopt supports:\n's' Structure summary\n");
1776
printf("'r' RasMol(PDB) format\n'k' Kinemage format\n'i', 'j', or 'a' ASN.1</pre><p>\n");
1783
DispOpt = 's'; /* structure summary is default when no dopt supplied */
1788
if ((IndexArgs = WWWFindName(info, "Complexity")) >= 0)
1790
pcThis = WWWGetValueByIndex(info,IndexArgs);
1793
for (iCount = 0; iCount < NUM_COMPLEXITY_TYPES; iCount++)
1794
if (StrICmp(pcThis,ComplexityDescriptions[iCount]) == 0)
1803
Complex = ONECOORDRES;
1806
Complex = ONECOORDATOM;
1815
MaxModels = INT2_MAX;
1818
Complex = ONECOORDATOM;
1822
printf("Content-type: text/html\r\n\r\n");
1823
printf("<H2>MMDBSRV Error</H2>\n - Wrong Complexity Type: Complexity=%s.<p>\n", pcThis );
1830
if ((IndexArgs = WWWFindName(info, "mdlLvl")) >= 0)
1832
pcThis = WWWGetValueByIndex(info, IndexArgs);
1833
Complex = atoi(pcThis);
1837
if ((IndexArgs = WWWFindName(info, "maxModels")) >= 0)
1839
pcThis = WWWGetValueByIndex(info, IndexArgs);
1840
MaxModels = atoi(pcThis);
1844
if ((IndexArgs = WWWFindName(info, "KinemageColor")) >= 0)
1846
pcThis = WWWGetValueByIndex(info, IndexArgs);
1847
KinColor = GetOptionValue(pcThis, NUM_COLOR_TYPES, ColorDescriptions);
1853
if ((IndexArgs = WWWFindName(info, "KinemageRender")) >= 0)
1855
pcThis = WWWGetValueByIndex(info,IndexArgs);
1856
StrToInt4(pcThis, &KinRender);
1860
if ((IndexArgs = WWWFindName(info, "save")) >= 0)
1861
{ /* these don't affect structure summaries */
1862
pcThis = WWWGetValueByIndex(info,IndexArgs);
1863
if (StrICmp(pcThis, "See") == 0)
1865
Save = 1; /* sends MIMED-type files to view in ascii-readable form */
1867
else if (StrICmp(pcThis, "Save") == 0)
1869
Save = 2; /* sends MIMED-type files in raw save form */
1871
else if (StrICmp(pcThis, "M") == 0)
1873
Save = 3; /* MacSave - not implemented */
1875
else if (StrICmp(pcThis, "asntext") == 0)
1877
Save = SEND_FILE; /* writes out asn text without the html header */
1882
if ((IndexArgs = WWWFindName(info, "header")) >= 0)
1884
pcThis = WWWGetValueByIndex(info,IndexArgs);
1885
if (StrICmp(pcThis, "no") == 0)
1893
if ((IndexArgs = WWWFindName(info, "title")) >= 0)
1895
pcThis = WWWGetValueByIndex(info,IndexArgs);
1896
if (StrICmp(pcThis, "no") == 0)
1899
GlobalTitles = FALSE;
1904
if ((IndexArgs = WWWFindName(info, "html")) >= 0)
1906
pcThis = WWWGetValueByIndex(info,IndexArgs);
1907
if (StrICmp(pcThis, "no") == 0)
1909
GlobalNonHtmlOutput = TRUE;
1910
GlobalTitles = FALSE;
1916
/* call the pertinent Page Sender */
1920
iBytes = SendSummaryPage(MMDBids, iMMDBids, Save);
1924
iBytes = SendStructureMIME(DispOpt, MMDBids[0], Save ,
1925
Complex, MaxModels, KinColor, KinRender);
1931
/* log first MMDB-id, number of id's asked for, number of bytes sent */
1932
time_now = GetSecs();
1933
TimeNowStr = ctime(&time_now);
1934
TimeNowStr[24] = '\0';
1935
ErrLogPrintf("\n%s|%s|%s|%s|Do %c|Id %ld|No %ld|By %ld|Sv %ld|Cp %ld|Md %ld|Kc %ld|Kr %ld",
1936
WWWGetAddress(info), WWWGetHost(info), WWWGetAgent(info), TimeNowStr,
1938
(long) MMDBids[0], (long) iMMDBids, (long)iBytes, (long) Save,
1939
(long) Complex, (long) MaxModels, (long) KinColor, (long) KinRender);
1951
/* log first MMDB-id, number of id's asked for, number of bytes sent */
1952
time_now = GetSecs();
1953
TimeNowStr = ctime(&time_now);
1954
TimeNowStr[24] = '\0';
1955
ErrLogPrintf("\n#Syntax Error %s|%s|%s|%s|%ld",
1956
WWWGetAddress(info), WWWGetHost(info), WWWGetAgent(info), TimeNowStr,
1964
/* log first MMDB-id, number of id's asked for, number of bytes sent */
1965
time_now = GetSecs();
1966
TimeNowStr = ctime(&time_now);
1967
TimeNowStr[24] = '\0';
1968
ErrLogPrintf("\n#Query Not Supported %s|%s|%s|%s|%ld",
1969
WWWGetAddress(info), WWWGetHost(info), WWWGetAgent(info), TimeNowStr,
1975
time_now = GetSecs();
1976
TimeNowStr = ctime(&time_now);
1977
TimeNowStr[24] = '\0';
1978
ErrLogPrintf("\n#Get/Post Error %s|%s|%s|%s|%ld",
1979
WWWGetAddress(info), WWWGetHost(info), WWWGetAgent(info), TimeNowStr,