-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathoptions.cpp
More file actions
1034 lines (836 loc) · 28.8 KB
/
options.cpp
File metadata and controls
1034 lines (836 loc) · 28.8 KB
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 "options.h"
#include "throw.h"
#ifdef WIN32
extern "C" {
#endif // WIN32
#include "getopt.h"
#ifdef WIN32
}
#endif // WIN32
#include <sstream>
using namespace std;
void Options::parse_command_line(int argc, char *argv[])
{
// Command line options:
// -i <input file of query oligos>
// -o <output file>
// -d <database of target sequences to search against>
// -D <local database of target sequences to search against>
// -l <maximum amplicon length>
// -e <min primer Tm>
// -E <min probe Tm>
// -z <min primer delta G>
// -Z <min probe delta G>
// -x <max primer Tm>
// -X <max probe Tm>
// -g <max primer delta G>
// -G <max probe delta G>
// -s <salt concentration (in MOL)>
// -t <primer strand concentration (in MOL)>
// -T <Probe strand concentration (in MOL)>
// -y <ratio of forward/reverse strand concentrations>
// -A <assay format>
// -W <hash word length>
// -m <output format>
// -a <T|F> (show alignments)
// -M <T|F> (show matching sequence)
// -k <T|F> (Mask primer binding sites)
// -K <T|F> (Mask probe binding sites)
// -r <T|F> (Replace primer binding sites w/ primer sequence)
// -v <T|F> (Disable verbose output)
// -p <T|F> (Ignore probe oligos in inputfile)
// -n <T|F> (One output file per query)
// -L <T|F> (Append assay name to output defline)
// -S <T|F> (Print assay summary after search)
// -? help
// -h help
// --help
// --primer-clamp <number of exact 3' primer matches required>
// --probe-clamp5 <number of exact 5' probe matches required>
// --probe-clamp3 <number of exact 3' probe matches required>
// --dangle5 <T|F> (Allow dangling bases on the 5' query side of an alignment)
// --dangle3 <T|F> (Allow dangling bases on the 3' query side of an alignment)
// --target-strand <sense|antisense|both>
// --plex <T|F> (All input assays in a single multiple reaction)
// --single-primer-pcr <T|F> (Allow amplicons produced by a single PCR primer
// binding in both forward and reverse orientation?)
// --temperature <temperature for computing Delta G (in Kelvin)>
// --hash-size <max size> (max number of hash elements)
// --max-target-len <max len> (max sequence length, in bases, before targets are split)
// --query-seg <always | never | adaptive> (query segmentation algorithm)
// --dump-query <T|F> (write queries to stdout)
// --dinkelbach <T|F> (Use the Dinkelbach fractional programming algorithm)
// --max-gap <number of gaps> (maximum number of gaps allowed in a DNA duplex)
// --max-mismatch <number of mismatches> (maximum number of mismatches allowed in a DNA duplex)
// --max-poly-N <number of bases> (maximum number of contiguous, fully degenerate bases to allow in an oligo alignment)
// --rescale-ct <T|F> (Use of degenerate bases results in rescaling of oligo concentration)
// --best-match (Only report the best match, in Tm, between an assay and a target)
// --blast-include <Accession or NCBI TaxId to include from BLAST database>
// --blast-exclude <Accession or NCBI TaxId to exclude from BLAST database>
const char* options = "-i:o:d:D:l:e:E:z:Z:x:X:g:G:s:t:T:y:A:W:m:a:M:k:K:r:v:p:n:L:S:?h";
int config_opt = 0;
int long_index = 0;
struct option long_opts[] = {
{"help", false, &config_opt, 1},
{"primer-clamp", true, &config_opt, 3},
{"probe-clamp5", true, &config_opt, 4},
{"probe-clamp3", true, &config_opt, 5},
{"plex", true, &config_opt, 6},
{"single-primer-pcr", true, &config_opt, 7},
{"hash-size", true, &config_opt, 8},
{"target-strand", true, &config_opt, 9},
{"temperature", true, &config_opt, 10},
{"max-target-len", true, &config_opt, 11},
{"query-seg", true, &config_opt, 12},
{"dump-query", true, &config_opt, 13},
{"dangle5", true, &config_opt, 14},
{"dangle3", true, &config_opt, 15},
{"min-max-primer-clamp", true, &config_opt, 16},
{"dinkelbach", true, &config_opt, 17},
{"max-gap", true, &config_opt, 18},
{"max-mismatch", true, &config_opt, 19},
{"rescale-ct", true, &config_opt, 20},
{"best-match", false, &config_opt, 21},
{"blast-include", true, &config_opt, 22},
{"blast-exclude", true, &config_opt, 23},
{"max-poly-degen", true, &config_opt, 24},
{0,0,0,0} // Terminate options list
};
int opt_code;
opterr = 0;
threshold_format = THRESHOLD_NONE;
// If no command line arguments are specified, then print the command line usage
print_usage = (argc == 1);
// Read the command line options
while( (opt_code = getopt_long( argc, argv, options, long_opts, &long_index) ) != EOF ){
switch( opt_code ){
case 0:
// --help
if(config_opt == 1){
print_usage = true;
break;
}
// --primer-clamp
if(config_opt == 3){
primer_clamp = atoi(optarg);
break;
}
// --probe-clamp5
if(config_opt == 4){
probe_clamp_5 = atoi(optarg);
break;
}
// --probe-clamp3
if(config_opt == 5){
probe_clamp_3 = atoi(optarg);
break;
}
// --plex
if(config_opt == 6){
multiplex = parse_bool(optarg);
break;
}
// --single-primer-pcr
if(config_opt == 7){
single_primer_pcr = parse_bool(optarg);
break;
}
// --target-strand
if(config_opt == 9){
target_strand = parse_strand(optarg);
break;
}
// --temperature
if(config_opt == 10){
target_t = atof(optarg);
if(target_t < 0.0f){
cerr << "Warning: --temperature is less than zero!" << endl;
}
break;
}
// --max-target-len
if(config_opt == 11){
fragment_target_threshold = atoi(optarg);
if(fragment_target_threshold <= 1){
THROW("Error: --max-target-len is <= 1");
}
break;
}
// --query-seg
if(config_opt == 12){
query_segmentation = parse_query_seg(optarg);
break;
}
// --dump-query
if(config_opt == 13){
dump_query = parse_bool(optarg);
break;
}
// --dangle5
if(config_opt == 14){
allow_dangle_5 = parse_bool(optarg);
break;
}
// --dangle3
if(config_opt == 15){
allow_dangle_3 = parse_bool(optarg);
break;
}
// --min-max-primer-clamp
if(config_opt == 16){
min_max_primer_clamp = atoi(optarg);
break;
}
// --dinkelbach
if(config_opt == 17){
use_dinkelbach = parse_bool(optarg);
break;
}
// --max-gap
if(config_opt == 18){
max_gap = atoi(optarg);
break;
}
// --max-mismatch
if(config_opt == 19){
max_mismatch = atoi(optarg);
break;
}
// --rescale-ct
if(config_opt == 20){
degen_rescale_ct = parse_bool(optarg);
break;
}
// --best-match
if(config_opt == 21){
best_match = true;
break;
}
// --blast-include
if(config_opt == 22){
blast_include.push_back(optarg);
break;
}
// --blast-exclude
if(config_opt == 23){
blast_exclude.push_back(optarg);
break;
}
// --max-poly-degen
if(config_opt == 24){
max_poly_degen = abs( atoi(optarg) );
break;
}
cerr << "Unknown flag!" << endl;
break;
case 'i':
input_filename = optarg;
break;
case 'o':
output_filename = optarg;
break;
case 'd':
dbase_filename = optarg;
break;
case 'D':
local_dbase_filename = optarg;
break;
case 'l':
max_len = atoi(optarg);
break;
case 'e':
min_primer_tm = float( atof(optarg) );
threshold_format |= THRESHOLD_PRIMER_TM;
break;
case 'E':
min_probe_tm = float( atof(optarg) );
threshold_format |= THRESHOLD_PROBE_TM;
break;
case 'z':
min_primer_dg = float( atof(optarg) );
threshold_format |= THRESHOLD_PRIMER_DELTA_G;
break;
case 'Z':
min_probe_dg = float( atof(optarg) );
threshold_format |= THRESHOLD_PROBE_DELTA_G;
break;
case 'x':
max_primer_tm = float( atof(optarg) );
threshold_format |= THRESHOLD_PRIMER_TM;
break;
case 'X':
max_probe_tm = float( atof(optarg) );
threshold_format |= THRESHOLD_PROBE_TM;
break;
case 'g':
max_primer_dg = float( atof(optarg) );
threshold_format |= THRESHOLD_PRIMER_DELTA_G;
break;
case 'G':
max_probe_dg = float( atof(optarg) );
threshold_format |= THRESHOLD_PROBE_DELTA_G;
break;
case 's':
salt = float( atof(optarg) );
break;
case 't':
primer_strand = float( atof(optarg) );
break;
case 'T':
probe_strand = float( atof(optarg) );
break;
case 'y':
asymmetric_strand_ratio = float( atof(optarg) );
break;
case 'A':
assay_format = parse_assay_format(optarg);
break;
case 'W':
hash_word_size = atoi(optarg);
break;
case 'm':
parse_output_file(optarg);
break;
case 'a':
if(parse_bool(optarg) == true){
// Set the bit
output_format |= OUTPUT_ALIGNMENTS;
}
else{
// Unset the bit
output_format &= ~OUTPUT_ALIGNMENTS;
}
break;
case 'M':
if(parse_bool(optarg) == true){
// Set the bit
output_format |= OUTPUT_SEQ_MATCH;
}
else{
// Unset the bit
output_format &= ~OUTPUT_SEQ_MATCH;
}
break;
case 'k':
if(parse_bool(optarg) == true){
mask_options |= MASK_PRIMERS;
}
else{
mask_options &= ~MASK_PRIMERS;
}
break;
case 'K':
if(parse_bool(optarg) == true){
mask_options |= MASK_PROBE;
}
else{
mask_options &= ~MASK_PROBE;
}
break;
case 'r':
if(parse_bool(optarg) == true){
mask_options |= REPLACE_PRIMERS;
}
else{
mask_options &= ~REPLACE_PRIMERS;
}
break;
case 'v':
verbose = parse_bool(optarg);
break;
case 'p':
ignore_probe = parse_bool(optarg);
break;
case 'n':
one_output_file_per_query = parse_bool(optarg);
break;
case 'L':
append_name_to_defline = parse_bool(optarg);
break;
case 'S':
assay_summary = parse_bool(optarg);
break;
case 'h':
case '?':
print_usage = true;
break;
default:
cerr << '\"' << (char)opt_code << "\" is not a valid option!" << endl;
break;
};
}
if(print_usage){
cerr << "thermonucleotideBLAST v." << TNTBLAST_VERSION << endl;
cerr << "Options:" << endl;
cerr << "\t-i <input file of query oligos>" << endl;
cerr << "\t-o <output file> (default is stdout)" << endl;
cerr << "\t-d <database of target sequences to search against>" << endl;
cerr << "\t[-D <local database of target sequences to search against>]" << endl;
cerr << "\t[-l <maximum amplicon length> (default is " << DEFAULT_MAX_LEN << " bases)" << endl;
cerr << "\t-e <minimum primer Tm>" << endl;
cerr << "\t-E <minimum probe Tm>" << endl;
cerr << "\t[-z <minimum primer delta G (in Kcal/Mol)>] (default is no limit)" << endl;
cerr << "\t[-Z <minimum probe delta G (in Kcal/Mol)>] (default is no limit)" << endl;
cerr << "\t[-x <maximum primer Tm>] (default is no limit)" << endl;
cerr << "\t[-X <maximum probe Tm>] (default is no limit)" << endl;
cerr << "\t[-g <maximum primer delta G (in Kcal/Mol)>] (default is no limit)" << endl;
cerr << "\t[-G <maximum probe delta G(in Kcal/Mol)>] (default is no limit)" << endl;
cerr << "\t[-s <salt concentration (in MOL)>] (default is " << DEFAULT_SALT << " M)" << endl;
cerr << "\t[-t <primer strand concentration (in MOL)>] (default is " << DEFAULT_PRIMER_STRAND << " M)" << endl;
cerr << "\t[-T <Probe strand concentration (in MOL)>] (default is " << DEFAULT_PROBE_STRAND << " M)" << endl;
cerr << "\t[-y <ratio of forward/reverse strand concentrations>] (default is 1, i.e. symmetric PCR)" << endl;
cerr << "\t[-A <PCR | PROBE | PADLOCK | MIPS | AFFY>] (assay format, default is PCR)" << endl;
cerr << "\t[-W <2-8>] (hash word length, default is " << DEFAULT_HASH_WORD_SIZE << ")" << endl;
cerr << "\t[-m <output format>] " << endl;
cerr << "\t\t0 = verbose output file (default)" << endl;
cerr << "\t\t1 = fasta output file" << endl;
cerr << "\t\t2 = network output files (*.atr and *.sif)" << endl;
cerr << "\t\t3 = \"inverse target\" (targets that *don't* match any query)" << endl;
cerr << "\t\t4 = \"inverse query\" (queries that *don't* match any target)" << endl;
cerr << "\t[-a <T|F>] (show alignments, default is T)" << endl;
cerr << "\t[-M <T|F>] (show matching sequence, default is T)" << endl;
cerr << "\t[-k <T|F>] (Mask primer binding sites, default is F)" << endl;
cerr << "\t[-K <T|F>] (Mask probe binding sites, default is F)" << endl;
cerr << "\t[-r <T|F>] (Replace primer binding sites w/ primer sequence, default is F)" << endl;
cerr << "\t[-v <T|F>] (Disable verbose terminal output, default is T)" << endl;
cerr << "\t[-p <T|F>] (Ignore all probe oligos in inputfile, default is F)" << endl;
cerr << "\t[-n <T|F>] (One output file per query, default is F)" << endl;
cerr << "\t[-L <T|F>] (Append assay name to output defline, default is F)" << endl;
cerr << "\t[-S <T|F>] (Ouput assay summary after searching, default is F)" << endl;
cerr << "\t[-h|-?] (Command-line usage)" << endl;
cerr << "\t[--primer-clamp <number of exact 3' primer matches required>] (default is "
<< DEFAULT_PRIMER_CLAMP << " bases)" << endl;
cerr << "\t[--min-max-primer-clamp <the minimum max number of exact 3' primer matches required>] (default is no limit)" << endl;
cerr << "\t[--probe-clamp5 <number of exact 5' probe matches required>] (default is "
<< DEFAULT_PROBE_CLAMP_5 << " bases)" << endl;
cerr << "\t[--probe-clamp3 <number of exact 3' probe matches required>] (default is "
<< DEFAULT_PROBE_CLAMP_3 << " bases)" << endl;
cerr << "\t[--dangle5 <T|F>] (Allow dangling bases on the 5' query side of an alignment, default is "
<< (DEFAULT_DANGLE_5 ? "T" : "F") << ")" << endl;
cerr << "\t[--dangle3 <T|F>] (Allow dangling bases on the 3' query side of an alignment, default is "
<< (DEFAULT_DANGLE_3 ? "T" : "F") << ")" << endl;
cerr << "\t[--plex <T|F>] (All input assays in a single multiple reaction, default is F)" << endl;
cerr << "\t[--temperature <temperature for computing Delta G (in Kelvin)>] (default is "
<< DEFAULT_TARGET_T << " K)" << endl;
cerr << "\t[--single-primer-pcr <T|F>] (Allow amplicons produced by a single PCR primer binding in both forward and reverse orientation, default is T)" << endl;
cerr << "\t[--target-strand <plus|minus|both>] (which strand to target with probes, default is \"both\")" << endl;
cerr << "\t[--max-target-len <max len>] (max sequence length before targets are split, default is "
<< DEFAULT_FRAGMENT_TARGET_LENGTH << " bases)" << endl;
cerr << "\t[--query-seg <always | never | adaptive>] (query segmentation algorithm, default is \"never\")" << endl;
cerr << "\t[--dump-query <T|F>] (write queries to stdout, default is F)" << endl;
cerr << "\t[--dinkelbach <T|F>] (Use the Dinkelbach fractional programming algorithm, default is F)" << endl;
cerr << "\t[--max-gap <number of gaps>] (Max number of allowed gaps in a DNA duplex, default is "
<< DEFAULT_MAX_GAP << ")" << endl;
cerr << "\t[--max-mismatch <number of mismatches>] (Max number of allowed mismatches in a DNA duplex, default is "
<< DEFAULT_MAX_MISMATCH << ")" << endl;
cerr << "\t[--max-poly-degen <number of bases>] (maximum number of contiguous, fully or partially degenerate bases to allow in an "
<< "oligo alignment, default is " << DEFAULT_MAX_POLY_DEGEN << ")" << endl;
cerr << "\t[--rescale-ct <T|F>] (Use of degenerate bases results in rescaling of oligo concentration, default is "
<< (DEFAULT_RESCALE_CT ? "T" : "F") << ")" << endl;
cerr << "\t[--best-match] (Only save the best match, in Tm, between a query and target)" << endl;
#ifdef USE_BLAST_DB
cerr << "\t[--blast-include <Limit search to include accessions or NCBI TaxIds from a BLAST database>] (may be repeated)" << endl;
cerr << "\t[--blast-exclude <Limit search to exclude accessions or NCBI TaxId from a BLAST database>] (may be repeated)" << endl;
#endif // USE_BLAST_DB
}
}
unsigned int Options::parse_assay_format(string m_opt)
{
for(string::iterator i = m_opt.begin();i != m_opt.end();i++){
*i = toupper(*i);
}
if(m_opt == "PCR"){
return ASSAY_PCR;
}
if(m_opt == "PROBE"){
return ASSAY_PROBE;
}
if(m_opt == "PADLOCK"){
return ASSAY_PADLOCK;
}
if( (m_opt == "MIPS") || (m_opt == "MIP") ){
return ASSAY_MIPS;
}
if( (m_opt == "AFFYMETRIX") || (m_opt == "AFFY") ){
return ASSAY_AFFYMETRIX;
}
return ASSAY_NONE;
}
void Options::validate_parameters()
{
if( (dbase_filename == "") && (local_dbase_filename == "") ){
THROW("Unable to read either dbase or local_dbase");
}
if( (dbase_filename != "") && (local_dbase_filename != "") ){
THROW("Please specify either dbase or local_dbase (but not both)");
}
if(ignore_probe){
if(assay_format != ASSAY_PCR){
THROW("Error: Ignore probes (i.e. -p T) can only be used with a PCR-based assay format");
}
if(verbose){
cout << "** Ignoring all probe sequences **" << endl;
}
}
if(salt <= 0.0f){
THROW("[Na+] (i.e. \"salt\") is less than zero");
}
if(salt >= 1.0f){
THROW("[Na+] (i.e. \"salt\") is greater than 1M");
}
if(primer_strand <= 0.0f){
THROW("[Ct] (i.e. \"primer_strand\") is less than zero");
}
if(primer_strand > 10.0f){
THROW("[Ct] (i.e. \"primer_strand\") is greater than 10M");
}
if(probe_strand < 0.0f){
if(verbose){
cout << "Setting probe strand concentration equal to primer strand concentration" << endl;
}
probe_strand = primer_strand;
}
if(probe_strand <= 0.0f){
THROW("[Ct] (i.e. \"probe_strand\") is less than zero");
}
if(probe_strand > 10.0f){
THROW("[Ct] (i.e. \"probe_strand\") is greater than 10M");
}
if(asymmetric_strand_ratio <= 0.0){
THROW("The ratio of forward to reverse primer [Ct] is <= 0");
}
if(min_primer_tm < 0.0f){
THROW("min_primer_tm is less than zero");
}
if(min_primer_tm > 200.0f){
THROW("min_primer_tm is greater than 200 C -- that's too hot!");
}
if(max_primer_tm < 0.0f){
THROW("max_primer_tm is less than zero");
}
if(min_primer_tm > max_primer_tm){
THROW("min_primer_tm > max_primer_tm. Please use consistent values!");
}
if(min_probe_tm < 0.0f){
THROW("min_probe_tm is less than zero");
}
if(min_probe_tm > 200.0f){
THROW("min_probe_tm is greater than 200 C -- that's too hot!");
}
if(max_probe_tm < 0.0f){
THROW("max_probe_tm is less than zero");
}
if(min_probe_tm > max_probe_tm){
THROW("min_probe_tm > max_probe_tm. Please use consistent values!");
}
if(max_len <= 0){
THROW("max_len is less than 1 base -- too small!");
}
if(primer_clamp < 0){
THROW("primer_clamp is less than 0 -- too small!");
}
if(probe_clamp_5 < 0){
THROW("probe_clamp_5 is less than 0 -- too small!");
}
if(probe_clamp_3 < 0){
THROW("probe_clamp_3 is less than 0 -- too small!");
}
if(assay_format == ASSAY_NONE){
THROW("Please specify a valid assay format");
}
if( (hash_word_size < 3) || (hash_word_size > 8) ){
THROW("Please specify a valid hash word size");
}
if(output_format & OUTPUT_NETWORK){
if(output_filename == ""){
THROW("Please specify an output filename when writing network files");
}
}
if(max_gap < 0){
THROW("Error: --max-gap < 0");
}
if(max_mismatch < 0){
THROW("Error: --max-mismatch < 0");
}
if(verbose){
switch(query_segmentation){
case QUERY_SEGMENTATION_ON:
cout << "Query segmentation: always on" << endl;
break;
case QUERY_SEGMENTATION_OFF:
cout << "Query segmentation: disabled" << endl;
break;
case QUERY_SEGMENTATION_ADAPTIVE:
cout << "Query segmentation: adaptive" << endl;
break;
default:
THROW("Unknown option for query segmentation");
break;
};
}
}
void Options::parse_output_file(const string &m_format)
{
const int opt = atoi( m_format.c_str() );
// Unset any previous output file format
output_format &= ~OUTPUT_STANDARD;
output_format &= ~OUTPUT_FASTA;
output_format &= ~OUTPUT_NETWORK;
output_format &= ~OUTPUT_INVERSE_TARGET;
output_format &= ~OUTPUT_INVERSE_QUERY;
switch(opt){
case 0: // 0 = standard verbose output file
output_format |= OUTPUT_STANDARD;
break;
case 1: // 1 = fasta output file
output_format |= OUTPUT_FASTA;
break;
case 2: // 2 = network files (*.atr and *.sif)
output_format |= OUTPUT_NETWORK;
break;
case 3: // 3 = targets (deflines) that *don't* match a query
output_format |= OUTPUT_INVERSE_TARGET;
break;
case 4: // 4 = queries that *don't* match a target
output_format |= OUTPUT_INVERSE_QUERY;
break;
default:
THROW("Unknown output format. Please specify a number between 0-3");
break;
};
}
bool Options::parse_bool(string m_opt)
{
// Make the input string upper case
for(string::iterator i = m_opt.begin();i != m_opt.end();i++){
*i = toupper(*i);
}
if( (m_opt == "T") || (m_opt == "TRUE") ){
return true;
}
if( (m_opt == "F") || (m_opt == "FALSE") ){
return false;
}
THROW("Unknown boolean options -- please use \"T\" or \"F\"");
return false;
}
int Options::parse_strand(string m_opt)
{
// Make the input string upper case
for(string::iterator i = m_opt.begin();i != m_opt.end();i++){
*i = toupper(*i);
}
if( (m_opt == "PLUS") || (m_opt == "+") || (m_opt == "SENSE") ){
return Seq_strand_plus;
}
if( (m_opt == "MINUS") || (m_opt == "-") || (m_opt == "ANTISENSE") ){
return Seq_strand_minus;
}
if(m_opt == "BOTH"){
return Seq_strand_both;
}
cerr << "Unknown target-strand option." << endl;
cerr << "Use \"+\", \"plus\" or \"sense\" for the sense strand" << endl;
cerr << "Use \"-\", \"minus\" or \"antisense\" for the antisense strand" << endl;
cerr << "Use \"both\" for both sense and antisense strands" << endl;
// If we get here, we could not identify the users input
THROW("Unknown target-strand option");
}
int Options::parse_query_seg(string m_opt)
{
// Make the input string upper case
for(string::iterator i = m_opt.begin();i != m_opt.end();i++){
*i = toupper(*i);
}
if(m_opt == "ALWAYS"){
return QUERY_SEGMENTATION_ON;
}
if(m_opt == "NEVER"){
return QUERY_SEGMENTATION_OFF;
}
if(m_opt == "ADAPTIVE"){
return QUERY_SEGMENTATION_ADAPTIVE;
}
cerr << "Unknown query segmentation option." << endl;
cerr << "Use \"always\" to force segmentation" << endl;
cerr << "Use \"never\" to disable segmentation" << endl;
cerr << "Use \"adaptive\" for an adaptive algorithm" << endl;
// If we get here, we could not identify the users input
THROW("Unknown query segmentation option");
}
size_t Options::max_product_length(const vector<string> &m_oligo_table) const
{
size_t ret = 0;
#define STRING(VAR) \
index_to_str(VAR, m_oligo_table)
if(assay_format == ASSAY_PCR){
for(vector<hybrid_sig>::const_iterator iter = sig_list.begin();iter != sig_list.end();iter++){
if(iter->has_primers() == true){
ret = max_len;
break;
}
ret = max( ret, STRING(iter->probe_oligo_str_index).size() );
}
return ret;
}
if(assay_format == ASSAY_PADLOCK){
for(vector<hybrid_sig>::const_iterator iter = sig_list.begin();iter != sig_list.end();iter++){
ret = max( ret, STRING(iter->forward_oligo_str_index).size() + STRING(iter->reverse_oligo_str_index).size() );
}
return ret;
}
for(vector<hybrid_sig>::const_iterator iter = sig_list.begin();iter != sig_list.end();iter++){
ret = max( ret, STRING(iter->probe_oligo_str_index).size() );
}
#undef STRING
return ret;
}
void Options::validate_search_threshold()
{
// Make sure that the user has specific a threshold that is appropriate to
// the assay format
switch(assay_format){
case ASSAY_PCR:
// Since the ASSAY_PCR format can be either PCR primers, or PCR primers and a probe,
// or just a probe, we need to check every assay that the user has provided
for(vector<hybrid_sig>::const_iterator iter = sig_list.begin();iter != sig_list.end();iter++){
if(iter->has_primers() == true){
if( !(threshold_format & THRESHOLD_PRIMER_DELTA_G) &&
!(threshold_format & THRESHOLD_PRIMER_TM) ){
THROW("Please specify primer search bounds in Tm and/or Delta G");
}
}
if(iter->has_probe() == true){
if( !(threshold_format & THRESHOLD_PROBE_DELTA_G) &&
!(threshold_format & THRESHOLD_PROBE_TM) ){
THROW("Please specify probe search bounds in Tm and/or Delta G");
}
}
}
break;
case ASSAY_AFFYMETRIX:
case ASSAY_PROBE:
if( !(threshold_format & THRESHOLD_PROBE_DELTA_G) &&
!(threshold_format & THRESHOLD_PROBE_TM) ){
// Check to see if the user has specified primer constraints. Since this assay format is
// only has probes, we can set the probe constraints to the user-specified primer constraints
if( (threshold_format & THRESHOLD_PRIMER_DELTA_G) || (threshold_format & THRESHOLD_PRIMER_TM) ){
min_probe_dg = min_primer_dg;
max_probe_dg = max_primer_dg;
min_probe_tm = min_primer_tm;
max_probe_tm = max_primer_tm;
}
else{
THROW("Please specify probe search bounds in Tm and/or Delta G");
}
}
break;
case ASSAY_PADLOCK:
case ASSAY_MIPS:
if( !(threshold_format & THRESHOLD_PROBE_DELTA_G) &&
!(threshold_format & THRESHOLD_PROBE_TM) ){
// Check to see if the user has specified primer constraints. Since this assay format is
// only has probes, we can set the probe constraints to the user-specified primer constraints
if( (threshold_format & THRESHOLD_PRIMER_DELTA_G) || (threshold_format & THRESHOLD_PRIMER_TM) ){
min_probe_dg = min_primer_dg;
max_probe_dg = max_primer_dg;
min_probe_tm = min_primer_tm;
max_probe_tm = max_primer_tm;
}
else{
THROW("Please specify probe search bounds in Tm and/or Delta G");
}
}
break;
case ASSAY_NONE:
THROW("No assay format has been specified!");
break;
default:
THROW(__FILE__ ":validate_search_threshold: Unknown assay format!");
break;
};
}
void Options::write_queries(std::ostream &s, const vector<string> &m_str_table)
{
#define STRING(VAR) \
index_to_str(VAR, m_str_table)
for(vector<hybrid_sig>::const_iterator iter = sig_list.begin();iter != sig_list.end();iter ++){
s << STRING(iter->name_str_index);
if(iter->has_primers() == true){
s << '\t' << STRING(iter->forward_oligo_str_index) << '\t' << STRING(iter->reverse_oligo_str_index);
}
if(iter->has_probe() == true){
s << '\t' << STRING(iter->probe_oligo_str_index);
}
s << endl;
}
#undef STRING
}
ostream& operator << (ostream &s, const Options &m_opt)
{
s << "Found " << m_opt.sig_list.size() << " query assays" << endl;
s << "Search parameters:" << endl;
s << "\tOutput = " << m_opt.output_filename << endl;
s << "\t[Na+] = " << m_opt.salt << " M" << endl;
s << "\tmax gap = " << m_opt.max_gap << endl;
s << "\tmax mismatch = " << m_opt.max_mismatch << endl;
if( m_opt.has_primers() ){
if(m_opt.asymmetric_strand_ratio != 1.0f){
s << "\t[reverse primer Ct] = " << m_opt.primer_strand
<< " M" << endl;
s << "\t[forward primer Ct]/[reverse primer Ct] = "
<< m_opt.asymmetric_strand_ratio << endl;
}
else{
s << "\t[primer Ct] = " << m_opt.primer_strand << " M" << endl;
}
}
if( m_opt.has_probe() ){
s << "\t[probe Ct] = " << m_opt.probe_strand << " M" << endl;
}
if( m_opt.has_primers() ){
if(m_opt.assay_format == ASSAY_PCR){ // These are PCR primers
s << '\t' << m_opt.min_primer_tm << " <= Primer Tm (C) <= " << m_opt.max_primer_tm << endl;
s << '\t' << m_opt.min_primer_dg << " <= Primer Delta G (Kcal/Mol) <= "
<< m_opt.max_primer_dg << endl;
}
else{ // These are Padlock probes (not actually primers)
s << '\t' << m_opt.min_primer_tm << " <= Padlock Tm (C) <= " << m_opt.max_primer_tm << endl;
s << '\t' << m_opt.min_primer_dg << " <= Padlock Delta G (Kcal/Mol) <= "
<< m_opt.max_primer_dg << endl;
}
}
if( m_opt.has_probe() ){
s << '\t' << m_opt.min_probe_tm << " <= Probe Tm (C) <= " << m_opt.max_probe_tm << endl;
s << '\t' << m_opt.min_probe_dg << " <= Probe Delta G (Kcal/Mol) <= "
<< m_opt.max_probe_dg << endl;
}
if(m_opt.assay_format == ASSAY_PADLOCK){
s << "\t5' Ligation clamp = " << m_opt.probe_clamp_5 << endl;
s << "\t3' Ligation clamp = " << m_opt.probe_clamp_3 << endl;
s << "Assay format is PADLOCK/MOL-PCR" << endl;
}
else{