00001
00002
00003
00004
00005
00007
00008
00009
00010
00011
00012
00013
00014
00016
00020
00022
00023
00024
00025
00026
00027
00028
00029
00030
00032
00034
00035
00036
00037
00038
00039
00040
00043
00044
00045
00046
00048
00049
00050
00051
00052
00053
00054 #include <iostream>
00055 #include <fstream>
00056 #include <string.h>
00057
00058
00059
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
00072
00073
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
00087
00088 #include <sys/stat.h>
00089
00090
00091
00092
00093
00095
00096
00097
00098
00099 int xml_elno=-1;
00100 msd_xml_element * xml_inf;
00101
00102 char * xml_Buff;
00103 char * xml_txtbuff;
00104
00105
00106 void default_hndl(void *data, const char *s, int len) {
00107
00108 }
00109
00110
00111
00112
00113
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 }
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", "");
00135
00136
00137
00138
00139 printcurrent((XML_Parser) data);
00140 }
00141
00142
00143 void end_hndl(void *data, const char *el) {
00144
00145 sprintf(xml_inf[xml_elno].data,"%s",xml_txtbuff);
00146
00147
00148 }
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
00156 strcpy(xbuf,txt);
00157 xbuf[txtlen]='\0';
00158
00159 sprintf(xml_txtbuff,"%s%s", xml_txtbuff, xbuf);
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172 }
00173
00174 void proc_hndl(void *data, const char *target, const char *pidata) {
00175
00176 printcurrent((XML_Parser) data);
00177
00178 }
00179
00180
00181
00182
00183
00184
00185
00186
00188
00189
00190
00191
00192
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
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217 if (argc < 3)
00218 {
00219
00220 soap_serve(&soap);
00221 }
00222 else
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);
00237 fprintf(stderr, "request served\n");
00238 soap_destroy(&soap);
00239 soap_end(&soap);
00240
00241 }
00242 }
00243
00244 soap_destroy(&soap);
00245 soap_end(&soap);
00246
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
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
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
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
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
00353
00354
00355
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
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
00382
00383
00384 char* stmnt = (char*)soap_malloc(soap,512);
00385 int j=0;
00386 wait(30);
00387 while(j<12*15)
00388 { if (fileexists(xmlfn))
00389 { out_file_ok=0;
00390 break;}else
00391 {wait(5);}
00392 j++;
00393 }
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
00408
00409 InitMatType();
00410
00411 SSMXML = new CSSMXML();
00412
00413
00414
00415
00416
00417 rc = SSMXML->readSSMXML ( xmlfn );
00418
00419
00420 if (rc) {
00421 result=rc;
00422
00423 }
00424
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438
00440
00441
00442 nMatches = SSMXML->getNofMatches();
00443 sprintf (write_line, " Total %i matches\n",nMatches );
00444
00445
00446 if (nMatches<=0){
00447 result=2;
00448
00449 }
00450
00451
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
00466
00467
00468
00469
00470
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();
00482 try{
00483 db.rlogon(loginstr);
00484
00485
00486
00487 msdbStream i(1, table_exists_stm, db);
00488 i >> n;
00489 if (n==0)
00490 {otl_cursor::direct_exec(db,create_table_stm);
00491 }
00492
00493
00494 }
00495 catch(msdbException& p){
00496 cerr<<p.msg<<endl;
00497 cerr<<p.stm_text<<endl;
00498 cerr<<p.var_info<<endl;
00499
00500
00501
00502
00503
00504 }
00505 if (rc==query_pdbentry) {
00506 sprintf(stmnt, "%s, '%s'",stmnt,queryID);
00507
00508
00509
00510
00511
00512 }
00513 else if (rc==query_file) {
00514 sprintf(stmnt, "%s, '%s'",stmnt,queryID);
00515
00516
00517
00518
00519
00520 }
00521 else {
00522 sprintf(stmnt, "%s, NULL",stmnt);
00523
00524
00525
00526
00527 }
00528
00529
00530
00531
00532
00533
00534 for (int i=1;i<=nMatches;i++) {
00535 sprintf (insert_stm,"%s",stmnt);
00536
00537
00538
00539 rc = SSMXML->getTargetID ( targetID,i );
00540 switch (rc) {
00541 case target_pdbentry :
00542 {
00543 sprintf(insert_stm, "%s, '%s'",insert_stm,targetID);
00544
00545 }
00546 break;
00547 case target_file :
00548 {
00549 sprintf(insert_stm, "%s, '%s'",insert_stm,targetID);
00550
00551 }
00552 break;
00553 case target_pdb :
00554 {
00555 sprintf(insert_stm, "%s, '%s'",insert_stm,targetID);
00556
00557 }
00558 break;
00559 case target_scop :
00560 {
00561 sprintf(insert_stm, "%s, '%s'",insert_stm,targetID);
00562
00563 }
00564 break;
00565 case target_scopsubset :
00566 {
00567 sprintf(insert_stm, "%s, '%s'",insert_stm,targetID);
00568
00569 }
00570 break;
00571 default :
00572 {
00573 sprintf(insert_stm, "%s, NULL",insert_stm);}
00574 }
00575
00576
00577
00578 SSMXML->getQueryChain ( queryCh ,i );
00579 SSMXML->getTargetChain ( targetCh,i );
00580
00581
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
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
00594 }
00595
00596
00597
00598
00599
00600
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
00609 rc = SSMXML->getRTMatrix ( RT,i );
00610 if (rc) {
00611
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
00619 sprintf(insert_stm, "%s )",insert_stm);
00620
00621
00622 break;
00623 }
00624
00625
00626
00627
00628
00629
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
00637
00638
00639
00640
00641
00642
00643 try
00644 {
00645 otl_cursor::direct_exec(db,insert_stm);
00646 }
00647 catch(msdbException& p){
00648 cerr<<p.msg<<endl;
00649 cerr<<p.stm_text<<endl;
00650 cerr<<p.var_info<<endl;
00651
00652
00653
00654 }
00655
00656 }
00657
00658
00660
00661
00662
00663
00664
00665
00666
00668 db.logoff();
00670
00671 sprintf(syscall, "rm -f %s %s", fname,xmlfn);
00672 result = system(syscall);
00673 if (result < 0){
00674 result = errno;
00675 }else{
00676 result=0;
00677 }
00678
00679
00680
00681
00682
00683
00684
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);
00707 if (result < 0)
00708 {result = errno;
00709 }
00710 return SOAP_OK;
00711 }
00712
00713
00715
00716
00717
00718
00719
00720
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);
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
00748
00749
00750
00751
00752 inparams->__size=numofpars;
00753 size_t buffsize=0;
00754 sprintf(xmlstr,"%s",(*inparams)[0]->__item);
00755
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
00779
00780
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
00795
00796
00797
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 }
00806
00807
00808
00809
00810
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
00819
00820
00821
00822
00823
00824
00825
00826
00827
00828
00829 fclose (pfile);
00830 pfile=NULL;
00831
00832
00833
00834
00835 lcase(libref);
00836 if (strcmp(libref, "pdb")==0)
00837 {sprintf(library,"/ebi/msd/ssm/cgi-bin/ws/fasta/pdb_aa.fasta");
00838 }
00839
00840
00841
00842
00843
00844
00845
00846
00847
00848
00849
00850
00851
00852
00853
00854
00855
00856
00857
00858 xml_elno = -1;
00859 char* buff;
00860 char* syscall;
00861
00862
00863
00864
00865
00866
00867
00868
00869
00870
00871
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
00898
00899
00900
00901
00902
00903
00904
00905
00906
00907
00908
00909
00910
00911
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
00918
00919
00920
00921 syscall = (char*)soap_malloc(soap, strlen(buff)+1);
00922 sprintf(syscall,"%s", buff);
00923
00924
00925
00926
00927
00928
00929
00930
00931
00932
00933
00934
00935
00936
00937
00938
00939 pfile=fopen (infname,"r+t");
00940 if (pfile)
00941 {
00942 fclose (pfile);
00943 pfile=NULL;
00945
00946 result = system(syscall);
00947
00948
00949
00950
00951 }
00952
00953
00954 if (result < 0)
00955 {result = errno;
00956 }
00957
00958
00959
00960
00961
00962
00963
00964
00965
00966
00967
00968
00969
00970
00971
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
00987
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
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
01017 while(!lsf_file_completed(fastafn) && j<12*15)
01018 { wait(5);
01019 j++;
01020 }
01021
01022
01023
01024 ifstream infile;
01025 infile.open(fastafn);
01026
01027
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
01045 char * pchs;
01046 char * pche;
01047
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();
01065 try{
01066 db.rlogon(loginstr);
01067
01068
01069
01070
01071 otl_long_string alignment_blob(6000);
01072 db.set_max_long_size(6000);
01073 msdbStream i(1, table_exists_stm, db);
01074 i >> n;
01075 if (n==0)
01076 {otl_cursor::direct_exec(db,create_table_stm);
01077 }
01078
01079
01080
01081
01082
01083
01084
01086
01087
01088 msdbStream o(1,
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 {
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
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
01144
01145
01146
01147
01148
01149
01150
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;
01163
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
01176
01177
01178
01179
01180
01181
01182
01183
01184
01185
01186
01187
01188
01189 }
01190 catch(msdbException& p){
01191 cerr<<p.msg<<endl;
01192 cerr<<p.stm_text<<endl;
01193 cerr<<p.var_info<<endl;
01194
01195
01196
01197 }
01198
01199 db.logoff();
01200 infile.close();
01201
01202 sprintf(syscall, "rm -f %s %s", fasta_parser,fastafn);
01203 result = system(syscall);
01204 if (result < 0){
01205 result = errno;
01206 }else{
01207 result=0;
01208 }
01209
01210
01211
01212
01213
01214
01215
01216
01217
01218
01219
01220
01221 return SOAP_OK;
01222 }