3 unsigned int REVBWTForwardSearch(const unsigned char *convertedkey
, const unsigned int keylength
, const BWT
*rev_bwt
, unsigned int *resultsaindexleft
, unsigned int *resultsaindexright
, unsigned int *rev_resultsaindexleft
, unsigned int *rev_resultsaindexright
) {
5 unsigned int sacount
=0;
6 unsigned int rev_startsaindex
, rev_endsaindex
;
7 unsigned int startsaindex
, endsaindex
;
10 unsigned int c
= convertedkey
[0];
11 unsigned int occcount_start
[4];
12 unsigned int occcount_end
[4];
13 unsigned int occcount
[4];
15 rev_startsaindex
= rev_bwt
->cumulativeFreq
[convertedkey
[0]]+1;
16 rev_endsaindex
= rev_bwt
->cumulativeFreq
[convertedkey
[0]+1];
17 startsaindex
= rev_bwt
->cumulativeFreq
[convertedkey
[0]]+1;
18 endsaindex
= rev_bwt
->cumulativeFreq
[convertedkey
[0]+1];
20 while (pos
< keylength
&& startsaindex
<= endsaindex
) {
21 c
= convertedkey
[pos
];
23 BWTAllOccValue(rev_bwt
,rev_startsaindex
,occcount_start
);
24 BWTAllOccValue(rev_bwt
,rev_endsaindex
+ 1,occcount_end
);
26 rev_startsaindex
= rev_bwt
->cumulativeFreq
[c
] + occcount_start
[c
] + 1;
27 rev_endsaindex
= rev_bwt
->cumulativeFreq
[c
] + occcount_end
[c
];
31 occcount
[i
]=occcount
[i
+1]+occcount_end
[i
+1]-occcount_start
[i
+1];
34 endsaindex
= endsaindex
- occcount
[c
];
35 startsaindex
= endsaindex
- (rev_endsaindex
-rev_startsaindex
);
39 *resultsaindexleft
= startsaindex
;
40 *resultsaindexright
= endsaindex
;
41 *rev_resultsaindexleft
= rev_startsaindex
;
42 *rev_resultsaindexright
= rev_endsaindex
;
44 sacount
+=endsaindex
-startsaindex
+1;
45 // number of occurrence = endsaindex - startsaindex + 1
51 unsigned int REVBWTContForwardSearch(const unsigned char *convertedkey
, const unsigned int start
, const unsigned int len
, const BWT
*rev_bwt
, unsigned int *sal
, unsigned int *sar
, unsigned int *rev_sal
, unsigned int *rev_sar
) {
53 unsigned int sacount
=0;
54 unsigned int pos
= start
;
56 unsigned int occcount_start
[4];
57 unsigned int occcount_end
[4];
58 unsigned int occcount
[4];
60 while (pos
< start
+len
&& *sal
<= *sar
) {
61 c
= convertedkey
[pos
];
63 BWTAllOccValue(rev_bwt
,*rev_sal
,occcount_start
);
64 BWTAllOccValue(rev_bwt
,*rev_sar
+ 1,occcount_end
);
66 *rev_sal
= rev_bwt
->cumulativeFreq
[c
] + occcount_start
[c
] + 1;
67 *rev_sar
= rev_bwt
->cumulativeFreq
[c
] + occcount_end
[c
];
71 occcount
[k
]=occcount
[k
+1]+occcount_end
[k
+1]-occcount_start
[k
+1];
74 *sar
= *sar
- occcount
[c
];
75 *sal
= *sar
- (*rev_sar
-*rev_sal
);
83 unsigned int BWTContBackwardSearch(const unsigned char *convertedkey
, const unsigned int start
, const unsigned int len
, const BWT
*bwt
, unsigned int *sal
, unsigned int *sar
) {
85 unsigned int sacount
=0;
86 unsigned int pos
= len
;
93 while (pos
> 0 && *sal
<= *sar
) {
94 c
= convertedkey
[pos
-1];
95 *sal
= bwt
->cumulativeFreq
[c
] + BWTOccValue(bwt
, *sal
, c
) + 1;
96 *sar
= bwt
->cumulativeFreq
[c
] + BWTOccValue(bwt
, *sar
+ 1, c
);
103 unsigned int BWTBackward1Error(char *querypattern
, int chain
, BWT
*bwt
, unsigned int start
, unsigned int len
, unsigned int pl
, unsigned int pr
, unsigned int allele2
, HitInfo
*hits
, unsigned int *numOfHits
) {
104 unsigned int mk_l
=1,mk_r
=0;
105 unsigned int occcount_pstart
[4];
106 unsigned int occcount_pend
[4];
107 unsigned int occcount_start
[4];
108 unsigned int occcount_end
[4];
109 unsigned int occcount
[4];
110 unsigned int sacount
=0;
115 unsigned int allele1
;
116 //printf("bwtbackward1error %u %u\n",pl,pr);
117 // v--start v----start+len
118 // querypattern = xxxxxxxxxxxxxxxxx[xxxxxxxxxxxxxx]xxxxxx
119 // <------- search direction
120 // querypattern[start+len-1], querypattern[start+len-2]...querypattern[start]
122 // append querypatter[start+len-1-i]!
124 for (i
=0;(i
<len
&& pl
<=pr
);i
++) {
125 //call once only proceduressssss - great
126 BWTAllOccValue(bwt
,pl
,occcount_pstart
);
127 BWTAllOccValue(bwt
,pr
+ 1,occcount_pend
);
130 for (ec
=0;ec
<4;ec
++) {
131 if (querypattern
[start
+len
-1-i
]==ec
)
134 allele1
= ((((start
+len
-1-i
) & 0xfff)<<2) | (ec
& 0x3));
138 unsigned int pos
= i
+1;
139 mk_l
= bwt
->cumulativeFreq
[ec
] + occcount_pstart
[ec
] + 1;
140 mk_r
= bwt
->cumulativeFreq
[ec
] + occcount_pend
[ec
];
142 if (BWTContBackwardSearch(querypattern
,start
,len
-i
-1,bwt
,&mk_l
,&mk_r
)) {
143 // printf("%d\t", start+len-1-i);
144 // printf("%d\n", ec);
145 // printf("%d\t%d\n",allele1, allele2);
146 OCCProcess(mk_l
,mk_r
, chain
, allele1
, allele2
, hits
, numOfHits
);
147 sacount
+=mk_r
-mk_l
+1;
150 c
= querypattern
[start
+len
-1-i
];
151 pl
= bwt
->cumulativeFreq
[c
] + occcount_pstart
[c
] + 1;
152 pr
= bwt
->cumulativeFreq
[c
] + occcount_pend
[c
];
159 unsigned int REVBWTForward1Error(char *querypattern
, int chain
, BWT
* bwt
,BWT
* rev_bwt
, unsigned int start
,unsigned int len
,unsigned int pl
,unsigned int pr
,unsigned int rev_pl
,unsigned int rev_pr
, unsigned int allele2
, HitInfo
*hits
, unsigned int *numOfHits
) {
161 unsigned int mk_l
=1,mk_r
=0,rev_mk_l
,rev_mk_r
;
162 unsigned int occcount_pstart
[4];
163 unsigned int occcount_pend
[4];
164 unsigned int occcountp
[4];
165 unsigned int occcount_start
[4];
166 unsigned int occcount_end
[4];
167 unsigned int occcount
[4];
168 unsigned int sacount
=0;
174 unsigned int allele1
;
175 for (i
=0;(i
<len
&& pl
<=pr
);i
++) {
176 //call once only proceduressssss - great
177 BWTAllOccValue(rev_bwt
,rev_pl
,occcount_pstart
);
178 BWTAllOccValue(rev_bwt
,rev_pr
+ 1,occcount_pend
);
182 occcountp
[k
]=occcountp
[k
+1]+occcount_pend
[k
+1]-occcount_pstart
[k
+1];
187 for (ec
=0;ec
<4;ec
++) {
188 if (querypattern
[start
+i
]==ec
)
191 allele1
= ((((start
+i
) & 0xfff)<<2) | (ec
& 0x3));
197 unsigned int pos
= i
+1;
199 rev_mk_l
= rev_bwt
->cumulativeFreq
[ec
] + occcount_pstart
[ec
] + 1;
200 rev_mk_r
= rev_bwt
->cumulativeFreq
[ec
] + occcount_pend
[ec
];
202 mk_r
= mk_r
- occcountp
[ec
];
203 mk_l
= mk_r
- (rev_mk_r
-rev_mk_l
);
205 if (REVBWTContForwardSearch(querypattern
,start
+pos
,len
-i
-1,rev_bwt
,&mk_l
,&mk_r
,&rev_mk_l
,&rev_mk_r
)) {
206 // printf("%d\t", start+i);
207 // printf("%d\n", ec);
208 OCCProcess(mk_l
,mk_r
, chain
, allele1
, allele2
, hits
, numOfHits
);
210 sacount
+=mk_r
-mk_l
+1;
213 c
= querypattern
[start
+i
];
215 rev_pl
= rev_bwt
->cumulativeFreq
[c
] + occcount_pstart
[c
] + 1;
216 rev_pr
= rev_bwt
->cumulativeFreq
[c
] + occcount_pend
[c
];
218 pr
= pr
- occcountp
[c
];
219 pl
= pr
- (rev_pr
-rev_pl
);