-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathseed.cpp
52 lines (45 loc) · 1.58 KB
/
seed.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include "seed.h"
SIZE_T GetHashValue(const InBits & r) {
return (SIZE_T)((r.ub << HASHSEEDLEN) + r.lb);
}
SIZE_T GetHashValue(const char * strVal, const int & len) {
if (len != HASHSEEDLEN)
return 0;
InBits r;
EncodeRead(strVal, &r, HASHSEEDLEN);
return GetHashValue(r);
}
SIZE_T GetKmer(const CReference * refGenome, const SIZE_T & nRefStart,
SIZE_T kmerLen, InBits * r) {
/* This function get kmerLen characters from the genome, start from position nRefstart*/
if (nRefStart + kmerLen > refGenome->nRefSize) {
kmerLen = refGenome->nRefSize - nRefStart;
}
r->ub = 0;
r->lb = 0;
SIZE_T indexInWords = nRefStart / wordSize;
SIZE_T bitsShift = nRefStart % wordSize;
/* the bitsShift bits are delete from the refInBits[indexInWords]
* get (WORD_SIZE - bitsShift) bits */
r->ub = refGenome->refInBits[indexInWords].ub >> bitsShift;
r->lb = refGenome->refInBits[indexInWords].lb >> bitsShift;
/* kmer in two WORDSIZE, here kmerLen should less than WORD_SIZE */
if (bitsShift != 0) {
/* delete the high (wordSize - bitsShift) bits, and get (bitsShift) bits */
r->ub |= (refGenome->refInBits[indexInWords + 1].ub
<< (wordSize - bitsShift));
r->lb |= (refGenome->refInBits[indexInWords + 1].lb
<< (wordSize - bitsShift));
}
SIZE_T elimatedBits = wordSize - kmerLen;
r->ub <<= elimatedBits;
r->lb <<= elimatedBits;
r->ub >>= elimatedBits;
r->lb >>= elimatedBits;
//printWORD(r->ub, kmerLen);
//printWORD(r->lb, kmerLen);
//cout << r->ub << endl;
//cout << r->lb << endl;
//cout << endl;
return kmerLen;
}