Debian Codegraph @

tests/test_common_variants.cpp

raw
1 #include <fstream>
2 #include <iostream>
3 #include <map>
4 #include <string>
5
6 #include "../src/get_common_variants.h"
7
8 int main() {
9 int num_success = 0;
10 std::string files[] = {"../data/test.1.tsv", "../data/test.2.tsv",
11 "../data/test.3.tsv"};
12 std::ifstream fin;
13 std::map<std::string, std::string> file_tab_delimited_str;
14 std::map<std::string, unsigned int> counts;
15 // Read all files
16 for (int i = 0; i < 3; ++i) {
17 fin.open(files[i]);
18 read_variant_file(fin, i, counts, file_tab_delimited_str);
19 fin.close();
20 }
21 std::map<std::string, std::string>::iterator it =
22 file_tab_delimited_str.begin();
23 // Test tab delimited strings for test.1.tsv.
24 std::string keys[] = {"test\t42\tG\tT\tid-test3\tAGG\tR\tATG\tM\t0",
25 "test\t69\tT\tG\tid-test3\tTTG\tL\tTGG\tW\t0",
26 "test\t320\tA\tT\tNA\tNA\tNA\tNA\tNA\t2"};
27 std::string values[] = {"0\t0\t0\t1\t0\t49\t1\t1\t1\tFALSE",
28 "1\t0\t57\t1\t0\t53\t0.5\t2\t0.666667\tFALSE",
29 "1\t1\t35\t1\t1\t46\t0.5\t2\t0.666667\tFALSE"};
30 int ctr = 0;
31 while (it != file_tab_delimited_str.end() && ctr < 2) {
32 // Check if key in map
33 if (file_tab_delimited_str.find(keys[ctr]) ==
34 file_tab_delimited_str.end()) {
35 std::cout << keys[ctr] << std::endl;
36 num_success = -1;
37 } else {
38 ctr++;
39 }
40 if ((it->first).compare(keys[ctr]) == 0 &&
41 (it->second).compare(values[ctr]) !=
42 0) { // Check if value of key matches
43 std::cout << it->first << ": " << it->second << std::endl;
44 std::cout << keys[ctr] << ": " << values[ctr] << " -> Correct"
45 << std::endl;
46 num_success = -1;
47 }
48 it++;
49 }
50 // Test counts
51 std::map<std::string, unsigned int>::iterator count_it = counts.begin();
52 std::string count_keys[] = {"test\t42\tG\tT\tid-test3\tAGG\tR\tATG\tM\t",
53 "test\t320\tA\tT\tNA\tNA\tNA\tNA\tNA\t",
54 "test\t365\tA\tT\tNA\tNA\tNA\tNA\tNA\t",
55 "test\t42\tG\tT\tid-test4\tCAG\tQ\tCAT\tH\t"};
56 unsigned int count_values[] = {1, 2, 3, 1};
57 ctr = 0;
58 while (count_it != counts.end() && ctr < 3) {
59 if (counts.find(count_keys[ctr]) == counts.end()) {
60 std::cout << count_keys[ctr] << std::endl;
61 num_success = -1;
62 } else {
63 ctr++;
64 }
65 if ((count_it->first).compare(count_keys[ctr]) == 0 &&
66 count_it->second != count_values[ctr]) {
67 std::cout << count_it->first << ": " << count_it->second << std::endl;
68 std::cout << count_keys[ctr] << ": " << count_values[ctr] << " -> Correct"
69 << std::endl;
70 num_success = -1;
71 }
72 count_it++;
73 }
74 if (num_success == 0) return 0;
75 return -1;
76 }