-
Notifications
You must be signed in to change notification settings - Fork 0
/
utility.cc
425 lines (370 loc) · 8.93 KB
/
utility.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
#include "defs.h"
using namespace std;
std::string category;
std::string RUNPATH;
std::string currentDateTime()
{
time_t now = time(0);
struct tm tstruct;
char buf[80];
tstruct = *localtime(&now);
strftime(buf, sizeof(buf), "%Y-%m-%d.%X", &tstruct);
return buf;
}
//modulename, option, cbp, ibp, char XY, valOption ,val mean stdev param1 param2
void fileLog(std::string moduleName, std::string opt,std::string cbp_opt, std::string ibp_opt, std::string xy_opt, std::string cbp, std::string ibp, std::string xy,std::string valOption,float val,float mean,float stdev,float param1,float param2,int mc)
{
logfile << "[" << currentDateTime() << "]" << ": " << "<"<<moduleName<<"> " << "Options:"<<opt<<" "<< cbp_opt <<" "<< ibp_opt << " " << xy_opt <<" cbp:"<<cbp<<" ibp:"<< ibp <<" xy:"<<xy<<" valOption:"<<valOption<<" val:"<<val<<" mean:"<<mean<<" stdev:"<<stdev<<" ub:"<<param1<<" lb:"<<param2<<" #mod="<< mc <<"\n";
}
void fileLog(std::string query)
{
logfile << "[" << currentDateTime() << "]" << ": " << query <<"\n";
}
void undoModule()
{
//int21
for(int i=0; i<LINES_INT21; i++)
{
for(int j=0; j<COLS_INT21; j++)
{
int21[i][j] = int21_ORIG[i][j];
}
}
//int22
for(int i=0; i<LINES_INT22; i++)
{
for(int j=0; j<COLS_INT22; j++)
{
int22[i][j] = int22_ORIG[i][j];
}
}
//dangle
for(int i=0; i<LINES_DANGLE; i++)
{
for(int j=0; j<COLS_DANGLE; j++)
{
dangle[i][j] = dangle_ORIG[i][j];
}
}
//int21
for(int i=0; i<LINES_INT11; i++)
{
for(int j=0; j<COLS_INT11; j++)
{
int11[i][j] = int11_ORIG[i][j];
}
}
//loop
for(int i=0; i<LINES_LOOP; i++)
{
for(int j=0; j<COLS_LOOP; j++)
{
loop[i][j] = loop_ORIG[i][j];
}
}
//stack
for(int i=0; i<LINES_STACK; i++)
{
for(int j=0; j<COLS_STACK; j++)
{
stack[i][j] = stack_ORIG[i][j];
}
}
//tloop
for(int i=0; i<LINES_TLOOP; i++)
{
tloop[i] = tloop_ORIG[i];
}
//tstackh
for(int i=0; i<LINES_TSTACKH; i++)
{
for(int j=0; j<COLS_TSTACKH; j++)
{
tstackh[i][j] = tstackh_ORIG[i][j];
}
}
//tstacki
for(int i=0; i<LINES_TSTACKI; i++)
{
for(int j=0; j<COLS_TSTACKI; j++)
{
tstacki[i][j] = tstacki_ORIG[i][j];
}
}
fileLog("UNDO OPERATION");
cout<<"\n>>Latest Query Undone!";
return;
}
string getCurrentWorkingDir()
{
char cwd[1000];
string retval="";
if(getcwd(cwd, sizeof(cwd)) == NULL)
return retval;
else
retval = cwd;
return retval;
}
string findRunPath()
{
char *val;
val = getenv("GTMODIFYRUNPATH");
string retval = "";
if(val != NULL)
retval = val;
return retval;
}
void computeFunction()
{
//implement integration with gtfold
string retval = findRunPath();
if(retval == "")
{
cout<<"\n>>Environment variable GTMODIFYRUNPATH not set";
return;
}
//saving arrays to default temp dir which will be used to feed parameter values to gtfold
saveArraysToPath(CURRENT_WORKING_DIR+"/temp");
//making the runpath and integrating with gtfold
string gtfoldFileName;
cout<<"\n>>Enter File Name: ";
cin >> gtfoldFileName;
RUNPATH = retval+"/gtmfe "+"-p "+ CURRENT_WORKING_DIR +"/temp " +"./"+gtfoldFileName;
//cout<<"\n------"<<RUNPATH;
system(RUNPATH.c_str());
return;
}
void readCategory()
{
cout<< ">>Categories:\n>>(length) : modify hairpin/bulge/internal energies based on length of loop\n>>(misc) : modify tetraloop and other miscellaneous energies\n>>(internal) : modify 1x1 2x1 2x2 internal loop energies\n>>(stack) : modify stack energies\n>>(terminal) : modify terminal mismatch energies for hairpin and internal loops\n>>(dangle) : modify dangling energies\n\n";
cout<<">>Enter category to Modify: ";
cin >> category;
if (category == "length")
{
lengthBasedModule();
return;
}
else if (category == "misc")
{
miscModule();
return;
}
else if (category == "dangle")
{
dangleModule();
return;
}
else if(category == "stack")
{
stackModule();
return;
}
else if(category == "terminal")
{
terminalModule();
return;
}
if(category == "internal")
{
internalModule();
return;
}
else if (category == "exit")
{
exitFunction();
}
else
{
cout<<">>Wrong Input Format\n";
return;
}
}
void saveModule()
{
string savePath;
cout<<"\n>>Enter Full Path where you wish to save: ";
cin >> savePath;
if(savePath == "0")
return;
if(saveArraysToPath(savePath))
{
cout << ">>Files saved to :" << savePath << "\n";
fileLog("SAVE OPERATION to : "+savePath);
}
else
cout << "ERROR Saving to :" << savePath << "\n";
}
int saveArraysToPath(string savePath)
{
//try to make dir if not exists
string makeTheDir = "mkdir "+ savePath;
system(makeTheDir.c_str());
string fileSavePath;
FILE *fp;
//save int22
fileSavePath = savePath+"/int22.DAT";
fp = fopen(fileSavePath.c_str(),"w");
for(int i=0; i<LINES_INT22; i++)
{
for(int j=0; j<COLS_INT22; j++)
{
fprintf(fp, "%f ",int22[i][j]);
}
fprintf(fp,"\n");
}
fclose(fp);
//save int21
fileSavePath = savePath+"/int21.DAT";
fp = fopen(fileSavePath.c_str(), "w");
for(int i=0; i<LINES_INT21; i++)
{
for(int j=0; j<COLS_INT21; j++)
{
fprintf(fp, "%f\t",int21[i][j]);
}
fprintf(fp, "\n");
}
fclose(fp);
//save dangle
fileSavePath = savePath +"/dangle.DAT";
fp = fopen(fileSavePath.c_str(), "w");
for(int i=0; i<LINES_DANGLE; i++)
{
for(int j=0; j<COLS_DANGLE; j++)
{
fprintf(fp,"%f \t",dangle[i][j]);
}
fprintf(fp,"\n");
}
fclose(fp);
//save int11
fileSavePath = savePath +"/int11.DAT";
fp = fopen(fileSavePath.c_str(), "w");
for(int i=0; i<LINES_INT11; i++)
{
for(int j=0; j<COLS_INT11; j++)
{
fprintf(fp, "%f\t",int11[i][j]);
}
fprintf(fp, "\n");
}
fclose(fp);
//save loop
fileSavePath = savePath +"/loop.DAT";
fp = fopen(fileSavePath.c_str(), "w");
for(int i=0; i<LINES_LOOP; i++)
{
for(int j=0; j<COLS_LOOP; j++)
{
if(j == 0)
fprintf(fp, "%d\t", (i+1));
else
//cout<<"---------------- "<<loop[i][j]<<"\n";
fprintf(fp, "%f\t",loop[i][j]);
//fprintf(fp, "Hello\t");
}
fprintf(fp, "\n");
}
fclose(fp);
//save stack
fileSavePath = savePath +"/stack.DAT";
fp = fopen(fileSavePath.c_str(), "w");
for(int i=0; i<LINES_STACK; i++)
{
for(int j=0; j<COLS_STACK; j++)
{
fprintf(fp, "%f\t",stack[i][j]);
}
fprintf(fp, "\n");
}
fclose(fp);
//save tloop has string values as well
fileSavePath = savePath + "/tloop.DAT";
fp = fopen(fileSavePath.c_str(), "w");
for(int i=0; i<LINES_TLOOP; i++)
{
fprintf(fp,"%s\t%f",stringTloop[i].c_str(), tloop[i]);
fprintf(fp, "\n");
}
fclose(fp);
//save tstackh
fileSavePath = savePath +"/tstackh.DAT";
fp = fopen(fileSavePath.c_str(), "w");
for(int i=0; i<LINES_TSTACKH; i++)
{
for(int j=0; j<COLS_TSTACKH; j++)
{
fprintf(fp, "%f\t",tstackh[i][j]);
}
fprintf(fp, "\n");
}
fclose(fp);
//save tstacki
fileSavePath = savePath +"/tstacki.DAT";
fp = fopen(fileSavePath.c_str(), "w");
for(int i=0; i<LINES_TSTACKI; i++)
{
for(int j=0; j<COLS_TSTACKI; j++)
{
fprintf(fp, "%f\t",tstacki[i][j]);
}
fprintf(fp, "\n");
}
fclose(fp);
//copy miscloop.DAT, tstacke.DAT and tstackm.DAT to savePath
string copyCommand;
//copy miscloop.DAT
copyCommand = "cp miscloop.DAT "+savePath;
system(copyCommand.c_str());
//copy tstacke.DAT
copyCommand = "cp tstacke.DAT "+savePath;
system(copyCommand.c_str());
//copy tstackm.DAT
copyCommand = "cp tstackm.DAT "+savePath;
system(copyCommand.c_str());
return 1;
}
void loadModule()
{
string loadPath;
cout<<"\n>>Enter the full Path to Load Data files: ";
cin >> loadPath;
if(loadPath == "0")
return;
if(loadArraysFromPath(loadPath))
{
cout<< ">>Files loaded from : "<< loadPath <<"\n";
fileLog("LOAD OPERATION to : "+loadPath);
}
else
cout << "ERROR Loading from : "<< loadPath <<"\n";
}
int loadArraysFromPath(string loadPath)
{
//implement function here
string pathInt22 = loadPath+"/int22.DAT";
string pathInt21 = loadPath+"/int21.DAT";
string pathDangle = loadPath+"/dangle.DAT";
string pathInt11 = loadPath+"/int11.DAT";
string pathLoop = loadPath+"/loop.DAT";
string pathStack = loadPath+"/stack.DAT";
string pathTloop = loadPath+"/tloop.DAT";
string pathTstackh = loadPath+"/tstackh.DAT";
string pathTstacki = loadPath+"/tstacki.DAT";
loadInt22(pathInt22);
loadInt21(pathInt21);
loadDangle(pathDangle);
loadInt11(pathInt11);
loadLoop(pathLoop);
loadStack(pathStack);
loadTloop(pathTloop);
loadTstackh(pathTstackh);
loadTstacki(pathTstacki);
return 1;
}
void exitFunction()
{
logfile << "\n-------------------- SESSION END ---------------------\n";
logfile.close();
exit(0);
}