forked from trichelab/squeakr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkmer_inner_prod.cc
118 lines (99 loc) · 3.12 KB
/
kmer_inner_prod.cc
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
/*
* =====================================================================================
*
* Filename: kmer_query.cc
*
* Description:
*
* Version: 1.0
* Created: 04/27/2016 08:48:26 AM
* Revision: none
* Compiler: gcc
*
* Author: Prashant Pandey ([email protected])
* Rob Patro ([email protected])
* Rob Johnson ([email protected])
* Organization: Stony Brook University
*
* =====================================================================================
*/
#include <iostream>
#include <cstring>
#include <vector>
#include <set>
#include <bitset>
#include <cassert>
#include <fstream>
#include <time.h>
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/time.h>
#include "clipp.h"
#include "threadsafe-gqf/gqf.h"
using namespace std;
/* Print elapsed time using the start and end timeval */
void print_time_elapsed(string desc, struct timeval* start, struct timeval* end)
{
struct timeval elapsed;
if (start->tv_usec > end->tv_usec) {
end->tv_usec += 1000000;
end->tv_sec--;
}
elapsed.tv_usec = end->tv_usec - start->tv_usec;
elapsed.tv_sec = end->tv_sec - start->tv_sec;
float time_elapsed = (elapsed.tv_sec * 1000000 + elapsed.tv_usec)/1000000.f;
cout << desc << "Total Time Elapsed: " << to_string(time_elapsed) << " seconds" << endl;
}
/*
* === FUNCTION ======================================================================
* Name: main
* Description:
* =====================================================================================
*/
int main ( int argc, char *argv[] )
{
QF cfa, cfb;
//if (argc == 2) {
//string arg_help(argv[1]);
//if (arg_help.compare("-h") != 0 || arg_help.compare("-help") != 0) {
//cout << "./squeakr-inner-product [OPTIONS]" << endl
//<< "file1: dataset 1 Squeakr representation" << endl
//<< "file2: dataset 2 Squeakr representation" << endl;
//exit(0);
//}
//}
string ds_filea;
string ds_fileb;
uint64_t inner_prod;
struct timeval start, end;
struct timezone tzp;
using namespace clipp;
auto cli = (
required("-a", "--cqf-file-first") & value("cqf-file-first", ds_filea) % "first input CQF file",
required("-b", "--cqf-file-second") & value("cqf-file-second", ds_fileb) % "second input CQF file",
option("-h", "--help") % "show help"
);
auto res = parse(argc, argv, cli);
if (!res) {
std::cout << make_man_page(cli, argv[0]) << "\n";
return 1;
}
srand(time(NULL));
//Initialize the QF
cout << "Mmap the QF from disk" << endl;
qf_read(&cfa, ds_filea.c_str());
qf_read(&cfb, ds_fileb.c_str());
if (cfa.metadata->seed != cfb.metadata->seed) {
cerr << "Input CQFs do not have the same seed." << std::endl;
return 1;
}
cout << "Performing inner product querries." << endl;
gettimeofday(&start, &tzp);
inner_prod = qf_inner_product(&cfa, &cfb);
gettimeofday(&end, &tzp);
cout << "Inner product: " << inner_prod << "\n" << endl;
print_time_elapsed("", &start, &end);
return EXIT_SUCCESS;
} /* ---------- end of function main ---------- */