-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.cpp
67 lines (49 loc) · 1.52 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
#include "gzstream.h"
#include "genoFreq.hpp"
#include <set>
int main(int argc, char **argv) {
int max_haplotype = 6;
std::string output_dir;
if (argc < 2){
std::cerr << "run as following" << std::endl;
std::cerr << "./genoFreq <file.vcf/file.vcf.gz> ";
std::cerr << "<output_dir> <optional: max_haplotype_number, default=6>" << std::endl;
exit(0);
}
if (argc < 3){
std::cerr << "must provide output path" << std::endl;
exit(0);
}
output_dir = argv[2];
if (argc > 3) {
if (atoi(argv[3]) > 9) {
std::cerr
<< "cannot process haplotypes number greater than 9\nTerminating..."
<< std::endl;
exit(0);
} else {
max_haplotype = atoi(argv[3]);
}
}
GenoFreq *GENO = new GenoFreq(argv[1], max_haplotype, output_dir);
igzstream in(argv[1]);
std::string str = "##";
// Extract all filter names
std::set<std::string> filter_names;
while (str.substr(0, 2) == "##") {
if (str.substr(0, 8) == "##FILTER") {
filter_names.insert(GENO->split(str, ',')[0].substr(13));
}
getline(in, str);
}
std::vector<std::string> splitted = GENO->split(str, '\t');
std::vector<std::string> samples_names;
for (uint i = 9; i < splitted.size(); i++) {
samples_names.push_back(splitted[i]);
}
GENO->create_index(filter_names, samples_names);
std::cerr << "Analyzing... " << std::endl;
std::vector<std::string> all_samples;
for (std::string str; std::getline(in, str);) GENO->analyze(str);
GENO->write_results();
}