dparams.c File Reference

#include "../headers/dparams.h"

Go to the source code of this file.

Functions

s_dparamsinit_def_dparams (void)
s_dparamsget_dpocket_args (int nargs, char **args)
int add_list_complexes (char *str_list_file, s_dparams *par)
int add_complexe (char *complex, char *ligand, s_dparams *par)
int parse_dist_crit (char *str, s_dparams *p)
void print_dparams (s_dparams *p, FILE *f)
void print_dpocket_usage (FILE *f)
void free_dparams (s_dparams *p)


Function Documentation

int add_complexe ( char *  complex,
char *  ligand,
s_dparams par 
)

## FUNCTION: add_complexe

## SPECIFICATION: Add a set of data to the list of set of data in the parameters. this function is used for the tpocket program only.

The function will try to open the file, and data will be stored only if the file exists, and if the name of the ligand is valid.

## PARAMETERS: @ char *apo : The apo path @ char *complex : The complex path @ char *ligan : The ligand resname: a 4 letter (max!) @ s_dparams *par: The structure than contains parameters.

## RETURN: int: 1 if everything is OK, 0 if not.

Definition at line 301 of file dparams.c.

References s_dparams::fcomplex, fopen_pdb_check_case(), s_dparams::ligs, my_malloc(), my_realloc(), and s_dparams::nfiles.

Referenced by add_list_complexes().

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 }

int add_list_complexes ( char *  str_list_file,
s_dparams par 
)

## FUNCTION: add_list_complexes

## SPECIFICATION: Load a list of protein-ligand pdb file path. This file should have the following format:

complex_pdb_file ligand_code complex_pdb_file2 ligand_code2 complex_pdb_file3 ligand_code3 (...)

Each complexe-ligand set will be stored in the parameters structure.

## PARAMETRES: @ char *str_list_file : Path of the file containing all data @ s_dparams *par : Structures that stores all thoses files

## RETURN: int: Number of file read.

Definition at line 234 of file dparams.c.

References add_complexe(), M_MAX_PDB_NAME_LEN, and s_dparams::nfiles.

