00001
00002 #include "../headers/tparams.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 s_tparams* init_def_tparams(void)
00076 {
00077 s_tparams *par = (s_tparams *)my_malloc(sizeof(s_tparams)) ;
00078 par->p_output = (char *)my_malloc(M_MAX_FILE_NAME_LENGTH*sizeof(char)) ;
00079 strcpy(par->p_output, M_STATS_OUTP) ;
00080 par->g_output = (char *)my_malloc(M_MAX_FILE_NAME_LENGTH*sizeof(char)) ;
00081 strcpy(par->g_output, M_STATS_OUTG) ;
00082 par->fapo = NULL ;
00083 par->fcomplex = NULL ;
00084 par->fligan = NULL ;
00085 par->nfiles = 0 ;
00086 par->keep_fpout = 0 ;
00087 par->lig_neigh_dist = M_LIG_NEIG_DIST ;
00088
00089 return par ;
00090 }
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108 s_tparams* get_tpocket_args(int nargs, char **args)
00109 {
00110 int i,
00111 status = 0 ;
00112
00113 int nstats = 0;
00114
00115 char *str_lig = NULL,
00116 *str_complex_file = NULL,
00117 *str_apo_file = NULL,
00118 *str_list_file = NULL ;
00119
00120 s_tparams *par = init_def_tparams() ;
00121 par->fpar = get_fpocket_args(nargs, args) ;
00122
00123 if(!par->fpar) {
00124 free_tparams(par) ;
00125 print_test_usage(stdout);
00126
00127 return NULL ;
00128 }
00129
00130
00131 for (i = 1; i < nargs; i++) {
00132 if (strlen(args[i]) == 2 && args[i][0] == '-' &&
00133 (i < (nargs-1) || args[i][1] == M_PAR_KEEP_FP_OUTPUT) ) {
00134 switch (args[i][1]) {
00135 case M_PAR_LIG_NEIG_DIST :
00136 status += parse_lig_neigh_dist(args[++i], par) ;
00137 break ;
00138 case M_PAR_KEEP_FP_OUTPUT :
00139 par->keep_fpout = 1 ;
00140 break ;
00141
00142 case M_PAR_P_STATS_OUT :
00143 if(nstats >= 1) fprintf(stdout, "! More than one single file for the stats output file has been given. Ignoring this one.\n") ;
00144 else {
00145 if(i < nargs-1) {
00146 if(strlen(args[++i]) < M_MAX_FILE_NAME_LENGTH) strcpy(par->p_output, args[i]) ;
00147 else fprintf(stdout, "! Output file name is too long... Keeping default (%s).", M_STATS_OUTP) ;
00148 }
00149 else {
00150 fprintf(stdout, "! Invalid output file name argument missing.\n") ;
00151 status += 1 ;
00152 }
00153 }
00154 break ;
00155 case M_PAR_G_STATS_OUT :
00156 if(nstats >= 1) fprintf(stdout, "! More than one single file for the stats output file has been given. Ignoring this one.\n") ;
00157 else {
00158 if(i < nargs-1) {
00159 if(strlen(args[++i]) < M_MAX_FILE_NAME_LENGTH) strcpy(par->g_output, args[i]) ;
00160 else fprintf(stdout, "! Output file name is too long... Keeping default (%s).", M_STATS_OUTG) ;
00161 }
00162 else {
00163 fprintf(stdout, "! Invalid output file name argument missing.\n") ;
00164 status += 1 ;
00165 }
00166 }
00167 break ;
00168 case M_PAR_VALID_INPUT_FILE : str_list_file = args[++i] ; break ;
00169 default:
00170
00171 if(!is_fpocket_opt(args[i][1])) {
00172 fprintf(stdout, "> Unknown option '%s'. Ignoring it.\n",
00173 args[i]) ;
00174 }
00175 break ;
00176 }
00177 }
00178 }
00179
00180 if(status > 0) {
00181 free_tparams(par) ;
00182 par = NULL ;
00183 print_test_usage(stdout);
00184 }
00185 else {
00186 if(str_list_file) {
00187 int res = add_list_data(str_list_file, par) ;
00188 if(res <= 0) {
00189 fprintf(stderr, "! No data has been read.\n") ;
00190 free_tparams(par) ;
00191 par = NULL ;
00192 print_test_usage(stdout);
00193 }
00194 else {
00195 strcpy (par->stats_g, M_STATS_OUTG) ;
00196 strcpy (par->stats_p, M_STATS_OUTP) ;
00197
00198 }
00199 }
00200 else {
00201 if(str_lig && str_apo_file && str_complex_file) {
00202 if(add_prot(str_apo_file, str_complex_file, str_lig, par) == 0){
00203 fprintf(stderr, "! No data has been read.\n") ;
00204 free_tparams(par) ;
00205 par = NULL ;
00206 print_test_usage(stdout);
00207 }
00208 else {
00209 strcpy (par->stats_g, M_STATS_OUTG) ;
00210 strcpy (par->stats_p, M_STATS_OUTP) ;
00211
00212 }
00213 }
00214 else {
00215 fprintf(stdout, "! Argument is missing! \n");
00216 free_tparams(par) ;
00217 par = NULL ;
00218 print_test_usage(stdout) ;
00219 }
00220 }
00221 }
00222
00223 return par;
00224 }
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243 int add_list_data(char *str_list_file, s_tparams *par)
00244 {
00245 FILE *f;
00246 int n,
00247 nread = 0,
00248 status ;
00249
00250 char buf[M_MAX_PDB_NAME_LEN*2 + 6],
00251 apobuf[M_MAX_PDB_NAME_LEN],
00252 complexbuf[M_MAX_PDB_NAME_LEN],
00253 ligbuf[5];
00254
00255
00256 f = fopen(str_list_file, "r") ;
00257 if(f) {
00258 while(fgets(buf, 210, f)) {
00259 n = par->nfiles ;
00260 status = sscanf(buf, "%s\t%s\t%s", apobuf, complexbuf, ligbuf) ;
00261
00262 if(strlen(ligbuf) == 1) {
00263 ligbuf [2] = ligbuf[0] ;
00264 ligbuf [0] = ' ' ;
00265 ligbuf [1] = ' ' ;
00266 }
00267
00268 if(status < 3) {
00269 fprintf(stderr, "! Skipping row '%s' with bad format (status %d).\n", buf, status) ;
00270 }
00271 else {
00272 nread += add_prot(apobuf, complexbuf, ligbuf, par) ;
00273 }
00274 }
00275 }
00276 else {
00277 fprintf(stderr, "! File %s doesn't exists\n", str_list_file) ;
00278 }
00279
00280
00281
00282 return nread ;
00283 }
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306 int add_prot(char *apo, char *complex, char *ligan, s_tparams *par)
00307 {
00308 FILE *f = fopen_pdb_check_case(apo, "r") ;
00309 int nm1, l, i ;
00310 if(f) {
00311 fclose(f) ;
00312 f = fopen_pdb_check_case(complex, "r") ;
00313 if(f) {
00314 l = strlen(ligan) ;
00315 if(ligan && l >= 1) {
00316
00317 for(i = 0 ; i < l ; i++) ligan[i] = toupper(ligan[i]) ;
00318
00319 nm1 = par->nfiles ;
00320 par->nfiles += 1 ;
00321 par->fapo = (char**) my_realloc(par->fapo, (par->nfiles)*sizeof(char*)) ;
00322 par->fligan = (char**) my_realloc(par->fligan, (par->nfiles)*sizeof(char*)) ;
00323 par->fcomplex = (char**) my_realloc(par->fcomplex, (par->nfiles)*sizeof(char*)) ;
00324
00325 par->fapo[nm1] = (char *)my_malloc((strlen(apo)+1)*sizeof(char)) ;
00326 par->fcomplex[nm1] = (char *)my_malloc((strlen(complex)+1)*sizeof(char)) ;
00327 par->fligan[nm1] = (char *)my_malloc((strlen(ligan)+1)*sizeof(char)) ;
00328
00329 strcpy(par->fapo[nm1], apo) ;
00330 strcpy(par->fcomplex[nm1], complex) ;
00331 strcpy(par->fligan[nm1], ligan) ;
00332
00333 fclose(f) ;
00334 }
00335 else {
00336 fprintf(stdout, "! The name given for the ligand is invalid or absent.\n") ;
00337 return 0 ;
00338 }
00339
00340 }
00341 else {
00342 fprintf(stdout, "! The pdb complexe file '%s' doesn't exists.\n", complex) ;
00343 return 0 ;
00344 }
00345 }
00346 else {
00347
00348 fprintf(stdout, "! The pdb apo file '%s' doesn't exists.\n", apo) ;
00349 return 0 ;
00350 }
00351
00352 return 1 ;
00353 }
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370 int parse_lig_neigh_dist(char *str, s_tparams *p)
00371 {
00372 if(str_is_float(str, M_NO_SIGN)) {
00373 p->lig_neigh_dist = atof(str) ;
00374 }
00375 else {
00376 fprintf(stdout, "! Invalid value (%s) given for distance criteria to define interface atoms.\n", str) ;
00377 return 1 ;
00378 }
00379
00380 return 0 ;
00381 }
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397 void free_tparams(s_tparams *p)
00398 {
00399 if(p) {
00400 if(p->fapo) {
00401 my_free(p->fapo) ;
00402 p->fapo = NULL ;
00403 }
00404
00405 if(p->fligan) {
00406 my_free(p->fligan) ;
00407 p->fligan = NULL ;
00408 }
00409
00410 if(p->fcomplex) {
00411 my_free(p->fcomplex) ;
00412 p->fcomplex = NULL ;
00413 }
00414
00415 if(p->fpar) {
00416 free_fparams(p->fpar) ;
00417 p->fpar = NULL ;
00418 }
00419
00420 my_free(p) ;
00421 }
00422 }
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438 void print_test_usage(FILE *f)
00439 {
00440 f = (f == NULL) ? stdout:f ;
00441 fprintf(f, M_TP_USAGE) ;
00442 }
00443
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457
00458 void print_params(s_tparams *p, FILE *f)
00459 {
00460
00461 if(p) {
00462 fprintf(f, "==============\nParameters of the program: \n");
00463 int i ;
00464 for(i = 0 ; i < p->nfiles ; i++) {
00465 fprintf(f, "> Protein %d: '%s', '%s', '%s'\n", i+1, p->fapo[i], p->fcomplex[i], p->fligan[i]) ;
00466 }
00467 fprintf(f, "> Minimum alpha sphere radius: %f\n", p->fpar->asph_min_size);
00468 fprintf(f, "> Maximum alpha sphere radius: %f\n", p->fpar->asph_max_size);
00469 fprintf(f, "> Minimum number of apolar neighbor: %d\n", p->fpar->min_apol_neigh);
00470 fprintf(f, "> Maximum distance for first clustering algorithm: %f \n", p->fpar->clust_max_dist) ;
00471 fprintf(f, "> Single linkage clustering distance: %f\n", p->fpar->sl_clust_max_dist);
00472 fprintf(f, "> Single linkage clustering neighbor: %d\n", p->fpar->sl_clust_min_nneigh);
00473 fprintf(f, "> Refine clustering distance: %f\n", p->fpar->refine_clust_dist);
00474 fprintf(f, "> Min number of apolar sphere in refine to keep a pocket: %f\n", p->fpar->refine_min_apolar_asphere_prop) ;
00475 fprintf(f, "> Monte carlo iterations: %d\n", p->fpar->nb_mcv_iter);
00476 fprintf(f, "> Basic method for volume calculation: %d\n", p->fpar->basic_volume_div);
00477 fprintf(f, "==============\n");
00478 }
00479 else fprintf(f, "> No parameters detected\n");
00480 }