| 1 | // This file is part of A2Amapper.cxx . . $ `<file>/atac-driver/uniqueFilter/uniqueFilter.C`/ |
| 2 | // Copyright (c) 2005 J. Craig Venter Institute |
| 3 | // Author: Brian Walenz |
| 4 | // |
| 5 | // This program is free software; you can redistribute it and/or modify |
| 6 | // it under the terms of the GNU General Public License as published by |
| 7 | // the Free Software Foundation; either version 2 of the License, or |
| 8 | // (at your option) any later version. |
| 9 | // |
| 10 | // This program is distributed in the hope that it will be useful, |
| 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | // GNU General Public License for more details. |
| 14 | // |
| 15 | // You should have received (LICENSE.txt) a copy of the GNU General Public |
| 16 | // License along with this program; if not, write to the Free Software |
| 17 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 18 | |
| 19 | #include <stdio.h> |
| 20 | #include <stdlib.h> |
| 21 | #include <time.h> |
| 22 | |
| 23 | #include "util++.H"cxx . . $ `<file>/libutil/util++.H`/ |
| 24 | #include "atac.H"cxx . . $ `<file>/atac-driver/libatac/atac.H`/ |
| 25 | |
| 26 | // Kaz Kylheku <[email protected]> library. |
| 27 | #include "kazlib/dict.h"cxx . . $ `<file>/libutil/kazlib/dict.h`/ |
| 28 | #include "kazlib/except.h"cxx . . $ `<file>/libutil/kazlib/except.h`/ |
| 29 | #include "kazlib/hash.h"cxx . . $ `<file>/libutil/kazlib/hash.h`/ |
| 30 | #include "kazlib/list.h"cxx . . $ `<file>/libutil/kazlib/list.h`/ |
| 31 | #include "kazlib/sfx.h"cxx . . $ `<file>/libutil/kazlib/sfx.h`/ |
| 32 | |
| 33 | // Filters out matches that have non-unique pieces. Does not discard |
| 34 | // the whole match, but just trims out the non-unique section. |
| 35 | // |
| 36 | // Original implementation in Python by Clark Mobarry: |
| 37 | // |
| 38 | // sort the matches in X |
| 39 | // apply the mask to the X |
| 40 | // sort the matchs in Y |
| 41 | // apply the mask to the Y |
| 42 | // output the matches |
| 43 | // |
| 44 | // if we keep the coverage intervals in core, we get around sorting |
| 45 | // the matches. how big can they be -- especially if we only keep |
| 46 | // things with > 1 coverage! But, we also can't use an elegant |
| 47 | // algorithm for trimming/splitting. |
| 48 | |
| 49 | |
| 50 | // We can abuse this to subtract matches from other matches. The |
| 51 | // operation done for removing non-unique is to first find any |
| 52 | // overlapping intervals in the set, then subract those from the |
| 53 | // input. If we instead just find all intervals in a set of matches, |
| 54 | // and subtract those from the input, we get subtraction. |
| 55 | |
| 56 | |
| 57 | // Reads the input, builds an interval list of the regions |
| 58 | // that have coverage > 1. |
| 59 | // |
| 60 | struct coverage1_scxx . . $ coverage1_s# { |
| 61 | uint32cxx . . $ uint32# axiscxx . . $ coverage1_s#axis.; |
| 62 | uint32cxx . . $ uint32# positioncxx . . $ coverage1_s#position.; |
| 63 | int incrementcxx . . $ coverage1_s#increment.; |
| 64 | }; |
| 65 | |
| 66 | struct coverage2_scxx . . $ coverage2_s# { |
| 67 | uint32cxx . . $ uint32# axiscxx . . $ coverage2_s#axis.; |
| 68 | uint32cxx . . $ uint32# begcxx . . $ coverage2_s#beg.; |
| 69 | uint32cxx . . $ uint32# endcxx . . $ coverage2_s#end.; |
| 70 | uint32cxx . . $ uint32# coveragecxx . . $ coverage2_s#coverage.; |
| 71 | }; |
| 72 | |
| 73 | struct match_scxx . . $ match_s# { |
| 74 | uint32cxx . . $ uint32# iid1cxx . . $ match_s#iid1., pos1cxx . . $ match_s#pos1., len1cxx . . $ match_s#len1., ori1cxx . . $ match_s#ori1.; |
| 75 | uint32cxx . . $ uint32# iid2cxx . . $ match_s#iid2., pos2cxx . . $ match_s#pos2., len2cxx . . $ match_s#len2., ori2cxx . . $ match_s#ori2.; |
| 76 | }; |
| 77 | |
| 78 | int |
| 79 | sortCoverage1cxx . . $ sortCoverage1(9148c8c3ff42c9d8).(const void *a, const void *b) { |
| 80 | const coverage1_scxx . . $ coverage1_s# *A = *((const coverage1_scxx . . $ coverage1_s# * const *)a); |
| 81 | const coverage1_scxx . . $ coverage1_s# *B = *((const coverage1_scxx . . $ coverage1_s# * const *)b); |
| 82 | |
| 83 | if (A->axiscxx . . $ coverage1_s#axis. < B->axiscxx . . $ coverage1_s#axis.) return(-1); |
| 84 | if (A->axiscxx . . $ coverage1_s#axis. > B->axiscxx . . $ coverage1_s#axis.) return(1); |
| 85 | if (A->positioncxx . . $ coverage1_s#position. < B->positioncxx . . $ coverage1_s#position.) return(-1); |
| 86 | if (A->positioncxx . . $ coverage1_s#position. > B->positioncxx . . $ coverage1_s#position.) return(1); |
| 87 | if (A->incrementcxx . . $ coverage1_s#increment. > B->incrementcxx . . $ coverage1_s#increment.) return(-1); |
| 88 | if (A->incrementcxx . . $ coverage1_s#increment. < B->incrementcxx . . $ coverage1_s#increment.) return(1); |
| 89 | return(0); |
| 90 | } |
| 91 | |
| 92 | |
| 93 | // Not a complete comparison, but we only use this for an interval |
| 94 | // list. |
| 95 | // |
| 96 | int |
| 97 | sortCoverage2cxx . . $ sortCoverage2(9148c8c3ff42c9d8).(const void *a, const void *b) { |
| 98 | const coverage2_scxx . . $ coverage2_s# *A = *((const coverage2_scxx . . $ coverage2_s# * const *)a); |
| 99 | const coverage2_scxx . . $ coverage2_s# *B = *((const coverage2_scxx . . $ coverage2_s# * const *)b); |
| 100 | |
| 101 | if (A->axiscxx . . $ coverage2_s#axis. < B->axiscxx . . $ coverage2_s#axis.) return(-1); |
| 102 | if (A->axiscxx . . $ coverage2_s#axis. > B->axiscxx . . $ coverage2_s#axis.) return(1); |
| 103 | if (A->begcxx . . $ coverage2_s#beg. < B->begcxx . . $ coverage2_s#beg.) return(-1); |
| 104 | if (A->begcxx . . $ coverage2_s#beg. > B->begcxx . . $ coverage2_s#beg.) return(1); |
| 105 | return(0); |
| 106 | } |
| 107 | |
| 108 | |
| 109 | // Same as sortCoverage2, but the array being sorted is not |
| 110 | // an array of pointers. |
| 111 | // |
| 112 | int |
| 113 | sortCoverage3cxx . . $ sortCoverage3(9148c8c3ff42c9d8).(const void *a, const void *b) { |
| 114 | const coverage2_scxx . . $ coverage2_s# *A = (const coverage2_scxx . . $ coverage2_s# *)a; |
| 115 | const coverage2_scxx . . $ coverage2_s# *B = (const coverage2_scxx . . $ coverage2_s# *)b; |
| 116 | |
| 117 | if (A->axiscxx . . $ coverage2_s#axis. < B->axiscxx . . $ coverage2_s#axis.) return(-1); |
| 118 | if (A->axiscxx . . $ coverage2_s#axis. > B->axiscxx . . $ coverage2_s#axis.) return(1); |
| 119 | if (A->begcxx . . $ coverage2_s#beg. < B->begcxx . . $ coverage2_s#beg.) return(-1); |
| 120 | if (A->begcxx . . $ coverage2_s#beg. > B->begcxx . . $ coverage2_s#beg.) return(1); |
| 121 | return(0); |
| 122 | } |
| 123 | |
| 124 | |
| 125 | |
| 126 | |
| 127 | // An interval list, searchable |
| 128 | // |
| 129 | class coverageIntervalscxx . . $ coverageIntervals# { |
| 130 | public: |
| 131 | dict_t *_ilcxx . . $ coverageIntervals#_il.; |
| 132 | dict_load_t _loadcxx . . $ coverageIntervals#_load.; |
| 133 | public: |
| 134 | coverageIntervalscxx . . $ coverageIntervals#coverageIntervals(49f6e7a06ebc5aa8).() { |
| 135 | _ilcxx . . $ coverageIntervals#_il. = dict_create(DICTCOUNT_T_MAXcxx . . $ `libutil/kazlib/dict.h:36:9`!, sortCoverage2cxx . . $ sortCoverage2(9148c8c3ff42c9d8).); |
| 136 | }; |
| 137 | |
| 138 | ~cxx . . $ coverageIntervals#`~coverageIntervals`(ced63f7c635d850d).coverageIntervalscxx . . $ coverageIntervals#() { |
| 139 | dict_free(_ilcxx . . $ coverageIntervals#_il.); |
| 140 | pfree(); |
| 141 | }; |
| 142 | |
| 143 | |
| 144 | // We want to return the first node that is before our thing. Our comparison |
| 145 | // tests the start position. If there is no first node before our thing, |
| 146 | // return the next node. |
| 147 | // |
| 148 | dnode_t *lookupcxx . . $ coverageIntervals#lookup(7b926da9c864cd9a).(void *thing) { |
| 149 | dnode_t *it = dict_upper_bound(_ilcxx . . $ coverageIntervals#_il., thing); |
| 150 | if (it == 0L) |
| 151 | it = dict_lower_bound(_ilcxx . . $ coverageIntervals#_il., thing); |
| 152 | return(it); |
| 153 | }; |
| 154 | |
| 155 | |
| 156 | void addIntervalcxx . . $ coverageIntervals#addInterval(748afa4755bc9595).(int axis, int beg, int end, int coverage) { |
| 157 | dnode_t *node = (dnode_t *)palloc(sizeof(dnode_t)); |
| 158 | coverage2_scxx . . $ coverage2_s# *cov = (coverage2_scxx . . $ coverage2_s# *)palloc(sizeof(coverage2_scxx . . $ coverage2_s#)); |
| 159 | |
| 160 | cov->axiscxx . . $ coverage2_s#axis. = axis; |
| 161 | cov->begcxx . . $ coverage2_s#beg. = beg; |
| 162 | cov->endcxx . . $ coverage2_s#end. = end; |
| 163 | cov->coveragecxx . . $ coverage2_s#coverage. = coverage; |
| 164 | |
| 165 | // initialize the node with the value |
| 166 | dnode_init(node, 0L); |
| 167 | |
| 168 | // insert the node into the tree using the key |
| 169 | dict_insert(_ilcxx . . $ coverageIntervals#_il., node, (void *)cov); |
| 170 | }; |
| 171 | |
| 172 | void beginLoadcxx . . $ coverageIntervals#beginLoad(49f6e7a06ebc5aa8).(void) { |
| 173 | dict_load_begin(&_loadcxx . . $ coverageIntervals#_load., _ilcxx . . $ coverageIntervals#_il.); |
| 174 | }; |
| 175 | void endLoadcxx . . $ coverageIntervals#endLoad(49f6e7a06ebc5aa8).(void) { |
| 176 | dict_load_end(&_loadcxx . . $ coverageIntervals#_load.); |
| 177 | }; |
| 178 | void loadIntervalcxx . . $ coverageIntervals#loadInterval(748afa4755bc9595).(int axis, int beg, int end, int coverage) { |
| 179 | dnode_t *node = (dnode_t *)palloc(sizeof(dnode_t)); |
| 180 | coverage2_scxx . . $ coverage2_s# *cov = (coverage2_scxx . . $ coverage2_s# *)palloc(sizeof(coverage2_scxx . . $ coverage2_s#)); |
| 181 | |
| 182 | cov->axiscxx . . $ coverage2_s#axis. = axis; |
| 183 | cov->begcxx . . $ coverage2_s#beg. = beg; |
| 184 | cov->endcxx . . $ coverage2_s#end. = end; |
| 185 | cov->coveragecxx . . $ coverage2_s#coverage. = coverage; |
| 186 | |
| 187 | // initialize the node with the value |
| 188 | dnode_init(node, 0L); |
| 189 | |
| 190 | // insert the node into the tree using the key |
| 191 | dict_load_next(&_loadcxx . . $ coverageIntervals#_load., node, (void *)cov); |
| 192 | }; |
| 193 | }; |
| 194 | |
| 195 | |
| 196 | |
| 197 | |
| 198 | void |
| 199 | offsetsToCoveragecxx . . $ offsetsToCoverage(ad3c75f9df3541f9).(uint32cxx . . $ uint32# minCov, bigQueuecxx . . $ bigQueue# *I, coverageIntervalscxx . . $ coverageIntervals# *L) { |
| 200 | uint32cxx . . $ uint32# axis = ~uint32ZEROcxx . . $ `libutil/util.h:60:10`!; |
| 201 | uint32cxx . . $ uint32# position = ~uint32ZEROcxx . . $ `libutil/util.h:60:10`!; |
| 202 | uint32cxx . . $ uint32# coverage = 0; |
| 203 | uint64cxx . . $ uint64# covered = 0; |
| 204 | |
| 205 | |
| 206 | L->beginLoadcxx . . $ coverageIntervals#beginLoad(49f6e7a06ebc5aa8).(); |
| 207 | speedCountercxx . . $ speedCounter# Dcxx . . $ speedCounter#speedCounter(cdc90e45b9a80ad5).(" %8.0f matches treed (%8.2f matches/sec)\r", 1, 511, false); |
| 208 | while (I->nextcxx . . $ bigQueue#next(c9857a73d68e59ba).()) { |
| 209 | coverage1_scxx . . $ coverage1_s# *cov1 = (coverage1_scxx . . $ coverage1_s# *)I->getcxx . . $ bigQueue#get(50c7df7de5344ebb).(); |
| 210 | |
| 211 | if ((cov1->axiscxx . . $ coverage1_s#axis. != axis) && (coverage != 0)) |
| 212 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Sorting error -- have coverage at the end of an axis.\n"), exitcxx . . $ exit(44ed87f96534fad7).(1); |
| 213 | |
| 214 | int length = cov1->positioncxx . . $ coverage1_s#position. - position; |
| 215 | |
| 216 | if ((coverage >= minCov) && (length > 0)) { |
| 217 | D.tickcxx . . $ speedCounter#tick(c9857a73d68e59ba).(); |
| 218 | L->loadIntervalcxx . . $ coverageIntervals#loadInterval(748afa4755bc9595).(axis, position, position+length, coverage); |
| 219 | covered += length; |
| 220 | } |
| 221 | |
| 222 | // Occasionally, we get stung by insisting to use unsigned |
| 223 | // numbers. This is one of them. |
| 224 | // |
| 225 | if ((coverage == 0) && (cov1->incrementcxx . . $ coverage1_s#increment. == -1)) |
| 226 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Sorting error -- have negative coverage (axis="uint32FMTcxx . . $ `libutil/util.h:65:10`!" position="uint32FMTcxx . . $ `libutil/util.h:65:10`!")!\n", |
| 227 | axis, position), exitcxx . . $ exit(44ed87f96534fad7).(1); |
| 228 | |
| 229 | coverage += cov1->incrementcxx . . $ coverage1_s#increment.; |
| 230 | axis = cov1->axiscxx . . $ coverage1_s#axis.; |
| 231 | position = cov1->positioncxx . . $ coverage1_s#position.; |
| 232 | } |
| 233 | D.finishcxx . . $ speedCounter#finish(49f6e7a06ebc5aa8).(); |
| 234 | L->endLoadcxx . . $ coverageIntervals#endLoad(49f6e7a06ebc5aa8).(); |
| 235 | |
| 236 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "offsetsToCoverage()-- Found "uint64FMTcxx . . $ `libutil/util.h:55:10`!" bases at coverage "uint32FMTcxx . . $ `libutil/util.h:65:10`!" or greater.\n", |
| 237 | covered, minCov); |
| 238 | } |
| 239 | |
| 240 | |
| 241 | |
| 242 | |
| 243 | |
| 244 | void |
| 245 | findCoverageIntervalscxx . . $ findCoverageIntervals(f50a2635b58926e7).(char const *fileName, |
| 246 | uint32cxx . . $ uint32# minCov, |
| 247 | coverageIntervalscxx . . $ coverageIntervals# *Fint, |
| 248 | coverageIntervalscxx . . $ coverageIntervals# *Rint) { |
| 249 | bigQueuecxx . . $ bigQueue# Fcxx . . $ bigQueue#bigQueue(920db8d8b8a1da69).(sortCoverage1cxx . . $ sortCoverage1(9148c8c3ff42c9d8)., 0L, 0L, 0L, sizeof(coverage1_scxx . . $ coverage1_s#), 128, 0L); |
| 250 | bigQueuecxx . . $ bigQueue# Rcxx . . $ bigQueue#bigQueue(920db8d8b8a1da69).(sortCoverage1cxx . . $ sortCoverage1(9148c8c3ff42c9d8)., 0L, 0L, 0L, sizeof(coverage1_scxx . . $ coverage1_s#), 128, 0L); |
| 251 | |
| 252 | // |
| 253 | // Read the input file, building a bigQueue of the interval offsets |
| 254 | // |
| 255 | |
| 256 | |
| 257 | atacFileStreamcxx . . $ atacFileStream# AFcxx . . $ atacFileStream#atacFileStream(85c52e162fed56f9).(fileName); |
| 258 | atacMatchcxx . . $ atacMatch# *m = AF.nextMatchcxx . . $ atacFileStream#nextMatch(7b3c5176a3224eae).('u'); |
| 259 | |
| 260 | while (m) { |
| 261 | coverage1_scxx . . $ coverage1_s# *fbeg = (coverage1_scxx . . $ coverage1_s# *)malloccxx . . $ malloc(9f008b2a9698428b).(sizeof(coverage1_scxx . . $ coverage1_s#)); |
| 262 | coverage1_scxx . . $ coverage1_s# *fend = (coverage1_scxx . . $ coverage1_s# *)malloccxx . . $ malloc(9f008b2a9698428b).(sizeof(coverage1_scxx . . $ coverage1_s#)); |
| 263 | coverage1_scxx . . $ coverage1_s# *rbeg = (coverage1_scxx . . $ coverage1_s# *)malloccxx . . $ malloc(9f008b2a9698428b).(sizeof(coverage1_scxx . . $ coverage1_s#)); |
| 264 | coverage1_scxx . . $ coverage1_s# *rend = (coverage1_scxx . . $ coverage1_s# *)malloccxx . . $ malloc(9f008b2a9698428b).(sizeof(coverage1_scxx . . $ coverage1_s#)); |
| 265 | |
| 266 | fbeg->axiscxx . . $ coverage1_s#axis. = m->iid1cxx . . $ atacMatch#iid1.; |
| 267 | fbeg->positioncxx . . $ coverage1_s#position. = m->pos1cxx . . $ atacMatch#pos1.; |
| 268 | fbeg->incrementcxx . . $ coverage1_s#increment. = 1; |
| 269 | |
| 270 | fend->axiscxx . . $ coverage1_s#axis. = m->iid1cxx . . $ atacMatch#iid1.; |
| 271 | fend->positioncxx . . $ coverage1_s#position. = m->pos1cxx . . $ atacMatch#pos1. + m->len1cxx . . $ atacMatch#len1.; |
| 272 | fend->incrementcxx . . $ coverage1_s#increment. = -1; |
| 273 | |
| 274 | rbeg->axiscxx . . $ coverage1_s#axis. = m->iid2cxx . . $ atacMatch#iid2.; |
| 275 | rbeg->positioncxx . . $ coverage1_s#position. = m->pos2cxx . . $ atacMatch#pos2.; |
| 276 | rbeg->incrementcxx . . $ coverage1_s#increment. = 1; |
| 277 | |
| 278 | rend->axiscxx . . $ coverage1_s#axis. = m->iid2cxx . . $ atacMatch#iid2.; |
| 279 | rend->positioncxx . . $ coverage1_s#position. = m->pos2cxx . . $ atacMatch#pos2. + m->len2cxx . . $ atacMatch#len2.; |
| 280 | rend->incrementcxx . . $ coverage1_s#increment. = -1; |
| 281 | |
| 282 | F.addcxx . . $ bigQueue#add(5d22bdacc48458e8).(fbeg); |
| 283 | F.addcxx . . $ bigQueue#add(5d22bdacc48458e8).(fend); |
| 284 | R.addcxx . . $ bigQueue#add(5d22bdacc48458e8).(rbeg); |
| 285 | R.addcxx . . $ bigQueue#add(5d22bdacc48458e8).(rend); |
| 286 | |
| 287 | m = AF.nextMatchcxx . . $ atacFileStream#nextMatch(7b3c5176a3224eae).('u'); |
| 288 | } |
| 289 | |
| 290 | // Sort each bigQueue |
| 291 | // |
| 292 | F.sortcxx . . $ bigQueue#sort(49f6e7a06ebc5aa8).(); |
| 293 | R.sortcxx . . $ bigQueue#sort(49f6e7a06ebc5aa8).(); |
| 294 | |
| 295 | // Convert the interval offsets into a coverage interval list |
| 296 | // |
| 297 | offsetsToCoveragecxx . . $ offsetsToCoverage(ad3c75f9df3541f9).(minCov, &F, Fint); |
| 298 | offsetsToCoveragecxx . . $ offsetsToCoverage(ad3c75f9df3541f9).(minCov, &R, Rint); |
| 299 | } |
| 300 | |
| 301 | |
| 302 | |
| 303 | |
| 304 | |
| 305 | |
| 306 | |
| 307 | |
| 308 | |
| 309 | |
| 310 | void |
| 311 | intersectTestcxx . . $ intersectTest(a26c85d2beb8dd6e).(match_scxx . . $ match_s# *matches, |
| 312 | uint32cxx . . $ uint32# matchesLen, |
| 313 | coverageIntervalscxx . . $ coverageIntervals# *Fint, |
| 314 | coverageIntervalscxx . . $ coverageIntervals# *Rint, |
| 315 | uint32cxx . . $ uint32# matchNumber) { |
| 316 | bool errors = false; |
| 317 | |
| 318 | for (uint32cxx . . $ uint32# i=0; i<matchesLen; i++) { |
| 319 | coverage2_scxx . . $ coverage2_s# thing; |
| 320 | |
| 321 | // Query the tree for the first interval intersecting iid1 |
| 322 | // |
| 323 | thing.axiscxx . . $ coverage2_s#axis. = matches[i].iid1cxx . . $ match_s#iid1.; |
| 324 | thing.begcxx . . $ coverage2_s#beg. = matches[i].pos1cxx . . $ match_s#pos1.; |
| 325 | thing.endcxx . . $ coverage2_s#end. = matches[i].pos1cxx . . $ match_s#pos1. + matches[i].len1cxx . . $ match_s#len1.; |
| 326 | thing.coveragecxx . . $ coverage2_s#coverage. = 0; |
| 327 | dnode_t *node1 = Fint->lookupcxx . . $ coverageIntervals#lookup(7b926da9c864cd9a).(&thing); |
| 328 | |
| 329 | thing.axiscxx . . $ coverage2_s#axis. = matches[i].iid2cxx . . $ match_s#iid2.; |
| 330 | thing.begcxx . . $ coverage2_s#beg. = matches[i].pos2cxx . . $ match_s#pos2.; |
| 331 | thing.endcxx . . $ coverage2_s#end. = matches[i].pos2cxx . . $ match_s#pos2. + matches[i].len2cxx . . $ match_s#len2.; |
| 332 | thing.coveragecxx . . $ coverage2_s#coverage. = 0; |
| 333 | dnode_t *node2 = Rint->lookupcxx . . $ coverageIntervals#lookup(7b926da9c864cd9a).(&thing); |
| 334 | |
| 335 | |
| 336 | // Keep iterating until the node returned from the tree |
| 337 | // is empty, or it is after our region |
| 338 | // |
| 339 | while (node1 && node2) { |
| 340 | const coverage2_scxx . . $ coverage2_s# *key1 = 0L, *key2 = 0L; |
| 341 | |
| 342 | bool isect1=false, before1=false; |
| 343 | bool isect2=false, before2=false; |
| 344 | |
| 345 | if (node1) { |
| 346 | key1 = (const coverage2_scxx . . $ coverage2_s# *)dnode_getkeycxx . . $ `libutil/kazlib/dict.h:134:9`!(node1); |
| 347 | |
| 348 | isect1 = ((key1->axiscxx . . $ coverage2_s#axis. == matches[i].iid1cxx . . $ match_s#iid1.) && |
| 349 | (matches[i].pos1cxx . . $ match_s#pos1. < key1->endcxx . . $ coverage2_s#end.) && |
| 350 | (key1->begcxx . . $ coverage2_s#beg. < matches[i].pos1cxx . . $ match_s#pos1. + matches[i].len1cxx . . $ match_s#len1.)); |
| 351 | |
| 352 | before1 = ((key1->axiscxx . . $ coverage2_s#axis. < matches[i].iid1cxx . . $ match_s#iid1.) || |
| 353 | ((key1->axiscxx . . $ coverage2_s#axis. == matches[i].iid1cxx . . $ match_s#iid1.) && (key1->begcxx . . $ coverage2_s#beg. < matches[i].pos1cxx . . $ match_s#pos1. + matches[i].len1cxx . . $ match_s#len1.))); |
| 354 | } |
| 355 | |
| 356 | |
| 357 | if (node2) { |
| 358 | key2 = (const coverage2_scxx . . $ coverage2_s# *)dnode_getkeycxx . . $ `libutil/kazlib/dict.h:134:9`!(node2); |
| 359 | |
| 360 | isect2 = ((key2->axiscxx . . $ coverage2_s#axis. == matches[i].iid2cxx . . $ match_s#iid2.) && |
| 361 | (matches[i].pos2cxx . . $ match_s#pos2. < key2->endcxx . . $ coverage2_s#end.) && |
| 362 | (key2->begcxx . . $ coverage2_s#beg. < matches[i].pos2cxx . . $ match_s#pos2. + matches[i].len2cxx . . $ match_s#len2.)); |
| 363 | |
| 364 | before2 = ((key2->axiscxx . . $ coverage2_s#axis. < matches[i].iid2cxx . . $ match_s#iid2.) || |
| 365 | ((key2->axiscxx . . $ coverage2_s#axis. == matches[i].iid2cxx . . $ match_s#iid2.) && (key2->begcxx . . $ coverage2_s#beg. < matches[i].pos2cxx . . $ match_s#pos2. + matches[i].len2cxx . . $ match_s#len2.))); |
| 366 | } |
| 367 | |
| 368 | |
| 369 | if (isect1) { |
| 370 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Got fwd intersection on i="uint32FMTcxx . . $ `libutil/util.h:65:10`!" matchNumber="uint32FMTcxx . . $ `libutil/util.h:65:10`!"\n", i, matchNumber); |
| 371 | fprintf(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!, "--"uint32FMTcxx . . $ `libutil/util.h:65:10`!" "uint32FMTcxx . . $ `libutil/util.h:65:10`!" 1 "uint32FMTcxx . . $ `libutil/util.h:65:10`!" "uint32FMTcxx . . $ `libutil/util.h:65:10`!" %d\n", |
| 372 | matches[i].pos1cxx . . $ match_s#pos1., matches[i].pos1cxx . . $ match_s#pos1. + matches[i].len1cxx . . $ match_s#len1., |
| 373 | matches[i].pos2cxx . . $ match_s#pos2., matches[i].pos2cxx . . $ match_s#pos2. + matches[i].len2cxx . . $ match_s#len2., matches[i].ori2cxx . . $ match_s#ori2. ? 1 : -1); |
| 374 | fprintf(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!, "--key1 beg="uint32FMTcxx . . $ `libutil/util.h:65:10`!" end="uint32FMTcxx . . $ `libutil/util.h:65:10`!"\n", |
| 375 | key1->begcxx . . $ coverage2_s#beg., key1->endcxx . . $ coverage2_s#end.); |
| 376 | errors = true; |
| 377 | } |
| 378 | if (isect2) { |
| 379 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Got rev intersection on i="uint32FMTcxx . . $ `libutil/util.h:65:10`!" matchNumber="uint32FMTcxx . . $ `libutil/util.h:65:10`!"\n", i, matchNumber); |
| 380 | fprintf(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!, "--"uint32FMTcxx . . $ `libutil/util.h:65:10`!" "uint32FMTcxx . . $ `libutil/util.h:65:10`!" 1 "uint32FMTcxx . . $ `libutil/util.h:65:10`!" "uint32FMTcxx . . $ `libutil/util.h:65:10`!" %d\n", |
| 381 | matches[i].pos1cxx . . $ match_s#pos1., matches[i].pos1cxx . . $ match_s#pos1. + matches[i].len1cxx . . $ match_s#len1., |
| 382 | matches[i].pos2cxx . . $ match_s#pos2., matches[i].pos2cxx . . $ match_s#pos2. + matches[i].len2cxx . . $ match_s#len2., matches[i].ori2cxx . . $ match_s#ori2. ? 1 : -1); |
| 383 | fprintf(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!, "--key2 beg="uint32FMTcxx . . $ `libutil/util.h:65:10`!" end="uint32FMTcxx . . $ `libutil/util.h:65:10`!"\n", |
| 384 | key2->begcxx . . $ coverage2_s#beg., key2->endcxx . . $ coverage2_s#end.); |
| 385 | errors = true; |
| 386 | } |
| 387 | |
| 388 | |
| 389 | // If we intersected or were before, move to the next, otherwise, |
| 390 | // stop |
| 391 | // |
| 392 | if (isect1 || before1) |
| 393 | node1 = dict_next(Fint->_ilcxx . . $ coverageIntervals#_il., node1); |
| 394 | else |
| 395 | node1 = 0L; |
| 396 | |
| 397 | if (isect2 || before2) |
| 398 | node2 = dict_next(Rint->_ilcxx . . $ coverageIntervals#_il., node2); |
| 399 | else |
| 400 | node2 = 0L; |
| 401 | } |
| 402 | } |
| 403 | |
| 404 | if (errors) |
| 405 | abortcxx . . $ abort(15d318a79ddce9e0).(); |
| 406 | } |
| 407 | |
| 408 | |
| 409 | |
| 410 | |
| 411 | |
| 412 | |
| 413 | |
| 414 | |
| 415 | |
| 416 | // This is used all over the place. |
| 417 | // |
| 418 | #define D08D2cxx . . $ `atac-driver/uniqueFilter/uniqueFilter.C:418:9`! uint32FMTW(8)" "uint32FMTW(8) |
| 419 | #define KEY1THINGcxx . . $ `atac-driver/uniqueFilter/uniqueFilter.C:419:9`! "key1 = "uint32FMTW(8)" "uint32FMTW(8)" "uint32FMTW(8)" thing = "D08D2" "D08D2"\n" |
| 420 | #define KEY2THINGcxx . . $ `atac-driver/uniqueFilter/uniqueFilter.C:420:9`! "key2 = "uint32FMTW(8)" "uint32FMTW(8)" "uint32FMTW(8)" thing = "D08D2" "D08D2"\n" |
| 421 | |
| 422 | int |
| 423 | maincxx . . $ main(afcd3168fc1188a4).(int argc, char **argv) { |
| 424 | char *inputName = 0L; |
| 425 | char *subtractName = 0L; |
| 426 | |
| 427 | int arg = 1; |
| 428 | while (arg < argc) { |
| 429 | if (strcmp(argv[arg], "-i") == 0) { |
| 430 | inputName = argv[++arg]; |
| 431 | } else if (strcmp(argv[arg], "-s") == 0) { |
| 432 | subtractName = argv[++arg]; |
| 433 | } else { |
| 434 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "usage: %s [-h] [-s subtractFile] [-i inputFile]\n", argv[0]); |
| 435 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, " -s instead of finding regions to remove by looking\n"); |
| 436 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, " for duplicatd regions in inputFile, load them\n"); |
| 437 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, " from subtractFile.\n"); |
| 438 | exitcxx . . $ exit(44ed87f96534fad7).(1); |
| 439 | } |
| 440 | arg++; |
| 441 | } |
| 442 | |
| 443 | if (inputName == 0L) |
| 444 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "usage: %s [-i inputfile] [-o outputfile] [-h]\n", argv[0]), exitcxx . . $ exit(44ed87f96534fad7).(1); |
| 445 | |
| 446 | coverageIntervalscxx . . $ coverageIntervals# *Fint = new coverageIntervalscxx . . $ coverageIntervals#; |
| 447 | coverageIntervalscxx . . $ coverageIntervals# *Rint = new coverageIntervalscxx . . $ coverageIntervals#; |
| 448 | |
| 449 | if (subtractName) |
| 450 | findCoverageIntervalscxx . . $ findCoverageIntervals(f50a2635b58926e7).(subtractName, 1, Fint, Rint); |
| 451 | else |
| 452 | findCoverageIntervalscxx . . $ findCoverageIntervals(f50a2635b58926e7).(inputName, 2, Fint, Rint); |
| 453 | |
| 454 | |
| 455 | |
| 456 | // The original implementation would then sort the matches in X, |
| 457 | // merge the sorted intervals and the sorted matches together, resort |
| 458 | // the matches by Y, and merge with Rcov. That is a lot of work to |
| 459 | // avoid keeping two interval lists in memory. |
| 460 | // |
| 461 | // We build an in-core interval list for both assemblies, and |
| 462 | // then stream the matches by it. |
| 463 | |
| 464 | // we need to ask the interval list: |
| 465 | // return the intervals that are covered by this interval |
| 466 | |
| 467 | |
| 468 | uint32cxx . . $ uint32# matchesLen = 0; |
| 469 | uint32cxx . . $ uint32# matchesMax = 1024; |
| 470 | match_scxx . . $ match_s# *matches = new match_scxx . . $ match_s# [matchesMax]; |
| 471 | match_scxx . . $ match_s# extent; |
| 472 | |
| 473 | uint32cxx . . $ uint32# matchNumber = 0; |
| 474 | |
| 475 | atacFileStreamcxx . . $ atacFileStream# AFcxx . . $ atacFileStream#atacFileStream(85c52e162fed56f9).(inputName); |
| 476 | atacMatchcxx . . $ atacMatch# *m = AF.nextMatchcxx . . $ atacFileStream#nextMatch(7b3c5176a3224eae).('u'); |
| 477 | |
| 478 | while (m) { |
| 479 | matches[0].iid1cxx . . $ match_s#iid1. = m->iid1cxx . . $ atacMatch#iid1.; |
| 480 | matches[0].pos1cxx . . $ match_s#pos1. = m->pos1cxx . . $ atacMatch#pos1.; |
| 481 | matches[0].len1cxx . . $ match_s#len1. = m->len1cxx . . $ atacMatch#len1.; |
| 482 | matches[0].ori1cxx . . $ match_s#ori1. = m->fwd1cxx . . $ atacMatch#fwd1.; |
| 483 | matches[0].iid2cxx . . $ match_s#iid2. = m->iid2cxx . . $ atacMatch#iid2.; |
| 484 | matches[0].pos2cxx . . $ match_s#pos2. = m->pos2cxx . . $ atacMatch#pos2.; |
| 485 | matches[0].len2cxx . . $ match_s#len2. = m->len2cxx . . $ atacMatch#len2.; |
| 486 | matches[0].ori2cxx . . $ match_s#ori2. = m->fwd2cxx . . $ atacMatch#fwd2.; |
| 487 | |
| 488 | // Save the original, we'll use this to test for intersections. |
| 489 | // |
| 490 | memcpy(&extent, matches, sizeof(match_scxx . . $ match_s#)); |
| 491 | |
| 492 | bool fwd = (matches[0].ori1cxx . . $ match_s#ori1. == matches[0].ori2cxx . . $ match_s#ori2.); |
| 493 | |
| 494 | |
| 495 | // Query the tree for the first interval intersecting iid1 |
| 496 | // XXX: Should this be upper_bound instead? |
| 497 | // |
| 498 | // A scratch interval used for querying the list |
| 499 | // |
| 500 | coverage2_scxx . . $ coverage2_s# thing; |
| 501 | |
| 502 | thing.axiscxx . . $ coverage2_s#axis. = extent.iid1cxx . . $ match_s#iid1.; |
| 503 | thing.begcxx . . $ coverage2_s#beg. = extent.pos1cxx . . $ match_s#pos1.; |
| 504 | thing.endcxx . . $ coverage2_s#end. = extent.pos1cxx . . $ match_s#pos1. + extent.len1cxx . . $ match_s#len1.; |
| 505 | thing.coveragecxx . . $ coverage2_s#coverage. = 0; |
| 506 | dnode_t *node1start = Fint->lookupcxx . . $ coverageIntervals#lookup(7b926da9c864cd9a).(&thing); |
| 507 | dnode_t *node1 = node1start; |
| 508 | |
| 509 | |
| 510 | thing.axiscxx . . $ coverage2_s#axis. = extent.iid2cxx . . $ match_s#iid2.; |
| 511 | thing.begcxx . . $ coverage2_s#beg. = extent.pos2cxx . . $ match_s#pos2.; |
| 512 | thing.endcxx . . $ coverage2_s#end. = extent.pos2cxx . . $ match_s#pos2. + extent.len2cxx . . $ match_s#len2.; |
| 513 | thing.coveragecxx . . $ coverage2_s#coverage. = 0; |
| 514 | dnode_t *node2start = Rint->lookupcxx . . $ coverageIntervals#lookup(7b926da9c864cd9a).(&thing); |
| 515 | dnode_t *node2 = node2start; |
| 516 | |
| 517 | // while the node intersects the match, trim or split it, then |
| 518 | // get the next node. |
| 519 | // |
| 520 | // any way I tried this, it's ugly. |
| 521 | // |
| 522 | // if there is one match, then it is in [0]. If there is more |
| 523 | // than one match, then the trimmed match is in [0], but the |
| 524 | // split matches are in [1] on. |
| 525 | |
| 526 | |
| 527 | // XXX the problem is that we split off things, then move |
| 528 | // to the next match, without checking previously split |
| 529 | // things against this match |
| 530 | // |
| 531 | |
| 532 | // Keep iterating until the node returned from the tree |
| 533 | // is empty, or it is after our region |
| 534 | // |
| 535 | while (node1 || node2) { |
| 536 | |
| 537 | bool before1=false; |
| 538 | bool before2=false; |
| 539 | |
| 540 | bool modified=false; |
| 541 | |
| 542 | const coverage2_scxx . . $ coverage2_s# *key1 = 0L; |
| 543 | const coverage2_scxx . . $ coverage2_s# *key2 = 0L; |
| 544 | |
| 545 | if (node1) { |
| 546 | key1 = (const coverage2_scxx . . $ coverage2_s# *)dnode_getkeycxx . . $ `libutil/kazlib/dict.h:134:9`!(node1); |
| 547 | before1 = ((key1->axiscxx . . $ coverage2_s#axis. < extent.iid1cxx . . $ match_s#iid1.) || |
| 548 | ((key1->axiscxx . . $ coverage2_s#axis. == extent.iid1cxx . . $ match_s#iid1.) && (key1->begcxx . . $ coverage2_s#beg. < extent.pos1cxx . . $ match_s#pos1. + extent.len1cxx . . $ match_s#len1.))); |
| 549 | |
| 550 | |
| 551 | // Three cases: (1) we trim off the front, (2) trim off the |
| 552 | // back or (3) split. And, (4) delete the whole damn thing. |
| 553 | // |
| 554 | // Further complicated by having multiple things to try. |
| 555 | // |
| 556 | // If anything is modified, reset the node to the start |
| 557 | // |
| 558 | |
| 559 | for (uint32cxx . . $ uint32# i=0; i<matchesLen; i++) { |
| 560 | if (matches[i].len1cxx . . $ match_s#len1. == 0) |
| 561 | continue; |
| 562 | |
| 563 | if ((key1->begcxx . . $ coverage2_s#beg. <= matches[i].pos1cxx . . $ match_s#pos1.) && |
| 564 | ((matches[i].pos1cxx . . $ match_s#pos1. + matches[i].len1cxx . . $ match_s#len1.) <= key1->endcxx . . $ coverage2_s#end.)) { |
| 565 | modified = true; |
| 566 | |
| 567 | // Trim the whole thing? |
| 568 | // |
| 569 | matches[i].pos1cxx . . $ match_s#pos1. = 0; |
| 570 | matches[i].len1cxx . . $ match_s#len1. = 0; |
| 571 | matches[i].pos2cxx . . $ match_s#pos2. = 0; |
| 572 | matches[i].len2cxx . . $ match_s#len2. = 0; |
| 573 | } else if ((matches[i].pos1cxx . . $ match_s#pos1. < key1->begcxx . . $ coverage2_s#beg.) && |
| 574 | (key1->endcxx . . $ coverage2_s#end. < (matches[i].pos1cxx . . $ match_s#pos1. + matches[i].len1cxx . . $ match_s#len1.))) { |
| 575 | modified = true; |
| 576 | |
| 577 | // Contained. Split it. |
| 578 | // |
| 579 | |
| 580 | // The left half |
| 581 | // |
| 582 | int newLen = key1->begcxx . . $ coverage2_s#beg. - matches[i].pos1cxx . . $ match_s#pos1.; |
| 583 | |
| 584 | matches[matchesLen].iid1cxx . . $ match_s#iid1. = matches[i].iid1cxx . . $ match_s#iid1.; |
| 585 | matches[matchesLen].pos1cxx . . $ match_s#pos1. = matches[i].pos1cxx . . $ match_s#pos1.; |
| 586 | matches[matchesLen].len1cxx . . $ match_s#len1. = newLen; |
| 587 | matches[matchesLen].ori1cxx . . $ match_s#ori1. = matches[i].ori1cxx . . $ match_s#ori1.; |
| 588 | |
| 589 | if (fwd) { |
| 590 | matches[matchesLen].iid2cxx . . $ match_s#iid2. = matches[i].iid2cxx . . $ match_s#iid2.; |
| 591 | matches[matchesLen].pos2cxx . . $ match_s#pos2. = matches[i].pos2cxx . . $ match_s#pos2.; |
| 592 | matches[matchesLen].len2cxx . . $ match_s#len2. = newLen; |
| 593 | matches[matchesLen].ori2cxx . . $ match_s#ori2. = matches[i].ori2cxx . . $ match_s#ori2.; |
| 594 | } else { |
| 595 | matches[matchesLen].iid2cxx . . $ match_s#iid2. = matches[i].iid2cxx . . $ match_s#iid2.; |
| 596 | matches[matchesLen].pos2cxx . . $ match_s#pos2. = matches[i].pos2cxx . . $ match_s#pos2. + matches[i].len2cxx . . $ match_s#len2. - newLen; |
| 597 | matches[matchesLen].len2cxx . . $ match_s#len2. = newLen; |
| 598 | matches[matchesLen].ori2cxx . . $ match_s#ori2. = matches[i].ori2cxx . . $ match_s#ori2.; |
| 599 | } |
| 600 | |
| 601 | matchesLen++; |
| 602 | |
| 603 | // The right half |
| 604 | // |
| 605 | newLen = matches[i].pos1cxx . . $ match_s#pos1. + matches[i].len1cxx . . $ match_s#len1. - key1->endcxx . . $ coverage2_s#end.; |
| 606 | |
| 607 | matches[matchesLen].iid1cxx . . $ match_s#iid1. = matches[i].iid1cxx . . $ match_s#iid1.; |
| 608 | matches[matchesLen].pos1cxx . . $ match_s#pos1. = key1->endcxx . . $ coverage2_s#end.; |
| 609 | matches[matchesLen].len1cxx . . $ match_s#len1. = newLen; |
| 610 | matches[matchesLen].ori1cxx . . $ match_s#ori1. = matches[i].ori1cxx . . $ match_s#ori1.; |
| 611 | |
| 612 | if (fwd) { |
| 613 | matches[matchesLen].iid2cxx . . $ match_s#iid2. = matches[i].iid2cxx . . $ match_s#iid2.; |
| 614 | matches[matchesLen].pos2cxx . . $ match_s#pos2. = matches[i].pos2cxx . . $ match_s#pos2. + (key1->endcxx . . $ coverage2_s#end. - matches[i].pos1cxx . . $ match_s#pos1.); |
| 615 | matches[matchesLen].len2cxx . . $ match_s#len2. = newLen; |
| 616 | matches[matchesLen].ori2cxx . . $ match_s#ori2. = matches[i].ori2cxx . . $ match_s#ori2.; |
| 617 | } else { |
| 618 | matches[matchesLen].iid2cxx . . $ match_s#iid2. = matches[i].iid2cxx . . $ match_s#iid2.; |
| 619 | matches[matchesLen].pos2cxx . . $ match_s#pos2. = matches[i].pos2cxx . . $ match_s#pos2.; |
| 620 | matches[matchesLen].len2cxx . . $ match_s#len2. = newLen; |
| 621 | matches[matchesLen].ori2cxx . . $ match_s#ori2. = matches[i].ori2cxx . . $ match_s#ori2.; |
| 622 | } |
| 623 | |
| 624 | matchesLen++; |
| 625 | |
| 626 | // Invalidate this match |
| 627 | // |
| 628 | matches[i].pos1cxx . . $ match_s#pos1. = 0; |
| 629 | matches[i].len1cxx . . $ match_s#len1. = 0; |
| 630 | matches[i].pos2cxx . . $ match_s#pos2. = 0; |
| 631 | matches[i].len2cxx . . $ match_s#len2. = 0; |
| 632 | } else if ((key1->begcxx . . $ coverage2_s#beg. <= matches[i].pos1cxx . . $ match_s#pos1.) && |
| 633 | (matches[i].pos1cxx . . $ match_s#pos1. < key1->endcxx . . $ coverage2_s#end.)) { |
| 634 | modified = true; |
| 635 | |
| 636 | // Trim the begin? |
| 637 | // |
| 638 | |
| 639 | int trimLen = key1->endcxx . . $ coverage2_s#end. - matches[i].pos1cxx . . $ match_s#pos1.; |
| 640 | matches[i].pos1cxx . . $ match_s#pos1. += trimLen; |
| 641 | matches[i].len1cxx . . $ match_s#len1. -= trimLen; |
| 642 | |
| 643 | if (fwd == true) |
| 644 | matches[i].pos2cxx . . $ match_s#pos2. += trimLen; |
| 645 | matches[i].len2cxx . . $ match_s#len2. -= trimLen; |
| 646 | |
| 647 | } else if ((key1->begcxx . . $ coverage2_s#beg. < (matches[i].pos1cxx . . $ match_s#pos1. + matches[i].len1cxx . . $ match_s#len1.)) && |
| 648 | ((matches[i].pos1cxx . . $ match_s#pos1. + matches[i].len1cxx . . $ match_s#len1.) <= key1->endcxx . . $ coverage2_s#end.)) { |
| 649 | modified = true; |
| 650 | |
| 651 | // Trim the end? |
| 652 | // |
| 653 | |
| 654 | int trimLen = matches[i].pos1cxx . . $ match_s#pos1. + matches[i].len1cxx . . $ match_s#len1. - key1->begcxx . . $ coverage2_s#beg.; |
| 655 | matches[i].len1cxx . . $ match_s#len1. -= trimLen; |
| 656 | |
| 657 | if (fwd == false) |
| 658 | matches[i].pos2cxx . . $ match_s#pos2. += trimLen; |
| 659 | matches[i].len2cxx . . $ match_s#len2. -= trimLen; |
| 660 | } |
| 661 | } |
| 662 | } // isect |
| 663 | |
| 664 | |
| 665 | |
| 666 | if (node2) { |
| 667 | key2 = (const coverage2_scxx . . $ coverage2_s# *)dnode_getkeycxx . . $ `libutil/kazlib/dict.h:134:9`!(node2); |
| 668 | before2 = ((key2->axiscxx . . $ coverage2_s#axis. < extent.iid2cxx . . $ match_s#iid2.) || |
| 669 | ((key2->axiscxx . . $ coverage2_s#axis. == extent.iid2cxx . . $ match_s#iid2.) && (key2->begcxx . . $ coverage2_s#beg. < extent.pos2cxx . . $ match_s#pos2. + extent.len2cxx . . $ match_s#len2.))); |
| 670 | |
| 671 | for (uint32cxx . . $ uint32# i=0; i<matchesLen; i++) { |
| 672 | if (matches[i].len2cxx . . $ match_s#len2. == 0) |
| 673 | continue; |
| 674 | |
| 675 | if ((key2->begcxx . . $ coverage2_s#beg. <= matches[i].pos2cxx . . $ match_s#pos2.) && |
| 676 | ((matches[i].pos2cxx . . $ match_s#pos2. + matches[i].len2cxx . . $ match_s#len2.) <= key2->endcxx . . $ coverage2_s#end.)) { |
| 677 | modified = true; |
| 678 | |
| 679 | // Trim the whole thing? |
| 680 | // |
| 681 | matches[i].pos1cxx . . $ match_s#pos1. = 0; |
| 682 | matches[i].len1cxx . . $ match_s#len1. = 0; |
| 683 | matches[i].pos2cxx . . $ match_s#pos2. = 0; |
| 684 | matches[i].len2cxx . . $ match_s#len2. = 0; |
| 685 | } else if ((matches[i].pos2cxx . . $ match_s#pos2. < key2->begcxx . . $ coverage2_s#beg.) && |
| 686 | (key2->endcxx . . $ coverage2_s#end. < (matches[i].pos2cxx . . $ match_s#pos2. + matches[i].len2cxx . . $ match_s#len2.))) { |
| 687 | modified = true; |
| 688 | |
| 689 | // Contained. Split it. |
| 690 | // |
| 691 | |
| 692 | // The left (forward strand) half |
| 693 | // |
| 694 | |
| 695 | if (fwd) { |
| 696 | int newLen = key2->begcxx . . $ coverage2_s#beg. - matches[i].pos2cxx . . $ match_s#pos2.; |
| 697 | |
| 698 | matches[matchesLen].iid1cxx . . $ match_s#iid1. = matches[i].iid1cxx . . $ match_s#iid1.; |
| 699 | matches[matchesLen].pos1cxx . . $ match_s#pos1. = matches[i].pos1cxx . . $ match_s#pos1.; |
| 700 | matches[matchesLen].len1cxx . . $ match_s#len1. = newLen; |
| 701 | matches[matchesLen].ori1cxx . . $ match_s#ori1. = matches[i].ori1cxx . . $ match_s#ori1.; |
| 702 | |
| 703 | matches[matchesLen].iid2cxx . . $ match_s#iid2. = matches[i].iid2cxx . . $ match_s#iid2.; |
| 704 | matches[matchesLen].pos2cxx . . $ match_s#pos2. = matches[i].pos2cxx . . $ match_s#pos2.; |
| 705 | matches[matchesLen].len2cxx . . $ match_s#len2. = newLen; |
| 706 | matches[matchesLen].ori2cxx . . $ match_s#ori2. = matches[i].ori2cxx . . $ match_s#ori2.; |
| 707 | } else { |
| 708 | int newLen = matches[i].pos2cxx . . $ match_s#pos2. + matches[i].len2cxx . . $ match_s#len2. - key2->endcxx . . $ coverage2_s#end.; |
| 709 | |
| 710 | matches[matchesLen].iid1cxx . . $ match_s#iid1. = matches[i].iid1cxx . . $ match_s#iid1.; |
| 711 | matches[matchesLen].pos1cxx . . $ match_s#pos1. = matches[i].pos1cxx . . $ match_s#pos1.; |
| 712 | matches[matchesLen].len1cxx . . $ match_s#len1. = newLen; |
| 713 | matches[matchesLen].ori1cxx . . $ match_s#ori1. = matches[i].ori1cxx . . $ match_s#ori1.; |
| 714 | |
| 715 | matches[matchesLen].iid2cxx . . $ match_s#iid2. = matches[i].iid2cxx . . $ match_s#iid2.; |
| 716 | matches[matchesLen].pos2cxx . . $ match_s#pos2. = key2->endcxx . . $ coverage2_s#end.; |
| 717 | matches[matchesLen].len2cxx . . $ match_s#len2. = newLen; |
| 718 | matches[matchesLen].ori2cxx . . $ match_s#ori2. = matches[i].ori2cxx . . $ match_s#ori2.; |
| 719 | } |
| 720 | |
| 721 | matchesLen++; |
| 722 | |
| 723 | // The right (forward strand) half |
| 724 | // |
| 725 | if (fwd) { |
| 726 | int newLen = matches[i].pos2cxx . . $ match_s#pos2. + matches[i].len2cxx . . $ match_s#len2. - key2->endcxx . . $ coverage2_s#end.; |
| 727 | |
| 728 | matches[matchesLen].iid1cxx . . $ match_s#iid1. = matches[i].iid1cxx . . $ match_s#iid1.; |
| 729 | matches[matchesLen].pos1cxx . . $ match_s#pos1. = matches[i].pos1cxx . . $ match_s#pos1. + key2->endcxx . . $ coverage2_s#end. - matches[i].pos2cxx . . $ match_s#pos2.; |
| 730 | matches[matchesLen].len1cxx . . $ match_s#len1. = newLen; |
| 731 | matches[matchesLen].ori1cxx . . $ match_s#ori1. = matches[i].ori1cxx . . $ match_s#ori1.; |
| 732 | |
| 733 | matches[matchesLen].iid2cxx . . $ match_s#iid2. = matches[i].iid2cxx . . $ match_s#iid2.; |
| 734 | matches[matchesLen].pos2cxx . . $ match_s#pos2. = key2->endcxx . . $ coverage2_s#end.; |
| 735 | matches[matchesLen].len2cxx . . $ match_s#len2. = newLen; |
| 736 | matches[matchesLen].ori2cxx . . $ match_s#ori2. = matches[i].ori2cxx . . $ match_s#ori2.; |
| 737 | } else { |
| 738 | int newLen = key2->begcxx . . $ coverage2_s#beg. - matches[i].pos2cxx . . $ match_s#pos2.; |
| 739 | |
| 740 | matches[matchesLen].iid1cxx . . $ match_s#iid1. = matches[i].iid1cxx . . $ match_s#iid1.; |
| 741 | matches[matchesLen].pos1cxx . . $ match_s#pos1. = matches[i].pos1cxx . . $ match_s#pos1. + matches[i].pos2cxx . . $ match_s#pos2. + matches[i].len2cxx . . $ match_s#len2. - key2->begcxx . . $ coverage2_s#beg.; |
| 742 | matches[matchesLen].len1cxx . . $ match_s#len1. = newLen; |
| 743 | matches[matchesLen].ori1cxx . . $ match_s#ori1. = matches[i].ori1cxx . . $ match_s#ori1.; |
| 744 | |
| 745 | matches[matchesLen].iid2cxx . . $ match_s#iid2. = matches[i].iid2cxx . . $ match_s#iid2.; |
| 746 | matches[matchesLen].pos2cxx . . $ match_s#pos2. = matches[i].pos2cxx . . $ match_s#pos2.; |
| 747 | matches[matchesLen].len2cxx . . $ match_s#len2. = newLen; |
| 748 | matches[matchesLen].ori2cxx . . $ match_s#ori2. = matches[i].ori2cxx . . $ match_s#ori2.; |
| 749 | } |
| 750 | |
| 751 | matchesLen++; |
| 752 | |
| 753 | // Invalidate this match |
| 754 | // |
| 755 | matches[i].pos1cxx . . $ match_s#pos1. = 0; |
| 756 | matches[i].len1cxx . . $ match_s#len1. = 0; |
| 757 | matches[i].pos2cxx . . $ match_s#pos2. = 0; |
| 758 | matches[i].len2cxx . . $ match_s#len2. = 0; |
| 759 | } else if ((key2->begcxx . . $ coverage2_s#beg. <= matches[i].pos2cxx . . $ match_s#pos2.) && |
| 760 | (matches[i].pos2cxx . . $ match_s#pos2. < key2->endcxx . . $ coverage2_s#end.)) { |
| 761 | modified = true; |
| 762 | |
| 763 | // Trim the begin? fwdOK, revOK |
| 764 | // |
| 765 | |
| 766 | int trimLen = key2->endcxx . . $ coverage2_s#end. - matches[i].pos2cxx . . $ match_s#pos2.; |
| 767 | matches[i].pos2cxx . . $ match_s#pos2. += trimLen; |
| 768 | matches[i].len2cxx . . $ match_s#len2. -= trimLen; |
| 769 | |
| 770 | if (fwd == true) |
| 771 | matches[i].pos1cxx . . $ match_s#pos1. += trimLen; |
| 772 | matches[i].len1cxx . . $ match_s#len1. -= trimLen; |
| 773 | |
| 774 | } else if ((key2->begcxx . . $ coverage2_s#beg. < (matches[i].pos2cxx . . $ match_s#pos2. + matches[i].len2cxx . . $ match_s#len2.)) && |
| 775 | ((matches[i].pos2cxx . . $ match_s#pos2. + matches[i].len2cxx . . $ match_s#len2.) <= key2->endcxx . . $ coverage2_s#end.)) { |
| 776 | modified = true; |
| 777 | |
| 778 | // Trim the end? |
| 779 | // |
| 780 | |
| 781 | int trimLen = matches[i].pos2cxx . . $ match_s#pos2. + matches[i].len2cxx . . $ match_s#len2. - key2->begcxx . . $ coverage2_s#beg.; |
| 782 | matches[i].len1cxx . . $ match_s#len1. -= trimLen; |
| 783 | |
| 784 | if (fwd == false) |
| 785 | matches[i].pos1cxx . . $ match_s#pos1. += trimLen; |
| 786 | matches[i].len2cxx . . $ match_s#len2. -= trimLen; |
| 787 | } |
| 788 | } |
| 789 | } |
| 790 | |
| 791 | // If we intersected or were before, move to the next, otherwise, |
| 792 | // stop. |
| 793 | // |
| 794 | if (modified) |
| 795 | node1 = node1start; |
| 796 | else if (before1) |
| 797 | node1 = dict_next(Fint->_ilcxx . . $ coverageIntervals#_il., node1); |
| 798 | else |
| 799 | node1 = 0L; |
| 800 | |
| 801 | if (modified) |
| 802 | node2 = node2start; |
| 803 | else if (before2) |
| 804 | node2 = dict_next(Rint->_ilcxx . . $ coverageIntervals#_il., node2); |
| 805 | else |
| 806 | node2 = 0L; |
| 807 | } // end of while (node1 || node2) |
| 808 | |
| 809 | |
| 810 | // Nobody should be outside the extent |
| 811 | // |
| 812 | for (uint32cxx . . $ uint32# i=0; i<matchesLen; i++) { |
| 813 | if ((matches[i].len1cxx . . $ match_s#len1. > 0) && (matches[i].len2cxx . . $ match_s#len2. > 0)) { |
| 814 | if ((matches[i].pos1cxx . . $ match_s#pos1. < extent.pos1cxx . . $ match_s#pos1.) || |
| 815 | (matches[i].pos1cxx . . $ match_s#pos1. + matches[i].len1cxx . . $ match_s#len1. > extent.pos1cxx . . $ match_s#pos1. + extent.len1cxx . . $ match_s#len1.) || |
| 816 | (matches[i].pos2cxx . . $ match_s#pos2. < extent.pos2cxx . . $ match_s#pos2.) || |
| 817 | (matches[i].pos2cxx . . $ match_s#pos2. + matches[i].len2cxx . . $ match_s#len2. > extent.pos2cxx . . $ match_s#pos2. + extent.len2cxx . . $ match_s#len2.)) { |
| 818 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "match "uint32FMTcxx . . $ `libutil/util.h:65:10`!" is outside the extent!\n", i); |
| 819 | abortcxx . . $ abort(15d318a79ddce9e0).(); |
| 820 | } |
| 821 | } |
| 822 | } |
| 823 | |
| 824 | // Print out all the modified matches |
| 825 | // |
| 826 | for (uint32cxx . . $ uint32# i=0; i<matchesLen; i++) { |
| 827 | if ((matches[i].len1cxx . . $ match_s#len1. > 0) && (matches[i].len2cxx . . $ match_s#len2. > 0)) { |
| 828 | fprintf(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!, "M %s %s."uint32FMTcxx . . $ `libutil/util.h:65:10`!" . %s "uint32FMTcxx . . $ `libutil/util.h:65:10`!" "uint32FMTcxx . . $ `libutil/util.h:65:10`!" 1 %s "uint32FMTcxx . . $ `libutil/util.h:65:10`!" "uint32FMTcxx . . $ `libutil/util.h:65:10`!" %d\n", |
| 829 | m->matchuidcxx . . $ atacMatch#matchuid., m->parentuidcxx . . $ atacMatch#parentuid., i, |
| 830 | AF.labelAcxx . . $ atacFileBase#labelA(41208ce6ca65dd58).(), matches[i].pos1cxx . . $ match_s#pos1., matches[i].len1cxx . . $ match_s#len1., |
| 831 | AF.labelBcxx . . $ atacFileBase#labelB(41208ce6ca65dd58).(), matches[i].pos2cxx . . $ match_s#pos2., matches[i].len2cxx . . $ match_s#len2., matches[i].ori2cxx . . $ match_s#ori2. ? 1 : -1); |
| 832 | } |
| 833 | } |
| 834 | |
| 835 | // Check that the modified matches do not intersect anything in |
| 836 | // the tree. |
| 837 | // |
| 838 | intersectTestcxx . . $ intersectTest(a26c85d2beb8dd6e).(matches, matchesLen, Fint, Rint, matchNumber); |
| 839 | |
| 840 | matchNumber++; |
| 841 | } |
| 842 | } |