-
Notifications
You must be signed in to change notification settings - Fork 67
/
IntersectingAligner.h
414 lines (357 loc) · 13.7 KB
/
IntersectingAligner.h
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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
/*++
Module Name:
IntersectingAligner.h
Abstract:
Header for SNAP genome aligner
Authors:
Bill Bolosky, September, 2011
Environment:
User mode service.
This class is NOT thread safe. It's the caller's responsibility to ensure that
at most one thread uses an instance at any time.
Revision History:
Adapted from Matei Zaharia's Scala implementation.
--*/
#pragma once
#if 0
#include "options.h"
#include "Read.h"
#include "Seed.h"
#include "Genome.h"
#include "GenomeIndex.h"
#include "Histogram.h"
#include "Aligner.h"
#include "LandauVishkin.h"
class IntersectingAligner: public Aligner {
public:
IntersectingAligner(
GenomeIndex *i_genomeIndex,
unsigned i_confDiff,
unsigned i_maxHitsToConsider,
unsigned i_maxK,
unsigned i_maxReadSize,
unsigned i_maxSeedsToUse,
unsigned i_lvCutoff);
AlignmentResult
AlignRead(
Read *read,
unsigned *genomeLocation,
bool *hitIsRC,
int *score = NULL,
int *mapq = NULL);
void
ComputeHitDistribution(
Read *read,
unsigned correctGenomeLocation,
bool correctHitIsRC,
unsigned *hitCountBySeed,
unsigned *rcHitCountBySeed,
unsigned &nSeedsApplied,
unsigned &nRCSeedsApplied,
unsigned *hitsCountsContainingCorrectLocation)
{
fprintf(stderr,"ComputeHitDistribution doesn't work for IntersectingAligner.\n");
exit(1);
}
_int64 getNHashTableLookups() const {return nHashTableLookups;}
_int64 getLocationsScored() const {return nLocationsScored;}
_int64 getNHitsIgnoredBecauseOfTooHighPopularity() const {return nHitsIgnoredBecauseOfTooHighPopularity;}
_int64 getNReadsIgnoredBecauseOfTooManyNs() const {return nReadsIgnoredBecauseOfTooManyNs;}
_int64 getNIndelsMerged() const {return nIndelsMerged;}
#if MAINTAIN_HISTOGRAMS
const Histogram *getLVHistogram() const {return lvHistogram;}
const Histogram *getLookupHistogram() const {return lookupHistogram;}
const Histogram *getLVHistogramForMulti() const {return lvHistogramForMulti;}
const Histogram *getLVHistogramWhenBestFound() const {return lvCountWhenBestFound;}
#endif // MAINTAIN_HISTOGRAMS
const char *getRCTranslationTable() const {return rcTranslationTable;}
~IntersectingAligner();
inline int getMaxK() const {return maxK;}
inline int getConfDiff() const {return confDiff;}
const char *getName() const {return "Intersecting Aligner";}
struct LookupResult {
unsigned nHits;
bool isRC;
const unsigned *hits;
unsigned offset; // The offset of the seed within the read. This is corrected for during intersection.
};
void addIgnoredReads(_int64 newlyIgnoredReads) {};
private:
LandauVishkin landauVishkin;
char rcTranslationTable[256];
AlignmentResult
AlignReadInternal(
unsigned seedOffset,
Read *read,
unsigned *genomeLocation,
bool *hitIsRC,
int *score);
static const unsigned maxIntersections = 4;
#if MAINTAIN_HISTOGRAMS
Histogram *lvHistogram;
Histogram *lookupHistogram;
Histogram *lvHistogramForMulti;
Histogram *lvCountWhenBestFound;
#endif // MAINTAIN_HISTOGRAMS
_int64 nHashTableLookups;
_int64 nLocationsScored;
_int64 nHitsIgnoredBecauseOfTooHighPopularity;
_int64 nReadsIgnoredBecauseOfTooManyNs;
_int64 nIndelsMerged;
//
// A bitvector indexed by offset in the read indicating whether this seed is used.
// This is here to avoid doing a memory allocation in the aligner.
//
BYTE *seedUsed;
BYTE *seedUsedAsAllocated; // Use this for deleting seedUsed.
inline bool IsSeedUsed(unsigned indexInRead) const {
return (seedUsed[indexInRead / 8] & (1 << (indexInRead % 8))) != 0;
}
inline void SetSeedUsed(unsigned indexInRead) {
seedUsed[indexInRead / 8] |= (1 << (indexInRead % 8));
}
LookupResult *lookupResults;
int nLookupResults;
LookupResult *rcLookupResults;
int nRCLookupResults;
//
// A big array of ulongs that we can use for intersection results.
//
unsigned *intersectionResultSpace;
unsigned intersectionResultsSpaceSize;
unsigned usedEntriesInIntersectionResultSpace;
struct IntersectionResult {
int nMisses; // How many results isn't it in?
unsigned nHits; // What's the size of the intersection?
bool isRC;
unsigned *hits;
};
IntersectionResult *intersectionResults;
unsigned nIntersectionResults;
IntersectionResult *rcIntersectionResults;
unsigned nRCIntersectionResults;
//
// This is really a local to computeIntersection, but we allocate it here to avoid having to
// do a memory allocation/deallocation there.
//
int *intersectionOffsets;
int *alreadyIntersectedOffsets;
void
computeIntersection(
IntersectionResult *alreadyIntersected,
int nAlreadyIntersected,
int totalSetsRepresentedByAlreadyIntersected,
int maxMisses,
LookupResult *lookups,
int nLookups,
IntersectionResult *results,
bool *truncatedResult); // Set iff we got more than maxHitsToConsider in any result set
static const unsigned UnusedScoreValue = 0xffff;
const Genome *genome;
GenomeIndex *genomeIndex;
unsigned seedLen;
int confDiff;
unsigned maxHitsToConsider;
int maxK;
int maxReadSize;
int maxSeedsToUse; // Max number of seeds to look up in the hash table
unsigned lvCutoff;
char *rcReadData;
unsigned nTable[256];
inline unsigned getWrappedNextSeedToTest(unsigned wrapCount) {
if (0 == wrapCount) {
return 0;
}
switch (seedLen) {
case 23: {
switch (wrapCount) {
case 1: return 12;
case 2: return 6;
case 3: return 17;
case 4: return 3;
case 5: return 9;
case 6: return 20;
case 7: return 14;
case 8: return 1;
case 9: return 4;
case 10: return 7;
case 11: return 10;
case 12: return 15;
case 13: return 18;
case 14: return 21;
case 15: return 4;
case 16: return 2;
case 17: return 5;
case 18: return 11;
case 19: return 16;
case 20: return 19;
case 21: return 22;
case 22: return 8;
}
}
case 22: {
switch (wrapCount) {
case 1: return 11;
case 2: return 6;
case 3: return 16;
case 4: return 3;
case 5: return 9;
case 6: return 14;
case 7: return 19;
case 8: return 2;
case 9: return 7;
case 10: return 12;
case 11: return 17;
case 12: return 20;
case 13: return 4;
case 14: return 1;
case 15: return 10;
case 16: return 13;
case 17: return 15;
case 18: return 18;
case 19: return 21;
case 20: return 5;
case 21: return 8;
default: _ASSERT(!"NOTREACHED");
}
}
case 21: {
switch (wrapCount) {
case 1: return 11;
case 2: return 6;
case 3: return 16;
case 4: return 3;
case 5: return 9;
case 6: return 13;
case 7: return 17;
case 8: return 18;
case 9: return 2;
case 10: return 5;
case 11: return 8;
case 12: return 15;
case 13: return 20;
case 14: return 1;
case 15: return 4;
case 16: return 7;
case 17: return 10;
case 18: return 12;
case 19: return 14;
case 20: return 19;
default: _ASSERT(!"NOTREACHED");
}
}
case 20: {
switch (wrapCount) {
case 1: return 10;
case 2: return 5;
case 3: return 15;
case 4: return 2;
case 5: return 7;
case 6: return 12;
case 7: return 17;
case 8: return 3;
case 9: return 9;
case 10: return 11;
case 11: return 13;
case 12: return 19;
case 13: return 1;
case 14: return 4;
case 15: return 6;
case 16: return 8;
case 17: return 14;
case 18: return 18;
case 19: return 16;
default: _ASSERT(!"NOTREACHED");
}
}
case 19: {
switch (wrapCount) {
case 1: return 10;
case 2: return 4;
case 3: return 14;
case 4: return 2;
case 5: return 6;
case 6: return 8;
case 7: return 12;
case 8: return 16;
case 9: return 18;
case 10: return 1;
case 11: return 3;
case 12: return 5;
case 13: return 7;
case 14: return 9;
case 15: return 11;
case 16: return 13;
case 17: return 15;
case 18: return 17;
default: _ASSERT(!"NOTREACHED");
}
}
case 18: {
switch (wrapCount) {
case 1: return 9;
case 2: return 4;
case 3: return 13;
case 4: return 2;
case 5: return 6;
case 6: return 11;
case 7: return 15;
case 8: return 1;
case 9: return 3;
case 10: return 5;
case 11: return 7;
case 12: return 8;
case 13: return 10;
case 14: return 12;
case 15: return 14;
case 16: return 16;
case 17: return 17;
default: _ASSERT(!"NOTREACHED");
}
}
case 17: {
switch (wrapCount) {
case 1: return 8;
case 2: return 4;
case 3: return 12;
case 4: return 2;
case 5: return 6;
case 6: return 10;
case 7: return 14;
case 8: return 1;
case 9: return 3;
case 10: return 5;
case 11: return 7;
case 12: return 9;
case 13: return 11;
case 14: return 13;
case 15: return 15;
case 16: return 16;
default: _ASSERT(!"NOTREACHED");
}
}
case 16: {
switch (wrapCount) {
case 1: return 8;
case 2: return 4;
case 3: return 12;
case 4: return 2;
case 5: return 6;
case 6: return 10;
case 7: return 14;
case 8: return 1;
case 9: return 3;
case 10: return 5;
case 11: return 7;
case 12: return 9;
case 13: return 11;
case 14: return 13;
case 15: return 15;
default: _ASSERT(!"NOTREACHED");
}
} // inner switch
default: fprintf(stderr,"IntersectingAligner: Not set up to run with this seed size\n"); exit(1);
} // outer switch
}
};
#endif // 0