| 1 | #cxx . . $ `<file>/seagen/hitMatrix.C`/include "searchGENOME.H"cxx . . $ `<file>/seagen/searchGENOME.H`/ |
| 2 | #include "aHit.H"cxx . . $ `<file>/seagen/aHit.H`/ |
| 3 | |
| 4 | #define TRACEcxx . . $ `seagen/hitMatrix.C:4:9`! 0 |
| 5 | |
| 6 | hitMatrixcxx . . $ hitMatrix#::hitMatrixcxx . . $ hitMatrix#hitMatrix(6df00707c193238d).(uint32cxx . . $ uint32# qsLen, uint32cxx . . $ uint32# qsMers, uint32cxx . . $ uint32# qsIdx) { |
| 7 | _qsLencxx . . $ hitMatrix#_qsLen. = qsLen; |
| 8 | _qsMerscxx . . $ hitMatrix#_qsMers. = qsMers; |
| 9 | _qsIdxcxx . . $ hitMatrix#_qsIdx. = qsIdx; |
| 10 | |
| 11 | _hitsLencxx . . $ hitMatrix#_hitsLen. = 0; |
| 12 | _hitsMaxcxx . . $ hitMatrix#_hitsMax. = 128; |
| 13 | _hitscxx . . $ hitMatrix#_hits. = new diagonalLinecxx . . $ diagonalLine# [_hitsMaxcxx . . $ hitMatrix#_hitsMax.]; |
| 14 | |
| 15 | _matchescxx . . $ hitMatrix#_matches. = 0L; |
| 16 | } |
| 17 | |
| 18 | |
| 19 | hitMatrixcxx . . $ hitMatrix#::~cxx . . $ hitMatrix#`~hitMatrix`(ced63f7c635d850d).hitMatrixcxx . . $ hitMatrix#() { |
| 20 | delete [] _hitscxx . . $ hitMatrix#_hits.; |
| 21 | } |
| 22 | |
| 23 | void |
| 24 | hitMatrixcxx . . $ hitMatrix#::addMatchcxx . . $ hitMatrix#addMatch(be234fe48972ff86).(uint32cxx . . $ uint32# qsLo, |
| 25 | uint32cxx . . $ uint32# qsHi, |
| 26 | uint32cxx . . $ uint32# dsLo, |
| 27 | uint32cxx . . $ uint32# dsHi, |
| 28 | merCoveringcxx . . $ merCovering# *IL) { |
| 29 | uint32cxx . . $ uint32# offset = 0; |
| 30 | |
| 31 | // Extend the match |
| 32 | // |
| 33 | // Two methods: the first uses hardcoded parameters, has two |
| 34 | // plateau's, and is the one to use for ESTs and mRNA in ESTmapper. |
| 35 | // The second is paramterized, and has a single plateau. |
| 36 | // |
| 37 | |
| 38 | if (configcxx . . $ config.._extendAlternatecxx . . $ configuration#_extendAlternate.) { |
| 39 | offset = configcxx . . $ config.._extendWeightcxx . . $ configuration#_extendWeight. * qsLo; |
| 40 | |
| 41 | if (offset < configcxx . . $ config.._extendMinimumcxx . . $ configuration#_extendMinimum.) |
| 42 | offset = configcxx . . $ config.._extendMinimumcxx . . $ configuration#_extendMinimum.; |
| 43 | |
| 44 | if (dsLo < offset) |
| 45 | dsLo = 0; |
| 46 | else |
| 47 | dsLo -= offset; |
| 48 | |
| 49 | offset = configcxx . . $ config.._extendWeightcxx . . $ configuration#_extendWeight. * (_qsLencxx . . $ hitMatrix#_qsLen. - qsHi); |
| 50 | |
| 51 | if (offset < configcxx . . $ config.._extendMinimumcxx . . $ configuration#_extendMinimum.) |
| 52 | offset = configcxx . . $ config.._extendMinimumcxx . . $ configuration#_extendMinimum.; |
| 53 | |
| 54 | dsHi += offset; |
| 55 | } else { |
| 56 | // If the start of the match is near the start of the EST, we do |
| 57 | // not need to search very far in the genome. |
| 58 | // |
| 59 | offset = 0; |
| 60 | if (qsLo < 50) |
| 61 | offset = 2000; |
| 62 | else |
| 63 | if (qsLo < 100) |
| 64 | offset = 5000; |
| 65 | else |
| 66 | offset = 50 * qsLo; |
| 67 | |
| 68 | if (dsLo < offset) |
| 69 | dsLo = 0; |
| 70 | else |
| 71 | dsLo -= offset; |
| 72 | |
| 73 | // Likewise, if the match is near the end of the EST, extend. We |
| 74 | // don't know the length of the genomic sequence, so we can't check |
| 75 | // for "overflow". |
| 76 | // |
| 77 | offset = _qsLencxx . . $ hitMatrix#_qsLen. - qsHi; |
| 78 | if (offset < 50) |
| 79 | dsHi += 2000; |
| 80 | else |
| 81 | if (offset < 100) |
| 82 | dsHi += 5000; |
| 83 | else |
| 84 | dsHi += 50 * offset; |
| 85 | } |
| 86 | |
| 87 | |
| 88 | |
| 89 | // Create a new match |
| 90 | // |
| 91 | // n = new match |
| 92 | // m = current match |
| 93 | // l = last match |
| 94 | // |
| 95 | trapMatchcxx . . $ trapMatch# *n = new trapMatchcxx . . $ trapMatch#(qsLo, qsHi, dsLo, dsHi, IL); |
| 96 | |
| 97 | |
| 98 | // And find a home for it in the list. No merging of matches is done here. It's |
| 99 | // too hard. |
| 100 | // |
| 101 | if ((_matchescxx . . $ hitMatrix#_matches. == 0L) || (n->_dsHicxx . . $ trapMatch#_dsHi. > _matchescxx . . $ hitMatrix#_matches.->_dsHicxx . . $ trapMatch#_dsHi.)) { |
| 102 | n->_nextcxx . . $ trapMatch#_next. = _matchescxx . . $ hitMatrix#_matches.; |
| 103 | _matchescxx . . $ hitMatrix#_matches. = n; |
| 104 | } else { |
| 105 | trapMatchcxx . . $ trapMatch# *l = _matchescxx . . $ hitMatrix#_matches.; |
| 106 | trapMatchcxx . . $ trapMatch# *m = _matchescxx . . $ hitMatrix#_matches.->_nextcxx . . $ trapMatch#_next.; |
| 107 | |
| 108 | while ((m) && (n->_dsHicxx . . $ trapMatch#_dsHi. < m->_dsHicxx . . $ trapMatch#_dsHi.)) { |
| 109 | l = m; |
| 110 | m = m->_nextcxx . . $ trapMatch#_next.; |
| 111 | } |
| 112 | |
| 113 | n->_nextcxx . . $ trapMatch#_next. = m; |
| 114 | l->_nextcxx . . $ trapMatch#_next. = n; |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | |
| 119 | // Utility for sorting the diagonal lines in the hitMatrix |
| 120 | // |
| 121 | // The two comparison functions return true if the first line |
| 122 | // is less than the second line. |
| 123 | |
| 124 | #ifdef WITHOUT_DIAGONALIDcxx . . $ `seagen/hitMatrix.H:28:9`! |
| 125 | |
| 126 | inline |
| 127 | int |
| 128 | compareLinescxx . . $ compareLines(b94d232718cef8d5).(diagonalLinecxx . . $ diagonalLine# *A, diagonalLinecxx . . $ diagonalLine# *B, uint32cxx . . $ uint32# qsLen) { |
| 129 | uint32cxx . . $ uint32# a = qsLen - A->_qsPoscxx . . $ diagonalLine#_qsPos. - 1 + A->_dsPoscxx . . $ diagonalLine#_dsPos.; |
| 130 | uint32cxx . . $ uint32# b = qsLen - B->_qsPoscxx . . $ diagonalLine#_qsPos. - 1 + B->_dsPoscxx . . $ diagonalLine#_dsPos.; |
| 131 | |
| 132 | return(((a < b)) || |
| 133 | ((a == b) && (A->_qsPoscxx . . $ diagonalLine#_qsPos. < B->_qsPoscxx . . $ diagonalLine#_qsPos.))); |
| 134 | } |
| 135 | |
| 136 | inline |
| 137 | int |
| 138 | compareLinescxx . . $ compareLines(676a4e832e1d5068).(uint32cxx . . $ uint32# l, uint32cxx . . $ uint32# q, diagonalLinecxx . . $ diagonalLine# *B, uint32cxx . . $ uint32# qsLen) { |
| 139 | uint32cxx . . $ uint32# b = qsLen - B->_qsPoscxx . . $ diagonalLine#_qsPos. - 1 + B->_dsPoscxx . . $ diagonalLine#_dsPos.; |
| 140 | |
| 141 | return(((l < b)) || |
| 142 | ((l == b) && (q < B->_qsPoscxx . . $ diagonalLine#_qsPos.))); |
| 143 | } |
| 144 | |
| 145 | inline |
| 146 | void |
| 147 | adjustHeapcxx . . $ adjustHeap(b88a07326068cf67).(diagonalLinecxx . . $ diagonalLine# *L, int32cxx . . $ int32# p, int32cxx . . $ int32# n, uint32cxx . . $ uint32# qsLen) { |
| 148 | uint32cxx . . $ uint32# q = L[p]._qsPoscxx . . $ diagonalLine#_qsPos.; |
| 149 | uint32cxx . . $ uint32# d = L[p]._dsPoscxx . . $ diagonalLine#_dsPos.; |
| 150 | uint32cxx . . $ uint32# l = qsLen - q - 1 + d; |
| 151 | int32cxx . . $ int32# c = (p << 1) + 1; // let c be the left child of p |
| 152 | |
| 153 | while (c < n) { |
| 154 | |
| 155 | // Find the larger of the two children |
| 156 | // |
| 157 | if ((c+1 < n) && compareLinescxx . . $ compareLines(b94d232718cef8d5).(L+c, L+c+1, qsLen)) |
| 158 | c++; |
| 159 | |
| 160 | // Does the node in question fit here? |
| 161 | // |
| 162 | if (compareLinescxx . . $ compareLines(676a4e832e1d5068).(l, q, L+c, qsLen) == false) |
| 163 | break; |
| 164 | |
| 165 | // Else, swap the parent and the child |
| 166 | // |
| 167 | L[p]._qsPoscxx . . $ diagonalLine#_qsPos. = L[c]._qsPoscxx . . $ diagonalLine#_qsPos.; |
| 168 | L[p]._dsPoscxx . . $ diagonalLine#_dsPos. = L[c]._dsPoscxx . . $ diagonalLine#_dsPos.; |
| 169 | |
| 170 | // Move down the tree |
| 171 | // |
| 172 | p = c; |
| 173 | c = (p << 1) + 1; |
| 174 | } |
| 175 | |
| 176 | L[p]._qsPoscxx . . $ diagonalLine#_qsPos. = q; |
| 177 | L[p]._dsPoscxx . . $ diagonalLine#_dsPos. = d; |
| 178 | } |
| 179 | |
| 180 | |
| 181 | #else // WITH_DIAGONALID |
| 182 | |
| 183 | |
| 184 | inline |
| 185 | int |
| 186 | compareLines(diagonalLine *A, diagonalLine *B) { |
| 187 | return(((A->_diagonalID < B->_diagonalID)) || |
| 188 | ((A->_diagonalID == B->_diagonalID) && (A->_qsPos < B->_qsPos))); |
| 189 | } |
| 190 | |
| 191 | inline |
| 192 | int |
| 193 | compareLines(uint32 l, uint32 q, diagonalLine *B) { |
| 194 | return(((l < B->_diagonalID)) || |
| 195 | ((l == B->_diagonalID) && (q < B->_qsPos))); |
| 196 | } |
| 197 | |
| 198 | inline |
| 199 | void |
| 200 | adjustHeap(diagonalLine *L, int32 p, int32 n) { |
| 201 | uint32 q = L[p]._qsPos; |
| 202 | uint32 d = L[p]._dsPos; |
| 203 | uint32 l = L[p]._diagonalID; |
| 204 | int32 c = (p << 1) + 1; // let c be the left child of p |
| 205 | |
| 206 | while (c < n) { |
| 207 | |
| 208 | // Find the larger of the two children |
| 209 | // |
| 210 | if ((c+1 < n) && compareLines(L+c, L+c+1)) |
| 211 | c++; |
| 212 | |
| 213 | // Does the node in question fit here? |
| 214 | // |
| 215 | if (compareLines(l, q, L+c) == false) |
| 216 | break; |
| 217 | |
| 218 | // Else, swap the parent and the child |
| 219 | // |
| 220 | L[p]._qsPos = L[c]._qsPos; |
| 221 | L[p]._dsPos = L[c]._dsPos; |
| 222 | L[p]._diagonalID = L[c]._diagonalID; |
| 223 | |
| 224 | // Move down the tree |
| 225 | // |
| 226 | p = c; |
| 227 | c = (p << 1) + 1; |
| 228 | } |
| 229 | |
| 230 | L[p]._qsPos = q; |
| 231 | L[p]._dsPos = d; |
| 232 | L[p]._diagonalID = l; |
| 233 | } |
| 234 | |
| 235 | |
| 236 | #endif |
| 237 | |
| 238 | void |
| 239 | hitMatrixcxx . . $ hitMatrix#::filtercxx . . $ hitMatrix#filter(ed2fd544d42a775a).(encodedQuerycxx . . $ encodedQuery# *query, bool isReverse) { |
| 240 | |
| 241 | if (_hitsLencxx . . $ hitMatrix#_hitsLen. == 0) |
| 242 | return; |
| 243 | |
| 244 | // Decide on the minimum quality values; we pick the larger of |
| 245 | // the fixed lengths, and the sequence length * coverage. |
| 246 | // |
| 247 | uint32cxx . . $ uint32# minLengthSingle = (uint32cxx . . $ uint32#)(configcxx . . $ config.._minCoverageSinglecxx . . $ configuration#_minCoverageSingle. * _qsLencxx . . $ hitMatrix#_qsLen.); |
| 248 | uint32cxx . . $ uint32# minLengthMultiple = (uint32cxx . . $ uint32#)(configcxx . . $ config.._minCoverageMultiplecxx . . $ configuration#_minCoverageMultiple. * _qsLencxx . . $ hitMatrix#_qsLen.); |
| 249 | |
| 250 | if (minLengthSingle < configcxx . . $ config.._minLengthSinglecxx . . $ configuration#_minLengthSingle.) |
| 251 | minLengthSingle = configcxx . . $ config.._minLengthSinglecxx . . $ configuration#_minLengthSingle.; |
| 252 | |
| 253 | if (minLengthMultiple < configcxx . . $ config.._minLengthMultiplecxx . . $ configuration#_minLengthMultiple.) |
| 254 | minLengthMultiple = configcxx . . $ config.._minLengthMultiplecxx . . $ configuration#_minLengthMultiple.; |
| 255 | |
| 256 | |
| 257 | |
| 258 | // First, sort by the dsPos. This is done so that we can find all the hits for |
| 259 | // a specific scaffold. |
| 260 | // |
| 261 | sort_dsPoscxx . . $ hitMatrix#sort_dsPos(49f6e7a06ebc5aa8).(); |
| 262 | |
| 263 | |
| 264 | // Now, while there are hits left.... |
| 265 | // |
| 266 | uint32cxx . . $ uint32# firstHit = 0; |
| 267 | uint32cxx . . $ uint32# lastHit = 0; |
| 268 | uint32cxx . . $ uint32# currentSeq = 0; |
| 269 | |
| 270 | while (firstHit < _hitsLencxx . . $ hitMatrix#_hitsLen.) { |
| 271 | |
| 272 | // Move the currentSeq until the firstHit is below it. |
| 273 | // |
| 274 | while ((currentSeq < configcxx . . $ config.._dbSTREAMcxx . . $ configuration#_dbSTREAM.->numberOfSequencescxx . . $ seqStream#numberOfSequences(db52760e79bf9054).()) && |
| 275 | (configcxx . . $ config.._dbSTREAMcxx . . $ configuration#_dbSTREAM.->startOfcxx . . $ seqStream#startOf(1892545c1754497d).(currentSeq) <= _hitscxx . . $ hitMatrix#_hits.[firstHit]._dsPoscxx . . $ diagonalLine#_dsPos.)) |
| 276 | currentSeq++; |
| 277 | |
| 278 | // |
| 279 | // currentSeq is now the sequence AFTER the one that we want hits in. |
| 280 | // |
| 281 | |
| 282 | // Find the first hit that is in currentSeq. If this is the last sequence, |
| 283 | // then, of course, all remaining hits are in it. |
| 284 | // |
| 285 | if (currentSeq < configcxx . . $ config.._dbSTREAMcxx . . $ configuration#_dbSTREAM.->numberOfSequencescxx . . $ seqStream#numberOfSequences(db52760e79bf9054).()) { |
| 286 | lastHit = firstHit + 1; |
| 287 | while ((lastHit < _hitsLencxx . . $ hitMatrix#_hitsLen.) && |
| 288 | (_hitscxx . . $ hitMatrix#_hits.[lastHit]._dsPoscxx . . $ diagonalLine#_dsPos. < configcxx . . $ config.._dbSTREAMcxx . . $ configuration#_dbSTREAM.->startOfcxx . . $ seqStream#startOf(1892545c1754497d).(currentSeq))) |
| 289 | lastHit++; |
| 290 | } else { |
| 291 | lastHit = _hitsLencxx . . $ hitMatrix#_hitsLen.; |
| 292 | } |
| 293 | |
| 294 | // Drop back one sequence; this is the sequence the hits are in. |
| 295 | // |
| 296 | currentSeq--; |
| 297 | |
| 298 | #if TRACEcxx . . $ `seagen/hitMatrix.C:4:9`! |
| 299 | fprintf(stdout, "Hits are in sequence %d\n", config._dbSTREAM->IIDOf(currentSeq)); |
| 300 | fprintf(stdout, "filtering %u hits -- first = %u last = %u.\n", _hitsLen, firstHit, lastHit); |
| 301 | |
| 302 | #if 0 |
| 303 | fprintf(stdout, "UNSORTED\n"); |
| 304 | for (uint32 i=firstHit; i<lastHit; i++) |
| 305 | fprintf(stdout, "hit at qs=%4u ds=%6u diag=%6u\n", |
| 306 | _hits[i]._qsPos, |
| 307 | _hits[i]._dsPos, |
| 308 | _hits[i]._diagonalID); |
| 309 | #endif |
| 310 | #endif |
| 311 | |
| 312 | // Adjust the hits to be relative to the start of this sequence |
| 313 | // |
| 314 | for (uint32cxx . . $ uint32# i=firstHit; i<lastHit; i++) |
| 315 | _hitscxx . . $ hitMatrix#_hits.[i]._dsPoscxx . . $ diagonalLine#_dsPos. -= configcxx . . $ config.._dbSTREAMcxx . . $ configuration#_dbSTREAM.->startOfcxx . . $ seqStream#startOf(1892545c1754497d).(currentSeq); |
| 316 | |
| 317 | // Sort them, if needed. |
| 318 | // |
| 319 | if (lastHit - firstHit > 1) { |
| 320 | |
| 321 | // We cheat; heapsort isn't too friendly to sorting the middle of |
| 322 | // an array, so we make a new array in the middle! |
| 323 | // |
| 324 | diagonalLinecxx . . $ diagonalLine# *hitsToSort = _hitscxx . . $ hitMatrix#_hits. + firstHit; |
| 325 | |
| 326 | // Build the heap. I initially thought this could be done at the |
| 327 | // same time as the scan for the last hit, but it can't (easily) |
| 328 | // |
| 329 | for (int32cxx . . $ int32# i=(lastHit - firstHit)/2 - 1; i>=0; i--) |
| 330 | #ifdef WITHOUT_DIAGONALIDcxx . . $ `seagen/hitMatrix.H:28:9`! |
| 331 | adjustHeapcxx . . $ adjustHeap(b88a07326068cf67).(hitsToSort, i, lastHit - firstHit, _qsLencxx . . $ hitMatrix#_qsLen.); |
| 332 | #else |
| 333 | adjustHeap(hitsToSort, i, lastHit - firstHit); |
| 334 | #endif |
| 335 | |
| 336 | // Sort the hits be diagonal. This is the second part of |
| 337 | // heap sort -- Interchange the new maximum with the element |
| 338 | // at the end of the tree |
| 339 | // |
| 340 | for (uint32cxx . . $ uint32# i=lastHit - firstHit - 1; i>0; i--) { |
| 341 | uint32cxx . . $ uint32# q = hitsToSort[i]._qsPoscxx . . $ diagonalLine#_qsPos.; |
| 342 | uint32cxx . . $ uint32# d = hitsToSort[i]._dsPoscxx . . $ diagonalLine#_dsPos.; |
| 343 | #ifndef WITHOUT_DIAGONALIDcxx . . $ `seagen/hitMatrix.H:28:9`! |
| 344 | uint32 l = hitsToSort[i]._diagonalID; |
| 345 | #endif |
| 346 | |
| 347 | hitsToSort[i]._qsPoscxx . . $ diagonalLine#_qsPos. = hitsToSort[0]._qsPoscxx . . $ diagonalLine#_qsPos.; |
| 348 | hitsToSort[i]._dsPoscxx . . $ diagonalLine#_dsPos. = hitsToSort[0]._dsPoscxx . . $ diagonalLine#_dsPos.; |
| 349 | #ifndef WITHOUT_DIAGONALIDcxx . . $ `seagen/hitMatrix.H:28:9`! |
| 350 | hitsToSort[i]._diagonalID = hitsToSort[0]._diagonalID; |
| 351 | #endif |
| 352 | |
| 353 | hitsToSort[0]._qsPoscxx . . $ diagonalLine#_qsPos. = q; |
| 354 | hitsToSort[0]._dsPoscxx . . $ diagonalLine#_dsPos. = d; |
| 355 | #ifndef WITHOUT_DIAGONALIDcxx . . $ `seagen/hitMatrix.H:28:9`! |
| 356 | hitsToSort[0]._diagonalID = l; |
| 357 | #endif |
| 358 | |
| 359 | #ifdef WITHOUT_DIAGONALIDcxx . . $ `seagen/hitMatrix.H:28:9`! |
| 360 | adjustHeapcxx . . $ adjustHeap(b88a07326068cf67).(hitsToSort, 0, i, _qsLencxx . . $ hitMatrix#_qsLen.); |
| 361 | #else |
| 362 | adjustHeap(hitsToSort, 0, i); |
| 363 | #endif |
| 364 | } |
| 365 | } |
| 366 | |
| 367 | |
| 368 | // Check the sorting |
| 369 | // |
| 370 | #if 0 |
| 371 | #if 0 |
| 372 | fprintf(stderr, "sort by diagonal:\n"); |
| 373 | for (uint32 i=firstHit; i<lastHit; i++) |
| 374 | fprintf(stderr, "%8u %8u %8u\n", _hits[i]._diagonalID, _hits[i]._qsPos, _hits[i]._dsPos); |
| 375 | #endif |
| 376 | for (uint32 i=firstHit; i<lastHit-1; i++) { |
| 377 | if (_hits[i]._diagonalID > _hits[i+1]._diagonalID) { |
| 378 | fprintf(stderr, "sort by diagonal failed.\n"); |
| 379 | exit(1); |
| 380 | } |
| 381 | } |
| 382 | #endif |
| 383 | |
| 384 | |
| 385 | |
| 386 | #if TRACEcxx . . $ `seagen/hitMatrix.C:4:9`! |
| 387 | #if 0 |
| 388 | fprintf(stdout, "SORTED\n"); |
| 389 | for (uint32 i=firstHit; i<lastHit; i++) |
| 390 | fprintf(stdout, "hit at qs=%4u ds=%6u diag=%6u\n", |
| 391 | _hits[i]._qsPos, |
| 392 | _hits[i]._dsPos, |
| 393 | _hits[i]._diagonalID); |
| 394 | #endif |
| 395 | |
| 396 | fprintf(stdout, "FILTERED\n"); |
| 397 | #endif |
| 398 | |
| 399 | // Filter them |
| 400 | // |
| 401 | #ifdef WITHOUT_DIAGONALIDcxx . . $ `seagen/hitMatrix.H:28:9`! |
| 402 | uint32cxx . . $ uint32# frstDiagonal = _qsLencxx . . $ hitMatrix#_qsLen. - _hitscxx . . $ hitMatrix#_hits.[firstHit]._qsPoscxx . . $ diagonalLine#_qsPos. - 1 + _hitscxx . . $ hitMatrix#_hits.[firstHit]._dsPoscxx . . $ diagonalLine#_dsPos.; |
| 403 | uint32cxx . . $ uint32# lastDiagonal = frstDiagonal; |
| 404 | #else |
| 405 | uint32 frstDiagonal = _hits[firstHit]._diagonalID; |
| 406 | uint32 lastDiagonal = _hits[firstHit]._diagonalID; |
| 407 | #endif |
| 408 | uint32cxx . . $ uint32# qsLow = _hitscxx . . $ hitMatrix#_hits.[firstHit]._qsPoscxx . . $ diagonalLine#_qsPos.; |
| 409 | uint32cxx . . $ uint32# qsHigh = _hitscxx . . $ hitMatrix#_hits.[firstHit]._qsPoscxx . . $ diagonalLine#_qsPos.; |
| 410 | uint32cxx . . $ uint32# dsLow = _hitscxx . . $ hitMatrix#_hits.[firstHit]._dsPoscxx . . $ diagonalLine#_dsPos.; |
| 411 | uint32cxx . . $ uint32# dsHigh = _hitscxx . . $ hitMatrix#_hits.[firstHit]._dsPoscxx . . $ diagonalLine#_dsPos.; |
| 412 | |
| 413 | // Create a new merCovering, and space to count the number of mers in a match |
| 414 | // |
| 415 | merCoveringcxx . . $ merCovering# *IL = new merCoveringcxx . . $ merCovering#(configcxx . . $ config.._merSizecxx . . $ configuration#_merSize.); |
| 416 | |
| 417 | for (uint32cxx . . $ uint32# i=firstHit; i<lastHit; i++) { |
| 418 | #ifdef WITHOUT_DIAGONALIDcxx . . $ `seagen/hitMatrix.H:28:9`! |
| 419 | uint32cxx . . $ uint32# thisDiagonalID = _qsLencxx . . $ hitMatrix#_qsLen. - _hitscxx . . $ hitMatrix#_hits.[i]._qsPoscxx . . $ diagonalLine#_qsPos. - 1 + _hitscxx . . $ hitMatrix#_hits.[i]._dsPoscxx . . $ diagonalLine#_dsPos.; |
| 420 | #else |
| 421 | uint32 thisDiagonalID = _hits[i]._diagonalID; |
| 422 | #endif |
| 423 | |
| 424 | |
| 425 | |
| 426 | #if TRACEcxx . . $ `seagen/hitMatrix.C:4:9`! |
| 427 | fprintf(stdout, "hit[qs=%6u ds=%7u d=%7u] box[qs=%6u-%6u ds=%7u-%7u d=%7u-%7u] ", |
| 428 | _hits[i]._qsPos, |
| 429 | _hits[i]._dsPos, |
| 430 | thisDiagonalID, |
| 431 | qsLow, qsHigh, dsLow, dsHigh, frstDiagonal, lastDiagonal); |
| 432 | #endif |
| 433 | |
| 434 | // Unconditionally extend if the diagonal difference is small. |
| 435 | // |
| 436 | if (lastDiagonal + configcxx . . $ config.._maxDiagonalcxx . . $ configuration#_maxDiagonal. >= thisDiagonalID) { |
| 437 | lastDiagonal = thisDiagonalID; |
| 438 | if (qsLow > _hitscxx . . $ hitMatrix#_hits.[i]._qsPoscxx . . $ diagonalLine#_qsPos.) qsLow = _hitscxx . . $ hitMatrix#_hits.[i]._qsPoscxx . . $ diagonalLine#_qsPos.; |
| 439 | if (qsHigh < _hitscxx . . $ hitMatrix#_hits.[i]._qsPoscxx . . $ diagonalLine#_qsPos.) qsHigh = _hitscxx . . $ hitMatrix#_hits.[i]._qsPoscxx . . $ diagonalLine#_qsPos.; |
| 440 | if (dsLow > _hitscxx . . $ hitMatrix#_hits.[i]._dsPoscxx . . $ diagonalLine#_dsPos.) dsLow = _hitscxx . . $ hitMatrix#_hits.[i]._dsPoscxx . . $ diagonalLine#_dsPos.; |
| 441 | if (dsHigh < _hitscxx . . $ hitMatrix#_hits.[i]._dsPoscxx . . $ diagonalLine#_dsPos.) dsHigh = _hitscxx . . $ hitMatrix#_hits.[i]._dsPoscxx . . $ diagonalLine#_dsPos.; |
| 442 | IL->addMercxx . . $ merCovering#addMer(cb2f890c2fdad230).(_hitscxx . . $ hitMatrix#_hits.[i]._qsPoscxx . . $ diagonalLine#_qsPos.); |
| 443 | #if TRACEcxx . . $ `seagen/hitMatrix.C:4:9`! |
| 444 | fprintf(stdout, "extend qs=%9u-%9u ds=%9u-%9u diag=%9u-%9u (diagonal)\n", |
| 445 | qsLow, qsHigh, dsLow, dsHigh, frstDiagonal, lastDiagonal); |
| 446 | #endif |
| 447 | continue; |
| 448 | } |
| 449 | |
| 450 | |
| 451 | // XXX: Prototype for extending only if the next hit is near |
| 452 | // the last hit. |
| 453 | // |
| 454 | if (((dsHigh <= _hitscxx . . $ hitMatrix#_hits.[i]._dsPoscxx . . $ diagonalLine#_dsPos.) && (_hitscxx . . $ hitMatrix#_hits.[i]._dsPoscxx . . $ diagonalLine#_dsPos. - dsHigh <= configcxx . . $ config.._maxIntronLengthcxx . . $ configuration#_maxIntronLength.)) || |
| 455 | ((dsHigh >= _hitscxx . . $ hitMatrix#_hits.[i]._dsPoscxx . . $ diagonalLine#_dsPos.) && (dsHigh - _hitscxx . . $ hitMatrix#_hits.[i]._dsPoscxx . . $ diagonalLine#_dsPos. <= configcxx . . $ config.._maxIntronLengthcxx . . $ configuration#_maxIntronLength.))) { |
| 456 | |
| 457 | // Extend into multiple-exon like things only if the input |
| 458 | // sequence is long. |
| 459 | // |
| 460 | if (_qsLencxx . . $ hitMatrix#_qsLen. > configcxx . . $ config.._smallSequenceCutoffcxx . . $ configuration#_smallSequenceCutoff.) { |
| 461 | |
| 462 | // Extend if the qsOverlap is small (or nonexistant) |
| 463 | // |
| 464 | if ((qsHigh + configcxx . . $ config.._merSizecxx . . $ configuration#_merSize.) < (_hitscxx . . $ hitMatrix#_hits.[i]._qsPoscxx . . $ diagonalLine#_qsPos. + configcxx . . $ config.._qsOverlapcxx . . $ configuration#_qsOverlap.)) { |
| 465 | lastDiagonal = thisDiagonalID; |
| 466 | if (qsLow > _hitscxx . . $ hitMatrix#_hits.[i]._qsPoscxx . . $ diagonalLine#_qsPos.) qsLow = _hitscxx . . $ hitMatrix#_hits.[i]._qsPoscxx . . $ diagonalLine#_qsPos.; |
| 467 | if (qsHigh < _hitscxx . . $ hitMatrix#_hits.[i]._qsPoscxx . . $ diagonalLine#_qsPos.) qsHigh = _hitscxx . . $ hitMatrix#_hits.[i]._qsPoscxx . . $ diagonalLine#_qsPos.; |
| 468 | if (dsLow > _hitscxx . . $ hitMatrix#_hits.[i]._dsPoscxx . . $ diagonalLine#_dsPos.) dsLow = _hitscxx . . $ hitMatrix#_hits.[i]._dsPoscxx . . $ diagonalLine#_dsPos.; |
| 469 | if (dsHigh < _hitscxx . . $ hitMatrix#_hits.[i]._dsPoscxx . . $ diagonalLine#_dsPos.) dsHigh = _hitscxx . . $ hitMatrix#_hits.[i]._dsPoscxx . . $ diagonalLine#_dsPos.; |
| 470 | IL->addMercxx . . $ merCovering#addMer(cb2f890c2fdad230).(_hitscxx . . $ hitMatrix#_hits.[i]._qsPoscxx . . $ diagonalLine#_qsPos.); |
| 471 | #if TRACEcxx . . $ `seagen/hitMatrix.C:4:9`! |
| 472 | fprintf(stdout, "extend qs=%9u-%9u ds=%9u-%9u diag=%9u-%9u (qsOverlap)\n", |
| 473 | qsLow, qsHigh, dsLow, dsHigh, frstDiagonal, lastDiagonal); |
| 474 | #endif |
| 475 | continue; |
| 476 | } |
| 477 | |
| 478 | // Extend if the dsOverlap is small (or nonexistant) |
| 479 | // |
| 480 | if (_hitscxx . . $ hitMatrix#_hits.[i]._dsPoscxx . . $ diagonalLine#_dsPos. < (dsLow + configcxx . . $ config.._dsOverlapcxx . . $ configuration#_dsOverlap.)) { |
| 481 | lastDiagonal = thisDiagonalID; |
| 482 | if (qsLow > _hitscxx . . $ hitMatrix#_hits.[i]._qsPoscxx . . $ diagonalLine#_qsPos.) qsLow = _hitscxx . . $ hitMatrix#_hits.[i]._qsPoscxx . . $ diagonalLine#_qsPos.; |
| 483 | if (qsHigh < _hitscxx . . $ hitMatrix#_hits.[i]._qsPoscxx . . $ diagonalLine#_qsPos.) qsHigh = _hitscxx . . $ hitMatrix#_hits.[i]._qsPoscxx . . $ diagonalLine#_qsPos.; |
| 484 | if (dsLow > _hitscxx . . $ hitMatrix#_hits.[i]._dsPoscxx . . $ diagonalLine#_dsPos.) dsLow = _hitscxx . . $ hitMatrix#_hits.[i]._dsPoscxx . . $ diagonalLine#_dsPos.; |
| 485 | if (dsHigh < _hitscxx . . $ hitMatrix#_hits.[i]._dsPoscxx . . $ diagonalLine#_dsPos.) dsHigh = _hitscxx . . $ hitMatrix#_hits.[i]._dsPoscxx . . $ diagonalLine#_dsPos.; |
| 486 | IL->addMercxx . . $ merCovering#addMer(cb2f890c2fdad230).(_hitscxx . . $ hitMatrix#_hits.[i]._qsPoscxx . . $ diagonalLine#_qsPos.); |
| 487 | #if TRACEcxx . . $ `seagen/hitMatrix.C:4:9`! |
| 488 | fprintf(stdout, "extend qs=%9u-%9u ds=%9u-%9u diag=%9u-%9u (dsOverlap)\n", |
| 489 | qsLow, qsHigh, dsLow, dsHigh, frstDiagonal, lastDiagonal); |
| 490 | #endif |
| 491 | continue; |
| 492 | } |
| 493 | } |
| 494 | } // XXX: End prototype |
| 495 | |
| 496 | #if TRACEcxx . . $ `seagen/hitMatrix.C:4:9`! |
| 497 | fprintf(stdout, "close current cluster.\nGOOD? qsCov=%u; >= %u or %u? diag: %u < 25?\n", |
| 498 | qsHigh - qsLow, |
| 499 | minLengthSingle, |
| 500 | minLengthMultiple, |
| 501 | lastDiagonal - frstDiagonal); |
| 502 | #endif |
| 503 | |
| 504 | |
| 505 | // Save the current cluster and start a new one? |
| 506 | // |
| 507 | uint32cxx . . $ uint32# qCov = IL->sumOfLengthscxx . . $ merCovering#sumOfLengths(db52760e79bf9054).(); |
| 508 | if ((qCov >= minLengthMultiple) || |
| 509 | ((lastDiagonal - frstDiagonal < 25) && (qCov >= minLengthSingle))) { |
| 510 | #if TRACEcxx . . $ `seagen/hitMatrix.C:4:9`! |
| 511 | fprintf(stdout, "add match!\n"); |
| 512 | #endif |
| 513 | addMatchcxx . . $ hitMatrix#addMatch(be234fe48972ff86).(qsLow, |
| 514 | qsHigh + configcxx . . $ config.._merSizecxx . . $ configuration#_merSize., |
| 515 | dsLow, |
| 516 | dsHigh + configcxx . . $ config.._merSizecxx . . $ configuration#_merSize., |
| 517 | IL); |
| 518 | IL = new merCoveringcxx . . $ merCovering#(configcxx . . $ config.._merSizecxx . . $ configuration#_merSize.); |
| 519 | } |
| 520 | |
| 521 | if (IL) |
| 522 | IL->clearcxx . . $ merCovering#clear(49f6e7a06ebc5aa8).(); |
| 523 | |
| 524 | #if TRACEcxx . . $ `seagen/hitMatrix.C:4:9`! |
| 525 | fprintf(stdout, "reset!\n"); |
| 526 | #endif |
| 527 | |
| 528 | frstDiagonal = thisDiagonalID; |
| 529 | lastDiagonal = thisDiagonalID; |
| 530 | qsLow = _hitscxx . . $ hitMatrix#_hits.[i]._qsPoscxx . . $ diagonalLine#_qsPos.; |
| 531 | qsHigh = _hitscxx . . $ hitMatrix#_hits.[i]._qsPoscxx . . $ diagonalLine#_qsPos.; |
| 532 | dsLow = _hitscxx . . $ hitMatrix#_hits.[i]._dsPoscxx . . $ diagonalLine#_dsPos.; |
| 533 | dsHigh = _hitscxx . . $ hitMatrix#_hits.[i]._dsPoscxx . . $ diagonalLine#_dsPos.; |
| 534 | |
| 535 | #if TRACEcxx . . $ `seagen/hitMatrix.C:4:9`! |
| 536 | fprintf(stdout, "hit[qs=%6u ds=%7u d=%7u] box[qs=%6u-%6u ds=%7u-%7u d=%7u-%7u] (initial hit)\n", |
| 537 | _hits[i]._qsPos, |
| 538 | _hits[i]._dsPos, |
| 539 | _qsLen - _hits[i]._qsPos - 1 + _hits[i]._dsPos, |
| 540 | qsLow, qsHigh, dsLow, dsHigh, frstDiagonal, lastDiagonal); |
| 541 | #endif |
| 542 | |
| 543 | IL->addMercxx . . $ merCovering#addMer(cb2f890c2fdad230).(_hitscxx . . $ hitMatrix#_hits.[i]._qsPoscxx . . $ diagonalLine#_qsPos.); |
| 544 | } |
| 545 | |
| 546 | // Save the final cluster? |
| 547 | // |
| 548 | uint32cxx . . $ uint32# qCov = IL->sumOfLengthscxx . . $ merCovering#sumOfLengths(db52760e79bf9054).(); |
| 549 | if ((qCov >= minLengthMultiple) || |
| 550 | ((lastDiagonal - frstDiagonal < 21) && (qCov >= minLengthSingle))) { |
| 551 | addMatchcxx . . $ hitMatrix#addMatch(be234fe48972ff86).(qsLow, |
| 552 | qsHigh + configcxx . . $ config.._merSizecxx . . $ configuration#_merSize., |
| 553 | dsLow, |
| 554 | dsHigh + configcxx . . $ config.._merSizecxx . . $ configuration#_merSize., |
| 555 | IL); |
| 556 | IL = 0; |
| 557 | } |
| 558 | |
| 559 | // Delete any remaining IL |
| 560 | // |
| 561 | delete IL; |
| 562 | |
| 563 | |
| 564 | |
| 565 | // Merge and print the matches |
| 566 | // |
| 567 | trapMatchcxx . . $ trapMatch# *n = 0L; |
| 568 | uint32cxx . . $ uint32# ML = 0; |
| 569 | |
| 570 | while (_matchescxx . . $ hitMatrix#_matches.) { |
| 571 | |
| 572 | // Save the current match, then delete it. |
| 573 | // |
| 574 | dsLow = _matchescxx . . $ hitMatrix#_matches.->_dsLocxx . . $ trapMatch#_dsLo.; |
| 575 | dsHigh = _matchescxx . . $ hitMatrix#_matches.->_dsHicxx . . $ trapMatch#_dsHi.; |
| 576 | IL = _matchescxx . . $ hitMatrix#_matches.->_ILcxx . . $ trapMatch#_IL.; |
| 577 | ML = IL->sumOfLengthscxx . . $ merCovering#sumOfLengths(db52760e79bf9054).(); |
| 578 | |
| 579 | n = _matchescxx . . $ hitMatrix#_matches.; |
| 580 | _matchescxx . . $ hitMatrix#_matches. = _matchescxx . . $ hitMatrix#_matches.->_nextcxx . . $ trapMatch#_next.; |
| 581 | delete n; |
| 582 | |
| 583 | #if TRACEcxx . . $ `seagen/hitMatrix.C:4:9`! |
| 584 | fprintf(stdout, "Merge: %8u %8u\n", dsLow, dsHigh); |
| 585 | #endif |
| 586 | |
| 587 | // Assimilate as many of the remaining matches as possible. |
| 588 | // |
| 589 | // Think of this as first reversing the list, then merging as |
| 590 | // long as (dsHigh + 1000 > _matches->_dsLo). But since we |
| 591 | // don't reverse the list, we can map: |
| 592 | // dsHigh --> _matches->dsHi |
| 593 | // _matches->_dsLo --> dsLow |
| 594 | // where dsHigh and dsLow are the values for the extended match. |
| 595 | // |
| 596 | while (_matchescxx . . $ hitMatrix#_matches. && (dsLow < _matchescxx . . $ hitMatrix#_matches.->_dsHicxx . . $ trapMatch#_dsHi. + 5000)) { |
| 597 | |
| 598 | // Combine the two merCoverings |
| 599 | // |
| 600 | IL->mergecxx . . $ merCovering#merge(aef64fd763bc9478).(_matchescxx . . $ hitMatrix#_matches.->_ILcxx . . $ trapMatch#_IL.); |
| 601 | ML += _matchescxx . . $ hitMatrix#_matches.->_ILcxx . . $ trapMatch#_IL.->sumOfLengthscxx . . $ merCovering#sumOfLengths(db52760e79bf9054).(); |
| 602 | |
| 603 | // The start of the new match might be after the start of the |
| 604 | // merged region. (Only rarely is it before) |
| 605 | // |
| 606 | if (dsLow > _matchescxx . . $ hitMatrix#_matches.->_dsLocxx . . $ trapMatch#_dsLo.) |
| 607 | dsLow = _matchescxx . . $ hitMatrix#_matches.->_dsLocxx . . $ trapMatch#_dsLo.; |
| 608 | |
| 609 | // The end of current match is always greater than the end of the |
| 610 | // new match! |
| 611 | // |
| 612 | //dsHigh = _matches->_dsHi; |
| 613 | |
| 614 | #if TRACEcxx . . $ `seagen/hitMatrix.C:4:9`! |
| 615 | fprintf(stdout, "Merge: %8u %8u -> %8u %8u\n", _matches->_dsLo, _matches->_dsHi, dsLow, dsHigh); |
| 616 | #endif |
| 617 | |
| 618 | n = _matchescxx . . $ hitMatrix#_matches.; |
| 619 | _matchescxx . . $ hitMatrix#_matches. = _matchescxx . . $ hitMatrix#_matches.->_nextcxx . . $ trapMatch#_next.; |
| 620 | delete n->_ILcxx . . $ trapMatch#_IL.; |
| 621 | delete n; |
| 622 | } |
| 623 | |
| 624 | |
| 625 | if (configcxx . . $ config.._binaryOutputcxx . . $ configuration#_binaryOutput.) { |
| 626 | aHitcxx . . $ aHit# a; |
| 627 | |
| 628 | a._forwardcxx . . $ aHit#_forward. = !isReverse; |
| 629 | a._mergedcxx . . $ aHit#_merged. = false; |
| 630 | a._qsIdxcxx . . $ aHit#_qsIdx. = _qsIdxcxx . . $ hitMatrix#_qsIdx.; |
| 631 | a._dsIdxcxx . . $ aHit#_dsIdx. = configcxx . . $ config.._dbSTREAMcxx . . $ configuration#_dbSTREAM.->IIDOfcxx . . $ seqStream#IIDOf(2141b656ce2cc063).(currentSeq); |
| 632 | a._dsLocxx . . $ aHit#_dsLo. = dsLow; |
| 633 | a._dsHicxx . . $ aHit#_dsHi. = dsHigh; |
| 634 | a._coveredcxx . . $ aHit#_covered. = IL->sumOfLengthscxx . . $ merCovering#sumOfLengths(db52760e79bf9054).(); |
| 635 | a._matchedcxx . . $ aHit#_matched. = ML; |
| 636 | a._numMerscxx . . $ aHit#_numMers. = _qsMerscxx . . $ hitMatrix#_qsMers.; |
| 637 | |
| 638 | query->addOutputcxx . . $ encodedQuery#addOutput(67abb4dd43ac34c5).(&a, sizeof(aHitcxx . . $ aHit#)); |
| 639 | } else { |
| 640 | char line[128]; |
| 641 | |
| 642 | sprintf(line, "-%c -e "uint32FMTcxx . . $ `libutil/util.h:65:10`!" -D "uint32FMTcxx . . $ `libutil/util.h:65:10`!" "uint32FMTcxx . . $ `libutil/util.h:65:10`!" "uint32FMTcxx . . $ `libutil/util.h:65:10`!" -M "uint32FMTcxx . . $ `libutil/util.h:65:10`!" "uint32FMTcxx . . $ `libutil/util.h:65:10`!" "uint32FMTcxx . . $ `libutil/util.h:65:10`!"\n", |
| 643 | isReverse ? 'r' : 'f', _qsIdxcxx . . $ hitMatrix#_qsIdx., |
| 644 | configcxx . . $ config.._dbSTREAMcxx . . $ configuration#_dbSTREAM.->IIDOfcxx . . $ seqStream#IIDOf(2141b656ce2cc063).(currentSeq), |
| 645 | dsLow, dsHigh, IL->sumOfLengthscxx . . $ merCovering#sumOfLengths(db52760e79bf9054).(), ML, _qsMerscxx . . $ hitMatrix#_qsMers.); |
| 646 | |
| 647 | query->addOutputcxx . . $ encodedQuery#addOutput(67abb4dd43ac34c5).(line, 0); |
| 648 | } |
| 649 | |
| 650 | delete IL; |
| 651 | } |
| 652 | |
| 653 | // All done with these hits. Move to the next set. |
| 654 | // |
| 655 | firstHit = lastHit; |
| 656 | } |
| 657 | } |
| 658 |