-
Notifications
You must be signed in to change notification settings - Fork 11
/
StreamJoin.cpp
141 lines (114 loc) · 2.83 KB
/
StreamJoin.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
136
137
138
139
140
141
#include <iostream>
#include <string>
#include <vector>
#include <cstring>
#include <getopt.h>
#include <sys/stat.h>
#include <fstream>
#include <stdint.h>
#include <sstream>
#include <bitset>
#include <cstdlib>
#include "common.h"
#include "StreamCounter.hpp"
using namespace std;
struct ProgramOptions {
//size_t k;
std::string output;
std::vector<string> files;
bool verbose;
ProgramOptions() : verbose(false) {}
};
void PrintUsage() {
cout << "KmerStreamJoin " << VERSION << endl << endl;
cout << "Creates union of many stream estimates" << endl << endl;
cout << "Usage: KmerStreamJoin -o output files ..." << endl;
cout << " KmerStreamJoin merged-file";
cout << endl << endl <<
"-o, --output=STRING Filename for output" << endl <<
" --verbose Print output at the end" << endl <<
endl;
}
void ParseOptions(int argc, char **argv, ProgramOptions& opt) {
int verbose_flag = 0;
const char *opt_string = "o:";
static struct option long_options[] = {
{"verbose", no_argument, &verbose_flag, 1},
{"output", required_argument, 0, 'o'},
{0,0,0,0}
};
int option_index = 0;
int c;
while (true) {
c = getopt_long(argc,argv,opt_string, long_options, &option_index);
if (c == -1) {
break;
}
switch (c) {
case 0:
break;
case 'o':
opt.output = optarg;
break;
default: break;
}
}
// all other arguments are fast[a/q] files to be read
for (int i = optind; i < argc; i++) {
opt.files.push_back(argv[i]);
}
if (verbose_flag) {
opt.verbose = true;
}
}
bool CheckOptions(ProgramOptions& opt) {
bool ret = true;
if (opt.files.size() == 0) {
cerr << "Need to specify files for input" << endl;
ret = false;
} else {
struct stat stFileInfo;
vector<string>::const_iterator it;
int intStat;
for(it = opt.files.begin(); it != opt.files.end(); ++it) {
intStat = stat(it->c_str(), &stFileInfo);
if (intStat != 0) {
cerr << "Error: file not found, " << *it << endl;
ret = false;
}
}
}
if (opt.output.empty()) {
if (opt.files.size() != 1) {
cerr << "Missing output file" << endl;
ret = false;
}
}
return ret;
}
int main(int argc, char **argv) {
ProgramOptions opt;
ParseOptions(argc,argv,opt);
if (!CheckOptions(opt)) {
PrintUsage();
exit(1);
}
if (opt.output.empty()) {
std::string fn = opt.files[0];
StreamCounter sc(0.01,0);
sc.loadBinary(fn);
std::cout << sc.report();
} else {
StreamCounter sc(0.01,0);
StreamCounter join(0.01,0);
join.loadBinary(opt.files[0]);
for(size_t i = 1; i < opt.files.size(); i++) {
sc.loadBinary(opt.files[i]);
join.join(sc);
}
join.writeBinary(opt.output);
if (opt.verbose) {
std::cout << join.report();
}
}
}