thor_getdat.pl

{
/* ________________________________________________________________________________
                                            Copyright (C) DataAspects, Inc. 1998
  thor_getdat.pl
  Objective: To generate a USMILES, search WR Thor database, 
             and return the SMILES, WRNO, CAS, MF, and MW.
  Actions:
    1. Client thor_getdat.pl connects to chemcop.pl running on the 
       Daylight Server and passes it three parameters:
        parm.0  db_exec - orders chemcop to run a command procedure
        parm.1  'thor_getdat' - name of chemcop procedure that executes
                                'get_data_from_cis.c' on the Daylight Server
        parm.2  WRNOSMI list which has one row with one of these values:
                1. 'wrno,999999' (i.e. 'wrno,001544)
                2. 'smi,c1cc...' (i.e. 'smi,c1ccccc1')
                3. 'cas,999-...' (i.e. 'cas,999-9999-9999')
    2. chemcop.pl executes get_data_from_cis.c.
    3. get_data_from_cis.c searches Thor for the either WRNO, SMILES or CAS and 
       returns the following code. If the search is successful, data are written 
       to an ASCII file.
       --Return Code:
                 0 - smile/wrno found, successful completion of program
                 1 - smile/wrno NOT FOUND in database
                 2 - failed to connect to database server
                 3 - failed to open cis database
                 4 - invalid parameters passed by calling program
                 5 - failed to open temp file needed to process data
                 6 - failed to generate unique smile from input 
                     (Note - a truly bad SMILES will cause the program 
                      to abort with the error message 'Segmentation Fault 
                     (core dumped)'. This is something I don't know how to trap.)

       --Data File:
                 CCN(CC)CCCC(C)Nc1ccnc2cc(Cl)ccc12.CC(=O)NC1(CCCC1)C(=O)O 
                 001544,C26H39ClN4O3,491.14, NONE 
    
    4. chemcop.pl returns the code and the data file to the client thor_getdat.pl.
    5. thor_getdat.pl parses the data.
  Note: In Unix, the values for SMILES, WRNO and CAS must be delimited 
  with single quotes and getchemdat.pl does this.

  SMILES for testing:
    WR008602 CAS= 1076-43-3 c1ccccc1
    WR018160 CAS= 338-69-2 N[C@@H](C)C(=O)O <- changed to USMILES -> C[C@H](N)C(=O)O
    WR024073 CAS= 7732-18-5 [2H]O[2H] <- changed to USMILES -> O([2H])[2H]

    not in Thor: c1c(CCCCCC)cc(CCCCCC)cc1
                 rc=1: SMILES/WRNO not found in Thor database.
    not in Thor: F/C=C\F 
                 rc=1: SMILES/WRNO not found in Thor database.
    not in Thor: [OH3+]
                 rc=1: SMILES/WRNO not found in Thor database.
    illegal SMILES:
                    c1ccccc
4.  get_data_from_cis.c can be run from the command line:
                 etchem% get_data_from_cis wrno '001544'
                 CCN(CC)CCCC(C)Nc1ccnc2cc(Cl)ccc12.CC(=O)NC1(CCCC1)C(=O)O 
                 001544,C26H39ClN4O3,491.14, NONE 

...Pat McGreevy, 18 Feb 99
________________________________________________________________________________*/
int c[4];                               /* store position of comma delimiters    */
int i;                                  /* counter                               */
int rc;                                 /* store return code fm TRIMrpc chemcopl */

char wrnosmi[4000];
char data[100];
char thorserver[20];

list wrnosmi_list;
list temp_list;
/* _____________________________________________________________________________ */
/*                    Connect to TRIMrpc Program, ChemCop.pl                     */
/* _____________________________________________________________________________ */
thorserver= "xxx.xxx.xx.xx";
printf("Connecting to Chemcop on ThorServer"); 
if (trap({
   connect(0,"net:chemcop@"^^G.thorserver^^"!vtxhost.trm");
   printf("Connected to Chemcop");
   })){
       bell();
       status("Failed to connect to Chemcop");
       connect(0);
       break;
       }
/* _____________________________________________________________________________ */
/*                           Format Thor Search String                           */
/* _____________________________________________________________________________ */
wrnosmi= prompt("Enter SMILES, WRNO or CAS: ");
wrnosmi_list= list_open("4000",1,"WRNO OR SMILES List");
if (length(translate(wrnosmi,"0123456789",""))==0)       /* WRNOs: numbers only */
  list_mod(wrnosmi_list,1,"wrno '"^^wrnosmi^^"'");       /* delimit string w/ ' */
else if (length(translate(wrnosmi,"0123456789-",""))==0) /* CAS: numbers & -    */
  list_mod(wrnosmi_list,1,"cas '"^^wrnosmi^^"'");        /* delimit string w/ ' */
else                                                     /* else it is a SMILES */
  list_mod(wrnosmi_list,1,"smi '"^^wrnosmi^^"'");         /*delimit string w/ ' */

printf("parm.2 is "^^list_curr(wrnosmi_list,0) );

/* _____________________________________________________________________________ */
/* Call ChemCop to run 'thor_getdat' module which executes 'get_data_from_cis.c' */
/* _____________________________________________________________________________ */
rc= (exec_sql("thor_getdat",wrnosmi_list));     /* TRIMrpc-remote procedure call */
printf(decode(rc,
           0,"rc=0: SMILES found in Thor",
         256,"rc=1: SMILES/WRNO/CAS not found in Thor",
         512,"rc=2: Server 'get_data_from_cis.c' failed to connect to ThorServer",
         768,"rc=3: Server 'get_data_from_cis.c' failed to open CIS Thor database",
        1024,"rc=4: Invalid parameters passed by client getchemdat.pl",
        1280,"rc=5: Server 'get_data_from_cis.c' failed to open temporary file",
        1536,"rc=6: Server 'get_data_from_cis.c' failed to generate USMILES",
             "Cannot interpret value '"^^rc^^"' Returned from chemcop"));

/* _____________________________________________________________________________ */
/*    Call ChemCop to run 'select f2000' procedure to open/return data file      */
/* _____________________________________________________________________________ */
if (rc == 0){
  temp_list= list_open("select results",1000);      /* name of chemcop procedure */
  if (list_rows(temp_list)==2){             /* row 0=SMILES; row1=delimited data */
    printf(list_curr(temp_list,0));                        /* assign SMILES      */
    list_next(temp_list);                                  /* move to data row   */
    for(i=1;i<=3;i++)                                      /* find pos of commas */
      c[i]= instr(list_curr(temp_list,0),",",1,i);
    printf(substr(list_curr(temp_list,0),1,c[1]-1));        /* parse/assign WRNO */
    printf(substr(list_curr(temp_list,0), c[1]+1, c[2]-c[1]-1));/*parse/assign MF*/
    printf(substr(list_curr(temp_list,0),c[2]+1,c[3]-c[2]-1)); /*parse/assign MW */
    printf(substr(list_curr(temp_list,0),c[3]+1));          /* parse/assign CAS  */
    }                                       /* end if (list_rows(temp_list)==2){ */
  else
    list_view(temp_list,0);                      /* show error msg from Daylight */
  }                                              /* end else if (rc == 0){       */
}