-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.cpp
238 lines (203 loc) · 5.56 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
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
#include <stdio.h>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <vector>
#include <atomic>
#include <mutex>
#include <stdint.h>
#include <unordered_map>
#include <pthread.h>
#include <chrono>
#include <omp.h>
#include <math.h>
#include <unistd.h>
#include <bitset>
#include "Miekki.h"
#include "utils.h"
using namespace std;
using namespace chrono;
inline uint number_miss(const string str1,const string str2){
uint res(0);
for(uint i(0);i<str1.size();++i){
if(str1[i]!=str2[i]){
res++;
}
}
return res;
}
inline char revCompChar(char c) {
switch (c) {
case 'A': return 'T';
case 'C': return 'G';
case 'G': return 'C';
}
return 'A';
}
inline string revComp(const string& s){
string rc(s.size(),0);
for (int i((int)s.length() - 1); i >= 0; i--){
rc[s.size()-1-i] = revCompChar(s[i]);
}
return rc;
}
inline string getCanonical(const string& str){
return (min(str,revComp(str)));
}
uint collisions_unordered(vector<uint64_t>& V1, const vector<uint64_t>& V2){
uint res(0);
sort(V1.begin(),V1.end());
for(uint i(0);i<V2.size();++i){
if(binary_search (V1.begin(), V1.end(), V2[i])){
++res;
}
}
return res;
}
uint collisions_sort(vector<uint64_t>& V1, vector<uint64_t>& V2){
uint res(0);
sort(V1.begin(),V1.end());
V1.erase( unique( V1.begin(), V1.end() ), V1.end() );
sort(V2.begin(),V2.end());
V2.erase( unique( V2.begin(), V2.end() ), V2.end() );
for(uint i1(0),i2(0);i1<V1.size() and i2<V2.size();){
if(V1[i1]==V2[i2]){
++res;++i2;++i1;
}else if(V1[i1]<V2[i2]){
++i1;
}else{
++i2;
}
}
return res;
}
void help(){
cout<<"This is a help message"<<endl;
cout<<"Input "<<endl;
cout<<"-i load a constructed index from disk"<<endl;
cout<<"-l construct an index from a list of file"<<endl;
cout<<"-a query a fasta file"<<endl;
cout<<"-A query fasta from file of file"<<endl;
cout<<"\nOutput "<<endl;
cout<<"-o output file name (out.txt)"<<endl;
cout<<"-d dump the index on disk"<<endl;
cout<<"\nPerformances "<<endl;
cout<<"-h use 2^h minimizers per sequence (20 for 1048576 minimizers)"<<endl;
cout<<"-k kmer size (31)"<<endl;
cout<<"-s minimal estimated intersection to be reported (100)"<<endl;
cout<<"-t thread number (1)"<<endl;
cout<<"\nAdvanced usage "<<endl;
cout<<"-f fingerprint size "<<endl;
cout<<"-b 2^b bits used for the bloom filter "<<endl;
cout<<"-e exact mode, real intersection will be computed on hits"<<endl;
}
int main(int argc, char ** argv){
if(argc<2){
help();
exit(0);
}
string index_file,index_file_of_file,query_fastq,query_lines_of_file,query_files_of_list,outputFile("out.txt"),index_dump("");
uint64_t H(17),core_number(8),kmer_size(31),bloom_size(33),fingerprint_size(3);
double threshold(200);
bool exact_mode(false);
srand (time(NULL));
Miekki *INDEX;
char c;
while ((c = getopt (argc, argv, "i:l:a:h:t:f:k:s:b:o:ed:A:")) != -1){
switch(c){
case 'i':
index_file=optarg;
break;
case 'l':
index_file_of_file=optarg;
break;
case 'a':
query_lines_of_file=optarg;
break;
case 'A':
query_files_of_list=optarg;
break;
//~ case 'q':
//~ query_fastq=optarg;
//~ break;
case 'o':
outputFile=optarg;
break;
case 'h':
H=stoi(optarg);
break;
case 't':
core_number=stoi(optarg);
break;
case 'k':
kmer_size=stoi(optarg);
break;
case 's':
threshold=stof(optarg);
break;
case 'f':
fingerprint_size=stoi(optarg);
break;
case 'b':
bloom_size=stoi(optarg);
break;
case 'e':
exact_mode=true;
break;
case 'd':
index_dump=optarg;
break;
}
}
uint32_t bit_per_min=(5+fingerprint_size);
cout<<"Using "<<bit_per_min<<" bits per minimizer, "<<intToString(1<<H)<<" minimizers so "<<intToString(bit_per_min*(1<<H))<<" bits per sequences"<<endl;
auto start = system_clock::now();
if(index_file!=""){
INDEX =new Miekki(index_file);
INDEX->out= new ofstream(outputFile.c_str());
INDEX->core_number=core_number;
cout<<"I output results in "<<outputFile<<endl;
cout<<"Load sucessful"<<endl;
//TODO CHANGE WHAT CAN BE CHANGED
}else if(index_file_of_file!=""){
INDEX =new Miekki(kmer_size,H,bit_per_min,5,0,outputFile,bloom_size,threshold,core_number);
INDEX->index_file_of_file(index_file_of_file);
INDEX->compress_index(1);
}else{
cout<<"What am I supposed to index ? use either -i or -l options please"<<endl;
help();
exit(0);
}
if(index_dump!=""){
cout<<"I write this index on the disk for later"<<endl;
INDEX->dump_disk(index_dump);
}
auto endIndex = system_clock::now();
duration<double> elapsed_seconds = endIndex - start;
cout<< "elapsed time: " << elapsed_seconds.count() << "s\n";
if(query_lines_of_file!=""){
if(exact_mode){
cout<<"running in exact mode, actual intersection will be computed on hits found by the index"<<endl;
INDEX->query_file_exact(query_lines_of_file);
//TODO HANDLE FASTQ FILES
}else{
cout<<"running in approx mode, intersection is estimated by the index"<<endl;
INDEX->query_file(query_lines_of_file);
}
}else if(query_files_of_list!=""){
if(exact_mode){
cout<<"running in exact mode, actual intersection will be computed on hits found by the index"<<endl;
INDEX->query_file_of_file_exact(query_files_of_list);
}else{
cout<<"running in approx mode, intersection is estimated by the index"<<endl;
INDEX->query_file_of_file(query_files_of_list);
}
}else{
cout<<"No query file, No queries"<<endl;
}
auto endQuery = system_clock::now();
elapsed_seconds = endQuery -endIndex;
cout<< "elapsed time: " << elapsed_seconds.count() << "s\n";
cout<<"The end"<<endl;
return 0;
}