00001
00002 #include "../headers/dparams.h"
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076 s_dparams* init_def_dparams(void)
00077 {
00078 s_dparams *par = (s_dparams*) my_malloc(sizeof(s_dparams)) ;
00079
00080 par->f_exp = (char *)my_malloc(M_MAX_FILE_NAME_LENGTH*sizeof(char)) ;
00081 par->f_fpckp = (char *)my_malloc(M_MAX_FILE_NAME_LENGTH*sizeof(char)) ;
00082 par->f_fpcknp = (char *)my_malloc(M_MAX_FILE_NAME_LENGTH*sizeof(char)) ;
00083
00084 strcpy(par->f_exp, M_OUTPUT_FILE1_DEFAULT) ;
00085 strcpy(par->f_fpckp, M_OUTPUT_FILE2_DEFAULT) ;
00086 strcpy(par->f_fpcknp, M_OUTPUT_FILE3_DEFAULT) ;
00087
00088 par->fcomplex = NULL ;
00089 par->ligs = NULL ;
00090 par->nfiles = 0 ;
00091 par->interface_dist_crit = M_VERT_LIG_NEIG_DIST ;
00092 par->interface_method = M_INTERFACE_METHOD1 ;
00093
00094 return par ;
00095 }
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113 s_dparams* get_dpocket_args(int nargs, char **args)
00114 {
00115 int i,
00116 status = 0,
00117 nstats = 0,
00118 res;
00119
00120 char *str_list_file = NULL ;
00121
00122 s_dparams *par = init_def_dparams() ;
00123 par->fpar = get_fpocket_args(nargs, args) ;
00124
00125
00126 for (i = 1; i < nargs; i++) {
00127 if (strlen(args[i]) == 2 && args[i][0] == '-') {
00128 switch (args[i][1]) {
00129 case M_DPAR_DISTANCE_CRITERIA :
00130 if(i < nargs-1) status += parse_dist_crit(args[++i], par) ;
00131 else {
00132 fprintf(stdout, "! Distance criteria defining the protein-ligand interface is missing.\n") ;
00133 status += 1 ;
00134 }
00135 break ;
00136
00137 case M_DPAR_INTERFACE_METHOD1 :
00138 par->interface_method = M_INTERFACE_METHOD1 ;
00139 par->interface_dist_crit = M_VERT_LIG_NEIG_DIST ;
00140 break ;
00141
00142 case M_DPAR_INTERFACE_METHOD2 :
00143 par->interface_method = M_INTERFACE_METHOD2 ;
00144 par->interface_dist_crit = M_LIG_NEIG_DIST ;
00145 break ;
00146
00147 case M_DPAR_OUTPUT_FILE :
00148 if(nstats >= 1) fprintf(stdout, "! More than one single file for the stats output file has been given. Ignoring this one.\n") ;
00149 else {
00150 if(i < nargs-1) {
00151 if(strlen(args[++i]) < M_MAX_FILE_NAME_LENGTH) {
00152 remove_ext(args[i]) ;
00153 sprintf(par->f_exp, "%s_exp.txt", args[i]) ;
00154 sprintf(par->f_fpckp, "%s_fp.txt", args[i]) ;
00155 sprintf(par->f_fpcknp, "%s_fpn.txt", args[i]) ;
00156 }
00157 else fprintf(stdout, "! Output file name is too long... Keeping default.") ;
00158 }
00159 else {
00160 fprintf(stdout, "! Invalid output file name argument missing.\n") ;
00161 status += 1 ;
00162 }
00163 }
00164 break ;
00165
00166 case M_DPAR_INPUT_FILE :
00167 if(i < nargs-1) str_list_file = args[++i] ;
00168 else {
00169 fprintf(stdout, "! Input file name argument missing.\n") ;
00170 status += 1 ;
00171 }
00172 break ;
00173
00174 default:
00175
00176 if(!is_fpocket_opt(args[i][1])) {
00177 fprintf(stdout, "> Unknown option '%s'. Ignoring it.\n",
00178 args[i]) ;
00179 }
00180 break ;
00181 }
00182 }
00183 }
00184
00185 if(status > 0) {
00186 free_dparams(par) ;
00187 par = NULL ;
00188 print_dpocket_usage(stdout);
00189 }
00190 else {
00191 if(str_list_file) {
00192 res = add_list_complexes(str_list_file, par) ;
00193 if(res <= 0) {
00194 fprintf(stdout, "! No data has been read.\n") ;
00195 free_dparams(par) ;
00196 par = NULL ;
00197 print_dpocket_usage(stdout);
00198 }
00199 }
00200 else {
00201 fprintf(stdout, "! No input file given... Try again :).\n") ;
00202 free_dparams(par) ;
00203 par = NULL ;
00204 print_dpocket_usage(stdout);
00205 }
00206 }
00207
00208 return par;
00209 }
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234 int add_list_complexes(char *str_list_file, s_dparams *par)
00235 {
00236 FILE *f;
00237 int n,
00238 nread = 0,
00239 status ;
00240
00241 char buf[M_MAX_PDB_NAME_LEN*2 + 6],
00242 complexbuf[M_MAX_PDB_NAME_LEN],
00243 ligbuf[5];
00244
00245
00246 f = fopen(str_list_file, "r") ;
00247
00248
00249
00250 if(f) {
00251 while(fgets(buf, 210, f)) {
00252
00253
00254
00255 n = par->nfiles ;
00256 status = sscanf(buf, "%s\t%s", complexbuf, ligbuf) ;
00257
00258 if(status < 2) {
00259
00260
00261
00262
00263 }
00264 else {
00265
00266
00267
00268 nread += add_complexe(complexbuf, ligbuf, par) ;
00269 }
00270
00271 }
00272 }
00273 else {
00274 fprintf(stderr, "! File %s doesn't exists\n", str_list_file) ;
00275 }
00276
00277 return nread ;
00278 }
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301 int add_complexe(char *complex, char *ligand, s_dparams *par)
00302 {
00303 int nm1, i, l ;
00304
00305 FILE *f = fopen_pdb_check_case(complex, "r") ;
00306 if(f) {
00307 l = strlen(ligand) ;
00308 if(strlen(ligand) >= 2) {
00309 for(i = 0 ; i < l ; i++) ligand[i] = toupper(ligand[i]) ;
00310
00311 nm1 = par->nfiles ;
00312 par->nfiles += 1 ;
00313
00314 par->ligs = (char**) my_realloc(par->ligs, (par->nfiles)*sizeof(char*)) ;
00315 par->fcomplex = (char**) my_realloc(par->fcomplex, (par->nfiles)*sizeof(char*)) ;
00316
00317 par->fcomplex[nm1] = (char *)my_malloc((strlen(complex)+1)*sizeof(char)) ;
00318 par->ligs[nm1] = (char *)my_malloc((strlen(ligand)+1)*sizeof(char)) ;
00319
00320 strcpy(par->fcomplex[nm1], complex) ;
00321 strcpy(par->ligs[nm1], ligand) ;
00322
00323 fclose(f) ;
00324 }
00325 else {
00326 fprintf(stdout, "! The name given for the ligand is invalid or absent.\n") ;
00327 fclose(f) ;
00328 return 0 ;
00329 }
00330
00331 }
00332 else {
00333 fprintf(stdout, "! The pdb file '%s' doesn't exists.\n", complex) ;
00334 return 0 ;
00335 }
00336
00337 return 1 ;
00338 }
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356 int parse_dist_crit(char *str, s_dparams *p)
00357 {
00358 if(str_is_float(str, M_NO_SIGN)) {
00359 p->interface_dist_crit = (float) atof(str) ;
00360 }
00361 else {
00362 fprintf(stdout, "! Invalid value (%s) given for the distance criteria defining the protein-ligand interface.\n", str) ;
00363 return 1 ;
00364 }
00365
00366 return 0 ;
00367 }
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384 void print_dparams(s_dparams *p, FILE *f)
00385 {
00386
00387 if(p) {
00388 fprintf(f, "==============\nParameters of the program: \n");
00389 int i ;
00390 for(i = 0 ; i < p->nfiles ; i++) {
00391 fprintf(f, "> Protein %d: '%s', '%s'\n", i+1, p->fcomplex[i], p->ligs[i]) ;
00392 }
00393
00394 if(p->interface_method == M_INTERFACE_METHOD1)
00395 fprintf(f, "> Method used to define explicitely the interface atoms: contacted atom by alpha spheres.\n") ;
00396 else fprintf(f, "> Method used to define explicitely the interface atoms: ligand's neighbors.\n") ;
00397
00398 fprintf(f, "> Distance used to define explicitely the interface: %f.\n",
00399 p->interface_dist_crit) ;
00400
00401 fprintf(f, "==============\n");
00402 }
00403 else fprintf(f, "> No parameters detected\n");
00404 }
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419 void print_dpocket_usage(FILE *f)
00420 {
00421 f = (f == NULL) ? stdout:f ;
00422
00423 fprintf(f, M_DP_USAGE) ;
00424 }
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440 void free_dparams(s_dparams *p)
00441 {
00442 if(p) {
00443 if(p->ligs) {
00444 my_free(p->ligs) ;
00445 p->ligs = NULL ;
00446 }
00447
00448 if(p->fcomplex) {
00449 my_free(p->fcomplex) ;
00450 p->fcomplex = NULL ;
00451 }
00452
00453 if(p->f_exp) {
00454 my_free(p->f_exp) ;
00455 p->f_exp = NULL ;
00456 }
00457
00458 if(p->f_fpckp) {
00459 my_free(p->f_fpckp) ;
00460 p->f_fpckp = NULL ;
00461 }
00462
00463 if(p->f_fpcknp) {
00464 my_free(p->f_fpcknp) ;
00465 p->f_fpcknp = NULL ;
00466 }
00467
00468 free_fparams(p->fpar) ;
00469
00470 my_free(p) ;
00471 }
00472 }