-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmy_needle.cpp
3742 lines (3499 loc) · 132 KB
/
my_needle.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
/* @funcstatic embAlignGetScoreNWMatrix ***************************************
**
** Returns score of the optimal global or overlap alignment for
** the specified path matrix for Needleman Wunsch
**
** @param [r] ix [const float*] Gap scores array, ix(i,j) is the best score
** given that a(i) is aligned to a gap
** (in an insertion with respect to b)
** @param [r] iy [const float*] Gap scores array, iy(i,j) is the best score
** given that b(i) is in an insertion
** with respect to a
**
** @param [r] m [const float*] Match scores array, m(i,j) is the best score
** up to (i,j) given that a(i) is aligned to b(j)
** @param [r] lena [ajint] length of the first sequence
** @param [r] lenb [ajint] length of the second sequence
** @param [w] start1 [ajint *] start of alignment in first sequence
** @param [w] start2 [ajint *] start of alignment in second sequence
** @param [r] endweight [AjBool] whether the matrix was built for
** a global or overlap alignment
**
** @return [float] optimal score
******************************************************************************/
/*
* =====================================================================================
* Filename: my_needle.cpp
* Description: global sequence alignment with position specific gap
* penalties
* Created: 09/09/2010 11:26:51 PM CEST
* Compiler: g++
* Author: Nanjiang Shu, nanjiang.shu@scilifelab.se
* Company: Department of Biochemistry and Biophysics, Stockholm Univesity
* =====================================================================================
*/
#include <cstdio>
#include <sys/stat.h>
#include <sys/types.h>
#include <cstring>
#include <cctype>
#include <cstdlib>
#include <cmath>
#include <string>
#include <map>
#include <set>
#include <vector>
#include <iostream>
#include <sstream>
#include <fstream>
#include <algorithm>
#include <cassert>
#include <ctime>
#include <climits>
#include "array.h"
using namespace std;
typedef unsigned char BYTE;
struct Pair{/*{{{*/
string mem1;
string mem2;
};/*}}}*/
struct dbindex{/*{{{*/
int dbfileindex;
long offset;
unsigned long size;
};/*}}}*/
/*the gapopenarray,
* if want to open a gap at position 4, set the gapopen score at 4th position
* to be a low value
* e.g.
*
* ACDEGD
* AVDEGD
*
* if you want an alignment
* ACD-EGD
* AVDEGD-
*
* set the gapopen value of seq1 gapopen[3] = -1000
*
* */
#ifndef WHITE_SPACE
#define WHITE_SPACE " \t\r\n"
#endif
#ifndef SEQALIGN
#define SEQALIGN
/*for the alignment result*/
#define IDT 3 /* identity*/
#define SIM 2 /* similar, positive*/
#define MIS 1 /* mismatch*/
#define GAP 0 /* gap*/
#endif
#ifndef ERROR_CODE
#define READ_FILE_ERROR 1
#define WRITE_FILE_ERROR 2
//#define READ_OVERFLOW 5
//#define WRITE_OVERFLOW 5
//#define UNDERFLOW 10
#endif /*ERROR_CODE*/
#ifndef SEQ_TYPE
#define SEQ_TYPE
#define DNA_SEQ 0 // dna sequence
#define AA_SEQ 1 // amino acid sequence
#define SHAPE_SEQ 2 // shape string sequence
#define UNKNOWN_SEQ_TYPE -1
#endif
typedef int ajint;
typedef unsigned int ajuint;
typedef ajint AjBool;
typedef signed char int8;
#define ajFalse 0
#define ajTrue 1
#define U_FEPS 1.192e-6F /* 1.0F + E_FEPS != 1.0F */
#define U_DEPS 2.22e-15 /* 1.0 + E_DEPS != 1.0 */
#undef DIAG
#undef LEFT
#undef DOWN
#define DIAG 0
#define LEFT 1
#define DOWN 2
#undef CHAR_GAP
#define CHAR_GAP '-'
#define E_FPEQ(a,b,e) (((b - e) < a) && (a < (b + e)))
#undef SIZE_TITLE
#define SIZE_TITLE 100
#undef LONGEST_SEQ
int LONGEST_SEQ=80000;
float gapopen = 10.0;
float gapextend = 0.5;
float endgapopen = 10.0;
float endgapextend = 10.0;
int seq_type = AA_SEQ; /* sequence type, default is amino acid sequence*/
int nchar = 50; /*maximum length of sequence to print at each line*/
bool isCheckSeqIDTClass = true;
bool isShowProgress = true;
bool isRandSelection = true;
int method_select_pair = 1;
#define HIGH_COVERAGE 0
#define HIGH_PRECISION 1
int KMerThresholdMode = HIGH_PRECISION;
bool isPrintKMerBitScore = false;
int wordsize = 3;
int maxSeqIDTClass[]={
10000, /*0 - 10*/
10000, /*10 - 20*/
10000, /*20 - 30*/
10000, /*30 - 40*/
10000, /*40 - 50*/
10000, /*50 - 60*/
10000, /*60 - 70*/
10000, /*70 - 80*/
10000, /*80 - 90*/
10000 /*90 - 100*/
};
float binSeqIDTClass[] = {
0.0, 10.0,
10.0, 20.0,
20.0, 30.0,
30.0, 40.0,
40.0, 50.0,
50.0, 60.0,
60.0, 70.0,
70.0, 80.0,
80.0, 90.0,
90.0, 100.0
};
int numSeqIDTClass = sizeof(maxSeqIDTClass)/sizeof(int);
const int para20[]={
1,
20,
20*20,
20*20*20,
20*20*20*20,
20*20*20*20*20,
20*20*20*20*20*20,
20*20*20*20*20*20*20,
};
const int aacode[]=
{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*first 65 chars*/
/*unique AA, ARNDCQEGHILKMFPSTWYVBZX */
/*A,B, C,D,E,F ,G,H,I,J, K, L, M, N,O, P, Q,R,S ,T, U, V, W, X, Y, Z */
0,20,4,3,6,13,7,8,9,22,11,10,12,2,22,14,5,1,15,16,22,19,17,22,18,21
-1,-1,-1,-1,-1,-1,-1,
/*a,b, c,d,e,f ,g,h,i,j, k, l, m, n,o, p, q,r,s ,t, u, v, w, x, y, z */
0,20,4,3,6,13,7,8,9,22,11,10,12,2,22,14,5,1,15,16,22,19,17,22,18,21
};
#define NUM_BLOSUM 24 //size of BLOSUM matrix
#define NUM_NUC 15
#define NUM_SHAG 12
int MAX_ALIGN_SIZE=1024; /*1024 MB*/
int THRESHOLD_DB_FILESIZE = 0; /*0 MB*/
/* Experiments show that the most time consuming part is the alignment, not
* file reading. The gain by reading all sequences in to memory is very little.
* so just use fseek and fread technique.
*
$ /data3/program/my_needle/my_needle -mode 1 -l t3.pair -seqdb pfamfullseq_uniq.fasta -o t3.txt -threshold-seqdb-size 0 -m 1
# Read Database Index with 1393148 records costs 4.51 seconds.
# Align 3000 pairs of sequences costs 9.04 seconds.
/data3/program/my_needle/my_needle -mode 1 -l t3.pair -seqdb pfamfullseq_uniq.fasta -o t3.1.txt -threshold-seqdb-size 1024 -m 1
# GetIDSeqMap of 1393148 sequences costs 7.49 seconds.
# Align 3000 pairs of sequences costs 8.95 seconds.
*/
struct AlignFactor/*{{{*/
{
float score;
float zScore;
float pozScore;
double eValue;
int idt_cnt;
float identity;
float identity_short;
int sim_cnt;
float similarity;
float similarity_short;
int gap_cnt;
float gapPercent;
};/*}}}*/
const char ALPHABET_BLOSUM[]="ARNDCQEGHILKMFPSTWYVBZX*";
const char ALPHABET_NUC[]="ATGCSWRYKMBVHDN";
const char ALPHABET_SHAG[]="AKRSUVTGHBC-";
int outformat = 0; /*set by the -m option
0: full pairwise alignment
1: full pairwise alignment in Fasta format, they are placed sequentially */
int pairlistmode=0;/*set by the -mode option
0: pairs are two filenames of sequences
1: pairs are two seqIDs of sequences
2: all-to-all alignment given a file with multiple sequences
*/
const int blosum62[][NUM_BLOSUM] =/*{{{*/
{ // substitution matrix for amino acid sequences
/* A R N D C Q E G H I L K M F P S T W Y V B Z X * */
{ 4, -1, -2, -2, 0, -1, -1, 0, -2, -1, -1, -1, -1, -2, -1, 1, 0, -3, -2, 0, -2, -1, 0, -4},
{ -1, 5, 0, -2, -3, 1, 0, -2, 0, -3, -2, 2, -1, -3, -2, -1, -1, -3, -2, -3, -1, 0, -1, -4},
{ -2, 0, 6, 1, -3, 0, 0, 0, 1, -3, -3, 0, -2, -3, -2, 1, 0, -4, -2, -3, 3, 0, -1, -4},
{ -2, -2, 1, 6, -3, 0, 2, -1, -1, -3, -4, -1, -3, -3, -1, 0, -1, -4, -3, -3, 4, 1, -1, -4},
{ 0, -3, -3, -3, 9, -3, -4, -3, -3, -1, -1, -3, -1, -2, -3, -1, -1, -2, -2, -1, -3, -3, -2, -4},
{ -1, 1, 0, 0, -3, 5, 2, -2, 0, -3, -2, 1, 0, -3, -1, 0, -1, -2, -1, -2, 0, 3, -1, -4},
{ -1, 0, 0, 2, -4, 2, 5, -2, 0, -3, -3, 1, -2, -3, -1, 0, -1, -3, -2, -2, 1, 4, -1, -4},
{ 0, -2, 0, -1, -3, -2, -2, 6, -2, -4, -4, -2, -3, -3, -2, 0, -2, -2, -3, -3, -1, -2, -1, -4},
{ -2, 0, 1, -1, -3, 0, 0, -2, 8, -3, -3, -1, -2, -1, -2, -1, -2, -2, 2, -3, 0, 0, -1, -4},
{ -1, -3, -3, -3, -1, -3, -3, -4, -3, 4, 2, -3, 1, 0, -3, -2, -1, -3, -1, 3, -3, -3, -1, -4},
{ -1, -2, -3, -4, -1, -2, -3, -4, -3, 2, 4, -2, 2, 0, -3, -2, -1, -2, -1, 1, -4, -3, -1, -4},
{ -1, 2, 0, -1, -3, 1, 1, -2, -1, -3, -2, 5, -1, -3, -1, 0, -1, -3, -2, -2, 0, 1, -1, -4},
{ -1, -1, -2, -3, -1, 0, -2, -3, -2, 1, 2, -1, 5, 0, -2, -1, -1, -1, -1, 1, -3, -1, -1, -4},
{ -2, -3, -3, -3, -2, -3, -3, -3, -1, 0, 0, -3, 0, 6, -4, -2, -2, 1, 3, -1, -3, -3, -1, -4},
{ -1, -2, -2, -1, -3, -1, -1, -2, -2, -3, -3, -1, -2, -4, 7, -1, -1, -4, -3, -2, -2, -1, -2, -4},
{ 1, -1, 1, 0, -1, 0, 0, 0, -1, -2, -2, 0, -1, -2, -1, 4, 1, -3, -2, -2, 0, 0, 0, -4},
{ 0, -1, 0, -1, -1, -1, -1, -2, -2, -1, -1, -1, -1, -2, -1, 1, 5, -2, -2, 0, -1, -1, 0, -4},
{ -3, -3, -4, -4, -2, -2, -3, -2, -2, -3, -2, -3, -1, 1, -4, -3, -2, 11, 2, -3, -4, -3, -2, -4},
{ -2, -2, -2, -3, -2, -1, -2, -3, 2, -1, -1, -2, -1, 3, -3, -2, -2, 2, 7, -1, -3, -2, -1, -4},
{ 0, -3, -3, -3, -1, -2, -2, -3, -3, 3, 1, -2, 1, -1, -2, -2, 0, -3, -1, 4, -3, -2, -1, -4},
{ -2, -1, 3, 4, -3, 0, 1, -1, 0, -3, -4, 0, -3, -3, -2, 0, -1, -4, -3, -3, 4, 1, -1, -4},
{ -1, 0, 0, 1, -3, 3, 4, -2, 0, -3, -3, 1, -1, -3, -1, 0, -1, -3, -2, -2, 1, 4, -1, -4},
{ 0, -1, -1, -1, -2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -2, 0, 0, -2, -1, -1, -1, -1, -1, -4},
{ -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, 1}
};
/*}}}*/
const int nuc44[][NUM_NUC] =/*{{{*/
{ // substitution matrix for DNA
//# This matrix was created by Todd Lowe 12/10/92
//# Uses ambiguous nucleotide codes, probabilities rounded to nearest integer
//# Lowest score = -4, Highest score = 5
//A T G C S W R Y K M B V H D N
{ 5, -4 , -4 , -4 , -4 , 1 , 1 , -4 , -4 , 1 , -4 , -1 , -1 , -1 , -2 },
{-4, 5 , -4 , -4 , -4 , 1 , -4 , 1 , 1 , -4 , -1 , -4 , -1 , -1 , -2 },
{-4, -4 , 5 , -4 , 1 , -4 , 1 , -4 , 1 , -4 , -1 , -1 , -4 , -1 , -2 },
{-4, -4 , -4 , 5 , 1 , -4 , -4 , 1 , -4 , 1 , -1 , -1 , -1 , -4 , -2 },
{-4, -4 , 1 , 1 , -1 , -4 , -2 , -2 , -2 , -2 , -1 , -1 , -3 , -3 , -1 },
{ 1, 1 , -4 , -4 , -4 , -1 , -2 , -2 , -2 , -2 , -3 , -3 , -1 , -1 , -1 },
{ 1, -4 , 1 , -4 , -2 , -2 , -1 , -4 , -2 , -2 , -3 , -1 , -3 , -1 , -1 },
{-4, 1 , -4 , 1 , -2 , -2 , -4 , -1 , -2 , -2 , -1 , -3 , -1 , -3 , -1 },
{-4, 1 , 1 , -4 , -2 , -2 , -2 , -2 , -1 , -4 , -1 , -3 , -3 , -1 , -1 },
{ 1, -4 , -4 , 1 , -2 , -2 , -2 , -2 , -4 , -1 , -3 , -1 , -1 , -3 , -1 },
{-4, -1 , -1 , -1 , -1 , -3 , -3 , -1 , -1 , -3 , -1 , -2 , -2 , -2 , -1 },
{-1, -4 , -1 , -1 , -1 , -3 , -1 , -3 , -3 , -1 , -2 , -1 , -2 , -2 , -1 },
{-1, -1 , -4 , -1 , -3 , -1 , -3 , -1 , -3 , -1 , -2 , -2 , -1 , -2 , -1 },
{-1, -1 , -1 , -4 , -3 , -1 , -1 , -3 , -1 , -3 , -2 , -2 , -2 , -1 , -1 },
{-2, -2 , -2 , -2 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 }
};/*}}}*/
const int shag6[][NUM_SHAG] =/*{{{*/
{ // substitution matrix for shape strings
//# substitution matrix in integer format, scale = 9
//# modified on 2007-03-18,
//# the score of A-K should be positive and U-V as well
//# in that case, manually modify
//# A-A = 3
//# A-K = 2
//# A-U/V = 1
//# K-U/V = 1
//# R-S = 1
//# R-U/V = 1
// A K R S U V T G H B C -
{ 3, 2,-4, -6, 1, 1, -2, -3, 2, -5, -3, -1, },
{ 2, 5,-1, -3, 1, 1, 0, 0, 1, -2, 1, 0, },
{-4,-1, 4, 1, 1, 1, -1, 0, -3, 2, 0, 0, },
{-6,-3, 1, 4, 1, 1, -3, 0, -6, 3, -1, -1, },
{ 1, 1, 1, 1, 9, 5, 1, 1, -2, 0, 4, 0, },
{ 1, 1, 1, 1, 5, 8, 1, 0, -2, 1, 4, 0, },
{-2, 0,-1, -3, 1, 1, 9, 2, -2, -2, 7, 0, },
{-3, 0, 0, 0, 1, 0, 2, 11, -2, 0, 6, 0, },
{ 2, 1,-3, -6, -2, -2, -2, -2, 2, -5, -2, -1, },
{-5,-2, 2, 3, 0, 1, -2, 0, -5, 3, -1, 0, },
{-3, 1, 0, -1, 4, 4, 7, 6, -2, -1, 6, 0, },
{-1, 0, 0, -1, 0, 0, 0, 0, -1, 0, 0, 0, }
};/*}}}*/
char alphabet[500] = "";
AjBool endweight = false;
bool show = false;
string matrixFile = "";
int sizeAlphabet = 0;
bool isPrintTraceMatrix = false;
bool noGapOpenArray = false;
int alnType = AA_SEQ;
char usage[]/*{{{*/="\n\
usage: my_needle [options] seqfile1 seqfile2\n\
\n\
Pairwise sequence alignment derived from the needle program in the EMBOSS package\n\
Gapopens can be supplied under the sequence and enclosed in { }\n\
\n\
Options:\n\
-list FILE Supply the pair list, one line a pair\n\
-mode INT Pair mode, (default: 0)\n\
0: pairs are two filenames of sequences\n\
1: pairs are two seqIDs of sequences\n\
2: do all-to-all pairwise alignment given a fasta file\n\
with multiple sequences\n\
-seqdb STR Indexed sequence database, this must be supplied when mode = 1\n\
-m INT Output alignment format, (default: 0)\n\
0: full pairwise alignment in EMBOSS needle format\n\
1: full pairwise alignment in Fasta format\n\
-table FILE Output tab delimited alignment info table to FILE\n\
-type INT Set the alignment type. (default: 1)\n\
0: for dna, \n\
1: for aaseq\n\
2: for shape strings\n\
-matrix FILE Supply substitution matrix file. default is\n\
NUC.4.4: for DNA alignment\n\
BLOSUM62: for amino acid alignment\n\
ShagMatrix6: for shape string alignment\n\
-title1 STR Force the title of the first seqfile\n\
-title2 STR Force the title of the second seqfile\n\
-G FLOAT Penalty to open a gap, (default: 10.0)\n\
-E FLOAT Penalty to extend a gap, default: 0.5)\n\
-o FILE Output the alignment to outfile, (default: stdout)\n\
-eg FLOAT Set endgapopen, (default: 10.0)\n\
-ee FLOAT Set endgapextend, (default: 0.5)\n\
-debug FILE Print the debug information to FILE\n\
-endweight Enable endweight, default= No\n\
-nogoarray Do not use the gapopen array even supplied\n\
-threshold-seqdb-size INT\n\
Threshold of seqdb file size in MB. (default: 1024)\n\
If seqdb filesize < threshold, the whole file will be read\n\
in to memory.\n\
-max-align-size INT\n\
Maximum align size in MB. (default: 1024)\n\
max_align_size = seqlength1 * seqlengh2\n\
-selpair INT Pair selection method for mode 2, (default: 1)\n\
0: sequentially \n\
1: randomly\n\
-wordsize INT Wordsize for Kmer comparison, (default: 3)\n\
-pkmer|-printkmerscore yes|no\n\
Whether print KMer score, (default: no)\n\
\n\
-h | --help Print this help message and exit\n\
\n\
Created on 2010-09-10, updated 2012-05-30, Nanjiang\n\
\n\
Examples:\n\
# align the first sequence in test1.fa to all sequences in the test2.fa\n\
my_needle test1.fa test2.fa\n\
\n\
# align a large number of pairs of sequences by supplying sequence db and\n\
# pairs of seqids\n\
my_needle -list pairlist.txt -mode 1 -seqdb seqdb -m 1 -o outfile.txt\n\
\n\
# all to all pairwise alignment given a file with multiple sequences\n\
my_needle t2.fa -mode 2 -m 1 -table table1.txt\n\
";
/*}}}*/
char explanation_table_format[]="\
# Seq1 Sequence 1 in alignment\n\
# Seq2 Sequence 2 in alignment\n\
# IDT0 numIDTRes / alnLength\n\
# SIM0 numSIMRes / alnLength\n\
# AlnLength length of the alignment\n\
# Len1 length of sequence 1 in the pair\n\
# Len2 length of sequence 2 in the pair\n\
# Score alignment score\n\
# N_IDT number of identical residues\n\
# N_SIM number of similar (including identical) residues\n\
# N_GAP number of gaps\n\
# IDT1 numIDTRes / min(len1, len2)\n\
# IDT2 numIDTRes / (alnLength - N_GAP)\n\
#\n";
void PrintHelp() {/*{{{*/
fprintf(stdout,"%s\n",usage);
} /*}}}*/
void PrintNeedleAlignmentHeader(string &programname,struct tm* timeinfo,string& outfile, int argc, char **argv,FILE *fpout)/*{{{*/
{
fprintf(fpout,"########################################\n");
fprintf(fpout,"# Program: %s\n", programname.c_str());
fprintf(fpout,"# Rundate: %s", asctime(timeinfo));
fprintf(fpout,"# Commandline: ");
for (int jj = 0; jj < argc; jj++) {
fprintf(fpout,"%s ", argv[jj]);
}
fprintf(fpout,"\n");
fprintf(fpout,"# Align_format: %s\n", "srspair");
fprintf(fpout,"# Report_file: %s\n", outfile.c_str());
fprintf(fpout,"########################################\n");
fprintf(fpout,"\n");
}/*}}}*/
bool IsFileExist(const char *name)/*{{{*/
{
struct stat st;
return (stat(name,&st) == 0);
}/*}}}*/
bool IsInCharSet(const char ch, const char *charSet, int n /*= 0 */)/*{{{*/
/*****************************************************************************
* check if the character "ch" is in charSet,
****************************************************************************/
{
if(n == 0) {
n = strlen(charSet);
}
int i;
for(i = 0 ;i < n ; i ++) {
if(ch == charSet[i]) {
return true;
}
}
return false;
}/*}}}*/
int GetFileSize(const char *name)/*{{{*/
{
struct stat st;
if (stat(name,&st) == 0){
return st.st_size;
}else{
cerr << "File "
<< name
<< " does not exist." << endl;
return -1;
}
}/*}}}*/
string int2string(int number)/*{{{*/
{
stringstream ss;//create a stringstream
ss << number;//add number to the stream
return ss.str();//return a string with the contents of the stream
}/*}}}*/
void InitAlignFactor(AlignFactor *pAlignFactor)/*{{{*/
{
pAlignFactor -> score = 0.0;
pAlignFactor -> zScore = 0.0;
pAlignFactor -> pozScore = 0.0;
pAlignFactor -> eValue = 0.0;
pAlignFactor -> idt_cnt = 0;
pAlignFactor -> identity = 0.0;
pAlignFactor -> identity_short = 0.0;
pAlignFactor -> sim_cnt = 0;
pAlignFactor -> similarity = 0.0;
pAlignFactor -> similarity_short = 0.0;
pAlignFactor -> gap_cnt = 0;
pAlignFactor -> gapPercent = 0.0;
}
/*}}}*/
bool IsAllGroupFilled(vector <int> &cntSeqIDTClass)/*{{{*/
{
for (int i = 0 ; i < numSeqIDTClass ; i ++) {
if (cntSeqIDTClass[i] < maxSeqIDTClass[i]){
return false;
}
}
return true;
}
/*}}}*/
int GetSeqIDTClass(float seqIdentity, float* binSeqIDTClass, int numSeqIDTClass){/*{{{*/
for (int i = 0; i < numSeqIDTClass; i++){
//printf("%g %.3g %g\n", binSeqIDTClass[i], seqIdentity, binSeqIDTClass[i+1]);
if (seqIdentity >= binSeqIDTClass[2*i] && seqIdentity < binSeqIDTClass[2*i+1]){
return i;
}
}
return numSeqIDTClass;
}/*}}}*/
float GetThresholdKMerScore(float minimalSeqIdentity){/*{{{*/
/*sequence pair with kMerBitScore < threshold_kmerScore are not likely to
* have sequence identity > minimalSeqIdentity*/
/*To be developed*/
if (KMerThresholdMode == HIGH_COVERAGE ){
if (minimalSeqIdentity >=95.0){
return -0.3;
} else if (minimalSeqIdentity>=90.0){
return -0.5;
} else if (minimalSeqIdentity>=80.0){
return -1.0;
}else if (minimalSeqIdentity>=70.0){
return -1.3;
}else if (minimalSeqIdentity>=60.0){
return -1.5;
}else if (minimalSeqIdentity>=50.0){
return -1.6;
}else if (minimalSeqIdentity>=40.0){
return -1.8;
}else if (minimalSeqIdentity>=30.0){
return -2.0;
} else if (minimalSeqIdentity>=20.0){
return -2.2;
}else if (minimalSeqIdentity>=10.0) {
return -2.25;
}else{
return -99999.0;
}
}else{/*high precision*/
if (minimalSeqIdentity >=95.0){
return -0.25;
} else if (minimalSeqIdentity>=90.0){
return -0.4;
} else if (minimalSeqIdentity>=80.0){
return -0.75;
}else if (minimalSeqIdentity>=70.0){
return -1.2;
}else if (minimalSeqIdentity>=60.0){
return -1.4;
}else if (minimalSeqIdentity>=50.0){
return -1.5;
}else if (minimalSeqIdentity>=40.0){
return -1.6;
}else if (minimalSeqIdentity>=30.0){
return -1.75;
} else if (minimalSeqIdentity>=20.0){
return -1.75;
}else if (minimalSeqIdentity>=10.0) {
return -1.8;
}else{
return -99999.0;
}
}
}/*}}}*/
float GetMinimalSeqIdentity(vector <int> &cntSeqIDTClass, int *maxSeqIDTClass, float* binSeqIDTClass, int numSeqIDTClass){/*{{{*/
for (int i = 0; i < numSeqIDTClass; i++){
if (cntSeqIDTClass[i] < maxSeqIDTClass[i]){
return binSeqIDTClass[2*i];
}
}
return binSeqIDTClass[(numSeqIDTClass-1)*2+1];
}/*}}}*/
struct cmp_str/*{{{*/
{
bool operator()(char const *a, char const *b)
{
return std::strcmp(a, b) < 0;
}
};/*}}}*/
int CountKMerOfSequence_c(const char* seq, map <char*, int, cmp_str> &wordCountMap, int wordsize){/*{{{*/
/*c style*/
int len = strlen(seq);
map <char*,int, cmp_str> :: iterator it;
int i = 0;
while (i < len - wordsize + 1 ){
char *substr=new char[wordsize+1];
strncpy(substr,seq+i,wordsize);
substr[wordsize]='\0';
it = wordCountMap.find(substr);
if (it == wordCountMap.end()){
wordCountMap.insert(pair<char*, int > (substr, 1));
}else {
it->second += 1;
delete [] substr;
}
i++;
}
return wordCountMap.size();
}/*}}}*/
float CalKMerVectorScore_norm_c(map <char*, int, cmp_str> &wordCountMap1, map <char*, int, cmp_str> &wordCountMap2){/*{{{*/
float bitScore = 0.0;
float numWord1 = (float)wordCountMap1.size();
float numWord2 = (float)wordCountMap2.size();
set <char*, cmp_str> unionKeys;
map <char*, int, cmp_str> :: iterator it;
map <char*, int, cmp_str> :: iterator it1;
map <char*, int, cmp_str> :: iterator it2;
for (it = wordCountMap1.begin(); it != wordCountMap1.end(); it++){
unionKeys.insert(it->first);
}
for (it = wordCountMap2.begin(); it != wordCountMap2.end(); it++){
unionKeys.insert(it->first);
}
set <char*, cmp_str> ::iterator iss;
for (iss = unionKeys.begin(); iss != unionKeys.end(); iss++){
it1 = wordCountMap1.find(*iss) ;
it2 = wordCountMap2.find(*iss) ;
if (it1 != wordCountMap1.end() && it2 != wordCountMap2.end()){
bitScore -= fabs(it1->second/numWord1 - it2->second/numWord2);
}else {
if (it1 != wordCountMap1.end()){
bitScore -= it1 -> second/numWord1;
}else{
bitScore -= it2 -> second/numWord2;
}
}
}
return bitScore;
}/*}}}*/
void PrintKMerVectorPair_c(map <char*, int, cmp_str> &wordCountMap1, map <char*, int, cmp_str>& wordCountMap2, const char* id1, const char* id2, FILE *fpout) {/*{{{*/
set <char*, cmp_str> unionKeys;
map <char*, int, cmp_str> :: iterator it;
for (it = wordCountMap1.begin(); it != wordCountMap1.end(); it++){
unionKeys.insert(it->first);
}
for (it = wordCountMap2.begin(); it != wordCountMap2.end(); it++){
unionKeys.insert(it->first);
}
set <char*, cmp_str> ::iterator iss;
fprintf(fpout, "\n%13s%10s%13s %d (%d - %d)\n", id1, "", id2, (int)unionKeys.size(), (int)wordCountMap1.size(), (int)wordCountMap2.size());
for (iss = unionKeys.begin(); iss != unionKeys.end(); iss++){
it = wordCountMap1.find(*iss) ;
if (it != wordCountMap1.end()){
fprintf(fpout,"%6s %6d", (*iss), it->second);
}else {
fprintf(fpout,"%6s %6s", (*iss), "NULL");
}
fprintf(fpout, "%10s","");
it = wordCountMap2.find(*iss) ;
if (it != wordCountMap2.end()){
fprintf(fpout,"%6s %6d", (*iss), it -> second);
}else {
fprintf(fpout,"%6s %6s", (*iss), "NULL");
}
fprintf(fpout,"\n");
}
}/*}}}*/
void FreeMem_WrodMap_c(map <char*, int, cmp_str> &wordCountMap){/*{{{*/
map <char*, int> :: iterator it;
for (it = wordCountMap.begin(); it != wordCountMap.end(); it++){
delete [] it->first;
}
}/*}}}*/
float KMerVectorPairwiseComparison_c(string& seq1, string& seq2, string& seqID1, string& seqID2, int wordsize, FILE *fpLog){/*{{{*/
/*c style*/
map <char*, int, cmp_str> wordCountMap1;
map <char*, int, cmp_str> wordCountMap2;
CountKMerOfSequence_c(seq1.c_str(), wordCountMap1, wordsize);
CountKMerOfSequence_c(seq2.c_str(), wordCountMap2, wordsize);
#ifdef DEBUG_KMER
PrintKMerVectorPair_c(wordCountMap1, wordCountMap2, seqID1.c_str(), seqID2.c_str(), stdout);
#endif
float bitScore = CalKMerVectorScore_norm_c(wordCountMap1, wordCountMap2);
FreeMem_WrodMap_c(wordCountMap1);
FreeMem_WrodMap_c(wordCountMap2);
return bitScore;
}/*}}}*/
int CountKMerOfSequence(string &seq, map <string, int> &wordCountMap, int wordsize){/*{{{*/
int len = seq.size();
map <string,int> :: iterator it;
string substr;
for (int i=0;i < len-wordsize+1; i ++){
substr = seq.substr(i,wordsize);
it = wordCountMap.find(substr);
if (it == wordCountMap.end()){
wordCountMap.insert(pair<string, int> (substr, 1));
}else {
it->second += 1;
}
}
return wordCountMap.size();
}/*}}}*/
void PrintKMerVectorPair(map <string, int> &wordCountMap1, map <string, int>& wordCountMap2, string &id1, string&id2, FILE *fpout) {/*{{{*/
set <string> unionKeys;
map <string, int> :: iterator it;
for (it = wordCountMap1.begin(); it != wordCountMap1.end(); it++){
unionKeys.insert(it->first);
}
for (it = wordCountMap2.begin(); it != wordCountMap2.end(); it++){
unionKeys.insert(it->first);
}
set <string> ::iterator iss;
fprintf(fpout, "\n%13s%10s%13s %d (%d - %d)\n", id1.c_str(), "", id2.c_str(), (int)unionKeys.size(), (int)wordCountMap1.size(), (int)wordCountMap2.size());
for (iss = unionKeys.begin(); iss != unionKeys.end(); iss++){
it = wordCountMap1.find(*iss) ;
if (it != wordCountMap1.end()){
fprintf(fpout,"%6s %6d", (*iss).c_str(), it->second);
}else {
fprintf(fpout,"%6s %6s", (*iss).c_str(), "NULL");
}
fprintf(fpout, "%10s","");
it = wordCountMap2.find(*iss) ;
if (it != wordCountMap2.end()){
fprintf(fpout,"%6s %6d", (*iss).c_str(), it -> second);
}else {
fprintf(fpout,"%6s %6s", (*iss).c_str(), "NULL");
}
fprintf(fpout,"\n");
}
}/*}}}*/
float CalKMerVectorScore_old1(map <string, int> &wordCountMap1, map <string, int> &wordCountMap2){/*{{{*/
float bitScore = 0.0;
set <string> unionKeys;
map <string, int> :: iterator it;
map <string, int> :: iterator it1;
map <string, int> :: iterator it2;
for (it = wordCountMap1.begin(); it != wordCountMap1.end(); it++){
unionKeys.insert(it->first);
}
for (it = wordCountMap2.begin(); it != wordCountMap2.end(); it++){
unionKeys.insert(it->first);
}
set <string> ::iterator iss;
for (iss = unionKeys.begin(); iss != unionKeys.end(); iss++){
it1 = wordCountMap1.find(*iss) ;
it2 = wordCountMap2.find(*iss) ;
if (it1 != wordCountMap1.end() && it2 != wordCountMap2.end()){
bitScore += min(it1->second, it2->second);
}else {
if (it1 != wordCountMap1.end()){
bitScore -= it1 -> second;
}else{
bitScore -= it2 -> second;
}
}
}
return bitScore;
}/*}}}*/
float CalKMerVectorScore(map <string, int> &wordCountMap1, map <string, int> &wordCountMap2){/*{{{*/
float bitScore = 0.0;
set <string> unionKeys;
map <string, int> :: iterator it;
map <string, int> :: iterator it1;
map <string, int> :: iterator it2;
for (it = wordCountMap1.begin(); it != wordCountMap1.end(); it++){
unionKeys.insert(it->first);
}
for (it = wordCountMap2.begin(); it != wordCountMap2.end(); it++){
unionKeys.insert(it->first);
}
set <string> ::iterator iss;
for (iss = unionKeys.begin(); iss != unionKeys.end(); iss++){
it1 = wordCountMap1.find(*iss) ;
it2 = wordCountMap2.find(*iss) ;
if (it1 != wordCountMap1.end() && it2 != wordCountMap2.end()){
bitScore -= abs(it1->second - it2->second);
}else {
if (it1 != wordCountMap1.end()){
bitScore -= it1 -> second;
}else{
bitScore -= it2 -> second;
}
}
}
return bitScore;
}/*}}}*/
float CalKMerVectorScore_norm(map <string, int> &wordCountMap1, map <string, int> &wordCountMap2){/*{{{*/
float bitScore = 0.0;
float numWord1 = (float)wordCountMap1.size();
float numWord2 = (float)wordCountMap2.size();
set <string> unionKeys;
map <string, int> :: iterator it;
map <string, int> :: iterator it1;
map <string, int> :: iterator it2;
for (it = wordCountMap1.begin(); it != wordCountMap1.end(); it++){
unionKeys.insert(it->first);
}
for (it = wordCountMap2.begin(); it != wordCountMap2.end(); it++){
unionKeys.insert(it->first);
}
set <string> ::iterator iss;
for (iss = unionKeys.begin(); iss != unionKeys.end(); iss++){
it1 = wordCountMap1.find(*iss) ;
it2 = wordCountMap2.find(*iss) ;
if (it1 != wordCountMap1.end() && it2 != wordCountMap2.end()){
bitScore -= fabs(it1->second/numWord1 - it2->second/numWord2);
}else {
if (it1 != wordCountMap1.end()){
bitScore -= it1 -> second/numWord1;
}else{
bitScore -= it2 -> second/numWord2;
}
}
}
return bitScore;
}/*}}}*/
float KMerVectorPairwiseComparison(string& seq1, string& seq2, string& seqID1, string& seqID2, int wordsize, FILE *fpLog){/*{{{*/
map <string, int> wordCountMap1;
map <string, int> wordCountMap2;
CountKMerOfSequence(seq1, wordCountMap1, wordsize);
CountKMerOfSequence(seq2, wordCountMap2, wordsize);
#ifdef DEBUG_KMER
PrintKMerVectorPair(wordCountMap1, wordCountMap2, seqID1, seqID2, stdout);
#endif
//return 0.0;
//float bitScore = CalKMerVectorScore(wordCountMap1, wordCountMap2);
float bitScore = CalKMerVectorScore_norm(wordCountMap1, wordCountMap2);
//bitScore = bitScore*(max(len1,len2)/(min(len1,len2) + 1e-9));
return bitScore;
}/*}}}*/
void PrintKMerVectorPair_table(int* freqTable1, int* freqTable2, vector<int>& indexWordHit1, vector <int> & indexWordHit2, string& id1, string& id2, FILE *fpout) {/*{{{*/
set <int> unionKeys;
unionKeys.insert(indexWordHit1.begin(),indexWordHit1.end());
unionKeys.insert(indexWordHit2.begin(),indexWordHit2.end());
set <int> ::iterator it;
fprintf(fpout, "\n%13s%10s%13s %d (%d - %d)\n", id1.c_str(), "", id2.c_str(), (int)unionKeys.size(), (int)indexWordHit1.size(), (int)indexWordHit2.size());
}/*}}}*/
int CountKMerOfSequence_table(const char*seq, int len, int* freqTable, set <int>&indexWordHit, int wordsize){/*{{{*/
set <int> ::iterator it;
for (int i= 0; i < len - wordsize + 1 ; i++){
int idx = 0;
for (int j = 0; j < wordsize; j++){
idx += *(aacode+seq[i+j]) * para20[wordsize-j-1];
}
it = indexWordHit.find(idx);
if (it == indexWordHit.end()){
indexWordHit.insert(idx);
freqTable[idx] = 1;
}else{
freqTable[idx] ++;
}
}
return indexWordHit.size();
}/*}}}*/
int CountKMerOfSequence_table_2(const char*seq, int len, int *freqTable, vector <int>&indexWordHit, int wordsize){/*{{{*/
int numTotalWord = len-wordsize +1; /*number of words with duplicates*/
int *idxList = new int [numTotalWord];
for (int i= 0; i < numTotalWord ; i++){
int idx = 0;
for (int j = 0; j < wordsize; j++){
idx += *(aacode+seq[i+j]) * para20[wordsize-j-1];
}
idxList[i] = idx;
freqTable[idx] = 0;
}
for (int i= 0; i < numTotalWord ; i++){
freqTable[idxList[i]] ++;
}
vector <int> newlist(idxList, idxList+numTotalWord);
vector <int> :: iterator it;
sort (newlist.begin(),newlist.end());
it = unique(newlist.begin(),newlist.end());
newlist.resize(it - newlist.begin());/*this must be added to actually get a uniq list*/
indexWordHit = newlist;
//indexWordHit.insert(idxList, idxList+numTotalWord); [>this takes 90% of time for this function<]
delete [] idxList;
return indexWordHit.size();
}/*}}}*/
float CalKMerVectorScore_norm_table(int * freqTable1, int* freqTable2, set <int> indexWordHit1, set <int> indexWordHit2){/*{{{*/
float bitScore = 0.0;
float numWord1 = (float)indexWordHit1.size();
float numWord2 = (float)indexWordHit2.size();
set <int> index_intersection;
set <int> index_1_minus_2;
set <int> index_2_minus_1;
set_intersection(indexWordHit1.begin(), indexWordHit1.end(),
indexWordHit2.begin(),indexWordHit2.end(),
inserter(index_intersection,index_intersection.begin()));
set_difference(indexWordHit1.begin(), indexWordHit1.end(),
indexWordHit2.begin(),indexWordHit2.end(),
inserter(index_1_minus_2, index_1_minus_2.begin()));
set_difference(indexWordHit2.begin(), indexWordHit2.end(),
indexWordHit1.begin(),indexWordHit1.end(),
inserter(index_2_minus_1, index_2_minus_1.begin()));
set <int> ::iterator it;
for (it = index_intersection.begin(); it != index_intersection.end(); it++){
bitScore -= fabs(freqTable1[*it]/numWord1 - freqTable2[*it]/numWord2);
}
for (it = index_1_minus_2.begin(); it != index_1_minus_2.end(); it++){
bitScore -= fabs(freqTable1[*it]/numWord1);
}
for (it = index_2_minus_1.begin(); it != index_2_minus_1.end(); it++){
bitScore -= fabs(freqTable2[*it]/numWord2);
}
return bitScore;
}/*}}}*/
float CalKMerVectorScore_norm_table_2(int * freqTable1, int* freqTable2, vector <int> indexWordHit1, vector <int> indexWordHit2){/*{{{*/
float bitScore = 0.0;
float numWord1 = (float)indexWordHit1.size();
float numWord2 = (float)indexWordHit2.size();
vector <int> index_intersection;
vector <int> index_1_minus_2;
vector <int> index_2_minus_1;
set_intersection(indexWordHit1.begin(), indexWordHit1.end(),
indexWordHit2.begin(),indexWordHit2.end(),
inserter(index_intersection,index_intersection.begin()));
set_difference(indexWordHit1.begin(), indexWordHit1.end(),
indexWordHit2.begin(),indexWordHit2.end(),
inserter(index_1_minus_2, index_1_minus_2.begin()));
set_difference(indexWordHit2.begin(), indexWordHit2.end(),
indexWordHit1.begin(),indexWordHit1.end(),
inserter(index_2_minus_1, index_2_minus_1.begin()));
#ifdef DEBUG_SET_OPT/*{{{*/
fprintf(stdout,"vector1(%d):\n", int(numWord1));
for (int i = 0; i < int(numWord1); i++){
fprintf(stdout,"%3d ", indexWordHit1[i]);
}
fprintf(stdout,"\n");
fprintf(stdout,"vector2(%d):\n", int(numWord2));
for (int i = 0; i < int(numWord2); i++){
fprintf(stdout,"%3d ", indexWordHit2[i]);
}
fprintf(stdout,"\n");
fprintf(stdout,"vector intersection(%d):\n", int(index_intersection.size()));
for (int i = 0; i < index_intersection.size(); i++){
fprintf(stdout,"%3d ", (index_intersection.begin())[i]);
}
fprintf(stdout,"\n");
fprintf(stdout,"vector diff 1(%d):\n", int(index_1_minus_2.size()));
for (int i = 0; i < index_1_minus_2.size(); i++){
fprintf(stdout,"%3d ", (index_1_minus_2.begin())[i]);
}
fprintf(stdout,"\n");
#endif /*}}}*/
vector <int> ::iterator it;
for (it = index_intersection.begin(); it != index_intersection.end(); it++){
bitScore -= fabs(freqTable1[*it]/numWord1 - freqTable2[*it]/numWord2);
}
for (it = index_1_minus_2.begin(); it != index_1_minus_2.end(); it++){
bitScore -= (freqTable1[*it]/numWord1);
}
for (it = index_2_minus_1.begin(); it != index_2_minus_1.end(); it++){
bitScore -= (freqTable2[*it]/numWord2);
}
return bitScore;
}/*}}}*/
float KMerVectorPairwiseComparison_table(string& seq1, string& seq2, string& seqID1, string& seqID2, int* freqTable1, int *freqTable2, int sizeTable, int wordsize, FILE *fpLog){/*{{{*/
/*keep a table*/
int len1 = seq1.size();
int len2 = seq2.size();
vector <int> indexWordHit1;
vector <int> indexWordHit2;
CountKMerOfSequence_table_2(seq1.c_str(), len1, freqTable1, indexWordHit1, wordsize);
CountKMerOfSequence_table_2(seq2.c_str(), len2, freqTable2, indexWordHit2, wordsize);
#ifdef DEBUG_KMER
PrintKMerVectorPair_table(freqTable1,freqTable2, indexWordHit1,indexWordHit2, seqID1, seqID2, stdout);
#endif
//return 0.0;
float bitScore ;
//float bitScore = CalKMerVectorScore_norm_table(freqTable1, freqTable2, indexWordHit1, indexWordHit2);
bitScore = CalKMerVectorScore_norm_table_2(freqTable1, freqTable2, indexWordHit1, indexWordHit2);
//bitScore = bitScore*(max(len1,len2))/1000;
return bitScore;
}/*}}}*/
int ReadInPairList(const char* file, vector <Pair>&pairList)/*{{{*/
{
ifstream ifp (file, ios::binary);
if (ifp.is_open()){
ifp.seekg (0, ios::end);
int length = ifp.tellg();
ifp.seekg (0, ios::beg);
char *buffer = new char [ length+1];
ifp.read(buffer,length);
ifp.close();
buffer[length] = '\0';
char *pch;
pch = strtok(buffer, "\n");
Pair tmppair;