NCBI C Toolkit Cross Reference

C/biostruc/newVSch/cVSMmdbcmd.cpp


  1 /*
  2  * $Id: cVSMmdbcmd.cpp,v 1.1 2005/07/26 17:11:46 chenj Exp $
  3  *
  4  * ===========================================================================
  5  *
  6  *                            PUBLIC DOMAIN NOTICE
  7  *            National Center for Biotechnology Information (NCBI)
  8  *
  9  *  This software/database is a "United States Government Work" under the
 10  *  terms of the United States Copyright Act.  It was written as part of
 11  *  the author's official duties as a United States Government employee and
 12  *  thus cannot be copyrighted.  This software/database is freely available
 13  *  to the public for use. The National Library of Medicine and the U.S.
 14  *  Government do not place any restriction on its use or reproduction.
 15  *  We would, however, appreciate having the NCBI and the author cited in
 16  *  any work or product based on this material
 17  *
 18  *  Although all reasonable efforts have been taken to ensure the accuracy
 19  *  and reliability of the software and data, the NLM and the U.S.
 20  *  Government do not and cannot warrant the performance or results that
 21  *  may be obtained by using this software or data. The NLM and the U.S.
 22  *  Government disclaim all warranties, express or implied, including
 23  *  warranties of performance, merchantability or fitness for any particular
 24  *  purpose.
 25  *
 26  * ===========================================================================
 27  *
 28  * Author: Jie Chen
 29  * Source file for VSMmdb.cgi
 30  *
 31  * $Log: cVSMmdbcmd.cpp,v $
 32  * Revision 1.1  2005/07/26 17:11:46  chenj
 33  * Making linux VSMmdb.cgi
 34  *
 35  *
 36  *
 37  */
 38 
 39 
 40 #include <corelib/ncbiexec.hpp>
 41 #include <corelib/ncbifile.hpp>
 42 #include <serial/objostr.hpp>
 43 
 44 #include "hVSMmdbapp.hpp"
 45 #include "hVSMmdbcmd.hpp"
 46 #include "VastSrchUti.hpp"
 47 #include "SHGlobal.hpp"
 48 #include "mmdbuti.hpp"
 49 #include "rdpdb.hpp"
 50 #include "qmuti.hpp"
 51 #include "SendSummary.hpp"
 52 
 53 #include <sstream>
 54 
 55 #include <objmime.h>
 56 
 57 #include <string.h>
 58 #include <sys/time.h>
 59 #include <math.h>
 60 
 61 
 62 // #include "../../newVSch/mmdbdep.h"
 63 // #include "../../newVSch/mmdbapi.h"
 64 
 65 
 66 // Initialization
 67 
 68 string          DataInfo::JobID;
 69 string          DataInfo::JobType;
 70 string          DataInfo::subset;
 71 stringstream    DataInfo::PDB_ios;
 72 stringstream    DataInfo::PDB_chk;
 73 QmReqID         DataInfo::ReqID = 0;
 74 QmGrpID         DataInfo::GrpID = 0;
 75 
 76 
 77 using namespace SHProjNS;
 78 using namespace ncbi;
 79 
 80 static ostringstream output;
 81 
 82 CVSMmdbCommand::CVSMmdbCommand(CNcbiResource& resource) : CNcbiCommand(resource)
 83 {};
 84 
 85 string CVSMmdbCommand::GetEntry() const
 86 {
 87         return string("cmdVSMmdb"); 
 88 }
 89 
 90 
 91 
 92 // CVSMmdbSubmitCommand
 93 
 94 CVSMmdbSubmitCommand :: CVSMmdbSubmitCommand(CNcbiResource& resource) : CVSMmdbCommand(resource)
 95 {};
 96 
 97 CNcbiCommand* CVSMmdbSubmitCommand :: Clone(void) const
 98 {
 99         return new CVSMmdbSubmitCommand(GetVSMmdbResource());
100 }
101 
102 string CVSMmdbSubmitCommand :: GetName() const
103 {
104         return string("Submit");
105 }
106 
107 
108 string CVSMmdbSubmitCommand :: ReadReqAndPDBSubmission(CCgiContext& ctx)
109 {
110 
111   string HeadValue = "HEADER";
112   string Remark = "REMARK  1";
113   string molname = "QUERY PROTEIN";
114 
115   CCgiRequest& req = ctx.GetRequest();
116   CCgiResponse& resp = ctx.GetResponse();
117 
118   static DataInfo Dinfo;
119   static VSMmdbConf thisConf;
120 
121   string date = GetTodaysDate();
122 
123   /* Write the contents of the pdb text area to buffer */
124 
125   string pdbdata = req.GetEntry("pdbfile").GetValue();
126   if (pdbdata.empty()) {
127       PrtMes::PrintErrorHeader(&resp, "VastSrch", 1);
128       PrtMes::PrintMsgWithoutTail(&resp,
129             "<h3>Missing Required PDB File:</h3><p>\nPlease submit a file.\n");
130 
131       
132         resp.out() << "<HR align=left width=800><br>\n"
133                 << "<a href=\"" << thisConf.HomePage
134                 << "\">Back</a> to the HomePage\n" 
135                 << "</body>\n</html>";
136         exit(1);
137   }
138 
139   if (pdbdata.size() > PDBMAXLEN) {
140 
141       PrtMes::PrintErrorHeader(&resp, "VastSrch", 1);
142       PrtMes::PrintMsgWithTail(&resp,
143            "<h2>You cannot submit a file greater than 5MB!</h2><p>\nIf this is a problem, please notify info@ncbi.nlm.nih.gov\n");
144 
145              THROWS("input file too bigger");
146   }
147 
148   unsigned pos = pdbdata.find(HeadValue);
149   if (pos == string::npos) {
150 
151                 Dinfo.PDB_ios.setf(ios::left);
152                 Dinfo.PDB_ios << setw(10) << HeadValue << setw(40) << molname;
153                 Dinfo.PDB_ios.unsetf(ios::left);
154                 Dinfo.PDB_ios << date;
155                 Dinfo.PDB_ios << setw(7) << Dinfo.JobID.substr(0,4)<< "\n";
156                 Dinfo.PDB_ios.setf(ios::left);
157                 Dinfo.PDB_ios << pdbdata;
158   }
159   else {
160                 if (pos) pdbdata = pdbdata.substr(pos);
161                 char data_line[100];
162                 istringstream  strm_tmp(pdbdata);
163 
164                 strm_tmp.getline(data_line, 100);
165                 string strtmp = data_line;
166                 unsigned siz = strtmp.size();
167                 if (siz < 59)
168                 {
169                      for (unsigned i= siz; i < 59; i++) strtmp += ' ';
170                      strtmp.replace(50, 9, date);
171                      Dinfo.PDB_ios << strtmp << "\n"
172                             << pdbdata.substr(siz+1);
173                 }
174                 else {
175         
176                         pdbdata.replace(50, 9, date);
177                         Dinfo.PDB_ios << pdbdata; 
178                 }
179   }
180 
181   Dinfo.subset = req.GetEntry("dataset").GetValue();
182   if (Dinfo.subset.empty()) {
183 
184         PrtMes::PrintErrorHeader(&resp, "VastSrch", 1);
185         PrtMes::PrintMsgWithoutTail(&resp,
186                 "<h3>No search set provided. ");
187         PrtMes::PrintMsgWithoutTail(&resp, Dinfo.subset);
188         PrtMes::PrintMsgWithTail(&resp,
189                 "Please select 'All' or 'Nonredundant' search set\n");
190         exit(1);
191      }
192 
193   return date;
194 
195 } // end of ReadReqAndPDBSubmission
196 
197 
198    
199 void CVSMmdbSubmitCommand :: Execute(CCgiContext& ctx)
200 {
201 
202         CCgiResponse& resp = ctx.GetResponse();
203         static DataInfo Dinfo;
204    
205         int iJobId = GetJobID_DB();
206         Dinfo.JobID = "VS" + ToString(iJobId);
207    
208         string date = ReadReqAndPDBSubmission(ctx);
209 
210         string headerStr = Dinfo.PDB_ios.str().substr(10, 39);
211         if (headerStr.find_first_not_of(" ") == string::npos) 
212                 headerStr = "NULL";
213         UploadReqInfo(Dinfo.subset, iJobId, date, headerStr);
214 
215 
216         //if (!UploadAllPdbOnly(Dinfo.JobID, Dinfo.PDB_ios.str(), Dinfo.PDB_chk.str())) {
217         if (!UploadOriPdbOnly(Dinfo.JobID, Dinfo.PDB_ios.str())) {
218 
219              THROWS("UploadAllPdb failed");
220         }
221 // return;
222 
223         static VSMmdbConf thisConf;
224 
225         if (!sqmInit())  {
226 
227              resp.WriteHeader();
228              resp.out() << "<html>\n<body>\n"
229                  << "<h1>VastSch Error: </h1>\n<br><br>\n"
230                  << "Can't Initialize QM\n"
231                  << "</body>\n</html>\n\n";
232 
233             ERR_POST("Can't Initialize QM.");
234             throw exception();
235         }
236 
237         Dinfo.ReqID = sqmSubmit(thisConf.QMqueStrName.c_str(), 0, 0);
238         if (!Dinfo.ReqID) {
239 
240 
241               resp.WriteHeader();
242 
243               resp.out() << "<html>\n<body>\n"
244                  << "<h1>VSchSrv Erro:</h1>\n<br><br>\n"
245                  << "ReqId1 = 0\n"
246                  << "</body>\n</html>\n\n";
247 
248               ERR_POST("Got 0 as reqId from QM");
249               THROWS("Got 0 as reqId from QM");
250 //            throw exception();
251 
252         }
253 
254 //      sqmSetAction(Dinfo.ReqID, qmReqActionRun);
255 
256 /*
257         char *IP = getenv("REMOTE_ADDR");
258         if (!IP) {
259 
260                 resp.WriteHeader();
261 
262                 resp.out() << "<html>\n<body>\n"
263                      << "<h1>VachSrv Error: </h1>\n<br><br>\n"
264                      << "No IP information.\n"
265                      << "</body>\n</html>\n";
266 
267                 ERR_POST("No IP information.\n");
268                 throw exception();
269         }
270 
271         sqmSetIP(Dinfo.ReqID, IP);
272 */
273 
274         Dinfo.GrpID = sqmSetGroup(Dinfo.ReqID, 0);
275         ChkGrpId(ctx, 0, Dinfo.GrpID);
276 
277         UploadQMIdsAndSetPdbLoaded(Dinfo.ReqID, Dinfo.GrpID, iJobId);
278 
279         if (!sqmFree()) {
280 
281                 resp.WriteHeader();
282                 resp.out() << "<html>\n<body>\n"
283                         << "<h1>VastSch Error: </h1>\n<br><br>\n"
284                         << "Can't close QM\n"
285                         << "</body>\n</html>\n\n";
286 
287                 ERR_POST("Can't close QM.");
288                 throw exception();
289 
290         };
291 
292         string UrlStr = thisConf.MonitUrl + thisConf.MonitCgi
293                         + "?cmdSch=Status&ReqId=" + ReqId2Str(Dinfo.ReqID)
294                         + "&GrpId=" + ReqId2Str(Dinfo.GrpID)
295                         + "&QMQue=" + thisConf.QMqueStrName;
296 
297         resp.WriteHeader();
298         resp.out() << "<html>\n"
299                 << "<meta http-equiv=refresh content=0;url=\""
300                 << UrlStr
301                 << "\">\n</html>\n";
302 
303 
304 }       // CVSMmdbSubmitCommand :: Execute()
305 
306 
307 
308 
309 // CVSMmdbStrTextCommand
310 
311 CVSMmdbStrTextCommand :: CVSMmdbStrTextCommand(CNcbiResource& resource)
312  : CVSMmdbCommand(resource)
313 {};
314 
315 string CVSMmdbStrTextCommand :: GetName() const
316 {
317 
318         return string("StrText");       // cmdVSMmdb=StrText,
319 };
320 
321 
322 CNcbiCommand* CVSMmdbStrTextCommand :: Clone(void)  const
323 {
324      return new CVSMmdbStrTextCommand(GetVSMmdbResource());
325 };
326 
327 
328 void CVSMmdbStrTextCommand :: Execute(CCgiContext& ctx)
329 {
330 
331      CCgiResponse& resp = ctx.GetResponse();
332      CCgiRequest&  req = ctx.GetRequest();
333      static DataInfo Dinfo;
334      static VSMmdbConf thisConf;
335      static ImgInfo Iinfo;
336      string strtmp;
337 
338      string value = req.GetEntry("grpid").GetValue();
339      Dinfo.GrpID = atoll(value.c_str());
340      if (!Dinfo.GrpID) {
341         
342         output.str("");
343         output << "<h3>Missing request_id the request_id provided is 0.</h3><p>\n"
344                 << "Please input a request_id.\n";
345         PrtMes::PrintErrorHeader(&resp, "VastSrch", 1);
346         PrtMes::PrintMsgWithoutTail(&resp, output.str());
347 
348         resp.out() << "<HR align=left width=800><br>\n"
349                 << "<a href=\"" << thisConf.HomePage
350                 << "\">Back</a> to the HomePage\n"
351                 << "</body>\n</html>";
352         exit(1);
353 
354      }
355      Iinfo.id = GrpId2JobId(Dinfo.GrpID);
356      if (!Iinfo.id) {
357         
358         output.str("");
359         output << "<h3>Invalid request_id.</h3><p>\n"
360            << "You provided either an invalid request_id, "
361            << "or your request_id has expired since the search results are kept only for 10 days.<p>\n"
362            << "Please check your request_id carefully, or you may resubmit your file to start a new search.\n";
363 
364         PrtMes::PrintErrorHeader(&resp, "VastSrch", 1);
365         PrtMes::PrintMsgWithoutTail(&resp, output.str());
366 
367         resp.out() << "<HR align=left width=800><br>\n"
368                 << "<a href=\"" << thisConf.HomePage
369                 << "\">Back</a> to the HomePage\n"
370                 << "</body>\n</html>";
371         exit(1);
372 
373 
374      }
375      Dinfo.JobID = "VS" + ToString(Iinfo.id);
376        
377      Dinfo.ReqID = JobId2ReqId(Iinfo.id);
378 
379      if (!VSMmdbJobDone(Iinfo.id)) {
380 
381         string errmsg, wmsg, wmsgH;
382         DownloadErrWarnMsgs( (long long)Dinfo.GrpID, errmsg, wmsg, wmsgH);
383         if ( errmsg.empty() && wmsg.empty() && wmsgH.empty() ) {
384         
385         // redirect  
386 
387                 string UrlStr = thisConf.MonitUrl + thisConf.MonitCgi
388                         + "?cmdSch=Status&ReqId=" + ReqId2Str(Dinfo.ReqID)
389                         + "&GrpId=" + ReqId2Str(Dinfo.GrpID)
390                         + "&QMQue=" + thisConf.QMqueStrName;
391 
392                 resp.WriteHeader();
393                 resp.out() << "<html>\n"
394                         << "<meta http-equiv=refresh content=0;url=\""
395                         << UrlStr
396                         << "\">\n</html>\n";
397         }
398         else {
399         
400              resp.WriteHeader();
401              resp.out() << "<html>\n<head>\n"
402                 << "<title>VAST Search Error Report</title>\n";
403              PrintFileData(resp, thisConf.HtmlDir + thisConf.HeadFName);
404 
405              resp.out() << "<pre><HR align=left width=800><br>\n";
406              if  ( !errmsg.empty() ) {
407 
408                 resp.out()
409                   << "<font class=H2>Errors in the submitted file:</font><br>\n"
410                   << errmsg << "<br><br>\n\n";
411              }
412 
413              if ( !wmsg.empty() ) {
414 
415                 resp.out() 
416                   << "\n<font class=H2>Warning: the following chains may have no structure neighbors due to missing Ca atoms.</font><br>\n"
417                   << wmsg << "<br><br>\n\n";
418              }
419 
420              if ( !wmsgH.empty() ) {
421 
422                 resp.out() << "\n<font class=H2>Warning: the following HETATM records interpreted as modified residues, changed to ATOM records in the submitted file.</font><br>\n"
423                         << wmsgH << "<br><br>\n\n";
424              }
425 
426              resp.out() << "<a href=\"" << thisConf.HomePage
427                 << "\">Back</a> to the HomePage\n"; 
428 
429         }
430 
431         return;
432      }
433 
434 
435      Dinfo.subset = GetSubsetName4Job(Iinfo.id);
436      if ( Dinfo.subset == "NULL" )  {
437                 ERR_POST("GetSubsetName4Job() failed");
438                 throw exception();
439      }
440      
441      resp.WriteHeader();
442      resp.out() << "<html>\n<head>\n"
443                 << "<title>VAST Search Structure Summary:&nbsp;"
444                 << GetTodaysDate()
445                 << "; ReqId: "
446                 << Dinfo.GrpID
447                 << "</title>\n";
448   
449      PrintFileData(resp, thisConf.HtmlDir + thisConf.HeadFName);
450 
451 string curtime;
452      value= req.GetEntry("ViewNbr").GetValue();
453      if (value.empty()) {
454 
455         if (!VSNbrStarted(Iinfo.id)) Dinfo.JobType = "Biostr";
456         else Dinfo.JobType = "Nbr";
457      }
458      else if (value == "No") Dinfo.JobType = "Biostr";
459      else if (value=="Yes" || value=="Show") Dinfo.JobType = "Nbr";
460 
461 curtime = CTime(CTime::eCurrent).AsString();
462 fprintf(stderr, "SendSummaryPageText curtime %s\n", curtime.c_str());
463 
464      if (Dinfo.JobType == "Biostr") {
465 
466         SendSummaryPageText(ctx, 0, 0);
467 
468 curtime = CTime(CTime::eCurrent).AsString();
469 fprintf(stderr, "after SendSummaryPageText curtime %s\n", curtime.c_str());
470 
471      }
472      else if (Dinfo.JobType == "Nbr") {
473         
474         if (VSJobDone(Iinfo.id)) {
475             SendSummaryPageText(ctx, 1);
476         }
477         else {
478          
479                 SendSummaryPageText(ctx, 1, 0);
480                 exit(0);
481         }
482      }
483      else {
484          THROWS("ViewNbr input incorrect");
485      }
486 
487         
488      ctx.GetResponse().out() << "</body>\n</html>\n\n";
489 
490      return;
491 
492 };  // end of CVSMmdbStrCommand :: Execute()
493 
494 
495 
496 
497 
498 // CVSMmdbStrImgCommand
499 CVSMmdbStrImgCommand :: CVSMmdbStrImgCommand(CNcbiResource& resource)
500  : CVSMmdbCommand(resource)
501 {};
502 
503 
504 string CVSMmdbStrImgCommand :: GetName() const
505 {
506         return string("StrImg"); 
507 };
508 
509 
510 CNcbiCommand* CVSMmdbStrImgCommand :: Clone(void)  const
511 {
512      return new CVSMmdbStrImgCommand(GetVSMmdbResource());
513 };
514 
515 
516 
517 void CVSMmdbStrImgCommand :: Execute(CCgiContext& ctx)
518 {
519     CCgiRequest& req = ctx.GetRequest();
520     static DataInfo Dinfo;
521     static ImgInfo Iinfo;
522 
523     string value = req.GetEntry("grpid").GetValue();
524     if (value.empty()) {
525 
526         ERR_POST("No grpid");
527         throw exception();
528 
529     }
530     Dinfo.GrpID = atoll(value.c_str());
531     if (!Dinfo.GrpID) {
532         ERR_POST("Grp ID is 0, from CVSMmdbStrImgCommand :: Execute");
533         throw exception();
534     }
535 
536     Iinfo.id = GrpId2JobId(Dinfo.GrpID);
537     Dinfo.JobID = "VS" + ToString(Iinfo.id);
538 
539     value = req.GetEntry("chbeg").GetValue();
540     if (value.empty()) THROWS("NO chbeg");
541     Iinfo.chbeg = atoi(value.c_str());
542 
543     value = req.GetEntry("chend").GetValue();
544     if (value.empty()) THROWS("NO chend");
545     Iinfo.chend = atoi(value.c_str());
546 
547     value = req.GetEntry("imgsize").GetValue();
548     if (value.empty()) THROWS("NO chend");
549     Iinfo.imgsize = atoi(value.c_str());
550 
551 /*
552     value = req.GetEntry("ViewNbr").GetValue();  
553     if (value == "Yes" || value=="Show") 
554                 DrawImg(ctx, 1);  // 1 or 0 VastLink
555     else DrawImg(ctx, 0);
556 */
557 
558     DrawImg(ctx);
559 
560 } // CVSMmdbSubmitStrImgCommand :: Execute
561 
562 
563 
564 // CVSMmdbViewCommand
565         
566 CVSMmdbViewCommand :: CVSMmdbViewCommand(CNcbiResource& resource) : CVSMmdbCommand(resource)
567 {};
568 
569 CNcbiCommand* CVSMmdbViewCommand :: Clone(void) const
570 {
571      return new CVSMmdbViewCommand(GetVSMmdbResource());
572 }
573 
574 string CVSMmdbViewCommand :: GetName() const
575 {
576      return string("View3D");
577 }
578 
579 
580 
581 void CVSMmdbViewCommand :: SendStructureMIME(char Filetype, int Mime, 
582                         int Complexity, int Models, CCgiContext& ctx)
583 {
584 
585   static DataInfo Dinfo;
586   CCgiResponse& resp = ctx.GetResponse();
587 
588   int iJobId = atoi(Dinfo.JobID.substr(2).c_str());
589 
590   BiostrucPtr bsp;
591   SeqEntryPtr sep;
592   NcbiMimeAsn1Ptr mime;
593   BiostrucSeqPtr bssp;
594 
595   /* Save or View  = add appropriate MIME header */
596 
597 // bsp = FetchBS((char*)bFile.c_str(), 1, Complexity, Models, POWER_VIEW);
598 
599    bsp = VSOpenBSP(iJobId, Complexity, Models);
600    if (bsp == NULL) {
601 
602         string strtmp = "Missing Biostruc data for reqid = "
603                         + ReqId2Str(Dinfo.GrpID) 
604                         + ". Please inform chenj@ncbi.nlm.nih.gov for this problem. Thanks!";
605         PrtMes::PrintErrorHeader(&resp, "VastSrch", 1);
606         PrtMes::PrintMsgWithTail(&resp,  strtmp);
607 
608         exit(1);
609    }
610 
611    bssp = BiostrucSeqNew();
612    bssp->structure = bsp;
613 
614    sep = GetSeqEntryForJobId(iJobId, 0, NULL);
615 
616    if (sep == NULL) {
617 
618         string strtmp = "Missing SeqEntry data for reqid = "
619                         + ReqId2Str(Dinfo.GrpID)
620                         + ". Please inform chenj@ncbi.nlm.nih.gov for this problem. Thanks!";
621 
622         PrtMes::PrintErrorHeader(&resp, "VastSrch", 1);
623         PrtMes::PrintMsgWithTail(&resp,  strtmp);
624 
625         exit(1);
626    }
627 
628    if (sep->choice == 2) {  // BioseqSet, multiple chains
629 
630        BioseqSetPtr seps = (BioseqSetPtr) sep->data.ptrvalue;
631        SeqEntryPtr subsep = (SeqEntryPtr) seps->seq_set;
632        SeqIdPtr sid;
633        int ori_gi=0;
634 
635        while (subsep != NULL) {
636 
637           sid = (SeqIdPtr) ((BioseqPtr)subsep->data.ptrvalue)->id;
638           while (sid != NULL) {
639 
640                 if (sid->choice == SEQID_GI) {
641 
642                     sid->data.intvalue = ori_gi++;
643                     break;
644                 }
645                 sid=sid->next;
646           }
647 
648           subsep = subsep->next;
649        }
650 
651    }
652 
653    ValNodeLink(&(bssp->sequences), sep);
654 
655    mime = (NcbiMimeAsn1Ptr) ValNodeNew(NULL);    /* yanli */
656    mime->choice = NcbiMimeAsn1_strucseq;
657    mime->data.ptrvalue = bssp;
658 
659    /* the following headers are format-independent */
660 
661    ESerialDataFormat dataformat;
662   // if (Filetype == 'i') {   BiostrucAsnWrite()
663    if (Filetype == 'j') {
664         /* Cn3D asn.1 format */
665         if (Mime == LAUNCH_VIEWER || Mime == SAVE_FILE)
666                          dataformat = eSerial_AsnBinary;
667         else dataformat = eSerial_AsnText;
668 
669         auto_ptr <CObjectOStream> oos
670                 (CObjectOStream::Open(dataformat, resp.out()));
671         CObjectOStream::AsnIo aip(*oos, "Ncbi-mime-asn1");
672 
673         switch (Mime) {
674            case LAUNCH_VIEWER:
675                 resp.SetContentType("chemical/ncbi-asn1-binary");
676                 resp.WriteHeader();
677                 NcbiMimeAsn1AsnWrite(mime, aip, NULL);
678                 break;
679 
680            case SAVE_FILE:
681                 resp.SetContentType("application/octet-stream");
682                 resp.WriteHeader();
683                 NcbiMimeAsn1AsnWrite(mime, aip, NULL);
684                 break;
685 
686            case SEE_FILE:
687                 resp.SetContentType("text/html");
688                 resp.WriteHeader();
689                 resp.out() << "<HTML><PRE>\r\n";
690                 NcbiMimeAsn1AsnWrite(mime, aip, NULL);
691                 break;
692             }
693 
694         aip.End();
695    }
696    if (Mime == SEE_FILE)
697                 resp.out() << "</PRE></HTML>\r\n";
698 
699 //   CExec::System((string("rm -r ") + dir).c_str());
700 
701 } // end of SendStructureMIME()
702 
703 
704 
705 void CVSMmdbViewCommand :: Execute(CCgiContext& ctx)
706 {
707 
708 fprintf(stderr, "CVSMmdbViewCommand :: Execute()\n");
709 
710 
711     CCgiRequest& req = ctx.GetRequest();
712     CCgiResponse& resp = ctx.GetResponse();
713     static DataInfo Dinfo;
714 
715     string value = req.GetEntry("grpid").GetValue();
716     if (value.empty()) {
717         THROWS("No GrpId");
718     }
719     Dinfo.GrpID = atoll(value.c_str());
720 
721     Dinfo.JobID = "VS" + ToString(GrpId2JobId(Dinfo.GrpID));
722     if (Dinfo.JobID.empty()) {
723                 ERR_POST("No JobID");
724                 throw exception();
725     }
726 
727     string View = req.GetEntry("dopt").GetValue();   
728     if (View.empty()) {
729 
730         PrtMes::PrintErrorHeader(&resp, "VastSrch", 1);
731         PrtMes::PrintMsgWithoutTail(&resp,
732                         "               Wrong Display Option Type: dopt= ");
733         PrtMes::PrintMsgWithoutTail(&resp, View);
734         PrtMes::PrintMsgWithTail(&resp, ".<p>\n<pre>dopt supports: 'i' or 'a' ASN.1</pre><p>\n");
735 
736         ERR_POST("No dopt provided");
737         throw exception();
738       
739     }
740    
741     char DispOpt = '\0'; 
742     int  Save = 0;
743     switch (View[0])
744     {
745       case 'i':
746         DispOpt = 'i';
747         break;
748       case 'a':
749         DispOpt = 'a';
750         Save = 1;
751         break;
752       case 'j':
753         DispOpt = 'j';
754         break;
755     }
756 
757     string com_value = req.GetEntry("Complexity").GetValue();
758     if (com_value.empty()) {
759         PrtMes::PrintErrorHeader(&resp, "VastSrch", 1);
760         PrtMes::PrintMsgWithTail(&resp, "Can't find value of Complexity.\n");
761         ERR_POST("No complexity provided");
762         throw exception();
763     }
764 
765     int iCount = -1;
766     vector<string> ComplexityDescriptions;
767     ComplexityDescriptions.push_back("Virtual Bond Model");
768     ComplexityDescriptions.push_back("All Atom Model");
769     ComplexityDescriptions.push_back("Up to 5 Models");
770     ComplexityDescriptions.push_back("Up to 10 Models");
771     ComplexityDescriptions.push_back("All Models");
772     ComplexityDescriptions.push_back("Cn3D Subset");
773 
774     for (int i=0; i< (int)ComplexityDescriptions.size(); i++) 
775         if (com_value.find(ComplexityDescriptions[i]) !=string::npos) {
776                 iCount = i;
777                 break;
778         }
779 
780     if (iCount < 0) {
781 
782       string strtmp = "Wrong Complexity Type\nPlease select one from: "
783                         + ComplexityDescriptions[5] + ", "
784                         + ComplexityDescriptions[0] + ", and "
785                         + ComplexityDescriptions[4] + ".";
786       PrtMes::PrintErrorHeader(&resp, "VastSrch", 1);
787       PrtMes::PrintMsgWithTail(&resp, strtmp);
788 
789       THROWS("Wrong Complexity type");
790    }
791 
792     int MaxModels = 1;
793     int Complex = ALLMDL;
794     switch (iCount)
795     {
796       case 0 :
797         Complex = ONECOORDRES;
798         break;
799       case 1:
800         Complex = ONECOORDATOM;
801         break;
802       case 2:
803         MaxModels = 5;
804         break;
805       case 3 :
806         MaxModels = 10;
807         break;
808       case 4 :
809         MaxModels = INT2_MAX;
810         break;
811       case 5:
812         Complex = ONECOORDATOM;
813         break;
814       }
815 
816     string SaveChoice = req.GetEntry("save").GetValue();
817 
818     if (SaveChoice.find("See") != string::npos)
819         Save = 1;  /* sends MIMED-type files to view in ascii*/
820     else if (SaveChoice.find("Save") != string::npos)
821         Save = 2;  /* sends MIMED-type files in raw save form */
822 
823     SendStructureMIME(DispOpt, Save, Complex, MaxModels, ctx);
824 
825 
826 } // end of CVSMmdbViewCommand :: Execute()
827 
828 
829 
830 
831 
832 // CVSMmdbSearchCommand
833 
834 CVSMmdbSearchCommand::CVSMmdbSearchCommand(CNcbiResource& resource):CVSMmdbCommand(resource)
835 {};
836 
837 
838 CNcbiCommand* CVSMmdbSearchCommand :: Clone(void) const
839 {
840      return new CVSMmdbSearchCommand(GetVSMmdbResource());
841 }
842 
843 string CVSMmdbSearchCommand :: GetName() const
844 {
845      return string("Search");
846 }
847 
848 void CVSMmdbSearchCommand :: Execute(CCgiContext& ctx)
849 {
850     static DataInfo Dinfo;
851     static VSMmdbConf thisConf;
852     CCgiRequest& req = ctx.GetRequest();
853     CCgiResponse& resp= ctx.GetResponse();
854 
855 
856     string value = req.GetEntry("grpid").GetValue();
857     if (value.empty())
858                 ERR_POST("No reqid in CVSMmdbSearchCommand :: Execute");
859     Dinfo.GrpID = atoll(value.c_str());
860 
861     if ( SetupDoitInDB(Dinfo.GrpID) ) {
862         
863         if (!sqmInit())  {
864 
865                 resp.WriteHeader();
866 
867                 resp.out()  << "<html>\n<body>\n"
868                         << "<h1>VastSch Error: </h1>\n<br><br>\n"
869                         << "Can't Initialize QM\n"
870                         << "</body>\n</html>\n\n";
871 
872                 ERR_POST("Can't Initialize QM.");
873                 throw exception();
874         }
875     
876         Dinfo.ReqID = sqmSubmit(thisConf.QMqueNbrName.c_str(), 0, 0);
877         if (!Dinfo.ReqID) {
878 
879                 resp.WriteHeader();
880 
881                 resp.out() << "<html>\n<body>\n"
882                         << "<h1>VSchSrv Erro:</h1>\n<br><br>\n"
883                         << "ReqId2 = 0\n"
884                         << "</body>\n</html>\n\n";
885 
886                 ERR_POST("Got 0 as reqId from QM");
887                 throw exception();
888 
889         }
890 
891 //    sqmSetAction(Dinfo.ReqID, qmReqActionRun);
892 
893         QmReqID grpid = sqmSetGroup(Dinfo.ReqID, Dinfo.GrpID);
894         ChkGrpId(ctx, Dinfo.GrpID, grpid);
895 
896         UpdateReqIdOfGrpId(Dinfo.GrpID, Dinfo.ReqID);
897 
898 /*
899         char *IP = getenv("REMOTE_ADDR");
900         if (!IP) {
901 
902                 resp.WriteHeader();
903 
904                 resp.out() << "<html>\n<body>\n"
905                      << "<h1>VachSrv Error: </h1>\n<br><br>\n"
906                      << "No IP information.\n"
907                      << "</body>\n</html>\n";
908 
909                 ERR_POST("No IP information.\n");
910                 throw exception();
911         }
912 
913         sqmSetIP(Dinfo.ReqID, IP);
914 */
915 
916 
917         if (!sqmFree()) {
918 
919                 resp.WriteHeader();
920                 resp.out() << "<html>\n<body>\n"
921                         << "<h1>VastSch Error: </h1>\n<br><br>\n"
922                         << "Can't close QM\n"
923                         << "</body>\n</html>\n\n";
924 
925                 ERR_POST("Can't close QM.");
926                 throw exception();
927 
928         };
929 
930     }
931 
932 /*
933 
934     output << thisConf.MonitUrl << thisConf.MonitCgi
935                 << "?cmdSch=Status&ReqId=" << Dinfo.ReqID
936                 << "&GrpId=" << Dinfo.GrpID
937                 << "&QMQue=" << thisConf.QMqueNbrName;
938 */
939 
940     output.str("");
941     output << thisConf.BaseUrl << thisConf.CgiName
942                 << "?cmdVSMmdb=StrText&grpid="  << Dinfo.GrpID
943                 << "&ViewNbr=Yes";
944 
945     resp.WriteHeader();
946     resp.out() << "<html>\n"
947                 << "<meta http-equiv=refresh content=0;url=\""
948                 << output.str()
949                 << "\">\n</html>\n";
950 
951 
952 
953 } // CVSMmdbSearchCommand :: Execute()
954 
955 
956 
957 // CVSMmdbChkErrCommand
958 
959 CVSMmdbChkErrCommand :: CVSMmdbChkErrCommand(CNcbiResource& resource):CVSMmdbCommand(resource)
960 {};
961 
962 CNcbiCommand* CVSMmdbChkErrCommand :: Clone(void) const
963 {
964      return new CVSMmdbChkErrCommand(GetVSMmdbResource());
965 }
966 
967 string CVSMmdbChkErrCommand :: GetName() const
968 {
969      return string("ChkErr");
970 }
971 
972 void CVSMmdbChkErrCommand :: Execute(CCgiContext& ctx)
973 {
974 
975      CCgiResponse& resp = ctx.GetResponse();
976      CCgiRequest&  req = ctx.GetRequest();
977      static DataInfo Dinfo;
978      static VSMmdbConf thisConf;
979 
980      string errmsg, wmsg, wmsgH;
981      string value = req.GetEntry("Jobid").GetValue();
982      if ( !value.empty() )
983         DownloadErrWarnMsgs((unsigned)atoi(value.c_str()), errmsg, wmsg, wmsgH);
984      else {
985         
986         value = req.GetEntry("grpid").GetValue();
987         if ( !value.empty() )
988             DownloadErrWarnMsgs((long long)atoll(value.c_str()), errmsg, 
989                                                                 wmsg, wmsgH);
990         else throw exception();
991      }
992 
993      resp.WriteHeader();
994      resp.out() << "<html>\n<head>\n"
995                 << "<title>VAST Search Error Report</title>\n";
996      PrintFileData(resp, thisConf.HtmlDir + thisConf.HeadFName);
997 
998      resp.out() << "<pre><HR align=left width=800><br>\n";
999      if  ( !errmsg.empty() ) {
1000 
1001         resp.out()
1002                 << "<font class=H2>Errors in the submitted file:</font><br>\n"
1003                 << errmsg << "<br><br>\n\n";
1004      }
1005 
1006      if ( !wmsg.empty() ) {
1007         
1008         resp.out() << "\n<font class=H2>Warning: the following chains may have no structure neighbors due to missing Ca atoms.</font><br>\n"
1009                 << wmsg << "<br><br>\n\n";
1010      }
1011 
1012      if ( !wmsgH.empty() ) {
1013 
1014         resp.out() << "\n<font class=H2>Warning: the following HETATM records interpreted as modified residues, changed to ATOM records in the submitted file.</font><br>\n"
1015                 << wmsgH << "<br><br>\n\n";
1016      }
1017      
1018      resp.out() << "<HR align=left width=800><br>\n"
1019                 << "<a href=# onclick=\"self.close();return false;\">"
1020                 << "Close Window</a>"
1021                 << "<br>\n</pre>\n</body>\n</html>\n\n";
1022 
1023 /*
1024                 << "<a href=\"" << thisConf.HomePage
1025                 << "\">Back</a> to the HomePage\n" 
1026 */
1027 
1028 }
1029 
1030 

source navigation ]   [ diff markup ]   [ identifier search ]   [ freetext search ]   [ file search ]  

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.