Referenced by get_dpocket_args().

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         /* Loading data. */
00246         f = fopen(str_list_file, "r") ;
00247 /*
00248         printf(str_list_file);
00249 */
00250         if(f) {
00251                 while(fgets(buf, 210, f)) {
00252 /*
00253                         printf("B: %s\n" , buf);
00254 */
00255                         n = par->nfiles ;
00256                         status = sscanf(buf, "%s\t%s", complexbuf, ligbuf) ;
00257 
00258                         if(status < 2) {
00259 /*
00260                                 fprintf(stderr, "! Skipping row '%s' with bad format (status %d).\n",
00261                                                                 buf, status) ;
00262 */
00263                         }
00264                         else {
00265 /*
00266                                 printf("%s %s\n", complexbuf, ligbuf );
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 }

void free_dparams ( s_dparams p  ) 

## FUNCTION: free_params

## SPECIFICATION: Free parameters

## PARAMETRES: @ s_dparams *p: Pointer to the structure to free

## RETURN: void

Definition at line 440 of file dparams.c.

References s_dparams::f_exp, s_dparams::f_fpcknp, s_dparams::f_fpckp, s_dparams::fcomplex, s_dparams::fpar, free_fparams(), s_dparams::ligs, and my_free().

Referenced by get_dpocket_args(), and main().

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 }

s_dparams* get_dpocket_args ( int  nargs,
char **  args 
)

## FUNCTION: get_dpocket_args

## SPECIFICATION: This function analyse the user's command line and parse it to store parameters for the descriptor calculator programm.

## PARAMETRES: @ int nargs : Number of arguments @ char **args : Arguments of main program

## RETURN: s_dparams*: Pointer to parameters

Definition at line 113 of file dparams.c.

References add_list_complexes(), s_dparams::f_exp, s_dparams::f_fpcknp, s_dparams::f_fpckp, s_dparams::fpar, free_dparams(), get_fpocket_args(), init_def_dparams(), s_dparams::interface_dist_crit, s_dparams::interface_method, is_fpocket_opt(), M_DPAR_DISTANCE_CRITERIA, M_DPAR_INPUT_FILE, M_DPAR_INTERFACE_METHOD1, M_DPAR_INTERFACE_METHOD2, M_DPAR_OUTPUT_FILE, M_INTERFACE_METHOD1, M_INTERFACE_METHOD2, M_LIG_NEIG_DIST, M_MAX_FILE_NAME_LENGTH, M_VERT_LIG_NEIG_DIST, parse_dist_crit(), print_dpocket_usage(), and remove_ext().

Referenced by main().

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         /* Read arguments by flags */
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                                         //  Check fpocket parameters!
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 }

s_dparams* init_def_dparams ( void   ) 

## GENERAL INFORMATION ## ## FILE dparams.c ## AUTHORS P. Schmidtke and V. Le Guilloux ## LAST MODIFIED 28-11-08 ## ## SPECIFICATIONS ## ## Handle parameters (parse the command line and sore values) ## for the dpocket programm. ## ## MODIFICATIONS HISTORY ## ## 28-11-08 (v) Comments UTD + relooking ## 27-11-08 (v) Minor Relooking ## 01-04-08 (v) Added comments and creation of history ## 01-01-08 (vp) Created (random date...) ## ## TODO or SUGGESTIONS ## ## (v) Check and update if necessary comments of each function!! ## (v) Review the main function and handle all possible crashes. ## COPYRIGHT DISCLAIMER

Vincent Le Guilloux, Peter Schmidtke and Pierre Tuffery, hereby disclaim all copyright interest in the program “fpocket” (which performs protein cavity detection) written by Vincent Le Guilloux and Peter Schmidtke.

Vincent Le Guilloux 28 November 2008 Peter Schmidtke 28 November 2008 Pierre Tuffery 28 November 2008

GNU GPL

This file is part of the fpocket package.

fpocket is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

fpocket is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with fpocket. If not, see <http://www.gnu.org/licenses/>. ## FUNCTION: init_def_dparams

## SPECIFICATION: Initialisation of default parameters.

## PARAMETRES: void

## RETURN: s_dparams*: Pointer to allocated paramers.

Definition at line 76 of file dparams.c.

References s_dparams::f_exp, s_dparams::f_fpcknp, s_dparams::f_fpckp, s_dparams::fcomplex, s_dparams::interface_dist_crit, s_dparams::interface_method, s_dparams::ligs, M_INTERFACE_METHOD1, M_MAX_FILE_NAME_LENGTH, M_OUTPUT_FILE1_DEFAULT, M_OUTPUT_FILE2_DEFAULT, M_OUTPUT_FILE3_DEFAULT, M_VERT_LIG_NEIG_DIST, my_malloc(), and s_dparams::nfiles.

Referenced by get_dpocket_args().

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 }

int parse_dist_crit ( char *  str,
s_dparams p 
)

## FUNCTION: parse_dist_crit

## SPECIFICATION: Parsing function for the distance criteria defining the protein-ligand interface.

## PARAMETERS: @ char *str : The string to parse @ s_dparams *p : The structure than will contain the parsed parameter

## RETURN: 0 if the parameter is valid (here a valid integer), 1 if not

Definition at line 356 of file dparams.c.

References s_dparams::interface_dist_crit, M_NO_SIGN, and str_is_float().

Referenced by get_dpocket_args().

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 }

void print_dparams ( s_dparams p,
FILE *  f 
)

## FUNCTION: print_dparams

## SPECIFICATION: Print function, usefull to debug

## PARAMETRES: @ s_dparams *p : The structure than will contain the parsed parameter @ FILE *f : The file to write in

## RETURN: void

Definition at line 384 of file dparams.c.

References s_dparams::fcomplex, s_dparams::interface_dist_crit, s_dparams::interface_method, s_dparams::ligs, M_INTERFACE_METHOD1, and s_dparams::nfiles.

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 }

void print_dpocket_usage ( FILE *  f  ) 

## FUNCTION: print_dparams_usage

## SPECIFICATION: Displaying usage of the programm in the given buffer

## PARAMETRES: @ FILE *f: buffer to print in

## RETURN:

Definition at line 419 of file dparams.c.

References M_DP_USAGE.

Referenced by get_dpocket_args().

00420 {
00421         f = (f == NULL) ? stdout:f ;
00422 
00423         fprintf(f, M_DP_USAGE) ;
00424 }


Generated on Mon Jun 7 16:44:23 2010 for fpocket by  doxygen 1.5.6