| 1 | #include <stdio.h> |
| 2 | #include <stdlib.h> |
| 3 | #include "seatac.H" |
| 4 | #include "bio++.H" |
| 5 | |
| 6 | encodedQuery::encodedQuery(char const *seq, |
| 7 | uint32 seqLen, |
| 8 | uint32 k, |
| 9 | bool rc) { |
| 10 | _seq = seq; |
| 11 | _seqLen = seqLen; |
| 12 | _merSize = k; |
| 13 | _rc = rc; |
| 14 | |
| 15 | _seqPos = 0; |
| 16 | |
| 17 | _substring = uint64ZERO; |
| 18 | _mermask = uint64MASK(2 * _merSize); |
| 19 | _timeUntilValid = _merSize; |
| 20 | } |
| 21 | |
| 22 | |
| 23 | bool |
| 24 | encodedQuery::getMer(uint64 &mer, uint32 &pos) { |
| 25 | bool found = false; |
| 26 | |
| 27 | mer = uint64ZERO; |
| 28 | pos = uint32ZERO; |
| 29 | |
| 30 | if (_rc) { |
| 31 | |
| 32 | while (!found && (_seqPos < _seqLen)) { |
| 33 | _substring <<= 2; |
| 34 | _substring &= _mermask; |
| 35 | |
| 36 | if (letterToBits[_seq[_seqLen - 1 - _seqPos]] != 0xff) { |
| 37 | _substring |= letterToBits[ complementSymbol[ _seq[_seqLen - 1 - _seqPos] ]]; |
| 38 | _timeUntilValid--; |
| 39 | } else { |
| 40 | _timeUntilValid = _merSize; |
| 41 | } |
| 42 | |
| 43 | _seqPos++; |
| 44 | |
| 45 | if (_seqPos >= _merSize) { |
| 46 | mer = _substring; |
| 47 | pos = _seqPos - _merSize; |
| 48 | found = _timeUntilValid <= 0; |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | } else { |
| 53 | |
| 54 | while (!found && (_seqPos < _seqLen)) { |
| 55 | _substring <<= 2; |
| 56 | _substring &= _mermask; |
| 57 | |
| 58 | if (letterToBits[_seq[_seqPos]] != 0xff) { |
| 59 | _substring |= letterToBits[_seq[_seqPos]]; |
| 60 | _timeUntilValid--; |
| 61 | } else { |
| 62 | _timeUntilValid = _merSize; |
| 63 | } |
| 64 | |
| 65 | _seqPos++; |
| 66 | |
| 67 | if (_seqPos >= _merSize) { |
| 68 | mer = _substring; |
| 69 | pos = _seqPos - _merSize; |
| 70 | found = _timeUntilValid <= 0; |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | } |
| 75 | |
| 76 | return(found); |
| 77 | } |
| 78 | |
| 79 | |
| 80 | |
| 81 | |
| 82 | encodedQuery::~encodedQuery() { |
| 83 | } |