5 This module contains DNA occurrence counting functions. The DNA must be
8 Copyright (C) 2004, Wong Chi Kwong.
10 This program is free software; you can redistribute it and/or
11 modify it under the terms of the GNU General Public License
12 as published by the Free Software Foundation; either version 2
13 of the License, or (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
29 #include "MiscUtilities.h"
32 void GenerateDNAOccCountTable(unsigned int *dnaDecodeTable
) {
34 unsigned int i
, j
, c
, t
;
36 for (i
=0; i
<DNA_OCC_CNT_TABLE_SIZE_IN_WORD
; i
++) {
37 dnaDecodeTable
[i
] = 0;
41 dnaDecodeTable
[i
] += 1 << (t
* 8);
48 unsigned int ForwardDNAOccCount(const unsigned int* dna
, const unsigned int index
, const unsigned int character
, const unsigned int* dnaDecodeTable
) {
50 static const unsigned int truncateRightMask
[16] = { 0x00000000, 0xC0000000, 0xF0000000, 0xFC000000,
51 0xFF000000, 0xFFC00000, 0xFFF00000, 0xFFFC0000,
52 0xFFFF0000, 0xFFFFC000, 0xFFFFF000, 0xFFFFFC00,
53 0xFFFFFF00, 0xFFFFFFC0, 0xFFFFFFF0, 0xFFFFFFFC };
55 unsigned int wordToCount
, charToCount
;
61 fprintf(stderr
, "ForwardDNAOccCount() : index >= 256!\n");
66 wordToCount
= index
/ 16;
67 charToCount
= index
- wordToCount
* 16;
69 for (i
=0; i
<wordToCount
; i
++) {
70 sum
+= dnaDecodeTable
[dna
[i
] >> 16];
71 sum
+= dnaDecodeTable
[dna
[i
] & 0x0000FFFF];
74 if (charToCount
> 0) {
75 c
= dna
[i
] & truncateRightMask
[charToCount
]; // increase count of 'a' by 16 - c;
76 sum
+= dnaDecodeTable
[c
>> 16];
77 sum
+= dnaDecodeTable
[c
& 0xFFFF];
78 sum
+= charToCount
- 16; // decrease count of 'a' by 16 - positionToProcess
81 return (sum
>> (character
* 8)) & 0x000000FF;
85 unsigned int BackwardDNAOccCount(const unsigned int* dna
, const unsigned int index
, const unsigned int character
, const unsigned int* dnaDecodeTable
) {
87 static const unsigned int truncateLeftMask
[16] = { 0x00000000, 0x00000003, 0x0000000F, 0x0000003F,
88 0x000000FF, 0x000003FF, 0x00000FFF, 0x00003FFF,
89 0x0000FFFF, 0x0003FFFF, 0x000FFFFF, 0x003FFFFF,
90 0x00FFFFFF, 0x03FFFFFF, 0x0FFFFFFF, 0x3FFFFFFF };
92 unsigned int wordToCount
, charToCount
;
98 fprintf(stderr
, "ForwardDNAOccCount() : index >= 256!\n");
103 wordToCount
= index
/ 16;
104 charToCount
= index
- wordToCount
* 16;
106 dna
-= wordToCount
+ 1;
108 if (charToCount
> 0) {
109 c
= *dna
& truncateLeftMask
[charToCount
]; // increase count of 'a' by 16 - c;
110 sum
+= dnaDecodeTable
[c
>> 16];
111 sum
+= dnaDecodeTable
[c
& 0xFFFF];
112 sum
+= charToCount
- 16; // decrease count of 'a' by 16 - positionToProcess
115 for (i
=0; i
<wordToCount
; i
++) {
117 sum
+= dnaDecodeTable
[*dna
>> 16];
118 sum
+= dnaDecodeTable
[*dna
& 0x0000FFFF];
121 return (sum
>> (character
* 8)) & 0x000000FF;
125 void ForwardDNAAllOccCount(const unsigned int* dna
, const unsigned int index
, unsigned int* __restrict occCount
, const unsigned int* dnaDecodeTable
) {
127 static const unsigned int truncateRightMask
[16] = { 0x00000000, 0xC0000000, 0xF0000000, 0xFC000000,
128 0xFF000000, 0xFFC00000, 0xFFF00000, 0xFFFC0000,
129 0xFFFF0000, 0xFFFFC000, 0xFFFFF000, 0xFFFFFC00,
130 0xFFFFFF00, 0xFFFFFFC0, 0xFFFFFFF0, 0xFFFFFFFC };
132 unsigned int wordToCount
, charToCount
;
134 unsigned int sum
= 0;
138 fprintf(stderr
, "ForwardDNAOccCount() : index >= 256!\n");
143 wordToCount
= index
/ 16;
144 charToCount
= index
- wordToCount
* 16;
146 for (i
=0; i
<wordToCount
; i
++) {
147 sum
+= dnaDecodeTable
[dna
[i
] >> 16];
148 sum
+= dnaDecodeTable
[dna
[i
] & 0x0000FFFF];
151 if (charToCount
> 0) {
152 c
= dna
[i
] & truncateRightMask
[charToCount
]; // increase count of 'a' by 16 - c;
153 sum
+= dnaDecodeTable
[c
>> 16];
154 sum
+= dnaDecodeTable
[c
& 0xFFFF];
155 sum
+= charToCount
- 16; // decrease count of 'a' by 16 - positionToProcess
158 occCount
[0] = sum
& 0x000000FF; sum
>>= 8;
159 occCount
[1] = sum
& 0x000000FF; sum
>>= 8;
160 occCount
[2] = sum
& 0x000000FF; sum
>>= 8;
165 void BackwardDNAAllOccCount(const unsigned int* dna
, const unsigned int index
, unsigned int* __restrict occCount
, const unsigned int* dnaDecodeTable
) {
167 static const unsigned int truncateLeftMask
[16] = { 0x00000000, 0x00000003, 0x0000000F, 0x0000003F,
168 0x000000FF, 0x000003FF, 0x00000FFF, 0x00003FFF,
169 0x0000FFFF, 0x0003FFFF, 0x000FFFFF, 0x003FFFFF,
170 0x00FFFFFF, 0x03FFFFFF, 0x0FFFFFFF, 0x3FFFFFFF };
172 unsigned int wordToCount
, charToCount
;
174 unsigned int sum
= 0;
178 fprintf(stderr
, "ForwardDNAOccCount() : index >= 256!\n");
183 wordToCount
= index
/ 16;
184 charToCount
= index
- wordToCount
* 16;
186 dna
-= wordToCount
+ 1;
188 if (charToCount
> 0) {
189 c
= *dna
& truncateLeftMask
[charToCount
]; // increase count of 'a' by 16 - c;
190 sum
+= dnaDecodeTable
[c
>> 16];
191 sum
+= dnaDecodeTable
[c
& 0xFFFF];
192 sum
+= charToCount
- 16; // decrease count of 'a' by 16 - positionToProcess
195 for (i
=0; i
<wordToCount
; i
++) {
197 sum
+= dnaDecodeTable
[*dna
>> 16];
198 sum
+= dnaDecodeTable
[*dna
& 0x0000FFFF];
201 occCount
[0] = sum
& 0x000000FF; sum
>>= 8;
202 occCount
[1] = sum
& 0x000000FF; sum
>>= 8;
203 occCount
[2] = sum
& 0x000000FF; sum
>>= 8;
208 unsigned int Forward1OccCount(const unsigned int* bitVector
, const unsigned int index
, const unsigned int* dnaDecodeTable
) {
210 static const unsigned int truncateRightMask
[32] = { 0x00000000, 0x80000000, 0xC0000000, 0xE0000000, 0xF0000000, 0xF8000000, 0xFC000000, 0xFE000000,
211 0xFF000000, 0xFF800000, 0xFFC00000, 0xFFE00000, 0xFFF00000, 0xFFF80000, 0xFFFC0000, 0xFFFE0000,
212 0xFFFF0000, 0xFFFF8000, 0xFFFFC000, 0xFFFFE000, 0xFFFFF000, 0xFFFFF800, 0xFFFFFC00, 0xFFFFFE00,
213 0xFFFFFF00, 0xFFFFFF80, 0xFFFFFFC0, 0xFFFFFFE0, 0xFFFFFFF0, 0xFFFFFFF8, 0xFFFFFFFC, 0xFFFFFFFE};
215 unsigned int wordToCount
, bitToCount
;
217 unsigned int sum
= 0;
218 unsigned int numberOf1
;
222 fprintf(stderr
, "Forward1OccCount() : index >= 256!\n");
227 wordToCount
= index
/ 32;
228 bitToCount
= index
- wordToCount
* 32;
230 for (i
=0; i
<wordToCount
; i
++) {
231 sum
+= dnaDecodeTable
[bitVector
[i
] >> 16];
232 sum
+= dnaDecodeTable
[bitVector
[i
] & 0x0000FFFF];
235 if (bitToCount
> 0) {
236 c
= bitVector
[i
] & truncateRightMask
[bitToCount
];
237 sum
+= dnaDecodeTable
[c
>> 16];
238 sum
+= dnaDecodeTable
[c
& 0x0000FFFF];
242 numberOf1
= sum
& 0x000000FF;
244 numberOf1
= sum
& 0x000000FF;
252 unsigned int Backward1OccCount(const unsigned int* bitVector
, const unsigned int index
, const unsigned int* dnaDecodeTable
) {
254 static const unsigned int truncateLeftMask
[32] = { 0x00000000, 0x00000001, 0x00000003, 0x00000007, 0x0000000F, 0x0000001F, 0x0000003F, 0x0000007F,
255 0x000000FF, 0x000001FF, 0x000003FF, 0x000007FF, 0x00000FFF, 0x00001FFF, 0x00003FFF, 0x00007FFF,
256 0x0000FFFF, 0x0001FFFF, 0x0003FFFF, 0x0007FFFF, 0x000FFFFF, 0x001FFFFF, 0x003FFFFF, 0x007FFFFF,
257 0x00FFFFFF, 0x01FFFFFF, 0x03FFFFFF, 0x07FFFFFF, 0x0FFFFFFF, 0x1FFFFFFF, 0x3FFFFFFF, 0x7FFFFFFF};
259 unsigned int wordToCount
, bitToCount
;
261 unsigned int sum
= 0;
262 unsigned int numberOf1
;
266 fprintf(stderr
, "ForwardDNAOccCount() : index >= 256!\n");
271 wordToCount
= index
/ 32;
272 bitToCount
= index
- wordToCount
* 32;
274 bitVector
-= wordToCount
+ 1;
276 if (bitToCount
> 0) {
277 c
= *bitVector
& truncateLeftMask
[bitToCount
];
278 sum
+= dnaDecodeTable
[c
>> 16];
279 sum
+= dnaDecodeTable
[c
& 0xFFFF];
282 for (i
=0; i
<wordToCount
; i
++) {
284 sum
+= dnaDecodeTable
[*bitVector
>> 16];
285 sum
+= dnaDecodeTable
[*bitVector
& 0x0000FFFF];
289 numberOf1
= sum
& 0x000000FF;
291 numberOf1
= sum
& 0x000000FF;
299 unsigned int ForwardDNAOccCountNoLimit(const unsigned int* dna
, const unsigned int index
, const unsigned int character
, const unsigned int* dnaDecodeTable
) {
301 static const unsigned int truncateRightMask
[16] = { 0x00000000, 0xC0000000, 0xF0000000, 0xFC000000,
302 0xFF000000, 0xFFC00000, 0xFFF00000, 0xFFFC0000,
303 0xFFFF0000, 0xFFFFC000, 0xFFFFF000, 0xFFFFFC00,
304 0xFFFFFF00, 0xFFFFFFC0, 0xFFFFFFF0, 0xFFFFFFFC };
306 unsigned int iteration
, wordToCount
, charToCount
;
307 unsigned int i
, j
, c
;
309 unsigned int occCount
= 0;
311 iteration
= index
/ 256;
312 wordToCount
= (index
- iteration
* 256) / 16;
313 charToCount
= index
- iteration
* 256 - wordToCount
* 16;
315 for (i
=0; i
<iteration
; i
++) {
318 for (j
=0; j
<16; j
++) {
319 sum
+= dnaDecodeTable
[*dna
>> 16];
320 sum
+= dnaDecodeTable
[*dna
& 0x0000FFFF];
323 if (!DNA_OCC_SUM_EXCEPTION(sum
)) {
324 occCount
+= (sum
>> (character
* 8)) & 0x000000FF;
326 // only some or all of the 3 bits are on
327 // in reality, only one of the four cases are possible
328 if (sum
== 0x00000100) {
329 if (character
== 0) {
332 } else if (sum
== 0x00010000) {
333 if (character
== 1) {
336 } else if (sum
== 0x01000000) {
337 if (character
== 2) {
340 } else if (sum
== 0x00000000) {
341 if (character
== 3) {
345 fprintf(stderr
, "ForwardDNAOccCountNoLimit(): DNA occ sum exception!\n");
353 for (j
=0; j
<wordToCount
; j
++) {
354 sum
+= dnaDecodeTable
[*dna
>> 16];
355 sum
+= dnaDecodeTable
[*dna
& 0x0000FFFF];
359 if (charToCount
> 0) {
360 c
= *dna
& truncateRightMask
[charToCount
]; // increase count of 'a' by 16 - c;
361 sum
+= dnaDecodeTable
[c
>> 16];
362 sum
+= dnaDecodeTable
[c
& 0xFFFF];
363 sum
+= charToCount
- 16; // decrease count of 'a' by 16 - positionToProcess
366 occCount
+= (sum
>> (character
* 8)) & 0x000000FF;
372 unsigned int BackwardDNAOccCountNoLimit(const unsigned int* dna
, const unsigned int index
, const unsigned int character
, const unsigned int* dnaDecodeTable
) {
374 static const unsigned int truncateLeftMask
[16] = { 0x00000000, 0x00000003, 0x0000000F, 0x0000003F,
375 0x000000FF, 0x000003FF, 0x00000FFF, 0x00003FFF,
376 0x0000FFFF, 0x0003FFFF, 0x000FFFFF, 0x003FFFFF,
377 0x00FFFFFF, 0x03FFFFFF, 0x0FFFFFFF, 0x3FFFFFFF };
379 unsigned int iteration
, wordToCount
, charToCount
;
380 unsigned int i
, j
, c
;
381 unsigned int sum
= 0;
382 unsigned int occCount
;
384 dna
-= index
/ 16 + 1;
386 iteration
= index
/ 256;
387 wordToCount
= (index
- iteration
* 256) / 16;
388 charToCount
= index
- iteration
* 256 - wordToCount
* 16;
390 if (charToCount
> 0) {
391 c
= *dna
& truncateLeftMask
[charToCount
]; // increase count of 'a' by 16 - c;
392 sum
+= dnaDecodeTable
[c
>> 16];
393 sum
+= dnaDecodeTable
[c
& 0xFFFF];
394 sum
+= charToCount
- 16; // decrease count of 'a' by 16 - positionToProcess
397 for (j
=0; j
<wordToCount
; j
++) {
399 sum
+= dnaDecodeTable
[*dna
>> 16];
400 sum
+= dnaDecodeTable
[*dna
& 0x0000FFFF];
403 occCount
= (sum
>> (character
* 8)) & 0x000000FF;
406 for (i
=0; i
<iteration
; i
++) {
409 for (j
=0; j
<16; j
++) {
411 sum
+= dnaDecodeTable
[*dna
>> 16];
412 sum
+= dnaDecodeTable
[*dna
& 0x0000FFFF];
414 if (!DNA_OCC_SUM_EXCEPTION(sum
)) {
415 occCount
+= (sum
>> (character
* 8)) & 0x000000FF;
417 // only some or all of the 3 bits are on
418 // in reality, only one of the four cases are possible
419 if (sum
== 0x00000100) {
420 if (character
== 0) {
423 } else if (sum
== 0x00010000) {
424 if (character
== 1) {
427 } else if (sum
== 0x01000000) {
428 if (character
== 2) {
431 } else if (sum
== 0x00000000) {
432 if (character
== 3) {
436 fprintf(stderr
, "BackwardDNAOccCountNoLimit(): DNA occ sum exception!\n");
447 void ForwardDNAAllOccCountNoLimit(const unsigned int* dna
, const unsigned int index
, unsigned int* __restrict occCount
, const unsigned int* dnaDecodeTable
) {
449 static const unsigned int truncateRightMask
[16] = { 0x00000000, 0xC0000000, 0xF0000000, 0xFC000000,
450 0xFF000000, 0xFFC00000, 0xFFF00000, 0xFFFC0000,
451 0xFFFF0000, 0xFFFFC000, 0xFFFFF000, 0xFFFFFC00,
452 0xFFFFFF00, 0xFFFFFFC0, 0xFFFFFFF0, 0xFFFFFFFC };
454 unsigned int iteration
, wordToCount
, charToCount
;
455 unsigned int i
, j
, c
;
463 iteration
= index
/ 256;
464 wordToCount
= (index
- iteration
* 256) / 16;
465 charToCount
= index
- iteration
* 256 - wordToCount
* 16;
467 for (i
=0; i
<iteration
; i
++) {
470 for (j
=0; j
<16; j
++) {
471 sum
+= dnaDecodeTable
[*dna
>> 16];
472 sum
+= dnaDecodeTable
[*dna
& 0x0000FFFF];
475 if (!DNA_OCC_SUM_EXCEPTION(sum
)) {
476 occCount
[0] += sum
& 0x000000FF; sum
>>= 8;
477 occCount
[1] += sum
& 0x000000FF; sum
>>= 8;
478 occCount
[2] += sum
& 0x000000FF; sum
>>= 8;
481 // only some or all of the 3 bits are on
482 // in reality, only one of the four cases are possible
483 if (sum
== 0x00000100) {
485 } else if (sum
== 0x00010000) {
487 } else if (sum
== 0x01000000) {
489 } else if (sum
== 0x00000000) {
492 fprintf(stderr
, "ForwardDNAAllOccCountNoLimit(): DNA occ sum exception!\n");
500 for (j
=0; j
<wordToCount
; j
++) {
501 sum
+= dnaDecodeTable
[*dna
>> 16];
502 sum
+= dnaDecodeTable
[*dna
& 0x0000FFFF];
506 if (charToCount
> 0) {
507 c
= *dna
& truncateRightMask
[charToCount
]; // increase count of 'a' by 16 - c;
508 sum
+= dnaDecodeTable
[c
>> 16];
509 sum
+= dnaDecodeTable
[c
& 0xFFFF];
510 sum
+= charToCount
- 16; // decrease count of 'a' by 16 - positionToProcess
513 occCount
[0] += sum
& 0x000000FF; sum
>>= 8;
514 occCount
[1] += sum
& 0x000000FF; sum
>>= 8;
515 occCount
[2] += sum
& 0x000000FF; sum
>>= 8;
520 void BackwardDNAAllOccCountNoLimit(const unsigned int* dna
, const unsigned int index
, unsigned int* __restrict occCount
, const unsigned int* dnaDecodeTable
) {
522 static const unsigned int truncateLeftMask
[16] = { 0x00000000, 0x00000003, 0x0000000F, 0x0000003F,
523 0x000000FF, 0x000003FF, 0x00000FFF, 0x00003FFF,
524 0x0000FFFF, 0x0003FFFF, 0x000FFFFF, 0x003FFFFF,
525 0x00FFFFFF, 0x03FFFFFF, 0x0FFFFFFF, 0x3FFFFFFF };
527 unsigned int iteration
, wordToCount
, charToCount
;
528 unsigned int i
, j
, c
;
531 dna
-= index
/ 16 + 1;
533 iteration
= index
/ 256;
534 wordToCount
= (index
- iteration
* 256) / 16;
535 charToCount
= index
- iteration
* 256 - wordToCount
* 16;
538 if (charToCount
> 0) {
539 c
= *dna
& truncateLeftMask
[charToCount
]; // increase count of 'a' by 16 - c;
540 sum
+= dnaDecodeTable
[c
>> 16];
541 sum
+= dnaDecodeTable
[c
& 0xFFFF];
542 sum
+= charToCount
- 16; // decrease count of 'a' by 16 - positionToProcess
545 for (j
=0; j
<wordToCount
; j
++) {
547 sum
+= dnaDecodeTable
[*dna
>> 16];
548 sum
+= dnaDecodeTable
[*dna
& 0x0000FFFF];
551 occCount
[0] = sum
& 0x000000FF; sum
>>= 8;
552 occCount
[1] = sum
& 0x000000FF; sum
>>= 8;
553 occCount
[2] = sum
& 0x000000FF; sum
>>= 8;
556 for (i
=0; i
<iteration
; i
++) {
559 for (j
=0; j
<16; j
++) {
561 sum
+= dnaDecodeTable
[*dna
>> 16];
562 sum
+= dnaDecodeTable
[*dna
& 0x0000FFFF];
564 if (!DNA_OCC_SUM_EXCEPTION(sum
)) {
565 occCount
[0] += sum
& 0x000000FF; sum
>>= 8;
566 occCount
[1] += sum
& 0x000000FF; sum
>>= 8;
567 occCount
[2] += sum
& 0x000000FF; sum
>>= 8;
570 // only some or all of the 3 bits are on
571 // in reality, only one of the four cases are possible
572 if (sum
== 0x00000100) {
574 } else if (sum
== 0x00010000) {
576 } else if (sum
== 0x01000000) {
578 } else if (sum
== 0x00000000) {
581 fprintf(stderr
, "BackwardDNAAllOccCountNoLimit(): DNA occ sum exception!\n");
591 void GenerateDNA_NOccCountTable(unsigned int *dnaDecodeTable
) {
593 unsigned int i
, j
, c
, t
;
595 for (i
=0; i
<DNA_N_OCC_CNT_TABLE_SIZE_IN_WORD
; i
++) {
596 dnaDecodeTable
[i
] = 0;
598 for (j
=0; j
<5; j
++) {
601 // Count of 'n' is to be derived from acgt
602 dnaDecodeTable
[i
] += 1 << (t
* 8);
610 unsigned int ForwardDNA_NOccCount(const unsigned int* dna
, const unsigned int index
, const unsigned int character
, const unsigned int* dnaDecodeTable
) {
612 static const unsigned int truncateRightMask
[10] = { 0x00000000, 0xE0000000, 0xFC000000, 0xFF800000,
613 0xFFF00000, 0xFFFE0000, 0xFFFFC000, 0xFFFFF800,
614 0xFFFFFF00, 0xFFFFFFE0};
616 unsigned int wordToCount
, charToCount
;
618 unsigned int sum
= 0;
619 unsigned int occCount
;
623 fprintf(stderr
, "ForwardDNA_NOccCount() : index > 250!\n");
628 wordToCount
= index
/ 10;
629 charToCount
= index
- wordToCount
* 10;
631 for (i
=0; i
<wordToCount
; i
++) {
632 sum
+= dnaDecodeTable
[dna
[i
] >> 17];
633 sum
+= dnaDecodeTable
[(dna
[i
] >> 2) & 0x00007FFF];
636 if (charToCount
> 0) {
637 c
= dna
[i
] & truncateRightMask
[charToCount
]; // increase count of 'a' by 10 - charToCount;
638 sum
+= dnaDecodeTable
[c
>> 17];
639 sum
+= dnaDecodeTable
[(c
>> 2) & 0x00007FFF];
640 sum
+= charToCount
- 10; // decrease count of 'a' by 10 - charToCount
643 if (character
!= 4) {
644 occCount
= (sum
>> (character
* 8)) & 0x000000FF;
647 occCount
-= sum
& 0x000000FF; sum
>>= 8;
648 occCount
-= sum
& 0x000000FF; sum
>>= 8;
649 occCount
-= sum
& 0x000000FF; sum
>>= 8;
657 unsigned int BackwardDNA_NOccCount(const unsigned int* dna
, const unsigned int index
, const unsigned int character
, const unsigned int* dnaDecodeTable
) {
659 static const unsigned int truncateLeftMask
[10] = { 0x00000000, 0x0000001C, 0x000000FC, 0x000007FC,
660 0x00003FFC, 0x0001FFFC, 0x000FFFFC, 0x007FFFFC,
661 0x03FFFFFC, 0x1FFFFFFC};
663 unsigned int wordToCount
, charToCount
;
665 unsigned int sum
= 0;
666 unsigned int occCount
;
670 fprintf(stderr
, "BackwardDNA_NOccCount() : index >= 250!\n");
675 wordToCount
= index
/ 10;
676 charToCount
= index
- wordToCount
* 10;
678 dna
-= wordToCount
+ 1;
680 if (charToCount
> 0) {
681 c
= *dna
& truncateLeftMask
[charToCount
]; // increase count of 'a' by 10 - charToCount;
682 sum
+= dnaDecodeTable
[c
>> 17];
683 sum
+= dnaDecodeTable
[(c
>> 2) & 0x00007FFF];
684 sum
+= charToCount
- 10; // decrease count of 'a' by 10 - charToCount
687 for (j
=0; j
<wordToCount
; j
++) {
689 sum
+= dnaDecodeTable
[*dna
>> 17];
690 sum
+= dnaDecodeTable
[(*dna
>> 2) & 0x00007FFF];
693 if (character
!= 4) {
694 occCount
= (sum
>> (character
* 8)) & 0x000000FF;
697 occCount
-= sum
& 0x000000FF; sum
>>= 8;
698 occCount
-= sum
& 0x000000FF; sum
>>= 8;
699 occCount
-= sum
& 0x000000FF; sum
>>= 8;
704 if (occCount
> index
+ 1) {
705 fprintf(stderr
, "BackwardDNA_NOccCount() : occCount > index + 1!\n");
714 void ForwardDNA_NAllOccCount(const unsigned int* dna
, const unsigned int index
, unsigned int* __restrict occCount
, const unsigned int* dnaDecodeTable
) {
716 static const unsigned int truncateRightMask
[10] = { 0x00000000, 0xE0000000, 0xFC000000, 0xFF800000,
717 0xFFF00000, 0xFFFE0000, 0xFFFFC000, 0xFFFFF800,
718 0xFFFFFF00, 0xFFFFFFE0};
720 unsigned int wordToCount
, charToCount
;
722 unsigned int sum
= 0;
726 fprintf(stderr
, "ForwardDNA_NAllOccCount() : index >= 250!\n");
731 wordToCount
= index
/ 10;
732 charToCount
= index
- wordToCount
* 10;
734 for (i
=0; i
<wordToCount
; i
++) {
735 sum
+= dnaDecodeTable
[dna
[i
] >> 17];
736 sum
+= dnaDecodeTable
[(dna
[i
] >> 2) & 0x00007FFF];
739 if (charToCount
> 0) {
740 c
= dna
[i
] & truncateRightMask
[charToCount
]; // increase count of 'a' by 10 - charToCount;
741 sum
+= dnaDecodeTable
[c
>> 17];
742 sum
+= dnaDecodeTable
[(c
>> 2) & 0x00007FFF];
743 sum
+= charToCount
- 10; // decrease count of 'a' by 10 - charToCount
746 occCount
[0] = sum
& 0x000000FF; sum
>>= 8;
747 occCount
[1] = sum
& 0x000000FF; sum
>>= 8;
748 occCount
[2] = sum
& 0x000000FF; sum
>>= 8;
753 void BackwardDNA_NAllOccCount(const unsigned int* dna
, const unsigned int index
, unsigned int* __restrict occCount
, const unsigned int* dnaDecodeTable
) {
755 static const unsigned int truncateLeftMask
[10] = { 0x00000000, 0x0000001C, 0x000000FC, 0x000007FC,
756 0x00003FFC, 0x0001FFFC, 0x000FFFFC, 0x007FFFFC,
757 0x03FFFFFC, 0x1FFFFFFC};
759 unsigned int wordToCount
, charToCount
;
761 unsigned int sum
= 0;
765 fprintf(stderr
, "BackwardDNA_NAllOccCount() : index >= 250!\n");
770 wordToCount
= index
/ 10;
771 charToCount
= index
- wordToCount
* 10;
773 dna
-= wordToCount
+ 1;
775 if (charToCount
> 0) {
776 c
= *dna
& truncateLeftMask
[charToCount
]; // increase count of 'a' by 10 - charToCount;
777 sum
+= dnaDecodeTable
[c
>> 17];
778 sum
+= dnaDecodeTable
[(c
>> 2) & 0x00007FFF];
779 sum
+= charToCount
- 10; // decrease count of 'a' by 16 - charToCount
782 for (j
=0; j
<wordToCount
; j
++) {
784 sum
+= dnaDecodeTable
[*dna
>> 17];
785 sum
+= dnaDecodeTable
[(*dna
>> 2) & 0x00007FFF];
788 occCount
[0] = sum
& 0x000000FF; sum
>>= 8;
789 occCount
[1] = sum
& 0x000000FF; sum
>>= 8;
790 occCount
[2] = sum
& 0x000000FF; sum
>>= 8;
795 unsigned int ForwardDNA_NOccCountNoLimit(const unsigned int* dna
, const unsigned int index
, const unsigned int character
, const unsigned int* dnaDecodeTable
) {
797 static const unsigned int truncateRightMask
[10] = { 0x00000000, 0xE0000000, 0xFC000000, 0xFF800000,
798 0xFFF00000, 0xFFFE0000, 0xFFFFC000, 0xFFFFF800,
799 0xFFFFFF00, 0xFFFFFFE0};
801 unsigned int iteration
, wordToCount
, charToCount
;
802 unsigned int i
, j
, c
;
804 unsigned int occCount
= 0;
806 iteration
= index
/ 250;
807 wordToCount
= (index
- iteration
* 250) / 10;
808 charToCount
= index
- iteration
* 250 - wordToCount
* 10;
810 for (i
=0; i
<iteration
; i
++) {
813 for (j
=0; j
<25; j
++) {
814 sum
+= dnaDecodeTable
[*dna
>> 17];
815 sum
+= dnaDecodeTable
[(*dna
>> 2) & 0x00007FFF];
818 if (character
!= 4) {
819 occCount
+= (sum
>> (character
* 8)) & 0x000000FF;
821 occCount
-= sum
& 0x000000FF; sum
>>= 8;
822 occCount
-= sum
& 0x000000FF; sum
>>= 8;
823 occCount
-= sum
& 0x000000FF; sum
>>= 8;
829 for (j
=0; j
<wordToCount
; j
++) {
830 sum
+= dnaDecodeTable
[*dna
>> 17];
831 sum
+= dnaDecodeTable
[(*dna
>> 2) & 0x00007FFF];
835 if (charToCount
> 0) {
836 c
= *dna
& truncateRightMask
[charToCount
]; // increase count of 'a' by 10 - charToCount;
837 sum
+= dnaDecodeTable
[c
>> 17];
838 sum
+= dnaDecodeTable
[(c
>> 2) & 0x00007FFF];
839 sum
+= charToCount
- 10; // decrease count of 'a' by 10 - charToCount
842 if (character
!= 4) {
843 occCount
+= (sum
>> (character
* 8)) & 0x000000FF;
846 occCount
-= sum
& 0x000000FF; sum
>>= 8;
847 occCount
-= sum
& 0x000000FF; sum
>>= 8;
848 occCount
-= sum
& 0x000000FF; sum
>>= 8;
856 unsigned int BackwardDNA_NOccCountNoLimit(const unsigned int* dna
, const unsigned int index
, const unsigned int character
, const unsigned int* dnaDecodeTable
) {
858 static const unsigned int truncateLeftMask
[10] = { 0x00000000, 0x0000001C, 0x000000FC, 0x000007FC,
859 0x00003FFC, 0x0001FFFC, 0x000FFFFC, 0x007FFFFC,
860 0x03FFFFFC, 0x1FFFFFFC};
862 unsigned int iteration
, wordToCount
, charToCount
;
863 unsigned int i
, j
, c
;
864 unsigned int sum
= 0;
865 unsigned int occCount
= 0;
867 dna
-= index
/ 10 + 1;
869 iteration
= index
/ 250;
870 wordToCount
= (index
- iteration
* 250) / 10;
871 charToCount
= index
- iteration
* 250 - wordToCount
* 10;
873 if (charToCount
> 0) {
874 c
= *dna
& truncateLeftMask
[charToCount
]; // increase count of 'a' by 10 - charToCount;
875 sum
+= dnaDecodeTable
[c
>> 17];
876 sum
+= dnaDecodeTable
[(c
>> 2) & 0x00007FFF];
877 sum
+= charToCount
- 10; // decrease count of 'a' by 10 - charToCount
880 for (j
=0; j
<wordToCount
; j
++) {
882 sum
+= dnaDecodeTable
[*dna
>> 17];
883 sum
+= dnaDecodeTable
[(*dna
>> 2) & 0x00007FFF];
886 if (character
!= 4) {
887 occCount
= (sum
>> (character
* 8)) & 0x000000FF;
890 occCount
-= sum
& 0x000000FF; sum
>>= 8;
891 occCount
-= sum
& 0x000000FF; sum
>>= 8;
892 occCount
-= sum
& 0x000000FF; sum
>>= 8;
896 for (i
=0; i
<iteration
; i
++) {
899 for (j
=0; j
<25; j
++) {
901 sum
+= dnaDecodeTable
[*dna
>> 17];
902 sum
+= dnaDecodeTable
[(*dna
>> 2) & 0x00007FFF];
904 if (character
!= 4) {
905 occCount
+= (sum
>> (character
* 8)) & 0x000000FF;
907 occCount
-= sum
& 0x000000FF; sum
>>= 8;
908 occCount
-= sum
& 0x000000FF; sum
>>= 8;
909 occCount
-= sum
& 0x000000FF; sum
>>= 8;
918 void ForwardDNA_NAllOccCountNoLimit(const unsigned int* dna
, const unsigned int index
, unsigned int* __restrict occCount
, const unsigned int* dnaDecodeTable
) {
920 static const unsigned int truncateRightMask
[10] = { 0x00000000, 0xE0000000, 0xFC000000, 0xFF800000,
921 0xFFF00000, 0xFFFE0000, 0xFFFFC000, 0xFFFFF800,
922 0xFFFFFF00, 0xFFFFFFE0};
924 unsigned int iteration
, wordToCount
, charToCount
;
925 unsigned int i
, j
, c
;
933 iteration
= index
/ 250;
934 wordToCount
= (index
- iteration
* 250) / 10;
935 charToCount
= index
- iteration
* 250 - wordToCount
* 10;
937 for (i
=0; i
<iteration
; i
++) {
940 for (j
=0; j
<25; j
++) {
941 sum
+= dnaDecodeTable
[*dna
>> 17];
942 sum
+= dnaDecodeTable
[(*dna
>> 2) & 0x00007FFF];
945 occCount
[0] += sum
& 0x000000FF; sum
>>= 8;
946 occCount
[1] += sum
& 0x000000FF; sum
>>= 8;
947 occCount
[2] += sum
& 0x000000FF; sum
>>= 8;
952 for (j
=0; j
<wordToCount
; j
++) {
953 sum
+= dnaDecodeTable
[*dna
>> 17];
954 sum
+= dnaDecodeTable
[(*dna
>> 2) & 0x00007FFF];
958 if (charToCount
> 0) {
959 c
= *dna
& truncateRightMask
[charToCount
]; // increase count of 'a' by 10 - charToCount;
960 sum
+= dnaDecodeTable
[c
>> 17];
961 sum
+= dnaDecodeTable
[(c
>> 2) & 0x00007FFF];
962 sum
+= charToCount
- 10; // decrease count of 'a' by 10 - charToCount
965 occCount
[0] += sum
& 0x000000FF; sum
>>= 8;
966 occCount
[1] += sum
& 0x000000FF; sum
>>= 8;
967 occCount
[2] += sum
& 0x000000FF; sum
>>= 8;
972 void BackwardDNA_NAllOccCountNoLimit(const unsigned int* dna
, const unsigned int index
, unsigned int* __restrict occCount
, const unsigned int* dnaDecodeTable
) {
974 static const unsigned int truncateLeftMask
[10] = { 0x00000000, 0x0000001C, 0x000000FC, 0x000007FC,
975 0x00003FFC, 0x0001FFFC, 0x000FFFFC, 0x007FFFFC,
976 0x03FFFFFC, 0x1FFFFFFC};
978 unsigned int iteration
, wordToCount
, charToCount
;
979 unsigned int i
, j
, c
;
980 unsigned int sum
= 0;
982 dna
-= index
/ 10 + 1;
984 iteration
= index
/ 250;
985 wordToCount
= (index
- iteration
* 250) / 10;
986 charToCount
= index
- iteration
* 250 - wordToCount
* 10;
988 if (charToCount
> 0) {
989 c
= *dna
& truncateLeftMask
[charToCount
]; // increase count of 'a' by 10 - charToCount;
990 sum
+= dnaDecodeTable
[c
>> 17];
991 sum
+= dnaDecodeTable
[(c
>> 2) & 0x00007FFF];
992 sum
+= charToCount
- 10; // decrease count of 'a' by 16 - charToCount
995 for (j
=0; j
<wordToCount
; j
++) {
997 sum
+= dnaDecodeTable
[*dna
>> 17];
998 sum
+= dnaDecodeTable
[(*dna
>> 2) & 0x00007FFF];
1001 occCount
[0] = sum
& 0x000000FF; sum
>>= 8;
1002 occCount
[1] = sum
& 0x000000FF; sum
>>= 8;
1003 occCount
[2] = sum
& 0x000000FF; sum
>>= 8;
1006 for (i
=0; i
<iteration
; i
++) {
1009 for (j
=0; j
<25; j
++) {
1011 sum
+= dnaDecodeTable
[*dna
>> 17];
1012 sum
+= dnaDecodeTable
[(*dna
>> 2) & 0x00007FFF];
1014 occCount
[0] += sum
& 0x000000FF; sum
>>= 8;
1015 occCount
[1] += sum
& 0x000000FF; sum
>>= 8;
1016 occCount
[2] += sum
& 0x000000FF; sum
>>= 8;
1022 unsigned int ForwardOccCount(const unsigned int* packed
, const unsigned int index
, const unsigned int character
, const unsigned int alphabetSize
) {
1024 unsigned int wordToCount
, charToCount
;
1025 unsigned int bitPerChar
, charPerWord
;
1026 unsigned int i
, j
, c
;
1027 unsigned int occCount
= 0;
1029 bitPerChar
= ceilLog2(alphabetSize
);
1030 charPerWord
= BITS_IN_WORD
/ bitPerChar
;
1032 wordToCount
= index
/ charPerWord
;
1033 charToCount
= index
- wordToCount
* charPerWord
;
1035 for (i
=0; i
<wordToCount
; i
++) {
1037 for (j
=0; j
<charPerWord
; j
++) {
1038 if (c
>> (BITS_IN_WORD
- bitPerChar
) == character
) {
1044 if (charToCount
> 0) {
1046 for (j
=0; j
<charToCount
; j
++) {
1047 if (c
>> (BITS_IN_WORD
- bitPerChar
) == character
) {
1059 unsigned int BackwardOccCount(const unsigned int* packed
, const unsigned int index
, const unsigned int character
, const unsigned int alphabetSize
) {
1061 unsigned int wordToCount
, charToCount
;
1062 unsigned int bitPerChar
, charPerWord
;
1063 unsigned int i
, j
, c
;
1064 unsigned int occCount
= 0;
1066 bitPerChar
= ceilLog2(alphabetSize
);
1067 charPerWord
= BITS_IN_WORD
/ bitPerChar
;
1069 wordToCount
= index
/ charPerWord
;
1070 charToCount
= index
- wordToCount
* charPerWord
;
1072 packed
-= wordToCount
+ 1;
1074 if (charToCount
> 0) {
1075 c
= *packed
<< (bitPerChar
* (charPerWord
- charToCount
));
1076 for (j
=0; j
<charToCount
; j
++) {
1077 if (c
>> (BITS_IN_WORD
- bitPerChar
) == character
) {
1084 for (i
=1; i
<=wordToCount
; i
++) {
1087 for (j
=0; j
<charPerWord
; j
++) {
1088 if (c
>> (BITS_IN_WORD
- bitPerChar
) == character
) {
1098 void ForwardAllOccCount(const unsigned int* packed
, const unsigned int index
, const unsigned int alphabetSize
, unsigned int* occCount
) {
1100 unsigned int wordToCount
, charToCount
;
1101 unsigned int bitPerChar
, charPerWord
;
1102 unsigned int i
, j
, c
;
1104 bitPerChar
= ceilLog2(alphabetSize
);
1105 charPerWord
= BITS_IN_WORD
/ bitPerChar
;
1107 wordToCount
= index
/ charPerWord
;
1108 charToCount
= index
- wordToCount
* charPerWord
;
1110 for (i
=0; i
<wordToCount
; i
++) {
1112 for (j
=0; j
<charPerWord
; j
++) {
1113 occCount
[c
>> (BITS_IN_WORD
- bitPerChar
)]++;
1117 if (charToCount
> 0) {
1119 for (j
=0; j
<charToCount
; j
++) {
1120 occCount
[c
>> (BITS_IN_WORD
- bitPerChar
)]++;
1127 void BackwardAllOccCount(const unsigned int* packed
, const unsigned int index
, const unsigned int alphabetSize
, unsigned int* occCount
) {
1129 unsigned int wordToCount
, charToCount
;
1130 unsigned int bitPerChar
, charPerWord
;
1131 unsigned int i
, j
, c
;
1133 bitPerChar
= ceilLog2(alphabetSize
);
1134 charPerWord
= BITS_IN_WORD
/ bitPerChar
;
1136 wordToCount
= index
/ charPerWord
;
1137 charToCount
= index
- wordToCount
* charPerWord
;
1139 packed
-= wordToCount
+ 1;
1141 if (charToCount
> 0) {
1142 c
= *packed
<< (bitPerChar
* (charPerWord
- charToCount
));
1143 for (j
=0; j
<charToCount
; j
++) {
1144 occCount
[c
>> (BITS_IN_WORD
- bitPerChar
)]++;
1149 for (i
=1; i
<=wordToCount
; i
++) {
1152 for (j
=0; j
<charPerWord
; j
++) {
1153 occCount
[c
>> (BITS_IN_WORD
- bitPerChar
)]++;