1 /* vast2pdb.c
2  *
3  * ===========================================================================
4  *
5  *                            PUBLIC DOMAIN NOTICE
6  *            National Center for Biotechnology Information (NCBI)
7  *
8  *  This software/database is a "United States Government Work" under the
9  *  terms of the United States Copyright Act.  It was written as part of
10  *  the author's official duties as a United States Government employee and
11  *  thus cannot be copyrighted.  This software/database is freely available
12  *  to the public for use. The National Library of Medicine and the U.S.
13  *  Government do not place any restriction on its use or reproduction.
14  *  We would, however, appreciate having the NCBI and the author cited in
15  *  any work or product based on this material
16  *
17  *  Although all reasonable efforts have been taken to ensure the accuracy
18  *  and reliability of the software and data, the NLM and the U.S.
19  *  Government do not and cannot warrant the performance or results that
20  *  may be obtained by using this software or data. The NLM and the U.S.
21  *  Government disclaim all warranties, express or implied, including
22  *  warranties of performance, merchantability or fitness for any particular
23  *  purpose.
24  *
25  * ===========================================================================
26  *
27  * File Name: vast2pdb.c
28  *
29  * Author: Tom Madej
30  *
31  * Version Creation Date: 03/12/98
32  *
33  * $Log: vast2pdb.c,v $
34  * Revision 6.9  1999/10/13 20:19:35  zimmerma
35  * DZ: Removed use of temporary files - html output redirected to stdout
36  *
37  * Revision 6.8  1999/05/07 13:59:42  zimmerma
38  * Changed call to InstBSAnnotSet() to pass Chain and SlaveChain params
39  *
40  * Revision 6.7  1999/02/17 19:30:31  addess
41  * fixed problem with not being able to read new files
42  *
43  * Revision 6.6  1998/10/14  17:18:42  addess
44  * sending aligned chains to RASMOL
45  *
46  * Revision 6.5  1998/07/17  18:47:44  madej
47  * Allow files to be seen with Vast Search.
48  *
49  * Revision 6.4  1998/06/11  19:10:39  madej
50  * Minor cosmetic change.
51  *
52  * Revision 6.3  1998/05/19  20:22:26  madej
53  * Add general WWW routines for running on Sun servers.
54  *
55  * Revision 6.2  1998/03/30  19:13:41  madej
56  * Changes by Ken Addess.
57  *
58  * Revision 6.1  1998/03/12  17:10:26  madej
59  * First official version of vast2pdb.c
60  *
61  */
62 
63 #include <stdio.h>
64 #include <ncbi.h>
65 #include <accentr.h>
66 #include <netentr.h>
67 #include <www.h>
68 #include <sys/resource.h>
69 #include <mmdbapi.h>
70 #include "vastlocl.h"
71 #include "mmdblocl.h"
72 #include "mmdbdata.h"
73 #include "vast2mage.h"
74 #include "vast2pdb.h"
75 #include "vastsrv.h"
76 
77 static char *BaseURL;
78 static FILE *OutputFile = NULL;
79 static char OutputName[200];
80 
81 
82 /* Generate a PDB-format file with the reference protein rotated in the frame
83  * of the master.  This file can then be loaded, e.g. into Kinemage, and the
84  * structural alignment with the master protein displayed.
85  */
86 
VastToPDB(WWWInfoPtr www_info)87 Boolean LIBCALL VastToPDB(WWWInfoPtr www_info)
88 {
89   FILE *pFile = NULL;
90   FILE *pIn = NULL;
91   Char pcBuf[100];
92   CharPtr pcTest;
93   Int4 GetGi, Fid, Fsid;
94   Int4 iFileExists = 0, indx, complexity;
95   Char pcLine[256];
96   CharPtr pcL1 = NULL, www_arg;
97   CharPtr JobID = NULL, pcPass;
98   BiostrucAnnotSetPtr pbsa = NULL;
99   BiostrucAnnotSetPtr pbsaShort = NULL;
100   PDNMS pdnmsMaster = NULL;
101   PDNMS pdnmsSlave = NULL;
102   Int2 iTest = 0, iPDB = 0, ret;
103   AsnIoPtr aip = NULL;
104   Char giBuf[20], URL[200];
105   char *IPAddress = getenv("REMOTE_HOST");
106   Boolean Chain;
107 
108   if ((indx = WWWFindName(www_info, "uid")) < 0) {
109     printf("Content-type: text/html\n\n");
110     printf("<h2>VASTSERV (VastToPDB)</h2>\n");
111     printf("<h3>No accession (PDB ID) was input - nothing to report.</h3>\n");
112     return 0;
113   }
114 
115   www_arg = WWWGetValueByIndex(www_info, indx);
116 
117   if (isdigit(www_arg[0]))
118     GetGi = (Int4) atoi(www_arg);
119   else {
120     printf("Content-type: text/html\n\n");
121     printf("<h2>VASTSERV Error (VastToPDB)</h2>\n");
122     printf("<h3>Non-numeric MMDB-id input - no results.</h3>\n");
123     return 0;
124   }
125 
126   /* vsid and pass are to look at alignments from VAST Search */
127 	if ((indx = WWWFindName(www_info, "vsid")) >= 0) {
128 		www_arg = WWWGetValueByIndex(www_info, indx);
129 		JobID = StringSave(www_arg);
130 
131 		if ((indx = WWWFindName(www_info, "pass")) < 0) {
132 			printf("Content-type: text/html\n\n");
133 			printf("<body bgcolor = \"#f0f0f0\">\n");
134 			printf("<h2>VAST SEARCH</h2>\n");
135 			printf("<h3>Password required.</h3>\n");
136 			return 0;
137 		}
138 		else {
139 			www_arg = WWWGetValueByIndex(www_info, indx);
140 			pcPass = StringSave(www_arg);
141 
142 			if ((ret = Check_VastSearch_Password(pcPass, JobID)) != 1) {
143 				if (ret == 2) return 0;
144 				printf("Content-type: text/html\n\n");
145 				printf("<body bgcolor = \"#f0f0f0\">\n");
146 				printf("<h2>VAST SEARCH</h2>\n");
147 				printf("<h3>Incorrect password.</h3>\n");
148 				return 0;
149 			}
150 		}
151 	}
152   if ((indx = WWWFindName(www_info, "hit")) < 0) {
153     printf("Content-type: text/html\n\n");
154     printf("<body bgcolor = \"#f0f0f0\">\n");
155     printf("<br>\n<h2>No alignment was selected!</h2>\n");
156     printf("<h3>Please click on a box in the leftmost column of the table.</h3>\n");
157     return 0;
158   }
159 
160   www_arg = WWWGetValueByIndex(www_info, indx);
161 
162   if (isdigit(www_arg[0]))
163     Fid = (Int4) atoi(www_arg);
164   else {
165     printf("Content-type: text/html\n\n");
166     printf("<h2>VASTSERV Error (VastToPDB)</h2>\n");
167     printf("<h3>Non-numeric slave alignment code - no results.</h3>\n");
168     return 0;
169   }
170 
171   if ((indx = WWWFindName(www_info, "chaindom")) < 0) {
172     printf("Content-type: text/html\n\n");
173     printf("<h2>VASTSERV Error (VastToPDB)</h2>\n");
174     printf("<h3>No feature set ID (master alignment code) - nothing to report.</h3>\n");
175     return 0;
176   }
177 
178   www_arg = WWWGetValueByIndex(www_info, indx);
179 
180   if (isdigit(www_arg[0]))
181     Fsid = (Int4) atoi(www_arg);
182   else {
183        printf("Content-type: text/html\n\n");
184        printf("<h2>Error</h2>\n");
185        printf("<h3>Non-numeric master alignment code - no results</h3>\n");
186        return 0;
187    }
188    if ((indx = WWWFindName(www_info, "chn_complexity")) < 0)
189             Chain = TRUE;
190    else
191    {
192      www_arg = WWWGetValueByIndex(www_info, indx);
193      complexity =(Int2)atoi(www_arg);
194 
195      if (complexity) Chain = TRUE;
196      else Chain = FALSE;
197    }
198   /* action == 0 indicates MIME; action == 1 is text; action == 2 is save */
199   if ((indx = WWWFindName(www_info, "action")) < 0)
200     iPDB = 0;
201   else {
202     www_arg = WWWGetValueByIndex(www_info, indx);
203 
204     if (isdigit(www_arg[0]))
205       iPDB = (Int4) atoi(www_arg);
206     else
207       iPDB = 0;
208   }
209 
210   if (VASTInit() != TRUE) {
211     printf("Content-type: text/html\n\n");
212     printf("<h2>VASTSERV Error (VastToPDB)</h2>\n");
213     printf("<h3>Can't find VAST data on server.\n");
214     printf("Contact info@ncbi.nlm.nih.gov</h3>\n");
215     return 0;
216   }
217 
218   OpenMMDBAPI((POWER_VIEW /* ^ FETCH_ENTREZ */), NULL);
219   if (JobID == NULL)
220     pbsa = VASTBsAnnotSetGet(Fsid);
221   else
222     pbsa = LocalGetFeatureSet(GetGi, Fsid, JobID);
223 
224   if (pbsa == NULL) {
225     printf("Content-type: text/html\n\n");
226     printf("<h2>VASTSERV Error (VastToPDB)</h2>\n");
227     printf("<h3>No master alignment record exists for %ld.</h3>\n", (long) GetGi);
228     return 0;
229   }
230 
231   pbsaShort =  BiostrucAnnotSetGetByFid(pbsa, Fid, Fsid);
232 
233   if (pbsaShort == NULL) {
234     printf("Content-type: text/html\n\n");
235     printf("<h2>VASTSERV Error (VastToPDB)</h2>\n");
236     printf("<h3>Can't find alignment record.</h3>\n");
237     return 0;
238   }
239 
240   if (MMDBInit() == FALSE) {
241     printf("Content-type: text/html\n\n");
242     printf("<h2>VASTSERV Error (VastToPDB)</h2>\n");
243     printf("<h3>MMDBInit Failed.</h3>\n");
244     return 0;
245   }
246 
247  /*
248    aip = AsnIoOpen("pbsashort", "w");
249    BiostrucAnnotSetAsnWrite(pbsaShort, aip, NULL);
250    AsnIoClose(aip);
251  */
252 
253   /* K.A. changed 4/26/99 - previously used InstBSAnnotSet and InstBSAnnotSetVS */
254   /* collapsed to single version w/NULL JobID and Chain where not needed      */
255 
256   InstBSAnnotSet(pbsaShort, JobID, Chain, VSPATH);
257   pdnmsMaster = GetSelectedModelstruc();
258   pdnmsSlave = GetSlaveModelstruc();
259   if (!pdnmsMaster)
260     {
261       printf("Content-type: text/html\n\n");
262       printf("<h2>Error</h2>\n");
263       printf("<h3>Unable to load structures on server, - no VAST results</h3>\n");
264       return 0;
265      }
266 
267   /* PDB FILE GENERATOR */
268 
269    if (iPDB == 2)
270      {
271        fprintf(stdout, "Content-type: application/octet-stream\n\n");
272      }
273    else if (iPDB == 1)
274      {
275        fprintf(stdout, "Content-type: text/html\n\n");
276        fprintf(stdout, "<HTML><body><pre>\n");
277      }
278    else
279      { /* MIME */
280        fprintf(stdout,"Content-type: chemical/x-pdb\n\n");
281      }
282   iTest = WritePDBOneModel(pdnmsSlave, stdout,  0);
283 
284   if (!iTest)
285     {
286       printf("Content-type: text/html\n\n");
287       printf("<h2>Error</h2>\n");
288       printf("PDB File write failed on Server.<p>\n");
289       RemoveTempFiles();
290       CloseMMDBAPI();
291       MMDBFini();
292       VASTFini();
293       exit(1);
294     }
295   if (iPDB == 1)
296      {
297        fprintf(stdout, "</pre></body></HTML>\n");
298 
299      }
300 
301 
302   fflush(stdout);
303 
304   CloseMMDBAPI();
305   MMDBFini();
306   VASTFini();
307   return 0;
308 }
309 
310