00001
00002 #include "../headers/fparams.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 s_fparams* init_def_fparams(void)
00049 {
00050 s_fparams *par = (s_fparams *) my_malloc(sizeof(s_fparams)) ;
00051
00052 par->min_apol_neigh = M__MIN_APOL_NEIGH_DEFAULT ;
00053 par->asph_min_size = M_MIN_ASHAPE_SIZE_DEFAULT ;
00054 par->asph_max_size = M_MAX_ASHAPE_SIZE_DEFAULT ;
00055 par->sl_clust_max_dist = M_SLCLUST_MAX_DIST ;
00056 par->sl_clust_min_nneigh = M_SLCLUST_MIN_NUM_NEIGH ;
00057 par->pdb_path[0] = 0 ;
00058 par->basic_volume_div = M_BASIC_VOL_DIVISION ;
00059 par->nb_mcv_iter = M_MC_ITER ;
00060 par->min_pock_nb_asph = M_MIN_POCK_NB_ASPH ;
00061 par->refine_clust_dist = M_REFINE_DIST ;
00062 par->refine_min_apolar_asphere_prop = M_REFINE_MIN_PROP_APOL_AS ;
00063 par->clust_max_dist = M_CLUST_MAX_DIST ;
00064 par->npdb = 0 ;
00065 par->pdb_lst = NULL ;
00066 par->flag_do_asa_and_volume_calculations=1;
00067 par->db_run=M_DB_RUN;
00068
00069 return par ;
00070 }
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088 s_fparams* get_fpocket_args(int nargs, char **args)
00089 {
00090 int i,
00091 npdb = 0,
00092 status = 0 ;
00093
00094 s_fparams *par = init_def_fparams() ;
00095 char *pdb_lst = NULL ;
00096
00097
00098 for (i = 1; i < nargs; i++) {
00099 if (strlen(args[i]) == 2 && args[i][0] == '-' && i <= (nargs-1)) {
00100
00101 switch (args[i][1]) {
00102 case M_PAR_MAX_ASHAPE_SIZE :
00103 status += parse_asph_max_size(args[++i], par) ; break ;
00104 case M_PAR_MIN_ASHAPE_SIZE :
00105 status += parse_asph_min_size(args[++i], par) ; break ;
00106 case M_PAR_MIN_APOL_NEIGH :
00107 status += parse_min_apol_neigh(args[++i], par) ; break ;
00108 case M_PAR_CLUST_MAX_DIST :
00109 status += parse_clust_max_dist(args[++i], par) ; break ;
00110 case M_PAR_SL_MAX_DIST :
00111 status += parse_sclust_max_dist(args[++i], par) ; break ;
00112 case M_PAR_SL_MIN_NUM_NEIGH :
00113 status += parse_sclust_min_nneigh(args[++i], par) ; break ;
00114 case M_PAR_MC_ITER :
00115 status += parse_mc_niter(args[++i], par) ; break ;
00116 case M_PAR_BASIC_VOL_DIVISION :
00117 status += parse_basic_vol_div(args[++i], par) ; break ;
00118 case M_PAR_MIN_POCK_NB_ASPH :
00119 status += parse_min_pock_nb_asph(args[++i], par) ; break ;
00120 case M_PAR_REFINE_DIST :
00121 status += parse_refine_dist(args[++i], par) ; break ;
00122 case M_PAR_REFINE_MIN_NAPOL_AS:
00123 status += parse_refine_minaap(args[++i], par) ;
00124 break ;
00125 case M_PAR_DB_RUN :
00126 par->db_run=1;
00127 break;
00128
00129 case M_PAR_PDB_LIST :
00130 pdb_lst = args[++i] ;
00131 break ;
00132
00133 case M_PAR_PDB_FILE :
00134 if(npdb >= 1) fprintf(stderr,
00135 "! Only first input pdb will be used.\n") ;
00136 else {
00137 strcpy(par->pdb_path, args[++i]) ; npdb++ ;
00138 }
00139 break ;
00140 default: break ;
00141 }
00142 }
00143 }
00144
00145 if(status > 0) {
00146 free_fparams(par) ;
00147 print_pocket_usage(stdout);
00148 return NULL ;
00149 }
00150
00151 par->npdb = npdb ;
00152
00153
00154 if(pdb_lst != NULL) {
00155 FILE *f = fopen(pdb_lst, "r") ;
00156 if(f != NULL) {
00157
00158 int n = 0 ;
00159 char cline [M_MAX_PDB_NAME_LEN + 1] ;
00160
00161 while(fgets(cline, M_MAX_PDB_NAME_LEN, f) != NULL) {
00162 if(strcmp("\n", cline) != 0) {
00163 n ++ ;
00164 }
00165 }
00166 fclose(f) ;
00167 if(n == 0) {
00168 return par ;
00169 }
00170
00171
00172 par->pdb_lst = (char **)my_malloc(n*sizeof(char*)) ;
00173
00174 f = fopen (pdb_lst, "r") ;
00175 int i = 0, l = 0 ;
00176 char *line;
00177 while(fgets(cline, M_MAX_PDB_NAME_LEN, f) != NULL) {
00178 if(strcmp("\n", cline) != 0) {
00179 l = strlen(cline) ;
00180 if(cline[l-1] == '\n') {
00181 l-- ;
00182 cline[l] = '\0' ;
00183 }
00184 line = (char *) my_malloc((l+1)*sizeof(char)) ;
00185 memcpy (line, cline, l+1);
00186
00187 par->pdb_lst[i] = line ;
00188 i ++ ;
00189 }
00190 }
00191
00192 par->npdb = n ;
00193 }
00194 }
00195
00196 return par;
00197 }
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214 int parse_clust_max_dist(char *str, s_fparams *p)
00215 {
00216 if(str_is_float(str, M_NO_SIGN)) {
00217 p->clust_max_dist = atof(str) ;
00218 }
00219 else {
00220 fprintf(stdout, "! Invalid value (%s) given for the single linkage max dist.\n", str) ;
00221 return 1 ;
00222 }
00223
00224 return 0 ;
00225 }
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243 int parse_sclust_max_dist(char *str, s_fparams *p)
00244 {
00245 if(str_is_float(str, M_NO_SIGN)) {
00246 p->sl_clust_max_dist = atof(str) ;
00247 }
00248 else {
00249 fprintf(stdout, "! Invalid value (%s) given for the single linkage max dist.\n", str) ;
00250 return 1 ;
00251 }
00252
00253 return 0 ;
00254 }
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271 int parse_sclust_min_nneigh(char *str, s_fparams *p)
00272 {
00273 if(str_is_number(str, M_NO_SIGN)) {
00274 p->sl_clust_min_nneigh = atoi(str) ;
00275 }
00276 else {
00277 fprintf(stdout, "! Invalid value (%s) given for the single linkage max dist.\n", str) ;
00278 return 1 ;
00279 }
00280
00281 return 0 ;
00282 }
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300 int parse_min_apol_neigh(char *str, s_fparams *p)
00301 {
00302 if(str_is_number(str, M_NO_SIGN)) {
00303 p->min_apol_neigh = (int) atoi(str) ;
00304 if(p->min_apol_neigh < 0) p->min_apol_neigh = 0 ;
00305 if(p->min_apol_neigh > 4) p->min_apol_neigh = 4 ;
00306 }
00307 else {
00308 fprintf(stdout, "! Invalid value (%s) given for the min radius of alpha shperes.\n", str) ;
00309 return 1 ;
00310 }
00311
00312 return 0 ;
00313 }
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330 int parse_asph_min_size(char *str, s_fparams *p)
00331 {
00332 if(str_is_float(str, M_NO_SIGN)) {
00333 p->asph_min_size = (float) atof(str) ;
00334 }
00335 else {
00336 fprintf(stdout, "! Invalid value (%s) given for the min radius of alpha shperes.\n", str) ;
00337 return 1 ;
00338 }
00339
00340 return 0 ;
00341 }
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358 int parse_asph_max_size(char *str, s_fparams *p)
00359 {
00360 if(str_is_float(str, M_NO_SIGN)) {
00361 p->asph_max_size = (float) atof(str) ;
00362 }
00363 else {
00364 fprintf(stdout, "! Invalid value (%s) given for the max radius of alpha shperes.\n", str) ;
00365 return 1 ;
00366 }
00367
00368 return 0 ;
00369 }
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387 int parse_mc_niter(char *str, s_fparams *p)
00388 {
00389 if(str_is_float(str, M_NO_SIGN)) {
00390 p->nb_mcv_iter = (int) atoi(str) ;
00391 }
00392 else {
00393 fprintf(stdout, "! Invalid value (%s) given for the number of monte-carlo iteration for the volume.\n", str) ;
00394 return 1 ;
00395 }
00396
00397 return 0 ;
00398 }
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415 int parse_basic_vol_div(char *str, s_fparams *p)
00416 {
00417 if(str_is_number(str, M_NO_SIGN)) {
00418 p->basic_volume_div = (int) atoi(str) ;
00419 }
00420 else {
00421 fprintf(stdout, "! Invalid value (%s) given for the precision of the basic volume calculation.\n", str) ;
00422 return 1 ;
00423 }
00424
00425 return 0 ;
00426 }
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443 int parse_refine_dist(char *str, s_fparams *p)
00444 {
00445 if(str_is_float(str, M_NO_SIGN)) {
00446 p->refine_clust_dist = (float) atof(str) ;
00447 }
00448 else {
00449 fprintf(stdout, "! Invalid value (%s) given for the refine distance.\n", str) ;
00450 return 1 ;
00451 }
00452
00453 return 0 ;
00454 }
00455
00456
00457
00458
00459
00460
00461
00462
00463
00464
00465
00466
00467
00468
00469
00470
00471 int parse_refine_minaap(char *str, s_fparams *p)
00472 {
00473 if(str_is_float(str, M_NO_SIGN)) {
00474 p->refine_min_apolar_asphere_prop = (float) atof(str) ;
00475 }
00476 else {
00477 fprintf(stdout, "! Invalid value (%s) given for the refine distance.\n", str) ;
00478 return 1 ;
00479 }
00480
00481 return 0 ;
00482 }
00483
00484
00485
00486
00487
00488
00489
00490
00491
00492
00493
00494
00495
00496
00497
00498
00499 int parse_min_pock_nb_asph(char *str, s_fparams *p)
00500 {
00501 if(str_is_number(str, M_NO_SIGN)) {
00502 p->min_pock_nb_asph = (int) atoi(str) ;
00503 }
00504 else {
00505 fprintf(stdout, "! Invalid value (%s) given for the refine distance.\n", str) ;
00506 return 1 ;
00507 }
00508
00509 return 0 ;
00510 }
00511
00512
00513
00514
00515
00516
00517
00518
00519
00520
00521
00522
00523
00524
00525
00526
00527
00528
00529 int is_fpocket_opt(const char opt)
00530 {
00531 if( opt == M_PAR_MAX_ASHAPE_SIZE ||
00532 opt == M_PAR_MIN_ASHAPE_SIZE ||
00533 opt == M_PAR_MIN_APOL_NEIGH ||
00534 opt == M_PAR_CLUST_MAX_DIST ||
00535 opt == M_PAR_SL_MAX_DIST ||
00536 opt == M_PAR_SL_MIN_NUM_NEIGH ||
00537 opt == M_PAR_MC_ITER ||
00538 opt == M_PAR_BASIC_VOL_DIVISION ||
00539 opt == M_PAR_MIN_POCK_NB_ASPH ||
00540 opt == M_PAR_REFINE_DIST ||
00541 opt == M_PAR_REFINE_MIN_NAPOL_AS) {
00542 return 1 ;
00543 }
00544
00545 return 0 ;
00546 }
00547
00548
00549
00550
00551
00552
00553
00554
00555
00556
00557
00558
00559
00560
00561
00562 void free_fparams(s_fparams *p)
00563 {
00564 int i ;
00565 if(p) {
00566 if(p->npdb > 0 && p->pdb_lst != NULL) {
00567 for (i = 0 ; i < p->npdb ; i++) {
00568 if(p->pdb_lst[i] != NULL) my_free(p->pdb_lst[i]) ;
00569 }
00570 my_free(p->pdb_lst) ;
00571 }
00572 my_free(p) ;
00573 }
00574 }
00575
00576
00577
00578
00579
00580
00581
00582
00583
00584
00585
00586
00587
00588
00589
00590 void print_pocket_usage(FILE *f)
00591 {
00592 f = (f == NULL) ? stdout:f ;
00593
00594 fprintf(f, M_FP_USAGE) ;
00595 }
00596
00597
00598
00599
00600
00601
00602
00603
00604
00605
00606
00607
00608
00609
00610
00611 void print_fparams(s_fparams *p, FILE *f)
00612 {
00613 if(p) {
00614 fprintf(f, "==============\nParameters of fpocket: \n");
00615 fprintf(f, "> Minimum alpha sphere radius: %f\n", p->asph_min_size);
00616 fprintf(f, "> Maximum alpha sphere radius: %f\n", p->asph_max_size);
00617 fprintf(f, "> Minimum number of apolar neighbor: %d\n", p->min_apol_neigh);
00618 fprintf(f, "> Maximum distance for first clustering algorithm: %f \n", p->clust_max_dist) ;
00619 fprintf(f, "> Single linkage clustering distance: %f\n", p->sl_clust_max_dist);
00620 fprintf(f, "> Single linkage clustering neighbor: %d\n", p->sl_clust_min_nneigh);
00621 fprintf(f, "> Refine clustering distance: %f\n", p->refine_clust_dist);
00622 fprintf(f, "> Min number of apolar sphere in refine to keep a pocket: %f\n", p->refine_min_apolar_asphere_prop) ;
00623 fprintf(f, "> Monte carlo iterations: %d\n", p->nb_mcv_iter);
00624 fprintf(f, "> Basic method for volume calculation: %d\n", p->basic_volume_div);
00625 fprintf(f, "> PDB file: %s\n", p->pdb_path);
00626 fprintf(f, "==============\n");
00627 }
00628 else fprintf(f, "> No parameters detected\n");
00629 }
00630