Debian Codegraph @

seatac/hitMatrix.C

raw symbols SCIP
1 #cxx . . $ `<file>/seatac/hitMatrix.C`/include "seatac.H"cxx . . $ `<file>/seatac/seatac.H`/
2
3
4 hitMatrixcxx . . $ hitMatrix#::hitMatrixcxx . . $ hitMatrix#hitMatrix(b4d55b1286ff73e8).(uint32cxx . . $ uint32# qsLen, uint32cxx . . $ uint32# qsIdx) {
5 _qsLencxx . . $ hitMatrix#_qsLen. = qsLen;
6 _qsIdxcxx . . $ hitMatrix#_qsIdx. = qsIdx;
7
8 // Because this is doing scaffolds or chromosomes against more than
9 // 1/4 a genome, we expect a LOT of hits. Start off with a good
10 // amount of memory.
11 //
12 // At 8 bytes per diagonalLine, 128M of these is 1GB. Which works
13 // great for aligning mamalian chromosomes and stinks for microbes.
14 //
15 _hitsLencxx . . $ hitMatrix#_hitsLen. = 0;
16 _hitsMaxcxx . . $ hitMatrix#_hitsMax. = 32 * 1024 * 1024;
17 _hitscxx . . $ hitMatrix#_hits. = new diagonalLinecxx . . $ diagonalLine# [_hitsMaxcxx . . $ hitMatrix#_hitsMax.];
18 }
19
20
21 hitMatrixcxx . . $ hitMatrix#::~cxx . . $ hitMatrix#`~hitMatrix`(ced63f7c635d850d).hitMatrixcxx . . $ hitMatrix#() {
22 delete [] _hitscxx . . $ hitMatrix#_hits.;
23 }
24
25
26 // Utility for sorting the diagonal lines in the hitMatrix
27 //
28 // The two comparison functions return true if the first line
29 // is less than the second line.
30
31 #ifdef WITHOUT_DIAGONALIDcxx . . $ `seatac/hitMatrix.H:28:9`!
32
33 inline
34 int
35 compareLinescxx . . $ compareLines(b94d232718cef8d5).(diagonalLinecxx . . $ diagonalLine# *A, diagonalLinecxx . . $ diagonalLine# *B, uint32cxx . . $ uint32# qsLen) {
36 uint32cxx . . $ uint32# a = qsLen - A->_qsPoscxx . . $ diagonalLine#_qsPos. - 1 + A->_dsPoscxx . . $ diagonalLine#_dsPos.;
37 uint32cxx . . $ uint32# b = qsLen - B->_qsPoscxx . . $ diagonalLine#_qsPos. - 1 + B->_dsPoscxx . . $ diagonalLine#_dsPos.;
38
39 return(((a < b)) ||
40 ((a == b) && (A->_qsPoscxx . . $ diagonalLine#_qsPos. < B->_qsPoscxx . . $ diagonalLine#_qsPos.)));
41 }
42
43 inline
44 int
45 compareLinescxx . . $ compareLines(676a4e832e1d5068).(uint32cxx . . $ uint32# l, uint32cxx . . $ uint32# q, diagonalLinecxx . . $ diagonalLine# *B, uint32cxx . . $ uint32# qsLen) {
46 uint32cxx . . $ uint32# b = qsLen - B->_qsPoscxx . . $ diagonalLine#_qsPos. - 1 + B->_dsPoscxx . . $ diagonalLine#_dsPos.;
47
48 return(((l < b)) ||
49 ((l == b) && (q < B->_qsPoscxx . . $ diagonalLine#_qsPos.)));
50 }
51
52 inline
53 void
54 adjustHeapcxx . . $ adjustHeap(b88a07326068cf67).(diagonalLinecxx . . $ diagonalLine# *L, int32cxx . . $ int32# p, int32cxx . . $ int32# n, uint32cxx . . $ uint32# qsLen) {
55 uint32cxx . . $ uint32# q = L[p]._qsPoscxx . . $ diagonalLine#_qsPos.;
56 uint32cxx . . $ uint32# d = L[p]._dsPoscxx . . $ diagonalLine#_dsPos.;
57 uint32cxx . . $ uint32# l = qsLen - q - 1 + d;
58 int32cxx . . $ int32# c = (p << 1) + 1; // let c be the left child of p
59
60 while (c < n) {
61
62 // Find the larger of the two children
63 //
64 if ((c+1 < n) && compareLinescxx . . $ compareLines(b94d232718cef8d5).(L+c, L+c+1, qsLen))
65 c++;
66
67 // Does the node in question fit here?
68 //
69 if (compareLinescxx . . $ compareLines(676a4e832e1d5068).(l, q, L+c, qsLen) == false)
70 break;
71
72 // Else, swap the parent and the child
73 //
74 L[p]._qsPoscxx . . $ diagonalLine#_qsPos. = L[c]._qsPoscxx . . $ diagonalLine#_qsPos.;
75 L[p]._dsPoscxx . . $ diagonalLine#_dsPos. = L[c]._dsPoscxx . . $ diagonalLine#_dsPos.;
76
77 // Move down the tree
78 //
79 p = c;
80 c = (p << 1) + 1;
81 }
82
83 L[p]._qsPoscxx . . $ diagonalLine#_qsPos. = q;
84 L[p]._dsPoscxx . . $ diagonalLine#_dsPos. = d;
85 }
86
87
88 #else // WITH_DIAGONALID
89
90
91 inline
92 int
93 compareLines(diagonalLine *A, diagonalLine *B) {
94 return(((A->_diagonalID < B->_diagonalID)) ||
95 ((A->_diagonalID == B->_diagonalID) && (A->_qsPos < B->_qsPos)));
96 }
97
98 inline
99 int
100 compareLines(uint32 l, uint32 q, diagonalLine *B) {
101 return(((l < B->_diagonalID)) ||
102 ((l == B->_diagonalID) && (q < B->_qsPos)));
103 }
104
105 inline
106 void
107 adjustHeap(diagonalLine *L, int32 p, int32 n) {
108 uint32 q = L[p]._qsPos;
109 uint32 d = L[p]._dsPos;
110 uint32 l = L[p]._diagonalID;
111 int32 c = (p << 1) + 1; // let c be the left child of p
112
113 while (c < n) {
114
115 // Find the larger of the two children
116 //
117 if ((c+1 < n) && compareLines(L+c, L+c+1))
118 c++;
119
120 // Does the node in question fit here?
121 //
122 if (compareLines(l, q, L+c) == false)
123 break;
124
125 // Else, swap the parent and the child
126 //
127 L[p]._qsPos = L[c]._qsPos;
128 L[p]._dsPos = L[c]._dsPos;
129 L[p]._diagonalID = L[c]._diagonalID;
130
131 // Move down the tree
132 //
133 p = c;
134 c = (p << 1) + 1;
135 }
136
137 L[p]._qsPos = q;
138 L[p]._dsPos = d;
139 L[p]._diagonalID = l;
140 }
141
142
143 #endif
144
145
146
147
148
149
150 void
151 hitMatrixcxx . . $ hitMatrix#::processMatrixcxx . . $ hitMatrix#processMatrix(b2e8704fc2713a96).(char direction, filterObjcxx . . $ filterObj# *FO) {
152
153 if (_hitsLencxx . . $ hitMatrix#_hitsLen. == 0)
154 return;
155
156 // First, sort by the dsPos. This is done so that we can find all the hits for
157 // a specific scaffold.
158 //
159 sort_dsPoscxx . . $ hitMatrix#sort_dsPos(49f6e7a06ebc5aa8).();
160
161
162 merCoveringcxx . . $ merCovering# ILcxx . . $ merCovering#merCovering(cb2f890c2fdad230).(configcxx . . $ config.._merSizecxx . . $ configuration#_merSize.);
163 uint32cxx . . $ uint32# ILlength = 0;
164
165 // Now, while there are hits left....
166 //
167 uint32cxx . . $ uint32# firstHit = 0;
168 uint32cxx . . $ uint32# lastHit = 0;
169 uint32cxx . . $ uint32# currentSeq = 0;
170
171 while (firstHit < _hitsLencxx . . $ hitMatrix#_hitsLen.) {
172
173 // Move the currentSeq until the firstHit is below it.
174 //
175 while ((currentSeq < configcxx . . $ config.._genomecxx . . $ configuration#_genome.->numberOfSequencescxx . . $ seqStream#numberOfSequences(db52760e79bf9054).()) &&
176 (configcxx . . $ config.._genomecxx . . $ configuration#_genome.->startOfcxx . . $ seqStream#startOf(1892545c1754497d).(currentSeq) <= _hitscxx . . $ hitMatrix#_hits.[firstHit]._dsPoscxx . . $ diagonalLine#_dsPos.))
177 currentSeq++;
178
179 //
180 // currentSeq is now the sequence AFTER the one that we want hits in.
181 //
182
183 // Find the first hit that is in currentSeq. If this is the last sequence,
184 // then, of course, all remaining hits are in it.
185 //
186 if (currentSeq < configcxx . . $ config.._genomecxx . . $ configuration#_genome.->numberOfSequencescxx . . $ seqStream#numberOfSequences(db52760e79bf9054).()) {
187 lastHit = firstHit + 1;
188 while ((lastHit < _hitsLencxx . . $ hitMatrix#_hitsLen.) &&
189 (_hitscxx . . $ hitMatrix#_hits.[lastHit]._dsPoscxx . . $ diagonalLine#_dsPos. < configcxx . . $ config.._genomecxx . . $ configuration#_genome.->startOfcxx . . $ seqStream#startOf(1892545c1754497d).(currentSeq)))
190 lastHit++;
191 } else {
192 lastHit = _hitsLencxx . . $ hitMatrix#_hitsLen.;
193 }
194
195 // Drop back one sequence; this is the sequence the hits are in.
196 //
197 currentSeq--;
198
199
200 // Adjust the hits to be relative to the start of this sequence
201 //
202 for (uint32cxx . . $ uint32# i=firstHit; i<lastHit; i++)
203 _hitscxx . . $ hitMatrix#_hits.[i]._dsPoscxx . . $ diagonalLine#_dsPos. -= configcxx . . $ config.._genomecxx . . $ configuration#_genome.->startOfcxx . . $ seqStream#startOf(1892545c1754497d).(currentSeq);
204
205 // Sort them, if needed.
206 //
207 if (lastHit - firstHit > 1) {
208
209 // We cheat; heapsort isn't too friendly to sorting the middle of
210 // an array, so we make a new array in the middle!
211 //
212 diagonalLinecxx . . $ diagonalLine# *hitsToSort = _hitscxx . . $ hitMatrix#_hits. + firstHit;
213
214 // Build the heap. I initially thought this could be done at the
215 // same time as the scan for the last hit, but it can't (easily)
216 //
217 for (int32cxx . . $ int32# i=(lastHit - firstHit)/2 - 1; i>=0; i--)
218 #ifdef WITHOUT_DIAGONALIDcxx . . $ `seatac/hitMatrix.H:28:9`!
219 adjustHeapcxx . . $ adjustHeap(b88a07326068cf67).(hitsToSort, i, lastHit - firstHit, _qsLencxx . . $ hitMatrix#_qsLen.);
220 #else
221 adjustHeap(hitsToSort, i, lastHit - firstHit);
222 #endif
223
224 // Sort the hits be diagonal. This is the second part of
225 // heap sort -- Interchange the new maximum with the element
226 // at the end of the tree
227 //
228 for (uint32cxx . . $ uint32# i=lastHit - firstHit - 1; i>0; i--) {
229 uint32cxx . . $ uint32# q = hitsToSort[i]._qsPoscxx . . $ diagonalLine#_qsPos.;
230 uint32cxx . . $ uint32# d = hitsToSort[i]._dsPoscxx . . $ diagonalLine#_dsPos.;
231 #ifndef WITHOUT_DIAGONALIDcxx . . $ `seatac/hitMatrix.H:28:9`!
232 uint32 l = hitsToSort[i]._diagonalID;
233 #endif
234
235 hitsToSort[i]._qsPoscxx . . $ diagonalLine#_qsPos. = hitsToSort[0]._qsPoscxx . . $ diagonalLine#_qsPos.;
236 hitsToSort[i]._dsPoscxx . . $ diagonalLine#_dsPos. = hitsToSort[0]._dsPoscxx . . $ diagonalLine#_dsPos.;
237 #ifndef WITHOUT_DIAGONALIDcxx . . $ `seatac/hitMatrix.H:28:9`!
238 hitsToSort[i]._diagonalID = hitsToSort[0]._diagonalID;
239 #endif
240
241 hitsToSort[0]._qsPoscxx . . $ diagonalLine#_qsPos. = q;
242 hitsToSort[0]._dsPoscxx . . $ diagonalLine#_dsPos. = d;
243 #ifndef WITHOUT_DIAGONALIDcxx . . $ `seatac/hitMatrix.H:28:9`!
244 hitsToSort[0]._diagonalID = l;
245 #endif
246
247 #ifdef WITHOUT_DIAGONALIDcxx . . $ `seatac/hitMatrix.H:28:9`!
248 adjustHeapcxx . . $ adjustHeap(b88a07326068cf67).(hitsToSort, 0, i, _qsLencxx . . $ hitMatrix#_qsLen.);
249 #else
250 adjustHeap(hitsToSort, 0, i);
251 #endif
252 }
253 }
254
255
256 // Filter them
257 //
258 #ifdef WITHOUT_DIAGONALIDcxx . . $ `seatac/hitMatrix.H:28:9`!
259 uint32cxx . . $ uint32# lastDiagonal = _qsLencxx . . $ hitMatrix#_qsLen. - _hitscxx . . $ hitMatrix#_hits.[firstHit]._qsPoscxx . . $ diagonalLine#_qsPos. - 1 + _hitscxx . . $ hitMatrix#_hits.[firstHit]._dsPoscxx . . $ diagonalLine#_dsPos.;
260 #else
261 uint32 lastDiagonal = _hits[firstHit]._diagonalID;
262 #endif
263 uint32cxx . . $ uint32# qsLow = _hitscxx . . $ hitMatrix#_hits.[firstHit]._qsPoscxx . . $ diagonalLine#_qsPos.;
264 uint32cxx . . $ uint32# qsHigh = _hitscxx . . $ hitMatrix#_hits.[firstHit]._qsPoscxx . . $ diagonalLine#_qsPos.;
265 uint32cxx . . $ uint32# dsLow = _hitscxx . . $ hitMatrix#_hits.[firstHit]._dsPoscxx . . $ diagonalLine#_dsPos.;
266 uint32cxx . . $ uint32# dsHigh = _hitscxx . . $ hitMatrix#_hits.[firstHit]._dsPoscxx . . $ diagonalLine#_dsPos.;
267
268 IL.clearcxx . . $ merCovering#clear(49f6e7a06ebc5aa8).();
269
270 for (uint32cxx . . $ uint32# i=firstHit; i<lastHit; i++) {
271 //fprintf(stdout, "hit[%6u] seq=%8u qs=%5u ds=%5u\n", i, currentSeq, _hits[i]._qsPos, _hits[i]._dsPos);
272
273 //
274 // Extend if on the same diagonal, and consecutive sequence.
275 //
276 if ((lastDiagonal ==
277 #ifdef WITHOUT_DIAGONALIDcxx . . $ `seatac/hitMatrix.H:28:9`!
278 (_qsLencxx . . $ hitMatrix#_qsLen. - _hitscxx . . $ hitMatrix#_hits.[i]._qsPoscxx . . $ diagonalLine#_qsPos. - 1 + _hitscxx . . $ hitMatrix#_hits.[i]._dsPoscxx . . $ diagonalLine#_dsPos.)
279 #else
280 _hits[i]._diagonalID
281 #endif
282 ) &&
283 (qsLow <= _hitscxx . . $ hitMatrix#_hits.[i]._qsPoscxx . . $ diagonalLine#_qsPos.) &&
284 (_hitscxx . . $ hitMatrix#_hits.[i]._qsPoscxx . . $ diagonalLine#_qsPos. <= qsHigh + configcxx . . $ config.._merSizecxx . . $ configuration#_merSize. + configcxx . . $ config.._maxGapcxx . . $ configuration#_maxGap.)) {
285 if (qsLow > _hitscxx . . $ hitMatrix#_hits.[i]._qsPoscxx . . $ diagonalLine#_qsPos.) qsLow = _hitscxx . . $ hitMatrix#_hits.[i]._qsPoscxx . . $ diagonalLine#_qsPos.;
286 if (qsHigh < _hitscxx . . $ hitMatrix#_hits.[i]._qsPoscxx . . $ diagonalLine#_qsPos.) qsHigh = _hitscxx . . $ hitMatrix#_hits.[i]._qsPoscxx . . $ diagonalLine#_qsPos.;
287 if (dsLow > _hitscxx . . $ hitMatrix#_hits.[i]._dsPoscxx . . $ diagonalLine#_dsPos.) dsLow = _hitscxx . . $ hitMatrix#_hits.[i]._dsPoscxx . . $ diagonalLine#_dsPos.;
288 if (dsHigh < _hitscxx . . $ hitMatrix#_hits.[i]._dsPoscxx . . $ diagonalLine#_dsPos.) dsHigh = _hitscxx . . $ hitMatrix#_hits.[i]._dsPoscxx . . $ diagonalLine#_dsPos.;
289 IL.addMercxx . . $ merCovering#addMer(cb2f890c2fdad230).(_hitscxx . . $ hitMatrix#_hits.[i]._qsPoscxx . . $ diagonalLine#_qsPos.);
290 } else {
291
292 //
293 // Save the match. cut-n-paste with below.
294 //
295
296 ILlength = IL.sumOfLengthscxx . . $ merCovering#sumOfLengths(db52760e79bf9054).();
297 IL.clearcxx . . $ merCovering#clear(49f6e7a06ebc5aa8).();
298
299 if (ILlength >= configcxx . . $ config.._minLengthcxx . . $ configuration#_minLength.) {
300 if (direction == 'r') {
301 FO->addHitcxx . . $ filterObj#addHit(a209694d0a1a92e0).(direction,
302 configcxx . . $ config.._genomecxx . . $ configuration#_genome.->IIDOfcxx . . $ seqStream#IIDOf(2141b656ce2cc063).(currentSeq),
303 dsLow,
304 dsHigh - dsLow + configcxx . . $ config.._merSizecxx . . $ configuration#_merSize.,
305 _qsIdxcxx . . $ hitMatrix#_qsIdx.,
306 _qsLencxx . . $ hitMatrix#_qsLen. - qsHigh - configcxx . . $ config.._merSizecxx . . $ configuration#_merSize.,
307 qsHigh - qsLow + configcxx . . $ config.._merSizecxx . . $ configuration#_merSize.,
308 ILlength);
309 } else {
310 FO->addHitcxx . . $ filterObj#addHit(a209694d0a1a92e0).(direction,
311 configcxx . . $ config.._genomecxx . . $ configuration#_genome.->IIDOfcxx . . $ seqStream#IIDOf(2141b656ce2cc063).(currentSeq),
312 dsLow,
313 dsHigh - dsLow + configcxx . . $ config.._merSizecxx . . $ configuration#_merSize.,
314 _qsIdxcxx . . $ hitMatrix#_qsIdx.,
315 qsLow,
316 qsHigh - qsLow + configcxx . . $ config.._merSizecxx . . $ configuration#_merSize.,
317 ILlength);
318 }
319 }
320
321 #ifdef WITHOUT_DIAGONALIDcxx . . $ `seatac/hitMatrix.H:28:9`!
322 lastDiagonal = _qsLencxx . . $ hitMatrix#_qsLen. - _hitscxx . . $ hitMatrix#_hits.[i]._qsPoscxx . . $ diagonalLine#_qsPos. - 1 + _hitscxx . . $ hitMatrix#_hits.[i]._dsPoscxx . . $ diagonalLine#_dsPos.;
323 #else
324 lastDiagonal = _hits[i]._diagonalID;
325 #endif
326 qsLow = _hitscxx . . $ hitMatrix#_hits.[i]._qsPoscxx . . $ diagonalLine#_qsPos.;
327 qsHigh = _hitscxx . . $ hitMatrix#_hits.[i]._qsPoscxx . . $ diagonalLine#_qsPos.;
328 dsLow = _hitscxx . . $ hitMatrix#_hits.[i]._dsPoscxx . . $ diagonalLine#_dsPos.;
329 dsHigh = _hitscxx . . $ hitMatrix#_hits.[i]._dsPoscxx . . $ diagonalLine#_dsPos.;
330 IL.addMercxx . . $ merCovering#addMer(cb2f890c2fdad230).(_hitscxx . . $ hitMatrix#_hits.[i]._qsPoscxx . . $ diagonalLine#_qsPos.);
331 }
332 }
333
334 // Save the final cluster? (cut-n-paste from above)
335 //
336 ILlength = IL.sumOfLengthscxx . . $ merCovering#sumOfLengths(db52760e79bf9054).();
337 IL.clearcxx . . $ merCovering#clear(49f6e7a06ebc5aa8).();
338
339 if (ILlength >= configcxx . . $ config.._minLengthcxx . . $ configuration#_minLength.) {
340 if (direction == 'r') {
341 FO->addHitcxx . . $ filterObj#addHit(a209694d0a1a92e0).(direction,
342 configcxx . . $ config.._genomecxx . . $ configuration#_genome.->IIDOfcxx . . $ seqStream#IIDOf(2141b656ce2cc063).(currentSeq),
343 dsLow,
344 dsHigh - dsLow + configcxx . . $ config.._merSizecxx . . $ configuration#_merSize.,
345 _qsIdxcxx . . $ hitMatrix#_qsIdx.,
346 _qsLencxx . . $ hitMatrix#_qsLen. - qsHigh - configcxx . . $ config.._merSizecxx . . $ configuration#_merSize.,
347 qsHigh - qsLow + configcxx . . $ config.._merSizecxx . . $ configuration#_merSize.,
348 ILlength);
349 } else {
350 FO->addHitcxx . . $ filterObj#addHit(a209694d0a1a92e0).(direction,
351 configcxx . . $ config.._genomecxx . . $ configuration#_genome.->IIDOfcxx . . $ seqStream#IIDOf(2141b656ce2cc063).(currentSeq),
352 dsLow,
353 dsHigh - dsLow + configcxx . . $ config.._merSizecxx . . $ configuration#_merSize.,
354 _qsIdxcxx . . $ hitMatrix#_qsIdx.,
355 qsLow,
356 qsHigh - qsLow + configcxx . . $ config.._merSizecxx . . $ configuration#_merSize.,
357 ILlength);
358 }
359 }
360
361 // All done with these hits. Move to the next set.
362 //
363 firstHit = lastHit;
364 }
365 }
366
367