| 1 | #ifndef ENCODEDQUERY_H |
| 2 | #define ENCODEDQUERY_H |
| 3 | |
| 4 | #include <stdio.h> |
| 5 | #include <stdlib.h> |
| 6 | #include "bio++.H" |
| 7 | #include "seqCache.H" |
| 8 | |
| 9 | class encodedQuery { |
| 10 | public: |
| 11 | encodedQuery(seqInCore *S, |
| 12 | uint32 k); |
| 13 | ~encodedQuery(); |
| 14 | |
| 15 | void test(seqInCore *S); |
| 16 | |
| 17 | uint32 IID(void) { return(_iid); }; |
| 18 | |
| 19 | uint32 numberOfMers(void) { return(_mersTotal); }; |
| 20 | uint32 numberOfValidMers(void) { return(_mersAvail); }; |
| 21 | |
| 22 | // Return either an approximation or the exact number of bp covered by valid mers. |
| 23 | // |
| 24 | uint32 bpCovered(bool doCompute); |
| 25 | uint32 bpTotal(void); |
| 26 | |
| 27 | uint64 getMer(uint32 i, bool isReverse); |
| 28 | bool getSkip(uint32 i, bool isReverse); |
| 29 | void setSkip(uint32 i, bool isReverse); |
| 30 | |
| 31 | void addOutput(void *output, uint32 size); |
| 32 | |
| 33 | char *theOutput(void) { return(_output); }; |
| 34 | uint32 theOutputLength(void) { return(_outputLen); }; |
| 35 | uint32 numberOfResults(void) { return(_numberOfResults); }; |
| 36 | private: |
| 37 | uint32 _iid; |
| 38 | uint32 _sequenceLength; |
| 39 | |
| 40 | uint32 _merSize; |
| 41 | |
| 42 | uint32 _mersTotal; // Number of mers possible in the query |
| 43 | uint32 _mersAvail; // Number of mers not masked out |
| 44 | uint64 *_mers; // List of mers |
| 45 | uint8 *_skip; |
| 46 | |
| 47 | uint32 _numberOfResults; |
| 48 | char *_output; |
| 49 | uint32 _outputLen; |
| 50 | uint32 _outputMax; |
| 51 | }; |
| 52 | |
| 53 | |
| 54 | inline |
| 55 | uint32 |
| 56 | encodedQuery::bpCovered(bool doCompute) { |
| 57 | uint32 bp = numberOfValidMers(); |
| 58 | |
| 59 | if (doCompute) { |
| 60 | merCovering *IL = new merCovering(_merSize); |
| 61 | |
| 62 | for (uint32 qi=0; qi<numberOfMers(); qi++) { |
| 63 | if (getSkip(qi, false) == false) |
| 64 | IL->addMer(qi); |
| 65 | } |
| 66 | |
| 67 | bp = IL->sumOfLengths(); |
| 68 | delete IL; |
| 69 | } |
| 70 | |
| 71 | return(bp); |
| 72 | } |
| 73 | |
| 74 | inline |
| 75 | uint32 |
| 76 | encodedQuery::bpTotal(void) { |
| 77 | return(_sequenceLength); |
| 78 | } |
| 79 | |
| 80 | |
| 81 | // XXX: We need to extend get*() to also take a isReverse flag, |
| 82 | // and to then return the reverse-complement mer, skip, etc. |
| 83 | |
| 84 | inline |
| 85 | uint64 |
| 86 | encodedQuery::getMer(uint32 i, bool isReverse) { |
| 87 | |
| 88 | if (isReverse) { |
| 89 | i = _mersTotal - i - 1; |
| 90 | return(reverseComplementMer(_merSize, _mers[i])); |
| 91 | } else { |
| 92 | return(_mers[i]); |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | inline |
| 97 | bool |
| 98 | encodedQuery::getSkip(uint32 i, bool isReverse) { |
| 99 | |
| 100 | if (isReverse) |
| 101 | i = _mersTotal - i - 1; |
| 102 | |
| 103 | return(_skip[i]); |
| 104 | } |
| 105 | |
| 106 | inline |
| 107 | void |
| 108 | encodedQuery::setSkip(uint32 i, bool isReverse) { |
| 109 | |
| 110 | if (isReverse) |
| 111 | i = _mersTotal - i - 1; |
| 112 | |
| 113 | // If skip[i] is already set, don't adjust; otherwise, subtract |
| 114 | // one from the available. |
| 115 | _mersAvail -= 1 - _skip[i]; |
| 116 | _skip[i] = 1; |
| 117 | } |
| 118 | |
| 119 | |
| 120 | #endif // ENCODEDQUERY_H |