| 1 |
#include "bio++.H" |
| 2 |
|
| 3 |
#ifndef KMER_LITE_H |
| 4 |
#define KMER_LITE_H |
| 5 |
|
| 6 |
//////////////////////////////////////// |
| 7 |
// |
| 8 |
// This is kMerLite -- derived from kMer.H, removing |
| 9 |
// most of the accessors. |
| 10 |
// |
| 11 |
// Assumes that KMER_WORDS is already defined. |
| 12 |
|
| 13 |
|
| 14 |
class kMerLite { |
| 15 |
public: |
| 16 |
|
| 17 |
// Used by some of the test routines. |
| 18 |
void dump(void) const { |
| 19 |
for (uint32 i=0; i<KMER_WORDS; i++) |
| 20 |
fprintf(stderr, "kMerLite["uint32FMTW(2)"] = "uint64HEX"\n", i, _wd[i]); |
| 21 |
}; |
| 22 |
|
| 23 |
|
| 24 |
public: |
| 25 |
void copy(kMer const &that) { |
| 26 |
for (uint32 i=0; i<KMER_WORDS; i++) |
| 27 |
_wd[i] = that.getWord(i); |
| 28 |
}; |
| 29 |
void clear(void) { |
| 30 |
for (uint32 i=0; i<KMER_WORDS; i++) |
| 31 |
_wd[i] = uint64ZERO; |
| 32 |
}; |
| 33 |
|
| 34 |
public: |
| 35 |
kMerLite() { |
| 36 |
clear(); |
| 37 |
}; |
| 38 |
kMerLite(kMer const &that) { |
| 39 |
copy(that); |
| 40 |
}; |
| 41 |
~kMerLite() { |
| 42 |
}; |
| 43 |
|
| 44 |
kMerLite &operator=(kMer const &that) { |
| 45 |
copy(that); |
| 46 |
return(*this); |
| 47 |
}; |
| 48 |
|
| 49 |
char *merToString(uint32 merSize, char *instr) const { |
| 50 |
uint32 lastWord = merSize >> 5; |
| 51 |
char *str = instr; |
| 52 |
|
| 53 |
if ((merSize & uint32MASK(6)) == 0) |
| 54 |
lastWord++; |
| 55 |
|
| 56 |
// We build the string right to left, print any partial word |
| 57 |
// first, then print whole words until we run out of words to |
| 58 |
// print. |
| 59 |
|
| 60 |
if (merSize & uint32MASK(5)) { |
| 61 |
::merToString(merSize & uint32MASK(5), _wd[lastWord], str); |
| 62 |
str += merSize & uint32MASK(5); |
| 63 |
} |
| 64 |
|
| 65 |
while (lastWord > 0) { |
| 66 |
lastWord--; |
| 67 |
::merToString(32, _wd[lastWord], str); |
| 68 |
str += 32; |
| 69 |
} |
| 70 |
|
| 71 |
return(instr); |
| 72 |
}; |
| 73 |
|
| 74 |
#if KMER_WORDS == 1 |
| 75 |
|
| 76 |
bool operator!=(kMerLite const &r) const { return(_wd[0] != r._wd[0]); }; |
| 77 |
bool operator==(kMerLite const &r) const { return(_wd[0] == r._wd[0]); }; |
| 78 |
bool operator<(kMerLite const &r) const { return(_wd[0] < r._wd[0]); }; |
| 79 |
bool operator>(kMerLite const &r) const { return(_wd[0] > r._wd[0]); }; |
| 80 |
bool operator<=(kMerLite const &r) const { return(_wd[0] <= r._wd[0]); }; |
| 81 |
bool operator>=(kMerLite const &r) const { return(_wd[0] >= r._wd[0]); }; |
| 82 |
|
| 83 |
#else |
| 84 |
|
| 85 |
bool operator!=(kMerLite const &r) const { |
| 86 |
uint64 res = uint64ZERO; |
| 87 |
for (uint32 i=KMER_WORDS; i--; ) |
| 88 |
res |= _wd[i] ^ r._wd[i]; |
| 89 |
return(res != uint64ZERO); |
| 90 |
}; |
| 91 |
bool operator==(kMerLite const &r) const { |
| 92 |
uint64 res = uint64ZERO; |
| 93 |
for (uint32 i=KMER_WORDS; i--; ) |
| 94 |
res |= _wd[i] ^ r._wd[i]; |
| 95 |
return(res == uint64ZERO); |
| 96 |
}; |
| 97 |
|
| 98 |
bool operator<(kMerLite const &r) const { |
| 99 |
for (uint32 i=KMER_WORDS; i--; ) { |
| 100 |
if (_wd[i] < r._wd[i]) return(true); |
| 101 |
if (_wd[i] > r._wd[i]) return(false); |
| 102 |
} |
| 103 |
return(false); |
| 104 |
}; |
| 105 |
bool operator>(kMerLite const &r) const { |
| 106 |
for (uint32 i=KMER_WORDS; i--; ) { |
| 107 |
if (_wd[i] > r._wd[i]) return(true); |
| 108 |
if (_wd[i] < r._wd[i]) return(false); |
| 109 |
} |
| 110 |
return(false); |
| 111 |
}; |
| 112 |
bool operator<=(kMerLite const &r) const { |
| 113 |
for (uint32 i=KMER_WORDS; i--; ) { |
| 114 |
if (_wd[i] < r._wd[i]) return(true); |
| 115 |
if (_wd[i] > r._wd[i]) return(false); |
| 116 |
} |
| 117 |
return(true); |
| 118 |
}; |
| 119 |
bool operator>=(kMerLite const &r) const { |
| 120 |
for (uint32 i=KMER_WORDS; i--; ) { |
| 121 |
if (_wd[i] > r._wd[i]) return(true); |
| 122 |
if (_wd[i] < r._wd[i]) return(false); |
| 123 |
} |
| 124 |
return(true); |
| 125 |
}; |
| 126 |
#endif |
| 127 |
|
| 128 |
private: |
| 129 |
uint64 _wd[KMER_WORDS]; |
| 130 |
}; |
| 131 |
|
| 132 |
|
| 133 |
#endif // KMER_LITE_H |