| 1 | // This file is part of A2Amapper.cxx . . $ `<file>/atac-driver/gapShifter/gapShifter.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 <unistd.h> |
| 22 | |
| 23 | #include "atac.H"cxx . . $ `<file>/atac-driver/libatac/atac.H`/ |
| 24 | #include "bio++.H"cxx . . $ `<file>/libbio/bio++.H`/ |
| 25 | #include "seqCache.H"cxx . . $ `<file>/libseq/seqCache.H`/ |
| 26 | |
| 27 | #define MAXPRINTcxx . . $ `atac-driver/gapShifter/gapShifter.C:27:9`! 90 |
| 28 | |
| 29 | #if 0 |
| 30 | #define REPORT_RESULTS |
| 31 | #define REPORT_UNSHIFTABLE |
| 32 | #define REPORT_SHIFTING |
| 33 | #endif |
| 34 | |
| 35 | // Global statistics, reset on each iteration |
| 36 | // |
| 37 | uint32cxx . . $ uint32# numShiftedcxx . . $ numShifted.; // valid to be shifted, and were shifted |
| 38 | uint32cxx . . $ uint32# numNotShiftedcxx . . $ numNotShifted.; // but valid to be shifted |
| 39 | uint32cxx . . $ uint32# numDiffSeqcxx . . $ numDiffSeq.; // all the rest are not valid to be shifted |
| 40 | uint32cxx . . $ uint32# numDiffOricxx . . $ numDiffOri.; |
| 41 | uint32cxx . . $ uint32# numZeroLencxx . . $ numZeroLen.; |
| 42 | uint32cxx . . $ uint32# numOutOfOrdercxx . . $ numOutOfOrder.; |
| 43 | uint32cxx . . $ uint32# numNotAdjacentcxx . . $ numNotAdjacent.; |
| 44 | uint32cxx . . $ uint32# numNoGapcxx . . $ numNoGap.; |
| 45 | uint32cxx . . $ uint32# numGapTooBigcxx . . $ numGapTooBig.; |
| 46 | uint32cxx . . $ uint32# numOverlappingcxx . . $ numOverlapping.; |
| 47 | uint32cxx . . $ uint32# amountShiftedcxx . . $ amountShifted.[1024]; |
| 48 | |
| 49 | FILE *logFilecxx . . $ logFile. = 0L; |
| 50 | |
| 51 | // XXXXXX outer loop needs to skip empty matches!! |
| 52 | |
| 53 | // Reads a set of matches and shifts the location of all the gaps to |
| 54 | // one side or the other. |
| 55 | // |
| 56 | // Example: |
| 57 | // |
| 58 | // A middle gap: |
| 59 | // GGGGGGGGGGATATATATATATATATATATATATGGGGGGGGG |
| 60 | // GGGGGGGGGGATAT--ATATATATATATATATATGGGGGGGGG |
| 61 | // |
| 62 | // A left-most gap: |
| 63 | // GGGGGGGGGGATATATATATATATATATATATATGGGGGGGGG |
| 64 | // GGGGGGGGGG--ATATATATATATATATATATATGGGGGGGGG |
| 65 | // |
| 66 | // A right-most gap: |
| 67 | // GGGGGGGGGGATATATATATATATATATATATATGGGGGGGGG |
| 68 | // GGGGGGGGGGATATATATATATATATATATAT--GGGGGGGGG |
| 69 | // |
| 70 | // Shifting is done for both assembly-axes. |
| 71 | |
| 72 | |
| 73 | |
| 74 | // Returns true if these two matches have a potentially shiftable gap |
| 75 | // between them. Potentially shiftable means that the matches are |
| 76 | // contiguous on one axis, and consecutive (no matches between) on |
| 77 | // the other axis. |
| 78 | // |
| 79 | // Assume the matches are sorted by the first sequence. |
| 80 | // |
| 81 | bool |
| 82 | isPotentiallyShiftablecxx . . $ isPotentiallyShiftable(19356c0e3b047b0d).(atacMatchcxx . . $ atacMatch# *ma, |
| 83 | atacMatchcxx . . $ atacMatch# *mb, |
| 84 | atacMatchOrdercxx . . $ atacMatchOrder# &MOB, |
| 85 | uint32cxx . . $ uint32# gapLimit) { |
| 86 | |
| 87 | #ifdef REPORT_UNSHIFTABLE |
| 88 | fprintf(stderr, "isPotentiallyShiftable()\n"); |
| 89 | ma->print(stderr, "A", "B"); |
| 90 | mb->print(stderr, "A", "B"); |
| 91 | #endif |
| 92 | |
| 93 | // Not shiftable if on different sequences |
| 94 | // |
| 95 | if ((ma->iid1cxx . . $ atacMatch#iid1. != mb->iid1cxx . . $ atacMatch#iid1.) || |
| 96 | (ma->iid2cxx . . $ atacMatch#iid2. != mb->iid2cxx . . $ atacMatch#iid2.)) { |
| 97 | #ifdef REPORT_UNSHIFTABLE |
| 98 | fprintf(stderr, "UNSHIFTABLE different sequences\n"); |
| 99 | #endif |
| 100 | numDiffSeqcxx . . $ numDiffSeq.++; |
| 101 | return(false); |
| 102 | } |
| 103 | |
| 104 | // Not shiftable if the orientation of the two matches is |
| 105 | // different. This is probably not a gap we want to muck with. |
| 106 | // |
| 107 | if ((ma->fwd1cxx . . $ atacMatch#fwd1. != mb->fwd1cxx . . $ atacMatch#fwd1.) || |
| 108 | (ma->fwd2cxx . . $ atacMatch#fwd2. != mb->fwd2cxx . . $ atacMatch#fwd2.)) { |
| 109 | #ifdef REPORT_UNSHIFTABLE |
| 110 | fprintf(stderr, "UNSHIFTABLE different orientation\n"); |
| 111 | #endif |
| 112 | numDiffOricxx . . $ numDiffOri.++; |
| 113 | return(false); |
| 114 | } |
| 115 | |
| 116 | // Not shiftable if any length is zero. This isn't a gap, it's a |
| 117 | // dead match. |
| 118 | // |
| 119 | if ((ma->len1cxx . . $ atacMatch#len1. == 0) || |
| 120 | (ma->len2cxx . . $ atacMatch#len2. == 0) || |
| 121 | (mb->len1cxx . . $ atacMatch#len1. == 0) || |
| 122 | (mb->len2cxx . . $ atacMatch#len2. == 0)) { |
| 123 | #ifdef REPORT_UNSHIFTABLE |
| 124 | fprintf(stderr, "UNSHIFTABLE zero length\n"); |
| 125 | #endif |
| 126 | numZeroLencxx . . $ numZeroLen.++; |
| 127 | return(false); |
| 128 | } |
| 129 | |
| 130 | atacMatchcxx . . $ atacMatch# *bl = (ma->fwd2cxx . . $ atacMatch#fwd2.) ? ma : mb; // the left match on B, relative to forward orientation |
| 131 | atacMatchcxx . . $ atacMatch# *br = (ma->fwd2cxx . . $ atacMatch#fwd2.) ? mb : ma; // the right |
| 132 | |
| 133 | // Not shiftable if the B matches are out of order |
| 134 | // |
| 135 | if (bl->pos2cxx . . $ atacMatch#pos2. > br->pos2cxx . . $ atacMatch#pos2.) { |
| 136 | #ifdef REPORT_UNSHIFTABLE |
| 137 | fprintf(stderr, "UNSHIFTABLE misordered on B\n"); |
| 138 | #endif |
| 139 | numOutOfOrdercxx . . $ numOutOfOrder.++; |
| 140 | return(false); |
| 141 | } |
| 142 | |
| 143 | uint32cxx . . $ uint32# magap = mb->pos1cxx . . $ atacMatch#pos1. - (ma->pos1cxx . . $ atacMatch#pos1. + ma->len1cxx . . $ atacMatch#len1.); |
| 144 | uint32cxx . . $ uint32# mbgap = br->pos2cxx . . $ atacMatch#pos2. - (bl->pos2cxx . . $ atacMatch#pos2. + bl->len2cxx . . $ atacMatch#len2.); |
| 145 | |
| 146 | // Not shiftable if there is no zero size gap |
| 147 | // |
| 148 | if ((magap > 0) && (mbgap > 0)) { |
| 149 | #ifdef REPORT_UNSHIFTABLE |
| 150 | fprintf(stderr, "UNSHIFTABLE no zero size gap ("uint32FMT", "uint32FMT")\n", magap, mbgap); |
| 151 | #endif |
| 152 | numNotAdjacentcxx . . $ numNotAdjacent.++; |
| 153 | return(false); |
| 154 | } |
| 155 | |
| 156 | // Not shiftabe if there is no gap |
| 157 | // |
| 158 | if ((magap == 0) && (mbgap == 0)) { |
| 159 | #ifdef REPORT_UNSHIFTABLE |
| 160 | fprintf(stderr, "UNSHIFTABLE no gap on both sequences ("uint32FMT", "uint32FMT")\n", magap, mbgap); |
| 161 | #endif |
| 162 | numNoGapcxx . . $ numNoGap.++; |
| 163 | return(false); |
| 164 | } |
| 165 | |
| 166 | // Not shiftable if the gap is big |
| 167 | // |
| 168 | if ((magap > gapLimit) || (mbgap > gapLimit)) { |
| 169 | #ifdef REPORT_UNSHIFTABLE |
| 170 | fprintf(stderr, "UNSHIFTABLE gap too big ("uint32FMT", "uint32FMT")\n", magap, mbgap); |
| 171 | #endif |
| 172 | numGapTooBigcxx . . $ numGapTooBig.++; |
| 173 | return(false); |
| 174 | } |
| 175 | |
| 176 | // Not shiftable if they overlap |
| 177 | // |
| 178 | if (ma->pos1cxx . . $ atacMatch#pos1. + ma->len1cxx . . $ atacMatch#len1. > mb->pos1cxx . . $ atacMatch#pos1.) { |
| 179 | #ifdef REPORT_UNSHIFTABLE |
| 180 | fprintf(stderr, "UNSHIFTABLE overlap on sequence A\n"); |
| 181 | #endif |
| 182 | numOverlappingcxx . . $ numOverlapping.++; |
| 183 | return(false); |
| 184 | } |
| 185 | if (bl->pos2cxx . . $ atacMatch#pos2. + bl->len2cxx . . $ atacMatch#len2. > br->pos2cxx . . $ atacMatch#pos2.) { |
| 186 | #ifdef REPORT_UNSHIFTABLE |
| 187 | fprintf(stderr, "UNSHIFTABLE overlap on sequence B\n"); |
| 188 | #endif |
| 189 | numOverlappingcxx . . $ numOverlapping.++; |
| 190 | return(false); |
| 191 | } |
| 192 | |
| 193 | uint32cxx . . $ uint32# iid1 = ma->matchiidcxx . . $ atacMatch#matchiid.; |
| 194 | uint32cxx . . $ uint32# iid2 = mb->matchiidcxx . . $ atacMatch#matchiid.; |
| 195 | |
| 196 | // Check that there isn't another match stuck in the middle on |
| 197 | // the B axis. |
| 198 | // |
| 199 | if (ma->fwd2cxx . . $ atacMatch#fwd2. == true) { |
| 200 | if ((MOB.indexcxx . . $ atacMatchOrder#index(2141b656ce2cc063).(iid1)+1) != MOB.indexcxx . . $ atacMatchOrder#index(2141b656ce2cc063).(iid2)) { |
| 201 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "WARNING: Match inbetween! (forward)\n"); |
| 202 | |
| 203 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "iid1 "uint32FMTcxx . . $ `libutil/util.h:65:10`!", iid2 "uint32FMTcxx . . $ `libutil/util.h:65:10`!"\n", iid1, iid2); |
| 204 | ma->printcxx . . $ atacMatch#print(f61d327ebbdda89f).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "A", "B"); |
| 205 | mb->printcxx . . $ atacMatch#print(f61d327ebbdda89f).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "A", "B"); |
| 206 | |
| 207 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "before, iid1, after\n"); |
| 208 | MOB[cxx . . $ atacMatchOrder#`operator[]`(4b949e4d42dbfd78).MOB.indexcxx . . $ atacMatchOrder#index(2141b656ce2cc063).(iid1)-1]->printcxx . . $ atacMatch#print(f61d327ebbdda89f).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "A", "B"); |
| 209 | MOB[cxx . . $ atacMatchOrder#`operator[]`(4b949e4d42dbfd78).MOB.indexcxx . . $ atacMatchOrder#index(2141b656ce2cc063).(iid1) ]->printcxx . . $ atacMatch#print(f61d327ebbdda89f).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "A", "B"); |
| 210 | MOB[cxx . . $ atacMatchOrder#`operator[]`(4b949e4d42dbfd78).MOB.indexcxx . . $ atacMatchOrder#index(2141b656ce2cc063).(iid1)+1]->printcxx . . $ atacMatch#print(f61d327ebbdda89f).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "A", "B"); |
| 211 | |
| 212 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "before, iid2, after\n"); |
| 213 | MOB[cxx . . $ atacMatchOrder#`operator[]`(4b949e4d42dbfd78).MOB.indexcxx . . $ atacMatchOrder#index(2141b656ce2cc063).(iid2)-1]->printcxx . . $ atacMatch#print(f61d327ebbdda89f).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "A", "B"); |
| 214 | MOB[cxx . . $ atacMatchOrder#`operator[]`(4b949e4d42dbfd78).MOB.indexcxx . . $ atacMatchOrder#index(2141b656ce2cc063).(iid2) ]->printcxx . . $ atacMatch#print(f61d327ebbdda89f).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "A", "B"); |
| 215 | MOB[cxx . . $ atacMatchOrder#`operator[]`(4b949e4d42dbfd78).MOB.indexcxx . . $ atacMatchOrder#index(2141b656ce2cc063).(iid2)+1]->printcxx . . $ atacMatch#print(f61d327ebbdda89f).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "A", "B"); |
| 216 | |
| 217 | return(false); |
| 218 | } |
| 219 | } else { |
| 220 | if ((MOB.indexcxx . . $ atacMatchOrder#index(2141b656ce2cc063).(iid1)-1) != MOB.indexcxx . . $ atacMatchOrder#index(2141b656ce2cc063).(iid2)) { |
| 221 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "WARNING: Match inbetween! (reverse-complement)\n"); |
| 222 | |
| 223 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "iid1 "uint32FMTcxx . . $ `libutil/util.h:65:10`!", iid2 "uint32FMTcxx . . $ `libutil/util.h:65:10`!"\n", iid1, iid2); |
| 224 | ma->printcxx . . $ atacMatch#print(f61d327ebbdda89f).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "A", "B"); |
| 225 | mb->printcxx . . $ atacMatch#print(f61d327ebbdda89f).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "A", "B"); |
| 226 | |
| 227 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "before, iid1, after\n"); |
| 228 | MOB[cxx . . $ atacMatchOrder#`operator[]`(4b949e4d42dbfd78).MOB.indexcxx . . $ atacMatchOrder#index(2141b656ce2cc063).(iid1)-1]->printcxx . . $ atacMatch#print(f61d327ebbdda89f).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "A", "B"); |
| 229 | MOB[cxx . . $ atacMatchOrder#`operator[]`(4b949e4d42dbfd78).MOB.indexcxx . . $ atacMatchOrder#index(2141b656ce2cc063).(iid1) ]->printcxx . . $ atacMatch#print(f61d327ebbdda89f).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "A", "B"); |
| 230 | MOB[cxx . . $ atacMatchOrder#`operator[]`(4b949e4d42dbfd78).MOB.indexcxx . . $ atacMatchOrder#index(2141b656ce2cc063).(iid1)+1]->printcxx . . $ atacMatch#print(f61d327ebbdda89f).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "A", "B"); |
| 231 | |
| 232 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "before, iid2, after\n"); |
| 233 | MOB[cxx . . $ atacMatchOrder#`operator[]`(4b949e4d42dbfd78).MOB.indexcxx . . $ atacMatchOrder#index(2141b656ce2cc063).(iid2)-1]->printcxx . . $ atacMatch#print(f61d327ebbdda89f).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "A", "B"); |
| 234 | MOB[cxx . . $ atacMatchOrder#`operator[]`(4b949e4d42dbfd78).MOB.indexcxx . . $ atacMatchOrder#index(2141b656ce2cc063).(iid2) ]->printcxx . . $ atacMatch#print(f61d327ebbdda89f).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "A", "B"); |
| 235 | MOB[cxx . . $ atacMatchOrder#`operator[]`(4b949e4d42dbfd78).MOB.indexcxx . . $ atacMatchOrder#index(2141b656ce2cc063).(iid2)+1]->printcxx . . $ atacMatch#print(f61d327ebbdda89f).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "A", "B"); |
| 236 | |
| 237 | return(false); |
| 238 | } |
| 239 | } |
| 240 | |
| 241 | return(true); |
| 242 | } |
| 243 | |
| 244 | |
| 245 | |
| 246 | void |
| 247 | dumpAgapcxx . . $ dumpAgap(4230c8483992e864).(atacMatchcxx . . $ atacMatch# *ma, atacMatchcxx . . $ atacMatch# *mb, |
| 248 | atacMatchOrdercxx . . $ atacMatchOrder# &MOB, |
| 249 | seqCachecxx . . $ seqCache# *C1, seqCachecxx . . $ seqCache# *C2, |
| 250 | uint32cxx . . $ uint32# gapLimit, |
| 251 | bool shiftRight) { |
| 252 | } |
| 253 | |
| 254 | |
| 255 | void |
| 256 | dumpBgapcxx . . $ dumpBgap(4230c8483992e864).(atacMatchcxx . . $ atacMatch# *ma, atacMatchcxx . . $ atacMatch# *mb, |
| 257 | atacMatchOrdercxx . . $ atacMatchOrder# &MOB, |
| 258 | seqCachecxx . . $ seqCache# *C1, seqCachecxx . . $ seqCache# *C2, |
| 259 | uint32cxx . . $ uint32# gapLimit, |
| 260 | bool shiftRight) { |
| 261 | } |
| 262 | |
| 263 | |
| 264 | // Returns the beginning of the sequence from pos to pos+len |
| 265 | char * |
| 266 | getSequenceBegcxx . . $ getSequenceBeg(35e4bbf65cc8cb9e).(char *str, uint32cxx . . $ uint32# pos, uint32cxx . . $ uint32# len, FastAAccessorcxx . . $ FastAAccessor# &it) { |
| 267 | uint32cxx . . $ uint32# i = 0; |
| 268 | |
| 269 | it.setRangecxx . . $ FastAAccessor#setRange(8e1b545ea3aecce3).(pos, len); |
| 270 | |
| 271 | if (len > MAXPRINTcxx . . $ `atac-driver/gapShifter/gapShifter.C:27:9`!) |
| 272 | len = MAXPRINTcxx . . $ `atac-driver/gapShifter/gapShifter.C:27:9`!; |
| 273 | |
| 274 | if (len > 0) { |
| 275 | it.setPositioncxx . . $ FastAAccessor#setPosition(dfa6e707f7696010).(pos); |
| 276 | |
| 277 | for (i=0; i<len; i++, ++cxx . . $ FastAAccessor#operator++(ab00271b6674b0d4).it) |
| 278 | str[i] = *cxx . . $ FastAAccessor#`operator*`(1b8b762cbef9c2c9).it; |
| 279 | } |
| 280 | str[i] = 0; |
| 281 | |
| 282 | return(str); |
| 283 | } |
| 284 | |
| 285 | |
| 286 | // Returns all sequence from pos to pos+len |
| 287 | char * |
| 288 | getSequenceAllcxx . . $ getSequenceAll(35e4bbf65cc8cb9e).(char *str, uint32cxx . . $ uint32# pos, uint32cxx . . $ uint32# len, FastAAccessorcxx . . $ FastAAccessor# &it) { |
| 289 | uint32cxx . . $ uint32# i = 0; |
| 290 | |
| 291 | it.setRangecxx . . $ FastAAccessor#setRange(8e1b545ea3aecce3).(pos, len); |
| 292 | |
| 293 | if (len > 0) { |
| 294 | it.setPositioncxx . . $ FastAAccessor#setPosition(dfa6e707f7696010).(pos); |
| 295 | |
| 296 | for (i=0; i<len; i++, ++cxx . . $ FastAAccessor#operator++(ab00271b6674b0d4).it) |
| 297 | str[i] = *cxx . . $ FastAAccessor#`operator*`(1b8b762cbef9c2c9).it; |
| 298 | } |
| 299 | str[i] = 0; |
| 300 | |
| 301 | return(str); |
| 302 | } |
| 303 | |
| 304 | |
| 305 | // Returns the end of the sequence from pos to pos+len |
| 306 | char * |
| 307 | getSequenceEndcxx . . $ getSequenceEnd(35e4bbf65cc8cb9e).(char *str, uint32cxx . . $ uint32# pos, uint32cxx . . $ uint32# len, FastAAccessorcxx . . $ FastAAccessor# &it) { |
| 308 | uint32cxx . . $ uint32# i = 0; |
| 309 | |
| 310 | it.setRangecxx . . $ FastAAccessor#setRange(8e1b545ea3aecce3).(pos, len); |
| 311 | |
| 312 | pos += len; |
| 313 | if (len > MAXPRINTcxx . . $ `atac-driver/gapShifter/gapShifter.C:27:9`!) |
| 314 | len = MAXPRINTcxx . . $ `atac-driver/gapShifter/gapShifter.C:27:9`!; |
| 315 | |
| 316 | if (len > 0) { |
| 317 | it.setPositioncxx . . $ FastAAccessor#setPosition(dfa6e707f7696010).(pos - len); |
| 318 | |
| 319 | for (i=0; i<len; i++, ++cxx . . $ FastAAccessor#operator++(ab00271b6674b0d4).it) |
| 320 | str[i] = *cxx . . $ FastAAccessor#`operator*`(1b8b762cbef9c2c9).it; |
| 321 | } |
| 322 | str[i] = 0; |
| 323 | |
| 324 | return(str); |
| 325 | } |
| 326 | |
| 327 | |
| 328 | |
| 329 | uint32cxx . . $ uint32# |
| 330 | shiftGapcxx . . $ shiftGap(6ffbc924b31ef216).(atacFilecxx . . $ atacFile# &AF, |
| 331 | atacMatchListcxx . . $ atacMatchList# &ML, |
| 332 | atacMatchcxx . . $ atacMatch# *ma, atacMatchcxx . . $ atacMatch# *mb, |
| 333 | atacMatchOrdercxx . . $ atacMatchOrder# &MOB, |
| 334 | seqCachecxx . . $ seqCache# *C1, seqCachecxx . . $ seqCache# *C2, |
| 335 | uint32cxx . . $ uint32# gapLimit, |
| 336 | bool shiftRight) { |
| 337 | |
| 338 | #ifdef REPORT_RESULTS |
| 339 | fprintf(stderr, "----------------------------------------\n"); |
| 340 | #endif |
| 341 | |
| 342 | if (isPotentiallyShiftablecxx . . $ isPotentiallyShiftable(19356c0e3b047b0d).(ma, mb, MOB, gapLimit) == false) |
| 343 | return(0); |
| 344 | |
| 345 | // Save a copy of the original matches |
| 346 | atacMatchcxx . . $ atacMatch# macopy = *ma; |
| 347 | atacMatchcxx . . $ atacMatch# mbcopy = *mb; |
| 348 | |
| 349 | // Grab the sequences we use, and make the accesors |
| 350 | // |
| 351 | seqInCorecxx . . $ seqInCore# *s1 = C1->getSequenceInCorecxx . . $ seqCache#getSequenceInCore(715c05706546271f).(ma->iid1cxx . . $ atacMatch#iid1.); |
| 352 | seqInCorecxx . . $ seqInCore# *s2 = C2->getSequenceInCorecxx . . $ seqCache#getSequenceInCore(715c05706546271f).(ma->iid2cxx . . $ atacMatch#iid2.); |
| 353 | |
| 354 | FastAAccessorcxx . . $ FastAAccessor# mas1cxx . . $ FastAAccessor#FastAAccessor(15bbd9d839cdf78d).(s1, ma->fwd1cxx . . $ atacMatch#fwd1. == false); |
| 355 | FastAAccessorcxx . . $ FastAAccessor# mas2cxx . . $ FastAAccessor#FastAAccessor(15bbd9d839cdf78d).(s2, ma->fwd2cxx . . $ atacMatch#fwd2. == false); |
| 356 | FastAAccessorcxx . . $ FastAAccessor# mbs1cxx . . $ FastAAccessor#FastAAccessor(15bbd9d839cdf78d).(s1, mb->fwd1cxx . . $ atacMatch#fwd1. == false); |
| 357 | FastAAccessorcxx . . $ FastAAccessor# mbs2cxx . . $ FastAAccessor#FastAAccessor(15bbd9d839cdf78d).(s2, mb->fwd2cxx . . $ atacMatch#fwd2. == false); |
| 358 | |
| 359 | mas1.setRangecxx . . $ FastAAccessor#setRange(8e1b545ea3aecce3).(ma->pos1cxx . . $ atacMatch#pos1., ma->len1cxx . . $ atacMatch#len1.); |
| 360 | mas2.setRangecxx . . $ FastAAccessor#setRange(8e1b545ea3aecce3).(ma->pos2cxx . . $ atacMatch#pos2., ma->len2cxx . . $ atacMatch#len2.); |
| 361 | mbs1.setRangecxx . . $ FastAAccessor#setRange(8e1b545ea3aecce3).(mb->pos1cxx . . $ atacMatch#pos1., mb->len1cxx . . $ atacMatch#len1.); |
| 362 | mbs2.setRangecxx . . $ FastAAccessor#setRange(8e1b545ea3aecce3).(mb->pos2cxx . . $ atacMatch#pos2., mb->len2cxx . . $ atacMatch#len2.); |
| 363 | |
| 364 | uint32cxx . . $ uint32# shifted = 0; |
| 365 | |
| 366 | // We want to extend ma to the right, this will shift the gap to |
| 367 | // the right-most position (relative to the forward genomic). |
| 368 | // |
| 369 | // While there is a match after ma, extend ma to the right, and |
| 370 | // decrease mb from the left. |
| 371 | // |
| 372 | if (shiftRight == false) { |
| 373 | |
| 374 | // Similar to above. The accessor hides most of the pain caused |
| 375 | // by reverse complement. |
| 376 | |
| 377 | mas1.setPositioncxx . . $ FastAAccessor#setPosition(dfa6e707f7696010).(ma->pos1cxx . . $ atacMatch#pos1. + ma->len1cxx . . $ atacMatch#len1. - 1); |
| 378 | mas2.setPositioncxx . . $ FastAAccessor#setPosition(dfa6e707f7696010).(ma->pos2cxx . . $ atacMatch#pos2. + ma->len2cxx . . $ atacMatch#len2. - 1); |
| 379 | |
| 380 | mbs1.setPositioncxx . . $ FastAAccessor#setPosition(dfa6e707f7696010).(mb->pos1cxx . . $ atacMatch#pos1.); --cxx . . $ FastAAccessor#operator--(ab00271b6674b0d4).mbs1; |
| 381 | mbs2.setPositioncxx . . $ FastAAccessor#setPosition(dfa6e707f7696010).(mb->pos2cxx . . $ atacMatch#pos2.); --cxx . . $ FastAAccessor#operator--(ab00271b6674b0d4).mbs2; |
| 382 | |
| 383 | |
| 384 | #ifdef REPORT_DEBUG |
| 385 | // Dump out some sequence to see where we really are |
| 386 | // |
| 387 | fprintf(stderr, "A: "); |
| 388 | for (uint32 i=0; i<50; i++) { |
| 389 | fprintf(stderr, "%c", *mas1); |
| 390 | --mas1; |
| 391 | } |
| 392 | fprintf(stderr, "\n"); |
| 393 | |
| 394 | fprintf(stderr, "B: "); |
| 395 | for (uint32 i=0; i<50; i++) { |
| 396 | fprintf(stderr, "%c", *mbs1); |
| 397 | --mbs1; |
| 398 | } |
| 399 | fprintf(stderr, "\n"); |
| 400 | |
| 401 | // Reset the iterators |
| 402 | // |
| 403 | mas1.setPosition(ma->pos1 + ma->len1 - 1); |
| 404 | mas2.setPosition(ma->pos2 + ma->len2 - 1); |
| 405 | |
| 406 | mbs1.setPosition(mb->pos1); --mbs1; |
| 407 | mbs2.setPosition(mb->pos2); --mbs2; |
| 408 | #endif |
| 409 | |
| 410 | |
| 411 | |
| 412 | while (mas1.isValidcxx . . $ FastAAccessor#isValid(c9857a73d68e59ba).() && |
| 413 | mas2.isValidcxx . . $ FastAAccessor#isValid(c9857a73d68e59ba).() && |
| 414 | mbs1.isValidcxx . . $ FastAAccessor#isValid(c9857a73d68e59ba).() && |
| 415 | mbs2.isValidcxx . . $ FastAAccessor#isValid(c9857a73d68e59ba).() && |
| 416 | (ma->len1cxx . . $ atacMatch#len1. > 0) && |
| 417 | (ma->len2cxx . . $ atacMatch#len2. > 0) && |
| 418 | (letterToBits[(int)*cxx . . $ FastAAccessor#`operator*`(1b8b762cbef9c2c9).mbs1] != 0xff) && |
| 419 | (letterToBits[(int)*cxx . . $ FastAAccessor#`operator*`(1b8b762cbef9c2c9).mbs2] != 0xff) && |
| 420 | IUPACidentity[(int)*cxx . . $ FastAAccessor#`operator*`(1b8b762cbef9c2c9).mbs1][(int)*cxx . . $ FastAAccessor#`operator*`(1b8b762cbef9c2c9).mbs2]) { |
| 421 | |
| 422 | #ifdef REPORT_SHIFTING |
| 423 | fprintf(stderr, "EXTENDrev: MA %c/%c ----- %c/%c MB\n", |
| 424 | *mas1, *mas2, *mbs1, *mbs2); |
| 425 | #endif |
| 426 | |
| 427 | mas1.extendRightcxx . . $ FastAAccessor#extendRight(83c267b20bac841a).(-1); ma->len1cxx . . $ atacMatch#len1.--; --cxx . . $ FastAAccessor#operator--(ab00271b6674b0d4).mas1; |
| 428 | mas2.extendRightcxx . . $ FastAAccessor#extendRight(83c267b20bac841a).(-1); ma->len2cxx . . $ atacMatch#len2.--; --cxx . . $ FastAAccessor#operator--(ab00271b6674b0d4).mas2; |
| 429 | |
| 430 | mbs1.extendLeftcxx . . $ FastAAccessor#extendLeft(83c267b20bac841a).(1); mb->len1cxx . . $ atacMatch#len1.++; --cxx . . $ FastAAccessor#operator--(ab00271b6674b0d4).mbs1; |
| 431 | mbs2.extendLeftcxx . . $ FastAAccessor#extendLeft(83c267b20bac841a).(1); mb->len2cxx . . $ atacMatch#len2.++; --cxx . . $ FastAAccessor#operator--(ab00271b6674b0d4).mbs2; |
| 432 | |
| 433 | shifted++; |
| 434 | } |
| 435 | } else { |
| 436 | |
| 437 | // A wants to be the first thing after ma -- the first base in |
| 438 | // the gap. Set the position to the last thing in the range, |
| 439 | // then use the increment operator to extend past that. The spec |
| 440 | // on FastAAccessor says we can't directly go somewhere outside |
| 441 | // the range. |
| 442 | // |
| 443 | mas1.setPositioncxx . . $ FastAAccessor#setPosition(dfa6e707f7696010).(ma->pos1cxx . . $ atacMatch#pos1. + ma->len1cxx . . $ atacMatch#len1. - 1); ++cxx . . $ FastAAccessor#operator++(ab00271b6674b0d4).mas1; |
| 444 | mas2.setPositioncxx . . $ FastAAccessor#setPosition(dfa6e707f7696010).(ma->pos2cxx . . $ atacMatch#pos2. + ma->len2cxx . . $ atacMatch#len2. - 1); ++cxx . . $ FastAAccessor#operator++(ab00271b6674b0d4).mas2; |
| 445 | |
| 446 | // B can be set to the first thing in the match with no problem. |
| 447 | // |
| 448 | mbs1.setPositioncxx . . $ FastAAccessor#setPosition(dfa6e707f7696010).(mb->pos1cxx . . $ atacMatch#pos1.); |
| 449 | mbs2.setPositioncxx . . $ FastAAccessor#setPosition(dfa6e707f7696010).(mb->pos2cxx . . $ atacMatch#pos2.); |
| 450 | |
| 451 | // While we're still in sequence (isValid()) and we haven't |
| 452 | // obliterated the match we're shifting the gap into, and we can |
| 453 | // extend the other match (being both validSymbols and identity), |
| 454 | // shift the gap to the right. |
| 455 | // |
| 456 | while (mas1.isValidcxx . . $ FastAAccessor#isValid(c9857a73d68e59ba).() && |
| 457 | mas2.isValidcxx . . $ FastAAccessor#isValid(c9857a73d68e59ba).() && |
| 458 | mbs1.isValidcxx . . $ FastAAccessor#isValid(c9857a73d68e59ba).() && |
| 459 | mbs2.isValidcxx . . $ FastAAccessor#isValid(c9857a73d68e59ba).() && |
| 460 | (mb->len1cxx . . $ atacMatch#len1. > 0) && |
| 461 | (mb->len2cxx . . $ atacMatch#len2. > 0) && |
| 462 | (letterToBits[(int)*cxx . . $ FastAAccessor#`operator*`(1b8b762cbef9c2c9).mas1]) && |
| 463 | (letterToBits[(int)*cxx . . $ FastAAccessor#`operator*`(1b8b762cbef9c2c9).mas2]) && |
| 464 | IUPACidentity[(int)*cxx . . $ FastAAccessor#`operator*`(1b8b762cbef9c2c9).mas1][(int)*cxx . . $ FastAAccessor#`operator*`(1b8b762cbef9c2c9).mas2]) { |
| 465 | |
| 466 | #ifdef REPORT_SHIFTING |
| 467 | fprintf(stderr, "EXTENDfwd: MA %c/%c ----- %c/%c MB\n", |
| 468 | *mas1, *mas2, *mbs1, *mbs2); |
| 469 | #endif |
| 470 | |
| 471 | mas1.extendRightcxx . . $ FastAAccessor#extendRight(83c267b20bac841a).(1); ma->len1cxx . . $ atacMatch#len1.++; ++cxx . . $ FastAAccessor#operator++(ab00271b6674b0d4).mas1; |
| 472 | mas2.extendRightcxx . . $ FastAAccessor#extendRight(83c267b20bac841a).(1); ma->len2cxx . . $ atacMatch#len2.++; ++cxx . . $ FastAAccessor#operator++(ab00271b6674b0d4).mas2; |
| 473 | |
| 474 | mbs1.extendLeftcxx . . $ FastAAccessor#extendLeft(83c267b20bac841a).(-1); mb->len1cxx . . $ atacMatch#len1.--; ++cxx . . $ FastAAccessor#operator++(ab00271b6674b0d4).mbs1; |
| 475 | mbs2.extendLeftcxx . . $ FastAAccessor#extendLeft(83c267b20bac841a).(-1); mb->len2cxx . . $ atacMatch#len2.--; ++cxx . . $ FastAAccessor#operator++(ab00271b6674b0d4).mbs2; |
| 476 | |
| 477 | shifted++; |
| 478 | } |
| 479 | } |
| 480 | |
| 481 | // Finally, update the two matches with the shifted results. |
| 482 | |
| 483 | ma->pos1cxx . . $ atacMatch#pos1. = mas1.getRangeBegincxx . . $ FastAAccessor#getRangeBegin(db52760e79bf9054).(); |
| 484 | ma->len1cxx . . $ atacMatch#len1. = mas1.getRangeLengthcxx . . $ FastAAccessor#getRangeLength(db52760e79bf9054).(); |
| 485 | ma->pos2cxx . . $ atacMatch#pos2. = mas2.getRangeBegincxx . . $ FastAAccessor#getRangeBegin(db52760e79bf9054).(); |
| 486 | ma->len2cxx . . $ atacMatch#len2. = mas2.getRangeLengthcxx . . $ FastAAccessor#getRangeLength(db52760e79bf9054).(); |
| 487 | mb->pos1cxx . . $ atacMatch#pos1. = mbs1.getRangeBegincxx . . $ FastAAccessor#getRangeBegin(db52760e79bf9054).(); |
| 488 | mb->len1cxx . . $ atacMatch#len1. = mbs1.getRangeLengthcxx . . $ FastAAccessor#getRangeLength(db52760e79bf9054).(); |
| 489 | mb->pos2cxx . . $ atacMatch#pos2. = mbs2.getRangeBegincxx . . $ FastAAccessor#getRangeBegin(db52760e79bf9054).(); |
| 490 | mb->len2cxx . . $ atacMatch#len2. = mbs2.getRangeLengthcxx . . $ FastAAccessor#getRangeLength(db52760e79bf9054).(); |
| 491 | |
| 492 | |
| 493 | // |
| 494 | // The rest is just error checking. |
| 495 | // |
| 496 | |
| 497 | if (shifted) |
| 498 | numShiftedcxx . . $ numShifted.++; |
| 499 | else |
| 500 | numNotShiftedcxx . . $ numNotShifted.++; |
| 501 | |
| 502 | if (shifted < 1024) |
| 503 | amountShiftedcxx . . $ amountShifted.[shifted]++; |
| 504 | |
| 505 | // leftmatch origend newend rightmatch origbegin newbegin |
| 506 | if (shifted && logFilecxx . . $ logFile.) { |
| 507 | if (ma->fwd2cxx . . $ atacMatch#fwd2.) { |
| 508 | // Forward matches are easy. |
| 509 | // |
| 510 | fprintf(logFilecxx . . $ logFile., "%s\t%s\t%s:"uint32FMTcxx . . $ `libutil/util.h:65:10`!"\t"uint32FMTcxx . . $ `libutil/util.h:65:10`!"\t"uint32FMTcxx . . $ `libutil/util.h:65:10`!"\t->\t"uint32FMTcxx . . $ `libutil/util.h:65:10`!"\t"uint32FMTcxx . . $ `libutil/util.h:65:10`!"\t", |
| 511 | ma->matchuidcxx . . $ atacMatch#matchuid., mb->matchuidcxx . . $ atacMatch#matchuid., |
| 512 | AF.labelAcxx . . $ atacFileBase#labelA(41208ce6ca65dd58).(), ma->iid1cxx . . $ atacMatch#iid1., |
| 513 | macopy.pos1cxx . . $ atacMatch#pos1. + macopy.len1cxx . . $ atacMatch#len1., ma->pos1cxx . . $ atacMatch#pos1. + ma->len1cxx . . $ atacMatch#len1., |
| 514 | mbcopy.pos1cxx . . $ atacMatch#pos1., mb->pos1cxx . . $ atacMatch#pos1.); |
| 515 | fprintf(logFilecxx . . $ logFile., "%s:"uint32FMTcxx . . $ `libutil/util.h:65:10`!"\t"uint32FMTcxx . . $ `libutil/util.h:65:10`!"\t"uint32FMTcxx . . $ `libutil/util.h:65:10`!"\t->\t"uint32FMTcxx . . $ `libutil/util.h:65:10`!"\t"uint32FMTcxx . . $ `libutil/util.h:65:10`!"\n", |
| 516 | AF.labelBcxx . . $ atacFileBase#labelB(41208ce6ca65dd58).(), ma->iid2cxx . . $ atacMatch#iid2., |
| 517 | macopy.pos2cxx . . $ atacMatch#pos2. + macopy.len2cxx . . $ atacMatch#len2., ma->pos2cxx . . $ atacMatch#pos2. + ma->len2cxx . . $ atacMatch#len2., |
| 518 | mbcopy.pos2cxx . . $ atacMatch#pos2., mb->pos2cxx . . $ atacMatch#pos2.); |
| 519 | } else { |
| 520 | // Reverse matches are painful. The gap on B is between the |
| 521 | // right edge of mb, and the the left edge of ma. |
| 522 | // |
| 523 | fprintf(logFilecxx . . $ logFile., "%s\t%s\t%s:"uint32FMTcxx . . $ `libutil/util.h:65:10`!"\t"uint32FMTcxx . . $ `libutil/util.h:65:10`!"\t"uint32FMTcxx . . $ `libutil/util.h:65:10`!"\t->\t"uint32FMTcxx . . $ `libutil/util.h:65:10`!"\t"uint32FMTcxx . . $ `libutil/util.h:65:10`!"\t", |
| 524 | ma->matchuidcxx . . $ atacMatch#matchuid., mb->matchuidcxx . . $ atacMatch#matchuid., |
| 525 | AF.labelAcxx . . $ atacFileBase#labelA(41208ce6ca65dd58).(), ma->iid1cxx . . $ atacMatch#iid1., |
| 526 | macopy.pos1cxx . . $ atacMatch#pos1. + macopy.len1cxx . . $ atacMatch#len1., ma->pos1cxx . . $ atacMatch#pos1. + ma->len1cxx . . $ atacMatch#len1., |
| 527 | mbcopy.pos1cxx . . $ atacMatch#pos1., mb->pos1cxx . . $ atacMatch#pos1.); |
| 528 | fprintf(logFilecxx . . $ logFile., "%s:"uint32FMTcxx . . $ `libutil/util.h:65:10`!"\t"uint32FMTcxx . . $ `libutil/util.h:65:10`!"\t"uint32FMTcxx . . $ `libutil/util.h:65:10`!"\t->\t"uint32FMTcxx . . $ `libutil/util.h:65:10`!"\t"uint32FMTcxx . . $ `libutil/util.h:65:10`!"\n", |
| 529 | AF.labelBcxx . . $ atacFileBase#labelB(41208ce6ca65dd58).(), ma->iid2cxx . . $ atacMatch#iid2., |
| 530 | mbcopy.pos2cxx . . $ atacMatch#pos2. + mbcopy.len2cxx . . $ atacMatch#len2., mb->pos2cxx . . $ atacMatch#pos2. + mb->len2cxx . . $ atacMatch#len2., |
| 531 | macopy.pos2cxx . . $ atacMatch#pos2., ma->pos2cxx . . $ atacMatch#pos2.); |
| 532 | } |
| 533 | } |
| 534 | |
| 535 | |
| 536 | #ifdef REPORT_RESULTS |
| 537 | if (shifted) |
| 538 | fprintf(stderr, "SHIFTED "uint32FMT" bases.\n", shifted); |
| 539 | else |
| 540 | fprintf(stderr, "NOT SHIFTED.\n"); |
| 541 | |
| 542 | fprintf(stderr, uint32FMTW(9)"-"uint32FMTW(9)" -- "uint32FMTW(9)"-"uint32FMTW(9)"\n", |
| 543 | macopy.pos1, macopy.pos1 + macopy.len1, |
| 544 | mbcopy.pos1, mbcopy.pos1 + mbcopy.len1); |
| 545 | fprintf(stderr, uint32FMTW(9)"-"uint32FMTW(9)" -- "uint32FMTW(9)"-"uint32FMTW(9)"\n", |
| 546 | macopy.pos2, macopy.pos2 + macopy.len2, |
| 547 | mbcopy.pos2, mbcopy.pos2 + mbcopy.len2); |
| 548 | fprintf(stderr, "shifted "uint32FMT" bases (fwd1=%d fwd2=%d fwd1=%d fwd2=%d)\n", shifted, ma->fwd1, ma->fwd2, mb->fwd1, mb->fwd2); |
| 549 | fprintf(stderr, uint32FMTW(9)"-"uint32FMTW(9)" -- "uint32FMTW(9)"-"uint32FMTW(9)"\n", |
| 550 | ma->pos1, ma->pos1 + ma->len1, |
| 551 | mb->pos1, mb->pos1 + mb->len1); |
| 552 | fprintf(stderr, uint32FMTW(9)"-"uint32FMTW(9)" -- "uint32FMTW(9)"-"uint32FMTW(9)"\n", |
| 553 | ma->pos2, ma->pos2 + ma->len2, |
| 554 | mb->pos2, mb->pos2 + mb->len2); |
| 555 | #endif |
| 556 | |
| 557 | uint32cxx . . $ uint32# errors = 0; |
| 558 | |
| 559 | if (macopy.pos1cxx . . $ atacMatch#pos1. != ma->pos1cxx . . $ atacMatch#pos1.) |
| 560 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "WARNING: begin of assembly 1 moved!\n"), errors++; |
| 561 | if (mbcopy.pos1cxx . . $ atacMatch#pos1. + mbcopy.len1cxx . . $ atacMatch#len1. != mb->pos1cxx . . $ atacMatch#pos1. + mb->len1cxx . . $ atacMatch#len1.) |
| 562 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "WARNING: end of assembly 1 moved!\n"), errors++; |
| 563 | |
| 564 | if ((ma->fwd2cxx . . $ atacMatch#fwd2. == true) && (macopy.pos2cxx . . $ atacMatch#pos2. != ma->pos2cxx . . $ atacMatch#pos2.)) |
| 565 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "WARNING: begin of assembly 2 moved!\n"), errors++; |
| 566 | if ((ma->fwd2cxx . . $ atacMatch#fwd2. == false) && (mbcopy.pos2cxx . . $ atacMatch#pos2. != mb->pos2cxx . . $ atacMatch#pos2.)) |
| 567 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "WARNING: begin of assembly 2 moved (rc)!\n"), errors++; |
| 568 | |
| 569 | if ((ma->fwd2cxx . . $ atacMatch#fwd2. == true) && (mbcopy.pos2cxx . . $ atacMatch#pos2. + mbcopy.len2cxx . . $ atacMatch#len2. != mb->pos2cxx . . $ atacMatch#pos2. + mb->len2cxx . . $ atacMatch#len2.)) |
| 570 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "WARNING: end of assembly 1 moved!\n"), errors++; |
| 571 | if ((ma->fwd2cxx . . $ atacMatch#fwd2. == false) && (macopy.pos2cxx . . $ atacMatch#pos2. + macopy.len2cxx . . $ atacMatch#len2. != ma->pos2cxx . . $ atacMatch#pos2. + ma->len2cxx . . $ atacMatch#len2.)) |
| 572 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "WARNING: end of assembly 2 moved (rc)!\n"), errors++; |
| 573 | |
| 574 | // For debugging, claim there were errors if we shifted something. |
| 575 | #ifdef REPORT_RESULTS |
| 576 | errors++; |
| 577 | #endif |
| 578 | |
| 579 | if (errors > 0) { |
| 580 | atacMatchcxx . . $ atacMatch# *l = 0L; |
| 581 | atacMatchcxx . . $ atacMatch# *r = 0L; |
| 582 | char str1[1024]; |
| 583 | char str2[1024]; |
| 584 | char str3[1024]; |
| 585 | |
| 586 | // Print the sequence. We could print each piece separately |
| 587 | // (and, indeed, we tried that initially) but that's difficult |
| 588 | // because we need to remember which match is first on B, |
| 589 | |
| 590 | macopy.printcxx . . $ atacMatch#print(f61d327ebbdda89f).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "A", "B"); |
| 591 | mbcopy.printcxx . . $ atacMatch#print(f61d327ebbdda89f).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "A", "B"); |
| 592 | l = &macopy; |
| 593 | r = &mbcopy; |
| 594 | |
| 595 | getSequenceEndcxx . . $ getSequenceEnd(35e4bbf65cc8cb9e).(str1, l->pos1cxx . . $ atacMatch#pos1., l->len1cxx . . $ atacMatch#len1., mas1); |
| 596 | getSequenceAllcxx . . $ getSequenceAll(35e4bbf65cc8cb9e).(str2, l->pos1cxx . . $ atacMatch#pos1. + l->len1cxx . . $ atacMatch#len1., r->pos1cxx . . $ atacMatch#pos1. - l->pos1cxx . . $ atacMatch#pos1. - l->len1cxx . . $ atacMatch#len1., mas1); |
| 597 | getSequenceBegcxx . . $ getSequenceBeg(35e4bbf65cc8cb9e).(str3, r->pos1cxx . . $ atacMatch#pos1., r->len1cxx . . $ atacMatch#len1., mas1); |
| 598 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "SEQA: %s -- %s -- %s\n", str1, str2, str3); |
| 599 | |
| 600 | if (macopy.fwd2cxx . . $ atacMatch#fwd2.) { |
| 601 | // We're forward, so l is really first on B. |
| 602 | getSequenceEndcxx . . $ getSequenceEnd(35e4bbf65cc8cb9e).(str1, l->pos2cxx . . $ atacMatch#pos2., l->len2cxx . . $ atacMatch#len2., mas2); |
| 603 | getSequenceAllcxx . . $ getSequenceAll(35e4bbf65cc8cb9e).(str2, l->pos2cxx . . $ atacMatch#pos2. + l->len2cxx . . $ atacMatch#len2., r->pos2cxx . . $ atacMatch#pos2. - l->pos2cxx . . $ atacMatch#pos2. - l->len2cxx . . $ atacMatch#len2., mas2); |
| 604 | getSequenceBegcxx . . $ getSequenceBeg(35e4bbf65cc8cb9e).(str3, r->pos2cxx . . $ atacMatch#pos2., r->len2cxx . . $ atacMatch#len2., mas2); |
| 605 | } else { |
| 606 | // Nope, reverse complement, so r is really first on B. This |
| 607 | // only changes how we get the gap. |
| 608 | // |
| 609 | getSequenceEndcxx . . $ getSequenceEnd(35e4bbf65cc8cb9e).(str1, l->pos2cxx . . $ atacMatch#pos2., l->len2cxx . . $ atacMatch#len2., mas2); |
| 610 | getSequenceAllcxx . . $ getSequenceAll(35e4bbf65cc8cb9e).(str2, r->pos2cxx . . $ atacMatch#pos2. + r->len2cxx . . $ atacMatch#len2., l->pos2cxx . . $ atacMatch#pos2. - r->pos2cxx . . $ atacMatch#pos2. - r->len2cxx . . $ atacMatch#len2., mas2); |
| 611 | getSequenceBegcxx . . $ getSequenceBeg(35e4bbf65cc8cb9e).(str3, r->pos2cxx . . $ atacMatch#pos2., r->len2cxx . . $ atacMatch#len2., mas2); |
| 612 | } |
| 613 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "SEQB: %s -- %s -- %s\n", str1, str2, str3); |
| 614 | |
| 615 | |
| 616 | // Do the same thing (same getSequence calls) for the after picture. |
| 617 | |
| 618 | ma->printcxx . . $ atacMatch#print(f61d327ebbdda89f).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "A", "B"); |
| 619 | mb->printcxx . . $ atacMatch#print(f61d327ebbdda89f).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "A", "B"); |
| 620 | l = ma; |
| 621 | r = mb; |
| 622 | |
| 623 | getSequenceEndcxx . . $ getSequenceEnd(35e4bbf65cc8cb9e).(str1, l->pos1cxx . . $ atacMatch#pos1., l->len1cxx . . $ atacMatch#len1., mas1); |
| 624 | getSequenceAllcxx . . $ getSequenceAll(35e4bbf65cc8cb9e).(str2, l->pos1cxx . . $ atacMatch#pos1. + l->len1cxx . . $ atacMatch#len1., r->pos1cxx . . $ atacMatch#pos1. - l->pos1cxx . . $ atacMatch#pos1. - l->len1cxx . . $ atacMatch#len1., mas1); |
| 625 | getSequenceBegcxx . . $ getSequenceBeg(35e4bbf65cc8cb9e).(str3, r->pos1cxx . . $ atacMatch#pos1., r->len1cxx . . $ atacMatch#len1., mas1); |
| 626 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "SEQA: %s -- %s -- %s\n", str1, str2, str3); |
| 627 | |
| 628 | if (ma->fwd2cxx . . $ atacMatch#fwd2.) { |
| 629 | getSequenceEndcxx . . $ getSequenceEnd(35e4bbf65cc8cb9e).(str1, l->pos2cxx . . $ atacMatch#pos2., l->len2cxx . . $ atacMatch#len2., mas2); |
| 630 | getSequenceAllcxx . . $ getSequenceAll(35e4bbf65cc8cb9e).(str2, l->pos2cxx . . $ atacMatch#pos2. + l->len2cxx . . $ atacMatch#len2., r->pos2cxx . . $ atacMatch#pos2. - l->pos2cxx . . $ atacMatch#pos2. - l->len2cxx . . $ atacMatch#len2., mas2); |
| 631 | getSequenceBegcxx . . $ getSequenceBeg(35e4bbf65cc8cb9e).(str3, r->pos2cxx . . $ atacMatch#pos2., r->len2cxx . . $ atacMatch#len2., mas2); |
| 632 | } else { |
| 633 | getSequenceEndcxx . . $ getSequenceEnd(35e4bbf65cc8cb9e).(str1, l->pos2cxx . . $ atacMatch#pos2., l->len2cxx . . $ atacMatch#len2., mas2); |
| 634 | getSequenceAllcxx . . $ getSequenceAll(35e4bbf65cc8cb9e).(str2, r->pos2cxx . . $ atacMatch#pos2. + r->len2cxx . . $ atacMatch#len2., l->pos2cxx . . $ atacMatch#pos2. - r->pos2cxx . . $ atacMatch#pos2. - r->len2cxx . . $ atacMatch#len2., mas2); |
| 635 | getSequenceBegcxx . . $ getSequenceBeg(35e4bbf65cc8cb9e).(str3, r->pos2cxx . . $ atacMatch#pos2., r->len2cxx . . $ atacMatch#len2., mas2); |
| 636 | } |
| 637 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "SEQB: %s -- %s -- %s\n", str1, str2, str3); |
| 638 | } |
| 639 | |
| 640 | //if (errors) |
| 641 | // exit(1); |
| 642 | |
| 643 | return(shifted); |
| 644 | } |
| 645 | |
| 646 | |
| 647 | |
| 648 | |
| 649 | |
| 650 | int |
| 651 | maincxx . . $ main(afcd3168fc1188a4).(int argc, char *argv[]) { |
| 652 | |
| 653 | if (argc == 1) { |
| 654 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "usage: %s [options] < matches > matches\n", argv[0]); |
| 655 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, " Instead of the usual switch based options to enable behavior\n"); |
| 656 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, " gapShifter iterates of a list of shift directions and sizes.\n"); |
| 657 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, " l -- shift gaps to the left\n"); |
| 658 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, " r -- shift gaps to the right\n"); |
| 659 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, " # -- set the maximum size of a gap to shift\n"); |
| 660 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, " log x -- open a logfile 'x' for results of the next shift\n"); |
| 661 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "\n"); |
| 662 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, " for example\n"); |
| 663 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, " gapShifter 1 l r l r 10 l r l log X r < some.atac > shifted.atac\n"); |
| 664 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, " would shift 1bp gaps to the left, then to the right, then left,\n"); |
| 665 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, " then set the gap size to 10bp and repeat. The last shift is logged\n"); |
| 666 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, " into fle 'X'.\n"); |
| 667 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, " \n"); |
| 668 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, " This is useful since shifting gaps can obliterate matches, but possibly.\n"); |
| 669 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, " when both left and right shifts are used.\n"); |
| 670 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, " GCTAATTAGACG\n"); |
| 671 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, " GCT-AT-AGACG\n"); |
| 672 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, " The second gap can be shifted to the left, and the first gap can be\n"); |
| 673 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, " shifted right, resulting in\n"); |
| 674 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, " GCTAATTAGACG\n"); |
| 675 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, " GCTA--TAGACG\n"); |
| 676 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, " Thus, two one base gaps were merged into a two base gap, which might\n"); |
| 677 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, " then be able to be shifted. e.g.:\n"); |
| 678 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, " atgatcatcttatc\n"); |
| 679 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, " at---c-t--tatc\n"); |
| 680 | exitcxx . . $ exit(44ed87f96534fad7).(1); |
| 681 | } |
| 682 | |
| 683 | atacFilecxx . . $ atacFile# AFcxx . . $ atacFile#atacFile(85c52e162fed56f9).("-"); |
| 684 | atacMatchListcxx . . $ atacMatchList# &ML = *AF.matchescxx . . $ atacFile#matches(33e88ebc28d05bce).(); |
| 685 | atacMatchOrdercxx . . $ atacMatchOrder# MOAcxx . . $ atacMatchOrder#atacMatchOrder(f3ef1525738b52af).(ML); |
| 686 | atacMatchOrdercxx . . $ atacMatchOrder# MOBcxx . . $ atacMatchOrder#atacMatchOrder(f3ef1525738b52af).(ML); |
| 687 | |
| 688 | MOA.sortAcxx . . $ atacMatchOrder#sortA(b4d55b1286ff73e8).(); |
| 689 | MOB.sortBcxx . . $ atacMatchOrder#sortB(b4d55b1286ff73e8).(); |
| 690 | |
| 691 | // second to last == loadAll |
| 692 | // last == report loading |
| 693 | // |
| 694 | seqCachecxx . . $ seqCache# *C1 = new seqCachecxx . . $ seqCache#seqCache(cc76bd1196c143a3).(AF.assemblyFileAcxx . . $ atacFileBase#assemblyFileA(41208ce6ca65dd58).(), 2, false); |
| 695 | seqCachecxx . . $ seqCache# *C2 = new seqCachecxx . . $ seqCache#seqCache(cc76bd1196c143a3).(AF.assemblyFileBcxx . . $ atacFileBase#assemblyFileB(41208ce6ca65dd58).(), 1024, false); |
| 696 | |
| 697 | bool shiftRight = true; |
| 698 | uint32cxx . . $ uint32# gapLimit = 5; |
| 699 | |
| 700 | char *logFileName = 0L; |
| 701 | |
| 702 | int arg=1; |
| 703 | while (arg < argc) { |
| 704 | bool doShift = false; |
| 705 | |
| 706 | if (strcmp(argv[arg], "log") == 0) { |
| 707 | logFileName = argv[++arg]; |
| 708 | errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! = 0; |
| 709 | logFilecxx . . $ logFile. = fopen(logFileName, "w"); |
| 710 | if (errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!) |
| 711 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "gapShifter: can't open log file '%s': %s\n", logFileName, strerror(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!)), exitcxx . . $ exit(44ed87f96534fad7).(1); |
| 712 | } else if (strcmp(argv[arg], "l") == 0) { |
| 713 | shiftRight = false; |
| 714 | doShift = true; |
| 715 | } else if (strcmp(argv[arg], "r") == 0) { |
| 716 | shiftRight = true; |
| 717 | doShift = true; |
| 718 | } else { |
| 719 | gapLimit = strtouint32cxx . . $ `libutil/util.h:82:10`!(argv[arg], 0L); |
| 720 | } |
| 721 | |
| 722 | if (doShift) { |
| 723 | |
| 724 | for (uint32cxx . . $ uint32# x=0; x<1024; x++) |
| 725 | amountShiftedcxx . . $ amountShifted.[x] = 0; |
| 726 | |
| 727 | numShiftedcxx . . $ numShifted. = 0; |
| 728 | numNotShiftedcxx . . $ numNotShifted. = 0; |
| 729 | numDiffSeqcxx . . $ numDiffSeq. = 0; |
| 730 | numDiffOricxx . . $ numDiffOri. = 0; |
| 731 | numZeroLencxx . . $ numZeroLen. = 0; |
| 732 | numOutOfOrdercxx . . $ numOutOfOrder. = 0; |
| 733 | numNotAdjacentcxx . . $ numNotAdjacent. = 0; |
| 734 | numNoGapcxx . . $ numNoGap. = 0; |
| 735 | numGapTooBigcxx . . $ numGapTooBig. = 0; |
| 736 | numOverlappingcxx . . $ numOverlapping. = 0; |
| 737 | |
| 738 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Shifting gaps of length at most "uint32FMTcxx . . $ `libutil/util.h:65:10`!" bases, to the %s.\n", gapLimit, (shiftRight) ? "right" : "left"); |
| 739 | |
| 740 | uint32cxx . . $ uint32# gapsShifted = 0; |
| 741 | for (uint32cxx . . $ uint32# i=1; i<ML.numMatchescxx . . $ atacMatchList#numMatches(db52760e79bf9054).(); i++) { |
| 742 | |
| 743 | if (shiftGapcxx . . $ shiftGap(6ffbc924b31ef216).(AF, ML, MOA[cxx . . $ atacMatchOrder#`operator[]`(4b949e4d42dbfd78).i-1], MOA[cxx . . $ atacMatchOrder#`operator[]`(4b949e4d42dbfd78).i], MOB, C1, C2, gapLimit, shiftRight)) { |
| 744 | gapsShifted++; |
| 745 | //fprintf(stderr, "shifted "uint32FMT" out of "uint32FMT" (%6.2f%%)\r", gapsShifted, i, (double)gapsShifted / (double)i * 100.0); |
| 746 | //fflush(stderr); |
| 747 | } |
| 748 | } |
| 749 | |
| 750 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "numShifted = "uint32FMTcxx . . $ `libutil/util.h:65:10`!"\n", numShiftedcxx . . $ numShifted.); |
| 751 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "numNotShifted = "uint32FMTcxx . . $ `libutil/util.h:65:10`!"\n", numNotShiftedcxx . . $ numNotShifted.); |
| 752 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "numDiffSeq = "uint32FMTcxx . . $ `libutil/util.h:65:10`!"\n", numDiffSeqcxx . . $ numDiffSeq.); |
| 753 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "numDiffOri = "uint32FMTcxx . . $ `libutil/util.h:65:10`!"\n", numDiffOricxx . . $ numDiffOri.); |
| 754 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "numZeroLen = "uint32FMTcxx . . $ `libutil/util.h:65:10`!"\n", numZeroLencxx . . $ numZeroLen.); |
| 755 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "numOutOfOrder = "uint32FMTcxx . . $ `libutil/util.h:65:10`!"\n", numOutOfOrdercxx . . $ numOutOfOrder.); |
| 756 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "numNotAdjacent = "uint32FMTcxx . . $ `libutil/util.h:65:10`!"\n", numNotAdjacentcxx . . $ numNotAdjacent.); |
| 757 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "numNoGap = "uint32FMTcxx . . $ `libutil/util.h:65:10`!"\n", numNoGapcxx . . $ numNoGap.); |
| 758 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "numGapTooBig = "uint32FMTcxx . . $ `libutil/util.h:65:10`!"\n", numGapTooBigcxx . . $ numGapTooBig.); |
| 759 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "numOverlapping = "uint32FMTcxx . . $ `libutil/util.h:65:10`!"\n", numOverlappingcxx . . $ numOverlapping.); |
| 760 | |
| 761 | for (uint32cxx . . $ uint32# x=0; x<50; x++) |
| 762 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "amountShifted["uint32FMTcxx . . $ `libutil/util.h:65:10`!"] = "uint32FMTcxx . . $ `libutil/util.h:65:10`!" (number of gaps shifted by [number of bases])\n", x, amountShiftedcxx . . $ amountShifted.[x]); |
| 763 | |
| 764 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "shifted "uint32FMTcxx . . $ `libutil/util.h:65:10`!" out of "uint32FMTcxx . . $ `libutil/util.h:65:10`!" (%6.2f%%)\n", gapsShifted, ML.numMatchescxx . . $ atacMatchList#numMatches(db52760e79bf9054).(), (double)gapsShifted / (double)ML.numMatchescxx . . $ atacMatchList#numMatches(db52760e79bf9054).() * 100.0); |
| 765 | |
| 766 | if (logFilecxx . . $ logFile.) { |
| 767 | fclose(logFilecxx . . $ logFile.); |
| 768 | logFileName = 0L; |
| 769 | logFilecxx . . $ logFile. = 0L; |
| 770 | } |
| 771 | } |
| 772 | |
| 773 | arg++; |
| 774 | } |
| 775 | |
| 776 | |
| 777 | for (uint32cxx . . $ uint32# i=0; i<ML.numMatchescxx . . $ atacMatchList#numMatches(db52760e79bf9054).(); i++) { |
| 778 | atacMatchcxx . . $ atacMatch# *ma = ML[cxx . . $ atacMatchList#`operator[]`(4b949e4d42dbfd78).i]; |
| 779 | if ((ma->len1cxx . . $ atacMatch#len1. > 0) && (ma->len2cxx . . $ atacMatch#len2. > 0)) |
| 780 | fprintf(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!, "M u %s %s %s:"uint32FMTcxx . . $ `libutil/util.h:65:10`!" "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`!" "uint32FMTcxx . . $ `libutil/util.h:65:10`!" %d\n", |
| 781 | ma->matchuidcxx . . $ atacMatch#matchuid., ma->parentuidcxx . . $ atacMatch#parentuid., |
| 782 | AF.labelAcxx . . $ atacFileBase#labelA(41208ce6ca65dd58).(), ma->iid1cxx . . $ atacMatch#iid1., ma->pos1cxx . . $ atacMatch#pos1., ma->len1cxx . . $ atacMatch#len1., |
| 783 | AF.labelBcxx . . $ atacFileBase#labelB(41208ce6ca65dd58).(), ma->iid2cxx . . $ atacMatch#iid2., ma->pos2cxx . . $ atacMatch#pos2., ma->len2cxx . . $ atacMatch#len2., ma->fwd2cxx . . $ atacMatch#fwd2. ? 1 : -1); |
| 784 | } |
| 785 | |
| 786 | return(0); |
| 787 | } |