File: test_common_variants.cpp

package info (click to toggle)
ivar 1.3%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 3,924 kB
  • sloc: cpp: 4,907; javascript: 866; sh: 120; makefile: 37
file content (69 lines) | stat: -rwxr-xr-x 2,530 bytes parent folder | download | duplicates (2)
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
#include <iostream>
#include <fstream>
#include <string>
#include <map>
#include "../src/get_common_variants.h"

int main() {
  int num_success = 0;
  std::string files[] = {"../data/test.1.tsv", "../data/test.2.tsv", "../data/test.3.tsv"};
  std::ifstream fin;
  std::map<std::string, std::string> file_tab_delimited_str;
  std::map<std::string, unsigned int> counts;
  // Read all files
  for (int i = 0; i < 3; ++i) {
    fin.open(files[i]);
    read_variant_file(fin, i, counts, file_tab_delimited_str);
    fin.close();
  }
  std::map<std::string, std::string>::iterator it = file_tab_delimited_str.begin();
  // Test tab delimited strings for test.1.tsv.
  std::string keys[] = {
    "test\t42\tG\tT\tid-test3\tAGG\tR\tATG\tM\t0",
    "test\t69\tT\tG\tid-test3\tTTG\tL\tTGG\tW\t0",
    "test\t320\tA\tT\tNA\tNA\tNA\tNA\tNA\t2"
  };
  std::string values[] = {
    "0\t0\t0\t1\t0\t49\t1\t1\t1\tFALSE",
    "1\t0\t57\t1\t0\t53\t0.5\t2\t0.666667\tFALSE",
    "1\t1\t35\t1\t1\t46\t0.5\t2\t0.666667\tFALSE"
  };
  int ctr = 0;
  while(it!=file_tab_delimited_str.end() && ctr < 2){
    // Check if key in map
    if(file_tab_delimited_str.find(keys[ctr]) == file_tab_delimited_str.end()){
      std::cout << keys[ctr] << std::endl;
      num_success = -1;
    } else {
      ctr++;
    }
    if((it->first).compare(keys[ctr]) == 0 && (it->second).compare(values[ctr]) != 0){ // Check if value of key matches
      std::cout << it->first << ": " << it->second << std::endl;
      std::cout << keys[ctr] << ": " << values[ctr] << " -> Correct" << std::endl;
      num_success = -1;
    }
    it++;
  }
  // Test counts
  std::map<std::string, unsigned int>::iterator count_it = counts.begin();
  std::string count_keys[] = {"test\t42\tG\tT\tid-test3\tAGG\tR\tATG\tM\t", "test\t320\tA\tT\tNA\tNA\tNA\tNA\tNA\t", "test\t365\tA\tT\tNA\tNA\tNA\tNA\tNA\t", "test\t42\tG\tT\tid-test4\tCAG\tQ\tCAT\tH\t"};
  unsigned int count_values[] = {1, 2, 3, 1};
  ctr = 0;
  while(count_it!=counts.end() && ctr < 3){
    if(counts.find(count_keys[ctr]) == counts.end()){
      std::cout << count_keys[ctr] << std::endl;
      num_success = -1;
    } else {
      ctr++;
    }
    if((count_it->first).compare(count_keys[ctr]) == 0 && count_it->second != count_values[ctr]){
      std::cout << count_it->first << ": " << count_it->second << std::endl;
      std::cout << count_keys[ctr] << ": " << count_values[ctr] << " -> Correct" << std::endl;
      num_success = -1;
    }
    count_it++;
  }  
  if(num_success == 0)
    return 0;
  return -1;
}