-
Notifications
You must be signed in to change notification settings - Fork 9
/
Levenshtein_Cal.cpp
6936 lines (5204 loc) · 220 KB
/
Levenshtein_Cal.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
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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Authors:
Haoyu Cheng
chhy@mail.ustc.edu.cn
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include<stdint.h>
#include <xmmintrin.h>
#include <mmintrin.h>
#include "Levenshtein_Cal.h"
unsigned short tmp_Peq[MAX_Thread][128][8];
unsigned int tmp_Peq_32[MAX_Thread][128][4];
int each_length;
int Calcu_Cigar_MD(int Peq_i,char *pattern,int p_length,char *text,int t_length,
unsigned short errthold,unsigned short band_down,unsigned short band_below,unsigned short band_length,int err,int match_site,char* cigar,char* MD_Z,int thread_id)
{
int mis_sites[SEQ_MAX_LENGTH];
int i = 0;
///这里要添加
int start_location=match_site-t_length+1;
int tmp_err=0;
for(i=0;i<t_length;i++)
{
if(text[i]!=pattern[i+start_location])
{
mis_sites[tmp_err]=i;
tmp_err++;
}
}
if(tmp_err==err)
{
i=0;
int pre_i=-1;
for(i=0;i<tmp_err;i++)
{
if(mis_sites[i]-pre_i>1)
{
sprintf(MD_Z+strlen(MD_Z),"%d%c",mis_sites[i]-pre_i-1,pattern[mis_sites[i]+start_location]);
}
else
{
sprintf(MD_Z+strlen(MD_Z),"%c",pattern[mis_sites[i]+start_location]);
}
pre_i=mis_sites[i];
}
if(pre_i+1<t_length)
{
sprintf(MD_Z+strlen(MD_Z),"%d",t_length-pre_i-1);
}
sprintf(cigar+strlen(cigar),"%d%c",t_length,'M');
return start_location;
}
start_location=match_site-t_length+1;
Word D0_arry_64[2000];
Word HP_arry_64[2000];
int Route_Size_Whole[2000];
char Route_Char_Whole[2000];
char err_match[2000];
Word Peq[128];
char Peq_index[4]= {'A','C','G','T'};
int symbol = 0;
int r;
Word tmp_Peq_1=(Word)1;
for(symbol = 0; symbol < 128; symbol++)
{
Peq[symbol]=(Word)0;
}
Peq['A']=tmp_Peq[thread_id]['A'][Peq_i];
Peq['C']=tmp_Peq[thread_id]['C'][Peq_i];
Peq['T']=tmp_Peq[thread_id]['T'][Peq_i];
Peq['G']=tmp_Peq[thread_id]['G'][Peq_i];
Word Mask_Pre=(Word)1<<(band_length-2);
Word Mask=(Word)1<<(band_length-1);
Word VP=0;
Word VN=0;
Word X=0;
Word HN=0;
int s=0;
int j=0;
i=0;
int bound=band_length-2-band_down;
Word err_mask=(Word)1;
int s1=band_length-2;
int i_bd=i+band_down;
int last_high=band_length-t_length+p_length-band_down-1;
Word bit_Mask=((Word)-1)>>(64-band_length);
Word tmp_D0,tmp_HP;
tmp_D0=0;
tmp_HP=0;
int t_length_1=t_length-1;
while(i<t_length_1)
{
X=Peq[text[i]]|VN;
tmp_D0=((VP+(X&VP))^VP)|X;
HN=VP&tmp_D0;
tmp_HP=VN|~(VP|tmp_D0);
X=tmp_D0>>1;
VN=X&tmp_HP;
VP=HN|~(X|tmp_HP);
D0_arry_64[i]=tmp_D0;
HP_arry_64[i]=tmp_HP;
Peq['A']=Peq['A']>>1;
Peq['C']=Peq['C']>>1;
Peq['G']=Peq['G']>>1;
Peq['T']=Peq['T']>>1;
++i;
++i_bd;
if((i_bd)<p_length)
Peq[pattern[i_bd]]=Peq[pattern[i_bd]]|Mask;
}
X=Peq[text[i]]|VN;
tmp_D0=((VP+(X&VP))^VP)|X;
HN=VP&tmp_D0;
tmp_HP=VN|~(VP|tmp_D0);
X=tmp_D0>>1;
VN=X&tmp_HP;
VP=HN|~(X|tmp_HP);
D0_arry_64[i]=tmp_D0;
HP_arry_64[i]=tmp_HP;
int site=p_length-last_high-1;
///对角方向和竖向就是这个;要是横向还要减1
int search_site=match_site-site;
///要是竖向还要减1
int pre_size=1;
char pre_char='N';
Word Mask_1=(Word)1;
i=t_length-1;
int sum_err=0;
///Route_size[0]存储到是Route_size这个数组到长度
j=1;
int err_char_i=0;
///这个放最前面是因为这些都是匹配的片段,所以绝大部分时间是匹配到
if(((D0_arry_64[i]>>search_site)&Mask_1)&&(pattern[match_site]==text[i])) ///对角方向(匹配)
{
i--;
pre_size=1;
pre_char='M';
match_site--;
///j--;
}
else if(!((D0_arry_64[i]>>search_site)&Mask_1)&&(pattern[match_site]!=text[i])) ///对角方向(替换)
{
err_match[err_char_i]=pattern[match_site];
err_char_i++;
i--;
pre_size=1;
pre_char='S';
match_site--;
sum_err++;
///j--;
}
else if((HP_arry_64[i]>>search_site)&Mask_1) ///水平方向过来,这个表示基因组上缺了一块 I代表参考基因组比read上少,即参考基因组比read缺了一块
{
err_match[err_char_i]=pattern[match_site];
err_char_i++;
i--;
search_site++;
pre_size=1;
///'I'代表基因组上缺了一块,但是这里是最后一个位置
///在这个地方,'S'与'I'是一样的
pre_char='S';
sum_err++;
start_location++;
}
else ///上方过来到 ///这个属于read上缺了一块
{
search_site--;
pre_size=1;
pre_char='D';
err_match[err_char_i]=pattern[match_site];;
err_char_i++;
match_site--;
sum_err++;
start_location--;
}
while(i>=0)
{
if(sum_err==err)
{
break;
}
///这个放最前面是因为这些都是匹配的片段,所以绝大部分时间是匹配到
if(((D0_arry_64[i]>>search_site)&Mask_1)&&(pattern[match_site]==text[i])) ///对角方向(匹配)
{
i--;
match_site--;
if(pre_char!='M')
{
Route_Size_Whole[j]=pre_size;
Route_Char_Whole[j++]=pre_char;
pre_size=1;
pre_char='M';
}
else
{
pre_size++;
}
}
else if(!((D0_arry_64[i]>>search_site)&Mask_1)&&(pattern[match_site]!=text[i])) ///对角方向(替换)
{
err_match[err_char_i]=pattern[match_site];
err_char_i++;
i--;
match_site--;
sum_err++;
if(pre_char!='S')
{
Route_Size_Whole[j]=pre_size;
Route_Char_Whole[j++]=pre_char;
pre_size=1;
pre_char='S';
}
else
{
pre_size++;
}
}
else if((HP_arry_64[i]>>search_site)&Mask_1) ///水平方向过来,这个表示基因组上缺了一块 I代表参考基因组比read上少,即参考基因组比read缺了一块
{
i--;
search_site++;
sum_err++;
if(pre_char!='I')
{
Route_Size_Whole[j]=pre_size;
Route_Char_Whole[j++]=pre_char;
pre_size=1;
pre_char='I';
}
else
{
pre_size++;
}
start_location++;
}
else ///上方过来到
{
err_match[err_char_i]=pattern[match_site];;
err_char_i++;
search_site--;
match_site--;
sum_err++;
if(pre_char!='D')
{
Route_Size_Whole[j]=pre_size;
Route_Char_Whole[j++]=pre_char;
pre_size=1;
pre_char='D';
}
else
{
pre_size++;
}
start_location--;
}
}
Route_Size_Whole[j]=pre_size;
Route_Char_Whole[j++]=pre_char;
///如果是break出来的,也就是后面还有M,则i一定是-1;i只要大于等于0,就代表提前终止了
if(i>=0)
{
Route_Size_Whole[j]=i+1;
Route_Char_Whole[j++]='M';
}
Route_Size_Whole[0]=j-1;
char pre_cigar=0;
///这里要修改
err_char_i--;
int ijk=0;
int is_D=0;
int pre_length=0;
for(j--;j>=1;--j)
{
if(Route_Char_Whole[j]=='M')
{
pre_length=pre_length+Route_Size_Whole[j];
///sprintf(MD_Z+strlen(MD_Z),"%d",Route_Size_Whole[j]);
is_D=0;
}
else if(Route_Char_Whole[j]=='S')
{
if(pre_length!=0)
sprintf(MD_Z+strlen(MD_Z),"%d",pre_length);
pre_length=0;
if(is_D)
{
sprintf(MD_Z+strlen(MD_Z),"%d",0);
}
for(ijk=0;ijk<Route_Size_Whole[j];++ijk)
{
sprintf(MD_Z+strlen(MD_Z),"%c",err_match[err_char_i]);
err_char_i--; ///这里要改
}
is_D=0;
}
else if(Route_Char_Whole[j]=='D') ///这里要改
{
if(pre_length!=0)
sprintf(MD_Z+strlen(MD_Z),"%d",pre_length);
pre_length=0;
sprintf(MD_Z+strlen(MD_Z),"%c",'^');
for(ijk=0;ijk<Route_Size_Whole[j];++ijk)
{
sprintf(MD_Z+strlen(MD_Z),"%c",err_match[err_char_i]);
err_char_i--; ///这里要改
}
is_D=1;
}
else
{
is_D=0;
}
}
if(pre_length!=0)
sprintf(MD_Z+strlen(MD_Z),"%d",pre_length);
int size_SM=0;
j=Route_Size_Whole[0];
for(;j>=1;--j)
{
if(Route_Char_Whole[j]=='M'||Route_Char_Whole[j]=='S')
{
size_SM=0;
while(Route_Char_Whole[j]=='M'||Route_Char_Whole[j]=='S')
{
size_SM=size_SM+Route_Size_Whole[j];
j--;
}
j++;
sprintf(cigar+strlen(cigar),"%d%c",size_SM,'M');
}
else
{
sprintf(cigar+strlen(cigar),"%d%c",Route_Size_Whole[j],Route_Char_Whole[j]);
}
}
return start_location;
}
int Start_location_Calcu_Cigar_MD(char *pattern,int p_length,char *text,int t_length,
unsigned short errthold,unsigned short band_down,unsigned short band_below,unsigned short band_length,int pre_err, char* cigar ,char* MD_Z,int thread_id,int return_site)
{
///这个与反向不同,已经知道start_location了
int mis_sites[SEQ_MAX_LENGTH];
int i = 0;
///基因组传过来的就已经是起始位置-errthold
int tmp_err=0;
for(i=0;i<t_length;i++)
{
if(text[i]!=pattern[thread_e+i])
{
mis_sites[tmp_err]=thread_e+i;
tmp_err++;
}
}
if(tmp_err==pre_err)
{
i=0;
int pre_i=thread_e-1;
for(i=0;i<tmp_err;i++)
{
if(mis_sites[i]-pre_i>1)
{
sprintf(MD_Z+strlen(MD_Z),"%d%c",mis_sites[i]-pre_i-1,pattern[mis_sites[i]]);
}
else
{
sprintf(MD_Z+strlen(MD_Z),"%c",pattern[mis_sites[i]]);
}
pre_i=mis_sites[i];
}
if(pre_i+1+thread_e<p_length)
{
sprintf(MD_Z+strlen(MD_Z),"%d",p_length-pre_i-1-thread_e);
}
sprintf(cigar+strlen(cigar),"%d%c",t_length,'M');
return 1;
}
Word D0_arry_64[2000];
Word HP_arry_64[2000];
int Route_Size_Whole[2000];
char Route_Char_Whole[2000];
char err_match[2000];
Word Peq[128];
char Peq_index[4]= {'A','C','G','T'};
int symbol = 0;
int r;
Word tmp_Peq_1=(Word)1;
Peq['A']=(Word)0;
Peq['T']=(Word)0;
Peq['G']=(Word)0;
Peq['C']=(Word)0;
Word Peq_A;
Word Peq_T;
Word Peq_C;
Word Peq_G;
for (r =0; r<band_length; r++)
{
Peq[pattern[p_length-r-1]]=Peq[pattern[p_length-r-1]]|tmp_Peq_1;
tmp_Peq_1=tmp_Peq_1<<1;
}
Peq_A=Peq['A'];
Peq_C=Peq['C'];
Peq_T=Peq['T'];
Peq_G=Peq['G'];
for(symbol = 0; symbol < 128; symbol++)
{
Peq[symbol]=(Word)0;
}
Peq['A']=Peq_A;
Peq['C']=Peq_C;
Peq['T']=Peq_T;
Peq['G']=Peq_G;
Word Mask_Pre=(Word)1<<(band_length-2);
Word Mask=(Word)1<<(band_length-1);
Word VP=0;
Word VN=0;
Word X=0;
Word D0=0;
Word HN=0;
Word HP=0;
int s=0;
i = 0;
int j=0;
int bound=band_length-2-band_down;
int err=0;
Word err_mask=(Word)1;
int s1=band_length-2;
i=t_length-1;
int i_bd=p_length-band_length;
int last_high=band_length-t_length+p_length-band_down-1;
while(i>0)
{
X=Peq[text[i]]|VN;
D0=((VP+(X&VP))^VP)|X;
D0_arry_64[i]=D0;
HN=VP&D0;
HP=VN|~(VP|D0);
HP_arry_64[i]=HP;
X=D0>>1;
VN=X&HP;
VP=HN|~(X|HP);
Peq['A']=Peq['A']>>1;
Peq['T']=Peq['T']>>1;
Peq['G']=Peq['G']>>1;
Peq['C']=Peq['C']>>1;
--i;
--i_bd;
Peq[pattern[i_bd]]=Peq[pattern[i_bd]]|Mask;
}
X=Peq[text[i]]|VN;
D0=((VP+(X&VP))^VP)|X;
D0_arry_64[i]=D0;
HN=VP&D0;
HP=VN|~(VP|D0);
HP_arry_64[i]=HP;
X=D0>>1;
VN=X&HP;
VP=HN|~(X|HP);
///int match_site=errthold;
///应该左移才对
int match_site=thread_e;
///int site=last_high-1;
///对角方向和竖向就是这个;要是横向还要减1
///int search_site=errthold;
///参考基因组的低位对应D0的高位
int search_site=2*thread_e-match_site;
///要是竖向还要减1
int pre_size=1;
char pre_char='N';
Word Mask_1=(Word)1;
i=0;
int sum_err=0;
int err_char_i=0;
char err_match_char[1000];
err_match_char[0]='\0';
int err_match_length[100];
err_match_length[0]=0;
char MD_Z_match[1000];
int MD_Z_char_i=0;
while(i<t_length)
{
if(sum_err==pre_err)
{
break;
}
if(((D0_arry_64[i]>>search_site)&Mask_1)&&(pattern[match_site]==text[i])) ///对角方向(匹配)
{
i++;
match_site++;
if(err_match_char[err_char_i]!='M')
{
err_char_i++;
err_match_char[err_char_i]='M';
err_match_length[err_char_i]=1;
err_match_length[0]++;
}
else
{
err_match_length[err_char_i]++;
}
///j--;
}
else if(!((D0_arry_64[i]>>search_site)&Mask_1)&&(pattern[match_site]!=text[i])) ///对角方向(替换)
{
MD_Z_match[MD_Z_char_i]=pattern[match_site];
MD_Z_char_i++;
i++;
match_site++;
sum_err++;
if(err_match_char[err_char_i]!='S')
{
err_char_i++;
err_match_char[err_char_i]='S';
err_match_length[err_char_i]=1;
err_match_length[0]++;
}
else
{
err_match_length[err_char_i]++;
}
}
else if((HP_arry_64[i]>>search_site)&Mask_1) ///水平方向过来
{
i++;
search_site++;
sum_err++;
if(err_match_char[err_char_i]!='I')
{
err_char_i++;
err_match_char[err_char_i]='I';
err_match_length[err_char_i]=1;
err_match_length[0]++;
}
else
{
err_match_length[err_char_i]++;
}
}
else ///上方过来到
{
MD_Z_match[MD_Z_char_i]=pattern[match_site];
MD_Z_char_i++;
search_site--;
match_site++;
sum_err++;
if(err_match_char[err_char_i]!='D')
{
err_char_i++;
err_match_char[err_char_i]='D';
err_match_length[err_char_i]=1;
err_match_length[0]++;
}
else
{
err_match_length[err_char_i]++;
}
continue;
}
}
if(i<t_length)
{
if(err_match_char[err_char_i]=='M')
{
err_match_length[err_char_i]+=t_length-i;
}
else
{
err_char_i++;
err_match_char[err_char_i]='M';
err_match_length[err_char_i]=t_length-i;
err_match_length[0]++;
}
}
int ijk=0;
int is_D=0;
int pre_length=0;
MD_Z_char_i=0;
for(i=1;i<=err_char_i;i++)
{
if(err_match_char[i]=='M')
{
pre_length=pre_length+err_match_length[i];
///sprintf(MD_Z+strlen(MD_Z),"%d",Route_Size_Whole[j]);
is_D=0;
}
else if(err_match_char[i]=='S')
{
if(pre_length!=0)
sprintf(MD_Z+strlen(MD_Z),"%d",pre_length);
pre_length=0;
if(is_D)
{
sprintf(MD_Z+strlen(MD_Z),"%d",0);
}
for(ijk=0;ijk<err_match_length[i];++ijk)
{
sprintf(MD_Z+strlen(MD_Z),"%c",MD_Z_match[MD_Z_char_i]);
MD_Z_char_i++; ///这里要改
}
is_D=0;
}
else if(err_match_char[i]=='D') ///这里要改
{
if(pre_length!=0)
sprintf(MD_Z+strlen(MD_Z),"%d",pre_length);
pre_length=0;
sprintf(MD_Z+strlen(MD_Z),"%c",'^');
for(ijk=0;ijk<err_match_length[i];++ijk)
{
sprintf(MD_Z+strlen(MD_Z),"%c",MD_Z_match[MD_Z_char_i]);
MD_Z_char_i++; ///这里要改
}
is_D=1;
}
else
{
///pre_length=pre_length+Route_Size_Whole[j];
is_D=0;
}
///fprintf(_out_fp,"%d%c",map.CIGAR_SIZE[j],map.CIGAR_CHAR[j]);
}
if(pre_length!=0)
sprintf(MD_Z+strlen(MD_Z),"%d",pre_length);
int size_SM=0;
/**
for(i=1;i<=err_char_i;i++)
{
sprintf(cigar+strlen(cigar),"%d%c",err_match_length[i],err_match_char[i]);
}
sprintf(cigar+strlen(cigar),"#####");
**/
for(i=1;i<=err_char_i;i++)
{
if(err_match_char[i]=='M'||err_match_char[i]=='S')
{
size_SM=0;
while(err_match_char[i]=='M'||err_match_char[i]=='S')
{
if(i>err_char_i)
break;
size_SM=size_SM+err_match_length[i];
///sprintf(cigar+strlen(cigar),"i=%d,length=%d,char=%c",i,err_match_length[i],err_match_char[i]);
i++;
}
i--;
sprintf(cigar+strlen(cigar),"%d%c",size_SM,'M');
}
else
{
sprintf(cigar+strlen(cigar),"%d%c",err_match_length[i],err_match_char[i]);
}
}
}
/****************************************4条,固定区间长度的算法***************************************************************/
int Brief_4_Banded_BPM_Non_SSE(char *pattern1,char *pattern2,char* pattern3, char* pattern4, int p_length,char *text,int t_length,
int* return_sites,int* return_sites_error,unsigned short errthold,unsigned short band_down,unsigned short band_below,unsigned short band_length, int thread_id)
{
Word Peq[128];
char Peq_index[4]= {'A','C','G','T'};
int symbol = 0;
int r;
Peq['A']=(Word)0;
Peq['T']=(Word)0;
Peq['G']=(Word)0;
Peq['C']=(Word)0;
Word Peq_A;
Word Peq_T;
Word Peq_C;
Word Peq_G;
Word tmp_Peq_1=(Word)1;
Word tmp_Peq_2=tmp_Peq_1<<(each_length); ///注意each_length对应的是band_length+1而不是band_length
Word tmp_Peq_3=tmp_Peq_2<<(each_length);
Word tmp_Peq_4=tmp_Peq_3<<(each_length);
int i=0;
for (r =0; r<band_length; r++)
{
Peq[pattern1[r]]=Peq[pattern1[r]]|tmp_Peq_1;
Peq[pattern2[r]]=Peq[pattern2[r]]|tmp_Peq_2;
Peq[pattern3[r]]=Peq[pattern3[r]]|tmp_Peq_3;
Peq[pattern4[r]]=Peq[pattern4[r]]|tmp_Peq_4;
tmp_Peq_1=tmp_Peq_1<<1;
tmp_Peq_2=tmp_Peq_2<<1;
tmp_Peq_3=tmp_Peq_3<<1;
tmp_Peq_4=tmp_Peq_4<<1;
}
Peq_A=Peq['A'];
Peq_C=Peq['C'];
Peq_T=Peq['T'];
Peq_G=Peq['G'];
for(symbol = 0; symbol < 128; symbol++)
{
Peq[symbol]=(Word)0;
}
Peq['A']=Peq_A;
Peq['C']=Peq_C;
Peq['T']=Peq_T;
Peq['G']=Peq_G;
Word All_1=(Word)-1;
Word single_err_mask1=All_1>>(64-each_length);
Word single_err_mask2=single_err_mask1<<(each_length);
Word single_err_mask3=single_err_mask2<<(each_length);
Word single_err_mask4=single_err_mask3<<(each_length);
if(each_length<=16)
{
tmp_Peq[thread_id]['A'][0]=Peq_A&single_err_mask1;
tmp_Peq[thread_id]['A'][1]=(Peq_A&single_err_mask2)>>each_length;
tmp_Peq[thread_id]['A'][2]=(Peq_A&single_err_mask3)>>(each_length+each_length);
tmp_Peq[thread_id]['A'][3]=(Peq_A)>>(each_length+each_length+each_length);
tmp_Peq[thread_id]['T'][0]=Peq_T&single_err_mask1;
tmp_Peq[thread_id]['T'][1]=(Peq_T&single_err_mask2)>>each_length;
tmp_Peq[thread_id]['T'][2]=(Peq_T&single_err_mask3)>>(each_length+each_length);
tmp_Peq[thread_id]['T'][3]=(Peq_T)>>(each_length+each_length+each_length);
tmp_Peq[thread_id]['G'][0]=Peq_G&single_err_mask1;
tmp_Peq[thread_id]['G'][1]=(Peq_G&single_err_mask2)>>each_length;
tmp_Peq[thread_id]['G'][2]=(Peq_G&single_err_mask3)>>(each_length+each_length);
tmp_Peq[thread_id]['G'][3]=(Peq_G)>>(each_length+each_length+each_length);
tmp_Peq[thread_id]['C'][0]=Peq_C&single_err_mask1;
tmp_Peq[thread_id]['C'][1]=(Peq_C&single_err_mask2)>>each_length;
tmp_Peq[thread_id]['C'][2]=(Peq_C&single_err_mask3)>>(each_length+each_length);
tmp_Peq[thread_id]['C'][3]=(Peq_C)>>(each_length+each_length+each_length);
}
else
{
tmp_Peq_32[thread_id]['A'][0]=Peq_A&single_err_mask1;
tmp_Peq_32[thread_id]['A'][1]=(Peq_A&single_err_mask2)>>each_length;
tmp_Peq_32[thread_id]['A'][2]=(Peq_A&single_err_mask3)>>(each_length+each_length);
tmp_Peq_32[thread_id]['A'][3]=(Peq_A)>>(each_length+each_length+each_length);
tmp_Peq_32[thread_id]['T'][0]=Peq_T&single_err_mask1;
tmp_Peq_32[thread_id]['T'][1]=(Peq_T&single_err_mask2)>>each_length;
tmp_Peq_32[thread_id]['T'][2]=(Peq_T&single_err_mask3)>>(each_length+each_length);
tmp_Peq_32[thread_id]['T'][3]=(Peq_T)>>(each_length+each_length+each_length);
tmp_Peq_32[thread_id]['G'][0]=Peq_G&single_err_mask1;
tmp_Peq_32[thread_id]['G'][1]=(Peq_G&single_err_mask2)>>each_length;
tmp_Peq_32[thread_id]['G'][2]=(Peq_G&single_err_mask3)>>(each_length+each_length);
tmp_Peq_32[thread_id]['G'][3]=(Peq_G)>>(each_length+each_length+each_length);
tmp_Peq_32[thread_id]['C'][0]=Peq_C&single_err_mask1;
tmp_Peq_32[thread_id]['C'][1]=(Peq_C&single_err_mask2)>>each_length;
tmp_Peq_32[thread_id]['C'][2]=(Peq_C&single_err_mask3)>>(each_length+each_length);
tmp_Peq_32[thread_id]['C'][3]=(Peq_C)>>(each_length+each_length+each_length);
}
Word Mask1=(Word)1<<(band_length-1);
Word Mask2=Mask1<<(each_length); ///each_length对应的是band_length+1
Word Mask3=Mask2<<(each_length);
Word Mask4=Mask3<<(each_length);
/*******************************这个是D0右移用的,好像也是加法也能用用的**************************************/
///这个是低band_length为1,高each_length-band_length为0
Word tmp_MASK=All_1>>(64-band_length);
Word Hppp_mask=((Word)0)|tmp_MASK;
tmp_MASK=tmp_MASK<<(each_length);
Hppp_mask=Hppp_mask|tmp_MASK;
tmp_MASK=tmp_MASK<<(each_length);
Hppp_mask=Hppp_mask|tmp_MASK;
tmp_MASK=tmp_MASK<<(each_length);
Hppp_mask=Hppp_mask|tmp_MASK;
Word _Hppp_mask=~Hppp_mask;
///这个是循环右移的掩码
tmp_MASK=All_1>>(64-band_length+1);
Word Hpp_Mask=((Word)0)|tmp_MASK;
tmp_MASK=tmp_MASK<<(each_length);
Hpp_Mask=Hpp_Mask|tmp_MASK;