Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members

msdsearch_soap_service.cc

00001 // httpd -f /ebi/msd/work/siamak/apache/conf/httpd.conf
00002 // ps -x (returns PID)
00003 // kill PID
00004 // httpd -f /ebi/msd/work/siamak/apache/conf/phoenix_httpd.conf 
00005 //  ./soapcpp2 -2 -i -pmsdsearch_soap msdsearch_soap.h 
00007 
00008 //msdsearch_soap_service.cgi:
00009 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00010 // #!/bin/csh -f
00011 // # disable filename globbing
00012 // source /ebi/msd/work/siamak/apache/cgi-bin/apisercnf.csh
00013 // exec /ebi/msd/work/siamak/apache/cgi-bin/msdsearch_soap_service
00014 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00016 // For final web services:
00020 //  more /ebi/msd/software/common/tns_admin/tnsnames.ora
00022 
00023 // **** This process should be executed on web6-node2 machine: ***** //
00024 
00025 // make fsoap [VER=-2]-----> for making SOAP 1.2 (default is  SOAP 1.1)
00026 // make fsoapcopy
00027 // make fwservice
00028 // make fwclient
00029 // http://parrot.ebi.ac.uk:8099/cgi-bin/msdsearch_soap_client
00030 // or http://www.ebi.ac.uk/msd-srv/ssm/cgi-bin/ws/msd_soap_client
00032 
00034 // to config expat:  
00035 //          ./configure --prefix=/home/me/mystuff
00036 // cd /ebi/msd/work/siamak/expat-1.95.5
00037 //./configure --prefix=/ebi/msd/work/siamak/msd_api
00038 //make
00039 //make install
00040 
00043 // make shared
00044 // make cleanj
00045 // make msdj
00046 // java MSDJapi
00048 
00049 
00050 
00051 
00052 
00053 
00054 #include <iostream>
00055 #include <fstream>
00056 #include <string.h>
00057 
00058 //#include <stdio.h>
00059 //#include <stdlib.h>
00060 
00061 #ifndef __MSD_DEFS_H__
00062 #include "msd_defs.h"
00063 #endif
00064 
00065 #include "msdsearch_soapH.h"
00066 #ifndef __MSD_SOAP_ENABLED__
00067 #define __MSD_SOAP_ENABLED__
00068 #endif
00069 
00070 
00071 //#define LPP_True_NODEFINE
00072 
00073 //extern class ostream;
00074 
00075 #ifndef __MSD_USER_H__
00076 #include "msd_user.h"
00077 #endif
00078 #include "msdsearch_soap_service.nsmap"
00079 
00080 #ifndef  __SRV_PXML__
00081 #include "srv_pxml.h"
00082 #endif
00083 
00084 #include "expat.h"
00085 
00086 //~~~~~~~#define LEASETERM 300
00087 
00088 #include <sys/stat.h> // for open()
00089 //#include <iostream>
00090 
00091 //using std::ios;
00092 //using std::fstream;
00093 //using std::cout;
00095 //#include "msd_datatypes.h"
00096 
00097 
00098 
00099 int xml_elno=-1;
00100 msd_xml_element * xml_inf;
00101 //int Eventcnt = 0;
00102 char * xml_Buff;
00103 char * xml_txtbuff;
00104 
00105 
00106 void default_hndl(void *data, const char *s, int len) {
00107   //fwrite(s, len, sizeof(char), stdout);
00108 }  /* End default_hndl */
00109 
00110 /****************************************************************
00111  ** Call from within a handler to print the currently recognized
00112  ** document fragment. Temporarily set the default handler and then
00113  ** invoke it via the the XML_DefaultCurrent call.
00114  */
00116 void printcurrent(XML_Parser x_p) {
00117   XML_SetDefaultHandler(x_p, default_hndl);
00118   XML_DefaultCurrent(x_p);
00119   XML_SetDefaultHandler(x_p, (XML_DefaultHandler) 0);
00120 }  /* End printcurrent */
00121 
00122 
00123 
00124 
00125 void start_hndl(void *data, const char *el, const char **attr) {
00126   
00127 xml_elno++;
00128 
00129 xml_inf[xml_elno].tag=(char *)malloc(strlen(el)+1);
00130  
00131 sprintf(xml_inf[xml_elno].tag,"%s",el);
00132 xml_inf[xml_elno].data=(char *)malloc(strlen(xml_txtbuff)+1);
00133 sprintf(xml_inf[xml_elno].data,"%s","");
00134 sprintf(xml_txtbuff,"%s", "");  //NULL
00135 
00136  
00137  // printf("\n%4d: Start tag %s - ", Eventcnt++, el);
00138 
00139   printcurrent((XML_Parser) data);
00140 }  /* End of start_hndl */
00141 
00142 
00143 void end_hndl(void *data, const char *el) {
00144  
00145  sprintf(xml_inf[xml_elno].data,"%s",xml_txtbuff);
00146  
00147  //printf("\n%4d: End tag %s -\n", Eventcnt++, el);
00148 }  /* End of end_hndl */
00149 
00150 void char_hndl(void *data, const char *txt, int txtlen) {
00151  
00152  char* xbuf;
00153  xbuf=(char*)malloc(strlen(txt)+1);
00154  sprintf(xbuf,"%s","");
00155  //strncpy(xbuf,txt,txtlen);
00156  strcpy(xbuf,txt);
00157  xbuf[txtlen]='\0';
00158  //trimspace(xbuf);
00159  sprintf(xml_txtbuff,"%s%s", xml_txtbuff, xbuf);
00160  //free(xbuf);
00161  
00162   //printf("\n%4d: Text - ", Eventcnt++);
00163   //fwrite(txt, txtlen, sizeof(char), stdout);
00164  //if (xml_txtbuff)
00165 // {printf("\n%4d: Text - ", Eventcnt++);
00166 //  fwrite(xml_txtbuff, strlen(xml_txtbuff), sizeof(char), stdout);
00167 // }
00168   
00169   
00170   
00171  
00172 }  /* End char_hndl */
00173 
00174 void proc_hndl(void *data, const char *target, const char *pidata) {
00175   //printf("\n%4d: Processing Instruction - ", Eventcnt++);
00176   printcurrent((XML_Parser) data);
00177  // elno++;
00178 }  /* End proc_hndl */
00179 
00180 
00181  
00182   /* Notice that the default handler is not set at this point */
00183 
00184   
00185  
00186 
00188 
00189 
00190 
00191 
00192 //const char msd_soap_service[] = "http://phoenix.ebi.ac.uk:8099/cgi-bin/msdsearch_soap_service.cgi";
00193 const char msdsearch_soap_service[] = "http://www.ebi.ac.uk/msd-srv/ssm/cgi-bin/ws/msdsearch_soap_service.cgi";
00194 
00195 int main(int argc, char **argv)
00196 {  
00197    
00198    
00199    int m, s;
00200    struct soap soap;
00201    soap_init(&soap);
00202    //soap.user = (void*)&conn;          // associate factory with run-time
00203    
00204    //~~~soap.accept_timeout = LEASETERM;        // term before leases runs out is used as a rate to purge objects
00205    
00206    
00207    //soap.cookie_domain = "http://www.ebi.ac.uk/msd-srv/ssm/cgi-bin/ws/"; 
00208    //soap.cookie_path = "/ebi/msd/ssm/cgi-bin/ws"; // the path which is used to filter/set cookies with this destination 
00209    //int cookie_max =64;
00210    
00211    //soap_set_recv_logfile(&soap, "/ebi/msd/ssm/cgi-bin/ws/work/msd_ws_recv.log"); // append all messages received in /logs/recv/service12.log 
00212    //soap_set_sent_logfile(&soap, "/ebi/msd/ssm/cgi-bin/ws/work/msd_ws_sent.log"); // append all messages sent in /logs/sent/service12.log 
00213    //soap_set_test_logfile(&soap, "/ebi/msd/ssm/cgi-bin/ws/work/msd_ws_test.log"); //  NULL no file name: do not save debug messages 
00214    
00215    
00216    
00217    if (argc < 3)
00218         {
00219           // soap_getenv_cookies(&soap); // CGI app: grab cookies from 'HTTP_COOKIE' env var 
00220            soap_serve(&soap); // run as CGI application over the Web
00221     }
00222   else // run as stand-alone server on machine given by argv[1] listening to port argv[2]
00223   { m = soap_bind(&soap, argv[1], atoi(argv[2]), 100);
00224     if (m < 0)
00225     { soap_print_fault(&soap, stderr);
00226       exit(-1);
00227     }
00228     fprintf(stderr, "Socket connection successful: master socket = %d\n", m);
00229     for (int i = 1; ; i++)
00230     { s = soap_accept(&soap);
00231       if (s < 0)
00232       { soap_print_fault(&soap, stderr);
00233         exit(-1);
00234       }
00235       fprintf(stderr, "%d: accepted connection from IP = %d.%d.%d.%d socket = %d ... ", i, (int)(soap.ip>>24)&0xFF, (int)(soap.ip>>16)&0xFF, (int)(soap.ip>>8)&0xFF, (int)soap.ip&0xFF, s);
00236       soap_serve(&soap);                // process request
00237       fprintf(stderr, "request served\n");
00238       soap_destroy(&soap);      // delete class instances
00239       soap_end(&soap);          // clean up everything and close socket
00240          // soap_free_cookies(&soap); // remove all old cookies from database so no interference occurs with the arrival of new cookies 
00241     }
00242   }
00243   //soap_dealloc(&soap, NULL); 
00244   soap_destroy(&soap);
00245   soap_end(&soap);
00246   //free(&soap);
00247   return 0;
00248 }
00249 
00250 
00251  int ns__msdSSM(struct soap *soap,int numofpars, array *inparams, int &result){
00252  char* xmlstr = (char*)soap_malloc(soap,4096);
00253  char* xmlstrn = (char*)soap_malloc(soap,4096);
00254  char* infname = (char*)soap_malloc(soap,256);
00255  char* outfname = (char*)soap_malloc(soap,256);
00256  inparams->__size=numofpars;
00257  sprintf(xmlstr,"%s",(*inparams)[0]->__item);
00258 
00259  
00261 char * pch;
00262   pch = strtok (xmlstr,">");
00263   sprintf (xmlstrn,"%s", "");
00264   while (pch != NULL){
00265         //int i=1;
00266     if (pch[0]==' ' || pch[0]=='\n')
00267     { while (pch[0]==' ' || pch[0]=='\n'){ 
00268            pch++;
00269       }
00270           sprintf (xmlstrn,"%s%s>",xmlstrn, pch);
00271     }else{
00272         sprintf (xmlstrn,"%s%s>",xmlstrn, pch);}
00273         pch = strtok (NULL, ">");
00274   }
00275   sprintf (xmlstr, "%s",xmlstrn);
00276   pch = strtok (xmlstr,">");
00277   sprintf (xmlstrn,"%s", "");
00278   while (pch != NULL)
00279   { if (pch[0]=='<' )
00280     {sprintf (xmlstrn,"%s\n%s>",xmlstrn, pch);
00281     }else{
00282         sprintf (xmlstrn,"%s%s>",xmlstrn, pch);}
00283         pch = strtok (NULL, ">\n");
00284   }
00285 sprintf (xmlstrn,"%s\n",xmlstrn);
00287 
00288 sprintf(infname,"/ebi/msd/ssm/cgi-bin/ws/work/%s_in.xml",(*inparams)[1]->__item);
00289  FILE * pfile;
00290  pfile = fopen (infname,"w+t");
00291    if (pfile==NULL)
00292    {cerr << "error: could not create " << infname  << endl;
00293     exit(1);}
00294  fwrite (xmlstrn , 1 , strlen(xmlstrn), pfile);
00295  //fputs (xmlstrn,pfile);
00296  fclose (pfile);
00297  pfile=NULL;
00298  sprintf(outfname,"/ebi/msd/ssm/cgi-bin/ws/work/%s_out.xml",(*inparams)[1]->__item);
00299  char* buff;
00300  char* syscall;
00301  size_t buffsize=0;
00302  
00303 // msd_anyType* tmp[5];
00305 // //tmp[0]=new msd_string("bsub -q extsrv_interactive -R msd_ssm -o /ebi/msd/ssm/cgi-bin/ws/work/ssmws.log"); // -o outfname
00306 // tmp[0]=new msd_string("/ebi/msd/ssm/cgi-bin/ssmserver -offline");
00307 // tmp[1]=new msd_string(infname);
00308 // tmp[2]=new msd_string(outfname);
00309 // tmp[3]=new msd_string("/ebi/msd/ssm/ssmdata/ssm_webservice.conf");
00310 // tmp[4]=new msd_string("> /ebi/msd/ssm/cgi-bin/ws/work/ssmws.log"); // should change according session
00311 // 
00312 // for (int i=0;i<5 ;i++ )
00313 // {buffsize = buffsize + strlen(tmp[i]->msd_item)+1;
00314 // }
00315 //  buff=(char *)soap_malloc(soap, buffsize);
00316 // sprintf(buff,"%s",tmp[0]->msd_item);
00317 // for (int i=1;i<5 ;i++ )
00318 // {sprintf(buff,"%s %s",buff,tmp[i]->msd_item);
00319 // }
00320 // for (int i = 0; i < 5; i++){
00321 //        delete tmp[i];
00322 // }
00323  char ** tmp = (char**)soap_malloc(soap,5*256);
00324  for (int i=0;i<5 ;i++ ){
00325  tmp[i]= (char*)soap_malloc(soap,256);
00326  } 
00327  sprintf(tmp[0],"%s","/ebi/msd/ssm/cgi-bin/ssmserver -offline");
00328  sprintf(tmp[1],"%s",infname);
00329  sprintf(tmp[2],"%s",outfname);
00330  sprintf(tmp[3],"%s","/ebi/msd/ssm/ssmdata/ssm_webservice.conf");
00331  sprintf(tmp[4]," > /ebi/msd/ssm/cgi-bin/ws/work/%s_ssmws.log", (*inparams)[1]->__item);
00332  buff=(char *)soap_malloc(soap, 5*(256+1));
00333  sprintf(buff,"%s",tmp[0]);
00334  for (int i=1;i<5 ;i++ )
00335  {sprintf(buff,"%s %s",buff,tmp[i]);
00336  }
00337  
00338  
00339 
00340  syscall = (char*)soap_malloc(soap, strlen(buff)+1);
00341  sprintf(syscall,"%s", buff);
00342  pfile=fopen (infname,"rt");
00343  if (pfile)
00344  {fclose (pfile);
00345   pfile=NULL;
00346   result = system(syscall);
00347  }
00348  
00349  if (result < 0){
00350          result = errno;         
00351  }
00352  //soap_unlink(soap, (void*)xmlstr);
00353  //soap_unlink(soap, (void*)xmlstrn);
00354  //soap_unlink(soap, (void*)buff);
00355  //soap_unlink(soap, (void*)syscall);
00356  return SOAP_OK;
00357  }          
00358 
00359  int ns__msdSSMParser(struct soap *soap, char* sessionid, char* dbserver, int &result){
00360  char* xmlfn = (char*)soap_malloc(soap,256);
00361  char* session = (char*)soap_malloc(soap,64);
00362  char* db_server= (char*)soap_malloc(soap,32);
00363  char* login_string = (char*)soap_malloc(soap,64);
00364  char* syscall = (char*)soap_malloc(soap,256);
00365  char* loginstr;
00366  char* fname = (char*)soap_malloc(soap,512);
00367  char* ofname = (char*)soap_malloc(soap,512);
00368  int out_file_ok=1;
00369  char* tmp = (char*)soap_malloc(soap,64);
00370  //session_id = (char*)soap_malloc(soap, strlen(sessionid)+1);
00371  sprintf(session,"%s",sessionid);
00372  sprintf(db_server,"%s",dbserver);
00373  sprintf(login_string,"search/search55@%s",db_server);
00374  loginstr = (char*)malloc(strlen(login_string)+1);
00375  strcpy(loginstr, login_string);
00376  sprintf(xmlfn,"/ebi/msd/ssm/cgi-bin/ws/work/%s_out.xml",session);
00377  sprintf(fname,"/ebi/msd/ssm/cgi-bin/ws/work/%s_in.xml",session);
00378  sprintf(ofname,"/ebi/msd/ssm/cgi-bin/ws/work/%s_log.txt",session);
00379  char write_line[1024];
00380 
00381  //sprintf(table_exists_stm,"select o.object_name as table_name,o.owner as owner " 
00382  //"from all_objects o where o.object_name like 'SSM_OUT_TAB' and o.owner = 'search'");
00383  
00384   char* stmnt = (char*)soap_malloc(soap,512);
00385   int j=0;
00386   wait(30);
00387   while(j<12*15) // up to 15 minutes wait for result
00388   { if (fileexists(xmlfn))
00389           { out_file_ok=0;
00390             break;}else 
00391           {wait(5);} // wait 5 seconds and retry again
00392         j++;
00393   } // end while
00394  if (out_file_ok!=0)
00395    {cerr << "error: SSM's xml output file: "  << xmlfn << " does not exists! " << endl;
00396     result = -2;
00397         exit(1);}
00398  
00400  PCSSMXML SSMXML;
00401  char*  queryID = (char*)soap_malloc(soap,500);
00402  char*  targetID = (char*)soap_malloc(soap,500);
00403  char*  queryCh = (char*)soap_malloc(soap,10);
00404  char*  targetCh = (char*)soap_malloc(soap,10);
00405  mat44    RT;
00406  int      rc, nMatches;
00407  //  1.  Make routine initializations, which must always be done
00408  //      before working with MMDB
00409  InitMatType();
00410  //  2.  Create an instance of XML object
00411  SSMXML = new CSSMXML();
00412 
00413  //sprintf (write_line, "%s", "Before SSM XML file read\n");
00414  //fputs (write_line,pfile);
00415 
00416  //  3.  Read XML file.
00417  rc = SSMXML->readSSMXML ( xmlfn );
00418  //sprintf (write_line, "  SSM XML file read rc=%i\n",rc );
00419  //fputs (write_line,pfile);
00420  if (rc) {
00421  result=rc;
00422  //return SOAP_FAULT;
00423  }
00424  
00426 
00427 //ofstream outfile;
00428 //outfile.open(ofname);
00429 
00430 
00431 //FILE * pfile;
00432 //pfile = fopen (ofname,"w+t");
00433 // if (pfile==NULL)
00434 // {
00435 //  cerr << "error: could not open " << ofname  << endl;
00436 // exit(1); 
00437 // }
00438 
00440 
00441  
00442  nMatches = SSMXML->getNofMatches();
00443   sprintf (write_line, "  Total %i matches\n",nMatches );
00444   //fputs (write_line,pfile);
00445   //outfile << write_line;
00446   if (nMatches<=0){
00447           result=2;
00448           //return SOAP_FAULT; 
00449           }
00450   //fclose (pfile);
00451   //exit(1);
00452   char* insert_stm = (char*)soap_malloc(soap,4096);
00453   
00454   sprintf(stmnt, "insert into ssm_out_tab values ('%s' ", session); 
00455   
00456 
00457 
00458 
00459 
00460   
00461   
00462   rc = SSMXML->getQueryID ( queryID );
00463   
00465 //~~~~~~~~~  FILE * pfile;
00466 //~~~~~~~~~  pfile = fopen (fname,"w+t");
00467 //~~~~~~~~~   if (pfile==NULL)
00468 //~~~~~~~~~   {
00469 //~~~~~~~~~    cerr << "error: could not open " << fname  << endl;
00470 //~~~~~~~~~    exit(1); 
00471 //~~~~~~~~~   }
00473  char*  table_exists_stm = (char*)soap_malloc(soap,3072);
00474  int n;
00475  char* create_table_stm="create table ssm_out_tab(session_id varchar2(64), query_id varchar2(10), target_id  varchar2(10), query_chain varchar2(6), target_chain  varchar2(6),"
00476  "p_score number, z_score number, rmsd number, r_xx number, r_xy number, r_xz number, r_yx number, r_yy number, r_yz number, r_zx number, r_zy number, r_zz number,"
00477  "t_x number, t_y number, t_z number, pair_query_start varchar2(10), pair_query_end varchar2(10),pair_target_chain varchar2(6), pair_target_start varchar2(6),pair_target_end varchar2(6),querydate varchar2(32) DEFAULT TO_CHAR(SYSDATE, 'MM-DD-YYYY HH24:MI:SS'))";
00478  sprintf(table_exists_stm, "select count(*) " 
00479  "from all_objects o where o.object_name like 'SSM_OUT_TAB' and o.owner = 'SEARCH'");
00480  msdbConnect db;
00481  msdbConnect::msdbInit(); // initialize OCI environment
00482  try{
00483   db.rlogon(loginstr); // connect to Oracle
00484  // otl_cursor::direct_exec(db,"drop table ssm_out_tab",
00485  //   msdbException::disabled // disable OTL exceptions
00486  //  ); // drop table
00487  msdbStream i(1, table_exists_stm, db);
00488  i >> n;
00489  if (n==0)
00490  {otl_cursor::direct_exec(db,create_table_stm);  // create table
00491  }
00492  
00493   
00494  } //try
00495  catch(msdbException& p){ // intercept OTL exceptions
00496   cerr<<p.msg<<endl; // print out error message
00497   cerr<<p.stm_text<<endl; // print out SQL that caused the error
00498   cerr<<p.var_info<<endl; // print out the variable that caused the error
00499   //outfile <<p.msg<<endl; // print out error message                          
00500   //outfile <<p.stm_text<<endl; // print out SQL that caused the error         
00501   //outfile <<p.var_info<<endl; // print out the variable that caused the error
00502  
00503  
00504  }
00505  if (rc==query_pdbentry)  {
00506           sprintf(stmnt, "%s, '%s'",stmnt,queryID);
00507           //sprintf(tmp, "'%s'",queryID);
00508           //sprintf (write_line, "  Query: PDB code %s\n",queryID );
00509      
00510           //fwrite (write_line, 1 , strlen(write_line), pfile);
00511          
00512           }
00513   else if (rc==query_file) {
00514           sprintf(stmnt, "%s, '%s'",stmnt,queryID);
00515           //sprintf(tmp, "'%s'",queryID);
00516           //sprintf (write_line,"  Query: coordinate file %s\n",queryID );
00517           
00518           //fwrite (write_line, 1 , strlen(write_line), pfile);
00519          
00520           }
00521                       else {
00522                                                   sprintf(stmnt, "%s, NULL",stmnt);
00523                                                   //sprintf (write_line, "  Error retrieving query ID #%i\n",rc );
00524                                                   
00525                                                   //fwrite (write_line, 1 , strlen(write_line), pfile);
00526                                                 
00527                                                   }
00528 
00529   
00530   
00531   
00532   
00533   
00534   for (int i=1;i<=nMatches;i++)  { //nMatches
00535     sprintf (insert_stm,"%s",stmnt);
00536     //sprintf (write_line, "\n  MATCH #%i\n",i );
00537    
00538         //fwrite (write_line, 1 , strlen(write_line), pfile);
00539     rc = SSMXML->getTargetID ( targetID,i );
00540     switch (rc)  {
00541       case target_pdbentry   :
00542         {//sprintf (write_line, "  Target: PDB code %s\n" ,targetID );
00543             sprintf(insert_stm, "%s, '%s'",insert_stm,targetID);
00544                 //sprintf(tmp, "'%s'",targetID);
00545                 }
00546                 break;
00547       case target_file       :
00548         {//sprintf (write_line, "  Target: file %s\n"     ,targetID );
00549              sprintf(insert_stm, "%s, '%s'",insert_stm,targetID);
00550                  //sprintf(tmp, "'%s'",targetID);
00551                  } 
00552            break;
00553       case target_pdb        :
00554         {//sprintf (write_line, "  Target: PDB entry %s\n",targetID );
00555             sprintf(insert_stm, "%s, '%s'",insert_stm,targetID);
00556                 //sprintf(tmp, "'%s'",targetID);
00557                 }
00558                 break;
00559       case target_scop       :
00560         {//sprintf (write_line, "  Target: SCOP entry %s\n",targetID );
00561             sprintf(insert_stm, "%s, '%s'",insert_stm,targetID);
00562                 //sprintf(tmp, "'%s'",targetID);
00563                 }
00564                 break;
00565       case target_scopsubset :
00566         {//sprintf (write_line, "  Target: SCOP subset entry %s\n",targetID );
00567             sprintf(insert_stm, "%s, '%s'",insert_stm,targetID);
00568                 //sprintf(tmp, "'%s'",targetID);
00569                 }
00570                 break;
00571       default :
00572         {//sprintf (write_line, "  Error retrueving target ID #%i\n",rc );
00573                  sprintf(insert_stm, "%s, NULL",insert_stm);}
00574     } // end switch
00575     //outfile << queryID << endl;
00576         //outfile << targetID << endl;
00577         //fwrite (write_line, 1 , strlen(write_line), pfile);
00578     SSMXML->getQueryChain  ( queryCh ,i );
00579     SSMXML->getTargetChain ( targetCh,i );
00580     //sprintf (write_line, "          query  chain '%s'\n"
00581     //         "          target chain '%s'\n", queryCh,targetCh );
00582     
00583         if (!queryCh || strlen(queryCh)==0 || queryCh==NULL)
00584      {sprintf(insert_stm, "%s, NULL",insert_stm);}
00585           else
00586          {sprintf(insert_stm, "%s, '%s'",insert_stm,queryCh);
00587           //sprintf(tmp, "'%s'",queryCh);
00588           }
00589         if (!targetCh || strlen(targetCh)==0 || targetCh==NULL)
00590      {sprintf(insert_stm, "%s, NULL",insert_stm);}
00591           else
00592          {sprintf(insert_stm, "%s, '%s'",insert_stm,targetCh);
00593          //sprintf(tmp, "'%s'",targetCh);
00594          }
00595     
00596         //outfile << "\nHere I am\n";
00597     
00598         //fwrite (write_line, 1 , strlen(write_line), pfile);
00599     //sprintf (write_line, "          P-score %11.4f, Z-score %11.4f, RPDBe %11.4f\n",
00600     //         SSMXML->getPScore(i),SSMXML->getZScore(i),SSMXML->getRMSD(i) );
00601     sprintf(insert_stm, "%s, %11.4f",insert_stm,SSMXML->getPScore(i));
00602         
00603         sprintf(insert_stm, "%s, %11.4f",insert_stm,SSMXML->getZScore(i));
00604         
00605         sprintf(insert_stm, "%s, %11.4f",insert_stm,SSMXML->getRMSD(i));
00606         
00607         
00608         //fwrite (write_line, 1 , strlen(write_line), pfile);
00609     rc = SSMXML->getRTMatrix ( RT,i );
00610     if (rc)  {
00611       //sprintf (write_line, "          Error #%i at retrieving RT-matrix.\n",rc );
00612           for (int x=0;x<3 ;x++ )
00613    {for (int y=0;y<4 ;y++ )
00614     {sprintf(insert_stm, "%s, NULL",insert_stm);}
00615    }
00616           
00617          
00618           //fwrite (write_line, 1 , strlen(write_line), pfile);
00619           sprintf(insert_stm, "%s )",insert_stm);
00620       //fwrite (insert_stm, 1 , strlen(insert_stm), pfile);
00621       //fclose (pfile);
00622       break;
00623     }
00624     //sprintf (write_line, "          RT-matrix: %10.3f %10.3f %10.3f   %10.3f\n"
00625     //         "                     %10.3f %10.3f %10.3f   %10.3f\n"
00626     //         "                     %10.3f %10.3f %10.3f   %10.3f\n",
00627     //         RT[0][0], RT[0][1], RT[0][2], RT[0][3],
00628     //         RT[1][0], RT[1][1], RT[1][2], RT[1][3],
00629     //         RT[2][0], RT[2][1], RT[2][2], RT[2][3] );
00630    for (int x=0;x<3 ;x++ )
00631    {for (int y=0;y<4 ;y++ )
00632     {sprintf(insert_stm, "%s, %10.3f",insert_stm, RT[x][y]);}
00633    }
00634    sprintf(insert_stm, "%s, NULL, NULL, NULL, NULL, NULL, TO_CHAR(SYSDATE, 'MM-DD-YYYY HH24:MI:SS'))",insert_stm);
00635    
00636    //TO_DATE(TO_CHAR(SYSDATE, 'MM-DD-YYYY HH24:MI:SS'),'MM-DD-YYYY HH24:MI:SS')
00637    //~*******sprintf(insert_stm, "%s )",insert_stm);
00638    //fwrite (insert_stm, 1 , strlen(insert_stm), pfile);
00639    //fclose (pfile);
00640    //fwrite (write_line, 1 , strlen(write_line), pfile);
00641   
00642    //fwrite (insert_stm, 1 , strlen(insert_stm), pfile);
00643    try
00644   {
00645         otl_cursor::direct_exec(db,insert_stm);
00646   }
00647    catch(msdbException& p){ // intercept OTL exceptions
00648    cerr<<p.msg<<endl; // print out error message
00649    cerr<<p.stm_text<<endl; // print out SQL that caused the error
00650    cerr<<p.var_info<<endl; // print out the variable that caused the error
00651    //outfile <<p.msg<<endl; // print out error message                          
00652    //outfile <<p.stm_text<<endl; // print out SQL that caused the error         
00653    //outfile <<p.var_info<<endl; // print out the variable that caused the error
00654   }
00655 
00656   } // for loop
00657  
00658  
00660  //outfile.close();
00661 
00662  
00663 
00664 //~***********  fwrite (insert_stm, 1 , strlen(insert_stm), pfile);
00665 //~***********  
00666   //fclose (pfile);
00668   db.logoff(); // disconnect from Oracle 
00670   
00671   sprintf(syscall, "rm -f %s %s", fname,xmlfn);
00672   result = system(syscall); // syscall to delete files 
00673   if (result < 0){
00674           result = errno;
00675   }else{
00676           result=0;
00677   }
00678   
00679   
00680   
00681   //msdbStream o(50, // buffer size
00682   //            "insert into test_tab values(12345678900000000+:f1<int>,:f11<int>,:f2<char[31]>, SYSDATE)", 
00683   //               // SQL statement
00684   //            db // connect object
00685   //           );
00686  
00687  return SOAP_OK;
00688  }           
00689 
00690 
00691 int ns__msdAppServer(struct soap *soap, int numofpars, array *inparams,  int &result){
00692  inparams->__size=numofpars;
00693  size_t buffsize=0;
00694  char* syscall;
00695  char * buff;
00696  for (int i=0;i<numofpars ;i++ )
00697  {buffsize = buffsize + strlen((*inparams)[i]->__item)+1;
00698  }
00699  buff=(char *)soap_malloc(soap, buffsize);
00700  sprintf(buff,"%s",(*inparams)[0]->__item);
00701  for (int i=1;i<numofpars ;i++ )
00702  {sprintf(buff,"%s %s",buff,(*inparams)[i]->__item);
00703  }
00704  syscall = (char*)soap_malloc(soap, strlen(buff)+1);
00705  sprintf(syscall,"%s", buff);
00706  result = system(syscall); // syscall
00707  if (result < 0)
00708  {result = errno;
00709  }
00710   return SOAP_OK;
00711 }       
00712 
00713 
00715 
00716 //char* instr ="<fatsa>"
00717 // "<sequence>VMVSPMASIRSDEGMPIFVGDRSNVQDGVVLHALETINEEGEPIEDNI</sequence>"
00718 // "<evalue>1e-10</evalue>"
00719 //" <library>PDB</library>"
00720 //"</fatsa>";
00721 
00723 
00724 
00725 
00726 
00727 
00728 
00729 
00730 
00731 
00732 
00733 
00734 
00735 
00736 int ns__msdFasta(struct soap *soap, int numofpars, array *inparams,  int &result){
00737  char* xmlstr=(char*)soap_malloc(soap,4096); //4096
00738  char* xmlstrn=(char*)soap_malloc(soap,4096);
00739  char* infname=(char*)soap_malloc(soap,256);
00740  char* outfname=(char*)soap_malloc(soap,256);
00741  char* sessionid=(char*)soap_malloc(soap,64);
00742  char* sequence=(char*)soap_malloc(soap,3072);
00743  char* evalue=(char*)soap_malloc(soap,256);
00744  char* library=(char*)soap_malloc(soap,256);
00745  char* libref=(char*)soap_malloc(soap,8);
00746  
00747  //char xml_txtbuff[256];
00748  //char * xml_Buff;
00749  //int xml_elno=-1;
00750  //msd_xml_element * xml_inf=new msd_xml_element[10];
00751  
00752  inparams->__size=numofpars;
00753  size_t buffsize=0;
00754  sprintf(xmlstr,"%s",(*inparams)[0]->__item);
00755  //~~~~trimcr(xmlstr);
00756  xml_Buff=(char*)soap_malloc(soap,strlen(xmlstr)+1);
00757  sprintf(xml_Buff,"%s",xmlstr);
00758  sprintf(sessionid,"%s",(*inparams)[1]->__item);
00759  sprintf(infname,"/ebi/msd/ssm/cgi-bin/ws/work/%s_in.fasta",sessionid);
00760  sprintf(outfname,"/ebi/msd/ssm/cgi-bin/ws/work/%s_out.fasta",sessionid);
00761  
00762  xml_inf = (msd_xml_element *) soap_malloc(soap, sizeof(msd_xml_element)*10);
00763  xml_txtbuff = (char*)soap_malloc(soap, 3072);
00764  
00765     
00766  
00767  XML_Parser xp = XML_ParserCreate(NULL);
00768  XML_Parser * pxp;
00769   if (! xp) {
00770     fprintf(stderr, "Couldn't allocate memory for parser\n");
00771     exit(-1);
00772   } else {
00773    pxp=(XML_Parser *)soap_malloc(soap, sizeof(XML_Parser));
00774    pxp=&xp;
00775   }
00776  
00777 
00778   //xml_elements * info;
00779  
00780   //XML_SetUserData(*pxp, soap);
00781 
00782   XML_UseParserAsHandlerArg(*pxp);
00783   XML_SetElementHandler(*pxp, start_hndl, end_hndl);
00784   XML_SetCharacterDataHandler(*pxp, char_hndl);
00785   XML_SetProcessingInstructionHandler(*pxp, proc_hndl);
00786 if (! XML_Parse(*pxp, xml_Buff, strlen(xml_Buff), true)) {
00787         fprintf(stderr, "Parse error at line %d:\n%s\n",
00788               XML_GetCurrentLineNumber(*pxp),
00789               XML_ErrorString(XML_GetErrorCode(*pxp)));
00790       exit(-1);
00791     }
00792         
00793         XML_ParserFree(xp);
00794         //printf("\nNumber of objects created: %d \n",elno);
00795         //for (int i=0;i<=elno ;i++ )
00796         //{printf("\nValue of tag %s :",inf[i].tag);
00797         // printf("%s\n",inf[i].data);
00798         //}
00799 for (int i=0;i<=xml_elno ;i++ ){
00800         if (strcmp(xml_inf[i].tag,"evalue")==0)
00801         {sprintf(evalue,"%s",xml_inf[i].data);}else if (strcmp(xml_inf[i].tag,"sequence")==0)
00802         {removena(xml_inf[i].data);
00803          sprintf(sequence,">Q\n%s\n",xml_inf[i].data);}else if (strcmp(xml_inf[i].tag,"library")==0)
00804         {sprintf(libref,"%s",xml_inf[i].data);}
00805 } //end for
00806 
00807 
00808 //~~~~sprintf(sequence,">Q\n%s\n",inf[1].data);
00809 //~~~~sprintf(evalue,"%s",inf[2].data);
00810 //~~~~sprintf(libref,"%s",inf[3].data);
00811 
00812 FILE * pfile;
00813  pfile = fopen (infname,"w+t");
00814    if (pfile==NULL)
00815    {cerr << "error: could not create " << infname  << endl;
00816     exit(1);}
00817  fwrite (sequence , 1 , strlen(sequence), pfile);
00818  //pfile << sequence << endl;
00819  //pfile.close();
00820  //pfile << evalue << endl;
00821  //pfile << library << endl;
00822  //fwrite (xmlstr , 1 , strlen(xmlstr), pfile);
00823  //fwrite (evalue , 1 , strlen(evalue), pfile);
00824  //fwrite (library , 1 , strlen(library), pfile);
00825 
00826          //fputs (xmlstrn,pfile);
00827 // pfile.close();
00828 
00829 fclose (pfile);
00830 pfile=NULL; 
00831 
00832 
00833 
00834 
00835 lcase(libref);
00836 if (strcmp(libref, "pdb")==0) // strcmp((*inparams)[3]->__item 
00837 {sprintf(library,"/ebi/msd/ssm/cgi-bin/ws/fasta/pdb_aa.fasta"); // /ebi/ftp/pub/databases/msd/pdb_aa.fasta
00838 } //     /ebi/msd/srchsrv/fastalib/pdb_aa.fasta
00839  
00840  
00841  //ofstream pfile;
00842  //pfile.open(infname);
00843  
00844  
00845 
00846 
00847  //for (int i = 0; i < 10; i++){
00848 //      free(xml_inf[i].data); 
00849 //      free(xml_inf[i].tag);
00850  //}
00851  
00852  //delete [] xml_Buff;
00853  //delete [] xml_txtbuff;
00854  
00855  //free(xml_Buff);
00856  //free(xml_txtbuff);
00857  
00858  xml_elno = -1;
00859  char* buff;
00860  char* syscall;
00861  
00862  
00863 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
00864 //Try this first:
00865 //system("/bin/sh -c bsub ...")
00866 //other choices:
00867 //". /etc/profile.d/lsf.sh ; bsub ..."
00868 //for tcsh
00869 //"source /etc/profile.d/lsf.csh ; bsub ..."
00870  
00871 //bsub -q extsrv_interactive -R msd_ssm -o /ebi/msd/work/siamak/apache/htdocs/23f5a66ec9c2091bea3b8f7fb82b4864_out.fasta /ebi/msd/work/siamak/msd_api/fasta/bin/fasta -Q -H -E 1e-10 /ebi/msd/work/siamak/apache/htdocs/23f5a66ec9c2091bea3b8f7fb82b4864_in.fasta /ebi/msd/srchsrv/fastalib/pdb_aa.fasta
00872  int noarr = 8;
00873  char ** tmp = (char**)soap_malloc(soap,noarr*256);
00874  for (int i=0;i<noarr ;i++ ){
00875  tmp[i]= (char*)soap_malloc(soap,256);
00876  } 
00877  sprintf(tmp[0],"%s","bsub -q extsrv_interactive -R msd_ssm -o");
00878  sprintf(tmp[1],"%s",outfname);
00879  sprintf(tmp[2],"%s","/ebi/msd/ssm/cgi-bin/ws/fasta/bin/fasta -Q -H -E ");
00880  sprintf(tmp[3],"%s",evalue);
00881  sprintf(tmp[4],"%s",infname);
00882  sprintf(tmp[5],"%s",library);
00883  sprintf(tmp[6],"%s",">");
00884  sprintf(tmp[7],"%s",outfname);
00885 
00886  buff=(char *)soap_malloc(soap, noarr*(256+1));
00887  sprintf(buff,"%s",tmp[0]);
00888  for (int i=1;i<noarr ;i++ )
00889  {sprintf(buff,"%s %s",buff,tmp[i]);
00890  }
00891  
00892  
00893  
00894  
00895  
00896  
00897 // xsd__anyType* tmp[8];
00898 // tmp[0]=new xsd__string("bsub -q extsrv_interactive -R msd_ssm -o"); // -o outfname
00899 // tmp[1]=new xsd__string(outfname);
00900 // tmp[2]=new xsd__string("/ebi/msd/ssm/cgi-bin/ws/fasta/bin/fasta -Q -H -E ");
00901 // tmp[3]=new xsd__string(evalue);
00902 // tmp[4]=new xsd__string(infname);
00903 // tmp[5]=new xsd__string(library);
00904 // tmp[6]=new xsd__string(">"); 
00905 // tmp[7]=new xsd__string(outfname);
00906 //  
00907 // 
00908 // for (int i=0;i<8 ;i++ ) //6
00909 // {buffsize = buffsize + strlen(tmp[i]->__item)+1;
00910 // }
00911 //buff=(char *)soap_malloc(soap, buffsize);
00912  sprintf(buff,"%s",tmp[0]);
00913  for (int i=1;i<noarr ;i++ ) 
00914  {sprintf(buff,"%s %s",buff,tmp[i]);
00915  }
00916  
00917  //for (int i = 0; i < 8; i++){
00918  //       delete tmp[i];
00919  //}
00920 
00921  syscall = (char*)soap_malloc(soap, strlen(buff)+1);
00922  sprintf(syscall,"%s", buff);
00923  //pfile << syscall << endl;
00924  //pfile = fopen (infname,"a");
00925  //fwrite (syscall, 1 , strlen(syscall), pfile);
00926  //fwrite (library , 1 , strlen(library), pfile);
00927  //fwrite (evalue , 1 , strlen(evalue), pfile);
00928  //fclose (pfile);
00929  //pfile=NULL;
00930  //int j=0;
00931  //while(!fileexists(infname) && j<12*15) // fileexists --- up to 15 minutes wait for result
00932  // { wait(5); // wait 5 seconds and retry again
00933  //     j++;
00934  // } // end while
00935  
00936 
00937 
00938  
00939  pfile=fopen (infname,"r+t");
00940  if (pfile)
00941  { //fwrite (syscall, 1 , strlen(syscall), pfile);
00942   fclose (pfile);
00943   pfile=NULL;
00945   
00946   result = system(syscall);
00947   
00948   //result = system("/ebi/msd/work/siamak/apache/cgi-bin/msd_main > /ebi/msd/ssm/cgi-bin/ws/work/appserv.txt");
00949   //system(syscall);
00950   //result = 0;
00951  } 
00952   //wait(5);
00953   
00954   if (result < 0)
00955   {result = errno;         
00956   }
00957 
00958 
00959  //int j=0;
00960   //wait(5);
00961   //while(!fileexists(outfname) && j<12*15) // up to 15 minutes wait for result
00962  // { wait(5); // wait 5 seconds and retry again
00963  //     j++;
00964  // }
00965  
00966  //delete [] buff;
00967  //delete [] syscall;
00968  
00969  //soap_dealloc(soap, (void*)buff);
00970  //soap_dealloc(soap,(void*)syscall);
00971  //soap_dealloc(soap,(void*)xml_Buff);
00972 
00973  soap_dealloc(soap, (void*)xmlstr);
00974  soap_dealloc(soap, (void*)xmlstrn);
00975  soap_dealloc(soap, (void*)xml_Buff);
00976  soap_dealloc(soap, (void*)xml_txtbuff);
00977  soap_dealloc(soap, (void*)sequence);
00978  
00979  
00980  soap_unlink(soap, (void*)xmlstr);
00981  soap_unlink(soap, (void*)xmlstrn);
00982  soap_unlink(soap, (void*)xml_Buff);
00983  soap_unlink(soap, (void*)xml_txtbuff);
00984  soap_unlink(soap, (void*)sequence);
00985  
00986  //soap_unlink(soap, (void*)buff);
00987  //soap_unlink(soap, (void*)syscall);
00988 
00989  return SOAP_OK;
00990 }       
00992 
00993 
00994 
00995 
00996 
00997 int ns__msdFastaParser (struct soap *soap, char* sessionid, char* dbserver, int &result){
00998  char* fastafn = (char*)soap_malloc(soap,256);
00999  char* session_id;
01000  char* login_string = (char*)soap_malloc(soap,64);
01001  char* loginstr;
01002  char* fasta_parser = (char*)soap_malloc(soap,256);
01003  char* syscall = (char*)soap_malloc(soap,256);
01004  session_id=(char*)soap_malloc(soap, strlen(sessionid)+1);
01005  //sprintf(session_id,"%s",sessionid);
01006  strcpy(session_id,sessionid);
01007  sprintf(login_string,"search/search55@%s",dbserver);
01008  loginstr = (char*)soap_malloc(soap,strlen(login_string)+1);
01009  strcpy(loginstr, login_string);
01010  sprintf(fastafn,"/ebi/msd/ssm/cgi-bin/ws/work/%s_out.fasta",session_id);
01011  sprintf(fasta_parser,"/ebi/msd/ssm/cgi-bin/ws/work/%s_in.fasta",session_id);
01012  
01013  char* read_line = (char*)soap_malloc(soap,1024);
01014  char* stmnt = (char*)soap_malloc(soap,256);
01015   int j=0;
01016   //wait(5);
01017   while(!lsf_file_completed(fastafn) && j<12*15) // fileexists --- up to 15 minutes wait for result
01018   { wait(5); // wait 5 seconds and retry again
01019         j++;
01020   } // end while
01021   
01022   
01023   //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
01024     ifstream infile;
01025         infile.open(fastafn);
01026         //ofstream outfile;
01027         //outfile.open(fasta_parser);
01028         
01029         char * search = ">>";
01030         char * replace = "Record No.";
01031         char * linebuf = (char*)soap_malloc(soap,256);
01032         char * tempbuf = (char*)soap_malloc(soap,256);
01033         char * lastTok = (char*)soap_malloc(soap,256);
01034         char * record = (char*)soap_malloc(soap,7000);
01035     char * tmprec = (char*)soap_malloc(soap,7000);
01036     char * evalue_result = (char*)soap_malloc(soap,16);
01037         char * id_chain = (char*)soap_malloc(soap,16);
01038         char * id = (char*)soap_malloc(soap,12);
01039         char * chain = (char*)soap_malloc(soap,4);
01040         char * alignment = (char*)soap_malloc(soap,6000);
01041         char*  midbuf = (char*)soap_malloc(soap,12);
01042         char* tmp = (char*)soap_malloc(soap,16);
01043         char * outBuf = (char*)soap_malloc(soap,6000);
01044         // char tokbuf[100]= "";
01045     char * pchs;
01046         char * pche;
01047         //char * pche;
01048         char * per;
01049         char * tok;
01050         char * pid;
01051         char * pch;
01052         char * token = (char*)soap_malloc(soap,16);
01053         int start,end,len,newrecord,recno;
01054         newrecord=0;
01055         char* insert_stm = (char*)soap_malloc(soap,4096);
01056     sprintf(stmnt, "insert into ssm_out_tab values ('%s' ", session_id);   
01057         char* table_exists_stm = (char*)soap_malloc(soap,3072);
01058  int n;
01059  char* create_table_stm="create table fasta_out_tab(session_id varchar2(64), e_value_result varchar2(16), lib_id_and_chain varchar2(16), lib_id varchar2(12), chain  varchar2(4),"
01060  "alignment blob, querydate varchar2(32) DEFAULT TO_CHAR(SYSDATE, 'MM-DD-YYYY HH24:MI:SS'))";
01061  sprintf(table_exists_stm, "select count(*) " 
01062  "from all_objects o where o.object_name like 'FASTA_OUT_TAB' and o.owner = 'SEARCH'");
01063  msdbConnect db;
01064  msdbConnect::msdbInit(); // initialize OCI environment
01065  try{
01066   db.rlogon(loginstr); // connect to Oracle
01067  // otl_cursor::direct_exec(db,"drop table ssm_out_tab",
01068  //   msdbException::disabled // disable OTL exceptions
01069  //  ); // drop table
01070  
01071  otl_long_string alignment_blob(6000); // define long string variable for blob
01072  db.set_max_long_size(6000); // set maximum long string size for connect object
01073  msdbStream i(1, table_exists_stm, db);
01074  i >> n;
01075  if (n==0)
01076  {otl_cursor::direct_exec(db,create_table_stm);  // create table
01077  }
01078  //otl_cursor::direct_exec(db,insert_stm);
01079  //} //------------> try
01080 // catch(msdbException& p){ // intercept OTL exceptions
01081 //  cerr<<p.msg<<endl; // print out error message
01082 //  cerr<<p.stm_text<<endl; // print out SQL that caused the error
01083 //  cerr<<p.var_info<<endl; // print out the variable that caused the error
01084 // }
01086         
01087  
01088  msdbStream o(1, // buffer size has to be set to 1 for operations with LOBs
01089  "insert into fasta_out_tab values(:session_id<char[64]>,:e_value_result<char[16]>,:lib_id_and_chain<char[16]>, "
01090  ":lib_id<char[12]>,:chain<char[4]>,empty_blob(),TO_CHAR(SYSDATE, 'MM-DD-YYYY HH24:MI:SS')) returning alignment into :alignment<blob> ",
01091  db );  
01092  recno=0;
01093         do {      //newrecord=0;
01094                       infile.getline(linebuf, 256);
01095                       if(linebuf != NULL)
01096                                 { strcpy(tempbuf, linebuf);
01097                                   pchs = strstr (tempbuf, ">>");
01098                                   pche = strstr (tempbuf, "Library scan:");
01099                   if ((pchs != NULL) || (newrecord == 1) || (pche != NULL))
01100                     {   
01101                                           sprintf(record,"%s%s\n",record, linebuf);
01102                                           do {
01103                                                  infile.getline(linebuf, 256);
01104                                                  if(linebuf != NULL)
01105                                           {strcpy(tempbuf, linebuf);
01106                                                    pchs = strstr (tempbuf, ">>");
01107                                                    pche = strstr (tempbuf, "Library scan:");
01108                                                    if ((pchs == NULL) && (pche == NULL)){
01109                                                     sprintf(record,"%s%s\n",record, linebuf);
01110                                                         }else{
01111                                                                 //recore has been completed and should be processed
01112 
01113                                                                 sprintf(tmprec,"%s",record);
01114                                                     per = strstr (tmprec,":");
01115                                                 tok = strtok (tmprec," ");
01116                                                 sprintf(token,"%s", tok);
01117                                 len=strlen(token);
01118                                                     start=per-tok+1;
01119                                                     end=len;
01120                                                     midcopy(token,midbuf,start,end);
01121                                                     sprintf(id_chain,"%s",midbuf);
01122                                                                 sprintf(tmp,"%s",id_chain);
01123                                                                 pid = strtok (tmp,"_");
01124                                                                 sprintf(id,"%s",pid);
01125                                                                 start=strlen(id)+1;
01126                                                                 end=strlen(id_chain);
01127                                                                 if (start != end)
01128                                                                 {midcopy(id_chain,chain,start,end);
01129                                                                 }else sprintf(chain,"%s","");
01130                                                                 
01131                                                                 sprintf(tmprec,"%s",record);
01132                                 per = strstr (tmprec,"E():");
01133                                                                 tok = strtok(per,"\n");
01134                                                                 sprintf(token,"%s", tok);
01135                                                                 start=per-tok+5;
01136                                                     end=strlen(token);
01137                                                                 midcopy(token,midbuf,start,end);
01138                                                     sprintf(evalue_result,"%s",midbuf);
01139                                                                 sprintf(tmprec,"%s",record);
01140                                                                 per = strstr (tmprec,"Q   ");
01141                                                                 sprintf(alignment,"%s",per-68);
01142 
01143 //~~~~~~~~~                                      outfile << session_id <<endl;
01144 //~~~~~~~~~                                      outfile << record <<endl;
01145 //~~~~~~~~~                  outfile << id_chain <<endl;
01146 //~~~~~~~~~                                      outfile << id <<endl;
01147 //~~~~~~~~~                                      outfile << chain <<endl;
01148 //~~~~~~~~~                                      outfile << evalue_result << endl;
01149 //~~~~~~~~~                  outfile << alignment << endl;
01150 //~~~~~~~~~                                      outfile << "Record finished~~~~~~~~" << endl;
01151                                          
01152                                          recno++;
01153                                          len=strlen(alignment);
01154                                          
01155                      for (int i=0;i< len ;i++ )
01156                      {alignment_blob[i] = alignment[i];
01157                      }
01158                                          alignment_blob.set_len(len+1); 
01159                                           o << session_id << evalue_result << id_chain << id << chain << alignment_blob;         
01160                                                                 sprintf(record,"%s","");
01161                                                                 sprintf(record,"%s\n", linebuf);
01162                                                                 newrecord=1; // new record starts
01163                                                                 //pchs=NULL;
01164                                                                 } 
01165                                                   }
01166                                                  } while ((pchs == NULL) && !infile.eof() && (pche == NULL));
01167                                     }
01168                                   }
01169                         else linebuf[0] = '0';
01170                         
01171                  } while ( ! infile.eof());
01172  
01174  
01175 //--- otl_long_string blob_result(4000); // define long string variable
01176 //--- db.set_max_long_size(4000); // set maximum long string size for connect object
01177 //---
01178 //--- msdbStream si(10, // buffer size. To read BLOBs, it can be set to a size greater than 1
01179 //---              "select alignment from fasta_out_tab",
01180 //---                 // SELECT statement
01181 //---              db // connect object
01182 //---             ); 
01183 //--- while(!si.eof()){ // while not end-of-data
01184 //---  si>>blob_result;
01185 //---  outfile <<"blob_result="<<blob_result[0]<<blob_result[blob_result.len()-1]<<", len="<<blob_result.len()<<endl;
01186 //--- } // end while
01187  
01188  
01189  } // try
01190  catch(msdbException& p){ // intercept OTL exceptions
01191   cerr<<p.msg<<endl; // print out error message
01192   cerr<<p.stm_text<<endl; // print out SQL that caused the error
01193   cerr<<p.var_info<<endl; // print out the variable that caused the error
01194 //~~~~~~~  outfile <<p.msg<<endl; // print out error message
01195 //~~~~~~~  outfile <<p.stm_text<<endl; // print out SQL that caused the error
01196 //~~~~~~~  outfile <<p.var_info<<endl; // print out the variable that caused the error
01197  }
01198 //~~~~~~~  outfile << "Total Records: " << recno <<endl;
01199     db.logoff();        
01200         infile.close();
01201         //~~~~~~~ outfile.close();
01202         sprintf(syscall, "rm -f %s %s", fasta_parser,fastafn);
01203     result = system(syscall); // syscall
01204    if (result < 0){
01205           result = errno;
01206    }else{
01207           result=0;
01208    }
01209         
01210         
01211         
01212 //      delete linebuf;
01213 //      delete tempbuf;
01214 //      delete lastTok;
01215 //      delete record;
01216 //      delete tmprec;
01217 //      delete outBuf;
01218 //      delete alignment;
01219   //outfile << outBuf <<endl;
01220   
01221   return SOAP_OK;
01222 }

Generated on Fri Apr 16 13:47:45 2004 for MSDAPI by doxygen 1.3.4-20031005