Debian Codegraph @

unit_tests/test_kmerhashtable.cpp

raw symbols ◀ ▶ SCIP
1 Debian patch touch this file
1 #include "catch.hpp"
2
3 #include <random>
4 #include <string>
5 #include <map>
6 #include <unordered_map>
7 #include <stdio.h>
8 #include <iostream>
9
10 #include "common.h"
11 #include "Kmer.hpp"
12 #include "KmerIterator.hpp"
13 #include "KmerHashTable.h"
14
15 #include <zlib.h>
•16 #include <htslib/kseq.h>
17
18 #ifndef KSEQ_INIT_READY
19 #define KSEQ_INIT_READY
20 KSEQ_INIT(gzFile, gzread)
21 #endif
22
23
24 using namespace std;
25
26 TEST_CASE("Build table", "[build_table]")
27 {
28
29 ProgramOptions global_opts;
30 std::string short_reads {"../test/input/short_reads.fastq"};
31
32 std::random_device rd;
33 std::mt19937 gen(rd());
34 std::uniform_int_distribution<int> dis(1, 100);
35
36 // TODO: figure out a better way to deal with initialization
37 Kmer::set_k(global_opts.k);
38
39 unordered_map<Kmer, int, KmerHash> kmap1;
40 map<Kmer, int> kmap2;
41 KmerHashTable<int, KmerHash> kmap3;
42 vector<Kmer> v;
43
44
45 std::ios_base::sync_with_stdio(false);
46 gzFile fp = gzopen(short_reads.c_str(), "r");
47 kseq_t *seq = kseq_init(fp);
48 int l;
49 int val = 0;
50 while ((l = kseq_read(seq)) >= 0) {
51 KmerIterator kit(seq->seq.s), kit_end;
52 for (; kit != kit_end; ++kit) {
53 Kmer rep = kit->first.rep();
54 //int val = dis(gen);
55 v.push_back(rep);
56 kmap1.insert({rep,val});
57 kmap2.insert({rep,val});
58 kmap3.insert({rep,val});
59 val++;
60 }
61
62 }
63
64 gzclose(fp);
65 kseq_destroy(seq);
66
67 REQUIRE(kmap1.size() == kmap2.size());
68 REQUIRE(kmap3.size() == kmap1.size());
69 cerr << kmap1.size() << endl;
70 for (auto & km : v) {
71 auto s1 = kmap1.find(km);
72 REQUIRE(s1 != kmap1.end());
73 REQUIRE(s1->first == km);
74 //REQUIRE(s1->second == i);
75
76
77 auto s2 = kmap2.find(km);
78 REQUIRE(s2 != kmap2.end());
79 REQUIRE(s2->first == km);
80 REQUIRE(s2->second == s1->second);
81
82 auto s3 = kmap3.find(km);
83 REQUIRE(s3 != kmap3.end());
84 REQUIRE(s3->second == s1->second);
85 }
86
87 }