-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalnSeq.c
executable file
·2809 lines (2394 loc) · 82.4 KB
/
alnSeq.c
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
/*#########################################################
# Name: alignSeq
# Use:
# - Runs a Needlman Wunsch or Smith Waterman alignment on
# a pair of fasta files
# Includes:
# - "hirschberg/hirschberg.h"
# - "hirschberg/hirschbergNoGap.h"
# o "hirschberg/genScoreHirsch.h"
# o "hirschberg/genScoreNoGapHirsc.h"
# o "hirschberg/genHirsch.h"
#
# - "needleman/needleman.h"
# - "needleman/needleNoGap.h"
# - "needleman/needleTwoBit.h"
# - "needleman/needleTwoBitNoGap.h"
# o "needleman/genNeedle.h"
# o "needleman/genNeedleNoGap.h"
#
# - "waterman/waterman.h"
# - "waterman/waterNoGap.h"
# - "waterman/waterTwoBit.h"
# - "waterman/waterTwoBitNoGap.h"
# o "waterman/genWater.h"
# o "waterman/genWaterNoGap.h"
#
# - "waterman/waterScan.h"
# - "waterman/waterScanNoGap.h"
# - "waterman/waterScanTwoBit.h"
# - "waterman/waterScanTwoBitNoGap.h"
# o "waterman/genWaterScan.h"
# o "waterman/genWaterScanNoGap.h"
#
# - "memWater/memWater.h"
# - "memWater/memWaterNoGap.h"
#
# - "memWater/memWaterScan.h"
# - "memWater/memWaterScanNoGap.h"
#
# - "general/sortAndFiltAltAlns.h"
# o "general/alnMatrixStruct.h"
# o "general/alnSeqDefaults.h"
# o "general/alnSetStruct.h"
# o "general/alnStruct.h"
# o "general/base10StrToNum.h"
# o "general/dataTypeShortHand.h"
# o "general/genAln.h"
# o "general/genScan.h"
# o "general/seqStruct.h"
# o "general/twoBitArrays.h"
# o "general/genMath.h"
# C standard libraries:
# o <string.h>
# o <stdlib.h>
# o <stdio.h>
# o <stdint.h>
#########################################################*/
#include "hirschberg/hirschberg.h"
#include "hirschberg/hirschbergNoGap.h"
#include "memWater/memWater.h"
#include "memWater/memWaterNoGap.h"
#include "memWater/memWaterScan.h"
#include "memWater/memWaterScanNoGap.h"
#include "waterman/waterman.h"
#include "waterman/watermanNoGap.h"
#include "waterman/waterTwoBit.h"
#include "waterman/waterTwoBitNoGap.h"
#include "waterman/waterScan.h"
#include "waterman/waterScanNoGap.h"
#include "waterman/waterScanTwoBit.h"
#include "waterman/waterScanTwoBitNoGap.h"
#include "needleman/needleman.h"
#include "needleman/needleNoGap.h"
#include "needleman/needleTwoBit.h"
#include "needleman/needleTwoBitNoGap.h"
#include "general/sortAndFiltAltAlns.h"
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\
' SOP: Start Of Program
' - main: Run this program
' o fun-01 checkInput:
' o Gets user input
' o fun-02 printHelpMesg:
' - Prints the help message for alnSeq
' o fun-03 printCompilerSettings:
' - Prints out the compiler flags used
' - Prints out what each possible compiler flag does
\~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
/*-------------------------------------------------------\
| Fun-01: checkInput
| - Gets user input and lets program now if something
| was incorrect.
| Input:
| - lenArgsInt:
| o Number of arguments the user input
| - argsCStr:
| o Array of c-strings with the users input arguments
| - refFileCStr:
| o Pointer to c-string to hold the name of the fasta
| file with the reference sequence
| - qryFileCStr:
| o Pointer to c-string to hold the name of the fasta
| file with the query sequence
| - outFileStr:
| o Pointer to c-string to hold the name of the file to
| output the main alignment to
| - altAlnFileStr:
| o Pointer to c-string to hold the name of the file to
| output the alternative alignments to
| - refStartAlnUL
| o Pointer to unsigned long to hold the first position
| to align on the reference sequence
| - refEndAlnUL
| o Pointer to unsigned long to hold the last position
| to align on the reference sequence
| - qryStartAlnUL
| o Pointer to unsigned long to hold the first position
| to align on the query sequence
| - qryEndAlnUL
| o Pointer to unsigned long to hold the last position
| to align on the query sequence
| - scoreMtrxFileStr:
| o Pointer to hold the file name of the input score
| matrix (socre matrix is read into settings by
| checkInput)
| - matchMtrxFileStr:
| o Pointer to hold the file name of the input match
| matrix (the match matrix is read into settings by
| checkInput)
| - settings:
| o Pointer to alnSet structure to hold the users
| input settings for the alignment
| Output:
| - Modifies:
| o Each input variable to hold the specified user
| input
| - Returns:
| o 0: If no errors
| o Pointer to parameter that was an issue
| o Pointer to "-score-matrix" for invalid scoring
| matrix input
| - Prints to stdout when the scoring file is invalid
\-------------------------------------------------------*/
char * checkInput(
int *lenArgsInt, /*Number arguments user input*/
char *argsCStr[], /*Array with user arguments*/
char **refFileCStr, /*file name of reference file*/
char **queryFileCStr,/*File name of the query file*/
char **outFileStr, /*Name of the output file*/
char **altAlnFileStr, /*file: alternative alignments*/
ulong *refStartAlnUL, /*Start of reference alignment*/
ulong *refEndAlnUL, /*End of reference alignment*/
ulong *qryStartAlnUL, /*Start of query alignment*/
ulong *qryEndAlnUL, /*End of query alignment*/
char **scoreMtrxFileStr,/*Holds scoring matrix file*/
char **matchMtrxFileStr,/*Holds matching matrix file*/
struct alnSet *settings /*Aligment settings*/
); /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\
' Fun-01 TOC: checkInput
' - Checks & extracts user input
' o fun-01 sec-01:
' - Variable declerations
' o fun-01 sec-02:
' - Look through user input
\~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
/*-------------------------------------------------------\
| Fun-02: printHelpMesg
| - Prints the help message for alnSeq
| Input:
| - outFILE:
| o File to print the help message to
| - breifBl:
| o 1: Print the short help message
| o 0: Print the entire help message
| Output:
| - Prints:
| o help message to outFILE.
\-------------------------------------------------------*/
void printHelpMesg(
FILE *outFILE,
char breifBl /*Print a shorter help message*/
); /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\
' Fun-02 TOC: printHelpMesg
' - Prints out the help message to outFILE
' o fun-02 sec-01:
' - Usage block
' o fun-02 sec-02:
' - Input block
' o fun-02 sec-03:
' - Output block
\~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
/*-------------------------------------------------------\
| Fun-03: printCompilerSettings
| - Prints out the compiler flags used
| - Prints out what each possible compiler flag does
| Input:
| - outFILE:
| o File to print flags and flag descriptions to
| - pDescBl:
| o 1: print out descriptions for each flag (all)
| o 0: Do not print out any flag descriptions
| Output:
| - Prints flags and description to outFILE
\-------------------------------------------------------*/
void printCompileSettings(
FILE *outFILE, /*Output file*/
char pDescBl /*not 0: print out flag descriptions*/
); /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\
' Fun-03 TOC:
' - Print out compile flags used and what each
' compiler flag does.
' o fun-03 sec-01:
' - Print out the compiled settings
' o fun-03 sec-02:
' - Print out what each compiler flag does
\~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
int main(
int lenArgsInt,
char *argsCStr[]
){ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\
' Main TOC:
' - Main function that drives the Smith Waterman or
' Needlman Wunsch alignment
' o main sec-01:
' - Variable declerations
' o main sec-02:
' - Read in user input and check input
' o main sec-03:
' - read in the reference sequence
' o main sec-04:
' - read in the query sequence
' o main sec-05:
' - Do the alingment
' o main sec-06:
' - Print out multi-alignments or find the single
' alignment array
' o main sec-07:
' - Print out the alignment
\~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
/*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\
^ Main Sec-01:
^ - Variable declerations
\<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
/*User input*/
char *refFileCStr = 0;
char *queryFileCStr = 0;
char *outFileStr = 0;
char *altAlnFileStr = 0;
char *inputCStr = 0;
char *scoreMtrxFileStr = 0;
char *matchMtrxFileStr = 0;
/*Holds the reference and query sequence*/
struct seqStruct refST;
struct seqStruct queryST;
/*Caputures error type from functions*/
uchar errUC = 0;
long bestScoreL = 0;
ulong iterUL = 0;
/*Will hold the users settings*/
struct alnSet settings;
/*For holding alignment output*/
struct alnMatrix *alnMtrxST = 0;
struct alnMatrixTwoBit *alnMtrxTwoBitST = 0;
struct alnStruct *alnST = 0;
FILE *faFILE = 0;
FILE *outFILE = 0;
FILE *altAlnFILE = 0;
/*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\
^ Main Sec-02:
^ - initalize variables, get user input, & check input
^ o main sec-02 sub-01:
^ - initialize variables and get user input
^ o main sec-02 sub-02:
^ - Check user input for errors
^ o main sec-02 sub-03:
^ - Check if the main output file exists/was input
^ o main sec-02 sub-04:
^ - Check if file input for alternative alignments
\<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
/*****************************************************\
* Main Sec-02 Sub-01:
* - Initialize variables and Get user input
\*****************************************************/
initSeqST(&refST);
initSeqST(&queryST);
initAlnSet(&settings);
inputCStr =
checkInput(
&lenArgsInt,
argsCStr,
&refFileCStr,
&queryFileCStr,
&outFileStr,
&altAlnFileStr, /*TODO: ADD IN SETTING*/
&(refST.offsetUL), /*TODO: ADD IN CALL*/
&(refST.endAlnUL),
&(queryST.offsetUL),
&(queryST.endAlnUL),
&scoreMtrxFileStr,
&matchMtrxFileStr,
&settings
); /*Get user input*/
/*****************************************************\
* Main Sec-02 Sub-02:
* - Check user input for errors
\*****************************************************/
if(inputCStr != 0)
{ /*If had problematic input*/
if(strcmp(inputCStr, "-h") == 0 ||
strcmp(inputCStr, "--h") == 0 ||
strcmp(inputCStr, "-help") == 0 ||
strcmp(inputCStr, "--help") == 0 ||
strcmp(inputCStr, "help") == 0
) { /*If user wanted the help message*/
printHelpMesg(stdout, 1);/*Breif help messag*/
exit(0);
} /*If user wanted the help message*/
if(strcmp(inputCStr, "-h-all") == 0 ||
strcmp(inputCStr, "--h-all") == 0 ||
strcmp(inputCStr, "-help-all") == 0 ||
strcmp(inputCStr, "--help-all") == 0 ||
strcmp(inputCStr, "help-all") == 0
) { /*If user wanted the help message*/
printHelpMesg(stdout, 0); /*full help messag*/
exit(0);
} /*If user wanted the help message*/
if(strcmp(inputCStr, "-V") == 0 ||
strcmp(inputCStr, "-v") == 0 ||
strcmp(inputCStr, "--V") == 0 ||
strcmp(inputCStr, "--v") == 0 ||
strcmp(inputCStr, "--version") == 0 ||
strcmp(inputCStr, "--Version") == 0 ||
strcmp(inputCStr, "-version") == 0 ||
strcmp(inputCStr, "-Version") == 0 ||
strcmp(inputCStr, "Version") == 0 ||
strcmp(inputCStr, "version") == 0
) { /*if the user wanted the version number*/
fprintf(
stdout,
"alnSeq version: %u\n",
defVersion
); /*Print out closest thing to a version*/
exit(0);
} /*Else if the user wanted the version number*/
else if(strcmp(inputCStr, "-flags") == 0)
{ /*If user wanted to print the compiler flags*/
printCompileSettings(stdout, 1);
exit(0);
} /*If user wanted to print the compiler flags*/
/*Just the flags (no descriptions)*/
else if(strcmp(inputCStr, "-flags-only") == 0)
{ /*If user wanted to print the compiler flags*/
fprintf(
stdout,
"alnSeq version: %u\n",
defVersion
); /*user will likely want version number*/
printCompileSettings(stdout, 0);
exit(0);
} /*If user wanted to print the compiler flags*/
/*If file with scoring matrix was invalid*/
else if(strcmp(inputCStr, "-score-matrix") == 0)
exit(1);
else if(strcmp(inputCStr, "-match-matrix") == 0)
exit(1);
else if(inputCStr != 0)
{ /*If user had invalid input*/
printHelpMesg(stderr, 1); /*short help*/
fprintf(stderr, "%s is invalid\n", inputCStr);
exit(1); /*Let user know their was an error*/
} /*If user had invalid input*/
} /*If had problematic input*/;
/*****************************************************\
* Main Sec-02 Sub-03:
* - Check if the main output file exists/was input
\*****************************************************/
if(outFileStr != 0)
{ /*If printing output to a file*/
outFILE = fopen(outFileStr, "w");
if(outFILE == 0)
{ /*If an invalid output file*/
printf(
"Output (-out %s) file is invalid.\n",
outFileStr
); /*Let user know about the invalid file*/
exit(-1);
} /*If an invalid output file*/
fclose(outFILE);
outFILE = 0;
} /*If printing output to a file*/
/*****************************************************\
* Main Sec-02 Sub-04:
* - Check if file was input for alternative alignments
\*****************************************************/
if(altAlnFileStr != 0)
{ /*If: I have a file for alternative alignments*/
altAlnFILE = fopen(altAlnFileStr, "w");
if(altAlnFILE == 0)
{ /*If an invalid output file*/
printf(
"Output (-out-alt %s) file is invalid.\n",
altAlnFileStr
); /*Let user know about the invalid file*/
exit(-1);
} /*If an invalid output file*/
fclose(altAlnFILE);
altAlnFILE = 0;
} /*If: I have a file for alternative alignments*/
/*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\
^ Main Sec-3:
^ - read in the reference sequence
\<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
faFILE = fopen(refFileCStr, "r");
if(faFILE == 0)
{ /*If: reference file could not be opened*/
fprintf(
stderr,
"Reference (-ref %s) could not be opend\n",
refFileCStr
);
exit(-1);
} /*If: reference file could not be opened*/
/*Read in the reference sequence*/
errUC = readFaSeq(faFILE, &refST);
fclose(faFILE);
faFILE = 0;
if(errUC & 2)
{ /*If: I had an Invalid fasta file*/
freeSeqSTStack(&refST);
fprintf(
stderr,
"Reference (-ref %s) is not valid\n",
refFileCStr
);
exit(-1);
} /*If: I had an Invalid fasta file*/
if(errUC & 64)
{ /*If: I had a memory error*/
freeSeqSTStack(&refST);
fprintf(stderr, "Memory allocation error\n");
exit(-1);
} /*If: I had a memory error*/
/*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\
^ Main Sec-04:
^ - read in the query sequence
\<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
faFILE = fopen(queryFileCStr, "r");
if(faFILE == 0)
{ /*If: reference file could not be opened*/
freeSeqSTStack(&refST);
fprintf(
stderr,
"Query (-query %s) could not be opend\n",
queryFileCStr
);
exit(-1);
} /*If: reference file could not be opened*/
/*Read in the query sequence*/
errUC = readFaSeq(faFILE, &queryST);
fclose(faFILE);
faFILE = 0;
if(errUC & 2)
{ /*If: I had an Invalid fasta file*/
freeSeqSTStack(&refST);
freeSeqSTStack(&queryST);
fprintf(
stderr,
"Query (-query %s) is not valid\n",
refFileCStr
);
exit(-1);
} /*If: I had an Invalid fasta file*/
if(errUC & 64)
{ /*If: I had a memory error*/
freeSeqSTStack(&refST);
freeSeqSTStack(&queryST);
fprintf(stderr, "Memory allocation error\n");
exit(-1);
} /*If: I had a memory error*/
/*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\
^ Main Sec-05:
^ - Do the alingment
^ o main sec-05 sub-01:
^ - Set up for the alignment
^ o main sec-05 sub-02:
^ - Open the output files
^ o main sec-05 sub-03:
^ - Check if doing a Needleman alignment
^ o main sec-05 sub-04:
^ - Check if doing an Waterman alignment
^ o main sec-05 sub-05:
^ - Check if doing an query reference scan Waterman
^ o main sec-05 sub-06:
^ - Check if doing an memory efficent Waterman
^ alignment that prints out alternative alignment
^ positions (Gets combined with a Hirschberg)
^ o main sec-05 sub-07:
^ - Check if doing an memory efficent Waterman
^ alignment that prints out a single alignment
^ (uses a Hirschberg to get the alignment)
^ o main sec-05 sub-08:
^ - Check if doing an Hirschberg alignment
^ o main sec-05 sub-09:
^ - Let user know this was an invalid alignment
^ o main sec-05 sub-10:
^ - Check if the alignment failed
\<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
/******************************************************\
* Main Sec-05 Sub-01:
* - Set up for the alignment
\******************************************************/
seqToLookupIndex(refST.seqCStr);
seqToLookupIndex(queryST.seqCStr);
if(refST.endAlnUL == 0)
refST.endAlnUL = refST.lenSeqUL - 1;
if(queryST.endAlnUL == 0)
queryST.endAlnUL = queryST.lenSeqUL - 1;
/*****************************************************\
* Main Sec-05 Sub-02:
* - Open the output files
\*****************************************************/
if(outFileStr != 0)
{ /*If: The user input an alternative alignment file*/
if(strcmp("-", outFileStr) == 0)
outFILE = stdout;
else outFILE = fopen(outFileStr, "w");
} /*If: The user input an alternative alignment file*/
else
{ /*Else putting output to stdout*/
outFILE = stdout;
outFileStr = "out";
} /*Else putting output to stdout*/
if(altAlnFileStr != 0)
{ /*If: The user input an alternative alignment file*/
if(strcmp("-", altAlnFileStr) == 0)
altAlnFILE = stdout;
else altAlnFILE = fopen(altAlnFileStr, "w");
} /*If: The user input an alternative alignment file*/
else altAlnFILE = outFILE;
/******************************************************\
* Main Sec-05 Sub-03:
* - Check if doing an Needleman alignment
\******************************************************/
if(settings.useNeedleBl)
{ /*If: I am doing a Needleman alignment*/
if(settings.noGapBl)
alnMtrxST =
NeedleAlnNoGap(&queryST, &refST, &settings);
else if(settings.twoBitBl && settings.noGapBl)
alnMtrxTwoBitST =
NeedleTwoBitNoGap(&queryST, &refST, &settings);
else if(settings.twoBitBl)
alnMtrxTwoBitST =
NeedleTwoBit(&queryST, &refST, &settings);
else
alnMtrxST =
NeedlemanAln(&queryST, &refST, &settings);
if(alnMtrxST == 0 && alnMtrxTwoBitST == 0)
{ /*If: the aligment falied*/
freeSeqSTStack(&refST);
freeSeqSTStack(&queryST);
fprintf(
stderr,
"Ran out of memory for Needleman alignment\n"
);
if(outFILE != stdout) fclose(outFILE);
if(altAlnFILE != stdout) fclose(altAlnFILE);
freeSeqSTStack(&refST);
freeSeqSTStack(&queryST);
exit(-1);
} /*If: the aligment falied*/
if(alnMtrxST != 0)
{ /*If: I am doning a byte array (normal)*/
alnST =
dirMatrixToAln(
&refST,
&queryST,
alnMtrxST->bestEndIndexUL,
&settings,
alnMtrxST
);
bestScoreL = alnMtrxST->bestScoreL;
freeAlnMatrix(alnMtrxST); /*No longer needed*/
alnMtrxST = 0;
} /*If: I am doning a byte array (normal)*/
else
{ /*Else: I am doing a two bit alignment*/
alnST =
twoBitDirMatrixToAln(
&refST,
&queryST,
alnMtrxTwoBitST->bestEndIndexUL,
&settings,
alnMtrxTwoBitST
);
bestScoreL = alnMtrxTwoBitST->bestScoreL;
freeAlnMatrixTwoBit(alnMtrxTwoBitST);
alnMtrxTwoBitST = 0;
} /*Else: I am doing a two bit alignment*/
goto printAlignment;
} /*If: I am doing a Needleman alignment*/
/******************************************************\
* Main Sec-05 Sub-03:
* - Check if doing an Waterman alignment
\******************************************************/
else if(settings.useWaterBl && !settings.refQueryScanBl)
{ /*Else If: doing a waterman alignment*/
if(settings.noGapBl)
alnMtrxST =
WatermanAlnNoGap(&queryST, &refST, &settings);
else if(settings.twoBitBl && settings.noGapBl)
alnMtrxTwoBitST =
WaterTwoBitNoGap(&queryST, &refST, &settings);
else if(settings.twoBitBl)
alnMtrxTwoBitST =
WaterTwoBit(&queryST, &refST, &settings);
else
alnMtrxST =
WatermanAln(&queryST,&refST,&settings);
if(alnMtrxST == 0 && alnMtrxTwoBitST == 0)
{ /*If: the aligment falied*/
freeSeqSTStack(&refST);
freeSeqSTStack(&queryST);
fprintf(
stderr,
"Ran out of memory for Waterman alignment\n"
);
if(outFILE != stdout) fclose(outFILE);
if(altAlnFILE != stdout) fclose(altAlnFILE);
freeSeqSTStack(&refST);
freeSeqSTStack(&queryST);
exit(-1);
} /*If: the aligment falied*/
if(alnMtrxST != 0)
{ /*If: I did a byte Waterman Smith alignment*/
alnST =
dirMatrixToAln(
&refST,
&queryST,
alnMtrxST->bestEndIndexUL,
&settings,
alnMtrxST
);
bestScoreL = alnMtrxST->bestScoreL;
freeAlnMatrix(alnMtrxST); /*No longer need*/
alnMtrxST = 0;
} /*If: I did a byte Waterman Smith alignment*/
else if(alnMtrxTwoBitST != 0)
{ /*If: I did a byte Waterman Smith alignment*/
alnST =
twoBitDirMatrixToAln(
&refST,
&queryST,
alnMtrxTwoBitST->bestEndIndexUL,
&settings,
alnMtrxTwoBitST
);
bestScoreL = alnMtrxTwoBitST->bestScoreL;
freeAlnMatrixTwoBit(alnMtrxTwoBitST);
alnMtrxTwoBitST = 0;
} /*If: I did a byte Waterman Smith alignment*/
goto printAlignment;
} /*Else If: I am doing a single score waterman*/
/*****************************************************\
* Main Sec-05 Sub-04:
* - Check if doing an query reference scan Waterman
\*****************************************************/
else if(settings.useWaterBl && settings.refQueryScanBl)
{ /*Else If: Wateman with query reference scan */
if(settings.noGapBl)
alnMtrxST =
WaterScanNoGap(&queryST, &refST, &settings);
else if(settings.twoBitBl && settings.noGapBl)
alnMtrxTwoBitST =
WaterScanTwoBitNoGap(&queryST,&refST,&settings);
else if(settings.twoBitBl)
alnMtrxTwoBitST =
WaterScanTwoBit(&queryST, &refST, &settings);
else
alnMtrxST =
WaterScan(&queryST, &refST, &settings);
if(alnMtrxST == 0 && alnMtrxTwoBitST == 0)
{ /*If: the aligment falied*/
freeSeqSTStack(&refST);
freeSeqSTStack(&queryST);
fprintf(
stderr,
"Ran out of memory for Waterman Query"
);
fprintf(stderr, " reference scan\n");
if(outFILE != stdout) fclose(outFILE);
if(altAlnFILE != stdout) fclose(altAlnFILE);
freeSeqSTStack(&refST);
freeSeqSTStack(&queryST);
exit(-1);
} /*If: the aligment falied*/
/*Check if I am filtering the alternative scores*/
/*
if(settings.filtQryRefBl)
altScoreFiltRefQry(alnMtrxST);
if(settings.filtRefBl)
altScoreFiltRef(alnMtrxST);
if(settings.filtQryBl)
altScoreFiltQry(alnMtrxST);
*/
if(!settings.pAltAlns)
{ /*If: I am not printing full alt alignments*/
if(alnMtrxST != 0)
{ /*If: I used a byte matrix*/
pAltAlnScores(
alnMtrxST,
settings.minScoreL,
altAlnFILE
); /*Print out socres for all alignments*/
} /*If: I used a byte matrix*/
else
{ /*Else: I used a two bit matrix*/
pAltAlnScores(
alnMtrxTwoBitST,
settings.minScoreL,
altAlnFILE
); /*Print out socres for all alignments*/
} /*Else: I used a two bit matrix*/
if(settings.justScoresBl)
{ /*If: I am printing out scores only*/
if(outFILE != stdout) fclose(outFILE);
if(altAlnFILE != stdout) fclose(altAlnFILE);
freeSeqSTStack(&refST);
freeSeqSTStack(&queryST);
if(alnMtrxST != 0)
{freeAlnMatrix(alnMtrxST);}
else
{freeAlnMatrixTwoBit(alnMtrxTwoBitST);}
exit(0);
} /*If: I am printing out scores only*/
} /*If: I am not printing full alt alignments*/
else
{ /*Else: printing out an alignment for each alt*/
for(
iterUL = 0;
iterUL < alnMtrxST->lenArraysUL;
++iterUL
){ /*Loop: Pint out kept alignments*/
if(alnMtrxST != 0)
{ /*If: I am doing a byte alignment*/
alnST =
dirMatrixToAln(
&refST,
&queryST,
alnMtrxST->endIndexAryUL[iterUL],
&settings,
alnMtrxST
); /*Get the alternative alignment*/
} /*If: I am doing a byte alignment*/
else
{ /*Else: I am doing a two bit alignment*/
alnST =
twoBitDirMatrixToAln(
&refST,
&queryST,
alnMtrxTwoBitST->endIndexAryUL[iterUL],
&settings,
alnMtrxTwoBitST
); /*Get the alternative alignment*/
} /*Else: I am doing a two bit alignment*/
errUC =
printAln(
altAlnFILE,
altAlnFileStr,
&refST,
&queryST,
alnST,
alnMtrxST->scoreAryL[iterUL],
&settings,
scoreMtrxFileStr/*Name: scoring matrix*/
); /*Print out the alternative alignment*/
freeAlnST(alnST);
alnST = 0;
if(errUC)
{ /*If: I falied to print out the alignment*/
if(altAlnFILE != stdout)
fclose(altAlnFILE);
if(outFILE != stdout) fclose(outFILE);
freeSeqSTStack(&refST);
freeSeqSTStack(&queryST);
if(alnMtrxST != 0)
{freeAlnMatrix(alnMtrxST);}
else
{freeAlnMatrixTwoBit(alnMtrxTwoBitST);}
fprintf(
stderr,
"Error while printing alternative"
);
fprintf(stderr, "alignments\n");
exit(-1);
} /*If: I falied to print out the alignment*/
} /*Loop: Pint out kept alignments*/
} /*Else: printing out an alignment for each alt*/
if(alnMtrxST != 0)
{ /*If: I did a byte aligment*/
alnST =
dirMatrixToAln(
&refST,
&queryST,
alnMtrxST->bestEndIndexUL,
&settings,
alnMtrxST
);
bestScoreL = alnMtrxST->bestScoreL;
freeAlnMatrix(alnMtrxST); /*No longer need*/
} /*If: I did a byte aligment*/
else
{ /*Else: I did a two bit aligment*/
alnST =
twoBitDirMatrixToAln(
&refST,
&queryST,
alnMtrxTwoBitST->bestEndIndexUL,
&settings,
alnMtrxTwoBitST
);
bestScoreL = alnMtrxTwoBitST->bestScoreL;
freeAlnMatrixTwoBit(alnMtrxTwoBitST);
} /*Else: I did a two bit aligment*/
goto printAlignment;
} /*Else If: Wateman with query reference scan*/
/******************************************************\
* Main Sec-05 Sub-04:
* - Check if doing an memory efficent Waterman
* alignment that prints out alternative alignment
* positions (Gets combined with a Hirschberg)
\******************************************************/
else if(settings.memWaterBl && settings.refQueryScanBl)
{ /*Else if; memory waterman alignment + scan*/
if(settings.noGapBl)
alnMtrxST =
memWaterScanNoGap(&queryST,&refST,&settings);
else
alnMtrxST =
memWaterScan(&queryST,&refST,&settings);
if(alnMtrxST == 0)
{ /*If: the aligment falied*/
freeSeqSTStack(&refST);
freeSeqSTStack(&queryST);
fprintf(
stderr,
"Ran out of memory for mem-water Query"
);
fprintf(stderr, " reference scan\n");
if(outFILE != stdout) fclose(outFILE);
if(altAlnFILE != stdout) fclose(altAlnFILE);
freeSeqSTStack(&refST);
freeSeqSTStack(&queryST);
exit(-1);
} /*If: the aligment falied*/
/*Check if I am filtering the alternative scores*/
/*
if(settings.filtQryRefBl)
altScoreFiltRefQry(alnMtrxST);
if(settings.filtRefBl)
altScoreFiltRef(alnMtrxST);
if(settings.filtQryBl)
altScoreFiltQry(alnMtrxST);
*/
alnMatrixSortScores(alnMtrxST, 0, alnMtrxST->lenArraysUL - 1);
if(!settings.pAltAlns)
{ /*If: I am not printing full alt alignments*/