| 1 | #cxx . . $ `<file>/seagen/encodedQuery.C`/include <new> |
| 2 | |
| 3 | #include "encodedQuery.H"cxx . . $ `<file>/seagen/encodedQuery.H`/ |
| 4 | |
| 5 | encodedQuerycxx . . $ encodedQuery#::encodedQuerycxx . . $ encodedQuery#encodedQuery(c9266dfd898f6cb1).(seqInCorecxx . . $ seqInCore# *S, |
| 6 | uint32cxx . . $ uint32# k) { |
| 7 | |
| 8 | _iidcxx . . $ encodedQuery#_iid. = S->getIIDcxx . . $ seqInCore#getIID(ddd8539a2fcdd4ce).(); |
| 9 | _sequenceLengthcxx . . $ encodedQuery#_sequenceLength. = S->sequenceLengthcxx . . $ seqInCore#sequenceLength(ddd8539a2fcdd4ce).(); |
| 10 | _merSizecxx . . $ encodedQuery#_merSize. = k; |
| 11 | _mersTotalcxx . . $ encodedQuery#_mersTotal. = 0; |
| 12 | _mersAvailcxx . . $ encodedQuery#_mersAvail. = 0; |
| 13 | _merscxx . . $ encodedQuery#_mers. = 0L; |
| 14 | _skipcxx . . $ encodedQuery#_skip. = 0L; |
| 15 | _numberOfResultscxx . . $ encodedQuery#_numberOfResults. = 0; |
| 16 | _outputcxx . . $ encodedQuery#_output. = 0L; |
| 17 | _outputLencxx . . $ encodedQuery#_outputLen. = 0; |
| 18 | _outputMaxcxx . . $ encodedQuery#_outputMax. = 0; |
| 19 | |
| 20 | if (k > _sequenceLengthcxx . . $ encodedQuery#_sequenceLength.) |
| 21 | return; |
| 22 | |
| 23 | char const *seq = S->sequencecxx . . $ seqInCore#sequence(e7e5aa338b9d5147).(); |
| 24 | uint32cxx . . $ uint32# seqLen = S->sequenceLengthcxx . . $ seqInCore#sequenceLength(ddd8539a2fcdd4ce).(); |
| 25 | |
| 26 | _mersTotalcxx . . $ encodedQuery#_mersTotal. = seqLen - k + 1; |
| 27 | _mersAvailcxx . . $ encodedQuery#_mersAvail. = 0; |
| 28 | _merscxx . . $ encodedQuery#_mers. = new uint64cxx . . $ uint64# [_mersTotalcxx . . $ encodedQuery#_mersTotal.]; |
| 29 | _skipcxx . . $ encodedQuery#_skip. = new uint8cxx . . $ uint8# [_mersTotalcxx . . $ encodedQuery#_mersTotal.]; |
| 30 | |
| 31 | uint64cxx . . $ uint64# substring = uint64ZEROcxx . . $ `libutil/util.h:50:10`!; |
| 32 | uint64cxx . . $ uint64# mermask = uint64MASKcxx . . $ `libutil/util.h:53:10`!(2 * k); |
| 33 | int32cxx . . $ int32# timeUntilValid = k; |
| 34 | |
| 35 | for (uint32cxx . . $ uint32# i=0; i<seqLen; ) { |
| 36 | substring <<= 2; |
| 37 | substring &= mermask; |
| 38 | |
| 39 | if (letterToBits[seq[i]] != 0xff) { |
| 40 | substring |= letterToBits[ seq[i] ]; |
| 41 | timeUntilValid--; |
| 42 | } else { |
| 43 | timeUntilValid = k; |
| 44 | } |
| 45 | |
| 46 | i++; |
| 47 | |
| 48 | if (i >= k) { |
| 49 | _merscxx . . $ encodedQuery#_mers.[i-k] = substring; |
| 50 | _skipcxx . . $ encodedQuery#_skip.[i-k] = timeUntilValid > 0; |
| 51 | _mersAvailcxx . . $ encodedQuery#_mersAvail. += 1 - _skipcxx . . $ encodedQuery#_skip.[i-k]; |
| 52 | } |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | encodedQuerycxx . . $ encodedQuery#::~cxx . . $ encodedQuery#`~encodedQuery`(ced63f7c635d850d).encodedQuerycxx . . $ encodedQuery#() { |
| 57 | delete [] _merscxx . . $ encodedQuery#_mers.; |
| 58 | delete [] _skipcxx . . $ encodedQuery#_skip.; |
| 59 | delete [] _outputcxx . . $ encodedQuery#_output.; |
| 60 | } |
| 61 | |
| 62 | |
| 63 | |
| 64 | |
| 65 | void |
| 66 | encodedQuerycxx . . $ encodedQuery#::testcxx . . $ encodedQuery#test(b490fd58fed50ecf).(seqInCorecxx . . $ seqInCore# *S) { |
| 67 | |
| 68 | // We assume we've been initialized with the forward version! |
| 69 | |
| 70 | uint32cxx . . $ uint32# k = _merSizecxx . . $ encodedQuery#_merSize.; |
| 71 | |
| 72 | char const *seq = S->sequencecxx . . $ seqInCore#sequence(e7e5aa338b9d5147).(); |
| 73 | uint32cxx . . $ uint32# seqLen = S->sequenceLengthcxx . . $ seqInCore#sequenceLength(ddd8539a2fcdd4ce).(); |
| 74 | |
| 75 | uint64cxx . . $ uint64# substring = uint64ZEROcxx . . $ `libutil/util.h:50:10`!; |
| 76 | uint64cxx . . $ uint64# mermask = uint64MASKcxx . . $ `libutil/util.h:53:10`!(2 * k); |
| 77 | int32cxx . . $ int32# timeUntilValid = k; |
| 78 | |
| 79 | // Compute the complement version; we'll iterate through all data |
| 80 | // in us, comparing against what the original method would say. |
| 81 | |
| 82 | uint32cxx . . $ uint32# _r_mersAvail = 0; |
| 83 | uint64cxx . . $ uint64# *_r_mers = new uint64cxx . . $ uint64# [_mersTotalcxx . . $ encodedQuery#_mersTotal.]; |
| 84 | uint8cxx . . $ uint8# *_r_skip = new uint8cxx . . $ uint8# [_mersTotalcxx . . $ encodedQuery#_mersTotal.]; |
| 85 | |
| 86 | substring = uint64ZEROcxx . . $ `libutil/util.h:50:10`!; |
| 87 | mermask = uint64MASKcxx . . $ `libutil/util.h:53:10`!(2 * k); |
| 88 | timeUntilValid = k; |
| 89 | |
| 90 | for (uint32cxx . . $ uint32# i=0; i<seqLen; ) { |
| 91 | substring <<= 2; |
| 92 | substring &= mermask; |
| 93 | |
| 94 | if (letterToBits[seq[seqLen - 1 - i]] != 0xff) { |
| 95 | substring |= letterToBits[ complementSymbol[ seq[seqLen - 1 - i] ]]; |
| 96 | timeUntilValid--; |
| 97 | } else { |
| 98 | timeUntilValid = k; |
| 99 | } |
| 100 | |
| 101 | i++; |
| 102 | |
| 103 | if (i >= k) { |
| 104 | _r_mers[i-k] = substring; |
| 105 | _r_skip[i-k] = timeUntilValid > 0; |
| 106 | _r_mersAvail += 1 - _r_skip[i-k]; |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | #if 0 |
| 111 | // For comparison, this is the original code used to compute the |
| 112 | // reverse complement mers. |
| 113 | |
| 114 | for (uint32 i=0; i<seqLen; ) { |
| 115 | substring <<= 2; |
| 116 | substring &= mermask; |
| 117 | |
| 118 | if (validSymbol[seq[seqLen - 1 - i]]) { |
| 119 | substring |= compressSymbol[ complementSymbol[ seq[seqLen - 1 - i] ]]; |
| 120 | timeUntilValid--; |
| 121 | } else { |
| 122 | timeUntilValid = k; |
| 123 | } |
| 124 | |
| 125 | i++; |
| 126 | |
| 127 | if (i >= k) { |
| 128 | _mers[i-k] = substring; |
| 129 | _skip[i-k] = timeUntilValid > 0; |
| 130 | _mersAvail += 1 - _skip[i-k]; |
| 131 | } |
| 132 | } |
| 133 | #endif |
| 134 | |
| 135 | |
| 136 | |
| 137 | |
| 138 | |
| 139 | // CHECK! |
| 140 | // |
| 141 | if (_r_mersAvail != _mersAvailcxx . . $ encodedQuery#_mersAvail.) { |
| 142 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "encodedQuery::test()-- mersAvail incorrect: Recomputed:"uint32FMTcxx . . $ `libutil/util.h:65:10`!" Real:"uint32FMTcxx . . $ `libutil/util.h:65:10`!"\n", _mersAvailcxx . . $ encodedQuery#_mersAvail., _r_mersAvail); |
| 143 | } |
| 144 | |
| 145 | char mer1[65]; |
| 146 | char mer2[65]; |
| 147 | bool fail = false; |
| 148 | |
| 149 | for (uint32cxx . . $ uint32# i=0; i<_mersTotalcxx . . $ encodedQuery#_mersTotal.; i++) { |
| 150 | |
| 151 | if (getSkipcxx . . $ encodedQuery#getSkip(f97cc7cf123a0aff).(i, true) != _r_skip[i]) { |
| 152 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "encodedQuery::test()-- skip["uint32FMTWcxx . . $ `libutil/util.h:64:10`!(4)"] incorrect: Acc:%d Real:%d\n", i, getSkipcxx . . $ encodedQuery#getSkip(f97cc7cf123a0aff).(i, true), _r_skip[i]); |
| 153 | fail = true; |
| 154 | } |
| 155 | |
| 156 | if (getSkipcxx . . $ encodedQuery#getSkip(f97cc7cf123a0aff).(i, true) == false) { |
| 157 | if (getMercxx . . $ encodedQuery#getMer(874e921e06c50d5d).(i, true) != _r_mers[i]) { |
| 158 | uint64ToMerStringcxx . . $ uint64ToMerString(24c04f7e556aaa85).(_merSizecxx . . $ encodedQuery#_merSize., getMercxx . . $ encodedQuery#getMer(874e921e06c50d5d).(i, true), mer1); |
| 159 | uint64ToMerStringcxx . . $ uint64ToMerString(24c04f7e556aaa85).(_merSizecxx . . $ encodedQuery#_merSize., _r_mers[i], mer2); |
| 160 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "encodedQuery::test()-- mers["uint32FMTWcxx . . $ `libutil/util.h:64:10`!(4)"] incorrect: Acc:"uint64HEXcxx . . $ `libutil/util.h:56:10`!" %s Real:"uint64HEXcxx . . $ `libutil/util.h:56:10`!" %s\n", |
| 161 | i, |
| 162 | getMercxx . . $ encodedQuery#getMer(874e921e06c50d5d).(i, true), mer1, |
| 163 | _r_mers[i], mer2); |
| 164 | fail = true; |
| 165 | } |
| 166 | } |
| 167 | |
| 168 | if (fail) { |
| 169 | char rev[2048]; |
| 170 | strcpy(rev, seq); |
| 171 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "seq='%s'\n", seq); |
| 172 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "rev='%s'\n", reverseComplementSequence(rev, seqLen)); |
| 173 | exitcxx . . $ exit(44ed87f96534fad7).(1); |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | //fprintf(stderr, "encodedQuery::test()-- %s\n", seq); |
| 178 | //fprintf(stderr, "encodedQuery::test()-- tested avail:"uint32FMT" total:"uint32FMT"\n", _mersAvail, _mersTotal); |
| 179 | |
| 180 | delete [] _r_mers; |
| 181 | delete [] _r_skip; |
| 182 | } |
| 183 | |
| 184 | |
| 185 | void |
| 186 | encodedQuerycxx . . $ encodedQuery#::addOutputcxx . . $ encodedQuery#addOutput(67abb4dd43ac34c5).(void *newout, uint32cxx . . $ uint32# size) { |
| 187 | |
| 188 | // Allocate space for the output -- 1MB should be enough for about |
| 189 | // 29000 signals. Make it 32K -> 900 signals. |
| 190 | // |
| 191 | // You probably do not want to move this into the query |
| 192 | // constructor, as that will just waste a lot of memory with |
| 193 | // thousands of these in the input queue. |
| 194 | // |
| 195 | if (_outputcxx . . $ encodedQuery#_output. == 0L) { |
| 196 | _outputLencxx . . $ encodedQuery#_outputLen. = 0; |
| 197 | _outputMaxcxx . . $ encodedQuery#_outputMax. = 32 * 1024; |
| 198 | _outputcxx . . $ encodedQuery#_output. = new char [_outputMaxcxx . . $ encodedQuery#_outputMax.]; |
| 199 | } |
| 200 | |
| 201 | if (_outputLencxx . . $ encodedQuery#_outputLen. + 128 >= _outputMaxcxx . . $ encodedQuery#_outputMax.) { |
| 202 | _outputMaxcxx . . $ encodedQuery#_outputMax. <<= 1; |
| 203 | char *o = 0L; |
| 204 | |
| 205 | try { |
| 206 | o = new char [_outputMaxcxx . . $ encodedQuery#_outputMax.]; |
| 207 | } catch (stdcxx . . $ std/::bad_alloccxx . . $ std/bad_alloc#)cxx . . $ std/bad_alloc#bad_alloc(f0898f11383ce75e). { |
| 208 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "encodedQuery::addOutput()-- out of memory, tried to extend output string\n"); |
| 209 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "encodedQuery::addOutput()-- from "uint32FMTcxx . . $ `libutil/util.h:65:10`!" to "uint32FMTcxx . . $ `libutil/util.h:65:10`!" bytes.\n", |
| 210 | _outputLencxx . . $ encodedQuery#_outputLen., _outputMaxcxx . . $ encodedQuery#_outputMax.); |
| 211 | exitcxx . . $ exit(44ed87f96534fad7).(1); |
| 212 | } |
| 213 | |
| 214 | memcpy(o, _outputcxx . . $ encodedQuery#_output., _outputLencxx . . $ encodedQuery#_outputLen.); |
| 215 | delete [] _outputcxx . . $ encodedQuery#_output.; |
| 216 | _outputcxx . . $ encodedQuery#_output. = o; |
| 217 | } |
| 218 | |
| 219 | if (size > 0) { |
| 220 | memcpy(_outputcxx . . $ encodedQuery#_output. + _outputLencxx . . $ encodedQuery#_outputLen., newout, size); |
| 221 | _outputLencxx . . $ encodedQuery#_outputLen. += size; |
| 222 | } else { |
| 223 | char *n = (char *)newout; |
| 224 | |
| 225 | while (*n) |
| 226 | _outputcxx . . $ encodedQuery#_output.[_outputLencxx . . $ encodedQuery#_outputLen.++] = *n++; |
| 227 | _outputcxx . . $ encodedQuery#_output.[_outputLencxx . . $ encodedQuery#_outputLen.] = 0; |
| 228 | } |
| 229 | |
| 230 | _numberOfResultscxx . . $ encodedQuery#_numberOfResults.++; |
| 231 | }; |