-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTest_main.cpp
1105 lines (988 loc) · 65.8 KB
/
Test_main.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
#include <iostream>
#include <filesystem>
#include <algorithm>
#include <unistd.h>
#include "test.cuh"
#include "cudaDevices.cuh"
#include "tajima.cuh"
#include "fu_li.cuh"
#include "fay_wu.cuh"
#include "neutral.cuh"
#include "ehh.cuh"
#include "mk_test.cuh"
#include "fst.cuh"
#include "gff2gene.cuh"
#include "vcf_splitter_2.cuh"
#include "hap_extract.cuh"
#include "map2gene.cuh"
#include "vcf_splitter.h"
#include "print_param.h"
#include "gene_extract.h"
#include "fasta_splitter.h"
#include "parameter.h"
#include "fasta_merge.h"
#include <bits/stdc++.h>
#include <cuda.h>
#include "cuda_runtime.h"
#include "device_launch_parameters.h"
// APOLLO Simulator classes
#include "parameter_load.h"
#include "functions_library.cuh"
#include "simulator_Master.cuh"
#include "hap_counter.cuh"
#include "bfs.cuh"
#include "mutations_T_json.cuh"
#include "segmatch.cuh"
using namespace std;
/**
* ! FOR THOSE WHO READ THE CODE.
* ! THE CODE HAS BEEN COMMENTED AS MUCH AS POSSIBLE.
* ! IN CERTAIN INSTANCES THERE WILL BE COMMENTED OUT SECTIONS OF CODE.
* ! THESE ARE USUALLY RELICS OF PREVIOUS TRIALS, FAILED EFFORTS, AIMED TO GET THE BEST POSSIBLE SPEED AND ACCURACIES FROM CATE.
* ! CONSIDER THEM AS MORALS AND LESSONS LEARNED ON WHAT CAN AND CANNOT BE DONE.
* ! GOOD LUCK.
**/
/**
* RENEGADES... LET US BEGIN
* TODO: FINISH COMMENTING!
**/
/**
* Function that prints the banner.
**/
void print_Cate();
void print_Apollo();
/**
* Function that prints the help menu.
**/
void print_HELP();
int main(int argc, char *argv[])
{
/**
* * MAIN FUNCTION OF CATE
* Provides ingress into CATE.
**/
cout.precision(10);
print_Cate();
cout << "CATE: CUDA Accelerated Testing of Evolution" << endl;
cout << "Evolutionary tests for large scale genomic data" << endl
<< "----------------------------------------------" << endl
<< "HOW TO CITE:\nPerera, D., Reisenhofer, E., Hussein, S., Higgins, E., Huber, C. D., & Long, Q. (2023).\n"
<< "CATE: A fast and scalable CUDA implementation to conduct highly parallelized evolutionary tests on large scale genomic data.\n"
<< "Methods in Ecology and Evolution, 00, 1–15.\n"
<< "https://doi.org/10.1111/2041-210X.14168\n"
<< "----------------------------------------------\n"
<< endl;
/**
* The title of CATE is an acronym.
* C.A.T.E. stands for CUDA Accelerated Testing of Evolution.
* It is a software designed with the aim of utilizing the computer's multiprocessing technologies of both the CPU and GPU.
* ! At present, CATE is compatible only with CUDA enabled NVIDIA GPU's.
**/
/**
* Since CATE is command line executable it depends on one or two parameters passed via the CLI.
* @param argv is used to get these inputs.
* * [1] will be used to get the function.
* * [2] if required will point to the location of the parameter file.
**/
/**
* @param gene_List can be specific to each function or be set as universal.
* Universal enables all functions to access the same gene list file.
**/
/**
* @param prometheus_Activate is used to activate the HPC catered high speed mode of CATE dubbed Prometheus.
* ! Prometheus, is available only for the Neutrality tests of Tajima, Fay and Wu and, Fu and Li.
**/
/**
* @param calc_Mode is used for all three aforementioned Neutrality tests and, the Fst function.
* CATE is designed to bridge te gap between current WINDOW based mechanisms and GENE based calculations.
* However, it does not shy away from providing WINDOW based calculations.
* calc_Mode enables users to shift between WINDOW and FILE (gene based) modes.
* calc_Mode is not case sensitive.
**/
if (argv[1] != NULL)
{
string function(argv[1]);
/**
* * Functions are converted to lowercase formats so that they will not be case sensetive.
**/
transform(function.begin(), function.end(), function.begin(), ::tolower);
if (function == "--help" || function == "-h")
{
/**
* Prints the help menu to the CLI.
**/
print_HELP();
}
else if (function == "--godmode")
{
/**
* CATE testing framework not required nor usable by the end user.
**/
test try_something = test();
try_something.thread_test();
}
else if (function == "--cuda" || function == "-c")
{
/**
* Prints all available CUDA devices present on the current system.
* User can use this list to determine which CUDA device to be used via the CUDA ID.
**/
cudaDevices cudaList = cudaDevices();
cout << "All CUDA capable devices have been listed" << endl;
}
else
{
if (argv[2] != NULL)
{
/**
* @param parameter_File is used to capture the parameter file location.
* Converts parameter file location to a string.
**/
string parameter_File(argv[2]);
char tmp[256];
getcwd(tmp, 256);
if (function == "--printparam" || function == "-pparam")
{
/**
* Prints a default parameter.json file for the user.
**/
print_param print = print_param(parameter_File);
print.ingress();
cout << endl
<< "Parameter Print has been completed." << endl;
}
else if (function == "--simulator" || function == "-sim")
{
print_Apollo();
simulator_Master simulator = simulator_Master(parameter_File);
simulator.ingress();
}
else if (function == "--hapretrieve" || function == "-hr")
{
print_Apollo();
cout << "Haplotype retriever with frequencies\n\n";
hap_counter hapcount = hap_counter(parameter_File);
hapcount.ingress();
}
else if (function == "--pedretrieve" || function == "-pedr")
{
print_Apollo();
cout << "Pedigree powered by Breath First Search\n\n";
bfs breath_first_pedigree = bfs(parameter_File);
breath_first_pedigree.ingress();
}
else if (function == "--site2json" || function == "-s2j")
{
print_Apollo();
cout << "Converting site model file to JSON script\n\n";
mutations_T_json m2j = mutations_T_json(parameter_File);
m2j.ingress("mutations");
}
else if (function == "--recom2json" || function == "-r2j")
{
print_Apollo();
cout << "Converting recombination file to JSON script\n\n";
mutations_T_json m2j = mutations_T_json(parameter_File);
m2j.ingress("recombinations");
}
else if (function == "--segmatch" || function == "-segm")
{
print_Apollo();
cout << "Finding sequences matching segregating sites\n\n";
segmatch segM = segmatch(parameter_File);
segM.ingress();
}
else
{
/**
* The parameter Class is used to read the parameter *.json file.
**/
parameter properties = parameter(parameter_File);
/**
* Configure, check for the presence and, create if auxillary folders are unavailable.
**/
/**
* @param output_Path defines the output folder path to which all outputs will be printed to.
**/
string output_Path = properties.where("Output path");
if (filesystem::exists(output_Path) == 0)
{
cout << "Creating output folder: " << output_Path << endl;
filesystem::create_directory(output_Path);
}
else
{
cout << "Output folder exists: " << output_Path << endl;
}
/**
* @param intermediate_Path defines the intermediate folder path to which all the intermediate outputs will be printed to.
* The intermediate folder is used to initialise the resume functions and keep track of the program's progress.
**/
string intermediate_Path = properties.where("Intermediate path");
if (filesystem::exists(intermediate_Path) == 0)
{
cout << "Creating intermediate folder: " << intermediate_Path << endl;
filesystem::create_directory(intermediate_Path);
}
else
{
cout << "Intermediate folder exists: " << intermediate_Path << endl;
}
cout << endl;
/**
* The execution of all supplementary and main evolutionary functions.
**/
if (function == "--splitvcf" || function == "-svcf")
{
/**
* * Execution of the SPLIT VCF function.
* The function is responsible for the creation of the indexed folder hierarchy,
* which is crucial for the functioning of CATE.
* * Enables the VCF files to be not only split by the number of SNPS, but by population and other
* * pre-defined filters.
**/
/**
* RENEGADES... LET US BEGIN
* TODO: ADD MAF FILTER!
* TODO: FINISH COMMENTING!
**/
// string input = properties.where("Input folder entry");
// vcf_splitter split = vcf_splitter(tmp, properties.where("Input path"), properties.where("Population file path"), output_Path, properties.where_Int("Reference allele count"), properties.where_Int("Alternate allele count"), properties.where_Int("SNP count per file"), properties.where_Int("Sample_ID Column number"), properties.where_Int("Population_ID Column number"));
// split.index_population();
// split.read_File();
string split_Mode = properties.where("Split mode");
transform(split_Mode.begin(), split_Mode.end(), split_Mode.begin(), ::toupper);
if (split_Mode == "CHR")
{
int summary = 0;
string summary_Individuals = properties.where("CHR individual summary");
transform(summary_Individuals.begin(), summary_Individuals.end(), summary_Individuals.begin(), ::toupper);
if (summary_Individuals == "YES")
{
summary = 1;
}
// vcf_splitter_2(string input_vcf_Folder, string output_Folder, int cores, int SNPs_per_time_CPU, int SNPs_per_time_GPU, int allele_Count_REF, int allele_Count_ALT);
vcf_splitter_2 split_CHR = vcf_splitter_2(properties.where_Int("CUDA Device ID"), properties.where("Input path"), output_Path, properties.where_Int("Split cores"), properties.where_Int("Split SNPs per_time_CPU"), properties.where_Int("Split SNPs per_time_GPU"), properties.where_Int("Reference allele count"), properties.where_Int("Alternate allele count"), properties.where_Int("Ploidy"), summary);
split_CHR.ingress_chr_Split();
}
else if (split_Mode == "CTSPLIT")
{
string MAF = properties.where("MAF frequency");
// 0 = equal;
// 1 = greater than
// 2 = less than
// 10 = greater than or equal
// 20 = less than or equal
int MAF_logic = -1;
string MAF_Logic_string = properties.where("Frequency logic");
if (MAF_Logic_string == "=")
{
MAF_logic = 0;
}
else if (MAF_Logic_string == ">")
{
MAF_logic = 1;
}
else if (MAF_Logic_string == "<")
{
MAF_logic = 2;
}
else if (MAF_Logic_string == ">=")
{
MAF_logic = 10;
}
else if (MAF_Logic_string == "<=")
{
MAF_logic = 20;
}
if (MAF_logic != -1)
{
vcf_splitter_2 CATE_split = vcf_splitter_2(properties.where_Int("CUDA Device ID"), properties.where("Input path"), output_Path, properties.where("Population file path"), properties.where_Int("Sample_ID Column number"), properties.where_Int("Population_ID Column number"), properties.where_Int("Split cores"), properties.where_Int("Split SNPs per_time_CPU"), properties.where_Int("Split SNPs per_time_GPU"), properties.where_Int("Ploidy"), properties.where_Int("SNP count per file"), MAF_logic, stod(MAF));
CATE_split.ingress_file_hierarchy();
}
else
{
cout << "ERROR in \"Frequency logic\" type in parameters.json file. PLEASE CHECK.\n"
<< endl;
}
}
else
{
cout << "ERROR IN SPLIT MODE:\nTHERE CAN BE ONLY TWO SPLIT MODES: \"CHR\" OR \"CTSPLIT\"\nREFER TO THE HELP MENU FOR THEIR DESCRIPTIONS\n"
<< endl;
}
cout << "VCF split has been completed." << endl;
}
else if (function == "--splitfasta" || function == "-sfasta")
{
/**
* * Execution of the SPLIT FASTA function.
* Can split a merged FASTA file into its individual sequences.
* It can also be used to extract a specific sequence by its sequence ID.
**/
fasta_splitter split = fasta_splitter(properties.where("Raw FASTA file"), output_Path, properties.where("Sequence"));
split.ingress();
cout << endl
<< "FASTA split has been completed." << endl;
}
else if (function == "--mergefasta" || function == "-mfasta")
{
/**
* * Execution of the MERGE FASTA function.
* Merges all FASTA files in the folder into a single FASTA file.
**/
fasta_merge merge = fasta_merge(properties.where("FASTA files folder"), properties.where("Merge FASTA path"));
merge.ingress();
cout << endl
<< "FASTA merge has been completed." << endl;
}
else if (function == "--extractgenes" || function == "-egenes")
{
/**
* * Execution of the EXTRACT GENE function.
* Extracts gene sequences using a pre determined reference sequence file.
* The reference FASTA file should only have a single sequence.
* Positions of the gene list file should align with that of the reference sequence.
**/
string gene_List = properties.where("Extract gene list");
/**
* Get the gene file.
**/
if (gene_List == "universal")
{
gene_List = properties.where("Universal gene list");
}
gene_extract ge = gene_extract(gene_List, properties.where("Reference genome ex"), output_Path, intermediate_Path);
ge.ingress();
cout << endl
<< "Gene extractor has been completed." << endl;
}
else if (function == "--gff2gene" || function == "-g2g")
{
/**
* * Execution of the GFF to GENE function.
* Collects and writes all GENE's in a *.GFF file to a CATE format gene list file.
**/
// gff2gene(string input_File, string output_Path);
gff2gene g2g = gff2gene(properties.where("GFF file"), output_Path);
g2g.ingress();
cout << endl
<< "Completed GFF to Gene list." << endl;
}
else if (function == "--hapfromvcf" || function == "-hapext")
{
/**
* * Execution of the Haplotypes from VCF function.
* Uses the VCF file folder and the reference genome FASTA file to reconstruct all unique
* haplotypes in a gene region.
* Can also be used to recreate the FASTA file of the VCF file population.
* ! Essentially ALL FASTA sequences per individual per ploidy will be generated.
**/
string gene_List = properties.where("Hap extract gene list");
/**
* Get the gene file.
**/
if (gene_List == "universal")
{
gene_List = properties.where("Universal gene list");
}
hap_extract haplotype_Extractor = hap_extract(gene_List, properties.where("Input path"), output_Path, properties.where_Int("CUDA Device ID"), intermediate_Path, properties.where_Int("Ploidy"), properties.where("Reference genome hap"), properties.where("Population out"));
haplotype_Extractor.ingress();
cout << endl
<< "Completed CUDA powered Haplotype extractor." << endl;
}
else if (function == "--map2gene" || function == "-m2g")
{
map2gene mp2 = map2gene(properties.where("MAP file"), output_Path, properties.where("SNP prefix"));
mp2.ingress();
cout << endl
<< "Completed MAP to gene list." << endl;
}
else if (function == "--tajima" || function == "-t")
{
/**
* * Execution of the Tajima's D function.
**/
string prometheus_Activate = properties.where("Prometheus activate");
transform(prometheus_Activate.begin(), prometheus_Activate.end(), prometheus_Activate.begin(), ::toupper);
string calc_Mode = properties.where("Calculation mode");
transform(calc_Mode.begin(), calc_Mode.end(), calc_Mode.begin(), ::toupper);
string gene_List;
if (calc_Mode == "FILE")
{
/**
* Get the gene file.
**/
gene_List = properties.where("Tajima gene list");
if (gene_List == "universal")
{
gene_List = properties.where("Universal gene list");
}
}
if (prometheus_Activate != "YES")
{
/**
* Configures the normal, NON Prometheus mode.
**/
if (calc_Mode == "FILE")
{
tajima tajimasD = tajima(gene_List, properties.where("Input path"), output_Path, properties.where_Int("CUDA Device ID"), intermediate_Path, properties.where_Int("Ploidy"));
tajimasD.ingress();
}
else
{
tajima tajimasD_Window = tajima(calc_Mode, properties.where_Int("Window size"), properties.where_Int("Step size"), properties.where("Input path"), output_Path, properties.where_Int("CUDA Device ID"), properties.where_Int("Ploidy"));
tajimasD_Window.ingress();
}
}
else
{
/**
* Configures the PROMETHEUS mode.
**/
if (calc_Mode == "FILE")
{
tajima tajimasD_Prometheus = tajima(gene_List, properties.where("Input path"), output_Path, properties.where_Int("CUDA Device ID"), intermediate_Path, properties.where_Int("Ploidy"), prometheus_Activate, properties.where("Multi read"), properties.where_Int("Number of genes"), properties.where_Int("CPU cores"), properties.where_Int("SNPs per time"));
tajimasD_Prometheus.ingress();
}
else
{
// WINDOW MODE
tajima tajimasD_Prometheus_Window = tajima(calc_Mode, properties.where_Int("Window size"), properties.where_Int("Step size"), properties.where("Input path"), output_Path, properties.where_Int("CUDA Device ID"), properties.where_Int("Ploidy"), prometheus_Activate, properties.where("Multi read"), properties.where_Int("Number of genes"), properties.where_Int("CPU cores"), properties.where_Int("SNPs per time"));
tajimasD_Prometheus_Window.ingress();
}
}
cout << endl
<< "CUDA powered Tajima's D calculator has been completed." << endl;
}
else if (function == "--fuli" || function == "-f")
{
/**
* * Execution of the Fu and Li function.
* Calculates all four Fu and Li statistics, namely:
* Fu and Li's D, D*, F and F*.
**/
string prometheus_Activate = properties.where("Prometheus activate");
transform(prometheus_Activate.begin(), prometheus_Activate.end(), prometheus_Activate.begin(), ::toupper);
string calc_Mode = properties.where("Calculation mode");
transform(calc_Mode.begin(), calc_Mode.end(), calc_Mode.begin(), ::toupper);
string gene_List;
if (calc_Mode == "FILE")
{
/**
* Get the gene file.
**/
gene_List = properties.where("Fu and Li gene list");
if (gene_List == "universal")
{
gene_List = properties.where("Universal gene list");
}
}
if (prometheus_Activate != "YES")
{
/**
* Configures the normal, NON Prometheus mode.
**/
if (calc_Mode == "FILE")
{
fu_li fuli = fu_li(gene_List, properties.where("Input path"), output_Path, properties.where_Int("CUDA Device ID"), intermediate_Path, properties.where_Int("Ploidy"));
fuli.ingress();
}
else
{
fu_li fuli_Window = fu_li(calc_Mode, properties.where_Int("Window size"), properties.where_Int("Step size"), properties.where("Input path"), output_Path, properties.where_Int("CUDA Device ID"), properties.where_Int("Ploidy"));
fuli_Window.ingress();
}
}
else
{
/**
* Configures the PROMETHEUS mode.
**/
if (calc_Mode == "FILE")
{
fu_li fuli_Prometheus = fu_li(gene_List, properties.where("Input path"), output_Path, properties.where_Int("CUDA Device ID"), intermediate_Path, properties.where_Int("Ploidy"), prometheus_Activate, properties.where("Multi read"), properties.where_Int("Number of genes"), properties.where_Int("CPU cores"), properties.where_Int("SNPs per time"));
fuli_Prometheus.ingress();
}
else
{
// WINDOW MODE
fu_li fuli_Prometheus_Window = fu_li(calc_Mode, properties.where_Int("Window size"), properties.where_Int("Step size"), properties.where("Input path"), output_Path, properties.where_Int("CUDA Device ID"), properties.where_Int("Ploidy"), prometheus_Activate, properties.where("Multi read"), properties.where_Int("Number of genes"), properties.where_Int("CPU cores"), properties.where_Int("SNPs per time"));
fuli_Prometheus_Window.ingress();
}
}
cout << "CUDA powered Fu and Li's D, D*, F and F* calculator has been completed." << endl;
}
else if (function == "--faywu" || function == "-w")
{
/**
* * Execution of the Fay and Wu function.
* Calculates all two Fay and Wu statistics, namely:
* Fay and Wu's normalized H and E.
**/
string prometheus_Activate = properties.where("Prometheus activate");
transform(prometheus_Activate.begin(), prometheus_Activate.end(), prometheus_Activate.begin(), ::toupper);
string calc_Mode = properties.where("Calculation mode");
transform(calc_Mode.begin(), calc_Mode.end(), calc_Mode.begin(), ::toupper);
string gene_List;
if (calc_Mode == "FILE")
{
/**
* Get the gene file.
**/
gene_List = properties.where("Fay and Wu gene list");
if (gene_List == "universal")
{
gene_List = properties.where("Universal gene list");
}
}
if (prometheus_Activate != "YES")
{
/**
* Configures the normal, NON Prometheus mode.
**/
if (calc_Mode == "FILE")
{
fay_wu faywu = fay_wu(gene_List, properties.where("Input path"), output_Path, properties.where_Int("CUDA Device ID"), intermediate_Path, properties.where_Int("Ploidy"));
faywu.ingress();
}
else
{
// WINDOW MODE
fay_wu faywu_Window = fay_wu(calc_Mode, properties.where_Int("Window size"), properties.where_Int("Step size"), properties.where("Input path"), output_Path, properties.where_Int("CUDA Device ID"), properties.where_Int("Ploidy"));
faywu_Window.ingress();
}
}
else
{
/**
* Configures the PROMETHEUS mode.
**/
if (calc_Mode == "FILE")
{
fay_wu faywu_Prometheus = fay_wu(gene_List, properties.where("Input path"), output_Path, properties.where_Int("CUDA Device ID"), intermediate_Path, properties.where_Int("Ploidy"), prometheus_Activate, properties.where("Multi read"), properties.where_Int("Number of genes"), properties.where_Int("CPU cores"), properties.where_Int("SNPs per time"));
faywu_Prometheus.ingress();
}
else
{
// WINDOW MODE
fay_wu faywu_Prometheus_Window = fay_wu(calc_Mode, properties.where_Int("Window size"), properties.where_Int("Step size"), properties.where("Input path"), output_Path, properties.where_Int("CUDA Device ID"), properties.where_Int("Ploidy"), prometheus_Activate, properties.where("Multi read"), properties.where_Int("Number of genes"), properties.where_Int("CPU cores"), properties.where_Int("SNPs per time"));
faywu_Prometheus_Window.ingress();
}
}
cout << "CUDA powered Fay and Wu's normalized H and E calculator has been completed." << endl;
}
else if (function == "--neutrality" || function == "-n")
{
/**
* * Execution of the all three Neutrality tests together.
* Optimized to calculate all three neutrality tests together.
**/
string prometheus_Activate = properties.where("Prometheus activate");
transform(prometheus_Activate.begin(), prometheus_Activate.end(), prometheus_Activate.begin(), ::toupper);
string calc_Mode = properties.where("Calculation mode");
transform(calc_Mode.begin(), calc_Mode.end(), calc_Mode.begin(), ::toupper);
string gene_List;
if (calc_Mode == "FILE")
{
/**
* Get the gene file.
**/
gene_List = properties.where("Neutrality gene list");
if (gene_List == "universal")
{
gene_List = properties.where("Universal gene list");
}
}
if (prometheus_Activate != "YES")
{
/**
* Configures the normal, NON Prometheus mode.
**/
if (calc_Mode == "FILE")
{
neutral neutrality = neutral(gene_List, properties.where("Input path"), output_Path, properties.where_Int("CUDA Device ID"), intermediate_Path, properties.where_Int("Ploidy"));
neutrality.ingress();
}
else
{
// WINDOW MODE
neutral neutrality_Window = neutral(calc_Mode, properties.where_Int("Window size"), properties.where_Int("Step size"), properties.where("Input path"), output_Path, properties.where_Int("CUDA Device ID"), properties.where_Int("Ploidy"));
neutrality_Window.ingress();
}
}
else
{
/**
* Configures the PROMETHEUS mode.
**/
if (calc_Mode == "FILE")
{
neutral neutrality_Prometheus = neutral(gene_List, properties.where("Input path"), output_Path, properties.where_Int("CUDA Device ID"), intermediate_Path, properties.where_Int("Ploidy"), prometheus_Activate, properties.where("Multi read"), properties.where_Int("Number of genes"), properties.where_Int("CPU cores"), properties.where_Int("SNPs per time"));
neutrality_Prometheus.ingress();
}
else
{
// WINDOW MODE
neutral neutrality_Prometheus = neutral(calc_Mode, properties.where_Int("Window size"), properties.where_Int("Step size"), properties.where("Input path"), output_Path, properties.where_Int("CUDA Device ID"), properties.where_Int("Ploidy"), prometheus_Activate, properties.where("Multi read"), properties.where_Int("Number of genes"), properties.where_Int("CPU cores"), properties.where_Int("SNPs per time"));
neutrality_Prometheus.ingress();
}
}
cout << "CUDA powered complete neutrality test calculator has completed" << endl;
}
else if (function == "--mk" || function == "-m")
{
/**
* * Execution of the McDonald–Kreitman (MK) function.
* MK test can be configured to calculate Chromosome wide or Gene wide analyses.
* Test can be configured to do automatic ORF searches or user pre-defined ORF searches.
**/
string gene_List = properties.where("McDonald–Kreitman gene list");
if (gene_List == "universal")
{
/**
* Get the gene file.
**/
gene_List = properties.where("Universal gene list");
}
mk_test mk = mk_test(properties.where("Reference genome mk"), properties.where("Alignment file"), gene_List, properties.where("Input path"), output_Path, properties.where_Int("CUDA Device ID"), intermediate_Path, properties.where_Int("Ploidy"), properties.where("Genetic code"), properties.where("Start codon(s)"), properties.where("Stop codon(s)"), properties.where("Alignment mode"), properties.where("ORF known"));
mk.ingress();
cout << "CUDA powered McDonald–Kreitman Neutrality Index (NI) test has been completed." << endl;
}
else if (function == "--fst" || function == "-x")
{
/**
* * Execution of the Fixation Index or Fst function.
* Calculates te population wide Fixation index using the,
* Hs and Ht statistics.
* Hs = expected heterozygosities in subpopulations.
* Ht = expected heterozygosities for overall total population.
**/
string calc_Mode = properties.where("Calculation mode");
transform(calc_Mode.begin(), calc_Mode.end(), calc_Mode.begin(), ::toupper);
if (calc_Mode == "FILE")
{
/**
* Get the gene file.
**/
string gene_List = properties.where("Fst gene list");
if (gene_List == "universal")
{
gene_List = properties.where("Universal gene list");
}
fst fs = fst(gene_List, properties.where("Input path"), output_Path, properties.where_Int("CUDA Device ID"), intermediate_Path, properties.where_Int("Ploidy"), properties.where("Population index file path"), properties.where("Population ID"));
fs.ingress();
}
else
{
// fst(string calc_Mode, int window_Size, int step_Size, string gene_List, string input_Folder, string output_Path, int cuda_ID, int ploidy, string pop_Index_path, string pop_List);
fst fst_Window = fst(calc_Mode, properties.where_Int("Window size"), properties.where_Int("Step size"), properties.where("Input path"), output_Path, properties.where_Int("CUDA Device ID"), properties.where_Int("Ploidy"), properties.where("Population index file path"), properties.where("Population ID"));
fst_Window.ingress();
}
cout << "CUDA powered Fst (Fixation Index) calculator has been completed." << endl;
}
else if (function == "--ehh" || function == "-e")
{
/**
* * Execution of the Extended Haplotype Homozygosity (EHH) function.
**/
string mode = properties.where("Range mode");
transform(mode.begin(), mode.end(), mode.begin(), ::toupper);
// cout << mode << endl;
string file_mode_Path = "NA";
string fixed_mode_Value = "NA";
int default_SNP_count = 100;
int default_SNP_BP_count = 100000;
int EHH_CPU_cores = 1;
string GO = "NO";
/**
* Get the gene file.
**/
file_mode_Path = properties.where("EHH FILE path");
if (file_mode_Path == "universal")
{
file_mode_Path = properties.where("Universal gene list");
}
if (mode != "FIXED")
{
if (mode == "SNP")
{
default_SNP_count = properties.where_Int("SNP default count");
EHH_CPU_cores = properties.where_Int("EHH CPU cores");
// EHH_cutoff = stod(EHH_cutoff_value);
}
else if (mode == "BP")
{
default_SNP_BP_count = properties.where_Int("SNP BP displacement");
EHH_CPU_cores = properties.where_Int("EHH CPU cores");
}
GO = "YES";
}
else
{
// file_mode_Path = properties.where("EHH FILE path");
// if (file_mode_Path == "universal")
// {
// file_mode_Path = properties.where("Universal gene list");
// }
fixed_mode_Value = properties.where("FIXED mode");
GO = "YES";
}
if (GO == "YES")
{
ehh ehh_ = ehh(mode, file_mode_Path, fixed_mode_Value, properties.where("Input path"), output_Path, properties.where_Int("CUDA Device ID"), intermediate_Path, properties.where_Int("Ploidy"), default_SNP_count, EHH_CPU_cores, default_SNP_BP_count);
ehh_.ingress();
cout << "CUDA powered Extended Haplotype Homozygosity (EHH) calculator has been completed." << endl;
}
else
{
cout << "RANGE MODE HAS AN INCORRECT VALUE. Should be either \"FILE\" or \"FIXED\" or \"SNP\"" << endl;
}
}
else
{
/**
* ! Initialized when an incorrect function has been entered.
**/
cout << "INVALID FUNCTION PASSED AS A RUNTIME ARGUMENT" << endl
<< "To see available functions type --help or -h." << endl;
}
}
}
else
{
/**
* ! Initialized when the parameter file has not been configured for a function that requires a parameter file.
**/
cout << "PLEASE SPECIFY A PARAMETER JSON FILE. PROGRAM REQUIRES A PARAMETER FILE TO EXECUTE.";
}
}
}
else
{
/**
* ! Initialized when CATE has been executed without a function.
**/
cout << "PLEASE ENTER A FUNCTION. ENTER -h OR --help TO LIST ALL AVAILABLE FUNCTIONS";
}
/**
* ! After all executions of code this prompt signifies the successful completion of the program.
**/
cout << endl
<< "Program has completed its run." << endl;
return 0;
}
void print_Cate()
{
/**
* * CATE banner design.
**/
cout << " /\\\\\\\\\\\\\\\\\\ /\\\\\\\\\\\\\\\\\\ /\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ /\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\n"
<< " /\\\\\\//////// /\\\\\\\\\\\\\\\\\\\\\\\\\\ \\///////\\\\\\///// \\/\\\\\\///////////\n"
<< "/\\\\\\/ /\\\\\\/////////\\\\\\ \\/\\\\\\ \\/\\\\\\\n"
<< "/\\\\\\ \\/\\\\\\ \\/\\\\\\ \\/\\\\\\ \\/\\\\\\\\\\\\\\\\\\\\\\\n"
<< "\\/\\\\\\ \\/\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ \\/\\\\\\ \\/\\\\\\///////\n"
<< " \\//\\\\\\ \\/\\\\\\/////////\\\\\\ \\/\\\\\\ \\/\\\\\\\n"
<< " \\///\\\\\\ \\/\\\\\\ \\/\\\\\\ \\/\\\\\\ \\/\\\\\\\n"
<< " \\////\\\\\\\\\\\\\\\\\\ \\/\\\\\\ \\/\\\\\\ \\/\\\\\\ \\/\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\n"
<< " \\///////// \\/// \\/// \\/// \\///////////////\n\n";
// cout << " 0000000 00000 0000000 0000000" << endl;
// cout << " 0000 00 00 000 00" << endl;
// cout << " 000 00 00 000 00" << endl;
// cout << "0 000000000 000 0000000" << endl;
// cout << " 000 00 00 000 00" << endl;
// cout << " 0000 00 00 000 00" << endl;
// cout << " 0000000 00 00 000 0000000" << endl;
// cout << endl;
}
void print_Apollo()
{
cout << " _____\n"
<< " (, / | /) /)\n"
<< " /---| __ ___// // ___\n"
<< " ) / |_/_)_(_)(/_(/_(_)\n"
<< "(_/ .-/\n"
<< " (_/\n"
<< "\nCATE powered viral simulator\n----------------------------------------------\n\n";
}
void print_HELP()
{
/**
* * Prints CATE's complete help menu on the CLI.
**/
cout << "HELP MENU" << endl
<< "---------"
<< endl
<< endl
<< "Execution format: \"[--function or -f] properties_file.json\"" << endl
<< endl
<< "** Available functions are (not CaSe sensitive) **" << endl
<< endl
<< "PROCESS MODES:"
<< endl
<< "A high performance and fully customizable mode called PROMETHEUS is available." << endl
<< endl
<< "PROMETHEUS is available for the three neutrality tests (Tajima's D, Fay and Wu tests and Fu and Li tests)." << endl
<< "PROMETHEUS is designed for power users on (High Performance Computing) HPC systems." << endl
<< "PROMETHEUS is activated via the parameters file. All other protocols of test execution remains the same." << endl
<< "PROMETHEUS uses a CUDA powered engine, therefore, requires a CUDA capable GPU." << endl
<< endl
<< "PROMETHEUS can be configured by the following five parameters:" << endl
<< "1. Prometheus activate: \"YES\" or \"NO\" parameters used to turn the mode ON or OFF." << endl
<< "2. CPU cores : Controls the maximum number of cores that can be used at a time." << endl
<< "3. SNPs per time : Controls the max number of SNPs that will be processed on the GPU at a time." << endl
<< "4. Number of genes : Controls the number gene combinations that will be processed at a time." << endl
<< "5. Multi read : \"YES\" or \"NO\" parameters used to control the ability to read multiple files at once." << endl
<< endl
<< "CALCULATION MODES:" << endl
<< "CATE can perform tests for pre-defined gene regions or the classical sliding window mechanism." << endl
<< endl
<< "Parameters for calculation mode is as follows:" << endl
<< "Calculation mode: Can be either \"WINDOW\" or \"FILE\"." << endl
<< endl
<< "If the calculation mode is \"WINDOW\" then the following two parameters need to be configured:" << endl
<< "1. Window size: Base pair size of the window or range of the combination." << endl
<< "2. Step size : The base pair amount by which the next window's start will be incremented." << endl
<< "NOTE: If \"Step size\" is set to \"0\" then CATE will shift to a continuous sliding window mode." << endl
<< endl
<< "If the calculation mode is \"FILE\" then the following two parameters need to be configured:" << endl
<< "1. Universal gene list: Configure the location for the tab deliminated gene list file for all tests." << endl
<< "2. * gene list : Specify the location of the per test file or set it as \"universal\" to access the universal list." << endl
<< endl
<< "TOOLS:"
<< endl
<< "A set of simple tools used to manipulate and alter VCF and FASTA files." << endl
<< endl
<< "-svcf or --splitvcf\t: Splits VCF file\n."
<< " \t\t There are two major modes, \"CHR\" and \"CTSPLIT\"." << endl
<< " \t\t CHR mode splits a VCF file by chromosome as well as extracts just the GT column data." << endl
<< " \t\t CTSPLIT mode creates CATE's file heirarchy from a vcf file." << endl
<< " \t\t For CTSPLIT the vcf must have only a single chromosome's data only the GT column present." << endl
<< " \t\t CTSPLIT can separate VCF data by population and even carry out by population MAF filtration." << endl
<< " \t\t CTSPLIT files are placed in their respective population folders." << endl
<< " \t\t CTSPLIT files are named as follows: \"CHROMOSOMEnumber_COUNTRY_STARTposition_ENDposition.vcf\"." << endl
<< endl
<< "-sfasta or --splitfasta\t: Split a user specified FASTA file to individual FASTA files." << endl
<< " \t\t Can be used to extract a singular user specified sequence as well." << endl
<< " \t\t Split files are placed in a user specified folder." << endl
<< " \t\t Each FASTA file name will be the name of the respective sequence entry." << endl
<< endl
<< "-mfasta or --mergefasta\t: Merge all FASTA files in a user specified folder to an individual FASTA file." << endl
<< " \t\t Ensure that the FASTA files have the APPROPRIATE extensions: .fasta, .fna, .ffn, .faa, .frn, .fa" << endl
<< endl
<< "-egenes or --extractgenes : Reads the gene list file to extract the gene sequences from the reference genome." << endl
<< " FASTA format reference genome must be specified." << endl
<< " All gene sequences will be generated into separate FASTA files." << endl
<< endl
<< "-g2g or --gff2gene : Creates the gene list file in a *.txt format from the input GFF3 file." << endl
<< " Note that only regions annotated as genes will be extracted." << endl
<< endl
<< "-hapext or --hapfromvcf : Extracts haplotypes and their sequences for a predefined gene list from a (split) VCF (indexed) folder provided the reference sequence." << endl
<< " The reference genome must be provided in a FASTA file." << endl
<< " The system will automatically identify each haplotype present." << endl
<< " In addition to the summary output each haplotype present for each gene will be generated in a separate FASTA file." << endl