2 Last changed Time-stamp: <2010-06-24 17:15:16 ivo>
3 c Christoph Flamm and Ivo L Hofacker
4 {xtof,ivo}@tbi.univie.ac.at
6 $Id: globals.c,v 1.8 2008/10/07 09:03:14 ivo Exp $
16 #include "fold_vars.h"
20 /* forward declarations privat functions */
21 static void ini_globs(void);
22 static void ini_gtoggles (void);
23 static void ini_gvars(void);
24 static void ini_garrays (void);
25 static void usage(int status);
26 static void display_settings(void);
27 static void display_fileformat(void);
28 static char *verbose(int optval, const char *which);
29 static int process_options (int argc, char *argv[]);
30 static void process_options_gg (int argc, char *argv[]);
32 static const char *costring(const char *str);
34 static char UNUSED rcsid[] ="$Id: globals.c,v 1.8 2008/10/07 09:03:14 ivo Exp $";
36 static char msg[MAXMSG][60] =
40 {"take from input file"},
42 {"mfe structure of sequence"},
43 {"ViennaRNA-Package-1.4 defaults"},
47 static struct option const long_options[] =
48 { {"dangle", required_argument, 0, 0},
49 {"Temp", required_argument, 0, 0},
50 {"Par", required_argument, 0, 0},
51 {"phi", required_argument, 0, 0},
52 {"pbounds", required_argument, 0, 0},
53 {"logML", no_argument, >V.logML, 0},
54 {"noShift", no_argument, >V.noShift, 1},
55 {"noLP", no_argument, >V.noLP, 1},
56 {"seed", required_argument, 0, 0},
57 {"time", required_argument, 0, 0},
58 {"num", required_argument, 0, 0},
59 {"start", no_argument, >V.start, 1},
60 {"stop", no_argument, >V.stop, 1},
61 {"fpt", no_argument, >V.fpt, 0},
62 {"met", no_argument, >V.mc, 1},
63 {"grow", required_argument, 0, 0},
64 {"glen", required_argument, 0, 0},
65 {"log", required_argument, 0, 0},
66 {"silent", no_argument, 0, 0},
67 {"lmin", no_argument, >V.lmin, 1},
68 {"cut", required_argument, 0, 0},
69 {"help", no_argument, 0, 'h'},
70 {"verbose", no_argument, 0, 0},
75 void decode_switches(int argc, char *argv[]) {
77 strcpy(GAV.ProgramName, argv[0]);
78 process_options_gg(argc, argv);
82 void clean_up_globals(void) {
84 free(GAV.ProgramName);
91 for (i = 0; i < GSV.maxS; i++) free(GAV.stopform[i]);
97 static void usage(int status) {
98 fprintf(stderr, "\n%s - Kinetic Folding Program for Nucleic Acids -\n",
100 fprintf(stderr, "Usage: %s [OPTION] < FILE\n", GAV.ProgramName);
104 " --dangle <0|1|2> set dangling end model to (non|normal|double)\n"
105 " --Temp <float> set simulation temperature to <float>\n"
106 " --Par <string> use energy-parameter-file <string>\n"
107 " --logML use linear multiloop-function not logarithmic\n"
109 " --noShift turn off shift-moves\n"
110 " --noLP forbit structures with isolated base-pairs\n"
112 " --seed <int=int=int> set random seed to <int=int=int>\n"
113 " --time <float> set maxtime of simulation to <float>\n"
114 " --num <int> set number of simulations to <int>\n"
115 " --start set start structure\n"
116 " --stop set stop structure(s)\n"
117 " --met use Metropolis rule not Kawasaki rule\n"
118 " --fpt stop stop structure(s) is reached\n"
119 " --grow <float> grow chain every <float> time steps\n"
120 " --phi <double> set phi value to <double>\n"
121 " --pbounds <d1=d2=d3> set phi_min to d1\n"
124 " (d? is a double value)\n"
126 " --log <string> set basename of log-file to <string>\n"
127 " --err <string> set basename of error-log-file to <string>\n"
128 " --silent no output to stdout\n"
129 " --verbose more information to stdout\n"
130 " --lmin output only local minima to stdout\n"
131 " --cut <float> output structures with E <= <float> to stdout\n");
133 display_fileformat();
138 static void display_fileformat(void) {
140 "Input File Format:\n"
141 "1st line sequence\n"
142 "2nd line start structure (if option --start is used)\n"
143 "following lines stop structures\n\n");
147 void log_prog_params(FILE *FP) {
150 "#EnergyModel: dangle=%d Temp=%.1f logML=%s Par=%s\n"
151 "#MoveSet: noShift=%s noLP=%s\n"
152 "#Simulation: num=%d time=%.2f seed=%s fpt=%s mc=%s\n"
153 "#Simulation: phi=%g pbounds=%s\n"
154 "#Output: log=%s silent=%s lmin=%s cut=%.2f\n",
158 verbose(GTV.logML, "logML"),
160 verbose(GTV.noShift, NULL),
161 verbose(GTV.noLP, NULL),
164 verbose(GTV.seed, "seed"),
165 verbose(GTV.fpt, NULL),
166 verbose(GTV.mc, "met"),
168 verbose(GTV.phi, "pbounds"),
170 verbose(GTV.silent, NULL),
171 verbose(GTV.lmin, NULL),
177 void log_start_stop(FILE *FP) {
179 fprintf(FP, "#%s\n#%s (%6.2f)\n", costring(GAV.farbe),
180 costring(GAV.startform), GSV.startE);
181 for (i = 0; i < GSV.maxS; i++) {
182 fprintf(FP, "#%s (%6.2f) X%02d\n", costring(GAV.stopform[i]), GAV.sE[i], i+1);
184 fprintf(FP, "(%-5hu %5hu %5hu)", GAV.subi[0], GAV.subi[1], GAV.subi[2]);
190 static void display_settings(void) {
192 "Default Settings:\n"
220 verbose(GTV.logML, "logML"),
221 verbose(GTV.noShift, NULL),
222 verbose(GTV.noLP, NULL),
223 verbose(GTV.seed, "seed"),
226 verbose(GTV.phi, "pbounds"),
228 verbose(GTV.start, "start"),
229 verbose(GTV.stop, "stop"),
230 verbose(GTV.mc, "met"),
231 verbose(GTV.fpt, NULL),
233 verbose(GTV.silent, NULL),
234 verbose(GTV.verbose, NULL),
235 verbose(GTV.lmin, NULL),
240 static char *verbose (int optval, const char *which) {
241 if (which == NULL) return msg[optval];
243 if ( strcmp(which, "seed") == 0 ) {
244 if (optval == 0 ) return "clock";
246 sprintf(msg[MAXMSG - 1],
247 "%hu %hu %hu", GAV.subi[0], GAV.subi[1],GAV.subi[2]);
248 return msg[MAXMSG - 1];
252 if (strcmp(which, "pbounds") == 0) {
253 sprintf(msg[MAXMSG - 1],
255 GAV.phi_bounds[0], GAV.phi_bounds[1], GAV.phi_bounds[2]);
256 return msg[MAXMSG - 1];
259 if ( strcmp(which, "met") == 0 ) {
260 if ( optval == 0 ) return "Kawasaki";
261 else return "Metropolis";
264 if ( strcmp(which, "logML") == 0 ) {
265 if ( optval == 0 ) return "linear";
266 else return "logarithmic";
269 if ( strcmp(which, "start") == 0 ) {
270 if ( optval == 0 ) return "OpenChain";
271 else return "input file";
274 if ( strcmp(which, "stop") == 0 ) {
275 if ( optval == 0 ) return "Mfe";
276 else return "input file";
283 static void ini_globs (void) {
289 static void process_options_gg (int argc, char *argv[]) {
290 struct gengetopt_args_info args_info;
291 if (cmdline_parser (argc, argv, &args_info) != 0)
293 if (args_info.help_given) cmdline_parser_print_help();
294 if (args_info.full_help_given) cmdline_parser_print_full_help();
296 GTV.dangle = args_info.dangle_arg;
297 GSV.Temp = args_info.Temp_arg;
298 strncpy(GAV.ParamFile,255,args_info.Par_arg);
299 GTV.Par = args_info.Par_given;
300 GTV.logML = args_info.logML_flag;
302 GTV.noShift = args_info.noShift_flag;
303 GTV.noLP = args_info.noLP_flag;
305 GTV.start= args_info.start_flag;
306 GTV.stop = args_info.stop_flag;
307 GTV.mc = args_info.met_flag;
308 GTV.lmin = args_info.lmin_flag;
310 GTV.verbose = args_info.verbose_flag;
311 GTV.silent = (GTV.verbose==0)?
312 args_info.silent_flag : 0;
313 if (args_info.seed_given)
314 if (sscanf(args_info.seed_arg, "%hu=%hu=%hu",
315 &GAV.subi[0], &GAV.subi[1], &GAV.subi[2]) != 3)
320 if (args_info.phi_given) {
321 if (args_info.phi_arg>0) {
323 GSV.phi = args_info.phi_arg;
326 fprintf(stderr, "Value of --phi must be > 0 >%lf<\n", args_info.phi_arg);
330 if (args_info.pbounds_given) {
331 if (sscanf(args_info.pbounds_arg, "%g=%g=%g",
334 &GAV.phi_bounds[2]) == 0)
338 /* check if values are proper */
339 if (GAV.phi_bounds[0] > GAV.phi_bounds[2]
340 || GAV.phi_bounds[1] > GAV.phi_bounds[2]) {
342 "Unmet requirements for pbounds:\n"
343 "phi_min < phi_max && phi_inc < phi_max\n"
344 "phi_min: %g phi_inc: %g phi_max: %g\n",
345 GAV.phi_bounds[0], GAV.phi_bounds[1], GAV.phi_bounds[2]);
349 GSV.time = args_info.time_arg;
350 GSV.num = args_info.num_arg;
351 strncpy(GAV.BaseName, args_info.log_arg, 255);
352 GSV.cut = args_info.cut_arg;
353 GSV.grow = args_info.grow_arg;
354 GSV.glen = args_info.glen_arg;
355 GTV.lmin = args_info.lmin_flag;
356 GTV.fpt = args_info.fpt_flag;
357 cmdline_parser_free(&args_info);
360 static int process_options (int argc, char *argv[]) {
364 int option_index = 0;
365 while ((c = getopt_long (argc, argv, "h",
366 long_options, &option_index)) != EOF) {
369 if (strcmp(long_options[option_index].name,"dangle")==0) {
371 if (sscanf(optarg, "%d", &itmp) == 0)
373 else if (itmp == 0 || itmp == 1 || itmp == 2 || itmp == 3)
376 fprintf(stderr, "Value of --dangle must be 0|1|2 >%d<\n", itmp);
377 usage (EXIT_FAILURE);
381 if (strcmp(long_options[option_index].name,"Temp")==0) {
383 if (sscanf(optarg, "%f", &ftmp) == 0)
385 else if ( ftmp >= 0 )
388 fprintf(stderr, "Value of --Temp must be >= 0 >%.2f<\n", ftmp);
389 usage (EXIT_FAILURE);
393 if (strcmp(long_options[option_index].name,"Par")==0) {
394 if (sscanf(optarg, "%s", GAV.ParamFile) == 0)
401 if (strcmp(long_options[option_index].name,"silent")==0) {
406 if (strcmp(long_options[option_index].name,"verbose")==0) {
411 if (strcmp(long_options[option_index].name,"seed")==0) {
412 if (sscanf(optarg, "%hu=%hu=%hu",
413 &GAV.subi[0], &GAV.subi[1], &GAV.subi[2]) == 0)
419 if (strcmp(long_options[option_index].name,"pbounds")==0) {
420 if (sscanf(optarg, "%g=%g=%g",
423 &GAV.phi_bounds[2]) == 0)
427 /* check if values are proper */
428 if (GAV.phi_bounds[0] > GAV.phi_bounds[2]
429 || GAV.phi_bounds[1] > GAV.phi_bounds[2]) {
431 "Unmet requirements for pbounds:\n"
432 "phi_min < phi_max && phi_inc < phi_max\n"
433 "phi_min: %g phi_inc: %g phi_max: %g\n",
434 GAV.phi_bounds[0], GAV.phi_bounds[1], GAV.phi_bounds[2]);
439 if (strcmp(long_options[option_index].name,"time")==0) {
441 if (sscanf(optarg, "%lf", &dtmp) == 0)
446 fprintf(stderr, "Value of --time must be > 0 >%lf<\n", dtmp);
452 if (strcmp(long_options[option_index].name, "phi")==0) {
454 if (sscanf(optarg, "%lf", &dtmp) == 0)
456 else if ( dtmp > 0 ) {
461 fprintf(stderr, "Value of --phi must be > 0 >%lf<\n", dtmp);
466 if (strcmp(long_options[option_index].name,"num")==0) {
468 if (sscanf(optarg, "%d", &itmp) == 0)
473 fprintf(stderr, "Value of --num must be > 0 >%d<\n", itmp);
478 if (strcmp(long_options[option_index].name,"log")==0)
479 if (sscanf(optarg, "%s", GAV.BaseName) == 0)
482 if (strcmp(long_options[option_index].name,"cut")==0)
483 if (sscanf(optarg, "%f", &GSV.cut) == 0)
486 if (strcmp(long_options[option_index].name,"grow")==0)
487 if (sscanf(optarg, "%lf", &GSV.grow) == 0)
490 if (strcmp(long_options[option_index].name,"glen")==0)
491 if (sscanf(optarg, "%d", &GSV.glen) == 0)
499 usage (EXIT_FAILURE);
506 static void ini_gtoggles(void) {
524 static void ini_gvars(void) {
540 static void ini_garrays(void) {
541 GAV.ProgramName = (char *)calloc((size_t)256, sizeof(char));
542 assert(GAV.ProgramName != NULL);
543 GAV.ParamFile = (char *)calloc((size_t)256, sizeof(char));
544 assert(GAV.ParamFile != NULL);
545 strcpy(GAV.ParamFile,"VRNA-1.4");
546 GAV.BaseName = (char *)calloc((size_t)256, sizeof(char));
547 assert(GAV.BaseName != NULL);
548 strcpy(GAV.BaseName, "kinout");
549 GAV.stopform = (char **)calloc(GSV.maxS + 1, sizeof(char *));
550 assert(GAV.stopform != NULL);
552 GAV.startform = NULL;
555 GAV.phi_bounds[0] = 0.1;
556 GAV.phi_bounds[1] = 0.1;
557 GAV.phi_bounds[2] = 2.0;
560 static const char *costring(const char *str) {
561 static char* buffer=NULL;
564 if ((str==NULL) && (buffer)) {
565 /* make it possible to free buffer */
572 buffer = realloc(buffer, size);
574 if ((cut_point>0)&&(cut_point<=n)) {
575 strncpy(buffer, str, cut_point-1);
576 buffer[cut_point-1] = '&';
577 strncpy(buffer+cut_point, str+cut_point-1, n-cut_point+1);
580 strncpy(buffer, str, n+1);