-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.cpp
1476 lines (1067 loc) · 39.3 KB
/
options.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 "pcramp.h"
#include <limits.h>
#include <stdlib.h>
#include <getopt.h>
#include <mpi.h>
#include <iostream>
#include <fstream>
// For testing and navigating directories
#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>
#include <ctype.h>
#include "JSON.h"
using namespace std;
Options::Verbosity parse_verbosity(string m_buffer);
// Enumerate the allowed fasta file extensions
const char* allowed_fasta_extions [] = {
".fna", ".fna.gz",
".fasta", ".fasta.gz",
".fa", ".fa.gz",
NULL
};
// Global MPI variables
extern int numtasks;
extern int id;
bool find_groups(const string &m_path, unordered_multimap<string, string> &m_group);
bool find_file_extension(const string &m_path, const char** m_ext);
void strip_trailing_path_separtor(deque<string> &m_str);
deque<string> parse_keys(const string &m_key_str);
string replace_special_with(char m_replacement, const string &m_str);
Options::Options()
{
// Set the default options
degen = DEFAULT_DEGEN;
num_trial = DEFAULT_NUM_TRIAL;
num_assay = DEFAULT_NUM_ASSAY;
output_filter = VERBOSE;
output_format = TEXT_OUTPUT;
target_amplicon_range = make_pair(DEFAULT_MIN_TARGET_AMPLICON, DEFAULT_MAX_TARGET_AMPLICON);
background_amplicon_range = make_pair(DEFAULT_MIN_BACKGROUND_AMPLICON, DEFAULT_MAX_BACKGROUND_AMPLICON);
target_length_range = make_pair(0, INT_MAX);
background_length_range = make_pair(0, INT_MAX);
primer_range = make_pair(DEFAULT_MIN_PRIMER, DEFAULT_MAX_PRIMER);
primer_tm_range = make_pair(DEFAULT_MIN_PRIMER_TM, DEFAULT_MAX_PRIMER_TM);
primer_strand = DEFAULT_PRIMER_STRAND;
salt = DEFAULT_SALT;
max_hairpin = DEFAULT_MAX_HAIRPIN;
max_dimer = DEFAULT_MAX_DIMER;
quit = false;
use_taq_mama = false;
top_down_search = false;
normalize_target_weight_per_file = false;
normalize_background_weight_per_file = false;
use_multiplex = true;
optimize_5 = false;
optimize_3 = false;
target_weight = DEFAULT_TARGET_WEIGHT;
background_weight = DEFAULT_BACKGROUND_WEIGHT;
target_search_multiplier = DEFAULT_SEARCH_THRESHOLD_MULTIPLIER;
background_search_multiplier = DEFAULT_SEARCH_THRESHOLD_MULTIPLIER;
target_threshold = DEFAULT_TARGET_THRESHOLD;
background_threshold = DEFAULT_BACKGROUND_THRESHOLD;
min_target_cover = DEFAULT_MIN_TARGET_COVER;
max_background_cover = DEFAULT_MAX_BACKGROUND_COVER;
seed = 0; // A seed of 0 triggers a time-based seed
// A max_thread of 0 uses all available threads
max_thread = 0;
pack_max_degen = DEFAULT_PACK_MAX_DEGEN;
pack_max_gc = DEFAULT_PACK_MAX_GC;
pack_min_gc = DEFAULT_PACK_MIN_GC;
}
void Options::load(int argc, char *argv[])
{
bool print_usage = (argc <= 1);
// Command line options:
// -t <fasta file of individual targets>
// -T <root directory of target subdirectories>
// [--T.prefix <directory prefix for target genomes>]
// [-b <fasta file of individual backgrounds>]
// [-B <root directory of background subdirectories>]
// [--B.prefix <directory prefix for background genomes>]
// -o <output file>
// [-d <max degeneracy> (default is 1)]
// [--count <total number of PCR assays to produce>]
// [--optimize.top-down Search using maximally degenerate inital primers (default is bottom up)]
// [--salt <salt concentration>]
// [--primer.hairpin <max oligo hairpin melting temperature>]
// [--primer.dimer <max oligo hetero/homo-dimer melting temperature>]
// [--optimize.5 (enable 5' oligo search to optimize primer coverage)]
// [--no-optimize.5 (disable 5' oligo search to optimize primer coverage)]
// [--optimize.3 (enable 3' oligo search to optimize primer coverage)]
// [--no-optimize.3 (disable 3' oligo search to optimize primer coverage)]
// [--target.amplicon.min <minimum amplicon length> (default is 80)]
// [--target.amplicon.max <maximum amplicon length> (default is 200)]
// [--target.weight <target weight> (default is 1.0)]
// [--target.threshold <target detection threshold> (default is 1.0)]
// [--target.cover <minimum per primer pair coverage> (default is 1)]
// [--target.ignore <defline key word to exclude a sequence>]
// [--target.normalize (normalize weights per fasta file)]
// [--target.size.min <length> (minimum input target length in bp)]
// [--target.size.max <length> (maximum input target length in bp)]
// [--target.prefix <directory prefix for target genomes>] (synonym for --T.prefix)
// [--background.amplicon.min <minimum amplicon length> (default is 80)]
// [--background.amplicon.max <maximum amplicon length> (default is 200)]
// [--background.weight <background weight> (default is 1.0)]
// [--background.threshold <background detection threshold> (default is 1.0)]
// [--background.cover <maximum per primer pair coverage> (default is 0)]
// [--background.ignore <defline key word to exclude a sequence>]
// [--background.normalize (normalize weights per fasta file)]
// [--background.size.min <length> (minimum input background length in bp)]
// [--background.size.max <length> (maximum input background length in bp)]
// [--background.fast (Only use a subset of background sequences)]
// [--background.prefix <directory prefix for background genomes>] (synonym for --B.prefix)
// [--primer.size.min <minimum primer length> (default is 18)]
// [--primer.size.max <maximum primer length> (default is 25)]
// [--primer.tm.min <minimum primer melting temperature>]
// [--primer.tm.max <maximum primer melting temperature>]
// [--primer.strand <primer concentration>]
// [--primer.taq-mama (use Taq MAMA rules for terminal primer mismatches)]
// [--trial <number of trials> (default is 1000)]
// [--seed <random number seed> (default is time-based)]
// [--thread <maximum number of OpenMP threads> (default is all)]
// [-v <verbosity level: silent, verbose, everything>]
// [--pack.degen.max <max degen when packing words> (default is 256)]
// [--pack.gc.max <max fractional GC content when packing words> (default is 1.0, disabled)]
// [--pack.gc.min <min fractional GC content when packing words> (default is 0.0, disabled)]
// [--input.prefix <directory prefix for both target and background input genomes>]
// [--json <JSON file of configuration values>]
// [--json.root <root key for JSON configuration file> ("xxx|yyy|zzz|...")]
const char* options = "t:T:b:B:o:d:v:?h";
int config_opt = 0;
int long_index = 0;
struct option long_opts[] = {
{"target.amplicon.min", true, &config_opt, 2},
{"target.amplicon.max", true, &config_opt, 3},
{"primer.size.min", true, &config_opt, 4},
{"primer.size.max", true, &config_opt, 5},
{"background.amplicon.min", true, &config_opt, 8},
{"background.amplicon.max", true, &config_opt, 9},
{"seed", true, &config_opt, 10},
{"target.weight", true, &config_opt, 11},
{"background.weight", true, &config_opt, 12},
{"target.threshold", true, &config_opt, 13},
{"background.threshold", true, &config_opt, 14},
{"target.cover", true, &config_opt, 15},
{"background.cover", true, &config_opt, 16},
{"primer.taq-mama", false, &config_opt, 17},
{"trial", true, &config_opt, 18},
{"pack.degen.max", true, &config_opt, 19},
{"pack.gc.min", true, &config_opt, 20},
{"pack.gc.max", true, &config_opt, 21},
{"count", true, &config_opt, 23},
{"target.search", true, &config_opt, 24},
{"optimize.top-down", false, &config_opt, 26},
{"target.ignore", true, &config_opt, 27},
{"background.ignore", true, &config_opt, 28},
{"primer.tm.min", true, &config_opt, 29},
{"primer.tm.max", true, &config_opt, 30},
{"primer.strand", true, &config_opt, 33},
{"salt", true, &config_opt, 35},
{"primer.hairpin", true, &config_opt, 36},
{"primer.dimer", true, &config_opt, 37},
{"target.normalize", false, &config_opt, 39},
{"background.normalize", false, &config_opt, 40},
{"thread", true, &config_opt, 41},
//{"multiplex", false, &config_opt, 42}, <-- default is true
{"target.size.min", true, &config_opt, 43},
{"target.size.max", true, &config_opt, 44},
{"background.size.min", true, &config_opt, 45},
{"background.size.max", true, &config_opt, 46},
{"background.search", true, &config_opt, 47},
{"optimize.5", false, &config_opt, 48},
{"no-optimize.5", false, &config_opt, 49},
{"optimize.3", false, &config_opt, 50},
{"no-optimize.3", false, &config_opt, 51},
{"json", true, &config_opt, 53},
{"json.root", true, &config_opt, 54},
{"target.prefix", true, &config_opt, 55},
{"T.prefix", true, &config_opt, 55}, // Synonym for target.prefix
{"background.prefix", true, &config_opt, 56},
{"B.prefix", true, &config_opt, 56}, // Synonym for background.prefix
{"input.prefix", true, &config_opt, 57},
{"o.text", false, &config_opt, 58},
{"o.json", false, &config_opt, 59},
{0,0,0,0} // Terminate options list
};
int opt_code;
opterr = 0;
deque<string> target_dir;
deque<string> background_dir;
string json_file;
string json_root;
string dir_prefix;
while( (opt_code = getopt_long( argc, argv, options, long_opts, &long_index) ) != EOF ){
switch( opt_code ){
case 0:
if(config_opt == 2){ // target.amplicon.min
target_amplicon_range.first = atoi(optarg);
if(target_amplicon_range.first < 0){
cerr << "Please specify a target.amplicon.min >= 0" << endl;
quit = true;
return;
}
break;
}
if(config_opt == 3){ // target.amplicon.max
target_amplicon_range.second = atoi(optarg);
if(target_amplicon_range.second < 0){
cerr << "Please specify a target.amplicon.max >= 0" << endl;
quit = true;
return;
}
break;
}
if(config_opt == 4){ // primer.size.min
primer_range.first = atoi(optarg);
if(primer_range.first < 0){
cerr << "Please specify a primer.min >= 0" << endl;
quit = true;
return;
}
break;
}
if(config_opt == 5){ // primer.size.max
primer_range.second = atoi(optarg);
if(primer_range.second < 0){
cerr << "Please specify a primer.max >= 0" << endl;
quit = true;
return;
}
break;
}
if(config_opt == 8){ // background.amplicon.min
background_amplicon_range.first = atoi(optarg);
if(background_amplicon_range.first < 0){
cerr << "Please specify a background.amplicon.min >= 0" << endl;
quit = true;
return;
}
break;
}
if(config_opt == 9){ // background.amplicon.max
background_amplicon_range.second = atoi(optarg);
if(background_amplicon_range.second < 0){
cerr << "Please specify a background.amplicon.max >= 0" << endl;
quit = true;
return;
}
break;
}
if(config_opt == 10){ // seed
seed = abs( atoi(optarg) );
break;
}
if(config_opt == 11){ // target.weight
target_weight = atof(optarg);
if(target_weight < 1.0){
cerr << "Please specify a valid target.weight value (>= 1.0)" << endl;
quit = true;
return;
}
break;
}
if(config_opt == 12){ // background.weight
background_weight = atof(optarg);
if(background_weight < 0.0f){
cerr << "Please specify a valid background.weight value (>= 0.0)" << endl;
quit = true;
return;
}
break;
}
if(config_opt == 13){ // target.threshold
target_threshold = atof(optarg);
if( (target_threshold < 0.0f) || (target_threshold > 1.0f) ){
cerr << "Please specify a valid target.threshold value (0 <= PCR <= 1)" << endl;
quit = true;
return;
}
break;
}
if(config_opt == 14){ // background.threshold
background_threshold = atof(optarg);
if( (background_threshold < 0.0f) || (background_threshold > 1.0f) ){
cerr << "Please specify a valid background.threshold value (0 <= PCR <= 1)" << endl;
quit = true;
return;
}
break;
}
if(config_opt == 15){ // target.cover
min_target_cover = atof(optarg);
if(min_target_cover < 0.0f){
cerr << "Please specify a valid target.cover value (>= 0)" << endl;
quit = true;
return;
}
break;
}
if(config_opt == 16){ // background.cover
max_background_cover = atof(optarg);
if(max_background_cover < 0.0f){
cerr << "Please specify a valid background.cover value (>= 0)" << endl;
quit = true;
return;
}
break;
}
if(config_opt == 17){ // primer.taq-mama
use_taq_mama = true;
break;
}
if(config_opt == 18){ // trial
// Read the number of trials as a float to allow the use
// of scientific notation when specifying large values for
// the number of trials.
num_trial = (unsigned int)( fabs( atof(optarg) ) );
if(num_trial == 0){
cerr << "Please enter --trial > 0" << endl;
quit = true;
return;
}
break;
}
if(config_opt == 19){ // pack.degen.max
pack_max_degen = abs( atoi(optarg) );
if(pack_max_degen == 0){
cerr << "Please enter --pack.max_degen > 0" << endl;
quit = true;
return;
}
break;
}
if(config_opt == 20){ // pack.gc.min
pack_min_gc = atof(optarg);
if( (pack_min_gc < 0.0f) || (pack_min_gc > 1.0f) ){
cerr << "Please enter --pack.min_gc >= 0 and <= 1.0" << endl;
quit = true;
return;
}
break;
}
if(config_opt == 21){ // pack.gc.max
pack_max_gc = atof(optarg);
if( (pack_max_gc < 0.0f) || (pack_max_gc > 1.0f) ){
cerr << "Please enter --pack.max_gc >= 0 and <= 1.0" << endl;
quit = true;
return;
}
break;
}
if(config_opt == 23){ // count
num_assay = abs( atoi(optarg) );
if( num_assay == 0 ){
cerr << "Please enter --count >= 1" << endl;
quit = true;
return;
}
break;
}
if(config_opt == 24){ // target.search
target_search_multiplier = atof(optarg);
if( (target_search_multiplier <= 0.0) || (target_search_multiplier > 1.0) ){
cerr << "Please enter 0 < target.search <= 1" << endl;
quit = true;
return;
}
break;
}
if(config_opt == 26){ // optimize.top-down
top_down_search = true;
break;
}
if(config_opt == 27){ // target.ignore
target_ignore.push_back( tolower(optarg) );
break;
}
if(config_opt == 28){ // background.ignore
background_ignore.push_back( tolower(optarg) );
break;
}
if(config_opt == 29){ // primer.tm.min
primer_tm_range.first = atof(optarg);
break;
}
if(config_opt == 30){ // primer.tm.max
primer_tm_range.second = atof(optarg);
break;
}
if(config_opt == 33){ // primer.strand
primer_strand = atof(optarg);
break;
}
if(config_opt == 35){ // salt
salt = atof(optarg);
break;
}
if(config_opt == 36){ // primer.hairpin
max_hairpin = atof(optarg);
break;
}
if(config_opt == 37){ // primer.dimer
max_dimer = atof(optarg);
break;
}
if(config_opt == 39){ // target.normalize
normalize_target_weight_per_file = true;
break;
}
if(config_opt == 40){ // background.normalize
normalize_background_weight_per_file = true;
break;
}
if(config_opt == 41){ // thread
max_thread = abs( atoi(optarg) );
break;
}
// Multiplex assay design is now the default
//if(config_opt == 42){ // multiplex
//
// use_multiplex = true;
// break;
//}
if(config_opt == 43){ // target.size.min
target_length_range.first = atoi(optarg);
break;
}
if(config_opt == 44){ // target.size.max
target_length_range.second = atoi(optarg);
break;
}
if(config_opt == 45){ // background.size.min
background_length_range.first = atoi(optarg);
break;
}
if(config_opt == 46){ // background.size.max
background_length_range.second = atoi(optarg);
break;
}
if(config_opt == 47){ // background.search
background_search_multiplier = atof(optarg);
if( (background_search_multiplier <= 0.0) || (background_search_multiplier > 1.0) ){
cerr << "Please enter 0 < background.search <= 1" << endl;
quit = true;
return;
}
break;
}
if(config_opt == 48){ // optimize.5
optimize_5 = true;
break;
}
if(config_opt == 49){ // no-optimize.5
optimize_5 = false;
break;
}
if(config_opt == 50){ // optimize.3
optimize_3 = true;
break;
}
if(config_opt == 51){ // no-optimize.3
optimize_3 = false;
break;
}
if(config_opt == 53){ // json
json_file = optarg;
break;
}
if(config_opt == 54){ // json.root
json_root = optarg;
break;
}
if(config_opt == 55){ // target.prefix or T.prefix
target_dir_prefix = optarg;
break;
}
if(config_opt == 56){ // background.prefix or B.prefix
background_dir_prefix = optarg;
break;
}
if(config_opt == 57){ // input.prefix
dir_prefix = optarg;
break;
}
if(config_opt == 58){ // o.text
output_format = TEXT_OUTPUT;
break;
}
if(config_opt == 59){ // o.json
output_format = JSON_OUTPUT;
break;
}
cerr << "Unknown command line flag!" << endl;
quit = true;
return;
case 't':
target_filename.push_back(optarg);
break;
case 'T':
target_dir.push_back(optarg);
break;
case 'b':
background_filename.push_back(optarg);
break;
case 'B':
background_dir.push_back(optarg);
break;
case 'o':
output_filename = optarg;
break;
case 'd':
degen = abs( atoi(optarg) );
break;
case 'v':
output_filter = parse_verbosity(optarg);
if(output_filter == UNKNOWN_VERBOSITY){
cerr << "Please enter a valid verbosity flag: \"silent\", \"verbose\", \"everything\""
<< endl;
quit = true;
return;
}
break;
case 'h':
case '?':
print_usage = true;
break;
default:
cerr << '\"' << (char)opt_code << "\" is not a valid option!" << endl;
quit = true;
return;
};
}
if(print_usage){
cerr << "PCRamp version "
<< PCRAMP_MAJOR_VERSION << "."
<< PCRAMP_MINOR_VERSION << endl;
cerr << "Usage:" << endl;
cerr << "\t-t <target fasta file>" << endl;
cerr << "\t-T <root directory of target subdirectories>" << endl;
cerr << "\t[--T.prefix <directory prefix for target genomes>]" << endl;
cerr << "\t[-b <background fasta file>]" << endl;
cerr << "\t[-B <root directory of background subdirectories>]" << endl;
cerr << "\t[--B.prefix <directory prefix for background genomes>]" << endl;
cerr << "\t-o <output file>" << endl;
cerr << "\t[--o.text (output results as [poorly] structured text)]" << endl;
cerr << "\t[--o.json (output results in JSON format)]" << endl;
cerr << "\t[-d <max degeneracy> (default is " << DEFAULT_DEGEN << ")]" << endl;
cerr << "\t[--trial <number of trials (default is " << DEFAULT_NUM_TRIAL << ")>]" << endl;
cerr << "\t[--seed <random number seed> (default is time-based)]" << endl;
cerr << "\t[--thread <maximum number of OpenMP threads> (default is all)]" << endl;
cerr << "\t[--salt <salt concentration> (default is " << DEFAULT_SALT << ")" << endl;
cerr << "\t[--primer.hairpin <max oligo hairpin Tm> (default is " << DEFAULT_MAX_HAIRPIN << ")" << endl;
cerr << "\t[--primer.dimer <max oligo hetero/homo-dimer Tm> (default is " << DEFAULT_MAX_DIMER << ")" << endl;
cerr << "\t[--count <total number of amplicons to produce> (default is " << DEFAULT_NUM_ASSAY << ")]" << endl;
cerr << "\t[--optimize.top-down Search using maximally degenerate inital primer oligos (default is bottom up)]" << endl;
//cerr << "\t[--multiplex (choose multiplex compatible assays)]" << endl;
cerr << "\t[--optimize.5 (enable 5' primer search to optimize coverage)]" << endl;
cerr << "\t[--no-optimize.5 (disable 5' primer search to optimize coverage; default)]" << endl;
cerr << "\t[--optimize.3 (enable 3' primer search to optimize coverage)]" << endl;
cerr << "\t[--no-optimize.3 (disable 3' primer search to optimize coverage; default)]" << endl;
cerr << "\t[-v <verbosity level: silent, verbose, everything>]" << endl;
cerr << "\t[--target.amplicon.min <minimum amplicon length> (default is " << DEFAULT_MIN_TARGET_AMPLICON << ")]" << endl;
cerr << "\t[--target.amplicon.max <maximum amplicon length> (default is " << DEFAULT_MAX_TARGET_AMPLICON << ")]" << endl;
cerr << "\t[--target.threshold <target detection threshold> (default is " << DEFAULT_TARGET_THRESHOLD << ")]" << endl;
cerr << "\t[--target.search <target search multiplier> (default is " << DEFAULT_SEARCH_THRESHOLD_MULTIPLIER << ")]" << endl;
cerr << "\t[--target.cover <minimum per primer pair coverage> (default is " << DEFAULT_MIN_TARGET_COVER << ")]" << endl;
cerr << "\t[--target.ignore <defline key word to exclude a sequence>]" << endl;
cerr << "\t[--target.normalize (normalize target weights per fasta file)]" << endl;
cerr << "\t[--target.size.min <length> (minimum input target length in bp)]" << endl;
cerr << "\t[--target.size.max <length> (maximum input target length in bp)]" << endl;
cerr << "\t[--background.amplicon.min <minimum amplicon length>]" << endl;
cerr << "\t[--background.amplicon.max <maximum amplicon length>]" << endl;
cerr << "\t[--background.threshold <background detection threshold> (default is " << DEFAULT_BACKGROUND_THRESHOLD << ")]" << endl;
cerr << "\t[--background.search <background search multiplier> (default is " << DEFAULT_SEARCH_THRESHOLD_MULTIPLIER << ")]" << endl;
cerr << "\t[--background.cover <maximum per primer pair coverage> (default is " << DEFAULT_MAX_BACKGROUND_COVER << ")]" << endl;
cerr << "\t[--background.ignore <defline key word to exclude a sequence>]" << endl;
cerr << "\t[--background.normalize (normalize background weights per fasta file)]" << endl;
cerr << "\t[--background.size.min <length> (minimum input background length in bp)]" << endl;
cerr << "\t[--background.size.max <length> (maximum input background length in bp)]" << endl;
cerr << "\t[--primer.size.min <minimum primer length> (default is " << DEFAULT_MIN_PRIMER << ")]" << endl;
cerr << "\t[--primer.size.max <maximum primer length> (default is " << DEFAULT_MAX_PRIMER << ")]" << endl;
cerr << "\t[--primer.tm.min <minimum primer melting temperature> (default is " << DEFAULT_MIN_PRIMER_TM << ")]" << endl;
cerr << "\t[--primer.tm.max <maximum primer melting temperature> (default is " << DEFAULT_MAX_PRIMER_TM << ")]" << endl;
cerr << "\t[--primer.strand <primer strand concentration> (default is " << DEFAULT_PRIMER_STRAND << ")]" << endl;
cerr << "\t[--primer.taq-mama (use Taq MAMA rules for terminal primer mismatches; default is false)]" << endl;
cerr << "\t[--pack.degen.max <max degen when packing words> (default is " << DEFAULT_PACK_MAX_DEGEN << ")]" << endl;
cerr << "\t[--pack.gc.max <max fractional GC content when packing words> (default is " << DEFAULT_PACK_MAX_GC << ", disabled)]" << endl;
cerr << "\t[--pack.gc.min <min fractional GC content when packing words> (default is " << DEFAULT_PACK_MIN_GC << ", disabled)]" << endl;
cerr << "\t[--input.prefix <directory prefix for both target and background input genomes>]" << endl;
// JSON-formatted input file is currently not recommended
//cerr << "\t[--json <JSON file of configuration values>]" << endl;
//cerr << "\t[--json.root <root key for JSON configuration file> (\"xxx|yyy|zzz|...\")]" << endl;
quit = true;
return;
}
if( !json_file.empty() ){
if( !parse_json(json_file, json_root,
target_dir, target_dir_prefix,
background_dir, background_dir_prefix) ){
cerr << "Error parsing JSON file \"" << json_file << "\" with root key \""
<< json_root << '"' << endl;
quit = true;
return;
}
}
if( target_filename.empty() && target_dir.empty() ){
cerr << "Please specify one or more target filenames (-t) or directories (-T)" << endl;
quit = true;
return;
}
if( output_filename.empty() ){
cerr << "Please specify an output filename (-o)" << endl;
quit = true;
return;
}
if(degen == 0){
cerr << "Please specify a valid maximum degeneracy (-d)" << endl;
quit = true;
return;
}
if(primer_range.second > WORD_LENGTH){
cerr << "The maximum primer length must be <= " << WORD_LENGTH << endl;
quit = true;
return;
}
if(primer_range.second < primer_range.first){
cerr << "The maximum primer length must be >= minimum primer length" << endl;
quit = true;
return;
}
if(primer_tm_range.first > primer_tm_range.second){
cerr << "The maximum primer melting temperature must be >= minimum primer melting temperature" << endl;
quit = true;
return;
}
if(target_amplicon_range.second < target_amplicon_range.first){
cerr << "The maximum target amplicon length must be >= minimum target amplicon length" << endl;
quit = true;
return;
}
if(background_amplicon_range.second < background_amplicon_range.first){
cerr << "The maximum background amplicon length must be >= minimum background amplicon length" << endl;
quit = true;
return;
}
if(target_length_range.second < target_length_range.first){
cerr << "The maximum target input sequence length must be >= minimum target input sequence length" << endl;
quit = true;
return;
}
if(background_length_range.second < background_length_range.first){
cerr << "The maximum background input sequence length must be >= minimum background input sequence length" << endl;
quit = true;
return;
}
if(pack_max_gc < pack_min_gc){
cerr << "The maximum packing GC content must be >= the minimum packing GC content" << endl;
quit = true;
return;
}
if(seed == 0){
seed = time(NULL);
}
if(salt < 0.0f){
cerr << "Please specify a salt concentration > 0" << endl;
quit = true;
return;
}
if(primer_strand < 0.0f){
cerr << "Please specify a [primer strand] concentration > 0" << endl;
quit = true;
return;
}
// Make sure that we don't attempt to read the same data more than once
make_set(target_filename);
make_set(background_filename);
// Strip any trailing path separators from the directory names to ensure
// that group naming is consistent
strip_trailing_path_separtor(target_dir);
strip_trailing_path_separtor(background_dir);
make_set(target_dir);
make_set(background_dir);
// If the user has set the directory prefix, but not the more specific
// target or background directory prefixs, set them here.
if( target_dir_prefix.empty() ){
target_dir_prefix = dir_prefix;
}
if( background_dir_prefix.empty() ){
background_dir_prefix = dir_prefix;
}
// Recursively search each input directory or file and extract all subdirectories that contain
// fasta files. Each subdirectory (or file name) becomes a group name for the fasta files contained
// in the subdirectory (or file). All of the fasta records associated with a group will be
// concatinated into a single sequence.
for(deque<string>::const_iterator i = target_dir.begin();i != target_dir.end();++i){
string target_path;
if( target_dir_prefix.empty() ){
target_path = *i;
}
else{
target_path = target_dir_prefix + PATH_SEPARATOR + *i;
}
if(find_groups(target_path, target_groups) == false){
cerr << "Invalid target path: " << target_path << endl;
quit = true;
return;
}
}
for(deque<string>::const_iterator i = background_dir.begin();i != background_dir.end();++i){
string background_path;
if( background_dir_prefix.empty() ){
background_path = *i;
}
else{
background_path = background_dir_prefix + PATH_SEPARATOR + *i;
}
if(find_groups(background_path, background_groups) == false){
cerr << "Invalid background path: " << *i << endl;
quit = true;
return;