1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <math.h>
5 #include <limits.h>
6 #include <time.h>
7 
8 #include <stack>
9 
10 extern "C" {
11   #include "pair_mat.h"
12   #include "fold.h"
13 }
14 
15 #include "globals.h"
16 #include "move_set_pk.h"
17 
18 // some singleton objects
19 Options Opt;
20 
SeqInfo()21 SeqInfo::SeqInfo()
22 {
23   seq = NULL;
24   s0 = s1 = NULL;
25 
26   update_fold_params();
27 }
28 
~SeqInfo()29 SeqInfo::~SeqInfo()
30 {
31   if (s0) free(s0);
32   if (s1) free(s1);
33   if (seq) free(seq);
34 }
35 
Init(char * seq)36 void SeqInfo::Init(char *seq) {
37   this->seq = (char*) malloc(sizeof(char)*strlen(seq)+1);
38   strcpy(this->seq, seq);
39   make_pair_matrix();
40   update_fold_params();
41   s0 = encode_sequence(seq, 0);
42   s1 = encode_sequence(seq, 1);
43 }
44 
Options()45 Options::Options()
46 {
47 }
48 
Init(gengetopt_args_info & args_info)49 int Options::Init(gengetopt_args_info &args_info)
50 {
51   int ret = 0;
52 
53   if (args_info.min_num_arg<0) {
54     fprintf(stderr, "Number of local minima should be non-negative integer (min-num)\n");
55     ret = -1;
56   }
57 
58   if (args_info.find_num_given && args_info.find_num_arg<=0) {
59     fprintf(stderr, "Number of local minima should be positive integer (find-num)\n");
60     ret = -1;
61   }
62 
63   if (args_info.verbose_lvl_arg<0 || args_info.verbose_lvl_arg>4) {
64     if (args_info.verbose_lvl_arg<0) args_info.verbose_lvl_arg = 0;
65     else args_info.verbose_lvl_arg = 4;
66     fprintf(stderr, "WARNING: level of verbosity is not in range (0-4), setting it to %d\n", args_info.verbose_lvl_arg);
67   }
68 
69   if (args_info.temp_arg<-273.15) {
70     fprintf(stderr, "Temperature cannot be below absolute zero\n");
71     ret = -1;
72   }
73 
74   if (args_info.floodMax_arg<0) {
75     fprintf(stderr, "Flood cap must be non-negative\n");
76     ret = -1;
77   }
78 
79   if (args_info.floodPortion_arg<0.0 || args_info.floodPortion_arg>1.0) {
80     args_info.floodPortion_arg = (args_info.floodPortion_arg<0.0 ? 0.0 : 1.0);
81     fprintf(stderr, "WARNING: floodPortion is not in range (0.0-1.0), setting it to %.1f\n", args_info.floodPortion_arg);
82   }
83 
84   if (args_info.depth_arg<=0) {
85     fprintf(stderr, "Depth of findpath search should be positive integer\n");
86     ret = -1;
87   }
88 
89   if (args_info.minh_arg<0.0) {
90     fprintf(stderr, "Depth of findpath search should be non-negative number\n");
91     ret = -1;
92   }
93 
94   if (args_info.numIntervals_arg<0) {
95     fprintf(stderr, "Number of intervals should be non-negative number\n");
96     ret = -1;
97   }
98 
99   if (args_info.eRange_given && args_info.eRange_arg<0.0) {
100     fprintf(stderr, "Energy range should be non-negative number\n");
101     ret = -1;
102   }
103 
104   if (args_info.dangles_arg<0 || args_info.dangles_arg>3) {
105     fprintf(stderr, "Dangle treatment constant should be 0, 1, 2, or 3\n");
106     ret = -1;
107   }
108 
109   if (ret ==-1) return -1;
110 
111   // adjust options
112   minh = (int)(args_info.minh_arg*100);
113   noLP = args_info.noLP_flag;
114   EOM = !args_info.useEOS_flag;
115   first = args_info.walk_arg[0]=='F';
116   rand = args_info.walk_arg[0]=='R';
117   shift = args_info.move_arg[0]=='S';
118   verbose_lvl = args_info.verbose_lvl_arg;
119   floodMax = args_info.floodMax_arg;
120   pknots = args_info.pseudoknots_flag;
121   neighs = args_info.neighborhood_flag;
122 
123   return ret;
124 }
125 
126 /*Degen::Degen()
127 {
128   current = 0;
129 }
130 
131 Degen::~Degen()
132 {
133   Clear();
134 }
135 
136 void Degen::Clear()
137 {
138   // unprocessed
139   for (set<short*, comps_short>::iterator it=unprocessed.begin(); it!=unprocessed.end(); it++) {
140     if (*it) free(*it);
141   }
142   unprocessed.clear();
143 
144   // processed
145   for (set<short*, comps_short>::iterator it=processed.begin(); it!=processed.end(); it++) {
146     if (*it) free(*it);
147   }
148   processed.clear();
149 }*/
150