-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSeed.cpp
More file actions
182 lines (164 loc) · 3.93 KB
/
Seed.cpp
File metadata and controls
182 lines (164 loc) · 3.93 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#include "Seed.h"
unsigned char Seed::alphabet[] = { 0 };
unsigned char Seed::alphabetRev[] = { 0 };
char Seed::score[4][4] ={{91,-114,-31,-123},
{-114, 100, -125, -31},
{-31, -125, 100, -114},
{-123, -31, -114, 91}};
/*char Seed::score[4][4] ={{0,2,1,2},
{2, 0, 2, 1},
{1, 2, 0, 2},
{2, 1, 2, 0}};*/
Seed::Seed(int32_t weight, int32_t dontCare)
{
this->weight=weight;
this->dontCare=dontCare;
this->length=weight+dontCare;
generatePattern();
}
void Seed::generatePattern()
{
pattern* pattern_obj;
pattern_obj = new pattern(NULL, NULL, 1, weight + dontCare, weight, 10000, 10000, 10000, 0.75, 0.25);
pattern_obj->ImproveSecure();
pattern_obj->Improve(5000);
std::string pattern=pattern_obj->GetBestPattern(0);
//std::string pattern="10010000000000000010000001000000000000001000000000000000000000000000000010000000000100010000000000001000000001";
for(int32_t i = 0; i < pattern.length(); i++)
{
if (pattern[i] == '1')
matchPos.push_back(i);
else
dontCarePos.push_back(i);
}
}
int32_t Seed::getLength()
{
return length;
}
int32_t Seed::getWeight()
{
return weight;
}
int32_t Seed::getDontCare()
{
return dontCare;
}
void Seed::init()
{
Seed::alphabet['A'] = 0;
Seed::alphabet['C'] = 1;
Seed::alphabet['G'] = 2;
Seed::alphabet['T'] = 3;
Seed::alphabetRev['A'] = 3;
Seed::alphabetRev['C'] = 2;
Seed::alphabetRev['G'] = 1;
Seed::alphabetRev['T'] = 0;
}
char Seed::getMismatches (std::vector<char> & dontCareRef, std::vector<char> & dontCareQry)
{
char mm=0;
for(uint32_t i = 0; i < dontCare; i++)
{
if(dontCareRef[i] != dontCareQry[i])
mm++;
}
return mm;
}
/*int32_t Seed::getScore (std::vector<char> & dontCareRef, std::vector<char> & dontCareQry)
{
int32_t score=0;
int32_t totalScore=0;
for(uint32_t i = 0; i < 10; i++)
{
score += Seed::score[dontCareRef[i]][dontCareQry[i]];
}
if(score<0)
return -1;
totalScore+=score;
score=0;
for(uint32_t i = 10; i < 90; i++)
{
score += Seed::score[dontCareRef[i]][dontCareQry[i]];
}
if(score<0)
return -1;
totalScore+=score;
score=0;
for(uint32_t i = 90; i < 100; i++)
{
score += Seed::score[dontCareRef[i]][dontCareQry[i]];
}
if(score<0)
return -1;
totalScore+=score;
return totalScore;
}*/
/*int32_t Seed::getScore (std::vector<char> & dontCareRef, std::vector<char> & dontCareQry)
{
int32_t score1=0;
for(uint32_t i = 0; i < 50; i++)
{
score1 += Seed::score[dontCareRef[i]][dontCareQry[i]];
}
int32_t score2=0;
for(uint32_t i = 50; i < 100; i++)
{
score2 += Seed::score[dontCareRef[i]][dontCareQry[i]];
}
if(score1>0&&score2>0)
return score1+score2;
else
return -1;
}*/
int32_t Seed::getScore (std::vector<char> & dontCareRef, std::vector<char> & dontCareQry)
{
int32_t score=0;
for(uint32_t i = 0; i < dontCare; i++)
{
score += Seed::score[dontCareRef[i]][dontCareQry[i]];
}
return score;
}
bool Seed::fillDontCare(std::vector<char> & vec, char * seq)
{
for(uint32_t i = 0; i < length; i++)
{
if( *(seq + i) == '$')
return false;
}
for(uint32_t i = 0; i < dontCare; i++)
{
vec[i] = *(seq + dontCarePos[i]);
}
return true;
}
bool Seed::fillDontCareScore(std::vector<char> & vec, char * seq)
{
for(uint32_t i = 0; i < length; i++)
{
if( *(seq + i) == '$')
return false;
}
for(uint32_t i = 0; i < dontCare; i++)
{
vec[i] = alphabet[ *(seq + dontCarePos[i]) ];
}
return true;
}
void Seed::getFirstWord(unsigned char & w, char* seq)
{
w |= alphabet[ *(seq + matchPos[0]) ] << 6;
w |= alphabet[ *(seq + matchPos[1]) ] << 4;
w |= alphabet[ *(seq + matchPos[2]) ] << 2;
w |= alphabet[ *(seq + matchPos[3]) ];
}
void Seed::getNextWord(uint32_t & w, char* seq)
{
uint32_t bits = (weight - 4) * 2 - 2;
for(uint32_t i = 4; i < weight; i++)
{
w|=(uint32_t) alphabet[ *(seq + matchPos[i]) ] << bits;
bits -= 2;
}
}