-
Notifications
You must be signed in to change notification settings - Fork 2
/
Main.cpp
135 lines (128 loc) · 3.85 KB
/
Main.cpp
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
#include <iostream>
#include <getopt.h>
#include <sys/time.h>
#include <unistd.h>
#include "CROP.h"
#include "Unique.h"
using namespace std;
char* program = NULL;
int main(int argc, char* argv[])
{
struct timeval program_start_time, program_end_time;
gettimeofday(& program_start_time, NULL);
int next_option;
/* A string listing valid short options letters. */
const char* const short_options = "i:o:b:gse:m:z:l:u:r:";
/* An array describing valid long options. */
const struct option long_options[] = {
{"input", 0, NULL, 'i'},
{"output", 0, NULL, 'o'},
{"block", 0, NULL, 'b'},
{"genus", 0, NULL, 'g'},
{"species", 0, NULL, 's'},
{"step", 0, NULL, 'e'},
{"maxiter", 0, NULL, 'm'},
{"maxiterblocksize", 0, NULL, 'z'},
{"threshold lower", 0, NULL, 'l'},
{"threshold upper", 0, NULL, 'u'},
{"rare cut", 0, NULL, 'r'},
{NULL, 0, NULL, 0}
};
program = argv[0];
char* fname=NULL;
char* oname=NULL;
int TempBlockSize=50;
bool BlockSizeFlag=false;
int TempStep=2000;
int TempCtrl=0;
int TempMaxiterBlockSize=500;
int TempMaxiter=20;
int NumSeq=0;
int tRareCut=2;
float Lower=0.0;
float Upper=0.0;
/* Process the arguments */
do{
next_option = getopt_long(argc, argv, short_options, long_options, NULL);
switch(next_option){
case 'i':
fname=new char[strlen(optarg)+1];
memset(fname,0x00,sizeof(char)*(strlen(optarg)+1));
strcpy(fname,optarg);
break;
case 'o':
oname=new char[strlen(optarg)+1];
memset(oname,0x00,sizeof(char)*(strlen(optarg)+1));
strcpy(oname,optarg);
break;
case 'b':
TempBlockSize=atoi(optarg);
BlockSizeFlag=true;
break;
case 'g':
TempCtrl=0;
break;
case 's':
TempCtrl=1;
break;
case 'e':
TempStep=atoi(optarg);
break;
case 'm':
TempMaxiter=atoi(optarg);
break;
case 'z':
TempMaxiterBlockSize=atoi(optarg);
break;
case 'u':
TempCtrl=2;
Upper=atof(optarg);
break;
case 'l':
TempCtrl=2;
Lower=atof(optarg);
break;
case 'r':
tRareCut=atoi(optarg);
break;
case -1: /* Done with options */
break;
default: /* Unexpected */
cout<<"Unexpected argument was taken."<<endl;
}
}while(next_option != -1);
if((TempCtrl==2)&&(Lower*Upper==0))
{
cout<<"invalid threshold setting (lower or upper = 0), using default -g option"<<endl;
TempCtrl=0;
}
CROPParameters CParameter;
NumSeq=ExtractUnique(fname);
cout<<NumSeq<<endl;
if(NumSeq==0)
{
return 0;
}
if(BlockSizeFlag==false) //if -b parameter is not specified
TempBlockSize=(NumSeq/TempMaxiterBlockSize)+1;
if(oname==NULL) //if -o parameter is not specified
{
string onametemp(fname);
string fnametemp(fname);
fnametemp+=".unique";
CROP(fnametemp, onametemp, TempBlockSize, TempStep, TempCtrl, Lower, Upper, TempMaxiter, TempMaxiterBlockSize, tRareCut, CParameter);
}
else
{
string onametemp(oname);
string fnametemp(fname);
fnametemp+=".unique";
CROP(fnametemp, onametemp, TempBlockSize, TempStep, TempCtrl, Lower, Upper,TempMaxiter, TempMaxiterBlockSize, tRareCut, CParameter);
}
DELETE(fname);
DELETE(oname);
gettimeofday(&program_end_time, NULL);
time_t total_program_time= (program_end_time.tv_sec - program_start_time.tv_sec);
cout<<"Total program run time is "<<total_program_time/60 +1<< " min"<<endl<<endl;
return 1;
}